Control flow evaluator; Support for block-level let/const variables

This commit is contained in:
dcodeIO
2018-01-18 23:34:12 +01:00
parent 1c4b0ddc57
commit 7be4f9fabb
54 changed files with 3285 additions and 13138 deletions

View File

@ -51,13 +51,20 @@ glob.sync(filter, { cwd: __dirname + "/compiler" }).forEach(filename => {
var program = parser.finish();
var parseTime = process.hrtime(startTime);
startTime = process.hrtime();
var module = Compiler.compile(program);
var module;
try {
module = Compiler.compile(program);
} catch (e) {
failed = true;
module = Module.create();
console.log(chalk.red("compile ERROR: ") + e.stack);
}
var compileTime = process.hrtime(startTime);
var actual = module.toText() + "(;\n[program.elements]\n " + elements(program.elements)
+ "\n[program.exports]\n " + elements(program.exports)
+ "\n;)\n";
var actualOptimized = null;
var actualInlined = null;
// var actualInlined = null;
console.log("parse incl. I/O: " + ((parseTime[0] * 1e9 + parseTime[1]) / 1e6).toFixed(3) + "ms / compile: " + ((compileTime[0] * 1e9 + compileTime[1]) / 1e6).toFixed(3) + "ms");
@ -87,16 +94,14 @@ glob.sync(filter, { cwd: __dirname + "/compiler" }).forEach(filename => {
console.log(chalk.green("instantiate OK"));
} catch (e) {
failed = true;
console.log(chalk.red("instantiate ERROR: ") + e);
console.log(chalk.red("instantiate ERROR: ") + e.stack);
}
} catch (e) {
failed = true;
console.log(chalk.red("interpret ERROR:") + e);
console.log(chalk.red("interpret ERROR:") + e.stack);
}
module.optimize();
actualOptimized = module.toText();
module.runPasses([ "inlining" ]);
actualInlined = module.toText();
if (isCreate)
fs.writeFileSync(__dirname + "/compiler/" + fixture + ".optimized.wasm", module.toBinary());
} else {
@ -111,17 +116,6 @@ glob.sync(filter, { cwd: __dirname + "/compiler" }).forEach(filename => {
fs.writeFileSync(__dirname + "/compiler/" + fixture + ".optimized.wast", actualOptimized, { encoding: "utf8" });
console.log("Created optimized");
}
if (actualInlined != null) {
if (actualInlined != actualOptimized) {
fs.writeFileSync(__dirname + "/compiler/" + fixture + ".optimized-inlined.wast", actualInlined, { encoding: "utf8" });
console.log("Created optimized & inlined");
} else {
try {
fs.unlinkSync(__dirname + "/compiler/" + fixture + ".optimized-inlined.wast");
console.log("Deleted optimized & inlined");
} catch (e) {}
}
}
} else {
var expected;
try {