Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed order of FilePosition components #3435

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions M2/Macaulay2/d/basic.d
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export hash(e:Expr):hash_t := (
is x:Error do (
929+hash(x.message)+12963*(
hash(x.position.filename)
+ 1299791 * (int(x.position.line) +
1299811 * int(x.position.column))))
+ 1299791 * (int(x.position.lineF) +
1299811 * int(x.position.columnF))))
is x:RawMonomialCell do hash(x.p)
is x:RawMonomialOrderingCell do Ccode(hash_t, "rawMonomialOrderingHash(",x.p,")" )
is x:RawMonoidCell do Ccode(hash_t, "rawMonoidHash(",x.p,")" )
Expand Down
145 changes: 76 additions & 69 deletions M2/Macaulay2/d/convertr.d

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions M2/Macaulay2/d/debugging.dd
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ locate(p:Position):Expr := (
else Expr(sethash(List(filePositionClass,
Sequence(
toExpr(verifyMinimizeFilename(p.filename)),
toExpr(int(p.line1)), toExpr(int(p.column1)),
toExpr(int(p.line2)), toExpr(int(p.column2)),
toExpr(int(p.line)), toExpr(int(p.column))),
toExpr(int(p.lineL)), toExpr(int(p.columnL)),
toExpr(int(p.lineR)), toExpr(int(p.columnR)),
toExpr(int(p.lineF)), toExpr(int(p.columnF))),
hash_t(0), false), false)));

