Skip to content

Commit 284533a

Browse files
committed
fix: initialize recursive types on the stack
This is in keeping with the way we handle other structs in Carp.
1 parent aa56369 commit 284533a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/RecType.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ recursiveProductInitBinder insidePath structTy@(StructTy (ConcreteNameTy _) _) [
6363
instanceBinder
6464
(SymPath insidePath "init")
6565
(FuncTy (initArgListTypes membersXObjs) structTy StaticLifetimeTy)
66-
(recursiveProductInit HeapAlloc structTy membersXObjs)
66+
(recursiveProductInit StackAlloc structTy membersXObjs)
6767
("creates a `" ++ show structTy ++ "`.")
6868
where initArgListTypes :: [XObj] -> [Ty]
6969
initArgListTypes xobjs =
@@ -116,7 +116,7 @@ productInitTokens allocationMode typeName membersXObjs =
116116
StackAlloc -> " $p instance;"
117117
HeapAlloc -> " $p *instance = CARP_MALLOC(sizeof(" ++ typeName ++ "));",
118118
assignments pairs,
119-
" return *instance;",
119+
" return instance;",
120120
"}"
121121
]
122122
where
@@ -125,8 +125,8 @@ productInitTokens allocationMode typeName membersXObjs =
125125
go [] = ""
126126
go xobjs = joinLines $ assign allocationMode <$> xobjs
127127
assign _ (name, (RecTy _)) =
128-
" instance" ++ "->" ++ name ++ " = " ++ "CARP_MALLOC(sizeof(" ++ typeName ++ "));\n"
129-
++ " *instance->" ++ name ++ " = " ++ name ++ ";\n"
128+
" instance" ++ "." ++ name ++ " = " ++ "CARP_MALLOC(sizeof(" ++ typeName ++ "));\n"
129+
++ " *instance." ++ name ++ " = " ++ name ++ ";\n"
130130
-- ++ " instance" ++ "->" ++ name ++ " = " ++ "&" ++ name ++ ";\n"
131131
-- ++ " " ++ typeName ++"_delete(" ++ name ++ ");"
132132
assign alloc (name, _) =

0 commit comments

Comments
 (0)