blob: dd315ea8db5738a62df1d437bee2931142f0cd6d [file] [log] [blame]
# RUN: toyc-ch1 %s -emit=ast 2>&1 | FileCheck %s
# User defined generic function that operates solely on
def multiply_transpose(a, b) {
return a * transpose(b);
}
def main() {
# Define a variable `a` with shape <2, 3>, initialized with the literal value.
# The shape is inferred from the supplied literal.
var a = [[1, 2, 3], [4, 5, 6]];
# b is identical to a, the literal array is implicitly reshaped: defining new
# variables is the way to reshape arrays (element count must match).
var b<2, 3> = [1, 2, 3, 4, 5, 6];
# This call will specialize `multiply_transpose` with <2, 3> for both
# arguments and deduce a return type of <2, 2> in initialization of `c`.
var c = multiply_transpose(a, b);
# A second call to `multiply_transpose` with <2, 3> for both arguments will
# reuse the previously specialized and inferred version and return `<2, 2>`
var d = multiply_transpose(b, a);
# A new call with `<2, 2>` for both dimension will trigger another
# specialization of `multiply_transpose`.
var e = multiply_transpose(b, c);
# Finally, calling into `multiply_transpose` with incompatible shape will
# trigger a shape inference error.
var e = multiply_transpose(transpose(a), c);
}
# CHECK: Module:
# CHECK-NEXT: Function
# CHECK-NEXT: Proto 'multiply_transpose' @{{.*}}Toy/Ch1/ast.toy:5:1'
# CHECK-NEXT: Params: [a, b]
# CHECK-NEXT: Block {
# CHECK-NEXT: Retur
# CHECK-NEXT: BinOp: * @{{.*}}Toy/Ch1/ast.toy:6:14
# CHECK-NEXT: var: a @{{.*}}Toy/Ch1/ast.toy:6:10
# CHECK-NEXT: Call 'transpose' [ @{{.*}}Toy/Ch1/ast.toy:6:14
# CHECK-NEXT: var: b @{{.*}}Toy/Ch1/ast.toy:6:24
# CHECK-NEXT: ]
# CHECK-NEXT: } // Block
# CHECK-NEXT: Function
# CHECK-NEXT: Proto 'main' @{{.*}}Toy/Ch1/ast.toy:9:1'
# CHECK-NEXT: Params: []
# CHECK-NEXT: Block {
# CHECK-NEXT: VarDecl a<> @{{.*}}Toy/Ch1/ast.toy:12:3
# 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]] @{{.*}}Toy/Ch1/ast.toy:12:11
# CHECK-NEXT: VarDecl b<2, 3> @{{.*}}Toy/Ch1/ast.toy:15:3
# CHECK-NEXT: Literal: <6>[ 1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00, 5.000000e+00, 6.000000e+00] @{{.*}}Toy/Ch1/ast.toy:15:17
# CHECK-NEXT: VarDecl c<> @{{.*}}Toy/Ch1/ast.toy:18:3
# CHECK-NEXT: Call 'multiply_transpose' [ @{{.*}}Toy/Ch1/ast.toy:18:11
# CHECK-NEXT: var: a @{{.*}}Toy/Ch1/ast.toy:18:30
# CHECK-NEXT: var: b @{{.*}}Toy/Ch1/ast.toy:18:33
# CHECK-NEXT: ]
# CHECK-NEXT: VarDecl d<> @{{.*}}Toy/Ch1/ast.toy:21:3
# CHECK-NEXT: Call 'multiply_transpose' [ @{{.*}}Toy/Ch1/ast.toy:21:11
# CHECK-NEXT: var: b @{{.*}}Toy/Ch1/ast.toy:21:30
# CHECK-NEXT: var: a @{{.*}}Toy/Ch1/ast.toy:21:33
# CHECK-NEXT: ]
# CHECK-NEXT: VarDecl e<> @{{.*}}Toy/Ch1/ast.toy:24:3
# CHECK-NEXT: Call 'multiply_transpose' [ @{{.*}}Toy/Ch1/ast.toy:24:11
# CHECK-NEXT: var: b @{{.*}}Toy/Ch1/ast.toy:24:30
# CHECK-NEXT: var: c @{{.*}}Toy/Ch1/ast.toy:24:33
# CHECK-NEXT: ]
# CHECK-NEXT: VarDecl e<> @{{.*}}Toy/Ch1/ast.toy:27:3
# CHECK-NEXT: Call 'multiply_transpose' [ @{{.*}}Toy/Ch1/ast.toy:27:11
# CHECK-NEXT: Call 'transpose' [ @{{.*}}Toy/Ch1/ast.toy:27:30
# CHECK-NEXT: var: a @{{.*}}Toy/Ch1/ast.toy:27:40
# CHECK-NEXT: ]
# CHECK-NEXT: var: c @{{.*}}Toy/Ch1/ast.toy:27:44
# CHECK-NEXT: ]