brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · d2ccc5a Raw
61 lines · plain
1# RUN: toyc-ch7 %s -emit=ast 2>&1 | FileCheck %s2 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:125# CHECK-NEXT:  Variables: [26# CHECK-NEXT:    VarDecl a<> @{{.*}}struct-ast.toy:4:327# CHECK-NEXT:    VarDecl b<> @{{.*}}struct-ast.toy:5:328# CHECK-NEXT:  ]29# CHECK-NEXT:Function30# CHECK-NEXT:  Proto 'multiply_transpose' @{{.*}}struct-ast.toy:9:131# CHECK-NEXT:  Params: [value]32# CHECK-NEXT:  Block {33# CHECK-NEXT:    Return34# CHECK-NEXT:      BinOp: * @{{.*}}struct-ast.toy:11:3135# CHECK-NEXT:        Call 'transpose' [ @{{.*}}struct-ast.toy:11:1036# CHECK-NEXT:          BinOp: . @{{.*}}struct-ast.toy:11:2637# CHECK-NEXT:            var: value @{{.*}}struct-ast.toy:11:2038# CHECK-NEXT:            var: a @{{.*}}struct-ast.toy:11:2639# CHECK-NEXT:        ]40# CHECK-NEXT:        Call 'transpose' [ @{{.*}}struct-ast.toy:11:3141# CHECK-NEXT:          BinOp: . @{{.*}}struct-ast.toy:11:4742# CHECK-NEXT:            var: value @{{.*}}struct-ast.toy:11:4143# CHECK-NEXT:            var: b @{{.*}}struct-ast.toy:11:4744# CHECK-NEXT:        ]45# CHECK-NEXT:  }46# CHECK-NEXT:Function47# CHECK-NEXT:  Proto 'main' @{{.*}}struct-ast.toy:14:148# CHECK-NEXT:  Params: []49# CHECK-NEXT:  Block {50# CHECK-NEXT:    VarDecl value<Struct> @{{.*}}struct-ast.toy:16:351# 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:1952# 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:4353# CHECK-NEXT:       @{{.*}}struct-ast.toy:16:1854# CHECK-NEXT:    VarDecl c<> @{{.*}}struct-ast.toy:19:355# CHECK-NEXT:      Call 'multiply_transpose' [ @{{.*}}struct-ast.toy:19:1156# CHECK-NEXT:        var: value @{{.*}}struct-ast.toy:19:3057# CHECK-NEXT:      ]58# CHECK-NEXT:    Print [ @{{.*}}struct-ast.toy:20:359# CHECK-NEXT:      var: c @{{.*}}struct-ast.toy:20:960# CHECK-NEXT:    ]61# CHECK-NEXT:  }