3 (func $ENV_NEW (param $outer i32) (result i32)
4 (LET $data ($HASHMAP) ;; allocate the data hashmap
5 $env ($ALLOC (global.get $ENVIRONMENT_T) $data $outer 0))
6 ;; environment takes ownership
11 (func $ENV_NEW_BINDS (param $outer i32 $binds i32 $exprs i32) (result i32)
12 (LET $env ($ENV_NEW $outer)
18 (br_if $done (i32.eqz ($VAL0 $binds)))
20 ;; get/deref the key from binds
21 (local.set $key ($MEM_VAL1_ptr $binds))
22 (if (i32.eqz ($strcmp "&" ($to_String $key)))
25 ;; get/deref the key from the next element of binds
26 (local.set $binds ($MEM_VAL0_ptr $binds))
27 (local.set $key ($MEM_VAL1_ptr $binds))
28 ;; the value is the remaining list in exprs
29 (local.set $exprs ($FORCE_SEQ_TYPE (global.get $LIST_T) $exprs))
30 ;; set the binding in the environment data
31 (drop ($ENV_SET $env $key $exprs))
32 ;; list is owned by the environment
37 ;; set the binding in the environment data
38 (drop ($ENV_SET $env $key ($MEM_VAL1_ptr $exprs)))
39 ;; go to next element of binds and exprs
40 (local.set $binds ($MEM_VAL0_ptr $binds))
41 (local.set $exprs ($MEM_VAL0_ptr $exprs))))
49 (func $ENV_SET (param $env i32 $key i32 $value i32) (result i32)
50 (LET $data ($MEM_VAL0_ptr $env))
51 (i32.store ($VAL0_ptr $env) ($IDX ($ASSOC1 $data $key $value)))
55 (func $ENV_SET_S (param $env i32 $key i32 $value i32) (result i32)
56 (LET $data ($MEM_VAL0_ptr $env))
57 (i32.store ($VAL0_ptr $env) ($IDX ($ASSOC1_S $data $key $value)))
61 (func $ENV_FIND (param $env i32 $key i32) (result i64)
62 (local $found_res i64)
68 (local.set $data ($MEM_VAL0_ptr $env))
69 (local.set $found_res ($HASHMAP_GET $data $key))
71 (if (i32.wrap_i64 (i64.shr_u $found_res (i64.const 32)))
73 (local.set $res (i32.wrap_i64 $found_res))
75 (local.set $env ($MEM_VAL1_ptr $env))
76 (if (i32.eq $env (global.get $NIL))
84 ;; combine res/env as hi 32/low 32 of i64
86 (i64.shl (i64.extend_i32_u $res) (i64.const 32))
87 (i64.extend_i32_u $env))
90 (func $ENV_GET (param $env i32 $key i32) (result i32)
94 (local.set $res_env ($ENV_FIND $env $key))
95 (local.set $env (i32.wrap_i64 $res_env))
96 (local.set $res (i32.wrap_i64 (i64.shr_u $res_env (i64.const 32))))
100 ($THROW_STR_1 "'%s' not found" ($to_String $key))
102 (return ($INC_REF $res))