diff --git a/README.md b/README.md new file mode 100644 index 0000000..d756178 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Empty AssemblyScript Project diff --git a/assembly/main.ts b/assembly/main.ts new file mode 100644 index 0000000..225079c --- /dev/null +++ b/assembly/main.ts @@ -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()) +} diff --git a/assembly/tsconfig.json b/assembly/tsconfig.json new file mode 100644 index 0000000..c76b0d8 --- /dev/null +++ b/assembly/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../node_modules/assemblyscript/std/assembly.json", + "include": [ + "./**/*.ts" + ] +} diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..7a167f9 --- /dev/null +++ b/gulpfile.js @@ -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, + }); +}); diff --git a/out/main.wasm b/out/main.wasm new file mode 100644 index 0000000..9ae059e Binary files /dev/null and b/out/main.wasm differ diff --git a/out/main.wasm.map b/out/main.wasm.map new file mode 100644 index 0000000..2d95272 --- /dev/null +++ b/out/main.wasm.map @@ -0,0 +1 @@ +{"version":3,"sources":["main.ts"],"names":[],"mappings":"6HAS6B,AAEX,EAAG","sourceRoot":"assemblyscript:///","sourceContents":["// ewasm imports\ndeclare function ethereum_return(dataOffset: i32, length: i32): void;\ndeclare function ethereum_revert(dataOffset: i32, length: i32): void;\ndeclare function ethereum_callDataCopy(resultOffset: i32, dataOffset: i32, length: i32): void;\ndeclare function ethereum_callDataSize(): i32;\ndeclare function ethereum_storageStore(pathOffset: i32, valueOffset: i32): void;\ndeclare function ethereum_storageLoad(pathOffset: i32, resultOffset: i32): void;\n\n// ewasm main function\nexport function main(): void {\n // assume the memory is already expanded..\n ethereum_return(0, ethereum_callDataSize())\n}\n"]} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..16aeb4c --- /dev/null +++ b/package.json @@ -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" + } +} \ No newline at end of file diff --git a/setup.js b/setup.js new file mode 100644 index 0000000..bfee161 --- /dev/null +++ b/setup.js @@ -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!"); +}); diff --git a/src/main.html b/src/main.html new file mode 100644 index 0000000..1b8d1e2 --- /dev/null +++ b/src/main.html @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..6c2227e --- /dev/null +++ b/src/main.js @@ -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); +