switched to GPLv3 ONLY, because i don't trust FSF anymore
[gaemu.git] / xvm.d
blobb10de01926c71910dff7f039ad7f614d4a4b69b5
1 module frex is aliced;
3 import std.stdio;
5 import gaem.parser;
6 import gaem.utils;
7 import gaem.runner;
8 import gaem.ungmk;
11 // ////////////////////////////////////////////////////////////////////////// //
12 void registerPrims () {
13 VM["write"] = (Real[] args) {
14 import std.stdio : stdout;
15 foreach (Real v; args[VM.Slot.Argument0..$]) {
16 if (v.isString) stdout.write(getDynStr(v.getStrId)); else stdout.write(v);
18 stdout.flush();
20 VM["writeln"] = (Real[] args) {
21 import std.stdio : stdout;
22 foreach (Real v; args[VM.Slot.Argument0..$]) {
23 if (v.isString) stdout.write(getDynStr(v.getStrId)); else stdout.write(v);
25 stdout.writeln;
26 stdout.flush();
29 VM["string_length"] = (string s) => s.length;
33 // ////////////////////////////////////////////////////////////////////////// //
34 void main (string[] args) {
35 bool measureTime = false;
36 bool doRun = true;
38 NodeFunc[] funcs;
40 cliLoadGmkScripts = false;
42 funcs = cliProcessArgs!(
43 "--time", (fname) { measureTime = true; },
44 "--norun", (fname) { doRun = false; },
45 )(args, (Gmk gmk) {
46 VM.setGmk(gmk);
47 createObjects(gmk);
48 });
50 if (funcs.length > 0) {
51 import core.time;
52 registerPrims();
53 writeln(funcs.length, " function", (funcs.length > 1 ? "s" : ""), " parsed");
54 foreach (auto fn; funcs) compile(fn);
55 if (doRun) {
56 if (measureTime) writeln("executing...");
57 auto stt = MonoTime.currTime;
58 auto res = VM.exec("main");
59 auto dur = (MonoTime.currTime-stt).total!"msecs";
60 writeln(res);
61 if (measureTime) writeln("total execution took ", dur, " milliseconds");