From: Elijah Cohen Date: Wed, 24 Jul 2024 05:58:35 +0000 (-0500) Subject: boutta make some big restructuring, makefile better X-Git-Url: https://git.eli173.com/?a=commitdiff_plain;h=cfccc158d2aa94f61a752bfc04f60898295d1a3b;p=klapaucius boutta make some big restructuring, makefile better --- diff --git a/src/Makefile b/src/Makefile index 9d52008..7117825 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,7 +3,7 @@ CC:=llvm-gcc # okay what the fuck am i doing with lex yacc generated stuff? just do it once? okay -SRCS:= $(wildcard *.c) +SRCS:= $(wildcard *.c */*.c) BUILD:= ../build BIN:=repl TEST_BIN:=test diff --git a/src/builtins.c b/src/builtins.c index 74ddec4..002897d 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -9,12 +9,21 @@ #include "builtins/core.h" -Sexpr* dispatch(Sexpr* b) { +Sexpr* apply(Sexpr* b, Sexpr* env) { uint64_t prefix = (b->value.b.opcode) >> 8; switch(prefix) { case CORE_PREFIX: - return x_core_dispatch(b); + return x_core_dispatch(b, env); default: return from_nil(); } } + +Sexpr* append_arg(Sexpr* b, Sexpr* arg) { + // where b better be a builtin + Sexpr* ret = malloc(sizeof(Sexpr)); + ret->type = BUILTIN; + ret->value.b.opcode = b->value.b.opcode; + ret->value.b.args = cons(arg, b->value.b.args); + return ret; +} diff --git a/src/builtins.h b/src/builtins.h index cc110c3..f5aa583 100644 --- a/src/builtins.h +++ b/src/builtins.h @@ -7,8 +7,8 @@ #define _HIIIII -Sexpr* dispatch(Sexpr* b); - +Sexpr* apply(Sexpr* b, Sexpr* env); +Sexpr* append_arg(Sexpr* b, Sexpr* arg); #endif diff --git a/src/builtins/core.c b/src/builtins/core.c index 8e08682..f6d14a6 100644 --- a/src/builtins/core.c +++ b/src/builtins/core.c @@ -4,13 +4,38 @@ #include "../sexpr.h" #include "../eval.h" +Sexpr* c_quote(Sexpr* args) { + return car(args); +} +Sexpr* c_cons(Sexpr* args) { + Sexpr* _car = car(args); + Sexpr* _cdr = car(cdr(args)); + return cons(_car, _cdr); +} +Sexpr* c_car(Sexpr* args) { + return car(car(args)); +} +Sexpr* c_cdr(Sexpr* args) { + return cdr(car(args)); +} +Sexpr* c_if(Sexpr* args) { + Sexpr* cond = car(args); + Sexpr* truthy = car(cdr(args)); + Sexpr* falsy = car(cdr(cdr(args))); + +} +//Sexpr* c_quote(Sexpr* args); +//Sexpr* c_cons(Sexpr* args); -Sexpr* x_core_dispatch(Sexpr* s) { +Sexpr* x_core_dispatch(Sexpr* s, Sexpr* env) { uint64_t code = s->value.b.opcode & 0xff; + Sexpr* args = s->value.b.args; switch(code) { case 0: // quote - + return c_quote(args); + case 1: // cons + return c_cons(args); default: return from_nil(); } diff --git a/src/builtins/core.h b/src/builtins/core.h index 7f941e0..bbcc74d 100644 --- a/src/builtins/core.h +++ b/src/builtins/core.h @@ -7,5 +7,5 @@ #define CORE_PREFIX 0x00 -Sexpr* x_core_dispatch(Sexpr* s); +Sexpr* x_core_dispatch(Sexpr* s, Sexpr* env); diff --git a/src/eval.c b/src/eval.c index a28fd07..e3a42dd 100644 --- a/src/eval.c +++ b/src/eval.c @@ -7,7 +7,7 @@ #include "dict.h" #include "builtins.h" -Sexpr* apply_builtin(Sexpr* func, Sexpr* arg); +Sexpr* apply_builtin(Sexpr* func, Sexpr* arg, Sexpr* env); Sexpr* eval(Sexpr* s, Sexpr* dict) { // non-null s @@ -39,7 +39,7 @@ Sexpr* eval(Sexpr* s, Sexpr* dict) { return curr; } -Sexpr* apply_builtin(Sexpr* func, Sexpr* arg) { +Sexpr* apply_builtin(Sexpr* func, Sexpr* arg, Sexpr* env) { if(func->type != BUILTIN) return from_nil(); // uhh this /should/ actually be impossible... uint8_t num_args = 0; @@ -59,5 +59,5 @@ Sexpr* apply_builtin(Sexpr* func, Sexpr* arg) { return ret; // what's left now: all the args needed are there, // just gotta dispatch to whatever handles the opcode evals - return dispatch(ret); + return dispatch(ret, env); }