From e068d45199bb23452821727e5b82a2307ae0256d Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Wed, 13 Oct 2021 17:18:31 +0200 Subject: Add eq? primitive procedure --- src/bootstrap/primitives.c | 47 ++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'src/bootstrap/primitives.c') diff --git a/src/bootstrap/primitives.c b/src/bootstrap/primitives.c index 8369fa8..2a82782 100644 --- a/src/bootstrap/primitives.c +++ b/src/bootstrap/primitives.c @@ -880,21 +880,32 @@ proc_list(Environment *env, Object *obj) { // Polymorphic procedures. // -//Object * -//proc_equal(Object *args) { -// // TODO: stub -// (void) args; -// return NULL; -//} - -//// TODO: fixnum left/right shift, mask, invert -//// TODO: implement and test missing procedures -//// TODO: add primitives for type transforms: string->symbol, symbol->string, etc -//// TODO: properly implement nested environments -//// TODO: implement support for quotes and semi-quotes -//// TODO: LAMBDA -//// TODO: let -//// TODO: better error handling? -//// TODO: Revise all instances where we are returning an object, since currently -//// we may be returning a pointer to an object instead of a new one. Check also -//// on eval function and everytime we do make_xxx(obj). +Object * +proc_equal(Environment *env, Object *obj) { + if (obj == obj_nil || obj->cdr == obj_nil) { + error_push((Error){ + .type = ERR_TYPE_RUNTIME, + .value = ERR_NOT_ENOUGH_ARGS, + }); + return obj_err; + } + Object *a = eval(env, obj->car); + if (a == obj_err) { + return obj_err; + } + Object *b = eval(env, obj->cdr->car); + if (b == obj_err) { + return obj_err; + } + return obj_eq(a, b) ? obj_true : obj_false; +} + + +// TODO: fixnum left/right shift, mask, invert +// TODO: add primitives for type transforms: string->symbol, symbol->string, etc +// TODO: implement support for semi-quotes +// TODO: LAMBDA +// TODO: let +// TODO: Revise all instances where we are returning an object, since currently +// we may be returning a pointer to an object instead of a new one. Check also +// on eval function and everytime we do make_xxx(obj). -- cgit v1.2.1