From a8fbd48ffd00f15e0fa1e5fb5105dc027173f424 Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Thu, 17 Jul 2008 17:38:42 -0400 Subject: [PATCH] Fixnums now go from 0 to 255 instead of -5 to 40. Nothings seems to have broken because of this, but the GC bug subsists. Saves us about 200 bytes for the stack (from 5980 to 5808). --- picobit-vm.c | 27 +++++++++++++++------------ picobit.scm | 28 +++++++++++++--------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/picobit-vm.c b/picobit-vm.c index c9b4ede..4c11750 100644 --- a/picobit-vm.c +++ b/picobit-vm.c @@ -6,7 +6,7 @@ * History: * * 15/08/2004 Release of version 1 - * 6/07/2008 Modified for PICOBOARD2_R3 + * 06/07/2008 Modified for PICOBOARD2_R3 */ #define DEBUG_not @@ -82,7 +82,6 @@ static volatile near bit ACTIVITY_LED2 @ ((unsigned)&ACTIVITY_LED2_LAT*8)+ACTIVI #ifdef DEBUG #define IF_TRACE(x) x #define IF_GC_TRACE(x) x -// TODO the last x was added to have gc debug info #else #define IF_TRACE(x) #define IF_GC_TRACE(x) @@ -134,16 +133,18 @@ typedef uint16 obj; /*---------------------------------------------------------------------------*/ -#define MIN_RAM_ENCODING 128 +/* #define MIN_RAM_ENCODING 128 */ // TODO NEW #define MAX_RAM_ENCODING 8192 +#define MIN_RAM_ENCODING 512 #define RAM_BYTES ((MAX_RAM_ENCODING - MIN_RAM_ENCODING + 1)*4) // TODO watch out if we address more than what the PIC actually has // TODO change if we change the proportion of rom and ram addresses #if WORD_BITS == 8 #define OBJ_TO_RAM_ADDR(o,f) (((ram_addr)((uint16)(o) - MIN_RAM_ENCODING) << 2) + (f)) -#define OBJ_TO_ROM_ADDR(o,f) (((rom_addr)((uint8)(o) - MIN_ROM_ENCODING) << 2) + (CODE_START + 4 + (f))) +#define OBJ_TO_ROM_ADDR(o,f) (((rom_addr)((uint16)(o) - MIN_ROM_ENCODING) << 2) + (CODE_START + 4 + (f))) #endif +// TODO ROM had uint8 cast, but seemed to cause problems #ifdef PICOBOARD2 @@ -156,7 +157,7 @@ uint8 ram_mem[RAM_BYTES]; #define ram_get(a) *(uint8*)(a+0x200) #define ram_set(a,x) *(uint8*)(a+0x200) = (x) - +// TODO change these since we change proportion of ram and rom ? #endif @@ -285,8 +286,10 @@ obj globals[GLOVARS]; #define OBJ_NULL 2 #define MIN_FIXNUM_ENCODING 3 -#define MIN_FIXNUM (-5) -#define MAX_FIXNUM 40 +#define MIN_FIXNUM 0 +// TODO NEW was (-5) +#define MAX_FIXNUM 255 +// TODO NEW was 40 #define MIN_ROM_ENCODING (MIN_FIXNUM_ENCODING+MAX_FIXNUM-MIN_FIXNUM+1) #define ENCODE_FIXNUM(n) ((obj)(n) + (MIN_FIXNUM_ENCODING - MIN_FIXNUM)) @@ -294,7 +297,7 @@ obj globals[GLOVARS]; #if WORD_BITS == 8 #define IN_RAM(o) ((o) >= MIN_RAM_ENCODING) -#define IN_ROM(o) ((o) >= MIN_ROM_ENCODING) +#define IN_ROM(o) (!IN_RAM(o) && ((o) >= MIN_ROM_ENCODING)) #endif // TODO BARF rom only checks the lower bound, might cause problem if not used in an else @@ -479,7 +482,7 @@ void show_type (obj o) // for debugging purposes else if (ROM_VECTOR(o)) printf("%x : rom vector\n", o); else if (ROM_CONTINUATION(o)) printf("%x : rom continuation\n", o); else if (RAM_CLOSURE(o)) printf("%x : rom closure\n", o); - } + } // TODO add fixnums, bools, nil } #endif @@ -665,7 +668,7 @@ void mark (obj temp) if (RAM_CLOSURE(stack)) // TODO doesn't seem to solve the problem // closures have one object field, but it's in the cdr - // TODO will the stack ever be a closure ? + // TODO will the stack ever be a closure ? probably { IF_GC_TRACE(printf ("case 13.5\n")); // TODO renumber cases @@ -894,7 +897,7 @@ void show (obj o) loop: show (car); - + if (cdr == OBJ_NULL) printf (")"); else if ((IN_RAM(cdr) && RAM_PAIR(cdr)) @@ -2351,7 +2354,7 @@ void interpreter (void) break; #endif case 12: - /* push-constant [long] */ // BARF seems to be wrong + /* push-constant [long] */ FETCH_NEXT_BYTECODE(); second_half = bytecode; FETCH_NEXT_BYTECODE(); diff --git a/picobit.scm b/picobit.scm index 5b5343c..8d91bda 100644 --- a/picobit.scm +++ b/picobit.scm @@ -748,7 +748,7 @@ (define gen-closure (lambda (label-entry ctx) - (gen-instruction (list 'closure label-entry) 1 1 ctx))) ;; TODO was 2 1 + (gen-instruction (list 'closure label-entry) 1 1 ctx))) (define gen-prim (lambda (id nargs unspec-result? ctx) @@ -1040,10 +1040,10 @@ (gen-push-local-var (car vars) ctx))))) (if (null? vars) - (gen-closure label-entry ;; TODO it seems no actual closure objects are stored in ROM, only the code to generate them, so we probably are ok if we don't modify anything, the vm takes care of everything - (gen-push-constant '() ctx)) ;; TODO was (gen-push-constant #f ctx) (gen-closure label-entry - (build vars ctx)))) ;; TODO was (gen-push-constant #f ctx) + (gen-push-constant '() ctx)) + (gen-closure label-entry + (build vars ctx)))) ;; TODO the last branch was changed because since pointers are now larger, there is not a pointer-sized free space in each closure, which could make it behave like a pair. now, everything is in the env, and closures only have a cdr (define comp-prc @@ -2417,11 +2417,11 @@ ;------------------------------------------------------------------------------ -(define min-fixnum-encoding 3) -(define min-fixnum -5) -(define max-fixnum 40) +(define min-fixnum-encoding 3) ;; BARF was changed +(define min-fixnum 0) ;; TODO have from 0 to 255, and 256-3 rom objects TODO was -5 +(define max-fixnum 255) ;; TODO was 40 (define min-rom-encoding (+ min-fixnum-encoding (- max-fixnum min-fixnum) 1)) -(define min-ram-encoding 128) ;; TODO change ? +(define min-ram-encoding 512) ;; TODO was 128 NEW (all these) (define max-ram-encoding 8191) (define code-start #x5000) @@ -2450,7 +2450,7 @@ (char->integer obj) obj)) -(define (encode-constant obj constants) ;; TODO FOOBAR, this should return a 12 bit value +(define (encode-constant obj constants) (let ((o (translate-constant obj))) (let ((e (encode-direct o))) (if e @@ -2460,7 +2460,7 @@ (vector-ref (cdr x) 0) (compiler-error "unknown object" obj))))))) -(define (add-constant obj constants from-code? cont) ;; TODO where does the actual encoding actually take place ? at assembly time ? probably +(define (add-constant obj constants from-code? cont) (let ((o (translate-constant obj))) (let ((e (encode-direct o))) (if e @@ -2514,7 +2514,7 @@ new-constants cont))))) -(define (add-global var globals cont) ;; TODO check if mutable, and if not, put as constant +(define (add-global var globals cont) (let ((x (assq var globals))) (if x (cont globals) @@ -2534,7 +2534,7 @@ (if (null? lst) (if (> i min-ram-encoding) (compiler-error "too many constants") - csts) ;; TODO do some constant propagation, actually, more for globals ? + csts) (begin (vector-set! (cdr (car lst)) 0 i) (loop (+ i 1) @@ -2583,11 +2583,9 @@ (define (label-instr label opcode) (asm-at-assembly (lambda (self) - 3) ;; TODO BARF was 2, maybe was length ? seems to be fixed + 3) (lambda (self) (let ((pos (- (asm-label-pos label) code-start))) - ;; (asm-8 (+ (quotient pos 256) opcode)) - ;; TODO do we mess up any offsets ? FOOBAR (asm-8 opcode) (asm-8 (quotient pos 256)) (asm-8 (modulo pos 256)))))) -- 2.11.4.GIT