wasd 0.0.1 copy "wasd: ^0.0.1" to clipboard
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
  • 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
    • i32 full core arithmetic/bit/compare ops
    • i64 core arithmetic/bit/compare ops
    • f32/f64 core arithmetic and compare ops
    • conversions/reinterpret/sign-extension/trunc-sat families
  • Bulk memory/table
    • memory.init, data.drop, memory.copy, memory.fill
    • table.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_pwrite
    • fd_seek, fd_tell, fd_advise, fd_allocate
    • fd_datasync, fd_sync
    • fd_filestat_get, fd_filestat_set_size, fd_filestat_set_times
    • fd_fdstat_get, fd_fdstat_set_flags, fd_fdstat_set_rights
    • fd_prestat_get, fd_prestat_dir_name, fd_readdir
    • fd_renumber
    • fd_close, path_open, path_rename, path_unlink_file
    • path_create_directory, path_remove_directory
    • path_filestat_get, path_filestat_set_times
    • path_link, path_symlink, path_readlink
    • args_sizes_get, args_get
    • environ_sizes_get, environ_get
    • clock_time_get, clock_res_get, random_get
    • poll_oneoff, sched_yield, proc_exit
    • proc_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 to WasiInMemoryFileSystem
    • 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_times full flag semantics, path_open symlink-follow semantics, full sock_* behavior, etc.)

Examples #

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.

3
likes
140
points
109
downloads

Publisher

verified publishermedz.dev

Weekly Downloads

WASD: Wasm And Dart System / WebAssembly System for Dart.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on wasd