Bytecode & Managed VMs

Architectura applies the same ArchManifest + SemProgram + IrEmitter model to stack-based and register-based virtual machines. Rather than treating bytecode as an unstructured native byte stream, each frontend validates and normalizes the container's function/method/prototype structure first, then lifts through checked Asem programs into archsem-ir.

[!NOTE] The four production bytecode crates—archsem-wasm, archsem-evm, archsem-cil, and archsem-lua—enable their default frontend features out of the box. archsem-python is an experimental handler-level frontend gated behind features = ["python"].

WebAssembly (archsem-wasm)

  • Parser & Validator: Backed by fWASM (re-exporting wasmparser types). WasmModule::parse / parse_with_features validates the Wasm binary up front.
  • Modes & Memory: WASM32 (32-bit linear memory) and WASM64 (Memory64, 64-bit linear memory). AddrSpace::Data models little-endian linear memory.
  • Stack Normalization (WasmFunction): Precomputes the deterministic WebAssembly operand-stack heights at every instruction and maps stack slots (STACK_REGISTER_BASE = 0x1000), locals (0x2000), and globals (0x3000) into synthetic registers. Structured control (block, loop, if/else, br, br_if, br_table, end) lowers directly to byte-addressed CFG edges.
  • One-Call Lifting: lift_function_cfg(&module, fn_index, &limits) returns LiftedWasmFunction containing the complete archsem_ir::Function CFG. Proposal opcodes outside the neutral core appear as WasmOpcode::Opaque with validated stack arity.

Ethereum Virtual Machine (archsem-evm)

  • Decoder & Fork Gating: Backed by evm-disassembler (EvmCode::parse / parse_hex). EvmFork (Frontier through Osaka) gates opcodes by hard fork—opcodes absent in the selected fork decode as INVALID. Truncated trailing PUSHn immediates zero-pad to full width, and JUMPDEST offsets are collected at instruction boundaries.
  • Static Jump-Target Resolution (EvmFunction): Performs bounded value-set analysis (AnalysisLimits) to resolve JUMP and JUMPI destinations within the code object, exposing FunctionStackGraph and EvmStackSsa views.
  • Address Spaces: Disjoint AddressSpaceAliasGroups separate big-endian EVM MEMORY_SPACE (Data), CODE_SPACE (Code), STACK_SPACE (Vendor(0)), STORAGE_SPACE (Vendor(1), 256-bit word-addressed), TRANSIENT_SPACE (Vendor(2)), CALLDATA_SPACE (Vendor(3)), RETURNDATA_SPACE (Vendor(4)), and WORLD_STATE_SPACE (Vendor(5)).
  • 256-bit Semantics & Stack Templates: Stack ops (stack evm in Asem) emit explicit underflow and 1024-word overflow guards (EVM_SP) around 256-bit arithmetic (ADD, MUL, EXP, ADDMOD, MULMOD, SHL/SHR/SAR, CLZ, etc.). External world-state, gas, and message calls remain typed opaque boundaries.
  • One-Call Lifting: lift_code_cfg(&code, &limits) lifts an entire contract into LiftedCode.

.NET CIL / ECMA-335 (archsem-cil)

  • PE & Metadata Decoder: Backed by cildec (metadata tables, method headers, signatures, exception clauses) and fNET (IL instruction decoder).
  • Modes (CIL32 / CIL64): mode_for_image_flags resolves 32BITREQUIRED vs PE32+ headers.
  • Evaluation Stack & Method Slots: CilFunction::normalize computes stack heights and assigns synthetic registers for evaluation-stack slots (0x1000), method arguments (0x2000), and locals (0x3000), plus CIL_STACK_POINTER, CIL_EXCEPTION, CIL_RET, and CIL_FILTER.
  • Exception Handling (lift_method_cfg & attach_unwind_edges): Discovers try / catch / filter / finally / fault handler entry points via CfgLiftConfig::additional_entries and attaches prioritized ExceptionalEdges onto the lifted Function.
  • Managed Object Services: Object-model instructions (newobj, callvirt, ldfld, castclass, etc.) emit typed OpaqueIntrinsics and volatile. / ordered memory contracts (LoadContract / StoreContract).

Lua & LuaJIT (archsem-lua)

  • Chunk Decoder: Backed by fLUA, supporting LUA51, LUA52, LUA53, LUA54, LUAJIT21, and LUAJIT21_BITOPS (mode_for_version).
  • Boxed 128-bit Slot Model: Frame slots hold 128-bit boxed values (64-bit payload + 64-bit tag: NIL_VALUE, FALSE_VALUE, TRUE_VALUE, INTEGER_TAG, FLOAT_TAG) addressed relative to LUA_FRAME, with LUA_LINK for continuations and dedicated system temporaries for numeric loops and scalar operations.
  • CFG Lifting & Optional Runtime (runtime feature): lift_function_cfg(&module, index, &limits) lifts a prototype's CFG (LiftedLuaFunction). Enabling features = ["runtime"] integrates archsem-ref with a suspensible cursor (lift_cursor / ProgramCursor) and version-matched error/scope policies (VmErrorPolicy), while table metamethods, upvalues, GC, and native C calls remain explicit guest services.

Experimental: CPython 3.11.9 (archsem-python)

archsem-python (gated behind features = ["python"], not enabled by default) is an experimental, handler-level frontend for baseline CPython 3.11.9 wordcode (LOAD_FAST, BINARY_OP, and generic vectorcall CALL). Callers supply a FrameContext with stack-slot ownership evidence (StackSlot::Object, Null, Unknown) and PreparedVectorcall witness data to decode_3119, then lift single handlers via archsem_python::lift into PYTHON_MANIFEST (PY_LOCALS, PY_SP, PY_LASTI) and five cpython.3119.* reference-counting/protocol opaque services (own_fast, binary, vectorcall, decref, pending_after_success).