From dad51824802bb99bfa507669ce553fba10c85e34 Mon Sep 17 00:00:00 2001 From: Matway Burkow <2745204+MatwayBurkow@users.noreply.github.com> Date: Wed, 15 Jul 2020 17:55:38 +0300 Subject: [PATCH] Refactor matching to use comparison trees instead of linear lookup Improve compilation speed Do not overwrite .ll files if the result did not change, write the result to .ll.temp instead, to facilitate build systems which depend on file timestamps (for example, MSBuild) Make [dynamic] built-in dynamize values instead of marking them dirty Fix aggressive caching that leads to variables having old values after being updated by reference Fix that variables created with newVarOfTheSameType do not destruct properly Fix that debug information provides the wrong location before function entry Fix that predicates do not compile properly inside of a loop --- Block.mpl | 87 +++-- NameManager.mpl | 16 + Var.mpl | 19 +- astNodeType.mpl | 28 +- astOptimizers.mpl | 18 +- builtinImpl.mpl | 28 +- builtins.mpl | 3 +- codeNode.mpl | 752 ++++++++++++++++++-------------------------- declarations.mpl | 8 +- defaultImpl.mpl | 556 +++++++++++++++++++++++++++++--- irWriter.mpl | 11 +- main.mpl | 26 +- parser.mpl | 72 +++-- processSubNodes.mpl | 573 ++++++++++++++++++--------------- processor.mpl | 23 +- processorImpl.mpl | 71 +++-- variable.mpl | 12 +- 17 files changed, 1391 insertions(+), 912 deletions(-) diff --git a/Block.mpl b/Block.mpl index 442b380..5624b08 100644 --- a/Block.mpl +++ b/Block.mpl @@ -14,9 +14,10 @@ ArgRef: [2n8 dynamic]; ArgCopy: [3n8 dynamic]; ArgDerefCopy: [4n8 dynamic]; ArgMeta: [5n8 dynamic]; -ArgReturn: [6n8 dynamic]; -ArgRefDeref: [7n8 dynamic]; -ArgReturnDeref: [8n8 dynamic]; +ArgAlreadyUsed: [6n8 dynamic]; +ArgReturn: [7n8 dynamic]; +ArgRefDeref: [8n8 dynamic]; +ArgReturnDeref: [9n8 dynamic]; NameCaseInvalid: [ 0n8 dynamic]; NameCaseBuiltin: [ 1n8 dynamic]; @@ -63,7 +64,8 @@ Argument: [{ Capture: [{ refToVar: RefToVar; argCase: ArgRef; - captureCase: NameCaseInvalid; + stable: Cond; + mplFieldIndex: -1 dynamic; nameInfo: -1 dynamic; nameOverloadDepth: -1 dynamic; file: ["MplFile.FileSchema" use FileSchema] Mref; @@ -80,16 +82,7 @@ CompilerPositionInfo: [{ file: ["MplFile.FileSchema" use FileSchema] Mref; line: -1 dynamic; column: -1 dynamic; - token: String; -}]; - -FieldCapture: [{ - object: RefToVar; - captureCase: NameCaseInvalid; - nameInfo: -1 dynamic; - nameOverloadDepth: -1 dynamic; - fieldIndex: -1 dynamic; - file: ["MplFile.FileSchema" use FileSchema] Mref; + token: StringView; }]; makeInstruction: [{ @@ -106,21 +99,13 @@ makeInstruction: [{ Instruction: [0 0 makeInstruction]; -ShadowEvent: [( - Cond #ShadowReasonNo - ShadowEventCapture #ShadowReasonCapture - ShadowEventStableName #ShadowReasonStableName - ShadowEventFieldCapture #ShadowReasonFieldCapture - ShadowEventInput #ShadowReasonInput - ShadowEventField #ShadowReasonField - ShadowEventPointee #ShadowReasonPointee -) Variant]; - MatchingInfo: [{ inputs: Argument Array; #for generating signatures captures: Capture Array; #for generating signatures, for finding 'self' shadowEvents: ShadowEvent Array; lastTopologyIndex: 0 dynamic; + currentInputCount: 0 dynamic; + maxInputCount: 0 dynamic; }]; NameWithOverload: [{ @@ -150,8 +135,6 @@ ShadowEventInput: [Argument]; ShadowEventCapture: [Capture]; -ShadowEventFieldCapture: [FieldCapture]; - ShadowEventField: [{ object: RefToVar; field: RefToVar; @@ -163,28 +146,35 @@ ShadowEventPointee: [{ pointee: RefToVar; }]; -ShadowEventStableName: [{ - nameInfo: Int32; -}]; +ShadowEvent: [( + Cond #ShadowReasonNo + ShadowEventCapture #ShadowReasonCapture + ShadowEventInput #ShadowReasonInput + ShadowEventField #ShadowReasonField + ShadowEventPointee #ShadowReasonPointee + Cond #ShadowReasonLambda +) Variant]; Block: [{ - id: Int32; - root: FALSE dynamic; - file: ["MplFile.FileSchema" use FileSchema] Mref; - topNode: [@BlockSchema] Mref; - capturedFiles: Cond Array; - beginPosition: CompilerPositionInfo; - parent: 0 dynamic; - nodeCase: NodeCaseCode; - stack: RefToVar Array; # we must compile node without touching parent - minStackDepth: 0 dynamic; - programTemplate: String; - program: Instruction Array; - aliases: String Array; - lastLambdaName: Int32; - nextRecLambdaId: -1 dynamic; - globalPriority: Int32; - + id: Int32; + root: FALSE dynamic; + file: ["MplFile.FileSchema" use FileSchema] Mref; + topNode: [@BlockSchema] Mref; + capturedFiles: Cond Array; + beginPosition: CompilerPositionInfo; + parent: 0 dynamic; + nodeCase: NodeCaseCode; + stack: RefToVar Array; # we must compile node without touching parent + minStackDepth: 0 dynamic; + programTemplate: String; + program: Instruction Array; + aliases: String Array; + lastLambdaName: Int32; + nextRecLambdaId: -1 dynamic; + globalPriority: Int32; + + instructionCountBeforeRet: Int32; + hasCallImport: FALSE dynamic; hasEmptyLambdas: FALSE dynamic; nodeIsRecursive: FALSE dynamic; nextLabelIsVirtual: FALSE dynamic; @@ -220,8 +210,7 @@ Block: [{ fromModuleNames: NameWithOverloadAndRefToVar Array; labelNames: NameWithOverloadAndRefToVar Array; - captureNames: NameWithOverloadAndRefToVar Array; - fieldCaptureNames: NameWithOverloadAndRefToVar Array; + captureNames: NameWithOverload Array; stableNames: Int32 Array; candidatesToDie: RefToVar Array; @@ -231,7 +220,7 @@ Block: [{ refToVar: RefToVar; #refToVar of function with compiled node varNameInfo: -1 dynamic; #variable name of imported function astArrayIndex: -1 dynamic; - matchingInfoIndex: -1 dynamic; + matchingChindIndex: -1 dynamic; exportDepth: 0 dynamic; namedFunctions: String Int32 HashTable; # name -> node ID capturedVars: RefToVar Array; diff --git a/NameManager.mpl b/NameManager.mpl index 9e8dacf..3455a96 100644 --- a/NameManager.mpl +++ b/NameManager.mpl @@ -46,6 +46,22 @@ NameManager: [{ index ]; + findItemStrong: [ + index: file: nameId:;; copy; + items: nameId names.at.items; + + index -1 = [items.size !index] when + [ + index 1 - !index + index -1 = [ + itemFile: index items.at.file; + file isNil [itemFile file is] || + ] || ~ + ] loop + + index + ]; + hasOverload: [ nameId: copy; nameId @names.at.overloadCount 0 > diff --git a/Var.mpl b/Var.mpl index b332a9d..00fd39d 100644 --- a/Var.mpl +++ b/Var.mpl @@ -13,13 +13,12 @@ Weak: [2n8 dynamic]; Static: [3n8 dynamic]; Virtual: [4n8 dynamic]; -ShadowReasonNo: [0]; -ShadowReasonCapture: [1]; -ShadowReasonStableName: [2]; -ShadowReasonFieldCapture: [3]; -ShadowReasonInput: [4]; -ShadowReasonField: [5]; -ShadowReasonPointee: [6]; +ShadowReasonNo: [0]; +ShadowReasonCapture: [1]; +ShadowReasonInput: [2]; +ShadowReasonField: [3]; +ShadowReasonPointee: [4]; +ShadowReasonTreeSplitterLambda: [5]; VarInvalid: [ 0 static]; VarCond: [ 1 static]; @@ -137,6 +136,7 @@ Variable: [{ storageStaticity: Static; global: FALSE dynamic; usedInHeader: FALSE dynamic; + usedInParams: FALSE dynamic; capturedByPtr: FALSE dynamic; capturedAsRealValue: FALSE dynamic; capturedForDeref: FALSE dynamic; @@ -202,6 +202,11 @@ isVirtual: [ [refToVar isVirtualType] || ]; +noMatterToCopy: [ + refToVar:; + refToVar isVirtual [refToVar isAutoStruct ~] && +]; + isVirtualType: [ refToVar:; diff --git a/astNodeType.mpl b/astNodeType.mpl index 1b574e0..8ee4c4a 100644 --- a/astNodeType.mpl +++ b/astNodeType.mpl @@ -45,12 +45,19 @@ NamedBranch: [{ nameInfo: 0 dynamic; #index in NameInfo pool }]; +makePositionInfo: [{ + token: String; + column: copy; + line: copy; + offset: copy; + fileId: copy; +}]; + +PositionInfo: [-1 dynamic -1 dynamic 1 dynamic 0 dynamic makePositionInfo]; + AstNode: [{ virtual AST_NODE: (); - token: String; - column: -1 dynamic; - line: -1 dynamic; - fileId: -1 dynamic; + positionInfo: PositionInfo; data: ( IndexOfArray #CodeNode: NamedRecursiveBranch #LabelNode: @@ -80,14 +87,11 @@ AstNode: [{ INIT: []; DIE: []; # default life control, and ban uneffective copy, because object is too big }]; -makePositionInfo: [{ - column: copy; - line: copy; - offset: copy; +AstNodeArray: [{ + positionInfo: PositionInfo; + nodes: AstNode Array; }]; -PositionInfo: [-1 dynamic 1 dynamic 0 dynamic makePositionInfo]; - ParserResult: [{ virtual PARSER_RESULT: (); success: TRUE dynamic; @@ -96,7 +100,7 @@ ParserResult: [{ position: PositionInfo; }; - memory: AstNode Array Array; + memory: AstNodeArray Array; root: IndexOfArray; INIT: []; DIE: []; # default life control, and ban uneffective copy, because object is too big @@ -105,7 +109,7 @@ ParserResult: [{ ParserResults: [ParserResult Array]; MultiParserResult: [{ - memory: AstNode Array Array; + memory: AstNodeArray Array; roots: IndexOfArray Array; # order of going is not defined before compiling INIT: []; DIE: []; # default life control, and ban uneffective copy, because object is too big diff --git a/astOptimizers.mpl b/astOptimizers.mpl index 7284614..9032da8 100644 --- a/astOptimizers.mpl +++ b/astOptimizers.mpl @@ -11,16 +11,18 @@ optimizeLabels: [ @parserResult.@memory [ currentIndexArray:; - newIndexArray: AstNode Array; - @currentIndexArray [ + newIndexArray: AstNodeArray; + @currentIndexArray.@positionInfo move @newIndexArray.@positionInfo set + + @currentIndexArray.@nodes [ current:; current.data.getTag AstNodeType.Label = [ - AstNodeType.Label current.data.get.children @parserResult.@memory.at [ - move @newIndexArray.pushBack + AstNodeType.Label current.data.get.children @parserResult.@memory.at.@nodes [ + move @newIndexArray.@nodes.pushBack ] each ] when - @current move @newIndexArray.pushBack + @current move @newIndexArray.@nodes.pushBack ] each @newIndexArray move @currentIndexArray set @@ -51,7 +53,7 @@ optimizeNames: [ parserResult: nameManager: ;; @parserResult.@memory [ - [ + .@nodes [ optimizeNamesInCurrentNode ] each ] each @@ -61,7 +63,6 @@ concatParserResult: [ mresult:; current:; shift: mresult.memory.getSize; - fileId: mresult.roots.getSize; adjustArray: [ astArrayIndex:; @@ -72,9 +73,8 @@ concatParserResult: [ @current.@memory [ currentArray:; - @currentArray [ + @currentArray.@nodes [ currentNode:; - fileId @currentNode.@fileId set currentNode.data.getTag AstNodeType.Code = [ AstNodeType.Code @currentNode.@data.get adjustArray diff --git a/builtinImpl.mpl b/builtinImpl.mpl index c67c7b9..eaee665 100644 --- a/builtinImpl.mpl +++ b/builtinImpl.mpl @@ -980,6 +980,14 @@ staticityOfBinResult: [ ) sequence ] "mplBuiltinDef" @declareBuiltin ucall +[ + refToVar: @processor @block pop; + processor compilable [ + refToVar @processor @block makeVarTreeDynamic + refToVar @block push + ] when +] "mplBuiltinDynamic" @declareBuiltin ucall + [ refToVar: @processor @block pop; processor compilable [ @@ -1485,6 +1493,10 @@ staticityOfBinResult: [ result isVirtual ~ [ TRUE @result.setMutable @result @processor @block createAllocIR @processor @block callInit + + result isAutoStruct [ + result @block.@candidatesToDie.pushBack + ] when ] when result @block push @@ -1518,6 +1530,15 @@ staticityOfBinResult: [ @processor block defaultPrintStackTrace ] "mplBuiltinPrintStackTrace" @declareBuiltin ucall + +[ + ("Print shadow events for block " block.id " in astNode " block.astArrayIndex LF) printList + block.buildingMatchingInfo.shadowEvents.size [ + event: i block.buildingMatchingInfo.shadowEvents.at; + event i TRUE @processor @block printShadowEvent + ] times +] "mplBuiltinPrintShadowEvents" @declareBuiltin ucall + [ debugMemory [ ("compilerMaxAllocationSize=" getMemoryMetrics.memoryMaxAllocationSize LF) printList @@ -1782,7 +1803,7 @@ tryFindInPath: [ @fullFileName checkLoadedFile ~ [ loadStringResult: fullFileName loadString; loadStringResult.success [ - errorInfo: fullFileName makeStringView loadStringResult.data makeStringView @processor.@multiParserResult @processor.@nameManager addToProcess; + errorInfo: processor.files.getSize fullFileName makeStringView loadStringResult.data makeStringView @processor.@multiParserResult @processor.@nameManager addToProcess; errorInfo "" = [ fileId: FALSE fullFileName makeStringView @processor addFileNameToProcessor; fullFileName @processor.@options.@fileNames.pushBack @@ -1891,6 +1912,7 @@ tryFindInPath: [ addNameData.size [ current: addNameData.size 1 - i - addNameData.at; + { addNameCase: NameCaseFromModule; refToVar: current.refToVar copy; @@ -1913,7 +1935,7 @@ tryFindInPath: [ CALL: [nameInfo:; fr: nameInfo @indexes.find; fr.success [ - result: fr.value.index file nameInfo @processor.@nameManager.findItem; + result: fr.value.index file nameInfo @processor.@nameManager.findItemStrong; result @fr.@value.@index set fr.value.depth 1 + @fr.@value.@depth set fr.value.index copy fr.value.depth copy @@ -1932,7 +1954,7 @@ tryFindInPath: [ index: -1; CALL: [ nameInfo:; - index file nameInfo @processor.@nameManager.findItem !index + index file nameInfo @processor.@nameManager.findItemStrong !index depth 1 + !depth index depth ]; diff --git a/builtins.mpl b/builtins.mpl index 382cc22..deb7a46 100644 --- a/builtins.mpl +++ b/builtins.mpl @@ -43,7 +43,7 @@ builtins: ( {name: "copy" ; impl: @mplBuiltinCopy ;} {name: "cos" ; impl: @mplBuiltinCos ;} {name: "def" ; impl: @mplBuiltinDef ;} - {name: "dynamic" ; impl: @mplBuiltinDirty ;} + {name: "dynamic" ; impl: @mplBuiltinDynamic ;} {name: "exportFunction" ; impl: @mplBuiltinExportFunction ;} {name: "exportVariable" ; impl: @mplBuiltinExportVariable ;} {name: "failProc" ; impl: @mplBuiltinFailProc ;} @@ -75,6 +75,7 @@ builtins: ( {name: "or" ; impl: @mplBuiltinOr ;} {name: "overload" ; impl: @mplBuiltinOverload ;} {name: "printCompilerMessage" ; impl: @mplBuiltinPrintCompilerMessage ;} + {name: "printShadowEvents" ; impl: @mplBuiltinPrintShadowEvents ;} {name: "printStack" ; impl: @mplBuiltinPrintStack ;} {name: "printStackTrace" ; impl: @mplBuiltinPrintStackTrace ;} {name: "raiseStaticError" ; impl: @mplBuiltinRaiseStaticError ;} diff --git a/codeNode.mpl b/codeNode.mpl index db16576..d1d4809 100644 --- a/codeNode.mpl +++ b/codeNode.mpl @@ -4,6 +4,7 @@ "String" use "control" use "conventions" use +"memory" use "Block" use "MplFile" use @@ -18,12 +19,18 @@ "staticCall" use "variable" use +startsFrom: [ + s1: s2: makeStringView; makeStringView; + s1.size s2.size < ~ [s2.size Natx cast s2.data storageAddress s1.data storageAddress memcmp 0 =] && +]; + addNameInfo: [ processor: block: ;; params:; forOverload: params "overload" has [params.overload copy] [FALSE dynamic] if; mplFieldIndex: params "mplFieldIndex" has [params.mplFieldIndex copy] [-1 dynamic] if; + object: params "object" has [params.object copy] [RefToVar] if; reg: params "reg" has [params.reg copy] [TRUE dynamic] if; startPoint: params "startPoint" has [params.startPoint copy] [block.id copy] if; overloadDepth: params "overloadDepth" has [params.overloadDepth copy] [0 dynamic] if; @@ -34,6 +41,12 @@ addNameInfo: [ [params.refToVar.assigned] "Add name must have corrent refToVar!" assert + #reg [block.parent 0 =] && [ + # nameInfo processor.nameManager.getText "lambda." startsFrom [ + # "Lambdas are not allowed in root!" failProc + # ] when + #] when + [ nameInfo 0 < ~ [ addInfo: TRUE; @@ -54,11 +67,9 @@ addNameInfo: [ nameWithOverload @block.@fromModuleNames.pushBack ] [ addNameCase NameCaseCapture = [addNameCase NameCaseSelfObjectCapture =] || [addNameCase NameCaseClosureObjectCapture =] || [ - nameWithOverload @block.@captureNames.pushBack FALSE @addInfo set ] [ addNameCase NameCaseSelfMember = [addNameCase NameCaseClosureMember =] || [ - nameWithOverload @block.@fieldCaptureNames.pushBack FALSE @addInfo set ] [ addNameCase NameCaseSelfObject = [addNameCase NameCaseClosureObject =] || [ @@ -83,6 +94,7 @@ addNameInfo: [ isLocal: startPoint processor.blocks.at.get.parent 0 = ~; + object @nameInfoEntry.@object set refToVar @nameInfoEntry.@refToVar set addNameCase @nameInfoEntry.@nameCase set startPoint @nameInfoEntry.@startPoint set @@ -255,6 +267,24 @@ getLastShadow: [ @result ]; +updateInputCountInMatchingInfo: [ + delta: matchingInfo: ;; + + matchingInfo.currentInputCount delta + @matchingInfo.!currentInputCount + matchingInfo.currentInputCount matchingInfo.maxInputCount > [ + matchingInfo.currentInputCount copy @matchingInfo.!maxInputCount + ] when +]; + +updateInputCount: [ + delta: block:;; + + delta @block.@buildingMatchingInfo updateInputCountInMatchingInfo + block.state NodeStateNew = [ + delta @block.@matchingInfo updateInputCountInMatchingInfo + ] when +]; + { block: Block Ref; entry: RefToVar Cref; @@ -262,8 +292,18 @@ getLastShadow: [ entry: block:;; entry @block.@stack.pushBack + -1 @block updateInputCount ] "push" exportFunction +{ + block: Block Ref; + entry: RefToVar Cref; +} () {} [ + entry: block:;; + + entry @block.@stack.pushBack +] "pushForMatching" exportFunction + setTopologyIndex: [ block: refToVar: ;; @@ -372,7 +412,6 @@ getPointeeWith: [ refToVar noMatterToCopy ~ [sourceValueVar.capturedHead getVar.host block is ~] && [pointee noMatterToCopy ~] && [shadowUsed ~] && [sourceValueVar.staticity.begin Static =] && [ TRUE @shadowUsed set - newEvent: ShadowEvent; ShadowReasonPointee @newEvent.setTag branch: ShadowReasonPointee @newEvent.get; @@ -381,8 +420,9 @@ getPointeeWith: [ pointee @branch.@pointee set @block @branch.@pointee setTopologyIndex - @newEvent @block addShadowEvent + @newEvent @processor @block addShadowEvent ] when + ] when ] if @@ -449,13 +489,16 @@ getFieldWith: [ fieldRefToVar noMatterToCopy ~ [ structIsDynamicStoraged [ mplFieldIndex structInfo.fields.at.usedHere ~ [ - fieldRefToVar @processor @block copyOneVarFromType Dynamic @processor @block makeStorageStaticity @fieldShadow set + fieldRefToVar @processor @block copyOneVarFromType Dynamic @processor @block makeStorageStaticity Dirty @processor @block makeStaticity @fieldShadow set TRUE mplFieldIndex @structInfo.@fields.at.!usedHere TRUE ] && ] [ fieldVar.host block is ~ [ @fieldShadow fieldRefToVar ShadowReasonField @processor @block makeShadows + var.storageStaticity Virtual = [ + @fieldShadow Dirty @processor @block makeStaticity drop + ] when @fieldShadow @processor block unglobalize TRUE ] && @@ -474,7 +517,7 @@ getFieldWith: [ ] when ] when - refToVar.mutable @fieldRefToVar.setMutable + fieldRefToVar.mutable @fieldRefToVar.setMutable refToVar noMatterToCopy ~ [fieldRefToVar noMatterToCopy ~] && [ var.capturedHead getVar.host block is ~ [var.buildingTopologyIndex 0 < ~] && [mplFieldIndex structInfo.fields.at.usedHere ~] && [structIsDynamicStoraged ~] && [ @@ -489,7 +532,7 @@ getFieldWith: [ fieldRefToVar @branch.@field set @block @branch.@field setTopologyIndex - @newEvent @block addShadowEvent + @newEvent @processor @block addShadowEvent ] [ structIsDynamicStoraged [ (refToVar copy fieldRefToVar copy FALSE) @block.@dependentPointers.pushBack @@ -497,6 +540,7 @@ getFieldWith: [ ] if ] when + refToVar.mutable @fieldRefToVar.setMutable @fieldRefToVar ] [ "index is out of bounds" @processor block compilerError @@ -825,7 +869,7 @@ makeVarTreeDirty: [ var.data.getTag VarRef = [ lastRefToVar staticityOfVar Static = [ pointee: @lastRefToVar @processor @block getPointeeWhileDynamize; - pointee.mutable [pointee @unfinishedVars.pushBack] when + pointee @unfinishedVars.pushBack ] [ [lastRefToVar staticityOfVar Dynamic > ~] "Ref must be only Static or Dynamic!" assert ] if @@ -961,7 +1005,7 @@ createNamedVariable: [ block.nextLabelIsVirtual ~ [refToVar isVirtual ~] && [refToVar isGlobal] && ]; - var.temporary [refToVar isGlobalLabel] && [ + var.temporary [refToVar isGlobalLabel] && [ refToVar @processor @block makeVarTreeDirty Dirty @staticity set ] when @@ -1050,10 +1094,10 @@ processCodeNode: [ astNodeBranch: ; codeInfo: CodeNodeInfo; - processor.positions.last.file @codeInfo.@file.set - astNode.line copy @codeInfo.!line - astNode.column copy @codeInfo.!column - astNodeBranch copy @codeInfo.!index #it is index of array + processor.positions.last.file @codeInfo.@file.set + processor.positions.last.line copy @codeInfo.!line + processor.positions.last.column copy @codeInfo.!column + astNodeBranch copy @codeInfo.!index #it is index of array @codeInfo move makeVarCode @block push ]; @@ -1099,50 +1143,6 @@ processListNode: [ ] when ] "compilerErrorImpl" exportFunction -findLocalObject: [ - pattern: captureCase: block: resultRefToVar: ;; copy;; - - pattern @resultRefToVar set - i: 0 dynamic; - [ - i block.buildingMatchingInfo.captures.size < [ - currentCapture: i block.buildingMatchingInfo.captures.at; - currentCapture.captureCase captureCase = [ - currentCapture.refToVar pattern variablesAreSame - ] && [ - currentCapture.refToVar @resultRefToVar set - FALSE - ] [ - i 1 + @i set - TRUE - ] if - ] && - ] loop -]; - -findNameStackObject: [ - nameInfo: pattern: file: nameCase: result:; copy;;; copy; - - i: -1 dynamic; - [ - i file nameInfo processor.nameManager.findItem !i - i 0 < [ - processor.varForFails @result.@refToVar set - FALSE - ] [ - item: i nameInfo processor.nameManager.getItem; - nameCase item.nameCase = [pattern item.refToVar variablesAreSame] && [ - item.refToVar @result.@refToVar set - item.nameCase @result.@nameCase set - item.startPoint @result.@startPoint set - FALSE - ] [ - TRUE - ] if - ] if - ] loop -]; - findPossibleModules: [ nameInfo: processor: ;; @@ -1185,9 +1185,9 @@ catPossibleModulesList: [ getNameAs: [ file:; processor: block: ;; - copy overloadIndex:; copy forMatching:; - matchingCapture:; + + copy overloadIndex:; copy nameInfo:; unknownName: [ @@ -1211,7 +1211,10 @@ getNameAs: [ nameCase: NameCaseInvalid; }; - overloadIndex 0 < [overloadIndex file nameInfo processor.nameManager.findItem !overloadIndex] when + overloadIndex 0 < [ + overloadIndex file nameInfo processor.nameManager.findItem !overloadIndex + ] when + overloadIndex 0 < [ unknownName ] [ @@ -1221,29 +1224,13 @@ getNameAs: [ nameInfoEntry.nameCase @result.@nameCase set nameInfoEntry.startPoint @result.@startPoint set - nameCase: matchingCapture.captureCase NameCaseInvalid = [result.nameCase copy] [matchingCapture.captureCase copy] if; - - nameCase NameCaseSelfMember = [nameCase NameCaseClosureMember =] || [ - object: nameInfoEntry.refToVar; - fields: VarStruct object getVar.data.get.get.fields; - nameInfoEntry.mplFieldIndex 0 < ~ [nameInfoEntry.mplFieldIndex fields.getSize <] && [nameInfoEntry.mplFieldIndex fields.at.nameInfo nameInfo =] && [ - object nameCase MemberCaseToObjectCase @block @result.@object findLocalObject #tut nujen object - nameInfoEntry.mplFieldIndex @result.@mplFieldIndex set - nameInfoEntry.mplFieldIndex fields.at.refToVar @result.@refToVar set - object.mutable @result.@refToVar.setMutable - ] [ - ("Internal error, mismatch structures for name:" nameInfo processor.nameManager.getText) assembleString @processor block compilerError - ] if + nameInfoEntry.nameCase NameCaseSelfMember = [nameInfoEntry.nameCase NameCaseClosureMember =] || [ + object: nameInfoEntry.object; + nameInfoEntry.object @result.@object set + nameInfoEntry.mplFieldIndex @result.@mplFieldIndex set + nameInfoEntry.refToVar @result.@refToVar set ] [ - nameCase NameCaseSelfObject = [nameCase NameCaseClosureObject =] || [ - forMatching [ - nameInfo matchingCapture.refToVar file nameCase @result findNameStackObject - ] [ - nameInfoEntry.refToVar nameCase @block @result.@refToVar findLocalObject - ] if - ] [ - nameInfoEntry.refToVar @result.@refToVar set - ] if + nameInfoEntry.refToVar @result.@refToVar set ] if moveToTail: [ @@ -1268,22 +1255,22 @@ getNameAs: [ @result ]; -getName: [processor: block:;; Capture FALSE dynamic -1 dynamic @processor @block processor.positions.last.file getNameAs]; -getNameEverywhere: [processor: block:;; Capture FALSE dynamic -1 dynamic @processor @block File Cref getNameAs]; +getName: [processor: block:;; -1 dynamic FALSE dynamic @processor @block processor.positions.last.file getNameAs]; +getNameEverywhere: [processor: block:;; -1 dynamic FALSE dynamic @processor @block File Cref getNameAs]; getNameForMatching: [ processor: block: file: ;;; - TRUE dynamic -1 dynamic @processor @block file getNameAs + -1 dynamic TRUE dynamic @processor @block file getNameAs ]; getNameWithOverloadIndex: [ overloadIndex: processor: block: file: ;;;; - Capture FALSE dynamic overloadIndex @processor @block file getNameAs + overloadIndex FALSE dynamic @processor @block file getNameAs ]; getNameForMatchingWithOverloadIndex: [ overloadIndex: processor: block: file: ;;;; - TRUE dynamic overloadIndex @processor @block file getNameAs + overloadIndex TRUE dynamic @processor @block file getNameAs ]; nameResultIsStable: [ @@ -1298,7 +1285,7 @@ nameResultIsStable: [ ]; addStableName: [ - nameInfo: processor: block: ;;; + refToVar: nameInfo: nameOverloadDepth: file: processor: block: ;;;;;; nameInfo processor.captureTable.stableNames.getSize < ~ [nameInfo 1 + @processor.@captureTable.@stableNames.resize] when current: nameInfo @processor.@captureTable.@stableNames.at; @@ -1307,10 +1294,14 @@ addStableName: [ nameInfo @block.@stableNames.pushBack newEvent: ShadowEvent; - ShadowReasonStableName @newEvent.setTag - branch: ShadowReasonStableName @newEvent.get; - nameInfo @branch.@nameInfo set - @newEvent @block addShadowEvent + ShadowReasonCapture @newEvent.setTag + branch: ShadowReasonCapture @newEvent.get; + refToVar @branch.@refToVar set + nameInfo @branch.@nameInfo set + nameOverloadDepth @branch.@nameOverloadDepth set + file @branch.@file.set + TRUE @branch.@stable set + @newEvent @processor @block addShadowEvent ] when nameInfo @processor @block addToPossibleUnstables @@ -1336,15 +1327,17 @@ captureName: [ getNameResult: overloadDepth: processor: block: file: ;;;;; result: { - refToVar: RefToVar; - object: RefToVar; + matchingEntry: RefToVar; + object: RefToVar; + refToVar: RefToVar; }; checkStable: file getNameResult processor nameResultIsStable; file.fileId @block captureFileToBlock checkStable [ - getNameResult.nameInfo @processor @block addStableName + getNameResult.refToVar getNameResult.nameInfo overloadDepth file @processor @block addStableName + getNameResult.refToVar @result.@matchingEntry set getNameResult.refToVar @result.@refToVar set ] [ processor compilable [getNameResult.nameCase NameCaseInvalid = ~] && [ @@ -1354,26 +1347,27 @@ captureName: [ copy overloadDepth:; copy nameInfo:; + result: { - refToVar: refToVar copy; + object: RefToVar; + refToVar: RefToVar; newVar: FALSE; }; + shadow: RefToVar; getNameResult.startPoint block.id = ~ [@processor.@captureTable nameInfo overloadDepth captureCase refToVar getVar.mplSchemaId file @processor @block addBlockIdTo] && [ - refToVar @result.@refToVar set - - shadow: RefToVar; @shadow refToVar ShadowReasonCapture @processor @block makeShadows @shadow fullUntemporize newCapture: Capture; - shadow @newCapture.@refToVar set + shadow @newCapture.@refToVar set nameInfo @newCapture.@nameInfo set [getNameResult.overloadIndex 0 < ~] "name overload not initialized!" assert - overloadDepth @newCapture.@nameOverloadDepth set - captureCase @newCapture.@captureCase set - file @newCapture.@file.set + FALSE @newCapture.@stable set + getNameResult.mplFieldIndex @newCapture.@mplFieldIndex set + overloadDepth @newCapture.@nameOverloadDepth set + file @newCapture.@file.set refToVar isVirtual [ArgVirtual] [refToVar isGlobal [ArgGlobal] [ArgRef] if ] if @newCapture.@argCase set realCapture: newCapture.argCase ArgRef =; @@ -1387,16 +1381,11 @@ captureName: [ ] when ] when - nameInfo processor.specialNames.selfNameInfo = [overloadDepth 0 = ~] && [ - [FALSE] "Self cannot have overloads!" assert - ] when - - refToVar getVar.data.getTag VarString = ~ [ + refToVar getVar.data.getTag VarString = ~ refToVar getVar.data.getTag VarImport = ~ and [ newEvent: ShadowEvent; ShadowReasonCapture @newEvent.setTag branch: ShadowReasonCapture @newEvent.get; newCapture @branch set - shadow @branch.@refToVar set newCapture @block.@buildingMatchingInfo.@captures.pushBack block.state NodeStateNew = [ @@ -1404,101 +1393,67 @@ captureName: [ ] when @block @shadow setTopologyIndex - @newEvent @block addShadowEvent + @newEvent @processor @block addShadowEvent ] when - processor.options.debug [shadow isVirtual ~] && [shadow isGlobal ~] && [ - fakePointer: shadow makeRefBranch FALSE @processor @block createRefVariable; - shadow @fakePointer @processor @block createRefOperation - nameInfo fakePointer @processor @block addVariableMetadata - programSize: block.program.getSize; - TRUE programSize 3 - @block.@program.at.@fakePointer set - TRUE programSize 2 - @block.@program.at.@fakePointer set - TRUE programSize 1 - @block.@program.at.@fakePointer set - @processor @block addDebugLocationForLastInstruction + getNameResult.mplFieldIndex 0 < ~ [ + shadow @result.@object set + getNameResult.mplFieldIndex shadow @processor @block processStaticAt @result.@refToVar set + gii: result.refToVar getVar.getInstructionIndex; + gii 0 < ~ [ + TRUE gii @block.@program.at.@fakePointer set + ] when + ] [ + shadow @result.@refToVar set + ] if + + processor.options.debug [ + varForFake: result.refToVar; + varForFake isVirtual ~ [varForFake isGlobal ~] && [ + fakePointer: varForFake makeRefBranch FALSE @processor @block createRefVariable; + varForFake @fakePointer @processor @block createRefOperation + nameInfo fakePointer @processor @block addVariableMetadata + 3 [ + TRUE block.program.getSize 1 - i - @block.@program.at.@fakePointer set + ] times + @processor @block addDebugLocationForLastInstruction + ] when ] when - shadow @result.@refToVar set TRUE @result.@newVar set [shadow getVar.temporary ~] "Captured var must not be temporary!" assert - ] when + ] [ + @shadow refToVar ShadowReasonCapture @processor @block makeShadows + + getNameResult.mplFieldIndex 0 < ~ [ + shadow @result.@object set + getNameResult.mplFieldIndex shadow @processor @block getField @result.@refToVar set + ] [ + shadow @result.@refToVar set + ] if + ] if result ]; # now we must capture and create GEP instruction getNameResult.mplFieldIndex 0 < ~ [ - nameInfo: getNameResult.nameCase NameCaseSelfMember = [ - processor.specialNames.selfNameInfo copy - ] [ - getNameResult.nameCase NameCaseClosureMember = [ - processor.specialNames.closureNameInfo copy - ] [ - [FALSE] "Invalid getName case for members!" assert - processor.specialNames.closureNameInfo copy - ] if - ] if; - - cro: nameInfo 0 @getNameResult.@object getNameResult.nameCase MemberCaseToObjectCase captureRefToVar; - - cro.refToVar @result.@object set - [cro.refToVar noMatterToCopy [cro.refToVar getVar.host block is] ||] "Captured name is not from here!" assert - getNameResult.mplFieldIndex @cro.@refToVar @processor @block processStaticAt @result.@refToVar set - cro.newVar [ - { - nameInfo: nameInfo copy; - mplFieldIndex: getNameResult.mplFieldIndex copy; - startPoint: getNameResult.startPoint copy; - overloadDepth: 0; - addNameCase: getNameResult.nameCase MemberCaseToObjectCaptureCase; - refToVar: cro.refToVar copy; - } @processor @block addNameInfo - ] when # add name info for "self"/"closure" as Object; result is object - - getNameResult.startPoint block.id = ~ [@processor.@captureTable getNameResult.nameInfo overloadDepth NameCaseCapture -1 file @processor @block addBlockIdTo] && [ - { - nameInfo: getNameResult.nameInfo copy; - mplFieldIndex: getNameResult.mplFieldIndex copy; - startPoint: getNameResult.startPoint copy; - overloadDepth: overloadDepth copy; - addNameCase: getNameResult.nameCase copy; - refToVar: result.refToVar copy; - } @processor @block addNameInfo - - newFieldCapture: FieldCapture; - [overloadDepth 0 < ~] "name overload not initialized!" assert - - getNameResult.nameInfo @newFieldCapture.@nameInfo set - overloadDepth @newFieldCapture.@nameOverloadDepth set - result.object @newFieldCapture.@object set - getNameResult.nameCase @newFieldCapture.@captureCase set - getNameResult.mplFieldIndex @newFieldCapture.@fieldIndex set - file @newFieldCapture.@file.set - - newEvent: ShadowEvent; - ShadowReasonFieldCapture @newEvent.setTag - branch: ShadowReasonFieldCapture @newEvent.get; - newFieldCapture @branch set - result.object @branch.@object set - @newEvent @block addShadowEvent - ] when + cro: getNameResult.nameInfo overloadDepth @getNameResult.@object getNameResult.nameCase captureRefToVar; + cro.object @result.@matchingEntry set + cro.object @result.@object set + cro.refToVar @result.@refToVar set + [cro.object noMatterToCopy [cro.object getVar.host.id block.id =] ||] "Capture object is not from here!" assert ] [ cr: getNameResult.nameInfo overloadDepth @getNameResult.@refToVar getNameResult.nameCase captureRefToVar; + cr.refToVar @result.@matchingEntry set + RefToVar @result.@object set cr.refToVar @result.@refToVar set - cr.newVar [ - { - nameInfo: getNameResult.nameInfo copy; - startPoint: getNameResult.startPoint copy; - overloadDepth: overloadDepth copy; - addNameCase: NameCaseCapture; - refToVar: result.refToVar copy; - } @processor @block addNameInfo - ] when ] if ] [ file getNameResult.nameInfo overloadDepth @processor @block addEmptyCapture processor.varForFails @result.@refToVar set + processor.varForFails @result.@matchingEntry set ] if ] if @@ -1535,7 +1490,8 @@ addFieldsNameInfos: [ nameInfo: currentField.nameInfo copy; mplFieldIndex: i copy; addNameCase: addNameCase copy; - refToVar: refToVar copy; + object: refToVar copy; + refToVar: currentField.refToVar copy; file: file; reg: FALSE; } @processor @block addNameInfo @@ -1718,7 +1674,6 @@ callCallableStructWithPre: [ gnr: nameInfo overloadIndex @processor @block processor.positions.last.file getNameWithOverloadIndex; processor compilable [ cnr: @gnr overloadDepth @processor @block processor.positions.last.file captureName; - cnr.object @object set cnr.refToVar @refToVar set ] when ] when @@ -1733,19 +1688,11 @@ callCallableStructWithPre: [ # no need pre, just call it! file: VarCode codeVar.data.get.file; - findInside [ - object file regNamesSelf - refToVar file regNamesClosure - VarCode codeVar.data.get.index nameInfo processor.nameManager.getText @processor @block processCall - refToVar unregNamesClosure - object unregNamesSelf - ] [ - object file regNamesSelf - refToVar file regNamesClosure - VarCode codeVar.data.get.index nameInfo processor.nameManager.getText @processor @block processCall - refToVar unregNamesClosure - object unregNamesSelf - ] if + object file regNamesSelf + refToVar file regNamesClosure + VarCode codeVar.data.get.index nameInfo processor.nameManager.getText @processor @block processCall + refToVar unregNamesClosure + object unregNamesSelf ] if ] [ "CALL field is not a code" @processor block compilerError @@ -1768,16 +1715,9 @@ callCallable: [ ] [ var.data.getTag VarCode = [ file: VarCode var.data.get.file; - - field [ - object file regNamesSelf - VarCode var.data.get.index @nameInfo processor.nameManager.getText @processor @block processCall - object unregNamesSelf - ] [ - object file regNamesSelf - VarCode var.data.get.index @nameInfo processor.nameManager.getText @processor @block processCall - object unregNamesSelf - ] if + object file regNamesSelf + VarCode var.data.get.index @nameInfo processor.nameManager.getText @processor @block processCall + object unregNamesSelf ] [ var.data.getTag VarImport = [ refToVar @processor @block processFuncPtr @@ -1806,6 +1746,11 @@ derefAndPush: [ @processor @block getPossiblePointee @block push ]; +setBlockEmptyLambdas: [ + block:; + TRUE @block.!hasEmptyLambdas +]; + checkVarForGlobalsFromAnotherFile: [ refToVar:; processor.options.partial [ @@ -1819,7 +1764,7 @@ checkVarForGlobalsFromAnotherFile: [ varBlock.file isNil ~ [ varBlock.file.usedInParams ~ [ TRUE @block.!empty - TRUE @block.!hasEmptyLambdas + @block setBlockEmptyLambdas ] when ] when ] when @@ -1893,6 +1838,7 @@ checkVarForGlobalsFromAnotherFile: [ headVar.capturedTail getVar.host block is [ headVar.capturedTail @result set refToVar.mutable @result.setMutable + refToVar.moved @result.setMoved [result getVar.host block is] "Begin hostId incorrect in makeShadows!" assert ] [ reallyCreateShadows @@ -2040,7 +1986,6 @@ checkVarForGlobalsFromAnotherFile: [ i 1 + @i set TRUE ] && ] loop - ] if ] "copyVarImpl" exportFunction @@ -2147,14 +2092,16 @@ checkVarForGlobalsFromAnotherFile: [ newInput @branch set result @branch.@refToVar set @block @result setTopologyIndex - @newEvent @block addShadowEvent + @newEvent @processor @block addShadowEvent #add input - result getVar.data.getTag VarInvalid = ~ [ - newInput @block.@buildingMatchingInfo.@inputs.pushBack - block.state NodeStateNew = [ - newInput @block.@matchingInfo.@inputs.pushBack - ] when + newInput @block.@buildingMatchingInfo.@inputs.pushBack + block.state NodeStateNew = [ + newInput @block.@matchingInfo.@inputs.pushBack + ] when + + forMatching ~ [result getVar.data.getTag VarInvalid = ~] && [ + 1 @block updateInputCount ] when ] [ processor.varForFails @result set @@ -2163,6 +2110,10 @@ checkVarForGlobalsFromAnotherFile: [ ] [ block.stack.last @result set @block.@stack.popBack + + forMatching ~ [result getVar.data.getTag VarInvalid = ~] && [ + 1 @block updateInputCount + ] when ] if ] "popWith" exportFunction @@ -2386,7 +2337,7 @@ addBlock: [ refToName: captureNameResult.refToVar copy; ] [ - TRUE dynamic captureNameResult.object refToName 0 nameInfo pushName + TRUE dynamic captureNameResult.refToVar refToName 0 nameInfo pushName ] ) sequence ] @@ -2438,6 +2389,16 @@ addBlock: [ cnr.refToVar @result set ] "makeVarStringImpl" exportFunction +addLambdaEvent: [ + success: processor: block: ;;; + + newEvent: ShadowEvent; + ShadowReasonTreeSplitterLambda @newEvent.setTag + branch: ShadowReasonTreeSplitterLambda @newEvent.get; + success @branch set + @newEvent @processor @block addShadowEvent +]; + { block: Block Ref; processor: Processor Ref; @@ -2462,8 +2423,19 @@ addBlock: [ implName: ("lambda." block.id "." block.lastLambdaName) assembleString; astArrayIndex: VarCode refToSrc getVar.data.get.index; - implIndex: csignature astArrayIndex implName makeStringView TRUE dynamic @processor @block processExportFunction; + processor.options.partial [ + topNode: block.topNode; + [topNode.file isNil ~] "Topnode in nil file!" assert + topNode.file.usedInParams ~ + ] && [ + @block setBlockEmptyLambdas + FALSE @processor @block addLambdaEvent + ] [ + TRUE @processor @block addLambdaEvent + ] if + + implIndex: csignature astArrayIndex implName makeStringView TRUE dynamic @processor @block processExportFunction; processor compilable [ implNode: implIndex processor.blocks.at.get; implNode.state NodeStateCompiled = ~ [ @@ -2488,14 +2460,6 @@ addBlock: [ ] if ] when - processor.options.partial [ - topNode: block.topNode; - [topNode.file isNil ~] "Topnode in nil file!" assert - topNode.file.usedInParams ~ - ] && [ - TRUE @block.!hasEmptyLambdas - ] when - block.lastLambdaName 1 + @block.@lastLambdaName set ] when ] when @@ -2758,7 +2722,7 @@ killStruct: [ processor.options.verboseIR [ ("fileName: " processor.positions.last.file.name - ", line: " processor.positions.last.line ", column: " processor.positions.last.column ", token: " astNode.token) assembleString @block createComment + ", line: " processor.positions.last.line ", column: " processor.positions.last.column ", token: " processor.positions.last.token) assembleString @block createComment ] when programSize: block.program.size; @@ -2941,17 +2905,9 @@ unregCodeNodeNames: [ @whereIds unregInLine ]; - nameWithOverloadAndRefToVar.nameInfo processor.specialNames.selfNameInfo = [ - nameWithOverloadAndRefToVar.nameOverloadDepth nameWithOverloadAndRefToVar.refToVar getVar.mplSchemaId @whereNames.@selfNames unregInObjectTable - ] [ - nameWithOverloadAndRefToVar.nameInfo processor.specialNames.closureNameInfo = [ - nameWithOverloadAndRefToVar.nameOverloadDepth nameWithOverloadAndRefToVar.refToVar getVar.mplSchemaId @whereNames.@closureNames unregInObjectTable - ] [ - whereOverloads: nameWithOverloadAndRefToVar.nameInfo @whereNames.@simpleNames.at; - whereIds: nameWithOverloadAndRefToVar.nameOverloadDepth @whereOverloads.at; - @whereIds unregInLine - ] if - ] if + whereOverloads: nameWithOverloadAndRefToVar.nameInfo @whereNames.@simpleNames.at; + whereIds: nameWithOverloadAndRefToVar.nameOverloadDepth @whereOverloads.at; + @whereIds unregInLine ] each ]; @@ -2983,7 +2939,6 @@ unregCodeNodeNames: [ ] when @block.@captureNames @processor.@captureTable unregTable - @block.@fieldCaptureNames @processor.@captureTable unregTable @block.@stableNames @processor.@captureTable unregStableNames @block.@capturedVars [ @@ -2993,7 +2948,6 @@ unregCodeNodeNames: [ @block.@capturedVars.release @block.@captureNames.release - @block.@fieldCaptureNames.release @block.@stableNames.release ]; @@ -3004,71 +2958,27 @@ addMatchingNode: [ astArrayIndex @block.@astArrayIndex set astArrayIndex processor.matchingNodes.size < [astArrayIndex processor.matchingNodes.at.assigned] && [ - matchingNode: astArrayIndex @processor.@matchingNodes.at.get; - - matchingNode.unknownMplType.getSize @block.@matchingInfoIndex set - matchingNode.size 1 + @matchingNode.@size set - block.id @matchingNode.@unknownMplType.pushBack + #it exists ] [ tableValue: MatchingNode; processor.positions.last @tableValue.@compilerPositionInfo set 1 @tableValue.@size set 0 @tableValue.@tries set 0 @tableValue.@entries set - 0 @block.@matchingInfoIndex set - block.id @tableValue.@unknownMplType.pushBack astArrayIndex processor.matchingNodes.size < ~ [astArrayIndex 1 + @processor.@matchingNodes.resize] when @tableValue move owner astArrayIndex @processor.@matchingNodes.at set ] if -]; -deleteMatchingNode: [ - block:; - block.matchingInfoIndex 0 < ~ [ - astArrayIndex: block.astArrayIndex copy; - info: astArrayIndex @processor.@matchingNodes.at.get; - indexArray: @info.@unknownMplType; - info.size 1 - @info.@size set - - [block.matchingInfoIndex indexArray.at block.id =] "Current block: matchingInfo table is incorrect!" assert - indexArray.getSize 1 - block.matchingInfoIndex = ~ [ - [indexArray.last processor.blocks.at.get.matchingInfoIndex indexArray.getSize 1 - =] "Last node: matchingInfo table is incorrect!" assert - - block.matchingInfoIndex indexArray.last @processor.@blocks.at.get.@matchingInfoIndex set - indexArray.last block.matchingInfoIndex @indexArray.at set - ] when - - -1 @block.@matchingInfoIndex set - @indexArray.popBack + matchingNode: astArrayIndex @processor.@matchingNodes.at.get; + matchingNode.treeMemory.getSize 0 = [ + MatchingNodeEntry @matchingNode.@treeMemory.pushBack ] when -]; - -concreteMatchingNode: [ - block:; - MatchingInfo @block.@buildingMatchingInfo set + matchingNode.count 1 + @matchingNode.@count set - block.matchingInfo.inputs.getSize 0 = ~ [ - @block deleteMatchingNode - - astArrayIndex: block.astArrayIndex copy; - info: astArrayIndex @processor.@matchingNodes.at.get; - info.size 1 + @info.@size set #return it back - - byMplType: info.@byMplType; - - key: 0 block.matchingInfo.inputs.at.refToVar getVar.mplSchemaId copy; - - fr: key @info.@byMplType.find; - fr.success [ - block.id @fr.@value.pushBack - ] [ - newBranch: Int32 Array; - block.id @newBranch.pushBack - key @newBranch move @info.@byMplType.insert - ] if - ] when + 0 @block.@matchingChindIndex set + block.id 0 @matchingNode.@treeMemory.at.@nodeIndexes.pushBack ]; createGlobalAliases: [ @@ -3114,8 +3024,7 @@ deleteNode: [ TRUE dynamic @node.@deleted set @node.@program.release - - @node deleteMatchingNode + @processor @node TRUE deleteMatchingNode ]; clearRecursionStack: [ @@ -3139,7 +3048,9 @@ changeTopologyIndexForAllVars: [ ] ShadowReasonCapture [ branch:; - @branch.@refToVar eachEventVarAction + branch.stable ~ [ + @branch.@refToVar eachEventVarAction + ] when ] ShadowReasonPointee [ branch:; @@ -3265,96 +3176,12 @@ checkRecursionOfCodeNode: [ ] [ block.state NodeStateHasOutput = [ comparingMessage: String; - currentMatchingNodeIndex: block.id copy; - currentMatchingNode: currentMatchingNodeIndex @processor.@blocks.at.get; - - compareShadows: [ - checkConstness:; - refToVar2:; - refToVar1:; - refToVar1 refToVar2 checkConstness @comparingMessage currentMatchingNode @processor compareOnePair - ]; - - compareTopologyIndex: [ - refToVar: buildingRefToVar: ;; - ti1: refToVar noMatterToCopy [-1][refToVar getVar.topologyIndex copy] if; - ti2: buildingRefToVar noMatterToCopy [-1][buildingRefToVar getVar.buildingTopologyIndex copy] if; - ti1 ti2 = - ]; #compare shadow events result [ block.matchingInfo.shadowEvents.getSize block.buildingMatchingInfo.shadowEvents.getSize = ~ [ FALSE @result set ] when - - block.matchingInfo.shadowEvents.size [ - result [ - currentMatchingEvent: i block.matchingInfo.shadowEvents.at; - currentBuildingMatchingEvent: i block.buildingMatchingInfo.shadowEvents.at; - - currentMatchingEvent.getTag currentBuildingMatchingEvent.getTag = [ - currentMatchingEvent.getTag ( - ShadowReasonInput [ - branch: ShadowReasonInput currentMatchingEvent.get; - buildingBranch: ShadowReasonInput currentBuildingMatchingEvent.get; - - branch.refToVar buildingBranch.refToVar compareTopologyIndex - [branch.refToVar buildingBranch.refToVar TRUE compareShadows] && ~ [ - FALSE !result - ] when - ] - ShadowReasonCapture [ - branch: ShadowReasonCapture currentMatchingEvent.get; - buildingBranch: ShadowReasonCapture currentBuildingMatchingEvent.get; - - branch.refToVar buildingBranch.refToVar compareTopologyIndex - [branch.captureCase buildingBranch.captureCase =] && - [branch.nameInfo buildingBranch.nameInfo =] && - [branch.nameOverloadDepth buildingBranch.nameOverloadDepth =] && - [branch.refToVar buildingBranch.refToVar TRUE compareShadows] && ~ [ - FALSE !result - ] when - ] - ShadowReasonFieldCapture [ - branch: ShadowReasonFieldCapture currentMatchingEvent.get; - buildingBranch: ShadowReasonFieldCapture currentBuildingMatchingEvent.get; - - branch.captureCase buildingBranch.captureCase = - [branch.nameInfo buildingBranch.nameInfo =] && - [branch.object buildingBranch.object compareTopologyIndex] && - [branch.nameOverloadDepth buildingBranch.nameOverloadDepth =] && ~ [ - FALSE !result - ] when - ] - ShadowReasonPointee [ - branch: ShadowReasonPointee currentMatchingEvent.get; - buildingBranch: ShadowReasonPointee currentBuildingMatchingEvent.get; - - branch.pointer buildingBranch.pointer compareTopologyIndex - [branch.pointee buildingBranch.pointee compareTopologyIndex] && - [branch.pointee buildingBranch.pointee TRUE compareShadows] && ~ [ - FALSE !result - ] when - ] - ShadowReasonField [ - branch: ShadowReasonField currentMatchingEvent.get; - buildingBranch: ShadowReasonField currentBuildingMatchingEvent.get; - - branch.object buildingBranch.object compareTopologyIndex - [branch.mplFieldIndex buildingBranch.mplFieldIndex =] && - [branch.field buildingBranch.field compareTopologyIndex] && - [branch.field buildingBranch.field FALSE compareShadows] && ~ [ - FALSE !result - ] when - ] - [] - ) case - ] [ - FALSE !result - ] if - ] when - ] times ] when result [ @@ -3379,17 +3206,17 @@ checkRecursionOfCodeNode: [ ]; astFileIdToFileRef: [ - 1 + processor.files.at.get + processor.files.at.get ]; makeCompilerPosition: [ - astNode: processor: ;; + positionInfo: processor: ;; result: CompilerPositionInfo; - astNode.fileId astFileIdToFileRef @result.@file.set - astNode.line copy @result.!line - astNode.column copy @result.!column - astNode.token copy @result.!token + positionInfo.fileId astFileIdToFileRef @result.@file.set + positionInfo.line copy @result.!line + positionInfo.column copy @result.!column + positionInfo.token makeStringView @result.!token result ]; @@ -3421,7 +3248,6 @@ makeCompilerPosition: [ hasEffect: FALSE; hasRet: FALSE; retRef: RefToVar; - hasImport: FALSE; "void" makeStringView @retType.cat @@ -3484,7 +3310,6 @@ makeCompilerPosition: [ ] when asCopy [ - #do nothing ] [ var: @refToVar getVar; regNameId 0 < [var.irNameId @regNameId set] when @@ -3678,49 +3503,32 @@ makeCompilerPosition: [ String @block.@signature set inputCountMismatch: [ - ("In signature there are " forcedSignature.inputs.getSize " inputs, but really here " block.buildingMatchingInfo.inputs.getSize " inputs") assembleString @processor block compilerError + ("In signature there are " forcedSignature.inputs.getSize " inputs, but really here " validInputCount " inputs") assembleString @processor block compilerError ]; - validInputCount: 0; - block.buildingMatchingInfo.inputs [ - current:; - current.refToVar getVar.data.getTag VarInvalid = ~ [ - validInputCount 1 + !validInputCount - ] when - ] each + block.buildingMatchingInfo.maxInputCount @block.@buildingMatchingInfo.@inputs.shrink + validInputCount: block.@buildingMatchingInfo.inputs.size; hasForcedSignature [ - validInputCount forcedSignature.inputs.getSize = ~ [ - validInputCount 1 + forcedSignature.inputs.getSize = - [forcedSignature.outputs.getSize 0 >] && - [0 forcedSignature.outputs.at forcedSignature.inputs.last variablesAreSame] && [ - #todo for MPL signature check each - @processor @block pop @block push - validInputCount 1 + !validInputCount - ] [ - inputCountMismatch - ] if - ] when - forcedSignature @block.@csignature set ] when addRefOrCopyArg: [ - needToCopy: current: ;; + needToCopy: refToVar: argCase: ;;; needToCopy [ regNameId: @processor @block generateRegisterIRName; - ArgCopy @current.@argCase set - current.refToVar regNameId addCopyArg + ArgCopy @argCase set + refToVar regNameId addCopyArg - current.refToVar isGlobal ~ [ - current.refToVar getVar.allocationInstructionIndex 0 <] && [ - regNameId @current.@refToVar @processor @block createAllocIR @processor @block createStoreFromRegister + refToVar isGlobal ~ [ + refToVar getVar.allocationInstructionIndex 0 <] && [ + regNameId @refToVar @processor @block createAllocIR @processor @block createStoreFromRegister TRUE @block.@program.last.@alloca set #fake for good sorting ] when ] [ - ArgRef @current.@argCase set - current.refToVar FALSE addRefArg + ArgRef @argCase set + refToVar FALSE addRefArg ] if ]; @@ -3759,10 +3567,21 @@ makeCompilerPosition: [ # const to plain make copy current: i @block.@buildingMatchingInfo.@inputs.at; + current.refToVar staticityOfVar Dirty > ~ [current.refToVar getVar.capturedAsRealValue copy] && [ + current.refToVar makeVarPtrCaptured + ] when + hasForcedSignature ~ [current.refToVar getVar.capturedAsRealValue ~] && [current.refToVar getVar.capturedByPtr ~] && [ ArgMeta @current.@argCase set ] when + current.refToVar getVar.usedInParams [ + processor.options.verboseIR [ + ("already used " current.refToVar @processor getIrName) assembleString @block createComment + ] when + ArgAlreadyUsed @current.@argCase set + ] when + current.refToVar getVar.data.getTag VarInvalid = [ ArgMeta @current.@argCase set ] [ @@ -3778,6 +3597,8 @@ makeCompilerPosition: [ currentVar: current.refToVar getVar; currentIsRef: hasForcedSignature [i forcedSignature.inputs.at getVar.data.getTag VarRef =] &&; + TRUE @currentVar.!usedInParams + needToCopy: hasForcedSignature [ currentIsRef ~ ] [ @@ -3788,7 +3609,7 @@ makeCompilerPosition: [ "getting huge agrument by copy; mpl's export function can not have this signature" @processor block compilerError ] when - needToCopy @current addRefOrCopyArg + needToCopy @current.@refToVar @current.@argCase addRefOrCopyArg ] if ] if ] if @@ -3804,8 +3625,10 @@ makeCompilerPosition: [ "module can not have inputs or outputs" @processor block compilerError ] when + invalidOutputCount: block.matchingInfo.inputs.getSize block.matchingInfo.maxInputCount -; + @block.@outputs.clear - i: 0 dynamic; + i: invalidOutputCount copy dynamic; [ i block.stack.size < [ current: i @block.@stack.at; @@ -3845,6 +3668,8 @@ makeCompilerPosition: [ ] && ] loop + block.program.size @block.@instructionCountBeforeRet set + hasRet [ retRef @processor @block createRetValue ] [ @@ -3866,9 +3691,28 @@ makeCompilerPosition: [ [ i block.buildingMatchingInfo.captures.size < [ current: i @block.@buildingMatchingInfo.@captures.at; + currentRefToVar: @current.@refToVar; + + currentRefToVar.assigned [ + currentVar: currentRefToVar getVar; + + currentVar.usedInParams [ + processor.options.verboseIR [ + ("already used " currentRefToVar @processor getIrName) assembleString @block createComment + ] when + ArgAlreadyUsed @current.@argCase set + ] when + + current.refToVar staticityOfVar Dirty > ~ [currentVar.capturedAsRealValue copy] && [ + current.refToVar makeVarPtrCaptured + ] when - current.refToVar.assigned [ - currentVar: current.refToVar getVar; + currentVar.capturedForDeref [ + pointee: VarRef currentVar.data.get.refToVar; + pointee staticityOfVar Dirty > ~ [ + pointee makeVarPtrCaptured + ] when + ] when needToDerefCopy: currentVar.capturedForDeref @@ -3890,16 +3734,18 @@ makeCompilerPosition: [ fr.value @processor.@positions.last set ] when - ("real function can not have local capture; name=" current.nameInfo processor.nameManager.getText "; type=" current.refToVar @processor block getMplType) assembleString @processor block compilerError + ("real function can not have local capture; name=" current.nameInfo processor.nameManager.getText "; type=" currentRefToVar @processor block getMplType) assembleString @processor block compilerError ] when - needToCopy: current.refToVar @processor argRecommendedToCopy; + needToCopy: currentRefToVar @processor argRecommendedToCopy; + TRUE @currentVar.!usedInParams needToDerefCopy [ - pointee: VarRef current.refToVar getVar.data.get.refToVar; + pointee: VarRef currentVar.data.get.refToVar; regNameId: @processor @block generateRegisterIRName; ArgDerefCopy @current.@argCase set pointee regNameId addCopyArg + TRUE @pointee getVar.!usedInParams pointee getVar.host block is [ pointee isGlobal ~ [pointee getVar.allocationInstructionIndex 0 <] && [ @@ -3907,8 +3753,8 @@ makeCompilerPosition: [ TRUE @block.@program.last.@alloca set #fake for good sorting ] when - current.refToVar isGlobal ~ [current.refToVar getVar.allocationInstructionIndex 0 <] && [ - pointee getVar.irNameId @current.@refToVar @processor @block createAllocIR @processor @block createStoreFromRegister + currentRefToVar isGlobal ~ [currentVar.allocationInstructionIndex 0 <] && [ + pointee getVar.irNameId @currentRefToVar @processor @block createAllocIR @processor @block createStoreFromRegister TRUE @block.@program.last.@alloca set #fake for good sorting ] when ] [ @@ -3918,26 +3764,24 @@ makeCompilerPosition: [ regNameId pointeeNameId pointee @processor getMplSchema.irTypeId @processor @block createStoreFromRegisterToRegister TRUE @block.@program.last.@alloca set #fake for good sorting - current.refToVar isGlobal ~ [current.refToVar getVar.allocationInstructionIndex 0 <] && [ - pointeeNameId @current.@refToVar @processor @block createAllocIR @processor @block createStoreFromRegister + currentRefToVar isGlobal ~ [currentVar.allocationInstructionIndex 0 <] && [ + pointeeNameId @currentRefToVar @processor @block createAllocIR @processor @block createStoreFromRegister TRUE @block.@program.last.@alloca set #fake for good sorting ] when ] when ] if ] [ - needToCopy @current addRefOrCopyArg + needToCopy @currentRefToVar @current.@argCase addRefOrCopyArg ] if ] [ current.argCase ArgGlobal = [ TRUE @hasEffect set ] [ current.argCase ArgMeta = [ - current.refToVar addMetaArg + currentRefToVar addMetaArg ] when ] if ] if - - current.refToVar getVar.data.getTag VarImport = [TRUE @hasImport set] when ] when i 1 + @i set processor compilable ] && @@ -3982,7 +3826,7 @@ makeCompilerPosition: [ noname [block.nodeCase NodeCaseLambda = ~] && [block.recursionState NodeRecursionStateNo =] && - [hasImport ~] && + [block.hasCallImport ~] && [hasRet ~] && [hasEffect ~] && [block.parent 0 = ~] && @@ -4006,15 +3850,12 @@ makeCompilerPosition: [ ] ShadowReasonCapture [ branch:; - ("shadow event [" i "] capture " branch.nameInfo processor.nameManager.getText "(" branch.nameOverloadDepth ") in " branch.file getFileName "; staticity=" branch.refToVar getVar.staticity.begin " as " branch.refToVar getVar.buildingTopologyIndex " type " branch.refToVar @processor @block getMplType) assembleString @block createComment - ] - ShadowReasonStableName [ - branch:; - ("shadow event [" i "] stableName " branch.nameInfo processor.nameManager.getText) assembleString @block createComment - ] - ShadowReasonFieldCapture [ - branch:; - ("shadow event [" i "] fieldCapture " branch.nameInfo processor.nameManager.getText "(" branch.nameOverloadDepth ") [" branch.fieldIndex "] in " branch.object getVar.buildingTopologyIndex) assembleString @block createComment + branch.stable [ + ("shadow event [" i "] capture " branch.nameInfo processor.nameManager.getText " as stable name") assembleString @block createComment + ] [ + ("shadow event [" i "] capture " branch.nameInfo processor.nameManager.getText "(" branch.nameOverloadDepth ") in " branch.file getFileName "; staticity=" branch.refToVar getVar.staticity.begin " as " branch.refToVar getVar.buildingTopologyIndex " type " branch.refToVar @processor @block getMplType) assembleString @block createComment + branch.mplFieldIndex 0 < ~ [(" as field " branch.mplFieldIndex " in object") assembleString @block createComment] when + ] if ] ShadowReasonPointee [ branch:; @@ -4028,6 +3869,8 @@ makeCompilerPosition: [ ) event.visit ] times + ("inputCount: " block.buildingMatchingInfo.maxInputCount) assembleString @block createComment + info: String; "labelNames: " @info.cat block.labelNames @info addNames @@ -4141,7 +3984,8 @@ makeCompilerPosition: [ nameInfo: nameInfo copy; addNameCase: NameCaseLocal; refToVar: refToVar copy; - file: topNode.file; + reg: block.nodeCase NodeCaseCodeRefDeclaration = ~ block.nodeCase NodeCaseLambda = ~ and; + file: block.nodeCase NodeCaseLambda = [File Cref][topNode.file] if; } @processor @topNode addNameInfo ]; @@ -4270,11 +4114,11 @@ makeCompilerPosition: [ addIndexArrayToProcess: [ astNodeArray: block: ;; - i: astNodeArray.size; + i: astNodeArray.nodes.size; [ i 0 > [ i 1 - @i set - astNode: i astNodeArray.at; + astNode: i astNodeArray.nodes.at; block.unprocessedAstNodes.size 1 + @block.@unprocessedAstNodes.enlarge unprocessedAstNode: @block.@unprocessedAstNodes.last; astNode @unprocessedAstNode.!astNode @@ -4314,7 +4158,7 @@ addIndexArrayToProcess: [ @processor @codeNode getTopNode @codeNode.@topNode.set 0 @codeNode.@globalPriority set - compilerPositionInfo: processor.positions.last copy; + compilerPositionInfo: astArrayIndex processor.multiParserResult.memory.at.positionInfo @processor makeCompilerPosition; compilerPositionInfo.file @codeNode.@file.set compilerPositionInfo @codeNode.@beginPosition set @@ -4336,7 +4180,6 @@ addIndexArrayToProcess: [ ] when #add to match table - astArrayIndex @block addMatchingNode block.parent 0 = [ block.id 0 > [ @@ -4353,12 +4196,12 @@ addIndexArrayToProcess: [ recursionTries: 0 dynamic; [ @block createLabel - + prevBlockMatchingChindIndex: block.matchingChindIndex copy; + astArrayIndex @block addMatchingNode 0 @block.@countOfUCall set @block.@labelNames.clear @block.@fromModuleNames.clear @block.@captureNames.clear - @block.@fieldCaptureNames.clear @block.@stableNames.clear @block.@unprocessedAstNodes.clear @block.@dependentPointers.clear @@ -4378,7 +4221,7 @@ addIndexArrayToProcess: [ @block.@unprocessedAstNodes.popBack astNode: tokenRef.astNode; - astNode @processor makeCompilerPosition @processor.@positions.last set + astNode.positionInfo @processor makeCompilerPosition @processor.@positions.last set astNode processNode processor compilable [block.state NodeStateNoOutput = ~] && @@ -4402,6 +4245,15 @@ addIndexArrayToProcess: [ processor compilable [ block.recursionState NodeRecursionStateNo > [block.state NodeStateCompiled = ~] && ] && + + printEventsOfBlock: FALSE; + printEventsOfBlock [ + ("current try matching events of " block.id " in " astArrayIndex ": " LF) printList + block.matchingInfo.shadowEvents.size [ + event: i block.matchingInfo.shadowEvents.at; + event i FALSE @processor @block printShadowEvent + ] times + ] when ] loop processor compilable [block.state NodeStateCompiled =] && [ @@ -4423,11 +4275,9 @@ addIndexArrayToProcess: [ TRUE @block.@empty set ] when - block.deleted ~ [ - @block concreteMatchingNode - ] when ] when + processor.varCount codeNode.variableCountDelta - @codeNode.@variableCountDelta set processor.depthOfRecursion 1 - @processor.@depthOfRecursion set diff --git a/declarations.mpl b/declarations.mpl index 6c0361b..895f8fc 100644 --- a/declarations.mpl +++ b/declarations.mpl @@ -94,9 +94,10 @@ compilerError: [processor: block:;; makeStringView block @processor compilerErro { processor: Processor Cref; - currentMatchingNode: Block Cref; + makeMessage: Cond; comparingMessage: String Ref; checkConstness: Cond; + forMatching: Cond; cacheEntry: RefToVar Cref; stackEntry: RefToVar Cref; } Cond {} "compareOnePair" importFunction @@ -337,13 +338,14 @@ createFailWithMessage: [ multiParserResult: MultiParserResult Ref; fileText: StringView Cref; fileName: StringView Cref; + fileId: Int32; errorMessage: String Ref; } () {} "addToProcessImpl" importFunction addToProcess: [ result: String; - fileName: fileText: multiParserResult: nameManager: ;;;; - @result fileName fileText @multiParserResult @nameManager addToProcessImpl + fileId: fileName: fileText: multiParserResult: nameManager: ;;;;; + @result fileId fileName fileText @multiParserResult @nameManager addToProcessImpl @result ]; diff --git a/defaultImpl.mpl b/defaultImpl.mpl index 55d03ca..023e246 100644 --- a/defaultImpl.mpl +++ b/defaultImpl.mpl @@ -1,3 +1,4 @@ +"Array" use "String" use "control" use "conventions" use @@ -6,6 +7,7 @@ "Var" use "declarations" use "processor" use +"staticCall" use FailProcForProcessor: [{ processor: block: ;; @@ -29,6 +31,9 @@ FailProcForProcessor: [{ "\nWhile compiling:\n" print processor block defaultPrintStackTrace + "\nCommand line:\n" print + processor.options.fullLine print + "\n" print 2 exit ]; @@ -180,7 +185,10 @@ getStackEntryWith: [ result: @block isConst [processor.varForFails] [@processor.@varForFails] uif; currentBlock: @block; [ currentBlock.root [ - check ["stack underflow" @processor block compilerError] when + check [ + "stack underflow" @processor block compilerError + ] when + FALSE ] [ depth currentBlock.stack.size < [ @@ -225,16 +233,11 @@ getStackDepth: [ processor: block:;; ("stack:" LF "depth=" processor block getStackDepth LF) printList - - i: 0 dynamic; - [ - i @processor block getStackDepth < [ - entry: i @processor block getStackEntryUnchecked; - (entry @processor block getMplType entry.mutable ["R"] ["C"] if entry getVar.temporary ["T"] [""] if - entry isPlain [entry getPlainValueInformation] [String] if LF) printList - i 1 + @i set TRUE - ] && - ] loop + @processor @block getStackDepth [ + entry: i @processor block getStackEntryUnchecked; + (entry @processor block getMplType entry.mutable ["R"] ["C"] if entry getVar.temporary ["T"] [""] if + entry isPlain [entry getPlainValueInformation] [String] if LF) printList + ] times ] "defaultPrintStack" exportFunction { @@ -257,6 +260,51 @@ getStackDepth: [ @processor block defaultPrintStack ] "defaultPrintStackTrace" exportFunction +printShadowEvent: [ + event: index: building: processor: block: ;;;;; + + getFileName: [ + file:; file isNil ["NIL" makeStringView] [file.name makeStringView] if + ]; + + getTopologyIndex: [ + building [ + .buildingTopologyIndex + ] [ + .topologyIndex + ] if + ]; + + ( + ShadowReasonInput [ + branch:; + ("shadow event [" index "] input as " branch.refToVar getVar getTopologyIndex LF) printList + ] + ShadowReasonCapture [ + branch:; + branch.stable [ + ("shadow event [" index "] capture " branch.nameInfo processor.nameManager.getText " as stable name" "(" branch.nameOverloadDepth ") in " branch.file getFileName "; type " branch.refToVar @processor @block getMplType LF) printList + ] [ + ("shadow event [" index "] capture " branch.nameInfo processor.nameManager.getText "(" branch.nameOverloadDepth ") in " branch.file getFileName "; staticity=" branch.refToVar getVar.staticity.begin " as " branch.refToVar getVar getTopologyIndex " type " branch.refToVar @processor @block getMplType LF) printList + branch.mplFieldIndex 0 < ~ [(" as field " branch.mplFieldIndex " in object" LF) printList] when + ] if + ] + ShadowReasonPointee [ + branch:; + ("shadow event [" index "] pointee " branch.pointer getVar getTopologyIndex " as " branch.pointee getVar getTopologyIndex LF) printList + ] + ShadowReasonField [ + branch:; + ("shadow event [" index "] field " branch.object getVar getTopologyIndex " [" branch.mplFieldIndex "] as " branch.field getVar getTopologyIndex LF) printList + ] + ShadowReasonTreeSplitterLambda [ + branch:; + ("shadow event [" index "] tree splitter lambda " branch LF) printList + ] + [] + ) event.visit +]; + findNameInfo: [ processor:; @processor.@nameManager.createName @@ -270,7 +318,7 @@ addStackUnderflowInfo: [ branch: ShadowReasonInput @newEvent.get; processor.varForFails @branch.@refToVar set ArgMeta @branch.@argCase set - @newEvent @block addShadowEvent + @newEvent @processor @block addShadowEvent ]; nodeHasCode: [ @@ -304,34 +352,22 @@ addBlockIdTo: [ NameInfoCoord @line.pushBack block @line.last.@block.set file @line.last.@file.set + + nameWithOverload: NameWithOverload; + nameInfo @nameWithOverload.@nameInfo set + nameOverloadDepth @nameWithOverload.@nameOverloadDepth set + #other fields does not matter + nameWithOverload @block.@captureNames.pushBack ] when result ]; - addBlockToObjectCase: [ - nameOverloadDepth: mplSchemaId: table: ;;; - - nameOverloadDepth table.size < ~ [nameOverloadDepth 1 + @table.resize] when - whereTypes: nameOverloadDepth @table.at; - mplSchemaId whereTypes.size < ~ [mplSchemaId 1 + @whereTypes.resize] when - whereIds: mplSchemaId @whereTypes.at; - @whereIds addToLine - ]; - - nameInfo processor.specialNames.selfNameInfo = [ - nameOverloadDepth mplSchemaId @whereNames.@selfNames addBlockToObjectCase - ] [ - nameInfo processor.specialNames.closureNameInfo = [ - nameOverloadDepth mplSchemaId @whereNames.@closureNames addBlockToObjectCase - ] [ - nameInfo whereNames.simpleNames.size < ~ [nameInfo 1 + @whereNames.@simpleNames.resize] when - whereOverloads: nameInfo @whereNames.@simpleNames.at; - nameOverloadDepth whereOverloads.size < ~ [nameOverloadDepth 1 + @whereOverloads.resize] when - whereIds: nameOverloadDepth @whereOverloads.at; - @whereIds addToLine - ] if - ] if + nameInfo whereNames.simpleNames.size < ~ [nameInfo 1 + @whereNames.@simpleNames.resize] when + whereOverloads: nameInfo @whereNames.@simpleNames.at; + nameOverloadDepth whereOverloads.size < ~ [nameOverloadDepth 1 + @whereOverloads.resize] when + whereIds: nameOverloadDepth @whereOverloads.at; + @whereIds addToLine ]; addEmptyCapture: [ @@ -344,25 +380,461 @@ addEmptyCapture: [ ShadowReasonCapture @newEvent.setTag branch: ShadowReasonCapture @newEvent.get; + -1 @branch.@mplFieldIndex set processor.varForFails @branch.@refToVar set nameInfo @branch.@nameInfo set nameOverloadDepth @branch.@nameOverloadDepth set - NameCaseInvalid @branch.@captureCase set file @branch.@file.set ArgMeta @branch.@argCase set - @newEvent @block addShadowEvent + @newEvent @processor @block addShadowEvent + ] when +]; + +getShadowEventHash: [ + event: whileMatching: processor: block: ;;;; + + apply: [ + value:; + result 0x8088405n32 * 1n32 + value xor !result + ]; + + applyRefToVar: [ + refToVar: checkMutable: ;; + var: refToVar getVar; + + whileMatching [ + var.topologyIndexWhileMatching Nat32 cast apply + var.staticity.end Nat32 cast apply + ] [ + var.buildingTopologyIndex Nat32 cast apply + var.staticity.begin Nat32 cast apply + ] if + + var.mplSchemaId Nat32 cast apply + var.globalId Nat32 cast apply + var.storageStaticity Nat32 cast apply + + checkMutable [ + refToVar.mutable [5n32][4n32] if apply + ] when + + refToVar isAutoStruct [ + refToVar.moved [3n32][2n32] if apply + ] when + + refToVar isPlain [ + currentStaticity: whileMatching [var.staticity.end copy] [var.staticity.begin copy] if; + currentStaticity Dynamic > [ + var.data.getTag VarCond VarReal64 1 + [ + tag:; + applyData: 0n64; + value: whileMatching [tag var.data.get.end copy] [tag var.data.get.begin copy] if; + value applyData storageAddress @value addressToReference set + applyData 32n32 rshift applyData 48n32 rshift xor applyData xor Nat32 cast apply + ] staticCall + ] when + ] when + ]; + + result: 0n32; + event.getTag Nat32 cast apply + ( + ShadowReasonInput [ + branch:; + # key - none + branch.refToVar TRUE applyRefToVar + ] + ShadowReasonCapture [ + branch:; + # key - nameInfo + branch.stable [ + 0n32 apply + branch.refToVar TRUE applyRefToVar + ] [ + 10n32 apply + branch.mplFieldIndex Nat32 cast apply + branch.refToVar TRUE applyRefToVar + ] if + ] + ShadowReasonPointee [ + branch:; + # key - pointer topologyIndex + branch.pointee TRUE applyRefToVar + ] + ShadowReasonField [ + branch:; + # key - object topologyIndex, object mplFieldIndex + branch.field FALSE applyRefToVar + ] + ShadowReasonTreeSplitterLambda [ + branch:; + # key - node + branch [0n32] [1n32] if apply + ] + [] + ) event.visit + + result +]; + +sameEvents: [ + event1: event2: ;; + + event1.getTag event2.getTag = [ + event1.getTag ( + ShadowReasonInput [ + # key - none + TRUE + ] + ShadowReasonCapture [ + # key - nameInfo + branch1: ShadowReasonCapture event1.get; + branch2: ShadowReasonCapture event2.get; + + branch1.nameInfo branch2.nameInfo = + [branch1.nameOverloadDepth branch2.nameOverloadDepth =] && + [branch1.file branch2.file is] && [ + TRUE + ] [ + getFileName: [ + file:; + file isNil ["NIL" makeStringView] [file.name makeStringView] if + ]; + + ("Capture events are different; " + LF branch1.nameInfo processor.nameManager.getText ":" branch1.nameOverloadDepth ":" branch1.file getFileName + LF branch2.nameInfo processor.nameManager.getText ":" branch2.nameOverloadDepth ":" branch2.file getFileName + LF) printList + FALSE + ] if + ] + ShadowReasonPointee [ + # key - pointer topologyIndex + branch1: ShadowReasonPointee event1.get; + branch2: ShadowReasonPointee event2.get; + pointer1: branch1.pointer getVar; + pointer2: branch2.pointer getVar; + pointer1.buildingTopologyIndex pointer2.topologyIndex = [ + TRUE + ] [ + ("Pointee events are different; " pointer1.buildingTopologyIndex " and " pointer2.topologyIndex LF) printList + FALSE + ] if + ] + ShadowReasonField [ + # key - object topologyIndex + branch1: ShadowReasonField event1.get; + branch2: ShadowReasonField event2.get; + object1: branch1.object getVar; + object2: branch2.object getVar; + object1.buildingTopologyIndex object2.topologyIndex = + [branch1.mplFieldIndex branch2.mplFieldIndex =] && [ + TRUE + ] [ + ("Field events are different; " object1.buildingTopologyIndex ":" branch1.mplFieldIndex " and " object2.topologyIndex ":" branch2.mplFieldIndex LF) printList + FALSE + ] if + ] + ShadowReasonTreeSplitterLambda [ + # key - none + TRUE + ] + [ + ("Event tags are invalid; " event1.getTag LF) printList + FALSE + ] + ) case + ] [ + ("Event tags are different; " event1.getTag " and " event2.getTag LF) printList + FALSE + ] if +]; + +compareShadows: [ + processor:; + comparingMessage:; + whileMatching:; + checkConstness:; + refToVar2:; + refToVar1:; + refToVar1 refToVar2 whileMatching checkConstness @comparingMessage FALSE @processor compareOnePair +]; + +compareTopologyIndex: [ + refToVar1: refToVar2: whileMatching: ;;; + + var1: refToVar1 getVar; + var2: refToVar2 getVar; + + ti1: refToVar1 noMatterToCopy [-1][ + whileMatching [ + var1.topologyIndexWhileMatching copy + ] [ + var1.buildingTopologyIndex copy + ] if + ] if; + + ti2: refToVar2 noMatterToCopy [-1][ + whileMatching [ + var2.topologyIndex copy + ] [ + var2.topologyIndex copy + ] if + ] if; + + ti1 ti2 = +]; + +compareEvents: [ + event1: event2: comparingMessage: whileMatching: processor: ;;;;; + + result: TRUE; + event1.getTag event2.getTag = [ + event1.getTag ( + ShadowReasonInput [ + branch1: ShadowReasonInput event1.get; + branch2: ShadowReasonInput event2.get; + + branch1.refToVar branch2.refToVar whileMatching compareTopologyIndex + [branch1.refToVar branch2.refToVar TRUE whileMatching @comparingMessage @processor compareShadows] && ~ [ + FALSE !result + ] when + ] + ShadowReasonCapture [ + branch1: ShadowReasonCapture event1.get; + branch2: ShadowReasonCapture event2.get; + + branch1.stable branch2.stable and [ + branch1.refToVar branch2.refToVar TRUE whileMatching @comparingMessage @processor compareShadows ~ [ + FALSE !result + ] when + ] [ + branch1.stable ~ branch2.stable ~ and + [branch1.refToVar branch2.refToVar whileMatching compareTopologyIndex] && + [branch1.mplFieldIndex branch2.mplFieldIndex =] && + [branch1.refToVar branch2.refToVar TRUE whileMatching @comparingMessage @processor compareShadows] && ~ [ + FALSE !result + ] when + ] if + ] + ShadowReasonPointee [ + branch1: ShadowReasonPointee event1.get; + branch2: ShadowReasonPointee event2.get; + + branch1.pointee branch2.pointee whileMatching compareTopologyIndex + [branch1.pointee branch2.pointee TRUE whileMatching @comparingMessage @processor compareShadows] && ~ [ + FALSE !result + ] when + ] + ShadowReasonField [ + branch1: ShadowReasonField event1.get; + branch2: ShadowReasonField event2.get; + + branch1.field branch2.field whileMatching compareTopologyIndex + [branch1.field branch2.field FALSE whileMatching @comparingMessage @processor compareShadows] && ~ [ + FALSE !result + ] when + ] + ShadowReasonTreeSplitterLambda [ + branch1: ShadowReasonTreeSplitterLambda event1.get; + branch2: ShadowReasonTreeSplitterLambda event2.get; + + branch1 branch2 = ~ [ + FALSE !result + ] when + ] + [] + ) case + ] [ + FALSE !result + ] if + + result +]; + +deleteMatchingNodeFrom: [ + processor: block: matchingChindIndex: full: ;;;; + + matchingChindIndex 0 < ~ [ + astArrayIndex: block.astArrayIndex copy; + matchingNode: astArrayIndex @processor.@matchingNodes.at.get; + currentMemory: matchingChindIndex @matchingNode.@treeMemory.at; + + index: -1 dynamic; + i: currentMemory.nodeIndexes.size 1 -; + [i 0 < ~ index 0 < and] [ + i currentMemory.nodeIndexes.at block.id = [ + i @index set + ] when + + i 1 - !i + ] while + + full [ + index: matchingChindIndex copy; + [ + parentIndex: index matchingNode.treeMemory.at.parentIndex copy; + parentIndex 0 < ~ [ + parentNode: parentIndex @matchingNode.@treeMemory.at; + parentNode.childIndices.size 1 = [ + i: parentNode.childIndices.size 1 -; + [i 0 < ~ [i parentNode.childIndices.at.childIndex index = ~] &&] [ + i 1 - !i + ] while + + [i 0 < ~] "No such child in parent in matchingTree!" assert + i @parentNode.@childIndices.erase + + parentIndex @index set + TRUE + ] && + ] && + ] loop + ] when + + index 0 < ~ [ + index @currentMemory.@nodeIndexes.erase + ] when + ] when +]; + +deleteMatchingNode: [ + processor: block: full: ;;; + + block.matchingChindIndex 0 < ~ [ + @processor @block block.matchingChindIndex full deleteMatchingNodeFrom + -1 @block.@matchingChindIndex set ] when ]; addShadowEvent: [ - event: block: ;; + event: processor: block: ;;; + + block.astArrayIndex 0 < ~ [ + #begin of var go to matching + event @block.@buildingMatchingInfo.@shadowEvents.pushBack - #begin of var go to matching + block.state NodeStateNew = [ + event @block.@matchingInfo.@shadowEvents.pushBack + ] when + + block.recursionState NodeRecursionStateNew = [ + ] [ + addChild: [ + event: machingMemoryNode:;; + + matchingNodePair: MatchingNodePair; + result: matchingNode.treeMemory.getSize; + + eventHash @matchingNodePair.@eventHash set + result @matchingNodePair.@childIndex set + + @matchingNodePair move @machingMemoryNode.@childIndices.pushBack + + newMatchingNodeEntry: MatchingNodeEntry; + event @newMatchingNodeEntry.@parentEvent set + currentEntryIndex @newMatchingNodeEntry.@parentIndex set + @newMatchingNodeEntry move @matchingNode.@treeMemory.pushBack + + result + ]; - event @block.@buildingMatchingInfo.@shadowEvents.pushBack + currentEntryIndex: block.matchingChindIndex copy; + comparingMessage: String; + matchingNode: block.astArrayIndex @processor.@matchingNodes.at.get; + currentMemory: currentEntryIndex @matchingNode.@treeMemory.at; - block.state NodeStateNew = [ - event @block.@matchingInfo.@shadowEvents.pushBack + eventHash: event FALSE dynamic @processor @block getShadowEventHash; + + currentMemory.childIndices.size 0 = [ + event @currentMemory addChild @currentEntryIndex set + ] [ + pattern: 0 currentMemory.childIndices @ .childIndex matchingNode.treeMemory.at.parentEvent; + [ + event pattern sameEvents [ + ("First event is new event; second is pattern; astNode index = " block.astArrayIndex LF) printList + ("Current try matching events: " LF) printList + + block.buildingMatchingInfo.shadowEvents.size [ + event: i block.buildingMatchingInfo.shadowEvents.at; + + getFileName: [ + file:; file isNil ["NIL" makeStringView] [file.name makeStringView] if + ]; + + ( + ShadowReasonInput [ + branch:; + ("shadow event [" i "] input as " branch.refToVar getVar.buildingTopologyIndex LF) printList + ] + ShadowReasonCapture [ + branch:; + branch.stable [ + ("shadow event [" i "] capture " branch.nameInfo processor.nameManager.getText " as stable name" LF) printList + ] [ + ("shadow event [" i "] capture " branch.nameInfo processor.nameManager.getText "(" branch.nameOverloadDepth ") in " branch.file getFileName "; staticity=" branch.refToVar getVar.staticity.begin " as " branch.refToVar getVar.buildingTopologyIndex " type " branch.refToVar @processor @block getMplType LF) printList + branch.mplFieldIndex 0 < ~ [(" as field " branch.mplFieldIndex " in object" LF) printList] when + ] if + ] + ShadowReasonPointee [ + branch:; + ("shadow event [" i "] pointee " branch.pointer getVar.buildingTopologyIndex " as " branch.pointee getVar.buildingTopologyIndex LF) printList + ] + ShadowReasonField [ + branch:; + ("shadow event [" i "] field " branch.object getVar.buildingTopologyIndex " [" branch.mplFieldIndex "] as " branch.field getVar.buildingTopologyIndex LF) printList + ] + ShadowReasonTreeSplitterLambda [ + branch:; + ("shadow event [" i "] tree splitter lambda " branch LF) printList + ] + [] + ) event.visit + ] times + + FALSE + ] || + ] "Matching events are not consistent" assert + + candidates: @currentMemory.@childIndices; + + prevEventIndex: -1 dynamic; + candidates [ + prevVersion:; + prevEventIndex 0 < [ + prevVersion.eventHash eventHash = [ + prevVersionEvent: prevVersion.childIndex matchingNode.treeMemory.at.parentEvent; + event prevVersionEvent @comparingMessage FALSE dynamic @processor compareEvents + ] && [ + prevVersion.childIndex @prevEventIndex set + ] when + ] when + ] each + + prevEventIndex 0 < [ + candidates [ + prevVersion:; + prevEventIndex 0 < [ + prevVersion.eventHash eventHash = [ + prevVersionEvent: prevVersion.childIndex matchingNode.treeMemory.at.parentEvent; + event prevVersionEvent @comparingMessage FALSE dynamic @processor compareEvents + ] && [ + prevVersion.childIndex @prevEventIndex set + ] when + ] when + ] each + + event @currentMemory addChild @currentEntryIndex set + ] [ + prevEventIndex @currentEntryIndex set + ] if + ] if + + @processor @block FALSE deleteMatchingNode + currentEntryIndex @block.@matchingChindIndex set + currentMemory: currentEntryIndex @matchingNode.@treeMemory.at; + block.id @currentMemory.@nodeIndexes.pushBack + ] if ] when ]; diff --git a/irWriter.mpl b/irWriter.mpl index 3449dfe..58884a4 100644 --- a/irWriter.mpl +++ b/irWriter.mpl @@ -243,6 +243,7 @@ createStaticGEP: [ resultRefToVar: index: structRefToVar: processor: block:;;;;; struct: structRefToVar getVar; realIndex: index VarStruct struct.data.get.get.realFieldIndexes.at; + [realIndex 0 < ~] "Gep index must be non-negative!" assert (" " resultRefToVar @processor getIrName " = getelementptr " structRefToVar @processor getIrType ", " structRefToVar @processor getIrType "* " structRefToVar @processor getIrName ", i32 0, i32 " realIndex) @block appendInstruction structRefToVar getVar.irNameId @block.@program.last.@irName1 set @@ -673,6 +674,8 @@ addCtorsToBeginFunc: [ ] times @processor.@positions.popBack + + block.instructionCountBeforeRet previousVersion.size - block.program.size + @block.!instructionCountBeforeRet ] when ]; @@ -687,7 +690,7 @@ addDtorsToEndFunc: [ block.beginPosition @processor.@positions.pushBack previousVersion.getSize [ - i previousVersion.getSize 1 - < [ + i block.instructionCountBeforeRet < [ current: i @previousVersion.at; @current move @block.@program.pushBack ] when @@ -707,8 +710,12 @@ addDtorsToEndFunc: [ ] when ] times + previousVersion.getSize block.instructionCountBeforeRet - [ + current: i block.instructionCountBeforeRet + @previousVersion.at; + @current move @block.@program.pushBack + ] times + @processor.@positions.popBack - @previousVersion.last move @block.@program.pushBack ] when ]; diff --git a/main.mpl b/main.mpl index f8b9ba8..d72b98d 100644 --- a/main.mpl +++ b/main.mpl @@ -135,6 +135,17 @@ addToProcessAndCheck: [ ] when ]; +checkedSaveString: [ + name: string: ;; + + loadResult: name loadString; + loadResult.success [loadResult.data string =] && [ + (name ".temp") assembleString string saveString + ] [ + name string saveString + ] if +]; + {argc: 0; argv: 0nx;} 0 {convention: cdecl;} [ #debugMemory [TRUE !memoryDebugEnabled] when ("Start mplc compiler") addLog @@ -177,16 +188,21 @@ addToProcessAndCheck: [ "main" toString @options.@beginFunc set "main" toString @options.@endFunc set + fullLine: String; + argc 1 = [ FALSE @success set ] [ argc [ i 0 = [ addr: 0nx storageSize i 0ix cast 0nx cast * argv + Natx addressToReference; - addr makeStringViewByAddress extractClearPath @options.@mainPath set + option: addr makeStringViewByAddress; + option @fullLine.cat + option extractClearPath @options.@mainPath set ] [ addr: 0nx storageSize i 0ix cast 0nx cast * argv + Natx addressToReference; option: addr makeStringViewByAddress; + (" " option) @fullLine.catMany option.size 0 = [ "Error, argument cannot be empty" print LF print @@ -300,6 +316,8 @@ addToProcessAndCheck: [ ] times ] if + @fullLine move @options.@fullLine set + nextOption OPT_ANY = ~ [ "Value expected" print LF print FALSE @success set @@ -352,13 +370,13 @@ addToProcessAndCheck: [ #builtins ] [ i 1 = [ - fileName makeStringView definitions makeStringView @multiParserResult @nameManager addToProcessAndCheck + i fileName makeStringView definitions makeStringView @multiParserResult @nameManager addToProcessAndCheck ] [ loadStringResult: fileName loadString; loadStringResult.success [ ("Loaded string from " fileName) addLog ("HASH=" loadStringResult.data hash) addLog - fileName makeStringView loadStringResult.data makeStringView @multiParserResult @nameManager addToProcessAndCheck + i fileName makeStringView loadStringResult.data makeStringView @multiParserResult @nameManager addToProcessAndCheck ] [ "Unable to load string:" print fileName print LF print FALSE @success set @@ -376,7 +394,7 @@ addToProcessAndCheck: [ program: String; @multiParserResult @nameManager options 0 @result @program process result.size 0 = [ - outputFileName program saveString [ + outputFileName program checkedSaveString [ ("program written to " outputFileName) addLog ] [ ("failed to save program" LF) printList diff --git a/parser.mpl b/parser.mpl index 3cb2511..d547c2b 100644 --- a/parser.mpl +++ b/parser.mpl @@ -27,8 +27,7 @@ codeunitTail?: [ fillPositionInfo: [ astNode:; - lastPosition.line @astNode.@line set - lastPosition.column @astNode.@column set + lastPosition @astNode.@positionInfo set ]; addToMainResult: [ @@ -41,7 +40,7 @@ addToMainResult: [ addToLastUnfinished: [ astNode:; - @astNode move @unfinishedNodes.last.pushBack + @astNode move @unfinishedNodes.last.@nodes.pushBack ]; makeLabelNode: [ @@ -49,7 +48,7 @@ makeLabelNode: [ name:; result: AstNode; @result fillPositionInfo - (name ":") assembleString @result.@token set + (name ":") assembleString @result.@positionInfo.@token set AstNodeType.Label @result.@data.setTag branch: AstNodeType.Label @result.@data.get; @children addToMainResult @branch.@children set @@ -61,7 +60,7 @@ makeCodeNode: [ children:; result: AstNode; @result fillPositionInfo - "[" toString @result.@token set + "[" toString @result.@positionInfo.@token set AstNodeType.Code @result.@data.setTag branch: AstNodeType.Code @result.@data.get; @children addToMainResult @branch set @@ -72,7 +71,7 @@ makeObjectNode: [ children:; result: AstNode; @result fillPositionInfo - "{" toString @result.@token set + "{" toString @result.@positionInfo.@token set AstNodeType.Object @result.@data.setTag branch: AstNodeType.Object @result.@data.get; @children addToMainResult @branch set @@ -83,7 +82,7 @@ makeListNode: [ children:; result: AstNode; @result fillPositionInfo - "(" toString @result.@token set + "(" toString @result.@positionInfo.@token set AstNodeType.List @result.@data.setTag branch: AstNodeType.List @result.@data.get; @children addToMainResult @branch set @@ -94,7 +93,7 @@ makeNameNode: [ name:; result: AstNode; @result fillPositionInfo - name toString @result.@token set + name toString @result.@positionInfo.@token set AstNodeType.Name @result.@data.setTag branch: AstNodeType.Name @result.@data.get; name toString @branch.@name set @@ -105,7 +104,7 @@ makeNameReadNode: [ name:; result: AstNode; @result fillPositionInfo - ("@" name) assembleString @result.@token set + ("@" name) assembleString @result.@positionInfo.@token set AstNodeType.NameRead @result.@data.setTag branch: AstNodeType.NameRead @result.@data.get; name toString @branch.@name set @@ -116,7 +115,7 @@ makeNameWriteNode: [ name:; result: AstNode; @result fillPositionInfo - ("!" name) assembleString @result.@token set + ("!" name) assembleString @result.@positionInfo.@token set AstNodeType.NameWrite @result.@data.setTag branch: AstNodeType.NameWrite @result.@data.get; name toString @branch.@name set @@ -127,7 +126,7 @@ makeNameMemberNode: [ name:; result: AstNode; @result fillPositionInfo - ("." name) assembleString @result.@token set + ("." name) assembleString @result.@positionInfo.@token set AstNodeType.NameMember @result.@data.setTag branch: AstNodeType.NameMember @result.@data.get; name toString @branch.@name set @@ -138,7 +137,7 @@ makeNameReadMemberNode: [ name:; result: AstNode; @result fillPositionInfo - (".@" name) assembleString @result.@token set + (".@" name) assembleString @result.@positionInfo.@token set AstNodeType.NameReadMember @result.@data.setTag branch: AstNodeType.NameReadMember @result.@data.get; name toString @branch.@name set @@ -149,7 +148,7 @@ makeNameWriteMemberNode: [ name:; result: AstNode; @result fillPositionInfo - (".!" name) assembleString @result.@token set + (".!" name) assembleString @result.@positionInfo.@token set AstNodeType.NameWriteMember @result.@data.setTag branch: AstNodeType.NameWriteMember @result.@data.get; name toString @branch.@name set @@ -160,7 +159,7 @@ makeStringNode: [ value:; result: AstNode; @result fillPositionInfo - "TEXT" toString @result.@token set + "TEXT" toString @result.@positionInfo.@token set AstNodeType.String @result.@data.setTag branch: AstNodeType.String @result.@data.get; value @branch set @@ -172,7 +171,7 @@ makeNumberi8Node: [ copy number:; result: AstNode; @result fillPositionInfo - token @result.@token set + token @result.@positionInfo.@token set AstNodeType.Numberi8 @result.@data.setTag branch: AstNodeType.Numberi8 @result.@data.get; number @branch set @@ -184,7 +183,7 @@ makeNumberi16Node: [ copy number:; result: AstNode; @result fillPositionInfo - token @result.@token set + token @result.@positionInfo.@token set AstNodeType.Numberi16 @result.@data.setTag branch: AstNodeType.Numberi16 @result.@data.get; number @branch set @@ -196,7 +195,7 @@ makeNumberi32Node: [ copy number:; result: AstNode; @result fillPositionInfo - token @result.@token set + token @result.@positionInfo.@token set AstNodeType.Numberi32 @result.@data.setTag branch: AstNodeType.Numberi32 @result.@data.get; number @branch set @@ -208,7 +207,7 @@ makeNumberi64Node: [ copy number:; result: AstNode; @result fillPositionInfo - token @result.@token set + token @result.@positionInfo.@token set AstNodeType.Numberi64 @result.@data.setTag branch: AstNodeType.Numberi64 @result.@data.get; number @branch set @@ -220,7 +219,7 @@ makeNumberixNode: [ copy number:; result: AstNode; @result fillPositionInfo - token @result.@token set + token @result.@positionInfo.@token set AstNodeType.Numberix @result.@data.setTag branch: AstNodeType.Numberix @result.@data.get; number @branch set @@ -232,7 +231,7 @@ makeNumbern8Node: [ copy number:; result: AstNode; @result fillPositionInfo - token @result.@token set + token @result.@positionInfo.@token set AstNodeType.Numbern8 @result.@data.setTag branch: AstNodeType.Numbern8 @result.@data.get; number @branch set @@ -244,7 +243,7 @@ makeNumbern16Node: [ copy number:; result: AstNode; @result fillPositionInfo - token @result.@token set + token @result.@positionInfo.@token set AstNodeType.Numbern16 @result.@data.setTag branch: AstNodeType.Numbern16 @result.@data.get; number @branch set @@ -256,7 +255,7 @@ makeNumbern32Node: [ copy number:; result: AstNode; @result fillPositionInfo - token @result.@token set + token @result.@positionInfo.@token set AstNodeType.Numbern32 @result.@data.setTag branch: AstNodeType.Numbern32 @result.@data.get; number @branch set @@ -268,7 +267,7 @@ makeNumbern64Node: [ copy number:; result: AstNode; @result fillPositionInfo - token @result.@token set + token @result.@positionInfo.@token set AstNodeType.Numbern64 @result.@data.setTag branch: AstNodeType.Numbern64 @result.@data.get; number @branch set @@ -280,7 +279,7 @@ makeNumbernxNode: [ copy number:; result: AstNode; @result fillPositionInfo - token @result.@token set + token @result.@positionInfo.@token set AstNodeType.Numbernx @result.@data.setTag branch: AstNodeType.Numbernx @result.@data.get; number @branch set @@ -292,7 +291,7 @@ makeReal32Node: [ copy number:; result: AstNode; @result fillPositionInfo - token @result.@token set + token @result.@positionInfo.@token set AstNodeType.Real32 @result.@data.setTag branch: AstNodeType.Real32 @result.@data.get; number @branch set @@ -304,7 +303,7 @@ makeReal64Node: [ copy number:; result: AstNode; @result fillPositionInfo - token @result.@token set + token @result.@positionInfo.@token set AstNodeType.Real64 @result.@data.setTag branch: AstNodeType.Real64 @result.@data.get; number @branch set @@ -314,7 +313,6 @@ makeReal64Node: [ makeParserConstants: [{ eof: [ 0n32]; - makeLookupTable: [ av:; result: Cond Array; @@ -395,6 +393,7 @@ iterate: [ currentPosition.line 1 + @currentPosition.@line set ] when + fileId @currentPosition.@fileId set currentPosition.offset 1 + @currentPosition.@offset set currentPosition.column 1 + @currentPosition.@column set @@ -875,7 +874,9 @@ makeLabel: [ lastPosition @unfinishedPositions.pushBack ascii.semicolon @unfinishedTerminators.pushBack name toString @unfinishedLabelNames.pushBack - AstNode Array @unfinishedNodes.pushBack + newAstNodeArray: AstNodeArray; + lastPosition @newAstNodeArray.@positionInfo set + @newAstNodeArray move @unfinishedNodes.pushBack ]; parseName: [ @@ -1065,7 +1066,10 @@ parseComment: [ addNestedNode: [ currentPosition @unfinishedPositions.pushBack - AstNode Array @unfinishedNodes.pushBack + newAstNodeArray: AstNodeArray; + currentPosition @newAstNodeArray.@positionInfo set + @newAstNodeArray move @unfinishedNodes.pushBack + currentCode ascii.openRBr = [ ascii.closeRBr @unfinishedTerminators.pushBack ] [ @@ -1184,9 +1188,11 @@ parseNode: [ { text: StringView Cref; + fileId: Int32; mainResult: ParserResult Ref; } () {} [ splittedString: splitString; + fileId:; mainResult:; splittedString.success [ @@ -1201,11 +1207,15 @@ parseNode: [ unfinishedPositions: PositionInfo Array; unfinishedLabelNames: String Array; - unfinishedNodes: AstNode Array Array; + unfinishedNodes: AstNodeArray Array; unfinishedTerminators: Nat32 Array; + fileId @currentPosition.@fileId set currentPosition @unfinishedPositions.pushBack - AstNode Array @unfinishedNodes.pushBack + newAstNodeArray: AstNodeArray; + currentPosition @newAstNodeArray.@positionInfo set + @newAstNodeArray move @unfinishedNodes.pushBack + ascii.null @unfinishedTerminators.pushBack iterate diff --git a/processSubNodes.mpl b/processSubNodes.mpl index 8d1b5fb..0b45429 100644 --- a/processSubNodes.mpl +++ b/processSubNodes.mpl @@ -43,7 +43,9 @@ ] if ] "variablesHaveSameGlobality" exportFunction -{processor: Processor Cref; comparingMessage: String Ref; makeMessage: Cond; cacheEntry: RefToVar Cref; stackEntry: RefToVar Cref;} Cond {} [ +varibaleAreEqualBody: [ + e1Checker: e2Checker: ;; + stackEntry: cacheEntry: makeMessage: comparingMessage: processor: ;;;;; stackDynamicBorder: Weak; @@ -65,8 +67,8 @@ FALSE ] [ stackEntryVar.data.getTag VarStruct = [ - cacheStaticity: cacheEntryVar.staticity.end copy; - stackStaticity: stackEntryVar.staticity.end copy; + cacheStaticity: cacheEntryVar.staticity e1Checker copy; + stackStaticity: stackEntryVar.staticity e2Checker copy; cacheStaticity Dynamic = [Static !cacheStaticity] when stackStaticity Dynamic = [Static !stackStaticity] when @@ -86,8 +88,8 @@ ] if ] if ] [ - cacheStaticity: cacheEntryVar.staticity.begin copy; - stackStaticity: stackEntryVar.staticity.end copy; + cacheStaticity: cacheEntryVar.staticity e1Checker copy; + stackStaticity: stackEntryVar.staticity e2Checker copy; cacheStaticity Weak > ~ stackStaticity stackDynamicBorder > ~ and [ # both dynamic @@ -107,8 +109,11 @@ cacheEntryVar.data.getTag VarCond VarReal64 1 + [ tag:; - tag cacheEntryVar.data.get.begin - tag stackEntryVar.data.get.end = + cacheValue: tag cacheEntryVar.data.get; + stackValue: tag stackEntryVar.data.get; + + cacheValue e1Checker + stackValue e2Checker = !result ] staticCall @@ -128,6 +133,15 @@ ] if ] if ] if + +]; + +{processor: Processor Cref; comparingMessage: String Ref; makeMessage: Cond; cacheEntry: RefToVar Cref; stackEntry: RefToVar Cref;} Cond {} [ + [.begin] [.begin] @varibaleAreEqualBody ucall +] "variablesAreEqualForTree" exportFunction + +{processor: Processor Cref; comparingMessage: String Ref; makeMessage: Cond; cacheEntry: RefToVar Cref; stackEntry: RefToVar Cref;} Cond {} [ + [.begin] [.end] @varibaleAreEqualBody ucall ] "variablesAreEqualForMatching" exportFunction {forLoop: Cond; processor: Processor Cref; cacheEntry: RefToVar Cref; stackEntry: RefToVar Cref; } Cond {} [ @@ -194,17 +208,21 @@ variablesAreEqualForLoop: [TRUE variablesAreEqualWith]; refToVar getVar.host currentMatchingNode is ~ [refToVar noMatterToCopy ~] && ] "variableIsUnused" exportFunction -{processor: Processor Cref; currentMatchingNode: Block Cref; comparingMessage: String Ref; checkConstness: Cond; cacheEntry: RefToVar Cref; stackEntry: RefToVar Cref;} Cond {} [ - stackEntry: cacheEntry: checkConstness: comparingMessage: currentMatchingNode: processor:;;;;;; +{processor: Processor Cref; makeMessage: Cond; comparingMessage: String Ref; checkConstness: Cond; forMatching: Cond; cacheEntry: RefToVar Cref; stackEntry: RefToVar Cref;} Cond {} [ + stackEntry: cacheEntry: forMatching: checkConstness: comparingMessage: makeMessage: processor:;;;;;;; checkConstness ~ [cacheEntry.mutable stackEntry.mutable =] || [ - stackEntry cacheEntry currentMatchingNode.nodeCompileOnce @comparingMessage processor variablesAreEqualForMatching [ + forMatching [ + stackEntry cacheEntry makeMessage @comparingMessage processor variablesAreEqualForMatching + ] [ + stackEntry cacheEntry makeMessage @comparingMessage processor variablesAreEqualForTree + ] if [ TRUE ] [ FALSE ] if ] [ - currentMatchingNode.nodeCompileOnce ["variables have different constness" toString @comparingMessage set] when + makeMessage ["variables have different constness" toString @comparingMessage set] when FALSE ] if ] "compareOnePair" exportFunction @@ -251,15 +269,12 @@ catShadowEvents: [ ] ShadowReasonCapture [ branch:; - ("shadow event [" i "] capture " branch.nameInfo processor.nameManager.getText "(" branch.nameOverloadDepth ") index " branch.refToVar getVar.topologyIndex " type " branch.refToVar @processor @block getMplType LF) @message.catMany - ] - ShadowReasonStableName [ - branch:; - ("shadow event [" i "] stableName " branch.nameInfo processor.nameManager.getText LF) @message.catMany - ] - ShadowReasonFieldCapture [ - branch:; - ("shadow event [" i "] fieldCapture " branch.nameInfo processor.nameManager.getText "(" branch.nameOverloadDepth ") [" branch.fieldIndex "] in " branch.object getVar.topologyIndex LF) @message.catMany + branch.stable [ + ("shadow event [" i "] capture " branch.nameInfo processor.nameManager.getText " as stable" LF) @message.catMany + ] [ + ("shadow event [" i "] capture " branch.nameInfo processor.nameManager.getText "(" branch.nameOverloadDepth ") index " branch.refToVar getVar.topologyIndex " type " branch.refToVar @processor @block getMplType LF) @message.catMany + branch.mplFieldIndex 0 < ~ [(" as field " branch.mplFieldIndex " in object" LF) @message.catMany] when + ] if ] ShadowReasonPointee [ branch:; @@ -274,6 +289,39 @@ catShadowEvents: [ ] times ]; +addEventVarWhileMatching: [ + stackEntry: cacheEntry: eventVars: ;;; + + success: TRUE dynamic; + stackEntry noMatterToCopy ~ [ + topologyIndex: cacheEntry getVar.topologyIndex copy; + [topologyIndex 0 < ~] "Shadow event index is negative!" assert + topologyIndex eventVars.size < [ + topologyIndex stackEntry getVar.topologyIndexWhileMatching = ~ [ + FALSE dynamic @success set + ] when + ] [ + stackEntry getVar.topologyIndexWhileMatching 0 < ~ [ + FALSE dynamic @success set + ] [ + [ + topologyIndex eventVars.size = [ + message: String; + currentMatchingNode.matchingInfo.shadowEvents.size 1 - @currentMatchingNode @message catShadowEvents + message print + FALSE + ] || + ] "Topology indexes are not sequenced!" assert + topologyIndex 1 + @eventVars.enlarge + topologyIndex @stackEntry getVar.@topologyIndexWhileMatching set + stackEntry topologyIndex @eventVars.at set + ] if + ] if + ] when + + success +]; + tryMatchNode: [ currentMatchingNode:; comparingMessage: String; @@ -315,159 +363,11 @@ tryMatchNode: [ ] ||; invisibleName: currentMatchingNode.nodeCase NodeCaseLambda = [currentMatchingNode.varNameInfo 0 < ~] && [ - matchingCapture: Capture; - currentMatchingNode.refToVar @matchingCapture.@refToVar set - NameCaseLocal @matchingCapture.@captureCase set - gnr: currentMatchingNode.varNameInfo matchingCapture @processor @block matchingCapture.file getNameForMatching; + gnr: currentMatchingNode.varNameInfo @processor @block File Cref getNameForMatching; gnr.refToVar.assigned ~ ] &&; - canMatch invisibleName ~ and goodReality and [ - mismatchMessage: [ - index:; - message: ("in compile-one func cache mismatch; " comparingMessage "; matching table events to failing event:" LF) assembleString; - - index currentMatchingNode @message catShadowEvents - message @processor block compilerError - ]; - - success: TRUE dynamic; - eventVars: @processor.acquireVarRefArray; - matchingNodeStackDepth: 0 dynamic; - - addEventVar: [ - stackEntry: cacheEntry: eventVars: ;;; - - success: TRUE dynamic; - stackEntry noMatterToCopy ~ [ - topologyIndex: cacheEntry getVar.topologyIndex copy; - [topologyIndex 0 < ~] "Shadow event index is negative!" assert - topologyIndex eventVars.size < [ - topologyIndex stackEntry getVar.topologyIndexWhileMatching = ~ [ - FALSE dynamic @success set - ] when - ] [ - stackEntry getVar.topologyIndexWhileMatching 0 < ~ [ - FALSE dynamic @success set - ] [ - topologyIndex 1 + @eventVars.enlarge - topologyIndex @stackEntry getVar.@topologyIndexWhileMatching set - stackEntry topologyIndex @eventVars.at set - ] if - ] if - ] when - - success - ]; - - currentMatchingNode.matchingInfo.shadowEvents.size [ - success processor compilable and [ - currentEvent: i currentMatchingNode.matchingInfo.shadowEvents.at; - ( - ShadowReasonInput [ - branch:; - stackEntry: matchingNodeStackDepth @processor block getStackEntryUnchecked; - cacheEntry: branch.refToVar; - - stackEntry cacheEntry TRUE @comparingMessage currentMatchingNode processor compareOnePair - [@stackEntry cacheEntry @eventVars addEventVar] && ~ [ - currentMatchingNode.nodeCompileOnce [i mismatchMessage] when - FALSE dynamic @success set - ] when - - matchingNodeStackDepth 1 + !matchingNodeStackDepth - ] - ShadowReasonCapture [ - branch:; - - cacheEntry: branch.refToVar; - overloadIndex: outOverloadDepth: branch @block branch.file TRUE getOverloadIndex;; - gnr: branch.nameInfo branch overloadIndex @processor @block branch.file getNameForMatchingWithOverloadIndex; - - branch.file gnr processor nameResultIsStable [ - "cache entry was not stable, now it is stable" toString @comparingMessage set - currentMatchingNode.nodeCompileOnce [i mismatchMessage] when - FALSE dynamic @success set - ] [ - stackEntry: gnr.refToVar; - stackEntry cacheEntry TRUE @comparingMessage currentMatchingNode processor compareOnePair - - [ - cacheEntry noMatterToCopy [cacheEntry getVar.topologyIndex 0 < ~] || [ - ("captureName=" branch.nameInfo processor.nameManager.getText "; captureType=" cacheEntry @processor @block getMplType LF) printList - FALSE - ] || - ] "Capture shadow event index is negative!" assert - - [@stackEntry cacheEntry @eventVars addEventVar] && ~ [ - currentMatchingNode.nodeCompileOnce [i mismatchMessage] when - FALSE dynamic @success set - ] when - ] if - ] - ShadowReasonStableName [ - branch:; - - #here need to check local def in all usef in thos implementation files! - branch.nameInfo processor.nameManager.hasOverload - [branch.nameInfo processor.nameManager.hasLocalDefinition] || [ - currentMatchingNode.nodeCompileOnce [ - "cache entry was stable, now it is not stable" toString @comparingMessage set - i mismatchMessage - ] when - - FALSE dynamic @success set - ] when - ] - ShadowReasonFieldCapture [ - branch:; - - overloadIndex: outOverloadDepth: branch @block branch.file TRUE getOverloadIndex;; - processor compilable [ - currentFieldInfo: overloadIndex branch.nameInfo processor.nameManager.getItem; - currentFieldInfo.nameCase branch.captureCase = [branch.object currentFieldInfo.refToVar variablesAreSame] && - ] && ~ [ - currentMatchingNode.nodeCompileOnce [i mismatchMessage] when - FALSE dynamic @success set - ] when - ] - ShadowReasonPointee [ - branch:; - cacheEntry: branch.pointee; - stackEntry: branch.pointer getVar.topologyIndex eventVars.at @processor @block getPointeeForMatching; - - stackEntry cacheEntry TRUE @comparingMessage currentMatchingNode processor compareOnePair - [@stackEntry cacheEntry @eventVars addEventVar] && ~ [ - currentMatchingNode.nodeCompileOnce [i mismatchMessage] when - FALSE dynamic @success set - ] when - ] - ShadowReasonField [ - branch:; - - cacheEntry: branch.field; - stackEntry: branch.mplFieldIndex branch.object getVar.topologyIndex eventVars.at @processor @block getFieldForMatching; - - stackEntry cacheEntry FALSE @comparingMessage currentMatchingNode processor compareOnePair - [@stackEntry cacheEntry @eventVars addEventVar] && ~ [ - currentMatchingNode.nodeCompileOnce [i mismatchMessage] when - FALSE dynamic @success set - ] when - ] - [] - ) @currentEvent.visit - ] when - ] times - - @eventVars [ - refToVar:; - -1 @refToVar getVar.@topologyIndexWhileMatching set - ] each - - @eventVars @processor.releaseVarRefArray - - success - ] && + canMatch invisibleName ~ and goodReality and ]; {processor: Processor Ref; block: Block Ref; forceRealFunction: Cond; astArrayIndex: Int32;} Int32 {} [ @@ -509,18 +409,133 @@ tryMatchNode: [ result ]; + #find-in-tree way result: -1 dynamic; + currentEntryIndex: 0 dynamic; + eventVars: @processor.acquireVarRefArray; - @processor block getStackDepth 0 > [ - byType: 0 @processor block getStackEntry getVar.mplSchemaId matchingNode.byMplType.find; + success: FALSE dynamic; + continueSearch: TRUE dynamic; + comparingMessage: String; + matchingNodeStackDepth: 0 dynamic; - byType.success [ - byType.value findInIndexArray @result set + addEventVar: [ + stackEntry: eventVars: ;; + + stackEntry noMatterToCopy ~ [ + stackEntry getVar.topologyIndexWhileMatching 0 < [ + eventVars.size @stackEntry getVar.@topologyIndexWhileMatching set + stackEntry @eventVars.pushBack + ] when ] when - ] when + ]; + + [ + currentMemory: currentEntryIndex matchingNode.treeMemory.at; + currentMemory.childIndices.size 0 = [ + TRUE !success + FALSE !continueSearch + ] [ + pattern: 0 currentMemory.childIndices @ .childIndex matchingNode.treeMemory.at.parentEvent; - result 0 < [ - matchingNode.unknownMplType findInIndexArray @result set + matchingFakeEvent: pattern copy; + + #step1: get our hash of event + ( + ShadowReasonInput [ + branch:; + stackEntry: matchingNodeStackDepth @processor block getStackEntryUnchecked; + stackEntry @branch.@refToVar set + stackEntry @eventVars addEventVar + matchingNodeStackDepth 1 + !matchingNodeStackDepth + ] + ShadowReasonCapture [ + branch:; + + overloadIndex: outOverloadDepth: branch @block branch.file TRUE getOverloadIndex;; + gnr: branch.nameInfo overloadIndex @processor @block branch.file getNameForMatchingWithOverloadIndex; + + branch.file gnr processor nameResultIsStable @branch.@stable set + stackEntry: gnr.mplFieldIndex 0 < [gnr.refToVar] [gnr.object] if; + + stackEntry @branch.@refToVar set + stackEntry @eventVars addEventVar + ] + ShadowReasonPointee [ + branch:; + stackPointer: branch.pointer getVar.topologyIndex eventVars.at; + stackEntry: stackPointer @processor @block getPointeeForMatching; + + stackPointer @branch.@pointer set + stackEntry @branch.@pointee set + stackEntry @eventVars addEventVar + ] + ShadowReasonField [ + branch:; + stackObject: branch.object getVar.topologyIndex eventVars.at; + stackEntry: branch.mplFieldIndex stackObject @processor @block getFieldForMatching; + + stackObject @branch.@object set + stackEntry @branch.@field set + stackEntry @eventVars addEventVar + ] + ShadowReasonTreeSplitterLambda [ + branch:; + + processor.options.partial ~ [ + topNode: block.topNode; + [topNode.file isNil ~] "Topnode in nil file!" assert + topNode.file.usedInParams copy + ] || @branch set + ] + [] + ) @matchingFakeEvent.visit + + continueSearch [ + eventHash: matchingFakeEvent TRUE dynamic @processor @block getShadowEventHash; + + candidates: @currentMemory.@childIndices; + candidateIndex: -1 dynamic; + + candidates [ + prevVersion:; + candidateIndex 0 < [ + eventHash prevVersion.eventHash = [ + prevVersionEvent: prevVersion.childIndex matchingNode.treeMemory.at.parentEvent; + matchingFakeEvent prevVersionEvent @comparingMessage TRUE dynamic @processor compareEvents + ] && [ + prevVersion.childIndex @candidateIndex set + ] when + ] when + ] each + + candidateIndex 0 < [ + TRUE !success #may be we can find it in + FALSE !continueSearch + ] [ + currentMemory.nodeIndexes.size 0 > [ + TRUE !success #may be we can find it in + FALSE !continueSearch + ] [ + candidateIndex @currentEntryIndex set + ] if + ] if + ] when + ] if + + continueSearch copy + ] loop + + eventVars [ + refToVar:; + -1 @refToVar getVar.@topologyIndexWhileMatching set + ] each + + @eventVars @processor.releaseVarRefArray + + success [ + currentMemory: currentEntryIndex matchingNode.treeMemory.at; + currentMemory.nodeIndexes findInIndexArray @result set ] when result @@ -682,15 +697,15 @@ fixOutputRefsRec: [ sourceVar.host block is [ [currentFromStack hasGoodSource] "Stack var source invariant failed!" assert ] [ - sourceIndex: sourceVar.topologyIndex copy; - sourceIndex 0 < ~ [ - sourceIndex appliedVars.stackVars.at @stackEntryVar.@sourceOfValue set - ] [ - sourceVar.host currentChangesNode is [ - currentFromStack @stackEntryVar.@sourceOfValue set + sourceVar.host currentChangesNode is [ + sourceIndex: sourceVar.topologyIndex copy; + sourceIndex 0 < ~ [ + sourceIndex appliedVars.stackVars.at @stackEntryVar.@sourceOfValue set ] [ - [FALSE] "Source of value is unknown!" assert + currentFromStack @stackEntryVar.@sourceOfValue set ] if + ] [ + [FALSE] "Source of value is unknown!" assert ] if [currentFromStack hasGoodSource] "Stack var source invariant failed!" assert @@ -794,7 +809,11 @@ fixCaptureRef: [ cachePointee getVar.storageStaticity Virtual = [ cachePointee @processor @block getLastShadow getVar @cachePointee.setVar ] [ - "returning pointer to local variable" @processor block compilerError + cachePointee isUnallocable [ + #its ok + ] [ + "returning pointer to local variable" @processor block compilerError + ] if ] if ] if ] [ @@ -843,6 +862,8 @@ applyNodeChanges: [ [stackEntry cacheEntry variablesAreSame] "Applied vars has different type!" assert stackEntry noMatterToCopy ~ [ + [stackEntry getVar.host.id block.id =] "Stack entry is not from here!" assert + topologyIndex: cacheEntry getVar.topologyIndex copy; [topologyIndex 0 < ~] "Shadow event index is negative!" assert topologyIndex appliedVars.stackVars.size < ~ [ @@ -870,43 +891,39 @@ applyNodeChanges: [ currentChangesNode.matchingInfo.shadowEvents.size [ processor compilable [ shadowEventIndex: i copy; - currentEvent: shadowEventIndex currentChangesNode.matchingInfo.shadowEvents.at; ( ShadowReasonInput [ branch:; stackEntry: @processor @block popForMatching; cacheEntry: branch.refToVar; - stackEntry getVar.data.getTag VarInvalid = ~ [stackEntry @pops.pushBack] when stackEntry cacheEntry @appliedVars addAppliedVar - ] - ShadowReasonStableName [ - branch:; - branch.nameInfo @processor @block addStableName + stackEntry @pops.pushBack ] ShadowReasonCapture [ branch:; - cacheEntry: branch.refToVar; - overloadIndex: outOverloadDepth: branch @block branch.file TRUE getOverloadIndex;; - gnr: branch.nameInfo branch overloadIndex @processor @block branch.file getNameForMatchingWithOverloadIndex; - stackEntry: gnr outOverloadDepth @processor @block branch.file captureName.refToVar; + branch.stable [ + branch.refToVar branch.nameInfo branch.nameOverloadDepth branch.file @processor @block addStableName + ] [ + cacheEntry: branch.refToVar; + overloadIndex: outOverloadDepth: branch @block branch.file TRUE getOverloadIndex;; + gnr: branch.nameInfo overloadIndex @processor @block branch.file getNameForMatchingWithOverloadIndex; + cnr: gnr outOverloadDepth @processor @block branch.file captureName; + stackEntry: cnr.matchingEntry; - [stackEntry cacheEntry variablesAreSame - [ - ( - "shadowEventIndex " shadowEventIndex " of " currentChangesNode.matchingInfo.shadowEvents.size LF - "capture name is " branch.nameInfo processor.nameManager.getText LF - "stack entry is " stackEntry @processor @block getMplType LF - "cache entry is " cacheEntry @processor @block getMplType LF) printList - FALSE - ] || - ] "Applied vars has different type!" assert - stackEntry cacheEntry @appliedVars addAppliedVar - ] - ShadowReasonFieldCapture [ - branch:; - overloadIndex: outOverloadDepth: branch @block branch.file FALSE getOverloadIndex;; - fieldCnr: branch.nameInfo overloadIndex @processor @block branch.file getNameWithOverloadIndex outOverloadDepth @processor @block branch.file captureName; + [stackEntry cacheEntry variablesAreSame + [ + ( + "shadowEventIndex " shadowEventIndex " of " currentChangesNode.matchingInfo.shadowEvents.size LF + "capture name is " branch.nameInfo processor.nameManager.getText LF + "stack entry is " stackEntry @processor @block getMplType LF + "cache entry is " cacheEntry @processor @block getMplType LF) printList + FALSE + ] || + ] "Applied vars has different type!" assert + + stackEntry cacheEntry @appliedVars addAppliedVar + ] if ] ShadowReasonPointee [ branch:; @@ -942,6 +959,10 @@ applyNodeChanges: [ stackEntry: branch.mplFieldIndex stackObject @processor @block getField; stackEntry cacheEntry @appliedVars addAppliedVar ] + ShadowReasonTreeSplitterLambda [ + branch:; + branch copy @processor @block addLambdaEvent + ] [] ) @currentEvent.visit ] when @@ -954,13 +975,13 @@ applyNodeChanges: [ ] times currentChangesNode.hasEmptyLambdas [ - TRUE @block.!hasEmptyLambdas + @block setBlockEmptyLambdas ] when i: 0 dynamic; [ i pops.size < [ - pops.size i - 1 - pops.at @block push + pops.size i - 1 - pops.at @block pushForMatching i 1 + @i set processor compilable ] && ] loop @@ -986,6 +1007,10 @@ applyNodeChanges: [ TRUE @block.@hasCallTrace set ] when + currentChangesNode.hasCallImport [ + TRUE @block.@hasCallImport set + ] when + appliedVars.stackVars.size [ stackEntry: i @appliedVars.@stackVars.at; cacheEntry: i @appliedVars.@cacheVars.at; @@ -1027,7 +1052,7 @@ changeVarValue: [ varDst.data.getTag VarRef = [ srcBranch: VarRef varSrc.data.get; dstBranch: VarRef @varDst.@data.get; - srcBranch @dstBranch set + srcBranch.refToVar @dstBranch.@refToVar set ] when ] if ] when @@ -1067,12 +1092,14 @@ applyNamedStackChanges: [ i: 0 dynamic; [ - i newNode.matchingInfo.inputs.size < [ - @processor @block pop @inputs.pushBack + i newNode.matchingInfo.inputs.getSize < [ + @processor @block popForMatching @inputs.pushBack i 1 + @i set TRUE ] && ] loop + newNode.matchingInfo.inputs.getSize @block updateInputCount + i: 0 dynamic; [ i appliedVars.fixedOutputs.getSize < [ @@ -1184,11 +1211,14 @@ makeCallInstructionWith: [ i newNode.matchingInfo.captures.size < [ currentCapture: i newNode.matchingInfo.captures.at; - currentCapture.refToVar.assigned [ + currentRefToVar: currentCapture.refToVar; + + currentRefToVar.assigned [ currentCapture.argCase ArgRef = currentCapture.argCase ArgCopy = or currentCapture.argCase ArgDerefCopy = or [ overloadIndex: outOverloadDepth: currentCapture @block currentCapture.file FALSE getOverloadIndex;; - refToVar: currentCapture.nameInfo currentCapture overloadIndex @processor @block currentCapture.file getNameForMatchingWithOverloadIndex outOverloadDepth @processor @block currentCapture.file captureName.refToVar; - [currentCapture.refToVar refToVar variablesAreSame] "invalid capture type while generating arg list!" assert + cnr: currentCapture.nameInfo overloadIndex @processor @block currentCapture.file getNameForMatchingWithOverloadIndex outOverloadDepth @processor @block currentCapture.file captureName; + refToVar: cnr.matchingEntry; + [currentRefToVar refToVar variablesAreSame] "invalid capture type while generating arg list!" assert arg: IRArgument; refToVar getVar.irNameId @arg.@irNameId set @@ -1245,9 +1275,10 @@ processNamedCallByNode: [ newNode: newNodeIndex processor.blocks.at.get; compileOnce - newNodeIndex changeNewNodeState - newNode.state NodeStateNoOutput = ~ [ + newNode.state NodeStateNoOutput = [ + newNode TRUE @processor @block useMatchingInfoOnly + ] [ appliedVars: newNode applyNodeChanges; appliedVars.stackVars.size [ @@ -1257,7 +1288,7 @@ processNamedCallByNode: [ ] times newNode newNodeIndex @appliedVars forcedName applyNamedStackChanges - ] when + ] if ]; processCallByNode: [ @@ -1266,10 +1297,10 @@ processCallByNode: [ ]; useMatchingInfoOnly: [ - newNode: processor: block: ;;; + newNode: useArgStatus: processor: block: ;;;; - pops: @processor.acquireVarRefArray; eventVars: @processor.acquireVarRefArray; + pops: @processor.acquireVarRefArray; addEventVar: [ stackEntry: cacheEntry: ;; @@ -1279,11 +1310,26 @@ useMatchingInfoOnly: [ index 1 + @eventVars.resize stackEntry index @eventVars.at set ] when + + useArgStatus [ + cacheEntry getVar.capturedByPtr [ + stackEntry makeVarPtrCaptured + ] when + + cacheEntry getVar.capturedAsRealValue [ + stackEntry @processor @block makeVarRealCaptured + ] when + + cacheEntry getVar.capturedForDeref [ + stackEntry makeVarDerefCaptured + ] when + ] when ] when ]; oldSuccess: processor.result.success copy; TRUE @processor.@result.@success set + oldSuccess @processor.@canBuildTree set newNode.matchingInfo.shadowEvents [ event:; @@ -1292,25 +1338,21 @@ useMatchingInfoOnly: [ branch:; cacheEntry: branch.refToVar; stackEntry: @processor @block popForMatching; - stackEntry getVar.data.getTag VarInvalid = ~ [stackEntry @pops.pushBack] when stackEntry cacheEntry addEventVar + stackEntry @pops.pushBack ] ShadowReasonCapture [ branch:; - cacheEntry: branch.refToVar; - overloadIndex: outOverloadDepth: branch @block branch.file TRUE getOverloadIndex;; - gnr: branch.nameInfo branch overloadIndex @processor @block branch.file getNameForMatchingWithOverloadIndex; - stackEntry: gnr outOverloadDepth @processor @block branch.file captureName.refToVar; - stackEntry cacheEntry addEventVar - ] - ShadowReasonStableName [ - branch:; - branch.nameInfo @processor @block addStableName - ] - ShadowReasonFieldCapture [ - branch:; - overloadIndex: outOverloadDepth: branch @block branch.file FALSE getOverloadIndex;; - fieldCnr: branch.nameInfo overloadIndex @processor @block branch.file getNameWithOverloadIndex outOverloadDepth @processor @block branch.file captureName; + branch.stable [ + branch.refToVar branch.nameInfo branch.nameOverloadDepth branch.file @processor @block addStableName + ] [ + cacheEntry: branch.refToVar; + overloadIndex: outOverloadDepth: branch @block branch.file TRUE getOverloadIndex;; + gnr: branch.nameInfo overloadIndex @processor @block branch.file getNameForMatchingWithOverloadIndex; + cnr: gnr outOverloadDepth @processor @block branch.file captureName; + stackEntry: cnr.matchingEntry; + stackEntry cacheEntry addEventVar + ] if ] ShadowReasonPointee [ branch:; @@ -1328,25 +1370,25 @@ useMatchingInfoOnly: [ ) event.visit ] each - newNode.capturedFiles.getSize [ - i newNode.capturedFiles.at [ - i @block captureFileToBlock - ] when - ] times - - @eventVars @processor.releaseVarRefArray + TRUE @processor.@canBuildTree set i: 0 dynamic; [ i pops.size < [ - pops.size i - 1 - pops.at @block push - i 1 + @i set - TRUE + pops.size i - 1 - pops.at @block pushForMatching + i 1 + @i set processor compilable ] && ] loop @pops @processor.releaseVarRefArray + newNode.capturedFiles.getSize [ + i newNode.capturedFiles.at [ + i @block captureFileToBlock + ] when + ] times + + @eventVars @processor.releaseVarRefArray oldSuccess @processor.@result.@success set ]; @@ -1397,7 +1439,7 @@ useMatchingInfoOnly: [ newNodeIndex forcedName processNamedCallByNode ] if ] [ - newNode @processor @block useMatchingInfoOnly + newNode FALSE @processor @block useMatchingInfoOnly ] if ] "processCallByIndexArray" exportFunction @@ -1428,7 +1470,7 @@ useMatchingInfoOnly: [ ] when newNode: newNodeIndex processor.blocks.at.get; - newNode @processor @block useMatchingInfoOnly + newNode FALSE @processor @block useMatchingInfoOnly oldGlobalErrorCount @processor.@result.@globalErrorInfo.shrink oldSuccess [ @@ -1481,7 +1523,7 @@ useMatchingInfoOnly: [ newNodeThen: newNodeThenIndex @processor.@blocks.at.get; processor compilable ~ [ - newNodeThen @processor @block useMatchingInfoOnly + newNodeThen FALSE @processor @block useMatchingInfoOnly ] [ newNodeElseIndex: @astArrayIndexElse @processor @block tryMatchAllNodes; newNodeElseIndex 0 < [ @@ -1497,7 +1539,8 @@ useMatchingInfoOnly: [ newNodeElse: newNodeElseIndex @processor.@blocks.at.get; processor compilable ~ [ - newNodeElse @processor @block useMatchingInfoOnly + newNodeThen FALSE @processor @block useMatchingInfoOnly + newNodeElse FALSE @processor @block useMatchingInfoOnly ] [ newNodeThenIndex changeNewNodeState newNodeElseIndex changeNewNodeState @@ -1508,11 +1551,17 @@ useMatchingInfoOnly: [ NodeStateNoOutput @block.@state set ] [ newNodeThen.state NodeStateHasOutput < [ - newNodeElseIndex processCallByNode + newNodeThen TRUE @processor @block useMatchingInfoOnly ] [ newNodeThenIndex processCallByNode ] if + newNodeElse.state NodeStateHasOutput < [ + newNodeElse TRUE @processor @block useMatchingInfoOnly + ] [ + newNodeElseIndex processCallByNode + ] if + NodeStateHasOutput @block.@state set ] if ] [ @@ -1846,6 +1895,7 @@ processDynamicLoop: [ newNodeIndex changeNewNodeState newNode.state NodeStateHasOutput < [ + newNode FALSE @processor @block useMatchingInfoOnly FALSE ] [ newNode.state NodeStateHasOutput = [NodeStateHasOutput @block.@state set] when @@ -2020,11 +2070,12 @@ processDynamicLoop: [ newNode: newNodeIndex @processor.@blocks.at.get; processor compilable ~ [ - newNode @processor @block useMatchingInfoOnly + newNode FALSE @processor @block useMatchingInfoOnly FALSE ] [ newNodeIndex changeNewNodeState newNode.state NodeStateHasOutput < [ + newNode TRUE @processor @block useMatchingInfoOnly FALSE ] [ newNode.state NodeStateHasOutput = [NodeStateHasOutput @block.@state set] when @@ -2166,10 +2217,13 @@ processDynamicLoop: [ ( ShadowReasonCapture [ branch:; - - overloadIndex: outOverloadDepth: branch @block branch.file TRUE getOverloadIndex;; - gnr: branch.nameInfo branch overloadIndex @processor @block branch.file getNameForMatchingWithOverloadIndex; - stackEntry: gnr outOverloadDepth @processor @block branch.file captureName.refToVar; + branch.stable [ + branch.refToVar branch.nameInfo branch.nameOverloadDepth branch.file @processor @block addStableName + ] [ + overloadIndex: outOverloadDepth: branch @block branch.file TRUE getOverloadIndex;; + gnr: branch.nameInfo overloadIndex @processor @block branch.file getNameForMatchingWithOverloadIndex; + stackEntry: gnr outOverloadDepth @processor @block branch.file captureName.refToVar; + ] if ] [] ) currentEvent.visit @@ -2372,6 +2426,7 @@ callImportWith: [ ] ) sequence + TRUE @block.@hasCallImport set TRUE @block.@hasCallTrace set @inputs @processor.releaseVarRefArray diff --git a/processor.mpl b/processor.mpl index cfa5d62..220fbc8 100644 --- a/processor.mpl +++ b/processor.mpl @@ -21,6 +21,7 @@ DEFAULT_PRE_RECURSION_DEPTH_LIMIT: [64]; ProcessorOptions: [{ mainPath: String; + fullLine: String; beginFunc: String; endFunc: String; fileNames: StringArray; @@ -69,6 +70,7 @@ RefToVarTable: [ NameInfoEntry: [{ file: File Cref; + object: RefToVar; # for NameCaseSelfMember refToVar: RefToVar; startPoint: -1 dynamic; # id of node mplFieldIndex: -1 dynamic; # for NameCaseSelfMember @@ -76,14 +78,26 @@ NameInfoEntry: [{ nameCase: NameCaseInvalid; }]; -MatchingNode: [{ - unknownMplType: Int32 Array; - byMplType: Int32 Int32 Array HashTable; #first input MPL type +MatchingNodePair: [{ + eventHash: Nat32; + childIndex: Int32; +}]; + +MatchingNodeEntry: [{ + nodeIndexes: Int32 Array; + parentIndex: -1 dynamic; + parentEvent: ShadowEvent; + childIndices: MatchingNodePair Array; +}]; +MatchingNode: [{ compilerPositionInfo: CompilerPositionInfo; entries: Int32; tries: Int32; size: Int32; + count: Int32; + + treeMemory: MatchingNodeEntry Array; }]; makeWayInfo: [{ @@ -111,6 +125,7 @@ Processor: [{ options: ProcessorOptions; multiParserResult: MultiParserResult Ref; result: ProcessorResult; + canBuildTree: TRUE dynamic; positions: CompilerPositionInfo Array; unfinishedFiles: Int32 Array; @@ -131,8 +146,6 @@ Processor: [{ captureTable: { simpleNames: NameInfoCoord Array Array Array; #name; overload; vector of blocks - selfNames: NameInfoCoord Array Array Array; #overload; mplTypeId; vector of blocks - closureNames: NameInfoCoord Array Array Array; #overload; mplTypeId; vector of blocks stableNames: Int32 Array Array; #vector of vector of blockId }; diff --git a/processorImpl.mpl b/processorImpl.mpl index 1bce2e6..e488c40 100644 --- a/processorImpl.mpl +++ b/processorImpl.mpl @@ -32,12 +32,13 @@ debugMemory [ multiParserResult: MultiParserResult Ref; fileText: StringView Cref; fileName: StringView Cref; + fileId: Int32; errorMessage: String Ref; } () {} [ - errorMessage: fileName: fileText: multiParserResult: nameManager: ;;;;; + errorMessage: fileId: fileName: fileText: multiParserResult: nameManager: ;;;;;; parserResult: ParserResult; - @parserResult fileText makeStringView parseString + @parserResult fileId fileText makeStringView parseString parserResult.success [ @parserResult optimizeLabels @@ -298,9 +299,25 @@ debugMemory [ ("all nodes generated" makeStringView) addLog [processor compilable ~ [processor.recursiveNodesStack.getSize 0 =] ||] "Recursive stack is not empty!" assert + getTreeSize: [ + result: 0nx dynamic; + processor.matchingNodes [ + current:; + current.assigned [ + current.get.treeMemory.dataReserve Natx cast current.get.treeMemory.elementType storageSize * result + !result + current.get.treeMemory [ + current:; + current.childIndices.dataReserve Natx cast current.childIndices.elementType storageSize * result + !result + ] each + ] when + ] each + + result + ]; + processor.result.success [ ("nameCount=" processor.nameManager.names.size - "; irNameCount=" processor.nameBuffer.size "; block count=" processor.blocks.getSize "; block size=" BlockSchema storageSize "; est var count=" processor.variables.getSize 4096 * "; var size=" VarSchema storageSize) addLog + "; irNameCount=" processor.nameBuffer.size "; block count=" processor.blocks.getSize "; block size=" BlockSchema storageSize "; est var count=" processor.variables.getSize 4096 * "; var size=" VarSchema storageSize "; tree size=" getTreeSize) addLog ("max depth of recursion=" processor.maxDepthOfRecursion) addLog @@ -330,10 +347,7 @@ debugMemory [ result ]; - coordsMemory: - processor.captureTable.simpleNames getCoordsMemory - processor.captureTable.selfNames getCoordsMemory + - processor.captureTable.closureNames getCoordsMemory +; + coordsMemory: processor.captureTable.simpleNames getCoordsMemory; getVariableUsedMemory: [ var:; @@ -399,23 +413,25 @@ debugMemory [ event.getTag ShadowReasonCapture = [ branch: ShadowReasonCapture event.get; - branch.refToVar getVar processor.varForFails getVar is [ - failedCaptureCount 1 + !failedCaptureCount - name: branch.nameInfo processor.nameManager.getText; - fr: name @failedCaptureNames.find; - fr.success [ - fr.value 1 + @fr.@value set - ] [ - name 1 @failedCaptureNames.insert - ] if - ] when - - branch.refToVar isGlobal [branch.refToVar isUnallocable] && [ - stringCaptureCount 1 + !stringCaptureCount - ] when - - branch.refToVar isGlobal [branch.refToVar isVirtual] && [ - virtualCaptureCount 1 + !virtualCaptureCount + branch.stable ~ [ + branch.refToVar getVar processor.varForFails getVar is [ + failedCaptureCount 1 + !failedCaptureCount + name: branch.nameInfo processor.nameManager.getText; + fr: name @failedCaptureNames.find; + fr.success [ + fr.value 1 + @fr.@value set + ] [ + name 1 @failedCaptureNames.insert + ] if + ] when + + branch.refToVar isGlobal [branch.refToVar isUnallocable] && [ + stringCaptureCount 1 + !stringCaptureCount + ] when + + branch.refToVar isGlobal [branch.refToVar isVirtual] && [ + virtualCaptureCount 1 + !virtualCaptureCount + ] when ] when ] when ] each @@ -431,7 +447,7 @@ debugMemory [ "; totalFieldCount=" totalFieldCount "; fieldSize=" Field storageSize "; beventCount=" beventCount "; meventCount=" meventCount - "; meventCountByTag=" 0 eventTagCount @ ":" 1 eventTagCount @ ":" 2 eventTagCount @ ":" 3 eventTagCount @ ":" 4 eventTagCount @ ":" 5 eventTagCount @ + "; meventCountByTag=" 0 eventTagCount @ ":" 1 eventTagCount @ ":" 2 eventTagCount @ ":" 3 eventTagCount @ ":" 4 eventTagCount @ "; eventSize=" ShadowEvent storageSize ) addLog @@ -505,7 +521,10 @@ debugMemory [ LF @processor.@result.@program.cat ] when ] each - ] when + ] [ + ("nameCount=" processor.nameManager.names.size + "; irNameCount=" processor.nameBuffer.size "; block count=" processor.blocks.getSize "; block size=" BlockSchema storageSize "; est var count=" processor.variables.getSize 4096 * "; var size=" VarSchema storageSize "; tree size=" getTreeSize) addLog + ] if processor.result.success ~ [ processor.result.globalErrorInfo.getSize [ diff --git a/variable.mpl b/variable.mpl index 05df849..7b7df1c 100644 --- a/variable.mpl +++ b/variable.mpl @@ -199,10 +199,11 @@ getNonrecursiveDataMPLType: [ "s" toString @result set ] [ var.data.getTag VarCode = [ - "c" toString @result set + info: VarCode var.data.get; + ("c'" info.file.name getStringImplementation "\"/" info.line ":" info.column) assembleString @result set ] [ var.data.getTag VarBuiltin = [ - "b" toString @result set + ("b'" VarBuiltin var.data.get) assembleString @result set ] [ var.data.getTag VarInvalid = [ "I" toString @result set @@ -321,11 +322,6 @@ untemporize: [ FALSE @var.@temporary set ]; -noMatterToCopy: [ - refToVar:; - refToVar isVirtual [refToVar isAutoStruct ~] && -]; - makeTypeAliasId: [ irTypeName:; @@ -662,7 +658,7 @@ makeDbgTypeId: [ refToVar isVirtual [ ir: refToVar getVirtualValue; "'" @resultMPL.cat - ir @resultMPL.cat + #ir @resultMPL.cat ] when ] "getMplTypeImpl" exportFunction