implemented hash for ints and removed unused portion of the build script

This commit is contained in:
cozis
2022-03-09 12:39:43 +01:00
parent 84fa86c373
commit ea51795aae
3 changed files with 30 additions and 3 deletions
-3
View File
@@ -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 \
+13
View File
@@ -1,10 +1,12 @@
#include <assert.h>
#include <string.h>
#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);
+17
View File
@@ -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;