├── tests ├── compiler │ ├── empty.ts │ ├── runtime-full.ts │ ├── runtime-half.ts │ ├── runtime-none.ts │ ├── runtime-stub.ts │ ├── wildcard-export.ts │ ├── exportimport-table.ts │ ├── features │ │ ├── README.md │ │ ├── reference-types.json │ │ ├── simd.json │ │ ├── mutable-globals.json │ │ ├── js-bigint-integration.json │ │ ├── threads.json │ │ ├── mutable-globals.ts │ │ ├── js-bigint-integration.ts │ │ ├── reference-types.js │ │ ├── mutable-globals.js │ │ └── js-bigint-integration.js │ ├── export-default.ts │ ├── if.json │ ├── abi.json │ ├── assert.json │ ├── binary.json │ ├── bool.json │ ├── class.json │ ├── comma.json │ ├── declare.json │ ├── enum.json │ ├── export.json │ ├── exports.json │ ├── import.json │ ├── limits.json │ ├── logical.json │ ├── memcpy.json │ ├── memmove.json │ ├── memset.json │ ├── merge.json │ ├── new.json │ ├── number.json │ ├── rt │ │ ├── ids.json │ │ ├── ids.optimized.wat │ │ ├── instanceof.json │ │ ├── stub-realloc.json │ │ ├── flags.json │ │ ├── ids.untouched.wat │ │ └── ids.ts │ ├── scoped.json │ ├── std │ │ ├── mod.json │ │ ├── new.json │ │ ├── date.json │ │ ├── hash.json │ │ ├── libm.json │ │ ├── math.json │ │ ├── pointer.json │ │ ├── simd.json │ │ ├── symbol.json │ │ ├── array-access.json │ │ ├── object.json │ │ ├── polyfills.json │ │ ├── static-array.json │ │ ├── object-literal.json │ │ ├── operator-overloading.json │ │ ├── simd.optimized.wat │ │ ├── map.json │ │ ├── set.json │ │ ├── trace.json │ │ ├── dataview.json │ │ ├── array-literal.json │ │ ├── arraybuffer.json │ │ ├── string-encoding.json │ │ ├── array.json │ │ ├── string.json │ │ ├── typedarray.json │ │ ├── mod.js │ │ ├── libm.ts │ │ ├── simd.untouched.wat │ │ ├── math.js │ │ ├── polyfills.optimized.wat │ │ ├── new.ts │ │ ├── trace.ts │ │ ├── date.ts │ │ ├── array-access.ts │ │ ├── object-literal.ts │ │ ├── string.js │ │ ├── hash.ts │ │ └── static-array.ts │ ├── switch.json │ ├── ternary.json │ ├── unary.json │ ├── void.json │ ├── ReturnType.json │ ├── builtins.json │ ├── call-super.json │ ├── constructor.json │ ├── continue.json │ ├── empty.json │ ├── external.json │ ├── function.json │ ├── getter-call.json │ ├── i64-polyfill.json │ ├── infer-array.json │ ├── infer-type.json │ ├── inlining.json │ ├── instanceof.json │ ├── literals.json │ ├── loop-flow.json │ ├── loop-wrap.json │ ├── mandelbrot.json │ ├── many-locals.json │ ├── namespace.json │ ├── overflow.json │ ├── recursive.json │ ├── reexport.json │ ├── rereexport.json │ ├── resolve-new.json │ ├── retain-i32.json │ ├── static-this.json │ ├── typealias.json │ ├── asc-constants.json │ ├── assert-nonnull.json │ ├── call-inferred.json │ ├── call-optional.json │ ├── class-extends.json │ ├── class-overloading.json │ ├── export-default.json │ ├── extends-recursive.json │ ├── function-types.json │ ├── getter-setter.json │ ├── indexof-valueof.json │ ├── infer-generic.json │ ├── instanceof-class.json │ ├── possibly-null.json │ ├── resolve-binary.json │ ├── resolve-nested.json │ ├── resolve-unary.json │ ├── runtime-full.json │ ├── runtime-half.json │ ├── runtime-none.json │ ├── runtime-stub.json │ ├── wildcard-export.json │ ├── class-static-function.json │ ├── function-expression.json │ ├── inlining-blocklocals.json │ ├── inlining-recursive.json │ ├── named-export-default.json │ ├── named-import-default.json │ ├── portable-conversions.json │ ├── resolve-access.json │ ├── resolve-elementaccess.json │ ├── resolve-propertyaccess.json │ ├── wasi-snapshot-preview1.json │ ├── assert.optimized.wat │ ├── basic-nullable.ts │ ├── empty.optimized.wat │ ├── extends-baseaggregate.json │ ├── import.optimized.wat │ ├── limits.optimized.wat │ ├── mandelbrot.ts │ ├── merge.optimized.wat │ ├── optional-typeparameters.json │ ├── resolve-function-expression.json │ ├── void.optimized.wat │ ├── ReturnType.optimized.wat │ ├── function.optimized.wat │ ├── literals.optimized.wat │ ├── runtime-half.optimized.wat │ ├── runtime-none.optimized.wat │ ├── tablebase.optimized.wat │ ├── asc-constants.optimized.wat │ ├── indexof-valueof.optimized.wat │ ├── tablebase.json │ ├── typeof.json │ ├── issues │ │ ├── 1095.json │ │ └── 1095.ts │ ├── memorybase.json │ ├── named-export-default.ts │ ├── resolve-new.ts │ ├── retain-release.json │ ├── retain-return.json │ ├── rc │ │ ├── global-init.json │ │ ├── local-init.json │ │ ├── optimize.json │ │ ├── logical-or-mismatch.json │ │ ├── ternary-mismatch.json │ │ ├── logical-and-mismatch.json │ │ ├── rereturn.ts │ │ ├── global-init.ts │ │ ├── local-init.ts │ │ ├── logical-and-mismatch.ts │ │ └── logical-or-mismatch.ts │ ├── assert.untouched.wat │ ├── empty.untouched.wat │ ├── implicit-getter-setter.json │ ├── retain-release-sanity.json │ ├── tsconfig.json │ ├── ReturnType.untouched.wat │ ├── extends-recursive.ts │ ├── extends-self.ts │ ├── recursive.ts │ ├── do.json │ ├── for.json │ ├── indexof-valueof.untouched.wat │ ├── runtime-half.untouched.wat │ ├── runtime-none.untouched.wat │ ├── while.json │ ├── nullable.ts │ ├── exportimport-table.json │ ├── extends-self.json │ ├── managed-cast.json │ ├── rereexport.ts │ ├── static-this.ts │ ├── named-import-default.ts │ ├── implicit-getter-setter.ts │ ├── tablebase.ts │ ├── basic-nullable.json │ ├── bool.optimized.wat │ ├── exportimport-table.js │ ├── nullable.json │ ├── overflow.optimized.wat │ ├── memorybase.optimized.wat │ ├── memorybase.ts │ ├── void.ts │ ├── class-extends.ts │ ├── static-this.optimized.wat │ ├── closure.json │ ├── getter-call.ts │ ├── class-static-function.ts │ ├── assert.ts │ ├── declare.js │ ├── ternary.ts │ ├── portable-conversions.optimized.wat │ ├── class-overloading.optimized.wat │ ├── inlining-recursive.ts │ ├── external.js │ ├── resolve-function-expression.ts │ ├── typealias.optimized.wat │ ├── named-export-default.optimized.wat │ ├── named-import-default.optimized.wat │ ├── export-default.optimized.wat │ ├── getter-setter.ts │ ├── typealias.untouched.wat │ ├── named-export-default.untouched.wat │ ├── wasi-snapshot-preview1.optimized.wat │ ├── continue.ts │ ├── export-default.untouched.wat │ ├── typealias.ts │ ├── declare.ts │ ├── extends-baseaggregate.ts │ ├── memorybase.untouched.wat │ ├── bool.ts │ ├── constant-assign.json │ ├── exportimport-table.optimized.wat │ ├── rereexport.optimized.wat │ ├── class-overloading.ts │ ├── resolve-elementaccess.ts │ ├── tablebase.untouched.wat │ ├── wildcard-export.optimized.wat │ ├── ternary.optimized.wat │ ├── asc-constants.ts │ ├── external.ts │ ├── literals.ts │ ├── named-import-default.untouched.wat │ ├── duplicate-identifier.ts │ ├── ReturnType.ts │ ├── i64-polyfill.ts │ ├── inlining-recursive.optimized.wat │ ├── namespace.optimized.wat │ ├── class-extends.optimized.wat │ ├── comma.ts │ ├── new.ts │ ├── duplicate-identifier.json │ ├── loop-wrap.ts │ ├── recursive.optimized.wat │ ├── limits.ts │ ├── call-optional.ts │ ├── reexport.ts │ ├── ternary.untouched.wat │ ├── recursive.untouched.wat │ ├── inlining-recursive.untouched.wat │ ├── resolve-access.ts │ ├── inlining-blocklocals.ts │ ├── closure.ts │ ├── constant-assign.ts │ ├── call-inferred.ts │ ├── optional-typeparameters.ts │ ├── exportimport-table.untouched.wat │ ├── external.optimized.wat │ ├── instanceof-class.ts │ ├── class.optimized.wat │ ├── export.ts │ ├── external.untouched.wat │ ├── void.untouched.wat │ ├── call-inferred.optimized.wat │ ├── import.ts │ ├── continue.optimized.wat │ ├── wasi-snapshot-preview1.untouched.wat │ ├── class-static-function.optimized.wat │ ├── retain-release-sanity.ts │ ├── scoped.ts │ ├── abi.optimized.wat │ └── scoped.optimized.wat ├── parser │ ├── empty.ts │ ├── empty.ts.fixture.ts │ ├── call-function-return.ts │ ├── call-function-return.ts.fixture.ts │ ├── optional-property.ts │ ├── index-declaration.ts │ ├── do.ts │ ├── index-declaration.ts.fixture.ts │ ├── do.ts.fixture.ts │ ├── propertyelementaccess.ts │ ├── type.ts │ ├── propertyelementaccess.ts.fixture.ts │ ├── type.ts.fixture.ts │ ├── interface.ts │ ├── class-expression.ts │ ├── interface.ts.fixture.ts │ ├── tsconfig.json │ ├── class-expression.ts.fixture.ts │ ├── calls.ts.fixture.ts │ ├── nonNullAssertion.ts │ ├── while.ts │ ├── enum.ts │ ├── for.ts │ ├── while.ts.fixture.ts │ ├── nonNullAssertion.ts.fixture.ts │ ├── for.ts.fixture.ts │ ├── optional-property.ts.fixture.ts │ ├── enum.ts.fixture.ts │ ├── continue-on-error.ts │ ├── arrow-functions.ts.fixture.ts │ ├── function-type.ts │ ├── optional-typeparameters.ts │ ├── object-literal.ts │ ├── object-literal.ts.fixture.ts │ ├── definite-assignment-assertion.ts │ ├── arrow-functions.ts │ ├── function-type.ts.fixture.ts │ ├── export-default.ts │ ├── decorators.ts │ ├── export-default.ts.fixture.ts │ ├── var.ts │ ├── continue-on-error.ts.fixture.ts │ ├── decorators.ts.fixture.ts │ ├── calls.ts │ ├── constructor.ts │ ├── constructor.ts.fixture.ts │ ├── import.ts │ ├── import.ts.fixture.ts │ ├── var.ts.fixture.ts │ ├── function.ts │ ├── function-expression.ts │ ├── optional-typeparameters.ts.fixture.ts │ ├── function-expression.ts.fixture.ts │ ├── function.ts.fixture.ts │ ├── type-signature.ts │ ├── type-signature.ts.fixture.ts │ ├── numeric-separators.ts │ ├── reserved-keywords.ts.fixture.ts │ ├── reserved-keywords.ts │ ├── regexp.ts │ ├── trailing-commas.ts.fixture.ts │ ├── namespace.ts │ ├── regexp.ts.fixture.ts │ ├── parameter-order.ts │ ├── also-identifier.ts.fixture.ts │ ├── definite-assignment-assertion.ts.fixture.ts │ ├── namespace.ts.fixture.ts │ ├── literals.ts.fixture.ts │ ├── trailing-commas.ts │ ├── parameter-order.ts.fixture.ts │ ├── literals.ts │ └── also-identifier.ts ├── .gitignore ├── runtime │ ├── assembly │ │ ├── index.ts │ │ └── tsconfig.json │ ├── .gitignore │ ├── untouched.wasm │ └── package.json ├── packages │ ├── packages │ │ ├── a │ │ │ └── assembly │ │ │ │ ├── index.ts │ │ │ │ └── a.ts │ │ ├── as │ │ │ ├── as │ │ │ │ ├── index.ts │ │ │ │ └── as.ts │ │ │ └── package.json │ │ ├── b │ │ │ ├── assembly │ │ │ │ ├── index.ts │ │ │ │ └── b.ts │ │ │ └── node_modules │ │ │ │ └── a │ │ │ │ └── assembly │ │ │ │ ├── index.ts │ │ │ │ └── a.ts │ │ ├── c │ │ │ ├── assembly │ │ │ │ ├── index.ts │ │ │ │ └── c.ts │ │ │ └── node_modules │ │ │ │ └── b │ │ │ │ ├── assembly │ │ │ │ ├── index.ts │ │ │ │ └── b.ts │ │ │ │ └── node_modules │ │ │ │ └── a │ │ │ │ └── assembly │ │ │ │ ├── index.ts │ │ │ │ └── a.ts │ │ ├── d │ │ │ ├── assembly │ │ │ │ ├── index.ts │ │ │ │ └── d.ts │ │ │ ├── node_modules │ │ │ │ ├── c │ │ │ │ │ ├── assembly │ │ │ │ │ │ ├── index.ts │ │ │ │ │ │ └── c.ts │ │ │ │ │ └── node_modules │ │ │ │ │ │ └── b │ │ │ │ │ │ ├── assembly │ │ │ │ │ │ ├── index.ts │ │ │ │ │ │ └── b.ts │ │ │ │ │ │ └── node_modules │ │ │ │ │ │ └── a │ │ │ │ │ │ └── assembly │ │ │ │ │ │ ├── index.ts │ │ │ │ │ │ └── a.ts │ │ │ │ └── as │ │ │ │ │ ├── notassembly │ │ │ │ │ ├── index.ts │ │ │ │ │ └── as.ts │ │ │ │ │ └── package.json │ │ │ └── packages │ │ │ │ └── e │ │ │ │ ├── assembly │ │ │ │ ├── index.ts │ │ │ │ └── e.ts │ │ │ │ └── packages │ │ │ │ └── f │ │ │ │ └── assembly │ │ │ │ ├── index.ts │ │ │ │ └── f.ts │ │ ├── g │ │ │ ├── assembly │ │ │ │ ├── index.ts │ │ │ │ └── g.ts │ │ │ ├── node_modules │ │ │ │ └── c │ │ │ │ │ ├── assembly │ │ │ │ │ ├── index.ts │ │ │ │ │ └── c.ts │ │ │ │ │ └── node_modules │ │ │ │ │ └── b │ │ │ │ │ ├── assembly │ │ │ │ │ ├── index.ts │ │ │ │ │ └── b.ts │ │ │ │ │ └── node_modules │ │ │ │ │ └── a │ │ │ │ │ └── assembly │ │ │ │ │ ├── index.ts │ │ │ │ │ └── a.ts │ │ │ └── test.js │ │ └── h │ │ │ ├── node_modules │ │ │ └── @foo │ │ │ │ └── bar │ │ │ │ ├── node_modules │ │ │ │ └── @bar │ │ │ │ │ └── baz │ │ │ │ │ └── assembly │ │ │ │ │ └── index.ts │ │ │ │ └── assembly │ │ │ │ └── index.ts │ │ │ └── assembly │ │ │ └── index.ts │ ├── .gitignore │ └── tsconfig.json ├── allocators │ ├── rt-full │ │ ├── assembly │ │ │ ├── index.ts │ │ │ └── tsconfig.json │ │ └── package.json │ ├── rt-stub │ │ ├── assembly │ │ │ ├── index.ts │ │ │ └── tsconfig.json │ │ └── package.json │ ├── buddy │ │ ├── assembly │ │ │ ├── index.ts │ │ │ └── tsconfig.json │ │ └── package.json │ ├── package.json │ └── forever.js ├── resolve-ternary.json ├── binaryen │ ├── unreachable-loop.wat │ ├── const-global.wat │ ├── optimize-if-eqz.wat │ ├── multi-value.js │ ├── precompute-join.wat │ ├── const-expr.wat │ ├── set_global-immutable.js │ ├── optimize-if-eqz.js │ ├── const-global.js │ ├── const-local.js │ ├── get_global-missing.js │ ├── block-stack.js │ ├── get_local-missing.js │ ├── i64-binary-result.js │ ├── block-pre.js │ ├── break-value.js │ ├── asmjs.wat │ ├── constant-indirect.js │ └── unreachable-loop.js ├── require │ ├── index.ts │ └── index-release.ts └── util-path.js ├── examples ├── n-body │ ├── rust │ │ ├── .gitignore │ │ ├── Cargo.lock │ │ ├── README.md │ │ ├── Cargo.toml │ │ └── index.js │ ├── build │ │ ├── .gitignore │ │ ├── optimized.wasm │ │ └── rust.optimized.wasm │ ├── assembly │ │ ├── tsconfig.json │ │ └── index.js │ └── scripts │ │ └── postprocess-asmjs.js ├── transform │ ├── assembly │ │ └── index.ts │ ├── README.md │ └── package.json ├── pson │ ├── build │ │ └── .gitignore │ ├── assembly │ │ └── tsconfig.json │ ├── README.md │ ├── tests │ │ └── index.js │ └── package.json ├── game-of-life │ ├── build │ │ ├── .gitignore │ │ ├── optimized.wasm │ │ └── optimized.d.ts │ ├── assembly │ │ ├── tsconfig.json │ │ └── config.ts │ ├── README.md │ └── package.json ├── mandelbrot │ ├── build │ │ ├── .gitignore │ │ ├── optimized.wasm │ │ └── optimized.d.ts │ ├── assembly │ │ └── tsconfig.json │ ├── index.js │ ├── README.md │ └── package.json ├── .gitignore └── sdk │ └── README.md ├── lib ├── parse │ ├── index.d.ts │ ├── build │ │ └── .gitignore │ ├── tests │ │ └── libm.wasm │ ├── assembly │ │ └── tsconfig.json │ └── src │ │ └── tsconfig.json ├── libm │ ├── build │ │ └── .gitignore │ ├── index.d.ts │ ├── assembly │ │ └── tsconfig.json │ ├── README.md │ └── index.js ├── i64 │ ├── build │ │ └── .gitignore │ ├── assembly │ │ └── tsconfig.json │ └── index.js ├── loader │ └── tests │ │ └── build │ │ ├── legacy.wasm │ │ └── default.wasm ├── rtrace │ └── package.json ├── lint │ ├── src │ │ └── tsconfig.json │ ├── index.json │ └── package.json └── webpack │ ├── package.json │ └── README.md ├── .github ├── FUNDING.yml └── stale.yml ├── src ├── glue │ ├── README.md │ ├── wasm │ │ ├── tsconfig.json │ │ ├── index.ts │ │ └── float.ts │ └── js │ │ ├── node.d.ts │ │ ├── index.ts │ │ ├── float.d.ts │ │ └── float.js ├── extra │ ├── README.md │ └── tsconfig.json ├── tsconfig.json ├── util │ ├── index.ts │ └── text.ts └── README.md ├── std ├── assembly │ ├── rt │ │ ├── index-half.ts │ │ ├── index-none.ts │ │ ├── index-stub.ts │ │ ├── index-full.ts │ │ └── rtrace.ts │ ├── compat.ts │ ├── bindings │ │ ├── wasi.ts │ │ ├── Date.ts │ │ ├── Reflect.ts │ │ ├── console.ts │ │ └── asyncify.ts │ ├── heap.ts │ ├── vector.ts │ ├── tsconfig.json │ ├── reference.ts │ ├── shared │ │ ├── tsconfig.json │ │ └── target.ts │ ├── diagnostics.ts │ ├── gc.ts │ ├── regexp.ts │ └── table.ts ├── types │ ├── assembly │ │ ├── index.d.ts │ │ └── package.json │ └── portable │ │ ├── index.d.ts │ │ └── package.json ├── README.md ├── portable.json └── assembly.json ├── index.d.ts ├── index.release.js ├── media ├── icon.png └── architecture.png ├── scripts ├── postpublish-files.json ├── build.js ├── clean.js ├── build-sdk.js └── postpublish.js ├── .gitignore ├── index.release.d.ts ├── cli ├── transform.js └── util │ ├── mkdirp.d.ts │ ├── find.d.ts │ └── find.js ├── .gitattributes ├── tsconfig-docs.json ├── index.js ├── tsconfig-base.json ├── snap ├── README.md └── snapcraft.yaml └── bin └── asc /tests/compiler/empty.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/parser/empty.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/compiler/runtime-full.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/compiler/runtime-half.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/compiler/runtime-none.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/compiler/runtime-stub.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/parser/empty.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/n-body/rust/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | -------------------------------------------------------------------------------- /lib/parse/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from "./src"; 2 | -------------------------------------------------------------------------------- /examples/transform/assembly/index.ts: -------------------------------------------------------------------------------- 1 | // empty 2 | -------------------------------------------------------------------------------- /lib/libm/build/.gitignore: -------------------------------------------------------------------------------- 1 | *.wasm 2 | *.wasm.map 3 | -------------------------------------------------------------------------------- /lib/parse/build/.gitignore: -------------------------------------------------------------------------------- 1 | *.wasm 2 | *.wasm.map 3 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | *.wasm 2 | *.wasm.map 3 | temp.* 4 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | open_collective: assemblyscript 2 | -------------------------------------------------------------------------------- /src/glue/README.md: -------------------------------------------------------------------------------- 1 | Environment specific glue code. 2 | -------------------------------------------------------------------------------- /std/assembly/rt/index-half.ts: -------------------------------------------------------------------------------- 1 | import "rt/index-full"; 2 | -------------------------------------------------------------------------------- /std/assembly/rt/index-none.ts: -------------------------------------------------------------------------------- 1 | import "rt/index-stub"; 2 | -------------------------------------------------------------------------------- /tests/parser/call-function-return.ts: -------------------------------------------------------------------------------- 1 | a = fn()(1, 2); 2 | -------------------------------------------------------------------------------- /tests/runtime/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export { __free }; 2 | -------------------------------------------------------------------------------- /lib/i64/build/.gitignore: -------------------------------------------------------------------------------- 1 | *.wasm 2 | *.wasm.map 3 | *.asm.js 4 | -------------------------------------------------------------------------------- /tests/packages/packages/a/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./a"; -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | import "./src/glue/js" 2 | export * from "./src"; 3 | -------------------------------------------------------------------------------- /std/types/assembly/index.d.ts: -------------------------------------------------------------------------------- 1 | import "../../assembly/index"; 2 | -------------------------------------------------------------------------------- /std/types/assembly/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": "index.d.ts" 3 | } -------------------------------------------------------------------------------- /std/types/portable/index.d.ts: -------------------------------------------------------------------------------- 1 | import "../../portable/index"; 2 | -------------------------------------------------------------------------------- /std/types/portable/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": "index.d.ts" 3 | } -------------------------------------------------------------------------------- /tests/allocators/rt-full/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export { __free }; 2 | -------------------------------------------------------------------------------- /tests/allocators/rt-stub/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export { __free }; 2 | -------------------------------------------------------------------------------- /tests/compiler/wildcard-export.ts: -------------------------------------------------------------------------------- 1 | export * from './rereexport'; 2 | -------------------------------------------------------------------------------- /tests/packages/packages/as/as/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./as"; 2 | -------------------------------------------------------------------------------- /tests/packages/packages/b/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./b"; 2 | -------------------------------------------------------------------------------- /tests/packages/packages/c/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./c"; 2 | -------------------------------------------------------------------------------- /tests/packages/packages/d/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./d"; 2 | -------------------------------------------------------------------------------- /tests/packages/packages/g/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./g"; 2 | -------------------------------------------------------------------------------- /tests/parser/call-function-return.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | a = fn()(1, 2); 2 | -------------------------------------------------------------------------------- /tests/parser/optional-property.ts: -------------------------------------------------------------------------------- 1 | class C { 2 | x?: i32; 3 | } 4 | -------------------------------------------------------------------------------- /examples/n-body/build/.gitignore: -------------------------------------------------------------------------------- 1 | *.wasm 2 | *.wasm.map 3 | *.asm.js 4 | -------------------------------------------------------------------------------- /examples/pson/build/.gitignore: -------------------------------------------------------------------------------- 1 | *.wasm 2 | *.wasm.map 3 | *.asm.js 4 | -------------------------------------------------------------------------------- /index.release.js: -------------------------------------------------------------------------------- 1 | module.exports = require("./dist/assemblyscript"); 2 | -------------------------------------------------------------------------------- /std/assembly/compat.ts: -------------------------------------------------------------------------------- 1 | 2 | export type ReturnType = returnof; 3 | -------------------------------------------------------------------------------- /tests/compiler/exportimport-table.ts: -------------------------------------------------------------------------------- 1 | var f = (): void => {}; 2 | f; 3 | -------------------------------------------------------------------------------- /examples/game-of-life/build/.gitignore: -------------------------------------------------------------------------------- 1 | *.wasm 2 | *.wasm.map 3 | *.asm.js 4 | -------------------------------------------------------------------------------- /examples/mandelbrot/build/.gitignore: -------------------------------------------------------------------------------- 1 | *.wasm 2 | *.wasm.map 3 | *.asm.js 4 | -------------------------------------------------------------------------------- /std/assembly/bindings/wasi.ts: -------------------------------------------------------------------------------- 1 | export * from "./wasi_snapshot_preview1"; 2 | -------------------------------------------------------------------------------- /tests/compiler/features/README.md: -------------------------------------------------------------------------------- 1 | Test cases for post-MVP WebAssembly features. -------------------------------------------------------------------------------- /tests/parser/index-declaration.ts: -------------------------------------------------------------------------------- 1 | class A { 2 | [key: i32]: f64; 3 | } 4 | -------------------------------------------------------------------------------- /tests/compiler/export-default.ts: -------------------------------------------------------------------------------- 1 | export default function theDefault(): void {} 2 | -------------------------------------------------------------------------------- /tests/compiler/if.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/packages/packages/as/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "ascMain": "as/index.ts" 3 | } 4 | -------------------------------------------------------------------------------- /tests/packages/packages/b/node_modules/a/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./a"; 2 | -------------------------------------------------------------------------------- /tests/packages/packages/c/node_modules/b/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./b"; 2 | -------------------------------------------------------------------------------- /tests/packages/packages/d/node_modules/c/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./c"; 2 | -------------------------------------------------------------------------------- /tests/packages/packages/d/packages/e/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./e"; 2 | -------------------------------------------------------------------------------- /tests/packages/packages/g/node_modules/c/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./c"; 2 | -------------------------------------------------------------------------------- /tests/parser/do.ts: -------------------------------------------------------------------------------- 1 | do { 2 | ; 3 | } while (a != b); 4 | do b; 5 | while (a); 6 | -------------------------------------------------------------------------------- /media/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/assemblyscript/master/media/icon.png -------------------------------------------------------------------------------- /tests/compiler/abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/assert.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/binary.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/bool.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/class.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/comma.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/declare.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/enum.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/export.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/exports.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/import.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/limits.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/logical.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/memcpy.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/memmove.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/memset.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/merge.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/new.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/number.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/rt/ids.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/scoped.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/std/mod.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/std/new.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/switch.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/ternary.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/unary.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/void.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/packages/packages/d/node_modules/as/notassembly/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./as"; 2 | -------------------------------------------------------------------------------- /tests/parser/index-declaration.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | class A { 2 | [key: i32]: f64; 3 | } 4 | -------------------------------------------------------------------------------- /tests/runtime/.gitignore: -------------------------------------------------------------------------------- 1 | !untouched.wasm 2 | node_modules/ 3 | package-lock.json 4 | -------------------------------------------------------------------------------- /tests/compiler/ReturnType.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/builtins.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/call-super.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/constructor.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/continue.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/empty.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /tests/compiler/external.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/function.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/getter-call.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/i64-polyfill.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/infer-array.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/infer-type.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/inlining.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/instanceof.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/literals.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/loop-flow.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/loop-wrap.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/mandelbrot.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/many-locals.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/namespace.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/overflow.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/recursive.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/reexport.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/rereexport.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/resolve-new.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/retain-i32.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/static-this.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/std/date.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/std/hash.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/std/libm.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/std/math.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/std/pointer.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/std/simd.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/std/symbol.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/typealias.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/packages/packages/c/node_modules/b/node_modules/a/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./a"; -------------------------------------------------------------------------------- /tests/packages/packages/d/packages/e/packages/f/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./f"; 2 | -------------------------------------------------------------------------------- /tests/parser/do.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | do { 2 | ; 3 | } while (a != b); 4 | do b; 5 | while (a); 6 | -------------------------------------------------------------------------------- /tests/resolve-ternary.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /tests/compiler/asc-constants.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/assert-nonnull.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/call-inferred.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/call-optional.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/class-extends.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/class-overloading.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/export-default.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/extends-recursive.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/function-types.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/getter-setter.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/indexof-valueof.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/infer-generic.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/instanceof-class.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/possibly-null.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/resolve-binary.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/resolve-nested.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/resolve-unary.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/runtime-full.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime full" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /tests/compiler/runtime-half.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /tests/compiler/runtime-none.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /tests/compiler/runtime-stub.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime stub" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /tests/compiler/std/array-access.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/std/object.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /tests/compiler/std/polyfills.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/std/static-array.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/wildcard-export.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/packages/packages/a/assembly/a.ts: -------------------------------------------------------------------------------- 1 | export function A(): string { 2 | return "A"; 3 | } 4 | -------------------------------------------------------------------------------- /tests/packages/packages/d/node_modules/c/node_modules/b/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./b"; 2 | -------------------------------------------------------------------------------- /tests/packages/packages/g/node_modules/c/node_modules/b/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./b"; 2 | -------------------------------------------------------------------------------- /tests/parser/propertyelementaccess.ts: -------------------------------------------------------------------------------- 1 | (((this).values[0].prop1.prop2.another[1]).prop)[2]; 2 | -------------------------------------------------------------------------------- /tests/parser/type.ts: -------------------------------------------------------------------------------- 1 | type int32_t = i32; 2 | @nonportable() 3 | export type uint64_t = u64; 4 | -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | *.wasm 2 | *.wasm.map 3 | node_modules/ 4 | npm-debug.log 5 | package-lock.json 6 | -------------------------------------------------------------------------------- /media/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/assemblyscript/master/media/architecture.png -------------------------------------------------------------------------------- /scripts/postpublish-files.json: -------------------------------------------------------------------------------- 1 | [ 2 | "package.json", 3 | "index.js", 4 | "index.d.ts" 5 | ] 6 | -------------------------------------------------------------------------------- /src/extra/README.md: -------------------------------------------------------------------------------- 1 | Extra components that are not ultimately required in a standalone compiler. 2 | -------------------------------------------------------------------------------- /tests/compiler/class-static-function.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/function-expression.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/inlining-blocklocals.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/inlining-recursive.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/named-export-default.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/named-import-default.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/portable-conversions.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/resolve-access.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /tests/compiler/resolve-elementaccess.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/resolve-propertyaccess.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/std/object-literal.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/wasi-snapshot-preview1.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/packages/packages/d/node_modules/as/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "ascMain": "./notassembly/index.ts" 3 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | npm-debug.* 2 | dist/ 3 | docs/ 4 | node_modules/ 5 | out/ 6 | raw/ 7 | .history 8 | *.backup 9 | -------------------------------------------------------------------------------- /std/assembly/heap.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore: decorator 2 | @builtin 3 | export declare const __heap_base: usize; 4 | -------------------------------------------------------------------------------- /tests/compiler/assert.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (export "memory" (memory $0)) 4 | ) 5 | -------------------------------------------------------------------------------- /tests/compiler/basic-nullable.ts: -------------------------------------------------------------------------------- 1 | var a: i32 | null; 2 | 3 | ERROR("EOF"); // mark end and ensure fail 4 | -------------------------------------------------------------------------------- /tests/compiler/empty.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (export "memory" (memory $0)) 4 | ) 5 | -------------------------------------------------------------------------------- /tests/compiler/extends-baseaggregate.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /tests/compiler/import.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (export "memory" (memory $0)) 4 | ) 5 | -------------------------------------------------------------------------------- /tests/compiler/limits.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (export "memory" (memory $0)) 4 | ) 5 | -------------------------------------------------------------------------------- /tests/compiler/mandelbrot.ts: -------------------------------------------------------------------------------- 1 | export { computeLine } from "../../examples/mandelbrot/assembly/index"; 2 | -------------------------------------------------------------------------------- /tests/compiler/merge.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (export "memory" (memory $0)) 4 | ) 5 | -------------------------------------------------------------------------------- /tests/compiler/optional-typeparameters.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/resolve-function-expression.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/rt/ids.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (export "memory" (memory $0)) 4 | ) 5 | -------------------------------------------------------------------------------- /tests/compiler/std/operator-overloading.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ] 5 | } -------------------------------------------------------------------------------- /tests/compiler/void.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (export "memory" (memory $0)) 4 | ) 5 | -------------------------------------------------------------------------------- /tests/parser/propertyelementaccess.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | (((this).values[0].prop1.prop2.another[1]).prop)[2]; 2 | -------------------------------------------------------------------------------- /tests/parser/type.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | type int32_t = i32; 2 | @nonportable() 3 | export type uint64_t = u64; 4 | -------------------------------------------------------------------------------- /index.release.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | export * from "assemblyscript"; 3 | -------------------------------------------------------------------------------- /lib/parse/tests/libm.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/assemblyscript/master/lib/parse/tests/libm.wasm -------------------------------------------------------------------------------- /tests/compiler/ReturnType.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (export "memory" (memory $0)) 4 | ) 5 | -------------------------------------------------------------------------------- /tests/compiler/function.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (export "memory" (memory $0)) 4 | ) 5 | -------------------------------------------------------------------------------- /tests/compiler/literals.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (export "memory" (memory $0)) 4 | ) 5 | -------------------------------------------------------------------------------- /tests/compiler/runtime-half.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (export "memory" (memory $0)) 4 | ) 5 | -------------------------------------------------------------------------------- /tests/compiler/runtime-none.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (export "memory" (memory $0)) 4 | ) 5 | -------------------------------------------------------------------------------- /tests/compiler/std/simd.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (export "memory" (memory $0)) 4 | ) 5 | -------------------------------------------------------------------------------- /tests/compiler/tablebase.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (export "memory" (memory $0)) 4 | ) 5 | -------------------------------------------------------------------------------- /tests/packages/packages/as/as/as.ts: -------------------------------------------------------------------------------- 1 | export function AS(str: string): string { 2 | return str + "S"; 3 | } 4 | -------------------------------------------------------------------------------- /tests/packages/packages/b/node_modules/a/assembly/a.ts: -------------------------------------------------------------------------------- 1 | export function A(): string { 2 | return "A"; 3 | } 4 | -------------------------------------------------------------------------------- /tests/packages/packages/d/node_modules/c/node_modules/b/node_modules/a/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./a"; 2 | -------------------------------------------------------------------------------- /tests/packages/packages/g/node_modules/c/node_modules/b/node_modules/a/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./a"; 2 | -------------------------------------------------------------------------------- /tests/packages/packages/h/node_modules/@foo/bar/node_modules/@bar/baz/assembly/index.ts: -------------------------------------------------------------------------------- 1 | export const h2 = 3; 2 | -------------------------------------------------------------------------------- /tests/parser/interface.ts: -------------------------------------------------------------------------------- 1 | interface Foo { 2 | bar(): void; 3 | baz: i32; 4 | readonly baz2: f64; 5 | } 6 | -------------------------------------------------------------------------------- /cli/transform.js: -------------------------------------------------------------------------------- 1 | // becomes replaced with the actual base by asc 2 | exports.Transform = function Transform() {}; 3 | -------------------------------------------------------------------------------- /std/assembly/vector.ts: -------------------------------------------------------------------------------- 1 | /** Vector abstraction. */ 2 | @sealed @unmanaged 3 | export abstract class V128 { 4 | } 5 | -------------------------------------------------------------------------------- /tests/compiler/asc-constants.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (export "memory" (memory $0)) 4 | ) 5 | -------------------------------------------------------------------------------- /tests/compiler/indexof-valueof.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (export "memory" (memory $0)) 4 | ) 5 | -------------------------------------------------------------------------------- /tests/compiler/std/map.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--use ASC_RTRACE=1" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/compiler/std/set.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--use ASC_RTRACE=1" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/compiler/std/trace.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none", 4 | "--explicitStart" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/compiler/tablebase.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none", 4 | "--tableBase 32" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/compiler/typeof.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none", 4 | "--explicitStart" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/runtime/untouched.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/assemblyscript/master/tests/runtime/untouched.wasm -------------------------------------------------------------------------------- /lib/libm/index.d.ts: -------------------------------------------------------------------------------- 1 | declare const libm: typeof Math & { libm: typeof Math, libmf: typeof Math }; 2 | export = libm; 3 | -------------------------------------------------------------------------------- /std/assembly/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../assembly.json", 3 | "include": [ 4 | "./**/*.ts" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /tests/compiler/issues/1095.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--use ASC_RTRACE=1" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/compiler/memorybase.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none", 4 | "--memoryBase 1024" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/compiler/named-export-default.ts: -------------------------------------------------------------------------------- 1 | function get3(): i32 { 2 | return 3; 3 | } 4 | 5 | export {get3 as default}; 6 | -------------------------------------------------------------------------------- /tests/compiler/resolve-new.ts: -------------------------------------------------------------------------------- 1 | class Foo { 2 | bar(): void {} 3 | } 4 | var foo = new Foo(); 5 | (new Foo()).bar(); 6 | -------------------------------------------------------------------------------- /tests/compiler/retain-release.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none", 4 | "--explicitStart" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/compiler/retain-return.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--explicitStart" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/compiler/rt/instanceof.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none", 4 | "--explicitStart" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/compiler/rt/stub-realloc.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime stub", 4 | "--explicitStart" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/compiler/std/dataview.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--use ASC_RTRACE=1" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/packages/packages/d/packages/e/packages/f/assembly/f.ts: -------------------------------------------------------------------------------- 1 | export function F(): string { 2 | return "F"; 3 | } 4 | -------------------------------------------------------------------------------- /tests/parser/class-expression.ts: -------------------------------------------------------------------------------- 1 | var a = class { 2 | foo(): void {} 3 | bar: i32; 4 | }; 5 | var b = class Foo {}; 6 | -------------------------------------------------------------------------------- /tests/parser/interface.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | interface Foo { 2 | bar(): void; 3 | baz: i32; 4 | readonly baz2: f64; 5 | } 6 | -------------------------------------------------------------------------------- /lib/loader/tests/build/legacy.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/assemblyscript/master/lib/loader/tests/build/legacy.wasm -------------------------------------------------------------------------------- /src/extra/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../std/portable.json", 3 | "include": [ 4 | "./**/*.ts" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /std/assembly/reference.ts: -------------------------------------------------------------------------------- 1 | /** Host reference abstraction. */ 2 | @sealed @unmanaged 3 | export abstract class Anyref { 4 | } 5 | -------------------------------------------------------------------------------- /tests/compiler/rc/global-init.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--use ASC_RTRACE=1" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/compiler/rc/local-init.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--use ASC_RTRACE=1" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/compiler/rc/optimize.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--use ASC_RTRACE=1" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /tests/compiler/std/array-literal.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--use ASC_RTRACE=1" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/compiler/std/arraybuffer.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--use ASC_RTRACE=1" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/packages/.gitignore: -------------------------------------------------------------------------------- 1 | packages/*/package-lock.json 2 | package-lock.json 3 | !node_modules/ 4 | !packages/**/*/node_modules/ -------------------------------------------------------------------------------- /tests/packages/packages/c/node_modules/b/node_modules/a/assembly/a.ts: -------------------------------------------------------------------------------- 1 | export function A(): string { 2 | return "A"; 3 | } 4 | -------------------------------------------------------------------------------- /tests/packages/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../std/assembly.json", 3 | "include": ["**/*/assembly/**/*.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /tests/parser/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../std/assembly.json", 3 | "include": [ 4 | "./*.ts" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /examples/n-body/build/optimized.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/assemblyscript/master/examples/n-body/build/optimized.wasm -------------------------------------------------------------------------------- /lib/loader/tests/build/default.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/assemblyscript/master/lib/loader/tests/build/default.wasm -------------------------------------------------------------------------------- /src/glue/wasm/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../std/assembly.json", 3 | "include": [ 4 | "./**/*.ts" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /tests/compiler/assert.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (table $0 1 funcref) 4 | (export "memory" (memory $0)) 5 | ) 6 | -------------------------------------------------------------------------------- /tests/compiler/empty.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (table $0 1 funcref) 4 | (export "memory" (memory $0)) 5 | ) 6 | -------------------------------------------------------------------------------- /tests/compiler/implicit-getter-setter.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime full", 4 | "--use ASC_RTRACE=1" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/compiler/rc/logical-or-mismatch.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--use ASC_RTRACE=1" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/compiler/rc/ternary-mismatch.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--use ASC_RTRACE=1" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/compiler/retain-release-sanity.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--use ASC_RTRACE=1" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/compiler/rt/flags.json: -------------------------------------------------------------------------------- 1 | { 2 | "features": [ 3 | "simd" 4 | ], 5 | "asc_flags": [ 6 | "--runtime none" 7 | ] 8 | } -------------------------------------------------------------------------------- /tests/compiler/rt/ids.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (table $0 1 funcref) 4 | (export "memory" (memory $0)) 5 | ) 6 | -------------------------------------------------------------------------------- /tests/compiler/std/string-encoding.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--use ASC_RTRACE=1" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/compiler/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../std/assembly.json", 3 | "include": [ 4 | "./**/*.ts" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /tests/packages/packages/h/node_modules/@foo/bar/assembly/index.ts: -------------------------------------------------------------------------------- 1 | import { h2 } from "@bar/baz"; 2 | 3 | export const h = h2; 4 | -------------------------------------------------------------------------------- /tests/parser/class-expression.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | var a = class { 2 | foo(): void {} 3 | bar: i32; 4 | }; 5 | var b = class Foo {}; 6 | -------------------------------------------------------------------------------- /lib/i64/assembly/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../std/assembly.json", 3 | "include": [ 4 | "./**/*.ts" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /lib/libm/assembly/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../std/assembly.json", 3 | "include": [ 4 | "./**/*.ts" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /lib/parse/assembly/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../std/assembly.json", 3 | "include": [ 4 | "./**/*.ts" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /src/glue/js/node.d.ts: -------------------------------------------------------------------------------- 1 | /** @module glue/js *//***/ 2 | 3 | declare const global: any; 4 | declare function require(name: string): any; 5 | -------------------------------------------------------------------------------- /tests/compiler/ReturnType.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (table $0 1 funcref) 4 | (export "memory" (memory $0)) 5 | ) 6 | -------------------------------------------------------------------------------- /tests/compiler/extends-recursive.ts: -------------------------------------------------------------------------------- 1 | class Parent { 2 | child: Child | null = null; 3 | } 4 | export class Child extends Parent { } 5 | -------------------------------------------------------------------------------- /tests/compiler/extends-self.ts: -------------------------------------------------------------------------------- 1 | class Parent extends Child { } 2 | class Child extends Parent { } 3 | new Child(); 4 | ERROR("EOF"); 5 | -------------------------------------------------------------------------------- /tests/compiler/rc/logical-and-mismatch.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--use ASC_RTRACE=1" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/compiler/recursive.ts: -------------------------------------------------------------------------------- 1 | export function fib(n: i32): i32 { 2 | if (n <= 1) return 1; 3 | return fib(n - 1) + fib(n - 2); 4 | } 5 | -------------------------------------------------------------------------------- /tests/packages/packages/d/node_modules/as/notassembly/as.ts: -------------------------------------------------------------------------------- 1 | export function AS(str: string): string { 2 | return str + "S"; 3 | } 4 | -------------------------------------------------------------------------------- /tests/packages/packages/h/assembly/index.ts: -------------------------------------------------------------------------------- 1 | import { h } from "@foo/bar"; 2 | 3 | export function getH(): i32 { 4 | return h; 5 | } 6 | -------------------------------------------------------------------------------- /examples/game-of-life/build/optimized.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/assemblyscript/master/examples/game-of-life/build/optimized.wasm -------------------------------------------------------------------------------- /examples/mandelbrot/assembly/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../std/assembly.json", 3 | "include": [ 4 | "./**/*.ts" 5 | ] 6 | } -------------------------------------------------------------------------------- /examples/mandelbrot/build/optimized.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/assemblyscript/master/examples/mandelbrot/build/optimized.wasm -------------------------------------------------------------------------------- /examples/n-body/assembly/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../std/assembly.json", 3 | "include": [ 4 | "./**/*.ts" 5 | ] 6 | } -------------------------------------------------------------------------------- /examples/n-body/build/rust.optimized.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ailisp/assemblyscript/master/examples/n-body/build/rust.optimized.wasm -------------------------------------------------------------------------------- /examples/pson/assembly/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../std/assembly.json", 3 | "include": [ 4 | "./**/*.ts" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /tests/compiler/do.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--explicitStart", 5 | "--use ASC_RTRACE=1" 6 | ] 7 | } -------------------------------------------------------------------------------- /tests/compiler/for.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--explicitStart", 5 | "--use ASC_RTRACE=1" 6 | ] 7 | } -------------------------------------------------------------------------------- /tests/compiler/indexof-valueof.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (table $0 1 funcref) 4 | (export "memory" (memory $0)) 5 | ) 6 | -------------------------------------------------------------------------------- /tests/compiler/runtime-half.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (table $0 1 funcref) 4 | (export "memory" (memory $0)) 5 | ) 6 | -------------------------------------------------------------------------------- /tests/compiler/runtime-none.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (table $0 1 funcref) 4 | (export "memory" (memory $0)) 5 | ) 6 | -------------------------------------------------------------------------------- /tests/compiler/while.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--explicitStart", 5 | "--use ASC_RTRACE=1" 6 | ] 7 | } -------------------------------------------------------------------------------- /tests/packages/packages/d/node_modules/c/node_modules/b/node_modules/a/assembly/a.ts: -------------------------------------------------------------------------------- 1 | export function A(): string { 2 | return "A"; 3 | } 4 | -------------------------------------------------------------------------------- /tests/packages/packages/g/node_modules/c/node_modules/b/node_modules/a/assembly/a.ts: -------------------------------------------------------------------------------- 1 | export function A(): string { 2 | return "A"; 3 | } 4 | -------------------------------------------------------------------------------- /tests/runtime/assembly/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../std/assembly.json", 3 | "include": [ 4 | "./**/*.ts" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /std/assembly/rt/index-stub.ts: -------------------------------------------------------------------------------- 1 | export { __alloc, __retain, __release, __collect, __reset } from "rt/stub"; 2 | export { __rtti_base } from "rt"; 3 | -------------------------------------------------------------------------------- /tests/compiler/nullable.ts: -------------------------------------------------------------------------------- 1 | class Example {} 2 | 3 | function notNullable(a: Example): void {} 4 | 5 | notNullable(null); 6 | 7 | ERROR("EOF") 8 | -------------------------------------------------------------------------------- /tests/compiler/std/array.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--explicitStart", 5 | "--use ASC_RTRACE=1" 6 | ] 7 | } -------------------------------------------------------------------------------- /tests/compiler/std/string.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--explicitStart", 5 | "--use ASC_RTRACE=1" 6 | ] 7 | } -------------------------------------------------------------------------------- /tests/parser/calls.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | id(); 2 | id()(); 3 | arr[0](); 4 | arr[0](1); 5 | obj.a(); 6 | obj.a(1); 7 | id(a)[0](b)(c).a(d)(e)[1](f)(g); 8 | -------------------------------------------------------------------------------- /tests/parser/nonNullAssertion.ts: -------------------------------------------------------------------------------- 1 | foo!; 2 | foo!!; 3 | foo!.bar; 4 | foo.bar!; 5 | foo![0]; 6 | foo[0]!; 7 | foo![0]!.bar!; 8 | foo!![0]!!.bar!!; 9 | -------------------------------------------------------------------------------- /tests/parser/while.ts: -------------------------------------------------------------------------------- 1 | while (1) { 2 | ; 3 | } 4 | while (false) { 5 | ; 6 | } 7 | while ("str") { 8 | ; 9 | } 10 | while (1); 11 | -------------------------------------------------------------------------------- /examples/game-of-life/assembly/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../std/assembly.json", 3 | "include": [ 4 | "./**/*.ts" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /lib/parse/src/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs" 4 | }, 5 | "include": [ 6 | "./**/*.ts" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /tests/allocators/buddy/assembly/index.ts: -------------------------------------------------------------------------------- 1 | import "./buddy"; 2 | export { memory }; 3 | export { __mem_allocate as __alloc, __mem_free as __free }; 4 | -------------------------------------------------------------------------------- /tests/compiler/exportimport-table.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none", 4 | "--importTable", 5 | "--exportTable" 6 | ] 7 | } -------------------------------------------------------------------------------- /tests/compiler/extends-self.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ], 5 | "stderr": [ 6 | "TS2506", 7 | "EOF" 8 | ] 9 | } -------------------------------------------------------------------------------- /tests/compiler/managed-cast.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--explicitStart", 5 | "--use ASC_RTRACE=1" 6 | ] 7 | } -------------------------------------------------------------------------------- /tests/compiler/rereexport.ts: -------------------------------------------------------------------------------- 1 | export { 2 | a, 3 | a as renamed_a, 4 | renamed_b, 5 | renamed_b as renamed_renamed_b 6 | } from "./reexport"; 7 | -------------------------------------------------------------------------------- /tests/compiler/std/typedarray.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime half", 4 | "--explicitStart", 5 | "--use ASC_RTRACE=1" 6 | ] 7 | } -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | bin/* text eol=lf 2 | dist/* binary 3 | scripts/*.sh eol=lf 4 | lib/binaryen.js binary 5 | tests/compiler/std/string-encoding.ts eol=lf 6 | -------------------------------------------------------------------------------- /scripts/build.js: -------------------------------------------------------------------------------- 1 | const webpack = require("webpack"); 2 | 3 | webpack(require("../webpack.config.js"), (err, stats) => { 4 | if (err) throw err; 5 | }); 6 | -------------------------------------------------------------------------------- /tests/allocators/buddy/assembly/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../std/assembly.json", 3 | "include": [ 4 | "./**/*.ts" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /tests/allocators/rt-full/assembly/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../std/assembly.json", 3 | "include": [ 4 | "./**/*.ts" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /tests/allocators/rt-stub/assembly/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../../std/assembly.json", 3 | "include": [ 4 | "./**/*.ts" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /tests/parser/enum.ts: -------------------------------------------------------------------------------- 1 | export const enum A { 2 | B = 1, 3 | C, 4 | D = 3 5 | } 6 | enum E { 7 | F, 8 | G = 1 + 2, 9 | H = 3 * 4 10 | } 11 | -------------------------------------------------------------------------------- /tests/parser/for.ts: -------------------------------------------------------------------------------- 1 | for (var i: i32 = 0; i < 10; ++i) { 2 | ; 3 | } 4 | for (i = 0; i < 10; ++i) { 5 | ; 6 | } 7 | for (;;) { 8 | ; 9 | } 10 | -------------------------------------------------------------------------------- /tests/parser/while.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | while (1) { 2 | ; 3 | } 4 | while (false) { 5 | ; 6 | } 7 | while ("str") { 8 | ; 9 | } 10 | while (1); 11 | -------------------------------------------------------------------------------- /tests/compiler/features/reference-types.json: -------------------------------------------------------------------------------- 1 | { 2 | "features": [ 3 | "reference-types" 4 | ], 5 | "asc_flags": [ 6 | "--runtime none" 7 | ] 8 | } -------------------------------------------------------------------------------- /tests/parser/nonNullAssertion.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | foo!; 2 | foo!!; 3 | foo!.bar; 4 | foo.bar!; 5 | foo![0]; 6 | foo[0]!; 7 | foo![0]!.bar!; 8 | foo!![0]!!.bar!!; 9 | -------------------------------------------------------------------------------- /std/assembly/rt/index-full.ts: -------------------------------------------------------------------------------- 1 | export { __alloc } from "rt/tlsf"; 2 | export { __retain, __release, __collect } from "rt/pure"; 3 | export { __rtti_base } from "rt"; 4 | -------------------------------------------------------------------------------- /tests/compiler/std/mod.js: -------------------------------------------------------------------------------- 1 | exports.preInstantiate = function(imports, exports) { 2 | imports.mod = { 3 | mod: function(a, b) { return a % b; } 4 | }; 5 | }; 6 | -------------------------------------------------------------------------------- /tests/parser/for.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | for (var i: i32 = 0; i < 10; ++i) { 2 | ; 3 | } 4 | for (i = 0; i < 10; ++i) { 5 | ; 6 | } 7 | for (;;) { 8 | ; 9 | } 10 | -------------------------------------------------------------------------------- /tests/parser/optional-property.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | class C { 2 | x: i32; 3 | } 4 | // ERROR 219: "Optional properties are not supported." in optional-property.ts:2:9 5 | -------------------------------------------------------------------------------- /cli/util/mkdirp.d.ts: -------------------------------------------------------------------------------- 1 | interface Options { 2 | mode?: number; 3 | } 4 | declare function mkdirp(path: string, options?: Options): string | null; 5 | export = mkdirp; 6 | -------------------------------------------------------------------------------- /tests/parser/enum.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | export const enum A { 2 | B = 1, 3 | C, 4 | D = 3 5 | } 6 | enum E { 7 | F, 8 | G = 1 + 2, 9 | H = 3 * 4 10 | } 11 | -------------------------------------------------------------------------------- /tests/compiler/static-this.ts: -------------------------------------------------------------------------------- 1 | class Foo { 2 | static bar: i32 = 42; 3 | static getBar(): i32 { 4 | return this.bar; 5 | } 6 | } 7 | 8 | assert(Foo.getBar() == 42); 9 | -------------------------------------------------------------------------------- /tests/compiler/std/libm.ts: -------------------------------------------------------------------------------- 1 | import * as libm from "../../../lib/libm/assembly/libm"; 2 | import * as libmf from "../../../lib/libm/assembly/libmf"; 3 | export { libm, libmf }; 4 | -------------------------------------------------------------------------------- /tests/parser/continue-on-error.ts: -------------------------------------------------------------------------------- 1 | // 1003: Identifier expected. 2 | var; 3 | // 1005: '(' expected. 4 | while for let; a from "./other"; 5 | do { 6 | ; 7 | } while (false); 8 | -------------------------------------------------------------------------------- /tsconfig-docs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./src/tsconfig.json", 3 | "include": [ 4 | "./src/**/*.ts" 5 | ], 6 | "exclude": [ 7 | "./std/**" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /tests/compiler/named-import-default.ts: -------------------------------------------------------------------------------- 1 | import { 2 | default as get3 3 | } from "./named-export-default"; 4 | 5 | export function getValue(): i32 { 6 | return get3(); 7 | } 8 | -------------------------------------------------------------------------------- /tests/parser/arrow-functions.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | (x): i32 => x; 2 | (x: i32) => x; 3 | (x?) => x; 4 | (x?, y?) => x; 5 | (x?: i32) => x; 6 | x => x; 7 | (b ? x : y); 8 | (b ? f : g)(); 9 | -------------------------------------------------------------------------------- /tests/parser/function-type.ts: -------------------------------------------------------------------------------- 1 | var a: () => void; 2 | var b: (a: i32, b: i32) => void; 3 | var c: (a: i32, b: i32) => (a: i32, b: i32) => void; 4 | var d: (a) => void; // TS1110 5 | -------------------------------------------------------------------------------- /tests/parser/optional-typeparameters.ts: -------------------------------------------------------------------------------- 1 | function a(): T { return 0; } 2 | function a(): T { return 0; } 3 | function a(): T { return 0; } // ERROR 2706 4 | -------------------------------------------------------------------------------- /cli/util/find.d.ts: -------------------------------------------------------------------------------- 1 | export function files(dirname: string, filter?: ((name: string) => bool) | RegExp): string[]; 2 | export const TS: RegExp; 3 | export const TS_EXCEPT_DTS: RegExp; 4 | -------------------------------------------------------------------------------- /lib/rtrace/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@assemblyscript/rtrace", 3 | "types": "index.d.ts", 4 | "version": "0.1.0", 5 | "license": "Apache-2.0", 6 | "main": "index.js" 7 | } 8 | -------------------------------------------------------------------------------- /tests/compiler/features/simd.json: -------------------------------------------------------------------------------- 1 | { 2 | "features": [ 3 | "simd" 4 | ], 5 | "asc_flags": [ 6 | "--runtime none" 7 | ], 8 | "skipInstantiate": true 9 | } 10 | -------------------------------------------------------------------------------- /tests/compiler/implicit-getter-setter.ts: -------------------------------------------------------------------------------- 1 | export class Basic { 2 | constructor(public val: i32) {} 3 | } 4 | 5 | export class Managed { 6 | constructor(public foo: Basic) {} 7 | } 8 | -------------------------------------------------------------------------------- /tests/compiler/tablebase.ts: -------------------------------------------------------------------------------- 1 | function foo(): void {} 2 | 3 | const staticFunction = foo; 4 | 5 | assert(ASC_TABLE_BASE == 32); 6 | assert(changetype(staticFunction) == 32); 7 | -------------------------------------------------------------------------------- /tests/compiler/basic-nullable.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ], 5 | "stderr": [ 6 | "AS204: Basic type 'i32' cannot be nullable.", 7 | "EOF" 8 | ] 9 | } -------------------------------------------------------------------------------- /tests/compiler/rt/ids.ts: -------------------------------------------------------------------------------- 1 | import { ArrayBufferView } from "arraybuffer"; 2 | 3 | assert(idof() == 0); 4 | assert(idof() == 1); 5 | assert(idof() == 2); 6 | -------------------------------------------------------------------------------- /tests/compiler/std/simd.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (table $0 1 funcref) 4 | (global $~lib/ASC_FEATURE_SIMD i32 (i32.const 0)) 5 | (export "memory" (memory $0)) 6 | ) 7 | -------------------------------------------------------------------------------- /tests/parser/object-literal.ts: -------------------------------------------------------------------------------- 1 | var obj = { 2 | a: 123, 3 | b: "234", 4 | "c": false, 5 | d: { 6 | a: 123, 7 | "b": {}, 8 | c, 9 | d: d 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /examples/n-body/rust/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "rust_nbody" 5 | version = "0.1.0" 6 | 7 | -------------------------------------------------------------------------------- /tests/compiler/std/math.js: -------------------------------------------------------------------------------- 1 | exports.preInstantiate = function(imports, exports) { 2 | imports.Math = Math; 3 | imports.math = { 4 | mod: function(a, b) { return a % b; } 5 | }; 6 | }; 7 | -------------------------------------------------------------------------------- /src/glue/wasm/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * WebAssembly glue code. 3 | * @module glue/wasm 4 | * @preferred 5 | *//***/ 6 | 7 | import "../binaryen.d"; 8 | import "./i64"; 9 | import "./float"; 10 | -------------------------------------------------------------------------------- /tests/binaryen/unreachable-loop.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func $0 3 | (drop 4 | (block $label$1 (result i32) 5 | (loop $label$2 6 | (unreachable) 7 | ) 8 | ) 9 | ) 10 | ) 11 | ) -------------------------------------------------------------------------------- /tests/compiler/features/mutable-globals.json: -------------------------------------------------------------------------------- 1 | { 2 | "features": [ 3 | "mutable-globals" 4 | ], 5 | "asc_flags": [ 6 | "--runtime none", 7 | "--explicitStart" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /tests/parser/object-literal.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | var obj = { 2 | a: 123, 3 | b: "234", 4 | "c": false, 5 | d: { 6 | a: 123, 7 | "b": {}, 8 | c, 9 | d: d 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /tests/compiler/bool.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 1) 3 | (data (i32.const 16) "\0e\00\00\00\01\00\00\00\01\00\00\00\0e\00\00\00b\00o\00o\00l\00.\00t\00s") 4 | (export "memory" (memory $0)) 5 | ) 6 | -------------------------------------------------------------------------------- /tests/compiler/exportimport-table.js: -------------------------------------------------------------------------------- 1 | exports.preInstantiate = function(imports, exports) { 2 | imports.env = { 3 | table: new WebAssembly.Table({ element: "anyfunc", initial: 2 }) 4 | }; 5 | }; 6 | -------------------------------------------------------------------------------- /tests/parser/definite-assignment-assertion.ts: -------------------------------------------------------------------------------- 1 | class C { 2 | x!: i32; 3 | x!: i32 = 0; 4 | static x!: i32; 5 | } 6 | function f(): void { 7 | let x!: i32; 8 | let x!: i32 = 0; 9 | } 10 | -------------------------------------------------------------------------------- /std/README.md: -------------------------------------------------------------------------------- 1 | Standard library components for use with `tsc` (portable) and `asc` (assembly). 2 | 3 | Base configurations (.json) and definition files (.d.ts) are relevant to `tsc` only and not used by `asc`. 4 | -------------------------------------------------------------------------------- /tests/compiler/features/js-bigint-integration.json: -------------------------------------------------------------------------------- 1 | { 2 | "features": [ 3 | "bigint-integration" 4 | ], 5 | "asc_flags": [ 6 | "--runtime none", 7 | "--explicitStart" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /tests/packages/packages/b/assembly/b.ts: -------------------------------------------------------------------------------- 1 | import { A } from "a"; 2 | 3 | export function B(): string { 4 | return "B"; 5 | } 6 | 7 | export function AB(): string { 8 | return A() + B(); 9 | } 10 | -------------------------------------------------------------------------------- /tests/compiler/features/threads.json: -------------------------------------------------------------------------------- 1 | { 2 | "features": [ 3 | "threads" 4 | ], 5 | "asc_flags": [ 6 | "--runtime none", 7 | "--memoryBase 8", 8 | "--sharedMemory 1" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /tests/packages/packages/d/packages/e/assembly/e.ts: -------------------------------------------------------------------------------- 1 | import { C } from "c"; 2 | 3 | export function E(): string { 4 | return "E"; 5 | } 6 | 7 | export function EC(): string { 8 | return C() + E(); 9 | } 10 | -------------------------------------------------------------------------------- /lib/lint/src/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "commonjs", 5 | "lib": ["es6", "es2015.collection"] 6 | }, 7 | "include": [ 8 | "./**/**.ts" 9 | ] 10 | } -------------------------------------------------------------------------------- /tests/compiler/nullable.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ], 5 | "stderr": [ 6 | "TS2322: Type 'nullable/Example | null' is not assignable to type 'nullable/Example'.", 7 | "EOF" 8 | ] 9 | } -------------------------------------------------------------------------------- /tests/compiler/overflow.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 1) 3 | (data (i32.const 16) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00o\00v\00e\00r\00f\00l\00o\00w\00.\00t\00s") 4 | (export "memory" (memory $0)) 5 | ) 6 | -------------------------------------------------------------------------------- /tests/packages/packages/c/node_modules/b/assembly/b.ts: -------------------------------------------------------------------------------- 1 | import { A } from "a"; 2 | 3 | export function B(): string { 4 | return "B"; 5 | } 6 | 7 | export function AB(): string { 8 | return A() + B(); 9 | } 10 | -------------------------------------------------------------------------------- /tests/allocators/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "test": "node ./index", 5 | "test:forever": "node ./forever", 6 | "test:all": "npm run test rt-full && npm run test rt-stub" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/compiler/memorybase.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 1) 3 | (data (i32.const 1024) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00h\00e\00l\00l\00o\00 \00w\00o\00r\00l\00d") 4 | (export "memory" (memory $0)) 5 | ) 6 | -------------------------------------------------------------------------------- /tests/compiler/memorybase.ts: -------------------------------------------------------------------------------- 1 | import { BLOCK_OVERHEAD } from "rt/common"; 2 | 3 | const staticString = "hello world"; 4 | 5 | assert(ASC_MEMORY_BASE == 1024); 6 | assert(changetype(staticString) - BLOCK_OVERHEAD == 1024); 7 | -------------------------------------------------------------------------------- /src/glue/js/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * JavaScript glue code. 3 | * @module glue/js 4 | * @preferred 5 | *//***/ 6 | 7 | import "../../../std/portable/index"; 8 | import "../binaryen"; 9 | import "./float"; 10 | import "./i64"; 11 | -------------------------------------------------------------------------------- /tests/compiler/void.ts: -------------------------------------------------------------------------------- 1 | void 1; 2 | 3 | function anInt(): i32 { 4 | return 2; 5 | } 6 | 7 | void anInt(); 8 | 9 | var u8Val1: u8 = 1; 10 | var u8Val2: u8 = 255; 11 | 12 | void (u8Val1 + u8Val2); // can remain unwrapped 13 | -------------------------------------------------------------------------------- /tests/binaryen/const-global.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i (func (result i32))) 3 | (global $testGlobal i32 (i32.const 2)) 4 | (export "test" (func $test)) 5 | (func $test (; 0 ;) (type $i) (result i32) 6 | (get_global $testGlobal) 7 | ) 8 | ) -------------------------------------------------------------------------------- /tests/compiler/class-extends.ts: -------------------------------------------------------------------------------- 1 | class A { 2 | a: i32 = 0; 3 | } 4 | 5 | class B extends A { 6 | b: i16 = 1; 7 | } 8 | 9 | export function test(b: B): void { 10 | b.a; 11 | b.b; 12 | b.a = 2; 13 | b.b = 3; 14 | } 15 | -------------------------------------------------------------------------------- /tests/compiler/static-this.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 1) 3 | (data (i32.const 16) "\1c\00\00\00\01\00\00\00\01\00\00\00\1c\00\00\00s\00t\00a\00t\00i\00c\00-\00t\00h\00i\00s\00.\00t\00s") 4 | (export "memory" (memory $0)) 5 | ) 6 | -------------------------------------------------------------------------------- /tests/packages/packages/d/node_modules/c/node_modules/b/assembly/b.ts: -------------------------------------------------------------------------------- 1 | import { A } from "a"; 2 | 3 | export function B(): string { 4 | return "B"; 5 | } 6 | 7 | export function AB(): string { 8 | return A() + B(); 9 | } 10 | -------------------------------------------------------------------------------- /tests/packages/packages/g/node_modules/c/node_modules/b/assembly/b.ts: -------------------------------------------------------------------------------- 1 | import { A } from "a"; 2 | 3 | export function B(): string { 4 | return "B"; 5 | } 6 | 7 | export function AB(): string { 8 | return A() + B(); 9 | } 10 | -------------------------------------------------------------------------------- /tests/parser/arrow-functions.ts: -------------------------------------------------------------------------------- 1 | // array function 2 | (x): i32 => x; 3 | (x: i32) => x; 4 | (x?) => x; 5 | (x?, y?) => x; 6 | (x?: i32) => x; 7 | x => x; 8 | 9 | // not an array function 10 | (b ? x : y); 11 | (b ? f : g)(); 12 | -------------------------------------------------------------------------------- /tests/parser/function-type.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | var a: () => void; 2 | var b: (a: i32, b: i32) => void; 3 | var c: (a: i32, b: i32) => (a: i32, b: i32) => void; 4 | var d: (a) => void; 5 | // ERROR 1110: "Type expected." in function-type.ts:4:9 6 | -------------------------------------------------------------------------------- /tests/parser/export-default.ts: -------------------------------------------------------------------------------- 1 | export default function theFunction(): void {} 2 | export default class TheClass {} 3 | // not so ts-y: 4 | export default enum TheEnum {} 5 | export default namespace theNamespace {} 6 | export default something; 7 | -------------------------------------------------------------------------------- /tests/compiler/closure.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ], 5 | "stderr": [ 6 | "AS100: Not implemented.", 7 | "AS100: Not implemented.", 8 | "Cannot find name '$local0'.", 9 | "EOF" 10 | ] 11 | } -------------------------------------------------------------------------------- /tests/compiler/std/polyfills.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 1) 3 | (data (i32.const 16) " \00\00\00\01\00\00\00\01\00\00\00 \00\00\00s\00t\00d\00/\00p\00o\00l\00y\00f\00i\00l\00l\00s\00.\00t\00s") 4 | (export "memory" (memory $0)) 5 | ) 6 | -------------------------------------------------------------------------------- /tests/parser/decorators.ts: -------------------------------------------------------------------------------- 1 | @global 2 | @operator("+") 3 | @operator.binary("-") 4 | @operator.prefix("~") 5 | @operator.postfix("++") 6 | @unmanaged 7 | @sealed 8 | @inline 9 | @external("a", "b") 10 | @custom 11 | function a(): void {} 12 | -------------------------------------------------------------------------------- /tests/compiler/getter-call.ts: -------------------------------------------------------------------------------- 1 | class C { 2 | get x(): () => i32 { 3 | return (): i32 => 42; 4 | } 5 | } 6 | 7 | export function test(): i32 { 8 | // TODO: GH#251 return new C().x(); 9 | let c = new C(); 10 | return c.x(); 11 | } 12 | -------------------------------------------------------------------------------- /tests/packages/packages/g/assembly/g.ts: -------------------------------------------------------------------------------- 1 | import { ABC } from "c"; 2 | import { A } from "a"; 3 | 4 | export function AAG(): string { 5 | return A() + A() + "G"; 6 | } 7 | 8 | export function ABCG(): string { 9 | return ABC() + "G"; 10 | } 11 | -------------------------------------------------------------------------------- /tests/parser/export-default.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | export default function theFunction(): void {} 2 | export default class TheClass {} 3 | export default enum TheEnum {} 4 | export default namespace theNamespace {} 5 | export { 6 | something as default 7 | }; 8 | -------------------------------------------------------------------------------- /tests/parser/var.ts: -------------------------------------------------------------------------------- 1 | var a: i32; 2 | var b: i32; 3 | const c: i32 = 0; 4 | var d = 2; 5 | 6 | // 1110: Type expected. 7 | var e; 8 | 9 | // 1155: 'const' declarations must be initialized. 10 | const f: i32; 11 | 12 | const t = 0 < (c / 10); 13 | -------------------------------------------------------------------------------- /src/glue/js/float.d.ts: -------------------------------------------------------------------------------- 1 | /** @module glue/js *//***/ 2 | 3 | declare function f32_as_i32(value: f32): i32; 4 | declare function i32_as_f32(value: i32): f32; 5 | declare function f64_as_i64(value: f64): I64; 6 | declare function i64_as_f64(value: I64): f64; 7 | -------------------------------------------------------------------------------- /tests/parser/continue-on-error.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | ; 2 | a; 3 | from; 4 | "./other"; 5 | do { 6 | ; 7 | } while (false); 8 | // ERROR 1003: "Identifier expected." in continue-on-error.ts:2:0 9 | // ERROR 1005: "'(' expected." in continue-on-error.ts:4:0 10 | -------------------------------------------------------------------------------- /tests/parser/decorators.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | @global 2 | @operator("+") 3 | @operator.binary("-") 4 | @operator.prefix("~") 5 | @operator.postfix("++") 6 | @unmanaged 7 | @sealed 8 | @inline 9 | @external("a", "b") 10 | @custom 11 | function a(): void {} 12 | -------------------------------------------------------------------------------- /tests/require/index.ts: -------------------------------------------------------------------------------- 1 | // used to check `require`ing portable sources 2 | // - src/glue/js/index.ts 3 | // - src/index.ts 4 | import * as as from "../../index"; 5 | var program: as.Program = as.newProgram(as.newOptions()); 6 | as.parse(program, "", "empty"); 7 | -------------------------------------------------------------------------------- /std/assembly/shared/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../portable.json", 3 | "compilerOptions": { 4 | "outDir": "../../../out", 5 | "allowJs": false, 6 | "sourceMap": true 7 | }, 8 | "include": [ 9 | "./**/*.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /tests/compiler/class-static-function.ts: -------------------------------------------------------------------------------- 1 | class Example { 2 | public static staticFunc(): i32 { 3 | return 42; 4 | } 5 | } 6 | 7 | function call(func: () => i32): i32 { 8 | return func(); 9 | } 10 | 11 | assert(call(Example.staticFunc) == 42); 12 | -------------------------------------------------------------------------------- /tests/parser/calls.ts: -------------------------------------------------------------------------------- 1 | // Identifier 2 | id(); 3 | 4 | // Call 5 | id()(); 6 | 7 | // ElementAccess 8 | arr[0](); 9 | arr[0](1); 10 | 11 | // PropertyAccess 12 | obj.a(); 13 | obj.a(1); 14 | 15 | // Everything 16 | id(a)[0](b)(c).a(d)(e)[1](f)(g); 17 | -------------------------------------------------------------------------------- /tests/parser/constructor.ts: -------------------------------------------------------------------------------- 1 | class MyClass { 2 | constructor() {} 3 | constructor(a: i32) {} 4 | constructor(a: i32, b: i32) {} 5 | } 6 | 7 | class MyClassImplicit { 8 | constructor(public a: i32, private readonly b: i32 = 2, c: i32 = 3) {} 9 | } 10 | -------------------------------------------------------------------------------- /tests/parser/constructor.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | class MyClass { 2 | constructor() {} 3 | constructor(a: i32) {} 4 | constructor(a: i32, b: i32) {} 5 | } 6 | class MyClassImplicit { 7 | constructor(public a: i32, private readonly b?: i32 = 2, c?: i32 = 3) {} 8 | } 9 | -------------------------------------------------------------------------------- /examples/n-body/rust/README.md: -------------------------------------------------------------------------------- 1 | ### Build 2 | 3 | ```bash 4 | RUSTFLAGS='-C link-arg=-s' cargo +nightly build --release --target wasm32-unknown-unknown 5 | ``` 6 | 7 | ***wasm-gc is deprecated. But the same strip effect we could get with RUSTFLAGS='-C link-arg=-s'*** 8 | -------------------------------------------------------------------------------- /tests/compiler/assert.ts: -------------------------------------------------------------------------------- 1 | assert(true); 2 | assert(1); 3 | assert(1 > 0); 4 | assert(0.5); 5 | assert(0.5 > 0.4); 6 | assert(0x100000000); 7 | assert(0x100000000 > 1); 8 | 9 | // can be used as an expression 10 | if (!assert(true, "must be true")) unreachable(); 11 | -------------------------------------------------------------------------------- /tests/compiler/declare.js: -------------------------------------------------------------------------------- 1 | exports.preInstantiate = function(imports, exports) { 2 | imports.declare = { 3 | externalFunction: function() { }, 4 | externalConstant: 1, 5 | "my.externalFunction": function() { }, 6 | "my.externalConstant": 2 7 | }; 8 | }; 9 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | try { require("source-map-support").install(); } catch (e) {} 2 | require("ts-node").register({ 3 | project: require("path").join(__dirname, "src", "tsconfig.json"), 4 | skipIgnore: true 5 | }); 6 | require("./src/glue/js"); 7 | module.exports = require("./src"); 8 | -------------------------------------------------------------------------------- /lib/webpack/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@assemblyscript/webpack", 3 | "version": "0.5.0", 4 | "description": "webpack loader for AssemblyScript modules.", 5 | "license": "Apache-2.0", 6 | "dependencies": { 7 | "@protobufjs/base64": "^1.1.2" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/compiler/ternary.ts: -------------------------------------------------------------------------------- 1 | 0 ? unreachable() : 1; 2 | 1 ? 1 : unreachable(); 3 | (0 ? unreachable() : 1) ? 1 : unreachable(); 4 | 5 | var a: i32; 6 | 7 | a = 0 ? unreachable() : 1; 8 | a = 1 ? 1 : unreachable(); 9 | a = (0 ? unreachable() : 1) ? 1 : unreachable(); 10 | -------------------------------------------------------------------------------- /tests/parser/import.ts: -------------------------------------------------------------------------------- 1 | import { 2 | A 3 | } from "./other"; 4 | import { 5 | A, 6 | B, 7 | C 8 | } from "./other"; 9 | import { 10 | A as B, 11 | C, 12 | D as E, 13 | F 14 | } from "./other"; 15 | import * as A from "./other"; 16 | import "./other"; 17 | -------------------------------------------------------------------------------- /tests/compiler/portable-conversions.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 1) 3 | (data (i32.const 16) ".\00\00\00\01\00\00\00\01\00\00\00.\00\00\00p\00o\00r\00t\00a\00b\00l\00e\00-\00c\00o\00n\00v\00e\00r\00s\00i\00o\00n\00s\00.\00t\00s") 4 | (export "memory" (memory $0)) 5 | ) 6 | -------------------------------------------------------------------------------- /tests/compiler/std/new.ts: -------------------------------------------------------------------------------- 1 | class AClass { 2 | static aStaticField: i32 = 0; 3 | aField: i32 = 1; 4 | anotherField: f32 = 2; 5 | constructor(value: f32) { 6 | this.aField += 1; 7 | this.anotherField = value; 8 | } 9 | } 10 | 11 | var aClass = new AClass(3); 12 | -------------------------------------------------------------------------------- /tests/packages/packages/c/assembly/c.ts: -------------------------------------------------------------------------------- 1 | import { B, AB } from "b"; 2 | 3 | export function C(): string { 4 | return "C"; 5 | } 6 | 7 | export function BC(): string { 8 | return B() + C(); 9 | } 10 | 11 | export function ABC(): string { 12 | return AB() + C(); 13 | } 14 | -------------------------------------------------------------------------------- /tests/parser/import.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | import { 2 | A 3 | } from "./other"; 4 | import { 5 | A, 6 | B, 7 | C 8 | } from "./other"; 9 | import { 10 | A as B, 11 | C, 12 | D as E, 13 | F 14 | } from "./other"; 15 | import * as A from "./other"; 16 | import "./other"; 17 | -------------------------------------------------------------------------------- /lib/lint/index.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./base.json", 3 | "rulesDirectory": ["./rules", "./rules/internal"], 4 | "formattersDirectory": ["./formatters"], 5 | "rules": { 6 | "as-types": { 7 | "severity": "error" 8 | }, 9 | "as-variables": {} 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/parser/var.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | var a: i32; 2 | var b: i32; 3 | const c: i32 = 0; 4 | var d = 2; 5 | var e; 6 | const f: i32; 7 | const t = 0 < (c / 10); 8 | // ERROR 1110: "Type expected." in var.ts:7:5 9 | // ERROR 1155: "'const' declarations must be initialized." in var.ts:10:6 10 | -------------------------------------------------------------------------------- /tests/require/index-release.ts: -------------------------------------------------------------------------------- 1 | // used to check `require`ing distribution files 2 | // - dist/assemblyscript.js 3 | // - dist/assemblyscript.d.ts 4 | import * as as from "../../index.release"; 5 | var program: as.Program = as.newProgram(as.newOptions()); 6 | as.parse(program, "", "empty"); 7 | -------------------------------------------------------------------------------- /lib/i64/index.js: -------------------------------------------------------------------------------- 1 | var fs = require("fs"); 2 | 3 | // Instantiate the module 4 | var mod = new WebAssembly.Module(fs.readFileSync(__dirname + "/build/optimized.wasm")); 5 | var ins = new WebAssembly.Instance(mod, { /* no imports */ }); 6 | 7 | // Export its exports 8 | module.exports = ins.exports; 9 | -------------------------------------------------------------------------------- /tests/compiler/class-overloading.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_=>_none (func (param i32))) 3 | (memory $0 0) 4 | (export "memory" (memory $0)) 5 | (export "test" (func $class-overloading/test)) 6 | (func $class-overloading/test (; 0 ;) (param $0 i32) 7 | nop 8 | ) 9 | ) 10 | -------------------------------------------------------------------------------- /tests/compiler/inlining-recursive.ts: -------------------------------------------------------------------------------- 1 | // direct 2 | 3 | @inline 4 | export function foo(): void { 5 | foo(); 6 | } 7 | 8 | // indirect 9 | 10 | @inline 11 | export function bar(): void { 12 | baz(); 13 | } 14 | 15 | @inline 16 | export function baz(): void { 17 | bar(); 18 | } 19 | -------------------------------------------------------------------------------- /tests/compiler/external.js: -------------------------------------------------------------------------------- 1 | exports.preInstantiate = function(imports, exports) { 2 | imports.external = { 3 | foo: function() {}, 4 | "foo.bar": function() {}, 5 | bar: function() {} 6 | }; 7 | imports.foo = { 8 | baz: function() {}, 9 | "var": 3 10 | }; 11 | }; 12 | -------------------------------------------------------------------------------- /tests/compiler/features/mutable-globals.ts: -------------------------------------------------------------------------------- 1 | export declare var external: i32; 2 | 3 | export var internal: i32 = 124; 4 | 5 | assert(external == 123); 6 | assert(internal == 124); 7 | 8 | external += 10; 9 | internal += 10; 10 | 11 | assert(external == 133); 12 | assert(internal == 134); 13 | -------------------------------------------------------------------------------- /tests/compiler/resolve-function-expression.ts: -------------------------------------------------------------------------------- 1 | assert( 2 | ((a: i32): i32 => a + 40)(2) 3 | == 4 | 42 5 | ); 6 | assert( 7 | (function(a: i32): i32 { return a + 41; })(1) 8 | == 9 | 42 10 | ); 11 | assert( 12 | ((a: i32): i32 => a + 42)(0).toString() 13 | == 14 | "42" 15 | ); 16 | -------------------------------------------------------------------------------- /tests/packages/packages/d/node_modules/c/assembly/c.ts: -------------------------------------------------------------------------------- 1 | import { B, AB } from "b"; 2 | 3 | export function C(): string { 4 | return "C"; 5 | } 6 | 7 | export function BC(): string { 8 | return B() + C(); 9 | } 10 | 11 | export function ABC(): string { 12 | return AB() + C(); 13 | } 14 | -------------------------------------------------------------------------------- /tests/packages/packages/g/node_modules/c/assembly/c.ts: -------------------------------------------------------------------------------- 1 | import { B, AB } from "b"; 2 | 3 | export function C(): string { 4 | return "C"; 5 | } 6 | 7 | export function BC(): string { 8 | return B() + C(); 9 | } 10 | 11 | export function ABC(): string { 12 | return AB() + C(); 13 | } 14 | -------------------------------------------------------------------------------- /tests/parser/function.ts: -------------------------------------------------------------------------------- 1 | function simple(): void {} 2 | function typeparams(a: V | null = null): void {} 3 | @decorator() 4 | function withdecorator(): void {} 5 | function withthis(this: i32): i32 { return this; } 6 | function withthisp(this: i32, a: f32, b: f64): i32 { return this; } 7 | -------------------------------------------------------------------------------- /tests/compiler/std/trace.ts: -------------------------------------------------------------------------------- 1 | trace("zero_implicit"); 2 | trace("zero_explicit", 0); 3 | trace("one_int", 1, 1); 4 | trace("two_int", 2, 1, 2); 5 | trace("three_int", 3, 1, 2, 3); 6 | trace("four_int", 4, 1, 2, 3, 4); 7 | trace("five_int", 5, 1, 2, 3, 4, 5); 8 | trace("five_dbl", 5, 1.1, 2.2, 3.3, 4.4, 5.5); 9 | -------------------------------------------------------------------------------- /tests/compiler/typealias.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_=>_i32 (func (param i32) (result i32))) 3 | (memory $0 0) 4 | (export "memory" (memory $0)) 5 | (export "alias" (func $typealias/alias)) 6 | (func $typealias/alias (; 0 ;) (param $0 i32) (result i32) 7 | local.get $0 8 | ) 9 | ) 10 | -------------------------------------------------------------------------------- /tsconfig-base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "alwaysStrict": true, 4 | "noImplicitAny": true, 5 | "noImplicitReturns": true, 6 | "noImplicitThis": true, 7 | "noEmitOnError": true, 8 | "strictNullChecks": true, 9 | "experimentalDecorators": true 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/compiler/named-export-default.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (memory $0 0) 4 | (export "memory" (memory $0)) 5 | (export "default" (func $named-export-default/get3)) 6 | (func $named-export-default/get3 (; 0 ;) (result i32) 7 | i32.const 3 8 | ) 9 | ) 10 | -------------------------------------------------------------------------------- /examples/mandelbrot/index.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | const compiled = new WebAssembly.Module(fs.readFileSync(__dirname + "/build/optimized.wasm")); 3 | const imports = { JSMath: Math }; 4 | Object.defineProperty(module, "exports", { 5 | get: () => new WebAssembly.Instance(compiled, imports).exports 6 | }); 7 | -------------------------------------------------------------------------------- /snap/README.md: -------------------------------------------------------------------------------- 1 | Snaps are containerised software packages that are simple to create and install on all major Linux systems without modification. [Learn more](https://docs.snapcraft.io/). 2 | 3 | [![Snap Status](https://build.snapcraft.io/badge/AssemblyScript/assemblyscript.svg)](https://snapcraft.io/assemblyscript) 4 | -------------------------------------------------------------------------------- /tests/compiler/named-import-default.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (memory $0 0) 4 | (export "memory" (memory $0)) 5 | (export "getValue" (func $named-import-default/getValue)) 6 | (func $named-import-default/getValue (; 0 ;) (result i32) 7 | i32.const 3 8 | ) 9 | ) 10 | -------------------------------------------------------------------------------- /tests/compiler/rc/rereturn.ts: -------------------------------------------------------------------------------- 1 | // Validates that skipped autorelease state is preserved accross calls and returns. 2 | 3 | class Ref {} 4 | 5 | function getRef(): Ref { 6 | return new Ref(); 7 | } 8 | 9 | function rereturnRef(): Ref { 10 | return getRef(); 11 | } 12 | 13 | /* __release( */ rereturnRef() /* ) */; 14 | -------------------------------------------------------------------------------- /std/portable.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig-base.json", 3 | "compilerOptions": { 4 | "target": "esnext", 5 | "module": "commonjs", 6 | "allowJs": true, 7 | "downlevelIteration": true, 8 | "preserveConstEnums": true, 9 | "typeRoots": [ "types" ], 10 | "types": [ "portable" ] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/compiler/export-default.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 0) 4 | (export "memory" (memory $0)) 5 | (export "theDefault" (func $export-default/theDefault)) 6 | (export "default" (func $export-default/theDefault)) 7 | (func $export-default/theDefault (; 0 ;) 8 | nop 9 | ) 10 | ) 11 | -------------------------------------------------------------------------------- /tests/compiler/getter-setter.ts: -------------------------------------------------------------------------------- 1 | class Foo { 2 | static _bar: i32 = 0; 3 | 4 | static get bar(): i32 { 5 | return Foo._bar; 6 | } 7 | 8 | static set bar(bar: i32) { 9 | Foo._bar = bar; 10 | } 11 | } 12 | 13 | assert(Foo.bar == 0); 14 | Foo.bar = 1; 15 | assert(Foo.bar == 1); 16 | assert((Foo.bar = 2) == 2); 17 | -------------------------------------------------------------------------------- /tests/compiler/typealias.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_=>_i32 (func (param i32) (result i32))) 3 | (memory $0 0) 4 | (table $0 1 funcref) 5 | (export "memory" (memory $0)) 6 | (export "alias" (func $typealias/alias)) 7 | (func $typealias/alias (; 0 ;) (param $0 i32) (result i32) 8 | local.get $0 9 | ) 10 | ) 11 | -------------------------------------------------------------------------------- /tests/parser/function-expression.ts: -------------------------------------------------------------------------------- 1 | var a = function(): void { 2 | ; 3 | }; 4 | var b = function someName(): void { 5 | ; 6 | }; 7 | var c = function(a: i32, b: i32): i32 { 8 | ; 9 | }; 10 | var d = (): void => { 11 | ; 12 | }; 13 | var e = (a: i32, b: i32): i32 => { 14 | ; 15 | }; 16 | var f = (a: i32): i32 => a; 17 | -------------------------------------------------------------------------------- /tests/compiler/named-export-default.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (memory $0 0) 4 | (table $0 1 funcref) 5 | (export "memory" (memory $0)) 6 | (export "default" (func $named-export-default/get3)) 7 | (func $named-export-default/get3 (; 0 ;) (result i32) 8 | i32.const 3 9 | ) 10 | ) 11 | -------------------------------------------------------------------------------- /tests/parser/optional-typeparameters.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | function a(): T { 2 | return 0; 3 | } 4 | function a(): T { 5 | return 0; 6 | } 7 | function a(): T { 8 | return 0; 9 | } 10 | // ERROR 2706: "Required type parameters may not follow optional type parameters." in optional-typeparameters.ts:3:19 11 | -------------------------------------------------------------------------------- /examples/n-body/rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust_nbody" 3 | version = "0.1.0" 4 | authors = ["MaxGraey "] 5 | 6 | [lib] 7 | path = "src/lib.rs" 8 | crate-type = ["cdylib"] 9 | 10 | [profile.dev] 11 | panic = "abort" 12 | 13 | [profile.release] 14 | panic = "abort" 15 | lto = true 16 | opt-level = 3 17 | -------------------------------------------------------------------------------- /std/assembly/diagnostics.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore: decorator 2 | @builtin 3 | export declare function ERROR(message?: string): void; 4 | 5 | // @ts-ignore: decorator 6 | @builtin 7 | export declare function WARNING(message?: string): void; 8 | 9 | // @ts-ignore: decorator 10 | @builtin 11 | export declare function INFO(message?: string): void; 12 | -------------------------------------------------------------------------------- /tests/binaryen/optimize-if-eqz.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i (func (param i32) (result i32))) 3 | (memory $0 0) 4 | (export "test" (func $test)) 5 | (func $test (; 0 ;) (type $i) (param $0 i32) (result i32) 6 | (if (result i32) 7 | (i32.eqz 8 | (get_local $0) 9 | ) 10 | (i32.const 0) 11 | (get_local $0) 12 | ) 13 | ) 14 | ) -------------------------------------------------------------------------------- /tests/compiler/wasi-snapshot-preview1.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 0) 4 | (global $wasi-snapshot-preview1/sig (mut i32) (i32.const 1)) 5 | (export "memory" (memory $0)) 6 | (start $~start) 7 | (func $~start (; 0 ;) 8 | i32.const 9 9 | global.set $wasi-snapshot-preview1/sig 10 | ) 11 | ) 12 | -------------------------------------------------------------------------------- /tests/parser/function-expression.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | var a = function(): void { 2 | ; 3 | }; 4 | var b = function someName(): void { 5 | ; 6 | }; 7 | var c = function(a: i32, b: i32): i32 { 8 | ; 9 | }; 10 | var d = (): void => { 11 | ; 12 | }; 13 | var e = (a: i32, b: i32): i32 => { 14 | ; 15 | }; 16 | var f = (a: i32): i32 => a; 17 | -------------------------------------------------------------------------------- /tests/parser/function.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | function simple(): void {} 2 | function typeparams(a?: V | null = null): void {} 3 | @decorator() 4 | function withdecorator(): void {} 5 | function withthis(this: i32): i32 { 6 | return this; 7 | } 8 | function withthisp(this: i32, a: f32, b: f64): i32 { 9 | return this; 10 | } 11 | -------------------------------------------------------------------------------- /examples/transform/README.md: -------------------------------------------------------------------------------- 1 | Compiler transform examples 2 | =========================== 3 | 4 | Both transforms written in JS and transforms written in TS can be used, with the 5 | latter requiring that the ts-node package is present. 6 | 7 | * [Example JavaScript transform](./mytransform.js) 8 | * [Example TypeScript transform](./mytransform.ts) 9 | -------------------------------------------------------------------------------- /src/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../std/portable.json", 3 | "compilerOptions": { 4 | "outDir": "../out", 5 | "allowJs": false, 6 | "sourceMap": true, 7 | "target": "ES2016" 8 | }, 9 | "include": [ 10 | "./**/*.ts" 11 | ], 12 | "exclude": [ 13 | "./binary.ts", 14 | "./glue/wasm/**" 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /std/assembly/rt/rtrace.ts: -------------------------------------------------------------------------------- 1 | import { BLOCK } from "./common"; 2 | 3 | export declare function onalloc(s: BLOCK): void; 4 | export declare function onrealloc(sOld: BLOCK, sNew: BLOCK): void; 5 | export declare function onincrement(s: BLOCK): void; 6 | export declare function ondecrement(s: BLOCK): void; 7 | export declare function onfree(s: BLOCK): void; 8 | -------------------------------------------------------------------------------- /tests/compiler/issues/1095.ts: -------------------------------------------------------------------------------- 1 | class Foo { 2 | bar: string | null = "test"; 3 | } 4 | 5 | function test(foo: Foo): void { 6 | // Make sure that the temp obtained for `foo` (`.bar` is loaded AND stored) 7 | // does not conflict with temps obtained and freed in the RHS expression. 8 | foo.bar = foo.bar!; 9 | } 10 | 11 | test(new Foo()); 12 | -------------------------------------------------------------------------------- /tests/parser/type-signature.ts: -------------------------------------------------------------------------------- 1 | type foo = () => void; 2 | type foo = (() => void) | null; 3 | type foo = (a: i32) => i32; 4 | type foo = (a?: i32) => i32; 5 | type foo = (this: AClass, a: i32) => i32; 6 | type foo = () => () => void; 7 | type foo = () => (() => void) | null; 8 | type foo = (this: AClass, a: i32) => ((this: BClass, b?: f32) => i32) | null; 9 | -------------------------------------------------------------------------------- /tests/compiler/continue.ts: -------------------------------------------------------------------------------- 1 | // see https://github.com/AssemblyScript/assemblyscript/issues/813 2 | export function testInherit(b: bool): void { 3 | for (let i = 0; i < 10; i++) { 4 | if (b) { 5 | if (i == 5) { 6 | continue; 7 | } 8 | // inheritConditional 9 | } 10 | // yielding a continue block 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/compiler/export-default.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 0) 4 | (table $0 1 funcref) 5 | (export "memory" (memory $0)) 6 | (export "theDefault" (func $export-default/theDefault)) 7 | (export "default" (func $export-default/theDefault)) 8 | (func $export-default/theDefault (; 0 ;) 9 | nop 10 | ) 11 | ) 12 | -------------------------------------------------------------------------------- /tests/compiler/typealias.ts: -------------------------------------------------------------------------------- 1 | export type alias = i32; 2 | // TODO: Without 'export' this yields 'ERROR TS2395: Individual declarations in merged declaration...' 3 | // which differs from TypeScript, but we don't have individual element and type spaces per file and this 4 | // just merges. 5 | 6 | export function alias(a: alias): alias { 7 | return a; 8 | } 9 | -------------------------------------------------------------------------------- /tests/parser/type-signature.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | type foo = () => void; 2 | type foo = (() => void) | null; 3 | type foo = (a: i32) => i32; 4 | type foo = (a?: i32) => i32; 5 | type foo = (this: AClass, a: i32) => i32; 6 | type foo = () => () => void; 7 | type foo = () => (() => void) | null; 8 | type foo = (this: AClass, a: i32) => ((this: BClass, b?: f32) => i32) | null; 9 | -------------------------------------------------------------------------------- /tests/compiler/declare.ts: -------------------------------------------------------------------------------- 1 | declare function externalFunction(): void; 2 | declare const externalConstant: i32; 3 | 4 | externalFunction(); 5 | assert(externalConstant == 1); 6 | 7 | declare namespace my { 8 | function externalFunction(): void; 9 | const externalConstant: i32; 10 | } 11 | 12 | my.externalFunction(); 13 | assert(my.externalConstant == 2); 14 | -------------------------------------------------------------------------------- /tests/compiler/extends-baseaggregate.ts: -------------------------------------------------------------------------------- 1 | class A1 { 2 | private padding0: f64; 3 | private padding1: f64; 4 | private c1: C1; 5 | } 6 | 7 | class A2 extends A1 { } 8 | 9 | class B1 { 10 | private a1: A1; 11 | } 12 | 13 | class C1 { 14 | private a2: A2; 15 | } 16 | 17 | const poolB: B1[] = []; 18 | const poolA: A2[] = []; 19 | poolA.push(new A2()); 20 | -------------------------------------------------------------------------------- /tests/compiler/memorybase.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 1) 3 | (data (i32.const 1024) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00h\00e\00l\00l\00o\00 \00w\00o\00r\00l\00d\00") 4 | (table $0 1 funcref) 5 | (global $memorybase/staticString i32 (i32.const 1040)) 6 | (global $~lib/ASC_MEMORY_BASE i32 (i32.const 1024)) 7 | (export "memory" (memory $0)) 8 | ) 9 | -------------------------------------------------------------------------------- /std/assembly/shared/target.ts: -------------------------------------------------------------------------------- 1 | // This file is shared with the compiler and must remain portable 2 | 3 | /** Compilation target. */ 4 | export enum Target { 5 | /** WebAssembly with 32-bit pointers. */ 6 | WASM32, 7 | /** WebAssembly with 64-bit pointers. Experimental and not supported by any runtime yet. */ 8 | WASM64, 9 | /** Portable. */ 10 | JS 11 | } 12 | -------------------------------------------------------------------------------- /tests/compiler/bool.ts: -------------------------------------------------------------------------------- 1 | var i = 2; 2 | assert(i == true); 3 | var I = 2; 4 | assert(I == true); 5 | var u = 2; 6 | assert(u == true); 7 | var U = 2; 8 | assert(U == true); 9 | var f = 2; 10 | assert(f == true); 11 | var F = 2; 12 | assert(F == true); 13 | var uu = 2; 14 | assert(uu == true); 15 | -------------------------------------------------------------------------------- /examples/n-body/scripts/postprocess-asmjs.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | const path = require("path"); 3 | 4 | const filename = path.join(__dirname, "..", "build" , "index.asm.js"); 5 | var source = fs.readFileSync(filename, { encoding: "utf8" }); 6 | source = source.replace(/^export var ([^ ]+) =/mg, ($0, $1) => "exports." + $1 + " = "); 7 | fs.writeFileSync(filename, source); 8 | -------------------------------------------------------------------------------- /tests/compiler/constant-assign.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ], 5 | "stderr": [ 6 | "TS2540: Cannot assign to", "b = 3;", 7 | "TS2540: Cannot assign to", "a = 2;", 8 | "TS2540: Cannot assign to", "b = [ 2 ];", 9 | "TS2540: Cannot assign to", "a = [ 2 ];", 10 | "TS2540: Cannot assign to", "a = 2;", 11 | "EOF" 12 | ] 13 | } -------------------------------------------------------------------------------- /tests/compiler/exportimport-table.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (import "env" "table" (table $0 2 funcref)) 4 | (elem (i32.const 1) $start:exportimport-table~anonymous|0) 5 | (memory $0 0) 6 | (export "memory" (memory $0)) 7 | (export "table" (table $0)) 8 | (func $start:exportimport-table~anonymous|0 (; 0 ;) 9 | nop 10 | ) 11 | ) 12 | -------------------------------------------------------------------------------- /tests/compiler/rereexport.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (global $export/a i32 (i32.const 1)) 4 | (global $export/b i32 (i32.const 2)) 5 | (export "memory" (memory $0)) 6 | (export "a" (global $export/a)) 7 | (export "renamed_a" (global $export/a)) 8 | (export "renamed_b" (global $export/b)) 9 | (export "renamed_renamed_b" (global $export/b)) 10 | ) 11 | -------------------------------------------------------------------------------- /examples/sdk/README.md: -------------------------------------------------------------------------------- 1 | Browser SDK 2 | =========== 3 | 4 | An [AssemblyScript](http://assemblyscript.org) example using the [AssemblyScript browser SDK](https://github.com/AssemblyScript/assemblyscript/tree/master/lib/sdk). 5 | 6 | Instructions 7 | ------------ 8 | 9 | Open [index.html](./index.html) in a browser and see the console. View the source to learn how it works. 10 | -------------------------------------------------------------------------------- /tests/compiler/class-overloading.ts: -------------------------------------------------------------------------------- 1 | class Foo { 2 | baz(): void {} 3 | } 4 | class Bar extends Foo { 5 | baz(): void {} 6 | } 7 | export function test(foo: Foo): void { 8 | foo.baz(); 9 | } 10 | // FIXME: this results in a call to Foo.baz instead of Bar.baz above. 11 | // ultimately, overloaded functions should implicitly become virtual. 12 | test(changetype(0)); 13 | -------------------------------------------------------------------------------- /tests/compiler/features/js-bigint-integration.ts: -------------------------------------------------------------------------------- 1 | declare const externalValue: i64; 2 | declare function getExternalValue(): i64; 3 | 4 | assert(externalValue == 9007199254740991); 5 | assert(getExternalValue() == externalValue); 6 | 7 | export const internalValue: i64 = 9007199254740991; 8 | 9 | export function getInternalValue(): i64 { 10 | return internalValue; 11 | } 12 | -------------------------------------------------------------------------------- /tests/compiler/resolve-elementaccess.ts: -------------------------------------------------------------------------------- 1 | var arr = new Float32Array(2); 2 | arr[0] = 1; 3 | arr[1] = 2; 4 | assert( 5 | arr[0].toString() 6 | == 7 | "1.0" 8 | ); 9 | assert( 10 | (arr[1]).toString() 11 | == 12 | "2.0" 13 | ); 14 | assert( 15 | (arr[0] += 10).toString() 16 | == 17 | "11.0" 18 | ); 19 | arr[0] += 10; // void context 20 | assert(arr[0] == 21.0); 21 | -------------------------------------------------------------------------------- /tests/compiler/tablebase.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 0) 4 | (table $0 33 funcref) 5 | (elem (i32.const 32) $tablebase/foo) 6 | (global $tablebase/staticFunction i32 (i32.const 32)) 7 | (global $~lib/ASC_TABLE_BASE i32 (i32.const 32)) 8 | (export "memory" (memory $0)) 9 | (func $tablebase/foo (; 0 ;) 10 | nop 11 | ) 12 | ) 13 | -------------------------------------------------------------------------------- /tests/compiler/wildcard-export.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 0) 3 | (global $export/a i32 (i32.const 1)) 4 | (global $export/b i32 (i32.const 2)) 5 | (export "memory" (memory $0)) 6 | (export "a" (global $export/a)) 7 | (export "renamed_a" (global $export/a)) 8 | (export "renamed_b" (global $export/b)) 9 | (export "renamed_renamed_b" (global $export/b)) 10 | ) 11 | -------------------------------------------------------------------------------- /tests/parser/numeric-separators.ts: -------------------------------------------------------------------------------- 1 | 11_11_11; 2 | 0b01_01_01; 3 | 0o12_12_12; 4 | 0x23_23_23; 5 | 6 | // error cases that should still continue parsing: 7 | 8 | 11_11_11_; // 6188 9 | 11__11_11; // 6189 10 | 11 | 0b01_01_01_; // 6188 12 | 0b01__01_01; // 6189 13 | 14 | 0o12_12_12_; // 6188 15 | 0o12__12_12; // 6189 16 | 17 | 0x23_23_23_; // 6188 18 | 0x23__23_23; // 6189 19 | -------------------------------------------------------------------------------- /tests/compiler/ternary.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 0) 4 | (global $ternary/a (mut i32) (i32.const 0)) 5 | (export "memory" (memory $0)) 6 | (start $~start) 7 | (func $~start (; 0 ;) 8 | i32.const 1 9 | global.set $ternary/a 10 | i32.const 1 11 | global.set $ternary/a 12 | i32.const 1 13 | global.set $ternary/a 14 | ) 15 | ) 16 | -------------------------------------------------------------------------------- /std/assembly.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig-base.json", 3 | "compilerOptions": { 4 | "target": "esnext", 5 | "module": "commonjs", 6 | "noLib": true, 7 | "allowJs": false, 8 | "typeRoots": [ "types" ], 9 | "types": [ "assembly" ], 10 | "baseUrl": ".", 11 | "paths": { 12 | "*": [ 13 | "./assembly/*" 14 | ] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /std/assembly/bindings/Date.ts: -------------------------------------------------------------------------------- 1 | export declare function UTC( 2 | // NOTE: Using i32 below saves us a f64.convert_s instruction and moves the responsibility for 3 | // converting the value to the WASM/JS boundary. 4 | year: i32, 5 | month: i32, 6 | day: i32, 7 | hour: i32, 8 | minute: i32, 9 | second: i32, 10 | millisecond: f64 11 | ): f64; 12 | export declare function now(): f64; 13 | -------------------------------------------------------------------------------- /std/assembly/gc.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | /** Garbage collector interface. */ 4 | export namespace gc { 5 | 6 | /** Can be set to `false` to disable automatic collection. Defaults to `true`. */ 7 | export var auto: bool = true; 8 | 9 | /** Performs a full garbage collection cycle. */ 10 | export function collect(): void { 11 | __collect(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/parser/reserved-keywords.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | function alsoIdentifier(readonly: i32): void {} 2 | class AClass { 3 | constructor(readonly: i32) {} 4 | constructor(readonly readonly: i32) {} 5 | } 6 | type type = i32; 7 | var type: i32; 8 | type = 123; 9 | namespace namespace {} 10 | var namespace: i32; 11 | namespace = 123; 12 | abstract class AClass {} 13 | var abstract: i32; 14 | abstract = 123; 15 | -------------------------------------------------------------------------------- /examples/mandelbrot/build/optimized.d.ts: -------------------------------------------------------------------------------- 1 | declare module ASModule { 2 | type i8 = number; 3 | type i16 = number; 4 | type i32 = number; 5 | type u8 = number; 6 | type u16 = number; 7 | type u32 = number; 8 | type f32 = number; 9 | type f64 = number; 10 | type bool = any; 11 | export function computeLine(y: u32, width: u32, height: u32, limit: u32): void; 12 | } 13 | export default ASModule; 14 | -------------------------------------------------------------------------------- /std/assembly/bindings/Reflect.ts: -------------------------------------------------------------------------------- 1 | export declare function get(target: anyref, propertyKey: anyref/*, receiver: anyref*/): anyref; 2 | export declare function has(target: anyref, propertyKey: anyref): bool; 3 | export declare function set(target: anyref, propertyKey: anyref, value: anyref/*, receiver: anyref*/): anyref; 4 | export declare function apply(target: anyref, thisArgument: anyref, argumentsList: anyref): anyref; 5 | -------------------------------------------------------------------------------- /tests/compiler/asc-constants.ts: -------------------------------------------------------------------------------- 1 | ASC_TARGET; 2 | ASC_NO_ASSERT; 3 | ASC_MEMORY_BASE; 4 | ASC_OPTIMIZE_LEVEL; 5 | ASC_SHRINK_LEVEL; 6 | 7 | ASC_FEATURE_SIGN_EXTENSION; 8 | ASC_FEATURE_MUTABLE_GLOBALS; 9 | ASC_FEATURE_NONTRAPPING_F2I; 10 | ASC_FEATURE_BULK_MEMORY; 11 | ASC_FEATURE_SIMD; 12 | ASC_FEATURE_THREADS; 13 | ASC_FEATURE_EXCEPTION_HANDLING; 14 | ASC_FEATURE_TAIL_CALLS; 15 | ASC_FEATURE_REFERENCE_TYPES; 16 | -------------------------------------------------------------------------------- /tests/parser/reserved-keywords.ts: -------------------------------------------------------------------------------- 1 | function alsoIdentifier(readonly: i32): void {} 2 | class AClass { 3 | constructor(readonly: i32) {} 4 | constructor(readonly readonly: i32) {} 5 | } 6 | 7 | type type = i32; 8 | var type: i32; 9 | type = 123; 10 | 11 | namespace namespace {} 12 | var namespace: i32; 13 | namespace = 123; 14 | 15 | abstract class AClass {} 16 | var abstract: i32; 17 | abstract = 123; 18 | -------------------------------------------------------------------------------- /examples/game-of-life/assembly/config.ts: -------------------------------------------------------------------------------- 1 | // On the WASM side, 32-bit color values are modified in ABGR order (alpha, blue, green, red) 2 | // because WASM is little endian. This results in RGBA in memory, which is exactly what the image 3 | // buffer, composed of 8-bit components, expects on the JS side. 4 | export declare const BGR_ALIVE: u32; 5 | export declare const BGR_DEAD: u32; 6 | export declare const BIT_ROT: u32; 7 | -------------------------------------------------------------------------------- /examples/transform/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "test:js": "asc assembly/index.ts --runtime none --transform mytransform.js", 4 | "test:ts": "asc assembly/index.ts --runtime none --transform mytransform.ts", 5 | "test:multi": "asc assembly/index.ts --runtime none --transform mytransform.js --transform mytransform.ts", 6 | "test": "npm run test:js && npm run test:ts && npm run test:multi" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /lib/libm/README.md: -------------------------------------------------------------------------------- 1 | # ![AS](https://avatars1.githubusercontent.com/u/28916798?s=48) libm 2 | 3 | AssemblyScript's math routines for double and single precision as a library. 4 | 5 | ```ts 6 | const libm = require("@assemblyscript/libm"); 7 | const libmf = libm.libmf; 8 | ... 9 | ``` 10 | 11 | Both `libm` and `libmf` have the same general interface as JavaScript's `Math`, with `libmf` doing single precision math. 12 | -------------------------------------------------------------------------------- /tests/parser/regexp.ts: -------------------------------------------------------------------------------- 1 | /(abc)\//ig; // with modifiers 2 | /(abc)\//; // without modifiers 3 | var re = /(abc)\//ig; // can be assigned 4 | var noRe = !/(abc)\//i; // generally behaves like an expression 5 | /a 6 | b/ig; // inner line break is unterminated 7 | //ig; 8 | /(abc)\//iig; // duplicate flags 9 | /(abc)\//iX; // invalid flags 10 | false && /abc/gX.test(someString) || true; // surrounding AST remains intact 11 | -------------------------------------------------------------------------------- /lib/libm/index.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | const libm = new WebAssembly.Instance(new WebAssembly.Module(fs.readFileSync("./build/libm.wasm")), { Math }).exports; 3 | const libmf = new WebAssembly.Instance(new WebAssembly.Module(fs.readFileSync("./build/libmf.wasm")), {}).exports; 4 | module.exports = Object.create(libm, { 5 | libm: { value: libm, enumerable: true }, 6 | libmf: { value: libmf, enumerable: true } 7 | }); 8 | -------------------------------------------------------------------------------- /tests/parser/trailing-commas.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | import { 2 | a, 3 | b 4 | } from "c"; 5 | enum Foo { 6 | A, 7 | B 8 | } 9 | function add(x: i32, y: i32): i32 { 10 | return x + y; 11 | } 12 | function parameterized(a: A, b: B): void {} 13 | export function compute(): i32 { 14 | const arr: Array = [1, 2]; 15 | parameterized(0, 0); 16 | return add(1, 2); 17 | } 18 | export { 19 | a, 20 | b 21 | }; 22 | -------------------------------------------------------------------------------- /tests/compiler/external.ts: -------------------------------------------------------------------------------- 1 | export declare function foo(): void; // external , foo 2 | export declare namespace foo { 3 | export function bar(): void; // external , foo.bar 4 | } 5 | 6 | @external("bar") 7 | export declare function two(): void; // external , bar 8 | 9 | @external("foo", "baz") 10 | export declare function three(): void; // foo , baz 11 | 12 | @external("foo", "var") // foo , var 13 | export declare const var_: i32; 14 | -------------------------------------------------------------------------------- /tests/compiler/literals.ts: -------------------------------------------------------------------------------- 1 | 0; 2 | 1; 3 | 2; 4 | 3; 5 | 4; 6 | 5; 7 | 6; 8 | 7; 9 | 8; 10 | 9; 11 | 0x0; 12 | 0x1; 13 | 0x2; 14 | 0x3; 15 | 0x4; 16 | 0x5; 17 | 0x6; 18 | 0x7; 19 | 0x8; 20 | 0x9; 21 | 0xA; 22 | 0xB; 23 | 0xC; 24 | 0xD; 25 | 0xE; 26 | 0xF; 27 | 0xa; 28 | 0xb; 29 | 0xc; 30 | 0xd; 31 | 0xe; 32 | 0xf; 33 | 0o0; 34 | 0o1; 35 | 0o2; 36 | 0o3; 37 | 0o4; 38 | 0o5; 39 | 0o6; 40 | 0o7; 41 | 0b0; 42 | 0b1; 43 | true; 44 | false; 45 | -------------------------------------------------------------------------------- /tests/compiler/std/date.ts: -------------------------------------------------------------------------------- 1 | assert(Date.UTC(1970, 0, 1) == 0); 2 | assert(Date.UTC(1970, 0, 1, 0, 0, 0, 0) == 0); 3 | 4 | var creationTime = Date.UTC(2018, 10, 10, 11, 0, 0, 1); 5 | assert(creationTime == 1541847600001); 6 | 7 | assert(Date.now() > creationTime); 8 | 9 | var date = new Date(creationTime); 10 | assert(date.getTime() == creationTime); 11 | date.setTime(creationTime + 1); 12 | assert(date.getTime() == creationTime + 1); 13 | -------------------------------------------------------------------------------- /tests/compiler/rc/global-init.ts: -------------------------------------------------------------------------------- 1 | function getRef(): string { 2 | return ""; 3 | } 4 | 5 | // Assignment of a return value picks up its delayed release state and skips 6 | // one set of retain/release. 7 | 8 | var a: string = getRef(); 9 | var b = getRef(); // same, but inferred 10 | 11 | // Unleak 12 | 13 | a = /* __retainRelease( */ changetype(0) /* , a) */; 14 | b = /* __retainRelease( */ changetype(0) /* , a) */; 15 | -------------------------------------------------------------------------------- /src/util/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Various compiler utilities. 3 | * @module util 4 | * @preferred 5 | *//***/ 6 | 7 | export * from "./bitset"; 8 | export * from "./charcode"; 9 | export * from "./collections"; 10 | export * from "./path"; 11 | export * from "./text"; 12 | export * from "./binary"; 13 | 14 | /** Tests if `x` is a power of two. */ 15 | export function isPowerOf2(x: i32): bool { 16 | return x != 0 && (x & (x - 1)) == 0; 17 | } 18 | -------------------------------------------------------------------------------- /std/assembly/regexp.ts: -------------------------------------------------------------------------------- 1 | export class RegExp { 2 | 3 | // @binding(CALL_NEW, [ STRING, STRING], OBJECT_HANDLE) 4 | constructor(pattern: string, flags: string = "") { throw new Error("unreachable"); } 5 | 6 | // @binding(CALL_THIS, [ STRING ], PASS_THRU) 7 | test(search: string): bool { throw new Error("unreachable"); } 8 | 9 | // @binding(CALL_THIS, [], STRING) 10 | toString(): string { throw new Error("unreachable"); } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /tests/compiler/named-import-default.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_i32 (func (result i32))) 3 | (memory $0 0) 4 | (table $0 1 funcref) 5 | (export "memory" (memory $0)) 6 | (export "getValue" (func $named-import-default/getValue)) 7 | (func $named-export-default/get3 (; 0 ;) (result i32) 8 | i32.const 3 9 | ) 10 | (func $named-import-default/getValue (; 1 ;) (result i32) 11 | call $named-export-default/get3 12 | ) 13 | ) 14 | -------------------------------------------------------------------------------- /tests/compiler/duplicate-identifier.ts: -------------------------------------------------------------------------------- 1 | var a: i32; 2 | var a: f32; 3 | 4 | class Foo { 5 | b: i32; 6 | b: f32; 7 | static c: i32; 8 | static c: f32; 9 | } 10 | 11 | namespace Bar { 12 | const d: i32 = 0; 13 | const d: f32 = 1; 14 | } 15 | 16 | function baz(): void { 17 | var e: i32; 18 | var e: f32; 19 | { 20 | let f: i32; 21 | let f: f32; 22 | } 23 | } 24 | 25 | baz(); 26 | 27 | ERROR("EOF"); // mark end and ensure fail 28 | -------------------------------------------------------------------------------- /tests/compiler/features/reference-types.js: -------------------------------------------------------------------------------- 1 | exports.preInstantiate = function(imports, exports) { 2 | imports.Reflect = Reflect; 3 | imports.console = { 4 | log: function(ref) { 5 | console.log(" log: " + ref); 6 | } 7 | }; 8 | imports["reference-types"] = { 9 | external: function(a) { 10 | return a; 11 | }, 12 | someObject: { 13 | theKey: "Hello world!" 14 | }, 15 | someKey: "theKey" 16 | }; 17 | }; 18 | -------------------------------------------------------------------------------- /tests/binaryen/multi-value.js: -------------------------------------------------------------------------------- 1 | var binaryen = require("binaryen"); 2 | 3 | var mod = new binaryen.Module(); 4 | var ii = binaryen.createType([ binaryen.i32, binaryen.i32 ]); 5 | var func = mod.addFunction("test", ii, ii, [], 6 | mod.unreachable() 7 | ); 8 | mod.addExport("test", "test"); 9 | 10 | console.log(mod.emitText()); 11 | if (!mod.validate()) 12 | console.log("-> does not validate"); 13 | 14 | mod.optimize(); 15 | console.log(mod.emitText()); 16 | -------------------------------------------------------------------------------- /tests/compiler/ReturnType.ts: -------------------------------------------------------------------------------- 1 | assert(isInteger i8>>()); 2 | assert(isSigned i8>>()); 3 | assert(sizeof i8>>() == 1); // i32 4 | 5 | assert(isFloat f64>>()); 6 | assert(sizeof f64>>() == 8); 7 | 8 | class SomeExample { 9 | a: f64; 10 | b: f64; 11 | } 12 | 13 | assert(isManaged SomeExample>>()); 14 | assert(offsetof SomeExample>>() == 16); 15 | -------------------------------------------------------------------------------- /tests/packages/packages/g/test.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | let asc = require("../../../../cli/asc"); 3 | 4 | let argv = [ 5 | "assembly/index.ts", 6 | "--noEmit", 7 | "--runtime", "stub", 8 | "--validate", 9 | "--traceResolution" 10 | ]; 11 | 12 | asc.main(argv, error => { 13 | if (/Import file .*lib\/a.ts.* not found/g.test(error.message)) { 14 | process.exit(0); 15 | } 16 | console.error("Failed!\n" + error); 17 | process.exit(1); 18 | }); 19 | -------------------------------------------------------------------------------- /tests/binaryen/precompute-join.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $ii (func (param i32) (result i32))) 3 | (export "fls" (func $assembly/tlsf/fls)) 4 | (func $assembly/tlsf/fls (; 8 ;) (type $ii) (param $0 i32) (result i32) 5 | (return 6 | (i32.sub 7 | (i32.sub 8 | (i32.shl 9 | (i32.const 4) 10 | (i32.const 3) 11 | ) 12 | (i32.clz 13 | (get_local $0) 14 | ) 15 | ) 16 | (i32.const 1) 17 | ) 18 | ) 19 | ) 20 | ) 21 | -------------------------------------------------------------------------------- /tests/compiler/i64-polyfill.ts: -------------------------------------------------------------------------------- 1 | export { 2 | getHi, 3 | getLo, 4 | 5 | clz, 6 | ctz, 7 | popcnt, 8 | eqz, 9 | add, 10 | sub, 11 | mul, 12 | div_s, 13 | div_u, 14 | rem_s, 15 | rem_u, 16 | and, 17 | or, 18 | xor, 19 | shl, 20 | shr_s, 21 | shr_u, 22 | rotl, 23 | rotr, 24 | eq, 25 | ne, 26 | lt_s, 27 | lt_u, 28 | le_s, 29 | le_u, 30 | gt_s, 31 | gt_u, 32 | ge_s, 33 | ge_u 34 | } from "../../lib/i64/assembly/i64"; 35 | -------------------------------------------------------------------------------- /tests/compiler/inlining-recursive.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 0) 4 | (export "memory" (memory $0)) 5 | (export "foo" (func $inlining-recursive/foo)) 6 | (export "bar" (func $inlining-recursive/baz)) 7 | (export "baz" (func $inlining-recursive/baz)) 8 | (func $inlining-recursive/foo (; 0 ;) 9 | call $inlining-recursive/foo 10 | ) 11 | (func $inlining-recursive/baz (; 1 ;) 12 | call $inlining-recursive/baz 13 | ) 14 | ) 15 | -------------------------------------------------------------------------------- /examples/game-of-life/build/optimized.d.ts: -------------------------------------------------------------------------------- 1 | declare module ASModule { 2 | type i8 = number; 3 | type i16 = number; 4 | type i32 = number; 5 | type u8 = number; 6 | type u16 = number; 7 | type u32 = number; 8 | type f32 = number; 9 | type f64 = number; 10 | type bool = any; 11 | export function init(width: i32, height: i32): void; 12 | export function step(): void; 13 | export function fill(x: u32, y: u32, p: f64): void; 14 | } 15 | export default ASModule; 16 | -------------------------------------------------------------------------------- /src/glue/wasm/float.ts: -------------------------------------------------------------------------------- 1 | /** @module glue/wasm *//***/ 2 | 3 | @global 4 | function f32_as_i32(value: f32): i32 { 5 | return reinterpret(value); 6 | } 7 | 8 | @global 9 | function i32_as_f32(value: i32): f32 { 10 | return reinterpret(value); 11 | } 12 | 13 | @global 14 | function f64_as_i64(value: f64): i64 { 15 | return reinterpret(value); 16 | } 17 | 18 | @global 19 | function i64_as_f64(value: i64): f64 { 20 | return reinterpret(value); 21 | } 22 | -------------------------------------------------------------------------------- /tests/allocators/buddy/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "build": "npm run build:untouched && npm run build:optimized", 5 | "build:untouched": "node ../../../bin/asc assembly/index.ts -t untouched.wat -b untouched.wasm --runtime none --validate --sourceMap --measure", 6 | "build:optimized": "node ../../../bin/asc assembly/index.ts -t optimized.wat -b optimized.wasm --runtime none --validate --sourceMap --measure --noAssert --optimize" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/allocators/rt-full/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "build": "npm run build:untouched && npm run build:optimized", 5 | "build:untouched": "node ../../../bin/asc assembly/index.ts -t untouched.wat -b untouched.wasm --runtime full --validate --sourceMap --measure", 6 | "build:optimized": "node ../../../bin/asc assembly/index.ts -t optimized.wat -b optimized.wasm --runtime full --validate --sourceMap --measure --noAssert --optimize" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/allocators/rt-stub/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "build": "npm run build:untouched && npm run build:optimized", 5 | "build:untouched": "node ../../../bin/asc assembly/index.ts -t untouched.wat -b untouched.wasm --runtime stub --validate --sourceMap --measure", 6 | "build:optimized": "node ../../../bin/asc assembly/index.ts -t optimized.wat -b optimized.wasm --runtime stub --validate --sourceMap --measure --noAssert --optimize" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/binaryen/const-expr.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $iii (func (param i32 i32) (result i32))) 3 | (type $i (func (result i32))) 4 | (export "add" (func $add)) 5 | (export "test" (func $test)) 6 | (func $add (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) 7 | (i32.add 8 | (get_local $0) 9 | (get_local $1) 10 | ) 11 | ) 12 | (func $test (; 1 ;) (type $i) (result i32) 13 | (call $add 14 | (i32.const 1) 15 | (i32.const 2) 16 | ) 17 | ) 18 | ) 19 | 20 | -------------------------------------------------------------------------------- /tests/compiler/namespace.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 0) 4 | (global $namespace/Outer.Inner.anotherVar (mut i32) (i32.const 0)) 5 | (global $namespace/Outer.Inner.evenAnotherVar (mut i32) (i32.const 0)) 6 | (export "memory" (memory $0)) 7 | (start $~start) 8 | (func $~start (; 0 ;) 9 | i32.const 0 10 | global.set $namespace/Outer.Inner.anotherVar 11 | i32.const 1 12 | global.set $namespace/Outer.Inner.evenAnotherVar 13 | ) 14 | ) 15 | -------------------------------------------------------------------------------- /tests/compiler/class-extends.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_=>_none (func (param i32))) 3 | (memory $0 0) 4 | (export "memory" (memory $0)) 5 | (export "test" (func $class-extends/test)) 6 | (func $class-extends/test (; 0 ;) (param $0 i32) 7 | local.get $0 8 | i32.load 9 | drop 10 | local.get $0 11 | i32.load16_s offset=4 12 | drop 13 | local.get $0 14 | i32.const 2 15 | i32.store 16 | local.get $0 17 | i32.const 3 18 | i32.store16 offset=4 19 | ) 20 | ) 21 | -------------------------------------------------------------------------------- /tests/util-path.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | const assert = require("assert"); 3 | 4 | require("ts-node").register({ project: path.join(__dirname, "..", "src", "tsconfig.json") }); 5 | require("../src/glue/js"); 6 | 7 | const { normalize, resolve } = require("../src/util/path"); 8 | 9 | var test = "./Y/./N/./N/../../././../Y/./."; 10 | assert.strictEqual(normalize(test), path.posix.normalize(test)); 11 | 12 | assert.strictEqual(resolve("../../..", "lib/util/i64.ts"), ".."); 13 | -------------------------------------------------------------------------------- /std/assembly/table.ts: -------------------------------------------------------------------------------- 1 | import { E_NOTIMPLEMENTED } from "./util/error"; 2 | 3 | export namespace table { 4 | 5 | export function copy(dst: u32, src: u32, n: u32): void { 6 | throw new Error(E_NOTIMPLEMENTED); 7 | } 8 | 9 | export function init(elementIndex: u32, srcOffset: u32, dstOffset: u32, n: u32): void { 10 | throw new Error(E_NOTIMPLEMENTED); 11 | } 12 | 13 | export function drop(elementIndex: u32): void { 14 | throw new Error(E_NOTIMPLEMENTED); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiler/comma.ts: -------------------------------------------------------------------------------- 1 | var a = 0, b = 0; 2 | 3 | b = a++, a; // lower precedence (like separate expressions) 4 | assert(a == 1); 5 | assert(b == 0); 6 | 7 | a++, b = a; 8 | assert(a == 2); 9 | assert(b == 2); 10 | 11 | a = b = 0; 12 | 13 | b = (a++, a); // higher precedence 14 | assert(a == 1); 15 | assert(b == 1); 16 | 17 | a = (a++, b = a); 18 | assert(a == 2); 19 | assert(b == 2); 20 | 21 | for (var c = 0; c < a; a--, c++); 22 | assert(c == 1); 23 | 24 | 1, 2, 3; // tsc doesn't allow this 25 | -------------------------------------------------------------------------------- /src/util/text.ts: -------------------------------------------------------------------------------- 1 | /** @module util *//***/ 2 | 3 | const indentX1 = " "; 4 | const indentX2 = " "; 5 | const indentX4 = " "; 6 | 7 | /** Creates an indentation matching the number of specified levels. */ 8 | export function indent(sb: string[], level: i32): void { 9 | while (level >= 4) { 10 | sb.push(indentX4); 11 | level -= 4; 12 | } 13 | if (level >= 2) { 14 | sb.push(indentX2); 15 | level -= 2; 16 | } 17 | if (level) { 18 | sb.push(indentX1); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/compiler/features/mutable-globals.js: -------------------------------------------------------------------------------- 1 | exports.preInstantiate = function(imports, exports) { 2 | imports["mutable-globals"] = { 3 | external: new WebAssembly.Global({ value: "i32", mutable: true }, 123) 4 | }; 5 | }; 6 | exports.postInstantiate = function(instance) { 7 | // adds 10 to both 8 | const exports = instance.exports; 9 | if (exports.external.valueOf() != 133) throw Error("unexpected value"); 10 | if (exports.internal.valueOf() != 134) throw Error("unexpected value"); 11 | }; 12 | -------------------------------------------------------------------------------- /lib/lint/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@assemblyscript/lint", 3 | "version": "1.0.0", 4 | "main": "index.json", 5 | "scripts": { 6 | "build": "tsc --project ./src --outDir . --diagnostics" 7 | }, 8 | "peerDependencies": { 9 | "tslint": "^5.11.0" 10 | }, 11 | "devDependencies": { 12 | "typescript": "^3.1.2" 13 | }, 14 | "files": [ 15 | "base.json", 16 | "index.json", 17 | "package.json", 18 | "README.md", 19 | "rules/", 20 | "formatters/" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /lib/webpack/README.md: -------------------------------------------------------------------------------- 1 | ![AS](https://avatars1.githubusercontent.com/u/28916798?s=48) webpack 2 | ================= 3 | 4 | [webpack](https://webpack.js.org/) loader for [AssemblyScript](http://assemblyscript.org) modules. 5 | 6 | Usage 7 | ----- 8 | 9 | ```js 10 | import MyModule from "@assemblyscript/webpack!mymodule.wasm"; 11 | 12 | var myModule = new MyModule({ imports: { /* if any */ } }); 13 | ``` 14 | 15 | TODO: Pipe .ts files through `asc`, accepting the usual options, but also keep raw .wasm support. 16 | -------------------------------------------------------------------------------- /tests/parser/namespace.ts: -------------------------------------------------------------------------------- 1 | declare namespace A { 2 | namespace B { 3 | export namespace C { 4 | var aVar: i32; 5 | const aConst: i32; 6 | const aConstInvalid: i32 = 0; // 1039: Initializers are not allowed in ambient contexts. 7 | function aFunc(): void; 8 | function aFuncInvalid(): void {} // 1183: An implementation cannot be declared in ambient contexts. 9 | enum AnEnum {} 10 | class AClass {} 11 | } 12 | namespace D { 13 | var aVar: i32; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/compiler/new.ts: -------------------------------------------------------------------------------- 1 | class Ref { 2 | get ref(): Ref { return this; } 3 | } 4 | 5 | var ref: Ref; 6 | ref = new Ref(); 7 | ref = new Ref; 8 | ref = new Ref().ref; 9 | 10 | class Gen { 11 | get gen(): Gen { return this; } 12 | } 13 | 14 | var gen: Gen; 15 | gen = new Gen(); 16 | gen = new Gen().gen; 17 | 18 | namespace ns { 19 | export class Ref { 20 | get ref(): Ref { return this; } 21 | } 22 | } 23 | 24 | var ref2: ns.Ref; 25 | ref2 = new ns.Ref(); 26 | ref2 = new ns.Ref; 27 | ref2 = new ns.Ref().ref; 28 | -------------------------------------------------------------------------------- /tests/parser/regexp.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | /(abc)\//ig; 2 | /(abc)\//; 3 | var re = /(abc)\//ig; 4 | var noRe = !/(abc)\//i; 5 | b / ig; 6 | /(abc)\//iig; 7 | /(abc)\//iX; 8 | false && /abc/gX.test(someString) || true; 9 | // ERROR 1161: "Unterminated regular expression literal." in regexp.ts:5:1 10 | // ERROR 1005: "'/' expected." in regexp.ts:5:0 11 | // ERROR 209: "Invalid regular expression flags." in regexp.ts:8:9 12 | // ERROR 209: "Invalid regular expression flags." in regexp.ts:9:9 13 | // ERROR 209: "Invalid regular expression flags." in regexp.ts:10:14 14 | -------------------------------------------------------------------------------- /scripts/clean.js: -------------------------------------------------------------------------------- 1 | var fs = require("fs"); 2 | var glob = require("glob"); 3 | 4 | glob("*", { cwd: __dirname + "/../dist" }, (err, matches) => { 5 | if (err) 6 | console.log("Failed to list files in 'dist/': " + err.message); 7 | else 8 | matches.forEach(match => { 9 | fs.unlink(__dirname + "/../dist/" + match, err => { 10 | if (err) 11 | console.log("Failed to delete 'dist/" + match + "': " + err.message); 12 | else 13 | console.log("Deleted 'dist/" + match + "'"); 14 | }); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /tests/compiler/duplicate-identifier.json: -------------------------------------------------------------------------------- 1 | { 2 | "asc_flags": [ 3 | "--runtime none" 4 | ], 5 | "stderr": [ 6 | "TS2300: Duplicate identifier 'a'", "var a: f32", "var a: i32", 7 | "TS2300: Duplicate identifier 'b'", "b: f32", "b: i32", 8 | "TS2300: Duplicate identifier 'c'", "static c: f32", " static c: i32", 9 | "TS2300: Duplicate identifier 'd'", "const d: f32", "const d: i32", 10 | "TS2300: Duplicate identifier 'e'", "var e: f32", "var e: i32", 11 | "TS2300: Duplicate identifier 'f'", "let f: f32", 12 | "EOF" 13 | ] 14 | } -------------------------------------------------------------------------------- /tests/compiler/loop-wrap.ts: -------------------------------------------------------------------------------- 1 | export function testAlwaysWrapped(): void { 2 | var i: u8 = 0; // <-- 3 | do { 4 | if (i == 10) break; // no need to wrap 5 | } while (i = (i + 1) & 0xff); // <-- 6 | } 7 | 8 | export function testFirstWrapped(): void { 9 | var i: u8 = 0; 10 | do { 11 | if (i == 10) break; // must wrap 12 | } while (++i); // <-- 13 | } 14 | 15 | export function testSubsequentWrapped(a: i32): void { 16 | var i = a; // <-- 17 | do { 18 | if (i == 10) break; // must wrap 19 | } while (i = (i + 1) & 0xff); 20 | } 21 | -------------------------------------------------------------------------------- /tests/compiler/recursive.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_=>_i32 (func (param i32) (result i32))) 3 | (memory $0 0) 4 | (export "memory" (memory $0)) 5 | (export "fib" (func $recursive/fib)) 6 | (func $recursive/fib (; 0 ;) (param $0 i32) (result i32) 7 | local.get $0 8 | i32.const 1 9 | i32.le_s 10 | if 11 | i32.const 1 12 | return 13 | end 14 | local.get $0 15 | i32.const 1 16 | i32.sub 17 | call $recursive/fib 18 | local.get $0 19 | i32.const 2 20 | i32.sub 21 | call $recursive/fib 22 | i32.add 23 | ) 24 | ) 25 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Automatically close questions and other uncategorized issues on inactivity 2 | only: issues 3 | daysUntilStale: 30 4 | daysUntilClose: 7 5 | exemptLabels: 6 | - bug 7 | - enhancement 8 | exemptProjects: true 9 | exemptMilestones: true 10 | exemptAssignees: true 11 | staleLabel: stale 12 | markComment: > 13 | This issue has been automatically marked as stale because it has not had 14 | recent activity. It will be closed if no further activity occurs. Thank you 15 | for your contributions. 16 | closeComment: false 17 | limitPerRun: 1 18 | -------------------------------------------------------------------------------- /std/assembly/bindings/console.ts: -------------------------------------------------------------------------------- 1 | export declare function assert(value: anyref): void; 2 | export declare function clear(): void; 3 | export declare function error(value: anyref): void; 4 | export declare function info(value: anyref): void; 5 | export declare function log(value: anyref): void; 6 | export declare function time(label: anyref): anyref; 7 | export declare function timeEnd(label: anyref): void; 8 | export declare function timeLog(label: anyref): void; 9 | export declare function trace(): void; 10 | export declare function warn(value: anyref): void; 11 | -------------------------------------------------------------------------------- /tests/compiler/limits.ts: -------------------------------------------------------------------------------- 1 | i8.MIN_VALUE; 2 | i8.MAX_VALUE; 3 | i16.MIN_VALUE; 4 | i16.MAX_VALUE; 5 | i32.MIN_VALUE; 6 | i32.MAX_VALUE; 7 | i64.MIN_VALUE; 8 | i64.MAX_VALUE; 9 | isize.MIN_VALUE; 10 | isize.MAX_VALUE; 11 | u8.MIN_VALUE; 12 | u8.MAX_VALUE; 13 | u16.MIN_VALUE; 14 | u16.MAX_VALUE; 15 | u32.MIN_VALUE; 16 | u32.MAX_VALUE; 17 | u64.MIN_VALUE; 18 | u64.MAX_VALUE; 19 | usize.MIN_VALUE; 20 | usize.MAX_VALUE; 21 | bool.MIN_VALUE; 22 | bool.MAX_VALUE; 23 | f32.MIN_SAFE_INTEGER; 24 | f32.MAX_SAFE_INTEGER; 25 | f64.MIN_SAFE_INTEGER; 26 | f64.MAX_SAFE_INTEGER; 27 | -------------------------------------------------------------------------------- /tests/compiler/rc/local-init.ts: -------------------------------------------------------------------------------- 1 | { 2 | // Normal assignment will retain and release. 3 | 4 | let a = /* __retain( */ "" /* ) */; 5 | // __release(a) 6 | } 7 | 8 | function getRef(): string { 9 | return /* __retain( */ "" /* ) */; 10 | } 11 | 12 | { 13 | // Assignment of a return value picks up its skipped autorelease 14 | 15 | let b = getRef(); 16 | // __release(b); 17 | } 18 | 19 | class Ref {} 20 | 21 | { 22 | // Assignment of an instantiation picks up its skipped autorelease 23 | 24 | let c = new Ref(); 25 | // __release(c); 26 | } 27 | -------------------------------------------------------------------------------- /tests/compiler/std/array-access.ts: -------------------------------------------------------------------------------- 1 | export function i32ArrayArrayElementAccess(a: i32[][]): i32 { 2 | return a[0][1]; 3 | } 4 | 5 | export function stringArrayPropertyAccess(a: string[]): i32 { 6 | return a[0].length; 7 | } 8 | 9 | export function stringArrayMethodCall(a: string[]): i32 { 10 | return a[0].startsWith(""); 11 | } 12 | 13 | export function stringArrayArrayPropertyAccess(a: string[][]): i32 { 14 | return a[0][1].length; 15 | } 16 | 17 | export function stringArrayArrayMethodCall(a: string[][]): i32 { 18 | return a[0][1].startsWith(""); 19 | } 20 | -------------------------------------------------------------------------------- /tests/compiler/std/object-literal.ts: -------------------------------------------------------------------------------- 1 | class Foo { 2 | bar: i32; 3 | baz: string; 4 | } 5 | 6 | function bar(foo: Foo): void { 7 | assert(foo.bar == 1); 8 | assert(foo.baz == "hello world"); 9 | } 10 | 11 | bar({ bar: 1, baz: "hello world" }); 12 | 13 | class Foo2 { 14 | bar: i32; 15 | constructor() { 16 | this.bar = 1; 17 | } 18 | test(): void { 19 | assert(this.bar == 3); 20 | } 21 | } 22 | 23 | function bar2(foo: Foo2): void { 24 | assert(foo.bar == 2); 25 | } 26 | 27 | bar2({ bar: 2 }); 28 | 29 | ({ bar: 3 }).test(); 30 | -------------------------------------------------------------------------------- /tests/packages/packages/d/assembly/d.ts: -------------------------------------------------------------------------------- 1 | import { C, BC, ABC } from "c"; 2 | import { E } from "e"; 3 | import { AS } from "as"; 4 | 5 | export function D(): string { 6 | return "D"; 7 | } 8 | 9 | export function CD(): string { 10 | return C() + D(); 11 | } 12 | 13 | export function BCD(): string { 14 | return BC() + D(); 15 | } 16 | 17 | export function ABCD(): string { 18 | return ABC() + D(); 19 | } 20 | 21 | export function ABCDE(): string { 22 | return ABCD() + E(); 23 | } 24 | 25 | export function ABCDS(): string { 26 | return AS(ABCD()); 27 | } 28 | -------------------------------------------------------------------------------- /tests/compiler/call-optional.ts: -------------------------------------------------------------------------------- 1 | function opt(a: i32, b: i32 = -1, c: i32 = -2): i32 { 2 | return a + b + c; 3 | } 4 | assert(opt(3) == 0); // calls the trampoline with 0of2 5 | assert(opt(3, 4) == 5); // calls the trampoline with 1of2 6 | assert(opt(3, 4, 5) == 12); // calls the function directly 7 | 8 | var optIndirect = opt; 9 | assert(optIndirect(3) == 0); // calls the trampoline indirectly with 0of2 10 | assert(optIndirect(3, 4) == 5); // calls the trampoline indirectly with 1of2 11 | assert(optIndirect(3, 4, 5) == 12); // calls the trampoline indirectly with 2of2 12 | -------------------------------------------------------------------------------- /tests/compiler/reexport.ts: -------------------------------------------------------------------------------- 1 | export { 2 | add, 3 | sub as renamed_sub, 4 | renamed_mul, 5 | renamed_mul as rerenamed_mul, 6 | 7 | a, 8 | b as renamed_b, 9 | renamed_c, 10 | renamed_c as rerenamed_c 11 | } from "./export"; 12 | 13 | import { 14 | add as imported_add, 15 | renamed_mul as imported_sub, 16 | ns as imported_ns 17 | } from "./export"; 18 | 19 | export { 20 | imported_add as renamed_add, 21 | imported_sub as rerenamed_sub 22 | }; 23 | 24 | imported_add(1, 2) + imported_sub(3, 4); 25 | 26 | export { ns as renamed_ns } from "./export"; 27 | -------------------------------------------------------------------------------- /tests/compiler/ternary.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 0) 4 | (table $0 1 funcref) 5 | (global $ternary/a (mut i32) (i32.const 0)) 6 | (export "memory" (memory $0)) 7 | (start $~start) 8 | (func $start:ternary (; 0 ;) 9 | i32.const 1 10 | drop 11 | i32.const 1 12 | drop 13 | i32.const 1 14 | drop 15 | i32.const 1 16 | global.set $ternary/a 17 | i32.const 1 18 | global.set $ternary/a 19 | i32.const 1 20 | global.set $ternary/a 21 | ) 22 | (func $~start (; 1 ;) 23 | call $start:ternary 24 | ) 25 | ) 26 | -------------------------------------------------------------------------------- /tests/parser/parameter-order.ts: -------------------------------------------------------------------------------- 1 | function restValid(a: i32, ...b: i32[]): void {} 2 | function optionalValid(a: i32, b?: i32): void {} 3 | 4 | // 1014: A rest parameter must be last in a parameter list. 5 | function restParameterMustBeLast(...a: i32[], b: i32): void {} 6 | 7 | // 1016: A required parameter cannot follow an optional parameter. 8 | function optionalCannotPrecedeRequired(a?: i32, b: i32): void {} 9 | 10 | // 1016: A required parameter cannot follow an optional parameter. 11 | function optionalWithInitializerCannotPrecedeRequired(a: i32 = 1, b: i32): void {} 12 | -------------------------------------------------------------------------------- /examples/pson/README.md: -------------------------------------------------------------------------------- 1 | PSON decoder in WebAssembly 2 | =========================== 3 | 4 | An [AssemblyScript](http://assemblyscript.org) example. Decodes a [PSON](https://github.com/dcodeIO/PSON) encoded buffer. 5 | 6 | Instructions 7 | ------------ 8 | 9 | To build [assembly/pson.ts](./assembly/pson.ts) to an untouched and an optimized `.wasm` including their respective `.wat` representations, run: 10 | 11 | ``` 12 | $> npm run asbuild 13 | ``` 14 | 15 | Afterwards, to run the included [test](./tests/index.js): 16 | 17 | ``` 18 | $> npm install 19 | $> npm test 20 | ``` 21 | -------------------------------------------------------------------------------- /examples/pson/tests/index.js: -------------------------------------------------------------------------------- 1 | var Long = require("long"); 2 | 3 | var psonJS = require("pson"); 4 | var psonWASM = require(".."); 5 | 6 | // encode in JS 7 | var buf = new psonJS.Encoder().encode({ 8 | emptyObject: {}, 9 | emptyArray: [], 10 | emptyString: "", 11 | object: { 12 | aSmallInt: 42, 13 | anInt: 9000, 14 | aLong: Long.MIN_VALUE.add(1) 15 | }, 16 | array: [ 17 | 0.25, // fits into float 18 | 0.1 // always a double 19 | ], 20 | binary: Buffer.from([1, 2, 3]) 21 | }).toBuffer(); 22 | 23 | // decode in WASM 24 | psonWASM.decode(buf); 25 | -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | Portable compiler sources that compile to both JavaScript using `tsc` and, eventually, WebAssembly using `asc`. 2 | 3 | Architecture 4 | ------------ 5 | 6 | ![](https://assemblyscript.github.io/assemblyscript/media/architecture.svg) 7 | 8 | Usage 9 | ----- 10 | 11 | Note that using the compiler as a library requires awaiting Binaryen ready state, like so: 12 | 13 | ```js 14 | const binaryen = require("binaryen"); 15 | const assemblyscript = require("assemblyscript"); 16 | binaryen.ready.then(() => { 17 | // do something with assemblyscript 18 | }); 19 | ``` 20 | -------------------------------------------------------------------------------- /tests/compiler/recursive.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_=>_i32 (func (param i32) (result i32))) 3 | (memory $0 0) 4 | (table $0 1 funcref) 5 | (export "memory" (memory $0)) 6 | (export "fib" (func $recursive/fib)) 7 | (func $recursive/fib (; 0 ;) (param $0 i32) (result i32) 8 | local.get $0 9 | i32.const 1 10 | i32.le_s 11 | if 12 | i32.const 1 13 | return 14 | end 15 | local.get $0 16 | i32.const 1 17 | i32.sub 18 | call $recursive/fib 19 | local.get $0 20 | i32.const 2 21 | i32.sub 22 | call $recursive/fib 23 | i32.add 24 | ) 25 | ) 26 | -------------------------------------------------------------------------------- /tests/binaryen/set_global-immutable.js: -------------------------------------------------------------------------------- 1 | var binaryen = require("binaryen"); 2 | 3 | // "It is a validation error for a set_global to index an immutable global variable." 4 | 5 | var mod = new binaryen.Module(); 6 | mod.addGlobal("a", binaryen.i32, false, mod.i32.const(0)); 7 | 8 | var funcType = mod.addFunctionType("v", binaryen.none, []); 9 | var func = mod.addFunction("start", funcType, [], mod.block("", [ 10 | mod.setGlobal("a", mod.i32.const(1)) 11 | ])); 12 | mod.setStart(func); 13 | 14 | console.log(mod.emitText()); 15 | if (mod.validate()) 16 | console.log("-> validates"); 17 | -------------------------------------------------------------------------------- /tests/compiler/inlining-recursive.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 0) 4 | (table $0 1 funcref) 5 | (export "memory" (memory $0)) 6 | (export "foo" (func $inlining-recursive/foo)) 7 | (export "bar" (func $inlining-recursive/bar)) 8 | (export "baz" (func $inlining-recursive/baz)) 9 | (func $inlining-recursive/foo (; 0 ;) 10 | call $inlining-recursive/foo 11 | ) 12 | (func $inlining-recursive/baz (; 1 ;) 13 | call $inlining-recursive/bar 14 | ) 15 | (func $inlining-recursive/bar (; 2 ;) 16 | call $inlining-recursive/baz 17 | ) 18 | ) 19 | -------------------------------------------------------------------------------- /tests/parser/also-identifier.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | class Foo { 2 | as: i32; 3 | declare: i32; 4 | delete: i32; 5 | from: i32; 6 | for: i32; 7 | get: i32; 8 | instanceof: i32; 9 | is: i32; 10 | keyof: i32; 11 | module: i32; 12 | namespace: i32; 13 | null: i32; 14 | readonly: i32; 15 | set: i32; 16 | type: i32; 17 | void: i32; 18 | } 19 | var as: i32; 20 | var constructor: i32; 21 | var declare: i32; 22 | var from: i32; 23 | var get: i32; 24 | var is: i32; 25 | var keyof: i32; 26 | var module: i32; 27 | var namespace: i32; 28 | var readonly: i32; 29 | var set: i32; 30 | -------------------------------------------------------------------------------- /tests/runtime/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "server": "http-server . -o -c-1", 5 | "build": "npm run build:untouched && npm run build:optimized", 6 | "build:untouched": "node ../../bin/asc assembly/index.ts -t untouched.wat -b untouched.wasm --runtime full --validate --sourceMap --measure", 7 | "build:optimized": "node ../../bin/asc assembly/index.ts -t optimized.wat -b optimized.wasm --runtime full --validate --sourceMap --measure --noAssert --optimize" 8 | }, 9 | "devDependencies": { 10 | "http-server": "^0.11.1" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/binaryen/optimize-if-eqz.js: -------------------------------------------------------------------------------- 1 | var binaryen = require("binaryen"); 2 | 3 | var mod = new binaryen.Module(); 4 | var funcType = mod.addFunctionType("i", binaryen.i32, [ binaryen.i32 ]); 5 | var func = mod.addFunction("test", funcType, [], 6 | mod.if( 7 | mod.i32.eqz(mod.getLocal(0, binaryen.i32)), 8 | mod.i32.const(0), 9 | mod.getLocal(0, binaryen.i32) 10 | ) 11 | ); 12 | mod.addExport("test", "test"); 13 | 14 | console.log(mod.emitText()); 15 | if (!mod.validate()) 16 | console.log("-> does not validate"); 17 | 18 | mod.optimize(); 19 | console.log(mod.emitText()); 20 | -------------------------------------------------------------------------------- /tests/compiler/resolve-access.ts: -------------------------------------------------------------------------------- 1 | export function arrayAccess(): string { 2 | let arr: u64[] = [1]; 3 | return arr[0].toString(); 4 | } 5 | 6 | class Container { 7 | foo: u64; 8 | 9 | toU32(): u32 { 10 | return this.foo as u32; 11 | } 12 | } 13 | 14 | export function fieldAccess(): string { 15 | let container = new Container(); 16 | container.foo = 1; 17 | return container.foo.toString(); 18 | } 19 | 20 | export function propertyAccess(): string { 21 | let container = new Container(); 22 | container.foo = 1; 23 | return container.toU32().toString(); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /tests/parser/definite-assignment-assertion.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | class C { 2 | x!: i32; 3 | x!: i32 = 0; 4 | static x!: i32; 5 | } 6 | function f(): void { 7 | let x!: i32; 8 | let x!: i32 = 0; 9 | } 10 | // ERROR 1255: "A definite assignment assertion '!' is not permitted in this context." in definite-assignment-assertion.ts:3:10 11 | // ERROR 1255: "A definite assignment assertion '!' is not permitted in this context." in definite-assignment-assertion.ts:4:14 12 | // ERROR 1255: "A definite assignment assertion '!' is not permitted in this context." in definite-assignment-assertion.ts:8:6 13 | -------------------------------------------------------------------------------- /examples/n-body/assembly/index.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | const path = require("path"); 3 | 4 | const compiled = new WebAssembly.Module( 5 | fs.readFileSync(path.resolve(__dirname, "..", "build", "optimized.wasm")) 6 | ); 7 | 8 | const imports = { 9 | env: { 10 | memory: new WebAssembly.Memory({ initial: 10 }), 11 | abort: (filename, line, column) => { 12 | throw Error("abort called at " + line + ":" + column); 13 | } 14 | } 15 | }; 16 | 17 | Object.defineProperty(module, "exports", { 18 | get: () => new WebAssembly.Instance(compiled, imports).exports 19 | }); 20 | -------------------------------------------------------------------------------- /src/glue/js/float.js: -------------------------------------------------------------------------------- 1 | const F64 = new Float64Array(1); 2 | const F32 = new Float32Array(F64.buffer); 3 | const I32 = new Int32Array(F64.buffer); 4 | 5 | global.f32_as_i32 = function(value) { 6 | F32[0] = value; 7 | return I32[0]; 8 | }; 9 | 10 | global.i32_as_f32 = function(value) { 11 | I32[0] = value; 12 | return F32[0]; 13 | }; 14 | 15 | global.f64_as_i64 = function(value) { 16 | F64[0] = value; 17 | return i64_new(I32[0], I32[1]); 18 | }; 19 | 20 | global.i64_as_f64 = function(value) { 21 | I32[0] = i64_low(value); 22 | I32[1] = i64_high(value); 23 | return F64[0]; 24 | }; 25 | -------------------------------------------------------------------------------- /tests/compiler/inlining-blocklocals.ts: -------------------------------------------------------------------------------- 1 | var b: i32 = 2; 2 | 3 | var theCall_a: i32; 4 | var theCall_b: i32; 5 | var theCall_c: i32; 6 | 7 | @inline function theCall(a: i32, b: i32, c: i32): void { 8 | theCall_a = a; 9 | theCall_b = b; 10 | theCall_c = c; 11 | } 12 | 13 | function test(): void { 14 | var a = 1; 15 | // see comment in Compiler#makeCallInlinePrechecked 16 | // theCall($3, $2=[except $3], $1=[except $3,$2]) 17 | theCall(a++, b++, ++a); 18 | assert(theCall_a == 1); 19 | assert(theCall_b == 2); 20 | assert(theCall_c == 3); 21 | assert(a == 3); 22 | } 23 | test(); 24 | -------------------------------------------------------------------------------- /examples/n-body/rust/index.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | const path = require("path"); 3 | 4 | const compiled = new WebAssembly.Module( 5 | fs.readFileSync(path.resolve(__dirname, "..", "build", "rust.optimized.wasm")) 6 | ); 7 | 8 | const imports = { 9 | env: { 10 | memory: new WebAssembly.Memory({ initial: 17 }), 11 | abort: (_filename, line, column) => { 12 | throw Error("abort called at " + line + ":" + column); 13 | } 14 | } 15 | }; 16 | 17 | Object.defineProperty(module, "exports", { 18 | get: () => new WebAssembly.Instance(compiled, imports).exports 19 | }); 20 | -------------------------------------------------------------------------------- /examples/pson/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@assemblyscript/pson-example", 3 | "version": "1.0.0", 4 | "private": true, 5 | "scripts": { 6 | "asbuild": "npm run asbuild:untouched && npm run asbuild:optimized", 7 | "asbuild:untouched": "asc assembly/pson.ts -b build/untouched.wasm -t build/untouched.wat --validate --sourceMap --debug --measure", 8 | "asbuild:optimized": "asc -O assembly/pson.ts -b build/optimized.wasm -t build/optimized.wat --validate --sourceMap --measure", 9 | "test": "node tests" 10 | }, 11 | "devDependencies": { 12 | "pson": "^2.0.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/compiler/closure.ts: -------------------------------------------------------------------------------- 1 | function testParam($local0: i32, $local1: i32): (value: i32) => i32 { 2 | return function inner(value: i32) { 3 | return $local1; // closure 4 | }; 5 | } 6 | testParam(1, 2); 7 | 8 | function testVar(): (value: i32) => i32 { 9 | var $local0 = 0; 10 | return function inner(value: i32) { 11 | return $local0; // closure 12 | }; 13 | } 14 | testVar(); 15 | 16 | function testLet(): (value: i32) => i32 { 17 | let $local0 = 0; 18 | return function inner(value: i32) { 19 | return $local0; // closure 20 | }; 21 | } 22 | testLet(); 23 | 24 | ERROR("EOF"); 25 | -------------------------------------------------------------------------------- /tests/compiler/std/string.js: -------------------------------------------------------------------------------- 1 | exports.preInstantiate = function preInstantiate(imports) { 2 | imports.string = { 3 | toUpperCaseFromIndex: function toUpperCaseFromIndex(index, codePointIndex) { 4 | const code = String.fromCodePoint(index).toUpperCase().codePointAt(codePointIndex|0); 5 | return code !== undefined ? code : -1; 6 | }, 7 | toLowerCaseFromIndex: function toLowerCaseFromIndex(index, codePointIndex) { 8 | const code = String.fromCodePoint(index).toLowerCase().codePointAt(codePointIndex|0); 9 | return code !== undefined ? code : -1; 10 | } 11 | }; 12 | }; -------------------------------------------------------------------------------- /tests/allocators/forever.js: -------------------------------------------------------------------------------- 1 | var child_process = require("child_process"); 2 | 3 | // restarts the test forever, that is, until an issue is detected 4 | 5 | if (process.argv.length < 2) { 6 | console.error("Usage: npm run test:forever "); 7 | process.exit(1); 8 | } 9 | 10 | var count = 0; 11 | while (true) { 12 | console.log("[ #" + ++count + " ]\n"); 13 | var res = child_process.spawnSync("node", [ "./index", process.argv[2] ], { stdio: "inherit" }); 14 | if (res.status !== 0) 15 | throw Error("exited with " + res.status); 16 | if (res.error) 17 | throw res.error; 18 | } 19 | -------------------------------------------------------------------------------- /tests/parser/namespace.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | declare namespace A { 2 | namespace B { 3 | export namespace C { 4 | var aVar: i32; 5 | const aConst: i32; 6 | const aConstInvalid: i32 = 0; 7 | function aFunc(): void; 8 | function aFuncInvalid(): void {} 9 | enum AnEnum {} 10 | class AClass {} 11 | } 12 | namespace D { 13 | var aVar: i32; 14 | } 15 | } 16 | } 17 | // ERROR 1039: "Initializers are not allowed in ambient contexts." in namespace.ts:6:31 18 | // ERROR 1183: "An implementation cannot be declared in ambient contexts." in namespace.ts:8:36 19 | -------------------------------------------------------------------------------- /tests/compiler/constant-assign.ts: -------------------------------------------------------------------------------- 1 | function localConst(a: i32): void { 2 | const b = a + 1; 3 | b = 3; 4 | } 5 | localConst(1); 6 | 7 | function localConstInline(): void { 8 | const a = 1; 9 | a = 2; 10 | } 11 | localConstInline(); 12 | 13 | function localConstArray(a: i32): void { 14 | const b: i32[] = [ a ]; 15 | b = [ 2 ]; 16 | } 17 | localConstArray(1); 18 | 19 | function localConstArrayInline(): void { 20 | const a: i32[] = [ 1 ]; 21 | a = [ 2 ]; 22 | } 23 | localConstArrayInline(); 24 | 25 | // globalConst 26 | const a = 1; 27 | a = 2; 28 | 29 | ERROR("EOF"); // mark end and ensure fail 30 | -------------------------------------------------------------------------------- /tests/binaryen/const-global.js: -------------------------------------------------------------------------------- 1 | var binaryen = require("binaryen"); 2 | 3 | var mod = new binaryen.Module(); 4 | 5 | mod.addGlobal("testGlobal", binaryen.i32, false, mod.i32.const(2)); 6 | var funcType = mod.addFunctionType("i", binaryen.i32, []); 7 | mod.addFunction("test", funcType, [], 8 | mod.get_global("testGlobal", binaryen.i32) 9 | ); 10 | mod.addFunctionExport("test", "test"); 11 | 12 | binaryen.setOptimizeLevel(4); 13 | binaryen.setShrinkLevel(0); 14 | binaryen.setDebugInfo(false); 15 | mod.optimize(); 16 | if (!mod.validate()) 17 | console.log("-> does not validate"); 18 | console.log(mod.emitText()); 19 | -------------------------------------------------------------------------------- /tests/compiler/call-inferred.ts: -------------------------------------------------------------------------------- 1 | function foo(a: T): T { 2 | return a; 3 | } 4 | 5 | assert(foo(42) == 42); 6 | assert(foo(42.0) == 42); 7 | assert(foo(42.0) == 42); 8 | 9 | function bar(a: T = 42.0): T { 10 | return a; 11 | } 12 | 13 | assert(bar() == 42); 14 | 15 | // TODO: this'd require return type inference, i.e., omitted return type 16 | // function baz(a: i32): T { 17 | // return a; 18 | // } 19 | // baz(42); 20 | 21 | // TODO: this'd ideally be inferred by matching contextualType, avoiding conversions 22 | // function baz(): T { 23 | // return 1; 24 | // } 25 | // baz(42); 26 | -------------------------------------------------------------------------------- /tests/parser/literals.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | 0; 2 | 1; 3 | 2; 4 | 3; 5 | 4; 6 | 5; 7 | 6; 8 | 7; 9 | 8; 10 | 9; 11 | 2147483647; 12 | 0; 13 | 1; 14 | 2; 15 | 3; 16 | 4; 17 | 5; 18 | 6; 19 | 7; 20 | 8; 21 | 9; 22 | 10; 23 | 11; 24 | 12; 25 | 13; 26 | 14; 27 | 15; 28 | 2147483647; 29 | 10; 30 | 11; 31 | 12; 32 | 13; 33 | 14; 34 | 15; 35 | 2147483647; 36 | 0; 37 | 1; 38 | 2; 39 | 3; 40 | 4; 41 | 5; 42 | 6; 43 | 7; 44 | 2147483647; 45 | 0; 46 | 1; 47 | 2147483647; 48 | 0; 49 | 0.123; 50 | 0; 51 | 0.123; 52 | 12.34; 53 | 10; 54 | 10; 55 | 10; 56 | 10; 57 | 0.1; 58 | 0.1; 59 | "123"; 60 | "1\"23"; 61 | "1\"2\\3"; 62 | "\0\n\\n\r"; 63 | -------------------------------------------------------------------------------- /tests/binaryen/const-local.js: -------------------------------------------------------------------------------- 1 | var binaryen = require("binaryen"); 2 | 3 | var mod = new binaryen.Module(); 4 | 5 | var funcType = mod.addFunctionType("i", binaryen.i32, [ binaryen.i32 ]); 6 | mod.addFunction("test", funcType, [], mod.block("", [ 7 | mod.setLocal(0, mod.i32.const(2)), 8 | mod.getLocal(0, binaryen.i32) 9 | ], binaryen.i32)); 10 | mod.addFunctionExport("test", "test"); 11 | 12 | binaryen.setOptimizeLevel(4); 13 | binaryen.setShrinkLevel(0); 14 | binaryen.setDebugInfo(false); 15 | mod.optimize(); 16 | if (!mod.validate()) 17 | console.log("-> does not validate"); 18 | console.log(mod.emitText()); 19 | -------------------------------------------------------------------------------- /tests/compiler/optional-typeparameters.ts: -------------------------------------------------------------------------------- 1 | function testConcrete(a: T): U { 2 | return a; 3 | } 4 | 5 | function testDerived(a: T): U { 6 | return a; 7 | } 8 | 9 | testConcrete(1); 10 | testDerived(2); 11 | 12 | class TestConcrete { 13 | test(a: T, b: U): V { 14 | return a + b; 15 | } 16 | } 17 | 18 | class TestDerived { 19 | test(a: T, b: U): V { 20 | return a + b; 21 | } 22 | } 23 | 24 | var tConcrete = new TestConcrete(); 25 | tConcrete.test(1, 2); 26 | var tDerived = new TestDerived() 27 | tDerived.test(1, 2); 28 | -------------------------------------------------------------------------------- /tests/compiler/exportimport-table.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (import "env" "table" (table $0 2 funcref)) 4 | (elem (i32.const 1) $start:exportimport-table~anonymous|0) 5 | (memory $0 0) 6 | (global $exportimport-table/f (mut i32) (i32.const 1)) 7 | (export "memory" (memory $0)) 8 | (export "table" (table $0)) 9 | (start $~start) 10 | (func $start:exportimport-table~anonymous|0 (; 0 ;) 11 | nop 12 | ) 13 | (func $start:exportimport-table (; 1 ;) 14 | global.get $exportimport-table/f 15 | drop 16 | ) 17 | (func $~start (; 2 ;) 18 | call $start:exportimport-table 19 | ) 20 | ) 21 | -------------------------------------------------------------------------------- /tests/compiler/external.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (import "foo" "var" (global $external/var_ i32)) 4 | (import "external" "foo" (func $external/foo)) 5 | (import "external" "foo.bar" (func $external/foo.bar)) 6 | (import "external" "bar" (func $external/two)) 7 | (import "foo" "baz" (func $external/three)) 8 | (memory $0 0) 9 | (export "memory" (memory $0)) 10 | (export "foo" (func $external/foo)) 11 | (export "foo.bar" (func $external/foo.bar)) 12 | (export "two" (func $external/two)) 13 | (export "three" (func $external/three)) 14 | (export "var_" (global $external/var_)) 15 | ) 16 | -------------------------------------------------------------------------------- /bin/asc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* tslint:disable */ 4 | 5 | const tailArgs = process.argv.indexOf("--"); 6 | if (~tailArgs) { 7 | require("child_process").spawnSync( 8 | process.argv[0], 9 | process.argv.slice(tailArgs + 1).concat( 10 | process.argv.slice(1, tailArgs) 11 | ), 12 | { stdio: "inherit" } 13 | ); 14 | return; 15 | } 16 | 17 | try { require("source-map-support").install(); } catch (e) {} 18 | 19 | const asc = module.exports = require("../cli/asc.js"); 20 | if (/\basc$/.test(process.argv[1])) { 21 | asc.ready.then(() => process.exitCode = asc.main(process.argv.slice(2))); 22 | } 23 | -------------------------------------------------------------------------------- /tests/binaryen/get_global-missing.js: -------------------------------------------------------------------------------- 1 | var binaryen = require("binaryen"); 2 | 3 | var mod = new binaryen.Module(); 4 | var funcType = mod.addFunctionType("v", binaryen.void, []); 5 | var func = mod.addFunction("test", funcType, [], 6 | mod.block("", [ 7 | mod.drop( 8 | mod.getGlobal("missing", binaryen.i32) 9 | ) 10 | ]) 11 | ); 12 | mod.addFunctionExport("test", "test", func); 13 | 14 | console.log(mod.emitText()); 15 | if (mod.validate()) 16 | console.log("-> validates"); 17 | mod.emitBinary(); // -> Assertion failed: mappedGlobals.count(name), at: binaryen/src/wasm/wasm-binary.cpp,355,getGlobalIndex at Error 18 | -------------------------------------------------------------------------------- /tests/compiler/features/js-bigint-integration.js: -------------------------------------------------------------------------------- 1 | exports.preInstantiate = function(imports, exports) { 2 | const externalValue = 9007199254740991n; 3 | imports["js-bigint-integration"] = { 4 | externalValue, 5 | getExternalValue: function() { 6 | return externalValue; 7 | }, 8 | }; 9 | }; 10 | exports.postInstantiate = function(instance) { 11 | const exports = instance.exports; 12 | const internalValue = exports.internalValue; 13 | if (internalValue != 9007199254740991n) throw Error("unexpected value"); 14 | if (exports.getInternalValue() != internalValue) throw Error("unexpected value"); 15 | }; 16 | -------------------------------------------------------------------------------- /tests/compiler/instanceof-class.ts: -------------------------------------------------------------------------------- 1 | class Parent { 2 | } 3 | 4 | class Child extends Parent { 5 | } 6 | 7 | class SomethingElse { 8 | } 9 | 10 | var a: Child = new Child(); 11 | assert(a instanceof Child); // static true 12 | assert(a instanceof Parent); // static true 13 | assert(!(a instanceof SomethingElse)); // static false 14 | 15 | var b: Parent = new Child(); 16 | assert(b instanceof Parent); // static true 17 | assert(b instanceof Child); // dynamic true (checks Child, Child) 18 | assert(!(b instanceof SomethingElse)); // static false 19 | -------------------------------------------------------------------------------- /tests/compiler/class.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_=>_i32 (func (param i32) (result i32))) 3 | (memory $0 0) 4 | (export "memory" (memory $0)) 5 | (export "test" (func $class/test)) 6 | (func $class/test (; 0 ;) (param $0 i32) (result i32) 7 | local.get $0 8 | i32.load 9 | drop 10 | local.get $0 11 | i32.load16_s offset=4 12 | drop 13 | local.get $0 14 | i32.load8_s offset=6 15 | drop 16 | local.get $0 17 | i32.const 1 18 | i32.store 19 | local.get $0 20 | i32.const 2 21 | i32.store16 offset=4 22 | local.get $0 23 | i32.const 3 24 | i32.store8 offset=6 25 | local.get $0 26 | ) 27 | ) 28 | -------------------------------------------------------------------------------- /tests/compiler/rc/logical-and-mismatch.ts: -------------------------------------------------------------------------------- 1 | class Ref {} 2 | 3 | function getRef(): Ref { 4 | return new Ref(); 5 | } 6 | 7 | var gloRef = new Ref(); 8 | 9 | { 10 | // Left skips autorelease, right doesn't 11 | let a = /* t = */ getRef() && /* __release(t), */ gloRef; 12 | // __release(a) 13 | } 14 | { 15 | // Right skips autorelease, left doesn't 16 | let b = gloRef && getRef(); 17 | } 18 | { 19 | // Both skip autorelease, for completeness 20 | let c = getRef() && getRef(); 21 | } 22 | { 23 | // Both don't 24 | let d = gloRef && gloRef; 25 | } 26 | 27 | // Unleak 28 | 29 | __release(changetype(gloRef)); 30 | -------------------------------------------------------------------------------- /tests/compiler/rc/logical-or-mismatch.ts: -------------------------------------------------------------------------------- 1 | class Ref {} 2 | 3 | function getRef(): Ref { 4 | return new Ref(); 5 | } 6 | 7 | var gloRef = new Ref(); 8 | 9 | { 10 | // Left skips autorelease, right doesn't 11 | let a = /* t = */ getRef() || /* __release(t), */ gloRef; 12 | // __release(a) 13 | } 14 | { 15 | // Right skips autorelease, left doesn't 16 | let b = gloRef || getRef(); 17 | } 18 | { 19 | // Both skip autorelease, for completeness 20 | let c = getRef() || getRef(); 21 | } 22 | { 23 | // Both don't 24 | let d = gloRef || gloRef; 25 | } 26 | 27 | // Unleak 28 | 29 | __release(changetype(gloRef)); 30 | -------------------------------------------------------------------------------- /tests/compiler/export.ts: -------------------------------------------------------------------------------- 1 | export function add(a: i32, b: i32): i32 { 2 | return a + b; 3 | } 4 | 5 | function sub(a: i32, b: i32): i32 { 6 | return a - b; 7 | } 8 | 9 | export { sub }; 10 | 11 | function mul(a: i32, b: i32): i32 { // not exported as "mul" 12 | return a * b; 13 | } 14 | 15 | export { mul as renamed_mul }; 16 | 17 | export const a: i32 = 1; 18 | 19 | const b: i32 = 2; 20 | 21 | export { b }; 22 | 23 | const c: i32 = 3; // not exported as "c" 24 | 25 | export { c as renamed_c }; 26 | 27 | export namespace ns { 28 | function one(): void {} 29 | export function two(): void {} 30 | } 31 | 32 | export default ns; 33 | -------------------------------------------------------------------------------- /tests/compiler/std/hash.ts: -------------------------------------------------------------------------------- 1 | import { HASH } from "util/hash"; 2 | 3 | function check(hash: u32): bool { 4 | return true; 5 | } 6 | 7 | check(HASH(null)); 8 | check(HASH("")); 9 | check(HASH("a")); 10 | check(HASH("ab")); 11 | check(HASH("abc")); 12 | 13 | check(HASH(0.0)); 14 | check(HASH(1.0)); 15 | check(HASH(1.1)); 16 | check(HASH(-0)); 17 | check(HASH(Infinity)); 18 | check(HASH(NaN)); 19 | 20 | check(HASH(0.0)); 21 | check(HASH(1.0)); 22 | check(HASH(1.1)); 23 | check(HASH(-0)); 24 | check(HASH(Infinity)); 25 | check(HASH(NaN)); 26 | -------------------------------------------------------------------------------- /tests/binaryen/block-stack.js: -------------------------------------------------------------------------------- 1 | var binaryen = require("binaryen"); 2 | 3 | // "non-final block elements returning a value must be drop()ed" 4 | // "0 == 0: block with value must not have last element that is none, on" 5 | 6 | var mod = new binaryen.Module(); 7 | 8 | var funcType = mod.addFunctionType("i", binaryen.i32, []); 9 | var func = mod.addFunction("test", funcType, [ binaryen.i32 ], 10 | mod.block("", [ 11 | mod.teeLocal(0, mod.i32.const(1)), 12 | mod.nop() 13 | ], binaryen.i32) 14 | ); 15 | mod.addExport("test", func); 16 | 17 | console.log(mod.emitText()); 18 | if (!mod.validate()) 19 | console.log("-> does not validate"); 20 | -------------------------------------------------------------------------------- /tests/compiler/external.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (import "foo" "var" (global $external/var_ i32)) 4 | (import "external" "foo" (func $external/foo)) 5 | (import "external" "foo.bar" (func $external/foo.bar)) 6 | (import "external" "bar" (func $external/two)) 7 | (import "foo" "baz" (func $external/three)) 8 | (memory $0 0) 9 | (table $0 1 funcref) 10 | (export "memory" (memory $0)) 11 | (export "foo" (func $external/foo)) 12 | (export "foo.bar" (func $external/foo.bar)) 13 | (export "two" (func $external/two)) 14 | (export "three" (func $external/three)) 15 | (export "var_" (global $external/var_)) 16 | ) 17 | -------------------------------------------------------------------------------- /tests/compiler/std/static-array.ts: -------------------------------------------------------------------------------- 1 | const i: i32[] = [1, 2]; 2 | const I: i64[] = [3, 4]; 3 | const f: f32[] = [1.5, 2.5]; 4 | const F: f64[] = [1.25, 2.25]; 5 | 6 | assert(i.length == 2); 7 | assert(i[0] == 1); 8 | assert(i[1] == 2); 9 | i[0] = 2; 10 | assert(i[0] == 2); 11 | 12 | assert(I.length == 2); 13 | assert(I[0] == 3); 14 | assert(I[1] == 4); 15 | I[0] = 4; 16 | assert(I[0] == 4); 17 | 18 | assert(f.length == 2); 19 | assert(f[0] == 1.5); 20 | assert(f[1] == 2.5); 21 | f[0] = 2.5; 22 | assert(f[0] == 2.5); 23 | 24 | assert(F.length == 2); 25 | assert(F[0] == 1.25); 26 | assert(F[1] == 2.25); 27 | F[0] = 2.25; 28 | assert(F[0] == 2.25); 29 | -------------------------------------------------------------------------------- /tests/compiler/void.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (type $none_=>_i32 (func (result i32))) 4 | (memory $0 0) 5 | (table $0 1 funcref) 6 | (global $void/u8Val1 (mut i32) (i32.const 1)) 7 | (global $void/u8Val2 (mut i32) (i32.const 255)) 8 | (export "memory" (memory $0)) 9 | (start $~start) 10 | (func $void/anInt (; 0 ;) (result i32) 11 | i32.const 2 12 | ) 13 | (func $start:void (; 1 ;) 14 | i32.const 1 15 | drop 16 | call $void/anInt 17 | drop 18 | global.get $void/u8Val1 19 | global.get $void/u8Val2 20 | i32.add 21 | drop 22 | ) 23 | (func $~start (; 2 ;) 24 | call $start:void 25 | ) 26 | ) 27 | -------------------------------------------------------------------------------- /cli/util/find.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | const path = require("path"); 3 | 4 | function findFiles(dirname, filter) { 5 | var out = []; 6 | fs.readdirSync(dirname).forEach(name => { 7 | if (fs.statSync(path.join(dirname, name)).isDirectory()) { 8 | findFiles(path.join(dirname, name), filter).forEach(iname => out.push(name + "/" + iname)); 9 | } else if (!filter || typeof filter === "function" ? filter(name) : filter.test(name)) { 10 | out.push(name); 11 | } 12 | }); 13 | return out; 14 | } 15 | 16 | exports.files = findFiles; 17 | 18 | exports.TS = /\.ts$/; 19 | exports.TS_EXCEPT_DTS = /(?:(?!\.d).{2}|^.{0,1})\.ts$/; 20 | -------------------------------------------------------------------------------- /snap/snapcraft.yaml: -------------------------------------------------------------------------------- 1 | name: assemblyscript 2 | version: git 3 | summary: A TypeScript to WebAssembly compiler. 4 | description: | 5 | AssemblyScript compiles strictly typed TypeScript to WebAssembly using Binaryen. More precisely, it subsets TypeScript's syntax and semantics so programs written using this subset can be compiled to WebAssembly ahead of time. 6 | 7 | See the AssemblyScript wiki for further documentation: 8 | https://github.com/AssemblyScript/assemblyscript/wiki 9 | icon: media/icon.svg 10 | grade: stable 11 | confinement: strict 12 | apps: 13 | asc: 14 | command: asc 15 | parts: 16 | assemblyscript: 17 | source: . 18 | plugin: nodejs 19 | -------------------------------------------------------------------------------- /tests/compiler/call-inferred.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (type $i32_=>_none (func (param i32))) 4 | (memory $0 1) 5 | (data (i32.const 16) " \00\00\00\01\00\00\00\01\00\00\00 \00\00\00c\00a\00l\00l\00-\00i\00n\00f\00e\00r\00r\00e\00d\00.\00t\00s") 6 | (global $~argumentsLength (mut i32) (i32.const 0)) 7 | (export "__setArgumentsLength" (func $~setArgumentsLength)) 8 | (export "memory" (memory $0)) 9 | (start $~start) 10 | (func $~setArgumentsLength (; 0 ;) (param $0 i32) 11 | local.get $0 12 | global.set $~argumentsLength 13 | ) 14 | (func $~start (; 1 ;) 15 | i32.const 0 16 | global.set $~argumentsLength 17 | ) 18 | ) 19 | -------------------------------------------------------------------------------- /tests/compiler/import.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-duplicate-imports */ 2 | 3 | import { 4 | add, 5 | sub as sub, 6 | renamed_mul as mul, 7 | a, 8 | b as b, 9 | renamed_c as c, 10 | ns as renamed_ns 11 | } from "./export"; 12 | 13 | add(a, b) + sub(b, c) + mul(c, a); 14 | 15 | renamed_ns.two(); 16 | 17 | import * as other from "./export"; 18 | 19 | other.add(other.a, other.b) + 20 | other.sub(other.b, other.renamed_c) + 21 | other.renamed_mul(other.renamed_c, other.a); 22 | 23 | other.ns.two(); 24 | 25 | import theDefault from "./export"; 26 | 27 | theDefault.two(); 28 | 29 | import theOtherDefault from "./export-default"; 30 | 31 | theOtherDefault(); 32 | -------------------------------------------------------------------------------- /tests/parser/trailing-commas.ts: -------------------------------------------------------------------------------- 1 | import { 2 | a, 3 | b, 4 | } from "c"; 5 | 6 | enum Foo { 7 | A, 8 | B, 9 | } 10 | 11 | function add( 12 | x: i32, 13 | y: i32, 14 | ): i32 { 15 | return x + y; 16 | } 17 | 18 | function parameterized< 19 | A, 20 | B, 21 | >(a: A, b: B): void { 22 | } 23 | 24 | export function compute(): i32 { 25 | const arr: Array = [ 26 | 1, 27 | 2, 28 | ]; 29 | parameterized< 30 | i8, 31 | // @ts-ignore: Waiting on https://github.com/Microsoft/TypeScript/issues/21984 32 | i32, 33 | >(0, 0); 34 | return add( 35 | 1, 36 | 2, 37 | ); 38 | } 39 | 40 | export { 41 | a, 42 | b, 43 | }; 44 | -------------------------------------------------------------------------------- /tests/binaryen/get_local-missing.js: -------------------------------------------------------------------------------- 1 | var binaryen = require("binaryen"); 2 | 3 | var mod = new binaryen.Module(); 4 | var funcType = mod.addFunctionType("v", binaryen.void, []); 5 | var func = mod.addFunction("test", funcType, [], 6 | mod.block("", [ 7 | mod.drop( 8 | mod.getLocal(0, binaryen.i32) 9 | ) 10 | ]) 11 | ); 12 | mod.addFunctionExport("test", "test", func); 13 | 14 | console.log(mod.emitText()); 15 | if (mod.validate()) { 16 | console.log("-> validates"); 17 | var binary = mod.emitBinary(); 18 | new WebAssembly.Module(binary); // CompileError: WebAssembly.Module(): Compiling wasm function #0:test failed: invalid local index: 0 @+34 19 | } 20 | -------------------------------------------------------------------------------- /tests/parser/parameter-order.ts.fixture.ts: -------------------------------------------------------------------------------- 1 | function restValid(a: i32, ...b: Array): void {} 2 | function optionalValid(a: i32, b?: i32): void {} 3 | function restParameterMustBeLast(...a: Array, b: i32): void {} 4 | function optionalCannotPrecedeRequired(a?: i32, b: i32): void {} 5 | function optionalWithInitializerCannotPrecedeRequired(a?: i32 = 1, b: i32): void {} 6 | // ERROR 1014: "A rest parameter must be last in a parameter list." in parameter-order.ts:5:36 7 | // ERROR 1016: "A required parameter cannot follow an optional parameter." in parameter-order.ts:8:48 8 | // ERROR 1016: "A required parameter cannot follow an optional parameter." in parameter-order.ts:11:66 9 | -------------------------------------------------------------------------------- /tests/binaryen/i64-binary-result.js: -------------------------------------------------------------------------------- 1 | var binaryen = require("binaryen"); 2 | 3 | // "non-final block elements returning a value must be drop()ed" 4 | // "0 == 0: block with value must not have last element that is none, on" 5 | 6 | var mod = new binaryen.Module(); 7 | 8 | var funcType = mod.addFunctionType("I", binaryen.void, [ binaryen.i64 ]); 9 | var func = mod.addFunction("test", funcType, [ binaryen.i32 ], 10 | mod.block("", [ 11 | mod.setLocal(1, mod.i64.eq(mod.i64.const(0, 0), mod.getLocal(0, binaryen.i64))) 12 | ]) 13 | ); 14 | mod.addExport("test", func); 15 | 16 | console.log(mod.emitText()); 17 | if (mod.validate()) 18 | console.log("-> ok: i64.eq returns i32"); 19 | -------------------------------------------------------------------------------- /tests/binaryen/block-pre.js: -------------------------------------------------------------------------------- 1 | var binaryen = require("binaryen"); 2 | var mod = binaryen.parseText(` 3 | (module 4 | (global $ref (mut i32) (i32.const 1)) 5 | (func $test 6 | (call $release 7 | (block (result i32) 8 | (global.get $ref) 9 | (global.set $ref 10 | (call $retain 11 | (i32.const 2) (; some-expression-that-might-conflict-with-a-temp ;) 12 | ) 13 | ) 14 | ) 15 | ) 16 | ) 17 | (func $retain (param i32) (result i32) 18 | (local.get 0) 19 | ) 20 | (func $release (param i32) 21 | (nop) 22 | ) 23 | ) 24 | `); 25 | if (!mod.validate()) console.log(":-("); 26 | else console.log(mod.emitText()); 27 | -------------------------------------------------------------------------------- /tests/binaryen/break-value.js: -------------------------------------------------------------------------------- 1 | var binaryen = require("binaryen"); 2 | 3 | var mod = new binaryen.Module(); 4 | var ftype = mod.addFunctionType("ii", binaryen.i32, [ binaryen.i32 ]); 5 | mod.addFunction("test", ftype, [], 6 | mod.block("label", [ 7 | mod.drop( // "br_if returns the value too" 8 | mod.break("label", 9 | // condition: $0 == 1 10 | mod.i32.eq( 11 | mod.getLocal(0, binaryen.i32), 12 | mod.i32.const(1) 13 | ), 14 | // value: 1 15 | mod.i32.const(1) 16 | ) 17 | ), 18 | // push: 0 19 | mod.i32.const(0) 20 | ], binaryen.i32) 21 | ); 22 | console.log(mod.emitText()); 23 | 24 | mod.validate(); 25 | -------------------------------------------------------------------------------- /examples/mandelbrot/README.md: -------------------------------------------------------------------------------- 1 | Mandelbrot Set 2 | ============== 3 | 4 | An [AssemblyScript](http://assemblyscript.org) example. Renders the Mandelbrot set to a canvas. Compiles to ~590 bytes of optimized WASM. 5 | 6 | Instructions 7 | ------------ 8 | 9 | First, install the development dependencies: 10 | 11 | ``` 12 | $> npm install 13 | ``` 14 | 15 | Now, to build [assembly/index.ts](./assembly/index.ts) to an untouched and an optimized `.wasm` including their respective `.wat` representations, run: 16 | 17 | ``` 18 | $> npm run asbuild 19 | ``` 20 | 21 | Afterwards, run `npm run server` to start a local server. Should also automatically launch a browser. 22 | -------------------------------------------------------------------------------- /tests/binaryen/asmjs.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i (func (param i32) (result i32))) 3 | (memory $0 0) 4 | (export "test/switch/case/eval" (func $test/switch/case/eval)) 5 | (export "const" (func $test/switch/case/eval)) 6 | (import "env" "switch" (func $switch (param i32 i32 i32 i32))) 7 | (global $INT i32 (i32.const 4)) 8 | (global $FLT i32 (f32.const -4.0)) 9 | (global $DBL i32 (f64.const -4.0)) 10 | (func $test/switch/case/eval (; 0 ;) (type $i) (param $0 i32) (result i32) 11 | (if (result i32) 12 | (i32.eq 13 | (get_global $INT) 14 | (i32.load 15 | (i32.const 0) 16 | ) 17 | ) 18 | (i32.ctz 19 | (i32.const 0) 20 | ) 21 | (get_local $0) 22 | ) 23 | ) 24 | ) -------------------------------------------------------------------------------- /tests/binaryen/constant-indirect.js: -------------------------------------------------------------------------------- 1 | var binaryen = require("binaryen"); 2 | 3 | var mod = new binaryen.Module(); 4 | 5 | var ftype = mod.addFunctionType("v", binaryen.none, []); 6 | 7 | mod.addFunction("callee", ftype, [], mod.block(null, [ 8 | ])); 9 | mod.setFunctionTable(1, 1, [ "callee" ]); 10 | 11 | mod.addFunction("caller", ftype, [], mod.block(null, [ 12 | mod.call_indirect(mod.i32.const(0), [], "v"), 13 | ])); 14 | mod.addFunctionExport("caller", "main"); 15 | 16 | binaryen.setOptimizeLevel(4); 17 | binaryen.setShrinkLevel(0); 18 | binaryen.setDebugInfo(false); 19 | mod.optimize(); 20 | if (!mod.validate()) 21 | console.log("-> does not validate"); 22 | console.log(mod.emitText()); 23 | -------------------------------------------------------------------------------- /tests/parser/literals.ts: -------------------------------------------------------------------------------- 1 | 0; 2 | 1; 3 | 2; 4 | 3; 5 | 4; 6 | 5; 7 | 6; 8 | 7; 9 | 8; 10 | 9; 11 | 2147483647; 12 | 0x0; 13 | 0x1; 14 | 0x2; 15 | 0x3; 16 | 0x4; 17 | 0x5; 18 | 0x6; 19 | 0x7; 20 | 0x8; 21 | 0x9; 22 | 0xA; 23 | 0xB; 24 | 0xC; 25 | 0xD; 26 | 0xE; 27 | 0xF; 28 | 0x7FFFFFFF; 29 | 0xa; 30 | 0xb; 31 | 0xc; 32 | 0xd; 33 | 0xe; 34 | 0xf; 35 | 0x7fffffff; 36 | 0o0; 37 | 0o1; 38 | 0o2; 39 | 0o3; 40 | 0o4; 41 | 0o5; 42 | 0o6; 43 | 0o7; 44 | 0o17777777777; 45 | 0b0; 46 | 0b1; 47 | 0b1111111111111111111111111111111; 48 | 0.0; 49 | 0.123; 50 | .0; 51 | .123; 52 | 12.34; 53 | 1e1; 54 | 1.0e1; 55 | 1e+1; 56 | 1.0e+1; 57 | 1e-1; 58 | 1.0e-1; 59 | "123"; 60 | "1\"23"; 61 | "1\"2\\3"; 62 | "\0\n\\n\r"; 63 | -------------------------------------------------------------------------------- /tests/compiler/continue.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $i32_=>_none (func (param i32))) 3 | (memory $0 0) 4 | (export "memory" (memory $0)) 5 | (export "testInherit" (func $continue/testInherit)) 6 | (func $continue/testInherit (; 0 ;) (param $0 i32) 7 | (local $1 i32) 8 | loop $for-loop|0 9 | local.get $1 10 | i32.const 10 11 | i32.lt_s 12 | if 13 | block $for-continue|0 14 | local.get $0 15 | i32.const 0 16 | local.get $1 17 | i32.const 5 18 | i32.eq 19 | select 20 | br_if $for-continue|0 21 | end 22 | local.get $1 23 | i32.const 1 24 | i32.add 25 | local.set $1 26 | br $for-loop|0 27 | end 28 | end 29 | ) 30 | ) 31 | -------------------------------------------------------------------------------- /tests/compiler/wasi-snapshot-preview1.untouched.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 0) 4 | (table $0 1 funcref) 5 | (global $~lib/shared/target/Target.WASM32 i32 (i32.const 0)) 6 | (global $~lib/shared/target/Target.WASM64 i32 (i32.const 1)) 7 | (global $~lib/shared/target/Target.JS i32 (i32.const 2)) 8 | (global $~lib/ASC_TARGET i32 (i32.const 0)) 9 | (global $wasi-snapshot-preview1/sig (mut i32) (i32.const 1)) 10 | (export "memory" (memory $0)) 11 | (start $~start) 12 | (func $start:wasi-snapshot-preview1 (; 0 ;) 13 | i32.const 9 14 | global.set $wasi-snapshot-preview1/sig 15 | ) 16 | (func $~start (; 1 ;) 17 | call $start:wasi-snapshot-preview1 18 | ) 19 | ) 20 | -------------------------------------------------------------------------------- /tests/compiler/class-static-function.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (type $i32_=>_none (func (param i32))) 4 | (memory $0 1) 5 | (data (i32.const 16) "0\00\00\00\01\00\00\00\01\00\00\000\00\00\00c\00l\00a\00s\00s\00-\00s\00t\00a\00t\00i\00c\00-\00f\00u\00n\00c\00t\00i\00o\00n\00.\00t\00s") 6 | (global $~argumentsLength (mut i32) (i32.const 0)) 7 | (export "__setArgumentsLength" (func $~setArgumentsLength)) 8 | (export "memory" (memory $0)) 9 | (start $~start) 10 | (func $~setArgumentsLength (; 0 ;) (param $0 i32) 11 | local.get $0 12 | global.set $~argumentsLength 13 | ) 14 | (func $~start (; 1 ;) 15 | i32.const 0 16 | global.set $~argumentsLength 17 | ) 18 | ) 19 | -------------------------------------------------------------------------------- /std/assembly/bindings/asyncify.ts: -------------------------------------------------------------------------------- 1 | @unmanaged 2 | export class StackDescriptor { 3 | /** The index in linear memory of the start of the “asyncify stack”. */ 4 | stackStart: usize; 5 | /** The index of the end of that stack region, which implies how big it is. */ 6 | stackEnd: usize; 7 | } 8 | 9 | /** Starts to unwind the call stack. */ 10 | export declare function start_unwind(data: StackDescriptor): void; 11 | /** Stops unwinding the call stack. */ 12 | export declare function stop_unwind(): void; 13 | /** Starts to rewind the call stack. */ 14 | export declare function start_rewind(data: StackDescriptor): void; 15 | /** Stops rewinding the call stack. */ 16 | export declare function stop_rewind(): void; 17 | -------------------------------------------------------------------------------- /tests/binaryen/unreachable-loop.js: -------------------------------------------------------------------------------- 1 | var binaryen = require("binaryen"); 2 | 3 | var mod = new binaryen.Module(); 4 | var funcType = mod.addFunctionType("v", binaryen.none, []); 5 | var func = mod.addFunction("0", funcType, [], 6 | mod.drop( 7 | mod.block("label$1", [ 8 | mod.loop("label$2", 9 | mod.unreachable() 10 | ) 11 | ], binaryen.i32) 12 | ) 13 | ); 14 | mod.addExport("0", "0"); 15 | 16 | console.log(mod.emitText()); 17 | if (!mod.validate()) 18 | console.log("-> does not validate"); 19 | 20 | var bin = mod.emitBinary(); 21 | require("fs").writeFileSync(__dirname + "/unreachable-loop.wasm", bin); 22 | var mod2 = binaryen.readBinary(bin); 23 | console.log(mod2.emitText()); 24 | -------------------------------------------------------------------------------- /tests/compiler/retain-release-sanity.ts: -------------------------------------------------------------------------------- 1 | { 2 | let arr: i32[] = new Array(3); 3 | arr.push(123); 4 | arr.push(123); 5 | arr.pop(); 6 | } 7 | { 8 | let outer = new Array>(); 9 | for (let i = 0; i < 10; ++i) { 10 | let arr = new Array(); 11 | for (let j = 0; j < 10; ++j) { 12 | arr.push(""); 13 | // outer.push(arr); 14 | } 15 | } 16 | } 17 | { 18 | let a = "a"; 19 | let c = a + "b"; 20 | c + "d"; 21 | } 22 | 23 | class A { 24 | b: B; 25 | } 26 | class B { 27 | a: A; 28 | } 29 | 30 | { 31 | let a = new A(); 32 | let b = new B(); 33 | a.b = b; 34 | a.b = b; 35 | b.a = a; 36 | b.a = a; 37 | a.b = b; 38 | b.a = a; 39 | } 40 | 41 | __collect(); 42 | -------------------------------------------------------------------------------- /tests/compiler/scoped.ts: -------------------------------------------------------------------------------- 1 | var aGlobal: i32 = 1; 2 | const aConstant: i32 = 3; 3 | 4 | let aStartFunctionLocal: i32 = 2; 5 | for (var anotherStartFunctionLocal: i32 = 0; anotherStartFunctionLocal < 1; ++anotherStartFunctionLocal); 6 | for (let aGlobal /* that shadows */: i32 = 0; aGlobal < 1; ++aGlobal) 7 | aGlobal; 8 | 9 | { 10 | let /* actually not */ aConstant: i64 = 5; 11 | { 12 | let /* still not */ aConstant: f32 = 10; 13 | } 14 | } 15 | 16 | // regression test: reused local should be updated with new requested type 17 | function fn(c: i32): void { 18 | { 19 | let a: bool = 0; 20 | } 21 | { 22 | let b: i32; 23 | b = c; // should not issue a conversion warning mentioning 'bool' 24 | } 25 | } 26 | fn(42); 27 | -------------------------------------------------------------------------------- /examples/mandelbrot/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@assemblyscript/mandelbrot-example", 3 | "version": "1.0.0", 4 | "private": true, 5 | "scripts": { 6 | "asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --use Math=JSMath --runtime none --importMemory --sourceMap --debug --validate --measure", 7 | "asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -d build/optimized.d.ts --use Math=JSMath --runtime none -O3 --importMemory --sourceMap --validate --measure", 8 | "asbuild": "npm run asbuild:untouched && npm run asbuild:optimized", 9 | "server": "http-server . -o -c-1" 10 | }, 11 | "devDependencies": { 12 | "http-server": "^0.11.1" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/compiler/abi.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (type $none_=>_i32 (func (result i32))) 4 | (memory $0 1) 5 | (data (i32.const 16) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00a\00b\00i\00.\00t\00s") 6 | (global $abi/condition (mut i32) (i32.const 0)) 7 | (global $abi/y (mut i32) (i32.const 0)) 8 | (export "memory" (memory $0)) 9 | (export "exported" (func $abi/exported)) 10 | (export "exportedExported" (func $abi/exported)) 11 | (export "exportedInternal" (func $abi/exported)) 12 | (start $~start) 13 | (func $abi/exported (; 0 ;) (result i32) 14 | i32.const -128 15 | ) 16 | (func $~start (; 1 ;) 17 | i32.const 1 18 | global.set $abi/condition 19 | i32.const 0 20 | global.set $abi/y 21 | ) 22 | ) 23 | -------------------------------------------------------------------------------- /tests/compiler/scoped.optimized.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $none_=>_none (func)) 3 | (memory $0 0) 4 | (export "memory" (memory $0)) 5 | (start $~start) 6 | (func $start:scoped (; 0 ;) 7 | (local $0 i32) 8 | loop $for-loop|0 9 | local.get $0 10 | i32.const 1 11 | i32.lt_s 12 | if 13 | local.get $0 14 | i32.const 1 15 | i32.add 16 | local.set $0 17 | br $for-loop|0 18 | end 19 | end 20 | i32.const 0 21 | local.set $0 22 | loop $for-loop|1 23 | local.get $0 24 | i32.const 1 25 | i32.lt_s 26 | if 27 | local.get $0 28 | i32.const 1 29 | i32.add 30 | local.set $0 31 | br $for-loop|1 32 | end 33 | end 34 | ) 35 | (func $~start (; 1 ;) 36 | call $start:scoped 37 | ) 38 | ) 39 | -------------------------------------------------------------------------------- /tests/parser/also-identifier.ts: -------------------------------------------------------------------------------- 1 | class Foo { 2 | as: i32; 3 | declare: i32; 4 | delete: i32; 5 | from: i32; 6 | for: i32; 7 | get: i32; 8 | instanceof: i32; 9 | is: i32; 10 | keyof: i32; 11 | module: i32; 12 | namespace: i32; 13 | null: i32; 14 | readonly: i32; 15 | set: i32; 16 | type: i32; 17 | void: i32; 18 | } 19 | 20 | var as: i32; 21 | var constructor: i32; 22 | var declare: i32; 23 | var from: i32; 24 | var get: i32; 25 | var is: i32; 26 | var keyof: i32; 27 | var module: i32; 28 | var namespace: i32; 29 | var readonly: i32; 30 | var set: i32; 31 | 32 | // -- illegal -- 33 | // var delete: i32; 34 | // var for: i32; 35 | // var instanceof: i32; 36 | // var null: i32; 37 | // var type: i32; 38 | // var void: i32; 39 | -------------------------------------------------------------------------------- /examples/game-of-life/README.md: -------------------------------------------------------------------------------- 1 | Conway's Game of Life 2 | ===================== 3 | 4 | An [AssemblyScript](http://assemblyscript.org) example. Continuously updates the cellular automaton and visualizes its state on a canvas. Compiles to ~940 bytes of optimized WASM. 5 | 6 | Instructions 7 | ------------ 8 | 9 | First, install the development dependencies: 10 | 11 | ``` 12 | $> npm install 13 | ``` 14 | 15 | Now, to build [assembly/index.ts](./assembly/index.ts) to an untouched and an optimized `.wasm` including their respective `.wat` representations, run: 16 | 17 | ``` 18 | $> npm run asbuild 19 | ``` 20 | 21 | Afterwards, run `npm run server` to start a local server. Should also automatically launch a browser. 22 | -------------------------------------------------------------------------------- /examples/game-of-life/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@assemblyscript/game-of-life-example", 3 | "version": "1.0.0", 4 | "private": true, 5 | "scripts": { 6 | "asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --use Math=JSMath --runtime none --importMemory --sourceMap --debug --validate --measure", 7 | "asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -d build/optimized.d.ts --use Math=JSMath -O3 --runtime none --importMemory --sourceMap --validate --measure", 8 | "asbuild": "npm run asbuild:untouched && npm run asbuild:optimized", 9 | "server": "http-server . -o -c-1" 10 | }, 11 | "devDependencies": { 12 | "http-server": "^0.11.1" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /scripts/build-sdk.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | const fs = require("fs"); 3 | const pkg = require("../package-lock.json"); 4 | 5 | fs.readFile(path.join(__dirname, "..", "lib", "sdk", "index.js"), "utf8", function(err, data) { 6 | if (err) throw err; 7 | data = data 8 | .replace(/BINARYEN_VERSION = "nightly"/, "BINARYEN_VERSION = " + JSON.stringify(pkg.dependencies.binaryen.version)) 9 | .replace(/LONG_VERSION = "latest"/, "LONG_VERSION = " + JSON.stringify(pkg.dependencies.long.version)) 10 | .replace(/ASSEMBLYSCRIPT_VERSION = "nightly"/, "ASSEMBLYSCRIPT_VERSION = " + JSON.stringify(pkg.version)); 11 | fs.writeFile(path.join(__dirname, "..", "dist", "sdk.js"), data, function(err) { 12 | if (err) throw err; 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /scripts/postpublish.js: -------------------------------------------------------------------------------- 1 | // Reconfigures the repository after publishing 2 | 3 | const fs = require("fs"); 4 | const path = require("path"); 5 | const devFiles = require("./postpublish-files.json"); 6 | 7 | console.log("Restoring development files ..."); 8 | 9 | devFiles.forEach(originalName => { 10 | const backupName = originalName + ".backup"; 11 | const backupPath = path.join(__dirname, "..", backupName); 12 | if (!fs.existsSync(backupPath)) { 13 | console.log("- " + backupName + " does not exist"); 14 | } else { 15 | console.log("- " + backupName + " -> " + originalName); 16 | fs.copyFileSync( 17 | backupPath, 18 | path.join(__dirname, "..", originalName) 19 | ); 20 | fs.unlinkSync(backupPath); 21 | } 22 | }); 23 | --------------------------------------------------------------------------------