diff --git a/Block.mpl b/Block.mpl index e09f6ed..63512bd 100644 --- a/Block.mpl +++ b/Block.mpl @@ -1,13 +1,11 @@ +"Array" use +"HashTable" use +"String" use +"Variant" use "control" use -"Array.Array" use -"HashTable.HashTable" use -"String.String" use -"Variant.Variant" use - -"Mref.Mref" use -"Var.RefToVar" use -"Var.Struct" use +"Mref" use +"Var" use ArgVirtual: [0n8 dynamic]; ArgGlobal: [1n8 dynamic]; @@ -67,7 +65,7 @@ Capture: [{ captureCase: NameCaseInvalid; nameInfo: -1 dynamic; nameOverloadDepth: -1 dynamic; - file: ["File.FileSchema" use FileSchema] Mref; + file: ["MplFile.FileSchema" use FileSchema] Mref; }]; CFunctionSignature: [{ @@ -78,7 +76,7 @@ CFunctionSignature: [{ }]; CompilerPositionInfo: [{ - file: ["File.FileSchema" use FileSchema] Mref; + file: ["MplFile.FileSchema" use FileSchema] Mref; line: -1 dynamic; column: -1 dynamic; token: String; @@ -90,7 +88,7 @@ FieldCapture: [{ nameInfo: -1 dynamic; nameOverloadDepth: -1 dynamic; fieldIndex: -1 dynamic; - file: ["File.FileSchema" use FileSchema] Mref; + file: ["MplFile.FileSchema" use FileSchema] Mref; }]; makeInstruction: [{ @@ -110,6 +108,7 @@ Instruction: [0 0 makeInstruction]; ShadowEvent: [( Cond #ShadowReasonNo ShadowEventCapture #ShadowReasonCapture + ShadowEventStableName #ShadowReasonStableName ShadowEventFieldCapture #ShadowReasonFieldCapture ShadowEventInput #ShadowReasonInput ShadowEventField #ShadowReasonField @@ -125,7 +124,7 @@ MatchingInfo: [{ NameWithOverload: [{ nameInfo: -1 dynamic; - nameOverloadDepth: -1 dynamic; + nameOverloadDepth: -1 dynamic; }]; NameWithOverloadAndRefToVar: [{ @@ -138,7 +137,7 @@ NameWithOverloadAndRefToVar: [{ }]; TokenRef: [{ - file: ["File.FileSchema" use FileSchema] Mref; + file: ["MplFile.FileSchema" use FileSchema] Mref; token: Int32; }]; @@ -171,7 +170,9 @@ ShadowEventStableName: [{ Block: [{ id: Int32; root: FALSE dynamic; - file: ["File.FileSchema" use FileSchema] Mref; + file: ["MplFile.FileSchema" use FileSchema] Mref; + topNode: [@BlockSchema] Mref; + capturedFiles: Cond Array; beginPosition: CompilerPositionInfo; parent: 0 dynamic; nodeCase: NodeCaseCode; @@ -182,7 +183,9 @@ Block: [{ aliases: String Array; lastLambdaName: Int32; nextRecLambdaId: -1 dynamic; + globalPriority: Int32; + hasEmptyLambdas: FALSE dynamic; nodeIsRecursive: FALSE dynamic; nextLabelIsVirtual: FALSE dynamic; nextLabelIsConst: FALSE dynamic; @@ -204,6 +207,8 @@ Block: [{ uncompilable: FALSE dynamic; variadic: FALSE dynamic; hasNestedCall: FALSE dynamic; + hasCallTrace: FALSE dynamic; + changedStableName: FALSE dynamic; countOfUCall: 0 dynamic; declarationRefs: Cond Array; @@ -217,9 +222,11 @@ Block: [{ labelNames: NameWithOverloadAndRefToVar Array; captureNames: NameWithOverloadAndRefToVar Array; fieldCaptureNames: NameWithOverloadAndRefToVar Array; + stableNames: Int32 Array; candidatesToDie: RefToVar Array; unprocessedAstNodes: TokenRef Array; + globalVariableNames: Int32 RefToVar Array HashTable; refToVar: RefToVar; #refToVar of function with compiled node varNameInfo: -1 dynamic; #variable name of imported function diff --git a/File.mpl b/MplFile.mpl similarity index 72% rename from File.mpl rename to MplFile.mpl index b553df6..f0ae5fc 100644 --- a/File.mpl +++ b/MplFile.mpl @@ -1,9 +1,11 @@ -"Mref.Mref" use -"String.String" use +"Mref" use +"String" use "control" use File: [{ name: String; + usedInParams: Cond; + fileId: Int32; text: String; debugId: Int32; rootBlock: ["Block.BlockSchema" use BlockSchema] Mref; diff --git a/Mref.mpl b/Mref.mpl index 7ed7838..43e5754 100644 --- a/Mref.mpl +++ b/Mref.mpl @@ -1,3 +1,5 @@ +"control" use + Mref: [{ ObjectSchema:; data: 0nx dynamic; diff --git a/NameManager.mpl b/NameManager.mpl index d9d2c2d..9e8dacf 100644 --- a/NameManager.mpl +++ b/NameManager.mpl @@ -1,10 +1,6 @@ -"Array.Array" use -"HashTable.HashTable" use -"HashTable.hash" use -"String.String" use -"String.StringView" use -"String.hash" use -"String.toString" use +"Array" use +"HashTable" use +"String" use "control" use NameManager: [{ @@ -19,6 +15,8 @@ NameManager: [{ nameId 1 + @names.enlarge string.getStringView nameId @textNameIds.insertUnsafe # Make StringView using the source String object, reference should remain valid when we move String @string move @names.last.@text set + 0 @names.last.!overloadCount + 0 @names.last.!localCount nameId ] if ]; @@ -26,7 +24,10 @@ NameManager: [{ addItem: [ item: nameId:;; - @item move nameId @names.at.@items.pushBack + current: nameId @names.at; + item.file isNil [current.overloadCount 1 + @current.!overloadCount] when + item.isLocal [current.localCount 1 + @current.!localCount] when + @item move @current.@items.pushBack ]; findItem: [ @@ -45,6 +46,16 @@ NameManager: [{ index ]; + hasOverload: [ + nameId: copy; + nameId @names.at.overloadCount 0 > + ]; + + hasLocalDefinition: [ + nameId: copy; + nameId @names.at.localCount 0 > + ]; + getItem: [ index: nameId:;; index nameId @names.at.@items.at @@ -58,7 +69,12 @@ NameManager: [{ removeItem: [ nameId:; - nameId @names.at.@items.popBack + current: nameId @names.at; + current.items.last.file isNil [current.overloadCount 1 - @current.!overloadCount] when + current.items.last.isLocal [current.localCount 1 - @current.!localCount] when + + @current.@items.popBack + ]; # Private @@ -66,6 +82,8 @@ NameManager: [{ Name: [{ text: String; items: @itemSchema Array; + overloadCount: Int32; + localCount: Int32; }]; names: Name Array; diff --git a/Var.mpl b/Var.mpl index b68675c..dce24cb 100644 --- a/Var.mpl +++ b/Var.mpl @@ -1,17 +1,11 @@ - -"Array.Array" use -"Owner.Owner" use -"String.String" use -"String.StringView" use -"String.addLog" use -"String.assembleString" use -"String.makeStringView" use -"String.toString" use -"Variant.Variant" use +"Array" use +"Owner" use +"String" use +"Variant" use "control" use -"Mref.Mref" use -"staticCall.staticCall" use +"Mref" use +"staticCall" use Dirty: [0n8 dynamic]; Dynamic: [1n8 dynamic]; @@ -21,10 +15,11 @@ Virtual: [4n8 dynamic]; ShadowReasonNo: [0]; ShadowReasonCapture: [1]; -ShadowReasonFieldCapture: [2]; -ShadowReasonInput: [3]; -ShadowReasonField: [4]; -ShadowReasonPointee: [5]; +ShadowReasonStableName: [2]; +ShadowReasonFieldCapture: [3]; +ShadowReasonInput: [4]; +ShadowReasonField: [5]; +ShadowReasonPointee: [6]; VarInvalid: [ 0 static]; VarCond: [ 1 static]; @@ -49,7 +44,7 @@ VarStruct: [19 static]; VarEnd: [20 static]; CodeNodeInfo: [{ - file: ["File.FileSchema" use FileSchema] Mref; + file: ["MplFile.FileSchema" use FileSchema] Mref; line: Int32; column: Int32; index: Int32; @@ -341,7 +336,6 @@ getVirtualValue: [ refToVar isPlain [ refToVar getPlainConstantIR @result.cat ] [ - ("Tag = " var.data.getTag) addLog [FALSE] "Wrong type for virtual value!" assert ] if ] @@ -544,6 +538,18 @@ makeStringId: [ ] if ]; +makeDefaultVarId: [ + varId: processor: ;; + + [varId processor.defaultVarNames.getSize < ~] [ + -1 @processor.@defaultVarNames.pushBack + ] while + + result: varId @processor.@defaultVarNames.at; + result 0 < [("%var." varId) assembleString @processor makeStringId @result set] when + result copy +]; + markAsUnableToDie: [ refToVar:; var: @refToVar getVar; diff --git a/astNodeType.mpl b/astNodeType.mpl index a0d19a5..d9a4e6c 100644 --- a/astNodeType.mpl +++ b/astNodeType.mpl @@ -1,10 +1,10 @@ +"Array" use +"HashTable" use +"Owner" use +"String" use +"Variant" use "control" use -"Array.Array" use -"HashTable.HashTable" use -"String.String" use -"Variant.Variant" use - AstNodeType: { Code: [ 0]; Label: [ 1]; @@ -103,8 +103,8 @@ ParserResult: [{ ParserResults: [ParserResult Array]; MultiParserResult: [{ - memory: AstNode Array; - nodes: IndexArray Array; # order of going is not defined before compiling + memory: AstNode Owner Array; + nodes: IndexArray Owner 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 87275a0..28d635c 100644 --- a/astOptimizers.mpl +++ b/astOptimizers.mpl @@ -1,10 +1,10 @@ -"Array.Array" use -"Array.makeArrayRange" use -"String.makeStringView" use -"astNodeType.AstNodeType" use -"astNodeType.IndexArray" use +"Array" use +"Owner" use +"String" use "control" use +"astNodeType" use + optimizeLabelsInCurrentNode: [ node:; @@ -117,47 +117,37 @@ optimizeNamesInCurrentNode: [ ]; optimizeNames: [ - multiParserResult: nameManager: ;; - - i: 0 dynamic; - [ - i multiParserResult.nodes.dataSize < [ - currentNodesArray: i @multiParserResult.@nodes.at; - - unfinishedNodes: IndexArray AsRef Array; - unfinishedIndexes: Int32 Array; - @currentNodesArray AsRef @unfinishedNodes.pushBack - 0 dynamic @unfinishedIndexes.pushBack + current: nameManager: ;; - [ - uSize: unfinishedIndexes.dataSize 1 -; - index: uSize unfinishedIndexes.at copy; - nodes: unfinishedNodes.last.data; + unfinishedNodes: IndexArray AsRef Array; + unfinishedIndexes: Int32 Array; + @current.@nodes AsRef @unfinishedNodes.pushBack + 0 dynamic @unfinishedIndexes.pushBack - index nodes.dataSize < [ - index nodes.at @multiParserResult.@memory.at optimizeNamesInCurrentNode # reallocation here + [ + uSize: unfinishedIndexes.dataSize 1 -; + index: uSize unfinishedIndexes.at copy; + nodes: unfinishedNodes.last.data; - indexAfter: uSize @unfinishedIndexes.at; - indexAfter 1 + @indexAfter set - TRUE - ] [ - @unfinishedIndexes.popBack - @unfinishedNodes.popBack + index nodes.dataSize < [ + index nodes.at @current.@memory.at optimizeNamesInCurrentNode # reallocation here - unfinishedNodes.getSize 0 > - ] if - ] loop + indexAfter: uSize @unfinishedIndexes.at; + indexAfter 1 + @indexAfter set + TRUE + ] [ + @unfinishedIndexes.popBack + @unfinishedNodes.popBack - i 1 + @i set TRUE - ] && + unfinishedNodes.getSize 0 > + ] if ] loop ]; -concatParserResults: [ +concatParserResult: [ mresult:; - results:; - p: 0; - shift: 0; + current:; + shift: mresult.memory.getSize; adjustArray: [ indexArray:; @@ -167,30 +157,23 @@ concatParserResults: [ ] each ]; - r: @results makeArrayRange; - - @results [ - current:; - @current.@nodes adjustArray - @current.@memory [ - currentNode:; - currentNode.data.getTag AstNodeType.Code = [ - AstNodeType.Code @currentNode.@data.get adjustArray + @current.@nodes adjustArray + @current.@memory [ + currentNode:; + currentNode.data.getTag AstNodeType.Code = [ + AstNodeType.Code @currentNode.@data.get adjustArray + ] [ + currentNode.data.getTag AstNodeType.List = [ + AstNodeType.List @currentNode.@data.get adjustArray ] [ - currentNode.data.getTag AstNodeType.List = [ - AstNodeType.List @currentNode.@data.get adjustArray - ] [ - currentNode.data.getTag AstNodeType.Object = [ - AstNodeType.Object @currentNode.@data.get adjustArray - ] when - ] if + currentNode.data.getTag AstNodeType.Object = [ + AstNodeType.Object @currentNode.@data.get adjustArray + ] when ] if + ] if - @currentNode move @mresult.@memory.pushBack - ] each - - @current.@nodes move @mresult.@nodes.pushBack - - shift current.memory.dataSize + @shift set + @currentNode move owner @mresult.@memory.pushBack ] each + + @current.@nodes move owner @mresult.@nodes.pushBack ]; diff --git a/build/compile.bat b/build/compile.bat index e8e3581..54d099d 100755 --- a/build/compile.bat +++ b/build/compile.bat @@ -2,37 +2,4 @@ FOR /F "tokens=*" %%v IN ('git log --date^=format:%%y%%m%%d --format^=%%cd -1') DO SET SOURCE_VERSION=%%v -mplc.exe -D COMPILER_SOURCE_VERSION=%SOURCE_VERSION% -D DEBUG=FALSE -D DEBUG_MEMORY=TRUE -call_trace 0 -debug_memory -ndebug -o mplc.ll^ - ../astNodeType.mpl^ - ../astOptimizers.mpl^ - ../Block.mpl^ - ../builtinImpl.mpl^ - ../builtins.mpl^ - ../codeNode.mpl^ - ../debugWriter.mpl^ - ../declarations.mpl^ - ../defaultImpl.mpl^ - ../File.mpl^ - ../irWriter.mpl^ - ../main.mpl^ - ../Mref.mpl^ - ../NameManager.mpl^ - ../parser.mpl^ - ../pathUtils.mpl^ - ../processor.mpl^ - ../processorImpl.mpl^ - ../processSubNodes.mpl^ - ../schemas.mpl^ - ../staticCall.mpl^ - ../Var.mpl^ - ../variable.mpl^ - ../sl/Array.mpl^ - ../sl/ascii.mpl^ - ../sl/control.mpl^ - ../sl/conventions.mpl^ - ../sl/file.mpl^ - ../sl/HashTable.mpl^ - ../sl/memory.mpl^ - ../sl/Owner.mpl^ - ../sl/String.mpl^ - ../sl/Variant.mpl +mplc.exe -D COMPILER_SOURCE_VERSION=%SOURCE_VERSION% -D DEBUG=FALSE -D DEBUG_MEMORY=TRUE -I ../sl -call_trace 0 -debug_memory -ndebug -o mplc.ll ../main.mpl diff --git a/build/compile.sh b/build/compile.sh index efe29a7..d878d8d 100755 --- a/build/compile.sh +++ b/build/compile.sh @@ -2,32 +2,4 @@ SOURCE_VERSION=$(git log --date=format:%y%m%d --format=%cd -1) -mplc -D COMPILER_SOURCE_VERSION=$SOURCE_VERSION -ndebug -o mplc.ll\ - ../astNodeType.mpl\ - ../astOptimizers.mpl\ - ../builtinImpl.mpl\ - ../builtins.mpl\ - ../codeNode.mpl\ - ../debugWriter.mpl\ - ../declarations.mpl\ - ../defaultImpl.mpl\ - ../irWriter.mpl\ - ../main.mpl\ - ../parser.mpl\ - ../pathUtils.mpl\ - ../processor.mpl\ - ../processorImpl.mpl\ - ../processSubNodes.mpl\ - ../schemas.mpl\ - ../staticCall.mpl\ - ../variable.mpl\ - ../sl/ascii.mpl\ - ../sl/Array.mpl\ - ../sl/control.mpl\ - ../sl/conventions.mpl\ - ../sl/file.mpl\ - ../sl/HashTable.mpl\ - ../sl/memory.mpl\ - ../sl/Owner.mpl\ - ../sl/String.mpl\ - ../sl/Variant.mpl +mplc -D COMPILER_SOURCE_VERSION=$SOURCE_VERSION -I ../sl -ndebug -o mplc.ll ../main.mpl diff --git a/builtinImpl.mpl b/builtinImpl.mpl index 6735a77..fab1b54 100644 --- a/builtinImpl.mpl +++ b/builtinImpl.mpl @@ -1,167 +1,24 @@ -"Array.Array" use -"HashTable.HashTable" use -"Owner.owner" use -"String.String" use -"String.assembleString" use -"String.makeStringView" use -"String.print" use -"String.printList" use -"String.splitString" use -"String.toString" use +"Array" use +"HashTable" use +"Owner" use +"String" use "control" use - -"Block.Block" use -"Block.CFunctionSignature" use -"Block.NameCaseFromModule" use -"Block.NameCaseLocal" use -"Var.Dirty" use -"Var.Dynamic" use -"Var.Field" use -"Var.RefToVar" use -"Var.ShadowReasonCapture" use -"Var.ShadowReasonField" use -"Var.Static" use -"Var.Struct" use -"Var.VarBuiltin" use -"Var.VarCode" use -"Var.VarCond" use -"Var.VarEnd" use -"Var.VarImport" use -"Var.VarInt16" use -"Var.VarInt32" use -"Var.VarInt64" use -"Var.VarInt8" use -"Var.VarIntX" use -"Var.VarInvalid" use -"Var.VarNat16" use -"Var.VarNat32" use -"Var.VarNat64" use -"Var.VarNat8" use -"Var.VarNatX" use -"Var.VarReal32" use -"Var.VarReal64" use -"Var.VarRef" use -"Var.VarString" use -"Var.VarStruct" use -"Var.Variable" use -"Var.Virtual" use -"Var.Virtual" use -"Var.Weak" use -"Var.fullUntemporize" use -"Var.getAlignment" use -"Var.getStorageSize" use -"Var.getVar" use -"Var.isAnyInt" use -"Var.isAutoStruct" use -"Var.isNat" use -"Var.isNumber" use -"Var.isPlain" use -"Var.isReal" use -"Var.isUnallocable" use -"Var.isVirtual" use -"Var.makeRefBranch" use -"Var.makeStringId" use -"Var.makeValuePair" use -"Var.markAsUnableToDie" use -"Var.staticityOfVar" use -"Var.varIsMoved" use -"Var.variablesAreSame" use -"astNodeType.AstNodeType" use -"codeNode.addIndexArrayToProcess" use -"codeNode.addNameInfo" use -"codeNode.captureName" use -"codeNode.catPossibleModulesList" use -"codeNode.createNamedVariable" use -"codeNode.createRefVariable" use -"codeNode.createVariable" use -"codeNode.createVariableWithVirtual" use -"codeNode.derefAndPush" use -"codeNode.getLastShadow" use -"codeNode.getNameWithOverloadIndex" use -"codeNode.getName" use -"codeNode.getNilVar" use -"codeNode.makeStaticity" use -"codeNode.makeStorageStaticity" use -"codeNode.makeVarDirty" use -"codeNode.makeVarTreeDirty" use -"codeNode.makeVarTreeDynamic" use -"codeNode.makeVarTreeDynamicStoraged" use -"codeNode.makeVirtualVarReal" use -"codeNode.processMember" use -"codeNode.processStaticAt" use -"codeNode.push" use -"codeNode.setRef" use -"debugWriter.addGlobalVariableDebugInfo" use -"declarations.callAssign" use -"declarations.callDie" use -"declarations.callInit" use -"declarations.compilerError" use -"declarations.copyOneVar" use -"declarations.copyOneVarFromType" use -"declarations.copyVar" use -"declarations.copyVarFromChild" use -"declarations.copyVarFromType" use -"declarations.copyVarToNew" use -"declarations.defaultCall" use -"declarations.defaultPrintStack" use -"declarations.defaultPrintStackTrace" use -"declarations.getMplType" use -"declarations.makeShadows" use -"declarations.makeVarString" use -"declarations.processCall" use -"defaultImpl.FailProcForProcessor" use -"defaultImpl.compilable" use -"defaultImpl.createRef" use -"defaultImpl.createRefNoOp" use -"defaultImpl.defaultFailProc" use -"defaultImpl.defaultMakeConstWith" use -"defaultImpl.defaultSet" use -"defaultImpl.findNameInfo" use -"defaultImpl.makeVarPtrCaptured" use -"defaultImpl.makeVarRealCaptured" use -"defaultImpl.pop" use -"irWriter.createAllocIR" use -"irWriter.createBinaryOperation" use -"irWriter.createBinaryOperationDiffTypes" use -"irWriter.createCallIR" use -"irWriter.createCastCopyPtrToNew" use -"irWriter.createCastCopyToNew" use -"irWriter.createCheckedCopyToNew" use -"irWriter.createComment" use -"irWriter.createCopyToNew" use -"irWriter.createDerefToRegister" use -"irWriter.createDirectBinaryOperation" use -"irWriter.createDynamicGEP" use -"irWriter.createGEPInsteadOfAlloc" use -"irWriter.createGetCallTrace" use -"irWriter.createGetTextSizeIR" use -"irWriter.createGlobalAliasIR" use -"irWriter.createPlainIR" use -"irWriter.createStoreFromRegister" use -"irWriter.createStringCompare" use -"irWriter.createUnaryOperation" use -"irWriter.createVarExportIR" use -"irWriter.createVarImportIR" use -"irWriter.getIrType" use -"irWriter.getMplSchema" use -"memory.debugMemory" use -"pathUtils.extractExtension" use -"pathUtils.stripExtension" use -"processSubNodes.clearProcessorResult" use -"processSubNodes.processExportFunction" use -"processSubNodes.processIf" use -"processSubNodes.processImportFunction" use -"processSubNodes.processLoop" use -"processor.IRArgument" use -"processor.Processor" use -"staticCall.staticCall" use -"variable.checkUnsizedData" use -"variable.cutValue" use -"variable.findField" use -"variable.isGlobal" use -"variable.refsAreEqual" use -"variable.unglobalize" use -"variable.zeroValue" use +"file" use + +"Block" use +"Var" use +"astNodeType" use +"codeNode" use +"debugWriter" use +"declarations" use +"defaultImpl" use +"irWriter" use +"memory" use +"pathUtils" use +"processSubNodes" use +"processor" use +"staticCall" use +"variable" use debugMemory [ "memory.getMemoryMetrics" use @@ -346,7 +203,7 @@ mplNumberBuiltinOp: [ FALSE @irarg.@byRef set irarg @args.pushBack - result args String @opName @processor @block createCallIR retName:; + result args String @opName FALSE dynamic @processor @block createCallIR retName:; retName result @processor @block createStoreFromRegister @@ -710,10 +567,6 @@ staticityOfBinResult: [ FALSE makeValuePair VarCond @processor @block createVariable @processor @block createPlainIR @block push ] "mplBuiltinFalse" @declareBuiltin ucall -[ - processor.options.logs makeValuePair VarCond @processor @block createVariable Static @processor @block makeStaticity @processor @block createPlainIR @block push -] "mplBuiltinHasLogs" @declareBuiltin ucall - [ LF toString @processor @block makeVarString @block push ] "mplBuiltinLF" @declareBuiltin ucall @@ -777,7 +630,7 @@ staticityOfBinResult: [ arg2 @processor getMplSchema.irTypeId @irarg.@irTypeId set irarg @args.pushBack - result args String tag VarReal32 = ["@llvm.pow.f32" makeStringView] ["@llvm.pow.f64" makeStringView] if @processor @block createCallIR retName:; + result args String tag VarReal32 = ["@llvm.pow.f32" makeStringView] ["@llvm.pow.f64" makeStringView] if FALSE dynamic @processor @block createCallIR retName:; @retName result @processor @block createStoreFromRegister @@ -1045,13 +898,12 @@ staticityOfBinResult: [ [signature: parseSignature;] [ name: ("null." processor.blocks.getSize) assembleString; - newBlock: signature name makeStringView TRUE dynamic @processor @block processImportFunction Block addressToReference; + newBlock: signature name makeStringView TRUE dynamic @processor @block processImportFunction @processor.@blocks.at.get; ] [ gnr: newBlock.varNameInfo @processor @block getName; cnr: @gnr 0 dynamic @processor @block processor.positions.last.file captureName; refToVar: cnr.refToVar copy; - refToVar @block push ] ) sequence @@ -1153,7 +1005,7 @@ staticityOfBinResult: [ ] [signature: parseSignature;] [ - astNode: VarCode varBody.data.get.index processor.multiParserResult.memory.at; + astNode: VarCode varBody.data.get.index processor.multiParserResult.memory.at.get; index: signature astNode VarCode varBody.data.get.file VarString varName.data.get makeStringView FALSE dynamic @processor @block processExportFunction; ] ) sequence @@ -1177,20 +1029,33 @@ staticityOfBinResult: [ ] when var: @refToVar getVar; FALSE @var.@temporary set + ] [ + refToVar @processor @block makeVarTreeDirty ] [ name: VarString varName.data.get; + nameInfo: name makeStringView @processor findNameInfo; + fr: nameInfo processor.exportVarIds.find; + fr.success ["export variable name used now" @processor block compilerError] when + ] [ oldIrNameId: var.irNameId copy; + nameInfo refToVar @processor.@exportVarIds.insert oldInstructionIndex: var.globalDeclarationInstructionIndex copy; ("@" name) assembleString @processor makeStringId @var.@irNameId set - instruction: var.globalDeclarationInstructionIndex @processor.@prolog.at; - @refToVar @processor @block createVarExportIR drop - @processor.@prolog.last move @instruction set - @processor.@prolog.popBack - TRUE @refToVar.setMutable - oldIrNameId var.irNameId refToVar @processor getMplSchema.irTypeId @processor createGlobalAliasIR - oldInstructionIndex @var.@globalDeclarationInstructionIndex set - nameInfo: name makeStringView @processor findNameInfo; + processor.options.partial [ + [block.file isNil ~] "ExportVariable in nil file!" assert + block.file.usedInParams ~ + ] && [ + @refToVar @processor @block createVarImportIR drop + ] [ + @refToVar @processor @block createVarExportIR drop + instruction: var.globalDeclarationInstructionIndex @processor.@prolog.at; + @processor.@prolog.last move @instruction set + @processor.@prolog.popBack + TRUE @refToVar.setMutable + var.irNameId oldIrNameId refToVar @processor getMplSchema.irTypeId @processor createGlobalAliasIR + oldInstructionIndex @var.@globalDeclarationInstructionIndex set + ] if { addNameCase: NameCaseLocal; @@ -1279,44 +1144,38 @@ staticityOfBinResult: [ ] "mplBuiltinFloor" @declareBuiltin ucall [ - varPrev: 0n64 makeValuePair VarNatX @processor @block createVariable; - varNext: 0n64 makeValuePair VarNatX @processor @block createVariable; - varName: String @processor @block makeVarString TRUE dynamic @processor @block createRefNoOp; - varLine: 0i64 makeValuePair VarInt32 @processor @block createVariable; - varColumn: 0i64 makeValuePair VarInt32 @processor @block createVariable; - - @varPrev @processor @block makeVarDirty - @varNext @processor @block makeVarDirty - @varName @processor @block makeVarDirty - @varLine @processor @block makeVarDirty - @varColumn @processor @block makeVarDirty - - struct: Struct; - 5 @struct.@fields.resize + processor.varForCallTrace.assigned ~ [ + varPrev: 0n64 makeValuePair VarNatX @processor @block createVariable; + varNext: 0n64 makeValuePair VarNatX @processor @block createVariable; + varName: String @processor @block makeVarString TRUE dynamic @processor @block createRefNoOp; + varLine: 0i64 makeValuePair VarInt32 @processor @block createVariable; + varColumn: 0i64 makeValuePair VarInt32 @processor @block createVariable; - varPrev 0 @struct.@fields.at.@refToVar set - "prev" makeStringView @processor findNameInfo 0 @struct.@fields.at.@nameInfo set + struct: Struct; + 5 @struct.@fields.resize - varNext 1 @struct.@fields.at.@refToVar set - "next" makeStringView @processor findNameInfo 1 @struct.@fields.at.@nameInfo set + varPrev 0 @struct.@fields.at.@refToVar set + "prev" makeStringView @processor findNameInfo 0 @struct.@fields.at.@nameInfo set - varName 2 @struct.@fields.at.@refToVar set - "name" makeStringView @processor findNameInfo 2 @struct.@fields.at.@nameInfo set + varNext 1 @struct.@fields.at.@refToVar set + "next" makeStringView @processor findNameInfo 1 @struct.@fields.at.@nameInfo set - varLine 3 @struct.@fields.at.@refToVar set - "line" makeStringView @processor findNameInfo 3 @struct.@fields.at.@nameInfo set + varName 2 @struct.@fields.at.@refToVar set + "name" makeStringView @processor findNameInfo 2 @struct.@fields.at.@nameInfo set - varColumn 4 @struct.@fields.at.@refToVar set - "column" makeStringView @processor findNameInfo 4 @struct.@fields.at.@nameInfo set + varLine 3 @struct.@fields.at.@refToVar set + "line" makeStringView @processor findNameInfo 3 @struct.@fields.at.@nameInfo set - first: @struct move owner VarStruct @processor @block createVariable; - last: first @processor @block copyVar; + varColumn 4 @struct.@fields.at.@refToVar set + "column" makeStringView @processor findNameInfo 4 @struct.@fields.at.@nameInfo set - firstRef: @first FALSE dynamic @processor @block createRefNoOp; - lastRef: @last FALSE dynamic @processor @block createRefNoOp; + @struct move owner VarStruct @processor @block createVariable @processor.@varForCallTrace set + Dynamic @processor.@varForCallTrace getVar.@storageStaticity set + @processor.@varForCallTrace @processor @block makeVarTreeDirty + ] when - @firstRef @processor @block makeVarDirty - @lastRef @processor @block makeVarDirty + firstRef: @processor.@varForCallTrace FALSE dynamic @processor @block createRefNoOp; + lastRef: @processor.@varForCallTrace FALSE dynamic @processor @block createRefNoOp; resultStruct: Struct; 2 @resultStruct.@fields.resize @@ -1328,8 +1187,10 @@ staticityOfBinResult: [ "last" makeStringView @processor findNameInfo 1 @resultStruct.@fields.at.@nameInfo set result: @resultStruct move owner VarStruct @processor @block createVariable @processor @block createAllocIR; - first @processor getIrType result @processor getIrType result @processor @block createGetCallTrace + @processor.@varForCallTrace @processor getIrType result @processor getIrType result @processor @block createGetCallTrace result @block push + + TRUE @block.!hasCallTrace ] "mplBuiltinGetCallTrace" @declareBuiltin ucall [ @@ -1384,9 +1245,9 @@ staticityOfBinResult: [ condition @processor @block makeVarRealCaptured condition - VarCode varThen.data.get.index processor.multiParserResult.memory.at + VarCode varThen.data.get.index processor.multiParserResult.memory.at.get VarCode varThen.data.get.file - VarCode varElse.data.get.index processor.multiParserResult.memory.at + VarCode varElse.data.get.index processor.multiParserResult.memory.at.get VarCode varElse.data.get.file @processor @block processIf ] if @@ -1405,7 +1266,7 @@ staticityOfBinResult: [ varName.data.getTag VarString = ~ ["function name must be static string" @processor block compilerError] when ] [signature: parseSignature;] - [newBlock: signature VarString varName.data.get makeStringView FALSE dynamic @processor @block processImportFunction Block addressToReference;] + [newBlockId: signature VarString varName.data.get makeStringView FALSE dynamic @processor @block processImportFunction;] ) sequence ] "mplBuiltinImportFunction" @declareBuiltin ucall @@ -1533,7 +1394,7 @@ staticityOfBinResult: [ varBody: body getVar; varBody.data.getTag VarCode = ~ ["body must be [CODE]" @processor block compilerError] when ] [ - astNode: VarCode varBody.data.get.index processor.multiParserResult.memory.at; + astNode: VarCode varBody.data.get.index processor.multiParserResult.memory.at.get; astNode @processor @block VarCode varBody.data.get.file processLoop ] ) sequence @@ -1853,7 +1714,7 @@ staticityOfBinResult: [ processor compilable [ codeIndex: VarCode varCode.data.get.index copy; codeFile: VarCode varCode.data.get.file; - astNode: codeIndex processor.multiParserResult.memory.at; + astNode: codeIndex processor.multiParserResult.memory.at.get; [astNode.data.getTag AstNodeType.Code =] "Not a code!" assert block.countOfUCall 1 + @block.@countOfUCall set block.countOfUCall 65535 > ["ucall limit exceeded" @processor block compilerError] when @@ -1881,7 +1742,7 @@ staticityOfBinResult: [ condition staticityOfVar Weak > [ value: VarCond varCond.data.get.end copy; code: value [VarCode varThen.data.get] [VarCode varElse.data.get] if; - astNode: code.index processor.multiParserResult.memory.at; + astNode: code.index processor.multiParserResult.memory.at.get; [astNode.data.getTag AstNodeType.Code =] "Not a code!" assert block.countOfUCall 1 + @block.@countOfUCall set block.countOfUCall 65535 > ["ucall limit exceeded" @processor block compilerError] when @@ -1894,6 +1755,74 @@ staticityOfBinResult: [ ] when ] "mplBuiltinUif" @declareBuiltin ucall +FindInPathResult: { + NO_FILE: [0]; + FILE_WITH_ERROR: [1]; + UNCOMPILED_FILE: [2]; + COMPILED_FILE: [3]; +}; + +tryFindInPath: [ + moduleName: path: processor: block: ;;;; + + fullFileName: path "" = [(moduleName ".mpl") assembleString] [(path "/" moduleName ".mpl") assembleString] if; + + result: { + success: FindInPathResult.NO_FILE; + fullFileName: String; + block: Block Cref; + }; + + checkLoadedFile: [ + fullFileName:; + + fr: fullFileName processor.fileNameIds.find; + fr.success [ + fr: fullFileName processor.modules.find; + fr.success [fr.value 0 < ~] && [ + fileBlock: fr.value processor.blocks.at.get; + fileBlock @result.!block + @fullFileName move @result.@fullFileName set + FindInPathResult.COMPILED_FILE @result.!success + ] [ + @fullFileName move @result.@fullFileName set + FindInPathResult.UNCOMPILED_FILE @result.!success + ] if + + TRUE + ] && + ]; + + @fullFileName checkLoadedFile ~ [ + loadStringResult: fullFileName loadString; + loadStringResult.success [ + errorInfo: fullFileName makeStringView loadStringResult.data makeStringView @processor.@multiParserResult @processor.@nameManager addToProcess; + errorInfo "" = [ + fileId: FALSE fullFileName makeStringView @processor addFileNameToProcessor; + fullFileName @processor.@options.@fileNames.pushBack + fileId @processor.@unfinishedFiles.pushBack + @fullFileName move @result.@fullFileName set + FindInPathResult.UNCOMPILED_FILE @result.!success + ] [ + errorInfo @processor @block compilerError + @fullFileName move @result.@fullFileName set + FindInPathResult.FILE_WITH_ERROR @result.!success + ] if + ] [ + findInCmd: moduleName processor.cmdFileNameIds.find; + findInCmd.success [ + findInCmd.value copy checkLoadedFile ~ [ + FindInPathResult.NO_FILE @result.!success + ] when + ] [ + FindInPathResult.NO_FILE @result.!success + ] if + ] if + ] when + + result +]; + [ ( [processor compilable] @@ -1904,22 +1833,54 @@ staticityOfBinResult: [ varName.data.getTag VarString = ~ ["path must be static string" @processor block compilerError] when ] [ string: VarString varName.data.get; - filename: string stripExtension; - filename "" = ["invalid filename" @processor block compilerError] when + fileName: string stripExtension; + fileName "" = ["invalid fileName" @processor block compilerError] when ] [ - name: string extractExtension; - useAll: name "" =; - - fr: filename processor.fileNameIds.find; - fr.success [ - fr: filename processor.modules.find; - + variableName: string extractExtension; + useAll: variableName "" =; + currentFile: processor.positions.last.file; + currentFilePath: currentFile.name stripFilename; + + findResult: fileName currentFilePath @processor @block tryFindInPath; + findResult.success FindInPathResult.NO_FILE = [ + processor.options.includePaths [ + currentPath:; + findResult.success FindInPathResult.NO_FILE = [ + fileName currentPath @processor @block tryFindInPath !findResult + ] when + ] each + ] when - fr.success [fr.value 0 < ~] && [ - fileBlock: fr.value processor.blocks.at.get; + findResult.success ( + FindInPathResult.NO_FILE [ + oldSuccess: processor compilable; + message: ("module not found: " fileName) assembleString; + message @processor block compilerError + oldSuccess [ + @processor.@result.@errorInfo move @processor.@result.@globalErrorInfo.pushBack + -1 @processor.@result clearProcessorResult + ] when + ] + FindInPathResult.FILE_WITH_ERROR [ + #we has error yet + ] + FindInPathResult.UNCOMPILED_FILE [ + TRUE dynamic @processor.@result.@findModuleFail set + @findResult.@fullFileName move @processor.@result.@errorInfo.@missedModule set + ("module not compiled yet: " fileName) assembleString @processor block compilerError + ] + FindInPathResult.COMPILED_FILE [ + fileBlock: findResult.block; file: fileBlock.file; - nameInfo: name @processor findNameInfo; + block.exportDepth 0 = [ + topNode: @block.topNode; + fileBlock.globalPriority topNode.globalPriority < ~ [ + fileBlock.globalPriority 1 + @topNode.!globalPriority + ] when + ] when + + nameInfo: variableName @processor findNameInfo; labelCount: 0; findLabelNames: [ @@ -1950,6 +1911,8 @@ staticityOfBinResult: [ nameInfo: current.nameInfo copy; overload: block.nextLabelIsOverload; } @processor @block addNameInfo + + current.nameInfo @processor @block checkPossibleUnstables ] times @addNameData.clear @@ -1970,7 +1933,7 @@ staticityOfBinResult: [ fr.value.index copy fr.value.depth copy ] [ result: -1 file nameInfo @processor.@nameManager.findItem; - nameInfo {index: result copy; depth: 0;} @indexes.insert + nameInfo {index: result copy; depth: 0;} @indexes.insert result 0 ] if ]; @@ -1992,12 +1955,11 @@ staticityOfBinResult: [ } findLabelNames ] if - FALSE @block.!nextLabelIsOverload labelCount 0 = [ oldSuccess: processor compilable; - message: ("no names match \"" name "\"") assembleString; + message: ("no names match \"" variableName "\"") assembleString; useAll ~ [ @message nameInfo @processor catPossibleModulesList @@ -2009,21 +1971,10 @@ staticityOfBinResult: [ -1 @processor.@result clearProcessorResult ] when ] when - ] [ - TRUE dynamic @processor.@result.@findModuleFail set - filename toString @processor.@result.@errorInfo.@missedModule set - ("module not found: " filename) assembleString @processor block compilerError - ] if - ] [ - #if module name is totally wrong - oldSuccess: processor compilable; - message: ("module not found: " filename) assembleString; - message @processor block compilerError - oldSuccess [ - @processor.@result.@errorInfo move @processor.@result.@globalErrorInfo.pushBack - -1 @processor.@result clearProcessorResult - ] when - ] if + ] + [ + ] + ) case ] ) sequence ] "mplBuiltinUse" @declareBuiltin ucall diff --git a/builtins.mpl b/builtins.mpl index 68e84c2..382cc22 100644 --- a/builtins.mpl +++ b/builtins.mpl @@ -1,24 +1,16 @@ -"String.makeStringView" use -"String.print" use -"String.toString" use +"String" use "control" use -"conventions.cdecl" use +"conventions" use -"Block.Block" use -"Block.NameCaseBuiltin" use -"File.File" use -"Var.VarBuiltin" use -"Var.Virtual" use -"Var.getVar" use +"Block" use +"MplFile" use +"Var" use "builtinImpl" use -"codeNode.addNameInfo" use -"codeNode.createVariable" use -"codeNode.makeStaticity" use -"declarations.getMplType" use -"defaultImpl.FailProcForProcessor" use -"processor.Processor" use -"processor.ProcessorResult" use -"variable.NameInfo" use +"codeNode" use +"declarations" use +"defaultImpl" use +"processor" use +"variable" use builtins: ( {name: "!" ; impl: @mplBuiltinExclamation ;} @@ -34,7 +26,6 @@ builtins: ( {name: "COMPILER_VERSION" ; impl: @mplBuiltinCompilerVersion ;} {name: "DEBUG" ; impl: @mplBuiltinDebug ;} {name: "FALSE" ; impl: @mplBuiltinFalse ;} - {name: "HAS_LOGS" ; impl: @mplBuiltinHasLogs ;} {name: "LF" ; impl: @mplBuiltinLF ;} {name: "TRUE" ; impl: @mplBuiltinTrue ;} {name: "^" ; impl: @mplBuiltinPow ;} @@ -117,10 +108,10 @@ addBuiltin: [ bvar: @id VarBuiltin @processor @block createVariable Virtual @processor @block makeStaticity; { - addNameCase: NameCaseBuiltin; + addNameCase: NameCaseLocal; refToVar: bvar copy; nameInfo: nameId copy; - file: File Cref; + file: 0 processor.files.at.get; } @processor @block addNameInfo ]; diff --git a/codeNode.mpl b/codeNode.mpl index 51bc800..f933668 100644 --- a/codeNode.mpl +++ b/codeNode.mpl @@ -1,224 +1,22 @@ -"Array.Array" use -"HashTable.hash" use -"Owner.owner" use -"String.String" use -"String.StringView" use -"String.addLog" use -"String.assembleString" use -"String.hash" use -"String.makeStringView" use -"String.print" use -"String.splitString" use -"String.toString" use +"Array" use +"HashTable" use +"Owner" use +"String" use "control" use -"conventions.cdecl" use - -"Block.ArgCopy" use -"Block.ArgDerefCopy" use -"Block.ArgGlobal" use -"Block.ArgMeta" use -"Block.ArgRef" use -"Block.ArgRefDeref" use -"Block.ArgReturn" use -"Block.ArgReturnDeref" use -"Block.ArgVirtual" use -"Block.Argument" use -"Block.Block" use -"Block.BlockSchema" use -"Block.CFunctionSignature" use -"Block.Capture" use -"Block.CompilerPositionInfo" use -"Block.FieldCapture" use -"Block.MatchingInfo" use -"Block.MemberCaseToObjectCaptureCase" use -"Block.MemberCaseToObjectCase" use -"Block.NameCaseBuiltin" use -"Block.NameCaseCapture" use -"Block.NameCaseClosureMember" use -"Block.NameCaseClosureObject" use -"Block.NameCaseClosureObjectCapture" use -"Block.NameCaseFromModule" use -"Block.NameCaseInvalid" use -"Block.NameCaseLocal" use -"Block.NameCaseSelfMember" use -"Block.NameCaseSelfObject" use -"Block.NameCaseSelfObjectCapture" use -"Block.NameWithOverload" use -"Block.NameWithOverloadAndRefToVar" use -"Block.NodeCaseCode" use -"Block.NodeCaseCodeRefDeclaration" use -"Block.NodeCaseDeclaration" use -"Block.NodeCaseDtor" use -"Block.NodeCaseEmpty" use -"Block.NodeCaseExport" use -"Block.NodeCaseLambda" use -"Block.NodeCaseList" use -"Block.NodeCaseObject" use -"Block.NodeRecursionStateFail" use -"Block.NodeRecursionStateNo" use -"Block.NodeRecursionStateOld" use -"Block.NodeStateCompiled" use -"Block.NodeStateFailed" use -"Block.NodeStateHasOutput" use -"Block.NodeStateNew" use -"Block.NodeStateNoOutput" use -"Block.ShadowEvent" use -"File.File" use -"Var.CodeNodeInfo" use -"Var.Dirty" use -"Var.Dynamic" use -"Var.Field" use -"Var.RefToVar" use -"Var.ShadowReasonCapture" use -"Var.ShadowReasonField" use -"Var.ShadowReasonFieldCapture" use -"Var.ShadowReasonInput" use -"Var.ShadowReasonPointee" use -"Var.Static" use -"Var.Struct" use -"Var.VarBuiltin" use -"Var.VarCode" use -"Var.VarCond" use -"Var.VarEnd" use -"Var.VarImport" use -"Var.VarInt16" use -"Var.VarInt32" use -"Var.VarInt64" use -"Var.VarInt8" use -"Var.VarIntX" use -"Var.VarInvalid" use -"Var.VarInvalid" use -"Var.VarNat16" use -"Var.VarNat32" use -"Var.VarNat64" use -"Var.VarNat8" use -"Var.VarNatX" use -"Var.VarReal32" use -"Var.VarReal64" use -"Var.VarRef" use -"Var.VarString" use -"Var.VarStruct" use -"Var.Variable" use -"Var.Virtual" use -"Var.Weak" use -"Var.fullUntemporize" use -"Var.getPlainConstantIR" use -"Var.getVar" use -"Var.isAutoStruct" use -"Var.isNonrecursiveType" use -"Var.isPlain" use -"Var.isTinyArg" use -"Var.isUnallocable" use -"Var.isVirtual" use -"Var.isVirtualType" use -"Var.makeRefBranch" use -"Var.makeStringId" use -"Var.makeValuePair" use -"Var.markAsUnableToDie" use -"Var.staticityOfVar" use -"Var.varIsMoved" use -"Var.variablesAreSame" use -"astNodeType.AstNode" use -"astNodeType.AstNodeType" use -"astNodeType.IndexArray" use -"debugWriter.addDebugLocation" use -"debugWriter.addDebugReserve" use -"debugWriter.addFuncDebugInfo" use -"debugWriter.addGlobalVariableDebugInfo" use -"debugWriter.addVariableMetadata" use -"debugWriter.moveLastDebugString" use -"declarations.CopyVarFlags" use -"declarations.TryImplicitLambdaCastResult" use -"declarations.callBuiltin" use -"declarations.compareOnePair" use -"declarations.compilerError" use -"declarations.copyOneVar" use -"declarations.copyOneVarFromType" use -"declarations.copyOneVarWith" use -"declarations.copyVar" use -"declarations.copyVarFromChild" use -"declarations.copyVarFromType" use -"declarations.copyVarToNew" use -"declarations.createDtorForGlobalVar" use -"declarations.createRefWith" use -"declarations.defaultPrintStack" use -"declarations.defaultPrintStackTrace" use -"declarations.getMplType" use -"declarations.makeShadows" use -"declarations.makeShadowsDynamic" use -"declarations.makeVarString" use -"declarations.makeVariableType" use -"declarations.popWith" use -"declarations.processCall" use -"declarations.processCallByIndexArray" use -"declarations.processExportFunction" use -"declarations.processFuncPtr" use -"declarations.processPre" use -"defaultImpl.FailProcForProcessor" use -"defaultImpl.addEmptyCapture" use -"defaultImpl.addShadowEvent" use -"defaultImpl.addStackUnderflowInfo" use -"defaultImpl.compilable" use -"defaultImpl.createRef" use -"defaultImpl.defaultFailProc" use -"defaultImpl.defaultMakeConstWith" use -"defaultImpl.defaultRef" use -"defaultImpl.defaultSet" use -"defaultImpl.findNameInfo" use -"defaultImpl.getStackDepth" use -"defaultImpl.getStackEntry" use -"defaultImpl.getStackEntryUnchecked" use -"defaultImpl.makeVarDerefCaptured" use -"defaultImpl.makeVarPtrCaptured" use -"defaultImpl.makeVarRealCaptured" use -"defaultImpl.nodeHasCode" use -"defaultImpl.pop" use -"irWriter.addStrToProlog" use -"irWriter.appendInstruction" use -"irWriter.createAllocIR" use -"irWriter.createAllocIRByReg" use -"irWriter.createComment" use -"irWriter.createCopyToNew" use -"irWriter.createDerefTo" use -"irWriter.createGEPInsteadOfAlloc" use -"irWriter.createJump" use -"irWriter.createLabel" use -"irWriter.createMemset" use -"irWriter.createPlainIR" use -"irWriter.createRefOperation" use -"irWriter.createRetValue" use -"irWriter.createStaticGEP" use -"irWriter.createStoreConstant" use -"irWriter.createStoreFromRegister" use -"irWriter.createStoreFromRegisterToRegister" use -"irWriter.createStringIR" use -"irWriter.generateRegisterIRName" use -"irWriter.getIrName" use -"irWriter.getIrType" use -"irWriter.getMplSchema" use -"irWriter.getNameById" use -"irWriter.sortInstructions" use -"pathUtils.extractFilename" use -"pathUtils.nameWithoutBadSymbols" use -"pathUtils.stripExtension" use -"processor.MatchingNode" use -"processor.NameInfoCoord" use -"processor.NameInfoEntry" use -"processor.Processor" use -"processor.ProcessorResult" use -"processor.RefToVarTable" use -"staticCall.staticCall" use -"variable.NameInfo" use -"variable.Overload" use -"variable.checkValue" use -"variable.findField" use -"variable.findFieldWithOverloadDepth" use -"variable.isGlobal" use -"variable.makeVariableIRName" use -"variable.maxStaticity" use -"variable.noMatterToCopy" use -"variable.unglobalize" use -"variable.untemporize" use +"conventions" use + +"Block" use +"MplFile" use +"Var" use +"astNodeType" use +"debugWriter" use +"declarations" use +"defaultImpl" use +"irWriter" use +"pathUtils" use +"processor" use +"staticCall" use +"variable" use addNameInfo: [ processor: block: ;; @@ -234,6 +32,8 @@ addNameInfo: [ refToVar: params.refToVar copy dynamic; nameInfo: params.nameInfo copy dynamic; + [params.refToVar.assigned] "Add name must have corrent refToVar!" assert + [ nameInfo 0 < ~ [ addInfo: TRUE; @@ -281,10 +81,13 @@ addNameInfo: [ file @nameInfoEntry.!file ] if + isLocal: startPoint processor.blocks.at.get.parent 0 = ~; + refToVar @nameInfoEntry.@refToVar set addNameCase @nameInfoEntry.@nameCase set startPoint @nameInfoEntry.@startPoint set mplFieldIndex @nameInfoEntry.@mplFieldIndex set + isLocal @nameInfoEntry.@isLocal set @nameInfoEntry nameInfo @processor.@nameManager.addItem ] when @@ -426,15 +229,6 @@ createRefVariable: [ @result ]; -getTopNode: [ - topNode:; - [topNode.parent 0 = ~] [ - topNode.parent @processor.@blocks.at.get !topNode - ] while - - @topNode -]; - getNilVar: [ refToVar: processor: block: ;;; @@ -1132,6 +926,23 @@ makeVarTreeDynamicWith: [ makeVarTreeDynamic: [processor: block: ;; FALSE dynamic @processor @block makeVarTreeDynamicWith]; makeVarTreeDynamicStoraged: [processor: block: ;; TRUE dynamic @processor @block makeVarTreeDynamicWith]; +checkPossibleUnstables: [ + nameInfo: processor: block: ;;; + + block.parent 0 = [ + nameInfo processor.possibleUnstables.getSize < [ + current: nameInfo @processor.@possibleUnstables.at; + current [ + blockId:; + unstableBlock: blockId @processor.@blocks.at.get; + TRUE @unstableBlock.@changedStableName set + ] each + + @current.clear + ] when + ] when +]; + createNamedVariable: [ nameInfo: refToVar: processor: block: ;;;; @@ -1186,14 +997,35 @@ createNamedVariable: [ overload: block.nextLabelIsOverload copy; } @processor @block addNameInfo + nameInfo @processor @block checkPossibleUnstables + + block.parent 0 = [ + fr: nameInfo @block.@globalVariableNames.find; + fr.success [ + newRefToVar @fr.@value.pushBack + ] [ + newEntry: RefToVar Array; + newRefToVar @newEntry.pushBack + nameInfo @newEntry move @block.@globalVariableNames.insert + ] if + ] when + FALSE @block.!nextLabelIsOverload processor compilable [processor.options.debug copy] && [newRefToVar isVirtual ~] && [ newRefToVar isGlobal [ - d: nameInfo newRefToVar @processor block addGlobalVariableDebugInfo; - globalInstruction: newRefToVar getVar.globalDeclarationInstructionIndex @processor.@prolog.at; - ", !dbg !" @globalInstruction.cat - d @globalInstruction.cat + processor.options.partial copy [ + varBlock: block; + [varBlock.file isNil ~] "Topnode in nil file!" assert + varBlock.file.usedInParams ~ + ] && [ + #do not create dbg info + ] [ + d: nameInfo newRefToVar @processor block addGlobalVariableDebugInfo; + globalInstruction: newRefToVar getVar.globalDeclarationInstructionIndex @processor.@prolog.at; + ", !dbg !" @globalInstruction.cat + d @globalInstruction.cat + ] if ] [ nameInfo newRefToVar @processor @block addVariableMetadata ] if @@ -1217,7 +1049,7 @@ processLabelNode: [ processCodeNode: [ indexOfAstNode: ; - astNode: indexOfAstNode processor.multiParserResult.memory.at; #we have info from parser anyway + astNode: indexOfAstNode processor.multiParserResult.memory.at.get; #we have info from parser anyway codeInfo: CodeNodeInfo; processor.positions.last.file @codeInfo.@file.set @@ -1252,7 +1084,7 @@ processListNode: [ message:; overload failProc: processor block FailProcForProcessor; - processor.result.findModuleFail ~ [processor.depthOfPre 0 =] && [HAS_LOGS] && [ + processor.result.findModuleFail ~ [processor.depthOfPre 0 =] && [hasLogs] && [ ("COMPILATION ERROR") addLog (message) addLog @processor block defaultPrintStackTrace @@ -1363,14 +1195,14 @@ getNameAs: [ copy nameInfo:; unknownName: [ - forMatching [ - processor.varForFails @result.@refToVar set - ] [ + processor.varForFails @result.@refToVar set + + forMatching ~ [ message: ("unknown name: " nameInfo processor.nameManager.getText) assembleString; @message nameInfo @processor catPossibleModulesList message @processor block compilerError - ] if + ] when ]; result: { @@ -1381,7 +1213,6 @@ getNameAs: [ object: RefToVar; mplFieldIndex: -1 dynamic; nameCase: NameCaseInvalid; - isOverloaded: FALSE dynamic; }; overloadIndex 0 < [overloadIndex file nameInfo processor.nameManager.findItem !overloadIndex] when @@ -1393,7 +1224,6 @@ getNameAs: [ overloadIndex @result.@overloadIndex set nameInfoEntry.nameCase @result.@nameCase set nameInfoEntry.startPoint @result.@startPoint set - nameInfoEntry.file isNil ~ @result.@isOverloaded set nameCase: matchingCapture.captureCase NameCaseInvalid = [result.nameCase copy] [matchingCapture.captureCase copy] if; @@ -1460,74 +1290,68 @@ getNameForMatchingWithOverloadIndex: [ TRUE dynamic overloadIndex @processor @block file getNameAs ]; -captureName: [ - getNameResult: overloadDepth: processor: block: file: ;;;;; +nameResultIsStable: [ + file: getNameResult: processor: ;;; - result: { - refToVar: RefToVar; - object: RefToVar; - }; + getNameResult.nameCase NameCaseCapture > ~ + [getNameResult.nameInfo processor.nameManager.hasOverload ~] && + [getNameResult.nameInfo processor.nameManager.hasLocalDefinition ~] && + [getNameResult.nameCase NameCaseInvalid = ~] && + [getNameResult.startPoint processor.blocks.at.get.parent 0 =] && + [getNameResult.refToVar isVirtual] && +]; - #file.rootBlock.state NodeStateCompiled = [getNameResult.nameInfoNotOverloaded copy] && [getNameResult.refToVar isGlobal] && [FALSE] && [ +addStableName: [ + nameInfo: processor: block: ;;; - #] [ - processor compilable [getNameResult.nameCase NameCaseInvalid = ~] && [ - addBlockIdTo: [ - whereNames: nameInfo: nameOverloadDepth: captureCase: mplSchemaId: ;;;;; + nameInfo processor.captureTable.stableNames.getSize < ~ [nameInfo 1 + @processor.@captureTable.@stableNames.resize] when + current: nameInfo @processor.@captureTable.@stableNames.at; + current.getSize 0 = [current.last block.id = ~] || [ + block.id @current.pushBack + nameInfo @block.@stableNames.pushBack - addToLine: [ - line:; - index: line.size 1 -; - result: TRUE dynamic; + newEvent: ShadowEvent; + ShadowReasonStableName @newEvent.setTag + branch: ShadowReasonStableName @newEvent.get; + nameInfo @branch.@nameInfo set + @newEvent @block addShadowEvent + ] when - [ - index 0 < [index line.at.block block is ~] || [ - FALSE #no such item - ] [ - index line.at.file file is [ - FALSE !result #we have such item - FALSE - ] [ - index 1 - !index - TRUE #find deeper - ] if - ] if - ] loop + nameInfo @processor @block addToPossibleUnstables +]; - result [ - NameInfoCoord @line.pushBack - block @line.last.@block.set - file @line.last.@file.set - ] when +addToPossibleUnstables: [ + nameInfo: processor: block: ;;; - result - ]; + nameInfo processor.possibleUnstables.getSize < ~ [nameInfo 1 + @processor.@possibleUnstables.resize] when + block.id nameInfo @processor.@possibleUnstables.at.pushBack +]; - addBlockToObjectCase: [ - nameOverloadDepth: mplSchemaId: table: ;;; +captureFileToBlock: [ + fileId: block: ;; + [fileId block.capturedFiles.getSize < ~] [ + FALSE @block.@capturedFiles.pushBack + ] while - 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 - ]; + TRUE fileId @block.@capturedFiles.at set +]; - nameInfo processor.selfNameInfo = [ - nameOverloadDepth mplSchemaId @whereNames.@selfNames addBlockToObjectCase - ] [ - nameInfo processor.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 - ]; +captureName: [ + getNameResult: overloadDepth: processor: block: file: ;;;;; + + result: { + refToVar: RefToVar; + object: RefToVar; + }; + + checkStable: file getNameResult processor nameResultIsStable; + file.fileId @block captureFileToBlock + checkStable [ + getNameResult.nameInfo @processor @block addStableName + getNameResult.refToVar @result.@refToVar set + ] [ + processor compilable [getNameResult.nameCase NameCaseInvalid = ~] && [ captureRefToVar: [ copy captureCase:; refToVar:; @@ -1539,7 +1363,7 @@ captureName: [ newVar: FALSE; }; - getNameResult.startPoint block.id = ~ [@processor.@captureTable nameInfo overloadDepth captureCase refToVar getVar.mplSchemaId addBlockIdTo] && [ + getNameResult.startPoint block.id = ~ [@processor.@captureTable nameInfo overloadDepth captureCase refToVar getVar.mplSchemaId file @processor @block addBlockIdTo] && [ refToVar @result.@refToVar set shadow: RefToVar; @@ -1571,19 +1395,21 @@ captureName: [ [FALSE] "Self cannot have overloads!" assert ] when - newEvent: ShadowEvent; - ShadowReasonCapture @newEvent.setTag - branch: ShadowReasonCapture @newEvent.get; - newCapture @branch set - shadow @branch.@refToVar set - - newCapture @block.@buildingMatchingInfo.@captures.pushBack - block.state NodeStateNew = [ - newCapture @block.@matchingInfo.@captures.pushBack - ] when + refToVar getVar.data.getTag VarString = ~ [ + newEvent: ShadowEvent; + ShadowReasonCapture @newEvent.setTag + branch: ShadowReasonCapture @newEvent.get; + newCapture @branch set + shadow @branch.@refToVar set - @block @shadow setTopologyIndex - @newEvent @block addShadowEvent + newCapture @block.@buildingMatchingInfo.@captures.pushBack + block.state NodeStateNew = [ + newCapture @block.@matchingInfo.@captures.pushBack + ] when + + @block @shadow setTopologyIndex + @newEvent @block addShadowEvent + ] when processor.options.debug [shadow isVirtual ~] && [shadow isGlobal ~] && [ fakePointer: shadow makeRefBranch FALSE @processor @block createRefVariable; @@ -1634,7 +1460,7 @@ captureName: [ } @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 addBlockIdTo] && [ + getNameResult.startPoint block.id = ~ [@processor.@captureTable getNameResult.nameInfo overloadDepth NameCaseCapture -1 file @processor @block addBlockIdTo] && [ { nameInfo: getNameResult.nameInfo copy; mplFieldIndex: getNameResult.mplFieldIndex copy; @@ -1678,7 +1504,7 @@ captureName: [ file getNameResult.nameInfo overloadDepth @processor @block addEmptyCapture processor.varForFails @result.@refToVar set ] if - #] if + ] if result ]; @@ -1984,51 +1810,25 @@ derefAndPush: [ @processor @block getPossiblePointee @block push ]; -setRef: [ - processor: block: ;; - refToVar:; # destination - compileOnce - - var: refToVar getVar; - var.data.getTag VarRef = [ - refToVar isVirtual [ - "can not write to virtual" @processor block compilerError - ] [ - pointee: VarRef var.data.get.refToVar; - pointee.mutable ~ [ - FALSE @processor @block defaultMakeConstWith #source - ] when - - processor compilable [ - src: @processor @block pop; - processor compilable [ - src pointee variablesAreSame [ - src @block push - @src makeVarPtrCaptured - TRUE @processor @block defaultRef #source - refToVar @block push - @processor @block defaultSet - ] [ - src @block push - refToVar @block push - @processor @block defaultSet - ] if +checkVarForGlobalsFromAnotherFile: [ + refToVar:; + processor.options.partial [ + refToVar isVirtual ~ [ + topNode: block.topNode; + [topNode isNil ~] "Topnode is nil!" assert + [topNode.file isNil ~] "Topnode in nil file!" assert + topNode.file.usedInParams ~ [ + var: refToVar getVar; + varBlock: var.host; + varBlock.file isNil ~ [ + varBlock.file.usedInParams ~ [ + TRUE @block.!empty + TRUE @block.!hasEmptyLambdas + ] when ] when ] when - ] if - ] [ - #rewrite value case! - src: @processor @block pop; - processor compilable [ - src getVar.temporary [ - src @block push - refToVar @block push - @processor @block defaultSet - ] [ - "rewrite value works only with temporary values" @processor block compilerError - ] if ] when - ] if + ] when ]; { @@ -2069,11 +1869,12 @@ setRef: [ var.storageStaticity @resultVar.@storageStaticity set global [ + TRUE @resultVar.@global set + reason ShadowReasonField = ~ [ var.irNameId @resultVar.@irNameId set + result checkVarForGlobalsFromAnotherFile ] when - - TRUE @resultVar.@global set ] [ @result @processor block unglobalize ] if @@ -2621,6 +2422,7 @@ addBlock: [ refToVar: refToVar copy; nameInfo: refToVar getVar.mplNameId copy; overload: TRUE; + file: 0 processor.files.at.get; } @processor @block addNameInfo ] if @@ -2653,7 +2455,7 @@ addBlock: [ csignature: declarationNode.csignature; implName: ("lambda." block.id "." block.lastLambdaName) assembleString; - astNode: VarCode refToSrc getVar.data.get.index processor.multiParserResult.memory.at; + astNode: VarCode refToSrc getVar.data.get.index processor.multiParserResult.memory.at.get; implIndex: csignature astNode VarCode refToSrc getVar.data.get.file implName makeStringView TRUE dynamic @processor @block processExportFunction; processor compilable [ @@ -2680,6 +2482,14 @@ 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 @@ -2943,7 +2753,7 @@ killStruct: [ overload failProc: processor block FailProcForProcessor; processor.options.verboseIR [ - ("filename: " processor.positions.last.file.name + ("fileName: " processor.positions.last.file.name ", line: " processor.positions.last.line ", column: " processor.positions.last.column ", token: " astNode.token) assembleString @block createComment ] when @@ -3141,6 +2951,15 @@ unregCodeNodeNames: [ ] each ]; + unregStableNames: [ + whereNames:; + [ + current: @whereNames.@stableNames.at; + [current.last block.id =] "Wrong block id while unreg object name!" assert + @current.popBack + ] each + ]; + registerWithoutOverload: [ addNameCase:; [ @@ -3161,6 +2980,7 @@ unregCodeNodeNames: [ @block.@captureNames @processor.@captureTable unregTable @block.@fieldCaptureNames @processor.@captureTable unregTable + @block.@stableNames @processor.@captureTable unregStableNames @block.@capturedVars [ curVar: getVar; @@ -3170,6 +2990,7 @@ unregCodeNodeNames: [ @block.@capturedVars.release @block.@captureNames.release @block.@fieldCaptureNames.release + @block.@stableNames.release ]; addMatchingNode: [ @@ -3243,6 +3064,41 @@ concreteMatchingNode: [ ] when ]; +createGlobalAliases: [ + processor: block: ;; + + @block.@globalVariableNames [ + pair:; + + nameInfo: pair.key; + pair.value.getSize [ + index: pair.value.getSize 1 - i -; + refToVar: i @pair.@value.at; + refToVar isVirtual ~ [ + var: @refToVar getVar; + oldIrNameId: var.irNameId copy; + ("@" block.file.name stripExtension nameWithoutBadSymbols "." nameInfo processor.nameManager.getText "." index) assembleString @processor makeStringId @var.@irNameId set + + [block.file isNil ~] "createGlobalAliases in nil file!" assert + processor.options.partial [ + [block.file isNil ~] "Nil file in createGlobalAliases!" assert + block.file.usedInParams ~ + ] && [ + refToVar @processor @block createVarImportIR drop + processor.options.debug [ + d: nameInfo refToVar @processor block addGlobalVariableDebugInfo; + globalInstruction: refToVar getVar.globalDeclarationInstructionIndex @processor.@prolog.at; + ", !dbg !" @globalInstruction.cat + d @globalInstruction.cat + ] when + ] [ + var.irNameId oldIrNameId refToVar @processor getMplSchema.irTypeId @processor createGlobalAliasIR + ] if + ] when + ] times + ] each +]; + deleteNode: [ processor:; copy nodeIndex:; @@ -3401,8 +3257,6 @@ checkRecursionOfCodeNode: [ @processor.@recursiveNodesStack.popBack ] [ block.state NodeStateHasOutput = [ - #curToNested: RefToVarTable; - #nestedToCur: RefToVarTable; comparingMessage: String; currentMatchingNodeIndex: block.id copy; currentMatchingNode: currentMatchingNodeIndex @processor.@blocks.at.get; @@ -3439,7 +3293,9 @@ checkRecursionOfCodeNode: [ buildingBranch: ShadowReasonInput currentBuildingMatchingEvent.get; branch.refToVar buildingBranch.refToVar compareTopologyIndex - [branch.refToVar buildingBranch.refToVar TRUE compareShadows] && ~ [FALSE !result] when + [branch.refToVar buildingBranch.refToVar TRUE compareShadows] && ~ [ + FALSE !result + ] when ] ShadowReasonCapture [ branch: ShadowReasonCapture currentMatchingEvent.get; @@ -3449,7 +3305,9 @@ checkRecursionOfCodeNode: [ [branch.captureCase buildingBranch.captureCase =] && [branch.nameInfo buildingBranch.nameInfo =] && [branch.nameOverloadDepth buildingBranch.nameOverloadDepth =] && - [branch.refToVar buildingBranch.refToVar TRUE compareShadows] && ~ [FALSE !result] when + [branch.refToVar buildingBranch.refToVar TRUE compareShadows] && ~ [ + FALSE !result + ] when ] ShadowReasonFieldCapture [ branch: ShadowReasonFieldCapture currentMatchingEvent.get; @@ -3458,7 +3316,9 @@ checkRecursionOfCodeNode: [ branch.captureCase buildingBranch.captureCase = [branch.nameInfo buildingBranch.nameInfo =] && [branch.object buildingBranch.object compareTopologyIndex] && - [branch.nameOverloadDepth buildingBranch.nameOverloadDepth =] && ~ [FALSE !result] when + [branch.nameOverloadDepth buildingBranch.nameOverloadDepth =] && ~ [ + FALSE !result + ] when ] ShadowReasonPointee [ branch: ShadowReasonPointee currentMatchingEvent.get; @@ -3466,7 +3326,9 @@ checkRecursionOfCodeNode: [ branch.pointer buildingBranch.pointer compareTopologyIndex [branch.pointee buildingBranch.pointee compareTopologyIndex] && - [branch.pointee buildingBranch.pointee TRUE compareShadows] && ~ [FALSE !result] when + [branch.pointee buildingBranch.pointee TRUE compareShadows] && ~ [ + FALSE !result + ] when ] ShadowReasonField [ branch: ShadowReasonField currentMatchingEvent.get; @@ -3475,7 +3337,9 @@ checkRecursionOfCodeNode: [ branch.object buildingBranch.object compareTopologyIndex [branch.mplFieldIndex buildingBranch.mplFieldIndex =] && [branch.field buildingBranch.field compareTopologyIndex] && - [branch.field buildingBranch.field FALSE compareShadows] && ~ [FALSE !result] when + [branch.field buildingBranch.field FALSE compareShadows] && ~ [ + FALSE !result + ] when ] [] ) case @@ -3769,7 +3633,7 @@ makeCompilerPosition: [ block.candidatesToDie [ refToVar:; refToVar isAutoStruct [ - refToVar compilerPositionInfo CFunctionSignature @processor createDtorForGlobalVar + refToVar compilerPositionInfo CFunctionSignature block.file @processor createDtorForGlobalVar ] when ] each ] [ @@ -3980,7 +3844,15 @@ makeCompilerPosition: [ (" ret void") @block appendInstruction ] if - callDestructors + block.parent 0 = ~ + [processor.options.partial ~] || + [ + [block.file isNil ~] "Block in nil file!" assert + block.file.usedInParams copy + ] || [ + callDestructors + ] when + processor.options.verboseIR ["called destructors" @block createComment] when i: 0 dynamic; @@ -4116,6 +3988,10 @@ makeCompilerPosition: [ block.buildingMatchingInfo.shadowEvents.size [ event: i block.buildingMatchingInfo.shadowEvents.at; + getFileName: [ + file:; file isNil ["NIL" makeStringView] [file.name makeStringView] if + ]; + ( ShadowReasonInput [ branch:; @@ -4123,7 +3999,11 @@ makeCompilerPosition: [ ] ShadowReasonCapture [ branch:; - ("shadow event [" i "] capture " branch.nameInfo processor.nameManager.getText "(" branch.nameOverloadDepth "); staticity=" branch.refToVar getVar.staticity.begin " as " branch.refToVar getVar.buildingTopologyIndex " type " branch.refToVar @processor @block getMplType) 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 + ] + ShadowReasonStableName [ + branch:; + ("shadow event [" i "] stableName " branch.nameInfo processor.nameManager.getText) assembleString @block createComment ] ShadowReasonFieldCapture [ branch:; @@ -4203,7 +4083,7 @@ makeCompilerPosition: [ declarationNode: @block; # we can call func as imported - topNode: @block getTopNode; + topNode: @block.topNode; currentFile: processor.positions.last.file; topNode.file currentFile is ~ [ #we calling func description from another file @@ -4234,15 +4114,15 @@ makeCompilerPosition: [ "null" toString @processor makeStringId @refToVar getVar.@irNameId set "null" toString @declarationNode.@irName set topNode.parent 0 = [ - (";declare func: " functionName) assembleString @processor addStrToProlog #fix global import var matching bug + ("; declare func: " functionName) assembleString @processor addStrToProlog #fix global import var matching bug processor.prolog.size 1 - @refToVar getVar.@globalDeclarationInstructionIndex set ] [ - (";declare func: " functionName) assembleString @topNode createComment #fix global import var matching bug + ("; declare func: " functionName) assembleString @topNode createComment #fix global import var matching bug topNode.program.size 1 - @refToVar getVar.@allocationInstructionIndex set ] if ] [ declarationNode.irName toString @processor makeStringId @refToVar getVar.@irNameId set - (";declare func: " functionName) assembleString @processor addStrToProlog #fix global import var matching bug + ("; declare func: " functionName) assembleString @processor addStrToProlog #fix global import var matching bug processor.prolog.size 1 - @refToVar getVar.@globalDeclarationInstructionIndex set ] if @@ -4310,7 +4190,7 @@ makeCompilerPosition: [ block.nodeCase NodeCaseCodeRefDeclaration = [block.nodeCase NodeCaseLambda =] || [ addFunctionVariableInfo ] [ - parentBlock: @block getTopNode; + parentBlock: @block.topNode; fr: @functionName @processor.@namedFunctions.find; fr.success [ prevNode: fr.value @processor.@blocks.at.get; @@ -4360,9 +4240,7 @@ makeCompilerPosition: [ signature @block.@argTypes set processor.options.debug [block.empty ~] && [isDeclaration ~] && [block.nodeCase NodeCaseEmpty = ~] && [ - fullFunctionName: (functionName "." block.beginPosition.file.name stripExtension nameWithoutBadSymbols "." - block.beginPosition.line "." - block.beginPosition.column) assembleString; + fullFunctionName: functionName; compilerPositionInfo fullFunctionName makeStringView block.irName makeStringView block.funcDbgIndex @processor addFuncDebugInfo block.funcDbgIndex @processor moveLastDebugString @@ -4412,6 +4290,8 @@ addIndexArrayToProcess: [ functionName:; compileOnce + [file isNil ~] "File is nil" assert + @processor addBlock codeNode: @processor.@blocks.last.get; block: @codeNode; @@ -4425,6 +4305,8 @@ addIndexArrayToProcess: [ processor.exportDepth @codeNode.@exportDepth set file @codeNode.@file.set compilerPositionInfo @codeNode.@beginPosition set + @processor @codeNode getTopNode @codeNode.@topNode.set + 0 @codeNode.@globalPriority set compilerPositionInfo @processor.@positions.pushBack @@ -4446,8 +4328,16 @@ addIndexArrayToProcess: [ #add to match table indexArray storageAddress @block addMatchingNode - block.parent 0 = [block.id 1 >] && [ - 1 dynamic addNamesFromModule + block.parent 0 = [ + block.id 0 > [ + 0 dynamic addNamesFromModule #builtins + ] when + + block.id 1 > [ + 1 dynamic addNamesFromModule #definitions + ] when + + @processor.@possibleUnstables [.clear] each ] when recursionTries: 0 dynamic; @@ -4459,6 +4349,7 @@ addIndexArrayToProcess: [ @block.@fromModuleNames.clear @block.@captureNames.clear @block.@fieldCaptureNames.clear + @block.@stableNames.clear @block.@unprocessedAstNodes.clear @block.@dependentPointers.clear @block.@captureErrors.clear @@ -4474,7 +4365,7 @@ addIndexArrayToProcess: [ tokenRef: block.unprocessedAstNodes.last copy; @block.@unprocessedAstNodes.popBack - astNode: tokenRef.token processor.multiParserResult.memory.at; + astNode: tokenRef.token processor.multiParserResult.memory.at.get; astNode tokenRef.file makeCompilerPosition @processor.@positions.last set astNode tokenRef.token processNode @@ -4502,13 +4393,32 @@ addIndexArrayToProcess: [ ] loop processor compilable [block.state NodeStateCompiled =] && [ - @block concreteMatchingNode + block.parent 0 = [ + @processor @block createGlobalAliases + ] when + + block.hasEmptyLambdas + [ + block.parent 0 = + [processor.options.partial copy] && + [ + topNode: block.topNode; + [topNode.file isNil ~] "Topnode in nil file!" assert + topNode.file.usedInParams ~ + ] && + ] || + [block.id 1 =] || [ + TRUE @block.@empty set + ] when + + block.deleted ~ [ + @block concreteMatchingNode + ] when ] when processor.varCount codeNode.variableCountDelta - @codeNode.@variableCountDelta set processor.depthOfRecursion 1 - @processor.@depthOfRecursion set @processor.@positions.popBack - block.id copy ] "astNodeToCodeNode" exportFunction diff --git a/debugWriter.mpl b/debugWriter.mpl index a011bcd..e482d20 100644 --- a/debugWriter.mpl +++ b/debugWriter.mpl @@ -1,47 +1,12 @@ +"Array" use +"HashTable" use +"String" use "control" use -"Array.Array" use -"HashTable.hash" use -"String.assembleString" use -"String.makeStringView" use -"String.toString" use -"String.splitString" use -"String.String" use - -"Var.VarBuiltin" use -"Var.VarCode" use -"Var.VarCond" use -"Var.VarEnd" use -"Var.VarImport" use -"Var.VarInt16" use -"Var.VarInt32" use -"Var.VarInt64" use -"Var.VarInt8" use -"Var.VarIntX" use -"Var.VarInvalid" use -"Var.VarNat16" use -"Var.VarNat32" use -"Var.VarNat64" use -"Var.VarNat8" use -"Var.VarNatX" use -"Var.VarReal32" use -"Var.VarReal64" use -"Var.VarRef" use -"Var.VarString" use -"Var.VarStruct" use -"Var.getAlignment" use -"Var.getStorageSize" use -"Var.getStringImplementation" use -"Var.getVar" use -"Var.isPlain" use -"Var.isVirtual" use -"Var.isVirtualType" use -"declarations.compilerError" use -"irWriter.appendInstruction" use -"irWriter.getIrName" use -"irWriter.getIrType" use -"irWriter.getMplSchema" use -"irWriter.getNameById" use -"pathUtils.simplifyPath" use + +"Var" use +"declarations" use +"irWriter" use +"pathUtils" use addDebugProlog: [ processor:; @@ -412,7 +377,7 @@ addFuncDebugInfo: [ funcImplementation: funcName makeStringView getStringImplementation; ( - "!" funcDebugIndex " = distinct !DISubprogram(name: \"" funcImplementation ".dbgId" funcDebugIndex "\", linkageName: \"" @funcIRName + "!" funcDebugIndex " = distinct !DISubprogram(name: \"" funcImplementation "\", linkageName: \"" @funcIRName "\", scope: !" position.file.debugId ", file: !" position.file.debugId ", line: " position.line ", type: !" subroutineIndex ", scopeLine: " position.line ", unit: !" processor.debugInfo.unit ")") assembleString @processor.@debugInfo.@strings.pushBack diff --git a/declarations.mpl b/declarations.mpl index 6fb468f..d834b12 100644 --- a/declarations.mpl +++ b/declarations.mpl @@ -1,20 +1,12 @@ -"String.String" use -"String.StringView" use -"String.makeStringView" use -"String.toString" use +"String" use "control" use -"Block.Block" use -"Block.CFunctionSignature" use -"Block.CompilerPositionInfo" use -"Block.NodeCaseCode" use -"File.File" use -"Var.RefToVar" use -"Var.Variable" use -"astNodeType.AstNode" use -"astNodeType.IndexArray" use -"processor.Processor" use -"processor.RefToVarTable" use +"Block" use +"MplFile" use +"NameManager" use +"Var" use +"astNodeType" use +"processor" use { processor: Processor Ref; @@ -38,7 +30,7 @@ compilerError: [processor: block:;; makeStringView block @processor compilerErro { processor: Processor Ref; - + file: File Cref; signature: CFunctionSignature Cref; compilerPositionInfo: CompilerPositionInfo Cref; refToVar: RefToVar Cref; @@ -97,7 +89,7 @@ compilerError: [processor: block:;; makeStringView block @processor compilerErro asCodeRef: Cond; name: StringView Cref; signature: CFunctionSignature Cref; -} Natx {} "processImportFunction" importFunction +} Int32 {} "processImportFunction" importFunction { block: Block Ref; @@ -349,3 +341,25 @@ createFailWithMessage: [ string: text String same [@text] [text toString] uif; @string @processor @block createFailWithMessageImpl ]; + +{ + nameManager: NameInfoEntry NameManager Ref; + multiParserResult: MultiParserResult Ref; + fileText: StringView Cref; + fileName: StringView Cref; + errorMessage: String Ref; +} () {} "addToProcessImpl" importFunction + +addToProcess: [ + result: String; + fileName: fileText: multiParserResult: nameManager: ;;;; + @result fileName fileText @multiParserResult @nameManager addToProcessImpl + @result +]; + +{ + processor: Processor Ref; + fileName: StringView Cref; + fromCmd: Cond; +} Int32 {} "addFileNameToProcessor" importFunction + diff --git a/defaultImpl.mpl b/defaultImpl.mpl index 579996f..35648ea 100644 --- a/defaultImpl.mpl +++ b/defaultImpl.mpl @@ -1,45 +1,11 @@ -"String.String" use -"String.StringView" use -"String.addLog" use -"String.assembleString" use -"String.makeStringView" use -"String.print" use -"String.printList" use -"String.toString" use +"String" use "control" use -"conventions.cdecl" use - -"Block.ArgMeta" use -"Block.Block" use -"Block.NameCaseInvalid" use -"Block.NodeCaseCodeRefDeclaration" use -"Block.NodeStateNew" use -"Block.ShadowEvent" use -"Var.RefToVar" use -"Var.ShadowReasonCapture" use -"Var.ShadowReasonInput" use -"Var.VarCode" use -"Var.VarImport" use -"Var.VarString" use -"Var.Virtual" use -"Var.Weak" use -"Var.getPlainValueInformation" use -"Var.getVar" use -"Var.isPlain" use -"Var.staticityOfVar" use -"Var.variablesAreSame" use -"declarations.compilerError" use -"declarations.createCopyToExists" use -"declarations.createRefWith" use -"declarations.defaultPrintStack" use -"declarations.defaultPrintStackTrace" use -"declarations.getMplType" use -"declarations.popWith" use -"declarations.processCall" use -"declarations.processFuncPtr" use -"declarations.push" use -"declarations.tryImplicitLambdaCast" use -"processor.Processor" use +"conventions" use + +"Block" use +"Var" use +"declarations" use +"processor" use FailProcForProcessor: [{ processor: block: ;; @@ -150,6 +116,53 @@ defaultRef: [ ] when ]; +setRef: [ + processor: block: ;; + refToVar:; # destination + compileOnce + + var: refToVar getVar; + var.data.getTag VarRef = [ + refToVar isVirtual [ + "can not write to virtual" @processor block compilerError + ] [ + pointee: VarRef var.data.get.refToVar; + pointee.mutable ~ [ + FALSE @processor @block defaultMakeConstWith #source + ] when + + processor compilable [ + src: @processor @block pop; + processor compilable [ + src pointee variablesAreSame [ + src @block push + @src makeVarPtrCaptured + TRUE @processor @block defaultRef #source + refToVar @block push + @processor @block defaultSet + ] [ + src @block push + refToVar @block push + @processor @block defaultSet + ] if + ] when + ] when + ] if + ] [ + #rewrite value case! + src: @processor @block pop; + processor compilable [ + src getVar.temporary [ + src @block push + refToVar @block push + @processor @block defaultSet + ] [ + "rewrite value works only with temporary values" @processor block compilerError + ] if + ] when + ] if +]; + defaultMakeConstWith: [ check: processor: block: ;;; refToVar: @processor @block pop; @@ -220,7 +233,7 @@ getStackDepth: [ 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 + entry isPlain [entry getPlainValueInformation] [String] if LF) printList i 1 + @i set TRUE ] && ] loop @@ -236,7 +249,7 @@ getStackDepth: [ currentPosition: processor.positions.getSize 1 - i - processor.positions.at; ( - "at filename: " currentPosition.file.name + "at fileName: " currentPosition.file.name ", token: " currentPosition.token ", line: " currentPosition.line ", column: " currentPosition.column LF @@ -267,22 +280,80 @@ nodeHasCode: [ node.emptyDeclaration ~ [node.uncompilable ~] && [node.empty ~] && [node.deleted ~] && [node.nodeCase NodeCaseCodeRefDeclaration = ~] && ]; +addBlockIdTo: [ + whereNames: nameInfo: nameOverloadDepth: captureCase: mplSchemaId: file: processor: block: ;;;;;;;; + + addToLine: [ + line:; + index: line.size 1 -; + result: TRUE dynamic; + + [ + index 0 < [index line.at.block block is ~] || [ + FALSE #no such item + ] [ + index line.at.file file is [ + FALSE !result #we have such item + FALSE + ] [ + index 1 - !index + TRUE #find deeper + ] if + ] if + ] loop + + result [ + NameInfoCoord @line.pushBack + block @line.last.@block.set + file @line.last.@file.set + ] 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.selfNameInfo = [ + nameOverloadDepth mplSchemaId @whereNames.@selfNames addBlockToObjectCase + ] [ + nameInfo processor.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 +]; + addEmptyCapture: [ processor: block: ;; nameInfo: nameOverloadDepth: ;; file:; - newEvent: ShadowEvent; - ShadowReasonCapture @newEvent.setTag - branch: ShadowReasonCapture @newEvent.get; - - 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 + @processor.@captureTable nameInfo nameOverloadDepth NameCaseInvalid processor.varForFails getVar.mplSchemaId file @processor @block addBlockIdTo [ + newEvent: ShadowEvent; + ShadowReasonCapture @newEvent.setTag + branch: ShadowReasonCapture @newEvent.get; + + 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 + ] when ]; addShadowEvent: [ @@ -296,3 +367,12 @@ addShadowEvent: [ event @block.@matchingInfo.@shadowEvents.pushBack ] when ]; + +getTopNode: [ + processor: topNode:;; + [topNode.parent 0 = ~] [ + topNode.parent @processor.@blocks.at.get !topNode + ] while + + @topNode +]; diff --git a/irWriter.mpl b/irWriter.mpl index fa24c38..fa41fd5 100644 --- a/irWriter.mpl +++ b/irWriter.mpl @@ -1,49 +1,15 @@ -"Array.Array" use -"String.String" use -"String.StringView" use -"String.assembleString" use -"String.makeStringView" use -"String.print" use -"String.toString" use +"Array" use +"String" use "control" use -"conventions.cdecl" use - -"Block.Block" use -"Block.Instruction" use -"Block.makeInstruction" use -"File.File" use -"Var.Dynamic" use -"Var.RefToVar" use -"Var.VarBuiltin" use -"Var.VarStruct" use -"Var.fullUntemporize" use -"Var.getPlainConstantIR" use -"Var.getStorageSize" use -"Var.getStringImplementation" use -"Var.getVar" use -"Var.isAutoStruct" use -"Var.isNat" use -"Var.isPlain" use -"Var.isVirtual" use -"Var.makeStringId" use -"Var.markAsUnableToDie" use -"Var.staticityOfVar" use -"Var.varIsMoved" use -"declarations.addDebugLocationForLastInstruction" use -"declarations.callAssign" use -"declarations.callDie" use -"declarations.callInit" use -"declarations.compilerError" use -"declarations.createFailWithMessage" use -"declarations.makeVarString" use -"declarations.setVar" use -"defaultImpl.findNameInfo" use -"defaultImpl.makeVarPtrCaptured" use -"defaultImpl.makeVarRealCaptured" use -"defaultImpl.nodeHasCode" use -"pathUtils.nameWithoutBadSymbols" use -"pathUtils.stripExtension" use -"processor.Processor" use +"conventions" use + +"Block" use +"MplFile" use +"Var" use +"declarations" use +"defaultImpl" use +"pathUtils" use +"processor" use appendInstruction: [ list: block:;; @@ -153,7 +119,16 @@ createAllocIR: [ refToVar: processor: block: ;;; var: @refToVar getVar; block.parent 0 = [ - (refToVar @processor getIrName " = local_unnamed_addr global " refToVar @processor getIrType " zeroinitializer") assembleString @processor.@prolog.pushBack + processor.options.partial copy [ + varBlock: block; + [varBlock.file isNil ~] "Topnode in nil file!" assert + varBlock.file.usedInParams ~ + ] && [ + "; global var from another file" toString @processor.@prolog.pushBack + ] [ + (refToVar @processor getIrName " = private local_unnamed_addr global " refToVar @processor getIrType " zeroinitializer") assembleString @processor.@prolog.pushBack + ] if + processor.prolog.size 1 - @var.@globalDeclarationInstructionIndex set ] [ refToVar getVar.irNameId refToVar @processor getMplSchema.irTypeId @processor @block createAllocIRByReg @@ -161,7 +136,6 @@ createAllocIR: [ block.program.size 1 - @var.@allocationInstructionIndex set ] if - refToVar copy ]; @@ -169,7 +143,16 @@ createStaticInitIR: [ refToVar: processor: block: ;;; var: @refToVar getVar; [block.parent 0 =] "Can be used only with global vars!" assert - (refToVar @processor getIrName " = local_unnamed_addr global " refToVar @processor getStaticStructIR) assembleString @processor.@prolog.pushBack + + processor.options.partial copy [ + varBlock: block; + [varBlock.file isNil ~] "Topnode in nil file!" assert + varBlock.file.usedInParams ~ + ] && [ + "; global var from another file" toString @processor.@prolog.pushBack + ] [ + (refToVar @processor getIrName " = private local_unnamed_addr global " refToVar @processor getStaticStructIR) assembleString @processor.@prolog.pushBack + ] if processor.prolog.size 1 - @var.@globalDeclarationInstructionIndex set refToVar copy ]; @@ -482,11 +465,11 @@ createRetValue: [ ]; createCallIR: [ - refToRet: argList: conventionName: funcName: processor: block: ;;;;;; + refToRet: argList: conventionName: funcName: hasCallTrace: processor: block: ;;;;;;; haveRet: refToRet.var isNil ~; retName: 0; - processor.options.callTrace [@processor @block createCallTraceProlog] when + processor.options.callTrace hasCallTrace and [@processor @block createCallTraceProlog] when offset: block.programTemplate.size; @@ -520,7 +503,7 @@ createCallIR: [ @processor @block addDebugLocationForLastInstruction - processor.options.callTrace [@processor @block createCallTraceEpilog] when + processor.options.callTrace hasCallTrace and [@processor @block createCallTraceEpilog] when retName ]; @@ -578,11 +561,30 @@ createFloatBuiltins: [ "declare double @llvm.pow.f64(double, double)" @processor addStrToProlog ]; +getLLPriority: [ + processor:; + + priority: 0 dynamic; + + processor.moduleFunctions [ + currentBlock: processor.blocks.at.get; + currentBlock.deleted ~ currentBlock.empty ~ and [ + currentBlock.globalPriority priority > [ + currentBlock.globalPriority @priority set + ] when + ] when + ] each + + priority +]; + createCtors: [ createTlsInit: processor: ; copy; + priority: @processor getLLPriority; + "" @processor addStrToProlog - "@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @global.ctors, i8* null }]" @processor addStrToProlog + ("@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 " priority ", void ()* @global.ctors, i8* null }]") assembleString @processor addStrToProlog "" @processor addStrToProlog "define internal void @global.ctors() {" @processor addStrToProlog @@ -591,8 +593,10 @@ createCtors: [ ] when processor.moduleFunctions [ - cur: processor.blocks.at.get.irName copy; - (" call void " cur "()") assembleString @processor addStrToProlog + currentBlock: processor.blocks.at.get; + currentBlock.deleted ~ currentBlock.empty ~ and [ + (" call void " currentBlock.irName "()") assembleString @processor addStrToProlog + ] when ] each " ret void" @processor addStrToProlog @@ -601,9 +605,10 @@ createCtors: [ createDtors: [ processor:; + priority: @processor getLLPriority; "" @processor addStrToProlog - "@llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @global.dtors, i8* null }]" @processor addStrToProlog + ("@llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 " 65536 priority + ", void ()* @global.dtors, i8* null }]") assembleString @processor addStrToProlog "" @processor addStrToProlog "define internal void @global.dtors() {" @processor addStrToProlog processor.dtorFunctions [ @@ -807,7 +812,7 @@ generateVariableIRNameWith: [ ("@global." processor.globalVarCount) assembleString @processor makeStringId processor.globalVarCount 1 + @processor.@globalVarCount set ] [ - ("%var." hostOfVariable.lastVarName) assembleString @processor makeStringId + hostOfVariable.lastVarName @processor makeDefaultVarId hostOfVariable.lastVarName 1 + @hostOfVariable.@lastVarName set ] if ]; diff --git a/main.mpl b/main.mpl index 45bd115..efd966e 100644 --- a/main.mpl +++ b/main.mpl @@ -1,40 +1,18 @@ -"Array.makeSubRange" use -"HashTable.hash" use -"String.String" use -"String.StringView" use -"String.addLog" use -"String.assembleString" use -"String.hash" use -"String.makeStringView" use -"String.makeStringViewByAddress" use -"String.print" use -"String.printList" use -"String.splitString" use -"String.toString" use -"ascii.ascii" use +"Array" use +"HashTable" use +"String" use +"ascii" use "control" use -"conventions.cdecl" use -"conventions.stdcall" use -"file.loadString" use -"file.saveString" use -"memory.debugMemory" use - -"NameManager.NameManager" use -"astNodeType.MultiParserResult" use -"astNodeType.ParserResult" use -"astNodeType.ParserResults" use -"astOptimizers.concatParserResults" use -"astOptimizers.optimizeLabels" use -"astOptimizers.optimizeNames" use -"parser.parseString" use -"pathUtils.extractClearPath" use -"processor.DEFAULT_PRE_RECURSION_DEPTH_LIMIT" use -"processor.DEFAULT_RECURSION_DEPTH_LIMIT" use -"processor.DEFAULT_STATIC_LOOP_LENGTH_LIMIT" use -"processor.NameInfoEntry" use -"processor.Processor" use -"processor.ProcessorOptions" use -"processorImpl.process" use +"conventions" use +"file" use +"memory" use + +"NameManager" use +"astNodeType" use +"declarations" use +"pathUtils" use +"processor" use +"processorImpl" use debugMemory [ "memory.getMemoryMetrics" use @@ -46,6 +24,7 @@ printInfo: [ " -32bits Set 32-bit mode, default mode is 64-bit" print LF print " -64bits Set 64-bit mode, default mode is 64-bit" print LF print " -D Define global name with value, default value is ()" print LF print + " -I Add include path to find files" print LF print " -array_checks 0|1 Turn off/on array index checks, by default it is on in debug mode and off in release mode" print LF print " -auto_recursion Make all code block recursive-by-default" print LF print " -call_trace Generate information about call trace" print LF print @@ -54,9 +33,9 @@ printInfo: [ ] when " -dynalit Number literals are dynamic constants, which are not used in analysis; default mode is static literals" print LF print " -linker_option Add linker option for LLVM" print LF print - " -logs Value of \"HAS_LOGS\" constant in code turn to TRUE" print LF print " -ndebug Disable debug info; value of \"DEBUG\" constant in code turn to FALSE" print LF print " -o Write output to , default output file is \"mpl.ll\"" print LF print + " -part Create ll only for files in cmd line" print LF print " -pre_recursion_depth_limit Set PRE recursion depth limit, default value is " print DEFAULT_PRE_RECURSION_DEPTH_LIMIT print LF print " -recursion_depth_limit Set recursion depth limit, default value is " print DEFAULT_RECURSION_DEPTH_LIMIT print LF print " -static_loop_length_limit Set static loop length limit, default value is " print DEFAULT_STATIC_LOOP_LENGTH_LIMIT print LF print @@ -66,25 +45,6 @@ printInfo: [ FALSE @success set ]; -addToProcess: [ - fileText:; - fileName:; - parserResult: ParserResult; - - @parserResult fileText makeStringView parseString - - parserResult.success [ - @parserResult optimizeLabels - @parserResult move @parserResults.pushBack - ] [ - ("ERROR") addLog - - (fileName "(" parserResult.errorInfo.position.line "," makeStringView parserResult.errorInfo.position.column "): syntax error, " - parserResult.errorInfo.message) assembleString print LF print - FALSE @success set - ] if -]; - createDefinition: [ splittedOption:; eqIndex: -1; @@ -165,6 +125,14 @@ processIntegerOption: [ ] if ]; +addToProcessAndCheck: [ + errorMessage: addToProcess; + errorMessage "" = ~ [ + errorMessage print LF print + FALSE !success + ] when +]; + {argc: 0; argv: 0nx;} 0 {convention: cdecl;} [ #debugMemory [TRUE !memoryDebugEnabled] when ("Start mplc compiler") addLog @@ -184,12 +152,12 @@ processIntegerOption: [ OPT_RECURSION_DEPTH_LIMIT: [7 dynamic]; OPT_PRE_RECURSION_DEPTH_LIMIT: [8 dynamic]; OPT_STATIC_LOOP_LENGTH_LIMIT: [9 dynamic]; + OPT_INCLUDE_PATH: [10 dynamic]; nextOption: OPT_ANY; options: ProcessorOptions; hasVersion: FALSE dynamic; - parserResults: ParserResults; definitions: String; hasVersion: FALSE dynamic; outputFileName: "mpl.ll" toString; @@ -197,6 +165,10 @@ processIntegerOption: [ forceArrayChecks: -1 dynamic; forceCallTrace: -1 dynamic; + multiParserResult: MultiParserResult; + nameManager: NameInfoEntry NameManager; + + "*builtins" toString @options.@fileNames.pushBack "*definitions" toString @options.@fileNames.pushBack argc 1 = [ @@ -225,6 +197,7 @@ processIntegerOption: [ "-32bits" [32nx @options.!pointerSize] "-64bits" [64nx @options.!pointerSize] "-D" [OPT_DEFINITION !nextOption] + "-I" [OPT_INCLUDE_PATH !nextOption] "-array_checks" [OPT_ARRAY_CHECK !nextOption] "-auto_recursion" [TRUE @options.!autoRecursion] "-call_trace" [OPT_CALL_TRACE !nextOption] @@ -233,9 +206,9 @@ processIntegerOption: [ ] when "-dynalit" [FALSE @options.!staticLiterals] "-linker_option" [OPT_LINKER_OPTION !nextOption] - "-logs" [TRUE @options.!logs] "-ndebug" [FALSE @options.!debug] "-o" [OPT_OUTPUT_FILE_NAME !nextOption] + "-part" [TRUE @options.!partial] "-pre_recursion_depth_limit" [OPT_PRE_RECURSION_DEPTH_LIMIT !nextOption] "-recursion_depth_limit" [OPT_RECURSION_DEPTH_LIMIT !nextOption] "-static_loop_length_limit" [OPT_STATIC_LOOP_LENGTH_LIMIT !nextOption] @@ -247,7 +220,7 @@ processIntegerOption: [ "Invalid argument: " print option print LF print FALSE @success set ] [ - option toString @options.@fileNames.pushBack + option simplifyFileName @options.@fileNames.pushBack ] if ] ) case @@ -299,6 +272,10 @@ processIntegerOption: [ option @options.@staticLoopLengthLimit processIntegerOption OPT_ANY !nextOption ] + OPT_INCLUDE_PATH [ + option simplifyFileName @options.@includePaths.pushBack + OPT_ANY !nextOption + ] [] ) case ] if @@ -317,7 +294,7 @@ processIntegerOption: [ FALSE @success set ] when - options.fileNames.getSize 1 = [ + options.fileNames.getSize 2 = [ hasVersion [ DEBUG [ ("MPL compiler version " COMPILER_SOURCE_VERSION " debug" LF) printList @@ -343,7 +320,7 @@ processIntegerOption: [ 0 [FALSE] 1 [TRUE] 2 [TRUE] - [options.debug copy] + [FALSE] ) case @options.@callTrace set forceCallTrace 2 = [1 @options.@threadModel set] when @@ -353,37 +330,36 @@ processIntegerOption: [ "Input files ignored" print LF print ] [ options.fileNames.getSize [ - filename: i options.fileNames @; + fileName: i options.fileNames @; i 0 = [ - filename definitions addToProcess + #builtins ] [ - loadStringResult: filename loadString; - loadStringResult.success [ - ("Loaded string from " filename) addLog - ("HASH=" loadStringResult.data hash) addLog - filename loadStringResult.data addToProcess + i 1 = [ + fileName makeStringView definitions makeStringView @multiParserResult @nameManager addToProcessAndCheck ] [ - "Unable to load string:" print filename print LF print - FALSE @success set + loadStringResult: fileName loadString; + loadStringResult.success [ + ("Loaded string from " fileName) addLog + ("HASH=" loadStringResult.data hash) addLog + fileName makeStringView loadStringResult.data makeStringView @multiParserResult @nameManager addToProcessAndCheck + ] [ + "Unable to load string:" print fileName print LF print + FALSE @success set + ] if ] if ] if ] times success [ - multiParserResult: MultiParserResult; - nameManager: NameInfoEntry NameManager; - @parserResults @multiParserResult concatParserResults - ("trees concated" makeStringView) addLog - @multiParserResult @nameManager optimizeNames - ("names optimized" makeStringView) addLog + ("trees concated" makeStringView) addLog ("filenames:" makeStringView) addLog options.fileNames [fileName:; (fileName) addLog] each result: String; program: String; - multiParserResult @nameManager options 0 @result @program process + @multiParserResult @nameManager options 0 @result @program process result.size 0 = [ outputFileName program saveString [ ("program written to " outputFileName) addLog @@ -406,12 +382,21 @@ processIntegerOption: [ debugMemory [] && [ #mplReleaseCache - ( - "allocations: " getMemoryMetrics.memoryCurrentAllocationCount copy "/" getMemoryMetrics.memoryTotalAllocationCount copy - ", bytes: " getMemoryMetrics.memoryCurrentAllocationSize copy "/" getMemoryMetrics.memoryTotalAllocationSize copy - ", max: " getMemoryMetrics.memoryMaxAllocationSize copy - ", checksum: " getMemoryMetrics.memoryChecksum copy - LF - ) printList + getMemoryMetrics.memoryChecksum 0nx = ~ [ + ( + "allocations: " getMemoryMetrics.memoryCurrentAllocationCount copy By3 "/" getMemoryMetrics.memoryTotalAllocationCount copy By3 + ", bytes: " getMemoryMetrics.memoryCurrentAllocationSize copy By3 "/" getMemoryMetrics.memoryTotalAllocationSize copy By3 + ", max: " getMemoryMetrics.memoryMaxAllocationSize copy By3 + ", checksum: " getMemoryMetrics.memoryChecksum copy By3 + LF + ) printList + ] [ + ( + "allocations: " getMemoryMetrics.memoryTotalAllocationCount copy By3 + ", bytes: " getMemoryMetrics.memoryTotalAllocationSize copy By3 + ", max: " getMemoryMetrics.memoryMaxAllocationSize copy By3 + LF + ) printList + ] if ] when ] "main" exportFunction diff --git a/parser.mpl b/parser.mpl index 6085c92..fd4f53b 100644 --- a/parser.mpl +++ b/parser.mpl @@ -1,22 +1,9 @@ -"Array.Array" use -"Array.makeSubRange" use -"String.String" use -"String.StringView" use -"String.assembleString" use -"String.codepointToString" use -"String.makeStringView" use -"String.makeStringView2" use -"String.print" use -"String.splitString" use -"String.toString" use +"Array" use +"String" use +"ascii" use "control" use -"ascii.ascii" use -"astNodeType.AstNode" use -"astNodeType.AstNodeType" use -"astNodeType.IndexArray" use -"astNodeType.ParserResult" use -"astNodeType.PositionInfo" use +"astNodeType" use codepointHex?: [ codepoint:; diff --git a/pathUtils.mpl b/pathUtils.mpl index fab7404..0296b5b 100644 --- a/pathUtils.mpl +++ b/pathUtils.mpl @@ -1,9 +1,5 @@ -"Array.Array" use -"Array.makeSubRange" use -"String.String" use -"String.assembleString" use -"String.makeStringView" use -"String.splitString" use +"Array" use +"String" use "control" use extractClearPath: [ @@ -83,6 +79,15 @@ simplifyPath: [ ] call ]; +simplifyFileName: [ + path: name: simplifyPath;; + path "" = [ + @name move copy + ] [ + (path "/" name) assembleString + ] if +]; + findExtensionPosition: [ view: makeStringView; extensionPosition: view.size copy; diff --git a/processSubNodes.mpl b/processSubNodes.mpl index 734b261..b9447bb 100644 --- a/processSubNodes.mpl +++ b/processSubNodes.mpl @@ -1,159 +1,20 @@ -"Array.Array" use -"HashTable.hash" use -"String.String" use -"String.StringView" use -"String.addLog" use -"String.asView" use -"String.assembleString" use -"String.hash" use -"String.makeStringView" use -"String.print" use -"String.printList" use -"String.toString" use +"Array" use +"HashTable" use +"String" use "control" use -"Block.ArgCopy" use -"Block.ArgDerefCopy" use -"Block.ArgGlobal" use -"Block.ArgMeta" use -"Block.ArgRef" use -"Block.ArgRefDeref" use -"Block.ArgReturn" use -"Block.ArgReturnDeref" use -"Block.ArgVirtual" use -"Block.Block" use -"Block.BlockSchema" use -"Block.CFunctionSignature" use -"Block.Capture" use -"Block.CompilerPositionInfo" use -"Block.NameCaseInvalid" use -"Block.NameCaseLocal" use -"Block.NodeCaseCode" use -"Block.NodeCaseCodeRefDeclaration" use -"Block.NodeCaseDeclaration" use -"Block.NodeCaseExport" use -"Block.NodeCaseLambda" use -"Block.NodeCaseList" use -"Block.NodeCaseObject" use -"Block.NodeRecursionStateFail" use -"Block.NodeRecursionStateNew" use -"Block.NodeRecursionStateNo" use -"Block.NodeRecursionStateOld" use -"Block.NodeStateCompiled" use -"Block.NodeStateFailed" use -"Block.NodeStateHasOutput" use -"Block.NodeStateNew" use -"Block.NodeStateNoOutput" use -"Block.ShadowEvent" use -"File.File" use -"Var.Dirty" use -"Var.Dynamic" use -"Var.RefToVar" use -"Var.ShadowReasonCapture" use -"Var.ShadowReasonField" use -"Var.ShadowReasonFieldCapture" use -"Var.ShadowReasonInput" use -"Var.ShadowReasonPointee" use -"Var.Static" use -"Var.VarBuiltin" use -"Var.VarCond" use -"Var.VarImport" use -"Var.VarInvalid" use -"Var.VarReal64" use -"Var.VarRef" use -"Var.VarString" use -"Var.VarStruct" use -"Var.Virtual" use -"Var.Weak" use -"Var.fullUntemporize" use -"Var.getVar" use -"Var.isNonrecursiveType" use -"Var.isPlain" use -"Var.isSemiplainNonrecursiveType" use -"Var.isVirtual" use -"Var.makeValuePair" use -"Var.staticityOfVar" use -"Var.varIsMoved" use -"Var.variablesAreSame" use -"astNodeType.AstNode" use -"astNodeType.AstNodeType" use -"astNodeType.IndexArray" use -"codeNode.addBlock" use -"codeNode.astNodeToCodeNode" use -"codeNode.captureName" use -"codeNode.deleteNode" use -"codeNode.finalizeCodeNode" use -"codeNode.getField" use -"codeNode.getFieldForMatching" use -"codeNode.getLastShadow" use -"codeNode.getNameForMatching" use -"codeNode.getNameForMatchingWithOverloadIndex" use -"codeNode.getNameWithOverloadIndex" use -"codeNode.getPointeeForMatching" use -"codeNode.getPointeeNoDerefIR" use -"codeNode.getPossiblePointee" use -"codeNode.makeCompilerPosition" use -"codeNode.makePointeeDirtyIfRef" use -"codeNode.makeStaticity" use -"codeNode.makeStorageStaticity" use -"codeNode.makeVarDirty" use -"codeNode.makeVarDynamic" use -"codeNode.makeVarTreeDirty" use -"codeNode.makeVarTreeDirty" use -"codeNode.makeVarTreeDynamic" use -"codeNode.popForMatching" use -"codeNode.processStaticAt" use -"debugWriter.addDebugReserve" use -"declarations.compilerError" use -"declarations.copyOneVar" use -"declarations.copyOneVarFromType" use -"declarations.copyVar" use -"declarations.copyVarFromChild" use -"declarations.copyVarToNew" use -"declarations.getMplType" use -"declarations.push" use -"declarations.tryImplicitLambdaCast" use -"defaultImpl.FailProcForProcessor" use -"defaultImpl.addEmptyCapture" use -"defaultImpl.addShadowEvent" use -"defaultImpl.addStackUnderflowInfo" use -"defaultImpl.compilable" use -"defaultImpl.findNameInfo" use -"defaultImpl.getStackDepth" use -"defaultImpl.getStackEntry" use -"defaultImpl.getStackEntryUnchecked" use -"defaultImpl.makeVarDerefCaptured" use -"defaultImpl.makeVarPtrCaptured" use -"defaultImpl.makeVarRealCaptured" use -"defaultImpl.pop" use -"irWriter.createAllocIR" use -"irWriter.createBranch" use -"irWriter.createCallIR" use -"irWriter.createCheckedCopyToNewNoDie" use -"irWriter.createComment" use -"irWriter.createDerefTo" use -"irWriter.createDerefToRegister" use -"irWriter.createDerefFromRegisterToRegister" use -"irWriter.createJump" use -"irWriter.createLabel" use -"irWriter.createPhiNode" use -"irWriter.createStaticInitIR" use -"irWriter.createStoreFromRegister" use -"irWriter.getIrName" use -"irWriter.getIrType" use -"irWriter.getMplSchema" use -"processor.IRArgument" use -"processor.Processor" use -"processor.ProcessorErrorInfo" use -"processor.ProcessorResult" use -"processor.RefToVarTable" use -"staticCall.staticCall" use -"variable.isGlobal" use -"variable.isStaticData" use -"variable.markAsAbleToDie" use -"variable.noMatterToCopy" use -"variable.refsAreEqual" use -"variable.unglobalize" use +"Block" use +"MplFile" use +"Var" use +"astNodeType" use +"codeNode" use +"debugWriter" use +"declarations" use +"defaultImpl" use +"irWriter" use +"processor" use +"staticCall" use +"variable" use {processorResult: ProcessorResult Ref; cachedGlobalErrorInfoSize: Int32;} () {} [ cachedGlobalErrorInfoSize: processorResult:;; @@ -392,6 +253,10 @@ catShadowEvents: [ 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 @@ -411,10 +276,23 @@ catShadowEvents: [ tryMatchNode: [ currentMatchingNode:; - comparingMessage: String; - canMatch: currentMatchingNode.deleted ~ [ + currentMatchingNode.changedStableName [currentMatchingNode.nodeCompileOnce copy] && [ + "in compile-once node stable name changed" @processor block compilerError + ] when + + labmdaMismatch: currentMatchingNode.hasEmptyLambdas [ + topNode: block.topNode; + [topNode.file isNil ~] "Topnode in nil file!" assert + topNode.file.usedInParams copy + ] &&; + + labmdaMismatch [currentMatchingNode.nodeCompileOnce copy] && [ + "in compile-once node was empty lambda, because it was called from unused module" @processor block compilerError + ] when + + canMatch: currentMatchingNode.deleted ~ [currentMatchingNode.changedStableName ~] && [labmdaMismatch ~] && [ currentMatchingNode.state NodeStateCompiled = currentMatchingNode.state NodeStateFailed = or [ #recursive condition @@ -426,7 +304,7 @@ tryMatchNode: [ [forceRealFunction copy] || ] && ] || - ] &&; + ] &&; goodReality: forceRealFunction ~ [ @@ -504,19 +382,40 @@ tryMatchNode: [ cacheEntry: branch.refToVar; overloadIndex: outOverloadDepth: branch @block branch.file TRUE getOverloadIndex;; - stackEntry: branch.nameInfo branch overloadIndex @processor @block branch.file getNameForMatchingWithOverloadIndex.refToVar; + gnr: branch.nameInfo branch overloadIndex @processor @block branch.file getNameForMatchingWithOverloadIndex; - stackEntry cacheEntry TRUE @comparingMessage currentMatchingNode processor compareOnePair + 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 + [ + 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 - [@stackEntry cacheEntry @eventVars addEventVar] && ~ [ - currentMatchingNode.nodeCompileOnce [i mismatchMessage] when FALSE dynamic @success set ] when ] @@ -555,7 +454,7 @@ tryMatchNode: [ FALSE dynamic @success set ] when ] - [] + [] ) @currentEvent.visit ] when ] times @@ -982,6 +881,10 @@ applyNodeChanges: [ stackEntry getVar.data.getTag VarInvalid = ~ [stackEntry @pops.pushBack] when stackEntry cacheEntry @appliedVars addAppliedVar ] + ShadowReasonStableName [ + branch:; + branch.nameInfo @processor @block addStableName + ] ShadowReasonCapture [ branch:; cacheEntry: branch.refToVar; @@ -1040,11 +943,21 @@ applyNodeChanges: [ stackEntry: branch.mplFieldIndex stackObject @processor @block getField; stackEntry cacheEntry @appliedVars addAppliedVar ] - [] + [] ) @currentEvent.visit ] when ] times + currentChangesNode.capturedFiles.getSize [ + i currentChangesNode.capturedFiles.at [ + i @block captureFileToBlock + ] when + ] times + + currentChangesNode.hasEmptyLambdas [ + TRUE @block.!hasEmptyLambdas + ] when + i: 0 dynamic; [ i pops.size < [ @@ -1070,6 +983,10 @@ applyNodeChanges: [ ] && ] loop + currentChangesNode.hasCallTrace [ + TRUE @block.@hasCallTrace set + ] when + appliedVars.stackVars.size [ stackEntry: i @appliedVars.@stackVars.at; cacheEntry: i @appliedVars.@cacheVars.at; @@ -1191,12 +1108,15 @@ applyStackChanges: [ makeCallInstructionWith: [ block:; + processor:; + copy hasCallTrace:; copy dynamicFunc:; refToVar:; forcedName:; newNode:; outputs:; inputs:; + argRet: RefToVar; argList: @processor.@irArgumentArray; @@ -1295,11 +1215,11 @@ makeCallInstructionWith: [ ] && ] loop - newNode.empty ~ [ + dynamicFunc newNode.empty ~ or [ pureFuncName: forcedName "" = [dynamicFunc [refToVar @processor getIrName][newNode.irName makeStringView] if][forcedName copy] if; funcName: newNode.variadic [("(" newNode.argTypes ") " pureFuncName) assembleString][pureFuncName toString] if; convName: newNode.convention; - retName: argRet argList convName funcName @processor @block createCallIR; + retName: argRet argList convName funcName hasCallTrace [newNode.hasCallTrace copy] || @processor @block createCallIR; argRet.var isNil ~ [ @retName argRet @processor @block createStoreFromRegister @@ -1311,13 +1231,13 @@ makeCallInstructionWith: [ makeNamedCallInstruction: [ r: RefToVar; - r FALSE dynamic @block makeCallInstructionWith + r FALSE dynamic FALSE dynamic @processor @block makeCallInstructionWith ]; makeCallInstruction: [ r: RefToVar; forcedName: StringView dynamic; - forcedName r FALSE dynamic @block makeCallInstructionWith + forcedName r FALSE dynamic FALSE dynamic @processor @block makeCallInstructionWith ]; processNamedCallByNode: [ @@ -1384,6 +1304,10 @@ useMatchingInfoOnly: [ 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;; @@ -1405,6 +1329,12 @@ useMatchingInfoOnly: [ ) event.visit ] each + newNode.capturedFiles.getSize [ + i newNode.capturedFiles.at [ + i @block captureFileToBlock + ] when + ] times + @eventVars @processor.releaseVarRefArray i: 0 dynamic; @@ -1467,6 +1397,7 @@ useMatchingInfoOnly: [ result: 0 newNode.outputs.at.refToVar @processor @block copyVarFromChild; TRUE @newNode.@deleted set @result @processor @block createStaticInitIR @block push + result @block.@candidatesToDie.pushBack ] [ forcedName: forcedNameString makeStringView dynamic; newNodeIndex forcedName processNamedCallByNode @@ -1484,7 +1415,7 @@ useMatchingInfoOnly: [ callAstNodeIndex:; overload failProc: processor block FailProcForProcessor; - astNode: callAstNodeIndex processor.multiParserResult.memory.at; + astNode: callAstNodeIndex processor.multiParserResult.memory.at.get; positionInfo: astNode file makeCompilerPosition; @@ -1508,7 +1439,7 @@ useMatchingInfoOnly: [ overload failProc: processor block FailProcForProcessor; processor compilable [ - astNode: preAstNodeIndex processor.multiParserResult.memory.at; + astNode: preAstNodeIndex processor.multiParserResult.memory.at.get; positionInfo: astNode file makeCompilerPosition; indexArray: AstNodeType.Code @astNode.@data.get; @@ -1550,7 +1481,14 @@ useMatchingInfoOnly: [ ] if ] "processPre" exportFunction -processIf: [ +{ + block: Block Ref; processor: Processor Ref; + fileElse: File Cref; + astNodeElse: AstNode Cref; + fileThen: File Cref; + astNodeThen: AstNode Cref; + refToCond: RefToVar Cref; +} () {} [ processor: block: ;; fileElse:; @@ -1559,6 +1497,8 @@ processIf: [ astNodeThen:; refToCond:; + overload failProc: processor block FailProcForProcessor; + indexArrayElse: AstNodeType.Code astNodeElse.data.get; indexArrayThen: AstNodeType.Code astNodeThen.data.get; @@ -1925,79 +1865,7 @@ processIf: [ ] if ] if ] if -]; - -processLoop: [ - astNode: processor: block: file: ;;;; - indexArray: AstNodeType.Code astNode.data.get; - positionInfo: astNode file makeCompilerPosition; - - iterationNumber: 0 dynamic; - loopIsDynamic: FALSE; - - [ - newNodeIndex: @indexArray @processor @block tryMatchAllNodes dynamic; - newNodeIndex 0 < [ - "loop" makeStringView - block.id - NodeCaseCode - indexArray - file - positionInfo - CFunctionSignature - @processor - astNodeToCodeNode @newNodeIndex set - ] when - - newNode: newNodeIndex @processor.@blocks.at.get; - processor compilable ~ [ - newNode @processor @block useMatchingInfoOnly - FALSE - ] [ - newNodeIndex changeNewNodeState - newNode.state NodeStateHasOutput < [ - FALSE - ] [ - newNode.state NodeStateHasOutput = [NodeStateHasOutput @block.@state set] when - appliedVars: newNode applyNodeChanges; - - appliedVars.fixedOutputs.getSize 0 = ["loop body must return Cond" @processor block compilerError] when - processor compilable [ - condition: newNode.outputs.last.refToVar; - condVar: condition getVar; - condVar.data.getTag VarCond = ~ ["loop body must return Cond" @processor block compilerError] when - - processor compilable [ - condition staticityOfVar Weak > [ - appliedVars.stackVars.size [ - stackEntry: i appliedVars.stackVars.at; - cacheEntry: i appliedVars.cacheVars.at; - cacheEntry @stackEntry changeVarValue - ] times - - newNode newNodeIndex @appliedVars applyStackChanges - a: @processor @block pop; - VarCond a getVar.data.get.end copy - ] [ - TRUE dynamic @loopIsDynamic set - FALSE - ] if - ] && - ] && - ] if - ] if - - iterationNumber 1 + @iterationNumber set - iterationNumber processor.options.staticLoopLengthLimit > [ - TRUE @processor.@result.!passErrorThroughPRE - ("Static loop length limit (" processor.options.staticLoopLengthLimit ") exceeded. Dynamize loop or increase limit using -static_loop_lenght_limit option") assembleString @processor block compilerError - ] when - - processor compilable and - ] loop - - loopIsDynamic [indexArray file processDynamicLoop] when -]; +] "processIf" exportFunction processDynamicLoop: [ indexArray: file:;; @@ -2172,9 +2040,86 @@ processDynamicLoop: [ ] loop ]; +{ + file: File Cref; block: Block Ref; processor: Processor Ref; astNode: AstNode Cref; +} () {} [ + astNode: processor: block: file: ;;;; + + overload failProc: processor block FailProcForProcessor; + + indexArray: AstNodeType.Code astNode.data.get; + positionInfo: astNode file makeCompilerPosition; + + iterationNumber: 0 dynamic; + loopIsDynamic: FALSE; + + [ + newNodeIndex: @indexArray @processor @block tryMatchAllNodes dynamic; + newNodeIndex 0 < [ + "loop" makeStringView + block.id + NodeCaseCode + indexArray + file + positionInfo + CFunctionSignature + @processor + astNodeToCodeNode @newNodeIndex set + ] when + + newNode: newNodeIndex @processor.@blocks.at.get; + processor compilable ~ [ + newNode @processor @block useMatchingInfoOnly + FALSE + ] [ + newNodeIndex changeNewNodeState + newNode.state NodeStateHasOutput < [ + FALSE + ] [ + newNode.state NodeStateHasOutput = [NodeStateHasOutput @block.@state set] when + appliedVars: newNode applyNodeChanges; + + appliedVars.fixedOutputs.getSize 0 = ["loop body must return Cond" @processor block compilerError] when + processor compilable [ + condition: newNode.outputs.last.refToVar; + condVar: condition getVar; + condVar.data.getTag VarCond = ~ ["loop body must return Cond" @processor block compilerError] when + + processor compilable [ + condition staticityOfVar Weak > [ + appliedVars.stackVars.size [ + stackEntry: i appliedVars.stackVars.at; + cacheEntry: i appliedVars.cacheVars.at; + cacheEntry @stackEntry changeVarValue + ] times + + newNode newNodeIndex @appliedVars applyStackChanges + a: @processor @block pop; + VarCond a getVar.data.get.end copy + ] [ + TRUE dynamic @loopIsDynamic set + FALSE + ] if + ] && + ] && + ] if + ] if + + iterationNumber 1 + @iterationNumber set + iterationNumber processor.options.staticLoopLengthLimit > [ + TRUE @processor.@result.!passErrorThroughPRE + ("Static loop length limit (" processor.options.staticLoopLengthLimit ") exceeded. Dynamize loop or increase limit using -static_loop_lenght_limit option") assembleString @processor block compilerError + ] when + + processor compilable and + ] loop + + loopIsDynamic [indexArray file processDynamicLoop] when +] "processLoop" exportFunction + { block: Block Ref; processor: Processor Ref; - asCodeRef: Cond; name: StringView Cref; signature: CFunctionSignature Cref;} Natx {} [ + asCodeRef: Cond; name: StringView Cref; signature: CFunctionSignature Cref;} Int32 {} [ block:; processor:; overload failProc: processor block FailProcForProcessor; @@ -2186,7 +2131,8 @@ processDynamicLoop: [ @processor addBlock declarationNode: @processor.@blocks.last.get; - block.id @declarationNode.@parent set + block.id @declarationNode.@parent set + @processor @block getTopNode @declarationNode.@topNode.set asCodeRef [NodeCaseCodeRefDeclaration][NodeCaseDeclaration] if @declarationNode.@nodeCase set signature.variadic @declarationNode.@variadic set @@ -2210,10 +2156,10 @@ processDynamicLoop: [ ] call signature.inputs [p:; a: @processor @block pop;] each - declarationNode storageAddress + declarationNode.id copy ] "processImportFunction" exportFunction -{block: Block Ref; processor: Processor Ref; +{block: Block Ref; processor: Processor Ref; asLambda: Cond; name: StringView Cref; file: File Cref; astNode: AstNode Cref; signature: CFunctionSignature Cref;} Int32 {} [ block:; processor:; @@ -2232,98 +2178,114 @@ processDynamicLoop: [ "export function cannot be variadic" @processor block compilerError ] when - ("process export: " makeStringView name makeStringView) addLog - - # we dont know count of used in export entites - signature.inputs.getSize [ - r: signature.inputs.getSize 1 - i - signature.inputs.at @processor @block copyVarFromChild; - r @processor @block makeVarTreeDynamic - @r @processor block unglobalize - @r fullUntemporize - r getVar.data.getTag VarRef = [ - @r @processor @block getPointeeNoDerefIR @block push - ] [ - TRUE @r.setMutable - r @block push - ] if - ] times + processor.options.partial ~ [ + topNode: block.topNode; + [topNode.file isNil ~] "Topnode in nil file!" assert + topNode.file.usedInParams copy + ] || [ + ("process export: " makeStringView name makeStringView) addLog + + # we dont know count of used in export entites + signature.inputs.getSize [ + r: signature.inputs.getSize 1 - i - signature.inputs.at @processor @block copyVarFromChild; + r @processor @block makeVarTreeDynamic + @r @processor block unglobalize + @r fullUntemporize + r getVar.data.getTag VarRef = [ + @r @processor @block getPointeeNoDerefIR @block push + ] [ + TRUE @r.setMutable + r @block push + ] if + ] times - oldSuccess: processor compilable; - oldRecursiveNodesStackSize: processor.recursiveNodesStack.getSize; + oldSuccess: processor compilable; + oldRecursiveNodesStackSize: processor.recursiveNodesStack.getSize; - newNodeIndex: @indexArray @processor @block tryMatchAllNodesForRealFunction; - newNodeIndex 0 < [ - nodeCase: asLambda [NodeCaseLambda][NodeCaseExport] if; - processor.exportDepth 1 + @processor.@exportDepth set - name block.id nodeCase indexArray file positionInfo signature @processor astNodeToCodeNode @newNodeIndex set - processor.exportDepth 1 - @processor.@exportDepth set - ] when + newNodeIndex: @indexArray @processor @block tryMatchAllNodesForRealFunction; + newNodeIndex 0 < [ + nodeCase: asLambda [NodeCaseLambda][NodeCaseExport] if; + processor.exportDepth 1 + @processor.@exportDepth set + name block.id nodeCase indexArray file positionInfo signature @processor astNodeToCodeNode @newNodeIndex set + processor.exportDepth 1 - @processor.@exportDepth set + ] when - successBeforeCaptures: processor.result.success copy; - TRUE @processor.@result.@success set + successBeforeCaptures: processor.result.success copy; + TRUE @processor.@result.@success set - newNode: newNodeIndex processor.blocks.at.get; - newNode.matchingInfo.shadowEvents [ - currentEvent:; - ( - ShadowReasonCapture [ - branch:; + newNode: newNodeIndex processor.blocks.at.get; + newNode.matchingInfo.shadowEvents [ + currentEvent:; + ( + 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; - ] - [] - ) currentEvent.visit - ] each + 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; + ] + [] + ) currentEvent.visit + ] each - successBeforeCaptures @processor.@result.@success set + successBeforeCaptures @processor.@result.@success set - processor compilable [ - newNodeIndex changeNewExportNodeState + processor compilable [ + newNodeIndex changeNewExportNodeState + + newNode: newNodeIndex processor.blocks.at.get; + newNode.outputs.getSize 1 > ["export function cant have 2 or more outputs" @processor block compilerError] when + newNode.outputs.getSize 1 = [signature.outputs.getSize 0 =] && ["signature is void, export function must be without output" @processor block compilerError] when + newNode.outputs.getSize 0 = [signature.outputs.getSize 1 =] && ["signature is not void, export function must have output" @processor block compilerError] when + newNode.state NodeStateCompiled = ~ [ + successBeforeCaptures [ + "can not implement lambda inside itself body" @processor block compilerError + ] when - newNode: newNodeIndex processor.blocks.at.get; - newNode.outputs.getSize 1 > ["export function cant have 2 or more outputs" @processor block compilerError] when - newNode.outputs.getSize 1 = [signature.outputs.getSize 0 =] && ["signature is void, export function must be without output" @processor block compilerError] when - newNode.outputs.getSize 0 = [signature.outputs.getSize 1 =] && ["signature is not void, export function must have output" @processor block compilerError] when - newNode.state NodeStateCompiled = ~ [ - successBeforeCaptures [ - "can not implement lambda inside itself body" @processor block compilerError + FALSE @oldSuccess set ] when - FALSE @oldSuccess set + processor compilable [ + signature.outputs.getSize [ + currentInNode: i newNode.outputs.at.refToVar; + currentInSignature: i signature.outputs.at; + + currentInNode currentInSignature variablesAreSame ~ [ + ("export function output mismatch, expected " currentInSignature @processor block getMplType ";" LF + "but found " currentInNode @processor block getMplType) assembleString @processor block compilerError + ] when + ] times + ] when ] when + signature.inputs [p:; a: @processor @block pop;] each + processor compilable [ - signature.outputs.getSize [ - currentInNode: i newNode.outputs.at.refToVar; - currentInSignature: i signature.outputs.at; + ("successfully processed export: " makeStringView name makeStringView) addLog + ] [ + ("failed while process export: " makeStringView name makeStringView) addLog + ] if - currentInNode currentInSignature variablesAreSame ~ [ - ("export function output mismatch, expected " currentInSignature @processor block getMplType ";" LF - "but found " currentInNode @processor block getMplType) assembleString @processor block compilerError - ] when - ] times - ] when - ] when + oldSuccess processor compilable ~ and processor.depthOfPre 0 = and processor.result.findModuleFail ~ and [ + @processor.@result.@errorInfo move @processor.@result.@globalErrorInfo.pushBack + oldRecursiveNodesStackSize @processor.@recursiveNodesStack.shrink + -1 @processor.@result clearProcessorResult - signature.inputs [p:; a: @processor @block pop;] each + signature name FALSE dynamic @processor @block processImportFunction !newNodeIndex + ] when - processor compilable [ - ("successfully processed export: " makeStringView name makeStringView) addLog + newNodeIndex ] [ - ("failed while process export: " makeStringView name makeStringView) addLog - ] if - - oldSuccess processor compilable ~ and processor.depthOfPre 0 = and processor.result.findModuleFail ~ and [ - @processor.@result.@errorInfo move @processor.@result.@globalErrorInfo.pushBack - oldRecursiveNodesStackSize @processor.@recursiveNodesStack.shrink - -1 @processor.@result clearProcessorResult + ("declare export from another file: " name) addLog + newNodeIndex: signature name FALSE dynamic @processor @block processImportFunction; + asLambda [ + block: newNodeIndex @processor.@blocks.at.get; + TRUE @block.@empty set + ] when - signature name FALSE dynamic @processor @block processImportFunction Block addressToReference .id copy !newNodeIndex - ] when + newNodeIndex + ] if - newNodeIndex ] "processExportFunction" exportFunction fixSourcesRec: [ @@ -2436,7 +2398,7 @@ callImportWith: [ ] loop ] [ forcedName: StringView; - inputs @outputs declarationNode forcedName refToVar dynamicFunc @block makeCallInstructionWith + inputs @outputs declarationNode forcedName refToVar dynamicFunc TRUE dynamic @processor @block makeCallInstructionWith i: 0 dynamic; [ i outputs.getSize < [ @@ -2456,6 +2418,8 @@ callImportWith: [ ] ) sequence + TRUE @block.@hasCallTrace set + @inputs @processor.releaseVarRefArray @outputs @processor.releaseVarRefArray ]; diff --git a/processor.mpl b/processor.mpl index 3ee28f9..c52c74a 100644 --- a/processor.mpl +++ b/processor.mpl @@ -1,22 +1,17 @@ -"Array.Array" use -"HashTable.HashTable" use -"Owner.Owner" use -"String.String" use -"String.StringView" use +"Array" use +"HashTable" use +"Owner" use +"String" use "control" use -"memory.debugMemory" use - -"Block.Block" use -"Block.CompilerPositionInfo" use -"Block.NameCaseInvalid" use -"File.File" use -"Mref.Mref" use -"NameManager.NameManager" use -"Var.RefToVar" use -"Var.Variable" use -"astNodeType.IndexArray" use -"astNodeType.MultiParserResult" use -"schemas.VariableSchema" use +"memory" use + +"Block" use +"MplFile" use +"Mref" use +"NameManager" use +"Var" use +"astNodeType" use +"schemas" use StringArray: [String Array]; @@ -27,15 +22,16 @@ DEFAULT_PRE_RECURSION_DEPTH_LIMIT: [64]; ProcessorOptions: [{ mainPath: String; fileNames: StringArray; + includePaths: StringArray; pointerSize: 64nx dynamic; staticLiterals: TRUE dynamic; debug: TRUE dynamic; debugMemory [ - debugMemory: TRUE dynamic; + debugMemory: FALSE dynamic; ] [] uif arrayChecks: TRUE dynamic; + partial: FALSE dynamic; autoRecursion: FALSE dynamic; - logs: FALSE dynamic; verboseIR: FALSE dynamic; callTrace: FALSE dynamic; threadModel: 0 dynamic; @@ -73,8 +69,9 @@ NameInfoEntry: [{ file: File Cref; refToVar: RefToVar; startPoint: -1 dynamic; # id of node - nameCase: NameCaseInvalid; mplFieldIndex: -1 dynamic; # for NameCaseSelfMember + isLocal: FALSE dynamic; + nameCase: NameCaseInvalid; }]; MatchingNode: [{ @@ -105,19 +102,20 @@ IRArgument: [{ NameInfoCoord: [{ block: ["Block.BlockSchema" use BlockSchema] Mref; - file: ["File.FileSchema" use FileSchema] Mref; + file: ["MplFile.FileSchema" use FileSchema] Mref; }]; Processor: [{ options: ProcessorOptions; - multiParserResult: MultiParserResult Cref; + multiParserResult: MultiParserResult Ref; result: ProcessorResult; positions: CompilerPositionInfo Array; + unfinishedFiles: IndexArray; files: File Owner Array; - #fileStack: File AsRef Array; - #file: [@fileStack.last.data]; # Currently processed File fileNameIds: String Int32 HashTable; + cmdFileNameIds: String String HashTable; + exportVarIds: Int32 RefToVar HashTable; blocks: Block Owner Array; variables: Variable Array Array; @@ -131,6 +129,7 @@ Processor: [{ 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 }; emptyNameInfo: -1 dynamic; @@ -153,6 +152,7 @@ Processor: [{ globalVarId: 0 dynamic; globalInitializer: -1 dynamic; # index of func for calling all initializers varForFails: RefToVar; + varForCallTrace: RefToVar; globalDestructibleVars: RefToVar Array; exportDepth: 0 dynamic; @@ -162,8 +162,9 @@ Processor: [{ schemaBuffer: VariableSchema Array; schemaTable: VariableSchema Int32 HashTable; - nameBuffer: String Array; - nameTable: StringView Int32 HashTable; #strings->nameTag; strings from nameBuffer + nameBuffer: String Array; + nameTable: StringView Int32 HashTable; #strings->nameTag; strings from nameBuffer + defaultVarNames: Int32 Array; depthOfRecursion: 0 dynamic; maxDepthOfRecursion: 0 dynamic; @@ -177,7 +178,7 @@ Processor: [{ acquireVarRefArray: [ varRefArrays.size 0 = [ - varRefArrayCount 15 = ["Too many varRef arrays requested\00" failProc] when + varRefArrayCount 20 = ["Too many varRef arrays requested\00" failProc] when varRefArrayCount 1 + !varRefArrayCount RefToVar Array ] [ @@ -214,9 +215,10 @@ Processor: [{ lastTypeId: 0 dynamic; unitId: 0 dynamic; # number of compiling unit - namedFunctions: String Int32 HashTable; # name -> node ID - moduleFunctions: Int32 Array; - dtorFunctions: Int32 Array; + namedFunctions: String Int32 HashTable; # name -> node ID + moduleFunctions: Int32 Array; + dtorFunctions: Int32 Array; + possibleUnstables: Int32 Array Array; #name -> array of blocks varCount: 0 dynamic; diff --git a/processorImpl.mpl b/processorImpl.mpl index 97c881e..2702d49 100644 --- a/processorImpl.mpl +++ b/processorImpl.mpl @@ -1,78 +1,84 @@ -"HashTable.HashTable" use -"Owner.owner" use -"String.String" use -"String.StringView" use -"String.addLog" use -"String.assembleString" use -"String.makeStringView" use -"String.toString" use +"HashTable" use +"Owner" use +"String" use "control" use -"memory.debugMemory" use - -"Block.BlockSchema" use -"Block.Capture" use -"Block.CFunctionSignature" use -"Block.CompilerPositionInfo" use -"Block.NodeCaseCode" use -"Block.NodeCaseDeclaration" use -"Block.NodeCaseDtor" use -"Block.ShadowEvent" use -"File.File" use -"NameManager.NameManager" use -"Var.Dirty" use -"Var.Dynamic" use -"Var.Field" use -"Var.RefToVar" use -"Var.ShadowReasonCapture" use -"Var.VarInvalid" use -"Var.VarSchema" use -"Var.VarStruct" use -"Var.getVar" use -"astNodeType.IndexArray" use -"astNodeType.MultiParserResult" use -"builtins.initBuiltins" use -"codeNode.addBlock" use -"codeNode.astNodeToCodeNode" use -"codeNode.createVariable" use -"codeNode.finalizeCodeNode" use -"codeNode.killStruct" use -"codeNode.makeStaticity" use -"codeNode.makeStorageStaticity" use -"debugWriter.addDebugProlog" use -"debugWriter.addDebugReserve" use -"debugWriter.addFileDebugInfo" use -"debugWriter.addLinkerOptionsDebugInfo" use -"debugWriter.clearUnusedDebugInfo" use -"debugWriter.correctUnitInfo" use -"declarations.makeShadows" use -"defaultImpl.FailProcForProcessor" use -"defaultImpl.compilable" use -"defaultImpl.findNameInfo" use -"defaultImpl.nodeHasCode" use -"irWriter.addAliasesForUsedNodes" use -"irWriter.addStrToProlog" use -"irWriter.createCallTraceData" use -"irWriter.createCtors" use -"irWriter.createDtors" use -"irWriter.createFloatBuiltins" use -"pathUtils.extractFilename" use -"pathUtils.stripExtension" use -"processSubNodes.clearProcessorResult" use -"processor.NameInfoEntry" use -"processor.Processor" use -"processor.ProcessorOptions" use +"memory" use + +"Block" use +"MplFile" use +"NameManager" use +"Var" use +"astNodeType" use +"astOptimizers" use +"builtins" use +"codeNode" use +"debugWriter" use +"declarations" use +"defaultImpl" use +"irWriter" use +"parser" use +"pathUtils" use +"processSubNodes" use +"processor" use +"variable" use debugMemory [ "memory.getMemoryMetrics" use ] [] uif +{ + nameManager: NameInfoEntry NameManager Ref; + multiParserResult: MultiParserResult Ref; + fileText: StringView Cref; + fileName: StringView Cref; + errorMessage: String Ref; +} () {} [ + errorMessage: fileName: fileText: multiParserResult: nameManager: ;;;;; + + parserResult: ParserResult; + @parserResult fileText makeStringView parseString + + parserResult.success [ + @parserResult optimizeLabels + @parserResult @nameManager optimizeNames + @parserResult @multiParserResult concatParserResult + String @errorMessage set + ] [ + (fileName "(" parserResult.errorInfo.position.line "," makeStringView parserResult.errorInfo.position.column "): syntax error, " + parserResult.errorInfo.message) assembleString @errorMessage set + ] if +] "addToProcessImpl" exportFunction + +{ + processor: Processor Ref; + fileName: StringView Cref; + fromCmd: Cond; +} Int32 {} [ + fromCmd: fileName: processor: ;;; + newFile: File; + + fileId: processor.files.getSize; + fileId @newFile.@fileId set + fileName toString @newFile.@name set + fromCmd @newFile.@usedInParams set + fileName toString fileId @processor.@fileNameIds.insert + + processor.options.debug [ + newFile.name @processor addFileDebugInfo @newFile.!debugId + ] when + + @newFile move owner @processor.@files.pushBack + #here we can implement search in cmd + fileId +] "addFileNameToProcessor" exportFunction + { program: String Ref; result: String Ref; unitId: 0; options: ProcessorOptions Cref; nameManager: NameInfoEntry NameManager Ref; - multiParserResult: MultiParserResult Cref; + multiParserResult: MultiParserResult Ref; } () {} [ program:; result:; @@ -86,7 +92,7 @@ debugMemory [ unitId @processor.@unitId set @nameManager move @processor.@nameManager set @options @processor.@options set - multiParserResult @processor.!multiParserResult + @multiParserResult @processor.!multiParserResult "" makeStringView @processor findNameInfo @processor.@emptyNameInfo set "CALL" makeStringView @processor findNameInfo @processor.@callNameInfo set @@ -106,6 +112,19 @@ debugMemory [ @processor addBlock TRUE dynamic @processor.@blocks.last.get.@root set + errorInCmdNames: FALSE dynamic; + processor.options.fileNames [ + current:; + errorInCmdNames ~ [ + #here set first parameter to TRUE to make cmd files visible + TRUE current makeStringView @processor addFileNameToProcessor 0 < [ + TRUE !errorInCmdNames + ] when + ] when + ] each + + @processor.@blocks.last.get 0 @processor.@files.at.get.@rootBlock.set + @processor initBuiltins [ @@ -133,25 +152,13 @@ debugMemory [ @processor addLinkerOptionsDebugInfo - processor.options.fileNames.size @processor.@files.resize - processor.options.fileNames.size [ - File owner i @processor.@files.at set - i processor.options.fileNames.at i @processor.@files.at.get.@name set - i processor.options.fileNames.at stripExtension extractFilename toString i @processor.@fileNameIds.insert - ] times - processor.options.debug [ @processor [processor:; @processor addDebugProlog @processor.@debugInfo.@unit set] call - - processor.files.size [ - i processor.files.at.get.name @processor addFileDebugInfo i @processor.@files.at.get.!debugId - ] times ] when lastFile: File Cref; multiParserResult.nodes.size 0 > [ - dependedFiles: String IndexArray HashTable; # string -> array of indexes of dependent files cachedGlobalErrorInfoSize: 0; @@ -159,7 +166,7 @@ debugMemory [ n:; file: n @processor.@files.at.get; file !lastFile - fileNode: n processor.multiParserResult.nodes.at; + fileNode: n 1 - processor.multiParserResult.nodes.at.get; rootPositionInfo: CompilerPositionInfo; file @rootPositionInfo.@file.set 1 @rootPositionInfo.!line @@ -187,7 +194,6 @@ debugMemory [ topNodeIndex @processor.@blocks.at.get @file.@rootBlock.set - moduleName stripExtension extractFilename toString !moduleName moduleName topNodeIndex @processor.@modules.insert # call files which depends from this module @@ -199,7 +205,7 @@ debugMemory [ i fr.value.size < [ numberOfDependent: fr.value.size 1 - i - fr.value.at; (numberOfDependent processor.files.at.get.name " is dependent from it, try to recompile") addLog - numberOfDependent @unfinishedFiles.pushBack + numberOfDependent @processor.@unfinishedFiles.pushBack i 1 + @i set TRUE ] && ] loop @@ -211,19 +217,18 @@ debugMemory [ ] if ]; - unfinishedFiles: IndexArray; n: 0 dynamic; [ n processor.multiParserResult.nodes.size < [ - processor.multiParserResult.nodes.size 1 - n - @unfinishedFiles.pushBack + processor.multiParserResult.nodes.size n - @processor.@unfinishedFiles.pushBack n 1 + @n set TRUE ] && ] loop [ - 0 unfinishedFiles.size < [ - n: unfinishedFiles.last copy; - @unfinishedFiles.popBack + 0 processor.unfinishedFiles.size < [ + n: processor.unfinishedFiles.last copy; + @processor.@unfinishedFiles.popBack n runFile processor.result.success copy ] && @@ -292,125 +297,149 @@ debugMemory [ ("max depth of recursion=" processor.maxDepthOfRecursion) addLog - varHeadMemory: 0nx; - varShadowMemory: 0nx; - totalFieldCount: 0; - - varStaticStoragedMemory: 0nx; - varDynamicStoragedHeadMemory: 0nx; - varDynamicStoragedShadowMemory: 0nx; - - getCoordsMemory: [ - where:; - - result: 0nx; - where.dataReserve Natx cast where.elementSize * result + !result - where [ - where1:; - where1.dataReserve Natx cast where1.elementSize * result + !result - where1 [ - where2:; - where2.dataReserve Natx cast where2.elementSize * result + !result + hasLogs [ + varHeadMemory: 0nx; + varShadowMemory: 0nx; + totalFieldCount: 0; + + varStaticStoragedMemory: 0nx; + varDynamicStoragedHeadMemory: 0nx; + varDynamicStoragedShadowMemory: 0nx; + + getCoordsMemory: [ + where:; + + result: 0nx; + where.dataReserve Natx cast where.elementSize * result + !result + where [ + where1:; + where1.dataReserve Natx cast where1.elementSize * result + !result + where1 [ + where2:; + where2.dataReserve Natx cast where2.elementSize * result + !result + ] each ] each - ] each - result - ]; - - coordsMemory: - processor.captureTable.simpleNames getCoordsMemory - processor.captureTable.selfNames getCoordsMemory + - processor.captureTable.closureNames getCoordsMemory +; + result + ]; - getVariableUsedMemory: [ - var:; + coordsMemory: + processor.captureTable.simpleNames getCoordsMemory + processor.captureTable.selfNames getCoordsMemory + + processor.captureTable.closureNames getCoordsMemory +; - var.data.getTag VarStruct = [ - struct: VarStruct var.data.get.get; - struct storageSize struct.fields.size Natx cast Field storageSize * + - var storageSize + - ] [ - var storageSize - ] if - ]; - - processor.variables [ - [ + getVariableUsedMemory: [ var:; - varSize: var getVariableUsedMemory; - var.capturedHead getVar.host var.host is ~ [ - varSize varShadowMemory + !varShadowMemory + var.data.getTag VarStruct = [ + struct: VarStruct var.data.get.get; + struct storageSize struct.fields.size Natx cast Field storageSize * + + var storageSize + ] [ - varSize varHeadMemory + !varHeadMemory + var storageSize ] if + ]; - var.data.getTag VarStruct = [ - VarStruct var.data.get.get.fields.size totalFieldCount + !totalFieldCount - ] when + processor.variables [ + [ + var:; + varSize: var getVariableUsedMemory; - var.storageStaticity Dynamic = [ - var.topologyIndex 0 < ~ [ - varSize varDynamicStoragedShadowMemory + !varDynamicStoragedShadowMemory + var.capturedHead getVar.host var.host is ~ [ + varSize varShadowMemory + !varShadowMemory ] [ - varSize varDynamicStoragedHeadMemory + !varDynamicStoragedHeadMemory + varSize varHeadMemory + !varHeadMemory ] if - ] [ - varSize varStaticStoragedMemory + !varStaticStoragedMemory - ] if - ] each - ] each - beventCount: 0; - meventCount: 0; - captureCount: 0; - globalCaptureCount: 0; - failedCaptureCount: 0; - dependentsSize: 0; - - eventTagCount: Int32 6 array; - - processor.blocks [ - block: .get; - block.buildingMatchingInfo.shadowEvents.size beventCount + !beventCount - block.matchingInfo.shadowEvents.size meventCount + !meventCount - block.matchingInfo.captures.size captureCount + !captureCount - block.dependentPointers.size dependentsSize + !dependentsSize - - block.matchingInfo.shadowEvents [ - event:; - src: event.getTag @eventTagCount @; - src 1 + @src set - - event.getTag ShadowReasonCapture = [ - branch: ShadowReasonCapture event.get; - branch.refToVar getVar processor.varForFails getVar is [ - failedCaptureCount 1 + !failedCaptureCount + var.data.getTag VarStruct = [ + VarStruct var.data.get.get.fields.size totalFieldCount + !totalFieldCount ] when - branch.refToVar getVar.global [ - globalCaptureCount 1 + !globalCaptureCount + var.storageStaticity Dynamic = [ + var.topologyIndex 0 < ~ [ + varSize varDynamicStoragedShadowMemory + !varDynamicStoragedShadowMemory + ] [ + varSize varDynamicStoragedHeadMemory + !varDynamicStoragedHeadMemory + ] if + ] [ + varSize varStaticStoragedMemory + !varStaticStoragedMemory + ] if + ] each + ] each + + beventCount: 0; + meventCount: 0; + captureCount: 0; + virtualCaptureCount: 0; + stringCaptureCount: 0; + failedCaptureCount: 0; + dependentsSize: 0; + failedCaptureNames: StringView Int32 HashTable; + + eventTagCount: Int32 ShadowEvent.typeList fieldCount array; + + processor.blocks [ + block: .get; + block.buildingMatchingInfo.shadowEvents.size beventCount + !beventCount + block.matchingInfo.shadowEvents.size meventCount + !meventCount + block.matchingInfo.captures.size captureCount + !captureCount + block.dependentPointers.size dependentsSize + !dependentsSize + + block.matchingInfo.shadowEvents [ + event:; + src: event.getTag @eventTagCount @; + src 1 + @src set + + 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 + ] when ] when - ] when + ] each ] each - ] each - ( - debugMemory ["; currentAllocationSize=" getMemoryMetrics.memoryCurrentAllocationSize] [] uif - "; coordsMemory=" coordsMemory - "; varShadowMemory=" varShadowMemory "; varHeadMemory=" varHeadMemory - "; varDynamicStoragedHeadMemory=" varDynamicStoragedHeadMemory - "; varDynamicStoragedShadowMemory=" varDynamicStoragedShadowMemory - "; varStaticStoragedMemory=" varStaticStoragedMemory - "; totalFieldCount=" totalFieldCount "; fieldSize=" Field storageSize - "; beventCount=" beventCount - "; meventCount=" meventCount - "; meventCountByTag=" 0 eventTagCount @ ":" 1 eventTagCount @ ":" 2 eventTagCount @ ":" 3 eventTagCount @ ":" 4 eventTagCount @ ":" 5 eventTagCount @ - "; eventSize=" ShadowEvent storageSize - "; captureCount=" captureCount "; failedCaptureCount=" failedCaptureCount "; globalCaptureCount=" globalCaptureCount - "; captureSize=" Capture storageSize - "; dependentPointersCount=" dependentsSize "; dependentPointer size=" (RefToVar RefToVar FALSE dynamic) storageSize - ) addLog + ( + debugMemory ["; currentAllocationSize=" getMemoryMetrics.memoryCurrentAllocationSize] [] uif + "; coordsMemory=" coordsMemory + "; varShadowMemory=" varShadowMemory "; varHeadMemory=" varHeadMemory + "; varDynamicStoragedHeadMemory=" varDynamicStoragedHeadMemory + "; varDynamicStoragedShadowMemory=" varDynamicStoragedShadowMemory + "; varStaticStoragedMemory=" varStaticStoragedMemory + "; totalFieldCount=" totalFieldCount "; fieldSize=" Field storageSize + "; beventCount=" beventCount + "; meventCount=" meventCount + "; meventCountByTag=" 0 eventTagCount @ ":" 1 eventTagCount @ ":" 2 eventTagCount @ ":" 3 eventTagCount @ ":" 4 eventTagCount @ ":" 5 eventTagCount @ + "; eventSize=" ShadowEvent storageSize + ) addLog + + ( + "; captureCount=" captureCount "; failedCaptureCount=" failedCaptureCount "; stringCaptureCount=" stringCaptureCount "; virtualCaptureCount=" virtualCaptureCount + "; captureSize=" Capture storageSize + "; dependentPointersCount=" dependentsSize "; dependentPointer size=" (RefToVar RefToVar FALSE dynamic) storageSize + ) addLog + + ("failed captureNames:") addLog + failedCaptureNames [ + pair:; + ("name=" pair.key "; count=" pair.value) addLog + ] each + ] when processor.usedFloatBuiltins [@processor createFloatBuiltins] when processor.options.callTrace processor.options.threadModel 1 = and @processor createCtors @@ -493,11 +522,13 @@ debugMemory [ { processor: Processor Ref; + file: File Cref; signature: CFunctionSignature Cref; compilerPositionInfo: CompilerPositionInfo Cref; refToVar: RefToVar Cref; } () {} [ processor:; + file:; forcedSignature:; compilerPositionInfo:; refToVar:; @@ -505,11 +536,12 @@ debugMemory [ @processor addBlock codeNode: @processor.@blocks.last.get; block: @codeNode; - compilerPositionInfo @codeNode.@beginPosition set overload failProc: processor block FailProcForProcessor; - NodeCaseDtor @codeNode.@nodeCase set - 0 dynamic @codeNode.@parent set + NodeCaseDtor @codeNode.@nodeCase set + 0 dynamic @codeNode.@parent set + file @codeNode.@file.set + @processor @codeNode getTopNode @codeNode.@topNode.set @compilerPositionInfo @processor.@positions.last set processor.options.debug [ diff --git a/schemas.mpl b/schemas.mpl index e337bea..7df027f 100644 --- a/schemas.mpl +++ b/schemas.mpl @@ -1,34 +1,9 @@ -"Array.Array" use -"String.String" use -"String.hash" use -"Variant.Variant" use +"Array" use +"String" use +"Variant" use "control" use -"Var.RefToVar" use -"Var.VarBuiltin" use -"Var.VarCode" use -"Var.VarCond" use -"Var.VarEnd" use -"Var.VarImport" use -"Var.VarInt16" use -"Var.VarInt32" use -"Var.VarInt64" use -"Var.VarInt8" use -"Var.VarIntX" use -"Var.VarInvalid" use -"Var.VarNat16" use -"Var.VarNat32" use -"Var.VarNat64" use -"Var.VarNat8" use -"Var.VarNatX" use -"Var.VarReal32" use -"Var.VarReal64" use -"Var.VarRef" use -"Var.VarString" use -"Var.VarStruct" use -"Var.getVar" use -"Var.getVirtualValue" use -"Var.isVirtual" use +"Var" use makeVariableSchema: [ refToVar: processor: ;; @@ -293,11 +268,11 @@ hashValue: [Int8 same] [Nat32 cast] pfunc; hashValue: [Int16 same] [Nat32 cast] pfunc; hashValue: [Int32 same] [Nat32 cast] pfunc; hashValue: [Int64 same] [Nat64 cast Nat32 cast] pfunc; -hashValue: [IntX same] [Nat64 cast Nat32 cast] pfunc; +hashValue: [Intx same] [Nat64 cast Nat32 cast] pfunc; hashValue: [Nat8 same] [Nat32 cast] pfunc; hashValue: [Nat16 same] [Nat32 cast] pfunc; hashValue: [Nat32 same] [Nat32 cast] pfunc; hashValue: [Nat32 same] [Nat32 cast] pfunc; hashValue: [Nat64 same] [Nat32 cast] pfunc; -hashValue: [NatX same] [Nat32 cast] pfunc; +hashValue: [Natx same] [Nat32 cast] pfunc; hashValue: [Cond same] [[1n32] [0n32] if] pfunc; diff --git a/staticCall.mpl b/staticCall.mpl index b8e575f..98f8719 100644 --- a/staticCall.mpl +++ b/staticCall.mpl @@ -1,5 +1,4 @@ -"String.addLog" use -"String.makeStringView" use +"String" use "control" use staticCall: [ diff --git a/variable.mpl b/variable.mpl index 36d55ef..7bd1ebb 100644 --- a/variable.mpl +++ b/variable.mpl @@ -1,89 +1,19 @@ -"Array.Array" use -"HashTable.hash" use -"String.String" use -"String.StringView" use -"String.addLog" use -"String.asView" use -"String.assembleString" use -"String.hash" use -"String.makeStringView" use -"String.print" use -"String.splitString" use -"String.toString" use +"Array" use +"HashTable" use +"String" use "control" use -"conventions.cdecl" use - -"Block.Block" use -"Block.CFunctionSignature" use -"Block.CompilerPositionInfo" use -"Block.NameCaseInvalid" use -"Block.NodeCaseCode" use -"File.File" use -"Var.Dirty" use -"Var.Dynamic" use -"Var.RefToVar" use -"Var.Static" use -"Var.VarBuiltin" use -"Var.VarCode" use -"Var.VarCond" use -"Var.VarImport" use -"Var.VarInt16" use -"Var.VarInt32" use -"Var.VarInt64" use -"Var.VarInt8" use -"Var.VarIntX" use -"Var.VarInvalid" use -"Var.VarNat16" use -"Var.VarNat32" use -"Var.VarNat64" use -"Var.VarNat8" use -"Var.VarNatX" use -"Var.VarReal32" use -"Var.VarReal64" use -"Var.VarRef" use -"Var.VarString" use -"Var.VarStruct" use -"Var.Variable" use -"Var.Virtual" use -"Var.Virtual" use -"Var.Weak" use -"Var.getAlignment" use -"Var.getSingleDataStorageSize" use -"Var.getStorageSize" use -"Var.getStringImplementation" use -"Var.getStructStorageSize" use -"Var.getVar" use -"Var.getVirtualValue" use -"Var.isAutoStruct" use -"Var.isNonrecursiveType" use -"Var.isPlain" use -"Var.isSingle" use -"Var.isStruct" use -"Var.isVirtual" use -"Var.isVirtualType" use -"Var.makeStringId" use -"Var.staticityOfVar" use -"Var.variablesAreSame" use -"astNodeType.AstNode" use -"astNodeType.IndexArray" use -"debugWriter.getDbgType" use -"debugWriter.getTypeDebugDeclaration" use -"declarations.compilerError" use -"declarations.generateDebugTypeId" use -"declarations.generateIrTypeId" use -"declarations.getMplType" use -"defaultImpl.FailProcForProcessor" use -"irWriter.createTypeDeclaration" use -"irWriter.generateRegisterIRName" use -"irWriter.generateVariableIRNameWith" use -"irWriter.getIrType" use -"irWriter.getMplSchema" use -"irWriter.getNameById" use -"processor.Processor" use -"processor.ProcessorResult" use -"processor.RefToVarTable" use -"schemas.getVariableSchemaId" use -"schemas.makeVariableSchema" use +"conventions" use + +"Block" use +"MplFile" use +"Var" use +"astNodeType" use +"debugWriter" use +"declarations" use +"defaultImpl" use +"irWriter" use +"processor" use +"schemas" use Overload: [NameInfoEntry Array];