Add wasm2elf: i32 WebAssembly to static x86-64 ELF compiler in MoonBit
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
b8617c7aaa
22 files changed
+1219
No files matched your search
@@ -0,0 +1,3 @@
|
||||
(module
|
||||
(func (export "main") (result i32)
|
||||
(i32.div_s (i32.const 7) (i32.sub (i32.const 3) (i32.const 3)))))
|
||||
@@ -0,0 +1,8 @@
|
||||
;; recursive factorial(5) = 120, plus if/else with result
|
||||
(module
|
||||
(func $fact (param $n i32) (result i32)
|
||||
(if (result i32) (i32.le_s (local.get $n) (i32.const 1))
|
||||
(then (i32.const 1))
|
||||
(else (i32.mul (local.get $n) (call $fact (i32.sub (local.get $n) (i32.const 1)))))))
|
||||
(func (export "main") (result i32)
|
||||
(call $fact (i32.const 5))))
|
||||
@@ -0,0 +1,16 @@
|
||||
;; select, tee, rem_s, shifts, early return, nested blocks with results: -> 42
|
||||
(module
|
||||
(func $pick (param $a i32) (param $b i32) (param $c i32) (result i32)
|
||||
(select (local.get $a) (local.get $b) (local.get $c)))
|
||||
(func (export "main") (result i32)
|
||||
(local $x i32)
|
||||
(local.set $x (i32.rem_s (i32.const -7) (i32.const 3))) ;; -1
|
||||
(if (i32.ne (local.get $x) (i32.const -1)) (then (return (i32.const 1))))
|
||||
(if (i32.ne (i32.shr_u (i32.const -1) (i32.const 28)) (i32.const 15)) (then (return (i32.const 2))))
|
||||
(if (i32.ne (call $pick (i32.const 10) (i32.const 20) (i32.const 0)) (i32.const 20)) (then (return (i32.const 3))))
|
||||
(if (i32.ne (call $pick (i32.const 10) (i32.const 20) (i32.const 1)) (i32.const 10)) (then (return (i32.const 4))))
|
||||
(i32.add
|
||||
(block (result i32)
|
||||
(drop (i32.const 99))
|
||||
(br 0 (i32.const 40)))
|
||||
(local.tee $x (i32.const 2)))))
|
||||
@@ -0,0 +1,15 @@
|
||||
(module
|
||||
(func $rise (result i32)
|
||||
i32.const 6)
|
||||
(func $shine (param $hour i32) (result i32)
|
||||
local.get $hour
|
||||
i32.const 9
|
||||
i32.lt_u
|
||||
if (result i32)
|
||||
unreachable
|
||||
else
|
||||
i32.const 1
|
||||
end)
|
||||
(func (export "morning") (result i32)
|
||||
call $rise
|
||||
call $shine))
|
||||
@@ -0,0 +1,12 @@
|
||||
;; sum 1..10 with a loop -> exit code 55
|
||||
(module
|
||||
(func (export "main") (result i32)
|
||||
(local $i i32) (local $acc i32)
|
||||
(local.set $i (i32.const 1))
|
||||
(block $done
|
||||
(loop $top
|
||||
(br_if $done (i32.gt_s (local.get $i) (i32.const 10)))
|
||||
(local.set $acc (i32.add (local.get $acc) (local.get $i)))
|
||||
(local.set $i (i32.add (local.get $i) (i32.const 1)))
|
||||
(br $top)))
|
||||
local.get $acc))
|
||||
Reference in new issue
Block a user