From f45261214f87cfd152389db82d79957e13deb140 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Thu, 4 May 2023 18:51:07 +0400 Subject: [PATCH] Organize builtins --- builtins.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/builtins.c b/builtins.c index 416e465..ac5cc4c 100644 --- a/builtins.c +++ b/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;