Organize builtins
This commit is contained in:
parent
65fdaec1cf
commit
f45261214f
1 changed files with 22 additions and 16 deletions
38
builtins.c
38
builtins.c
|
@ -11,9 +11,10 @@ struct Builtin {
|
|||
struct Object *(*func)(struct Object *args);
|
||||
};
|
||||
|
||||
// Basic functions
|
||||
static struct Object *func_cons(struct Object *args);
|
||||
// Evaluation
|
||||
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);
|
||||
// Type predicates
|
||||
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 Builtin builtins[] = {
|
||||
// Basic functions
|
||||
{ "cons", func_cons },
|
||||
// Evaluation
|
||||
{ "eval", func_eval },
|
||||
// Basic data structures
|
||||
{ "cons", func_cons },
|
||||
{ "quote", func_quote },
|
||||
// Type predicates
|
||||
{ "boolean?", func_booleanQN },
|
||||
|
@ -88,9 +90,22 @@ struct Object *builtins_eval(struct Object *program)
|
|||
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)
|
||||
{
|
||||
|
@ -108,15 +123,6 @@ struct Object *func_cons(struct Object *const args)
|
|||
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)
|
||||
{
|
||||
if (!args) return NULL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue