@@ -19,27 +19,27 @@ testCodeGenLoops = TestList
1919 Right code -> any (\ instr -> case instr of IJumpIfFalse _ -> True ; _ -> False ) (Vector. toList $ coInstrs code)
2020 Left _ -> False
2121 ~? " Should generate IJumpIfFalse for while"
22-
22+
2323 , " gen while with jump back" ~: case generateCode " test" (EWhile (EBool True ) (EInt 1 )) of
2424 Right code -> any (\ instr -> case instr of IJump _ -> True ; _ -> False ) (Vector. toList $ coInstrs code)
2525 Left _ -> False
2626 ~? " Should generate IJump back to loop start"
27-
27+
2828 , " gen for loop" ~: case generateCode " test" (EFor " i" (EInt 0 ) (EInt 10 ) (EInt 1 )) of
2929 Right code -> any (\ instr -> case instr of IStore _ -> True ; _ -> False ) (Vector. toList $ coInstrs code)
3030 Left _ -> False
3131 ~? " Should generate IStore for iterator"
32-
32+
3333 , " gen for with condition" ~: case generateCode " test" (EFor " i" (EInt 0 ) (EInt 10 ) (EVar " i" )) of
3434 Right code -> any (\ instr -> case instr of IPrim " <=" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
3535 Left _ -> False
3636 ~? " Should generate <= comparison for for loop"
37-
37+
3838 , " gen for with increment" ~: case generateCode " test" (EFor " i" (EInt 0 ) (EInt 10 ) (EInt 1 )) of
3939 Right code -> any (\ instr -> case instr of IPrim " +" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
4040 Left _ -> False
4141 ~? " Should generate + for increment"
42-
42+
4343 , " gen range" ~: case generateCode " test" (ERange (EInt 0 ) (EInt 10 )) of
4444 Right code -> any (\ instr -> case instr of IRangeCreate -> True ; _ -> False ) (Vector. toList $ coInstrs code)
4545 Left _ -> False
@@ -56,87 +56,87 @@ testCodeGenOperators = TestList
5656 Right code -> any (\ instr -> case instr of IPrim " +" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
5757 Left _ -> False
5858 ~? " Should generate IPrim + for Add"
59-
59+
6060 , " gen BinOp Sub" ~: case generateCode " test" (EBinOp Sub (EInt 5 ) (EInt 3 )) of
6161 Right code -> any (\ instr -> case instr of IPrim " -" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
6262 Left _ -> False
6363 ~? " Should generate IPrim - for Sub"
64-
64+
6565 , " gen BinOp Mul" ~: case generateCode " test" (EBinOp Mul (EInt 3 ) (EInt 4 )) of
6666 Right code -> any (\ instr -> case instr of IPrim " *" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
6767 Left _ -> False
6868 ~? " Should generate IPrim * for Mul"
69-
69+
7070 , " gen BinOp Div" ~: case generateCode " test" (EBinOp Div (EInt 10 ) (EInt 2 )) of
7171 Right code -> any (\ instr -> case instr of IPrim " div" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
7272 Left _ -> False
7373 ~? " Should generate IPrim div for Div"
74-
74+
7575 , " gen BinOp Mod" ~: case generateCode " test" (EBinOp Mod (EInt 10 ) (EInt 3 )) of
7676 Right code -> any (\ instr -> case instr of IPrim " mod" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
7777 Left _ -> False
7878 ~? " Should generate IPrim mod for Mod"
79-
79+
8080 , " gen BinOp Lt" ~: case generateCode " test" (EBinOp Lt (EInt 1 ) (EInt 2 )) of
8181 Right code -> any (\ instr -> case instr of IPrim " <" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
8282 Left _ -> False
8383 ~? " Should generate IPrim < for Lt"
84-
84+
8585 , " gen BinOp Lte" ~: case generateCode " test" (EBinOp Lte (EInt 1 ) (EInt 2 )) of
8686 Right code -> any (\ instr -> case instr of IPrim " <=" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
8787 Left _ -> False
8888 ~? " Should generate IPrim <= for Lte"
89-
89+
9090 , " gen BinOp Gt" ~: case generateCode " test" (EBinOp Gt (EInt 2 ) (EInt 1 )) of
9191 Right code -> any (\ instr -> case instr of IPrim " >" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
9292 Left _ -> False
9393 ~? " Should generate IPrim > for Gt"
94-
94+
9595 , " gen BinOp Gte" ~: case generateCode " test" (EBinOp Gte (EInt 2 ) (EInt 1 )) of
9696 Right code -> any (\ instr -> case instr of IPrim " >=" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
9797 Left _ -> False
9898 ~? " Should generate IPrim >= for Gte"
99-
99+
100100 , " gen BinOp Eq" ~: case generateCode " test" (EBinOp Eq (EInt 1 ) (EInt 1 )) of
101101 Right code -> any (\ instr -> case instr of IPrim " eq?" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
102102 Left _ -> False
103103 ~? " Should generate IPrim eq? for Eq"
104-
104+
105105 , " gen BinOp Neq" ~: case generateCode " test" (EBinOp Neq (EInt 1 ) (EInt 2 )) of
106106 Right code -> any (\ instr -> case instr of IPrim " not" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
107107 Left _ -> False
108108 ~? " Should generate IPrim not for Neq"
109-
109+
110110 , " gen BinOp And" ~: case generateCode " test" (EBinOp And (EBool True ) (EBool False )) of
111111 Right code -> any (\ instr -> case instr of IPrim " and" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
112112 Left _ -> False
113113 ~? " Should generate IPrim and for And"
114-
114+
115115 , " gen BinOp Or" ~: case generateCode " test" (EBinOp Or (EBool True ) (EBool False )) of
116116 Right code -> any (\ instr -> case instr of IPrim " or" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
117117 Left _ -> False
118118 ~? " Should generate IPrim or for Or"
119-
119+
120120 , " gen BinOp Concat" ~: case generateCode " test" (EBinOp Concat (EString " hello" ) (EString " world" )) of
121121 Right code -> any (\ instr -> case instr of IPrim " string-append" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
122122 Left _ -> False
123123 ~? " Should generate IPrim string-append for Concat"
124-
124+
125125 , " gen UnOp Not" ~: case generateCode " test" (EUnOp Not (EBool True )) of
126126 Right code -> any (\ instr -> case instr of IPrim " not" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
127127 Left _ -> False
128128 ~? " Should generate IPrim not for Not"
129-
129+
130130 , " gen UnOp Neg" ~: case generateCode " test" (EUnOp Neg (EInt 5 )) of
131131 Right code -> any (\ instr -> case instr of IPrim " -" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
132132 Left _ -> False
133133 ~? " Should generate IPrim - for Neg"
134-
134+
135135 , " gen complex nested operators" ~: case generateCode " test" (EBinOp Add (EBinOp Mul (EInt 2 ) (EInt 3 )) (EInt 4 )) of
136136 Right code -> length (filter (\ instr -> case instr of IPrim _ -> True ; _ -> False ) (Vector. toList $ coInstrs code)) >= 2
137137 Left _ -> False
138138 ~? " Should handle nested operators"
139-
139+
140140 , " gen modulo for isEven check" ~: case generateCode " test" (EBinOp Eq (EBinOp Mod (EVar " n" ) (EInt 2 )) (EInt 0 )) of
141141 Right code -> any (\ instr -> case instr of IPrim " mod" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
142142 Left _ -> False
@@ -153,27 +153,22 @@ testCodeGenTuples = TestList
153153 Right code -> any (\ instr -> case instr of ITupleCreate 0 -> True ; _ -> False ) (Vector. toList $ coInstrs code)
154154 Left _ -> False
155155 ~? " Should generate ITupleCreate 0"
156-
156+
157157 , " gen ETuple with elements" ~: case generateCode " test" (ETuple [EInt 1 , EInt 2 , EInt 3 ]) of
158158 Right code -> any (\ instr -> case instr of ITupleCreate 3 -> True ; _ -> False ) (Vector. toList $ coInstrs code)
159159 Left _ -> False
160160 ~? " Should generate ITupleCreate 3"
161-
161+
162162 , " gen ETupleDestruct" ~: case generateCode " test" (ETupleDestruct [" x" , " y" ] (ETuple [EInt 1 , EInt 2 ]) (EVar " x" )) of
163163 Right code -> any (\ instr -> case instr of ITupleGet 0 -> True ; _ -> False ) (Vector. toList $ coInstrs code)
164164 Left _ -> False
165165 ~? " Should generate ITupleGet for destructuring"
166-
167- , " gen EIndex with int" ~: case generateCode " test" (EIndex (ETuple [EInt 1 , EInt 2 ]) (EInt 0 )) of
168- Right code -> any (\ instr -> case instr of ITupleGet 0 -> True ; _ -> False ) (Vector. toList $ coInstrs code)
169- Left _ -> False
170- ~? " Should generate ITupleGet with index"
171-
166+
172167 , " gen nested tuple" ~: case generateCode " test" (ETuple [ETuple [EInt 1 , EInt 2 ], EInt 3 ]) of
173168 Right code -> length (filter (\ instr -> case instr of ITupleCreate _ -> True ; _ -> False ) (Vector. toList $ coInstrs code)) >= 2
174169 Left _ -> False
175170 ~? " Should generate multiple ITupleCreate"
176-
171+
177172 , " gen ETupleDestruct with IStore" ~: case generateCode " test" (ETupleDestruct [" x" , " y" , " z" ] (ETuple [EInt 1 , EInt 2 , EInt 3 ]) (EVar " x" )) of
178173 Right code -> length (filter (\ instr -> case instr of IStore _ -> True ; _ -> False ) (Vector. toList $ coInstrs code)) >= 3
179174 Left _ -> False
@@ -190,22 +185,22 @@ testCodeGenNativeLists = TestList
190185 Right code -> any (\ instr -> case instr of IListCreate 0 -> True ; _ -> False ) (Vector. toList $ coInstrs code)
191186 Left _ -> False
192187 ~? " Should generate IListCreate 0"
193-
188+
194189 , " gen EListLiteral with elements" ~: case generateCode " test" (EListLiteral [EInt 1 , EInt 2 , EInt 3 ] Nothing ) of
195190 Right code -> any (\ instr -> case instr of IListCreate 3 -> True ; _ -> False ) (Vector. toList $ coInstrs code)
196191 Left _ -> False
197192 ~? " Should generate IListCreate 3"
198-
193+
199194 , " gen EListLiteral typed" ~: case generateCode " test" (EListLiteral [EInt 1 , EInt 2 ] (Just TInt )) of
200195 Right code -> any (\ instr -> case instr of IListCreate 2 -> True ; _ -> False ) (Vector. toList $ coInstrs code)
201196 Left _ -> False
202197 ~? " Should generate IListCreate with type"
203-
198+
204199 , " gen EIndex dynamic" ~: case generateCode " test" (EIndex (EListLiteral [EInt 1 , EInt 2 ] Nothing ) (EVar " i" )) of
205200 Right code -> any (\ instr -> case instr of IListGet -> True ; _ -> False ) (Vector. toList $ coInstrs code)
206201 Left _ -> False
207202 ~? " Should generate IListGet"
208-
203+
209204 , " gen nested list" ~: case generateCode " test" (EListLiteral [EListLiteral [EInt 1 ] Nothing , EListLiteral [EInt 2 ] Nothing ] Nothing ) of
210205 Right code -> length (filter (\ instr -> case instr of IListCreate _ -> True ; _ -> False ) (Vector. toList $ coInstrs code)) >= 2
211206 Left _ -> False
@@ -222,7 +217,7 @@ testCodeGenObjects = TestList
222217 Right code -> Vector. length (coInstrs code) > 0
223218 Left _ -> False
224219 ~? " Should generate code for object declaration"
225-
220+
226221 , " gen EObjectInst" ~: case generateCode " test" (EObjectInst " Person" [(" name" , EString " Alice" )]) of
227222 Right code -> any (\ instr -> case instr of IObjectCreate " Person" [" name" ] -> True ; _ -> False ) (Vector. toList $ coInstrs code)
228223 Left _ -> False
@@ -232,12 +227,12 @@ testCodeGenObjects = TestList
232227 Right code -> any (\ instr -> case instr of IObjectCreate " Point" [" x" , " y" ] -> True ; _ -> False ) (Vector. toList $ coInstrs code)
233228 Left _ -> False
234229 ~? " Should generate IObjectCreate with fields"
235-
230+
236231 , " gen EMemberAccess" ~: case generateCode " test" (EMemberAccess (EVar " obj" ) " name" ) of
237232 Right code -> any (\ instr -> case instr of IMemberGet " name" -> True ; _ -> False ) (Vector. toList $ coInstrs code)
238233 Left _ -> False
239234 ~? " Should generate IMemberGet"
240-
235+
241236 , " gen nested member access" ~: case generateCode " test" (EMemberAccess (EMemberAccess (EVar " obj" ) " field1" ) " field2" ) of
242237 Right code -> length (filter (\ instr -> case instr of IMemberGet _ -> True ; _ -> False ) (Vector. toList $ coInstrs code)) >= 2
243238 Left _ -> False
@@ -254,17 +249,17 @@ testCodeGenAssignment = TestList
254249 Right code -> any (\ instr -> case instr of IAssign _ -> True ; _ -> False ) (Vector. toList $ coInstrs code)
255250 Left _ -> False
256251 ~? " Should generate IAssign"
257-
252+
258253 , " gen EAssign with expression" ~: case generateCode " test" (EList [EDefine " x" (EInt 1 ) [] , EAssign " x" (EBinOp Add (EInt 2 ) (EInt 3 ))]) of
259254 Right code -> any (\ instr -> case instr of IAssign _ -> True ; _ -> False ) (Vector. toList $ coInstrs code)
260255 Left _ -> False
261256 ~? " Should compile expression before assign"
262-
257+
263258 , " gen multiple assignments" ~: case generateCode " test" (EList [EDefine " x" (EInt 1 ) [] , EAssign " x" (EInt 2 ), EAssign " x" (EInt 3 )]) of
264259 Right code -> length (filter (\ instr -> case instr of IAssign _ -> True ; _ -> False ) (Vector. toList $ coInstrs code)) >= 2
265260 Left _ -> False
266261 ~? " Should generate multiple IAssign"
267-
262+
268263 , " gen assignment pushes value back" ~: case generateCode " test" (EList [EDefine " x" (EInt 1 ) [] , EAssign " x" (EInt 2 )]) of
269264 Right code -> any (\ instr -> case instr of ILoad _ -> True ; _ -> False ) (Vector. toList $ coInstrs code)
270265 Left _ -> False
@@ -281,12 +276,12 @@ testCodeGenReturn = TestList
281276 Right code -> any (\ instr -> case instr of IReturn -> True ; _ -> False ) (Vector. toList $ coInstrs code)
282277 Left _ -> False
283278 ~? " Should generate IReturn"
284-
279+
285280 , " gen EReturn with expression" ~: case generateCode " test" (EReturn (EBinOp Add (EInt 1 ) (EInt 2 ))) of
286281 Right code -> any (\ instr -> case instr of IReturn -> True ; _ -> False ) (Vector. toList $ coInstrs code)
287282 Left _ -> False
288283 ~? " Should compile expression before return"
289-
284+
290285 , " gen EReturn in lambda" ~: case generateCodeWithDefs " test" (EDefine " f" (ELambda [(" x" , Nothing )] Nothing (EReturn (EVar " x" )) [] ) [] ) of
291286 (Right _, codeObjs) -> case Map. lookup " f" codeObjs of
292287 Just code -> length (filter (\ instr -> case instr of IReturn -> True ; _ -> False ) (Vector. toList $ coInstrs code)) >= 2
@@ -305,31 +300,26 @@ testCodeGenEdgeCases = TestList
305300 Right code -> Vector. length (coInstrs code) > 0
306301 Left _ -> False
307302 ~? " Should generate code for package (no-op)"
308-
303+
309304 , " gen EImport" ~: case generateCode " test" (EImport " SomeModule" ) of
310305 Right code -> Vector. length (coInstrs code) > 0
311306 Left _ -> False
312307 ~? " Should generate code for import (no-op)"
313-
308+
314309 , " gen while loop with unit result" ~: case generateCode " test" (EWhile (EBool False ) (EInt 1 )) of
315310 Right code -> any (\ instr -> case instr of IConst _ -> True ; _ -> False ) (Vector. toList $ coInstrs code)
316311 Left _ -> False
317312 ~? " While should push unit value as result"
318-
313+
319314 , " gen for loop with unit result" ~: case generateCode " test" (EFor " i" (EInt 0 ) (EInt 5 ) (EInt 1 )) of
320315 Right code -> length (filter (\ instr -> case instr of IConst _ -> True ; _ -> False ) (Vector. toList $ coInstrs code)) >= 2
321316 Left _ -> False
322317 ~? " For should push unit value as result"
323-
318+
324319 , " gen EObjectInst field order" ~: case generateCode " test" (EObjectInst " Point" [(" x" , EInt 10 ), (" y" , EInt 20 )]) of
325320 Right code -> any (\ instr -> case instr of IObjectCreate " Point" [" x" , " y" ] -> True ; _ -> False ) (Vector. toList $ coInstrs code)
326321 Left _ -> False
327322 ~? " Should compile field values in order before IObjectCreate"
328-
329- , " gen EIndex tuple vs list disambiguation" ~: case generateCode " test" (EIndex (EVar " collection" ) (EInt 5 )) of
330- Right code -> any (\ instr -> case instr of ITupleGet 5 -> True ; _ -> False ) (Vector. toList $ coInstrs code)
331- Left _ -> False
332- ~? " Should use ITupleGet for constant integer index"
333323 ]
334324
335325tests :: Test
0 commit comments