timings
[gaemu.git] / fvm.d
blob129a8aeb70afed02feb7cde07f7dcd0d348dabc3
1 module frex is aliced;
3 import std.stdio;
5 import gmlparser;
6 import gmlparser.anal;
8 import ungmk;
9 import loader;
11 import gmlvm;
14 // ////////////////////////////////////////////////////////////////////////// //
15 void main (string[] args) {
16 bool dumpFileNames = false;
17 bool doScripts = true;
18 bool doActions = true;
19 bool measureTime = false;
21 NodeFunc[] funcs;
23 bool nomore = false;
24 string[] scargs;
25 foreach (string fname; args[1..$]) {
26 import std.file;
27 import std.path;
28 if (nomore) {
29 scargs ~= fname;
30 } else {
31 if (fname.length == 0) continue;
32 if (fname == "--") { nomore = true; continue; }
33 if (fname == "-d") { dumpFileNames = true; continue; }
34 if (fname == "-S") { doScripts = false; continue; }
35 if (fname == "-A") { doActions = false; continue; }
36 if (fname == "--time") { measureTime = true; continue; }
37 if (fname[0] == '@') {
38 if (fname.length < 2) assert(0, "gmk file?");
39 auto gmk = new Gmk(fname[1..$]);
40 funcs ~= gmkLoadScripts(gmk, doScripts:doScripts, doActions:doActions, warnings:false, checkReturns:false);
41 continue;
43 if (isDir(fname)) {
44 foreach (auto de; dirEntries(fname, "*.gm[lx]", SpanMode.breadth)) {
45 bool doit = true;
46 foreach (auto pt; pathSplitter(de.dirName)) {
47 if (pt.length && pt[0] == '_') { doit = false; break; }
49 if (doit) {
50 if (dumpFileNames) { import std.stdio; writeln("loading '", de.name, "'..."); }
51 funcs ~= loadScript(de.name, false);
54 } else {
55 if (dumpFileNames) { import std.stdio; writeln("loading '", fname, "'..."); }
56 funcs ~= loadScript(fname, false);
61 if (funcs.length > 0) {
62 import core.time;
63 auto vm = new VM();
64 writeln(funcs.length, " function", (funcs.length > 1 ? "s" : ""), " parsed");
65 foreach (auto fn; funcs) {
66 vm.compile(fn);
68 if (measureTime) writeln("executing...");
69 auto stt = MonoTime.currTime;
70 auto res = vm.exec("ack", 3, 7);
71 auto dur = (MonoTime.currTime-stt).total!"msecs";
72 writeln(res);
73 if (measureTime) writeln("total execution took ", dur, " milliseconds");