diff options
| author | Joel Martin <github@martintribe.org> | 2014-10-09 23:48:47 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-01-06 21:57:24 -0600 |
| commit | 01c9731649a7ed97fad0bdeac9cb75b7323c0ad6 (patch) | |
| tree | d6d00e574c489b206ddf78adc12c3d535bab7440 /c | |
| parent | 1771ab50b87c745181e4e30f94b63e3f23d33dac (diff) | |
| download | mal-01c9731649a7ed97fad0bdeac9cb75b7323c0ad6.tar.gz mal-01c9731649a7ed97fad0bdeac9cb75b7323c0ad6.zip | |
All: swap step9,A. Fixes for bash, C, perl.
step9_interop -> stepA_interop
stepA_more -> step9_try
C: fix glib headers
bash: behavior change of declare -A and pattern replacement.
perl: squelch new 5.18 warnings related to switch/given statement.
Also, include some in-progress interop related files.
Diffstat (limited to 'c')
| -rw-r--r-- | c/Makefile | 4 | ||||
| -rw-r--r-- | c/reader.c | 5 | ||||
| -rw-r--r-- | c/step9_try.c (renamed from c/step9_interop.c) | 26 | ||||
| -rw-r--r-- | c/stepA_interop.c (renamed from c/stepA_more.c) | 0 | ||||
| -rw-r--r-- | c/tests/stepA_interop.mal (renamed from c/tests/step9_interop.mal) | 0 |
5 files changed, 27 insertions, 8 deletions
@@ -9,7 +9,7 @@ TESTS = SOURCES_BASE = readline.h readline.c types.h types.c \ reader.h reader.c printer.h printer.c \ interop.h interop.c -SOURCES_LISP = env.c core.h core.c stepA_more.c +SOURCES_LISP = env.c core.h core.c stepA_interop.c SOURCES = $(SOURCES_BASE) $(SOURCES_LISP) @@ -17,7 +17,7 @@ SOURCES = $(SOURCES_BASE) $(SOURCES_LISP) SRCS = step0_repl.c step1_read_print.c step2_eval.c step3_env.c \ step4_if_fn_do.c step5_tco.c step6_file.c step7_quote.c \ - step8_macros.c step9_interop.c stepA_more.c + step8_macros.c step9_try.c stepA_interop.c OBJS = $(SRCS:%.c=%.o) BINS = $(OBJS:%.o=%) OTHER_OBJS = types.o readline.o reader.o printer.o env.o core.o interop.o @@ -2,8 +2,9 @@ #include <stdio.h> #include <string.h> -#include <glib/gregex.h> -#include <glib-object.h> +//#include <glib/gregex.h> +//#include <glib-object.h> +#include <glib.h> #include "types.h" #include "reader.h" diff --git a/c/step9_interop.c b/c/step9_try.c index 6ba594e..395a7f0 100644 --- a/c/step9_interop.c +++ b/c/step9_try.c @@ -181,10 +181,26 @@ MalVal *EVAL(MalVal *ast, Env *env) { MalVal *a1 = _nth(ast, 1); return macroexpand(a1, env); } else if ((a0->type & MAL_SYMBOL) && - strcmp(".", a0->val.string) == 0) { - //g_print("eval apply .\n"); - MalVal *el = eval_ast(_slice(ast, 1, _count(ast)), env); - return invoke_native(el); + strcmp("try*", a0->val.string) == 0) { + //g_print("eval apply try*\n"); + MalVal *a1 = _nth(ast, 1); + MalVal *a2 = _nth(ast, 2); + MalVal *res = EVAL(a1, env); + if (!mal_error) { return res; } + MalVal *a20 = _nth(a2, 0); + if (strcmp("catch*", a20->val.string) == 0) { + MalVal *a21 = _nth(a2, 1); + MalVal *a22 = _nth(a2, 2); + Env *catch_env = new_env(env, + _listX(1, a21), + _listX(1, mal_error)); + //malval_free(mal_error); + mal_error = NULL; + res = EVAL(a22, catch_env); + return res; + } else { + return &mal_nil; + } } else if ((a0->type & MAL_SYMBOL) && strcmp("do", a0->val.string) == 0) { //g_print("eval apply do\n"); @@ -287,6 +303,7 @@ void init_repl_env(int argc, char *argv[]) { env_set(repl_env, "*ARGV*", _argv); // core.mal: defined using the language itself + RE(repl_env, "", "(def! *host-language* \"c\")"); RE(repl_env, "", "(def! not (fn* (a) (if a false true)))"); RE(repl_env, "", "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); @@ -311,6 +328,7 @@ int main(int argc, char *argv[]) } // repl loop + RE(repl_env, "", "(println (str \"Mal [\" *host-language* \"]\"))"); for(;;) { exp = RE(repl_env, prompt, NULL); if (mal_error && strcmp("EOF", mal_error->val.string) == 0) { diff --git a/c/stepA_more.c b/c/stepA_interop.c index b4b7431..b4b7431 100644 --- a/c/stepA_more.c +++ b/c/stepA_interop.c diff --git a/c/tests/step9_interop.mal b/c/tests/stepA_interop.mal index 657e3e7..657e3e7 100644 --- a/c/tests/step9_interop.mal +++ b/c/tests/stepA_interop.mal |
