Skip to content

Commit aaba249

Browse files
committed
VB.Net, C#: fix cmd line arg handling with --raw
1 parent ee7cd58 commit aaba249

20 files changed

+87
-92
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ vb_RUNSTEP = mono ../$(2) --raw $(3)
8989

9090
# Extra options to pass to runtest.py
9191
cs_TEST_OPTS = --redirect
92-
mal_TEST_OPTS = --start-timeout 60 --test-timeout 120
92+
mal_TEST_OPTS = --redirect --start-timeout 60 --test-timeout 120
9393
vb_TEST_OPTS = --redirect
9494

9595

cs/core.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public class core {
3838

3939
// Number functions
4040
static MalFunc time_ms = new MalFunc(
41-
a => new MalInt((int)(
42-
DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond)));
41+
a => new MalInt(DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond));
4342

4443
// String functions
4544
static public MalFunc pr_str = new MalFunc(
@@ -160,7 +159,7 @@ public class core {
160159
});
161160

162161
static MalFunc nth = new MalFunc(
163-
a => ((MalList)a[0])[ ((MalInt)a[1]).getValue() ]);
162+
a => ((MalList)a[0])[ (int)((MalInt)a[1]).getValue() ]);
164163

165164
static MalFunc first = new MalFunc(
166165
a => ((MalList)a[0])[0]);

cs/step2_eval.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
using MalFunc = Mal.types.MalFunc;
1313

1414
namespace Mal {
15-
class step1_eval {
15+
class step2_eval {
1616
// read
1717
static MalVal READ(string str) {
1818
return reader.read_str(str);

cs/step6_file.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,13 @@ static void Main(string[] args) {
141141
repl_env.set(entry.Key, entry.Value);
142142
}
143143
repl_env.set("eval", new MalFunc(a => EVAL(a[0], repl_env)));
144+
int fileIdx = 1;
145+
if (args.Length > 0 && args[0] == "--raw") {
146+
Mal.readline.mode = Mal.readline.Mode.Raw;
147+
fileIdx = 2;
148+
}
144149
MalList _argv = new MalList();
145-
for (int i=1; i < args.Length; i++) {
150+
for (int i=fileIdx; i < args.Length; i++) {
146151
_argv.conj_BANG(new MalString(args[i]));
147152
}
148153
repl_env.set("*ARGV*", _argv);
@@ -151,11 +156,6 @@ static void Main(string[] args) {
151156
RE("(def! not (fn* (a) (if a false true)))");
152157
RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))");
153158

154-
int fileIdx = 0;
155-
if (args.Length > 0 && args[0] == "--raw") {
156-
Mal.readline.mode = Mal.readline.Mode.Raw;
157-
fileIdx = 1;
158-
}
159159
if (args.Length > fileIdx) {
160160
RE("(load-file \"" + args[fileIdx] + "\")");
161161
return;

cs/step7_quote.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,13 @@ static void Main(string[] args) {
173173
repl_env.set(entry.Key, entry.Value);
174174
}
175175
repl_env.set("eval", new MalFunc(a => EVAL(a[0], repl_env)));
176+
int fileIdx = 1;
177+
if (args.Length > 0 && args[0] == "--raw") {
178+
Mal.readline.mode = Mal.readline.Mode.Raw;
179+
fileIdx = 2;
180+
}
176181
MalList _argv = new MalList();
177-
for (int i=1; i < args.Length; i++) {
182+
for (int i=fileIdx; i < args.Length; i++) {
178183
_argv.conj_BANG(new MalString(args[i]));
179184
}
180185
repl_env.set("*ARGV*", _argv);
@@ -183,11 +188,6 @@ static void Main(string[] args) {
183188
RE("(def! not (fn* (a) (if a false true)))");
184189
RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))");
185190

186-
int fileIdx = 0;
187-
if (args.Length > 0 && args[0] == "--raw") {
188-
Mal.readline.mode = Mal.readline.Mode.Raw;
189-
fileIdx = 1;
190-
}
191191
if (args.Length > fileIdx) {
192192
RE("(load-file \"" + args[fileIdx] + "\")");
193193
return;

cs/step8_macros.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,13 @@ static void Main(string[] args) {
210210
repl_env.set(entry.Key, entry.Value);
211211
}
212212
repl_env.set("eval", new MalFunc(a => EVAL(a[0], repl_env)));
213+
int fileIdx = 1;
214+
if (args.Length > 0 && args[0] == "--raw") {
215+
Mal.readline.mode = Mal.readline.Mode.Raw;
216+
fileIdx = 2;
217+
}
213218
MalList _argv = new MalList();
214-
for (int i=1; i < args.Length; i++) {
219+
for (int i=fileIdx; i < args.Length; i++) {
215220
_argv.conj_BANG(new MalString(args[i]));
216221
}
217222
repl_env.set("*ARGV*", _argv);
@@ -222,11 +227,6 @@ static void Main(string[] args) {
222227
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)))))))");
223228
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))))))))");
224229

