Files
compiler-the-translators/tests/sprint2/test/sp2_carls_mistake.alpha
2025-04-16 16:30:58 -04:00

36 lines
745 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

type rec: [integer: x; integer: y]
type T1: integer -> integer
type T2: rec -> integer
type arr: 1 -> integer
type main: string -> integer
function entry: main
function foo: T1
function bar1: T2
function bar2: T2
foo (x) := {
return x * x;
}
bar1 (x, y) := {
return x * y;
}
bar2 (r,s) := {
return r * s;
}
entry (arg) := {
[ integer: result ; rec: w]
result := foo(5);
w := reserve w; (* see types.alpha reserve returns a value of type address, which can be assigned to array and record variables*)
w.x := 5;
w.y := 7;
ressult := bar1(w); (* pass w (a rec type value) to bar1 *)
result := bar2(5,7); (* implicitly build a rec type value, assign 5 and 7 to fields x and y, but call them r and s *)
return 0;
}