locate(e:Expr):Expr := (
Expand Down
4 changes: 2 additions & 2 deletions M2/Macaulay2/d/evaluate.d
Original file line number Diff line number Diff line change
Expand Up @@ -1305,11 +1305,11 @@ steppingFurther(c:Code):bool := steppingFlag && (
if p == dummyPosition || p.loadDepth < errorDepth then return true;
if stepCount >= 0 then (
if lastCodePosition.filename != p.filename
|| lastCodePosition.line != p.line
|| lastCodePosition.lineF != p.lineF
then (
stepCount = stepCount - 1;
lastCodePosition.filename = p.filename;
lastCodePosition.line = p.line;
lastCodePosition.lineF = p.lineF;
mahrud marked this conversation as resolved.
Show resolved Hide resolved
if debugLevel == 1001 && stepCount >= 0 then printErrorMessage(p,"--evaluating: "+present(tostring(c)));
);
stepCount >= 0)
Expand Down
5 changes: 4 additions & 1 deletion M2/Macaulay2/d/expr.d
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ dummybinary(w:ParseTree,v:Token,o:TokenFile,prec:int,obeylines:bool):ParseTree :
w);
export nopr := -1; -- represents unused precedence
export newParseinfo():parseinfo := parseinfo(nopr,nopr,nopr,parsefuns(dummyunary,dummybinary));

export dummyUnaryFun(c:Code):Expr := (
anywhereError("dummy unary function called");
nullE);
Expand All @@ -216,9 +217,11 @@ export dummyBinaryFun(c:Code,d:Code):Expr := (
export dummyTernaryFun(c:Code,d:Code,e:Code):Expr := (
anywhereError("dummy ternary function called");
nullE);
export dummyMultaryFun(c:CodeSequence):Expr := (
anywhereError("dummy multary function called");
nullE);

export emptySequence := Sequence();

export emptySequenceE := Expr(emptySequence);

export dummySymbol := Symbol(
Expand Down
27 changes: 19 additions & 8 deletions M2/Macaulay2/d/lex.d
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ export errorToken := Token(Word("-*error token*-",TCnone,hash_t(0),newParseinfo(
globalDictionary, -- should replace this by dummyDictionary, I think
dummySymbol,false);

newPosition(file:PosFile, line:ushort, column:ushort):Position := Position(
-- [ beginning ] [ endpoint ] [ focus ]
file.filename, line, column, file.line, file.column, line, column, loadDepth);

gettoken1(file:PosFile,sawNewline:bool):Token := (
-- warning : tokenbuf is static
while true do (
Expand All @@ -303,17 +307,19 @@ gettoken1(file:PosFile,sawNewline:bool):Token := (
line := file.line;
column := file.column;
ch := peek(file);
if iseof(ch) then return Token(wordEOF,Position(file.filename, line, column, line, column, file.line, file.column, loadDepth),globalDictionary,dummySymbol,sawNewline)
if iseof(ch) then return Token(wordEOF,
newPosition(file, line, column), globalDictionary, dummySymbol, sawNewline)
else if iserror(ch) then return errorToken
else if ch == int('\n') then (
getc(file);
return Token(
if file.file.fulllines then wordEOC else NewlineW,
Position(file.filename, line, column, line, column, file.line, file.column, loadDepth),globalDictionary,dummySymbol,sawNewline))
newPosition(file, line, column), globalDictionary, dummySymbol, sawNewline))
else if isalpha(ch) then ( -- valid symbols are an alpha (letters, any unicode except 226) followed by any number of alphanum (alpha, digit, dollar, prime)
tokenbuf << char(getc(file));
while isalnum(peek(file)) do tokenbuf << char(getc(file));
return Token(makeUniqueWord(takestring(tokenbuf),parseWORD),Position(file.filename, line, column, line, column, file.line, file.column, loadDepth),globalDictionary,dummySymbol,sawNewline))
return Token(makeUniqueWord(takestring(tokenbuf), parseWORD),
newPosition(file, line, column), globalDictionary, dummySymbol, sawNewline))
else if isdigit(ch) || ch==int('.') && isdigit(peek(file,1)) then (
typecode := TCint;
decimal := true;
Expand Down Expand Up @@ -386,33 +392,38 @@ gettoken1(file:PosFile,sawNewline:bool):Token := (
c = peek(file);
if isalpha(c) then printWarningMessage(position(file),"character '"+char(c)+"' immediately following number");
s := takestring(tokenbuf);
return Token(Word(s,typecode,hash_t(0), parseWORD),Position(file.filename, line, column, line, column, file.line, file.column, loadDepth),globalDictionary,dummySymbol,sawNewline))
return Token(Word(s,typecode,hash_t(0), parseWORD),
newPosition(file, line, column), globalDictionary, dummySymbol, sawNewline))
else if ch == int('/') && peek(file,1) == int('/') && peek(file,2) == int('/') then (
when getstringslashes(file)
is null do (
empty(tokenbuf);
return errorToken
)
is word:Word do return Token(word,Position(file.filename, line, column, line, column, file.line, file.column, loadDepth),globalDictionary,dummySymbol,sawNewline))
is word:Word do return Token(word,
newPosition(file, line, column), globalDictionary, dummySymbol, sawNewline))
else if isquote(ch) then (
when getstring(file)
is null do (
empty(tokenbuf);
return errorToken
)
is word:Word do return Token(word,Position(file.filename, line, column, line, column, file.line, file.column, loadDepth),globalDictionary,dummySymbol,sawNewline))
is word:Word do return Token(word,
newPosition(file, line, column), globalDictionary, dummySymbol, sawNewline))
else if ch == 226 then ( -- unicode math symbols
tokenbuf << char(getc(file));
tokenbuf << char(getc(file));
tokenbuf << char(getc(file));
return Token(makeUniqueWord(takestring(tokenbuf),parseWORD),Position(file.filename, line, column, line, column, file.line, file.column, loadDepth),globalDictionary,dummySymbol,sawNewline))
return Token(makeUniqueWord(takestring(tokenbuf), parseWORD),
newPosition(file, line, column), globalDictionary, dummySymbol, sawNewline))
else (
when recognize(file)
is null do (
empty(tokenbuf);
return errorToken
)
is word:Word do return Token(word,Position(file.filename, line, column, line, column, file.line, file.column,loadDepth),globalDictionary,dummySymbol,sawNewline))
is word:Word do return Token(word,
newPosition(file, line, column), globalDictionary, dummySymbol, sawNewline))
)
);
export gettoken(file:PosFile,obeylines:bool):Token := (
Expand Down
16 changes: 13 additions & 3 deletions M2/Macaulay2/d/stdiop.d
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export tostring(w:Position) : string := (
if c == ' ' then (
filename = "\"" + filename + "\"";
break));
errfmt(filename ,int(w.line),int(w.column),int(w.loadDepth))));
errfmt(filename, int(w.lineF), int(w.columnF), int(w.loadDepth))));
export (o:file) << (w:Position) : file := o << tostring(w);
export (o:BasicFile) << (w:Position) : BasicFile := o << tostring(w);
threadLocal export SuppressErrors := false;
Expand Down Expand Up @@ -147,8 +147,18 @@ export printErrorMessage(filename:string,line:ushort,column:ushort,message:strin
);
export (o:file) << (p:(null or Position)) : file := when p is null do o is w:Position do o << w;
export (o:BasicFile) << (p:(null or Position)) : BasicFile := when p is null do o is w:Position do o << w;
export copy(p:Position):Position := Position(p.filename, p.line, p.column, p.line1, p.column1, p.line2, p.column2, loadDepth);
export position(file:PosFile):Position := Position(file.filename,file.line,file.column,file.line,file.column,file.line,file.column,loadDepth);
export copy(p:Position):Position := Position(
p.filename,
p.lineL, p.columnL,
p.lineR, p.columnR,
p.lineF, p.columnF,
loadDepth);
export position(file:PosFile):Position := Position(
file.filename,
file.line, file.column,
file.line, file.column,
file.line, file.column,
loadDepth);
export dummyPosFile := PosFile(dummyfile,0,"-*dummy file name*-",ushort(0),ushort(0));
export fileError(f:PosFile):bool := fileError(f.file);
export clearFileError(f:PosFile):void := clearFileError(f.file);
Expand Down
28 changes: 23 additions & 5 deletions M2/Macaulay2/d/stdiop0.d
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
use nets;

