t3hn3rd b937e60838 feature: implement all float, conversion, table & bulk memory opcodes with IEEE 754 hardening
Complete implementation of remaining WASM MVP and post-MVP opcodes:

Float arithmetic (f32/f64):
- abs, neg (purely bitwise), ceil, floor, trunc, nearest, sqrt
- add, sub, mul, div with indeterminate form handling
  (Inf+(-Inf), Inf-Inf, Inf*0, 0/0, Inf/Inf -> NaN; x/0 -> ±Inf)
- min, max with signed-zero fix (OR for min, AND for max)
- copysign (bitwise sign transfer)

Float comparisons (f64 eq/ne/lt/gt/le/ge):
- Added bitwise NaN detection before comparisons to prevent EInvalidOp on x64 FPC

Conversion opcodes:
- i32.wrap_i64, i64.extend_i32_s/u
- i32/i64.trunc_f32/f64_s/u with NaN + overflow traps
- f32/f64.convert_i32/i64_s/u
- f32.demote_f64, f64.promote_f32
- i32/i64.reinterpret_f32/f64, f32/f64.reinterpret_i32/i64
- i32.extend8_s, i32.extend16_s, i64.extend8_s/16_s/32_s

0xFC prefix dispatch + saturating truncation (FC 00-07):
- i32/i64.trunc_sat_f32/f64_s/u with NaN->0, clamp to min/max

Bulk memory (FC 08-0B):
- memory.init, data.drop, memory.copy (overlap-safe), memory.fill

Table operations (FC 0C-11 + opcodes 0x25/0x26):
- table.get, table.set, table.init, elem.drop
- table.copy (overlap-safe), table.grow, table.size, table.fill

Control flow & infrastructure:
- select t* (typed select, 0x1C) with LEB128 type vector
- block/loop/if blocktype now parsed as LEB128 s33 (multi-byte support)
- Control flow scanner updated for all new opcodes (0xFC sub-opcodes,
  table.get/set, typed select)
- VM init: jump tables heap-allocated via kalloc, FC table initialized

All float ops use bitwise NaN detection to avoid FPC x64 EInvalidOp.
2026-02-24 21:45:10 +00:00

WASURO

A WebAssembly virtual machine for the Asuro operating system, written in Standard Pascal.

WASURO parses and executes WASM binaries directly in a bare-metal kernel environment — no runtime library, no classes, no heap manager beyond what the OS provides.

Architecture

src/
├── emu/               # OS emulation layer (types, console, memory, LEB128)
├── wasm/              # WASM Virtual Machine
│   ├── parser/        # WASM binary parser
│   │   └── sections/  # Section-specific parsers (type, function, export,
│   │                  #   code, global, memory, start, data, etc.)
│   ├── types/         # WASM type system, stack, and linear memory (heap)
│   ├── vm/            # VM tick loop and opcode jump table
│   └── test/          # Test suite
│       ├── infra/     # Stack, heap, LEB128 tests
│       ├── opcodes/   # Per-opcode test units
│       └── parsers/   # Per-section parser tests
└── project/           # Lazarus project files

Key components

  • VM (wasm.vm) — Tick-based execution loop dispatching opcodes through a 256-entry jump table.
  • Parser (wasm.parser) — Validates the WASM magic/version header, then routes each binary section to its handler.
  • Stack (wasm.types.stack) — Operand and control stacks supporting i32, i64, f32, f64 push/pop.
  • Heap (wasm.types.heap) — Paged linear memory with read/write at 8/16/32/64-bit widths.
  • Emulation layer (src/emu/) — Provides the same types, console, lmemorymanager, and leb128 interfaces that exist in the real Asuro kernel, allowing development and testing on a host OS.

Implemented opcodes

Category Opcodes
Control nop, unreachable, drop, select, return
Variables local.get/set/tee, global.get/set
Constants i32.const, i64.const, f32.const, f64.const
i32 Arithmetic add, sub, mul, div_s/u, rem_s/u, clz, ctz, popcnt
i32 Bitwise and, or, xor, shl, shr_s/u, rotl, rotr
i32 Comparison eqz, eq, ne, lt_s/u, gt_s/u, le_s/u, ge_s/u
i64 Arithmetic add, sub, mul, div_s/u, rem_s/u, clz, ctz, popcnt
i64 Bitwise and, or, xor, shl, shr_s/u, rotl, rotr
i64 Comparison eqz, eq, ne, lt_s/u, gt_s/u, le_s/u, ge_s/u
f32/f64 Comparison eq, ne, lt, gt, le, ge
Memory Loads i32/i64/f32/f64.load, sign/zero-extending variants (8/16/32-bit)
Memory Stores i32/i64/f32/f64.store, narrowing variants (8/16/32-bit)
Memory Mgmt memory.size, memory.grow

Parsed sections

Type, Function, Export, Code, Global, Memory, Start, Data, Import (stub), Table (stub), Element (stub), Custom (stub).

Constraints

  • Standard Pascal only — no runtime library, no classes.
  • Kernel-compatible — all arithmetic (including shr_s) uses manual implementations, no RTL intrinsics.
  • Emulation layer — src/emu/ mirrors the real Asuro kernel API; only these interfaces are available.

Requirements

Building

# Normal build
build.bat

# Build with test suite
build.bat test

Output: bin\WASURO.exe

Testing

build.bat test
bin\WASURO.exe

Runs 374 tests across 108 test units. Exit code equals the number of failed tests (0 on success), making it CI/CD-friendly.

License

See repository for license details.

S
Description
No description provided
Readme
751 KiB
0 Stars 4 Watchers 0 Forks
Languages
Pascal 98%
PowerShell 1.1%
WebAssembly 0.9%