summaryrefslogtreecommitdiff
path: root/src/eval.c
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2023-02-16 20:43:01 -0800
committerKai Stevenson <kai@kaistevenson.com>2023-02-16 20:43:01 -0800
commitcd4a69bf4b219e2f96de2d86d8ea41ab01d0f5e3 (patch)
treea1cf693053b31f8c3f0a0e1e63d70a9d4a785578 /src/eval.c
parentdeeb6aa4aa60e22190087a9615447e742c84a19c (diff)
added function parameters
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c19
1 files changed, 13 insertions, 6 deletions
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));