Skip to content

Commit

Permalink
Улучшение расширенной специализации (#251, #322)
Browse files Browse the repository at this point in the history
  • Loading branch information
VladisP committed Jun 20, 2021
1 parent 3e4ccc0 commit 3f42c44
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 152 deletions.
2 changes: 1 addition & 1 deletion autotests/@refal-5-lambda-diagnostics.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
memory-limit = 10000000
step-limit = 15000000
step-limit = 1000000000

This comment has been minimized.

Copy link
@Mazdaywik

Mazdaywik Jun 21, 2021

Member

А-а-а. Будут конфликты. См. https://github.com/bmstu-iu9/refal-5-lambda/pull/355/files. На 60000000 у Вас не работает?

idents-limit = 5000
enable-debugger = false
16 changes: 16 additions & 0 deletions autotests/opt-tree-spec10.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
* TREE

$ENTRY Go {
= <F ('A')>
}

F {
t.X = <Eq (t.X) t.X>
}

$SPEC Eq e.arg;

Eq {
t.Eq t.Eq = True;
t._ t._ = False;
}
15 changes: 15 additions & 0 deletions autotests/opt-tree-spec11.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
* TREE

$ENTRY Go {
= <F 1 '@' 2 '#' 3>
}

F {
e.X = <G (e.X) '+' (e.X)>
}

$SPEC G e.arg;

G {
(e.A '@' e.B) s.R (e.C '#' e.D) = (e.A) s.R (e.B) s.R (e.C) s.R (e.D);
}
30 changes: 30 additions & 0 deletions autotests/opt-tree-spec12.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
* TREE

$ENTRY Go {
/* empty */
= <F () ('AABBAACC' 9 'DD')> : ('AA') ('BB') ('CC') ('DD')
= <F ('A') ('ABBAACC' 9 'DD')> : ('AA') ('BB') ('CC') ('DD')
= <F ('AA') ('BBAACC' 9 'DD')> : ('AA') ('BB') ('CC') ('DD')
= <F ('AAB') ('BAACC' 9 'DD')> : ('AA') ('BB') ('CC') ('DD')
= <F ('AABB') ('AACC' 9 'DD')> : ('AA') ('BB') ('CC') ('DD')
= <F ('AABBA') ('ACC' 9 'DD')> : ('AA') ('BB') ('CC') ('DD')
= <F ('AABBAA') ('CC' 9 'DD')> : ('AA') ('BB') ('CC') ('DD')
= <F ('AABBAAC') ('C' 9 'DD')> : ('AA') ('BB') ('CC') ('DD')
= <F ('AABBAACC') (9 'DD')> : ('AA') ('BB') ('CC') ('DD')
= <F ('AABBAACC' 9) ('DD')> : ('AA') ('BB') ('CC') ('DD')
= <F ('AABBAACC' 9 'D') ('D')> : ('AA') ('BB') ('CC') ('DD')
= <F ('AABBAACC' 9 'DD') ()> : ('AA') ('BB') ('CC') ('DD')
= /* empty */;
}

F {
(e.1) (e.2) = <S e.1 e.2>;
}

$SPEC S e.arg;

S {
e.A e.B e.A e.C 9 e.D
, e.A : s._ s._
= (e.A) (e.B) (e.C) (e.D);
}
12 changes: 12 additions & 0 deletions autotests/opt-tree-spec7.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
* TREE

$ENTRY Go {
e.X = <S { = e.X }> : False = /* empty */;
}

$SPEC S s.X;

S {
s.X, A : s.X = True;
s._ = False;
}
15 changes: 15 additions & 0 deletions autotests/opt-tree-spec8.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
* TREE

$SPEC Rot e.dyn;

Rot {
e.1 s.2 = s.2 e.1;
}

Example {
(e.X) (e.Y) = <Rot 'A' e.X e.Y>;
}

$ENTRY Go {
= <Example (1 'a' 2) (3 'b' 4)>;
}
12 changes: 12 additions & 0 deletions autotests/opt-tree-spec9.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
* TREE

$ENTRY Go {
e.X = <Eq (A e.X) (e.X A)>;
}

$SPEC Eq e.arg;

Eq {
t.X t.X = True t.X;
t.Y t.Z = False t.Y t.Z;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
memory-limit = 10000000
step-limit = 800000000
step-limit = 1000000000
idents-limit = 5000
enable-debugger = false
73 changes: 58 additions & 15 deletions src/compiler/GenericMatch.ref
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Solve-Spec-Aux {
: {
e.Begin Generalize (e.Intervals) e.End
= <DoGeneralize
(e.UsedVars) (e.Intervals)
(e.UsedVars) <UnionIfIntersect (e.Intervals)>
(e.L) (e.GenAssigns)
>
: (e.UsedVars^) (e.L^) (e.GenAssigns^)
Expand All @@ -127,6 +127,52 @@ Solve-Spec-Aux {
}
}

/*
Объединяет два интервала, если они пересекаются.
В остальных случаях возвращает исходный список интервалов.

<UnionIfIntersect (e.Intervals)> == (e.Intervals^)

e.Intervals ::= t.Interval+
t.Interval ::= ('{' s.BeginCoord s.EndCoord '}')
*/

UnionIfIntersect {
(t.Interval-1 t.Interval-2)
, <HasIntersection (t.Interval-1 t.Interval-2)> : True
= t.Interval-1 : ('{' s.A s.B '}')
= t.Interval-2 : ('{' s.C s.D '}')
= <GetExtremum s.A '+' (s.B s.C s.D)> : s.Min
= <GetExtremum s.A '-' (s.B s.C s.D)> : s.Max
= (('{' s.Min s.Max '}'));

t.Intervals = t.Intervals;
}

HasIntersection {
(('{' s.A s.B '}') ('{' s.C s.D '}'))
, <Compare s.C s.B> : '+'
= False;

(('{' s.A s.B '}') ('{' s.C s.D '}'))
, <Compare s.A s.D> : '+'
= False;

t.Intervals = True;
}

GetExtremum {
s.Extremum s.Sign (s.CurrentCoord e.Rest)
, <Compare s.Extremum s.CurrentCoord> : s.Sign
= <GetExtremum s.CurrentCoord s.Sign (e.Rest)>;

s.Extremum s.Sign (s.CurrentCoord e.Rest)
= <GetExtremum s.Extremum s.Sign (e.Rest)>;

s.Extremum s.Sign (/* пусто */)
= s.Extremum;
}

/*
Преобразует решения в нужный формат для Solve-Drive и Solve-Spec

Expand Down Expand Up @@ -255,10 +301,10 @@ ApplyAssignments-toExpr {
}

ApplyAssignment-toExpr {
(e.Val ':' t.Var) e.Begin t.Var e.End
= <ApplyAssignment-toExpr (e.Val ':' t.Var) e.Begin>
(e.Val ':' (s.Type e.Index)) e.Begin (Var s.Type e.Index) e.End
= <ApplyAssignment-toExpr (e.Val ':' (s.Type e.Index)) e.Begin>
e.Val
<ApplyAssignment-toExpr (e.Val ':' t.Var) e.End>;
<ApplyAssignment-toExpr (e.Val ':' (s.Type e.Index)) e.End>;

t.Assign e.Begin (Brackets e.E) e.End
= <ApplyAssignment-toExpr t.Assign e.Begin>
Expand Down Expand Up @@ -2475,18 +2521,15 @@ AddContraction {

AddContraction-Spec {
t.toAdd (s.OpenFlag e.Contrs) e.Clashes (e.Assigns)
, t.toAdd : ((Var 'e' e._) ':' (Var 'e' e._) (Var 'e' e._))
= <SimplifyCoordinates
(
AfterOpen
<Map (&ApplyContraction-toContraction t.toAdd) e.Contrs>
t.toAdd
)
<Map (&ApplyContraction-toEquation t.toAdd) e.Clashes>
(<Map (&ApplyContraction-toAssign t.toAdd) e.Assigns>)
>;
= t.toAdd
: {
((Var 'e' e._) ':' (Var 'e' e._) (Var 'e' e._)) = AfterOpen;

t.toAdd (s.OpenFlag e.Contrs) e.Clashes (e.Assigns)
((Var 'e' e._) ':' (Var 'e' e._) (Var 't' e._) (Var 'e' e._)) = AfterOpen;

t._ = s.OpenFlag;
}
: s.OpenFlag^
= <SimplifyCoordinates
(
s.OpenFlag
Expand Down
Loading

0 comments on commit 3f42c44

Please sign in to comment.