lisp-take-1/builtins/comparision/equal_to.c

72 lines
1.3 KiB
C

#include <assert.h>
#include <debug.h>
#include "../defines/BUILTIN_PARAMETER_DECLARATION.h"
#include <gc/dec_external_refcount.h>
#include <value/struct.h>
#include <value/compare.h>
#include <value/boolean/new.h>
#include "equal_to.h"
struct value* builtin_equal_to(
BUILTIN_PARAMETER_DECLARATION)
{
ENTER;
if (arguments->kind != vk_list)
{
TODO;
exit(1);
}
struct list_value* arguments_lv = &arguments->subclass.list;
struct value* first = arguments_lv->first;
struct value* rest = arguments_lv->rest;
if (rest->kind != vk_list)
{
TODO;
exit(1);
}
struct value* second = rest->subclass.list.first;
struct value* restrest = rest->subclass.list.rest;
if (restrest->kind != vk_null)
{
TODO;
exit(1);
}
struct value* first_eval = evalfunc(first, environment, gc);
struct value* second_eval = evalfunc(second, environment, gc);
int cmp = compare_values(first_eval, second_eval);
struct value* result = new_boolean_value(gc, cmp == 0);
gc_dec_external_refcount(gc, first_eval);
gc_dec_external_refcount(gc, second_eval);
EXIT;
return result;
}