Skip to content

Commit

Permalink
Fix drawing demo and add tests on multiple calcs
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljharvey committed Jul 19, 2024
1 parent 7a837c1 commit 7e1674b
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 12 deletions.
5 changes: 2 additions & 3 deletions wasm-calc10/src/Calc/Wasm/FromExpr/Helpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,11 @@ getAbilitiesForFunction functionAbilities fnName =

-- take only the function info we need
getFunctionMap ::
Natural ->
[Function (Type ann)] ->
Either
FromWasmError
(M.Map FunctionName FromExprFunc)
getFunctionMap offset mdFunctions =
getFunctionMap mdFunctions =
M.fromList
<$> traverse
( \(i, Function {fnFunctionName, fnGenerics, fnArgs, fnBody}) -> do
Expand All @@ -176,7 +175,7 @@ getFunctionMap offset mdFunctions =
}
)
)
(zip [offset ..] mdFunctions)
(zip [0 ..] mdFunctions)

-- take only the function info we need
getImportMap ::
Expand Down
2 changes: 1 addition & 1 deletion wasm-calc10/src/Calc/Wasm/FromExpr/Module.hs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fromModule ::
fromModule wholeMod@(Module {mdMemory, mdTests, mdGlobals, mdImports, mdFunctions}) = do
let moduleAbilities = getAbilitiesForModule wholeMod
importMap <- getImportMap mdImports
funcMap <- getFunctionMap (fromIntegral (length importMap)) mdFunctions
funcMap <- getFunctionMap mdFunctions
globalMap <- getGlobalMap mdGlobals

wasmGlobals <- traverse fromGlobal mdGlobals
Expand Down
7 changes: 7 additions & 0 deletions wasm-calc10/test/Test/Wasm/WasmSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ spec = do
],
joinLines ["42n", "42n"]
),
( joinLines
[ "import console.log as consoleLog(number: Int64) -> Void",
"function max(one: Int64, two: Int64) -> Int64 { if one > two then one else two }",
"export function test() -> Int64 { let a = max(0,25); let _ = consoleLog(a); let _ = consoleLog(a + 1); 100 }"
],
joinLines ["25n", "26n"]
),
( joinLines
[ "import env.memory as memory 1000",
"import console.log as consoleLog(number: Int64) -> Void",
Expand Down
2 changes: 1 addition & 1 deletion wasm-calc11/src/Calc/Wasm/FromExpr/Drops.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Calc.Wasm.FromExpr.Patterns (Path (..))
import Calc.Wasm.FromExpr.Types
import Calc.Wasm.ToWasm.Helpers
import Calc.Wasm.ToWasm.Types
import Control.Monad (foldM )
import Control.Monad (foldM)
import Control.Monad.Except
import Control.Monad.State
import Data.Foldable (foldl')
Expand Down
2 changes: 1 addition & 1 deletion wasm-calc11/src/Calc/Wasm/ToWasm/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ data ToWasmEnv = ToWasmEnv
tweFunctionsOffset :: Natural,
tweGeneratedFunctionOffset :: Natural
}
deriving stock (Eq,Ord,Show)
deriving stock (Eq, Ord, Show)

data WasmType
= I8
Expand Down
3 changes: 1 addition & 2 deletions wasm-calc11/test/Test/Wasm/WasmSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ spec = do
joinLines ["42n", "42n"]
),
( joinLines
[
"import console.log as consoleLog(number: Int64) -> Void",
[ "import console.log as consoleLog(number: Int64) -> Void",
"function max(one: Int64, two: Int64) -> Int64 { if one > two then one else two }",
"export function test() -> Int64 { let a = max(0,25); let _ = consoleLog(a); let _ = consoleLog(a + 1); 100 }"
],
Expand Down
7 changes: 7 additions & 0 deletions wasm-calc8/test/Test/Wasm/WasmSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ spec = do
],
joinLines ["42n", "42n"]
),
( joinLines
[ "import console.log as consoleLog(number: Int64) -> Void",
"function max(one: Int64, two: Int64) -> Int64 { if one > two then one else two }",
"export function test() -> Int64 { let a = max(0,25); let _ = consoleLog(a); let _ = consoleLog(a + 1); 100 }"
],
joinLines ["25n", "26n"]
),
( joinLines
[ "import env.memory as memory 1000",
"import console.log as consoleLog(number: Int64) -> Void",
Expand Down
5 changes: 2 additions & 3 deletions wasm-calc9/src/Calc/Wasm/FromExpr/Helpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,11 @@ getAbilitiesForFunction functionAbilities fnName =

-- take only the function info we need
getFunctionMap ::
Natural ->
[Function (Type ann)] ->
Either
FromWasmError
(M.Map FunctionName FromExprFunc)
getFunctionMap offset mdFunctions =
getFunctionMap mdFunctions =
M.fromList
<$> traverse
( \(i, Function {fnFunctionName, fnGenerics, fnArgs, fnBody}) -> do
Expand All @@ -220,7 +219,7 @@ getFunctionMap offset mdFunctions =
}
)
)
(zip [offset ..] mdFunctions)
(zip [0 ..] mdFunctions)

-- take only the function info we need
getImportMap ::
Expand Down
2 changes: 1 addition & 1 deletion wasm-calc9/src/Calc/Wasm/FromExpr/Module.hs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fromModule ::
fromModule wholeMod@(Module {mdMemory, mdTests, mdGlobals, mdImports, mdFunctions}) = do
let moduleAbilities = getAbilitiesForModule wholeMod
importMap <- getImportMap mdImports
funcMap <- getFunctionMap (fromIntegral (length importMap)) mdFunctions
funcMap <- getFunctionMap mdFunctions
globalMap <- getGlobalMap mdGlobals

wasmGlobals <- traverse fromGlobal mdGlobals
Expand Down
7 changes: 7 additions & 0 deletions wasm-calc9/test/Test/Wasm/WasmSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ spec = do
],
joinLines ["42n", "42n"]
),
( joinLines
[ "import console.log as consoleLog(number: Int64) -> Void",
"function max(one: Int64, two: Int64) -> Int64 { if one > two then one else two }",
"export function test() -> Int64 { let a = max(0,25); let _ = consoleLog(a); let _ = consoleLog(a + 1); 100 }"
],
joinLines ["25n", "26n"]
),
( joinLines
[ "import env.memory as memory 1000",
"import console.log as consoleLog(number: Int64) -> Void",
Expand Down

0 comments on commit 7e1674b

Please sign in to comment.