diff options
| author | Joel Martin <github@martintribe.org> | 2014-11-15 23:51:59 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-01-09 16:16:47 -0600 |
| commit | aaba249304b184e12e2445ab22d66df1f39a51a5 (patch) | |
| tree | a3c7b1a0d683ef73ec030a390eca2922bfc9bc54 /cs | |
| parent | ee7cd5859e56423983f025088c8cef36b7ed09dd (diff) | |
| download | mal-aaba249304b184e12e2445ab22d66df1f39a51a5.tar.gz mal-aaba249304b184e12e2445ab22d66df1f39a51a5.zip | |
VB.Net, C#: fix cmd line arg handling with --raw
Diffstat (limited to 'cs')
| -rw-r--r-- | cs/core.cs | 5 | ||||
| -rw-r--r-- | cs/step2_eval.cs | 2 | ||||
| -rw-r--r-- | cs/step6_file.cs | 12 | ||||
| -rw-r--r-- | cs/step7_quote.cs | 12 | ||||
| -rw-r--r-- | cs/step8_macros.cs | 12 | ||||
| -rw-r--r-- | cs/step9_try.cs | 14 | ||||
| -rw-r--r-- | cs/stepA_interop.cs | 12 | ||||
| -rw-r--r-- | cs/types.cs | 10 |
8 files changed, 38 insertions, 41 deletions
@@ -38,8 +38,7 @@ namespace Mal { // Number functions static MalFunc time_ms = new MalFunc( - a => new MalInt((int)( - DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond))); + a => new MalInt(DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond)); // String functions static public MalFunc pr_str = new MalFunc( @@ -160,7 +159,7 @@ namespace Mal { }); static MalFunc nth = new MalFunc( - a => ((MalList)a[0])[ ((MalInt)a[1]).getValue() ]); + a => ((MalList)a[0])[ (int)((MalInt)a[1]).getValue() ]); static MalFunc first = new MalFunc( a => ((MalList)a[0])[0]); diff --git a/cs/step2_eval.cs b/cs/step2_eval.cs index 0c7db69..1e3866e 100644 --- a/cs/step2_eval.cs +++ b/cs/step2_eval.cs @@ -12,7 +12,7 @@ using MalHashMap = Mal.types.MalHashMap; using MalFunc = Mal.types.MalFunc; namespace Mal { - class step1_eval { + class step2_eval { // read static MalVal READ(string str) { return reader.read_str(str); diff --git a/cs/step6_file.cs b/cs/step6_file.cs index ab7a426..c885922 100644 --- a/cs/step6_file.cs +++ b/cs/step6_file.cs @@ -141,8 +141,13 @@ namespace Mal { repl_env.set(entry.Key, entry.Value); } repl_env.set("eval", new MalFunc(a => EVAL(a[0], repl_env))); + int fileIdx = 1; + if (args.Length > 0 && args[0] == "--raw") { + Mal.readline.mode = Mal.readline.Mode.Raw; + fileIdx = 2; + } MalList _argv = new MalList(); - for (int i=1; i < args.Length; i++) { + for (int i=fileIdx; i < args.Length; i++) { _argv.conj_BANG(new MalString(args[i])); } repl_env.set("*ARGV*", _argv); @@ -151,11 +156,6 @@ namespace Mal { RE("(def! not (fn* (a) (if a false true)))"); RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); - int fileIdx = 0; - if (args.Length > 0 && args[0] == "--raw") { - Mal.readline.mode = Mal.readline.Mode.Raw; - fileIdx = 1; - } if (args.Length > fileIdx) { RE("(load-file \"" + args[fileIdx] + "\")"); return; diff --git a/cs/step7_quote.cs b/cs/step7_quote.cs index 7c4cf11..c25498f 100644 --- a/cs/step7_quote.cs +++ b/cs/step7_quote.cs @@ -173,8 +173,13 @@ namespace Mal { repl_env.set(entry.Key, entry.Value); } repl_env.set("eval", new MalFunc(a => EVAL(a[0], repl_env))); + int fileIdx = 1; + if (args.Length > 0 && args[0] == "--raw") { + Mal.readline.mode = Mal.readline.Mode.Raw; + fileIdx = 2; + } MalList _argv = new MalList(); - for (int i=1; i < args.Length; i++) { + for (int i=fileIdx; i < args.Length; i++) { _argv.conj_BANG(new MalString(args[i])); } repl_env.set("*ARGV*", _argv); @@ -183,11 +188,6 @@ namespace Mal { RE("(def! not (fn* (a) (if a false true)))"); RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); - int fileIdx = 0; - if (args.Length > 0 && args[0] == "--raw") { - Mal.readline.mode = Mal.readline.Mode.Raw; - fileIdx = 1; - } if (args.Length > fileIdx) { RE("(load-file \"" + args[fileIdx] + "\")"); return; diff --git a/cs/step8_macros.cs b/cs/step8_macros.cs index 1aaa1fa..ccc0242 100644 --- a/cs/step8_macros.cs +++ b/cs/step8_macros.cs @@ -210,8 +210,13 @@ namespace Mal { repl_env.set(entry.Key, entry.Value); } repl_env.set("eval", new MalFunc(a => EVAL(a[0], repl_env))); + int fileIdx = 1; + if (args.Length > 0 && args[0] == "--raw") { + Mal.readline.mode = Mal.readline.Mode.Raw; + fileIdx = 2; + } MalList _argv = new MalList(); - for (int i=1; i < args.Length; i++) { + for (int i=fileIdx; i < args.Length; i++) { _argv.conj_BANG(new MalString(args[i])); } repl_env.set("*ARGV*", _argv); @@ -222,11 +227,6 @@ namespace Mal { RE("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))"); RE("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"); - int fileIdx = 0; - if (args.Length > 0 && args[0] == "--raw") { - Mal.readline.mode = Mal.readline.Mode.Raw; - fileIdx = 1; - } if (args.Length > fileIdx) { RE("(load-file \"" + args[fileIdx] + "\")"); return; diff --git a/cs/step9_try.cs b/cs/step9_try.cs index e5da607..1d724d1 100644 --- a/cs/step9_try.cs +++ b/cs/step9_try.cs @@ -231,31 +231,29 @@ namespace Mal { repl_env.set(entry.Key, entry.Value); } repl_env.set("eval", new MalFunc(a => EVAL(a[0], repl_env))); + int fileIdx = 1; + if (args.Length > 0 && args[0] == "--raw") { + Mal.readline.mode = Mal.readline.Mode.Raw; + fileIdx = 2; + } MalList _argv = new MalList(); - for (int i=1; i < args.Length; i++) { + for (int i=fileIdx; i < args.Length; i++) { _argv.conj_BANG(new MalString(args[i])); } repl_env.set("*ARGV*", _argv); // core.mal: defined using the language itself - RE("(def! *host-language* \"c#\")"); RE("(def! not (fn* (a) (if a false true)))"); RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); RE("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))"); RE("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"); - int fileIdx = 0; - if (args.Length > 0 && args[0] == "--raw") { - Mal.readline.mode = Mal.readline.Mode.Raw; - fileIdx = 1; - } if (args.Length > fileIdx) { RE("(load-file \"" + args[fileIdx] + "\")"); return; } // repl loop - RE("(println (str \"Mal [\" *host-language* \"]\"))"); while (true) { string line; try { diff --git a/cs/stepA_interop.cs b/cs/stepA_interop.cs index d84eca2..f51f824 100644 --- a/cs/stepA_interop.cs +++ b/cs/stepA_interop.cs @@ -231,8 +231,13 @@ namespace Mal { repl_env.set(entry.Key, entry.Value); } repl_env.set("eval", new MalFunc(a => EVAL(a[0], repl_env))); + int fileIdx = 1; + if (args.Length > 0 && args[0] == "--raw") { + Mal.readline.mode = Mal.readline.Mode.Raw; + fileIdx = 2; + } MalList _argv = new MalList(); - for (int i=1; i < args.Length; i++) { + for (int i=fileIdx; i < args.Length; i++) { _argv.conj_BANG(new MalString(args[i])); } repl_env.set("*ARGV*", _argv); @@ -244,11 +249,6 @@ namespace Mal { RE("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))"); RE("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"); - int fileIdx = 0; - if (args.Length > 0 && args[0] == "--raw") { - Mal.readline.mode = Mal.readline.Mode.Raw; - fileIdx = 1; - } if (args.Length > fileIdx) { RE("(load-file \"" + args[fileIdx] + "\")"); return; diff --git a/cs/types.cs b/cs/types.cs index fd0b9fb..c2f46c9 100644 --- a/cs/types.cs +++ b/cs/types.cs @@ -98,11 +98,11 @@ namespace Mal { static public MalConstant False = new MalConstant("false"); public class MalInt : MalVal { - int value; - public MalInt(int v) { value = v; } + Int64 value; + public MalInt(Int64 v) { value = v; } public new MalInt copy() { return this; } - public int getValue() { return value; } + public Int64 getValue() { return value; } public override string ToString() { return value.ToString(); } @@ -205,10 +205,10 @@ namespace Mal { public int size() { return value.Count; } public MalVal nth(int idx) { - return value.Count > 0 ? value[idx] : Nil; + return value.Count > idx ? value[idx] : Nil; } public MalVal this[int idx] { - get { return value.Count > 0 ? value[idx] : Nil; } + get { return value.Count > idx ? value[idx] : Nil; } } public MalList rest() { if (size() > 0) { |
