- x in someSet → someSet.has(x) - x in someMap.keys → someMap.has(x) - x notIn someMap.keys → !someMap.has(x) - m[k] → m.get(k) for Map state variables - s.size() → s.size (property, not method) - Track Map-typed state variables via mapVarNames for accurate .get() translation - Thread mapVarNames through emitAction and rewriteExpr All 41 tests passing. TigerBeetleLedger now generates correct TypeScript with .get() for Map access and .has() for Set membership. Part of M0.1: Fix TS generator bugs (speckl#18)
102 lines
No EOL
3 KiB
Text
102 lines
No EOL
3 KiB
Text
;; Auto-generated by speckl-compile from TigerBeetleLedger
|
|
;; Compile: wat2wasm TigerBeetleLedger.wat -o TigerBeetleLedger.wasm
|
|
|
|
(module
|
|
;; Host imports for Map/Set/alloc
|
|
(import "speckl" "map_create" (func $map_create (result i32)))
|
|
(import "speckl" "map_set" (func $map_set (param i32 i32 i32)))
|
|
(import "speckl" "map_get" (func $map_get (param i32 i32) (result i32)))
|
|
(import "speckl" "map_has" (func $map_has (param i32 i32) (result i32)))
|
|
(import "speckl" "map_remove" (func $map_remove (param i32 i32)))
|
|
(import "speckl" "set_create" (func $set_create (result i32)))
|
|
(import "speckl" "set_add" (func $set_add (param i32 i32)))
|
|
(import "speckl" "set_has" (func $set_has (param i32 i32) (result i32)))
|
|
(import "speckl" "set_size" (func $set_size (param i32) (result i32)))
|
|
(import "speckl" "alloc" (func $alloc (param i32) (result i32)))
|
|
(import "speckl" "write_i32" (func $write_i32 (param i32 i32)))
|
|
(import "speckl" "write_f64" (func $write_f64 (param i32 f64)))
|
|
|
|
;; Linear memory (exported so host can read state)
|
|
(memory (export "memory") 1)
|
|
|
|
;; State globals
|
|
(global $accounts (mut i32) (i32.const 0))
|
|
(global $transfers (mut i32) (i32.const 0))
|
|
(global $pending (mut i32) (i32.const 0))
|
|
(global $replicaState (mut i32) (i32.const 0))
|
|
(global $log (mut i32) (i32.const 0))
|
|
(global $commitIndex (mut i32) (i32.const 0))
|
|
(global $leader (mut i32) (i32.const 0))
|
|
|
|
;; ---- init ----
|
|
(func $init (export "init")
|
|
(call $map_create)
|
|
(global.set $accounts)
|
|
(call $map_create)
|
|
(global.set $transfers)
|
|
(call $set_create)
|
|
(global.set $pending)
|
|
(call $map_create)
|
|
(global.set $replicaState)
|
|
(i32.const 0)
|
|
(global.set $commitIndex)
|
|
(i32.const 0)
|
|
(global.set $leader)
|
|
)
|
|
|
|
;; ---- Actions ----
|
|
;; action: CreateTransfer
|
|
(func $CreateTransfer (export "CreateTransfer") (param $t i32) (result i32)
|
|
|
|
(i32.const 1)
|
|
)
|
|
|
|
;; action: CommitTransfer
|
|
(func $CommitTransfer (export "CommitTransfer") (param $id i32) (result i32)
|
|
|
|
(i32.const 1)
|
|
)
|
|
|
|
;; action: VoidTransfer
|
|
(func $VoidTransfer (export "VoidTransfer") (param $id i32) (result i32)
|
|
|
|
(i32.const 1)
|
|
)
|
|
|
|
;; action: PostTransfer
|
|
(func $PostTransfer (export "PostTransfer") (param $t i32) (result i32)
|
|
|
|
(i32.const 1)
|
|
)
|
|
|
|
;; action: BecomeLeader
|
|
(func $BecomeLeader (export "BecomeLeader") (param $replica i32) (param $term i32) (result i32)
|
|
|
|
(i32.const 1)
|
|
)
|
|
|
|
;; action: AppendEntry
|
|
(func $AppendEntry (export "AppendEntry") (param $entry i32) (param $term i32) (result i32)
|
|
|
|
(i32.const 1)
|
|
)
|
|
|
|
;; ---- getState ----
|
|
(func $getState (export "getState") (result i32 i32)
|
|
(i32.const 0)
|
|
(global.get $commitIndex)
|
|
(i32.store)
|
|
(i32.const 4)
|
|
(global.get $leader)
|
|
(i32.store)
|
|
(i32.const 0)
|
|
(i32.const 8)
|
|
)
|
|
|
|
|
|
;; checkConstraints — runtime constraint evaluation stub
|
|
(func $checkConstraints (export "checkConstraints") (result i32)
|
|
;; TODO: evaluate constraint expressions at runtime
|
|
(i32.const 1)
|
|
)
|
|
) |