1
0
Fork 0

Organize builtins

This commit is contained in:
Alex Kotov 2023-05-04 18:51:07 +04:00
parent 65fdaec1cf
commit f45261214f
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08

View file

@ -11,9 +11,10 @@ struct Builtin {
struct Object *(*func)(struct Object *args); struct Object *(*func)(struct Object *args);
}; };
// Basic functions // Evaluation
static struct Object *func_cons(struct Object *args);
static struct Object *func_eval(struct Object *args); static struct Object *func_eval(struct Object *args);
// Basic data structures
static struct Object *func_cons(struct Object *args);
static struct Object *func_quote(struct Object *args); static struct Object *func_quote(struct Object *args);
// Type predicates // Type predicates
static struct Object *func_booleanQN(struct Object *args); static struct Object *func_booleanQN(struct Object *args);
@ -34,9 +35,10 @@ static struct Object *func_newline(struct Object *args);
static struct Object *func_sum(struct Object *args); static struct Object *func_sum(struct Object *args);
static struct Builtin builtins[] = { static struct Builtin builtins[] = {
// Basic functions // Evaluation
{ "cons", func_cons },
{ "eval", func_eval }, { "eval", func_eval },
// Basic data structures
{ "cons", func_cons },
{ "quote", func_quote }, { "quote", func_quote },
// Type predicates // Type predicates
{ "boolean?", func_booleanQN }, { "boolean?", func_booleanQN },
@ -88,9 +90,22 @@ struct Object *builtins_eval(struct Object *program)
return builtins_call(program->pair.a->s, program->pair.b); return builtins_call(program->pair.a->s, program->pair.b);
} }
/******************* /**************
* Basic functions * * Evaluation *
*******************/ **************/
struct Object *func_eval(struct Object *const args)
{
assert(args);
assert(args->type == TYPE_PAIR);
assert(args->pair.b == NULL);
return builtins_eval(args->pair.a);
}
/*************************
* Basic data structures *
*************************/
struct Object *func_cons(struct Object *const args) struct Object *func_cons(struct Object *const args)
{ {
@ -108,15 +123,6 @@ struct Object *func_cons(struct Object *const args)
return Object_new_pair(car, cdr); return Object_new_pair(car, cdr);
} }
struct Object *func_eval(struct Object *const args)
{
assert(args);
assert(args->type == TYPE_PAIR);
assert(args->pair.b == NULL);
return builtins_eval(args->pair.a);
}
struct Object *func_quote(struct Object *const args) struct Object *func_quote(struct Object *const args)
{ {
if (!args) return NULL; if (!args) return NULL;