summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/functest.pcdt9
-rw-r--r--examples/scopetest.pcdt2
-rw-r--r--src/eval.c19
3 files changed, 24 insertions, 6 deletions
diff --git a/examples/functest.pcdt b/examples/functest.pcdt
new file mode 100644
index 0000000..a76883a
--- /dev/null
+++ b/examples/functest.pcdt
@@ -0,0 +1,9 @@
+store(
+ (
+ print(running function;)
+ eq(arg0() arg1())
+ )
+ myFunc;
+)
+print(equality?;)
+print(myFunc(0; 0;))
diff --git a/examples/scopetest.pcdt b/examples/scopetest.pcdt
new file mode 100644
index 0000000..73a9d12
--- /dev/null
+++ b/examples/scopetest.pcdt
@@ -0,0 +1,2 @@
+store(print(hello;) myFunc;)
+myFunc(test;)
diff --git a/src/eval.c b/src/eval.c
index dffd289..c658502 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -30,7 +30,18 @@ sym_t* eval(sym_t* symbol, hashtable_t* parentScope) {
/* TODO: scope */
pair_t p = hashtable_get_pair_recurse(parentScope, (char*)symbol->name);
if (p.key != NULL) {
- returnV = eval((sym_t*)p.value, newScope);
+ sym_t* nextSym = (sym_t*)p.value;
+ /* add params */
+ for (int i = 0; i < symbol->argCount; i++) {
+ char* keyName = malloc(6 * sizeof(char));
+ strcpy(keyName, "arg");
+ char index[3];
+ snprintf(index, 3, "%d", i);
+ strcat(keyName, index);
+ pair_t argPair = init_pair(keyName, eval(symbol->args[i], parentScope));
+ hashtable_add_pair(newScope, argPair);
+ }
+ returnV = eval(nextSym, newScope);
}
else {
printf("no matching pair in hashtable\n");
@@ -61,12 +72,8 @@ sym_t* try_eval_internal(sym_t* symbol, hashtable_t* symbolScope) {
exec_all(symbol->args, symbol->argCount - 1, symbolScope);
return eval(symbol->args[symbol->argCount - 1], symbolScope);
}
- else if (hash == get_hash("arg")) {
- /* get positional arg in current scope */
- return NULL;
- }
+ /* TODO: rename storel */
else if (hash == get_hash("store")) {
- /* TODO: scope */
/* first arg is value, remaining args are names */
/* TODO: recursion for multiple pairs */
char* k = symtos(eval(symbol->args[1], symbolScope));