diff --git a/src/compiler/OptTree-AutoMarkup-BasisVertexesExtractor.ref b/src/compiler/OptTree-AutoMarkup-BasisVertexesExtractor.ref new file mode 100644 index 00000000..8d82fcdd --- /dev/null +++ b/src/compiler/OptTree-AutoMarkup-BasisVertexesExtractor.ref @@ -0,0 +1,194 @@ +$INCLUDE "LibraryEx"; + +*$FROM OptTree-AutoMarkup-Common +$EXTERN OptTree-AutoMarkup-GetSetDifference, + OptTree-AutoMarkup-Contains, + OptTree-AutoMarkup-GetElemByKey, + OptTree-AutoMarkup-GetParents, + OptTree-AutoMarkup-Equal; + +/** + + = (e.BasisVertex)* (e.Graph) + + e.BasisVertex = e.FuncName +*/ + +$ENTRY OptTree-AutoMarkup-ExtractBasisVertexes { + e.Graph + = + : (e.GraphRoots) + = + : ( + (e.CurrentPath) + (e.Proccessed) + (e.BasisVertexes) + (e.Graph^) + ) + = (e.BasisVertexes) (e.Graph); +} + +OptTree-AutoMarkup-GetGraphRoots { + (e.Graph) + = : False + = ((e.Result) (e.Graph)); + + ((e.Result) (e.Graph^)) + (Func (e.FuncName) Children (e.Children)) + = ((e.Result (e.FuncName)) (e.Graph)) + } + ((/*result*/) (e.Graph)) e.Graph + > + : ((e.Roots) (e.Graph^)) + = (e.Roots); +} + +OptTree-AutoMarkup-GetBasisVertexes-GetResultByNode { + (Func (e.Name) Children (e.Children)) + ((e.CurrentPath) (e.Proccessed) (e.BasisVertexes) (e.Graph)) + = + : ( + (e.NewCurrentPath^) + (e.Proccessed^) + (e.BasisVertexes^) + (e.Graph^) + ) + = ( + (e.CurrentPath) + (e.Proccessed) + (e.BasisVertexes) + (e.Graph) + ); + } + ((e.CurrentPath) (e.Proccessed) (e.BasisVertexes) (e.Graph)) + e.Children + > + : ((e.CurrentPath^) (e.Proccessed^) (e.BasisVertexes^) (e.Graph^)) + = e.Proccessed (e.Name) : e.NewProccessed + = ( + (e.CurrentPath) + (e.NewProccessed) + (e.BasisVertexes) + (e.Graph) + ); + + (e.Other) + ((e.CurrentPath) (e.Proccessed) (e.BasisVertexes) (e.Graph)) + = ((e.CurrentPath) (e.Proccessed) (e.BasisVertexes) (e.Graph)); +} + + +OptTree-AutoMarkup-GetBasisVertexes { + (e.NextGraphNodes) + ( + (e.CurrentPath) + (e.Proccessed) + (e.BasisVertexes) + (e.Graph) + ) + = + : e.Node (e.Graph^) + = + } + ( + (e.CurrentPath) + (e.Proccessed) + (e.BasisVertexes) + (e.Graph) + ) + e.NextGraphNodes + >; + + (e.RootNodes) + e.Graph + = ; +} \ No newline at end of file diff --git a/src/compiler/OptTree-AutoMarkup-Common.ref b/src/compiler/OptTree-AutoMarkup-Common.ref new file mode 100644 index 00000000..ccdc3dbb --- /dev/null +++ b/src/compiler/OptTree-AutoMarkup-Common.ref @@ -0,0 +1,88 @@ +$INCLUDE "LibraryEx"; + +/** + == + (e.FirstSet\e.SecondSet) +*/ + +$ENTRY OptTree-AutoMarkup-GetSetDifference { + (e.FirstSet) (e.SecondSet) + = : False + = e.Node; + + e.Other + = ; + } + e.FirstSet + > + : e.Res + = (e.Res); +} + +/** + == True|False +*/ + +$ENTRY OptTree-AutoMarkup-Contains { + (e.Elem) (e.ArrayHead (e.Elem) e.ArrayTail) + = True; + + (e.Elem) (e.Array) + = False; +} + +/** + == True|False +*/ + +$ENTRY OptTree-AutoMarkup-Equal { + (e.X) (e.X) + = True; + + (e.X) (e.Y) + = False; +} + +/** + + == e.GraphNode (e.Graph) + + e.GraphNode = (Func (e.Key) Children (e.Children)) +*/ + +$ENTRY OptTree-AutoMarkup-GetElemByKey { + (e.Key) (e.GraphHead (Func (e.Key) Children (e.Children)) e.GraphTail) + = Func (e.Key) Children (e.Children) + (e.GraphHead (Func (e.Key) Children (e.Children)) e.GraphTail); + + (e.Key) (e.Graph) + = /* пусто */ (e.Graph); +} + +/** + == e.GraphNode* + + e.GraphNode = (Func (e.Key) Children (e.Children)) + + e.Children = (e._ (e.ChildName) e._) +*/ + +$ENTRY OptTree-AutoMarkup-GetParents { + (e.ChildName) + (e.Graph-B (Func (e.FuncName) Children (e._ (e.ChildName) e._)) e.Graph-E) + = (e.FuncName) + ; + + (e.ChildName) (e._) + = ; +} + +$ENTRY OptTree-AutoMarkup-IsEmpty { + () + = True; + + e.Other + = False; +} diff --git a/src/compiler/OptTree-AutoMarkup-GraphExtractor.ref b/src/compiler/OptTree-AutoMarkup-GraphExtractor.ref new file mode 100644 index 00000000..29bd6cd8 --- /dev/null +++ b/src/compiler/OptTree-AutoMarkup-GraphExtractor.ref @@ -0,0 +1,463 @@ +$INCLUDE "LibraryEx"; + +*$FROM DisplayName +$EXTERN DisplayName; + +*$FROM OptTree-AutoMarkup-Common +$EXTERN OptTree-AutoMarkup-Contains, + OptTree-AutoMarkup-GetElemByKey; + +/** + == e.FunctionCallsGraph +*/ + +$ENTRY OptTree-AutoMarkup-ExtractFunctionCallsGraph { + e.AST + = + : + { + (e.Node) (e.NodeIndirectChildren) + = ( + (e.GraphNodes (e.Node)) + (e.IndirectChildren e.NodeIndirectChildren) + ); + + e.Other + = ((e.GraphNodes) (e.IndirectChildren)); + } + + } + ((/*graph nodes*/) (/*indirect children*/)) e.AST + > + : ((e.ExtractedFuncs) (e.IndirectChildren)) + = + : e.MetatablesNames + = + : e.UniqueIndirectChildren + = + : e.ClearedUniqueIndirectChildren + = (Func (Indirect function for implicit calls) + Children (e.ClearedUniqueIndirectChildren)) + : e.IndirectFuncNode + = + : e.MetatablesNames + = + : e.ExtractedMetaTables + = + : e.InlinedGraph + = + : e.EntryPoints + = e.EntryPoints e.UniqueIndirectChildren + : e.EntryPoints^ + = + : ((e.ResultGraph) (e.InlinedGraph^)) + = ; +} + +OptTree-AutoMarkup-GetEntryPoints { + (Function GN-Entry (e.FuncName) Sentences e.Body) + = (e.FuncName); + + (Function s.Scope (e.FuncName) Sentences e.Body) + , : True + = (e.FuncName); + + e.Smth + = ; +} + +OptTree-AutoMarkup-GetClearedByEntryPointsGraph { + (e.Graph) (e.EntryPoints) + = ; + + (e.Graph) (e.ProccessedNodes) (e.EntryPoints) + = : False + = (e.ProcessedNodes (e.EntryPoint)) + : (e.NewProcessedNodes) + = + : e.Node (e.Graph^) + = e.Node + : { + Func (e.FuncName) Children (e.Children) + = + : ((e.SubTreeResult) (e.Graph^)) + = ( + (e.NewProcessedNodes) + ( + e.Result + (Func (e.FuncName) Children (e.Children)) + e.SubTreeResult + ) + (e.Graph) + ); + + e._ + = ( + (e.NewProcessedNodes) + (e.Result) + (e.Graph) + ); + }; + + ((e.ProcessedNodes) (e.Result) (e.Graph^)) e.Other + = ((e.ProcessedNodes) (e.Result) (e.Graph)); + } + ((e.ProccessedNodes) (/*result*/) (e.Graph)) e.EntryPoints + > + : ((e.ProccessedNodes^) (e.Result) (e.Graph^)) + = ((e.Result) (e.Graph)) +} + +OptTree-AutoMarkup-GetMetatables { + (Function s.ScopeClass (e.Name) Metatable e.Metatable) + = + : e.FunctionCalls + = (e.Name ()); + + e.Smth + = ; +} + +OptTree-AutoMarkup-GetMetatablesNames { + (Function s.ScopeClass (e.Name) Metatable e.Metatable) + = (e.Name); + + e.Smth + = ; +} + +OptTree-AutoMarkup-GetFuncs { + (Function s.ScopeClass (e.Name) Sentences e.Body) + = + : (e.SentenceDirectCalls) + (e.SentecnseImplicitCalls) + (e.SentecnseIndirectChildren) + = ( + (e.DirectCalls e.SentenceDirectCalls) + (e.ImplicitCalls e.SentecnseImplicitCalls) + (e.IndirectChildren e.SentecnseIndirectChildren) + ) + } + ((/*direct calls*/) (/*implicit calls*/) (/*indirect children*/)) + e.Body + > + : ((e.DirectCalls) (e.ImplicitCalls) (e.IndirectChildren)) + = : e.UniqueDirectCalls + = (e.ImplicitCalls) + : { + () + = ; + + (e._) + = (Indirect function for implicit calls) + } + : e.IndirectChild + = (Func (e.Name) Children (e.UniqueDirectCalls e.IndirectChild)) + (e.IndirectChildren); + + e.Smth + = ; +} + +OptTree-AutoMarkup-ExtractFunctionCallsFromMetatable { + ((Symbol Identifier e.Ident) (Symbol Name e.Name)) + = (e.Name); +} + +OptTree-AutoMarkup-ExtractFunctionCallsFromSentencesBody { + ((e.Pattern) e.Conditions (e.Result)) + = + : (e.PatternNames) (e.PatternIndirectCalls) (e.PatternIndirectChildren) + = + : (e.ConditionResultCalls) + (e.ConditionResultIndirectCalls) + (e.ConditionResultIndirectChildren) + = + : (e.ConditionPatternCalls) + (e.ConditionPatternIndirectCalls) + (e.ConditionPatternIndirectChildren) + = ( + ( + e.DirectCalls + e.ConditionResultCalls + e.ConditionPatternCalls + ) + ( + e.IndirectCalls + e.ConditionResultIndirectCalls + e.ConditionPatternIndirectCalls + ) + ( + e.IndirectChildren + e.ConditionResultIndirectChildren + e.ConditionPatternIndirectChildren + ) + ); + } + ((/*direct calls*/) (/*indirect calls*/) (/*indirect children*/)) + e.Conditions + > + : ( + (e.ConditionNames) + (e.ConditionIndirectCalls) + (e.ConditionIndirectChildren) + ) + = + : (e.ResultNames) (e.ResultIndirectCalls) (e.ResultIndirectChildren) + = ( + e.PatternNames + e.ConditionNames + e.ResultNames + ) + ( + e.PatternIndirectCalls + e.ConditionIndirectCalls + e.ResultIndirectCalls + ) + ( + e.PatternIndirectCalls + e.ConditionIndirectChildren + e.ResultIndirectChildren + ); +} + +OptTree-AutoMarkup-InnerExtractExpressionName { + (e.Expr) (e.DirectCalls) (e.IndirectDetected) (e.IndirectChildren) + = : True + = ; + + ((e.DirectCalls^) (e.IndirectDetected^) (e.IndirectChildren^)) + (CallBrackets + (Symbol Name e.Name) + e.NestedHead + (Symbol Name e.IndirectChild) + e.NestedTail + ) + = (e.IndirectChild) + + : e.AdditionaIndirectChildren + = + : e.Nested^ + = + : ( + (e.DirectCalls^) + (e.IndirectDetected^) + (e.IndirectChildren^) + ) + = ( + (e.DirectCalls (e.Name)) + (e.IndirectDetected) + (e.IndirectChildren e.AdditionaIndirectChildren) + ); + + ((e.DirectCalls^) (e.IndirectDetected^) (e.IndirectChildren^)) + (CallBrackets (Symbol Name e.Name) e.Nested) + = + : ( + (e.DirectCalls^) + (e.IndirectDetected^) + (e.IndirectChildren^) + ) + = ( + (e.DirectCalls (e.Name)) + (e.IndirectDetected) + (e.IndirectChildren) + ); + + ((e.DirectCalls^) (e.IndirectDetected^) (e.IndirectChildren^)) + (CallBrackets e.Nested) + = + : ( + (e.DirectCalls^) + (e.IndirectDetected^) + (e.IndirectChildren^) + ) + = ( + (e.DirectCalls) + (Indirect detected) + (e.IndirectChildren) + ); + + ((e.DirectCalls^) (e.IndirectDetected^) (e.IndirectChildren^)) + (t.Marker e.Smth) + = ((e.DirectCalls) (e.IndirectDetected) (e.IndirectChildren)); + } + ((e.DirectCalls) (e.IndirectDetected) (e.IndirectChildren)) + e.Expr + >; +} + +OptTree-AutoMarkup-ExtractExpressionName { + e.Expr + = + : ((e.DirectCalls) (e.IndirectDetected) (e.IndirectChildren)) + = (e.DirectCalls) (e.IndirectDetected) (e.IndirectChildren) +} + +OptTree-AutoMarkup-InlineFuncCallsWithMetatable { + (e.ExtractedFuncs) (e.ExtractedMetaTables) + = ; + } + e.ExtractedFuncs + >; +} + +OptTree-AutoMarkup-InlineOneFuncChildrenWithMetatable { + (Func (e.Name) Children (e.UniqueFunctionCalls)) (e.ExtractedMetaTables) + = ; + } + e.UniqueFunctionCalls + > + : e.ReplacedChildren + = + : e.UniqueReplacedChildren + = (Func (e.Name) Children (e.UniqueReplacedChildren)); +} + +OptTree-AutoMarkup-GetCallsFromMetaTables { + (e.FuncName) (e.ExtractedMetaTables) + = () + : e.ReplaceValue + = ; +} \ No newline at end of file diff --git a/src/compiler/OptTree-AutoMarkup-SpecializableExtractor.ref b/src/compiler/OptTree-AutoMarkup-SpecializableExtractor.ref new file mode 100644 index 00000000..625943df --- /dev/null +++ b/src/compiler/OptTree-AutoMarkup-SpecializableExtractor.ref @@ -0,0 +1,329 @@ +$INCLUDE "LibraryEx"; + +*$FROM GlobalGen +$EXTERN GlobalGen; + +*$FROM GenericMatch +$EXTERN GenericMatch; + +*$FROM Log +$EXTERN Log-PutLine; + +/** + + == ((e.FuncName) '->' ((e.TypedVariable)+)) + + e.TypedVariable = {s.VariableType} + {STAT | dyn} + {index} +*/ + +$ENTRY OptTree-AutoMarkup-GetSpecializableDict { + (e.AST) + = + : e.ExtractedPatterns + = + : { + True + = (NOTSPECIALIZABLE (e.Name)); + + False + = + : e.SpecifiedPattern + = + : e.DictNode + = e.DictNode; + }; + + e.Other + = ; + } + e.AST + >; + + e.Other + = ; +} + +OptTree-AutoMarkup-GetSpecializableDictNode { + (e.FuncName) (e.SpecifiedPattern) + , e.SpecifiedPattern : e.Head ('e.STAT' e.Suffix) e.Tail + = (SPECIALIZABLE (e.FuncName) '->' (e.SpecifiedPattern)); + + (e.FuncName) e.Other + = (NOTSPECIALIZABLE (e.FuncName)); +} + +OptTree-AutoMarkup-ContainsDuplications { + (e.ExtractedPatterns) + = + : e.Stm + = e.Stm + : { + e.Head (e.Variable) e._ (e.Variable) e.Tail + = (True); + + e.Other + = (False); + }; + } + e.ExtractedPatterns + > + : { + e.Head (True) e.Tail + = True; + + e.Other + = False; + } +} + +OptTree-AutoMarkup-GetPatternVariables { + (TkVariable e.Name) + = (e.Name); + + (Symbol Identifier VAR e.Name) + = (e.Name); + + (Brackets e.Nested) + = ; + } + e.Nested + >; + + (e.Other) + = ; +} + +OptTree-AutoMarkup-GetSpecifiedPattern { + (e.ExtractedPatterns) + = + : e.IndexedGlobalGens + = + : e.GenericMatch + = (e.GenericMatch); + } + e.ExtractedPatterns + > + : e.GenericMatches + = + : e.VariableMatchesDict + = + : e.TypedVariables + = e.TypedVariables; +} + +OptTree-AutoMarkup-GetIndexedGlobalGens { + () + = (); + + (e.Patterns) + = + : e.GlobalGens + = + : e.Result + = + : e.Result^ + = + : e.Result^ + = e.Result; + + e.Other + = ; +} + +OptTree-AutoMarkup-FillIndexes { + (e.GlobalGens) s.Type + = + : (e._) e.IndexedTypeGlobalGens + = e.IndexedTypeGlobalGens; + + (e.StartIndex) (e.GlobalGens) s.Type + = + : e.NewIndex + = (e.NewIndex) (e.IndexedVariable); + + (e.CurrentIndex) (TkVariable e.Other) + = (e.CurrentIndex) (TkVariable e.Other); + + (e.CurrentIndex) (Brackets e.Nested) + = + : (e.NextIndex) e.IndexedTypeGlobalGens + = (e.NextIndex) (Brackets e.IndexedTypeGlobalGens); + + (e.CurrentIndex) (e.Other) + = (e.CurrentIndex) (e.Other); + } + (e.StartIndex) e.GlobalGens + > +} + +OptTree-AutoMarkup-GetVariableMatchesByIndexedGlobalGen { + TkVariable e.VariableName (e.GenericMatches) + = ; + + e.Other + = ; + } + e.GenericMatches + > + : e.CurrentVariableRes + = + : e.CurrentVariableTypeRes + = (e.VariableName ':' e.CurrentVariableTypeRes); + + Brackets e.Nested (e.GenericMatches) + = ; + + (e.Nested) (e.GenericMatches) + = ; + + e.Other + = ; +} + +OptTree-AutoMarkup-GetVariableMatches { + (e.GenericMatches) (e.IndexedGlobalGens) + = ; + } + e.IndexedGlobalGens + > +} + +OptTree-AutoMarkup-GetVariablesTypes{ + () + = (); + + TkVariable 's' e._ + = TkVariable 's'; + TkVariable 't' e._ + = TkVariable 't'; + TkVariable 'e' e._ + = TkVariable 'e'; + + Symbol e.Tail + = Symbol e.Tail; + + Symbol Char e.Tail + = Symbol Char e.Tail; + + Brackets e.Nested + = + : e.NestedRes + = Brackets e.NestedRes; + + (e.Nested) e.Tail + = () + ; + + e.Other + = e.Other; +} + +OptTree-AutoMarkup-IsAllEqual { + (e.Single) + = True; + + (e.Value) (e.Value) + = True; + + (e.First) (e.Next) e.Tail + , e.Next : e.First + = ; + + e._ + = False; +} + +OptTree-AutoMarkup-GetMatchesByVariableName { + (e.Key) (e.Head (e.Value ':' (e.Key)) e.Tail) + = (e.Value); + + (e.Key) e.Other + = ; +} + +OptTree-AutoMarkup-GetVariableSpecType { + (e.VariableMatchesDict) + = + : { + True + = (t.VariableType '.STAT' t.VariableIndex); + + False + = (t.VariableType '.dyn' t.VariableIndex); + } + } + e.VariableMatchesDict + > +} \ No newline at end of file diff --git a/src/compiler/OptTree-AutoMarkup.ref b/src/compiler/OptTree-AutoMarkup.ref index 6a1f7fd0..0ca75f17 100644 --- a/src/compiler/OptTree-AutoMarkup.ref +++ b/src/compiler/OptTree-AutoMarkup.ref @@ -1,10 +1,195 @@ +$INCLUDE "LibraryEx"; + +*$FROM Log +$EXTERN Log-PutLine, Log-AST; + +*$FROM DisplayName +$EXTERN DisplayName; + +*$FROM OptTree-AutoMarkup-GraphExtractor +$EXTERN OptTree-AutoMarkup-ExtractFunctionCallsGraph; + +*$FROM OptTree-AutoMarkup-SpecializableExtractor +$EXTERN OptTree-AutoMarkup-GetSpecializableDict; + +*$FROM OptTree-AutoMarkup-BasisVertexesExtractor +$EXTERN OptTree-AutoMarkup-ExtractBasisVertexes; + +*$FROM OptTree-AutoMarkup-Common +$EXTERN OptTree-AutoMarkup-Contains, + OptTree-AutoMarkup-GetSetDifference, + OptTree-AutoMarkup-IsEmpty; + /** == e.AST */ + $ENTRY OptTree-AutoMarkup { - NoOpt e.AST = e.AST; + NoOpt e.AST + = : + = e.AST; OptAutoMarkup e.AST -* TODO: реализовать разметку - = e.AST; + = + : e.SpecializableDict + = + : e.ForbiddenToSpecializeFunctionNames + = + : e.SpecPatterns + = + : e.ExtractedGraph + = + : (e.BasisVertexes) (e.ExtractedGraph^) + = + : e.DrivenFunctions + = + : e.ForbiddenToDriveFuncs + = + : (e.FunctionToDrive) + = + : e.DrivedAst + = e.DrivedAst e.SpecPatterns; +} + +OptTree-AutoMarkup-GetForbiddenToSpecializeFunctionNames { + (e.AST) + = +} + +OptTree-AutoMarkup-GetSpecializePatterns { + (e.SpecializableDict) (e.Filter) + = ' (e.SpecifiedPattern)) + , : False + , : False + = + : e.MarkedSpecPattern + = (Spec (e.FuncName) e.MarkedSpecPattern); + + e.Other + = ; + } + e.SpecializableDict + > +} + +OptTree-AutoMarkup-GetForbiddenToDriveFunctions { + e.AST + = (INIT) (FINAL) + : True + = (e.Name); + + (Declaration GN-Entry e.FuncName) + = (e.FuncName); + + (Function GN-Entry (e.FuncName) Sentences e.Body) + = (e.FuncName); + + (Function s.Scope (e.FuncName) Sentences e.Body) + , (e.FuncName) : (e.Head '*' s.Num e.Tail) + = (e.FuncName); + + (Function s.Scope (e.FuncName) Sentences e.Body) + = + : s.SentencesCount e.Body^ + = + : { + '>' + = (e.FuncName); + + e.Other + = ; + }; + + e.Other + = ; + } + e.AST + > +} + +OptTree-AutoMarkup-GetDrivenFunctions { + (e.ExtractedGraph) (e.BasisVertexes) + = : False + = (e.FuncName); + + e.Other + = ; + } + e.ExtractedGraph + > } + +OptTree-AutoMarkup-GetUpdatedWithDrivenFunctionsAst { + (e.AST) (e.FunctionsToDrive) (e.BasisVertexes) + = + : e.DrivedFunctions + = + : e.ClearAST + = e.ClearAST e.DrivedFunctions; +} \ No newline at end of file