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);
|
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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue