diff --git a/bin/asc.js b/bin/asc.js
new file mode 100644
index 00000000..5a75820b
--- /dev/null
+++ b/bin/asc.js
@@ -0,0 +1,2 @@
+require("ts-node").register({ project: require("path").join(__dirname, "..", "src") });
+require("./asc.ts");
diff --git a/bin/asc.json b/bin/asc.json
new file mode 100644
index 00000000..0c6aa47f
--- /dev/null
+++ b/bin/asc.json
@@ -0,0 +1,12 @@
+{
+ "version": {
+ "desc": "Print the compiler's version.",
+ "type": "boolean",
+ "aliases": [ "v" ]
+ },
+ "help": {
+ "desc": "Print this message.",
+ "type": "boolean",
+ "aliases": [ "h" ]
+ }
+}
diff --git a/bin/asc.ts b/bin/asc.ts
new file mode 100644
index 00000000..67a30c45
--- /dev/null
+++ b/bin/asc.ts
@@ -0,0 +1,93 @@
+///
+
+import * as fs from "fs";
+import * as path from "path";
+import * as minimist from "minimist";
+import "../src/glue/js";
+import * as as from "../src";
+
+var conf: { [key: string]: { desc: string, type: string, aliases: string[], default: any } } = require("./asc.json");
+var opts: minimist.Opts = {};
+Object.keys(conf).forEach(key => {
+ var opt = conf[key];
+ if (opt.aliases)
+ (opts.alias || (opts.alias = {}))[key] = opt.aliases;
+ if (opt.default !== undefined)
+ (opts.default || (opts.default = {}))[key] = opt.default;
+ if (opt.type === "string")
+ ((opts.string || (opts.string = []))).push(key);
+ else if (opt.type === "boolean")
+ ((opts.boolean || (opts.boolean = []))).push(key);
+});
+
+const args = minimist(process.argv.slice(2), opts);
+const version = require("../package.json")["version"];
+
+if (args["version"]) {
+ console.log([
+ "Version " + version
+ ].join("\n"));
+ process.exit(0);
+}
+
+if (args["help"] || args._.length < 1) {
+ let options: string[] = [];
+ Object.keys(conf).forEach(name => {
+ const option = conf[name];
+ let text = "";
+ if (option.aliases) {
+ option.aliases.forEach((alias, i) => {
+ if (i > 0)
+ text += ", ";
+ text += "-" + alias;
+ });
+ text += ", ";
+ }
+ text += "--" + name;
+ while (text.length < 20)
+ text += " ";
+ options.push(text + option.desc);
+ });
+ console.log([
+ "Version " + version,
+ "Syntax: asc [options] [file ...]",
+ "",
+ "Examples: asc hello.ts",
+ "",
+ "Options:"
+ ].concat(options).join("\n"));
+ process.exit(args["help"] ? 0 : 1);
+}
+
+const entryPath = args._[0];
+const entryText = fs.readFileSync(entryPath, { encoding: "utf8" });
+
+const parser = as.parseFile(entryText, entryPath);
+
+let nextPath: string | null;
+let nextText: string;
+
+while ((nextPath = parser.nextFile()) != null) {
+ try {
+ nextText = fs.readFileSync(path.join(path.dirname(entryPath), nextPath + ".ts"), { encoding: "utf8" });
+ } catch (e) {
+ nextText = fs.readFileSync(path.join(path.dirname(entryPath), nextPath, "index.ts"), { encoding: "utf8" });
+ }
+ as.parseFile(nextText, nextPath, parser);
+}
+
+let diagnostic: as.DiagnosticMessage | null;
+let hasErrors: boolean = false;
+
+while ((diagnostic = as.nextDiagnostic(parser)) != null) {
+ console.error(as.formatDiagnostic(diagnostic, process.stdout.isTTY, true));
+ if (as.isError(diagnostic))
+ hasErrors = true;
+}
+
+if (hasErrors)
+ process.exit(1);
+
+const module = as.compile(parser);
+_BinaryenModulePrint(module.ref);
+module.dispose();
diff --git a/package-lock.json b/package-lock.json
index 92d9b01f..fc04ceea 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,4 +1,5 @@
{
+ "name": "@assemblyscript/next",
"requires": true,
"lockfileVersion": 1,
"dependencies": {
@@ -39,6 +40,11 @@
"integrity": "sha512-rUO/jz10KRSyA9SHoCWQ8WX9BICyj5jZYu1/ucKEJKb4KzLZCKMURdYbadP157Q6Zl1x0vHsrU+Z/O0XlhYQDw==",
"dev": true
},
+ "@types/minimist": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.0.tgz",
+ "integrity": "sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY="
+ },
"@types/node": {
"version": "8.0.53",
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.0.53.tgz",
@@ -190,8 +196,7 @@
"minimist": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
- "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
- "dev": true
+ "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
},
"mkdirp": {
"version": "0.5.1",
diff --git a/package.json b/package.json
index b9e09aa0..096180cc 100644
--- a/package.json
+++ b/package.json
@@ -1,8 +1,12 @@
{
+ "name": "@assemblyscript/next",
+ "version": "0.5.0",
"license": "Apache-2.0",
"dependencies": {
+ "@types/minimist": "^1.2.0",
"@types/node": "^8.0.53",
- "binaryen": "39.0.0-nightly.20171116"
+ "binaryen": "39.0.0-nightly.20171116",
+ "minimist": "^1.2.0"
},
"devDependencies": {
"@types/chalk": "^2.2.0",
@@ -16,6 +20,9 @@
"ts-node": "^3.3.0",
"typescript": "^2.6.2"
},
+ "bin": {
+ "asc": "bin/asc.js"
+ },
"scripts": {
"build": "tsc -P src",
"test:parser": "ts-node -P src tests/parser",
diff --git a/src/index.ts b/src/index.ts
index 1323f995..b6b3016e 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -55,4 +55,4 @@ export function compile(parser: Parser): Module {
return Compiler.compile(program);
}
-export { formatDiagnosticMessage as formatDiagnostic } from "./diagnostics";
+export { DiagnosticMessage, formatDiagnosticMessage as formatDiagnostic } from "./diagnostics";
diff --git a/src/tsconfig.json b/src/tsconfig.json
index bedfa6d4..cda728a6 100644
--- a/src/tsconfig.json
+++ b/src/tsconfig.json
@@ -40,7 +40,7 @@
],
"assembly": {
"exclude": [
- "glue/js.t.ts",
+ "glue/js.d.ts",
"glue/js.ts"
],
"include": [