From 60d6022d464455c8bd117b675e8273c9f71350ba Mon Sep 17 00:00:00 2001 From: = <=> Date: Sun, 10 May 2020 19:15:53 +0100 Subject: [PATCH] Multi-statements in cmdline args. Added tests. Commented out unnecessary deleteEnv() in main(). Was segfaulting. May be a bigger bug, there. --- src/pebblisp.c | 23 ++++++++++------------- src/tests.sh | 3 +++ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/pebblisp.c b/src/pebblisp.c index d4c7e04..7c143f6 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -350,13 +350,11 @@ Object parseEval(const char *input, struct Environment *env) } } #endif - // int statements = 0; int i = 0; int parens = 0; Object obj; struct Slice *tok = tokens; while(tok[i].text != NULL) { - //printf("tok[%d].text[0]: '%c'\n", i, tok[i].text[0]); if(tok[i].text[0] == '(') { parens++; } else if(tok[i].text[0] == ')') { @@ -366,18 +364,11 @@ Object parseEval(const char *input, struct Environment *env) tok = &tok[i + 1]; i = -1; obj = eval(&parsed, env); - //printf("End statement:\n"); - //printObj(&obj); } } i++; } - // for(int i = 0; i < statements; i++) { - // Object parsed = parse(tokens).obj; - // } - // Object parsed = parse(tokens).obj; free(tokens); - // return eval(&parsed, env); return obj; } @@ -398,9 +389,15 @@ int repl(struct Environment *env) int main(int argc, const char* argv[]) { struct Environment env = defaultEnv(); - if(argc == 2) { - Object r = parseEval(argv[1], &env); - printAndClean(&r); + if(argc >= 2) { + Object r = numberObject(0); + for(int i = 1; i < argc; i++) { + // cleanObject(&r); + r = parseEval(argv[i], &env); + } + printObj(&r); + // Object r = parseEval(argv[1], &env); + // printAndClean(&r); } else { #ifndef NO_REPL repl(&env); @@ -411,6 +408,6 @@ int main(int argc, const char* argv[]) printAndClean(&r); #endif } - deleteEnv(&env); + // deleteEnv(&env); } #endif diff --git a/src/tests.sh b/src/tests.sh index 3ff83e9..3267f16 100755 --- a/src/tests.sh +++ b/src/tests.sh @@ -54,6 +54,9 @@ check "WideSpac" "( + 1093 102852 )" "103945" check "VWidwSpc" " ( + 1093 102852 ) " "103945" echo "" check "DemoFunc" "(spent 68)" "Tip: \$13.60" +echo "" +check "MultStmt" "(def yee (fn (a) (* 10 a))) (yee 5)" "50" +check "DefinMap" "(def yee (fn (a) (* 10 a))) (map yee (5 10 2 (+ 12 0)))" "( 50 100 20 120 )" echo ""