-- from stdiop
export Position := {filename:string, line:ushort, column:ushort, line1:ushort, column1:ushort, line2:ushort, column2:ushort, loadDepth:ushort};
export dummyPosition := Position("-*dummy file name*-",ushort(0),ushort(0),ushort(0),ushort(0),ushort(0),ushort(0),loadDepth);
export tempPosition := Position("-*temp*-",ushort(0),ushort(0),ushort(0),ushort(0),ushort(0),ushort(0),loadDepth);
export (s:Position) === (t:Position) : bool := s == t || s.filename === t.filename && s.line == t.line && s.column == t.column && s.line1 == t.line1 && s.column1 == t.column1 && s.line2 == t.line2 && s.column2 == t.column2;

export Position := {
filename:string,
lineL:ushort, columnL:ushort, -- coordinates of the beginning
lineR:ushort, columnR:ushort, -- coordinates of the endpoint
lineF:ushort, columnF:ushort, -- coordinates of the focused location
loadDepth:ushort };
export dummyPosition := Position(
"-*dummy file name*-",
ushort(0), ushort(0),
ushort(0), ushort(0),
ushort(0), ushort(0),
loadDepth);
export tempPosition := Position(
"-*temp*-",
ushort(0), ushort(0),
ushort(0), ushort(0),
ushort(0), ushort(0),
loadDepth);
export (s:Position) === (t:Position) : bool := (
s == t || s.filename === t.filename
&& s.lineL == t.lineL && s.columnL == t.columnL
&& s.lineR == t.lineR && s.columnR == t.columnR
&& s.lineF == t.lineF && s.columnF == t.columnF);
37 changes: 37 additions & 0 deletions M2/Macaulay2/tests/normal/locate.m2
mahrud marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
f = () -> if ( true ) then ( "true" ) else ( "false" )
assert( ((F = functionBody f;)) === null );
assert( ((c = pseudocode f;)) === null );
assert( ((C = pseudocode F;)) === null );
getcols = P -> (toList P)_{2,4,6}
assert( (getcols locate f) === {4,54,7} );
assert( (getcols locate f) === {4,54,7} );
assert( (getcols locate F) === {4,54,7} );
assert( (getcols locate c) === {10,54,43} );
assert( (getcols locate C) === {10,54,43} );
assert( (getcols locate C_0) === {15,19,15} );
assert( (getcols locate C_1) === {29,35,29} );
assert( (getcols locate C_2) === {45,52,45} );
end--
-*
-- to update this file simply run these lines:
src = last separate("end-{2,}", get "locate.m2");
"locate.m2" << generateAssertions src << endl;
"locate.m2" << "end" << "--" << src << close;
*-
-- 0 0 1 1 1 1 2 2 2 2 3 3 3 4 4 5 5
-- 4 7 0 3 5 8 0 2 7 9 4 6 8 3 5 1 3
f = () -> if ( true ) then ( "true" ) else ( "false" )
(F = functionBody f;)
(c = pseudocode f;)
(C = pseudocode F;)
getcols = P -> (toList P)_{2,4,6}
getcols locate f
getcols locate f-* why is focus on '->'? *-
getcols locate F
getcols locate c-* why is focus on '( "false" )'? *-
getcols locate C
getcols locate C_0
getcols locate C_1
getcols locate C_2

-- TODO: add tests for other kinds of code as well
Loading