diff --git a/cart/as/.gitignore b/cart/as/.gitignore new file mode 100644 index 0000000..1a25504 --- /dev/null +++ b/cart/as/.gitignore @@ -0,0 +1,4 @@ +.DS_Store +node_modules +build +*.log diff --git a/cart/as/README.md b/cart/as/README.md new file mode 100644 index 0000000..4040be8 --- /dev/null +++ b/cart/as/README.md @@ -0,0 +1,5 @@ +This is an example null0 cart written in [assemblyscript](https://www.assemblyscript.org/). + +## TODO + +- look into [better build](https://github.com/notnullgames/null0-ideas/blob/main/projects/assemblyscript/tools/build.mjs) diff --git a/cart/as/asconfig.json b/cart/as/asconfig.json new file mode 100644 index 0000000..b72c80b --- /dev/null +++ b/cart/as/asconfig.json @@ -0,0 +1,16 @@ +{ + "targets": { + "release": { + "outFile": "build/main.wasm", + "textFile": "build/main.wat", + "sourceMap": true, + "optimizeLevel": 3, + "shrinkLevel": 0, + "converge": false, + "noAssert": false + } + }, + "options": { + "bindings": "esm" + } +} diff --git a/cart/as/null0.ts b/cart/as/null0.ts new file mode 100644 index 0000000..2c5e7ec --- /dev/null +++ b/cart/as/null0.ts @@ -0,0 +1,19 @@ +// log a string +@external("null0", "trace") +declare function _null0_real_trace(text: ArrayBuffer): void + +// these are called by language +// https://www.assemblyscript.org/concepts.html#special-imports +// TODO: would WASI help with these? + +export function _null0_trace(message: String): void { + _null0_real_trace(String.UTF8.encode(message, true)); +} + +export function _null0_abort(message: String, fileName: String, line: u32, column: u32): void { + _null0_real_trace(String.UTF8.encode("ABORT: " + message, true)); +} + +export function _null0_seed(): f64 { + return 1.0; +} diff --git a/cart/as/package-lock.json b/cart/as/package-lock.json new file mode 100644 index 0000000..eddbf24 --- /dev/null +++ b/cart/as/package-lock.json @@ -0,0 +1,57 @@ +{ + "name": "@null0/example-as", + "version": "0.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@null0/example-as", + "version": "0.0.0", + "license": "MIT", + "devDependencies": { + "assemblyscript": "^0.27.29" + } + }, + "node_modules/assemblyscript": { + "version": "0.27.29", + "resolved": "https://registry.npmjs.org/assemblyscript/-/assemblyscript-0.27.29.tgz", + "integrity": "sha512-pH6udb7aE2F0t6cTh+0uCepmucykhMnAmm7k0kkAU3SY7LvpIngEBZWM6p5VCguu4EpmKGwEuZpZbEXzJ/frHQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "binaryen": "116.0.0-nightly.20240114", + "long": "^5.2.1" + }, + "bin": { + "asc": "bin/asc.js", + "asinit": "bin/asinit.js" + }, + "engines": { + "node": ">=16", + "npm": ">=7" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/assemblyscript" + } + }, + "node_modules/binaryen": { + "version": "116.0.0-nightly.20240114", + "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-116.0.0-nightly.20240114.tgz", + "integrity": "sha512-0GZrojJnuhoe+hiwji7QFaL3tBlJoA+KFUN7ouYSDGZLSo9CKM8swQX8n/UcbR0d1VuZKU+nhogNzv423JEu5A==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "wasm-opt": "bin/wasm-opt", + "wasm2js": "bin/wasm2js" + } + }, + "node_modules/long": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz", + "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==", + "dev": true, + "license": "Apache-2.0" + } + } +} diff --git a/cart/as/package.json b/cart/as/package.json new file mode 100644 index 0000000..94e4a87 --- /dev/null +++ b/cart/as/package.json @@ -0,0 +1,20 @@ +{ + "name": "@null0/example-as", + "version": "0.0.0", + "scripts": { + "build": "asc src/index.ts --target release --use trace=_null0_trace --use abort=_null0_abort --use seed=_null0_seed --lib ./null0.ts && mkdir -p build/cart/assets && cp build/main.wasm build/cart && cp src/assets/* build/cart/assets && cd build/cart && zip -r ../example.null0 .", + "start": "../../build/host/null0 ./build/example.null0", + "prestart": "npm run build" + }, + "license": "MIT", + "devDependencies": { + "assemblyscript": "^0.27.29" + }, + "type": "module", + "exports": { + ".": { + "import": "./build/release.js", + "types": "./build/release.d.ts" + } + } +} diff --git a/cart/as/src/assets/notnullgames.ogg b/cart/as/src/assets/notnullgames.ogg new file mode 100755 index 0000000..3217a6c Binary files /dev/null and b/cart/as/src/assets/notnullgames.ogg differ diff --git a/cart/as/src/index.ts b/cart/as/src/index.ts new file mode 100644 index 0000000..f0f971b --- /dev/null +++ b/cart/as/src/index.ts @@ -0,0 +1,9 @@ +// called when the cart is loaded +export function load(): void { + trace("hello"); +} + +// called on every frame +export function update(): void { + trace("update"); +} diff --git a/cart/as/src/tsconfig.json b/cart/as/src/tsconfig.json new file mode 100644 index 0000000..e28fcf2 --- /dev/null +++ b/cart/as/src/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "assemblyscript/std/assembly.json", + "include": [ + "./**/*.ts" + ] +} \ No newline at end of file diff --git a/null0_api/src/null0_api_wamr.h b/null0_api/src/null0_api_wamr.h index f559ce4..2e2d4a3 100755 --- a/null0_api/src/null0_api_wamr.h +++ b/null0_api/src/null0_api_wamr.h @@ -785,7 +785,6 @@ RuntimeInitArgs null0_init_args() { init_args.n_native_symbols = sizeof(null0_wamr_callbacks) / sizeof(NativeSymbol); init_args.native_module_name = "null0"; init_args.native_symbols = null0_wamr_callbacks; - return init_args; } @@ -815,14 +814,14 @@ bool null0_init() { error_buf[0] = 0; wasm_module_t module = wasm_runtime_load(wasmBytes, wasmSize, error_buf, sizeof(error_buf)); if (error_buf[0] != 0) { - printf("load - %s\n", error_buf); + fprintf(stderr, "ERROR: load - %s\n", error_buf); return false; } error_buf[0] = 0; module_inst = wasm_runtime_instantiate(module, stack_size, heap_size, error_buf, sizeof(error_buf)); if (error_buf[0] != 0) { - printf("instantiate - %s\n", error_buf); + fprintf(stderr, "ERROR: instantiate - %s\n", error_buf); return false; }