mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-27 16:02:16 +00:00
Accept custom library paths in asc, see #19
This commit is contained in:
parent
1995bf9eb4
commit
cae89e0b1f
66
bin/asc.js
66
bin/asc.js
@ -104,13 +104,22 @@ function checkDiagnostics(parser) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include standard library
|
// Include standard library if --noLib isn't set
|
||||||
var stdlibDir = path.join(__dirname, "..", "std", "assembly");
|
var libDirs = args.noLib ? [] : [ path.join(__dirname, "..", "std", "assembly") ];
|
||||||
if (!args.noLib) {
|
|
||||||
|
// Include custom library components (with or without stdlib)
|
||||||
|
if (args.lib) {
|
||||||
|
if (Array.isArray(args.lib))
|
||||||
|
Array.prototype.push.apply(libDirs, args.lib.map(dir));
|
||||||
|
else
|
||||||
|
libDirs.push(args.lib);
|
||||||
|
}
|
||||||
|
|
||||||
|
libDirs.forEach(libDir => {
|
||||||
var notIoTime = 0;
|
var notIoTime = 0;
|
||||||
readTime += measure(() => {
|
readTime += measure(() => {
|
||||||
glob.sync("*.ts", { cwd: stdlibDir }).forEach(file => {
|
glob.sync("*.ts", { cwd: libDir }).forEach(file => {
|
||||||
var nextText = fs.readFileSync(path.join(stdlibDir, file), { encoding: "utf8" });
|
var nextText = fs.readFileSync(path.join(libDir, file), { encoding: "utf8" });
|
||||||
++readCount;
|
++readCount;
|
||||||
var time = measure(() => {
|
var time = measure(() => {
|
||||||
parser = assemblyscript.parseFile(nextText, "std:" + file, parser, false);
|
parser = assemblyscript.parseFile(nextText, "std:" + file, parser, false);
|
||||||
@ -119,7 +128,7 @@ if (!args.noLib) {
|
|||||||
notIoTime += time;
|
notIoTime += time;
|
||||||
});
|
});
|
||||||
}) - notIoTime;
|
}) - notIoTime;
|
||||||
}
|
});
|
||||||
|
|
||||||
// Include entry files
|
// Include entry files
|
||||||
args._.forEach(filename => {
|
args._.forEach(filename => {
|
||||||
@ -154,25 +163,40 @@ args._.forEach(filename => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
while ((nextPath = parser.nextFile()) != null) {
|
while ((nextPath = parser.nextFile()) != null) {
|
||||||
try {
|
var found = false;
|
||||||
readTime += measure(() => {
|
if (nextPath.startsWith("std:")) {
|
||||||
if (nextPath.startsWith("std:"))
|
for (var i = 0; i < libDirs.length; ++i) {
|
||||||
nextText = fs.readFileSync(stdlibDir + "/" + nextPath.substring(4) + ".ts", { encoding: "utf8" });
|
|
||||||
else
|
|
||||||
nextText = fs.readFileSync(nextPath + ".ts", { encoding: "utf8" });
|
|
||||||
});
|
|
||||||
++readCount;
|
|
||||||
} catch (e) {
|
|
||||||
try {
|
|
||||||
readTime += measure(() => {
|
readTime += measure(() => {
|
||||||
nextText = fs.readFileSync(nextPath + "/index.ts", { encoding: "utf8" });
|
try {
|
||||||
|
nextText = fs.readFileSync(libDirs[i] + "/" + nextPath.substring(4) + ".ts", { encoding: "utf8" });
|
||||||
|
found = true;
|
||||||
|
} catch (e) {}
|
||||||
});
|
});
|
||||||
++readCount;
|
++readCount;
|
||||||
nextPath = nextPath + "/index";
|
if (found)
|
||||||
} catch (e) {
|
break;
|
||||||
console.error("Imported file '" + nextPath + ".ts' not found.");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
readTime += measure(() => {
|
||||||
|
try {
|
||||||
|
nextText = fs.readFileSync(nextPath + "/index.ts", { encoding: "utf8" });
|
||||||
|
found = true;
|
||||||
|
} catch (e) {}
|
||||||
|
});
|
||||||
|
++readCount;
|
||||||
|
if (!found) {
|
||||||
|
readTime += measure(() => {
|
||||||
|
try {
|
||||||
|
nextText = fs.readFileSync(nextPath + ".ts", { encoding: "utf8" });
|
||||||
|
found = true;
|
||||||
|
} catch (e) {}
|
||||||
|
});
|
||||||
|
++readCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
console.error("Imported file '" + nextPath + ".ts' not found.");
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
parseTime += measure(() => {
|
parseTime += measure(() => {
|
||||||
assemblyscript.parseFile(nextText, nextPath, parser);
|
assemblyscript.parseFile(nextText, nextPath, parser);
|
||||||
|
10
bin/asc.json
10
bin/asc.json
@ -74,13 +74,17 @@
|
|||||||
"desc": "Performs compilation as usual without emitting code.",
|
"desc": "Performs compilation as usual without emitting code.",
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"noMemory": {
|
||||||
|
"desc": "Does not set up a memory.",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"noLib": {
|
"noLib": {
|
||||||
"desc": "Does not include the standard library.",
|
"desc": "Does not include the standard library.",
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"noMemory": {
|
"lib": {
|
||||||
"desc": "Does not set up a memory.",
|
"desc": "Adds one or multiple paths to custom library components.",
|
||||||
"type": "boolean"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"trapMode": {
|
"trapMode": {
|
||||||
"desc": [
|
"desc": [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user