annotate win32-mingw/include/capnp/test.capnp @ 135:38d1c0e7850b

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