From ad79f78ec9f7ddb505f5be58fd8dd5c65cf8abc6 Mon Sep 17 00:00:00 2001 From: Robert Muth Date: Sat, 13 Apr 2024 10:57:58 -0400 Subject: [PATCH] rename -> mlet, -> mfor --- FrontEnd/Lib/builtin.cw | 22 +++++++++++----------- FrontEnd/Lib/flate.cw | 2 +- FrontEnd/Lib/fmt.cw | 24 ++++++++++++------------ FrontEnd/Lib/sha3.cw | 2 +- FrontEnd/Lib/test.cw | 18 +++++++++--------- FrontEnd/TestData/macros.cw | 2 +- FrontEnd/cwast.py | 4 ++-- FrontEnd/pp.py | 6 +++--- 8 files changed, 40 insertions(+), 40 deletions(-) diff --git a/FrontEnd/Lib/builtin.cw b/FrontEnd/Lib/builtin.cw index e561223b..852876dd 100644 --- a/FrontEnd/Lib/builtin.cw +++ b/FrontEnd/Lib/builtin.cw @@ -19,14 +19,14 @@ The type of the loop variable is determined by $end""" (mparam $end EXPR) (mparam $step EXPR) (mparam $body STMT_LIST)] [$end_eval $step_eval $it] : - ($let $end_eval (typeof $end) $end) - ($let $step_eval (typeof $end) $step) - ($let! $it (typeof $end) $start) + (mlet $end_eval (typeof $end) $end) + (mlet $step_eval (typeof $end) $step) + (mlet! $it (typeof $end) $start) (block _ : (if (>= $it $end_eval) : (break) :) - ($let $index auto $it) + (mlet $index auto $it) (= $it (+ $it $step_eval)) $body (continue))) @@ -38,32 +38,32 @@ The type of the loop variable is determined by $end""" (mparam $expr EXPR) (mparam $catch_name ID) (mparam $catch_body STMT_LIST)] [$eval] : - ($let $eval auto $expr) + (mlet $eval auto $expr) (if (is $eval $type) : : - ($let $catch_name auto + (mlet $catch_name auto (@unchecked narrowto $eval (uniondelta (typeof $eval) $type))) $catch_body (trap)) - ($let $name $type (narrowto $eval $type))) + (mlet $name $type (narrowto $eval $type))) @pub (macro tryset STMT_LIST [ (mparam $name ID) (mparam $expr EXPR) (mparam $catch_name ID) (mparam $catch_body STMT_LIST)] [$eval] : - ($let $eval auto $expr) + (mlet $eval auto $expr) (if (is $eval (typeof $name)) : : - ($let $catch_name auto + (mlet $catch_name auto (@unchecked narrowto $eval (uniondelta (typeof $eval) (typeof $type)))) $catch_body (trap)) - ($let $name $type (narrowto $eval $type))) + (mlet $name $type (narrowto $eval $type))) (macro swap# STMT_LIST [(mparam $a EXPR) (mparam $b EXPR)] [$t] : - ($let $t auto $a) + (mlet $t auto $a) (= $a $b) (= $b $t)) diff --git a/FrontEnd/Lib/flate.cw b/FrontEnd/Lib/flate.cw index b633699a..43ef65a5 100644 --- a/FrontEnd/Lib/flate.cw +++ b/FrontEnd/Lib/flate.cw @@ -13,7 +13,7 @@ (macro xdump_slice# STMT_LIST [ (mparam $prefix EXPR) (mparam $slice EXPR)] [$s_eval $i] : - ($let $s_eval auto $slice) + (mlet $s_eval auto $slice) (for $i 0 (len $s_eval) 1 : (fmt::print# $prefix $i " -> " (at $s_eval $i) "\n")) ) diff --git a/FrontEnd/Lib/fmt.cw b/FrontEnd/Lib/fmt.cw index 52467849..34545419 100644 --- a/FrontEnd/Lib/fmt.cw +++ b/FrontEnd/Lib/fmt.cw @@ -49,10 +49,10 @@ (mparam $out EXPR)] [$v $out_eval $tmp $pos] : (expr : @doc "unsigned to str with given base" - ($let! $v auto $val) - ($let! $tmp auto (array_val 1024 u8)) - ($let! $pos uint $max_width) - ($let $out_eval auto $out) + (mlet! $v auto $val) + (mlet! $tmp auto (array_val 1024 u8)) + (mlet! $pos uint $max_width) + (mlet $out_eval auto $out) (block _ : (-= $pos 1) (let c auto (% $v $base)) @@ -351,10 +351,10 @@ @pub (macro print# STMT_LIST [ @doc "list of items to be printed" (mparam $parts EXPR_LIST_REST)] [$buffer $curr $options] : - ($let! $buffer auto (array_val FORMATED_STRING_MAX_LEN u8)) - ($let! $curr uint 0) - (@ref $let! $options auto (rec_val SysFormatOptions [])) - ($for $i $parts : + (mlet! $buffer auto (array_val FORMATED_STRING_MAX_LEN u8)) + (mlet! $curr uint 0) + (@ref mlet! $options auto (rec_val SysFormatOptions [])) + (mfor $i $parts : (+= $curr (@polymorphic SysRender [ $i (slice_val (pinc (front! $buffer) $curr) (- (len $buffer) $curr)) @@ -364,10 +364,10 @@ @doc "same as above but takes an EXPR_LIST - should only be used by other macros" @pub (macro print_list# STMT_LIST [ (mparam $parts EXPR_LIST)] [$buffer $curr $options] : - ($let! $buffer auto (array_val FORMATED_STRING_MAX_LEN u8)) - ($let! $curr uint 0) - (@ref $let! $options auto (rec_val SysFormatOptions [])) - ($for $i $parts : + (mlet! $buffer auto (array_val FORMATED_STRING_MAX_LEN u8)) + (mlet! $curr uint 0) + (@ref mlet! $options auto (rec_val SysFormatOptions [])) + (mfor $i $parts : (+= $curr (@polymorphic SysRender [ $i (slice_val (pinc (front! $buffer) $curr) (- (len $buffer) $curr)) diff --git a/FrontEnd/Lib/sha3.cw b/FrontEnd/Lib/sha3.cw index 3cea7d6d..41400461 100644 --- a/FrontEnd/Lib/sha3.cw +++ b/FrontEnd/Lib/sha3.cw @@ -71,7 +71,7 @@ https://emn178.github.io/online-tools/sha3_512.html ) (macro XOR_1# STMT_LIST [(mparam $x EXPR) (mparam $indices EXPR_LIST) (mparam $v EXPR)] [] : - ($for $i $indices : (xor= (at (^ $x) $i) $v)) + (mfor $i $indices : (xor= (at (^ $x) $i) $v)) ) (macro UPDATE# STMT_LIST [(mparam $a EXPR) (mparam $b EXPR) (mparam $x EXPR) (mparam $i EXPR) (mparam $bitpos EXPR)] [] : diff --git a/FrontEnd/Lib/test.cw b/FrontEnd/Lib/test.cw index 6fcb99f4..5a60226a 100644 --- a/FrontEnd/Lib/test.cw +++ b/FrontEnd/Lib/test.cw @@ -10,7 +10,7 @@ the footprint/dependencies small. (macro SysPrint# STMT_LIST [(mparam $msg EXPR)] [$msg_eval] : - ($let $msg_eval (slice u8) $msg) + (mlet $msg_eval (slice u8) $msg) (shed (os::write [(unwrap os::Stdout) (front $msg_eval) (len $msg_eval)]) )) @@ -22,8 +22,8 @@ the footprint/dependencies small. Both must have derivable types as we use `auto`""" @pub (macro AssertEq# STMT_LIST [(mparam $e_expr EXPR) (mparam $a_expr EXPR)] [$e_val $a_val] : - ($let $e_val auto $e_expr) - ($let $a_val auto $a_expr) + (mlet $e_val auto $e_expr) + (mlet $a_val auto $a_expr) (if (!= $e_val $a_val) : (SysPrint# "AssertEq failed: ") (SysPrint# (stringify $e_expr)) @@ -47,8 +47,8 @@ Both must have derivable types as we use `auto`""" @doc "The two arguments must type derivable" @pub (macro AssertSliceEq# STMT_LIST [(mparam $e_expr EXPR) (mparam $a_expr EXPR)] [$e_val $a_val $i] : - ($let $e_val auto $e_expr) - ($let $a_val auto $a_expr) + (mlet $e_val auto $e_expr) + (mlet $a_val auto $a_expr) (AssertEq# (len $e_val) (len $a_val)) (for $i 0 (len $a_val) 1 : (AssertEq# (^ (pinc (front $e_val) $i)) (^ (pinc (front $a_val) $i))))) @@ -59,8 +59,8 @@ Both must have derivable types as we use `auto`""" (mparam $e_expr EXPR) (mparam $a_expr EXPR) (mparam $epsilon EXPR)] [$e_val $a_val] : - ($let $e_val auto $e_expr) - ($let $a_val auto $a_expr) + (mlet $e_val auto $e_expr) + (mlet $a_val auto $a_expr) (if (|| (< $e_val (- $a_val $epsilon)) (> $e_val (+ $a_val $epsilon))) : (SysPrint# "AssertApproxEq failed: ") (SysPrint# (stringify $e_expr)) @@ -76,8 +76,8 @@ Both must have derivable types as we use `auto`""" (mparam $e_expr EXPR) (mparam $a_expr EXPR) (mparam $epsilon EXPR)] [$e_val $a_val $i] : - ($let $e_val auto $e_expr) - ($let $a_val auto $a_expr) + (mlet $e_val auto $e_expr) + (mlet $a_val auto $a_expr) (AssertEq# (len $e_val) (len $a_val)) (for $i 0 (len $a_val) 1 : (AssertApproxEq# (^ (pinc (front $e_val) $i)) (^ (pinc (front $a_val) $i)))) diff --git a/FrontEnd/TestData/macros.cw b/FrontEnd/TestData/macros.cw index 014c1be4..4b9a77e6 100644 --- a/FrontEnd/TestData/macros.cw +++ b/FrontEnd/TestData/macros.cw @@ -52,7 +52,7 @@ (macro product# STMT_LIST [(mparam $result ID) (mparam $factors STMT_LIST)] [] : - ($for $x $factors : + (mfor $x $factors : (= $result (* $result $x)))) diff --git a/FrontEnd/cwast.py b/FrontEnd/cwast.py index 9080f4af..9164219c 100755 --- a/FrontEnd/cwast.py +++ b/FrontEnd/cwast.py @@ -2822,7 +2822,7 @@ class MacroVar: `name` must start with a `$`. """ - ALIAS = "$let" + ALIAS = "mlet" GROUP = GROUP.Macro FLAGS = NF.TYPE_ANNOTATED | NF.LOCAL_SYM_DEF | NF.MACRO_BODY_ONLY | NF.NON_CORE # @@ -2848,7 +2848,7 @@ class MacroFor: loops over the macro parameter `name_list` which must be a list and binds each list element to `name` while expanding the AST nodes in `body_for`. """ - ALIAS = "$for" + ALIAS = "mfor" GROUP = GROUP.Macro FLAGS = NF.MACRO_BODY_ONLY | NF.NON_CORE # diff --git a/FrontEnd/pp.py b/FrontEnd/pp.py index 55172c3d..e1681279 100755 --- a/FrontEnd/pp.py +++ b/FrontEnd/pp.py @@ -482,7 +482,7 @@ class TK(enum.Enum): "break", "continue", "fun", "cond", "type", "if", "type", "shed", "discard", "rec", "case", "let", "let!", "set", "for", "macro", "while", "tryset", "trylet", "trap", "return", "NONE", "static_assert", - "$let", "$let!", "$for", "$for!", "swap", + "mlet", "$let!", "mfor", "$for!", "swap", ]) INDENT = 1 @@ -788,7 +788,7 @@ def TokensStmtLet(ts: TS, kind, name: str, type_or_auto, init_or_auto): def TokensMacroFor(ts: TS, node: cwast.MacroFor): - beg_for = ts.EmitBeg("$for") + beg_for = ts.EmitBeg("mfor") ts.EmitAttr(node.name) ts.EmitAttr(node.name_list) beg_colon = ts.EmitBegColon() @@ -1029,7 +1029,7 @@ def TokensExprIndex(ts: TS, node: cwast.ExprIndex): # cwast.MacroId: TokensMacroId, cwast.MacroInvoke: TokensMacroInvoke, - cwast.MacroVar: lambda ts, n: TokensStmtLet(ts, WithMut("$let", n.mut), n.name, n.type_or_auto, n.initial_or_undef_or_auto), + cwast.MacroVar: lambda ts, n: TokensStmtLet(ts, WithMut("mlet", n.mut), n.name, n.type_or_auto, n.initial_or_undef_or_auto), cwast.MacroFor: TokensMacroFor, # cwast.TypeAuto: lambda ts, n: ts.EmitAttr("auto"),