From ad346786382dacd0bf592f82e5e51ae05617cf0e Mon Sep 17 00:00:00 2001 From: Elijah Cohen Date: Wed, 30 Oct 2024 13:51:11 -0500 Subject: [PATCH] added unquote which i don't know what it does yet... --- demos.kl | 2 +- src/builtins/core.c | 14 ++++++++++++++ src/builtins/core.h | 6 ++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/demos.kl b/demos.kl index 237a576..a1da106 100644 --- a/demos.kl +++ b/demos.kl @@ -17,4 +17,4 @@ (def map (B (B reverse) (B (B (Z (B (S (S (B (eq nil) (2 cdr)) (B car cdr))) (C B (S (B cons car) (Phi cons (Phi cons (S car (B (B car cdr) cdr)) (B car cdr)) (3 cdr))))))) (C (B B cons) (cons nil))))) -(def fold (B (S (C (C (eq nil) nil) (Z (B (S (S (B (eq nil) (B cdr cdr)) (B car cdr))) (C B (S (B cons car) (Phi cons (S (S car (B car cdr)) (B car (2 cdr))) (3 cdr)))))))) cons)) \ No newline at end of file +(def fold (B (S (C (C (eq nil) nil) (Z (B (S (S (B (eq nil) (B cdr cdr)) (B car cdr))) (C B (S (B cons car) (Phi cons (S (S car (B car cdr)) (B car (2 cdr))) (3 cdr)))))))) cons)) diff --git a/src/builtins/core.c b/src/builtins/core.c index 8d2aefc..804c7cf 100644 --- a/src/builtins/core.c +++ b/src/builtins/core.c @@ -162,6 +162,17 @@ Sexpr* c_rest(Sexpr* b, Sexpr* rest, Sexpr* env) { return cons(first_arg, cons(from_quote(newrest), from_nil())); } +Sexpr* c_unquote(Sexpr* b, Sexpr* rest, Sexpr* env) { + // now the question here is, is it necessarily wrong + // to do this to non-quotes? + // this... needs an eval... + if(CORE_UNQUOTE_ARGS != u64_get_num_args(b)) + return cons(b, rest); + Sexpr* first_arg = car(b->value.b.args); + Sexpr* newthing = eval(clone(unquote(first_arg)), env); + sexpr_free(b); + return cons(newthing, rest); +} Sexpr* c_applyn(Sexpr* b, Sexpr* rest, Sexpr* env) { // possible commentary for the future: @@ -234,6 +245,8 @@ Sexpr* x_core_dispatch(Sexpr* b, Sexpr* rest, Sexpr* env) { return c_atom(b, rest, env); case CORE_REST: return c_rest(b, rest, env); + case CORE_UNQUOTE: + return c_unquote(b, rest, env); case CORE_APPLYN: return c_applyn(b, rest, env); case CORE_DEF: @@ -257,6 +270,7 @@ Sexpr* load_core_env(Sexpr* env) { load_builtin(CORE_NOT_STR, (CORE_PREFIX << 8) | CORE_NOT, env); load_builtin(CORE_ATOM_STR, (CORE_PREFIX << 8) | CORE_ATOM, env); load_builtin(CORE_REST_STR, (CORE_PREFIX << 8) | CORE_REST, env); + load_builtin(CORE_UNQUOTE_STR, (CORE_PREFIX << 8) | CORE_UNQUOTE, env); load_builtin(CORE_DEF_STR, (CORE_PREFIX << 8) | CORE_DEF, env); load_builtin(CORE_EXIT_STR, (CORE_PREFIX << 8) | CORE_EXIT, env); diff --git a/src/builtins/core.h b/src/builtins/core.h index 401aa6f..249d9f8 100644 --- a/src/builtins/core.h +++ b/src/builtins/core.h @@ -35,8 +35,10 @@ #define CORE_REST 0x08 #define CORE_REST_ARGS 2 #define CORE_REST_STR "rest" - -#define CORE_APPLYN 0x0f +#define CORE_UNQUOTE 0x09 +#define CORE_UNQUOTE_ARGS 1 +#define CORE_UNQUOTE_STR "unquote" +#define CORE_APPLYN 0x0a #define CORE_APPLYN_ARGS 3 #define CORE_APPLYN_STR "applyn" -- 2.39.2