diff options
| author | Joel Martin <github@martintribe.org> | 2014-04-16 23:57:50 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-04-16 23:57:50 -0500 |
| commit | 8cb5cda46cf3aef847ae3926dc53a5e5f87fe261 (patch) | |
| tree | 13e5b2878f19ee24272ead8a92a9cb84b33ad0e5 /c/step3_env.c | |
| parent | a05f7822b10ed4cdd61ed8384299a003baf1c1c6 (diff) | |
| download | mal-8cb5cda46cf3aef847ae3926dc53a5e5f87fe261.tar.gz mal-8cb5cda46cf3aef847ae3926dc53a5e5f87fe261.zip | |
All: move some fns to core. Major cleanup.
- Don't import/require core until step4.
- Define cond/or macros from step8
Diffstat (limited to 'c/step3_env.c')
| -rw-r--r-- | c/step3_env.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/c/step3_env.c b/c/step3_env.c index 4abf4d6..7c36b38 100644 --- a/c/step3_env.c +++ b/c/step3_env.c @@ -1,10 +1,10 @@ #include <stdlib.h> #include <stdio.h> #include <unistd.h> + #include "types.h" #include "readline.h" #include "reader.h" -#include "core.h" // Declarations MalVal *EVAL(MalVal *ast, Env *env); @@ -53,7 +53,7 @@ MalVal *eval_ast(MalVal *ast, Env *env) { MalVal *new_val = EVAL((MalVal *)value, env); g_array_append_val(seq->val.array, new_val); } - return hash_map(seq); + return _hash_map(seq); } else { //g_print("EVAL scalar: %s\n", _pr_str(ast,1)); return ast; @@ -61,8 +61,8 @@ MalVal *eval_ast(MalVal *ast, Env *env) { } MalVal *EVAL(MalVal *ast, Env *env) { - //g_print("EVAL: %s\n", _pr_str(ast,1)); if (!ast || mal_error) return NULL; + //g_print("EVAL: %s\n", _pr_str(ast,1)); if (ast->type != MAL_LIST) { return eval_ast(ast, env); } @@ -102,7 +102,7 @@ MalVal *EVAL(MalVal *ast, Env *env) { //g_print("eval apply\n"); MalVal *el = eval_ast(ast, env); if (!el || mal_error) { return NULL; } - MalVal *(*f)(void *, void*) = (MalVal *(*)(void*, void*))first(el); + MalVal *(*f)(void *, void*) = (MalVal *(*)(void*, void*))_first(el); return f(_nth(el, 1), _nth(el, 2)); } } @@ -138,6 +138,11 @@ Env *repl_env; void init_repl_env() { repl_env = new_env(NULL, NULL, NULL); + WRAP_INTEGER_OP(plus,+) + WRAP_INTEGER_OP(minus,-) + WRAP_INTEGER_OP(multiply,*) + WRAP_INTEGER_OP(divide,/) + env_set(repl_env, "+", (MalVal *)int_plus); env_set(repl_env, "-", (MalVal *)int_minus); env_set(repl_env, "*", (MalVal *)int_multiply); |
