pascalabcnet/Patterns/Desugaring-v3.pas

84 lines
1.2 KiB
ObjectPascal
Raw Permalink Normal View History

2018-05-12 18:10:37 +03:00
// Source
match x with
My(My1(s), My2(t)) when s = 'asd':
My(s, t):
2018-05-12 18:10:37 +03:00
end
// Desugared code (match, 1st stage)
var <>genVarExpr := x;
if <>genVarExpr is My(My1(s), My2(t)) and s = 'asd' then
2018-05-12 18:10:37 +03:00
begin
<ACTION>
end;
else
if <>genVarExpr is My(s, t) then
...
2018-05-12 18:10:37 +03:00
end;
// Desugared code (is, 2nd stage)
var <>genVarExpr := x;
var <>genVar1: My1;
var <>genVar2: My2;
if <>genVarExpr is My(<>genVar1, <>genVar2) and
<>genVar1 is My1(s) and
<>genVar2 is My2(t) and
s = 'asd' then
begin
<ACTION>
end;
// If desugaring (lvl 1)
if e is P(s) then
<ACTION>
end;
2018-05-12 18:10:37 +03:00
// ----
2018-05-12 18:10:37 +03:00
var <>gen: P;
if IsTest(e, <>gen) then
var s: ?;
<>gen.Deconstruct(s);
<ACTION>
end;
//-------------------------------------
// If desugaring (lvl 2)
if e is P1(s) and s is P2(t) then
<ACTION>
2018-05-14 17:15:01 +03:00
else
<ACTION_ELSE>
end;
// ----
2018-05-14 17:15:01 +03:00
2018-05-16 00:26:07 +03:00
begin
var <>genVar1: P1;
2018-05-16 00:26:07 +03:00
var s: ?;
2018-05-14 20:06:58 +03:00
var <>success1 := false;
if IsTest(e, <>genVar1) then
2018-05-16 00:26:07 +03:00
<>genVar1.Deconstruct(s);
2018-05-14 20:06:58 +03:00
<>success1 := true;
2018-05-14 20:06:58 +03:00
var <>genVar2: P2;
2018-05-16 00:26:07 +03:00
var t: ?;
2018-05-14 20:06:58 +03:00
var <>success2 := false;
2018-05-16 00:26:07 +03:00
if IsTest(t, <>genVar2) then
<>genVar2.Deconstruct(t);
2018-05-14 20:06:58 +03:00
<>success2 := true;
if (<>success and <>success2)
2018-05-14 17:15:01 +03:00
<ACTION>
2018-05-16 00:26:07 +03:00
goto empty_statement;
end
<ACTION_ELSE>
end_if_label: empty_statement