From 86b689f3d7111a9fa13da389a30f3dfdf877d1a4 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Sat, 19 Apr 2014 13:04:09 -0500 Subject: All: *ARGV* and *host-language*. Misc syncing/fixes. --- cs/Makefile | 2 +- cs/step0_repl.cs | 2 +- cs/step1_read_print.cs | 2 +- cs/step2_eval.cs | 2 +- cs/step3_env.cs | 4 +++- cs/step4_if_fn_do.cs | 4 +++- cs/step5_tco.cs | 4 +++- cs/step6_file.cs | 14 ++++++++++---- cs/step7_quote.cs | 13 +++++++++---- cs/step8_macros.cs | 13 +++++++++---- cs/stepA_more.cs | 14 ++++++++++---- 11 files changed, 51 insertions(+), 23 deletions(-) (limited to 'cs') diff --git a/cs/Makefile b/cs/Makefile index f8aefcc..b7eb023 100644 --- a/cs/Makefile +++ b/cs/Makefile @@ -34,7 +34,7 @@ mal.dll: $(LIB_SRCS) mcs $(FLAGS) -r:mal.dll $< clean: - rm -f *.dll *.exe *.mbd + rm -f *.dll *.exe *.mdb .PHONY: stats tests $(TESTS) diff --git a/cs/step0_repl.cs b/cs/step0_repl.cs index de7a6de..616e154 100644 --- a/cs/step0_repl.cs +++ b/cs/step0_repl.cs @@ -19,7 +19,7 @@ namespace Mal { return exp; } - // REPL + // repl static string RE(string env, string str) { return EVAL(READ(str), env); } diff --git a/cs/step1_read_print.cs b/cs/step1_read_print.cs index 62cd7ad..1b427c8 100644 --- a/cs/step1_read_print.cs +++ b/cs/step1_read_print.cs @@ -20,7 +20,7 @@ namespace Mal { return printer._pr_str(exp, true); } - // REPL + // repl static MalVal RE(string env, string str) { return EVAL(READ(str), env); } diff --git a/cs/step2_eval.cs b/cs/step2_eval.cs index dc467de..1a95a81 100644 --- a/cs/step2_eval.cs +++ b/cs/step2_eval.cs @@ -69,7 +69,7 @@ namespace Mal { return printer._pr_str(exp, true); } - // REPL + // repl static MalVal RE(Dictionary env, string str) { return EVAL(READ(str), env); } diff --git a/cs/step3_env.cs b/cs/step3_env.cs index ba859eb..2be7992 100644 --- a/cs/step3_env.cs +++ b/cs/step3_env.cs @@ -92,7 +92,7 @@ namespace Mal { return printer._pr_str(exp, true); } - // REPL + // repl static MalVal RE(Env env, string str) { return EVAL(READ(str), env); } @@ -119,6 +119,8 @@ namespace Mal { if (args.Length > 0 && args[0] == "--raw") { Mal.readline.mode = Mal.readline.Mode.Raw; } + + // repl loop while (true) { string line; try { diff --git a/cs/step4_if_fn_do.cs b/cs/step4_if_fn_do.cs index 2383c31..659fc18 100644 --- a/cs/step4_if_fn_do.cs +++ b/cs/step4_if_fn_do.cs @@ -116,7 +116,7 @@ namespace Mal { return printer._pr_str(exp, true); } - // REPL + // repl static MalVal RE(Env env, string str) { return EVAL(READ(str), env); } @@ -136,6 +136,8 @@ namespace Mal { if (args.Length > 0 && args[0] == "--raw") { Mal.readline.mode = Mal.readline.Mode.Raw; } + + // repl loop while (true) { string line; try { diff --git a/cs/step5_tco.cs b/cs/step5_tco.cs index b04d16e..95df860 100644 --- a/cs/step5_tco.cs +++ b/cs/step5_tco.cs @@ -128,7 +128,7 @@ namespace Mal { return printer._pr_str(exp, true); } - // REPL + // repl static MalVal RE(Env env, string str) { return EVAL(READ(str), env); } @@ -148,6 +148,8 @@ namespace Mal { if (args.Length > 0 && args[0] == "--raw") { Mal.readline.mode = Mal.readline.Mode.Raw; } + + // repl loop while (true) { string line; try { diff --git a/cs/step6_file.cs b/cs/step6_file.cs index cb2157e..db1a7b2 100644 --- a/cs/step6_file.cs +++ b/cs/step6_file.cs @@ -4,6 +4,7 @@ using System.Collections; using System.Collections.Generic; using Mal; using MalVal = Mal.types.MalVal; +using MalString = Mal.types.MalString; using MalSymbol = Mal.types.MalSymbol; using MalInteger = Mal.types.MalInteger; using MalList = Mal.types.MalList; @@ -128,7 +129,7 @@ namespace Mal { return printer._pr_str(exp, true); } - // REPL + // repl static MalVal RE(Env env, string str) { return EVAL(READ(str), env); } @@ -142,6 +143,11 @@ namespace Mal { repl_env.set(entry.Key, entry.Value); } repl_env.set("eval", new MalFunction(a => EVAL(a[0], repl_env))); + MalList _argv = new MalList(); + for (int i=1; i < args.Length; i++) { + _argv.conj_BANG(new MalString(args[i])); + } + repl_env.set("*ARGV*", _argv); // core.mal: defined using the language itself RE(repl_env, "(def! not (fn* (a) (if a false true)))"); @@ -153,11 +159,11 @@ namespace Mal { fileIdx = 1; } if (args.Length > fileIdx) { - for(int i=fileIdx; i EVAL(a[0], repl_env))); + MalList _argv = new MalList(); + for (int i=1; i < args.Length; i++) { + _argv.conj_BANG(new MalString(args[i])); + } + repl_env.set("*ARGV*", _argv); // core.mal: defined using the language itself RE(repl_env, "(def! not (fn* (a) (if a false true)))"); @@ -185,11 +190,11 @@ namespace Mal { fileIdx = 1; } if (args.Length > fileIdx) { - for(int i=fileIdx; i EVAL(a[0], repl_env))); + MalList _argv = new MalList(); + for (int i=1; i < args.Length; i++) { + _argv.conj_BANG(new MalString(args[i])); + } + repl_env.set("*ARGV*", _argv); // core.mal: defined using the language itself RE(repl_env, "(def! not (fn* (a) (if a false true)))"); @@ -224,11 +229,11 @@ namespace Mal { fileIdx = 1; } if (args.Length > fileIdx) { - for(int i=fileIdx; i EVAL(a[0], repl_env))); + MalList _argv = new MalList(); + for (int i=1; i < args.Length; i++) { + _argv.conj_BANG(new MalString(args[i])); + } + repl_env.set("*ARGV*", _argv); // core.mal: defined using the language itself RE(repl_env, "(def! *host-language* \"c#\")"); @@ -246,11 +251,12 @@ namespace Mal { fileIdx = 1; } if (args.Length > fileIdx) { - for(int i=fileIdx; i