Skip to content

Commit

Permalink
trying to revert
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Jan 2, 2019
1 parent f0477ba commit fbce899
Show file tree
Hide file tree
Showing 133 changed files with 14,717 additions and 34,285 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@ docs/
node_modules/
out/
raw/
.history
.vscode
.idea
Empty file modified bin/asinit
100755 → 100644
Empty file.
101 changes: 59 additions & 42 deletions cli/asc.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,41 +92,33 @@ exports.definitionFiles = exports.isBundle ? BUNDLE_DEFINITIONS : (() => { // se
})();

/** Convenience function that parses and compiles source strings directly. */
exports.compileString = async (sources, options) => {
exports.compileString = (sources, options) => {
if (typeof sources === "string") sources = { "input.ts": sources };
const output = Object.create({
stdout: createMemoryStream(),
stderr: createMemoryStream()
});
debugger;
var argv = [];
var argv = [
"--binaryFile", "binary",
"--textFile", "text",
];
Object.keys(options || {}).forEach(key => {
if (key != "readFile" && key != 'writeFile'){
var val = options[key];
debugger;
if (Array.isArray(val)) val.forEach(val => argv.push("--" + key, String(val)));
else argv.push("--" + key, String(val));
}
var val = options[key];
if (Array.isArray(val)) val.forEach(val => argv.push("--" + key, String(val)));
else argv.push("--" + key, String(val));
});
await exports.main(argv.concat(Object.keys(sources)), {
exports.main(argv.concat(Object.keys(sources)), {
stdout: output.stdout,
stderr: output.stderr,
readFile: async (name) => {
try {
return await options.readFile(name);
}catch (e){
return null;
}
},
writeFile: async (name, contents) => await options.writeFile(name, contents),
readFile: name => sources.hasOwnProperty(name) ? sources[name] : null,
writeFile: (name, contents) => output[name] = contents,
listFiles: () => []
});
debugger;
return output;
}

/** Runs the command line utility using the specified arguments array. */
exports.main = async function main(argv, options, callback) {
exports.main = function main(argv, options, callback) {
if (typeof options === "function") {
callback = options;
options = {};
Expand Down Expand Up @@ -234,7 +226,7 @@ exports.main = async function main(argv, options, callback) {

// Begin parsing
var parser = null;
debugger;

// Include library files
if (!args.noLib) {
Object.keys(exports.libraryFiles).forEach(libPath => {
Expand Down Expand Up @@ -276,7 +268,7 @@ exports.main = async function main(argv, options, callback) {
}
for (let j = 0, l = libFiles.length; j < l; ++j) {
let libPath = libFiles[j];
let libText = readFile(libPath, libDir);
let libText = readFile(path.join(libDir, libPath));
if (libText === null) return callback(Error("Library file '" + libPath + "' not found."));
stats.parseCount++;
stats.parseTime += measure(() => {
Expand All @@ -291,9 +283,31 @@ exports.main = async function main(argv, options, callback) {
}
}

// Parses the backlog of imported files after including entry files
function parseBacklog() {
var sourcePath, sourceText;
// Include entry files
for (let i = 0, k = argv.length; i < k; ++i) {
const filename = argv[i];

let sourcePath = String(filename).replace(/\\/g, "/").replace(/(\.ts|\/)$/, "");

// Try entryPath.ts, then entryPath/index.ts
let sourceText = readFile(path.join(baseDir, sourcePath) + ".ts");
if (sourceText === null) {
sourceText = readFile(path.join(baseDir, sourcePath, "index.ts"));
if (sourceText === null) {
return callback(Error("Entry file '" + sourcePath + ".ts' not found."));
} else {
sourcePath += "/index.ts";
}
} else {
sourcePath += ".ts";
}

stats.parseCount++;
stats.parseTime += measure(() => {
parser = assemblyscript.parseFile(sourceText, sourcePath, true, parser);
});

// Process backlog
while ((sourcePath = parser.nextFile()) != null) {

// Load library file if explicitly requested
Expand All @@ -308,12 +322,13 @@ exports.main = async function main(argv, options, callback) {
sourcePath = exports.libraryPrefix + indexName + ".ts";
} else {
for (let i = 0, k = customLibDirs.length; i < k; ++i) {
sourceText = readFile(plainName + ".ts", customLibDirs[i]);
const dir = customLibDirs[i];
sourceText = readFile(path.join(dir, plainName + ".ts"));
if (sourceText !== null) {
sourcePath = exports.libraryPrefix + plainName + ".ts";
break;
} else {
sourceText = readFile(indexName + ".ts", customLibDirs[i]);
sourceText = readFile(path.join(dir, indexName + ".ts"));
if (sourceText !== null) {
sourcePath = exports.libraryPrefix + indexName + ".ts";
break;
Expand All @@ -326,11 +341,11 @@ exports.main = async function main(argv, options, callback) {
} else {
const plainName = sourcePath;
const indexName = sourcePath + "/index";
sourceText = readFile(plainName + ".ts", baseDir);
sourceText = readFile(path.join(baseDir, plainName + ".ts"));
if (sourceText !== null) {
sourcePath = plainName + ".ts";
} else {
sourceText = readFile(indexName + ".ts", baseDir);
sourceText = readFile(path.join(baseDir, indexName + ".ts"));
if (sourceText !== null) {
sourcePath = indexName + ".ts";
} else if (!plainName.startsWith(".")) {
Expand All @@ -343,12 +358,12 @@ exports.main = async function main(argv, options, callback) {
} else {
for (let i = 0, k = customLibDirs.length; i < k; ++i) {
const dir = customLibDirs[i];
sourceText = readFile(plainName + ".ts", customLibDirs[i]);
sourceText = readFile(path.join(dir, plainName + ".ts"));
if (sourceText !== null) {
sourcePath = exports.libraryPrefix + plainName + ".ts";
break;
} else {
sourceText = readFile(indexName + ".ts", customLibDirs[i]);
sourceText = readFile(path.join(dir, indexName + ".ts"));
if (sourceText !== null) {
sourcePath = exports.libraryPrefix + indexName + ".ts";
break;
Expand Down Expand Up @@ -430,9 +445,7 @@ exports.main = async function main(argv, options, callback) {
assemblyscript.setNoTreeShaking(compilerOptions, args.noTreeShaking);
assemblyscript.setNoAssert(compilerOptions, args.noAssert);
assemblyscript.setImportMemory(compilerOptions, args.importMemory);
assemblyscript.setSharedMemory(compilerOptions, args.sharedMemory);
assemblyscript.setImportTable(compilerOptions, args.importTable);
assemblyscript.ignoreDataSegments(compilerOptions, args.ignoreDataSegments);
assemblyscript.setMemoryBase(compilerOptions, args.memoryBase >>> 0);
assemblyscript.setSourceMap(compilerOptions, args.sourceMap != null);
assemblyscript.setOptimizeLevelHints(compilerOptions, optimizeLevel, shrinkLevel);
Expand Down Expand Up @@ -565,7 +578,7 @@ exports.main = async function main(argv, options, callback) {
args.binaryFile = args.outFile;
}
}
debugger;

// Write binary
if (args.binaryFile != null) {
let sourceMapURL = args.sourceMap != null
Expand All @@ -581,7 +594,7 @@ exports.main = async function main(argv, options, callback) {
});

if (args.binaryFile.length) {
writeFile(args.binaryFile, wasm.output, baseDir);
writeFile(path.join(baseDir, args.binaryFile), wasm.output);
} else {
writeStdout(wasm.output);
hasStdout = true;
Expand All @@ -593,20 +606,23 @@ exports.main = async function main(argv, options, callback) {
if (args.binaryFile.length) {
let sourceMap = JSON.parse(wasm.sourceMap);
sourceMap.sourceRoot = exports.sourceMapRoot;
sourceMap.sources.forEach(async (name, index) => {
sourceMap.sources.forEach((name, index) => {
let text = null;
if (name.startsWith(exports.libraryPrefix)) {
let stdName = name.substring(exports.libraryPrefix.length).replace(/\.ts$/, "");
if (exports.libraryFiles.hasOwnProperty(stdName)) {
text = exports.libraryFiles[stdName];
} else {
for (let i = 0, k = customLibDirs.length; i < k; ++i) {
text = readFile(name.substring(exports.libraryPrefix.length), customLibDirs[i]);
text = readFile(path.join(
customLibDirs[i],
name.substring(exports.libraryPrefix.length))
);
if (text !== null) break;
}
}
} else {
text = readFile(name, baseDir);
text = readFile(path.join(baseDir, name));
}
if (text === null) {
return callback(Error("Source file '" + name + "' not found."));
Expand All @@ -615,6 +631,7 @@ exports.main = async function main(argv, options, callback) {
sourceMap.sourceContents[index] = text;
});
writeFile(path.join(
baseDir,
path.dirname(args.binaryFile),
path.basename(sourceMapURL)
).replace(/^\.\//, ""), JSON.stringify(sourceMap), baseDir);
Expand All @@ -632,7 +649,7 @@ exports.main = async function main(argv, options, callback) {
stats.emitTime += measure(() => {
asm = module.toAsmjs();
});
writeFile(args.asmjsFile, asm, baseDir);
writeFile(path.join(baseDir, args.asmjsFile), asm);
} else if (!hasStdout) {
stats.emitCount++;
stats.emitTime += measure(() => {
Expand All @@ -652,7 +669,7 @@ exports.main = async function main(argv, options, callback) {
stats.emitTime += measure(() => {
idl = assemblyscript.buildIDL(program);
});
writeFile(args.idlFile, idl, baseDir);
writeFile(path.join(baseDir, args.idlFile), idl);
} else if (!hasStdout) {
stats.emitCount++;
stats.emitTime += measure(() => {
Expand All @@ -672,7 +689,7 @@ exports.main = async function main(argv, options, callback) {
stats.emitTime += measure(() => {
tsd = assemblyscript.buildTSD(program);
});
writeFile(args.tsdFile, tsd, baseDir);
writeFile(path.join(baseDir, args.tsdFile), tsd);
} else if (!hasStdout) {
stats.emitCount++;
stats.emitTime += measure(() => {
Expand All @@ -692,7 +709,7 @@ exports.main = async function main(argv, options, callback) {
stats.emitTime += measure(() => {
wat = module.toText();
});
writeFile(args.textFile, wat, baseDir);
writeFile(path.join(baseDir, args.textFile), wat);
} else if (!hasStdout) {
stats.emitCount++;
stats.emitTime += measure(() => {
Expand Down
10 changes: 0 additions & 10 deletions cli/asc.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,6 @@
"type": "b",
"default": false
},
"sharedMemory": {
"description": "Declare memory as shared.",
"type": "i",
"default": 0
},
"ignoreDataSegments": {
"description": "Ingore data segments to binary. Default false.",
"type": "b",
"default": false
},
"memoryBase": {
"description": "Sets the start offset of compiler-generated static memory.",
"type": "i",
Expand Down
4 changes: 4 additions & 0 deletions dist/asc.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion dist/asc.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions dist/assemblyscript.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion dist/assemblyscript.js.map

Large diffs are not rendered by default.

23 changes: 0 additions & 23 deletions examples/atomic-shared-memory/assembly/index.js

This file was deleted.

Loading

0 comments on commit fbce899

Please sign in to comment.