Skip to content

Commit

Permalink
Fix for issue #53: record updates need dict copy
Browse files Browse the repository at this point in the history
  • Loading branch information
andyarvanitis committed Jul 28, 2020
1 parent d22d458 commit cd83d8c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/CodeGen/IL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ moduleToIL (Module _ coms mn _ imps _ foreigns decls) project =
updates <- mapM (sndM valueToIL) ps
obj' <- freshName'
let objVar = AST.Var Nothing obj'
copy = AST.VariableIntroduction Nothing obj' (Just $ AST.App Nothing (AST.StringLiteral Nothing (mkString dictType)) [obj])
copy = AST.VariableIntroduction Nothing obj' (Just $ copyDict obj)
assign (k, v) = AST.Assignment Nothing (accessorString k objVar) v
sts = copy : (assign <$> updates) ++ [AST.Return Nothing objVar]
return $ AST.App Nothing (AST.Function Nothing Nothing [] (AST.Block Nothing sts)) []
Expand Down Expand Up @@ -359,3 +359,6 @@ emptyAnn = (SourceSpan "" (SourcePos 0 0) (SourcePos 0 0), [], Nothing, Nothing)
arrayLength :: AST -> AST
arrayLength a = AST.App Nothing (AST.Var Nothing arrayLengthFn) [a]
-- arrayLength a = AST.Var Nothing (arrayLengthFn <> "(" <> prettyPrintIL1 a <> ")")

copyDict :: AST -> AST
copyDict a = AST.App Nothing (AST.Var Nothing copyDictFn) [a]
4 changes: 4 additions & 0 deletions src/CodeGen/IL/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ nameIsILBuiltIn name =
[ "Any"
, "Apply"
, "Contains"
, "CopyDict"
, "Dict"
, "EffFn"
, "Fn"
Expand Down Expand Up @@ -188,6 +189,9 @@ arrayLengthFn = "Length"
indexFn :: Text
indexFn = "Index"

copyDictFn :: Text
copyDictFn = "CopyDict"

freshName' :: MonadSupply m => m Text
freshName' = do
name <- freshName
Expand Down

0 comments on commit cd83d8c

Please sign in to comment.