Skip to content

Commit

Permalink
De-duplicate getGlobalSymbol code
Browse files Browse the repository at this point in the history
Add a helper function that performs the last step for both cases.  In
particular, this means that we now check if the symbol is in the
global case.
  • Loading branch information
d-torrance committed Nov 22, 2024
1 parent 81fe05a commit a9e7adf
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions M2/Macaulay2/d/actors5.d
Original file line number Diff line number Diff line change
Expand Up @@ -1581,23 +1581,24 @@ fillnodes(n:LexNode):void := (
fillnodes(baseLexNode);
setupconst("operatorNames",Expr(operatorNames));

createSymbol(w:Word, d:Dictionary, s:string):Expr := (
if !isvalidsymbol(s) then buildErrorPacket("invalid symbol")
else if d.Protected then (
buildErrorPacket("attempted to create symbol in protected dictionary"))
else (
t := makeSymbol(w, tempPosition, d);
globalFrame.values.(t.frameindex)));

getglobalsym(d:Dictionary,s:string):Expr := (
w := makeUniqueWord(s,parseWORD);
when lookup(w,d.symboltable) is x:Symbol do Expr(SymbolClosure(globalFrame,x))
is null do (
if !isvalidsymbol(s) then return buildErrorPacket("invalid symbol");
if d.Protected then return buildErrorPacket("attempted to create symbol in protected dictionary");
t := makeSymbol(w,tempPosition,d);
globalFrame.values.(t.frameindex)));
is null do createSymbol(w, d, s));

getglobalsym(s:string):Expr := (
w := makeUniqueWord(s,parseWORD);
when globalLookup(w)
is x:Symbol do Expr(SymbolClosure(if x.thread then threadFrame else globalFrame,x))
is null do (
if globalDictionary.Protected then return buildErrorPacket("attempted to create symbol in protected dictionary");
t := makeSymbol(w,tempPosition,globalDictionary);
globalFrame.values.(t.frameindex)));
is null do createSymbol(w, globalDictionary, s));

getGlobalSymbol(e:Expr):Expr := (
when e
Expand Down

0 comments on commit a9e7adf

Please sign in to comment.