Skip to content

Commit

Permalink
Fix params index
Browse files Browse the repository at this point in the history
  • Loading branch information
Saverio976 committed Jan 10, 2024
1 parent 1e7a2d7 commit 323b37c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lvtc/src/WatLikeToWat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ paramsToTypes ((_, t):vars) = typeStringToType t : paramsToTypes vars

nameIsInParams :: String -> [Var] -> Bool
nameIsInParams _ [] = False
nameIsInParams name ((_, name'):xs)
nameIsInParams name ((name', _):xs)
| name == name' = True
| otherwise = nameIsInParams name xs

findTypeFromInstructions :: String -> [Instruction] -> WatAST.Type
findTypeFromInstructions _ [] = error "Type not found"
findTypeFromInstructions name [] = error ("Type not found for: " ++ name)
findTypeFromInstructions name ((Declaration ((name', typ), _)):xs)
| name == name' = typeStringToType typ
| otherwise = findTypeFromInstructions name xs
Expand Down
62 changes: 60 additions & 2 deletions lvtc/test/UTWat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ utWat = testGroup "Wat"
assertEqual "Basic"
basic1_rep
(watsLikeToWat basic1)
, testCase "basic2" $
assertEqual "Basic2"
basic2_rep
(watsLikeToWat basic2)
]
where
basic1 = builtinsWatLike ++ [
basic1 =
builtinsWatLike ++
[
(
(
("10", [], "Int"),
Expand All @@ -40,11 +46,63 @@ utWat = testGroup "Wat"
[(0, "_tmpValue")]
)
]
basic1_rep = getBuiltinsWat ++ [
basic1_rep =
getBuiltinsWat ++
[
FuncDef 10 [] I32 [
I32Const 97,
LocalSet 0,
LocalGet 0,
WatAST.Return
] [(I32, 1)]
]
basic2 =
builtinsWatLike ++
[
(
(
("10", [("0", "Int"), ("1", "Int")], "Int"),
[
Declaration (("2", "Int"), FuncValue ("0", [Var "0", Var "1"])),
AST.Return (Var "2")
]
),
[(0, "a"), (1, "b"), (2, "_tmpValue")]
),
(
(
("11", [], "Int"),
[
Declaration (("0", "Int"), Integer 1),
Declaration (("1", "Int"), Integer 2),
Declaration (("2", "Int"), FuncValue ("10", [Var "0", Var "1"])),
AST.Return (Var "2")
]
),
[(0, "_tmpValue"), (1, "_tmpValue"), (2, "_tmpValue")]
)
]
basic2_rep =
getBuiltinsWat ++
[
FuncDef 10 [I32, I32] I32 [
LocalGet 0,
LocalGet 1,
Call 0,
LocalSet 2,
LocalGet 2,
WatAST.Return
] [(I32, 1)],
FuncDef 11 [] I32 [
I32Const 1,
LocalSet 0,
I32Const 2,
LocalSet 1,
LocalGet 0,
LocalGet 1,
Call 10,
LocalSet 2,
LocalGet 2,
WatAST.Return
] [(I32, 3)]
]

0 comments on commit 323b37c

Please sign in to comment.