Implement the env shuffling to enable blocks with labels and breaking to them (via 'hidden' depth constant added to each block env, from which the block depth is subtracted in the br vau
This commit is contained in:
@@ -8,12 +8,16 @@
|
||||
(func $add (param $num i32) (result i32)
|
||||
(local $tmp1 i32)
|
||||
(local $tmp2 i32)
|
||||
(block
|
||||
(block $test
|
||||
(i32.const 1337)
|
||||
(i32.const 1338)
|
||||
drop
|
||||
drop
|
||||
(br 0)
|
||||
(block $inner_test
|
||||
(br $inner_test)
|
||||
(br $test)
|
||||
)
|
||||
(br $test)
|
||||
drop
|
||||
)
|
||||
(i32.const 11)
|
||||
|
||||
12
wasm.kp
12
wasm.kp
@@ -176,7 +176,7 @@
|
||||
(= nil cur_typ) (recurse cur_list (idx (idx locals i) 2) 1 (+ 1 i))
|
||||
true (recurse (concat cur_list [[cur_num cur_typ]]) (idx (idx locals i) 2) 1 (+ 1 i)))
|
||||
) [] nil 0 0)
|
||||
inner_env (add-dict-to-env de inner_name_dict)
|
||||
inner_env (add-dict-to-env de (put inner_name_dict 'depth 0))
|
||||
our_type [ (map (lambda (x) (idx x 2)) params) (slice result 1 -1) ]
|
||||
_ (println "about to get our_code")
|
||||
our_code (flat_map (lambda (x) (let (ins (eval x inner_env))
|
||||
@@ -203,9 +203,13 @@
|
||||
i32.const (lambda (const) [['i32.const const]])
|
||||
local.get (lambda (const) [['local.get const]])
|
||||
i32.add (lambda (& flatten) (concat (flat_map (lambda (x) x) flatten) [['i32.add]]))
|
||||
block (lambda (& inner) [['block [] (flat_map (lambda (x) (cond (array? x) x
|
||||
true (x))) inner)]])
|
||||
br (lambda (const) [['br const]])
|
||||
block (vau de (name & inner) (let (
|
||||
new_depth (+ 1 (eval 'depth de))
|
||||
inner_env (add-dict-to-env de [[ name [new_depth] ] [ 'depth new_depth ]])
|
||||
) [['block [] (flat_map (lambda (x) (let (ins (eval x inner_env)) (cond (array? ins) ins
|
||||
true (ins)))) inner)]]))
|
||||
br (vau de (b) (let (block (eval b de)) (if (int? block) [['br block]]
|
||||
[['br (eval [- 'depth (idx block 0)] de)]])))
|
||||
export (vau de (name t_v) (lambda (name_dict type function memory export code)
|
||||
[ name_dict type function memory (concat export [ [ name (idx t_v 0) (get-value name_dict (idx t_v 1)) ] ]) code ]
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user