Skip to content

Commit

Permalink
Add [attribute] built-in
Browse files Browse the repository at this point in the history
Add [codeTokenCount] built-in
Add [codeTokenRead] built-in
Add object reality information to debug output ([printStack])
  • Loading branch information
MatwayBurkow committed Mar 10, 2023
1 parent 235d13a commit 73ebd2b
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 47 deletions.
2 changes: 2 additions & 0 deletions Block.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ Block: [{
lastBrLabelName: 0 dynamic;
variableCountDelta: 0 dynamic;

nextStringAttribute: String;

INIT: [];
DIE: [];
}];
Expand Down
31 changes: 24 additions & 7 deletions Var.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
];

Expand Down
13 changes: 7 additions & 6 deletions astNodeType.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -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: ();
Expand Down
53 changes: 52 additions & 1 deletion builtinImpl.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions builtins.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ 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 ;}
{name: "ceil" ; impl: @mplBuiltinCeil ;}
{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 ;}
Expand Down
3 changes: 2 additions & 1 deletion codeNode.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down
1 change: 1 addition & 0 deletions declarations.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ addToProcess: [

{
processor: Processor Ref;
fileText: StringView Cref;
fileName: StringView Cref;
fromCmd: Cond;
} Int32 {} "addFileNameToProcessor" importFunction
Expand Down
9 changes: 8 additions & 1 deletion irWriter.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ createPlainIR: [
];

createStringIR: [
block:;
processor:;
refToVar:;
string:;
Expand All @@ -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: [
Expand Down
2 changes: 2 additions & 0 deletions main.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 @;

Expand All @@ -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
Expand Down
56 changes: 31 additions & 25 deletions parser.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ codeunitTail?: [

fillPositionInfo: [
astNode:;
lastPosition @astNode.@positionInfo set
lastPosition @astNode.@positionInfo set
currentPosition.offsetStart new @astNode.@positionInfo.!offsetEnd
];

addToMainResult: [
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;

[
Expand Down Expand Up @@ -631,7 +632,7 @@ parseDecNumber: [
] if

p:;
p [currentPosition.offset @tokenEnd set] when
p [currentPosition.offsetStart @tokenEnd set] when
p mainResult.success and
] loop

Expand Down Expand Up @@ -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;

[
Expand Down Expand Up @@ -781,7 +782,7 @@ parseHexNumber: [
] if

p:;
p [ currentPosition.offset @tokenEnd set ] when
p [ currentPosition.offsetStart @tokenEnd set ] when
p mainResult.success and
] loop

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 = ~] &&
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions processor.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ProcessorOptions: [{
beginFunc: String;
endFunc: String;
fileNames: StringArray;
fileTexts: StringArray;
includePaths: StringArray;
hidePrefixes: StringArray;
pointerSize: 64nx dynamic;
Expand Down
Loading

0 comments on commit 73ebd2b

Please sign in to comment.