From c7878cd824360c6bf8a8e987acfa6a31140e9d69 Mon Sep 17 00:00:00 2001 From: Felix Perktold Date: Sun, 21 Dec 2025 22:03:34 +0100 Subject: add builtins, add pretty printing for lists, fix erroneous symbol x not found for forms (define, lambda ...) add check for head->type == VT_SYMBOL on forms (so a string cannot be misinterpreted as a form symbol), move is_integer from lisp.y to lisp.h/lisp.c --- lisp.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'lisp.h') diff --git a/lisp.h b/lisp.h index a43f750..b7e5a94 100644 --- a/lisp.h +++ b/lisp.h @@ -11,7 +11,8 @@ typedef enum { VT_STRING, VT_NIL, VT_PAIR, - VT_LAMBDA + VT_LAMBDA, + VT_BUILTIN } val_type; struct value { @@ -30,6 +31,9 @@ struct value { value *body; env *env; } lambda; + struct { + value *(*fn) (env *, value *); + } builtin; } as; }; @@ -39,6 +43,7 @@ value *make_symbol(const char *sym); value *make_string(const char *str); value *make_nil(); value *make_lambda(env *e, value *params, value *body); +value *make_builtin(value *(*fn) (env *, value *)); value *cons(value *car, value *cdr); value *car(value *cons); value *cdr(value *cons); @@ -64,4 +69,16 @@ value *eval_pair(env *e, value *val); value *apply(value *lambda, value *args); +value *builtin_cons(env *e, value *args); +value *builtin_car(env *e, value *args); +value *builtin_cdr(env *e, value *args); +value *builtin_isnull(env *e, value *args); +value *builtin_add(env *e, value *args); +value *builtin_sub(env *e, value *args); +value *builtin_mul(env *e, value *args); +value *builtin_div(env *e, value *args); +value *builtin_le(env *e, value *args); + +int is_integer(double x); + #endif -- cgit v1.2.3