10 // ////////////////////////////////////////////////////////////////////////// //
11 void registerPrims (VM vm
) {
12 vm
["write"] = (VM self
, Real
* bp
, ubyte argc
) {
13 import std
.stdio
: stdout
;
14 foreach (immutable idx
; 0..argc
) {
15 auto v
= bp
[vm
.Slot
.Argument0
+idx
];
16 if (v
.isString
) stdout
.write(getDynStr(v
.getStrId
)); else stdout
.write(v
);
20 vm
["writeln"] = (VM self
, Real
* bp
, ubyte argc
) {
21 import std
.stdio
: stdout
;
22 foreach (immutable idx
; 0..argc
) {
23 auto v
= bp
[vm
.Slot
.Argument0
+idx
];
24 if (v
.isString
) stdout
.write(getDynStr(v
.getStrId
)); else stdout
.write(v
);
30 vm
["string_length"] = (string s
) => s
.length
;
34 // ////////////////////////////////////////////////////////////////////////// //
35 void main (string
[] args
) {
36 bool measureTime
= false;
40 funcs
= cliProcessArgs
!(
41 "--time", (fname
) { measureTime
= true; },
44 if (funcs
.length
> 0) {
48 writeln(funcs
.length
, " function", (funcs
.length
> 1 ?
"s" : ""), " parsed");
49 foreach (auto fn
; funcs
) {
52 if (measureTime
) writeln("executing...");
53 auto stt
= MonoTime
.currTime
;
54 auto res
= vm
.exec("main");
55 auto dur
= (MonoTime
.currTime
-stt
).total
!"msecs";
57 if (measureTime
) writeln("total execution took ", dur
, " milliseconds");