diff --git a/build.sh b/build.sh index 58b4f73..0de9ebf 100755 --- a/build.sh +++ b/build.sh @@ -68,9 +68,6 @@ ar rcs build/libnoja-runtime.a \ build/libnoja-compile.a \ build/libnoja-objects.a -gcc tests/src/test-parse.c -o build/test-parse $FLAGS -Lbuild/ -lnoja-compile -lxjson -gcc tests/src/test-objects.c -o build/test-objects $FLAGS -Lbuild/ -lnoja-objects - gcc src/main.c \ src/noja.c \ temp/o_builtins.o \ diff --git a/src/objects/o_int.c b/src/objects/o_int.c index 883ebd3..9fcbd65 100644 --- a/src/objects/o_int.c +++ b/src/objects/o_int.c @@ -1,10 +1,12 @@ #include #include #include "objects.h" +#include "../utils/hash.h" static long long int to_int(Object *obj, Error *err); static void print(Object *obj, FILE *fp); static _Bool op_eql(Object *self, Object *other); +static int hash(Object *self); typedef struct { Object base; @@ -16,11 +18,22 @@ static TypeObject t_int = { .name = "int", .size = sizeof (IntObject), .atomic = ATMTP_INT, + .hash = hash, .to_int = to_int, .print = print, .op_eql = op_eql, }; +static int hash(Object *self) +{ + assert(self != NULL); + assert(self->type == &t_int); + + IntObject *iobj = (IntObject*) self; + + return hashbytes((unsigned char*) &iobj->val, sizeof(iobj->val)); +} + static long long int to_int(Object *obj, Error *err) { assert(obj != NULL); diff --git a/tests/test.noja b/tests/test.noja index a26c848..5d2d8ba 100644 --- a/tests/test.noja +++ b/tests/test.noja @@ -69,6 +69,23 @@ assert((false or false) == false); } +# Test lists. +{ + [1]; [1.0]; ['x']; [1, 1]; [1.0, 1.0]; ['x', 'x']; +} + +# Test maps. +{ + ({}); + ({'': none}); + ({1: none}); + ({1.0: none}); + ({true: none}); + ({false: none}); + ({[]: none}); + ({{}: none}); +} + # Test if-else statements. { if true: r = true; else r = false;