Move Patterns folder & remove prototypes
This commit is contained in:
parent
87cc35b09b
commit
751be6334a
3
Patterns/.gitignore
vendored
3
Patterns/.gitignore
vendored
|
|
@ -1,3 +0,0 @@
|
|||
// Ignore PascalABC.NET compiler output
|
||||
*.pdb
|
||||
*.exe
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
// Switch-statement
|
||||
|
||||
begin
|
||||
var a := new List<integer>(arr(1, 2));
|
||||
match a with
|
||||
integer(var c) when c = 3: write(1);
|
||||
string(var s) when not string.IsNullOrEmpty(s): write(2);
|
||||
List<integer>(var l) when l.Count > 0: write(3)
|
||||
end;
|
||||
end.
|
||||
|
||||
// User defined
|
||||
|
||||
type
|
||||
Person = class
|
||||
name: string;
|
||||
age: integer;
|
||||
|
||||
function Deconstruct(p: Person; name: string; age: integer): boolean;
|
||||
begin
|
||||
name := p.name;
|
||||
age := p.age;
|
||||
result := true;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
begin
|
||||
var p := new Person;
|
||||
if p is Person(var name, var age) then
|
||||
Print(name, ' ', age);
|
||||
end.
|
||||
|
||||
// Recursive patterns
|
||||
|
||||
begin
|
||||
if (tree is BinOp(IntConst(var ln), IntConst(var rn))) then
|
||||
tree = new IntConst(ln + rn);
|
||||
end.
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
// Source
|
||||
match e with
|
||||
Person(var value): <ACTION>
|
||||
end;
|
||||
|
||||
// Desugared code
|
||||
|
||||
var <>genVarExpr := e;
|
||||
var <>genVar: Person;
|
||||
if IsTest(<>genVarExpr, <>genVar) then
|
||||
begin
|
||||
// always the same code
|
||||
var value: ?; // should be filled during semantic analysis
|
||||
<>genVar.Deconstruct(value);
|
||||
|
||||
<ACTION>
|
||||
end;
|
||||
|
||||
{
|
||||
info we need to fill the tree:
|
||||
1. Syntactic nodes of parameters' types
|
||||
}
|
||||
|
||||
// ****************************************************************************
|
||||
|
||||
// Source
|
||||
if e is Person(var value) then
|
||||
<ACTION>
|
||||
|
||||
// Desugared code
|
||||
|
||||
var <>genVar: Person;
|
||||
if IsTest(e, <>genVar) then
|
||||
begin
|
||||
// always the same code
|
||||
var value: ?; // should be filled during semantic analysis
|
||||
<>genVar.Deconstruct(value);
|
||||
|
||||
<ACTION>
|
||||
end;
|
||||
|
||||
// ****************************************************************************
|
||||
|
||||
// Source
|
||||
var res := e is Person(var value);
|
||||
|
||||
// Desugared code
|
||||
|
||||
var <>genVar: Person;
|
||||
if IsTest(e, <>genVar) then
|
||||
begin
|
||||
// always the same code
|
||||
var value: ?; // should be filled during semantic analysis
|
||||
<>genVar.Deconstruct(value);
|
||||
|
||||
<ACTION>
|
||||
end;
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
// Source
|
||||
|
||||
match x with
|
||||
My(My1(s), My2(t)) when s = 'asd':
|
||||
My(s, t):
|
||||
end
|
||||
|
||||
// Desugared code (match, 1st stage)
|
||||
|
||||
var <>genVarExpr := x;
|
||||
if <>genVarExpr is My(My1(s), My2(t)) and s = 'asd' then
|
||||
begin
|
||||
<ACTION>
|
||||
end;
|
||||
else
|
||||
if <>genVarExpr is My(s, t) then
|
||||
...
|
||||
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;
|
||||
|
||||
// ----
|
||||
|
||||
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>
|
||||
else
|
||||
<ACTION_ELSE>
|
||||
end;
|
||||
|
||||
// ----
|
||||
|
||||
begin
|
||||
var <>genVar1: P1;
|
||||
var s: ?;
|
||||
var <>success1 := false;
|
||||
if IsTest(e, <>genVar1) then
|
||||
<>genVar1.Deconstruct(s);
|
||||
<>success1 := true;
|
||||
|
||||
var <>genVar2: P2;
|
||||
var t: ?;
|
||||
var <>success2 := false;
|
||||
if IsTest(t, <>genVar2) then
|
||||
<>genVar2.Deconstruct(t);
|
||||
<>success2 := true;
|
||||
|
||||
if (<>success and <>success2)
|
||||
<ACTION>
|
||||
goto empty_statement;
|
||||
end
|
||||
<ACTION_ELSE>
|
||||
end_if_label: empty_statement
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
// Source
|
||||
match e with
|
||||
Person(var value): <ACTION>
|
||||
end;
|
||||
|
||||
// Desugared code
|
||||
|
||||
var <>genVar: Person;
|
||||
if IsTest(e, <>genVar) then
|
||||
begin
|
||||
// one of 3 cases
|
||||
|
||||
// *********************************************************
|
||||
|
||||
// 1 - instance deconstruct
|
||||
var value: ?; // should be filled during semantic analysis
|
||||
<>genVar.Deconstruct(value);
|
||||
|
||||
// 2 - extension deconstruct
|
||||
var value: ?; // should be filled during semantic analysis
|
||||
PersonExt.Deconstruct(<>genVar, value);
|
||||
|
||||
// 3 - typecast - when there's only one deconstruction parameter and no Deconstruct methods were found
|
||||
var value := <>genVar;
|
||||
|
||||
// *********************************************************
|
||||
|
||||
<ACTION>
|
||||
end;
|
||||
|
||||
{
|
||||
info we need to fill the tree:
|
||||
1. Method type (instance or static) and a qualifier if static
|
||||
2. Syntactic nodes of parameters' types
|
||||
|
||||
General: how to get the type of expression
|
||||
|
||||
case 1:
|
||||
How to check if a certain type has instance method with given name - option 1
|
||||
Save information about all Deconstruct methods during creation of a semantic tree - option 2
|
||||
|
||||
case 2:
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue