Skip to content

Commit

Permalink
switch syntax for mod and indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmuth committed Feb 3, 2024
1 parent 91eb3ee commit 496422c
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 20 deletions.
8 changes: 4 additions & 4 deletions FrontEnd/LangTest/expr_sint_test.cw
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
(test::AssertEq# (* a b) 0xeb11e7f570b88d78_s64)
@doc """
(test::AssertEq# (/ a b) 0x7_u64)
(test::AssertEq# (mod a b) 0x7f6e5d907f6e5d9_u64) """
(test::AssertEq# (% a b) 0x7f6e5d907f6e5d9_u64) """
@doc ""
(test::AssertEq# (<< a 0) 0x8765432187654321_s64)
(test::AssertEq# (<< a 32) 0x8765432100000000_s64)
Expand Down Expand Up @@ -53,7 +53,7 @@
(test::AssertEq# (* a b) 0x70b88d78_s32)
@doc """
(test::AssertEq# (/ a b) 0x7_s32)
(test::AssertEq# (mod a b) 0x7f6e5d9_s32) """
(test::AssertEq# (% a b) 0x7f6e5d9_s32) """
@doc ""
(test::AssertEq# (! a) 0x789abcde_s32)
(test::AssertEq# (~ a) 0x789abcdf_s32)
Expand Down Expand Up @@ -92,7 +92,7 @@
@doc """
(test::AssertEq# (* a b) 0xf4b4_s16)
(test::AssertEq# (/ a b) 0x3_s16)
(test::AssertEq# (mod a b) 0xc85_s16)
(test::AssertEq# (% a b) 0xc85_s16)
@doc ""
(test::AssertEq# (! a) 0xbcde_s16)
(test::AssertEq# (~ a) 0xbcdf_s16) """
Expand Down Expand Up @@ -131,7 +131,7 @@
@doc """ needs backend fixes (test::AssertEq# (* a b) 0x48_s8) """
@doc """
(test::AssertEq# (/ a b) 0x1_s8)
(test::AssertEq# (mod a b) 0xf_s8) """
(test::AssertEq# (% a b) 0xf_s8) """
@doc ""
(test::AssertEq# (! a) 0x78_s8)
(test::AssertEq# (~ a) 0x79_s8)
Expand Down
8 changes: 4 additions & 4 deletions FrontEnd/LangTest/expr_uint_test.cw
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
(test::AssertEq# (xor a b) 0x9551155995511559_u64)
(test::AssertEq# (* a b) 0xeb11e7f570b88d78_u64)
(test::AssertEq# (/ a b) 0x7_u64)
(test::AssertEq# (mod a b) 0x7f6e5d907f6e5d9_u64)
(test::AssertEq# (% a b) 0x7f6e5d907f6e5d9_u64)
@doc ""
(test::AssertEq# (<< a 0) 0x8765432187654321_u64)
(test::AssertEq# (<< a 32) 0x8765432100000000_u64)
Expand Down Expand Up @@ -47,7 +47,7 @@
(test::AssertEq# (xor a b) 0x95511559_u32)
(test::AssertEq# (* a b) 0x70b88d78_u32)
(test::AssertEq# (/ a b) 0x7_u32)
(test::AssertEq# (mod a b) 0x7f6e5d9_u32)
(test::AssertEq# (% a b) 0x7f6e5d9_u32)
@doc ""
(test::AssertEq# (! a) 0x789abcde_u32)
(test::AssertEq# (~ a) 0x789abcdf_u32)
Expand Down Expand Up @@ -85,7 +85,7 @@
(test::AssertEq# (xor a b) 0x5115_u16)
(test::AssertEq# (* a b) 0xf4b4_u16)
(test::AssertEq# (/ a b) 0x3_u16)
(test::AssertEq# (mod a b) 0xc85_u16)
(test::AssertEq# (% a b) 0xc85_u16)
@doc ""
(test::AssertEq# (! a) 0xbcde_u16)
(test::AssertEq# (~ a) 0xbcdf_u16)
Expand Down Expand Up @@ -123,7 +123,7 @@
(test::AssertEq# (xor a b) 0xff_u8)
@doc """ needs backend fixes (test::AssertEq# (* a b) 0x48_u8) """
(test::AssertEq# (/ a b) 0x1_u8)
(test::AssertEq# (mod a b) 0xf_u8)
(test::AssertEq# (% a b) 0xf_u8)
@doc ""
(test::AssertEq# (! a) 0x78_u8)
(test::AssertEq# (~ a) 0x79_u8)
Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/Lib/fmt.cw
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
($let $out_eval auto $out)
(block _ :
(-= $pos 1)
(let c auto (mod $v $base))
(let c auto (% $v $base))
(let! c8 auto (as c u8))
(+= c8 (? (<= c8 9) '0' (- 'a' 10)))
(= (at $tmp $pos) c8)
Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/Lib/random.cw
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


@pub (fun get_random [(param max r64)] r64 :
(= LAST (mod (+ (* LAST IA) IC) IM))
(= LAST (% (+ (* LAST IA) IC) IM))
(return (/ (* max (as LAST r64)) (as IM r64))))


Expand Down
4 changes: 2 additions & 2 deletions FrontEnd/Lib/sha3.cw
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ https://emn178.github.io/online-tools/sha3_512.html
@doc """(fmt::print# "KeccakAdd: " (-> state msglen) " " data "\n")"""
(let tail_u8 auto (as (front! tail) (ptr! u8)))
(let block_size uint (* (len tail) 8))
(let tail_use uint (mod (-> state msglen) block_size))
(let tail_use uint (% (-> state msglen) block_size))

(let! offset uint 0)
(if (> tail_use 0) :
Expand Down Expand Up @@ -222,7 +222,7 @@ https://emn178.github.io/online-tools/sha3_512.html
(let tail_u8 auto (as (front! tail) (ptr! u8)))
(let block_size auto (* (len tail) 8))

(let padding_start uint (mod (-> state msglen) block_size))
(let padding_start uint (% (-> state msglen) block_size))
(for i padding_start block_size 1 :
(= (^ (pinc tail_u8 i)) 0))
(or= (^ (pinc tail_u8 padding_start)) padding)
Expand Down
6 changes: 3 additions & 3 deletions FrontEnd/TestData/comment.cw
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
@doc "cond"
(cond :
@doc "in block"
(case (== (mod argc 15) 0) :
(case (== (% argc 15) 0) :
@doc "in block"
(return 1))
@doc "in another block2"
(case (== (mod argc 3) 0) :
(case (== (% argc 3) 0) :
(return 2))
(case (== (mod argc 5) 0) :
(case (== (% argc 5) 0) :
(return 3))
(case true :
(return 4)))
Expand Down
6 changes: 3 additions & 3 deletions FrontEnd/TestData/fizzbuzz.cw
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
@cdecl (fun main [(param argc s32) (param argv (ptr (ptr u8)))] s32 :
(for i 0 31_uint 1 :
(cond :
(case (== (mod i 15) 0) :
(case (== (% i 15) 0) :
(fmt::print# FIZZBUZZ))
(case (== (mod i 3) 0) :
(case (== (% i 3) 0) :
(fmt::print# FIZZ))
(case (== (mod i 5) 0) :
(case (== (% i 5) 0) :
(fmt::print# BUZZ))
(case true :
(fmt::print# i)))
Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/cwast.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class BINARY_EXPR_KIND(enum.Enum):
"-": BINARY_EXPR_KIND.SUB,
"*": BINARY_EXPR_KIND.MUL,
"/": BINARY_EXPR_KIND.DIV,
"mod": BINARY_EXPR_KIND.MOD,
"%": BINARY_EXPR_KIND.MOD,
"max": BINARY_EXPR_KIND.MAX,
"min": BINARY_EXPR_KIND.MIN,
#
Expand Down
8 changes: 7 additions & 1 deletion FrontEnd/pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,12 @@ def TokensMacroId(ts: TS, node: cwast.MacroId):
else:
ts.EmitAttr(node.name)

def TokensExprIndex(ts: TS, node: cwast.ExprIndex):
EmitTokens(ts, node.container)
beg_paren = ts.EmitBegParen("[")
EmitTokens(ts, node.expr_index)
ts.EmitEnd(beg_paren)


_INFIX_OPS = set([
cwast.ExprIs,
Expand Down Expand Up @@ -1023,7 +1029,7 @@ def TokensMacroId(ts: TS, node: cwast.MacroId):
ts, cwast.POINTER_EXPR_SHORTCUT_INV[n.pointer_expr_kind],
[n.expr1, n.expr2] if isinstance(n.expr_bound_or_undef, cwast.ValUndef) else
[n.expr1, n.expr2, n.expr_bound_or_undef]),
cwast.ExprIndex: lambda ts, n: TokensBinaryInfix(ts, "at", n.container, n.expr_index, n),
cwast.ExprIndex: TokensExprIndex,
cwast.ValSlice: lambda ts, n: TokensFunctional(ts, "slice", [n.pointer, n.expr_size]),
cwast.ExprWrap: lambda ts, n: TokensFunctional(ts, "wrapas", [n.expr, n.type]),
cwast.ExprUnwrap: lambda ts, n: TokensFunctional(ts, "unwrap", n.expr),
Expand Down

0 comments on commit 496422c

Please sign in to comment.