Skip to content

Commit 98b4b9b

Browse files
Add Field type
We were using a tuple, but that does not scale well when more data is added. I ran into this when working on annotations (#256, PR #276). I ran into it again when adding source information to support test generation (#22). The `Field` types are used by *both* `Struct`/`Record` and `Newtype` types.
1 parent d1f136c commit 98b4b9b

23 files changed

+181
-159
lines changed

hs-bindgen/fixtures/anonymous.hs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
DeclData (Struct {structName = "CS1c", structConstr = "MkCS1c", structFields = ("cS1c_a",HsPrimType HsPrimCInt) ::: ("cS1c_b",HsPrimType HsPrimCInt) ::: VNil})
2-
DeclInstance (InstanceStorable (Struct {structName = "CS1c", structConstr = "MkCS1c", structFields = ("cS1c_a",HsPrimType HsPrimCInt) ::: ("cS1c_b",HsPrimType HsPrimCInt) ::: VNil}) (StorableInstance {storableSizeOf = 8, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CS1c", structConstr = "MkCS1c", structFields = ("cS1c_a",HsPrimType HsPrimCInt) ::: ("cS1c_b",HsPrimType HsPrimCInt) ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 4]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CS1c", structConstr = "MkCS1c", structFields = ("cS1c_a",HsPrimType HsPrimCInt) ::: ("cS1c_b",HsPrimType HsPrimCInt) ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 4 1])))}))
3-
DeclData (Struct {structName = "CS1", structConstr = "MkCS1", structFields = ("cS1_c",HsTypRef "CS1c") ::: ("cS1_d",HsPrimType HsPrimCInt) ::: VNil})
4-
DeclInstance (InstanceStorable (Struct {structName = "CS1", structConstr = "MkCS1", structFields = ("cS1_c",HsTypRef "CS1c") ::: ("cS1_d",HsPrimType HsPrimCInt) ::: VNil}) (StorableInstance {storableSizeOf = 12, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CS1", structConstr = "MkCS1", structFields = ("cS1_c",HsTypRef "CS1c") ::: ("cS1_d",HsPrimType HsPrimCInt) ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 8]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CS1", structConstr = "MkCS1", structFields = ("cS1_c",HsTypRef "CS1c") ::: ("cS1_d",HsPrimType HsPrimCInt) ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 8 1])))}))
5-
DeclData (Struct {structName = "CS2innerdeep", structConstr = "MkCS2innerdeep", structFields = ("cS2innerdeep_b",HsPrimType HsPrimCInt) ::: VNil})
6-
DeclInstance (InstanceStorable (Struct {structName = "CS2innerdeep", structConstr = "MkCS2innerdeep", structFields = ("cS2innerdeep_b",HsPrimType HsPrimCInt) ::: VNil}) (StorableInstance {storableSizeOf = 4, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CS2innerdeep", structConstr = "MkCS2innerdeep", structFields = ("cS2innerdeep_b",HsPrimType HsPrimCInt) ::: VNil})) [PeekByteOff 0 0]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CS2innerdeep", structConstr = "MkCS2innerdeep", structFields = ("cS2innerdeep_b",HsPrimType HsPrimCInt) ::: VNil}) 1 (Seq [PokeByteOff 2 0 0])))}))
7-
DeclData (Struct {structName = "CS2inner", structConstr = "MkCS2inner", structFields = ("cS2inner_a",HsPrimType HsPrimCInt) ::: ("cS2inner_deep",HsTypRef "CS2innerdeep") ::: VNil})
8-
DeclInstance (InstanceStorable (Struct {structName = "CS2inner", structConstr = "MkCS2inner", structFields = ("cS2inner_a",HsPrimType HsPrimCInt) ::: ("cS2inner_deep",HsTypRef "CS2innerdeep") ::: VNil}) (StorableInstance {storableSizeOf = 8, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CS2inner", structConstr = "MkCS2inner", structFields = ("cS2inner_a",HsPrimType HsPrimCInt) ::: ("cS2inner_deep",HsTypRef "CS2innerdeep") ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 4]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CS2inner", structConstr = "MkCS2inner", structFields = ("cS2inner_a",HsPrimType HsPrimCInt) ::: ("cS2inner_deep",HsTypRef "CS2innerdeep") ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 4 1])))}))
9-
DeclData (Struct {structName = "CS2", structConstr = "MkCS2", structFields = ("cS2_inner",HsTypRef "CS2inner") ::: ("cS2_d",HsPrimType HsPrimCInt) ::: VNil})
10-
DeclInstance (InstanceStorable (Struct {structName = "CS2", structConstr = "MkCS2", structFields = ("cS2_inner",HsTypRef "CS2inner") ::: ("cS2_d",HsPrimType HsPrimCInt) ::: VNil}) (StorableInstance {storableSizeOf = 12, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CS2", structConstr = "MkCS2", structFields = ("cS2_inner",HsTypRef "CS2inner") ::: ("cS2_d",HsPrimType HsPrimCInt) ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 8]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CS2", structConstr = "MkCS2", structFields = ("cS2_inner",HsTypRef "CS2inner") ::: ("cS2_d",HsPrimType HsPrimCInt) ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 8 1])))}))
1+
DeclData (Struct {structName = "CS1c", structConstr = "MkCS1c", structFields = Field {fieldName = "cS1c_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "cS1c_b", fieldType = HsPrimType HsPrimCInt} ::: VNil})
2+
DeclInstance (InstanceStorable (Struct {structName = "CS1c", structConstr = "MkCS1c", structFields = Field {fieldName = "cS1c_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "cS1c_b", fieldType = HsPrimType HsPrimCInt} ::: VNil}) (StorableInstance {storableSizeOf = 8, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CS1c", structConstr = "MkCS1c", structFields = Field {fieldName = "cS1c_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "cS1c_b", fieldType = HsPrimType HsPrimCInt} ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 4]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CS1c", structConstr = "MkCS1c", structFields = Field {fieldName = "cS1c_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "cS1c_b", fieldType = HsPrimType HsPrimCInt} ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 4 1])))}))
3+
DeclData (Struct {structName = "CS1", structConstr = "MkCS1", structFields = Field {fieldName = "cS1_c", fieldType = HsTypRef "CS1c"} ::: Field {fieldName = "cS1_d", fieldType = HsPrimType HsPrimCInt} ::: VNil})
4+
DeclInstance (InstanceStorable (Struct {structName = "CS1", structConstr = "MkCS1", structFields = Field {fieldName = "cS1_c", fieldType = HsTypRef "CS1c"} ::: Field {fieldName = "cS1_d", fieldType = HsPrimType HsPrimCInt} ::: VNil}) (StorableInstance {storableSizeOf = 12, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CS1", structConstr = "MkCS1", structFields = Field {fieldName = "cS1_c", fieldType = HsTypRef "CS1c"} ::: Field {fieldName = "cS1_d", fieldType = HsPrimType HsPrimCInt} ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 8]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CS1", structConstr = "MkCS1", structFields = Field {fieldName = "cS1_c", fieldType = HsTypRef "CS1c"} ::: Field {fieldName = "cS1_d", fieldType = HsPrimType HsPrimCInt} ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 8 1])))}))
5+
DeclData (Struct {structName = "CS2innerdeep", structConstr = "MkCS2innerdeep", structFields = Field {fieldName = "cS2innerdeep_b", fieldType = HsPrimType HsPrimCInt} ::: VNil})
6+
DeclInstance (InstanceStorable (Struct {structName = "CS2innerdeep", structConstr = "MkCS2innerdeep", structFields = Field {fieldName = "cS2innerdeep_b", fieldType = HsPrimType HsPrimCInt} ::: VNil}) (StorableInstance {storableSizeOf = 4, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CS2innerdeep", structConstr = "MkCS2innerdeep", structFields = Field {fieldName = "cS2innerdeep_b", fieldType = HsPrimType HsPrimCInt} ::: VNil})) [PeekByteOff 0 0]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CS2innerdeep", structConstr = "MkCS2innerdeep", structFields = Field {fieldName = "cS2innerdeep_b", fieldType = HsPrimType HsPrimCInt} ::: VNil}) 1 (Seq [PokeByteOff 2 0 0])))}))
7+
DeclData (Struct {structName = "CS2inner", structConstr = "MkCS2inner", structFields = Field {fieldName = "cS2inner_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "cS2inner_deep", fieldType = HsTypRef "CS2innerdeep"} ::: VNil})
8+
DeclInstance (InstanceStorable (Struct {structName = "CS2inner", structConstr = "MkCS2inner", structFields = Field {fieldName = "cS2inner_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "cS2inner_deep", fieldType = HsTypRef "CS2innerdeep"} ::: VNil}) (StorableInstance {storableSizeOf = 8, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CS2inner", structConstr = "MkCS2inner", structFields = Field {fieldName = "cS2inner_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "cS2inner_deep", fieldType = HsTypRef "CS2innerdeep"} ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 4]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CS2inner", structConstr = "MkCS2inner", structFields = Field {fieldName = "cS2inner_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "cS2inner_deep", fieldType = HsTypRef "CS2innerdeep"} ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 4 1])))}))
9+
DeclData (Struct {structName = "CS2", structConstr = "MkCS2", structFields = Field {fieldName = "cS2_inner", fieldType = HsTypRef "CS2inner"} ::: Field {fieldName = "cS2_d", fieldType = HsPrimType HsPrimCInt} ::: VNil})
10+
DeclInstance (InstanceStorable (Struct {structName = "CS2", structConstr = "MkCS2", structFields = Field {fieldName = "cS2_inner", fieldType = HsTypRef "CS2inner"} ::: Field {fieldName = "cS2_d", fieldType = HsPrimType HsPrimCInt} ::: VNil}) (StorableInstance {storableSizeOf = 12, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CS2", structConstr = "MkCS2", structFields = Field {fieldName = "cS2_inner", fieldType = HsTypRef "CS2inner"} ::: Field {fieldName = "cS2_d", fieldType = HsPrimType HsPrimCInt} ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 8]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CS2", structConstr = "MkCS2", structFields = Field {fieldName = "cS2_inner", fieldType = HsTypRef "CS2inner"} ::: Field {fieldName = "cS2_d", fieldType = HsPrimType HsPrimCInt} ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 8 1])))}))

hs-bindgen/fixtures/bool.hs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
DeclNewtype (Newtype {newtypeName = "CBOOL", newtypeConstr = "MkCBOOL", newtypeField = "unCBOOL", newtypeType = HsPrimType HsPrimCBool})
2-
DeclData (Struct {structName = "CBools1", structConstr = "MkCBools1", structFields = ("cBools1_x",HsPrimType HsPrimCBool) ::: ("cBools1_y",HsPrimType HsPrimCBool) ::: VNil})
3-
DeclInstance (InstanceStorable (Struct {structName = "CBools1", structConstr = "MkCBools1", structFields = ("cBools1_x",HsPrimType HsPrimCBool) ::: ("cBools1_y",HsPrimType HsPrimCBool) ::: VNil}) (StorableInstance {storableSizeOf = 2, storableAlignment = 1, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CBools1", structConstr = "MkCBools1", structFields = ("cBools1_x",HsPrimType HsPrimCBool) ::: ("cBools1_y",HsPrimType HsPrimCBool) ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 1]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CBools1", structConstr = "MkCBools1", structFields = ("cBools1_x",HsPrimType HsPrimCBool) ::: ("cBools1_y",HsPrimType HsPrimCBool) ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 1 1])))}))
4-
DeclData (Struct {structName = "CBools2", structConstr = "MkCBools2", structFields = ("cBools2_x",HsPrimType HsPrimCBool) ::: ("cBools2_y",HsPrimType HsPrimCBool) ::: VNil})
5-
DeclInstance (InstanceStorable (Struct {structName = "CBools2", structConstr = "MkCBools2", structFields = ("cBools2_x",HsPrimType HsPrimCBool) ::: ("cBools2_y",HsPrimType HsPrimCBool) ::: VNil}) (StorableInstance {storableSizeOf = 2, storableAlignment = 1, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CBools2", structConstr = "MkCBools2", structFields = ("cBools2_x",HsPrimType HsPrimCBool) ::: ("cBools2_y",HsPrimType HsPrimCBool) ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 1]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CBools2", structConstr = "MkCBools2", structFields = ("cBools2_x",HsPrimType HsPrimCBool) ::: ("cBools2_y",HsPrimType HsPrimCBool) ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 1 1])))}))
6-
DeclData (Struct {structName = "CBools3", structConstr = "MkCBools3", structFields = ("cBools3_x",HsTypRef "CBOOL") ::: ("cBools3_y",HsTypRef "CBOOL") ::: VNil})
7-
DeclInstance (InstanceStorable (Struct {structName = "CBools3", structConstr = "MkCBools3", structFields = ("cBools3_x",HsTypRef "CBOOL") ::: ("cBools3_y",HsTypRef "CBOOL") ::: VNil}) (StorableInstance {storableSizeOf = 2, storableAlignment = 1, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CBools3", structConstr = "MkCBools3", structFields = ("cBools3_x",HsTypRef "CBOOL") ::: ("cBools3_y",HsTypRef "CBOOL") ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 1]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CBools3", structConstr = "MkCBools3", structFields = ("cBools3_x",HsTypRef "CBOOL") ::: ("cBools3_y",HsTypRef "CBOOL") ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 1 1])))}))
1+
DeclNewtype (Newtype {newtypeName = "CBOOL", newtypeConstr = "MkCBOOL", newtypeField = Field {fieldName = "unCBOOL", fieldType = HsPrimType HsPrimCBool}})
2+
DeclData (Struct {structName = "CBools1", structConstr = "MkCBools1", structFields = Field {fieldName = "cBools1_x", fieldType = HsPrimType HsPrimCBool} ::: Field {fieldName = "cBools1_y", fieldType = HsPrimType HsPrimCBool} ::: VNil})
3+
DeclInstance (InstanceStorable (Struct {structName = "CBools1", structConstr = "MkCBools1", structFields = Field {fieldName = "cBools1_x", fieldType = HsPrimType HsPrimCBool} ::: Field {fieldName = "cBools1_y", fieldType = HsPrimType HsPrimCBool} ::: VNil}) (StorableInstance {storableSizeOf = 2, storableAlignment = 1, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CBools1", structConstr = "MkCBools1", structFields = Field {fieldName = "cBools1_x", fieldType = HsPrimType HsPrimCBool} ::: Field {fieldName = "cBools1_y", fieldType = HsPrimType HsPrimCBool} ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 1]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CBools1", structConstr = "MkCBools1", structFields = Field {fieldName = "cBools1_x", fieldType = HsPrimType HsPrimCBool} ::: Field {fieldName = "cBools1_y", fieldType = HsPrimType HsPrimCBool} ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 1 1])))}))
4+
DeclData (Struct {structName = "CBools2", structConstr = "MkCBools2", structFields = Field {fieldName = "cBools2_x", fieldType = HsPrimType HsPrimCBool} ::: Field {fieldName = "cBools2_y", fieldType = HsPrimType HsPrimCBool} ::: VNil})
5+
DeclInstance (InstanceStorable (Struct {structName = "CBools2", structConstr = "MkCBools2", structFields = Field {fieldName = "cBools2_x", fieldType = HsPrimType HsPrimCBool} ::: Field {fieldName = "cBools2_y", fieldType = HsPrimType HsPrimCBool} ::: VNil}) (StorableInstance {storableSizeOf = 2, storableAlignment = 1, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CBools2", structConstr = "MkCBools2", structFields = Field {fieldName = "cBools2_x", fieldType = HsPrimType HsPrimCBool} ::: Field {fieldName = "cBools2_y", fieldType = HsPrimType HsPrimCBool} ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 1]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CBools2", structConstr = "MkCBools2", structFields = Field {fieldName = "cBools2_x", fieldType = HsPrimType HsPrimCBool} ::: Field {fieldName = "cBools2_y", fieldType = HsPrimType HsPrimCBool} ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 1 1])))}))
6+
DeclData (Struct {structName = "CBools3", structConstr = "MkCBools3", structFields = Field {fieldName = "cBools3_x", fieldType = HsTypRef "CBOOL"} ::: Field {fieldName = "cBools3_y", fieldType = HsTypRef "CBOOL"} ::: VNil})
7+
DeclInstance (InstanceStorable (Struct {structName = "CBools3", structConstr = "MkCBools3", structFields = Field {fieldName = "cBools3_x", fieldType = HsTypRef "CBOOL"} ::: Field {fieldName = "cBools3_y", fieldType = HsTypRef "CBOOL"} ::: VNil}) (StorableInstance {storableSizeOf = 2, storableAlignment = 1, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CBools3", structConstr = "MkCBools3", structFields = Field {fieldName = "cBools3_x", fieldType = HsTypRef "CBOOL"} ::: Field {fieldName = "cBools3_y", fieldType = HsTypRef "CBOOL"} ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 1]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CBools3", structConstr = "MkCBools3", structFields = Field {fieldName = "cBools3_x", fieldType = HsTypRef "CBOOL"} ::: Field {fieldName = "cBools3_y", fieldType = HsTypRef "CBOOL"} ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 1 1])))}))

0 commit comments

Comments
 (0)