From e261eebabaf946fe7f64baa36e301095c63f8b0a Mon Sep 17 00:00:00 2001 From: Mahrud Sayrafi Date: Sun, 25 Aug 2024 15:25:45 +0200 Subject: [PATCH 1/3] moved a dummy declaration to expr.d --- M2/Macaulay2/d/convertr.d | 4 ---- M2/Macaulay2/d/expr.d | 5 ++++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/M2/Macaulay2/d/convertr.d b/M2/Macaulay2/d/convertr.d index 499f3d37d7..84f407d347 100644 --- a/M2/Macaulay2/d/convertr.d +++ b/M2/Macaulay2/d/convertr.d @@ -3,10 +3,6 @@ use binding; use common; use util; -dummyMultaryFun(c:CodeSequence):Expr := ( - error("dummy multary function called"); - nullE); - export AssignElemFun := dummyTernaryFun; -- filled export AssignQuotedElemFun := dummyTernaryFun; -- filled export NewFun := dummyUnaryFun; -- filled in later diff --git a/M2/Macaulay2/d/expr.d b/M2/Macaulay2/d/expr.d index 3d101ceba4..3d4506a67c 100644 --- a/M2/Macaulay2/d/expr.d +++ b/M2/Macaulay2/d/expr.d @@ -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); @@ -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( From 9823fdaa77d05422b67082e82a380ad5a5ab3965 Mon Sep 17 00:00:00 2001 From: Mahrud Sayrafi Date: Mon, 26 Aug 2024 02:13:28 +0200 Subject: [PATCH 2/3] fixed the order of FilePosition components --- M2/Macaulay2/d/basic.d | 4 +- M2/Macaulay2/d/convertr.d | 141 +++++++++++++++++++----------------- M2/Macaulay2/d/debugging.dd | 6 +- M2/Macaulay2/d/evaluate.d | 4 +- M2/Macaulay2/d/lex.d | 27 +++++-- M2/Macaulay2/d/stdiop.d | 16 +++- M2/Macaulay2/d/stdiop0.d | 28 +++++-- 7 files changed, 138 insertions(+), 88 deletions(-) diff --git a/M2/Macaulay2/d/basic.d b/M2/Macaulay2/d/basic.d index f6782187fc..21b6ad1ca2 100644 --- a/M2/Macaulay2/d/basic.d +++ b/M2/Macaulay2/d/basic.d @@ -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,")" ) diff --git a/M2/Macaulay2/d/convertr.d b/M2/Macaulay2/d/convertr.d index 84f407d347..dad78ec9a9 100644 --- a/M2/Macaulay2/d/convertr.d +++ b/M2/Macaulay2/d/convertr.d @@ -21,10 +21,21 @@ export UnaryInstallMethodFun := dummyTernaryFun; export InstallValueFun := dummyMultaryFun; export UnaryInstallValueFun := dummyTernaryFun; -combinePosition(a:Position,b:Position):Position := Position(a.filename,b.line,b.column,a.line1,a.column1,b.line2,b.column2,a.loadDepth); -- combine with emphasis on right -combinePositionLeft(a:Position,b:Position):Position := Position(a.filename,a.line,a.column,a.line1,a.column1,b.line2,b.column2,a.loadDepth); -- combine with emphasis on left -combinePosition(a:Position,b:Position,c:Position):Position := Position(a.filename,c.line,c.column,a.line1,a.column1,b.line2,b.column2,a.loadDepth); -- left, right, center -combinePositionAdjacent(a:Position,b:Position):Position := Position(a.filename,a.line2,a.column2,a.line1,a.column1,b.line2,b.column2,a.loadDepth); -- special for Adjacent +-- combine two positions with emphasis borrowed from beginning of the first one +combinePositionL(L:Position, R:Position):Position := Position( + L.filename, L.lineL, L.columnL, R.lineR, R.columnR, L.lineF, L.columnF, L.loadDepth); + +-- combine two positions with emphasis borrowed from endpoint of the second one +combinePositionR(L:Position, R:Position):Position := Position( + L.filename, L.lineL, L.columnL, R.lineR, R.columnR, R.lineF, R.columnF, L.loadDepth); + +-- combine two positions with emphasis borrowed from a third, central point +combinePositionC(L:Position, R:Position, C:Position):Position := Position( + L.filename, L.lineL, L.columnL, R.lineR, R.columnR, C.lineF, C.columnF, L.loadDepth); + +-- combine two positions belonging to adjacent tokens (focus is on endpoint of the first one) +combinePositionAdjacent(L:Position, R:Position):Position := Position( + L.filename, L.lineL, L.columnL, R.lineR, R.columnR, L.lineR, L.columnR, L.loadDepth); convert0(e:ParseTree):Code; convert(e:ParseTree):Code; @@ -117,7 +128,7 @@ nestingDepth(frameID:int,d:Dictionary):int := ( tokenAssignment(t:Token,p:ParseTree):Code := ( c:=convert0(p); - l:=combinePosition(t.position,codePosition(c)); + l:=combinePositionR(t.position, codePosition(c)); c=unseq(c); if t.entry.frameID == 0 then Code(globalAssignmentCode(t.entry,c,l)) @@ -135,7 +146,7 @@ parallelAssignment(par:Parentheses,rhs:ParseTree,d:Dictionary):Code := ( fr, symbols, unseq(c:=convert0(rhs)), - combinePosition(par.left.position,codePosition(c)) + combinePositionR(par.left.position, codePosition(c)) )) ); @@ -163,21 +174,21 @@ export convert0(e:ParseTree):Code := ( unseq(c), w.dictionary.frameID, w.dictionary.framesize, - combinePosition(w.forToken.position,loc) + combinePositionR(w.forToken.position, loc) ))) - is w:WhileDo do Code(whileDoCode(convert(w.predicate),unseq(c:=convert0(w.doClause)),combinePosition(w.whileToken.position,codePosition(c)))) - is w:WhileList do Code(whileListCode(convert(w.predicate),unseq(c:=convert0(w.listClause)),combinePosition(w.whileToken.position,codePosition(c)))) - is w:WhileListDo do Code(whileListDoCode(convert(w.predicate),convert(w.listClause),unseq(c:=convert0(w.doClause)),combinePosition(w.whileToken.position,codePosition(c)))) - is n:New do ( - if n.newparent == dummyTree - then if n.newinitializer == dummyTree - then Code(newCode(unseq(c:=convert0(n.newclass)),combinePosition(n.newtoken.position,codePosition(c)))) - else Code(newFromCode(convert(n.newclass),unseq(c:=convert0(n.newinitializer)),combinePosition(n.newtoken.position,codePosition(c)))) - else if n.newinitializer == dummyTree - then Code(newOfCode(convert(n.newclass),unseq(c:=convert0(n.newparent)),combinePosition(n.newtoken.position,codePosition(c)))) - else Code(newOfFromCode(convert(n.newclass),convert(n.newparent),unseq(c:=convert0(n.newinitializer)),combinePosition(n.newtoken.position,codePosition(c))))) - is i:IfThen do Code(ifCode(convert(i.predicate),unseq(c:=convert0(i.thenClause)),NullCode,combinePosition(i.ifToken.position,codePosition(c)))) - is i:IfThenElse do Code(ifCode(convert(i.predicate),convert(i.thenClause),unseq(c:=convert0(i.elseClause)),combinePosition(i.ifToken.position,codePosition(c)))) + is w:WhileDo do Code(whileDoCode( convert(w.predicate), unseq(c:=convert0(w.doClause)), combinePositionR(w.whileToken.position, codePosition(c)))) + is w:WhileList do Code(whileListCode( convert(w.predicate), unseq(c:=convert0(w.listClause)), combinePositionR(w.whileToken.position, codePosition(c)))) + is w:WhileListDo do Code(whileListDoCode(convert(w.predicate), convert(w.listClause), unseq(c:=convert0(w.doClause)), combinePositionR(w.whileToken.position, codePosition(c)))) + is n:New do ( + if n.newparent == dummyTree + then if n.newinitializer == dummyTree + then Code(newCode(unseq(c:=convert0(n.newclass)), combinePositionR(n.newtoken.position, codePosition(c)))) + else Code(newFromCode( convert(n.newclass), unseq(c:=convert0(n.newinitializer)), combinePositionR(n.newtoken.position, codePosition(c)))) + else if n.newinitializer == dummyTree + then Code(newOfCode( convert(n.newclass), unseq(c:=convert0(n.newparent)), combinePositionR(n.newtoken.position, codePosition(c)))) + else Code(newOfFromCode(convert(n.newclass), convert(n.newparent), unseq(c:=convert0(n.newinitializer)), combinePositionR(n.newtoken.position, codePosition(c))))) + is i:IfThen do Code(ifCode(convert(i.predicate), unseq(c:=convert0(i.thenClause)), NullCode, combinePositionR(i.ifToken.position, codePosition(c)))) + is i:IfThenElse do Code(ifCode(convert(i.predicate), convert(i.thenClause), unseq(c:=convert0(i.elseClause)), combinePositionR(i.ifToken.position, codePosition(c)))) is token:Token do ( var := token.entry; wrd := token.word; @@ -206,17 +217,17 @@ export convert0(e:ParseTree):Code := ( else Code(localMemoryReferenceCode(nestingDepth(var.frameID,token.dictionary),var.frameindex,token.position)) ) ) - is a:Adjacent do Code(adjacentCode(unseq(c:=convert0(a.lhs)),unseq(cc:=convert0(a.rhs)),combinePositionAdjacent(codePosition(c),codePosition(cc)))) - is p:EmptyParentheses do ( - pp:=combinePositionLeft(p.left.position,p.right.position); + is a:Adjacent do Code(adjacentCode(unseq(c:=convert0(a.lhs)), unseq(cc:=convert0(a.rhs)), combinePositionAdjacent(codePosition(c), codePosition(cc)))) + is p:EmptyParentheses do ( + pp := combinePositionL(p.left.position, p.right.position); if p.left.word == leftparen then Code(sequenceCode(CodeSequence(),pp)) else if p.left.word == leftbrace then Code(listCode(CodeSequence(),pp)) else if p.left.word == leftbracket then Code(arrayCode(CodeSequence(),pp)) else if p.left.word == leftAngleBar then Code(angleBarListCode(CodeSequence(),pp)) else dummyCode -- should not happen ) - is p:Parentheses do ( - pp:=combinePositionLeft(p.left.position,p.right.position); + is p:Parentheses do ( + pp := combinePositionL(p.left.position, p.right.position); if p.left.word == leftparen then Code(sequenceCode(makeCodeSequence(p.contents,CommaW),pp)) else if p.left.word == leftbrace @@ -245,7 +256,7 @@ export convert0(e:ParseTree):Code := ( b.Operator.entry.binary, unseq(c:=convert0(b.lhs)), Code(globalSymbolClosureCode(var,p)), - combinePosition(codePosition(c),p,b.Operator.position) + combinePositionC(codePosition(c), p, b.Operator.position) ) ) ) @@ -254,9 +265,9 @@ export convert0(e:ParseTree):Code := ( else dummyCode -- should not occur ) else if b.Operator.word == CommaW - then Code(sequenceCode(s:=makeCodeSequence(e,CommaW),combinePositionLeft(codePosition(s.0),codePosition(s.(length(s)-1))))) + then Code(sequenceCode(s:=makeCodeSequence(e, CommaW), combinePositionL(codePosition(s.0), codePosition(s.(length(s)-1))))) else if b.Operator.word == SemicolonW - then Code(semiCode(s:=makeCodeSequence(e,SemicolonW),combinePositionLeft(codePosition(s.0),codePosition(s.(length(s)-1))))) + then Code(semiCode( s:=makeCodeSequence(e, SemicolonW), combinePositionL(codePosition(s.0), codePosition(s.(length(s)-1))))) else if b.Operator.word == EqualW then ( when b.lhs @@ -269,25 +280,25 @@ export convert0(e:ParseTree):Code := ( unseq(c:=convert0(a.lhs)), convert(a.rhs), unseq(cc:=convert0(b.rhs))), - combinePosition(codePosition(c),codePosition(cc),b.Operator.position)))) + combinePositionC(codePosition(c), codePosition(cc), b.Operator.position)))) is u:Unary do Code( ternaryCode( UnaryInstallValueFun, Code(globalSymbolClosureCode(u.Operator.entry,p:=u.Operator.position)), convert(u.rhs), unseq(cc:=convert0(b.rhs)), - combinePosition(p,codePosition(cc),b.Operator.position))) + combinePositionC(p, codePosition(cc), b.Operator.position))) is u:Postfix do Code( ternaryCode( UnaryInstallValueFun, Code(globalSymbolClosureCode(u.Operator.entry,u.Operator.position)), unseq(c:=convert0(u.lhs)), unseq(cc:=convert0(b.rhs)), - combinePosition(codePosition(c),codePosition(cc),b.Operator.position))) + combinePositionC(codePosition(c), codePosition(cc), b.Operator.position))) is c:Binary do ( if c.Operator.entry == SharpS.symbol then Code(ternaryCode( AssignElemFun, c1:=convert(c.lhs), - convert(c.rhs), unseq(c2:=convert0(b.rhs)), combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) + convert(c.rhs), unseq(c2:=convert0(b.rhs)), combinePositionC(codePosition(c1), codePosition(c2), b.Operator.position))) else if c.Operator.entry == DotS.symbol then ( when c.rhs @@ -297,7 +308,7 @@ export convert0(e:ParseTree):Code := ( c1:=convert(c.lhs), Code(globalSymbolClosureCode(crhs.entry,crhs.position)), unseq(c2:=convert0(b.rhs)), - combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) + combinePositionC(codePosition(c1), codePosition(c2), b.Operator.position))) else dummyCode --should not happen ) else Code(multaryCode( @@ -307,7 +318,7 @@ export convert0(e:ParseTree):Code := ( c1:=convert(c.lhs), convert(c.rhs), unseq(c2:=convert0(b.rhs))), - combinePosition(codePosition(c1),codePosition(c2),b.Operator.position)))) + combinePositionC(codePosition(c1), codePosition(c2), b.Operator.position)))) is t:Token do tokenAssignment(t,b.rhs) is p:Parentheses do parallelAssignment(p,b.rhs,b.Operator.dictionary) else dummyCode -- should not happen @@ -322,20 +333,20 @@ export convert0(e:ParseTree):Code := ( AssignNewFun, convert(n.newclass), unseq(c:=convert0(b.rhs)), - combinePosition(n.newtoken.position,codePosition(c),b.Operator.position))) + combinePositionC(n.newtoken.position, codePosition(c), b.Operator.position))) else Code(ternaryCode( AssignNewFromFun, convert(n.newclass), convert(n.newinitializer), unseq(c:=convert0(b.rhs)), - combinePosition(n.newtoken.position,codePosition(c),b.Operator.position))) + combinePositionC(n.newtoken.position, codePosition(c), b.Operator.position))) else if n.newinitializer == dummyTree then Code(ternaryCode( AssignNewOfFun, convert(n.newclass), convert(n.newparent), unseq(c:=convert0(b.rhs)), - combinePosition(n.newtoken.position,codePosition(c),b.Operator.position))) + combinePositionC(n.newtoken.position, codePosition(c), b.Operator.position))) else Code(multaryCode( AssignNewOfFromFun, CodeSequence( @@ -343,7 +354,7 @@ export convert0(e:ParseTree):Code := ( convert(n.newparent), convert(n.newinitializer), unseq(c:=convert0(b.rhs))), - combinePosition(n.newtoken.position,codePosition(c),b.Operator.position)))) + combinePositionC(n.newtoken.position, codePosition(c), b.Operator.position)))) is a:Adjacent do ( Code(multaryCode( InstallMethodFun, @@ -352,19 +363,19 @@ export convert0(e:ParseTree):Code := ( unseq(c:=convert0(a.lhs)), convert(a.rhs), unseq(cc:=convert0(b.rhs))), - combinePosition(codePosition(c),codePosition(cc),b.Operator.position)))) + combinePositionC(codePosition(c), codePosition(cc), b.Operator.position)))) is u:Unary do Code(ternaryCode( UnaryInstallMethodFun, Code(globalSymbolClosureCode(u.Operator.entry,p:=u.Operator.position)), - convert(u.rhs), unseq(c:=convert0(b.rhs)), combinePosition(p,codePosition(c),b.Operator.position))) + convert(u.rhs), unseq(c:=convert0(b.rhs)), combinePositionC(p, codePosition(c), b.Operator.position))) is u:Postfix do Code(ternaryCode( UnaryInstallMethodFun, Code(globalSymbolClosureCode(u.Operator.entry,u.Operator.position)), - unseq(c:=convert0(u.lhs)), unseq(cc:=convert0(b.rhs)), combinePosition(codePosition(c),codePosition(cc),b.Operator.position))) + unseq(c:=convert0(u.lhs)), unseq(cc:=convert0(b.rhs)), combinePositionC(codePosition(c), codePosition(cc), b.Operator.position))) is c:Binary do ( if c.Operator.entry == SharpS.symbol then Code(ternaryCode( AssignElemFun, c1:=convert(c.lhs), - convert(c.rhs), unseq(c2:=convert0(b.rhs)), combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) + convert(c.rhs), unseq(c2:=convert0(b.rhs)), combinePositionC(codePosition(c1), codePosition(c2), b.Operator.position))) else if c.Operator.entry == UnderscoreS.symbol then Code(multaryCode( InstallMethodFun, @@ -373,7 +384,7 @@ export convert0(e:ParseTree):Code := ( unseq(c1:=convert0(c.lhs)), convert(c.rhs), unseq(c2:=convert0(b.rhs))), - combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) + combinePositionC(codePosition(c1), codePosition(c2), b.Operator.position))) else if c.Operator.entry == DotS.symbol then ( when c.rhs @@ -383,7 +394,7 @@ export convert0(e:ParseTree):Code := ( unseq(c1:=convert0(c.lhs)), Code(globalSymbolClosureCode(crhs.entry,crhs.position)), unseq(c2:=convert0(b.rhs)), - combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) + combinePositionC(codePosition(c1), codePosition(c2), b.Operator.position))) else dummyCode --should not happen ) else Code(multaryCode( @@ -393,7 +404,7 @@ export convert0(e:ParseTree):Code := ( unseq(c1:=convert0(c.lhs)), convert(c.rhs), unseq(c2:=convert0(b.rhs))), - combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) + combinePositionC(codePosition(c1), codePosition(c2), b.Operator.position))) ) is t:Token do tokenAssignment(t,b.rhs) is p:Parentheses do parallelAssignment(p,b.rhs,b.Operator.dictionary) @@ -404,49 +415,49 @@ export convert0(e:ParseTree):Code := ( when b.lhs is a:Adjacent do Code(augmentedAssignmentCode(b.Operator.entry, unseq(c1:=convert0(b.lhs)), - unseq(c2:=convert0(b.rhs)), AdjacentS.symbol, combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) + unseq(c2:=convert0(b.rhs)), AdjacentS.symbol, combinePositionC(codePosition(c1), codePosition(c2), b.Operator.position))) is u:Unary do Code(augmentedAssignmentCode(b.Operator.entry, unseq(c1:=convert0(b.lhs)), - unseq(c2:=convert0(b.rhs)), u.Operator.entry, combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) + unseq(c2:=convert0(b.rhs)), u.Operator.entry, combinePositionC(codePosition(c1), codePosition(c2), b.Operator.position))) is u:Postfix do Code(augmentedAssignmentCode(b.Operator.entry, unseq(c1:=convert0(b.lhs)), - unseq(c2:=convert0(b.rhs)), u.Operator.entry, combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) + unseq(c2:=convert0(b.rhs)), u.Operator.entry, combinePositionC(codePosition(c1), codePosition(c2), b.Operator.position))) is c:Binary do Code(augmentedAssignmentCode(b.Operator.entry, unseq(c1:=convert0(b.lhs)), - unseq(c2:=convert0(b.rhs)), c.Operator.entry, combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) + unseq(c2:=convert0(b.rhs)), c.Operator.entry, combinePositionC(codePosition(c1), codePosition(c2), b.Operator.position))) is t:Token do Code(augmentedAssignmentCode(b.Operator.entry, unseq(c1:=convert0(b.lhs)), - unseq(c2:=convert0(b.rhs)), t.entry, combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) + unseq(c2:=convert0(b.rhs)), t.entry, combinePositionC(codePosition(c1), codePosition(c2), b.Operator.position))) else Code(augmentedAssignmentCode(b.Operator.entry, dummyCode, dummyCode, dummySymbol, dummyPosition)) -- CHECK ) else Code(binaryCode(b.Operator.entry.binary,unseq(c1:=convert0(b.lhs)), - unseq(c2:=convert0(b.rhs)),combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) + unseq(c2:=convert0(b.rhs)), combinePositionC(codePosition(c1), codePosition(c2), b.Operator.position))) ) is a:Arrow do ( p:=treePosition(a.lhs); fc:=functionCode( unseq(c:=convert0(a.rhs)),a.desc,hash_t(0), - combinePosition(p,codePosition(c),a.Operator.position)); + combinePositionC(p,codePosition(c), a.Operator.position)); fc.hash = hashFromAddress(Expr(fc)); Code(fc)) is u:Unary do ( if u.Operator.word == CommaW - then Code(sequenceCode(s:=makeCodeSequence(e,CommaW),combinePositionLeft(u.Operator.position,codePosition(s.(length(s)-1))))) + then Code(sequenceCode(s:=makeCodeSequence(e, CommaW), combinePositionL(u.Operator.position, codePosition(s.(length(s)-1))))) else if u.Operator.word == SemicolonW - then Code(semiCode(s:=makeCodeSequence(e,SemicolonW),combinePositionLeft(u.Operator.position,codePosition(s.(length(s)-1))))) + then Code(semiCode( s:=makeCodeSequence(e, SemicolonW), combinePositionL(u.Operator.position, codePosition(s.(length(s)-1))))) else ( c:=convert0(u.rhs); loc:=codePosition(c); loc2:=u.Operator.position; when c is nullCode do nothing - else loc2=combinePositionLeft(loc2,loc); + else loc2 = combinePositionL(loc2, loc); Code(unaryCode(u.Operator.entry.unary,unseq(c),loc2)))) is q:Quote do ( token := q.rhs; sym := token.entry; - p := combinePosition(q.Operator.position,token.position); + p := combinePositionR(q.Operator.position, token.position); if sym.frameID == 0 then ( if sym.thread @@ -457,25 +468,25 @@ export convert0(e:ParseTree):Code := ( is q:GlobalQuote do ( token := q.rhs; sym := token.entry; - p := combinePosition(q.Operator.position,token.position); + p := combinePositionR(q.Operator.position, token.position); Code(globalSymbolClosureCode(sym,p))) is q:ThreadQuote do ( token := q.rhs; sym := token.entry; - p := combinePosition(q.Operator.position,token.position); + p := combinePositionR(q.Operator.position, token.position); Code(threadSymbolClosureCode(sym,p))) is q:LocalQuote do ( token := q.rhs; sym := token.entry; - p := combinePosition(q.Operator.position,token.position); + p := combinePositionR(q.Operator.position, token.position); nd := nestingDepth(sym.frameID,token.dictionary); Code(localSymbolClosureCode(nd,sym,p))) - is i:TryThenElse do Code(tryCode(convert(i.primary), convert(i.sequel), unseq(c:=convert0(i.alternate)), combinePosition(i.tryToken.position,codePosition(c)))) - is i:TryThen do Code(tryCode(convert(i.primary), unseq(c:=convert0(i.sequel)), NullCode, combinePosition(i.tryToken.position,codePosition(c)))) - is i:TryElse do Code(tryCode(convert(i.primary), NullCode, unseq(c:=convert0(i.alternate)), combinePosition(i.tryToken.position,codePosition(c)))) - is i:Try do Code(tryCode(unseq(c:=convert0(i.primary)), NullCode, NullCode, combinePosition(i.tryToken.position,codePosition(c)))) - is i:Catch do Code(catchCode(unseq(c:=convert0(i.primary)),combinePosition(i.catchToken.position,codePosition(c)))) - is u:Postfix do Code(unaryCode(u.Operator.entry.postfix,unseq(c:=convert0(u.lhs)),combinePosition(codePosition(c),u.Operator.position))) + is i:TryThenElse do Code(tryCode(convert(i.primary), convert(i.sequel), unseq(c:=convert0(i.alternate)), combinePositionR(i.tryToken.position, codePosition(c)))) + is i:TryThen do Code(tryCode(convert(i.primary), unseq(c:=convert0(i.sequel)), NullCode, combinePositionR(i.tryToken.position, codePosition(c)))) + is i:TryElse do Code(tryCode(convert(i.primary), NullCode, unseq(c:=convert0(i.alternate)), combinePositionR(i.tryToken.position, codePosition(c)))) + is i:Try do Code(tryCode(unseq(c:=convert0(i.primary)), NullCode, NullCode, combinePositionR(i.tryToken.position, codePosition(c)))) + is i:Catch do Code(catchCode(unseq(c:=convert0(i.primary)), combinePositionR(i.catchToken.position, codePosition(c)))) + is u:Postfix do Code(unaryCode(u.Operator.entry.postfix, unseq(c:=convert0(u.lhs)), combinePositionR(codePosition(c), u.Operator.position))) is d:dummy do dummyCode ); diff --git a/M2/Macaulay2/d/debugging.dd b/M2/Macaulay2/d/debugging.dd index 00d3a2bd8c..0f1c3b1935 100644 --- a/M2/Macaulay2/d/debugging.dd +++ b/M2/Macaulay2/d/debugging.dd @@ -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 := ( diff --git a/M2/Macaulay2/d/evaluate.d b/M2/Macaulay2/d/evaluate.d index d9296326d0..d74d21275f 100644 --- a/M2/Macaulay2/d/evaluate.d +++ b/M2/Macaulay2/d/evaluate.d @@ -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; if debugLevel == 1001 && stepCount >= 0 then printErrorMessage(p,"--evaluating: "+present(tostring(c))); ); stepCount >= 0) diff --git a/M2/Macaulay2/d/lex.d b/M2/Macaulay2/d/lex.d index 68eba8af21..6cf624aa8f 100644 --- a/M2/Macaulay2/d/lex.d +++ b/M2/Macaulay2/d/lex.d @@ -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 ( @@ -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; @@ -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 := ( diff --git a/M2/Macaulay2/d/stdiop.d b/M2/Macaulay2/d/stdiop.d index 766d706481..5cd4a8c6a5 100644 --- a/M2/Macaulay2/d/stdiop.d +++ b/M2/Macaulay2/d/stdiop.d @@ -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; @@ -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); diff --git a/M2/Macaulay2/d/stdiop0.d b/M2/Macaulay2/d/stdiop0.d index 0ac9357190..6762142417 100644 --- a/M2/Macaulay2/d/stdiop0.d +++ b/M2/Macaulay2/d/stdiop0.d @@ -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); From 85fc7fabf9fbcbed52c46197178eba784b4b8599 Mon Sep 17 00:00:00 2001 From: Mahrud Sayrafi Date: Mon, 26 Aug 2024 03:54:15 +0200 Subject: [PATCH 3/3] added tests for locate --- M2/Macaulay2/tests/normal/locate.m2 | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 M2/Macaulay2/tests/normal/locate.m2 diff --git a/M2/Macaulay2/tests/normal/locate.m2 b/M2/Macaulay2/tests/normal/locate.m2 new file mode 100644 index 0000000000..b91855d13b --- /dev/null +++ b/M2/Macaulay2/tests/normal/locate.m2 @@ -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