Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
5f08f50d
Commit
5f08f50d
authored
Apr 26, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get rid of stupid hacks to allow single-bit structs.
parent
dcfd0915
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
69 additions
and
118 deletions
+69
-118
encoding-test.c++
c++/src/capnproto/encoding-test.c++
+7
-47
layout-test.c++
c++/src/capnproto/layout-test.c++
+8
-8
layout.c++
c++/src/capnproto/layout.c++
+0
-0
layout.h
c++/src/capnproto/layout.h
+0
-0
test.capnp
c++/src/capnproto/test.capnp
+27
-35
Compiler.hs
compiler/src/Compiler.hs
+3
-3
CxxGenerator.hs
compiler/src/CxxGenerator.hs
+9
-9
Parser.hs
compiler/src/Parser.hs
+3
-4
Semantics.hs
compiler/src/Semantics.hs
+4
-4
c++-header.mustache
compiler/src/c++-header.mustache
+8
-8
No files found.
c++/src/capnproto/encoding-test.c++
View file @
5f08f50d
...
...
@@ -294,7 +294,6 @@ TEST(Encoding, InlineStructUnionLayout) {
initUnion<TestInlineUnions>([](TestInlineUnions::Builder b) {b.setter;})
EXPECT_EQ
(
UnionState
({
0
,
0
,
0
,
0
},
-
1
),
INIT_UNION
(
getUnion0
().
initF0
()));
EXPECT_EQ
(
UnionState
({
1
,
0
,
0
,
0
},
0
),
INIT_UNION
(
getUnion0
().
initF1
().
setF
(
1
)));
EXPECT_EQ
(
UnionState
({
2
,
0
,
0
,
0
},
0
),
INIT_UNION
(
getUnion0
().
initF8
().
setF0
(
true
)));
EXPECT_EQ
(
UnionState
({
3
,
0
,
0
,
0
},
0
),
INIT_UNION
(
getUnion0
().
initF16
().
setF0
(
1
)));
EXPECT_EQ
(
UnionState
({
4
,
0
,
0
,
0
},
0
),
INIT_UNION
(
getUnion0
().
initF32
().
setF0
(
1
)));
...
...
@@ -303,7 +302,6 @@ TEST(Encoding, InlineStructUnionLayout) {
EXPECT_EQ
(
UnionState
({
7
,
0
,
0
,
0
},
0
),
INIT_UNION
(
getUnion0
().
initF192
().
setF0
(
1
)));
EXPECT_EQ
(
UnionState
({
8
,
0
,
0
,
0
},
-
1
),
INIT_UNION
(
getUnion0
().
initF0p
().
initF
()));
EXPECT_EQ
(
UnionState
({
9
,
0
,
0
,
0
},
0
),
INIT_UNION
(
getUnion0
().
initF1p
().
initF
().
setF
(
1
)));
EXPECT_EQ
(
UnionState
({
10
,
0
,
0
,
0
},
0
),
INIT_UNION
(
getUnion0
().
initF8p
().
initF
().
setF0
(
true
)));
EXPECT_EQ
(
UnionState
({
11
,
0
,
0
,
0
},
0
),
INIT_UNION
(
getUnion0
().
initF16p
().
initF
().
setF0
(
1
)));
EXPECT_EQ
(
UnionState
({
12
,
0
,
0
,
0
},
0
),
INIT_UNION
(
getUnion0
().
initF32p
().
initF
().
setF0
(
1
)));
...
...
@@ -312,7 +310,6 @@ TEST(Encoding, InlineStructUnionLayout) {
EXPECT_EQ
(
UnionState
({
15
,
0
,
0
,
0
},
0
),
INIT_UNION
(
getUnion0
().
initF192p
().
initF
().
setF0
(
1
)));
EXPECT_EQ
(
UnionState
({
8
,
0
,
0
,
0
},
ptr
(
0
)),
INIT_UNION
(
getUnion0
().
initF0p
().
setP0
(
"1"
)));
EXPECT_EQ
(
UnionState
({
9
,
0
,
0
,
0
},
ptr
(
0
)),
INIT_UNION
(
getUnion0
().
initF1p
().
setP0
(
"1"
)));
EXPECT_EQ
(
UnionState
({
10
,
0
,
0
,
0
},
ptr
(
0
)),
INIT_UNION
(
getUnion0
().
initF8p
().
setP0
(
"1"
)));
EXPECT_EQ
(
UnionState
({
11
,
0
,
0
,
0
},
ptr
(
0
)),
INIT_UNION
(
getUnion0
().
initF16p
().
setP0
(
"1"
)));
EXPECT_EQ
(
UnionState
({
12
,
0
,
0
,
0
},
ptr
(
0
)),
INIT_UNION
(
getUnion0
().
initF32p
().
setP0
(
"1"
)));
...
...
@@ -321,7 +318,6 @@ TEST(Encoding, InlineStructUnionLayout) {
EXPECT_EQ
(
UnionState
({
15
,
0
,
0
,
0
},
ptr
(
0
)),
INIT_UNION
(
getUnion0
().
initF192p
().
setP0
(
"1"
)));
EXPECT_EQ
(
UnionState
({
0
,
0
,
0
,
0
},
-
1
),
INIT_UNION
(
getUnion1
().
initF0
()));
EXPECT_EQ
(
UnionState
({
0
,
1
,
0
,
0
},
193
),
INIT_UNION
(
getUnion1
().
initF1
().
setF
(
1
)));
EXPECT_EQ
(
UnionState
({
0
,
2
,
0
,
0
},
200
),
INIT_UNION
(
getUnion1
().
initF8
().
setF0
(
true
)));
EXPECT_EQ
(
UnionState
({
0
,
3
,
0
,
0
},
208
),
INIT_UNION
(
getUnion1
().
initF16
().
setF0
(
1
)));
EXPECT_EQ
(
UnionState
({
0
,
4
,
0
,
0
},
224
),
INIT_UNION
(
getUnion1
().
initF32
().
setF0
(
1
)));
...
...
@@ -329,8 +325,6 @@ TEST(Encoding, InlineStructUnionLayout) {
EXPECT_EQ
(
UnionState
({
0
,
6
,
0
,
0
},
256
),
INIT_UNION
(
getUnion1
().
initF128
().
setF0
(
1
)));
EXPECT_EQ
(
UnionState
({
0
,
7
,
0
,
0
},
256
),
INIT_UNION
(
getUnion1
().
initF192
().
setF0
(
1
)));
EXPECT_EQ
(
UnionState
({
0
,
0
,
0
,
0
},
448
),
INIT_UNION
(
getUnion2
().
initF1p
().
initF
().
setF
(
1
)));
EXPECT_EQ
(
UnionState
({
0
,
0
,
0
,
0
},
449
),
INIT_UNION
(
getUnion3
().
initF1p
().
initF
().
setF
(
1
)));
EXPECT_EQ
(
UnionState
({
0
,
0
,
1
,
0
},
456
),
INIT_UNION
(
getUnion2
().
initF8p
().
initF
().
setF0
(
true
)));
EXPECT_EQ
(
UnionState
({
0
,
0
,
0
,
1
},
464
),
INIT_UNION
(
getUnion3
().
initF8p
().
initF
().
setF0
(
true
)));
EXPECT_EQ
(
UnionState
({
0
,
0
,
2
,
0
},
480
),
INIT_UNION
(
getUnion2
().
initF16p
().
initF
().
setF0
(
1
)));
...
...
@@ -344,8 +338,6 @@ TEST(Encoding, InlineStructUnionLayout) {
EXPECT_EQ
(
UnionState
({
0
,
0
,
6
,
0
},
960
),
INIT_UNION
(
getUnion2
().
initF192p
().
initF
().
setF0
(
1
)));
EXPECT_EQ
(
UnionState
({
0
,
0
,
0
,
6
},
1152
),
INIT_UNION
(
getUnion3
().
initF192p
().
initF
().
setF0
(
1
)));
EXPECT_EQ
(
UnionState
({
0
,
0
,
0
,
0
},
ptr
(
3
)),
INIT_UNION
(
getUnion2
().
initF1p
().
setP0
(
"1"
)));
EXPECT_EQ
(
UnionState
({
0
,
0
,
0
,
0
},
ptr
(
4
)),
INIT_UNION
(
getUnion3
().
initF1p
().
setP0
(
"1"
)));
EXPECT_EQ
(
UnionState
({
0
,
0
,
1
,
0
},
ptr
(
3
)),
INIT_UNION
(
getUnion2
().
initF8p
().
setP0
(
"1"
)));
EXPECT_EQ
(
UnionState
({
0
,
0
,
0
,
1
},
ptr
(
4
)),
INIT_UNION
(
getUnion3
().
initF8p
().
setP0
(
"1"
)));
EXPECT_EQ
(
UnionState
({
0
,
0
,
2
,
0
},
ptr
(
5
)),
INIT_UNION
(
getUnion2
().
initF16p
().
setP0
(
"1"
)));
...
...
@@ -367,9 +359,7 @@ TEST(Encoding, InitInlineStruct) {
auto
root
=
builder
.
getRoot
<
TestInlineLayout
>
();
// Set as many bits as we can.
root
.
initF1
().
setF
(
true
);
root
.
initF1Offset
().
setF
(
true
);
root
.
setBit
(
true
);
root
.
setPad1
(
0xffu
);
root
.
initF8
().
setF0
(
true
);
root
.
getF8
().
setF1
(
true
);
root
.
getF8
().
setF2
(
true
);
...
...
@@ -386,8 +376,8 @@ TEST(Encoding, InitInlineStruct) {
root
.
getF192
().
setF2
(
0xffffffffffffffffull
);
root
.
initF0p
().
setP0
(
"foo"
);
root
.
initF1p
().
setP0
(
"foo"
);
root
.
getF1p
().
initF
().
setF
(
true
);
root
.
setPad2
(
0xffu
);
root
.
setPadP
(
"foo"
);
root
.
initF8p
().
setP0
(
"foo"
);
root
.
initF16p
().
setP0
(
"foo"
);
root
.
getF16p
().
setP1
(
"foo"
);
...
...
@@ -403,21 +393,10 @@ TEST(Encoding, InitInlineStruct) {
root
.
getF192p
().
setP2
(
"foo"
);
// Now try re-initializing each thing and making sure the surrounding things aren't modified.
EXPECT_FALSE
(
root
.
initF1
().
getF
());
EXPECT_TRUE
(
root
.
getF1Offset
().
getF
());
root
.
getF1
().
setF
(
true
);
EXPECT_FALSE
(
root
.
initF1Offset
().
getF
());
EXPECT_TRUE
(
root
.
getF1
().
getF
());
EXPECT_TRUE
(
root
.
getBit
());
EXPECT_TRUE
(
root
.
getF8
().
getF0
());
root
.
getF1Offset
().
setF
(
true
);
EXPECT_FALSE
(
root
.
initF8
().
getF0
());
EXPECT_FALSE
(
root
.
getF8
().
getF1
());
EXPECT_FALSE
(
root
.
getF8
().
getF2
());
EXPECT_TRUE
(
root
.
getF1
().
getF
());
EXPECT_TRUE
(
root
.
getBit
());
EXPECT_EQ
(
0xffu
,
root
.
getPad1
());
EXPECT_EQ
(
0xffu
,
root
.
getF16
().
getF0
());
root
.
initF8
().
setF0
(
true
);
root
.
getF8
().
setF1
(
true
);
...
...
@@ -461,22 +440,17 @@ TEST(Encoding, InitInlineStruct) {
EXPECT_EQ
(
0u
,
root
.
getF192
().
getF2
());
EXPECT_EQ
(
0xffffffffffffffffull
,
root
.
getF128
().
getF0
());
EXPECT_EQ
(
0xffffffffffffffffull
,
root
.
getF128
().
getF1
());
EXPECT_
TRUE
(
root
.
getF1p
().
getF
().
getF
());
EXPECT_
EQ
(
0xffu
,
root
.
getPad2
());
root
.
getF192
().
setF0
(
0xffffffffffffffffull
);
root
.
getF192
().
setF1
(
0xffffffffffffffffull
);
root
.
getF192
().
setF2
(
0xffffffffffffffffull
);
EXPECT_EQ
(
""
,
root
.
initF0p
().
getP0
());
EXPECT_EQ
(
"foo"
,
root
.
get
F1p
().
getP0
());
EXPECT_EQ
(
"foo"
,
root
.
get
PadP
());
root
.
getF0p
().
setP0
(
"foo"
);
EXPECT_EQ
(
""
,
root
.
initF1p
().
getP0
());
EXPECT_EQ
(
"foo"
,
root
.
getF0p
().
getP0
());
EXPECT_EQ
(
"foo"
,
root
.
getF8p
().
getP0
());
root
.
getF1p
().
setP0
(
"foo"
);
EXPECT_EQ
(
""
,
root
.
initF8p
().
getP0
());
EXPECT_EQ
(
"foo"
,
root
.
get
F1p
().
getP0
());
EXPECT_EQ
(
"foo"
,
root
.
get
PadP
());
EXPECT_EQ
(
"foo"
,
root
.
getF16p
().
getP0
());
root
.
initF8p
().
setP0
(
"foo"
);
...
...
@@ -525,7 +499,6 @@ TEST(Encoding, InlineDefaults) {
{
auto
normal
=
reader
.
getNormal
();
EXPECT_TRUE
(
normal
.
getF1
().
getF
());
EXPECT_TRUE
(
normal
.
getF8
().
getF0
());
EXPECT_FALSE
(
normal
.
getF8
().
getF1
());
EXPECT_TRUE
(
normal
.
getF8
().
getF2
());
...
...
@@ -541,7 +514,6 @@ TEST(Encoding, InlineDefaults) {
EXPECT_EQ
(
2345678901234ull
,
normal
.
getF192
().
getF1
());
EXPECT_EQ
(
5678901234567ull
,
normal
.
getF192
().
getF2
());
EXPECT_FALSE
(
normal
.
getF1p
().
getF
().
getF
());
EXPECT_TRUE
(
normal
.
getF8p
().
getF
().
getF0
());
EXPECT_TRUE
(
normal
.
getF8p
().
getF
().
getF1
());
EXPECT_FALSE
(
normal
.
getF8p
().
getF
().
getF2
());
...
...
@@ -558,7 +530,6 @@ TEST(Encoding, InlineDefaults) {
EXPECT_EQ
(
5432109876543ull
,
normal
.
getF192p
().
getF
().
getF2
());
EXPECT_EQ
(
"foo"
,
normal
.
getF0p
().
getP0
());
EXPECT_EQ
(
"bar"
,
normal
.
getF1p
().
getP0
());
EXPECT_EQ
(
"baz"
,
normal
.
getF8p
().
getP0
());
EXPECT_EQ
(
"qux"
,
normal
.
getF16p
().
getP0
());
EXPECT_EQ
(
"quux"
,
normal
.
getF16p
().
getP1
());
...
...
@@ -585,9 +556,6 @@ TEST(Encoding, InlineDefaults) {
EXPECT_EQ
(
1234567890123ull
,
unions
.
getUnion1
().
getF128
().
getF0
());
EXPECT_EQ
(
4567890123456ull
,
unions
.
getUnion1
().
getF128
().
getF1
());
ASSERT_EQ
(
TestInlineUnions
::
Union2
::
F1P
,
unions
.
getUnion2
().
which
());
EXPECT_EQ
(
"foo"
,
unions
.
getUnion2
().
getF1p
().
getP0
());
ASSERT_EQ
(
TestInlineUnions
::
Union3
::
F16P
,
unions
.
getUnion3
().
which
());
EXPECT_EQ
(
98u
,
unions
.
getUnion3
().
getF16p
().
getF
().
getF0
());
EXPECT_EQ
(
76u
,
unions
.
getUnion3
().
getF16p
().
getF
().
getF1
());
...
...
@@ -659,10 +627,6 @@ TEST(Encoding, InlineDefaults) {
EXPECT_EQ
(
Void
::
VOID
,
lists
.
getStructList0
()[
0
].
getF
());
EXPECT_EQ
(
Void
::
VOID
,
lists
.
getStructList0
()[
1
].
getF
());
EXPECT_TRUE
(
lists
.
getStructList1
()[
0
].
getF
());
EXPECT_FALSE
(
lists
.
getStructList1
()[
1
].
getF
());
// EXPECT_TRUE(lists.getStructList1()[2].getF());
EXPECT_TRUE
(
lists
.
getStructList8
()[
0
].
getF0
());
EXPECT_FALSE
(
lists
.
getStructList8
()[
0
].
getF1
());
EXPECT_FALSE
(
lists
.
getStructList8
()[
0
].
getF2
());
...
...
@@ -717,10 +681,6 @@ TEST(Encoding, InlineDefaults) {
EXPECT_EQ
(
"baz"
,
lists
.
getStructList0p
()[
2
].
getP0
());
EXPECT_EQ
(
"qux"
,
lists
.
getStructList0p
()[
3
].
getP0
());
EXPECT_TRUE
(
lists
.
getStructList1p
()[
0
].
getF
().
getF
());
EXPECT_EQ
(
"quux"
,
lists
.
getStructList1p
()[
0
].
getP0
());
EXPECT_EQ
(
"corge"
,
lists
.
getStructList1p
()[
1
].
getP0
());
EXPECT_TRUE
(
lists
.
getStructList8p
()[
0
].
getF
().
getF0
());
EXPECT_EQ
(
"grault"
,
lists
.
getStructList8p
()[
0
].
getP0
());
EXPECT_EQ
(
"garply"
,
lists
.
getStructList8p
()[
1
].
getP0
());
...
...
c++/src/capnproto/layout-test.c++
View file @
5f08f50d
...
...
@@ -102,7 +102,7 @@ static const AlignedData<2> SUBSTRUCT_DEFAULT = {{0,0,0,0,1,0,0,0, 0,0,0,0,0,0,
static
const
AlignedData
<
2
>
STRUCTLIST_ELEMENT_SUBSTRUCT_DEFAULT
=
{{
0
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
}};
static
constexpr
StructSize
STRUCTLIST_ELEMENT_SIZE
(
1
*
WORDS
,
1
*
REFERENCES
,
64
*
BIT
S
);
static
constexpr
StructSize
STRUCTLIST_ELEMENT_SIZE
(
1
*
WORDS
,
1
*
REFERENCES
,
8
*
BYTE
S
);
static
void
setupStruct
(
StructBuilder
builder
)
{
builder
.
setDataField
<
uint64_t
>
(
0
*
ELEMENTS
,
0x1011121314151617ull
);
...
...
@@ -120,7 +120,7 @@ static void setupStruct(StructBuilder builder) {
{
StructBuilder
subStruct
=
builder
.
initStructField
(
0
*
REFERENCES
,
StructSize
(
1
*
WORDS
,
0
*
REFERENCES
,
64
*
BIT
S
));
0
*
REFERENCES
,
StructSize
(
1
*
WORDS
,
0
*
REFERENCES
,
8
*
BYTE
S
));
subStruct
.
setDataField
<
uint32_t
>
(
0
*
ELEMENTS
,
123
);
}
...
...
@@ -139,7 +139,7 @@ static void setupStruct(StructBuilder builder) {
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
StructBuilder
element
=
list
.
getStructElement
(
i
*
ELEMENTS
,
STRUCTLIST_ELEMENT_SIZE
);
element
.
setDataField
<
int32_t
>
(
0
*
ELEMENTS
,
300
+
i
);
element
.
initStructField
(
0
*
REFERENCES
,
StructSize
(
1
*
WORDS
,
0
*
REFERENCES
,
64
*
BIT
S
))
element
.
initStructField
(
0
*
REFERENCES
,
StructSize
(
1
*
WORDS
,
0
*
REFERENCES
,
8
*
BYTE
S
))
.
setDataField
<
int32_t
>
(
0
*
ELEMENTS
,
400
+
i
);
}
}
...
...
@@ -174,7 +174,7 @@ static void checkStruct(StructBuilder builder) {
{
StructBuilder
subStruct
=
builder
.
getStructField
(
0
*
REFERENCES
,
StructSize
(
1
*
WORDS
,
0
*
REFERENCES
,
64
*
BIT
S
),
SUBSTRUCT_DEFAULT
.
words
);
0
*
REFERENCES
,
StructSize
(
1
*
WORDS
,
0
*
REFERENCES
,
8
*
BYTE
S
),
SUBSTRUCT_DEFAULT
.
words
);
EXPECT_EQ
(
123u
,
subStruct
.
getDataField
<
uint32_t
>
(
0
*
ELEMENTS
));
}
...
...
@@ -193,7 +193,7 @@ static void checkStruct(StructBuilder builder) {
StructBuilder
element
=
list
.
getStructElement
(
i
*
ELEMENTS
,
STRUCTLIST_ELEMENT_SIZE
);
EXPECT_EQ
(
300
+
i
,
element
.
getDataField
<
int32_t
>
(
0
*
ELEMENTS
));
EXPECT_EQ
(
400
+
i
,
element
.
getStructField
(
0
*
REFERENCES
,
StructSize
(
1
*
WORDS
,
0
*
REFERENCES
,
64
*
BIT
S
),
element
.
getStructField
(
0
*
REFERENCES
,
StructSize
(
1
*
WORDS
,
0
*
REFERENCES
,
8
*
BYTE
S
),
STRUCTLIST_ELEMENT_SUBSTRUCT_DEFAULT
.
words
)
.
getDataField
<
int32_t
>
(
0
*
ELEMENTS
));
}
...
...
@@ -272,7 +272,7 @@ TEST(WireFormat, StructRoundTrip_OneSegment) {
word
*
rootLocation
=
segment
->
allocate
(
1
*
WORDS
);
StructBuilder
builder
=
StructBuilder
::
initRoot
(
segment
,
rootLocation
,
StructSize
(
2
*
WORDS
,
4
*
REFERENCES
,
1
28
*
BIT
S
));
segment
,
rootLocation
,
StructSize
(
2
*
WORDS
,
4
*
REFERENCES
,
1
6
*
BYTE
S
));
setupStruct
(
builder
);
// word count:
...
...
@@ -308,7 +308,7 @@ TEST(WireFormat, StructRoundTrip_OneSegmentPerAllocation) {
word
*
rootLocation
=
segment
->
allocate
(
1
*
WORDS
);
StructBuilder
builder
=
StructBuilder
::
initRoot
(
segment
,
rootLocation
,
StructSize
(
2
*
WORDS
,
4
*
REFERENCES
,
1
28
*
BIT
S
));
segment
,
rootLocation
,
StructSize
(
2
*
WORDS
,
4
*
REFERENCES
,
1
6
*
BYTE
S
));
setupStruct
(
builder
);
// Verify that we made 15 segments.
...
...
@@ -345,7 +345,7 @@ TEST(WireFormat, StructRoundTrip_MultipleSegmentsWithMultipleAllocations) {
word
*
rootLocation
=
segment
->
allocate
(
1
*
WORDS
);
StructBuilder
builder
=
StructBuilder
::
initRoot
(
segment
,
rootLocation
,
StructSize
(
2
*
WORDS
,
4
*
REFERENCES
,
1
28
*
BIT
S
));
segment
,
rootLocation
,
StructSize
(
2
*
WORDS
,
4
*
REFERENCES
,
1
6
*
BYTE
S
));
setupStruct
(
builder
);
// Verify that we made 6 segments.
...
...
c++/src/capnproto/layout.c++
View file @
5f08f50d
This diff is collapsed.
Click to expand it.
c++/src/capnproto/layout.h
View file @
5f08f50d
This diff is collapsed.
Click to expand it.
c++/src/capnproto/test.capnp
View file @
5f08f50d
...
...
@@ -276,27 +276,25 @@ struct TestUsing {
innerNestedEnum @0 :NestedEnum = quux;
}
struct TestInline0 fixed(0 bits) { f @0: Void; }
struct TestInline1 fixed(1 bits) { f @0: Bool; }
struct TestInline8 fixed(8 bits) { f0 @0: Bool; f1 @1: Bool; f2 @2: Bool; }
struct TestInline16 fixed(16 bits) { f0 @0: UInt8; f1 @1: UInt8; }
struct TestInline32 fixed(32 bits) { f0 @0: UInt8; f1 @1: UInt16; }
struct TestInline64 fixed(64 bits) { f0 @0: UInt8; f1 @1: UInt32; }
struct TestInline0 fixed() { f @0: Void; }
struct TestInline8 fixed(1 bytes) { f0 @0: Bool; f1 @1: Bool; f2 @2: Bool; }
struct TestInline16 fixed(2 bytes) { f0 @0: UInt8; f1 @1: UInt8; }
struct TestInline32 fixed(4 bytes) { f0 @0: UInt8; f1 @1: UInt16; }
struct TestInline64 fixed(8 bytes) { f0 @0: UInt8; f1 @1: UInt32; }
struct TestInline128 fixed(2 words) { f0 @0: UInt64; f1 @1: UInt64; }
struct TestInline192 fixed(3 words) { f0 @0: UInt64; f1 @1: UInt64; f2 @2: UInt64; }
struct TestInline0p fixed(0 bits, 1 pointers) { f @0 :Inline(TestInline0); p0 @1 :Text; }
struct TestInline1p fixed(1 bits, 1 pointers) { f @0 :Inline(TestInline1); p0 @1 :Text; }
struct TestInline8p fixed(8 bits, 1 pointers) { f @0 :Inline(TestInline8); p0 @1 :Text; }
struct TestInline16p fixed(16 bits, 2 pointers) { f @0 :Inline(TestInline16); p0 @1 :Text; p1 @2 :Text; }
struct TestInline32p fixed(32 bits, 2 pointers) { f @0 :Inline(TestInline32); p0 @1 :Text; p1 @2 :Text; }
struct TestInline64p fixed(64 bits, 2 pointers) { f @0 :Inline(TestInline64); p0 @1 :Text; p1 @2 :Text; }
struct TestInline0p fixed(1 pointers) { f @0 :Inline(TestInline0); p0 @1 :Text; }
struct TestInline8p fixed(1 bytes, 1 pointers) { f @0 :Inline(TestInline8); p0 @1 :Text; }
struct TestInline16p fixed(2 bytes, 2 pointers) { f @0 :Inline(TestInline16); p0 @1 :Text; p1 @2 :Text; }
struct TestInline32p fixed(4 bytes, 2 pointers) { f @0 :Inline(TestInline32); p0 @1 :Text; p1 @2 :Text; }
struct TestInline64p fixed(8 bytes, 2 pointers) { f @0 :Inline(TestInline64); p0 @1 :Text; p1 @2 :Text; }
struct TestInline128p fixed(2 words, 3 pointers) { f @0 :Inline(TestInline128); p0 @1 :Text; p1 @2 :Text; p2 @3 :Text; }
struct TestInline192p fixed(3 words, 3 pointers) { f @0 :Inline(TestInline192); p0 @1 :Text; p1 @2 :Text; p2 @3 :Text; }
struct TestInlineLayout {
f0 @0 :Inline(TestInline0);
f1 @1 :Inline(TestInline1)
;
pad1 @1 :UInt8
;
f8 @2 :Inline(TestInline8);
f16 @3 :Inline(TestInline16);
f32 @4 :Inline(TestInline32);
...
...
@@ -305,22 +303,20 @@ struct TestInlineLayout {
f192 @7 :Inline(TestInline192);
f0p @8 :Inline(TestInline0p);
f1p @9 :Inline(TestInline1p);
f8p @10 :Inline(TestInline8p);
f16p @11 :Inline(TestInline16p);
f32p @12 :Inline(TestInline32p);
f64p @13 :Inline(TestInline64p);
f128p @14 :Inline(TestInline128p);
f192p @15 :Inline(TestInline192p);
f1Offset @16 :Inline(TestInline1);
bit @17 :Bool;
pad2 @9 :UInt8;
padP @10 :Text;
f8p @11 :Inline(TestInline8p);
f16p @12 :Inline(TestInline16p);
f32p @13 :Inline(TestInline32p);
f64p @14 :Inline(TestInline64p);
f128p @15 :Inline(TestInline128p);
f192p @16 :Inline(TestInline192p);
}
struct TestInlineUnions {
union0 @0 union {
f0 @4 :Inline(TestInline0);
f1 @5 :
Inline(TestInline1);
f1 @5 :
Bool; # There used to be a TestInline1 but it was decided to be a bad idea.
f8 @6 :Inline(TestInline8);
f16 @7 :Inline(TestInline16);
f32 @8 :Inline(TestInline32);
...
...
@@ -329,7 +325,7 @@ struct TestInlineUnions {
f192 @11 :Inline(TestInline192);
f0p @12 :Inline(TestInline0p);
f1p @13 :
Inline(TestInline1p)
;
f1p @13 :
Bool
;
f8p @14 :Inline(TestInline8p);
f16p @15 :Inline(TestInline16p);
f32p @16 :Inline(TestInline32p);
...
...
@@ -343,7 +339,7 @@ struct TestInlineUnions {
union1 @1 union {
f0 @21 :Inline(TestInline0);
f1 @22 :
Inline(TestInline1)
;
f1 @22 :
Bool
;
f8 @23 :Inline(TestInline8);
f16 @24 :Inline(TestInline16);
f32 @25 :Inline(TestInline32);
...
...
@@ -362,7 +358,7 @@ struct TestInlineUnions {
# Interleave two unions to be really annoying.
union2 @2 union {
f1p @35 :
Inline(TestInline1p)
;
f1p @35 :
Bool
;
f8p @37 :Inline(TestInline8p);
f16p @40 :Inline(TestInline16p);
f32p @42 :Inline(TestInline32p);
...
...
@@ -372,7 +368,7 @@ struct TestInlineUnions {
}
union3 @3 union {
f1p @36 :
Inline(TestInline1p)
;
f1p @36 :
Bool
;
f8p @38 :Inline(TestInline8p);
f16p @41 :Inline(TestInline16p);
f32p @43 :Inline(TestInline32p);
...
...
@@ -394,7 +390,7 @@ struct TestInlineLists {
textList @ 6 : InlineList(Text, 8);
structList0 @ 7 : InlineList(TestInline0, 2);
structList1 @ 8 : InlineList(
TestInline1
, 3);
structList1 @ 8 : InlineList(
Bool
, 3);
structList8 @ 9 : InlineList(TestInline8, 4);
structList16 @10 : InlineList(TestInline16, 2);
structList32 @11 : InlineList(TestInline32, 3);
...
...
@@ -403,7 +399,7 @@ struct TestInlineLists {
structList192 @14 : InlineList(TestInline192, 3);
structList0p @15 : InlineList(TestInline0p, 4);
structList1p @16 : InlineList(
TestInline1p
, 2);
structList1p @16 : InlineList(
Bool
, 2);
structList8p @17 : InlineList(TestInline8p, 3);
structList16p @18 : InlineList(TestInline16p, 4);
structList32p @19 : InlineList(TestInline32p, 2);
...
...
@@ -435,7 +431,6 @@ struct TestStructLists {
struct TestInlineDefaults {
normal @0 :TestInlineLayout = (
f0 = (f = void),
f1 = (f = true),
f8 = (f0 = true, f1 = false, f2 = true),
f16 = (f0 = 123, f1 = 45),
f32 = (f0 = 67, f1 = 8901),
...
...
@@ -444,7 +439,6 @@ struct TestInlineDefaults {
f192 = (f0 = 7890123456789, f1 = 2345678901234, f2 = 5678901234567),
f0p = (p0 = "foo"),
f1p = (f = (f = false), p0 = "bar"),
f8p = (f = (f0 = true, f1 = true, f2 = false), p0 = "baz"),
f16p = (f = (f0 = 98, f1 = 76), p0 = "qux", p1 = "quux"),
f32p = (f = (f0 = 54, f1 = 32109), p0 = "corge", p1 = "grault"),
...
...
@@ -457,7 +451,7 @@ struct TestInlineDefaults {
unions @1 :TestInlineUnions = (
union0 = f32(f0 = 67, f1 = 8901),
union1 = f128(f0 = 1234567890123, f1 = 4567890123456),
union2 = f
1
p(p0 = "foo"),
union2 = f
8
p(p0 = "foo"),
union3 = f16p(f = (f0 = 98, f1 = 76), p0 = "qux", p1 = "quux"));
lists @2 :TestInlineLists = (
...
...
@@ -470,7 +464,6 @@ struct TestInlineDefaults {
textList = ["foo", "bar", "baz", "qux", "quux", "corge", "grault", "garply"],
structList0 = [(f = void), ()],
structList1 = [(f = true), (f = false), (f = true)],
structList8 = [(f0 = true, f1 = false, f2 = false),
(f0 = false, f1 = true, f2 = false),
(f0 = true, f1 = true, f2 = false),
...
...
@@ -487,7 +480,6 @@ struct TestInlineDefaults {
structList0p = [(f = (f = void), p0 = "foo"), (p0 = "bar"),
(f = (), p0 = "baz"), (p0 = "qux")],
structList1p = [(f = (f = true), p0 = "quux"), (p0 = "corge")],
structList8p = [(f = (f0 = true), p0 = "grault"), (p0 = "garply"), (p0 = "waldo")],
structList16p = [(f = (f0 = 123), p0 = "fred", p1 = "plugh"),
(p0 = "xyzzy", p1 = "thud"),
...
...
compiler/src/Compiler.hs
View file @
5f08f50d
...
...
@@ -682,7 +682,8 @@ packUnion :: UnionDesc -> PackingState -> Map.Map Integer UnionPackingState
packUnion
_
state
unionState
=
(
DataOffset
Size16
offset
,
newState
,
unionState
)
where
(
offset
,
newState
)
=
packData
Size16
state
stripHolesFromFirstWord
Size1
_
=
Size1
-- Nothing left to strip.
stripHolesFromFirstWord
Size1
_
=
error
"can't get this far"
stripHolesFromFirstWord
Size8
_
=
Size8
-- Don't reduce to less than a byte.
stripHolesFromFirstWord
size
holes
=
let
nextSize
=
pred
size
in
case
Map
.
lookup
nextSize
holes
of
...
...
@@ -717,13 +718,12 @@ enforceFixed Nothing sizes = return sizes
enforceFixed
(
Just
(
Located
pos
(
requestedDataSize
,
requestedPointerCount
)))
(
actualDataSize
,
actualPointerCount
)
=
do
validatedRequestedDataSize
<-
case
requestedDataSize
of
1
->
return
DataSection1
8
->
return
DataSection8
16
->
return
DataSection16
32
->
return
DataSection32
s
|
mod
s
64
==
0
->
return
$
DataSectionWords
$
div
s
64
_
->
makeError
pos
$
printf
"Struct data section size must be a whole number of words
\
\
or 0, 1,
8, 16, or 32 bit
s."
\
or 0, 1,
2, 4, or 8 byte
s."
recover
()
$
when
(
dataSectionBits
actualDataSize
>
dataSectionBits
validatedRequestedDataSize
)
$
makeError
pos
$
printf
"Struct data section size is %s which exceeds specified maximum of
\
...
...
compiler/src/CxxGenerator.hs
View file @
5f08f50d
...
...
@@ -161,12 +161,12 @@ fieldOffsetInteger VoidOffset = "0"
fieldOffsetInteger
(
DataOffset
_
o
)
=
show
o
fieldOffsetInteger
(
PointerOffset
o
)
=
show
o
fieldOffsetInteger
(
InlineCompositeOffset
d
p
ds
ps
)
=
let
b
itSize
=
dataSectionBits
ds
b
it
Offset
=
case
ds
of
DataSectionWords
_
->
d
*
64
_
->
d
*
b
it
Size
in
printf
"%d * ::capnproto::B
ITS, %d * ::capnproto::BIT
S,
\
\
%d * ::capnproto::REFERENCES, %d * ::capnproto::REFERENCES"
b
itOffset
bit
Size
p
ps
b
yteSize
=
div
(
dataSectionBits
ds
)
8
b
yte
Offset
=
case
ds
of
DataSectionWords
_
->
d
*
8
_
->
d
*
b
yte
Size
in
printf
"%d * ::capnproto::B
YTES, %d * ::capnproto::BYTE
S,
\
\
%d * ::capnproto::REFERENCES, %d * ::capnproto::REFERENCES"
b
yteOffset
byte
Size
p
ps
isDefaultZero
VoidDesc
=
True
isDefaultZero
(
BoolDesc
b
)
=
not
b
...
...
@@ -266,11 +266,11 @@ fieldContext parent desc = mkStrContext context where
_
->
muNull
context
"fieldInlineDataOffset"
=
case
fieldOffset
desc
of
InlineCompositeOffset
off
_
size
_
->
MuVariable
(
off
*
d
ataSizeInBits
(
dataSectionAlignment
size
)
)
MuVariable
(
off
*
d
iv
(
dataSizeInBits
(
dataSectionAlignment
size
))
8
)
_
->
muNull
context
"fieldInlineDataSize"
=
case
fieldOffset
desc
of
InlineCompositeOffset
_
_
size
_
->
MuVariable
$
d
ataSectionBits
size
MuVariable
$
d
iv
(
dataSectionBits
size
)
8
_
->
muNull
context
"fieldInlinePointerOffset"
=
case
fieldOffset
desc
of
InlineCompositeOffset
_
off
_
_
->
MuVariable
off
...
...
@@ -330,7 +330,7 @@ structContext parent desc = mkStrContext context where
context
"structFields"
=
MuList
$
map
(
fieldContext
context
)
$
structFields
desc
context
"structUnions"
=
MuList
$
map
(
unionContext
context
)
$
structUnions
desc
context
"structDataSize"
=
MuVariable
$
dataSectionWordSize
$
structDataSize
desc
context
"structDataB
its"
=
MuVariable
$
dataSectionBits
$
structDataSize
desc
context
"structDataB
ytes"
=
MuVariable
(
div
(
dataSectionBits
(
structDataSize
desc
))
8
)
context
"structReferenceCount"
=
MuVariable
$
structPointerCount
desc
context
"structNestedEnums"
=
MuList
$
map
(
enumContext
context
)
[
m
|
DescEnum
m
<-
structMembers
desc
]
...
...
compiler/src/Parser.hs
View file @
5f08f50d
...
...
@@ -254,15 +254,14 @@ combineFixedSizes (_, Just _) (FixedPointers _) =
fixedSize
=
do
size
<-
literalInt
(
exactIdentifier
"bit"
>>
return
(
FixedData
size
))
<|>
(
exactIdentifier
"bits"
>>
return
(
FixedData
size
))
<|>
(
exactIdentifier
"byte"
>>
return
(
FixedData
(
8
*
size
)))
-- We do not allow single-bit structs because most CPUs cannot address bits.
(
exactIdentifier
"byte"
>>
return
(
FixedData
(
8
*
size
)))
<|>
(
exactIdentifier
"bytes"
>>
return
(
FixedData
(
8
*
size
)))
<|>
(
exactIdentifier
"word"
>>
return
(
FixedData
(
64
*
size
)))
<|>
(
exactIdentifier
"words"
>>
return
(
FixedData
(
64
*
size
)))
<|>
(
exactIdentifier
"pointer"
>>
return
(
FixedPointers
size
))
<|>
(
exactIdentifier
"pointers"
>>
return
(
FixedPointers
size
))
<?>
"
\"
b
its
\"
,
\"
b
ytes
\"
,
\"
words
\"
, or
\"
pointers
\"
"
<?>
"
\"
bytes
\"
,
\"
words
\"
, or
\"
pointers
\"
"
structLine
::
Maybe
[
Located
Statement
]
->
TokenParser
Declaration
structLine
Nothing
=
usingDecl
<|>
constantDecl
<|>
fieldDecl
<|>
annotationDecl
...
...
compiler/src/Semantics.hs
View file @
5f08f50d
...
...
@@ -263,9 +263,9 @@ dataSizeToSectionSize Size32 = DataSection32
dataSizeToSectionSize
Size64
=
DataSectionWords
1
dataSectionSizeString
DataSection1
=
"1 bits"
dataSectionSizeString
DataSection8
=
"
8 bit
s"
dataSectionSizeString
DataSection16
=
"
16 bit
s"
dataSectionSizeString
DataSection32
=
"
32 bit
s"
dataSectionSizeString
DataSection8
=
"
1 byte
s"
dataSectionSizeString
DataSection16
=
"
2 byte
s"
dataSectionSizeString
DataSection32
=
"
4 byte
s"
dataSectionSizeString
(
DataSectionWords
n
)
=
show
n
++
" words"
data
DataSize
=
Size1
|
Size8
|
Size16
|
Size32
|
Size64
deriving
(
Eq
,
Ord
,
Enum
)
...
...
@@ -319,9 +319,9 @@ fieldSize (InlineStructType StructDesc { structDataSize = ds, structPointerCount
fieldSize
(
InterfaceType
_
)
=
SizeReference
fieldSize
(
ListType
_
)
=
SizeReference
fieldSize
(
InlineListType
element
size
)
=
let
-- We intentionally do not allow single-bit lists because most CPUs cannot address bits.
minDataSectionForBits
bits
|
bits
<=
0
=
DataSectionWords
0
|
bits
<=
1
=
DataSection1
|
bits
<=
8
=
DataSection8
|
bits
<=
16
=
DataSection16
|
bits
<=
32
=
DataSection32
...
...
compiler/src/c++-header.mustache
View file @
5f08f50d
...
...
@@ -70,7 +70,7 @@ struct {{typeFullName}} {
static constexpr ::capnproto::internal::StructSize STRUCT_SIZE =
::capnproto::internal::StructSize(
{{
structDataSize
}}
* ::capnproto::WORDS,
{{
structReferenceCount
}}
* ::capnproto::REFERENCES,
{{
structDataB
its
}}
* ::capnproto::BIT
S);
{{
structDataB
ytes
}}
* ::capnproto::BYTE
S);
{{/
typeStruct
}}
{{#
typeUnion
}}
...
...
@@ -375,7 +375,7 @@ inline {{fieldType}}::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() {
"Must check which() before get()ing a union member.");
{{/
fieldUnion
}}
return
{{
fieldType
}}
::Reader(_reader.getInlineDataListField(
{{
fieldInlineDataOffset
}}
* ::capnproto::B
IT
S,
{{
fieldInlineDataOffset
}}
* ::capnproto::B
YTE
S,
{{
fieldInlineListSize
}}
* ::capnproto::ELEMENTS,
::capnproto::internal::FieldSize::
{{
fieldElementSize
}}
));
}
...
...
@@ -386,8 +386,8 @@ inline {{fieldType}}::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}(
{{
unionTagOffset
}}
* ::capnproto::ELEMENTS,
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
);
{{/
fieldUnion
}}
return
{{
fieldType
}}
::Builder(_builder.initInlineDataListField(
{{
fieldInlineDataOffset
}}
* ::capnproto::B
IT
S,
{{
fieldInlineDataSize
}}
* ::capnproto::B
IT
S,
{{
fieldInlineDataOffset
}}
* ::capnproto::B
YTE
S,
{{
fieldInlineDataSize
}}
* ::capnproto::B
YTE
S,
{{
fieldInlineListSize
}}
* ::capnproto::ELEMENTS,
::capnproto::internal::FieldSize::
{{
fieldElementSize
}}
));
}
...
...
@@ -397,7 +397,7 @@ inline {{fieldType}}::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}()
"Must check which() before get()ing a union member.");
{{/
fieldUnion
}}
return
{{
fieldType
}}
::Builder(_builder.getInlineDataListField(
{{
fieldInlineDataOffset
}}
* ::capnproto::B
IT
S,
{{
fieldInlineDataOffset
}}
* ::capnproto::B
YTE
S,
{{
fieldInlineListSize
}}
* ::capnproto::ELEMENTS,
::capnproto::internal::FieldSize::
{{
fieldElementSize
}}
));
}
...
...
@@ -509,7 +509,7 @@ inline {{fieldType}}::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() {
"Must check which() before get()ing a union member.");
{{/
fieldUnion
}}
return
{{
fieldType
}}
::Reader(_reader.getInlineStructListField(
{{
fieldInlineDataOffset
}}
* ::capnproto::B
IT
S,
{{
fieldInlineDataOffset
}}
* ::capnproto::B
YTE
S,
{{
fieldInlinePointerOffset
}}
* ::capnproto::REFERENCES,
{{
fieldInlineListSize
}}
* ::capnproto::ELEMENTS,
{{
fieldElementType
}}
::STRUCT_SIZE));
...
...
@@ -521,7 +521,7 @@ inline {{fieldType}}::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}(
{{
unionTagOffset
}}
* ::capnproto::ELEMENTS,
{{
unionTitleCase
}}
::
{{
fieldUpperCase
}}
);
{{/
fieldUnion
}}
return
{{
fieldType
}}
::Builder(_builder.initInlineStructListField(
{{
fieldInlineDataOffset
}}
* ::capnproto::B
IT
S,
{{
fieldInlineDataOffset
}}
* ::capnproto::B
YTE
S,
{{
fieldInlinePointerOffset
}}
* ::capnproto::REFERENCES,
{{
fieldInlineListSize
}}
* ::capnproto::ELEMENTS,
{{
fieldElementType
}}
::STRUCT_SIZE));
...
...
@@ -532,7 +532,7 @@ inline {{fieldType}}::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}()
"Must check which() before get()ing a union member.");
{{/
fieldUnion
}}
return
{{
fieldType
}}
::Builder(_builder.getInlineStructListField(
{{
fieldInlineDataOffset
}}
* ::capnproto::B
IT
S,
{{
fieldInlineDataOffset
}}
* ::capnproto::B
YTE
S,
{{
fieldInlinePointerOffset
}}
* ::capnproto::REFERENCES,
{{
fieldInlineListSize
}}
* ::capnproto::ELEMENTS,
{{
fieldElementType
}}
::STRUCT_SIZE));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment