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 | |
| parent | ee7cd5859e56423983f025088c8cef36b7ed09dd (diff) | |
| download | mal-aaba249304b184e12e2445ab22d66df1f39a51a5.tar.gz mal-aaba249304b184e12e2445ab22d66df1f39a51a5.zip | |
VB.Net, C#: fix cmd line arg handling with --raw
| -rw-r--r-- | Makefile | 2 | ||||
| -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 | ||||
| -rw-r--r-- | vb/step0_repl.vb | 4 | ||||
| -rw-r--r-- | vb/step1_read_print.vb | 4 | ||||
| -rw-r--r-- | vb/step2_eval.vb | 4 | ||||
| -rw-r--r-- | vb/step3_env.vb | 4 | ||||
| -rw-r--r-- | vb/step4_if_fn_do.vb | 4 | ||||
| -rw-r--r-- | vb/step5_tco.vb | 4 | ||||
| -rw-r--r-- | vb/step6_file.vb | 16 | ||||
| -rw-r--r-- | vb/step7_quote.vb | 16 | ||||
| -rw-r--r-- | vb/step8_macros.vb | 16 | ||||
| -rw-r--r-- | vb/step9_try.vb | 14 | ||||
| -rw-r--r-- | vb/stepA_interop.vb | 12 |
20 files changed, 87 insertions, 92 deletions
@@ -89,7 +89,7 @@ vb_RUNSTEP = mono ../$(2) --raw $(3) # Extra options to pass to runtest.py cs_TEST_OPTS = --redirect -mal_TEST_OPTS = --start-timeout 60 --test-timeout 120 +mal_TEST_OPTS = --redirect --start-timeout 60 --test-timeout 120 vb_TEST_OPTS = --redirect @@ -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) { diff --git a/vb/step0_repl.vb b/vb/step0_repl.vb index ab8fe5e..f53f378 100644 --- a/vb/step0_repl.vb +++ b/vb/step0_repl.vb @@ -2,7 +2,7 @@ Imports System Imports Mal Namespace Mal - class step0_repl + Class step0_repl ' read Shared Function READ(str As String) As String Return str @@ -39,5 +39,5 @@ Namespace Mal Loop While True Return 0 End function - end class + End Class End Namespace diff --git a/vb/step1_read_print.vb b/vb/step1_read_print.vb index f8b47af..2734973 100644 --- a/vb/step1_read_print.vb +++ b/vb/step1_read_print.vb @@ -4,7 +4,7 @@ Imports Mal Imports MalVal = Mal.types.MalVal Namespace Mal - class step1_read_print + Class step1_read_print ' read Shared Function READ(str As String) As MalVal Return reader.read_str(str) @@ -55,5 +55,5 @@ Namespace Mal End Try Loop While True End function - end class + End Class End Namespace diff --git a/vb/step2_eval.vb b/vb/step2_eval.vb index 70bc5e3..6e45efe 100644 --- a/vb/step2_eval.vb +++ b/vb/step2_eval.vb @@ -11,7 +11,7 @@ Imports MalHashMap = Mal.types.MalHashMap Imports MalFunc = Mal.types.MalFunc Namespace Mal - class step2_eval + Class step2_eval ' read Shared Function READ(str As String) As MalVal Return reader.read_str(str) @@ -130,5 +130,5 @@ Namespace Mal End Try Loop While True End function - end class + End Class End Namespace diff --git a/vb/step3_env.vb b/vb/step3_env.vb index 2877ef1..5793fdb 100644 --- a/vb/step3_env.vb +++ b/vb/step3_env.vb @@ -12,7 +12,7 @@ Imports MalFunc = Mal.types.MalFunc Imports MalEnv = Mal.env.Env Namespace Mal - class step3_eval + Class step3_env ' read Shared Function READ(str As String) As MalVal Return reader.read_str(str) @@ -152,5 +152,5 @@ Namespace Mal End Try Loop While True End function - end class + End Class End Namespace diff --git a/vb/step4_if_fn_do.vb b/vb/step4_if_fn_do.vb index 2f5e16a..4cf8721 100644 --- a/vb/step4_if_fn_do.vb +++ b/vb/step4_if_fn_do.vb @@ -12,7 +12,7 @@ Imports MalFunc = Mal.types.MalFunc Imports MalEnv = Mal.env.Env Namespace Mal - class step4_if_fn_do + Class step4_if_fn_do ' read Shared Function READ(str As String) As MalVal Return reader.read_str(str) @@ -185,5 +185,5 @@ Namespace Mal End Try Loop While True End function - end class + End Class End Namespace diff --git a/vb/step5_tco.vb b/vb/step5_tco.vb index a379cf5..3c1f51c 100644 --- a/vb/step5_tco.vb +++ b/vb/step5_tco.vb @@ -12,7 +12,7 @@ Imports MalFunc = Mal.types.MalFunc Imports MalEnv = Mal.env.Env Namespace Mal - class step5_tco + Class step5_tco ' read Shared Function READ(str As String) As MalVal Return reader.read_str(str) @@ -194,5 +194,5 @@ Namespace Mal End Try Loop While True End function - end class + End Class End Namespace diff --git a/vb/step6_file.vb b/vb/step6_file.vb index 32cbe5b..58f8cd2 100644 --- a/vb/step6_file.vb +++ b/vb/step6_file.vb @@ -13,7 +13,7 @@ Imports MalFunc = Mal.types.MalFunc Imports MalEnv = Mal.env.Env Namespace Mal - class step6_file + Class step6_file ' read Shared Function READ(str As String) As MalVal Return reader.read_str(str) @@ -169,8 +169,13 @@ Namespace Mal repl_env.do_set(entry.Key, entry.Value) Next repl_env.do_set("eval", new MalFunc(AddressOf do_eval)) + Dim fileIdx As Integer = 1 + If args.Length > 1 AndAlso args(1) = "--raw" Then + Mal.readline.SetMode(Mal.readline.Modes.Raw) + fileIdx = 2 + End If Dim argv As New MalList() - For i As Integer = 0 To args.Length()-1 + For i As Integer = fileIdx+1 To args.Length-1 argv.conj_BANG(new MalString(args(i))) Next repl_env.do_set("*ARGV*", argv) @@ -179,11 +184,6 @@ Namespace Mal REP("(def! not (fn* (a) (if a false true)))") REP("(def! load-file (fn* (f) (eval (read-string (str ""(do "" (slurp f) "")"")))))") - Dim fileIdx As Integer = 1 - If args.Length > 1 AndAlso args(1) = "--raw" Then - Mal.readline.SetMode(Mal.readline.Modes.Raw) - fileIdx = 2 - End If If args.Length > fileIdx Then REP("(load-file """ & args(fileIdx) & """)") return 0 @@ -212,5 +212,5 @@ Namespace Mal End Try Loop While True End function - end class + End Class End Namespace diff --git a/vb/step7_quote.vb b/vb/step7_quote.vb index d3b6174..3f2d614 100644 --- a/vb/step7_quote.vb +++ b/vb/step7_quote.vb @@ -13,7 +13,7 @@ Imports MalFunc = Mal.types.MalFunc Imports MalEnv = Mal.env.Env Namespace Mal - class step7_quote + Class step7_quote ' read Shared Function READ(str As String) As MalVal Return reader.read_str(str) @@ -202,8 +202,13 @@ Namespace Mal repl_env.do_set(entry.Key, entry.Value) Next repl_env.do_set("eval", new MalFunc(AddressOf do_eval)) + Dim fileIdx As Integer = 1 + If args.Length > 1 AndAlso args(1) = "--raw" Then + Mal.readline.SetMode(Mal.readline.Modes.Raw) + fileIdx = 2 + End If Dim argv As New MalList() - For i As Integer = 0 To args.Length()-1 + For i As Integer = fileIdx+1 To args.Length-1 argv.conj_BANG(new MalString(args(i))) Next repl_env.do_set("*ARGV*", argv) @@ -212,11 +217,6 @@ Namespace Mal REP("(def! not (fn* (a) (if a false true)))") REP("(def! load-file (fn* (f) (eval (read-string (str ""(do "" (slurp f) "")"")))))") - Dim fileIdx As Integer = 1 - If args.Length > 1 AndAlso args(1) = "--raw" Then - Mal.readline.SetMode(Mal.readline.Modes.Raw) - fileIdx = 2 - End If If args.Length > fileIdx Then REP("(load-file """ & args(fileIdx) & """)") return 0 @@ -245,5 +245,5 @@ Namespace Mal End Try Loop While True End function - end class + End Class End Namespace diff --git a/vb/step8_macros.vb b/vb/step8_macros.vb index 5a5fc77..1a7f211 100644 --- a/vb/step8_macros.vb +++ b/vb/step8_macros.vb @@ -13,7 +13,7 @@ Imports MalFunc = Mal.types.MalFunc Imports MalEnv = Mal.env.Env Namespace Mal - class step8_macros + Class step8_macros ' read Shared Function READ(str As String) As MalVal Return reader.read_str(str) @@ -240,8 +240,13 @@ Namespace Mal repl_env.do_set(entry.Key, entry.Value) Next repl_env.do_set("eval", new MalFunc(AddressOf do_eval)) + Dim fileIdx As Integer = 1 + If args.Length > 1 AndAlso args(1) = "--raw" Then + Mal.readline.SetMode(Mal.readline.Modes.Raw) + fileIdx = 2 + End If Dim argv As New MalList() - For i As Integer = 0 To args.Length()-1 + For i As Integer = fileIdx+1 To args.Length-1 argv.conj_BANG(new MalString(args(i))) Next repl_env.do_set("*ARGV*", argv) @@ -252,11 +257,6 @@ Namespace Mal REP("(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)))))))") REP("(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))))))))") - Dim fileIdx As Integer = 1 - If args.Length > 1 AndAlso args(1) = "--raw" Then - Mal.readline.SetMode(Mal.readline.Modes.Raw) - fileIdx = 2 - End If If args.Length > fileIdx Then REP("(load-file """ & args(fileIdx) & """)") return 0 @@ -285,5 +285,5 @@ Namespace Mal End Try Loop While True End function - end class + End Class End Namespace diff --git a/vb/step9_try.vb b/vb/step9_try.vb index 0b888b7..5bf600d 100644 --- a/vb/step9_try.vb +++ b/vb/step9_try.vb @@ -263,24 +263,23 @@ Namespace Mal repl_env.do_set(entry.Key, entry.Value) Next repl_env.do_set("eval", new MalFunc(AddressOf do_eval)) + Dim fileIdx As Integer = 1 + If args.Length > 1 AndAlso args(1) = "--raw" Then + Mal.readline.SetMode(Mal.readline.Modes.Raw) + fileIdx = 2 + End If Dim argv As New MalList() - For i As Integer = 0 To args.Length()-1 + For i As Integer = fileIdx+1 To args.Length-1 argv.conj_BANG(new MalString(args(i))) Next repl_env.do_set("*ARGV*", argv) ' core.mal: defined using the language itself - REP("(def! *host-language* ""VB.NET"")") REP("(def! not (fn* (a) (if a false true)))") REP("(def! load-file (fn* (f) (eval (read-string (str ""(do "" (slurp f) "")"")))))") REP("(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)))))))") REP("(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))))))))") - Dim fileIdx As Integer = 1 - If args.Length > 1 AndAlso args(1) = "--raw" Then - Mal.readline.SetMode(Mal.readline.Modes.Raw) - fileIdx = 2 - End If If args.Length > fileIdx Then REP("(load-file """ & args(fileIdx) & """)") return 0 @@ -288,7 +287,6 @@ Namespace Mal ' repl loop Dim line As String - REP("(println (str ""Mal ["" *host-language* ""]""))") Do Try line = Mal.readline.Readline("user> ") diff --git a/vb/stepA_interop.vb b/vb/stepA_interop.vb index 713954d..01702fa 100644 --- a/vb/stepA_interop.vb +++ b/vb/stepA_interop.vb @@ -263,8 +263,13 @@ Namespace Mal repl_env.do_set(entry.Key, entry.Value) Next repl_env.do_set("eval", new MalFunc(AddressOf do_eval)) + Dim fileIdx As Integer = 1 + If args.Length > 1 AndAlso args(1) = "--raw" Then + Mal.readline.SetMode(Mal.readline.Modes.Raw) + fileIdx = 2 + End If Dim argv As New MalList() - For i As Integer = 0 To args.Length()-1 + For i As Integer = fileIdx+1 To args.Length-1 argv.conj_BANG(new MalString(args(i))) Next repl_env.do_set("*ARGV*", argv) @@ -276,11 +281,6 @@ Namespace Mal REP("(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)))))))") REP("(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))))))))") - Dim fileIdx As Integer = 1 - If args.Length > 1 AndAlso args(1) = "--raw" Then - Mal.readline.SetMode(Mal.readline.Modes.Raw) - fileIdx = 2 - End If If args.Length > fileIdx Then REP("(load-file """ & args(fileIdx) & """)") return 0 |
