Skip to content

Commit

Permalink
1st attempt: m2 level makeKeyword
Browse files Browse the repository at this point in the history
  • Loading branch information
pzinn committed Nov 28, 2024
1 parent 9487393 commit a0c7a5f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
10 changes: 10 additions & 0 deletions M2/Macaulay2/d/actors5.d
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- Copyright 1995,2010 by Daniel R. Grayson
use actors;
use actors2;
use binding;

header "#include <interface/random.h>";

Expand All @@ -13,6 +14,15 @@ getParsing(e:Expr):Expr := (
else nullE);
setupfun("getParsing",getParsing);

export makeKeywordFun(e:Expr):Expr := (
when e
is s:stringCell do (
Expr(makeKeyword(binaryleft(s.v))) -- TODO check whether install is really needed (for mathematical symbols as opposed to words)
)
else nullE -- TODO error (but anyway won't be called directly)
);
setupfun("makeKeyword",makeKeywordFun);

LongDoubleRightArrowFun(lhs:Code,rhs:Code):Expr := binarymethod(lhs,rhs,LongDoubleRightArrowS);
setup(LongDoubleRightArrowS,LongDoubleRightArrowFun);

Expand Down
7 changes: 5 additions & 2 deletions 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 All @@ -157,7 +157,7 @@ unaryword(s:string) :Word := makeUniqueWord(s, parseinfo(prec,nopr
postfix(s:string) :Word := install(s,makeUniqueWord(s, parseinfo(prec,nopr ,nopr,parsefuns(errorunary,postfixop))));
unarybinaryleft(s:string) :Word := install(s,makeUniqueWord(s, parseinfo(prec,prec ,prec,parsefuns(unaryop ,binaryop))));
unarybinaryright(s:string) :Word := install(s,makeUniqueWord(s, parseinfo(prec,prec-1,prec,parsefuns(unaryop ,binaryop))));
binaryleft(s:string) :Word := install(s,makeUniqueWord(s, parseinfo(prec,prec ,nopr,parsefuns(errorunary,binaryop))));
export binaryleft(s:string) :Word := install(s,makeUniqueWord(s, parseinfo(prec,prec ,nopr,parsefuns(errorunary,binaryop))));
nright(s:string) :Word := install(s,makeUniqueWord(s, parseinfo(prec,prec-1,nopr,parsefuns(errorunary,nbinaryop))));
nleftword(s:string) :Word := makeUniqueWord(s, parseinfo(prec,prec ,nopr,parsefuns(errorunary,nbinaryop)));
nunarybinaryleft(s:string) :Word := install(s,makeUniqueWord(s, parseinfo(prec,prec ,prec,parsefuns(nnunaryop ,nbinaryop))));
Expand Down Expand Up @@ -644,14 +644,17 @@ bindParenParmList(e:ParseTree,dictionary:Dictionary,desc:functionDescription):vo
is p:EmptyParentheses do nothing
else makeErrorTree(e,"expected parenthesized argument list or symbol"));
opHasBinaryMethod(o:Symbol):bool := (
return true; -- TEMP
foreach s in opsWithBinaryMethod do if s.symbol == o then return true;
return false;
);
opHasUnaryMethod(o:Symbol):bool := (
return true; -- TEMP
foreach s in opsWithUnaryMethod do if s.symbol == o then return true;
return false;
);
opHasPostfixMethod(o:Symbol):bool := (
return true; -- TEMP
foreach s in opsWithPostfixMethod do if s.symbol == o then return true;
return false;
);
Expand Down
17 changes: 14 additions & 3 deletions M2/Macaulay2/d/convertr.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export UnaryInstallMethodFun := dummyTernaryFun;
export InstallValueFun := dummyMultaryFun;
export UnaryInstallValueFun := dummyTernaryFun;

export binarymethod1 := dummyTernaryFun; -- temporary, will be redefined in evaluate.d

convert(e:ParseTree):Code;
CodeSequenceLength(e:ParseTree,separator:Word):int := (
i := 0;
Expand Down Expand Up @@ -189,7 +191,12 @@ export convert0(e:ParseTree):Code := (
rhs := convertGlobalOperator(token);
-- TODO: is this check necessary?
if token.word.typecode == TCid
then Code(binaryCode(b.Operator.entry.binary, convert(b.lhs), rhs, pos))
then (
f:=b.Operator.entry.binary; if f==dummyBinaryFun then
Code(ternaryCode(binarymethod1,convert(b.lhs), rhs, globalSymbolClosureCode(b.Operator.entry, dummyPosition),pos))
else
Code(binaryCode(f, convert(b.lhs), rhs, pos))
)
else dummyCode -- should not occur
)
else dummyCode -- should not occur
Expand Down Expand Up @@ -300,8 +307,12 @@ export convert0(e:ParseTree):Code := (
else Code(augmentedAssignmentCode(
b.Operator.entry, dummyCode, dummyCode, dummySymbol, dummyPosition)) -- CHECK
)
else Code(binaryCode(b.Operator.entry.binary, convert(b.lhs), convert(b.rhs), pos))
)
else (
f:=b.Operator.entry.binary; if f==dummyBinaryFun then
Code(ternaryCode(binarymethod1,convert(b.lhs), convert(b.rhs), globalSymbolClosureCode(b.Operator.entry, dummyPosition),pos))
else
Code(binaryCode(f, convert(b.lhs), convert(b.rhs), pos))
))
is u:Unary do (
if u.Operator.word == CommaW then Code(sequenceCode(makeCodeSequence(e, CommaW), pos)) else
if u.Operator.word == SemicolonW then Code(semiCode( makeCodeSequence(e, SemicolonW), pos))
Expand Down
9 changes: 9 additions & 0 deletions M2/Macaulay2/d/evaluate.d
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,7 @@ export unarymethod(rhs:Code,methodkey:SymbolClosure):Expr := (
method := lookup(Class(right),Expr(methodkey),methodkey.symbol.hash);
if method == nullE then MissingMethod(methodkey)
else applyEE(method,right)));

export binarymethod(lhs:Code,rhs:Code,methodkey:SymbolClosure):Expr := (
left := eval(lhs);
when left is Error do left
Expand All @@ -1119,6 +1120,12 @@ export binarymethod(left:Expr,rhs:Code,methodkey:SymbolClosure):Expr := (
else MissingMethodPair(methodkey,left,right)
)
else applyEEE(method,left,right)));
export binarymethodCode(lhs:Code,rhs:Code,methodkey:Code):Expr := (
when methodkey is
s:globalSymbolClosureCode do binarymethod(lhs,rhs,SymbolClosure(globalFrame,s.symbol))
else nullE
);


-----------------------------------------------------------------------------

Expand Down Expand Up @@ -2110,6 +2117,8 @@ nullCoalescion(lhs:Code,rhs:Code):Expr := (
else e);
setup(QuestionQuestionS, nullify, nullCoalescion);

binarymethod1=binarymethodCode;

-- Local Variables:
-- compile-command: "echo \"make: Entering directory \\`$M2BUILDDIR/Macaulay2/d'\" && make -C $M2BUILDDIR/Macaulay2/d evaluate.o "
-- End:
1 change: 1 addition & 0 deletions M2/Macaulay2/m2/exports.m2
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@ export {
"lookup",
"lookupCount",
"makeDirectory",
"makeKeyword",
"makeDocumentTag",
"makePackageIndex",
"map",
Expand Down

0 comments on commit a0c7a5f

Please sign in to comment.