You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
"use strict";
|
|
|
|
const fs = require("fs");
|
|
const assert = require("assert");
|
|
|
|
const transpile = require("./src/transpile");
|
|
const measureTime = require("./src/astformer/util/measure-time");
|
|
|
|
assert(process.argv[2] != null);
|
|
|
|
const nixFilePath = process.argv[2];
|
|
const nixFile = fs.readFileSync(nixFilePath, "utf8");
|
|
|
|
let transpiled = transpile(nixFile);
|
|
|
|
const api = {
|
|
builtins: {},
|
|
$$jsNix$memoize: function (func) {
|
|
let isCalled = false;
|
|
let storedResult;
|
|
|
|
return function (arg) {
|
|
if (isCalled === false) {
|
|
storedResult = func(arg);
|
|
isCalled = true;
|
|
}
|
|
|
|
return storedResult;
|
|
};
|
|
}
|
|
};
|
|
|
|
// TODO: Switch to Node `vm` API instead, and check whether there's a polyfill for it for non-Node environments, build a custom one if not
|
|
const context = { module: {}, exports: {} };
|
|
context.module.exports = exports;
|
|
|
|
new Function("module", transpiled)(context.module);
|
|
|
|
console.log("-- EVALUATION RESULT:");
|
|
|
|
// Warm-up for hot VM performance testing
|
|
// for (let i = 0; i < 10000; i++) {
|
|
// context.module.exports(api);
|
|
// }
|
|
|
|
console.log(measureTime(() => context.module.exports(api)));
|