warning! This specification is unfinished. while you MAY implement it as written, the update comes in the form of a version bump.
ANT.wasm is a Brand New way to run wasm safely and securely (or that us the goal).
to use ANT.wasm you can use This Specification to insure interoperability. If you do not Like where this is going please fork.
this document written on is Semantic version 0.0.1. this document is self-published independently.
i am still Figuring things out. this is not final design and might be vague, impossible, or otherwise not implementable. im still seeking to bring this closer to my vision.
As a refresher here are some concepts you need to know.
f32: a float 32.
f64: a float 64.
i32: an int 32.
i64: an int 64.
Your Wasm package is called a game. Your Game has the following phases. in order of appearance
| Name | Description |
|---|---|
| Loading Phase | Here is where the Edge loads and verifies the ANT.zip. if it is marked as Untrusted the Edge MUST abort proceeding. |
| Initialization Phase | Here is where you Initialize your game before it runs. |
| game Phase | Here is where you let the player play. this is activated by calling
start_game.
|
It is assumed Imports and Exports are called to the invoking Wasm Module unless otherwise stated.
[[Variablename]] is an internal variable type. wasm doesnt support strings so
[[String]] is for the specification only is what i mean.
[[%FunctionName%]] is an internal function name. they MUST NOT be exposed to
any Wasm Module.
$Variablename is an internal variable name used only in the internal function.
they are unobservable outside it. even if they share the same name
If any of the following Invariants are violated, that is a spec bug.
[[%StringFromBytes%]] (ptr:
i32, len: i32): [[String]]Do the following in order
GENERIC_FAILURE (-1).
[[%BytesFromString%]] (string: [[String]]): i32Do the following in order
host_malloc is not exported return WASM_PORT_MISSING (-7).
host_malloc with
$length.
[[%LoadModule%]] (path: [[String]],
Imports: [[ImportLibrary]])>: i32Do the following in order
GAME_IS_RUNNING_ERROR (-5).
RESOLUTION_ERROR (-3).
RESOLUTION_ERROR (-3).
load_module if
present with ($wasmModulesLoaded as ModuleId).
All Wasm Modules MUST expose or be exposed to the following functions
| Name | Types | Import/Export | Description |
|---|---|---|---|
host_malloc
| (bytes: i32): i32
| Export | host_malloc MUST return a positive number indicating a pointer ($pointer)
on that Wasm's Linear Memory, $pointer until ($pointer + bytes)
MUST be free for the Edge to store whatever is the Edge needs. If that fails or there isnt memory to
allocate to the Edge, Return the appropriate Error Code.
|
on_module_load
| (ModuleId: i32): void
| Export | called when the Wasm Module is loaded via
load_module.
|
A Main is a wasm file that is called after a Core. it is the main function.
If we are talking about User Generated Content games, A Core is the actual Game where A Main is the core for a sharable package a user has created.
A Main MUST expose or be exposed to the following functions
| Name | Types | Import/Export | Description |
|---|---|---|---|
load_module
| (ptr: i32, len: i32): i32
| Import | Do the following in order
|
start_game
| (): void
| Import | Do the following in order
|
A Core is a wasm file that is first called. it is the engine so games can stay self-contained
within their ANT.zip. the core MUST live at
"/core.wasm" (case-sensitive) ziproot path.
If we are talking about User Generated Content games, A Core is the actual Game where A Main is the core for a sharable package a user has created.
A Core MUST expose or be exposed to the following functions
| Name | Types | Import/Export | Description |
|---|---|---|---|
load_module_core
| (ptr: i32, len: i32): i32
| Import | Do the following in order
|
load_main
| (): void
| Import | Do the following in order
|
the following table will list the error codes as negative numbers, their canonical upper snakecase name, and their description.
| Code | UPPER_CASE_NAME | Description |
|---|---|---|
-1 (Negative One) | GENERIC_FAILURE | A Generic Failure. |
-2 (Negative Two) | PATH_RESOLUTION_ERROR | A path cant be resolved due to any reason, including bt not limited to
|
-3 (Negative Three) | RESOLUTION_ERROR | A Path requiring a Wasm Module, but doesnt point to a valid compilable Wasm Module. |
-4 (Negative Four) | GAME_HASNT_STARTED_YET_ERROR | the start_game function hasnt been called by the Core when the function requires the game to be started. |
-5 (Negative Five) | GAME_IS_RUNNING_ERROR | the start_game function has been called by the Corewhen the function requires the game to be in the initialization phase (beforestart_game). |
-6 (Negative Six) | NO_MORE_MEMORY_ERROR | The Operation requires more memory but it cant be granted |
-7 (Negative Seven) | WASM_PORT_MISSING | An Import or Export is missing |