Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tuple destructuring #1106

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
]
},
"ghul.compiler": {
"version": "0.8.10",
"version": "0.8.12",
"commands": [
"ghul-compiler"
]
Expand Down
3 changes: 1 addition & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project>
<PropertyGroup>
<Version>0.8.11-alpha.14</Version>
<Version>0.8.13-alpha.6</Version>
<NoWarn>$(NoWarn);NU1507</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ghul.runtime" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run test",
"command": "dotnet ghul-test \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "Capture test expectation",
"command": "../../../tasks/capture.sh \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Empty file.
6 changes: 6 additions & 0 deletions integration-tests/execution/tuple-destructure-1/ghul.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compiler": "dotnet ../../../publish/ghul.dll",
"source": [
"."
]
}
Empty file.
Empty file.
20 changes: 20 additions & 0 deletions integration-tests/execution/tuple-destructure-1/run.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
tuples_let_a() = 10
tuples_let_b() = 10
tuplies_let_c((1, 2, 3, 4)) = 10
tuples_let_d() = 10
tuples_let_s() = a = 1, b = AA, c = 3, d = BB
tuples_assign_a() = 10
tuples_assign_b() = 10
tuples_assign_c((1, 2, 3, 4)) = 10
tuples_assign_d() = 10
tuples_assign_s() = a = 1, b = AA, c = 3, d = BB
i = 0, j = 1
i = 1, j = 2
i = 2, j = 3
i = 3, j = 4
i = 4, j = 5
i = 5, j = 6
i = 6, j = 7
i = 7, j = 8
i = 8, j = 9
i = 9, j = 10
102 changes: 102 additions & 0 deletions integration-tests/execution/tuple-destructure-1/test.ghul
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

use IO.Std.write_line;

entry() is
write_line("tuples_let_a() = {tuples_let_a()}");
write_line("tuples_let_b() = {tuples_let_b()}");
write_line("tuplies_let_c((1, 2, 3, 4)) = {tuplies_let_c((1, 2, 3, 4))}");
write_line("tuples_let_d() = {tuples_let_d()}");
write_line("tuples_let_s() = {tuples_let_s()}");
write_line("tuples_assign_a() = {tuples_assign_a()}");
write_line("tuples_assign_b() = {tuples_assign_b()}");
write_line("tuples_assign_c((1, 2, 3, 4)) = {tuples_assign_c((1, 2, 3, 4))}");
write_line("tuples_assign_d() = {tuples_assign_d()}");
write_line("tuples_assign_s() = {tuples_assign_s()}");
tuples_f();
si

tuples_let_a() -> int is
let t = (1, 2, 3, 4);

let (a, b, c, d) = t;

return a + b + c + d;
si

tuples_let_b() -> int is
let (a, b, c, d) = (1, 2, 3, 4);

return a + b + c + d;
si

tuplies_let_c(t: (int, int, int, int)) -> int is
let (a, b, c, d) = t;

return a + b + c + d;
si

tuples_let_d() -> int is
let (a, (b, c), d) = (1, (2, 3), 4);

return a + b + c + d;
si

tuples_let_s() -> string is
let (a, b, c, d) = (1, "AA", 3, "BB");

return "a = {a}, b = {b}, c = {c}, d = {d}";
si

tuples_assign_a() -> int is
let t = (1, 2, 3, 4);

let a: int, b: int, c: int, d: int;

(a, b, c, d) = t;

return a + b + c + d;
si

tuples_assign_b() -> int is
let a: int, b: int, c: int, d: int;

(a, b, c, d) = (1, 2, 3, 4);

return a + b + c + d;
si

tuples_assign_c(t: (int, int, int, int)) -> int is
let a: int, b: int, c: int, d: int;

(a, b, c, d) = t;

return a + b + c + d;
si

tuples_assign_d() -> int is
let a: int, b: int, c: int, d: int;

(a, (b, c), d) = (1, (2, 3), 4);

return a + b + c + d;
si

tuples_assign_s() -> string is
let a: int, b: string, c: int, d: string;

(a, b, c, d) = (1, "AA", 3, "BB");

return "a = {a}, b = {b}, c = {c}, d = {d}";
si

tuples_f() is
let a = new Collections.LIST[(int, int)]();

for i in 0..10 do
a.add((i, i + 1));
od

for (i, j) in a do
write_line("i = {i}, j = {j}");
od
si
Empty file.
2 changes: 1 addition & 1 deletion integration-tests/il/control-flow-if/il.expected
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ ldc.i4 2
stloc 'result.2'
br L_0
L_2:
L_0:
L_0:
2 changes: 1 addition & 1 deletion integration-tests/il/control-flow-while/il.expected
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ ldc.i4 1
add
stloc 'index.0'
br L_0
L_1:
L_1:
2 changes: 1 addition & 1 deletion integration-tests/il/convert-object-to-class/il.expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ldloc 'o.1'
castclass class 'convert_object_to_class__test'.'THINGER'
stloc 't.2'
stloc 't.2'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ldloc 'o.1'
unbox.any class ['System.Runtime']'System'.'Object'
box valuetype 'convert_object_to_struct__test'.'STRUCT_THINGER'
stloc 't.2'
stloc 't.2'
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ldloc 'o.1'
castclass class 'convert_parent_to_subclass__test'.'THINGER'
stloc 't.2'
stloc 't.2'
4 changes: 2 additions & 2 deletions integration-tests/il/empty-try-finally/il.expected
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.locals init (bool '.temp.0.1')
.locals init (bool '.need_return.0.1')
.try {
leave L_0
}
Expand All @@ -7,7 +7,7 @@ L_1:
endfinally
}
L_0:
ldloc '.temp.0.1'
ldloc '.need_return.0.1'
brfalse L_2
ret
L_2:
4 changes: 1 addition & 3 deletions integration-tests/il/empty-try-finally/test.ghul
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
namespace Test is
namespace TestEmptyTryFinally is
use Std = IO.Std;

