14 // ////////////////////////////////////////////////////////////////////////// //
15 void registerPrims (VM vm
) {
16 vm
["write"] = (VM self
, Real
* bp
, ubyte argc
) {
17 import std
.stdio
: stdout
;
18 foreach (immutable idx
; 0..argc
) {
19 auto v
= bp
[vm
.Slot
.Argument0
+idx
];
20 if (v
.isString
) stdout
.write(vm
.getDynStr(v
.getStrId
)); else stdout
.write(v
);
24 vm
["writeln"] = (VM self
, Real
* bp
, ubyte argc
) {
25 import std
.stdio
: stdout
;
26 foreach (immutable idx
; 0..argc
) {
27 auto v
= bp
[vm
.Slot
.Argument0
+idx
];
28 if (v
.isString
) stdout
.write(vm
.getDynStr(v
.getStrId
)); else stdout
.write(v
);
34 vm
["string_length"] = (string s
) => s
.length
;
38 // ////////////////////////////////////////////////////////////////////////// //
39 void main (string
[] args
) {
40 bool dumpFileNames
= false;
41 bool doScripts
= true;
42 bool doActions
= true;
43 bool measureTime
= false;
49 foreach (string fname
; args
[1..$]) {
55 if (fname
.length
== 0) continue;
56 if (fname
== "--") { nomore
= true; continue; }
57 if (fname
== "-d") { dumpFileNames
= true; continue; }
58 if (fname
== "-S") { doScripts
= false; continue; }
59 if (fname
== "-A") { doActions
= false; continue; }
60 if (fname
== "--time") { measureTime
= true; continue; }
61 if (fname
[0] == '@') {
62 if (fname
.length
< 2) assert(0, "gmk file?");
63 auto gmk
= new Gmk(fname
[1..$]);
64 funcs
~= gmkLoadScripts(gmk
, doScripts
:doScripts
, doActions
:doActions
, warnings
:false, checkReturns
:false);
68 foreach (auto de; dirEntries(fname
, "*.gm[lx]", SpanMode
.breadth
)) {
70 foreach (auto pt
; pathSplitter(de.dirName
)) {
71 if (pt
.length
&& pt
[0] == '_') { doit
= false; break; }
74 if (dumpFileNames
) { import std
.stdio
; writeln("loading '", de.name
, "'..."); }
75 funcs
~= loadScript(de.name
, false);
79 if (dumpFileNames
) { import std
.stdio
; writeln("loading '", fname
, "'..."); }
80 funcs
~= loadScript(fname
, false);
85 if (funcs
.length
> 0) {
89 writeln(funcs
.length
, " function", (funcs
.length
> 1 ?
"s" : ""), " parsed");
90 foreach (auto fn
; funcs
) {
93 if (measureTime
) writeln("executing...");
94 auto stt
= MonoTime
.currTime
;
95 auto res
= vm
.exec("main");
96 auto dur
= (MonoTime
.currTime
-stt
).total
!"msecs";
98 if (measureTime
) writeln("total execution took ", dur
, " milliseconds");