From 646cd57436554fe16f771700023385ea8dadf116 Mon Sep 17 00:00:00 2001 From: Daniel Harvey Date: Sat, 10 Aug 2024 22:32:12 +0100 Subject: [PATCH] It works but doesn't --- wasm-calc11/src/Calc/Ability/Check.hs | 3 +++ wasm-calc11/test/Test/Ability/AbilitySpec.hs | 3 +++ wasm-calc11/test/Test/Wasm/WasmSpec.hs | 9 +++++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/wasm-calc11/src/Calc/Ability/Check.hs b/wasm-calc11/src/Calc/Ability/Check.hs index 875795f6..97cfe466 100644 --- a/wasm-calc11/src/Calc/Ability/Check.hs +++ b/wasm-calc11/src/Calc/Ability/Check.hs @@ -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 diff --git a/wasm-calc11/test/Test/Ability/AbilitySpec.hs b/wasm-calc11/test/Test/Ability/AbilitySpec.hs index b03f68f1..3716ab1f 100644 --- a/wasm-calc11/test/Test/Ability/AbilitySpec.hs +++ b/wasm-calc11/test/Test/Ability/AbilitySpec.hs @@ -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} ), diff --git a/wasm-calc11/test/Test/Wasm/WasmSpec.hs b/wasm-calc11/test/Test/Wasm/WasmSpec.hs index 25d517cb..b0ce5198 100644 --- a/wasm-calc11/test/Test/Wasm/WasmSpec.hs +++ b/wasm-calc11/test/Test/Wasm/WasmSpec.hs @@ -4,6 +4,7 @@ module Test.Wasm.WasmSpec (spec) where +import Debug.Trace import Calc.Dependencies import Calc.Linearity (validateModule) import Calc.Module @@ -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), @@ -370,7 +371,7 @@ spec = do "}" ], Wasm.VI64 202 - ), + ), -} ( joinLines [ "type Maybe = Just(a) | Nothing", asTest "let boxA: Box(Int64) = Box(100); case Just(boxA) { Just(Box(a)) -> a + 1, Nothing -> 0 }" @@ -392,7 +393,7 @@ spec = do )-} ] - fdescribe "From expressions" $ do + describe "From expressions" $ do traverse_ testWithInterpreter testVals describe "Deallocations for expressions" $ do @@ -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