Skip to content

Commit

Permalink
starting work on assemblyscript example
Browse files Browse the repository at this point in the history
  • Loading branch information
konsumer committed Sep 15, 2024
1 parent aabe3a6 commit 2aec6c5
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 3 deletions.
4 changes: 4 additions & 0 deletions cart/as/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
node_modules
build
*.log
5 changes: 5 additions & 0 deletions cart/as/README.md
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 16 additions & 0 deletions cart/as/asconfig.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
19 changes: 19 additions & 0 deletions cart/as/null0.ts
Original file line number Diff line number Diff line change
@@ -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;
}
57 changes: 57 additions & 0 deletions cart/as/package-lock.json

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

20 changes: 20 additions & 0 deletions cart/as/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Binary file added cart/as/src/assets/notnullgames.ogg
Binary file not shown.
9 changes: 9 additions & 0 deletions cart/as/src/index.ts
Original file line number Diff line number Diff line change
@@ -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");
}
6 changes: 6 additions & 0 deletions cart/as/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "assemblyscript/std/assembly.json",
"include": [
"./**/*.ts"
]
}
5 changes: 2 additions & 3 deletions null0_api/src/null0_api_wamr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 2aec6c5

Please sign in to comment.