diff --git a/Block.mpl b/Block.mpl index 1d7910e..6d0880a 100644 --- a/Block.mpl +++ b/Block.mpl @@ -237,6 +237,8 @@ Block: [{ lastBrLabelName: 0 dynamic; variableCountDelta: 0 dynamic; + nextStringAttribute: String; + INIT: []; DIE: []; }]; diff --git a/Var.mpl b/Var.mpl index 9b91073..d39e706 100644 --- a/Var.mpl +++ b/Var.mpl @@ -445,15 +445,32 @@ getPlainValueInformation: [ var: getVar; result: String; - var.staticity.end Weak < [ - " dynamic" toString !result + var.staticity.end Dirty = [ + " dirty" toString !result ] [ - var.data.getTag VarCond VarReal64 1 + [ - tag: new; - branch: tag var.data.get; - (" static: " branch.end) assembleString !result - ] staticCall + var.staticity.end Dynamic = [ + " dynamic" toString !result + ] [ + var.staticity.end Weak = [ + " weak:" toString !result + ] [ + var.staticity.end Static = [ + " static:" toString !result + ] [ + var.staticity.end Virtual = [ + " virtual:" toString !result + ] when + ] if + ] if + + var.data.getTag VarCond VarReal64 1 + [ + tag: new; + branch: tag var.data.get; + (" " branch.end) assembleString @result.cat + ] staticCall + ] if ] if + result ]; diff --git a/astNodeType.mpl b/astNodeType.mpl index e3aaaad..dcf6c41 100644 --- a/astNodeType.mpl +++ b/astNodeType.mpl @@ -53,14 +53,15 @@ NamedBranch: [{ }]; makePositionInfo: [{ - token: String; - column: new; - line: new; - offset: new; - fileId: new; + token: String; + column: new; + line: new; + offsetStart: new; + offsetEnd: new; + fileId: new; }]; -PositionInfo: [-1 dynamic -1 dynamic 1 dynamic 0 dynamic makePositionInfo]; +PositionInfo: [-1 dynamic -1 dynamic -1 dynamic 1 dynamic 0 dynamic makePositionInfo]; AstNode: [{ virtual AST_NODE: (); diff --git a/builtinImpl.mpl b/builtinImpl.mpl index f89724d..eb524ed 100644 --- a/builtinImpl.mpl +++ b/builtinImpl.mpl @@ -775,6 +775,22 @@ staticityOfBinResult: [ ] when ] "mplBuiltinArray" @declareBuiltin ucall +[ + ( + [processor compilable] + [refToText: @processor @block pop;] + [ + refToText staticityOfVar Weak < ["name must be static string" @processor block compilerError] when + ] [ + varText: refToText getVar; + varText.data.getTag VarString = ~ ["name must be static string" @processor block compilerError] when + ] [ + block: 0 @processor.@blocks.at.get; + VarString varText.data.get new @block.!nextStringAttribute + ] + ) sequence +] "mplBuiltinAttribute" @declareBuiltin ucall + [ @processor @block defaultCall ] "mplBuiltinCall" @declareBuiltin ucall @@ -935,6 +951,41 @@ staticityOfBinResult: [ ] when ] "mplBuiltinCodeRefQuestion" @declareBuiltin ucall +[ + refToCode: @processor @block pop; + processor compilable [ + code: refToCode getVar; + code.data.getTag VarCode = ~ ["must be [CODE]" @processor block compilerError] [ + astNodeArray: VarCode code.data.get.index processor.multiParserResult.memory.at; + astNodeArray.nodes.size Int64 cast makeValuePair VarInt32 @processor @block createVariable Static @processor @block makeStaticity @processor @block createPlainIR @block push + ] if + ] when +] "mplBuiltinCodeTokenCount" @declareBuiltin ucall + +[ + refToOrdinal: @processor @block pop; + refToCode: @processor @block pop; + processor compilable [ + varCode: refToCode getVar; + varOrdinal: refToOrdinal getVar; + varCode.data.getTag VarCode = ~ ["First argument must be [CODE]" @processor block compilerError] [ + varOrdinal.data.getTag VarInt32 = ~ ["Ordinal must be Int32" @processor block compilerError] [ + refToOrdinal staticityOfVar Weak < ["Ordinal must be static" @processor block compilerError] [ + astNodeArray: VarCode varCode.data.get.index processor.multiParserResult.memory.at; + ordinal: VarInt32 varOrdinal.data.get.end Int32 cast; + ordinal 0 astNodeArray.nodes.size within ~ ["Ordinal is out of bounds" @processor block compilerError] [ + astNode: ordinal astNodeArray.nodes @; + ordinal astNodeArray.nodes @ .positionInfo.fileId processor.files.at.get.text.getStringView + ordinal astNodeArray.nodes @ .positionInfo.offsetStart + ordinal astNodeArray.nodes @ .positionInfo.offsetEnd range + @processor @block makeVarString @block push + ] if + ] if + ] if + ] if + ] when +] "mplBuiltinCodeTokenRead" @declareBuiltin ucall + [ TRUE dynamic @block.@nodeCompileOnce set ] "mplBuiltinCompileOnce" @declareBuiltin ucall @@ -1887,7 +1938,7 @@ tryFindInPath: [ loadStringResult.success [ errorInfo: processor.files.getSize fullFileName makeStringView loadStringResult.data makeStringView @processor.@multiParserResult @processor.@nameManager addToProcess; errorInfo "" = [ - fileId: FALSE fullFileName makeStringView @processor addFileNameToProcessor; + fileId: FALSE fullFileName makeStringView loadStringResult.data makeStringView @processor addFileNameToProcessor; fullFileName @processor.@options.@fileNames.append fileId @processor.@unfinishedFiles.append @fullFileName @result.@fullFileName set diff --git a/builtins.mpl b/builtins.mpl index 8b04ca2..7deedcf 100644 --- a/builtins.mpl +++ b/builtins.mpl @@ -36,6 +36,7 @@ builtins: ( {name: "alignment" ; impl: @mplBuiltinAlignment ;} {name: "and" ; impl: @mplBuiltinAnd ;} {name: "array" ; impl: @mplBuiltinArray ;} + {name: "attribute" ; impl: @mplBuiltinAttribute ;} {name: "call" ; impl: @mplBuiltinCall ;} {name: "callField" ; impl: @mplBuiltinCallField ;} {name: "cast" ; impl: @mplBuiltinCast ;} @@ -43,6 +44,8 @@ builtins: ( {name: "code?" ; impl: @mplBuiltinCodeQuestion ;} {name: "codeRef" ; impl: @mplBuiltinCodeRef ;} {name: "codeRef?" ; impl: @mplBuiltinCodeRefQuestion ;} + {name: "codeTokenCount" ; impl: @mplBuiltinCodeTokenCount ;} + {name: "codeTokenRead" ; impl: @mplBuiltinCodeTokenRead ;} {name: "compileOnce" ; impl: @mplBuiltinCompileOnce ;} {name: "const" ; impl: @mplBuiltinConst ;} {name: "cos" ; impl: @mplBuiltinCos ;} diff --git a/codeNode.mpl b/codeNode.mpl index ce4dd00..2f4bb29 100644 --- a/codeNode.mpl +++ b/codeNode.mpl @@ -2370,7 +2370,7 @@ addBlock: [ block: 0 @processor.@blocks.at.get; string VarString @processor @block createVariable @refToVar set - string.getStringView @refToVar @processor createStringIR + string.getStringView @refToVar @processor @block createStringIR string refToVar @processor.@stringNames.insert @refToVar fullUntemporize @@ -2384,6 +2384,7 @@ addBlock: [ } @processor @block addNameInfo ] if + 0 0 @processor.@blocks.at.get .@nextStringAttribute.resize gnr: refToVar getVar.mplNameId @processor @block getName; cnr: @gnr 0 dynamic @processor @block processor.positions.last.file captureName; diff --git a/declarations.mpl b/declarations.mpl index 74766c4..c11bf86 100644 --- a/declarations.mpl +++ b/declarations.mpl @@ -358,6 +358,7 @@ addToProcess: [ { processor: Processor Ref; + fileText: StringView Cref; fileName: StringView Cref; fromCmd: Cond; } Int32 {} "addFileNameToProcessor" importFunction diff --git a/irWriter.mpl b/irWriter.mpl index 502a4df..042e909 100644 --- a/irWriter.mpl +++ b/irWriter.mpl @@ -207,6 +207,7 @@ createPlainIR: [ ]; createStringIR: [ + block:; processor:; refToVar:; string:; @@ -221,7 +222,13 @@ createStringIR: [ valueImplementation: string getStringImplementation; - (stringName " = private unnamed_addr constant {i32, [" string.size " x i8]} {i32 " string.size ", [" string.size " x i8] c\"" valueImplementation "\"}") assembleString @processor.@prolog.append + prolog: (stringName " = private unnamed_addr constant {i32, [" string.size " x i8]} {i32 " string.size ", [" string.size " x i8] c\"" valueImplementation "\"}") assembleString; + block.nextStringAttribute.size 0 = ~ [ + ", " @prolog.cat + block.nextStringAttribute @prolog.cat + ] when + + @prolog @processor.@prolog.append ]; createGetTextSizeIR: [ diff --git a/main.mpl b/main.mpl index 324014d..b571c6c 100644 --- a/main.mpl +++ b/main.mpl @@ -407,6 +407,7 @@ checkedSaveString: [ ("MPL compiler version " COMPILER_SOURCE_VERSION LF) printList "Input files ignored" print LF print ] [ + options.fileNames.size @options.@fileTexts.resize options.fileNames.getSize [ fileName: i options.fileNames @; @@ -421,6 +422,7 @@ checkedSaveString: [ ("Loaded string from " fileName) addLog ("HASH=" loadStringResult.data hash) addLog i fileName makeStringView loadStringResult.data makeStringView @multiParserResult @nameManager addToProcessAndCheck + @loadStringResult.@data i @options.@fileTexts ! ] [ "Unable to load string:" print fileName print LF print FALSE @success set diff --git a/parser.mpl b/parser.mpl index 933b10d..4b64a68 100644 --- a/parser.mpl +++ b/parser.mpl @@ -35,7 +35,8 @@ codeunitTail?: [ fillPositionInfo: [ astNode:; - lastPosition @astNode.@positionInfo set + lastPosition @astNode.@positionInfo set + currentPosition.offsetStart new @astNode.@positionInfo.!offsetEnd ]; addToMainResult: [ @@ -382,8 +383,8 @@ inArray: [ undo: [ mainResult.success [ prevPosition @currentPosition set - currentPosition.offset 0 < ~ [ - currentPosition.offset splittedString.chars.at @currentSymbol set + currentPosition.offsetStart 0 < ~ [ + currentPosition.offsetStart splittedString.chars.at @currentSymbol set currentSymbol.data Nat32 cast @currentCode set ] [ StringView @currentSymbol set @@ -401,12 +402,12 @@ iterate: [ currentPosition.line 1 + @currentPosition.@line set ] when - fileId @currentPosition.@fileId set - currentPosition.offset 1 + @currentPosition.@offset set - currentPosition.column 1 + @currentPosition.@column set + fileId @currentPosition.@fileId set + currentPosition.offsetStart 1 + @currentPosition.@offsetStart set + currentPosition.column 1 + @currentPosition.@column set - currentPosition.offset splittedString.chars.getSize < [ - currentPosition.offset splittedString.chars.at @currentSymbol set + currentPosition.offsetStart splittedString.chars.getSize < [ + currentPosition.offsetStart splittedString.chars.at @currentSymbol set currentSymbol.data Nat32 cast @currentCode set ] [ StringView @currentSymbol set @@ -562,7 +563,7 @@ parseDecNumber: [ #3 after n/r result: 0 dynamic; - tokenBegin: currentPosition.offset hasMinus [1 -][new] if; + tokenBegin: currentPosition.offsetStart hasMinus [1 -][new] if; tokenEnd: tokenBegin new; [ @@ -631,7 +632,7 @@ parseDecNumber: [ ] if p:; - p [currentPosition.offset @tokenEnd set] when + p [currentPosition.offsetStart @tokenEnd set] when p mainResult.success and ] loop @@ -743,7 +744,7 @@ parseHexNumber: [ #1 after n result: 0 dynamic; - tokenBegin: currentPosition.offset hasMinus [3 -][2 -] if; + tokenBegin: currentPosition.offsetStart hasMinus [3 -][2 -] if; tokenEnd: tokenBegin new; [ @@ -781,7 +782,7 @@ parseHexNumber: [ ] if p:; - p [ currentPosition.offset @tokenEnd set ] when + p [ currentPosition.offsetStart @tokenEnd set ] when p mainResult.success and ] loop @@ -900,8 +901,8 @@ parseName: [ read: FALSE dynamic; write: FALSE dynamic; label: FALSE dynamic; - checkOffset: currentPosition.offset new; - checkFirst: [currentPosition.offset checkOffset > ["invalid identifier" lexicalError] when]; + checkOffset: currentPosition.offsetStart new; + checkFirst: [currentPosition.offsetStart checkOffset > ["invalid identifier" lexicalError] when]; nameSymbols: StringView Array; first: TRUE dynamic; @@ -1118,46 +1119,51 @@ parseNode: [ @unfinishedPositions.popBack currentCode ascii.closeRBr = [ + iterate @unfinishedNodes.last makeListNode @unfinishedNodes.popBack @unfinishedTerminators.popBack addToLastUnfinished ] [ currentCode ascii.closeSBr = [ + iterate @unfinishedNodes.last makeCodeNode @unfinishedNodes.popBack @unfinishedTerminators.popBack addToLastUnfinished ] [ currentCode ascii.closeFBr = [ + iterate @unfinishedNodes.last makeObjectNode @unfinishedNodes.popBack @unfinishedTerminators.popBack addToLastUnfinished ] [ - currentCode ascii.null = [ - unfinishedNodes.getSize 1 = ~ [ - "unexpected end of the file!" makeStringView lexicalError - ] when - 0 @unfinishedNodes.at addToMainResult @mainResult.@root set + currentCode ascii.semicolon = [ + iterate + @unfinishedLabelNames.last @unfinishedNodes.last makeLabelNode @unfinishedNodes.popBack @unfinishedTerminators.popBack + @unfinishedLabelNames.popBack + addToLastUnfinished ] [ - currentCode ascii.semicolon = [ - @unfinishedLabelNames.last @unfinishedNodes.last makeLabelNode + currentCode ascii.null = [ + unfinishedNodes.getSize 1 = ~ [ + "unexpected end of the file!" makeStringView lexicalError + ] when + 0 @unfinishedNodes.at addToMainResult @mainResult.@root set @unfinishedNodes.popBack @unfinishedTerminators.popBack - @unfinishedLabelNames.popBack - addToLastUnfinished ] [ "unknown terminator" makeStringView lexicalError ] if + + iterate ] if ] if ] if ] if ] if - iterate currentCode pc.specials inArray ~ [currentCode ascii.comma = ~] && @@ -1231,7 +1237,7 @@ parseNode: [ ] [ FALSE @mainResult.@success set ("wrong encoding, can not recognize line and column, offset in bytes: " splittedString.errorOffset) assembleString @mainResult.@errorInfo.@message set - splittedString.errorOffset 0 cast @mainResult.@errorInfo.@position.@offset set + splittedString.errorOffset 0 cast @mainResult.@errorInfo.@position.@offsetStart set 0 @mainResult.@errorInfo.@position.@line set splittedString.errorOffset 0 cast @mainResult.@errorInfo.@position.@column set ] if diff --git a/processor.mpl b/processor.mpl index 9a95755..76e645f 100644 --- a/processor.mpl +++ b/processor.mpl @@ -37,6 +37,7 @@ ProcessorOptions: [{ beginFunc: String; endFunc: String; fileNames: StringArray; + fileTexts: StringArray; includePaths: StringArray; hidePrefixes: StringArray; pointerSize: 64nx dynamic; diff --git a/processorImpl.mpl b/processorImpl.mpl index 7d232f4..43a0e1c 100644 --- a/processorImpl.mpl +++ b/processorImpl.mpl @@ -62,16 +62,18 @@ debugMemory [ { processor: Processor Ref; + fileText: StringView Cref; fileName: StringView Cref; fromCmd: Cond; } Int32 {} [ - fromCmd: fileName: processor: ;;; + fromCmd: fileName: fileText: processor:;;;; newFile: File; fileId: processor.files.getSize; - fileId @newFile.@fileId set fileName toString @newFile.@name set fromCmd @newFile.@usedInParams set + fileId @newFile.@fileId set + fileText toString @newFile.@text set fileName toString fileId @processor.@fileNameIds.insert processor.options.debug [ @@ -125,15 +127,14 @@ debugMemory [ TRUE dynamic @processor.@blocks.last.get.@root set errorInCmdNames: FALSE dynamic; - processor.options.fileNames [ - current:; + processor.options.fileNames.size [ errorInCmdNames ~ [ #here set first parameter to TRUE to make cmd files visible - TRUE current makeStringView @processor addFileNameToProcessor 0 < [ + TRUE i processor.options.fileNames @ makeStringView i processor.options.fileTexts @ makeStringView @processor addFileNameToProcessor 0 < [ TRUE !errorInCmdNames ] when ] when - ] each + ] times @processor.@blocks.last.get 0 @processor.@files.at.get.@rootBlock.set