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

Augmented assignment updates #3615

Merged
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
2 changes: 1 addition & 1 deletion M2/Macaulay2/d/convertr.d
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export convert0(e:ParseTree):Code := (
is t:Token do Code(augmentedAssignmentCode(
b.Operator.entry, convert(b.lhs), convert(b.rhs), t.entry, pos))
else Code(augmentedAssignmentCode(
b.Operator.entry, dummyCode, dummyCode, dummySymbol, dummyPosition)) -- CHECK
b.Operator.entry, convert(b.lhs), convert(b.rhs), dummySymbol, pos))
)
else Code(binaryCode(b.Operator.entry.binary, convert(b.lhs), convert(b.rhs), pos))
)
Expand Down
25 changes: 12 additions & 13 deletions M2/Macaulay2/d/evaluate.d
Original file line number Diff line number Diff line change
Expand Up @@ -1268,46 +1268,45 @@ augmentedAssignmentFun(x:augmentedAssignmentCode):Expr := (
is Nothing do nothing
else return e)
else lexpr = eval(x.lhs);
left := evaluatedCode(lexpr, dummyPosition);
when left.expr is e:Error do return Expr(e) else nothing;
when lexpr is e:Error do return lexpr else nothing;
-- check if user-defined method exists
meth := lookup(Class(left.expr),
Expr(SymbolClosure(globalFrame, x.oper)));
meth := lookup(Class(lexpr), Expr(SymbolClosure(globalFrame, x.oper)));
if meth != nullE then (
rightexpr := eval(x.rhs);
when rightexpr is e:Error do return(e) else nothing;
r := applyEEE(meth, left.expr, rightexpr);
rexpr := eval(x.rhs);
when rexpr is e:Error do return rexpr else nothing;
r := applyEEE(meth, lexpr, rexpr);
when r
is s:SymbolClosure do (
if s.symbol.word.name === "Default" then nothing
else return r)
else return r);
-- if not, use default behavior
left := evaluatedCode(lexpr, codePosition(x.lhs));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know writing tests for errors is complicated, but did you try to reproduce an error at the errors points below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah -- they're easy to reproduce. For example:

i1 : x = 5

o1 = 5

i2 : x += "foo"
stdio:2:2:(3): error: no method for binary operator + applied to objects:
            5 (of class ZZ)
      +     "foo" (of class String)

when x.lhs
is y:globalMemoryReferenceCode do (
r := s.binary(Code(left), x.rhs);
when r is e:Error do Expr(e)
when r is e:Error do r
else globalAssignment(y.frameindex, x.info, r))
is y:localMemoryReferenceCode do (
r := s.binary(Code(left), x.rhs);
when r is e:Error do Expr(e)
when r is e:Error do r
else localAssignment(y.nestingDepth, y.frameindex, r))
is y:threadMemoryReferenceCode do (
r := s.binary(Code(left), x.rhs);
when r is e:Error do Expr(e)
when r is e:Error do r
else globalAssignment(y.frameindex, x.info, r))
is y:binaryCode do (
r := Code(binaryCode(s.binary, Code(left), x.rhs, dummyPosition));
r := Code(binaryCode(s.binary, Code(left), x.rhs, x.position));
if y.f == DotS.symbol.binary || y.f == SharpS.symbol.binary
then AssignElemFun(y.lhs, y.rhs, r)
else InstallValueFun(CodeSequence(
convertGlobalOperator(x.info), y.lhs, y.rhs, r)))
is y:adjacentCode do (
r := Code(binaryCode(s.binary, Code(left), x.rhs, dummyPosition));
r := Code(binaryCode(s.binary, Code(left), x.rhs, x.position));
InstallValueFun(CodeSequence(
convertGlobalOperator(AdjacentS.symbol), y.lhs, y.rhs, r)))
is y:unaryCode do (
r := Code(binaryCode(s.binary, Code(left), x.rhs, dummyPosition));
r := Code(binaryCode(s.binary, Code(left), x.rhs, x.position));
UnaryInstallValueFun(convertGlobalOperator(x.info), y.rhs, r))
else buildErrorPacket(
"augmented assignment not implemented for this code")));
Expand Down
Loading