Skip to content

Commit

Permalink
Add newKeyword function (DRAFT)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-torrance committed Nov 26, 2024
1 parent 9487393 commit 599469f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
50 changes: 50 additions & 0 deletions M2/Macaulay2/d/actors.d
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,56 @@ CollectGarbage(e:Expr):Expr := (
nullE);
setupfun("collectGarbage",CollectGarbage);

newKeyword(s:string, p1:int, p2:int, p3:int, optype:int):Expr := (
if !isvalidsymbol(s)
then return buildErrorPacket("expected argument 1 to be a valid symbol");
isword := !ismathoperator(s.0, s.1);
pfuns := parsefuns(dummyunary, dummybinary);
if optype == 0 -- binary
then pfuns = parsefuns(errorunary, binaryop)
else if optype == 1 -- prefix & binary
then pfuns = parsefuns(unaryop, binaryop)
else if optype == 2 -- postfix
then pfuns = parsefuns(errorunary, postfixop)
else return buildErrorPacket("expected argument 5 to be 0, 1, or 2");
w := makeUniqueWord(s, parseinfo(p1, p2, p3, pfuns));
if !isword then w = install(s, w); -- TODO: what does install do?
sym := makeKeyword(w);
Expr(sym));

newKeyword(e:Expr):Expr := (
when e
is a:Sequence do (
if length(a) == 5 then (
when a.0
is s:stringCell do (
when a.1
is p1:ZZcell do (
if !isInt(p1)
then WrongArgSmallInteger(2)
else when a.2
is p2:ZZcell do (
if !isInt(p2)
then WrongArgSmallInteger(3)
else when a.3
is p3:ZZcell do (
if !isInt(p3)
then WrongArgSmallInteger(4)
else when a.4
is optype:ZZcell do (
if !isInt(optype)
then WrongArgSmallInteger(5)
else newKeyword(s.v, toInt(p1), toInt(p2),
toInt(p3), toInt(optype)))
else WrongArgZZ(5))
else WrongArgZZ(4))
else WrongArgZZ(3))
else WrongArgZZ(2))
else WrongArgString(1))
else WrongNumArgs(5))
else WrongNumArgs(5));
setupfun("newKeyword", newKeyword);

-- Local Variables:
-- compile-command: "echo \"make: Entering directory \\`$M2BUILDDIR/Macaulay2/d'\" && make -C $M2BUILDDIR/Macaulay2/d actors.o "
-- End:
2 changes: 1 addition & 1 deletion M2/Macaulay2/d/binding.d
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export makeProtectedSymbolClosure(w:Word):SymbolClosure := (
when globalFrame.values.(entry.frameindex)
is s:SymbolClosure do s
else SymbolClosure(globalFrame,entry));
makeKeyword(w:Word):SymbolClosure := (
export makeKeyword(w:Word):SymbolClosure := (
-- keywords differ from symbols in that their initial value is null
entry := makeEntry(w,dummyPosition,globalDictionary);
entry.Protected = true;
Expand Down
2 changes: 1 addition & 1 deletion M2/Macaulay2/d/ctype.d
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export ismathoperator(c:int):bool := (
(c & 0xfffc) == 0xe28c -- misc. technical
);
ismathoperator(c1:char, c2:char):bool := (
export ismathoperator(c1:char, c2:char):bool := (
ismathoperator((int(uchar(c1)) << 8) | int(uchar(c2))));
export isvalidsymbol(s:string):bool := (
Expand Down
4 changes: 2 additions & 2 deletions M2/Macaulay2/d/expr.d
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ export newCompiledFunction(fn:function(Expr):Expr):CompiledFunction := (
--More dummy declarations


dummyunary(w:Token,o:TokenFile,prec:int,obeylines:bool):ParseTree := (
export dummyunary(w:Token,o:TokenFile,prec:int,obeylines:bool):ParseTree := (
anywhereError("unary dummy used");
w);
dummybinary(w:ParseTree,v:Token,o:TokenFile,prec:int,obeylines:bool):ParseTree := (
export dummybinary(w:ParseTree,v:Token,o:TokenFile,prec:int,obeylines:bool):ParseTree := (
anywhereError("binary dummy used");
w);
export nopr := -1; -- represents unused precedence
Expand Down

0 comments on commit 599469f

Please sign in to comment.