From 8aab790c7621d928b03c34636ec6d65aa4066ed6 Mon Sep 17 00:00:00 2001 From: Nicolas Boulenguez Date: Wed, 28 Aug 2024 07:48:46 +0200 Subject: [PATCH] wasm: remove the now unneeded ENV_FIND environment method --- impls/wasm/env.wam | 30 +++++------------------------- impls/wasm/step3_env.wam | 18 +++++++++--------- impls/wasm/step4_if_fn_do.wam | 18 +++++++++--------- impls/wasm/step5_tco.wam | 15 +++++++-------- impls/wasm/step6_file.wam | 15 +++++++-------- impls/wasm/step7_quote.wam | 15 +++++++-------- impls/wasm/step8_macros.wam | 15 +++++++-------- impls/wasm/step9_try.wam | 15 +++++++-------- impls/wasm/stepA_mal.wam | 15 +++++++-------- 9 files changed, 65 insertions(+), 91 deletions(-) diff --git a/impls/wasm/env.wam b/impls/wasm/env.wam index cd10c76918..aa7eef75d8 100644 --- a/impls/wasm/env.wam +++ b/impls/wasm/env.wam @@ -58,12 +58,13 @@ $value ) - (func $ENV_FIND (param $env i32 $key i32) (result i64) + (func $ENV_GET (param $env i32 $key i32) (result i32) + ;; Return 0 when the key is not found, but do not set THROW_STR. + (local $found_res i64) (LET $res 0 $data 0) - (block $done (loop $loop (local.set $data ($MEM_VAL0_ptr $env)) (local.set $found_res ($HASHMAP_GET $data $key)) @@ -71,34 +72,13 @@ (if (i32.wrap_i64 (i64.shr_u $found_res (i64.const 32))) (then (local.set $res (i32.wrap_i64 $found_res)) - (br $done))) + (return ($INC_REF $res)))) (local.set $env ($MEM_VAL1_ptr $env)) (if (i32.eq $env (global.get $NIL)) (then - (local.set $env 0) - (br $done))) + (return 0))) (br $loop) ) - ) - - ;; combine res/env as hi 32/low 32 of i64 - (i64.or - (i64.shl (i64.extend_i32_u $res) (i64.const 32)) - (i64.extend_i32_u $env)) ) - (func $ENV_GET (param $env i32 $key i32) (result i32) - (local $res_env i64) - (LET $res 0) - - (local.set $res_env ($ENV_FIND $env $key)) - (local.set $env (i32.wrap_i64 $res_env)) - (local.set $res (i32.wrap_i64 (i64.shr_u $res_env (i64.const 32)))) - - (if (i32.eqz $env) - (then - ($THROW_STR_1 "'%s' not found" ($to_String $key)) - (return $res))) - (return ($INC_REF $res)) - ) ) diff --git a/impls/wasm/step3_env.wam b/impls/wasm/step3_env.wam index 6135e1d722..ca52623ff3 100644 --- a/impls/wasm/step3_env.wam +++ b/impls/wasm/step3_env.wam @@ -84,15 +84,12 @@ ($MEM_VAL1_ptr ($MEM_VAL0_ptr ($MEM_VAL0_ptr ($MEM_VAL0_ptr $ast))))) (func $ECHO_IF_DEBUG_EVAL (param $ast i32 $env i32) - (local $res_env i64 $value i32) - (local.set $res_env ($ENV_FIND $env (global.get $DEBUG_EVAL_S))) - (if (i32.wrap_i64 $res_env) + (LET $value ($ENV_GET $env (global.get $DEBUG_EVAL_S))) + (if (AND $value + (i32.ne $value (global.get $NIL)) + (i32.ne $value (global.get $FALSE))) (then - (local.set $value (i32.wrap_i64 (i64.shr_u $res_env (i64.const 32)))) - (if (AND (i32.ne $value (global.get $NIL)) - (i32.ne $value (global.get $FALSE))) - (then - ($PR_VALUE "EVAL: %s\n" $ast)))))) + ($PR_VALUE "EVAL: %s\n" $ast)))) (func $EVAL (param $ast i32 $env i32) (result i32) (LET $res 0 @@ -108,7 +105,10 @@ (if (i32.eq $ast_type (global.get $SYMBOL_T)) (then - (return ($ENV_GET $env $ast)))) + (local.set $res ($ENV_GET $env $ast)) + (if (i32.eqz $res) + ($THROW_STR_1 "'%s' not found" ($to_String $ast))) + (return $res))) (if (OR (i32.eq $ast_type (global.get $VECTOR_T)) (i32.eq $ast_type (global.get $HASHMAP_T))) diff --git a/impls/wasm/step4_if_fn_do.wam b/impls/wasm/step4_if_fn_do.wam index 26020305e5..01eaa69324 100644 --- a/impls/wasm/step4_if_fn_do.wam +++ b/impls/wasm/step4_if_fn_do.wam @@ -78,15 +78,12 @@ ($MEM_VAL1_ptr ($MEM_VAL0_ptr ($MEM_VAL0_ptr ($MEM_VAL0_ptr $ast))))) (func $ECHO_IF_DEBUG_EVAL (param $ast i32 $env i32) - (local $res_env i64 $value i32) - (local.set $res_env ($ENV_FIND $env (global.get $DEBUG_EVAL_S))) - (if (i32.wrap_i64 $res_env) + (LET $value ($ENV_GET $env (global.get $DEBUG_EVAL_S))) + (if (AND $value + (i32.ne $value (global.get $NIL)) + (i32.ne $value (global.get $FALSE))) (then - (local.set $value (i32.wrap_i64 (i64.shr_u $res_env (i64.const 32)))) - (if (AND (i32.ne $value (global.get $NIL)) - (i32.ne $value (global.get $FALSE))) - (then - ($PR_VALUE "EVAL: %s\n" $ast)))))) + ($PR_VALUE "EVAL: %s\n" $ast)))) (func $EVAL (param $ast i32 $env i32) (result i32) (LET $res 0 $el 0 @@ -102,7 +99,10 @@ (if (i32.eq $ast_type (global.get $SYMBOL_T)) (then - (return ($ENV_GET $env $ast)))) + (local.set $res ($ENV_GET $env $ast)) + (if (i32.eqz $res) + ($THROW_STR_1 "'%s' not found" ($to_String $ast))) + (return $res))) (if (OR (i32.eq $ast_type (global.get $VECTOR_T)) (i32.eq $ast_type (global.get $HASHMAP_T))) diff --git a/impls/wasm/step5_tco.wam b/impls/wasm/step5_tco.wam index 8751a0e699..4dabe4cc83 100644 --- a/impls/wasm/step5_tco.wam +++ b/impls/wasm/step5_tco.wam @@ -80,15 +80,12 @@ ($MEM_VAL1_ptr ($MEM_VAL0_ptr ($MEM_VAL0_ptr ($MEM_VAL0_ptr $ast))))) (func $ECHO_IF_DEBUG_EVAL (param $ast i32 $env i32) - (local $res_env i64 $value i32) - (local.set $res_env ($ENV_FIND $env (global.get $DEBUG_EVAL_S))) - (if (i32.wrap_i64 $res_env) + (LET $value ($ENV_GET $env (global.get $DEBUG_EVAL_S))) + (if (AND $value + (i32.ne $value (global.get $NIL)) + (i32.ne $value (global.get $FALSE))) (then - (local.set $value (i32.wrap_i64 (i64.shr_u $res_env (i64.const 32)))) - (if (AND (i32.ne $value (global.get $NIL)) - (i32.ne $value (global.get $FALSE))) - (then - ($PR_VALUE "EVAL: %s\n" $ast)))))) + ($PR_VALUE "EVAL: %s\n" $ast)))) (func $EVAL (param $orig_ast i32 $orig_env i32) (result i32) (LET $ast $orig_ast @@ -112,6 +109,8 @@ (if (i32.eq $ast_type (global.get $SYMBOL_T)) (then (local.set $res ($ENV_GET $env $ast)) + (if (i32.eqz $res) + ($THROW_STR_1 "'%s' not found" ($to_String $ast))) (br $EVAL_return))) (if (OR (i32.eq $ast_type (global.get $VECTOR_T)) diff --git a/impls/wasm/step6_file.wam b/impls/wasm/step6_file.wam index 813f7f487a..f7e8ee2100 100644 --- a/impls/wasm/step6_file.wam +++ b/impls/wasm/step6_file.wam @@ -80,15 +80,12 @@ ($MEM_VAL1_ptr ($MEM_VAL0_ptr ($MEM_VAL0_ptr ($MEM_VAL0_ptr $ast))))) (func $ECHO_IF_DEBUG_EVAL (param $ast i32 $env i32) - (local $res_env i64 $value i32) - (local.set $res_env ($ENV_FIND $env (global.get $DEBUG_EVAL_S))) - (if (i32.wrap_i64 $res_env) + (LET $value ($ENV_GET $env (global.get $DEBUG_EVAL_S))) + (if (AND $value + (i32.ne $value (global.get $NIL)) + (i32.ne $value (global.get $FALSE))) (then - (local.set $value (i32.wrap_i64 (i64.shr_u $res_env (i64.const 32)))) - (if (AND (i32.ne $value (global.get $NIL)) - (i32.ne $value (global.get $FALSE))) - (then - ($PR_VALUE "EVAL: %s\n" $ast)))))) + ($PR_VALUE "EVAL: %s\n" $ast)))) (func $EVAL (param $orig_ast i32 $orig_env i32) (result i32) (LET $ast $orig_ast @@ -112,6 +109,8 @@ (if (i32.eq $ast_type (global.get $SYMBOL_T)) (then (local.set $res ($ENV_GET $env $ast)) + (if (i32.eqz $res) + ($THROW_STR_1 "'%s' not found" ($to_String $ast))) (br $EVAL_return))) (if (OR (i32.eq $ast_type (global.get $VECTOR_T)) diff --git a/impls/wasm/step7_quote.wam b/impls/wasm/step7_quote.wam index 9127aa9efe..fce581e0d4 100644 --- a/impls/wasm/step7_quote.wam +++ b/impls/wasm/step7_quote.wam @@ -160,15 +160,12 @@ ($MEM_VAL1_ptr ($MEM_VAL0_ptr ($MEM_VAL0_ptr ($MEM_VAL0_ptr $ast))))) (func $ECHO_IF_DEBUG_EVAL (param $ast i32 $env i32) - (local $res_env i64 $value i32) - (local.set $res_env ($ENV_FIND $env (global.get $DEBUG_EVAL_S))) - (if (i32.wrap_i64 $res_env) + (LET $value ($ENV_GET $env (global.get $DEBUG_EVAL_S))) + (if (AND $value + (i32.ne $value (global.get $NIL)) + (i32.ne $value (global.get $FALSE))) (then - (local.set $value (i32.wrap_i64 (i64.shr_u $res_env (i64.const 32)))) - (if (AND (i32.ne $value (global.get $NIL)) - (i32.ne $value (global.get $FALSE))) - (then - ($PR_VALUE "EVAL: %s\n" $ast)))))) + ($PR_VALUE "EVAL: %s\n" $ast)))) (func $EVAL (param $orig_ast i32 $orig_env i32) (result i32) (LET $ast $orig_ast @@ -192,6 +189,8 @@ (if (i32.eq $ast_type (global.get $SYMBOL_T)) (then (local.set $res ($ENV_GET $env $ast)) + (if (i32.eqz $res) + ($THROW_STR_1 "'%s' not found" ($to_String $ast))) (br $EVAL_return))) (if (OR (i32.eq $ast_type (global.get $VECTOR_T)) diff --git a/impls/wasm/step8_macros.wam b/impls/wasm/step8_macros.wam index d50a5014e0..cadb6de970 100644 --- a/impls/wasm/step8_macros.wam +++ b/impls/wasm/step8_macros.wam @@ -160,15 +160,12 @@ ($MEM_VAL1_ptr ($MEM_VAL0_ptr ($MEM_VAL0_ptr ($MEM_VAL0_ptr $ast))))) (func $ECHO_IF_DEBUG_EVAL (param $ast i32 $env i32) - (local $res_env i64 $value i32) - (local.set $res_env ($ENV_FIND $env (global.get $DEBUG_EVAL_S))) - (if (i32.wrap_i64 $res_env) + (LET $value ($ENV_GET $env (global.get $DEBUG_EVAL_S))) + (if (AND $value + (i32.ne $value (global.get $NIL)) + (i32.ne $value (global.get $FALSE))) (then - (local.set $value (i32.wrap_i64 (i64.shr_u $res_env (i64.const 32)))) - (if (AND (i32.ne $value (global.get $NIL)) - (i32.ne $value (global.get $FALSE))) - (then - ($PR_VALUE "EVAL: %s\n" $ast)))))) + ($PR_VALUE "EVAL: %s\n" $ast)))) (func $EVAL (param $orig_ast i32 $orig_env i32) (result i32) (LET $ast $orig_ast @@ -193,6 +190,8 @@ (if (i32.eq $ast_type (global.get $SYMBOL_T)) (then (local.set $res ($ENV_GET $env $ast)) + (if (i32.eqz $res) + ($THROW_STR_1 "'%s' not found" ($to_String $ast))) (br $EVAL_return))) (if (OR (i32.eq $ast_type (global.get $VECTOR_T)) diff --git a/impls/wasm/step9_try.wam b/impls/wasm/step9_try.wam index 486906c2f8..809acd868e 100644 --- a/impls/wasm/step9_try.wam +++ b/impls/wasm/step9_try.wam @@ -160,15 +160,12 @@ ($MEM_VAL1_ptr ($MEM_VAL0_ptr ($MEM_VAL0_ptr ($MEM_VAL0_ptr $ast))))) (func $ECHO_IF_DEBUG_EVAL (param $ast i32 $env i32) - (local $res_env i64 $value i32) - (local.set $res_env ($ENV_FIND $env (global.get $DEBUG_EVAL_S))) - (if (i32.wrap_i64 $res_env) + (LET $value ($ENV_GET $env (global.get $DEBUG_EVAL_S))) + (if (AND $value + (i32.ne $value (global.get $NIL)) + (i32.ne $value (global.get $FALSE))) (then - (local.set $value (i32.wrap_i64 (i64.shr_u $res_env (i64.const 32)))) - (if (AND (i32.ne $value (global.get $NIL)) - (i32.ne $value (global.get $FALSE))) - (then - ($PR_VALUE "EVAL: %s\n" $ast)))))) + ($PR_VALUE "EVAL: %s\n" $ast)))) (func $EVAL (param $orig_ast i32 $orig_env i32) (result i32) (LET $ast $orig_ast @@ -193,6 +190,8 @@ (if (i32.eq $ast_type (global.get $SYMBOL_T)) (then (local.set $res ($ENV_GET $env $ast)) + (if (i32.eqz $res) + ($THROW_STR_1 "'%s' not found" ($to_String $ast))) (br $EVAL_return))) (if (OR (i32.eq $ast_type (global.get $VECTOR_T)) diff --git a/impls/wasm/stepA_mal.wam b/impls/wasm/stepA_mal.wam index 9cd6dcdfd0..fc413d4e15 100644 --- a/impls/wasm/stepA_mal.wam +++ b/impls/wasm/stepA_mal.wam @@ -160,15 +160,12 @@ ($MEM_VAL1_ptr ($MEM_VAL0_ptr ($MEM_VAL0_ptr ($MEM_VAL0_ptr $ast))))) (func $ECHO_IF_DEBUG_EVAL (param $ast i32 $env i32) - (local $res_env i64 $value i32) - (local.set $res_env ($ENV_FIND $env (global.get $DEBUG_EVAL_S))) - (if (i32.wrap_i64 $res_env) + (LET $value ($ENV_GET $env (global.get $DEBUG_EVAL_S))) + (if (AND $value + (i32.ne $value (global.get $NIL)) + (i32.ne $value (global.get $FALSE))) (then - (local.set $value (i32.wrap_i64 (i64.shr_u $res_env (i64.const 32)))) - (if (AND (i32.ne $value (global.get $NIL)) - (i32.ne $value (global.get $FALSE))) - (then - ($PR_VALUE "EVAL: %s\n" $ast)))))) + ($PR_VALUE "EVAL: %s\n" $ast)))) (func $EVAL (param $orig_ast i32 $orig_env i32) (result i32) (LET $ast $orig_ast @@ -193,6 +190,8 @@ (if (i32.eq $ast_type (global.get $SYMBOL_T)) (then (local.set $res ($ENV_GET $env $ast)) + (if (i32.eqz $res) + ($THROW_STR_1 "'%s' not found" ($to_String $ast))) (br $EVAL_return))) (if (OR (i32.eq $ast_type (global.get $VECTOR_T))