Skip to content

Commit 496963a

Browse files
committed
Update members of parallelAssignmentCode struct
Now contains a CodeSequence of the elements on the left hand side instead of symbol information. This will enable us to support other types of code in the left hand side.
1 parent fc9c84f commit 496963a

File tree

3 files changed

+11
-66
lines changed

3 files changed

+11
-66
lines changed

M2/Macaulay2/d/convertr.d

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -57,43 +57,6 @@ makeCodeSequence(e:ParseTree,separator:Word):CodeSequence := (
5757
v := new CodeSequence len CodeSequenceLength(e,separator) do provide dummyCode;
5858
fillCodeSequence(e,v,length(v),separator);
5959
v);
60-
SymbolSequenceLength(e:ParseTree):int := (
61-
i := 0;
62-
while true do (
63-
when e
64-
is p:Parentheses do e = p.contents
65-
is b:Binary do (
66-
i = i+1;
67-
e = b.lhs;
68-
)
69-
else ( -- should be the first token
70-
i = i+1;
71-
return i;
72-
)
73-
)
74-
);
75-
makeSymbolSequence(e:ParseTree):SymbolSequence := ( -- but replace local symbols by dummySymbol
76-
m := SymbolSequenceLength(e);
77-
v := new SymbolSequence len m do provide dummySymbol;
78-
while true do (
79-
when e
80-
is p:Parentheses do e = p.contents
81-
is b:Binary do (
82-
when b.rhs is t:Token do (
83-
m = m-1;
84-
v.m = t.entry;
85-
)
86-
else nothing; -- shouldn't happen
87-
e = b.lhs;
88-
)
89-
is t:Token do (
90-
m = m-1;
91-
v.m = t.entry;
92-
break;
93-
)
94-
else break; -- shouldn't happen
95-
);
96-
v);
9760
9861
nestingDepth(frameID:int,d:Dictionary):int := (
9962
if frameID == 0 then return -1;
@@ -138,15 +101,11 @@ convertTokenAssignment(token:Token, rhs:ParseTree):Code := (
138101
nestingDepth(sym.frameID, token.dictionary), sym.frameindex, val, pos))
139102
);
140103
141-
convertParallelAssignment(par:Parentheses,rhs:ParseTree,d:Dictionary):Code := (
142-
syms := makeSymbolSequence(ParseTree(par)); -- silly -- rethink
104+
convertParallelAssignment(colon:bool, par:Parentheses, rhs:ParseTree):Code := (
105+
lhs := makeCodeSequence(par.contents, CommaW);
143106
vals := convert(rhs);
144107
pos := combinePositionR(par.left.position, treePosition(rhs));
145-
n := length(syms);
146-
nd := new array(int) len n do foreach x in syms do provide nestingDepth(x.frameID, d); -- rethink dictionary
147-
fr := new array(int) len n do foreach x in syms do provide x.frameindex;
148-
foreach x in syms do if x.frameID != 0 then x = dummySymbol;
149-
Code(parallelAssignmentCode(nd, fr, syms, vals, pos))
108+
Code(parallelAssignmentCode(colon, lhs, vals, pos))
150109
);
151110
152111
export convertGlobalOperator(oper:Token):Code := Code(globalSymbolClosureCode(oper.entry, oper.position));
@@ -207,7 +166,7 @@ export convert0(e:ParseTree):Code := (
207166
-- e.g. x = ...
208167
is t:Token do convertTokenAssignment(t, b.rhs)
209168
-- e.g. (x,y,z) = (...)
210-
is p:Parentheses do convertParallelAssignment(p, b.rhs, b.Operator.dictionary)
169+
is p:Parentheses do convertParallelAssignment(false, p, b.rhs)
211170
-- Note: usable, but not used anywhere yet
212171
is u:Unary do convertUnaryInstallCode(UnaryInstallValueFun,
213172
convertGlobalOperator(u.Operator), convert(u.rhs), convert(b.rhs), pos)
@@ -243,7 +202,7 @@ export convert0(e:ParseTree):Code := (
243202
-- e.g. x := ...
244203
is t:Token do convertTokenAssignment(t, b.rhs)
245204
-- e.g. (x,y,z) := (...)
246-
is p:Parentheses do convertParallelAssignment(p, b.rhs, b.Operator.dictionary)
205+
is p:Parentheses do convertParallelAssignment(true, p, b.rhs)
247206
-- e.g. - Matrix := ...
248207
-- TODO: can #T be implemented here?
249208
is u:Unary do convertUnaryInstallCode(UnaryInstallMethodFun,

M2/Macaulay2/d/debugging.dd

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,8 @@ export tostring(c:Code):string := (
3737
is x:localAssignmentCode do concatenate(array(string)("(local-assign ", tostring(x.frameindex), " ", tostring(x.nestingDepth), " ", tostring(x.rhs), ")"))
3838
is x:globalAssignmentCode do concatenate(array(string)("(global-assign ", x.lhs.word.name, " ", tostring(x.rhs), ")"))
3939
is x:augmentedAssignmentCode do concatenate(array(string)("(augmented-assign ", x.oper.word.name, " ", tostring(x.lhs), " ", tostring(x.rhs), ")"))
40-
is x:parallelAssignmentCode do (
41-
n := length(x.nestingDepth);
42-
concatenate(array(string)(
43-
"(parallel-assign (", between(" ",
44-
new array(string) len n do
45-
for i from 0 to n-1 do
46-
if x.lhs.i == dummySymbol
47-
then provide concatenate(array(string)("(", tostring(x.frameindex.i), " ", tostring(x.nestingDepth.i), ")"))
48-
else provide join("'", x.lhs.i.word.name)),
49-
") ", tostring(x.rhs), ")")))
40+
is x:parallelAssignmentCode do concatenate(array(string)("(parallel-assign ( ", if x.colon then ":=" else "=", " (",
41+
between(" ", new array(string) len length(x.lhs) do foreach s in x.lhs do provide tostring(s)), ") ", tostring(x.rhs), ")"))
5042
-- TODO: what is an example that yields this?
5143
is x:evaluatedCode do concatenate(array(string)("(expr ", tostring(hash(x.expr)), ")"))
5244
--
@@ -115,13 +107,8 @@ export toList(c:Code):Expr := (
115107
is x:localAssignmentCode do list(toExpr("local-assign"), toExpr(x.frameindex), toExpr(x.nestingDepth), seq(toExpr(x.rhs)))
116108
is x:globalAssignmentCode do list(toExpr("global-assign"), Expr(SymbolBody(x.lhs)), toExpr(x.lhs.frameindex), seq(toExpr(x.rhs)))
117109
is x:augmentedAssignmentCode do list(toExpr("augmented-assign"), Expr(SymbolBody(x.oper)), seq(toExpr(x.lhs), toExpr(x.rhs)))
118-
is x:parallelAssignmentCode do list(toExpr("parallel-assign"), seq(
119-
Expr(new Sequence len length(x.nestingDepth) do
120-
for i from 0 to length(x.nestingDepth) - 1 do
121-
if x.lhs.i == dummySymbol
122-
then provide seq(toExpr(x.frameindex.i), toExpr(x.nestingDepth.i))
123-
else provide seq(Expr(SymbolBody(x.lhs.i)), toExpr(x.lhs.i.frameindex))),
124-
toExpr(x.rhs)))
110+
is x:parallelAssignmentCode do list(toExpr("parallel-assign"), Expr(SymbolBody(if x.colon then ColonEqualS.symbol else EqualS.symbol)),
111+
Expr(new Sequence len length(x.lhs) do foreach s in x.lhs do provide toExpr(s)), toExpr(x.rhs))
125112
-- used along augmentedAssignmentCode
126113
is x:evaluatedCode do toExpr(tostring(c))
127114
--

M2/Macaulay2/d/parse.d

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,8 @@ export catchCode := {+ code:Code, position:Position };
200200

201201
export SymbolSequence := array(Symbol);
202202
export parallelAssignmentCode := {+
203-
nestingDepth:array(int), -- spots corresponding to global and thread variables are filled with -1
204-
frameindex:array(int),
205-
lhs:SymbolSequence, -- spots corresponding to local variables are filled with dummySymbol
203+
colon:bool, -- := or =
204+
lhs:CodeSequence,
206205
rhs:Code,
207206
position:Position};
208207

0 commit comments

Comments
 (0)