80 lines
1.3 KiB
C
80 lines
1.3 KiB
C
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <value/struct.h>
|
|
|
|
#include <value/list/new.h>
|
|
|
|
#include <gc/dec_external_refcount.h>
|
|
|
|
#include "../defines/BUILTIN_PARAMETER_DECLARATION.h"
|
|
|
|
#include "cons.h"
|
|
|
|
struct value* builtin_cons(
|
|
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* eval_first = evalfunc(first, environment, gc);
|
|
|
|
struct value* eval_second = evalfunc(second, environment, gc);
|
|
|
|
struct value* result = new_list_value(
|
|
/* garbage collector: */ gc,
|
|
/* first: */ eval_first);
|
|
|
|
result->subclass.list.rest = eval_second;
|
|
|
|
gc_dec_external_refcount(gc, eval_first);
|
|
|
|
gc_dec_external_refcount(gc, eval_second);
|
|
|
|
EXIT;
|
|
return result;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|