1# RUN: toyc-ch7 %s -emit=ast 2>&1 | FileCheck %s 2 3struct Struct { 4 var a; 5 var b; 6} 7 8# User defined generic function may operate on struct types as well. 9def multiply_transpose(Struct value) { 10 # We can access the elements of a struct via the '.' operator. 11 return transpose(value.a) * transpose(value.b); 12} 13 14def main() { 15 # We initialize struct values using a composite initializer. 16 Struct value = {[[1, 2, 3], [4, 5, 6]], [[1, 2, 3], [4, 5, 6]]}; 17 18 # We pass these arguments to functions like we do with variables. 19 var c = multiply_transpose(value); 20 print(c); 21} 22 23# CHECK: Module: 24# CHECK-NEXT: Struct: Struct @{{.*}}struct-ast.toy:3:1 25# CHECK-NEXT: Variables: [ 26# CHECK-NEXT: VarDecl a<> @{{.*}}struct-ast.toy:4:3 27# CHECK-NEXT: VarDecl b<> @{{.*}}struct-ast.toy:5:3 28# CHECK-NEXT: ] 29# CHECK-NEXT:Function 30# CHECK-NEXT: Proto 'multiply_transpose' @{{.*}}struct-ast.toy:9:1 31# CHECK-NEXT: Params: [value] 32# CHECK-NEXT: Block { 33# CHECK-NEXT: Return 34# CHECK-NEXT: BinOp: * @{{.*}}struct-ast.toy:11:31 35# CHECK-NEXT: Call 'transpose' [ @{{.*}}struct-ast.toy:11:10 36# CHECK-NEXT: BinOp: . @{{.*}}struct-ast.toy:11:26 37# CHECK-NEXT: var: value @{{.*}}struct-ast.toy:11:20 38# CHECK-NEXT: var: a @{{.*}}struct-ast.toy:11:26 39# CHECK-NEXT: ] 40# CHECK-NEXT: Call 'transpose' [ @{{.*}}struct-ast.toy:11:31 41# CHECK-NEXT: BinOp: . @{{.*}}struct-ast.toy:11:47 42# CHECK-NEXT: var: value @{{.*}}struct-ast.toy:11:41 43# CHECK-NEXT: var: b @{{.*}}struct-ast.toy:11:47 44# CHECK-NEXT: ] 45# CHECK-NEXT: } 46# CHECK-NEXT:Function 47# CHECK-NEXT: Proto 'main' @{{.*}}struct-ast.toy:14:1 48# CHECK-NEXT: Params: [] 49# CHECK-NEXT: Block { 50# CHECK-NEXT: VarDecl value<Struct> @{{.*}}struct-ast.toy:16:3 51# CHECK-NEXT: Struct Literal: Literal: <2, 3>[ <3>[ 1.000000e+00, 2.000000e+00, 3.000000e+00], <3>[ 4.000000e+00, 5.000000e+00, 6.000000e+00]] @{{.*}}struct-ast.toy:16:19 52# CHECK-NEXT: Literal: <2, 3>[ <3>[ 1.000000e+00, 2.000000e+00, 3.000000e+00], <3>[ 4.000000e+00, 5.000000e+00, 6.000000e+00]] @{{.*}}struct-ast.toy:16:43 53# CHECK-NEXT: @{{.*}}struct-ast.toy:16:18 54# CHECK-NEXT: VarDecl c<> @{{.*}}struct-ast.toy:19:3 55# CHECK-NEXT: Call 'multiply_transpose' [ @{{.*}}struct-ast.toy:19:11 56# CHECK-NEXT: var: value @{{.*}}struct-ast.toy:19:30 57# CHECK-NEXT: ] 58# CHECK-NEXT: Print [ @{{.*}}struct-ast.toy:20:3 59# CHECK-NEXT: var: c @{{.*}}struct-ast.toy:20:9 60# CHECK-NEXT: ] 61# CHECK-NEXT: }