Skip to content

Commit

Permalink
Add Builtin.PointerRepresentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ollef committed May 21, 2024
1 parent f91c527 commit 3ca26f3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions builtin/Builtin.vix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mulInt : Int -> Int -> Int
subInt : Int -> Int -> Int

EmptyRepresentation : Type
PointerRepresentation : Type
WordRepresentation : Type

maxRepresentation : Type -> Type -> Type
Expand Down
4 changes: 4 additions & 0 deletions src/Builtin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ pattern WordRepresentationName :: Name.Qualified
pattern WordRepresentationName =
"Sixten.Builtin.WordRepresentation"

pattern PointerRepresentationName :: Name.Qualified
pattern PointerRepresentationName =
"Sixten.Builtin.PointerRepresentation"

pattern AddRepresentationName :: Name.Qualified
pattern AddRepresentationName =
"Sixten.Builtin.addRepresentation"
Expand Down
4 changes: 2 additions & 2 deletions src/ClosureConverted/Representation2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ compileData env dataTypeName (Syntax.ConstructorDefinitions constructors) = do
(boxity, maybeTags) <- fetch $ Query.ConstructorRepresentations dataTypeName
case boxity of
Boxed ->
pure $ Syntax.Global (Name.Lifted Builtin.WordRepresentationName 0)
pure $ Syntax.Global (Name.Lifted Builtin.PointerRepresentationName 0)
Unboxed -> do
compiledConstructorFields <- forM (OrderedHashMap.toList constructors) \(_, type_) -> do
type' <- Evaluation.evaluate env type_
Expand All @@ -238,7 +238,7 @@ compileData env dataTypeName (Syntax.ConstructorDefinitions constructors) = do
Just _ ->
Syntax.Apply
(Name.Lifted Builtin.AddRepresentationName 0)
[ Syntax.Global (Name.Lifted Builtin.WordRepresentationName 0)
[ Syntax.Global (Name.Lifted Builtin.IntName 0)
, maxFieldSize
]

Expand Down
1 change: 1 addition & 0 deletions src/Lower.hs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ mkCall = \cases
mkLoad :: Operand -> Representation -> Value
mkLoad = \cases
(Global (Name.Lifted Builtin.EmptyRepresentationName 0)) _ -> Operand $ Representation mempty
(Global (Name.Lifted Builtin.PointerRepresentationName 0)) _ -> Operand $ Representation Representation.pointer
(Global (Name.Lifted Builtin.UnitName 0)) _ -> Operand $ Representation mempty
(Global (Name.Lifted Builtin.IntName 0)) _ -> Operand $ Representation Representation.int
operand repr -> Load operand repr
Expand Down

0 comments on commit 3ca26f3

Please sign in to comment.