Skip to content

Commit

Permalink
Рассахариватель добавляет $SPEC ко вложенным функциям (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mazdaywik committed May 13, 2020
1 parent a0f036e commit 4f68cd3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
23 changes: 23 additions & 0 deletions autotests/opt-tree-drive-spec3-block.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
* TREE

$ENTRY Go {
/* empty */
= <F 1 /* empty */> : A 1
= <F 2 2> : B 2
= <F 3 1 2 3 4> : C 3
= <F 4 'abc'> : 'abc'
= /* empty */;
}

$SPEC F s.STAT e.dyn;

F {
s.Mark e.X
= e.X
: {
/* empty */ = A s.Mark;
s.Mark = B s.Mark;
e._ s.Mark e._ = C s.Mark;
e._ = e.X;
}
}
36 changes: 25 additions & 11 deletions src/compiler/Desugaring.ref
Original file line number Diff line number Diff line change
Expand Up @@ -592,15 +592,7 @@ Pass-FlatNestedFuncs {
{
(Function s.ScopeClass (e.Name) e.Body)
= <ExtractNested s.MarkupContext e.Body> : (e.NestedFuncs) e.Body^
= <Map
{
t.Function
, t.Function : (Function s._ScopeClass (e.NestedName) e._Body)
= (Drive e.NestedName)
t.Function
}
e.NestedFuncs
>
= e.NestedFuncs
(Function s.ScopeClass (e.Name) e.Body);

t.OtherProgramElement = t.OtherProgramElement;
Expand Down Expand Up @@ -799,6 +791,7 @@ ExtractNested-Result-Term {
/* Случай функции без контекста, нативной функции в том числе */
(/* нет захваченных переменных */) e.Body^
= (Function GN-Local (e.ClosureName) e.Body)
(Drive e.ClosureName)
(e.BorrowedVars)
(Symbol Name e.ClosureName);

Expand All @@ -816,14 +809,19 @@ ExtractNested-Result-Term {
e.Sentences
>
)
(Drive e.ClosureName)
(Spec (e.ClosureName) <CreateSpecPattern e.Context>)
<Reduce
(&CheckBorrowed (e.ScopeVars))
(e.BorrowedVars) e.NestedBorrowedVars
>
(ClosureBrackets (Symbol Name e.ClosureName) e.Context);
}
: t.Function (e.BorrowedVars^) t.ClosureTerm
= ((e.NestedFuncs e.NestedNestedFuncs t.Function) (e.BorrowedVars))
: t.Function e.OptMarks (e.BorrowedVars^) t.ClosureTerm
= (
(e.NestedFuncs e.NestedNestedFuncs t.Function e.OptMarks)
(e.BorrowedVars)
)
t.ClosureTerm;

s.MarkupContext (e.ScopeVars) (e.LocalVars)
Expand Down Expand Up @@ -869,6 +867,22 @@ CreateContext {
>;
}

CreateSpecPattern {
e.Context
= <Map
{
(Symbol Identifier e.Ident) = (Symbol Identifier e.Ident);

(TkVariable s.Mode e.Index) = (TkVariable s.Mode 'STAT_' e.Index);

(Brackets (TkVariable 'e' e.Index))
= (Brackets (TkVariable 'eSTAT_' e.Index));
}
e.Context
>
(TkVariable 'edyn' 0)
}

Pass-CleanupRedudandExterns {
/*
Проход Checker проверил корректность использования $FORWARD’ов
Expand Down

0 comments on commit 4f68cd3

Please sign in to comment.