wasd 0.0.1
wasd: ^0.0.1 copied to clipboard
WASD: Wasm And Dart System / WebAssembly System for Dart.
WASD #
WASD (Wasm And Dart System / WebAssembly System for Dart) is a pure Dart WebAssembly runtime inspired by zwasm's layered design, implemented as a cross-target interpreter that works on Dart native, JS, and Wasm compile targets.
Current coverage #
- Binary module decoding
- sections:
type,import,function,table,memory,global,export,start,element,code,data,data_count - custom sections are skipped safely during decode
- sections:
- Runtime features
- function/table/memory/global imports
- global initialization with const-expression evaluation
- active element initialization
- active data initialization
- start function execution
- pre-instantiation static validation phase (
WasmValidator)
- Control flow
block,loop,if,else,br,br_if,br_table,return
- Calls
call,call_indirect+ signature checking- tail-call opcodes:
return_call,return_call_indirect
- Variable and memory access
local.get/set/tee,global.get/set- full MVP load/store family (
i32/i64/f32/f64+ 8/16/32 signed/unsigned variants) memory.size,memory.grow- table instructions:
table.get/set
- Numeric execution
i32full core arithmetic/bit/compare opsi64core arithmetic/bit/compare opsf32/f64core arithmetic and compare ops- conversions/reinterpret/sign-extension/trunc-sat families
- Bulk memory/table
memory.init,data.drop,memory.copy,memory.filltable.init,elem.drop,table.copy,table.grow,table.size,table.fill
- Multi-value
- multi-result functions (including import/export call paths)
- WASI Preview1 (phase-2 baseline)
fd_write,fd_read,fd_pread,fd_pwritefd_seek,fd_tell,fd_advise,fd_allocatefd_datasync,fd_syncfd_filestat_get,fd_filestat_set_size,fd_filestat_set_timesfd_fdstat_get,fd_fdstat_set_flags,fd_fdstat_set_rightsfd_prestat_get,fd_prestat_dir_name,fd_readdirfd_renumberfd_close,path_open,path_rename,path_unlink_filepath_create_directory,path_remove_directorypath_filestat_get,path_filestat_set_timespath_link,path_symlink,path_readlinkargs_sizes_get,args_getenviron_sizes_get,environ_getclock_time_get,clock_res_get,random_getpoll_oneoff,sched_yield,proc_exitproc_raise(stub:ENOSYS)sock_accept,sock_recv,sock_send,sock_shutdown(stubs:ENOSYS)- filesystem backend auto-selection via conditional import:
- supports
dart:io: use host-backed filesystem - no
dart:io: fallback toWasiInMemoryFileSystem
- supports
- can force in-memory backend:
WasiPreview1(preferHostIo: false) - host-io path sandbox checks (canonical root boundary enforcement)
- proposal feature gates:
WasmFeatureSet(simd/threads/exceptionHandling/gc/componentModel) - helper runner:
WasiRunner(instantiate + bind memory + invoke_start) - runtime adapter: lib/src/wasi_preview1.dart
- filesystem abstractions: lib/src/wasi_filesystem.dart
- conditional backend selector: lib/src/wasi_fs_auto.dart
Not implemented yet #
- SIMD execution semantics
- threads/atomics/shared memory semantics
- exception handling semantics
- GC/reference-subtyping semantics
- component model semantics
- remaining WASI Preview1 semantics (
fd_prestat_set_flags,fd_filestat_set_timesfull flag semantics,path_opensymlink-follow semantics, fullsock_*behavior, etc.)
Examples #
- Basic invocation: example/invoke.dart
- Load various wasm modules: example/load_various_wasm.dart
- Load
.wasmfrom file: example/load_from_file.dart - Batch-load all
.wasmfiles under a directory: example/load_wasm_suite.dart - Minimal WASI hello example: example/wasi_hello.dart
- WASI file-write example (via in-memory FS): example/wasi_write_file.dart
- WASI seek/stat example: example/wasi_seek_stat.dart
- WASI runner example (
_start+ proc_exit): example/wasi_runner.dart - Doom wasm headless runner: example/run_doom_wasm.dart
- Doom wasm terminal playable runner: example/play_doom_terminal.dart
- Doom asset bootstrap script: example/doom/setup_assets.sh
Run:
dart run example/invoke.dart
dart run example/load_various_wasm.dart
dart run example/load_from_file.dart ./path/to/module.wasm exported_fn 1 2
dart run example/load_wasm_suite.dart ./path/to/wasm_dir
dart run example/wasi_hello.dart
dart run example/wasi_write_file.dart
dart run example/wasi_seek_stat.dart
dart run example/wasi_runner.dart
example/doom/setup_assets.sh
dart run example/run_doom_wasm.dart
dart run example/play_doom_terminal.dart
Doom quick run (headless, 120 frames, dump first frame as PPM):
example/doom/setup_assets.sh
dart run example/run_doom_wasm.dart example/doom/doom.wasm example/doom/doom1.wad 120 example/doom/frame_0001.ppm
Doom terminal playable mode (interactive):
example/doom/setup_assets.sh
dart run example/play_doom_terminal.dart
If your terminal shows a black screen, use monochrome fallback:
dart run example/play_doom_terminal.dart --mono
Doom desktop window mode (Flutter):
cd doom_window
tool/sync_assets.sh
flutter pub get
flutter run -d macos
On Linux/Windows, replace -d macos with your desktop target.
doom_window now loads doom.wasm + doom1.wad from Flutter assets
(doom_window/assets/doom/*) instead of external filesystem paths.
Controls in window mode: arrows/WASD move, Ctrl (and Space) fire, Alt
strafe, Shift run, Enter use, Esc menu.
zwasm WAT samples #
Copied from zwasm/examples/wat into:
These are source .wat samples for reference and conversion workflows.
Why WASD #
No FFI, no native code, and no runtime-specific APIs. This keeps the runtime portable across all Dart compile targets.