From acd51dee98eab636bb74dddba0b59a306b93ddc7 Mon Sep 17 00:00:00 2001 From: Annie Date: Tue, 11 Mar 2025 15:37:05 -0400 Subject: [PATCH] added tests for assignable and memory --- tests/sprint2/test/test_carls_mistake.alpha | 27 +++++++++++++++++++ tests/sprint2/test/test_invalid_recop.alpha | 10 +++++++ tests/sprint2/test/test_invalid_release.alpha | 8 ++++++ .../test/test_valid_assignable_and_mem.alpha | 12 +++++++++ 4 files changed, 57 insertions(+) create mode 100644 tests/sprint2/test/test_carls_mistake.alpha create mode 100644 tests/sprint2/test/test_invalid_recop.alpha create mode 100644 tests/sprint2/test/test_invalid_release.alpha create mode 100644 tests/sprint2/test/test_valid_assignable_and_mem.alpha diff --git a/tests/sprint2/test/test_carls_mistake.alpha b/tests/sprint2/test/test_carls_mistake.alpha new file mode 100644 index 0000000..fb75ca3 --- /dev/null +++ b/tests/sprint2/test/test_carls_mistake.alpha @@ -0,0 +1,27 @@ +type rec: [integer: x; integer: y] +type T1: integer -> integer +type T2: rec -> integer + +function foo : T1 +function bar1 : T2 +function bar2 : T2 + +foo(x) := { + return x * x; +} +bar1(a) := { + return a.x * a.y; +} +bar2 as (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; + result := 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; +} \ No newline at end of file diff --git a/tests/sprint2/test/test_invalid_recop.alpha b/tests/sprint2/test/test_invalid_recop.alpha new file mode 100644 index 0000000..5ea874d --- /dev/null +++ b/tests/sprint2/test/test_invalid_recop.alpha @@ -0,0 +1,10 @@ +type rec: [integer: x; integer: y] + +entry(arg) := { + [rec: w] + w := reserve w; + w.x := 1; + w.y := 2; + w.z := 3; + return 0; +} \ No newline at end of file diff --git a/tests/sprint2/test/test_invalid_release.alpha b/tests/sprint2/test/test_invalid_release.alpha new file mode 100644 index 0000000..41fbd8a --- /dev/null +++ b/tests/sprint2/test/test_invalid_release.alpha @@ -0,0 +1,8 @@ +type rec: [integer: x; integer: y] + +entry(arg) := { + [rec: w] + w := reserve w; + w := release (w); + return 0; +} \ No newline at end of file diff --git a/tests/sprint2/test/test_valid_assignable_and_mem.alpha b/tests/sprint2/test/test_valid_assignable_and_mem.alpha new file mode 100644 index 0000000..43c5a5f --- /dev/null +++ b/tests/sprint2/test/test_valid_assignable_and_mem.alpha @@ -0,0 +1,12 @@ +type rec: [integer: x; integer: y] +type T2: rec -> integer + +entry(arg) := { + [rec: w] + w := reserve w; + w.x := 1; + w.y := 2; + w := release w; + return 0; + +} \ No newline at end of file