Initial asc

This commit is contained in:
dcodeIO 2017-12-04 04:14:57 +01:00
parent 63a67e7c67
commit 558a4d5c63
7 changed files with 124 additions and 5 deletions

2
bin/asc.js Normal file
View File

@ -0,0 +1,2 @@
require("ts-node").register({ project: require("path").join(__dirname, "..", "src") });
require("./asc.ts");

12
bin/asc.json Normal file
View File

@ -0,0 +1,12 @@
{
"version": {
"desc": "Print the compiler's version.",
"type": "boolean",
"aliases": [ "v" ]
},
"help": {
"desc": "Print this message.",
"type": "boolean",
"aliases": [ "h" ]
}
}

93
bin/asc.ts Normal file
View File

@ -0,0 +1,93 @@
/// <reference path="../src/glue/binaryen.d.ts" />
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")
(<string[]>(opts.string || (opts.string = []))).push(key);
else if (opt.type === "boolean")
(<string[]>(opts.boolean || (opts.boolean = []))).push(key);
});
const args = minimist(process.argv.slice(2), opts);
const version = <string>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();

9
package-lock.json generated
View File

@ -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",

View File

@ -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",

View File

@ -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";

View File

@ -40,7 +40,7 @@
],
"assembly": {
"exclude": [
"glue/js.t.ts",
"glue/js.d.ts",
"glue/js.ts"
],
"include": [