diff --git a/src/env.c b/src/env.c index 7851eed..05c950a 100644 --- a/src/env.c +++ b/src/env.c @@ -230,7 +230,7 @@ struct Environment defaultEnv() {"ap", &append}, {"pre", &prepend}, {"at", &at}, {"rest", &rest}, {"rev", &reverse}, {"isnum", &isNum}, {"isstr", &isString}, - {"prn", &print}, {"penv", &printEnvO}, + {"prn", &print}, {"penv", &printEnvO}, {"eval", &parseEvalO}, }; for(unsigned i = 0; i < sizeof(symFuncs)/sizeof(symFuncs[0]); i++) { diff --git a/src/object.c b/src/object.c index 0704ec1..4a2ecab 100644 --- a/src/object.c +++ b/src/object.c @@ -219,7 +219,8 @@ static const char *errorText[] = { "ONLY_ONE_ARGUMENT", "NOT_A_LIST", "SCRIPT_NOT_FOUND", - "NO_CLONE_SPECIFIED" + "NO_CLONE_SPECIFIED", + "CAN_ONLY_EVAL_STRINGS" }; /** diff --git a/src/object.h b/src/object.h index 2d178f0..68bbe55 100644 --- a/src/object.h +++ b/src/object.h @@ -39,7 +39,8 @@ enum errorCode { ONLY_ONE_ARGUMENT, NOT_A_LIST, SCRIPT_NOT_FOUND, - NO_CLONE_SPECIFIED + NO_CLONE_SPECIFIED, + CAN_ONLY_EVAL_STRINGS }; #define MALLOC_FLAG 64 diff --git a/src/pebblisp.c b/src/pebblisp.c index ff53fe3..94643f8 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -415,6 +415,14 @@ Object printEnvO(Object i1, Object i2, struct Environment *env) { return numberObject(0); } +Object parseEvalO(Object text, Object ignore, struct Environment *env) +{ + if(text.type != TYPE_STRING) { + return errorObject(CAN_ONLY_EVAL_STRINGS); + } + return parseEval(text.string, env); +} + void copySlice(char * dest, struct Slice *src) { if(!dest || !src) diff --git a/src/pebblisp.h b/src/pebblisp.h index 4d93924..539a8e7 100644 --- a/src/pebblisp.h +++ b/src/pebblisp.h @@ -60,5 +60,6 @@ Object isString(Object test, Object ignore, struct Environment *ignore2); Object print(Object p, Object ignore, struct Environment *ignore2); Object printEnvO(Object i1, Object i2, struct Environment *env); +Object parseEvalO(Object text, Object ignore, struct Environment *env); #endif diff --git a/src/tests.sh b/src/tests.sh index da22e14..d05cbca 100755 --- a/src/tests.sh +++ b/src/tests.sh @@ -177,6 +177,12 @@ check "BadParens4" ")))hey" "MISMATCHED_PARENS" check "BadParens5" "hey))(" "MISMATCHED_PARENS" endBlock +title "Eval" +check "BasicNumberEval" "(eval \"5\")" "5" +check "BasicOpEval" "(eval \"(+ 5 10)\")" "15" +check "MapFilter" "(eval \"(fil (< 50) (map sq (1 2 3 4 5 6 7 8 9 10 11 12)))\")" "( 64 81 100 121 144 )" +endBlock + # title "Environment" # check "EnvStressTestEarly" "(def a 1)(def b 20)(def c 'yee')(def d 'yeehunnid')(def e 3) (a)" "1" # check "EnvStressTestLate" "(def a 1)(def b 2)(def c 3)(def d 4)(def e 5)(def f 6)(def n 40) (n)" "40"