annotate win64-msvc/include/capnp/test.capnp @ 132:42a73082be24

Current Capnp libs and headers from git
author Chris Cannam <cannam@all-day-breakfast.com>
date Thu, 20 Oct 2016 18:15:38 +0100
parents
children
rev   line source
cannam@132 1 # Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors
cannam@132 2 # Licensed under the MIT License:
cannam@132 3 #
cannam@132 4 # Permission is hereby granted, free of charge, to any person obtaining a copy
cannam@132 5 # of this software and associated documentation files (the "Software"), to deal
cannam@132 6 # in the Software without restriction, including without limitation the rights
cannam@132 7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
cannam@132 8 # copies of the Software, and to permit persons to whom the Software is
cannam@132 9 # furnished to do so, subject to the following conditions:
cannam@132 10 #
cannam@132 11 # The above copyright notice and this permission notice shall be included in
cannam@132 12 # all copies or substantial portions of the Software.
cannam@132 13 #
cannam@132 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
cannam@132 15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
cannam@132 16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
cannam@132 17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
cannam@132 18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
cannam@132 19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
cannam@132 20 # THE SOFTWARE.
cannam@132 21
cannam@132 22 @0xd508eebdc2dc42b8;
cannam@132 23
cannam@132 24 using Cxx = import "c++.capnp";
cannam@132 25
cannam@132 26 # Use a namespace likely to cause trouble if the generated code doesn't use fully-qualified
cannam@132 27 # names for stuff in the capnproto namespace.
cannam@132 28 $Cxx.namespace("capnproto_test::capnp::test");
cannam@132 29
cannam@132 30 enum TestEnum {
cannam@132 31 foo @0;
cannam@132 32 bar @1;
cannam@132 33 baz @2;
cannam@132 34 qux @3;
cannam@132 35 quux @4;
cannam@132 36 corge @5;
cannam@132 37 grault @6;
cannam@132 38 garply @7;
cannam@132 39 }
cannam@132 40
cannam@132 41 struct TestAllTypes {
cannam@132 42 voidField @0 : Void;
cannam@132 43 boolField @1 : Bool;
cannam@132 44 int8Field @2 : Int8;
cannam@132 45 int16Field @3 : Int16;
cannam@132 46 int32Field @4 : Int32;
cannam@132 47 int64Field @5 : Int64;
cannam@132 48 uInt8Field @6 : UInt8;
cannam@132 49 uInt16Field @7 : UInt16;
cannam@132 50 uInt32Field @8 : UInt32;
cannam@132 51 uInt64Field @9 : UInt64;
cannam@132 52 float32Field @10 : Float32;
cannam@132 53 float64Field @11 : Float64;
cannam@132 54 textField @12 : Text;
cannam@132 55 dataField @13 : Data;
cannam@132 56 structField @14 : TestAllTypes;
cannam@132 57 enumField @15 : TestEnum;
cannam@132 58 interfaceField @16 : Void; # TODO
cannam@132 59
cannam@132 60 voidList @17 : List(Void);
cannam@132 61 boolList @18 : List(Bool);
cannam@132 62 int8List @19 : List(Int8);
cannam@132 63 int16List @20 : List(Int16);
cannam@132 64 int32List @21 : List(Int32);
cannam@132 65 int64List @22 : List(Int64);
cannam@132 66 uInt8List @23 : List(UInt8);
cannam@132 67 uInt16List @24 : List(UInt16);
cannam@132 68 uInt32List @25 : List(UInt32);
cannam@132 69 uInt64List @26 : List(UInt64);
cannam@132 70 float32List @27 : List(Float32);
cannam@132 71 float64List @28 : List(Float64);
cannam@132 72 textList @29 : List(Text);
cannam@132 73 dataList @30 : List(Data);
cannam@132 74 structList @31 : List(TestAllTypes);
cannam@132 75 enumList @32 : List(TestEnum);
cannam@132 76 interfaceList @33 : List(Void); # TODO
cannam@132 77 }
cannam@132 78
cannam@132 79 struct TestDefaults {
cannam@132 80 voidField @0 : Void = void;
cannam@132 81 boolField @1 : Bool = true;
cannam@132 82 int8Field @2 : Int8 = -123;
cannam@132 83 int16Field @3 : Int16 = -12345;
cannam@132 84 int32Field @4 : Int32 = -12345678;
cannam@132 85 int64Field @5 : Int64 = -123456789012345;
cannam@132 86 uInt8Field @6 : UInt8 = 234;
cannam@132 87 uInt16Field @7 : UInt16 = 45678;
cannam@132 88 uInt32Field @8 : UInt32 = 3456789012;
cannam@132 89 uInt64Field @9 : UInt64 = 12345678901234567890;
cannam@132 90 float32Field @10 : Float32 = 1234.5;
cannam@132 91 float64Field @11 : Float64 = -123e45;
cannam@132 92 textField @12 : Text = "foo";
cannam@132 93 dataField @13 : Data = 0x"62 61 72"; # "bar"
cannam@132 94 structField @14 : TestAllTypes = (
cannam@132 95 voidField = void,
cannam@132 96 boolField = true,
cannam@132 97 int8Field = -12,
cannam@132 98 int16Field = 3456,
cannam@132 99 int32Field = -78901234,
cannam@132 100 int64Field = 56789012345678,
cannam@132 101 uInt8Field = 90,
cannam@132 102 uInt16Field = 1234,
cannam@132 103 uInt32Field = 56789012,
cannam@132 104 uInt64Field = 345678901234567890,
cannam@132 105 float32Field = -1.25e-10,
cannam@132 106 float64Field = 345,
cannam@132 107 textField = "baz",
cannam@132 108 dataField = "qux",
cannam@132 109 structField = (
cannam@132 110 textField = "nested",
cannam@132 111 structField = (textField = "really nested")),
cannam@132 112 enumField = baz,
cannam@132 113 # interfaceField can't have a default
cannam@132 114
cannam@132 115 voidList = [void, void, void],
cannam@132 116 boolList = [false, true, false, true, true],
cannam@132 117 int8List = [12, -34, -0x80, 0x7f],
cannam@132 118 int16List = [1234, -5678, -0x8000, 0x7fff],
cannam@132 119 int32List = [12345678, -90123456, -0x80000000, 0x7fffffff],
cannam@132 120 int64List = [123456789012345, -678901234567890, -0x8000000000000000, 0x7fffffffffffffff],
cannam@132 121 uInt8List = [12, 34, 0, 0xff],
cannam@132 122 uInt16List = [1234, 5678, 0, 0xffff],
cannam@132 123 uInt32List = [12345678, 90123456, 0, 0xffffffff],
cannam@132 124 uInt64List = [123456789012345, 678901234567890, 0, 0xffffffffffffffff],
cannam@132 125 float32List = [0, 1234567, 1e37, -1e37, 1e-37, -1e-37],
cannam@132 126 float64List = [0, 123456789012345, 1e306, -1e306, 1e-306, -1e-306],
cannam@132 127 textList = ["quux", "corge", "grault"],
cannam@132 128 dataList = ["garply", "waldo", "fred"],
cannam@132 129 structList = [
cannam@132 130 (textField = "x structlist 1"),
cannam@132 131 (textField = "x structlist 2"),
cannam@132 132 (textField = "x structlist 3")],
cannam@132 133 enumList = [qux, bar, grault]
cannam@132 134 # interfaceList can't have a default
cannam@132 135 );
cannam@132 136 enumField @15 : TestEnum = corge;
cannam@132 137 interfaceField @16 : Void; # TODO
cannam@132 138
cannam@132 139 voidList @17 : List(Void) = [void, void, void, void, void, void];
cannam@132 140 boolList @18 : List(Bool) = [true, false, false, true];
cannam@132 141 int8List @19 : List(Int8) = [111, -111];
cannam@132 142 int16List @20 : List(Int16) = [11111, -11111];
cannam@132 143 int32List @21 : List(Int32) = [111111111, -111111111];
cannam@132 144 int64List @22 : List(Int64) = [1111111111111111111, -1111111111111111111];
cannam@132 145 uInt8List @23 : List(UInt8) = [111, 222] ;
cannam@132 146 uInt16List @24 : List(UInt16) = [33333, 44444];
cannam@132 147 uInt32List @25 : List(UInt32) = [3333333333];
cannam@132 148 uInt64List @26 : List(UInt64) = [11111111111111111111];
cannam@132 149 float32List @27 : List(Float32) = [5555.5, inf, -inf, nan];
cannam@132 150 float64List @28 : List(Float64) = [7777.75, inf, -inf, nan];
cannam@132 151 textList @29 : List(Text) = ["plugh", "xyzzy", "thud"];
cannam@132 152 dataList @30 : List(Data) = ["oops", "exhausted", "rfc3092"];
cannam@132 153 structList @31 : List(TestAllTypes) = [
cannam@132 154 (textField = "structlist 1"),
cannam@132 155 (textField = "structlist 2"),
cannam@132 156 (textField = "structlist 3")];
cannam@132 157 enumList @32 : List(TestEnum) = [foo, garply];
cannam@132 158 interfaceList @33 : List(Void); # TODO
cannam@132 159 }
cannam@132 160
cannam@132 161 struct TestAnyPointer {
cannam@132 162 anyPointerField @0 :AnyPointer;
cannam@132 163
cannam@132 164 # Do not add any other fields here! Some tests rely on anyPointerField being the last pointer
cannam@132 165 # in the struct.
cannam@132 166 }
cannam@132 167
cannam@132 168 struct TestAnyOthers {
cannam@132 169 anyStructField @0 :AnyStruct;
cannam@132 170 anyListField @1 :AnyList;
cannam@132 171 capabilityField @2 :Capability;
cannam@132 172 }
cannam@132 173
cannam@132 174 struct TestOutOfOrder {
cannam@132 175 foo @3 :Text;
cannam@132 176 bar @2 :Text;
cannam@132 177 baz @8 :Text;
cannam@132 178 qux @0 :Text;
cannam@132 179 quux @6 :Text;
cannam@132 180 corge @4 :Text;
cannam@132 181 grault @1 :Text;
cannam@132 182 garply @7 :Text;
cannam@132 183 waldo @5 :Text;
cannam@132 184 }
cannam@132 185
cannam@132 186 struct TestUnion {
cannam@132 187 union0 @0! :union {
cannam@132 188 # Pack union 0 under ideal conditions: there is no unused padding space prior to it.
cannam@132 189 u0f0s0 @4: Void;
cannam@132 190 u0f0s1 @5: Bool;
cannam@132 191 u0f0s8 @6: Int8;
cannam@132 192 u0f0s16 @7: Int16;
cannam@132 193 u0f0s32 @8: Int32;
cannam@132 194 u0f0s64 @9: Int64;
cannam@132 195 u0f0sp @10: Text;
cannam@132 196
cannam@132 197 # Pack more stuff into union0 -- should go in same space.
cannam@132 198 u0f1s0 @11: Void;
cannam@132 199 u0f1s1 @12: Bool;
cannam@132 200 u0f1s8 @13: Int8;
cannam@132 201 u0f1s16 @14: Int16;
cannam@132 202 u0f1s32 @15: Int32;
cannam@132 203 u0f1s64 @16: Int64;
cannam@132 204 u0f1sp @17: Text;
cannam@132 205 }
cannam@132 206
cannam@132 207 # Pack one bit in order to make pathological situation for union1.
cannam@132 208 bit0 @18: Bool;
cannam@132 209
cannam@132 210 union1 @1! :union {
cannam@132 211 # Pack pathologically bad case. Each field takes up new space.
cannam@132 212 u1f0s0 @19: Void;
cannam@132 213 u1f0s1 @20: Bool;
cannam@132 214 u1f1s1 @21: Bool;
cannam@132 215 u1f0s8 @22: Int8;
cannam@132 216 u1f1s8 @23: Int8;
cannam@132 217 u1f0s16 @24: Int16;
cannam@132 218 u1f1s16 @25: Int16;
cannam@132 219 u1f0s32 @26: Int32;
cannam@132 220 u1f1s32 @27: Int32;
cannam@132 221 u1f0s64 @28: Int64;
cannam@132 222 u1f1s64 @29: Int64;
cannam@132 223 u1f0sp @30: Text;
cannam@132 224 u1f1sp @31: Text;
cannam@132 225
cannam@132 226 # Pack more stuff into union1 -- each should go into the same space as corresponding u1f0s*.
cannam@132 227 u1f2s0 @32: Void;
cannam@132 228 u1f2s1 @33: Bool;
cannam@132 229 u1f2s8 @34: Int8;
cannam@132 230 u1f2s16 @35: Int16;
cannam@132 231 u1f2s32 @36: Int32;
cannam@132 232 u1f2s64 @37: Int64;
cannam@132 233 u1f2sp @38: Text;
cannam@132 234 }
cannam@132 235
cannam@132 236 # Fill in the rest of that bitfield from earlier.
cannam@132 237 bit2 @39: Bool;
cannam@132 238 bit3 @40: Bool;
cannam@132 239 bit4 @41: Bool;
cannam@132 240 bit5 @42: Bool;
cannam@132 241 bit6 @43: Bool;
cannam@132 242 bit7 @44: Bool;
cannam@132 243
cannam@132 244 # Interleave two unions to be really annoying.
cannam@132 245 # Also declare in reverse order to make sure union discriminant values are sorted by field number
cannam@132 246 # and not by declaration order.
cannam@132 247 union2 @2! :union {
cannam@132 248 u2f0s64 @54: Int64;
cannam@132 249 u2f0s32 @52: Int32;
cannam@132 250 u2f0s16 @50: Int16;
cannam@132 251 u2f0s8 @47: Int8;
cannam@132 252 u2f0s1 @45: Bool;
cannam@132 253 }
cannam@132 254
cannam@132 255 union3 @3! :union {
cannam@132 256 u3f0s64 @55: Int64;
cannam@132 257 u3f0s32 @53: Int32;
cannam@132 258 u3f0s16 @51: Int16;
cannam@132 259 u3f0s8 @48: Int8;
cannam@132 260 u3f0s1 @46: Bool;
cannam@132 261 }
cannam@132 262
cannam@132 263 byte0 @49: UInt8;
cannam@132 264 }
cannam@132 265
cannam@132 266 struct TestUnnamedUnion {
cannam@132 267 before @0 :Text;
cannam@132 268
cannam@132 269 union {
cannam@132 270 foo @1 :UInt16;
cannam@132 271 bar @3 :UInt32;
cannam@132 272 }
cannam@132 273
cannam@132 274 middle @2 :UInt16;
cannam@132 275
cannam@132 276 after @4 :Text;
cannam@132 277 }
cannam@132 278
cannam@132 279 struct TestUnionInUnion {
cannam@132 280 # There is no reason to ever do this.
cannam@132 281 outer :union {
cannam@132 282 inner :union {
cannam@132 283 foo @0 :Int32;
cannam@132 284 bar @1 :Int32;
cannam@132 285 }
cannam@132 286 baz @2 :Int32;
cannam@132 287 }
cannam@132 288 }
cannam@132 289
cannam@132 290 struct TestGroups {
cannam@132 291 groups :union {
cannam@132 292 foo :group {
cannam@132 293 corge @0 :Int32;
cannam@132 294 grault @2 :Int64;
cannam@132 295 garply @8 :Text;
cannam@132 296 }
cannam@132 297 bar :group {
cannam@132 298 corge @3 :Int32;
cannam@132 299 grault @4 :Text;
cannam@132 300 garply @5 :Int64;
cannam@132 301 }
cannam@132 302 baz :group {
cannam@132 303 corge @1 :Int32;
cannam@132 304 grault @6 :Text;
cannam@132 305 garply @7 :Text;
cannam@132 306 }
cannam@132 307 }
cannam@132 308 }
cannam@132 309
cannam@132 310 struct TestInterleavedGroups {
cannam@132 311 group1 :group {
cannam@132 312 foo @0 :UInt32;
cannam@132 313 bar @2 :UInt64;
cannam@132 314 union {
cannam@132 315 qux @4 :UInt16;
cannam@132 316 corge :group {
cannam@132 317 grault @6 :UInt64;
cannam@132 318 garply @8 :UInt16;
cannam@132 319 plugh @14 :Text;
cannam@132 320 xyzzy @16 :Text;
cannam@132 321 }
cannam@132 322
cannam@132 323 fred @12 :Text;
cannam@132 324 }
cannam@132 325
cannam@132 326 waldo @10 :Text;
cannam@132 327 }
cannam@132 328
cannam@132 329 group2 :group {
cannam@132 330 foo @1 :UInt32;
cannam@132 331 bar @3 :UInt64;
cannam@132 332 union {
cannam@132 333 qux @5 :UInt16;
cannam@132 334 corge :group {
cannam@132 335 grault @7 :UInt64;
cannam@132 336 garply @9 :UInt16;
cannam@132 337 plugh @15 :Text;
cannam@132 338 xyzzy @17 :Text;
cannam@132 339 }
cannam@132 340
cannam@132 341 fred @13 :Text;
cannam@132 342 }
cannam@132 343
cannam@132 344 waldo @11 :Text;
cannam@132 345 }
cannam@132 346 }
cannam@132 347
cannam@132 348 struct TestUnionDefaults {
cannam@132 349 s16s8s64s8Set @0 :TestUnion =
cannam@132 350 (union0 = (u0f0s16 = 321), union1 = (u1f0s8 = 123), union2 = (u2f0s64 = 12345678901234567),
cannam@132 351 union3 = (u3f0s8 = 55));
cannam@132 352 s0sps1s32Set @1 :TestUnion =
cannam@132 353 (union0 = (u0f1s0 = void), union1 = (u1f0sp = "foo"), union2 = (u2f0s1 = true),
cannam@132 354 union3 = (u3f0s32 = 12345678));
cannam@132 355
cannam@132 356 unnamed1 @2 :TestUnnamedUnion = (foo = 123);
cannam@132 357 unnamed2 @3 :TestUnnamedUnion = (bar = 321, before = "foo", after = "bar");
cannam@132 358 }
cannam@132 359
cannam@132 360 struct TestNestedTypes {
cannam@132 361 enum NestedEnum {
cannam@132 362 foo @0;
cannam@132 363 bar @1;
cannam@132 364 }
cannam@132 365
cannam@132 366 struct NestedStruct {
cannam@132 367 enum NestedEnum {
cannam@132 368 baz @0;
cannam@132 369 qux @1;
cannam@132 370 quux @2;
cannam@132 371 }
cannam@132 372
cannam@132 373 outerNestedEnum @0 :TestNestedTypes.NestedEnum = bar;
cannam@132 374 innerNestedEnum @1 :NestedEnum = quux;
cannam@132 375 }
cannam@132 376
cannam@132 377 nestedStruct @0 :NestedStruct;
cannam@132 378
cannam@132 379 outerNestedEnum @1 :NestedEnum = bar;
cannam@132 380 innerNestedEnum @2 :NestedStruct.NestedEnum = quux;
cannam@132 381 }
cannam@132 382
cannam@132 383 struct TestUsing {
cannam@132 384 using OuterNestedEnum = TestNestedTypes.NestedEnum;
cannam@132 385 using TestNestedTypes.NestedStruct.NestedEnum;
cannam@132 386
cannam@132 387 outerNestedEnum @1 :OuterNestedEnum = bar;
cannam@132 388 innerNestedEnum @0 :NestedEnum = quux;
cannam@132 389 }
cannam@132 390
cannam@132 391 struct TestLists {
cannam@132 392 # Small structs, when encoded as list, will be encoded as primitive lists rather than struct
cannam@132 393 # lists, to save space.
cannam@132 394 struct Struct0 { f @0 :Void; }
cannam@132 395 struct Struct1 { f @0 :Bool; }
cannam@132 396 struct Struct8 { f @0 :UInt8; }
cannam@132 397 struct Struct16 { f @0 :UInt16; }
cannam@132 398 struct Struct32 { f @0 :UInt32; }
cannam@132 399 struct Struct64 { f @0 :UInt64; }
cannam@132 400 struct StructP { f @0 :Text; }
cannam@132 401
cannam@132 402 # Versions of the above which cannot be encoded as primitive lists.
cannam@132 403 struct Struct0c { f @0 :Void; pad @1 :Text; }
cannam@132 404 struct Struct1c { f @0 :Bool; pad @1 :Text; }
cannam@132 405 struct Struct8c { f @0 :UInt8; pad @1 :Text; }
cannam@132 406 struct Struct16c { f @0 :UInt16; pad @1 :Text; }
cannam@132 407 struct Struct32c { f @0 :UInt32; pad @1 :Text; }
cannam@132 408 struct Struct64c { f @0 :UInt64; pad @1 :Text; }
cannam@132 409 struct StructPc { f @0 :Text; pad @1 :UInt64; }
cannam@132 410
cannam@132 411 list0 @0 :List(Struct0);
cannam@132 412 list1 @1 :List(Struct1);
cannam@132 413 list8 @2 :List(Struct8);
cannam@132 414 list16 @3 :List(Struct16);
cannam@132 415 list32 @4 :List(Struct32);
cannam@132 416 list64 @5 :List(Struct64);
cannam@132 417 listP @6 :List(StructP);
cannam@132 418
cannam@132 419 int32ListList @7 :List(List(Int32));
cannam@132 420 textListList @8 :List(List(Text));
cannam@132 421 structListList @9 :List(List(TestAllTypes));
cannam@132 422 }
cannam@132 423
cannam@132 424 struct TestFieldZeroIsBit {
cannam@132 425 bit @0 :Bool;
cannam@132 426 secondBit @1 :Bool = true;
cannam@132 427 thirdField @2 :UInt8 = 123;
cannam@132 428 }
cannam@132 429
cannam@132 430 struct TestListDefaults {
cannam@132 431 lists @0 :TestLists = (
cannam@132 432 list0 = [(f = void), (f = void)],
cannam@132 433 list1 = [(f = true), (f = false), (f = true), (f = true)],
cannam@132 434 list8 = [(f = 123), (f = 45)],
cannam@132 435 list16 = [(f = 12345), (f = 6789)],
cannam@132 436 list32 = [(f = 123456789), (f = 234567890)],
cannam@132 437 list64 = [(f = 1234567890123456), (f = 2345678901234567)],
cannam@132 438 listP = [(f = "foo"), (f = "bar")],
cannam@132 439 int32ListList = [[1, 2, 3], [4, 5], [12341234]],
cannam@132 440 textListList = [["foo", "bar"], ["baz"], ["qux", "corge"]],
cannam@132 441 structListList = [[(int32Field = 123), (int32Field = 456)], [(int32Field = 789)]]);
cannam@132 442 }
cannam@132 443
cannam@132 444 struct TestLateUnion {
cannam@132 445 # Test what happens if the unions are not the first ordinals in the struct. At one point this
cannam@132 446 # was broken for the dynamic API.
cannam@132 447
cannam@132 448 foo @0 :Int32;
cannam@132 449 bar @1 :Text;
cannam@132 450 baz @2 :Int16;
cannam@132 451
cannam@132 452 theUnion @3! :union {
cannam@132 453 qux @4 :Text;
cannam@132 454 corge @5 :List(Int32);
cannam@132 455 grault @6 :Float32;
cannam@132 456 }
cannam@132 457
cannam@132 458 anotherUnion @7! :union {
cannam@132 459 qux @8 :Text;
cannam@132 460 corge @9 :List(Int32);
cannam@132 461 grault @10 :Float32;
cannam@132 462 }
cannam@132 463 }
cannam@132 464
cannam@132 465 struct TestOldVersion {
cannam@132 466 # A subset of TestNewVersion.
cannam@132 467 old1 @0 :Int64;
cannam@132 468 old2 @1 :Text;
cannam@132 469 old3 @2 :TestOldVersion;
cannam@132 470 }
cannam@132 471
cannam@132 472 struct TestNewVersion {
cannam@132 473 # A superset of TestOldVersion.
cannam@132 474 old1 @0 :Int64;
cannam@132 475 old2 @1 :Text;
cannam@132 476 old3 @2 :TestNewVersion;
cannam@132 477 new1 @3 :Int64 = 987;
cannam@132 478 new2 @4 :Text = "baz";
cannam@132 479 }
cannam@132 480
cannam@132 481 struct TestOldUnionVersion {
cannam@132 482 union {
cannam@132 483 a @0 :Void;
cannam@132 484 b @1 :UInt64;
cannam@132 485 }
cannam@132 486 }
cannam@132 487
cannam@132 488 struct TestNewUnionVersion {
cannam@132 489 union {
cannam@132 490 a :union {
cannam@132 491 a0 @0 :Void;
cannam@132 492 a1 @2 :UInt64;
cannam@132 493 }
cannam@132 494 b @1 :UInt64;
cannam@132 495 }
cannam@132 496 }
cannam@132 497
cannam@132 498 struct TestStructUnion {
cannam@132 499 un @0! :union {
cannam@132 500 struct @1 :SomeStruct;
cannam@132 501 object @2 :TestAnyPointer;
cannam@132 502 }
cannam@132 503
cannam@132 504 struct SomeStruct {
cannam@132 505 someText @0 :Text;
cannam@132 506 moreText @1 :Text;
cannam@132 507 }
cannam@132 508 }
cannam@132 509
cannam@132 510 struct TestPrintInlineStructs {
cannam@132 511 someText @0 :Text;
cannam@132 512
cannam@132 513 structList @1 :List(InlineStruct);
cannam@132 514 struct InlineStruct {
cannam@132 515 int32Field @0 :Int32;
cannam@132 516 textField @1 :Text;
cannam@132 517 }
cannam@132 518 }
cannam@132 519
cannam@132 520 struct TestWholeFloatDefault {
cannam@132 521 # At one point, these failed to compile in C++ because it would produce literals like "123f",
cannam@132 522 # which is not valid; it needs to be "123.0f".
cannam@132 523 field @0 :Float32 = 123;
cannam@132 524 bigField @1 :Float32 = 2e30;
cannam@132 525 const constant :Float32 = 456;
cannam@132 526 const bigConstant :Float32 = 4e30;
cannam@132 527 }
cannam@132 528
cannam@132 529 struct TestGenerics(Foo, Bar) {
cannam@132 530 foo @0 :Foo;
cannam@132 531 rev @1 :TestGenerics(Bar, Foo);
cannam@132 532
cannam@132 533 union {
cannam@132 534 uv @2:Void;
cannam@132 535 ug :group {
cannam@132 536 ugfoo @3:Int32;
cannam@132 537 }
cannam@132 538 }
cannam@132 539
cannam@132 540 struct Inner {
cannam@132 541 foo @0 :Foo;
cannam@132 542 bar @1 :Bar;
cannam@132 543 }
cannam@132 544
cannam@132 545 struct Inner2(Baz) {
cannam@132 546 bar @0 :Bar;
cannam@132 547 baz @1 :Baz;
cannam@132 548 innerBound @2 :Inner;
cannam@132 549 innerUnbound @3 :TestGenerics.Inner;
cannam@132 550
cannam@132 551 struct DeepNest(Qux) {
cannam@132 552 foo @0 :Foo;
cannam@132 553 bar @1 :Bar;
cannam@132 554 baz @2 :Baz;
cannam@132 555 qux @3 :Qux;
cannam@132 556 }
cannam@132 557 }
cannam@132 558
cannam@132 559 interface Interface(Qux) {
cannam@132 560 call @0 Inner2(Text) -> (qux :Qux, gen :TestGenerics(TestAllTypes, TestAnyPointer));
cannam@132 561 }
cannam@132 562
cannam@132 563 annotation ann(struct) :Foo;
cannam@132 564
cannam@132 565 using AliasFoo = Foo;
cannam@132 566 using AliasInner = Inner;
cannam@132 567 using AliasInner2 = Inner2;
cannam@132 568 using AliasInner2Text = Inner2(Text);
cannam@132 569 using AliasRev = TestGenerics(Bar, Foo);
cannam@132 570
cannam@132 571 struct UseAliases {
cannam@132 572 foo @0 :AliasFoo;
cannam@132 573 inner @1 :AliasInner;
cannam@132 574 inner2 @2 :AliasInner2;
cannam@132 575 inner2Bind @3 :AliasInner2(Text);
cannam@132 576 inner2Text @4 :AliasInner2Text;
cannam@132 577 revFoo @5 :AliasRev.AliasFoo;
cannam@132 578 }
cannam@132 579 }
cannam@132 580
cannam@132 581 struct TestGenericsWrapper(Foo, Bar) {
cannam@132 582 value @0 :TestGenerics(Foo, Bar);
cannam@132 583 }
cannam@132 584
cannam@132 585 struct TestGenericsWrapper2 {
cannam@132 586 value @0 :TestGenericsWrapper(Text, TestAllTypes);
cannam@132 587 }
cannam@132 588
cannam@132 589 interface TestImplicitMethodParams {
cannam@132 590 call @0 [T, U] (foo :T, bar :U) -> TestGenerics(T, U);
cannam@132 591 }
cannam@132 592
cannam@132 593 interface TestImplicitMethodParamsInGeneric(V) {
cannam@132 594 call @0 [T, U] (foo :T, bar :U) -> TestGenerics(T, U);
cannam@132 595 }
cannam@132 596
cannam@132 597 struct TestGenericsUnion(Foo, Bar) {
cannam@132 598 # At one point this failed to compile.
cannam@132 599
cannam@132 600 union {
cannam@132 601 foo @0 :Foo;
cannam@132 602 bar @1 :Bar;
cannam@132 603 }
cannam@132 604 }
cannam@132 605
cannam@132 606 struct TestUseGenerics $TestGenerics(Text, Data).ann("foo") {
cannam@132 607 basic @0 :TestGenerics(TestAllTypes, TestAnyPointer);
cannam@132 608 inner @1 :TestGenerics(TestAllTypes, TestAnyPointer).Inner;
cannam@132 609 inner2 @2 :TestGenerics(TestAllTypes, TestAnyPointer).Inner2(Text);
cannam@132 610 unspecified @3 :TestGenerics;
cannam@132 611 unspecifiedInner @4 :TestGenerics.Inner2(Text);
cannam@132 612 wrapper @8 :TestGenericsWrapper(TestAllTypes, TestAnyPointer);
cannam@132 613 cap @18 :TestGenerics(TestInterface, Text);
cannam@132 614 genericCap @19 :TestGenerics(TestAllTypes, List(UInt32)).Interface(Data);
cannam@132 615
cannam@132 616 default @5 :TestGenerics(TestAllTypes, Text) =
cannam@132 617 (foo = (int16Field = 123), rev = (foo = "text", rev = (foo = (int16Field = 321))));
cannam@132 618 defaultInner @6 :TestGenerics(TestAllTypes, Text).Inner =
cannam@132 619 (foo = (int16Field = 123), bar = "text");
cannam@132 620 defaultUser @7 :TestUseGenerics = (basic = (foo = (int16Field = 123)));
cannam@132 621 defaultWrapper @9 :TestGenericsWrapper(Text, TestAllTypes) =
cannam@132 622 (value = (foo = "text", rev = (foo = (int16Field = 321))));
cannam@132 623 defaultWrapper2 @10 :TestGenericsWrapper2 =
cannam@132 624 (value = (value = (foo = "text", rev = (foo = (int16Field = 321)))));
cannam@132 625
cannam@132 626 aliasFoo @11 :TestGenerics(TestAllTypes, TestAnyPointer).AliasFoo = (int16Field = 123);
cannam@132 627 aliasInner @12 :TestGenerics(TestAllTypes, TestAnyPointer).AliasInner
cannam@132 628 = (foo = (int16Field = 123));
cannam@132 629 aliasInner2 @13 :TestGenerics(TestAllTypes, TestAnyPointer).AliasInner2
cannam@132 630 = (innerBound = (foo = (int16Field = 123)));
cannam@132 631 aliasInner2Bind @14 :TestGenerics(TestAllTypes, TestAnyPointer).AliasInner2(List(UInt32))
cannam@132 632 = (baz = [12, 34], innerBound = (foo = (int16Field = 123)));
cannam@132 633 aliasInner2Text @15 :TestGenerics(TestAllTypes, TestAnyPointer).AliasInner2Text
cannam@132 634 = (baz = "text", innerBound = (foo = (int16Field = 123)));
cannam@132 635 aliasRev @16 :TestGenerics(TestAnyPointer, Text).AliasRev.AliasFoo = "text";
cannam@132 636
cannam@132 637 useAliases @17 :TestGenerics(TestAllTypes, List(UInt32)).UseAliases = (
cannam@132 638 foo = (int16Field = 123),
cannam@132 639 inner = (foo = (int16Field = 123)),
cannam@132 640 inner2 = (innerBound = (foo = (int16Field = 123))),
cannam@132 641 inner2Bind = (baz = "text", innerBound = (foo = (int16Field = 123))),
cannam@132 642 inner2Text = (baz = "text", innerBound = (foo = (int16Field = 123))),
cannam@132 643 revFoo = [12, 34, 56]);
cannam@132 644 }
cannam@132 645
cannam@132 646 struct TestEmptyStruct {}
cannam@132 647
cannam@132 648 struct TestConstants {
cannam@132 649 const voidConst :Void = void;
cannam@132 650 const boolConst :Bool = true;
cannam@132 651 const int8Const :Int8 = -123;
cannam@132 652 const int16Const :Int16 = -12345;
cannam@132 653 const int32Const :Int32 = -12345678;
cannam@132 654 const int64Const :Int64 = -123456789012345;
cannam@132 655 const uint8Const :UInt8 = 234;
cannam@132 656 const uint16Const :UInt16 = 45678;
cannam@132 657 const uint32Const :UInt32 = 3456789012;
cannam@132 658 const uint64Const :UInt64 = 12345678901234567890;
cannam@132 659 const float32Const :Float32 = 1234.5;
cannam@132 660 const float64Const :Float64 = -123e45;
cannam@132 661 const textConst :Text = "foo";
cannam@132 662 const dataConst :Data = "bar";
cannam@132 663 const structConst :TestAllTypes = (
cannam@132 664 voidField = void,
cannam@132 665 boolField = true,
cannam@132 666 int8Field = -12,
cannam@132 667 int16Field = 3456,
cannam@132 668 int32Field = -78901234,
cannam@132 669 int64Field = 56789012345678,
cannam@132 670 uInt8Field = 90,
cannam@132 671 uInt16Field = 1234,
cannam@132 672 uInt32Field = 56789012,
cannam@132 673 uInt64Field = 345678901234567890,
cannam@132 674 float32Field = -1.25e-10,
cannam@132 675 float64Field = 345,
cannam@132 676 textField = "baz",
cannam@132 677 dataField = "qux",
cannam@132 678 structField = (
cannam@132 679 textField = "nested",
cannam@132 680 structField = (textField = "really nested")),
cannam@132 681 enumField = baz,
cannam@132 682 # interfaceField can't have a default
cannam@132 683
cannam@132 684 voidList = [void, void, void],
cannam@132 685 boolList = [false, true, false, true, true],
cannam@132 686 int8List = [12, -34, -0x80, 0x7f],
cannam@132 687 int16List = [1234, -5678, -0x8000, 0x7fff],
cannam@132 688 int32List = [12345678, -90123456, -0x80000000, 0x7fffffff],
cannam@132 689 int64List = [123456789012345, -678901234567890, -0x8000000000000000, 0x7fffffffffffffff],
cannam@132 690 uInt8List = [12, 34, 0, 0xff],
cannam@132 691 uInt16List = [1234, 5678, 0, 0xffff],
cannam@132 692 uInt32List = [12345678, 90123456, 0, 0xffffffff],
cannam@132 693 uInt64List = [123456789012345, 678901234567890, 0, 0xffffffffffffffff],
cannam@132 694 float32List = [0, 1234567, 1e37, -1e37, 1e-37, -1e-37],
cannam@132 695 float64List = [0, 123456789012345, 1e306, -1e306, 1e-306, -1e-306],
cannam@132 696 textList = ["quux", "corge", "grault"],
cannam@132 697 dataList = ["garply", "waldo", "fred"],
cannam@132 698 structList = [
cannam@132 699 (textField = "x structlist 1"),
cannam@132 700 (textField = "x structlist 2"),
cannam@132 701 (textField = "x structlist 3")],
cannam@132 702 enumList = [qux, bar, grault]
cannam@132 703 # interfaceList can't have a default
cannam@132 704 );
cannam@132 705 const enumConst :TestEnum = corge;
cannam@132 706
cannam@132 707 const voidListConst :List(Void) = [void, void, void, void, void, void];
cannam@132 708 const boolListConst :List(Bool) = [true, false, false, true];
cannam@132 709 const int8ListConst :List(Int8) = [111, -111];
cannam@132 710 const int16ListConst :List(Int16) = [11111, -11111];
cannam@132 711 const int32ListConst :List(Int32) = [111111111, -111111111];
cannam@132 712 const int64ListConst :List(Int64) = [1111111111111111111, -1111111111111111111];
cannam@132 713 const uint8ListConst :List(UInt8) = [111, 222] ;
cannam@132 714 const uint16ListConst :List(UInt16) = [33333, 44444];
cannam@132 715 const uint32ListConst :List(UInt32) = [3333333333];
cannam@132 716 const uint64ListConst :List(UInt64) = [11111111111111111111];
cannam@132 717 const float32ListConst :List(Float32) = [5555.5, inf, -inf, nan];
cannam@132 718 const float64ListConst :List(Float64) = [7777.75, inf, -inf, nan];
cannam@132 719 const textListConst :List(Text) = ["plugh", "xyzzy", "thud"];
cannam@132 720 const dataListConst :List(Data) = ["oops", "exhausted", "rfc3092"];
cannam@132 721 const structListConst :List(TestAllTypes) = [
cannam@132 722 (textField = "structlist 1"),
cannam@132 723 (textField = "structlist 2"),
cannam@132 724 (textField = "structlist 3")];
cannam@132 725 const enumListConst :List(TestEnum) = [foo, garply];
cannam@132 726 }
cannam@132 727
cannam@132 728 const globalInt :UInt32 = 12345;
cannam@132 729 const globalText :Text = "foobar";
cannam@132 730 const globalStruct :TestAllTypes = (int32Field = 54321);
cannam@132 731 const globalPrintableStruct :TestPrintInlineStructs = (someText = "foo");
cannam@132 732 const derivedConstant :TestAllTypes = (
cannam@132 733 uInt32Field = .globalInt,
cannam@132 734 textField = TestConstants.textConst,
cannam@132 735 structField = TestConstants.structConst,
cannam@132 736 int16List = TestConstants.int16ListConst,
cannam@132 737 structList = TestConstants.structListConst);
cannam@132 738
cannam@132 739 const genericConstant :TestGenerics(TestAllTypes, Text) =
cannam@132 740 (foo = (int16Field = 123), rev = (foo = "text", rev = (foo = (int16Field = 321))));
cannam@132 741
cannam@132 742 const embeddedData :Data = embed "testdata/packed";
cannam@132 743 const embeddedText :Text = embed "testdata/short.txt";
cannam@132 744 const embeddedStruct :TestAllTypes = embed "testdata/binary";
cannam@132 745
cannam@132 746 interface TestInterface {
cannam@132 747 foo @0 (i :UInt32, j :Bool) -> (x :Text);
cannam@132 748 bar @1 () -> ();
cannam@132 749 baz @2 (s: TestAllTypes);
cannam@132 750 }
cannam@132 751
cannam@132 752 interface TestExtends extends(TestInterface) {
cannam@132 753 qux @0 ();
cannam@132 754 corge @1 TestAllTypes -> ();
cannam@132 755 grault @2 () -> TestAllTypes;
cannam@132 756 }
cannam@132 757
cannam@132 758 interface TestExtends2 extends(TestExtends) {}
cannam@132 759
cannam@132 760 interface TestPipeline {
cannam@132 761 getCap @0 (n: UInt32, inCap :TestInterface) -> (s: Text, outBox :Box);
cannam@132 762 testPointers @1 (cap :TestInterface, obj :AnyPointer, list :List(TestInterface)) -> ();
cannam@132 763
cannam@132 764 struct Box {
cannam@132 765 cap @0 :TestInterface;
cannam@132 766 }
cannam@132 767 }
cannam@132 768
cannam@132 769 interface TestCallOrder {
cannam@132 770 getCallSequence @0 (expected: UInt32) -> (n: UInt32);
cannam@132 771 # First call returns 0, next returns 1, ...
cannam@132 772 #
cannam@132 773 # The input `expected` is ignored but useful for disambiguating debug logs.
cannam@132 774 }
cannam@132 775
cannam@132 776 interface TestTailCallee {
cannam@132 777 struct TailResult {
cannam@132 778 i @0 :UInt32;
cannam@132 779 t @1 :Text;
cannam@132 780 c @2 :TestCallOrder;
cannam@132 781 }
cannam@132 782
cannam@132 783 foo @0 (i :Int32, t :Text) -> TailResult;
cannam@132 784 }
cannam@132 785
cannam@132 786 interface TestTailCaller {
cannam@132 787 foo @0 (i :Int32, callee :TestTailCallee) -> TestTailCallee.TailResult;
cannam@132 788 }
cannam@132 789
cannam@132 790 interface TestHandle {}
cannam@132 791
cannam@132 792 interface TestMoreStuff extends(TestCallOrder) {
cannam@132 793 # Catch-all type that contains lots of testing methods.
cannam@132 794
cannam@132 795 callFoo @0 (cap :TestInterface) -> (s: Text);
cannam@132 796 # Call `cap.foo()`, check the result, and return "bar".
cannam@132 797
cannam@132 798 callFooWhenResolved @1 (cap :TestInterface) -> (s: Text);
cannam@132 799 # Like callFoo but waits for `cap` to resolve first.
cannam@132 800
cannam@132 801 neverReturn @2 (cap :TestInterface) -> (capCopy :TestInterface);
cannam@132 802 # Doesn't return. You should cancel it.
cannam@132 803
cannam@132 804 hold @3 (cap :TestInterface) -> ();
cannam@132 805 # Returns immediately but holds on to the capability.
cannam@132 806
cannam@132 807 callHeld @4 () -> (s: Text);
cannam@132 808 # Calls the capability previously held using `hold` (and keeps holding it).
cannam@132 809
cannam@132 810 getHeld @5 () -> (cap :TestInterface);
cannam@132 811 # Returns the capability previously held using `hold` (and keeps holding it).
cannam@132 812
cannam@132 813 echo @6 (cap :TestCallOrder) -> (cap :TestCallOrder);
cannam@132 814 # Just returns the input cap.
cannam@132 815
cannam@132 816 expectCancel @7 (cap :TestInterface) -> ();
cannam@132 817 # evalLater()-loops forever, holding `cap`. Must be canceled.
cannam@132 818
cannam@132 819 methodWithDefaults @8 (a :Text, b :UInt32 = 123, c :Text = "foo") -> (d :Text, e :Text = "bar");
cannam@132 820
cannam@132 821 getHandle @9 () -> (handle :TestHandle);
cannam@132 822 # Get a new handle. Tests have an out-of-band way to check the current number of live handles, so
cannam@132 823 # this can be used to test garbage collection.
cannam@132 824
cannam@132 825 getNull @10 () -> (nullCap :TestMoreStuff);
cannam@132 826 # Always returns a null capability.
cannam@132 827 }
cannam@132 828
cannam@132 829 interface TestMembrane {
cannam@132 830 makeThing @0 () -> (thing :Thing);
cannam@132 831 callPassThrough @1 (thing :Thing, tailCall :Bool) -> Result;
cannam@132 832 callIntercept @2 (thing :Thing, tailCall :Bool) -> Result;
cannam@132 833 loopback @3 (thing :Thing) -> (thing :Thing);
cannam@132 834
cannam@132 835 interface Thing {
cannam@132 836 passThrough @0 () -> Result;
cannam@132 837 intercept @1 () -> Result;
cannam@132 838 }
cannam@132 839
cannam@132 840 struct Result {
cannam@132 841 text @0 :Text;
cannam@132 842 }
cannam@132 843 }
cannam@132 844
cannam@132 845 struct TestContainMembrane {
cannam@132 846 cap @0 :TestMembrane.Thing;
cannam@132 847 list @1 :List(TestMembrane.Thing);
cannam@132 848 }
cannam@132 849
cannam@132 850 struct TestTransferCap {
cannam@132 851 list @0 :List(Element);
cannam@132 852 struct Element {
cannam@132 853 text @0 :Text;
cannam@132 854 cap @1 :TestInterface;
cannam@132 855 }
cannam@132 856 }
cannam@132 857
cannam@132 858 interface TestKeywordMethods {
cannam@132 859 delete @0 ();
cannam@132 860 class @1 ();
cannam@132 861 void @2 ();
cannam@132 862 return @3 ();
cannam@132 863 }
cannam@132 864
cannam@132 865 interface TestAuthenticatedBootstrap(VatId) {
cannam@132 866 getCallerId @0 () -> (caller :VatId);
cannam@132 867 }
cannam@132 868
cannam@132 869 struct TestSturdyRef {
cannam@132 870 hostId @0 :TestSturdyRefHostId;
cannam@132 871 objectId @1 :AnyPointer;
cannam@132 872 }
cannam@132 873
cannam@132 874 struct TestSturdyRefHostId {
cannam@132 875 host @0 :Text;
cannam@132 876 }
cannam@132 877
cannam@132 878 struct TestSturdyRefObjectId {
cannam@132 879 tag @0 :Tag;
cannam@132 880 enum Tag {
cannam@132 881 testInterface @0;
cannam@132 882 testExtends @1;
cannam@132 883 testPipeline @2;
cannam@132 884 testTailCallee @3;
cannam@132 885 testTailCaller @4;
cannam@132 886 testMoreStuff @5;
cannam@132 887 }
cannam@132 888 }
cannam@132 889
cannam@132 890 struct TestProvisionId {}
cannam@132 891 struct TestRecipientId {}
cannam@132 892 struct TestThirdPartyCapId {}
cannam@132 893 struct TestJoinResult {}
cannam@132 894
cannam@132 895 struct TestNameAnnotation $Cxx.name("RenamedStruct") {
cannam@132 896 union {
cannam@132 897 badFieldName @0 :Bool $Cxx.name("goodFieldName");
cannam@132 898 bar @1 :Int8;
cannam@132 899 }
cannam@132 900
cannam@132 901 enum BadlyNamedEnum $Cxx.name("RenamedEnum") {
cannam@132 902 foo @0;
cannam@132 903 bar @1;
cannam@132 904 baz @2 $Cxx.name("qux");
cannam@132 905 }
cannam@132 906
cannam@132 907 anotherBadFieldName @2 :BadlyNamedEnum $Cxx.name("anotherGoodFieldName");
cannam@132 908
cannam@132 909 struct NestedStruct $Cxx.name("RenamedNestedStruct") {
cannam@132 910 badNestedFieldName @0 :Bool $Cxx.name("goodNestedFieldName");
cannam@132 911 anotherBadNestedFieldName @1 :NestedStruct $Cxx.name("anotherGoodNestedFieldName");
cannam@132 912
cannam@132 913 enum DeeplyNestedEnum $Cxx.name("RenamedDeeplyNestedEnum") {
cannam@132 914 quux @0;
cannam@132 915 corge @1;
cannam@132 916 grault @2 $Cxx.name("garply");
cannam@132 917 }
cannam@132 918 }
cannam@132 919
cannam@132 920 badlyNamedUnion :union $Cxx.name("renamedUnion") {
cannam@132 921 badlyNamedGroup :group $Cxx.name("renamedGroup") {
cannam@132 922 foo @3 :Void;
cannam@132 923 bar @4 :Void;
cannam@132 924 }
cannam@132 925 baz @5 :NestedStruct $Cxx.name("qux");
cannam@132 926 }
cannam@132 927 }
cannam@132 928
cannam@132 929 interface TestNameAnnotationInterface $Cxx.name("RenamedInterface") {
cannam@132 930 badlyNamedMethod @0 (badlyNamedParam :UInt8 $Cxx.name("renamedParam")) $Cxx.name("renamedMethod");
cannam@132 931 }