225-
int fileIdx = 0;
226-
if (args.Length > 0 && args[0] == "--raw") {
227-
Mal.readline.mode = Mal.readline.Mode.Raw;
228-
fileIdx = 1;
229-
}
230230
if (args.Length > fileIdx) {
231231
RE("(load-file \"" + args[fileIdx] + "\")");
232232
return;

cs/step9_try.cs

+6-8
Original file line numberDiff line numberDiff line change
@@ -231,31 +231,29 @@ static void Main(string[] args) {
231231
repl_env.set(entry.Key, entry.Value);
232232
}
233233
repl_env.set("eval", new MalFunc(a => EVAL(a[0], repl_env)));
234+
int fileIdx = 1;
235+
if (args.Length > 0 && args[0] == "--raw") {
236+
Mal.readline.mode = Mal.readline.Mode.Raw;
237+
fileIdx = 2;
238+
}
234239
MalList _argv = new MalList();
235-
for (int i=1; i < args.Length; i++) {
240+
for (int i=fileIdx; i < args.Length; i++) {
236241
_argv.conj_BANG(new MalString(args[i]));
237242
}
238243
repl_env.set("*ARGV*", _argv);
239244

240245
// core.mal: defined using the language itself
241-
RE("(def! *host-language* \"c#\")");
242246
RE("(def! not (fn* (a) (if a false true)))");
243247
RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))");
244248
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)))))))");
245249
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))))))))");
246250

247-
int fileIdx = 0;
248-
if (args.Length > 0 && args[0] == "--raw") {
249-
Mal.readline.mode = Mal.readline.Mode.Raw;
250-
fileIdx = 1;
251-
}
252251
if (args.Length > fileIdx) {
253252
RE("(load-file \"" + args[fileIdx] + "\")");
254253
return;
255254
}
256255

257256
// repl loop
258-
RE("(println (str \"Mal [\" *host-language* \"]\"))");
259257
while (true) {
260258
string line;
261259
try {

cs/stepA_interop.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,13 @@ static void Main(string[] args) {
231231
repl_env.set(entry.Key, entry.Value);
232232
}
233233
repl_env.set("eval", new MalFunc(a => EVAL(a[0], repl_env)));
234+
int fileIdx = 1;
235+
if (args.Length > 0 && args[0] == "--raw") {
236+
Mal.readline.mode = Mal.readline.Mode.Raw;
237+
fileIdx = 2;
238+
}
234239
MalList _argv = new MalList();
235-
for (int i=1; i < args.Length; i++) {
240+
for (int i=fileIdx; i < args.Length; i++) {
236241
_argv.conj_BANG(new MalString(args[i]));
237242
}
238243
repl_env.set("*ARGV*", _argv);
@@ -244,11 +249,6 @@ static void Main(string[] args) {
244249
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)))))))");
245250
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))))))))");
246251

