From: Elijah Cohen Date: Thu, 25 Jul 2024 22:03:35 +0000 (-0500) Subject: added repl that doesn't work X-Git-Url: https://git.eli173.com/?a=commitdiff_plain;h=43cd99a380d9cdc00f2a0f39824b3444a5b0db2e;p=klapaucius added repl that doesn't work --- diff --git a/.gitignore b/.gitignore index e4e5f6c..b8678e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -*~ \ No newline at end of file +*~ +/src/linenoise.c +/src/linenoise.h diff --git a/src/repl.c b/src/repl.c index e64cf3f..94ebb17 100644 --- a/src/repl.c +++ b/src/repl.c @@ -1,20 +1,19 @@ #include +#include + +#include "linenoise.h" #include "types.h" #include "eval.h" #include "dict.h" #include "parser.h" #include "builtins.h" +#include "sexpr.h" -Sexpr* stepl(char* str, Sexpr* env) { - Sexpr* toeval = parse(str); - -} - int main(int argc, char** argv) { printf("makefile functional lol\n"); @@ -22,7 +21,15 @@ int main(int argc, char** argv) { load_env(env); // now do the loop, right? char* input = NULL; - - + while(1) { + input = linenoise("> "); + if(input == NULL) + return 0; + linenoiseHistoryAdd(input); + Sexpr* in = parse(input); + Sexpr* out = eval(in, env); + printf(" - %s\n", sprint_sexpr(out)); + linenoiseFree(input); + } return 0; } diff --git a/src/sexpr.c b/src/sexpr.c index e8e00e2..14e7fdb 100644 --- a/src/sexpr.c +++ b/src/sexpr.c @@ -113,6 +113,7 @@ char* sprint_sexpr(Sexpr* s) { strcpy(out, s->value.s); return out; } + /* else if(s->type == FUN) { out = malloc(6*sizeof(char)); strcpy(out, ""); @@ -123,6 +124,7 @@ char* sprint_sexpr(Sexpr* s) { strcpy(out, ""); return out; } + */ else if(s->type == UINT) { nbytes = snprintf(NULL, 0, "%" PRIu64 "", s->value.u) + 1; out = malloc(nbytes*sizeof(char)); diff --git a/src/types.h b/src/types.h index 26f0336..d1e30c4 100644 --- a/src/types.h +++ b/src/types.h @@ -10,11 +10,10 @@ typedef char* Symbol_t; typedef void* Nil_t; typedef void* Truth_t; -//typedef uint64_t Builtin_t; typedef enum Sexpr_Type { - UINT, SYM, BUILTIN, NIL, T, CONS, FEXP, FUN -} Sexpr_Type; // to be used rarely, mainly only in eval i think + UINT, SYM, BUILTIN, NIL, T, CONS +} Sexpr_Type; typedef struct Cons { struct Sexpr* car; @@ -26,20 +25,10 @@ typedef struct Builtin { uint64_t opcode; } Builtin_t; -typedef struct Closure { - uint64_t opcode; - uint64_t num_args; - uint64_t len_args; - struct Sexpr* arglist; -} Closure_t; -typedef Closure_t Fexpr_t; -typedef Closure_t Fun_t; typedef struct Sexpr { Sexpr_Type type; union { - Fexpr_t x; - Fun_t f; uint64_t u; Builtin_t b; Symbol_t s;