Skip to content

Commit

Permalink
rename -> mlet, -> mfor
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmuth committed Apr 13, 2024
1 parent 4f16781 commit ad79f78
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 40 deletions.
22 changes: 11 additions & 11 deletions FrontEnd/Lib/builtin.cw
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/Lib/flate.cw
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
)
Expand Down
24 changes: 12 additions & 12 deletions FrontEnd/Lib/fmt.cw
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/Lib/sha3.cw
Original file line number Diff line number Diff line change
Expand Up @@ -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)] [] :
Expand Down
18 changes: 9 additions & 9 deletions FrontEnd/Lib/test.cw
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
))

Expand All @@ -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))
Expand All @@ -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)))))
Expand All @@ -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))
Expand All @@ -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))))
Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/TestData/macros.cw
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@


(macro product# STMT_LIST [(mparam $result ID) (mparam $factors STMT_LIST)] [] :
($for $x $factors :
(mfor $x $factors :
(= $result (* $result $x))))


Expand Down
4 changes: 2 additions & 2 deletions FrontEnd/cwast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -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
#
Expand Down
6 changes: 3 additions & 3 deletions FrontEnd/pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit ad79f78

Please sign in to comment.