changeset 183:37b01b114b50

also remove old code from bin/ sources
author Lewin Bormann <lbo@spheniscida.de>
date Sat, 28 Sep 2019 19:13:26 +0200
parents 8cd4314a144f
children 263256062455
files src/bin/repl.c src/bin/ylisp.c
diffstat 2 files changed, 1 insertions(+), 89 deletions(-) [+]
line wrap: on
line diff
--- a/src/bin/repl.c	Fri Sep 27 14:33:38 2019 +0200
+++ b/src/bin/repl.c	Sat Sep 28 19:13:26 2019 +0200
@@ -8,52 +8,6 @@
 #define bufsize 512
     char buf[bufsize];
 
-    yeval_state_t state;
-    state.call_stack = YVEC_NEW(NULL, 16, yexpr_t);
-    yvec_t* scope_stack = NULL;
-
-    while (1) {
-        ystr_t input = ystr_new(NULL), output = ystr_new(NULL),
-               error = ystr_new(NULL);
-        yexpr_t stmt = yexpr_new(), result;
-
-        fprintf(stdout, "() >> ");
-
-        if (NULL == fgets(buf, bufsize, stdin)) break;
-        input = ystr_new(buf);
-        if (0 == ystr_cmp_str(&input, "quit\n")) {
-            return 0;
-        }
-        if (!yparse_str(&input, &stmt, &error)) {
-            fprintf(stderr, "parse error: %s\n", ystr_str(&error));
-            goto cleanup_continue;
-        }
-        if (YEXPR_LIST != stmt.typ) {
-            fprintf(stderr, "bug: expression should be list!\n");
-            goto cleanup_continue;
-        }
-        ypreprocess_resolve_builtins(&stmt);
-        ypreprocess_refs_repl(&stmt, &scope_stack);
-
-        result = yeval_list_return_last(&state, &stmt.value.list, 0);
-
-        if (result.typ != YEXPR_UNDEF) {
-            output = yexpr_debug_str(&result);
-            fprintf(stdout, "%s\n", ystr_str(&output));
-        } else {
-            fputc('\n', stdout);
-        }
-
-    cleanup_continue:
-        ystr_destroy(&input);
-        ystr_destroy(&error);
-        ystr_destroy(&output);
-        yexpr_destroy(&result);
-        // stmt is not destroyed, values in it may be used later
-    }
-
-    yvec_destroy(&state.call_stack);
-
     return 0;
 #undef bufsize
 }
--- a/src/bin/ylisp.c	Fri Sep 27 14:33:38 2019 +0200
+++ b/src/bin/ylisp.c	Sat Sep 28 19:13:26 2019 +0200
@@ -5,52 +5,10 @@
 #include <src/preprocess.h>
 #include <src/eval.h>
 
-yexpr_t run(FILE* input, yeval_state_t* state, yvec_t** root) {
-    yexpr_t file = yexpr_new();
-    yexpr_t result = yexpr_new();
-    ystr_t error = ystr_new(NULL);
-    bool ok = yparse(input, &file, &error);
-    if (!ok) {
-        fprintf(stderr, "Parse error: %s\n", ystr_str(&error));
-        goto clean_all;
-    }
-    ypreprocess_resolve_builtins(&file);
-    ypreprocess_refs_repl(&file, root);
-    result = yeval_list_return_last(state, &file.value.list, 0);
-clean_all:
-    yexpr_destroy(&file);
-    ystr_destroy(&error);
+yexpr_t run(FILE* input) {
     return result;
 }
 
 int main(int argc, char** argv) {
-    yvec_t* root = NULL;
-    yeval_state_t state;
-    state.call_stack = YVEC_NEW(NULL, 16, yexpr_t);
-    yexpr_t result = yexpr_new();
-
-    if (argc == 1) {
-        result = run(stdin, &state, &root);
-    } else {
-        for (int i = 1; i < argc; i++) {
-            FILE* source = fopen(argv[i], "r");
-            if (source == NULL) {
-                err(1, "couldn't open file %s", argv[i]);
-            }
-            yexpr_t result = run(source, &state, &root);
-            yexpr_destroy(&result);
-            fclose(source);
-        }
-    }
-
-    yvec_destroy(YVEC_AT(root, 0, yvec_t));
-    free(*YVEC_AT(root, 0, void*));
-    yvec_destroy(root);
-    free(root);
-    yvec_destroy(&state.call_stack);
-    yexpr_destroy(&result);
-
-    yvalue_free_all();
-    yatom_free_all();
     return 0;
 }