]> git.eli173.com Git - klapaucius/commitdiff
added repl that doesn't work
authorElijah Cohen <eli@eli173.com>
Thu, 25 Jul 2024 22:03:35 +0000 (17:03 -0500)
committerElijah Cohen <eli@eli173.com>
Thu, 25 Jul 2024 22:03:35 +0000 (17:03 -0500)
.gitignore
src/repl.c
src/sexpr.c
src/types.h

index e4e5f6c8b2deb54bf38312dd9e2f53489b60d6a6..b8678e10ecca680766057edad085ea879ea6a3ee 100644 (file)
@@ -1 +1,3 @@
-*~
\ No newline at end of file
+*~
+/src/linenoise.c
+/src/linenoise.h
index e64cf3f41faf42a93055253b3a28a0afe5ce1501..94ebb17b9a651fdfb36ea69f3335237434386ba4 100644 (file)
@@ -1,20 +1,19 @@
 
 
 #include <stdio.h>
+#include <histedit.h>
+
+#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;
 }
index e8e00e286dd535a8ac6376a730a43bb8236eb1e9..14e7fdb4ef596ae9179caf602bd982a2c12466f8 100644 (file)
@@ -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, "<fun>");
@@ -123,6 +124,7 @@ char* sprint_sexpr(Sexpr* s) {
                strcpy(out, "<fexp>");
                return out;
        }
+       */
        else if(s->type == UINT) {
                nbytes = snprintf(NULL, 0, "%" PRIu64 "", s->value.u) + 1;
                out = malloc(nbytes*sizeof(char));
index 26f033610eb5f8fa0e55efa72e21bbd819dcae15..d1e30c44281a028e53612cd0e64a4e9dd1c1a8ca 100644 (file)
 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;