From 25afb2c964ed09dca3b9b17c2a7a92ea93c93918 Mon Sep 17 00:00:00 2001 From: mtardy Date: Wed, 5 Aug 2020 14:37:56 +0000 Subject: [PATCH] Bug fix integer tag optimization --- object.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/object.c b/object.c index f9021da..cfc4b41 100644 --- a/object.c +++ b/object.c @@ -3,7 +3,7 @@ #include #include -#define USE_TAG 1 +#define USE_TAG 0 #define USE_GC 1 @@ -131,16 +131,15 @@ int isInteger(oop obj) #endif } +#if (USE_TAG) +# define getType(PTR) (((intptr_t)(PTR) & 1) ? Integer : (PTR)->type) +#else type_t getType(oop ptr) { assert(ptr); -#if (USE_TAG) - if (isInteger(ptr)) { - return Integer; - } -#endif return ptr->type; } +#endif int is(type_t type, oop obj) { @@ -150,10 +149,10 @@ int is(type_t type, oop obj) oop _checkType(oop ptr, type_t type, char *file, int line) { assert(ptr); - if (ptr->type != type) { + if (getType(ptr) != type) { fprintf(stderr, "\n%s:%i: expected %i got %i\n", file, line, type, ptr->type); } - assert(ptr->type == type); + assert(getType(ptr) == type); return ptr; } @@ -379,7 +378,7 @@ void map_print(oop map, int ident) print(get(map, Map, elements)[i].key); printf(": "); oop rhs = get(map, Map, elements)[i].value; - if (rhs->type == Map) { + if (getType(rhs) == Map) { map_print(rhs, ident + 1); } else { print(rhs); @@ -392,7 +391,7 @@ void map_print(oop map, int ident) void print(oop ast) { assert(ast); - switch (ast->type) { + switch (getType(ast)) { case Undefined: printf("null"); return;