removed VM class: we won't need more than one VM
[gaemu.git] / fvm.d
blob36e09d3e000c6da8224549056e895285d155827c
1 module frex is aliced;
3 import std.stdio;
5 import gaem.parser;
6 import gaem.utils;
7 import gaem.runner;
10 // ////////////////////////////////////////////////////////////////////////// //
11 void registerPrims () {
12 VM["write"] = (Real[] args) {
13 import std.stdio : stdout;
14 foreach (Real v; args[VM.Slot.Argument0..$]) {
15 if (v.isString) stdout.write(getDynStr(v.getStrId)); else stdout.write(v);
17 stdout.flush();
19 VM["writeln"] = (Real[] args) {
20 import std.stdio : stdout;
21 foreach (Real v; args[VM.Slot.Argument0..$]) {
22 if (v.isString) stdout.write(getDynStr(v.getStrId)); else stdout.write(v);
24 stdout.writeln;
25 stdout.flush();
28 VM["string_length"] = (string s) => s.length;
32 // ////////////////////////////////////////////////////////////////////////// //
33 void main (string[] args) {
34 bool measureTime = false;
36 NodeFunc[] funcs;
38 funcs = cliProcessArgs!(
39 "--time", (fname) { measureTime = true; },
40 )(args);
42 if (funcs.length > 0) {
43 import core.time;
44 registerPrims();
45 writeln(funcs.length, " function", (funcs.length > 1 ? "s" : ""), " parsed");
46 foreach (auto fn; funcs) compile(fn);
47 if (measureTime) writeln("executing...");
48 auto stt = MonoTime.currTime;
49 auto res = VM.exec("main");
50 auto dur = (MonoTime.currTime-stt).total!"msecs";
51 writeln(res);
52 if (measureTime) writeln("total execution took ", dur, " milliseconds");