-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from well-typed/edsko/haskell-ast
Haskell AST
- Loading branch information
Showing
37 changed files
with
1,197 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
List {getList = []} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
List {getList = []} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
List {getList = []} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
List {getList = [DeclInstance (InstanceStorable (WithStruct (Struct {structName = "foo", structConstr = "Mkfoo", structFields = "i" ::: "c" ::: VNil}) (StorableInstance {storableSizeOf = 8, storableAlignment = 4, storablePeek = Lambda (\x0 -> Ap (IntroStruct (Struct {structName = "foo", structConstr = "Mkfoo", structFields = "i" ::: "c" ::: VNil})) [PeekByteOff x0 0, PeekByteOff x0 32]), storablePoke = Lambda (\x0 -> ElimStruct (Struct {structName = "foo", structConstr = "Mkfoo", structFields = "i" ::: "c" ::: VNil}) (\(x1 ::: x2 ::: VNil) -> (Seq (List {getList = [PokeByteOff x0 0 x1, PokeByteOff x0 32 x2]}))))}))), DeclInstance (InstanceStorable (WithStruct (Struct {structName = "bar", structConstr = "Mkbar", structFields = VNil}) (StorableInstance {storableSizeOf = 16, storableAlignment = 4, storablePeek = Lambda (\x0 -> Ap (IntroStruct (Struct {structName = "bar", structConstr = "Mkbar", structFields = VNil})) []), storablePoke = Lambda (\x0 -> ElimStruct (Struct {structName = "bar", structConstr = "Mkbar", structFields = VNil}) (\( ::: VNil) -> (Seq (List {getList = []}))))})))]} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
List {getList = [DeclInstance (InstanceStorable (WithStruct (Struct {structName = "primitive", structConstr = "Mkprimitive", structFields = "c" ::: "i" ::: "s2" ::: "si2" ::: "f" ::: VNil}) (StorableInstance {storableSizeOf = 176, storableAlignment = 16, storablePeek = Lambda (\x0 -> Ap (IntroStruct (Struct {structName = "primitive", structConstr = "Mkprimitive", structFields = "c" ::: "i" ::: "s2" ::: "si2" ::: "f" ::: VNil})) [PeekByteOff x0 0, PeekByteOff x0 128, PeekByteOff x0 160, PeekByteOff x0 192, PeekByteOff x0 1088]), storablePoke = Lambda (\x0 -> ElimStruct (Struct {structName = "primitive", structConstr = "Mkprimitive", structFields = "c" ::: "i" ::: "s2" ::: "si2" ::: "f" ::: VNil}) (\(x1 ::: x2 ::: x3 ::: x4 ::: x5 ::: VNil) -> (Seq (List {getList = [PokeByteOff x0 0 x1, PokeByteOff x0 128 x2, PokeByteOff x0 160 x3, PokeByteOff x0 192 x4, PokeByteOff x0 1088 x5]}))))})))]} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
List {getList = [DeclInstance (InstanceStorable (WithStruct (Struct {structName = "S1", structConstr = "MkS1", structFields = "a" ::: "b" ::: VNil}) (StorableInstance {storableSizeOf = 8, storableAlignment = 4, storablePeek = Lambda (\x0 -> Ap (IntroStruct (Struct {structName = "S1", structConstr = "MkS1", structFields = "a" ::: "b" ::: VNil})) [PeekByteOff x0 0, PeekByteOff x0 32]), storablePoke = Lambda (\x0 -> ElimStruct (Struct {structName = "S1", structConstr = "MkS1", structFields = "a" ::: "b" ::: VNil}) (\(x1 ::: x2 ::: VNil) -> (Seq (List {getList = [PokeByteOff x0 0 x1, PokeByteOff x0 32 x2]}))))}))), DeclInstance (InstanceStorable (WithStruct (Struct {structName = "S2", structConstr = "MkS2", structFields = "a" ::: "b" ::: "c" ::: VNil}) (StorableInstance {storableSizeOf = 12, storableAlignment = 4, storablePeek = Lambda (\x0 -> Ap (IntroStruct (Struct {structName = "S2", structConstr = "MkS2", structFields = "a" ::: "b" ::: "c" ::: VNil})) [PeekByteOff x0 0, PeekByteOff x0 32, PeekByteOff x0 64]), storablePoke = Lambda (\x0 -> ElimStruct (Struct {structName = "S2", structConstr = "MkS2", structFields = "a" ::: "b" ::: "c" ::: VNil}) (\(x1 ::: x2 ::: x3 ::: VNil) -> (Seq (List {getList = [PokeByteOff x0 0 x1, PokeByteOff x0 32 x2, PokeByteOff x0 64 x3]}))))}))), DeclInstance (InstanceStorable (WithStruct (Struct {structName = "X", structConstr = "MkX", structFields = "a" ::: VNil}) (StorableInstance {storableSizeOf = 1, storableAlignment = 1, storablePeek = Lambda (\x0 -> Ap (IntroStruct (Struct {structName = "X", structConstr = "MkX", structFields = "a" ::: VNil})) [PeekByteOff x0 0]), storablePoke = Lambda (\x0 -> ElimStruct (Struct {structName = "X", structConstr = "MkX", structFields = "a" ::: VNil}) (\(x1 ::: VNil) -> (Seq (List {getList = [PokeByteOff x0 0 x1]}))))}))), DeclInstance (InstanceStorable (WithStruct (Struct {structName = "S4", structConstr = "MkS4", structFields = "b" ::: "a" ::: VNil}) (StorableInstance {storableSizeOf = 8, storableAlignment = 4, storablePeek = Lambda (\x0 -> Ap (IntroStruct (Struct {structName = "S4", structConstr = "MkS4", structFields = "b" ::: "a" ::: VNil})) [PeekByteOff x0 0, PeekByteOff x0 32]), storablePoke = Lambda (\x0 -> ElimStruct (Struct {structName = "S4", structConstr = "MkS4", structFields = "b" ::: "a" ::: VNil}) (\(x1 ::: x2 ::: VNil) -> (Seq (List {getList = [PokeByteOff x0 0 x1, PokeByteOff x0 32 x2]}))))})))]} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
-- | Common backend functionality | ||
module HsBindgen.Backend.Common ( | ||
-- * Representation | ||
BackendRep(..) | ||
, Global(..) | ||
, SExpr(..) | ||
, SDecl(..) | ||
, Instance(..) | ||
-- * Full backend | ||
, Backend(..) | ||
, Fresh(..) | ||
) where | ||
|
||
import Data.Kind | ||
|
||
import HsBindgen.Util.PHOAS | ||
|
||
{------------------------------------------------------------------------------- | ||
Backend representation | ||
-------------------------------------------------------------------------------} | ||
|
||
class BackendRep be where | ||
type Name be :: Type | ||
type Expr be :: Type | ||
type Decl be :: Type | ||
|
||
resolve :: be -> Global -> Name be -- ^ Resolve name | ||
mkExpr :: be -> SExpr be -> Expr be -- ^ Construct expression | ||
mkDecl :: be -> SDecl be -> Decl be -- ^ Construct declaration | ||
|
||
data Global = | ||
Applicative_pure | ||
| Applicative_seq | ||
| Monad_seq | ||
| Storable_Storable | ||
| Storable_sizeOf | ||
| Storable_alignment | ||
| Storable_peekByteOff | ||
| Storable_pokeByteOff | ||
| Storable_peek | ||
| Storable_poke | ||
|
||
-- | Simple expressions | ||
data SExpr be = | ||
EGlobal Global | ||
| EVar (Fresh be Bound) | ||
| ECon String | ||
| EInt Int | ||
| EApp (SExpr be) (SExpr be) | ||
| EInfix Global (SExpr be) (SExpr be) | ||
| ELam (Maybe (Fresh be Bound)) (SExpr be) | ||
| ECase (SExpr be) [(String, [Fresh be Bound], SExpr be)] | ||
| EInj (Expr be) | ||
|
||
-- | Simple declarations | ||
data SDecl be = | ||
DVar (Name be) (SExpr be) | ||
| DInst (Instance be) | ||
|
||
data Instance be = Instance { | ||
instanceClass :: Global | ||
, instanceType :: String | ||
, instanceDecs :: [(Global, SExpr be)] | ||
} | ||
|
||
{------------------------------------------------------------------------------- | ||
Full backend | ||
-------------------------------------------------------------------------------} | ||
|
||
class (BackendRep be, Monad (M be)) => Backend be where | ||
data M be :: Type -> Type | ||
|
||
-- | Pick fresh variable | ||
-- | ||
-- This is scoped because variables don't need to be /globally/ unique. | ||
fresh :: be -> String -> (Fresh be Bound -> M be a) -> M be a | ||
|
||
newtype Fresh be a = Fresh { getFresh :: Name be } |
Oops, something went wrong.