3 ms·
Actually it is quite high level (with the GC extension even "higher" than C), not comparable to "real" assembler. It has types. It isn't fun writing WAT, but fo
by ReleaseCandidat 3y ago
Actually it is quite high level (with the GC extension even "higher" than C), not comparable to "real" assembler. It has types. It isn't fun writing WAT, but for small stuff it's perfectly doable.
That's a record with 3 fields, its constructor and getters using the GC extension:
;; A `struct` with 3 fields, all immutable.
(type $testStruct
(struct
(field $first i64)
(field $foo f32)
(field $baz f64)))
;; Constructor. `ref` is a reference
(func $mkTestStruct
(param $a i64) (param $b f32) (param $c f64) (result (ref $testStruct))
(struct.new $testStruct (local.get $a) (local.get $b) (local.get $c)))
(export "mkTestStruct" (func $mkTestStruct))
;; Getter function for the three fields:
(func $getTestStruct1 (param $rs (ref $testStruct)) (result i64)
(struct.get $testStruct 0 (local.get $rs)))
(export "getTestStruct1" (func $getTestStruct1))
(func $getTestStruct2 (param $rs (ref $testStruct)) (result f32)
(struct.get $testStruct 1 (local.get $rs)))
(export "getTestStruct2" (func $getTestStruct2))
(func $getTestStruct3 (param $rs (ref $testStruct)) (result f64)
(struct.get $testStruct 2 (local.get $rs)))
(export "getTestStruct3" (func $getTestStruct3))