8000 Add -l for emitting load instead of require · repos-javascript-compilers/LLJS@e4c369e · GitHub
[go: up one dir, main page]

Skip to content

Commit e4c369e

Browse files
committed
Add -l for emitting load instead of require
1 parent fae50cb commit e4c369e

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/compiler.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,13 +1572,17 @@
15721572
return new CallExpression(new Identifier("require"), [new Literal(name)]);
15731573
}
15741574

1575-
function createModule(program, name, bare) {
1575+
function createModule(program, name, bare, loadInstead) {
15761576
var body = [];
15771577
var cachedMEMORY = program.frame.cachedMEMORY;
15781578
if (cachedMEMORY) {
15791579
var mdecl;
15801580
if (name === "memory") {
15811581
mdecl = new VariableDeclarator(cachedMEMORY, new Identifier("exports"));
1582+
} else if (loadInstead) {
1583+
mdecl = new VariableDeclarator(cachedMEMORY, new SequenceExpression([
1584+
new CallExpression(new Identifier("load"), [new Literal("memory.js")]),
1585+
new Identifier("memory")]));
15821586
} else {
15831587
mdecl = new VariableDeclarator(cachedMEMORY, createRequire("memory"));
15841588
}
@@ -1633,7 +1637,7 @@
16331637
// Pass 4.
16341638
node = node.lower(o);
16351639

1636-
return T.flatten(createModule(node, name, options.bare));
1640+
return T.flatten(createModule(node, name, options.bare, options["load-instead"]));
16371641
}
16381642

16391643
exports.compile = compile;

src/ljc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
["A", "emit-ast", false, "Do not generate JS, emit AST"],
112112
["P", "pretty-print", false, "Pretty-print AST instead of emitting JSON (with -A)"],
113113
["b", "bare", false, "Do not wrap in a module"],
114+
["l", "load-instead", false, "Emit load('memory') instead of require('memory')"],
114115
["W", "warn", true, "Print warnings (enabled by default)"],
115116
["Wconversion", null, false, "Print intra-integer and pointer conversion warnings"],
116117
["0", "simple-log", false, "Log simple messages. No colors and snippets."],

0 commit comments

Comments
 (0)
0