Skip to content

Commit

Permalink
more @mut simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmuth committed Jan 30, 2024
1 parent ac654c6 commit dfac2bf
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 79 deletions.
36 changes: 18 additions & 18 deletions FrontEnd/Lib/huffman_test.cw
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ D = 100
]))

(fun test_tree0_decoding [] void :
(let @mut counts (array 4 u16))
(let @mut symbols (array 4 u16))
(let! counts (array 4 u16))
(let! symbols (array 4 u16))
(test::AssertEq#
(huffman::ComputeCountsAndSymbolsFromLengths [Tree0Length counts symbols])
4_u16)
Expand Down Expand Up @@ -130,8 +130,8 @@ D = 100
]))

(fun test_tree1_decoding [] void :
(let @mut counts (array 7 u16))
(let @mut symbols (array 11 u16))
(let! counts (array 7 u16))
(let! symbols (array 11 u16))

(test::AssertEq#
(huffman::ComputeCountsAndSymbolsFromLengths [Tree1Length counts symbols])
Expand All @@ -142,8 +142,8 @@ D = 100
)

(fun test_tree1_bitstream_decoding [] void :
(let @mut counts (array 7 u16))
(let @mut symbols (array 11 u16))
(let! counts (array 7 u16))
(let! symbols (array 11 u16))

(test::AssertEq#
(huffman::ComputeCountsAndSymbolsFromLengths [Tree1Length counts symbols])
Expand All @@ -159,23 +159,23 @@ D = 100
0
0
]))
(let @mut @ref bs auto (rec_val bitstream::Stream32 [(field_val data)]))
(test::AssertEq# 5_u16 (huffman::NextSymbol [(& @mut bs) counts symbols]))
(test::AssertEq# 10_u16 (huffman::NextSymbol [(& @mut bs) counts symbols]))
(test::AssertEq# 7_u16 (huffman::NextSymbol [(& @mut bs) counts symbols]))
(test::AssertEq# 7_u16 (huffman::NextSymbol [(& @mut bs) counts symbols]))
(test::AssertEq# 8_u16 (huffman::NextSymbol [(& @mut bs) counts symbols]))
(let! @ref bs auto (rec_val bitstream::Stream32 [(field_val data)]))
(test::AssertEq# 5_u16 (huffman::NextSymbol [(&! bs) counts symbols]))
(test::AssertEq# 10_u16 (huffman::NextSymbol [(&! bs) counts symbols]))
(test::AssertEq# 7_u16 (huffman::NextSymbol [(&! bs) counts symbols]))
(test::AssertEq# 7_u16 (huffman::NextSymbol [(&! bs) counts symbols]))
(test::AssertEq# 8_u16 (huffman::NextSymbol [(&! bs) counts symbols]))

)

(fun test_helper [] void :
(let @mut lengths (array 285 u16))
(let! lengths (array 285 u16))
(= (at lengths 0) 1)
(= (at lengths 256) 2)
(= (at lengths 284) 2)

(let @mut counts (array 8 u16))
(let @mut symbols (array 8 u16))
(let! counts (array 8 u16))
(let! symbols (array 8 u16))
(test::AssertEq#
(huffman::ComputeCountsAndSymbolsFromLengths [lengths counts symbols])
3_u16)
Expand All @@ -189,11 +189,11 @@ D = 100
)

(fun test_helper_single_code [] void :
(let @mut lengths (array 285 u16))
(let! lengths (array 285 u16))
(= (at lengths 66) 1)

(let @mut counts (array 8 u16))
(let @mut symbols (array 8 u16))
(let! counts (array 8 u16))
(let! symbols (array 8 u16))
(test::AssertEq#
(huffman::ComputeCountsAndSymbolsFromLengths [lengths counts symbols])
2_u16)
Expand Down
24 changes: 12 additions & 12 deletions FrontEnd/TestData/ascii_anim.cw
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
(field visible bool))


(fun @pub InitObjectState [(param s (ptr @mut ObjectState)) (param o (ptr Object))] void :
(fun @pub InitObjectState [(param s (ptr! ObjectState)) (param o (ptr Object))] void :
(= (-> s obj) o)
(= (-> s attr_lookup) DEF_ATTR_LOOKUP)
(= (-> s depth) (-> o def_depth))
Expand All @@ -59,7 +59,7 @@


(fun @pub SetBasics [
(param s (ptr @mut ObjectState))
(param s (ptr! ObjectState))
(param start_time r32)
(param x_pos r32)
(param y_pos r32)] void :
Expand Down Expand Up @@ -122,7 +122,7 @@
(return ""))))


(fun @pub draw [(param window (ptr @mut Window)) (param s (ptr @mut ObjectState))] void :
(fun @pub draw [(param window (ptr! Window)) (param s (ptr! ObjectState))] void :
(let width auto (-> window width))
(let height auto (-> window height))
(let obj auto (-> s obj))
Expand All @@ -131,14 +131,14 @@
(let color_map auto (-> sprite color_map))
(let def_attr auto (-> s def_attr))
(let depth auto (-> s depth))
(let @mut x s32 (as (-> s x_pos) s32))
(let @mut y s32 (as (-> s y_pos) s32))
(let @mut left_side auto true)
(let @mut have_color auto true)
(let @mut cpos uint 0)
(let! x s32 (as (-> s x_pos) s32))
(let! y s32 (as (-> s y_pos) s32))
(let! left_side auto true)
(let! have_color auto true)
(let! cpos uint 0)
(for ipos 0 (len image_map) 1 :
@doc "determine attribute"
(let @mut a u8 def_attr)
(let! a u8 def_attr)
(if have_color :
(let cc u8 (at color_map cpos))
(+= cpos 1)
Expand Down Expand Up @@ -185,9 +185,9 @@
(let w auto (-> obj width))
(let h auto (-> obj height))
@doc "@ is an invalid attrib"
(let @mut last_attr u8 '@')
(let! last_attr u8 '@')
(for x 0 w 1 :
(let @mut last_x auto MAX_DIM)
(let! last_x auto MAX_DIM)
(for y 0 h 1 :
(let index auto (+ (* y w) x))
(let c auto (at (-> obj char_map) index))
Expand All @@ -207,7 +207,7 @@


(fun @pub window_fill [
(param obj (ptr @mut Window))
(param obj (ptr! Window))
(param c u8)
(param a u8)] void :
(let size auto (* (-> obj width) (-> obj height)))
Expand Down
26 changes: 13 additions & 13 deletions FrontEnd/TestData/ascii_artwork.cw
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ Fish body parts:
|_______|__|_|_|_|__|_______|
""") (field_val r"""
RR

yyy
y y
y y
y y



yyy
yy yy
y y y y
Expand Down Expand Up @@ -117,27 +117,27 @@ yy

(global DucksRSprites auto (array_val 3 aanim::Sprite [
(index_val (rec_val aanim::Sprite [(field_val r"""
_??????????_??????????_
_??????????_??????????_
,____(')=??,____(')=??,____(')<
\~~= ')????\~~= ')????\~~= ')
\~~= ')????\~~= ')????\~~= ')
""") (field_val r"""
g g g
wwwwwgcgy wwwwwgcgy wwwwwgcgy
wwww Ww wwww Ww wwww Ww
""")]))
(index_val (rec_val aanim::Sprite [(field_val r"""
_??????????_??????????_
_??????????_??????????_
,____(')=??,____(')<??,____(')=
\~~= ')????\~~= ')????\~~= ')
\~~= ')????\~~= ')????\~~= ')
""") (field_val r"""
g g g
wwwwwgcgy wwwwwgcgy wwwwwgcgy
wwww Ww wwww Ww wwww Ww
""")]))
(index_val (rec_val aanim::Sprite [(field_val r"""
_??????????_??????????_
_??????????_??????????_
,____(')<??,____(')=??,____(')=
\~~= ')????\~~= ')????\~~= ')
\~~= ')????\~~= ')????\~~= ')
""") (field_val r"""
g g g
wwwwwgcgy wwwwwgcgy wwwwwgcgy
Expand Down Expand Up @@ -322,7 +322,7 @@ wwwwwgcgy wwwwwgcgy wwwwwgcgy

""")]))
(index_val (rec_val aanim::Sprite [(field_val r"""
____
____
__????????????????????/ o \
_??????????????????????_???????/ \????????_???????/ ____ >
| \??????????_????????/ \????| __ |?????/ \????| |
Expand Down Expand Up @@ -401,7 +401,7 @@ y y


cR

cWWWWWWWW


Expand Down Expand Up @@ -442,7 +442,7 @@ y y


(fun @pub UpdateState [
(param s (ptr @mut aanim::ObjectState))
(param s (ptr! aanim::ObjectState))
(param t r32)
(param dt r32)] void :
(= (-> s x_pos) (+ (-> s x_pos) (* (-> s x_speed) dt)))
Expand Down
18 changes: 9 additions & 9 deletions FrontEnd/TestData/asciiquarium.cw
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
(import os)
(import fmt)

(global @mut all_objects auto (array_val 100 aanim::ObjectState))
(global! all_objects auto (array_val 100 aanim::ObjectState))


(fun @cdecl main [(param argc s32) (param argv (ptr (ptr u8)))] s32 :
Expand All @@ -20,15 +20,15 @@
(let height s32 (as (fmt::str_to_u32 [arg_h]) s32))
@doc "100ms per frame"
(let @ref req os::TimeSpec (rec_val os::TimeSpec [(field_val 0) (field_val 100000000)]))
(let @mut @ref rem os::TimeSpec undef)
(let @mut @ref window auto (rec_val aanim::Window [
(let! @ref rem os::TimeSpec undef)
(let! @ref window auto (rec_val aanim::Window [
(field_val width)
(field_val height)
(field_val undef)
(field_val undef)
(field_val undef)
]))
(let @mut curr auto (front @mut all_objects))
(let! curr auto (front! all_objects))
@doc "add obj"
(shed (aanim::InitObjectState [curr (& artwork::DuckR)]))
(shed (aanim::SetBasics [
Expand Down Expand Up @@ -104,22 +104,22 @@
(= curr (pinc curr 1))
@doc "add obj"
(fmt::print# ansi::CURSOR_HIDE)
(let @mut last_t r32 0.0)
(let! last_t r32 0.0)
(for t 0.0 5.0_r32 0.1 :
(shed (aanim::window_fill [
(& @mut window)
(&! window)
' '
' ']))
(= curr (front @mut all_objects))
(= curr (front! all_objects))
(for i 0 9_uint 1 :
(shed (aanim::draw [(& @mut window) (pinc curr i)])))
(shed (aanim::draw [(&! window) (pinc curr i)])))
(shed (aanim::window_draw [(& window) 'k']))
(for i 0 9_uint 1 :
(shed (artwork::UpdateState [
(pinc curr i)
t
(- t last_t)])))
(shed (os::nanosleep [(& req) (& @mut rem)]))
(shed (os::nanosleep [(& req) (&! rem)]))
(= last_t t))
(fmt::print# ansi::CURSOR_SHOW)
(return 0))
Expand Down
10 changes: 5 additions & 5 deletions FrontEnd/TestData/binary_tree.cw
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@


(defrec @pub BinaryTreeNode :
(field left (union [NoneType (ptr @mut BinaryTreeNode)]))
(field right (union [NoneType (ptr @mut BinaryTreeNode)]))
(field left (union [NoneType (ptr! BinaryTreeNode)]))
(field right (union [NoneType (ptr! BinaryTreeNode)]))
(field payload u32))


(type MaybeNode (union [NoneType (ptr @mut BinaryTreeNode)]))
(type MaybeNode (union [NoneType (ptr! BinaryTreeNode)]))


(type Visitor (sig [(param node (ptr @mut BinaryTreeNode))] void))
(type Visitor (sig [(param node (ptr! BinaryTreeNode))] void))


(fun InorderTraversal [(param root MaybeNode) (param visitor Visitor)] void :
(trylet node (ptr @mut BinaryTreeNode) root _ : (return))
(trylet node (ptr! BinaryTreeNode) root _ : (return))
(shed (InorderTraversal [(. (^ node) left) visitor]))
(shed (visitor [node]))
(shed (InorderTraversal [(. (^ node) right) visitor])))
Expand Down
10 changes: 5 additions & 5 deletions FrontEnd/TestData/linked_list.cw
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@


(defrec @pub LinkedListNode :
(field next (union [NoneType (ptr @mut LinkedListNode)]))
(field next (union [NoneType (ptr! LinkedListNode)]))
(field payload u32))


(type MaybeNode (union [NoneType (ptr @mut LinkedListNode)]))
(type MaybeNode (union [NoneType (ptr! LinkedListNode)]))


(fun SumPayload [(param root MaybeNode)] u32 :
(let @mut sum u32 0)
(let @mut node auto root)
(let! sum u32 0)
(let! node auto root)
(while true :
(trylet x (ptr @mut LinkedListNode) node _ : (break))
(trylet x (ptr! LinkedListNode) node _ : (break))
(+= sum (. (^ x) payload))
(= node (. (^ x) next)))
(return sum))
Expand Down
8 changes: 4 additions & 4 deletions FrontEnd/TestData/macros.cw
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


(fun TestWhileMacro [(param end u32)] u32 :
(let @mut sum u32 0)
(let! sum u32 0)
(while (< sum end) :
(+= sum 1))
(return sum))
Expand All @@ -21,7 +21,7 @@


(fun TestForMacro! [(param end u32)] u32 :
(let @mut sum u32 0)
(let! sum u32 0)
(for i 0 end 1 :
(+= sum i))
(return sum))
Expand Down Expand Up @@ -57,7 +57,7 @@


(fun TestProductMacro [] u32 :
(let @mut result u32 1)
(let! result u32 1)
(product# result [
111
(* 2 111)
Expand All @@ -72,7 +72,7 @@
(return (stringify TestForMacroStringify)))


(fun TestSwap [(param vec (slice @mut u8))] void :
(fun TestSwap [(param vec (slice! u8))] void :
(swap (at vec 1) (at vec 2)))


Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/TestData/print_argv.cw
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(import fmt)

(fun strlen [(param s (ptr u8))] uint :
(let @mut i uint 0)
(let! i uint 0)
(while (!= (^ (pinc s i)) 0) :
(+= i 1))
(return i))
Expand Down
Loading

0 comments on commit dfac2bf

Please sign in to comment.