Skip to content

Commit 857584d

Browse files
committed
Rewrite evaluation of parallel assignment
The left hand side is now a sequence of Code objects rather than a list of symbols. Also add support for (x) = y (behaves just like x = y).
1 parent 496963a commit 857584d

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

M2/Macaulay2/d/evaluate.d

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,36 +1187,34 @@ globalAssignment(frameindex:int,t:Symbol,newvalue:Expr):Expr := ( -- frameID = 0
11871187
vals.frameindex = newvalue;
11881188
newvalue);
11891189
1190-
assignment(nestingDepth:int,frameindex:int,t:Symbol,newvalue:Expr):Expr := (
1191-
if nestingDepth == -1
1192-
then globalAssignment(frameindex,t,newvalue)
1193-
else localAssignment(nestingDepth,frameindex,newvalue));
1194-
11951190
globalAssignmentFun(x:globalAssignmentCode):Expr := (
11961191
t := x.lhs;
11971192
newvalue := eval(x.rhs);
11981193
when newvalue is Error do return newvalue else nothing;
11991194
globalAssignment(t.frameindex,t,newvalue));
12001195
1196+
ParallelAssignmentError(n:int):Expr := buildErrorPacket(
1197+
"parallel assignment: expected a sequence of " + tostring(n) + " values");
12011198
parallelAssignmentFun(x:parallelAssignmentCode):Expr := (
1202-
syms := x.lhs;
1203-
nestingDepth := x.nestingDepth;
1204-
frameindex := x.frameindex;
1205-
nlhs := length(frameindex);
1206-
foreach sym in syms do if sym.Protected then return buildErrorPacket("assignment to protected variable '" + sym.word.name + "'");
1207-
value := eval(x.rhs);
1208-
when value
1209-
is Error do return value
1210-
is values:Sequence do
1211-
if nlhs == length(values) then (
1212-
for i from 0 to nlhs-1 do (
1213-
r := assignment(nestingDepth.i,frameindex.i,syms.i,values.i);
1214-
when r is Error do return r else nothing;
1215-
);
1216-
value
1217-
)
1218-
else buildErrorPacket("parallel assignment: expected a sequence of " + tostring(nlhs) + " values")
1219-
else buildErrorPacket("parallel assignment: expected a sequence of " + tostring(nlhs) + " values"));
1199+
nlhs := length(x.lhs);
1200+
value := eval(x.rhs);
1201+
when value is Error do return value else nothing;
1202+
-- (x) = y should behave just like x = y
1203+
if nlhs == 1 then value = seq(value);
1204+
when value
1205+
is values:Sequence do (
1206+
if nlhs == length(values)
1207+
then Expr(new Sequence len nlhs at i do provide (
1208+
when x.lhs.i
1209+
is y:globalMemoryReferenceCode do (
1210+
globalAssignment(y.var.frameindex, y.var, values.i))
1211+
is y:localMemoryReferenceCode do (
1212+
localAssignment(y.nestingDepth, y.frameindex, values.i))
1213+
is y:threadMemoryReferenceCode do (
1214+
globalAssignment(y.var.frameindex, y.var, values.i))
1215+
else nullE)) -- TODO: handle other cases
1216+
else ParallelAssignmentError(nlhs))
1217+
else ParallelAssignmentError(nlhs));
12201218
12211219
-- helper function used when evaluating tryCode and by null coalescion
12221220
-- tryEvalSuccess is true unless an (non-interrupting) error occurred

0 commit comments

Comments
 (0)