Skip to content

Commit

Permalink
wasm: prevent macros from mutating functions
Browse files Browse the repository at this point in the history
  • Loading branch information
asarhaddon authored and kanaka committed Aug 8, 2024
1 parent 91f9877 commit 24d82e4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
7 changes: 5 additions & 2 deletions impls/wasm/step8_macros.wam
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,15 @@
(then
(local.set $a1 ($MAL_GET_A1 $ast))
(local.set $a2 ($MAL_GET_A2 $ast))
(local.set $res ($EVAL $a2 $env))
(local.set $f ($EVAL $a2 $env))
(local.set $res ($MALFUNC ($MEM_VAL0_ptr $f)
($MEM_VAL1_ptr $f) ($MEM_VAL2_ptr $f)))
($SET_TYPE $res (global.get $MACRO_T))
(br_if $EVAL_return (global.get $error_type))
($RELEASE $f)

;; set a1 in env to a2
(local.set $res ($ENV_SET $env $a1 $res))
(drop ($ENV_SET $env $a1 $res))
(br $EVAL_return))
)
(if (i32.eqz ($strcmp "if" $a0sym))
Expand Down
7 changes: 5 additions & 2 deletions impls/wasm/step9_try.wam
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,15 @@
(then
(local.set $a1 ($MAL_GET_A1 $ast))
(local.set $a2 ($MAL_GET_A2 $ast))
(local.set $res ($EVAL $a2 $env))
(local.set $f ($EVAL $a2 $env))
(local.set $res ($MALFUNC ($MEM_VAL0_ptr $f)
($MEM_VAL1_ptr $f) ($MEM_VAL2_ptr $f)))
($SET_TYPE $res (global.get $MACRO_T))
(br_if $EVAL_return (global.get $error_type))
($RELEASE $f)

;; set a1 in env to a2
(local.set $res ($ENV_SET $env $a1 $res))
(drop ($ENV_SET $env $a1 $res))
(br $EVAL_return))
)
(if (i32.eqz ($strcmp "try*" $a0sym))
Expand Down
7 changes: 5 additions & 2 deletions impls/wasm/stepA_mal.wam
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,15 @@
(then
(local.set $a1 ($MAL_GET_A1 $ast))
(local.set $a2 ($MAL_GET_A2 $ast))
(local.set $res ($EVAL $a2 $env))
(local.set $f ($EVAL $a2 $env))
(local.set $res ($MALFUNC ($MEM_VAL0_ptr $f)
($MEM_VAL1_ptr $f) ($MEM_VAL2_ptr $f)))
($SET_TYPE $res (global.get $MACRO_T))
(br_if $EVAL_return (global.get $error_type))
($RELEASE $f)

;; set a1 in env to a2
(local.set $res ($ENV_SET $env $a1 $res))
(drop ($ENV_SET $env $a1 $res))
(br $EVAL_return))
)
(if (i32.eqz ($strcmp "try*" $a0sym))
Expand Down

0 comments on commit 24d82e4

Please sign in to comment.