Skip to content

Commit

Permalink
It works but doesn't
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljharvey committed Aug 10, 2024
1 parent 2513f12 commit 646cd57
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions wasm-calc11/src/Calc/Ability/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ abilityExpr (EBox ann a) = do
-- we'll need to account for other allocations in future
tell (S.singleton $ AllocateMemory ann)
EBox ann <$> abilityExpr a
abilityExpr (EConstructor ann constructor as) = do
tell (S.singleton $ AllocateMemory ann)
EConstructor ann constructor <$> traverse abilityExpr as
abilityExpr (EApply ann fn args) = do
isImport <- asks (S.member fn . aeImportNames)
if isImport
Expand Down
3 changes: 3 additions & 0 deletions wasm-calc11/test/Test/Ability/AbilitySpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ spec = do
( "test box = { Box(1) }",
emptyModuleAbilities {maTests = M.singleton "box" (S.singleton (AllocateMemory ()))}
),
( "function main() -> Int32 { let _ = Just(1); 100 }",
emptyModuleAbilities { maFunctions = M.singleton "main" (S.singleton (AllocateMemory ())) }
),
( "import console.log as consoleLog(number: Int64) -> Void",
emptyModuleAbilities {maFunctions = mempty}
),
Expand Down
9 changes: 5 additions & 4 deletions wasm-calc11/test/Test/Wasm/WasmSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

module Test.Wasm.WasmSpec (spec) where

import Debug.Trace
import Calc.Dependencies
import Calc.Linearity (validateModule)
import Calc.Module
Expand Down Expand Up @@ -72,7 +73,7 @@ spec = do
describe "Test with interpreter" $ do
let asTest str = "export function test() -> Int64 { " <> str <> " }"
let testVals =
[ (asTest "42", Wasm.VI64 42),
[ {-(asTest "42", Wasm.VI64 42),
(asTest "(1 + 1)", Wasm.VI64 2),
(asTest "1 + 2 + 3 + 4 + 5 + 6", Wasm.VI64 21),
(asTest "6 * 6", Wasm.VI64 36),
Expand Down Expand Up @@ -370,7 +371,7 @@ spec = do
"}"
],
Wasm.VI64 202
),
), -}
( joinLines
[ "type Maybe<a> = Just(a) | Nothing",
asTest "let boxA: Box(Int64) = Box(100); case Just(boxA) { Just(Box(a)) -> a + 1, Nothing -> 0 }"
Expand All @@ -392,7 +393,7 @@ spec = do
)-}
]

fdescribe "From expressions" $ do
describe "From expressions" $ do
traverse_ testWithInterpreter testVals

describe "Deallocations for expressions" $ do
Expand Down Expand Up @@ -460,7 +461,7 @@ compile input =
case FromExpr.fromModule typedMod of
Left e -> error (show e)
Right wasmMod ->
ToWasm.moduleToWasm (addAllocCount wasmMod)
ToWasm.moduleToWasm (addAllocCount (traceShowId wasmMod))

-- add a `alloccount` function that returns state of allocator
addAllocCount :: ToWasm.WasmModule -> ToWasm.WasmModule
Expand Down

0 comments on commit 646cd57

Please sign in to comment.