247-
int fileIdx = 0;
248-
if (args.Length > 0 && args[0] == "--raw") {
249-
Mal.readline.mode = Mal.readline.Mode.Raw;
250-
fileIdx = 1;
251-
}
252252
if (args.Length > fileIdx) {
253253
RE("(load-file \"" + args[fileIdx] + "\")");
254254
return;

cs/types.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ public override string ToString(bool print_readably) {
9898
static public MalConstant False = new MalConstant("false");
9999

100100
public class MalInt : MalVal {
101-
int value;
102-
public MalInt(int v) { value = v; }
101+
Int64 value;
102+
public MalInt(Int64 v) { value = v; }
103103
public new MalInt copy() { return this; }
104104

105-
public int getValue() { return value; }
105+
public Int64 getValue() { return value; }
106106
public override string ToString() {
107107
return value.ToString();
108108
}
@@ -205,10 +205,10 @@ public MalList conj_BANG(params MalVal[] mvs) {
205205

206206
public int size() { return value.Count; }
207207
public MalVal nth(int idx) {
208-
return value.Count > 0 ? value[idx] : Nil;
208+
return value.Count > idx ? value[idx] : Nil;
209209
}
210210
public MalVal this[int idx] {
211-
get { return value.Count > 0 ? value[idx] : Nil; }
211+
get { return value.Count > idx ? value[idx] : Nil; }
212212
}
213213
public MalList rest() {
214214
if (size() > 0) {

vb/step0_repl.vb

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Imports System
22
Imports Mal
33

44
Namespace Mal
5-
class step0_repl
5+
Class step0_repl
66
' read
77
Shared Function READ(str As String) As String
88
Return str
@@ -39,5 +39,5 @@ Namespace Mal
3939
Loop While True
4040
Return 0
4141
End function
42-
end class
42+
End Class
4343
End Namespace

vb/step1_read_print.vb

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Imports Mal
44
Imports MalVal = Mal.types.MalVal
55

66
Namespace Mal
7-
class step1_read_print
7+
Class step1_read_print
88
' read
99
Shared Function READ(str As String) As MalVal
1010
Return reader.read_str(str)
@@ -55,5 +55,5 @@ Namespace Mal
5555
End Try
5656
Loop While True
5757
End function
58-
end class
58+
End Class
5959
End Namespace

vb/step2_eval.vb

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Imports MalHashMap = Mal.types.MalHashMap
1111
Imports MalFunc = Mal.types.MalFunc
1212

1313
Namespace Mal
14-
class step2_eval
14+
Class step2_eval
1515
' read
1616
Shared Function READ(str As String) As MalVal
1717
Return reader.read_str(str)
@@ -130,5 +130,5 @@ Namespace Mal
130130
End Try
131131
Loop While True
132132
End function
133-
end class
133+
End Class
134134
End Namespace

vb/step3_env.vb

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Imports MalFunc = Mal.types.MalFunc
1212
Imports MalEnv = Mal.env.Env
1313

1414
Namespace Mal
15-
class step3_eval
15+
Class step3_env
1616
' read
1717
Shared Function READ(str As String) As MalVal
1818
Return reader.read_str(str)
@@ -152,5 +152,5 @@ Namespace Mal
152152
End Try
153153
Loop While True
154154
End function
155-
end class
155+
End Class
156156
End Namespace

vb/step4_if_fn_do.vb

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Imports MalFunc = Mal.types.MalFunc
1212
Imports MalEnv = Mal.env.Env
1313

1414
Namespace Mal
15-
class step4_if_fn_do
15+
Class step4_if_fn_do
1616
' read
1717
Shared Function READ(str As String) As MalVal
1818
Return reader.read_str(str)
@@ -185,5 +185,5 @@ Namespace Mal
185185
End Try
186186
Loop While True
187187
End function
188-
end class
188+
End Class
189189
End Namespace

vb/step5_tco.vb

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Imports MalFunc = Mal.types.MalFunc
1212
Imports MalEnv = Mal.env.Env
1313

1414
Namespace Mal
15-
class step5_tco
15+
Class step5_tco
1616
' read
1717
Shared Function READ(str As String) As MalVal
1818
Return reader.read_str(str)
@@ -194,5 +194,5 @@ Namespace Mal
194194
End Try
195195
Loop While True
196196
End function
197-
end class
197+
End Class
198198
End Namespace

vb/step6_file.vb

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Imports MalFunc = Mal.types.MalFunc
1313
Imports MalEnv = Mal.env.Env
1414

1515
Namespace Mal
16-
class step6_file
16+
Class step6_file
1717
' read
1818
Shared Function READ(str As String) As MalVal
1919
Return reader.read_str(str)
@@ -169,8 +169,13 @@ Namespace Mal
169169
repl_env.do_set(entry.Key, entry.Value)
170170
Next
171171
repl_env.do_set("eval", new MalFunc(AddressOf do_eval))
172+
Dim fileIdx As Integer = 1
173+
If args.Length > 1 AndAlso args(1) = "--raw" Then
174+
Mal.readline.SetMode(Mal.readline.Modes.Raw)
175+
fileIdx = 2
176+
End If
172177
Dim argv As New MalList()
173-
For i As Integer = 0 To args.Length()-1
178+
For i As Integer = fileIdx+1 To args.Length-1
174179
argv.conj_BANG(new MalString(args(i)))
175180
Next
176181
repl_env.do_set("*ARGV*", argv)
@@ -179,11 +184,6 @@ Namespace Mal
179184
REP("(def! not (fn* (a) (if a false true)))")
180185
REP("(def! load-file (fn* (f) (eval (read-string (str ""(do "" (slurp f) "")"")))))")
181186

182-
Dim fileIdx As Integer = 1
183-
If args.Length > 1 AndAlso args(1) = "--raw" Then
184-
Mal.readline.SetMode(Mal.readline.Modes.Raw)
185-
fileIdx = 2
186-
End If
187187
If args.Length > fileIdx Then
188188
REP("(load-file """ & args(fileIdx) & """)")
189189
return 0
@@ -212,5 +212,5 @@ Namespace Mal
212212
End Try
213213
Loop While True
214214
End function
215-
end class
215+
End Class
216216
End Namespace

vb/step7_quote.vb

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Imports MalFunc = Mal.types.MalFunc
1313
Imports MalEnv = Mal.env.Env
1414

1515
Namespace Mal
16-
class step7_quote
16+
Class step7_quote
1717
' read
1818
Shared Function READ(str As String) As MalVal
1919
Return reader.read_str(str)
@@ -202,8 +202,13 @@ Namespace Mal
202202
repl_env.do_set(entry.Key, entry.Value)
203203
Next
204204
repl_env.do_set("eval", new MalFunc(AddressOf do_eval))
205+
Dim fileIdx As Integer = 1
206+
If args.Length > 1 AndAlso args(1) = "--raw" Then
207+
Mal.readline.SetMode(Mal.readline.Modes.Raw)
208+
fileIdx = 2
209+
End If
205210
Dim argv As New MalList()
206-
For i As Integer = 0 To args.Length()-1
211+
For i As Integer = fileIdx+1 To args.Length-1
207212
argv.conj_BANG(new MalString(args(i)))
208213
Next
209214
repl_env.do_set("*ARGV*", argv)
@@ -212,11 +217,6 @@ Namespace Mal
212217
REP("(def! not (fn* (a) (if a false true)))")
213218
REP("(def! load-file (fn* (f) (eval (read-string (str ""(do "" (slurp f) "")"")))))")
214219

215-
Dim fileIdx As Integer = 1
216-
If args.Length > 1 AndAlso args(1) = "--raw" Then
217-
Mal.readline.SetMode(Mal.readline.Modes.Raw)
218-
fileIdx = 2
219-
End If
220220
If args.Length > fileIdx Then
221221
REP("(load-file """ & args(fileIdx) & """)")
222222
return 0
@@ -245,5 +245,5 @@ Namespace Mal
245245
End Try
246246
Loop While True
247247
End function
248-
end class
248+
End Class
249249
End Namespace

0 commit comments

Comments
 (0)