Skip to content

Commit

Permalink
Initial prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Jun 25, 2018
0 parents commit 51d705c
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Empty AssemblyScript Project
15 changes: 15 additions & 0 deletions assembly/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// ewasm imports
declare function ethereum_return(dataOffset: i32, length: i32): void;
declare function ethereum_revert(dataOffset: i32, length: i32): void;
declare function ethereum_callDataCopy(resultOffset: i32, dataOffset: i32, length: i32): void;
declare function ethereum_callDataSize(): i32;
declare function ethereum_storageStore(pathOffset: i32, valueOffset: i32): void;
declare function ethereum_storageLoad(pathOffset: i32, resultOffset: i32): void;

// TODO: need to implement a nice wrapper over the native functions which use native types and handle the memory

// ewasm main function
export function main(): void {
// assume the memory is already expanded..
ethereum_return(0, ethereum_callDataSize())
}
6 changes: 6 additions & 0 deletions assembly/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../node_modules/assemblyscript/std/assembly.json",
"include": [
"./**/*.ts"
]
}
24 changes: 24 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const gulp = require("gulp");

gulp.task("build", callback => {
const asc = require("assemblyscript/bin/asc");
asc.main([
"main.ts",
"--baseDir", "assembly",
"--binaryFile", "../out/main.wasm",
"--sourceMap",
"--measure"
], callback);
});

gulp.task("default", ["build"]);

gulp.task("project:load", () => { // WebAssembly Studio only
const utils = require("@wasm/studio-utils");
utils.eval(utils.project.getFile("setup.js").getData(), {
logLn,
project,
monaco,
fileTypeForExtension,
});
});
Binary file added out/main.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions out/main.wasm.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@wasm/empty_ts",
"description": "",
"version": "1.0.0",
"scripts": {
"build": "gulp"
},
"devDependencies": {
"assemblyscript": "AssemblyScript/assemblyscript",
"gulp": "^3.9.1"
},
"wasmStudio": {
"name": "Empty AssemblyScript Project",
"description": "# Empty AssemblyScript Project\n\n[AssemblyScript](https://github.com/AssemblyScript/assemblyscript) compiles strictly typed TypeScript to WebAssembly using Binaryen.\n\nSee the [AssemblyScript wiki](https://github.com/AssemblyScript/assemblyscript/wiki) for further instructions and documentation.",
"icon": "typescript-lang-file-icon"
}
}
33 changes: 33 additions & 0 deletions setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// WebAssembly Studio only
require.config({
paths: {
"binaryen": "https://rawgit.com/AssemblyScript/binaryen.js/master/index",
"assemblyscript": "https://rawgit.com/AssemblyScript/assemblyscript/master/dist/assemblyscript",
"assemblyscript/bin/asc": "https://rawgit.com/AssemblyScript/assemblyscript/master/dist/asc"
}
});
logLn("Loading AssemblyScript compiler ...");
require(["assemblyscript/bin/asc"], asc => {
monaco.languages.typescript.typescriptDefaults.addExtraLib(asc.definitionFiles.assembly);
asc.main = (main => (args, options, fn) => {
if (typeof options === "function") {
fn = options;
options = undefined;
}
return main(args, options || {
stdout: asc.createMemoryStream(),
stderr: asc.createMemoryStream(logLn),
readFile: (filename) => {
const file = project.getFile(filename.replace(/^\//, ""));
return file ? file.data : null;
},
writeFile: (filename, contents) => {
const name = filename.startsWith("/") ? filename.substring(1) : filename;
const type = fileTypeForExtension(name.substring(name.lastIndexOf(".") + 1));
project.newFile(name, type, true).setData(contents);
},
listFiles: (dirname) => []
}, fn);
})(asc.main);
logLn("AssemblyScript compiler is ready!");
});
10 changes: 10 additions & 0 deletions src/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body style="background: #fff">
<span id="container"></span>
<script src="./main.js"></script>
</body>
</html>
15 changes: 15 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
WebAssembly.instantiateStreaming(fetch("../out/main.wasm"), {
env: {
ethereum_callDataSize: function() {
console.log("callDataSize -> 32");
return 32;
},
ethereum_return: function(offest, length) {
console.log("return(" + offset + "," + length + ")");
}
}
}).then(result => {
const exports = result.instance.exports;
exports.main();
}).catch(console.error);

0 comments on commit 51d705c

Please sign in to comment.