Explorar el Código

Bug fix integer tag optimization

pull/5/head
mtardy hace 4 años
padre
commit
25afb2c964
Se han modificado 1 ficheros con 9 adiciones y 10 borrados
  1. +9
    -10
      object.c

+ 9
- 10
object.c Ver fichero

@ -3,7 +3,7 @@
#include <sysexits.h> #include <sysexits.h>
#include <assert.h> #include <assert.h>
#define USE_TAG 1
#define USE_TAG 0
#define USE_GC 1 #define USE_GC 1
@ -131,16 +131,15 @@ int isInteger(oop obj)
#endif #endif
} }
#if (USE_TAG)
# define getType(PTR) (((intptr_t)(PTR) & 1) ? Integer : (PTR)->type)
#else
type_t getType(oop ptr) type_t getType(oop ptr)
{ {
assert(ptr); assert(ptr);
#if (USE_TAG)
if (isInteger(ptr)) {
return Integer;
}
#endif
return ptr->type; return ptr->type;
} }
#endif
int is(type_t type, oop obj) 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) oop _checkType(oop ptr, type_t type, char *file, int line)
{ {
assert(ptr); 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); 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; return ptr;
} }
@ -379,7 +378,7 @@ void map_print(oop map, int ident)
print(get(map, Map, elements)[i].key); print(get(map, Map, elements)[i].key);
printf(": "); printf(": ");
oop rhs = get(map, Map, elements)[i].value; oop rhs = get(map, Map, elements)[i].value;
if (rhs->type == Map) {
if (getType(rhs) == Map) {
map_print(rhs, ident + 1); map_print(rhs, ident + 1);
} else { } else {
print(rhs); print(rhs);
@ -392,7 +391,7 @@ void map_print(oop map, int ident)
void print(oop ast) void print(oop ast)
{ {
assert(ast); assert(ast);
switch (ast->type) {
switch (getType(ast)) {
case Undefined: case Undefined:
printf("null"); printf("null");
return; return;

Cargando…
Cancelar
Guardar