From b2301406c44ca423f6e0d93b4650a2748188d725 Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Tue, 9 Feb 2010 19:28:29 -0500 Subject: [PATCH] Since we don't use closures as pairs in the stack anymore, the environment pointer in closures has been moved to the car, to simplify gc. --- dispatch.c | 22 +++++++++++----------- gc.c | 22 ++-------------------- picobit-vm.c | 10 ++++------ picobit-vm.h | 7 +------ primitives.c | 6 +++--- 5 files changed, 21 insertions(+), 46 deletions(-) diff --git a/dispatch.c b/dispatch.c index 7fa01b6..d1edaa7 100644 --- a/dispatch.c +++ b/dispatch.c @@ -42,7 +42,7 @@ uint8 handle_arity_and_rest_param (uint8 na) { np = rom_get (entry++); if (arg1 != OBJ_NULL) - arg1 = ram_get_cdr(arg1); // closed environment + arg1 = ram_get_car(arg1); // closed environment if ((np & 0x80) == 0) { if (na != np) @@ -86,10 +86,10 @@ uint8 build_env (uint8 na) { void save_cont () { // the second half is a closure - arg3 = alloc_ram_cell_init (CLOSURE_FIELD0 | (pc >> 11), - (pc >> 3) & 0xff, - ((pc & 0x0007) << 5) | (env >> 8), - env & 0xff); + arg3 = alloc_ram_cell_init (CLOSURE_FIELD0 | (env >> 8), + env & 0xff, + (pc >> 8), + (pc & 0xff)); cont = alloc_ram_cell_init (COMPOSITE_FIELD0 | (cont >> 8), cont & 0xff, CONTINUATION_FIELD2 | (arg3 >> 8), @@ -311,10 +311,10 @@ void interpreter () { arg3 = pop(); // env - arg1 = alloc_ram_cell_init (CLOSURE_FIELD0 | (entry >> 11), - entry >> 3, - ((entry & 0x07) <<5) | ((arg3 >> 8) & 0x1f), - arg3 & 0xff); + arg1 = alloc_ram_cell_init (CLOSURE_FIELD0 | (arg3 >> 8), + arg3 & 0xff, + entry >> 8, + (entry & 0xff)); push_arg1(); @@ -575,7 +575,7 @@ void interpreter () { pc = ram_get_entry (arg2); - env = ram_get_cdr (arg2); + env = ram_get_car (arg2); cont = ram_get_car (cont); push_arg1(); @@ -674,7 +674,7 @@ void interpreter () { arg1 = pop(); arg2 = ram_get_cdr (cont); pc = ram_get_entry (arg2); - env = ram_get_cdr (arg2); + env = ram_get_car (arg2); cont = ram_get_car (cont); push_arg1(); arg2 = OBJ_FALSE; diff --git a/gc.c b/gc.c index d658f92..1d8f5b7 100644 --- a/gc.c +++ b/gc.c @@ -87,18 +87,12 @@ void mark (obj temp) { visit_field1: // closures have the pointer in the cdr, not in the car as others - if (RAM_CLOSURE(visit)) - temp = ram_get_cdr (visit); - else - temp = ram_get_car (visit); + temp = ram_get_car (visit); if (IN_RAM(temp)) { IF_GC_TRACE(printf ("case 6\n")); ram_set_gc_tag0 (visit, GC_TAG_0_LEFT); - if (RAM_CLOSURE(visit)) - ram_set_cdr (visit, stack); - else - ram_set_car (visit, stack); + ram_set_car (visit, stack); goto push; } @@ -130,18 +124,6 @@ void mark (obj temp) { goto visit_field1; } - if (RAM_CLOSURE(stack)) { - // closures have one object field, but it's in the cdr - IF_GC_TRACE(printf ("case 10\n")); - - temp = ram_get_cdr (stack); /* pop through cdr */ - ram_set_cdr (stack, visit); - visit = stack; - stack = temp; - - goto pop; - } - IF_GC_TRACE(printf ("case 11\n")); temp = ram_get_car (stack); /* pop through car */ diff --git a/picobit-vm.c b/picobit-vm.c index d7ba1f5..81bd323 100644 --- a/picobit-vm.c +++ b/picobit-vm.c @@ -92,14 +92,12 @@ void ram_set_cdr (obj o, obj val) { // function entry point // the temporary variables are necessary with SIXPIC, see above obj ram_get_entry (obj o) { - uint16 tmp = ram_get_field0 (o) & 0x1f; - uint16 tmp2 = ram_get_field1 (o); - return ((tmp << 11) | (tmp2 << 3) | (ram_get_field2 (o) >> 5)); + uint16 tmp = ram_get_field2 (o); + return ((tmp << 8) | ram_get_field3 (o)); } obj rom_get_entry (obj o){ - uint16 tmp = rom_get_field0 (o) & 0x1f; - uint16 tmp2 = rom_get_field1 (o); - return ((tmp << 11) | (tmp2 << 3) | (rom_get_field2 (o) >> 5)); + uint16 tmp = rom_get_field2 (o); + return ((tmp << 8) | rom_get_field3 (o)); } obj get_global (uint8 i) { diff --git a/picobit-vm.h b/picobit-vm.h index a9568be..032027d 100644 --- a/picobit-vm.h +++ b/picobit-vm.h @@ -378,14 +378,9 @@ void set_global (uint8 i, obj o); x is length of the vector, in bytes (stored raw, not encoded as an object) y is pointer to the elements themselves (stored in vector space) - closure 01Gaaaaa aaaaaaaa aaaxxxxx xxxxxxxx + closure 01Gxxxxx xxxxxxxx aaaaaaaa aaaaaaaa 0x5ff