class Main is
entry() static is


@IL.output("il.out")
try
finally
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/il/try-break-continue/il.expected
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.locals init (bool '.temp.0.1')
.locals init (bool '.need_return.0.1')
.try {
leave L_1
leave L_2
Expand All @@ -10,7 +10,7 @@ leave L_0
leave L_2
}
L_2:
ldloc '.temp.0.1'
ldloc '.need_return.0.1'
brfalse L_4
ret
L_4:
4 changes: 1 addition & 3 deletions integration-tests/il/try-break-continue/test.ghul
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
namespace Test is
namespace TestTryBreakContinue is
use Std = IO.Std;

use System.Exception;

class Main is
entry() static is


while true do
@IL.output("il.out")
try
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/il/try-catch-exception/il.expected
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.locals init (bool '.temp.0.1')
.locals init (bool '.need_return.0.1')
.try {
leave L_0
}
Expand All @@ -8,7 +8,7 @@ stloc 'ex.0'
leave L_0
}
L_0:
ldloc '.temp.0.1'
ldloc '.need_return.0.1'
brfalse L_2
ret
L_2:
2 changes: 1 addition & 1 deletion integration-tests/il/try-catch-exception/test.ghul
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Test is
namespace TestTryCatchException is
use Std = IO.Std;

class Main is
Expand Down
14 changes: 7 additions & 7 deletions integration-tests/il/try-catch-exceptions-finally/il.expected
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
.locals init (bool '.temp.0.1')
.locals init (bool '.need_return.0.1')
.try {
.try {
leave L_0
}
catch class ['System.Runtime']'System'.'Exception' {
.locals init (class ['System.Runtime']'System'.'Exception' 'ex.0')
stloc 'ex.0'
.locals init (class ['System.Runtime']'System'.'Exception' 'ex1.0')
stloc 'ex1.0'
leave L_0
}
catch class 'Test'.'MyException' {
.locals init (class 'Test'.'MyException' 'ex.1')
stloc 'ex.1'
catch class 'TestTryCatchTwoExceptionsFinally'.'MyException' {
.locals init (class 'TestTryCatchTwoExceptionsFinally'.'MyException' 'ex2.1')
stloc 'ex2.1'
leave L_0
}
}
Expand All @@ -19,7 +19,7 @@ L_1:
endfinally
}
L_0:
ldloc '.temp.0.1'
ldloc '.need_return.0.1'
brfalse L_2
ret
L_2:
10 changes: 5 additions & 5 deletions integration-tests/il/try-catch-exceptions-finally/test.ghul
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
namespace Test is
namespace TestTryCatchTwoExceptionsFinally is
use Std = IO.Std;

class Main is
entry() static is


@IL.output("il.out")
try
catch ex: System.Exception
catch ex: MyException
// FIXME: ex1 and ex2 should be in their
// own scopes, per catch block
catch ex1: System.Exception
catch ex2: MyException
finally
yrt
si
Expand Down
14 changes: 7 additions & 7 deletions integration-tests/il/try-catch-exceptions/il.expected
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
.locals init (bool '.temp.0.1')
.locals init (bool '.need_return.0.1')
.try {
leave L_0
}
catch class ['System.Runtime']'System'.'Exception' {
.locals init (class ['System.Runtime']'System'.'Exception' 'ex.0')
stloc 'ex.0'
.locals init (class ['System.Runtime']'System'.'Exception' 'ex1.0')
stloc 'ex1.0'
leave L_0
}
catch class 'Test'.'MyException' {
.locals init (class 'Test'.'MyException' 'ex.1')
stloc 'ex.1'
catch class 'TestTryCatchTwoExceptions'.'MyException' {
.locals init (class 'TestTryCatchTwoExceptions'.'MyException' 'ex2.1')
stloc 'ex2.1'
leave L_0
}
L_0:
ldloc '.temp.0.1'
ldloc '.need_return.0.1'
brfalse L_2
ret
L_2:
10 changes: 5 additions & 5 deletions integration-tests/il/try-catch-exceptions/test.ghul
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
namespace Test is
namespace TestTryCatchTwoExceptions is
use Std = IO.Std;

class Main is
entry() static is


@IL.output("il.out")
try
catch ex: System.Exception
catch ex: MyException
// FIXME: scope of ex1 and ex2 should be within their
// own catch clause only
catch ex1: System.Exception
catch ex2: MyException
yrt
si
si
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/il/try-finally/il.expected
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.locals init (bool '.temp.0.1')
.locals init (bool '.need_return.0.1')
.try {
leave L_0
}
Expand All @@ -7,7 +7,7 @@ L_1:
endfinally
}
L_0:
ldloc '.temp.0.1'
ldloc '.need_return.0.1'
brfalse L_2
ret
L_2:
Loading
Loading