annotate osx/include/capnp/test.capnp @ 54:5f67a29f0fc7

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