From 751be6334ae139aa9d479d4caa0deef185607581 Mon Sep 17 00:00:00 2001 From: Alexander Zakharenko Date: Sun, 17 Jun 2018 18:23:14 +0300 Subject: [PATCH] Move Patterns folder & remove prototypes --- .../Patterns/patterns-all.pas | 0 .../Patterns}/patterns-switch.pas | 0 .../Patterns}/patterns-user-defined.pas | 0 Patterns/.gitignore | 3 - Patterns/All-examples.pas | 39 --------- Patterns/Desugaring-v2.pas | 57 ------------- Patterns/Desugaring-v3.pas | 83 ------------------- Patterns/Desugaring.pas | 45 ---------- 8 files changed, 227 deletions(-) rename Patterns/patterns.pas => CodeExamples/Patterns/patterns-all.pas (100%) rename {Patterns => CodeExamples/Patterns}/patterns-switch.pas (100%) rename {Patterns => CodeExamples/Patterns}/patterns-user-defined.pas (100%) delete mode 100644 Patterns/.gitignore delete mode 100644 Patterns/All-examples.pas delete mode 100644 Patterns/Desugaring-v2.pas delete mode 100644 Patterns/Desugaring-v3.pas delete mode 100644 Patterns/Desugaring.pas diff --git a/Patterns/patterns.pas b/CodeExamples/Patterns/patterns-all.pas similarity index 100% rename from Patterns/patterns.pas rename to CodeExamples/Patterns/patterns-all.pas diff --git a/Patterns/patterns-switch.pas b/CodeExamples/Patterns/patterns-switch.pas similarity index 100% rename from Patterns/patterns-switch.pas rename to CodeExamples/Patterns/patterns-switch.pas diff --git a/Patterns/patterns-user-defined.pas b/CodeExamples/Patterns/patterns-user-defined.pas similarity index 100% rename from Patterns/patterns-user-defined.pas rename to CodeExamples/Patterns/patterns-user-defined.pas diff --git a/Patterns/.gitignore b/Patterns/.gitignore deleted file mode 100644 index 8e4bfeb96..000000000 --- a/Patterns/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -// Ignore PascalABC.NET compiler output -*.pdb -*.exe diff --git a/Patterns/All-examples.pas b/Patterns/All-examples.pas deleted file mode 100644 index 1f759a851..000000000 --- a/Patterns/All-examples.pas +++ /dev/null @@ -1,39 +0,0 @@ -// Switch-statement - -begin - var a := new List(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(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. \ No newline at end of file diff --git a/Patterns/Desugaring-v2.pas b/Patterns/Desugaring-v2.pas deleted file mode 100644 index 6a73df624..000000000 --- a/Patterns/Desugaring-v2.pas +++ /dev/null @@ -1,57 +0,0 @@ -// Source -match e with - Person(var value): -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); - - -end; - -{ -info we need to fill the tree: -1. Syntactic nodes of parameters' types -} - -// **************************************************************************** - -// Source -if e is Person(var value) then - - -// 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); - - -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); - - -end; \ No newline at end of file diff --git a/Patterns/Desugaring-v3.pas b/Patterns/Desugaring-v3.pas deleted file mode 100644 index e8a356709..000000000 --- a/Patterns/Desugaring-v3.pas +++ /dev/null @@ -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 - -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 - -end; - - -// If desugaring (lvl 1) - -if e is P(s) then - -end; - -// ---- - -var <>gen: P; -if IsTest(e, <>gen) then - var s: ?; - <>gen.Deconstruct(s); - - -end; - -//------------------------------------- - -// If desugaring (lvl 2) - -if e is P1(s) and s is P2(t) then - -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) - - goto empty_statement; -end - -end_if_label: empty_statement diff --git a/Patterns/Desugaring.pas b/Patterns/Desugaring.pas deleted file mode 100644 index 3ee1c9339..000000000 --- a/Patterns/Desugaring.pas +++ /dev/null @@ -1,45 +0,0 @@ -// Source -match e with - Person(var value): -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; - - // ********************************************************* - - -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: - - -}