diff --git a/M2/Macaulay2/c/error.c b/M2/Macaulay2/c/error.c index 4758407ed94..2e831306172 100644 --- a/M2/Macaulay2/c/error.c +++ b/M2/Macaulay2/c/error.c @@ -7,7 +7,7 @@ void fatal(const char *s,...) va_list ap; va_start(ap,s); if (cur.filename != NULL) { - fprintf(stderr,errfmt,cur.filename,cur.lineno,cur.column+1,""); + fprintf(stderr,errfmt,cur.filename,cur.lineno,cur.column,""); } vfprintf(stderr,s,ap); fprintf(stderr,"\n"); @@ -26,7 +26,7 @@ void error(char *s,...) va_list ap; va_start(ap,s); fprintf(stderr,errfmt, - cur.filename!=NULL?cur.filename:"",cur.lineno,cur.column+1,""); + cur.filename!=NULL?cur.filename:"",cur.lineno,cur.column,""); vfprintf(stderr,s,ap); fprintf(stderr,"\n"); fflush(stderr); @@ -117,11 +117,11 @@ void fail(char *filename, int lineno) { void downpos(node n){ struct POS *p = pos(n); if (p != NULL && p->filename != NULL) { - fprintf(stderr,errfmt,p->filename,p->lineno,p->column+1,""); + fprintf(stderr,errfmt,p->filename,p->lineno,p->column,""); } else { assert(cur.filename != NULL); - fprintf(stderr,errfmt,cur.filename,cur.lineno,cur.column+1,""); + fprintf(stderr,errfmt,cur.filename,cur.lineno,cur.column,""); } } diff --git a/M2/Macaulay2/d/CMakeLists.txt b/M2/Macaulay2/d/CMakeLists.txt index f887a8f7848..c77c2f579d1 100644 --- a/M2/Macaulay2/d/CMakeLists.txt +++ b/M2/Macaulay2/d/CMakeLists.txt @@ -60,9 +60,9 @@ set(DLIST parser.d binding.d basic.d - convertr.d common.d util.d + convertr.d struct.d classes.dd buckets.dd @@ -82,6 +82,7 @@ set(DLIST xmlactors.d # removed unless WITH_XML actors5.d actors6.dd + debugging.dd threads.dd python.d # removed unless WITH_PYTHON interface.dd interface2.d diff --git a/M2/Macaulay2/d/Makefile.files.in b/M2/Macaulay2/d/Makefile.files.in index 983b7b3ac51..674639fcec4 100644 --- a/M2/Macaulay2/d/Makefile.files.in +++ b/M2/Macaulay2/d/Makefile.files.in @@ -54,9 +54,9 @@ M2_DFILES += lex.d M2_DFILES += parser.d M2_DFILES += binding.d M2_DFILES += basic.d -M2_DFILES += convertr.d M2_DFILES += common.d M2_DFILES += util.d +M2_DFILES += convertr.d M2_DFILES += struct.d M2_DFILES += classes.dd M2_DFILES += buckets.dd @@ -86,6 +86,7 @@ M2_SRCFILES += xmlactors.d endif M2_DFILES += actors5.d M2_DFILES += actors6.dd +M2_DFILES += debugging.dd M2_DFILES += threads.dd ifeq (@PYTHON@,yes) diff --git a/M2/Macaulay2/d/actors.d b/M2/Macaulay2/d/actors.d index 0c3088590c6..42493ce7d6e 100644 --- a/M2/Macaulay2/d/actors.d +++ b/M2/Macaulay2/d/actors.d @@ -900,6 +900,7 @@ assignNewFun(newclass:Code,rhs:Code):Expr := ( is o:HashTable do installMethod(NewE,o,eval(rhs)) else printErrorMessageE(newclass,"expected a hash table as prospective class")); AssignNewFun = assignNewFun; +setup(NewS,AssignNewFun); assignNewOfFun(newclass:Code,newparent:Code,rhs:Code):Expr := ( c := eval(newclass); when c is Error do c @@ -910,6 +911,7 @@ assignNewOfFun(newclass:Code,newparent:Code,rhs:Code):Expr := ( else printErrorMessageE(newparent,"expected a hash table as prospective parent")) else printErrorMessageE(newclass,"expected a hash table as prospective class")); AssignNewOfFun = assignNewOfFun; +setup(NewOfS,AssignNewOfFun); assignNewFromFun(newclass:Code,newinitializer:Code,rhs:Code):Expr := ( c := eval(newclass); when c is Error do c @@ -920,6 +922,7 @@ assignNewFromFun(newclass:Code,newinitializer:Code,rhs:Code):Expr := ( else printErrorMessageE(newinitializer,"expected a hash table")) else printErrorMessageE(newclass,"expected a hash table as prospective class")); AssignNewFromFun = assignNewFromFun; +setup(NewFromS,AssignNewFromFun); assignNewOfFromFun(args:CodeSequence):Expr := ( newclass := args.0; newparent := args.1; @@ -946,6 +949,7 @@ assignNewOfFromFun(args:CodeSequence):Expr := ( else printErrorMessageE(newclass,"expected a hash table as prospective class") ); AssignNewOfFromFun = assignNewOfFromFun; +setup(NewOfFromS,AssignNewOfFromFun); installFun2(a:Expr,args:CodeSequence):Expr := ( opr := eval(args.0); when opr @@ -1010,6 +1014,7 @@ installMethodFun2(arg1:Expr,args:CodeSequence):Expr := ( else buildErrorPacket("expected left hand parameter to be a function, type, or a hash table")); installMethodFun(args:CodeSequence):Expr := installMethodFun2(eval(args.1),args); InstallMethodFun = installMethodFun; +setup(ColonEqualS,InstallMethodFun); mess1 := "objects on left hand side of assignment are not types (use ':=' instead?)"; @@ -1044,6 +1049,7 @@ installValueFun(args:CodeSequence):Expr := ( -- else buildErrorPacket(mess1)) -- else buildErrorPacket(mess1)); InstallValueFun = installValueFun; +setup(EqualS,InstallValueFun); unaryInstallMethodFun(meth:Code,argtype:Code,body:Code):Expr := ( f := eval(meth); @@ -1058,6 +1064,7 @@ unaryInstallMethodFun(meth:Code,argtype:Code,body:Code):Expr := ( ) else printErrorMessageE(argtype,"expected a hash table"))); UnaryInstallMethodFun = unaryInstallMethodFun; +setup(ColonEqualS,UnaryInstallMethodFun); unaryInstallValueFun(meth:Code,lhs:Code,rhs:Code):Expr := ( oper := eval(meth); @@ -1089,6 +1096,7 @@ unaryInstallValueFun(meth:Code,lhs:Code,rhs:Code):Expr := ( -- else printErrorMessageE(argtype,"expected a hash table") -- ); UnaryInstallValueFun = unaryInstallValueFun; +setup(EqualS,UnaryInstallValueFun); flatten(a:Sequence):Sequence := ( -- warning - this function may return its argument without copying diff --git a/M2/Macaulay2/d/actors2.dd b/M2/Macaulay2/d/actors2.dd index a62b7a10921..41580ed10ab 100644 --- a/M2/Macaulay2/d/actors2.dd +++ b/M2/Macaulay2/d/actors2.dd @@ -660,24 +660,6 @@ unSingleton(e:Expr):Expr := ( else e); setupfun("unsequence",unSingleton); -disassemble(e:Expr):Expr := ( - when e - is f:FunctionClosure do toExpr(tostring(Code(f.model))) - is f:functionCode do toExpr(tostring(Code(f))) - is c:CodeClosure do toExpr(tostring(c.code)) - is s:SpecialExpr do disassemble(s.e) - else WrongArg("pseudocode or a function closure derived from Macaulay 2 code") - ); -setupfun("disassemble", disassemble); - -pseudocode(e:Expr):Expr := ( - when e - is f:FunctionClosure do Expr(CodeClosure(f.frame, Code(f.model))) - is s:SpecialExpr do pseudocode(s.e) - else WrongArg("a function closure derived from Macaulay 2 code") - ); -setupfun("pseudocode", pseudocode); - cpuTime(e:Expr):Expr := ( when e is s:Sequence do if length(s) == 0 then toExpr(cpuTime()) diff --git a/M2/Macaulay2/d/actors3.d b/M2/Macaulay2/d/actors3.d index d8764266a4f..851c29c55a5 100644 --- a/M2/Macaulay2/d/actors3.d +++ b/M2/Macaulay2/d/actors3.d @@ -1213,7 +1213,7 @@ map(a1:Sequence,a2:Sequence,f:Expr):Expr := ( Expr(ret) ) else ( -- (x,y) -> ... - if numparms != 2 then WrongNumArgs(model.arrow,numparms,2) + if numparms != 2 then WrongNumArgs(Code(model),numparms,2) else ( saveLocalFrame := localFrame; values := new Sequence len framesize do provide nullE; @@ -1340,7 +1340,7 @@ map(a:Sequence,f:Expr):Expr := ( when arg is args:Sequence do ( if 1 == length(args) then values.0 = args.0 else ( - errret = WrongNumArgs(model.arrow,numparms,length(args)); + errret = WrongNumArgs(Code(model),numparms,length(args)); while true do provide nullE; ) ) @@ -1367,7 +1367,7 @@ map(a:Sequence,f:Expr):Expr := ( when arg is args:Sequence do ( if 1 == length(args) then values.0 = args.0 else ( - errret = WrongNumArgs(model.arrow,numparms,length(args)); + errret = WrongNumArgs(Code(model),numparms,length(args)); while true do provide nullE; ) ) @@ -1406,12 +1406,12 @@ map(a:Sequence,f:Expr):Expr := ( foreach arg in a do ( when arg is args:Sequence do ( if 0 != length(args) then ( - errret = WrongNumArgs(model.arrow,0,length(args)); + errret = WrongNumArgs(Code(model),0,length(args)); while true do provide nullE; ) ) else ( - errret = WrongNumArgs(model.arrow,numparms,1); + errret = WrongNumArgs(Code(model),numparms,1); while true do provide nullE; ); tmp := eval(body); @@ -1445,12 +1445,12 @@ map(a:Sequence,f:Expr):Expr := ( foreach x at i in args do values.i = x; ) else ( - errret=WrongNumArgs(model.arrow,numparms,length(args)); + errret=WrongNumArgs(Code(model),numparms,length(args)); while true do provide nullE; ) ) else ( - errret = WrongNumArgs(model.arrow,numparms,1); + errret = WrongNumArgs(Code(model),numparms,1); while true do provide nullE; ); tmp := eval(body); @@ -1529,7 +1529,7 @@ map(newlen:int,f:Expr):Expr := ( numparms := desc.numparms; framesize := desc.framesize; if numparms != 1 then ( - errret = WrongNumArgs(model.arrow,numparms,1); + errret = WrongNumArgs(Code(model),numparms,1); while true do provide nullE; ) else ( @@ -1716,7 +1716,7 @@ scan(n:int,f:Expr):Expr := ( framesize := desc.framesize; if numparms != 1 then ( recursionDepth = recursionDepth - 1; - return WrongNumArgs(model.arrow,numparms,1); + return WrongNumArgs(Code(model),numparms,1); ); if framesize == 1 then ( values := new Sequence len framesize do provide nullE; @@ -1848,7 +1848,7 @@ scan(a:Sequence,f:Expr):Expr := ( else ( recursionDepth = recursionDepth - 1; localFrame = saveLocalFrame; - return WrongNumArgs(model.arrow,numparms,length(args)); + return WrongNumArgs(Code(model),numparms,length(args)); ) ) else values.0 = arg; @@ -1874,7 +1874,7 @@ scan(a:Sequence,f:Expr):Expr := ( else ( recursionDepth = recursionDepth - 1; localFrame = saveLocalFrame; - return WrongNumArgs(model.arrow,numparms,length(args)); + return WrongNumArgs(Code(model),numparms,length(args)); ) ) else values.0 = arg; @@ -1903,13 +1903,13 @@ scan(a:Sequence,f:Expr):Expr := ( if 0 != length(args) then ( recursionDepth = recursionDepth - 1; localFrame = saveLocalFrame; - return WrongNumArgs(model.arrow,0,length(args)); + return WrongNumArgs(Code(model),0,length(args)); ) ) else ( recursionDepth = recursionDepth - 1; localFrame = saveLocalFrame; - return WrongNumArgs(model.arrow,numparms,1); + return WrongNumArgs(Code(model),numparms,1); ); tmp := eval(body); when tmp is err:Error do ( @@ -1931,13 +1931,13 @@ scan(a:Sequence,f:Expr):Expr := ( else ( recursionDepth = recursionDepth - 1; localFrame = saveLocalFrame; - return WrongNumArgs(model.arrow,numparms,length(args)); + return WrongNumArgs(Code(model),numparms,length(args)); ) ) else ( recursionDepth = recursionDepth - 1; localFrame = saveLocalFrame; - return WrongNumArgs(model.arrow,numparms,1); + return WrongNumArgs(Code(model),numparms,1); ); tmp := eval(body); when tmp is err:Error do ( @@ -2043,7 +2043,7 @@ scan(a1:Sequence,a2:Sequence,f:Expr):Expr := ( recursionDepth = recursionDepth - 1; nullE) else ( -- (x,y) -> ... - if numparms != 2 then WrongNumArgs(model.arrow,numparms,2) + if numparms != 2 then WrongNumArgs(Code(model),numparms,2) else ( saveLocalFrame := localFrame; values := new Sequence len framesize do provide nullE; diff --git a/M2/Macaulay2/d/actors4.d b/M2/Macaulay2/d/actors4.d index 50ca7c72f17..76bf21f5ca5 100644 --- a/M2/Macaulay2/d/actors4.d +++ b/M2/Macaulay2/d/actors4.d @@ -1011,7 +1011,8 @@ tostringfun(e:Expr):Expr := ( + tostring(Ccode(int,"\n # if WITH_MYSQL \n (", fld.fld, ")->type \n #else \n 0 \n #endif \n")) + ">>") is Net do toExpr("<>") - is CodeClosure do toExpr("<>") + is PseudocodeClosure do toExpr("<>") + is Pseudocode do toExpr("<>") is functionCode do toExpr("<>") is CompiledFunction do toExpr("<>") is CompiledFunctionClosure do toExpr("<>") @@ -1585,127 +1586,6 @@ precision(e:Expr):Expr := ( else WrongArgRR()); setupfun("precision0",precision); --- locate: - -positionRange := {filename:string, minline:int, mincol:int, maxline:int, maxcol:int}; -threadLocal locatedCode := positionRange("",0,0,0,0); -lookat(p:Position):void := ( - if p == dummyPosition then return; - locatedCode.filename = p.filename; - if locatedCode.minline > int(p.line) then ( - locatedCode.minline = int(p.line); - locatedCode.mincol = int(p.column); - ) - else if locatedCode.minline == int(p.line) && locatedCode.mincol > int(p.column) then ( - locatedCode.mincol = int(p.column); - ); - if locatedCode.maxline < int(p.line) then ( - locatedCode.maxline = int(p.line); - locatedCode.maxcol = int(p.column); - ) - else if locatedCode.maxline == int(p.line) && locatedCode.maxcol < int(p.column) then ( - locatedCode.maxcol = int(p.column); - ); - ); -locate(x:Token):void := lookat(position(x)); -locate(e:Code):void := ( - when e - is nullCode do nothing - is v:adjacentCode do (lookat(v.position); locate(v.lhs); locate(v.rhs);) - is v:augmentedAssignmentCode do (lookat(v.position); locate(v.lhs); locate(v.rhs)) - is v:arrayCode do foreach c in v.z do locate(c) - is v:angleBarListCode do foreach c in v.t do locate(c) - is v:Error do lookat(v.position) - is v:semiCode do foreach c in v.w do locate(c) - is v:binaryCode do (lookat(v.position); locate(v.lhs); locate(v.rhs);) - is v:evaluatedCode do lookat(v.position) - is v:forCode do ( lookat(v.position); locate(v.fromClause); locate(v.toClause); locate(v.whenClause); locate(v.listClause); locate(v.doClause); ) - is v:functionCode do (locate(v.arrow);locate(v.body);) - is v:globalAssignmentCode do (lookat(v.position); locate(v.rhs);) - is v:globalMemoryReferenceCode do lookat(v.position) - is v:threadMemoryReferenceCode do lookat(v.position) - is v:globalSymbolClosureCode do lookat(v.position) - is v:threadSymbolClosureCode do lookat(v.position) - is v:ifCode do ( lookat(v.position); locate(v.predicate); locate(v.thenClause); locate(v.elseClause); ) - is v:integerCode do lookat(v.position) - is v:listCode do foreach c in v.y do locate(c) - is v:localAssignmentCode do (lookat(v.position); locate(v.rhs);) - is v:localMemoryReferenceCode do lookat(v.position) - is v:localSymbolClosureCode do lookat(v.position) - is v:multaryCode do ( lookat(v.position); foreach c in v.args do locate(c);) - is v:newCode do ( lookat(v.position); locate(v.newClause); ) - is v:newFromCode do ( lookat(v.position); locate(v.newClause); locate(v.fromClause); ) - is v:newLocalFrameCode do locate(v.body) - is v:newOfCode do ( lookat(v.position); locate(v.newClause); locate(v.ofClause); ) - is v:newOfFromCode do ( lookat(v.position); locate(v.newClause); locate(v.ofClause); locate(v.fromClause); ) - is v:parallelAssignmentCode do (lookat(v.position); locate(v.rhs);) - is v:realCode do lookat(v.position) - is v:sequenceCode do foreach c in v.x do locate(c) - is v:stringCode do nothing - is v:ternaryCode do ( lookat(v.position); locate(v.arg1); locate(v.arg2); locate(v.arg3);) - is v:tryCode do ( lookat(v.position); locate(v.code); locate(v.thenClause); locate(v.elseClause); ) - is v:catchCode do ( lookat(v.position); locate(v.code); ) - is v:unaryCode do (lookat(v.position); locate(v.rhs);) - is v:whileDoCode do ( lookat(v.position); locate(v.predicate); locate(v.doClause); ) - is v:whileListCode do ( lookat(v.position); locate(v.predicate); locate(v.listClause); ) - is v:whileListDoCode do ( lookat(v.position); locate(v.predicate); locate(v.listClause); locate(v.doClause); ) - ); -locate0():void := ( - locatedCode.filename = "-*unknown file name*-"; - locatedCode.minline = 1000000; - locatedCode.maxline = 0; - ); -locate1():void := ( - if locatedCode.minline == 1000000 then ( - locatedCode.minline = 0; - locatedCode.mincol = 0; - locatedCode.maxcol = 0; - )); -locate2(c:Code):Expr := ( - locate1(); - p := codePosition(c); - Expr(Sequence( - toExpr(verifyMinimizeFilename(locatedCode.filename)), - toExpr(locatedCode.minline), - toExpr(locatedCode.mincol), - toExpr(locatedCode.maxline), - toExpr(locatedCode.maxcol), - toExpr(int(p.line)), - toExpr(int(p.column))))); -locate(e:Expr):Expr := ( - when e - is Nothing do nullE - is Sequence do locate(lookupfun(e)) - is CompiledFunction do nullE - is CompiledFunctionClosure do nullE - is s:SymbolClosure do ( - p := s.symbol.position; - if p == dummyPosition - then nullE - else Expr( - Sequence( - toExpr(verifyMinimizeFilename(p.filename)), - toExpr(int(p.line)),toExpr(int(p.column)), - toExpr(int(p.line)),toExpr(int(p.column)+length(s.symbol.word.name)), - toExpr(int(p.line)),toExpr(int(p.column)) - ))) - is c:CodeClosure do ( - locate0(); - locate(c.code); - locate2(c.code)) - is s:SpecialExpr do locate(s.e) - is f:functionCode do ( - locate0(); - locate(f.body); - locate2(f.body)) - is f:FunctionClosure do ( - locate0(); - locate(f.model.arrow); - locate(f.model.body); - locate2(f.model.body)) - else WrongArg("a function, symbol, sequence, or null")); -setupfun("locate", locate).Protected = false; -- will be overloaded in m2/methods.m2 - historyGet(e:Expr):Expr := ( when e is n:ZZcell do ( diff --git a/M2/Macaulay2/d/actors5.d b/M2/Macaulay2/d/actors5.d index 0ba5f84bbd3..d0ba64fc894 100644 --- a/M2/Macaulay2/d/actors5.d +++ b/M2/Macaulay2/d/actors5.d @@ -444,7 +444,7 @@ examine(e:Expr):Expr := ( stdIO << "symbol body :" << endl; showsym(sb.symbol); nullE) - is c:CodeClosure do ( + is c:PseudocodeClosure do ( f := c.frame; showFrames(f); nullE) @@ -1581,7 +1581,7 @@ getglobalsym(d:Dictionary,s:string):Expr := ( 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,dummyPosition,d); + t := makeSymbol(w,tempPosition,d); globalFrame.values.(t.frameindex))); getglobalsym(s:string):Expr := ( @@ -1590,7 +1590,7 @@ getglobalsym(s:string):Expr := ( 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,dummyPosition,globalDictionary); + t := makeSymbol(w,tempPosition,globalDictionary); globalFrame.values.(t.frameindex))); getGlobalSymbol(e:Expr):Expr := ( @@ -1625,14 +1625,14 @@ setupfun("isGlobalSymbol",isGlobalSymbol); -- else WrongNumArgs(0)); -- setupfun("history",history); -listFrame(s:Sequence):Expr := Expr(List(mutableListClass, s, nextHash(), true)); +listFrame(s:Sequence):Expr := Expr(List(mutableListClass, s, nextHash(), true)); listFrame(f:Frame):Expr := if f.frameID == 0 then listFrame(emptySequence) else listFrame(f.values); -- refuse to defeat the protection of global variables frame(e:Expr):Expr := ( when e is s:Sequence do if length(s) == 0 then Expr(listFrame(localFrame)) else WrongNumArgs(1,2) is sc:SymbolClosure do Expr(listFrame(sc.frame)) - is c:CodeClosure do Expr(listFrame(c.frame)) + is c:PseudocodeClosure do Expr(listFrame(c.frame)) is fc:FunctionClosure do Expr(listFrame(fc.frame)) is cfc:CompiledFunctionClosure do Expr(listFrame(cfc.env)) is CompiledFunction do Expr(listFrame(emptySequence)) @@ -1645,13 +1645,13 @@ numFrames(f:Frame):int := ( while ( n = n+1; f != f.outerFrame ) do f = f.outerFrame; n); -listFrames(f:Frame):Expr := Expr( list( new Sequence len numFrames(f) do while (provide listFrame(f) ; f != f.outerFrame ) do f = f.outerFrame)); +listFrames(f:Frame):Expr := Expr( list( new Sequence len numFrames(f) do while (provide listFrame(f) ; f != f.outerFrame ) do f = f.outerFrame)); frames(e:Expr):Expr := ( when e is a:Sequence do if length(a) == 0 then listFrames(localFrame) else WrongNumArgs(0,1) is sc:SymbolClosure do Expr(listFrames(sc.frame)) - is c:CodeClosure do Expr(listFrames(c.frame)) + is c:PseudocodeClosure do Expr(listFrames(c.frame)) is fc:FunctionClosure do Expr(listFrames(fc.frame)) is cfc:CompiledFunctionClosure do Expr(list(listFrame(cfc.env))) is CompiledFunction do Expr(list(listFrame(emptySequence))) @@ -1666,7 +1666,7 @@ localDictionaries(e:Expr):Expr := ( is x:Sequence do if length(x) != 0 then WrongNumArgs(0,1) else localDictionaries(noRecycle(localFrame)) is x:DictionaryClosure do localDictionaries(x.frame) is x:SymbolClosure do localDictionaries(x.frame) - is x:CodeClosure do localDictionaries(x.frame) + is x:PseudocodeClosure do localDictionaries(x.frame) is x:FunctionClosure do localDictionaries(x.frame) is CompiledFunctionClosure do localDictionaries(emptyFrame) -- some values are there, but no symbols is CompiledFunction do localDictionaries(emptyFrame) -- no values or symbols are there diff --git a/M2/Macaulay2/d/basic.d b/M2/Macaulay2/d/basic.d index 945ce77c335..86a42005a81 100644 --- a/M2/Macaulay2/d/basic.d +++ b/M2/Macaulay2/d/basic.d @@ -16,9 +16,10 @@ export hash(e:Expr):hash_t := ( is x:List do x.hash is f:functionCode do f.hash is MysqlConnectionWrapper do hash_t(237489) -- improve this later! - is MysqlFieldWrapper do hash_t(23748) -- improve this later! - is MysqlResultWrapper do hash_t(2374) -- improve this later! - is CodeClosure do hash_t(73889) -- improve this later! + is MysqlFieldWrapper do hash_t(23748) -- improve this later! + is MysqlResultWrapper do hash_t(2374) -- improve this later! + is PseudocodeClosure do hash_t(73889) -- improve this later! + is Pseudocode do hash_t(173889) -- improve this later! is x:DictionaryClosure do x.dictionary.hash -- there may be many dictionary closures with the same dictionary and different frames, too bad is x:QQcell do hash(x.v) is x:RRcell do hash(x.v) diff --git a/M2/Macaulay2/d/binding.d b/M2/Macaulay2/d/binding.d index 9a151fd38f7..6352a19e97c 100644 --- a/M2/Macaulay2/d/binding.d +++ b/M2/Macaulay2/d/binding.d @@ -400,7 +400,7 @@ export StopIterationE := Expr(StopIterationS); ----------------------------------------------------------------------------- export makeSymbol(t:Token):Symbol := ( - e := makeSymbol(t.word,position(t),t.dictionary); + e := makeSymbol(t.word,t.position,t.dictionary); t.entry = e; e); export makeErrorTree(e:ParseTree,message:string):void := ( @@ -462,6 +462,7 @@ lookup(t:Token,forcedef:bool,thread:bool):void := ( when lookup(t.word,t.dictionary) is entry:Symbol do ( t.entry = entry; + if entry.position == tempPosition then entry.position = t.position; if entry.flagLookup then ( printErrorMessage(t,"flagged symbol encountered"); HadError=true; @@ -483,7 +484,7 @@ lookup(t:Token,forcedef:bool,thread:bool):void := ( locallyCreated := t.dictionary.frameID != 0 && dictionaryDepth(t.dictionary) > 0; t.dictionary = globalDictionary; -- undefined variables are defined as global - t.entry = makeSymbol(t.word,position(t),globalDictionary,thread,locallyCreated); + t.entry = makeSymbol(t.word,t.position,globalDictionary,thread,locallyCreated); ) else ( printErrorMessage(t,"undefined symbol " + t.word.name); @@ -766,13 +767,13 @@ export bind(e:ParseTree,dictionary:Dictionary):void := ( when e is i:IfThen do ( bind(i.predicate,dictionary); - -- i.thenclause = bindnewdictionary(i.thenclause,dictionary); - bind(i.thenclause,dictionary); + -- i.thenClause = bindnewdictionary(i.thenClause,dictionary); + bind(i.thenClause,dictionary); ) is i:IfThenElse do ( bind(i.predicate,dictionary); - -- i.thenclause = bindnewdictionary(i.thenclause,dictionary); - bind(i.thenclause,dictionary); + -- i.thenClause = bindnewdictionary(i.thenClause,dictionary); + bind(i.thenClause,dictionary); -- i.elseClause = bindnewdictionary(i.elseClause,dictionary); bind(i.elseClause,dictionary); ) diff --git a/M2/Macaulay2/d/classes.dd b/M2/Macaulay2/d/classes.dd index d00123afce9..786fd3d7832 100644 --- a/M2/Macaulay2/d/classes.dd +++ b/M2/Macaulay2/d/classes.dd @@ -7,7 +7,8 @@ setupconst("HashTable",Expr(hashTableClass)); setupconst("Dictionary",Expr(dictionaryClass)); setupconst("LocalDictionary",Expr(localDictionaryClass)); setupconst("GlobalDictionary",Expr(globalDictionaryClass)); -setupconst("Pseudocode",Expr(codeClass)); +setupconst("Pseudocode",Expr(pseudocodeClass)); +setupconst("PseudocodeClosure",Expr(pseudocodeClosureClass)); setupconst("FunctionBody",Expr(functionBodyClass)); setupconst("SymbolBody",Expr(symbolBodyClass)); setupconst("CompiledFunctionBody",Expr(compiledFunctionBodyClass)); @@ -119,7 +120,8 @@ export Class(e:Expr):HashTable := ( is obj:HashTable do obj.Class is x:List do x.Class is ZZcell do ZZClass - is CodeClosure do codeClass + is PseudocodeClosure do pseudocodeClosureClass + is Pseudocode do pseudocodeClass is pythonObjectCell do pythonObjectClass is xmlNodeCell do xmlNodeClass is TaskCell do taskClass diff --git a/M2/Macaulay2/d/common.d b/M2/Macaulay2/d/common.d index 241b7a736ac..39b045e197f 100644 --- a/M2/Macaulay2/d/common.d +++ b/M2/Macaulay2/d/common.d @@ -1,9 +1,9 @@ -- Copyright 1994-2003 by Daniel R. Grayson - use basic; use binding; +use stdiop0; -export codePosition(c:Code):Position := ( +export codePosition(c:Code):Position := ( -- TODO retire when c is f:adjacentCode do f.position is f:augmentedAssignmentCode do f.position @@ -14,7 +14,7 @@ export codePosition(c:Code):Position := ( is f:Error do f.position is f:evaluatedCode do f.position is f:forCode do f.position - is f:functionCode do position(f.arrow) + is f:functionCode do f.position is f:globalAssignmentCode do f.position is f:globalMemoryReferenceCode do f.position is f:globalSymbolClosureCode do f.position @@ -35,7 +35,7 @@ export codePosition(c:Code):Position := ( is f:realCode do f.position is f:semiCode do f.position is f:sequenceCode do f.position - is f:stringCode do dummyPosition + is f:stringCode do f.position is f:ternaryCode do f.position is f:threadMemoryReferenceCode do f.position is f:threadSymbolClosureCode do f.position @@ -56,7 +56,7 @@ export tostring(c:Code):string := ( is x:semiCode do concatenate(array(string)( "(semi ", between(" ",new array(string) len length(x.w) do foreach s in x.w do provide tostring(s)), ")")) is x:arrayCode do concatenate(array(string)( "(array ", between(" ",new array(string) len length(x.z) do foreach s in x.z do provide tostring(s)), ")")) is x:angleBarListCode do concatenate(array(string)( "(angleBarList ", between(" ",new array(string) len length(x.t) do foreach s in x.t do provide tostring(s)), ")")) - is x:binaryCode do concatenate(array(string)("(2-OP ",getBinopName(x.f)," ",tostring(x.lhs)," ",tostring(x.rhs),")")) + is x:binaryCode do concatenate(array(string)("(2-OP ",getBinopName(x.f).word.name," ",tostring(x.lhs)," ",tostring(x.rhs),")")) is x:adjacentCode do concatenate(array(string)("(adjacent ",tostring(x.lhs)," ",tostring(x.rhs),")")) is x:evaluatedCode do concatenate(array(string)( "(expr ", @@ -94,7 +94,7 @@ export tostring(c:Code):string := ( is x:listCode do concatenate(array(string)( "(list ", between(" ",new array(string) len length(x.y) do foreach s in x.y do provide tostring(s)), ")")) is x:localMemoryReferenceCode do concatenate(array(string)("(fetch ",tostring(x.frameindex)," ",tostring(x.nestingDepth),")")) is x:localSymbolClosureCode do concatenate(array(string)("(local ",x.symbol.word.name," nestingDepth: ",tostring(x.nestingDepth),")")) - is x:multaryCode do concatenate(array(string)( "(OP ",getMultopName(x.f)," ", between(" ",new array(string) len length(x.args) do foreach c in x.args do provide tostring(c)), ")" )) + is x:multaryCode do concatenate(array(string)( "(OP ",getMultopName(x.f).word.name," ", between(" ",new array(string) len length(x.args) do foreach c in x.args do provide tostring(c)), ")" )) is x:newLocalFrameCode do concatenate(array(string)()) is x:nullCode do "(null)" is x:parallelAssignmentCode do ( @@ -103,9 +103,9 @@ export tostring(c:Code):string := ( array(string)( "(parallel-assign (", between(" ", - new array(string) len length(x.nestingDepth) do - for i from 0 to n-1 do - if x.lhs.i == dummySymbol + new array(string) len n do + for i from 0 to n-1 do + if x.lhs.i == dummySymbol then provide concatenate(array(string)("(",tostring(x.frameindex.i)," ",tostring(x.nestingDepth.i),")")) else provide join("'",x.lhs.i.word.name)), ") ", tostring(x.rhs), ")" ) ) ) @@ -122,76 +122,82 @@ export tostring(c:Code):string := ( between(" ",new array(string) len length(x.x) do foreach s in x.x do provide tostring(s)), ")"))) is x:stringCode do concatenate(array(string)("\"",present(x.x),"\"")) - is x:ternaryCode do concatenate(array(string)("(3-OP ",getTernopName(x.f)," ",tostring(x.arg1)," ",tostring(x.arg2)," ",tostring(x.arg3),")")) + is x:ternaryCode do concatenate(array(string)("(3-OP ",getTernopName(x.f).word.name," ",tostring(x.arg1)," ",tostring(x.arg2)," ",tostring(x.arg3),")")) is x:ifCode do concatenate(array(string)("(if ",tostring(x.predicate)," then: ",tostring(x.thenClause)," else: ",tostring(x.elseClause),")")) is x:tryCode do concatenate(array(string)("(try ",tostring(x.code)," ",tostring(x.thenClause)," ",tostring(x.elseClause),")")) is x:catchCode do concatenate(array(string)("(catch ",tostring(x.code),")")) - is x:unaryCode do concatenate(array(string)("(1-OP ",getUnopName(x.f)," ",tostring(x.rhs),")")) + is x:unaryCode do concatenate(array(string)("(1-OP ",getUnopName(x.f).word.name," ",tostring(x.rhs),")")) ); export setup(word:Word):void := ( makeSymbol(word,dummyPosition,globalDictionary); ); export setup(word:Word,fn:unop):void := ( - unopNameList = unopNameListCell(fn,word.name,unopNameList); e := makeSymbol(word,dummyPosition,globalDictionary); + unopNameList = unopNameListCell(fn,e,unopNameList); e.unary = fn; ); export setup(word:Word,fn:binop):void := ( - binopNameList = binopNameListCell(fn,word.name,binopNameList); e := makeSymbol(word,dummyPosition,globalDictionary); + binopNameList = binopNameListCell(fn,e,binopNameList); e.binary = fn; ); export setup(word:Word,fun1:unop,fun2:binop):void := ( - unopNameList = unopNameListCell(fun1,word.name,unopNameList); - binopNameList = binopNameListCell(fun2,word.name,binopNameList); e := makeSymbol(word,dummyPosition,globalDictionary); + unopNameList = unopNameListCell(fun1,e,unopNameList); + binopNameList = binopNameListCell(fun2,e,binopNameList); e.unary = fun1; e.binary = fun2; ); export setup(word:Word,fun1:unop,fun2:unop):void := ( - unopNameList = unopNameListCell(fun1,word.name,unopNameList); - unopNameList = unopNameListCell(fun2,word.name,unopNameList); e := makeSymbol(word,dummyPosition,globalDictionary); + unopNameList = unopNameListCell(fun2,e,unopNameList); + unopNameList = unopNameListCell(fun1,e,unopNameList); e.unary = fun1; e.postfix = fun2; ); export setup(e:SymbolClosure,fn:unop):void := ( - unopNameList = unopNameListCell(fn,e.symbol.word.name,unopNameList); + unopNameList = unopNameListCell(fn,e.symbol,unopNameList); e.symbol.unary = fn; ); export setuppostfix(e:SymbolClosure,fn:unop):void := ( - unopNameList = unopNameListCell(fn,e.symbol.word.name,unopNameList); + unopNameList = unopNameListCell(fn,e.symbol,unopNameList); e.symbol.postfix = fn; ); export setup(e:SymbolClosure,fn:binop):void := ( - binopNameList = binopNameListCell(fn,e.symbol.word.name,binopNameList); + binopNameList = binopNameListCell(fn,e.symbol,binopNameList); e.symbol.binary = fn; ); export setup(e:SymbolClosure,fun1:unop,fun2:binop):void := ( - unopNameList = unopNameListCell(fun1,e.symbol.word.name,unopNameList); - binopNameList = binopNameListCell(fun2,e.symbol.word.name,binopNameList); + unopNameList = unopNameListCell(fun1,e.symbol,unopNameList); + binopNameList = binopNameListCell(fun2,e.symbol,binopNameList); e.symbol.unary = fun1; e.symbol.binary = fun2; ); export setup(e:SymbolClosure,fun1:unop,fun2:unop):void := ( - unopNameList = unopNameListCell(fun1,e.symbol.word.name,unopNameList); - unopNameList = unopNameListCell(fun2,e.symbol.word.name,unopNameList); + unopNameList = unopNameListCell(fun1,e.symbol,unopNameList); + unopNameList = unopNameListCell(fun2,e.symbol,unopNameList); e.symbol.unary = fun1; e.symbol.postfix = fun2; ); export setupop(s:SymbolClosure,fun:unop):void := ( - unopNameList = unopNameListCell(fun,s.symbol.word.name,unopNameList); + unopNameList = unopNameListCell(fun,s.symbol,unopNameList); s.symbol.unary = fun; ); +export setup(e:SymbolClosure,fn:ternop):void := ( + ternopNameList = ternopNameListCell(fn,e.symbol,ternopNameList); + ); +export setup(e:SymbolClosure,fn:multop):void := ( + multopNameList = multopNameListCell(fn,e.symbol,multopNameList); + ); export setupfun(name:string,fun:unop):Symbol := ( - unopNameList = unopNameListCell(fun,name,unopNameList); word := makeUniqueWord(name, parseinfo(precSpace,precSpace,precSpace,parsefuns(unaryop, defaultbinary))); entry := makeSymbol(word,dummyPosition,globalDictionary); + unopNameList = unopNameListCell(fun,entry,unopNameList); entry.unary = fun; entry.Protected = true; - entry); + entry); export setupfun(name:string,value:fun):Symbol := ( word := makeUniqueWord(name,parseWORD); entry := makeSymbol(word,dummyPosition,globalDictionary); @@ -234,7 +240,7 @@ export printErrorMessageE(p:Position,message:string):Expr := ( -- for use when w if p.loadDepth >= errorDepth then printError(e); Expr(e)); export printErrorMessageE(c:Token,message:string):Expr := ( -- for use when we have no code - printErrorMessageE(position(c),message)); + printErrorMessageE(c.position,message)); export returnFromFunction(z:Expr):Expr := when z is err:Error do if err.message == returnMessage then err.value else z else z; export returnFromLoop(z:Expr):Expr := when z is err:Error do if err.message == breakMessage then if err.value == dummyExpr then nullE else err.value else z else z; @@ -248,6 +254,7 @@ export WrongNumArgs(c:Token,wanted:int,got:int):Expr := ( + (if wanted == 1 then "" else "s") + ", but got " + tostring(got))); + ----------------------------------------------------------------------------- hashfun(e:Expr):Expr := Expr(ZZcell(toInteger(hash(e)))); diff --git a/M2/Macaulay2/d/convertr.d b/M2/Macaulay2/d/convertr.d index 7548b1badd8..1104034d325 100644 --- a/M2/Macaulay2/d/convertr.d +++ b/M2/Macaulay2/d/convertr.d @@ -1,5 +1,7 @@ -- Copyright 1994 by Daniel R. Grayson use binding; +use common; +use util; dummyMultaryFun(c:CodeSequence):Expr := ( error("dummy multary function called"); @@ -23,7 +25,14 @@ export UnaryInstallMethodFun := dummyTernaryFun; export InstallValueFun := dummyMultaryFun; export UnaryInstallValueFun := dummyTernaryFun; +combinePosition(a:Position,b:Position):Position := Position(a.filename,b.line,b.column,a.line1,a.column1,b.line2,b.column2,a.loadDepth); -- combine with emphasis on right +combinePositionLeft(a:Position,b:Position):Position := Position(a.filename,a.line,a.column,a.line1,a.column1,b.line2,b.column2,a.loadDepth); -- combine with emphasis on left +combinePosition(a:Position,b:Position,c:Position):Position := Position(a.filename,c.line,c.column,a.line1,a.column1,b.line2,b.column2,a.loadDepth); -- left, right, center +combinePositionAdjacent(a:Position,b:Position):Position := Position(a.filename,a.line2,a.column2,a.line1,a.column1,b.line2,b.column2,a.loadDepth); -- special for Adjacent + +convert0(e:ParseTree):Code; convert(e:ParseTree):Code; +unseq(c:Code):Code; CodeSequenceLength(e:ParseTree,separator:Word):int := ( i := 0; while true do ( @@ -110,50 +119,69 @@ nestingDepth(frameID:int,d:Dictionary):int := ( ); n); -tokenAssignment(e:ParseTree,b:Binary,t:Token):Code := ( +tokenAssignment(t:Token,p:ParseTree):Code := ( + c:=convert0(p); + l:=combinePosition(t.position,codePosition(c)); + c=unseq(c); if t.entry.frameID == 0 - then Code(globalAssignmentCode(t.entry,convert(b.rhs),treePosition(e))) - else Code(localAssignmentCode(nestingDepth(t.entry.frameID,t.dictionary),t.entry.frameindex,convert(b.rhs),treePosition(e))) + then Code(globalAssignmentCode(t.entry,c,l)) + else Code(localAssignmentCode(nestingDepth(t.entry.frameID,t.dictionary),t.entry.frameindex,c,l)) ); -parallelAssignment(e:ParseTree,b:Binary,p:Parentheses):Code := ( - symbols := makeSymbolSequence(b.lhs); +parallelAssignment(par:Parentheses,rhs:ParseTree,d:Dictionary):Code := ( + symbols := makeSymbolSequence(ParseTree(par)); -- silly -- rethink n := length(symbols); - nd := new array(int) len n do foreach x in symbols do provide nestingDepth(x.frameID,b.Operator.dictionary); + nd := new array(int) len n do foreach x in symbols do provide nestingDepth(x.frameID,d); -- rethink dictionary fr := new array(int) len n do foreach x in symbols do provide x.frameindex; foreach x in symbols do if x.frameID != 0 then x = dummySymbol; Code(parallelAssignmentCode( nd, fr, symbols, - convert(b.rhs), - treePosition(e) + unseq(c:=convert0(rhs)), + combinePosition(par.left.position,codePosition(c)) )) ); -export convert(e:ParseTree):Code := ( +export unseq(c:Code):Code := ( + when c + is s:sequenceCode do ( + if length(s.x)==1 then s.x.0 else c + ) + else c + ); + +export convert0(e:ParseTree):Code := ( when e - is w:For do Code( + is w:For do ( + c:=convert0(w.doClause); + cc:=convert0(w.listClause); + loc:=codePosition(c); + when c is + nullCode do loc=codePosition(cc) + else nothing; + Code( forCode( convert(w.inClause), convert(w.fromClause), convert(w.toClause), - convert(w.whenClause), convert(w.listClause), - convert(w.doClause), + convert(w.whenClause), unseq(cc), + unseq(c), w.dictionary.frameID, w.dictionary.framesize, - treePosition(e))) - is w:WhileDo do Code(whileDoCode(convert(w.predicate),convert(w.doClause),treePosition(e))) - is w:WhileList do Code(whileListCode(convert(w.predicate),convert(w.listClause),treePosition(e))) - is w:WhileListDo do Code(whileListDoCode(convert(w.predicate),convert(w.listClause),convert(w.doClause),treePosition(e))) + combinePosition(w.forToken.position,loc) + ))) + is w:WhileDo do Code(whileDoCode(convert(w.predicate),unseq(c:=convert0(w.doClause)),combinePosition(w.whileToken.position,codePosition(c)))) + is w:WhileList do Code(whileListCode(convert(w.predicate),unseq(c:=convert0(w.listClause)),combinePosition(w.whileToken.position,codePosition(c)))) + is w:WhileListDo do Code(whileListDoCode(convert(w.predicate),convert(w.listClause),unseq(c:=convert0(w.doClause)),combinePosition(w.whileToken.position,codePosition(c)))) is n:New do ( if n.newparent == dummyTree then if n.newinitializer == dummyTree - then Code(newCode(convert(n.newclass),treePosition(e))) - else Code(newFromCode(convert(n.newclass),convert(n.newinitializer),treePosition(e))) + then Code(newCode(unseq(c:=convert0(n.newclass)),combinePosition(n.newtoken.position,codePosition(c)))) + else Code(newFromCode(convert(n.newclass),unseq(c:=convert0(n.newinitializer)),combinePosition(n.newtoken.position,codePosition(c)))) else if n.newinitializer == dummyTree - then Code(newOfCode(convert(n.newclass),convert(n.newparent),treePosition(e))) - else Code(newOfFromCode(convert(n.newclass),convert(n.newparent),convert(n.newinitializer),treePosition(e)))) - is i:IfThen do Code(ifCode(convert(i.predicate),convert(i.thenclause),NullCode,treePosition(e))) - is i:IfThenElse do Code(ifCode(convert(i.predicate),convert(i.thenclause),convert(i.elseClause),treePosition(e))) + then Code(newOfCode(convert(n.newclass),unseq(c:=convert0(n.newparent)),combinePosition(n.newtoken.position,codePosition(c)))) + else Code(newOfFromCode(convert(n.newclass),convert(n.newparent),unseq(c:=convert0(n.newinitializer)),combinePosition(n.newtoken.position,codePosition(c))))) + is i:IfThen do Code(ifCode(convert(i.predicate),unseq(c:=convert0(i.thenClause)),NullCode,combinePosition(i.ifToken.position,codePosition(c)))) + is i:IfThenElse do Code(ifCode(convert(i.predicate),convert(i.thenClause),unseq(c:=convert0(i.elseClause)),combinePosition(i.ifToken.position,codePosition(c)))) is token:Token do ( var := token.entry; wrd := token.word; @@ -161,45 +189,48 @@ export convert(e:ParseTree):Code := ( then ( x:= parseRR(wrd.name); when x - is y:RR do Code(realCode(y, position(token))) - is null do Code(Error(position(token), + is y:RR do Code(realCode(y, token.position)) + is null do Code(Error(token.position, "expected precision to be a small non-negative integer", nullE,false,dummyFrame))) else if wrd.typecode == TCint - then Code(integerCode(parseInt(wrd.name),position(token))) + then Code(integerCode(parseInt(wrd.name),token.position)) else if wrd.typecode == TCstring then ( s := parseString(wrd.name); - Code(stringCode(s)) + Code(stringCode(s,token.position)) ) else ( if var.frameID == 0 then ( if var.thread - then Code(threadMemoryReferenceCode(var.frameindex,position(token))) - else Code(globalMemoryReferenceCode(var.frameindex,position(token))) + then Code(threadMemoryReferenceCode(var.frameindex,token.position)) + else Code(globalMemoryReferenceCode(var.frameindex,token.position)) ) - else Code(localMemoryReferenceCode(nestingDepth(var.frameID,token.dictionary),var.frameindex,position(token))) + else Code(localMemoryReferenceCode(nestingDepth(var.frameID,token.dictionary),var.frameindex,token.position)) ) ) - is a:Adjacent do Code(adjacentCode(convert(a.lhs),convert(a.rhs),treePosition(e))) + is a:Adjacent do Code(adjacentCode(unseq(c:=convert0(a.lhs)),unseq(cc:=convert0(a.rhs)),combinePositionAdjacent(codePosition(c),codePosition(cc)))) is p:EmptyParentheses do ( - if p.left.word == leftparen then Code(sequenceCode(CodeSequence(),treePosition(e))) - else if p.left.word == leftbrace then Code(listCode(CodeSequence(),treePosition(e))) - else if p.left.word == leftbracket then Code(arrayCode(CodeSequence(),treePosition(e))) - else if p.left.word == leftAngleBar then Code(angleBarListCode(CodeSequence(),treePosition(e))) + pp:=combinePositionLeft(p.left.position,p.right.position); + if p.left.word == leftparen then Code(sequenceCode(CodeSequence(),pp)) + else if p.left.word == leftbrace then Code(listCode(CodeSequence(),pp)) + else if p.left.word == leftbracket then Code(arrayCode(CodeSequence(),pp)) + else if p.left.word == leftAngleBar then Code(angleBarListCode(CodeSequence(),pp)) else dummyCode -- should not happen ) is p:Parentheses do ( - if p.left.word == leftparen then convert(p.contents) + pp:=combinePositionLeft(p.left.position,p.right.position); + if p.left.word == leftparen + then Code(sequenceCode(makeCodeSequence(p.contents,CommaW),pp)) else if p.left.word == leftbrace - then Code(listCode(makeCodeSequence(p.contents,CommaW),treePosition(e))) + then Code(listCode(makeCodeSequence(p.contents,CommaW),pp)) else if p.left.word == leftbracket - then Code(arrayCode(makeCodeSequence(p.contents,CommaW),treePosition(e))) + then Code(arrayCode(makeCodeSequence(p.contents,CommaW),pp)) else if p.left.word == leftAngleBar - then Code(angleBarListCode(makeCodeSequence(p.contents,CommaW),treePosition(e))) + then Code(angleBarListCode(makeCodeSequence(p.contents,CommaW),pp)) else dummyCode -- should not happen ) @@ -211,13 +242,14 @@ export convert(e:ParseTree):Code := ( is token:Token do ( wrd := token.word; var := token.entry; + p := token.position; if wrd.typecode == TCid then ( Code(binaryCode( b.Operator.entry.binary, - convert(b.lhs), - Code(globalSymbolClosureCode(var,treePosition(b.rhs))), - treePosition(e) + unseq(c:=convert0(b.lhs)), + Code(globalSymbolClosureCode(var,p)), + combinePosition(codePosition(c),p,b.Operator.position) ) ) ) @@ -226,9 +258,9 @@ export convert(e:ParseTree):Code := ( else dummyCode -- should not occur ) else if b.Operator.word == CommaW - then Code(sequenceCode(makeCodeSequence(e,CommaW),treePosition(e))) + then Code(sequenceCode(s:=makeCodeSequence(e,CommaW),combinePositionLeft(codePosition(s.0),codePosition(s.(length(s)-1))))) else if b.Operator.word == SemicolonW - then Code(semiCode(makeCodeSequence(e,SemicolonW),treePosition(e))) + then Code(semiCode(s:=makeCodeSequence(e,SemicolonW),combinePositionLeft(codePosition(s.0),codePosition(s.(length(s)-1))))) else if b.Operator.word == EqualW then ( when b.lhs @@ -238,50 +270,50 @@ export convert(e:ParseTree):Code := ( InstallValueFun, CodeSequence( Code(globalSymbolClosureCode(AdjacentS.symbol,dummyPosition)), - convert(a.lhs), + unseq(c:=convert0(a.lhs)), convert(a.rhs), - convert(b.rhs)), - treePosition(e)))) + unseq(cc:=convert0(b.rhs))), + combinePosition(codePosition(c),codePosition(cc),b.Operator.position)))) is u:Unary do Code( ternaryCode( UnaryInstallValueFun, - Code(globalSymbolClosureCode(u.Operator.entry,position(u.Operator))), + Code(globalSymbolClosureCode(u.Operator.entry,p:=u.Operator.position)), convert(u.rhs), - convert(b.rhs), - treePosition(e))) + unseq(cc:=convert0(b.rhs)), + combinePosition(p,codePosition(cc),b.Operator.position))) is u:Postfix do Code( ternaryCode( UnaryInstallValueFun, - Code(globalSymbolClosureCode(u.Operator.entry,position(u.Operator))), - convert(u.lhs), - convert(b.rhs), - treePosition(e))) + Code(globalSymbolClosureCode(u.Operator.entry,u.Operator.position)), + unseq(c:=convert0(u.lhs)), + unseq(cc:=convert0(b.rhs)), + combinePosition(codePosition(c),codePosition(cc),b.Operator.position))) is c:Binary do ( if c.Operator.entry == SharpS.symbol - then Code(ternaryCode( AssignElemFun, convert(c.lhs), - convert(c.rhs), convert(b.rhs), treePosition(e))) + then Code(ternaryCode( AssignElemFun, c1:=convert(c.lhs), + convert(c.rhs), unseq(c2:=convert0(b.rhs)), combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) else if c.Operator.entry == DotS.symbol then ( when c.rhs is crhs:Token do Code(ternaryCode( AssignElemFun, - convert(c.lhs), - Code(globalSymbolClosureCode(crhs.entry,position(crhs))), - convert(b.rhs), - treePosition(e))) + c1:=convert(c.lhs), + Code(globalSymbolClosureCode(crhs.entry,crhs.position)), + unseq(c2:=convert0(b.rhs)), + combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) else dummyCode --should not happen ) else Code(multaryCode( InstallValueFun, CodeSequence( - Code(globalSymbolClosureCode(c.Operator.entry,position(c.Operator))), - convert(c.lhs), + Code(globalSymbolClosureCode(c.Operator.entry,c.Operator.position)), + c1:=convert(c.lhs), convert(c.rhs), - convert(b.rhs)), - treePosition(e)))) - is t:Token do tokenAssignment(e,b,t) - is p:Parentheses do parallelAssignment(e,b,p) + unseq(c2:=convert0(b.rhs))), + combinePosition(codePosition(c1),codePosition(c2),b.Operator.position)))) + is t:Token do tokenAssignment(t,b.rhs) + is p:Parentheses do parallelAssignment(p,b.rhs,b.Operator.dictionary) else dummyCode -- should not happen ) else if b.Operator.word == ColonEqualW @@ -293,153 +325,166 @@ export convert(e:ParseTree):Code := ( then Code(binaryCode( AssignNewFun, convert(n.newclass), - convert(b.rhs), - treePosition(e))) + unseq(c:=convert0(b.rhs)), + combinePosition(n.newtoken.position,codePosition(c),b.Operator.position))) else Code(ternaryCode( AssignNewFromFun, convert(n.newclass), convert(n.newinitializer), - convert(b.rhs), - treePosition(e))) + unseq(c:=convert0(b.rhs)), + combinePosition(n.newtoken.position,codePosition(c),b.Operator.position))) else if n.newinitializer == dummyTree then Code(ternaryCode( AssignNewOfFun, convert(n.newclass), convert(n.newparent), - convert(b.rhs), - treePosition(e))) + unseq(c:=convert0(b.rhs)), + combinePosition(n.newtoken.position,codePosition(c),b.Operator.position))) else Code(multaryCode( AssignNewOfFromFun, CodeSequence( convert(n.newclass), convert(n.newparent), convert(n.newinitializer), - convert(b.rhs)), - treePosition(e)))) + unseq(c:=convert0(b.rhs))), + combinePosition(n.newtoken.position,codePosition(c),b.Operator.position)))) is a:Adjacent do ( Code(multaryCode( InstallMethodFun, CodeSequence( Code(globalSymbolClosureCode(AdjacentS.symbol,dummyPosition)), - convert(a.lhs), + unseq(c:=convert0(a.lhs)), convert(a.rhs), - convert(b.rhs)), - treePosition(e)))) + unseq(cc:=convert0(b.rhs))), + combinePosition(codePosition(c),codePosition(cc),b.Operator.position)))) is u:Unary do Code(ternaryCode( UnaryInstallMethodFun, - Code(globalSymbolClosureCode(u.Operator.entry,position(u.Operator))), - convert(u.rhs), convert(b.rhs), treePosition(e))) + Code(globalSymbolClosureCode(u.Operator.entry,p:=u.Operator.position)), + convert(u.rhs), unseq(c:=convert0(b.rhs)), combinePosition(p,codePosition(c),b.Operator.position))) is u:Postfix do Code(ternaryCode( UnaryInstallMethodFun, - Code(globalSymbolClosureCode(u.Operator.entry,position(u.Operator))), - convert(u.lhs), convert(b.rhs), treePosition(e))) + Code(globalSymbolClosureCode(u.Operator.entry,u.Operator.position)), + unseq(c:=convert0(u.lhs)), unseq(cc:=convert0(b.rhs)), combinePosition(codePosition(c),codePosition(cc),b.Operator.position))) is c:Binary do ( if c.Operator.entry == SharpS.symbol - then Code(ternaryCode( AssignElemFun, convert(c.lhs), - convert(c.rhs), convert(b.rhs), treePosition(e))) + then Code(ternaryCode( AssignElemFun, c1:=convert(c.lhs), + convert(c.rhs), unseq(c2:=convert0(b.rhs)), combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) else if c.Operator.entry == UnderscoreS.symbol then Code(multaryCode( InstallMethodFun, CodeSequence( Code(globalSymbolClosureCode(UnderscoreS.symbol,dummyPosition)), - convert(c.lhs), + unseq(c1:=convert0(c.lhs)), convert(c.rhs), - convert(b.rhs)), - treePosition(e))) + unseq(c2:=convert0(b.rhs))), + combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) else if c.Operator.entry == DotS.symbol then ( when c.rhs is crhs:Token do Code(ternaryCode( AssignElemFun, - convert(c.lhs), - Code(globalSymbolClosureCode(crhs.entry,position(crhs))), - convert(b.rhs), - treePosition(e))) + unseq(c1:=convert0(c.lhs)), + Code(globalSymbolClosureCode(crhs.entry,crhs.position)), + unseq(c2:=convert0(b.rhs)), + combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) else dummyCode --should not happen ) else Code(multaryCode( InstallMethodFun, CodeSequence( - Code(globalSymbolClosureCode(c.Operator.entry,position(c.Operator))), - convert(c.lhs), + Code(globalSymbolClosureCode(c.Operator.entry,c.Operator.position)), + unseq(c1:=convert0(c.lhs)), convert(c.rhs), - convert(b.rhs)), - treePosition(e)))) - is t:Token do tokenAssignment(e,b,t) - is p:Parentheses do parallelAssignment(e,b,p) + unseq(c2:=convert0(b.rhs))), + combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) + ) + is t:Token do tokenAssignment(t,b.rhs) + is p:Parentheses do parallelAssignment(p,b.rhs,b.Operator.dictionary) else dummyCode -- should not happen ) else if isAugmentedAssignmentOperatorWord(b.Operator.word) then ( when b.lhs is a:Adjacent - do Code(augmentedAssignmentCode(b.Operator.entry, convert(b.lhs), - convert(b.rhs), AdjacentS.symbol, treePosition(e))) + do Code(augmentedAssignmentCode(b.Operator.entry, unseq(c1:=convert0(b.lhs)), + unseq(c2:=convert0(b.rhs)), AdjacentS.symbol, combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) is u:Unary - do Code(augmentedAssignmentCode(b.Operator.entry, convert(b.lhs), - convert(b.rhs), u.Operator.entry, treePosition(e))) + do Code(augmentedAssignmentCode(b.Operator.entry, unseq(c1:=convert0(b.lhs)), + unseq(c2:=convert0(b.rhs)), u.Operator.entry, combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) is u:Postfix - do Code(augmentedAssignmentCode(b.Operator.entry, convert(b.lhs), - convert(b.rhs), u.Operator.entry, treePosition(e))) + do Code(augmentedAssignmentCode(b.Operator.entry, unseq(c1:=convert0(b.lhs)), + unseq(c2:=convert0(b.rhs)), u.Operator.entry, combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) is c:Binary - do Code(augmentedAssignmentCode(b.Operator.entry, convert(b.lhs), - convert(b.rhs), c.Operator.entry, treePosition(e))) + do Code(augmentedAssignmentCode(b.Operator.entry, unseq(c1:=convert0(b.lhs)), + unseq(c2:=convert0(b.rhs)), c.Operator.entry, combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) is t:Token - do Code(augmentedAssignmentCode(b.Operator.entry, convert(b.lhs), - convert(b.rhs), t.entry, treePosition(e))) + do Code(augmentedAssignmentCode(b.Operator.entry, unseq(c1:=convert0(b.lhs)), + unseq(c2:=convert0(b.rhs)), t.entry, combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) else Code(augmentedAssignmentCode(b.Operator.entry, dummyCode, - dummyCode, dummySymbol, treePosition(e)))) - else Code(binaryCode(b.Operator.entry.binary,convert(b.lhs), - convert(b.rhs),treePosition(e))) + dummyCode, dummySymbol, dummyPosition)) -- CHECK + ) + else Code(binaryCode(b.Operator.entry.binary,unseq(c1:=convert0(b.lhs)), + unseq(c2:=convert0(b.rhs)),combinePosition(codePosition(c1),codePosition(c2),b.Operator.position))) ) is a:Arrow do ( - fc := functionCode( - a.Operator, -- just for display purposes! - convert(a.rhs),a.desc,hash_t(0)); - fc.hash = hashFromAddress(Expr(fc)); - Code(fc)) + p:=treePosition(a.lhs); + fc:=functionCode( + unseq(c:=convert0(a.rhs)),a.desc,hash_t(0), + combinePosition(p,codePosition(c),a.Operator.position)); + fc.hash = hashFromAddress(Expr(fc)); + Code(fc)) is u:Unary do ( if u.Operator.word == CommaW - then Code(sequenceCode(makeCodeSequence(e,CommaW),treePosition(e))) + then Code(sequenceCode(s:=makeCodeSequence(e,CommaW),combinePositionLeft(u.Operator.position,codePosition(s.(length(s)-1))))) else if u.Operator.word == SemicolonW - then Code(semiCode(makeCodeSequence(e,SemicolonW),treePosition(e))) - else Code(unaryCode(u.Operator.entry.unary,convert(u.rhs),treePosition(e)))) + then Code(semiCode(s:=makeCodeSequence(e,SemicolonW),combinePositionLeft(u.Operator.position,codePosition(s.(length(s)-1))))) + else ( + c:=convert0(u.rhs); + loc:=codePosition(c); + loc2:=u.Operator.position; + when c is + nullCode do nothing + else loc2=combinePositionLeft(loc2,loc); + Code(unaryCode(u.Operator.entry.unary,unseq(c),loc2)))) is q:Quote do ( token := q.rhs; sym := token.entry; - pos := treePosition(e); + p := combinePosition(q.Operator.position,token.position); if sym.frameID == 0 then ( if sym.thread - then Code(threadSymbolClosureCode(sym,pos)) - else Code(globalSymbolClosureCode(sym,pos)) + then Code(threadSymbolClosureCode(sym,p)) + else Code(globalSymbolClosureCode(sym,p)) ) - else Code(localSymbolClosureCode(nestingDepth(sym.frameID,token.dictionary),sym,pos))) + else Code(localSymbolClosureCode(nestingDepth(sym.frameID,token.dictionary),sym,p))) is q:GlobalQuote do ( token := q.rhs; sym := token.entry; - pos := treePosition(e); - Code(globalSymbolClosureCode(sym,pos))) + p := combinePosition(q.Operator.position,token.position); + Code(globalSymbolClosureCode(sym,p))) is q:ThreadQuote do ( token := q.rhs; sym := token.entry; - pos := treePosition(e); - Code(threadSymbolClosureCode(sym,pos))) + p := combinePosition(q.Operator.position,token.position); + Code(threadSymbolClosureCode(sym,p))) is q:LocalQuote do ( token := q.rhs; sym := token.entry; - pos := treePosition(e); + p := combinePosition(q.Operator.position,token.position); nd := nestingDepth(sym.frameID,token.dictionary); - Code(localSymbolClosureCode(nd,sym,pos))) - is i:TryThenElse do Code(tryCode(convert(i.primary),convert(i.sequel),convert(i.alternate),treePosition(e))) - is i:TryElse do Code(tryCode(convert(i.primary),NullCode,convert(i.alternate),treePosition(e))) - is i:Try do Code(tryCode(convert(i.primary),NullCode,NullCode,treePosition(e))) - is i:Catch do Code(catchCode(convert(i.primary),treePosition(e))) - is u:Postfix do Code(unaryCode(u.Operator.entry.postfix,convert(u.lhs),treePosition(e))) + Code(localSymbolClosureCode(nd,sym,p))) + is i:TryThenElse do Code(tryCode(convert(i.primary),convert(i.sequel),unseq(c:=convert0(i.alternate)),combinePosition(i.tryToken.position,codePosition(c)))) + is i:TryElse do Code(tryCode(convert(i.primary),NullCode,unseq(c:=convert0(i.alternate)),combinePosition(i.tryToken.position,codePosition(c)))) + is i:Try do Code(tryCode(unseq(c:=convert0(i.primary)),NullCode,NullCode,combinePosition(i.tryToken.position,codePosition(c)))) + is i:Catch do Code(catchCode(unseq(c:=convert0(i.primary)),combinePosition(i.catchToken.position,codePosition(c)))) + is u:Postfix do Code(unaryCode(u.Operator.entry.postfix,unseq(c:=convert0(u.lhs)),combinePosition(codePosition(c),u.Operator.position))) is d:dummy do dummyCode ); +export convert(e:ParseTree):Code := unseq(convert0(e)); + + -- Local Variables: -- compile-command: "echo \"make: Entering directory \\`$M2BUILDDIR/Macaulay2/d'\" && make -C $M2BUILDDIR/Macaulay2/d convertr.o " -- End: diff --git a/M2/Macaulay2/d/debugging.dd b/M2/Macaulay2/d/debugging.dd new file mode 100644 index 00000000000..6bed52d253a --- /dev/null +++ b/M2/Macaulay2/d/debugging.dd @@ -0,0 +1,195 @@ +use parse; +use util; +use tokens; +use common; +use hashtables; + +disassembleCode(c:Code):Expr := ( -- add locations? + when c + is x:Error do Expr(Sequence(toExpr("error"), toExpr(x.message))) + is x:sequenceCode do Expr(Sequence(toExpr("sequence"),list(new Sequence len length(x.x) do foreach s in x.x do provide toExpr(s)))) + is x:listCode do Expr(Sequence(toExpr("list"),list(new Sequence len length(x.y) do foreach s in x.y do provide toExpr(s)))) + is x:arrayCode do Expr(Sequence(toExpr("array"),list(new Sequence len length(x.z) do foreach s in x.z do provide toExpr(s)))) + is x:angleBarListCode do Expr(Sequence(toExpr("angleBarList"),list(new Sequence len length(x.t) do foreach s in x.t do provide toExpr(s)))) + is x:semiCode do Expr(Sequence(toExpr("semi"),list(new Sequence len length(x.w) do foreach s in x.w do provide toExpr(s)))) + is x:integerCode do toExpr(x.x) + is x:realCode do toExpr(x.x) + is x:unaryCode do Expr(Sequence(toExpr("1-OP"),SymbolBody(getUnopName(x.f)), + list(Sequence( + toExpr(x.rhs))) + )) + is x:binaryCode do Expr(Sequence(toExpr("2-OP"),SymbolBody(getBinopName(x.f)), + list(Sequence( + toExpr(x.lhs), + toExpr(x.rhs) + )))) + is x:ternaryCode do Expr(Sequence(toExpr("3-OP"),SymbolBody(getTernopName(x.f)), + list(Sequence( + toExpr(x.arg1), + toExpr(x.arg2), + toExpr(x.arg3) + )))) + is x:multaryCode do Expr(Sequence(toExpr("OP"),SymbolBody(getMultopName(x.f)), + list(new Sequence len length(x.args) do foreach c in x.args do provide toExpr(c)) + )) + is x:adjacentCode do Expr(Sequence(toExpr("adjacent"), + list(Sequence( + toExpr(x.lhs), + toExpr(x.rhs) + )))) + is x:functionCode do Expr(Sequence(toExpr("function"), + list(Sequence( + Sequence(toExpr("restargs"),toExpr(x.desc.restargs)), + Sequence(toExpr("numparms"),toExpr(x.desc.numparms)), + Sequence(toExpr("framesize"),toExpr(x.desc.framesize)), + Sequence(toExpr("frameID"),toExpr(x.desc.frameID)), + Sequence(toExpr("body"),toExpr(x.body)) + )))) + is x:globalAssignmentCode do Expr(Sequence( + toExpr("global-assign"), + SymbolBody(x.lhs), + toExpr(x.lhs.frameindex), + list(Sequence(toExpr(x.rhs))) + )) + is x:localAssignmentCode do Expr(Sequence( + toExpr("local-assign"),toExpr(x.frameindex),toExpr(x.nestingDepth), + list(Sequence(toExpr(x.rhs))) + )) + is x:parallelAssignmentCode do Expr(Sequence( + toExpr("parallel-assign"), + list(list(new Sequence len length(x.nestingDepth) do + for i from 0 to length(x.nestingDepth)-1 do + if x.lhs.i == dummySymbol + then provide Expr(Sequence(toExpr(x.frameindex.i),toExpr(x.nestingDepth.i))) + else provide Expr(Sequence(SymbolBody(x.lhs.i),toExpr(x.lhs.i.frameindex))) + ), + toExpr(x.rhs)) + )) + is x:augmentedAssignmentCode do Expr(Sequence( + toExpr("augmented-assign"), + SymbolBody(x.oper), + list(Sequence(toExpr(x.lhs),toExpr(x.rhs))) + )) + is x:globalMemoryReferenceCode do Expr(Sequence(toExpr("global-fetch"),toExpr((x.frameindex)))) + is x:localMemoryReferenceCode do Expr(Sequence(toExpr("fetch"),toExpr(x.frameindex),toExpr(x.nestingDepth))) + is x:threadMemoryReferenceCode do Expr(Sequence(toExpr("thread-fetch"),toExpr((x.frameindex)))) + is x:forCode do Expr(Sequence(toExpr("for"), + list(Sequence( + Sequence(toExpr("framesize"),toExpr(x.framesize)), + Sequence(toExpr("frameID"),toExpr(x.frameID)), + Sequence(toExpr("in"),toExpr(x.inClause)), + Sequence(toExpr("from"),toExpr(x.fromClause)), + Sequence(toExpr("to"),toExpr(x.toClause)), + Sequence(toExpr("when"),toExpr(x.whenClause)), + Sequence(toExpr("list"),toExpr(x.listClause)), + Sequence(toExpr("do"),toExpr(x.doClause)))) + )) + is x:whileListDoCode do Expr(Sequence(toExpr("while"), + list(Sequence( + toExpr(x.predicate), + Sequence(toExpr("list"),toExpr(x.listClause)), + Sequence(toExpr("do"),toExpr(x.doClause)))) + )) + is x:whileDoCode do Expr(Sequence(toExpr("while"), + list(Sequence( + toExpr(x.predicate), + Sequence(toExpr("do"),toExpr(x.doClause)))) + )) + is x:whileListCode do Expr(Sequence(toExpr("while"), + list(Sequence( + toExpr(x.predicate), + Sequence(toExpr("list"),toExpr(x.listClause)))) + )) + is x:newOfFromCode do Expr(Sequence(toExpr("new"), + list(Sequence( + toExpr(x.newClause), + Sequence(toExpr("of"),toExpr(x.ofClause)), + Sequence(toExpr("from"),toExpr(x.fromClause)) + )) + )) + is x:newFromCode do Expr(Sequence(toExpr("new"), + list(Sequence( + toExpr(x.newClause), + Sequence(toExpr("from"),toExpr(x.fromClause)) + )) + )) + is x:newOfCode do Expr(Sequence(toExpr("new"), + list(Sequence( + toExpr(x.newClause), + Sequence(toExpr("of"),toExpr(x.ofClause)) + )) + )) + is x:newCode do Expr(Sequence(toExpr("new"), + list(Sequence( + toExpr(x.newClause) + )) + )) + is x:ifCode do Expr(Sequence(toExpr("if"), + list(Sequence( + toExpr(x.predicate), + Sequence(toExpr("then"),toExpr(x.thenClause)), + Sequence(toExpr("else"),toExpr(x.elseClause)) + )) + )) + is x:tryCode do Expr(Sequence(toExpr("try"), + list(Sequence( + toExpr(x.code), + Sequence(toExpr("then"),toExpr(x.thenClause)), + Sequence(toExpr("else"),toExpr(x.elseClause)) + )) + )) + is x:catchCode do Expr(Sequence(toExpr("catch"),list(Sequence(toExpr(x.code))))) + is x:globalSymbolClosureCode do Expr(Sequence(toExpr("global"),SymbolBody(x.symbol),toExpr(x.symbol.frameindex))) + is x:threadSymbolClosureCode do Expr(Sequence(toExpr("thread"),SymbolBody(x.symbol),toExpr(x.symbol.frameindex))) + is x:localSymbolClosureCode do Expr(Sequence(toExpr("local"),SymbolBody(x.symbol),toExpr(x.symbol.frameindex),toExpr(x.nestingDepth))) + is x:nullCode do Expr(Sequence()) + else toExpr(tostring(c)) + ); +disassemble(e:Expr):Expr := ( + when e + is c:PseudocodeClosure do disassembleCode(c.code) + is c:Pseudocode do disassembleCode(c.code) + is s:SpecialExpr do disassemble(s.e) + else WrongArg("pseudocode") + ); +setupfun("disassemble", disassemble); + +pseudocode(e:Expr):Expr := ( + when e + is f:FunctionClosure do Expr(PseudocodeClosure(f.frame, Code(f.model))) + is f:functionCode do Expr(Pseudocode(f.body)) + is s:SpecialExpr do pseudocode(s.e) + else WrongArg("a function derived from Macaulay2 code") + ); +setupfun("pseudocode", pseudocode); + +-- locate: +export filePositionClass := newHashTableWithHash(typeClass,basicListClass); +setupconst("FilePosition",Expr(filePositionClass)); + +locate(p:Position):Expr := ( + if p == dummyPosition || p == tempPosition + then nullE + else Expr(sethash(List(filePositionClass, + Sequence( + toExpr(verifyMinimizeFilename(p.filename)), + toExpr(int(p.line1)),toExpr(int(p.column1)), + toExpr(int(p.line2)),toExpr(int(p.column2)), + toExpr(int(p.line)),toExpr(int(p.column))), + hash_t(0),false),false))); + +locate(e:Expr):Expr := ( + when e + is Nothing do nullE + is Sequence do locate(lookupfun(e)) + is CompiledFunction do nullE + is CompiledFunctionClosure do nullE + is CompiledFunctionBody do nullE + is s:SymbolClosure do locate(s.symbol.position) + is c:PseudocodeClosure do locate(codePosition(c.code)) + is c:Pseudocode do locate(codePosition(c.code)) + is s:SpecialExpr do locate(s.e) + is f:functionCode do locate(f.position) + is f:FunctionClosure do locate(f.model.position) + else WrongArg("a function, symbol, sequence, or null")); +setupfun("locate", locate).Protected = false; -- will be overloaded in m2/methods.m2 diff --git a/M2/Macaulay2/d/equality.dd b/M2/Macaulay2/d/equality.dd index d8a5af0115b..c34f82e85bf 100644 --- a/M2/Macaulay2/d/equality.dd +++ b/M2/Macaulay2/d/equality.dd @@ -121,14 +121,21 @@ export equal(lhs:Expr,rhs:Expr):Expr := ( ) -- other cases needed soon else False) - is c:CodeClosure do ( + is c:PseudocodeClosure do ( when rhs - is d:CodeClosure do ( + is d:PseudocodeClosure do ( if c.frame == d.frame && c.code == d.code then True else False) else False ) + is c:Pseudocode do ( + when rhs + is d:Pseudocode do ( + if c.code == d.code + then True else False) + else False + ) is x:RRcell do ( when rhs is y:RRcell do ( diff --git a/M2/Macaulay2/d/evaluate.d b/M2/Macaulay2/d/evaluate.d index 54b7c2b7512..bdbd4b022bc 100644 --- a/M2/Macaulay2/d/evaluate.d +++ b/M2/Macaulay2/d/evaluate.d @@ -13,7 +13,7 @@ threadLocal recycleBin := new array(Frame) len 20 do provide dummyFrame; export trace := false; threadLocal export backtrace := true; threadLocal lastCode := dummyCode; -threadLocal lastCodePosition := Position("",ushort(0),ushort(0),ushort(0)); +threadLocal lastCodePosition := Position("",ushort(0),ushort(0),ushort(0),ushort(0),ushort(0),ushort(0),ushort(0)); export chars := new array(Expr) len 256 do ( i := 0; while i<256 do ( @@ -531,7 +531,7 @@ export applyFCS(c:FunctionClosure,v:Sequence):Expr := ( ) ) else if desc.numparms != length(v) - then WrongNumArgs(model.arrow,desc.numparms,length(v)) + then WrongNumArgs(Code(model),desc.numparms,length(v)) else ( if framesize == 0 then ( saveLocalFrame := localFrame; @@ -591,7 +591,7 @@ export applyFCS(c:FunctionClosure,v:Sequence):Expr := ( ); wrongModel1(model:functionCode):Expr := printErrorMessageE( - model.arrow, + Code(model), "expected " + tostring(model.desc.numparms) + " argument" + (if model.desc.numparms == 1 then "" else "s") + " but got 1" ); @@ -828,7 +828,7 @@ export applyFCCS(c:FunctionClosure,cs:CodeSequence):Expr := ( else applyFCS(c,v) ) else if desc.numparms != length(cs) - then WrongNumArgs(model.arrow,desc.numparms,length(cs)) + then WrongNumArgs(Code(model),desc.numparms,length(cs)) else ( previousFrame := c.frame; framesize := desc.framesize; @@ -959,7 +959,7 @@ export applyEEE(g:Expr,e0:Expr,e1:Expr):Expr := ( if desc.restargs then applyFCS(c,Sequence(e0,e1)) else if desc.numparms != 2 - then WrongNumArgs(model.arrow,desc.numparms,2) + then WrongNumArgs(Code(model),desc.numparms,2) else if recursionDepth > recursionLimit then RecursionLimit() else ( previousFrame := c.frame; @@ -1028,7 +1028,7 @@ export applyEEEE(g:Expr,e0:Expr,e1:Expr,e2:Expr):Expr := ( if desc.restargs then applyFCS(c,Sequence(e0,e1,e2)) else if desc.numparms != 3 - then WrongNumArgs(model.arrow,desc.numparms,3) + then WrongNumArgs(Code(model),desc.numparms,3) else if recursionDepth > recursionLimit then RecursionLimit() else ( previousFrame := c.frame; @@ -1458,7 +1458,8 @@ export evalraw(c:Code):Expr := ( nd = nd - 3; while nd > 0 do ( nd = nd - 1; f = f.outerFrame ); ); - return f.values.(r.frameindex)) + if r.frameindex>=length(f.values) then buildErrorPacket("frame error") + else return f.values.(r.frameindex)) is r:globalMemoryReferenceCode do return globalFrame.values.(r.frameindex) is r:threadMemoryReferenceCode do return ( i := r.frameindex; @@ -2080,7 +2081,9 @@ export binarymethod(left:Expr,right:Expr,methodkey:Expr,methodkeyname:string):Ex else applyEEE(method,left,right)); AssignElemFun = assignelemfun; -AssignQuotedElemFun = assignquotedelemfun; +setup(EqualS,AssignElemFun); +AssignQuotedElemFun = assignquotedelemfun; -- what is this for? never used +setup(EqualS,AssignElemFun); export notFun(a:Expr):Expr := if a == True then False else if a == False then True else unarymethod(a,notS); diff --git a/M2/Macaulay2/d/expr.d b/M2/Macaulay2/d/expr.d index 48792789f53..a6d8b35203c 100644 --- a/M2/Macaulay2/d/expr.d +++ b/M2/Macaulay2/d/expr.d @@ -228,13 +228,10 @@ dummySymbolClosure := SymbolClosure(globalFrame,dummySymbol); globalFrame.values.dummySymbolFrameIndex = Expr(dummySymbolClosure); export dummyCode := Code(nullCode()); export NullCode := Code(nullCode()); -export dummyCodeClosure := CodeClosure(dummyFrame,dummyCode); +export dummyPseudocodeClosure := PseudocodeClosure(dummyFrame,dummyCode); export dummyToken := Token( Word("-*dummy token*-",TCnone,hash_t(0),newParseinfo()), - dummyPosition.filename, - dummyPosition.line, - dummyPosition.column, - dummyPosition.loadDepth, + dummyPosition, Macaulay2Dictionary,dummySymbol,false); export parseWORD := newParseinfo(); -- parsing functions filled in later @@ -278,12 +275,12 @@ export compiledFunctionClass := newtypeof(functionClass); export compiledFunctionClosureClass := newtypeof(functionClass); export symbolClass := newbasictype(); export keywordClass := newtypeof(symbolClass); -export codeClass := newbasictype(); +export pseudocodeClass := newbasictype(); export mysqlConnectionClass := newbasictype(); export mysqlFieldClass := newbasictype(); export mysqlResultClass := newbasictype(); export functionBodyClass := newbasictype(); -export compiledFunctionBodyClass := newbasictype(); +export compiledFunctionBodyClass := newtypeof(functionBodyClass); export errorClass := newbasictype(); export netClass := newbasictype(); export netFileClass := newbasictype(); @@ -349,6 +346,7 @@ export RRiClass := newbignumbertype(); export pointerClass := newbasictype(); export atomicIntClass := newbasictype(); -- all new types, dictionaries, and classes go just above this line, if possible, so hash codes don't change gratuitously! +export pseudocodeClosureClass := newtypeof(pseudocodeClass); --Error Handling diff --git a/M2/Macaulay2/d/interp.dd b/M2/Macaulay2/d/interp.dd index 3aabc8f672e..e53f81ae808 100644 --- a/M2/Macaulay2/d/interp.dd +++ b/M2/Macaulay2/d/interp.dd @@ -115,21 +115,21 @@ readeval4(file:TokenFile,printout:bool,dictionary:Dictionary,returnLastvalue:boo else ( t := u.word; if t == wordEOF then ( - if debugLevel == 123 then stderr << "-- EOF token, returning: " << position(u) << endl; + if debugLevel == 123 then stderr << "-- EOF token, returning: " << u.position << endl; return if returnLastvalue then lastvalue else nullE; ) else if t == NewlineW then ( - if debugLevel == 123 then stderr << "-- newline token, discarding: " << position(u) << endl; + if debugLevel == 123 then stderr << "-- newline token, discarding: " << u.position << endl; gettoken(file,true); ) else if t == wordEOC then ( - if debugLevel == 123 then stderr << "-- end-of-cell token, discarding: " << position(u) << endl; + if debugLevel == 123 then stderr << "-- end-of-cell token, discarding: " << u.position << endl; gettoken(file,true); ) else ( previousLineNumber = lineNumber; promptWanted = true; - if debugLevel == 123 then stderr << "-- ordinary token, ready to parse: " << position(u) << endl; + if debugLevel == 123 then stderr << "-- ordinary token, ready to parse: " << u.position << endl; parsed := parse(file,SemicolonW.parse.precedence,true); if parsed == errorTree then ( if test(interruptedFlag) then ( @@ -165,7 +165,7 @@ readeval4(file:TokenFile,printout:bool,dictionary:Dictionary,returnLastvalue:boo then ( msg := "syntax error: unmatched " + s.word.name; printErrorMessage(s,msg); - if stopIfError || returnIfError then return Expr(Error(position(s),msg,nullE,false,dummyFrame)); + if stopIfError || returnIfError then return Expr(Error(s.position,msg,nullE,false,dummyFrame)); ) else ( if localBind(parsed,dictionary) -- assign scopes to tokens, look up symbols; returns false iff an error occurred @@ -475,12 +475,12 @@ commandInterpreter(e:Expr):Expr := ( is Nothing do loadprint("-",newStaticLocalDictionaryClosure(),false) is x:DictionaryClosure do commandInterpreter(x) is x:SymbolClosure do commandInterpreter(x.frame) - is x:CodeClosure do commandInterpreter(x.frame) + is x:PseudocodeClosure do commandInterpreter(x.frame) is x:FunctionClosure do commandInterpreter(x.frame) is cfc:CompiledFunctionClosure do commandInterpreter(emptyFrame) -- some values are there, but no symbols is CompiledFunction do commandInterpreter(emptyFrame) -- no values or symbols are there is s:SpecialExpr do commandInterpreter(s.e) - else WrongArg("a function, symbol, dictionary, pseudocode, or ()"); + else WrongArg("a function, symbol, dictionary, pseudocode closure, or ()"); decrementInterpreterDepth(); ret); setupfun("commandInterpreter",commandInterpreter); @@ -492,7 +492,7 @@ debugger(f:Frame,c:Code):Expr := ( recursionDepth = 0; setDebuggingMode(false); oldDebuggerCode := getGlobalVariable(currentS); - setGlobalVariable(currentS,Expr(CodeClosure(f,c))); + setGlobalVariable(currentS,Expr(PseudocodeClosure(f,c))); incrementInterpreterDepth(); if debuggerHook != nullE then ( r := applyEE(debuggerHook,True); @@ -519,7 +519,8 @@ value(e:Expr):Expr := ( if i < length(vals) then vals.i else nullE -- localFrame is the only one that might be short ) - is c:CodeClosure do eval(c.frame,c.code) + is c:PseudocodeClosure do eval(c.frame,c.code) + is c:Pseudocode do eval(c.code) is s:stringCell do ( savecs := getGlobalVariable(currentString); setGlobalVariable(currentString,e); diff --git a/M2/Macaulay2/d/lex.d b/M2/Macaulay2/d/lex.d index 89f4d389e97..dcbfaa91f6e 100644 --- a/M2/Macaulay2/d/lex.d +++ b/M2/Macaulay2/d/lex.d @@ -281,10 +281,7 @@ skipwhite(file:PosFile):int := ( -- this errorToken means there was a parsing error or an error reading the file! export errorToken := Token(Word("-*error token*-",TCnone,hash_t(0),newParseinfo()), - dummyPosition.filename, - dummyPosition.line, - dummyPosition.column, - dummyPosition.loadDepth, + dummyPosition, globalDictionary, -- should replace this by dummyDictionary, I think dummySymbol,false); @@ -306,17 +303,17 @@ gettoken1(file:PosFile,sawNewline:bool):Token := ( line := file.line; column := file.column; ch := peek(file); - if iseof(ch) then return Token(wordEOF,file.filename, line, column, loadDepth,globalDictionary,dummySymbol,sawNewline) + if iseof(ch) then return Token(wordEOF,Position(file.filename, line, column, line, column, file.line, file.column, loadDepth),globalDictionary,dummySymbol,sawNewline) else if iserror(ch) then return errorToken else if ch == int('\n') then ( getc(file); return Token( if file.file.fulllines then wordEOC else NewlineW, - file.filename, line, column, loadDepth,globalDictionary,dummySymbol,sawNewline)) + Position(file.filename, line, column, line, column, file.line, file.column, loadDepth),globalDictionary,dummySymbol,sawNewline)) else if isalpha(ch) then ( -- valid symbols are an alpha (letters, any unicode except 226) followed by any number of alphanum (alpha, digit, dollar, prime) tokenbuf << char(getc(file)); while isalnum(peek(file)) do tokenbuf << char(getc(file)); - return Token(makeUniqueWord(takestring(tokenbuf),parseWORD),file.filename, line, column, loadDepth,globalDictionary,dummySymbol,sawNewline)) + return Token(makeUniqueWord(takestring(tokenbuf),parseWORD),Position(file.filename, line, column, line, column, file.line, file.column, loadDepth),globalDictionary,dummySymbol,sawNewline)) else if isdigit(ch) || ch==int('.') && isdigit(peek(file,1)) then ( typecode := TCint; decimal := true; @@ -389,33 +386,35 @@ gettoken1(file:PosFile,sawNewline:bool):Token := ( c = peek(file); if isalpha(c) then printWarningMessage(position(file),"character '"+char(c)+"' immediately following number"); s := takestring(tokenbuf); - return Token(Word(s,typecode,hash_t(0), parseWORD),file.filename, line, column, loadDepth,globalDictionary,dummySymbol,sawNewline)) + return Token(Word(s,typecode,hash_t(0), parseWORD),Position(file.filename, line, column, line, column, file.line, file.column, loadDepth),globalDictionary,dummySymbol,sawNewline)) else if ch == int('/') && peek(file,1) == int('/') && peek(file,2) == int('/') then ( when getstringslashes(file) is null do ( empty(tokenbuf); return errorToken ) - is word:Word do return Token(word,file.filename, line, column, loadDepth,globalDictionary,dummySymbol,sawNewline)) + is word:Word do return Token(word,Position(file.filename, line, column, line, column, file.line, file.column, loadDepth),globalDictionary,dummySymbol,sawNewline)) else if isquote(ch) then ( when getstring(file) is null do ( empty(tokenbuf); return errorToken ) - is word:Word do return Token(word,file.filename, line, column, loadDepth,globalDictionary,dummySymbol,sawNewline)) + is word:Word do return Token(word,Position(file.filename, line, column, line, column, file.line, file.column, loadDepth),globalDictionary,dummySymbol,sawNewline)) else if ch == 226 then ( -- unicode math symbols tokenbuf << char(getc(file)); tokenbuf << char(getc(file)); tokenbuf << char(getc(file)); - return Token(makeUniqueWord(takestring(tokenbuf),parseWORD),file.filename, line, column, loadDepth,globalDictionary,dummySymbol,sawNewline)) + return Token(makeUniqueWord(takestring(tokenbuf),parseWORD),Position(file.filename, line, column, line, column, file.line, file.column, loadDepth),globalDictionary,dummySymbol,sawNewline)) else ( when recognize(file) is null do ( empty(tokenbuf); return errorToken ) - is word:Word do return Token(word,file.filename, line, column, loadDepth,globalDictionary,dummySymbol,sawNewline)))); + is word:Word do return Token(word,Position(file.filename, line, column, line, column, file.line, file.column,loadDepth),globalDictionary,dummySymbol,sawNewline)) + ) + ); export gettoken(file:PosFile,obeylines:bool):Token := ( sawNewline := false; while true do ( diff --git a/M2/Macaulay2/d/parse.d b/M2/Macaulay2/d/parse.d index affb860699b..fe36f9edc6a 100644 --- a/M2/Macaulay2/d/parse.d +++ b/M2/Macaulay2/d/parse.d @@ -112,7 +112,7 @@ export Dictionary := { export Token := {+ -- a word, as encountered in the input word:Word, -- the word - filename:string, line:ushort, column:ushort, loadDepth:ushort, -- position:Position, -- the location where it was encountered + position:Position, -- the location where it was encountered dictionary:Dictionary, -- the dictionary active at the time it was encountered entry:Symbol, -- the symbol table entry, found in the dictionary above, or one for wider lexical scope followsNewline:bool -- whether it followed white space with a newline in it @@ -131,8 +131,8 @@ export TryElse := {+ tryToken:Token, primary:ParseTree, elseToken:Token, alterna export TryThenElse := {+ tryToken:Token, primary:ParseTree, thenToken:Token, sequel:ParseTree, elseToken:Token, alternate:ParseTree}; export Try := {+ tryToken:Token, primary:ParseTree}; export Catch := {+ catchToken:Token, primary:ParseTree}; -export IfThen := {+ ifToken:Token, predicate:ParseTree, thenclause:ParseTree }; -export IfThenElse := {+ ifToken:Token, predicate:ParseTree, thenclause:ParseTree, elseClause:ParseTree}; +export IfThen := {+ ifToken:Token, predicate:ParseTree, thenClause:ParseTree }; +export IfThenElse := {+ ifToken:Token, predicate:ParseTree, thenClause:ParseTree, elseClause:ParseTree}; export New := {+ newtoken:Token, newclass:ParseTree, newparent:ParseTree, newinitializer:ParseTree}; export Arrow := {+lhs:ParseTree, Operator:Token, rhs:ParseTree, desc:functionDescription}; export Quote := {+Operator:Token, rhs:Token}; @@ -219,7 +219,7 @@ export evaluatedCode := {+ expr:Expr, position:Position}; export nullCode := {+}; export realCode := {+x:RR,position:Position}; export integerCode := {+x:ZZ,position:Position}; -export stringCode := {+x:string}; +export stringCode := {+x:string,position:Position}; export unaryCode := {+f:unop,rhs:Code,position:Position}; export binaryCode := {+f:binop,lhs:Code,rhs:Code,position:Position}; export adjacentCode := {+lhs:Code,rhs:Code,position:Position}; @@ -256,10 +256,10 @@ export functionDescription := { }; export dummyDesc := functionDescription(-1,0,0,false); export functionCode := {+ - arrow:Token, -- just for display purposes - body:Code, + body:Code, desc:functionDescription, - hash:hash_t + hash:hash_t, + position:Position }; export Code := ( nullCode or realCode or stringCode or integerCode @@ -275,7 +275,8 @@ export Code := ( or Error -- for tail recursion or newLocalFrameCode -- soon obsolete ); -export CodeClosure := {+ frame:Frame, code:Code }; +export PseudocodeClosure := {+ frame:Frame, code:Code }; +export Pseudocode := {+ code:Code }; @@ -379,7 +380,8 @@ export Expr := ( RRcell or RRicell or Boolean or - CodeClosure or + PseudocodeClosure or + Pseudocode or CompiledFunction or CompiledFunctionBody or CompiledFunctionClosure or diff --git a/M2/Macaulay2/d/parser.d b/M2/Macaulay2/d/parser.d index 8295240bd92..50a4560ef9b 100644 --- a/M2/Macaulay2/d/parser.d +++ b/M2/Macaulay2/d/parser.d @@ -241,7 +241,7 @@ export nparse(file:TokenFile,prec:int,obeylines:bool):ParseTree := ( token = gettoken(file,obeylines); token.word.parse.funs.unary(token,file,prec,obeylines) ) - else ParseTree(dummy(position(token))) + else ParseTree(dummy(token.position)) ); if ret == errorTree then ( if isatty(file) then flushToken(file) else skip(file,prec)); @@ -518,29 +518,29 @@ export treePosition(e:ParseTree):Position := ( while true do ( when e is dummy do return dummyPosition - is token:Token do return position(token) + is token:Token do return token.position is adjacent:Adjacent do e = adjacent.lhs - is binary:Binary do return position(binary.Operator) - is a:Arrow do return position(a.Operator) - is unary:Unary do return position(unary.Operator) - is postfix:Postfix do return position(postfix.Operator) - is a:Quote do return position(a.Operator) - is a:GlobalQuote do return position(a.Operator) - is a:ThreadQuote do return position(a.Operator) - is a:LocalQuote do return position(a.Operator) - is ee:Parentheses do return position(ee.left) - is ee:EmptyParentheses do return position(ee.left) - is i:IfThen do return position(i.ifToken) - is i:TryThenElse do return position(i.tryToken) - is i:TryElse do return position(i.tryToken) - is i:Try do return position(i.tryToken) - is i:Catch do return position(i.catchToken) - is i:IfThenElse do return position(i.ifToken) - is w:For do return position(w.forToken) - is w:WhileDo do return position(w.whileToken) - is w:WhileList do return position(w.whileToken) - is w:WhileListDo do return position(w.whileToken) - is n:New do return position(n.newtoken) + is binary:Binary do return binary.Operator.position + is a:Arrow do return a.Operator.position + is unary:Unary do return unary.Operator.position + is postfix:Postfix do return postfix.Operator.position + is a:Quote do return a.Operator.position + is a:GlobalQuote do return a.Operator.position + is a:ThreadQuote do return a.Operator.position + is a:LocalQuote do return a.Operator.position + is ee:Parentheses do return ee.left.position + is ee:EmptyParentheses do return ee.left.position + is i:IfThen do return i.ifToken.position + is i:TryThenElse do return i.tryToken.position + is i:TryElse do return i.tryToken.position + is i:Try do return i.tryToken.position + is i:Catch do return i.catchToken.position + is i:IfThenElse do return i.ifToken.position + is w:For do return w.forToken.position + is w:WhileDo do return w.whileToken.position + is w:WhileList do return w.whileToken.position + is w:WhileListDo do return w.whileToken.position + is n:New do return n.newtoken.position ) ); @@ -562,8 +562,8 @@ export size(e:ParseTree):int := ( is x:LocalQuote do Ccode(int,"sizeof(*",x,")") + size(x.rhs) + size(x.Operator) is x:Parentheses do Ccode(int,"sizeof(*",x,")") + size(x.left) + size(x.right) + size(x.contents) is x:EmptyParentheses do Ccode(int,"sizeof(*",x,")") + size(x.left) + size(x.right) - is x:IfThen do Ccode(int,"sizeof(*",x,")") + size(x.ifToken) + size(x.predicate) + size(x.thenclause) - is x:IfThenElse do Ccode(int,"sizeof(*",x,")") + size(x.ifToken) + size(x.predicate) + size(x.thenclause) + size(x.elseClause) + is x:IfThen do Ccode(int,"sizeof(*",x,")") + size(x.ifToken) + size(x.predicate) + size(x.thenClause) + is x:IfThenElse do Ccode(int,"sizeof(*",x,")") + size(x.ifToken) + size(x.predicate) + size(x.thenClause) + size(x.elseClause) is x:TryThenElse do Ccode(int,"sizeof(*",x,")") + size(x.tryToken) + size(x.primary) + size(x.thenToken) + size(x.sequel) + size(x.elseToken) + size(x.alternate) is x:TryElse do Ccode(int,"sizeof(*",x,")") + size(x.tryToken) + size(x.primary) + size(x.elseToken) + size(x.alternate) is x:Try do Ccode(int,"sizeof(*",x,")") + size(x.tryToken) + size(x.primary) diff --git a/M2/Macaulay2/d/stdiop.d b/M2/Macaulay2/d/stdiop.d index 5e05fcc01db..766d706481e 100644 --- a/M2/Macaulay2/d/stdiop.d +++ b/M2/Macaulay2/d/stdiop.d @@ -118,7 +118,7 @@ export tostring(w:Position) : string := ( if c == ' ' then ( filename = "\"" + filename + "\""; break)); - errfmt(filename ,int(w.line),int(w.column + 1),int(w.loadDepth)))); + errfmt(filename ,int(w.line),int(w.column),int(w.loadDepth)))); export (o:file) << (w:Position) : file := o << tostring(w); export (o:BasicFile) << (w:Position) : BasicFile := o << tostring(w); threadLocal export SuppressErrors := false; @@ -143,12 +143,12 @@ export printErrorMessage(position:Position,message:string):void := ( ); export printWarningMessage(position:Position,message:string):void := printMessage(position,"warning: "+message); export printErrorMessage(filename:string,line:ushort,column:ushort,message:string):void := ( - printErrorMessage(Position(filename,line,column,ushort(0)), message); + printErrorMessage(Position(filename,line,column,line,column,line,column,ushort(0)), message); ); export (o:file) << (p:(null or Position)) : file := when p is null do o is w:Position do o << w; export (o:BasicFile) << (p:(null or Position)) : BasicFile := when p is null do o is w:Position do o << w; -export copy(p:Position):Position := Position(p.filename, p.line, p.column, loadDepth); -export position(file:PosFile):Position := Position(file.filename,file.line,file.column,loadDepth); +export copy(p:Position):Position := Position(p.filename, p.line, p.column, p.line1, p.column1, p.line2, p.column2, loadDepth); +export position(file:PosFile):Position := Position(file.filename,file.line,file.column,file.line,file.column,file.line,file.column,loadDepth); export dummyPosFile := PosFile(dummyfile,0,"-*dummy file name*-",ushort(0),ushort(0)); export fileError(f:PosFile):bool := fileError(f.file); export clearFileError(f:PosFile):void := clearFileError(f.file); diff --git a/M2/Macaulay2/d/stdiop0.d b/M2/Macaulay2/d/stdiop0.d index c40565400ad..0ac9357190f 100644 --- a/M2/Macaulay2/d/stdiop0.d +++ b/M2/Macaulay2/d/stdiop0.d @@ -1,7 +1,8 @@ use nets; -- from stdiop -export Position := {filename:string, line:ushort, column:ushort, loadDepth:ushort}; -export dummyPosition := Position("-*dummy file name*-",ushort(0),ushort(0),loadDepth); -export (s:Position) === (t:Position) : bool := s == t || s.filename === t.filename && s.line == t.line && s.column == t.column; +export Position := {filename:string, line:ushort, column:ushort, line1:ushort, column1:ushort, line2:ushort, column2:ushort, loadDepth:ushort}; +export dummyPosition := Position("-*dummy file name*-",ushort(0),ushort(0),ushort(0),ushort(0),ushort(0),ushort(0),loadDepth); +export tempPosition := Position("-*temp*-",ushort(0),ushort(0),ushort(0),ushort(0),ushort(0),ushort(0),loadDepth); +export (s:Position) === (t:Position) : bool := s == t || s.filename === t.filename && s.line == t.line && s.column == t.column && s.line1 == t.line1 && s.column1 == t.column1 && s.line2 == t.line2 && s.column2 == t.column2; diff --git a/M2/Macaulay2/d/tokens.d b/M2/Macaulay2/d/tokens.d index 8cf3a0f9584..59e433da4a4 100644 --- a/M2/Macaulay2/d/tokens.d +++ b/M2/Macaulay2/d/tokens.d @@ -77,9 +77,8 @@ export printError(err:Error):Error := ( then printErrorMessage(err.position, if err.printed then "--back trace--" else err.message); err.printed = true; err); -export position(t:Token):Position := Position(t.filename,t.line,t.column,t.loadDepth); -export printErrorMessage(t:Token,message:string):void := printErrorMessage(position(t),message); -export printWarningMessage(t:Token,message:string):void := printWarningMessage(position(t),message); +export printErrorMessage(t:Token,message:string):void := printErrorMessage(t.position,message); +export printWarningMessage(t:Token,message:string):void := printWarningMessage(t.position,message); export (x:SymbolClosure) === (y:SymbolClosure) : bool := ( @@ -128,40 +127,36 @@ export dummyUnop(c:Code):Expr := nullE; export dummyBinop(c:Code,d:Code):Expr := nullE; export dummyTernop(c:Code,d:Code,e:Code):Expr := nullE; export dummyMultop(s:CodeSequence):Expr := nullE; -export unopNameListCell := {f:unop,name:string,next:unopNameListCell}; -export binopNameListCell := {f:binop,name:string,next:binopNameListCell}; -export ternopNameListCell := {f:ternop,name:string,next:ternopNameListCell}; -export multopNameListCell := {f:multop,name:string,next:multopNameListCell}; -export unopNameList := unopNameListCell(dummyUnop,"-*dummy unary operator*-",self); -export binopNameList := binopNameListCell(dummyBinop,"-*dummy binary operator*-",self); -export ternopNameList := ternopNameListCell(dummyTernop,"-*dummy ternary operator*-",self); -export multopNameList := multopNameListCell(dummyMultop,"-*dummy n-ary operator*-",self); -export getUnopName(f:unop):string := ( +export unopNameListCell := {f:unop,name:Symbol,next:unopNameListCell}; +export binopNameListCell := {f:binop,name:Symbol,next:binopNameListCell}; +export ternopNameListCell := {f:ternop,name:Symbol,next:ternopNameListCell}; +export multopNameListCell := {f:multop,name:Symbol,next:multopNameListCell}; +export unopNameList := unopNameListCell(dummyUnop,dummySymbol,self); +export binopNameList := binopNameListCell(dummyBinop,dummySymbol,self); +export ternopNameList := ternopNameListCell(dummyTernop,dummySymbol,self); +export multopNameList := multopNameListCell(dummyMultop,dummySymbol,self); +export getUnopName(f:unop):Symbol := ( p := unopNameList; while true do ( - if p == p.next then return ""; - if p.f == f then return p.name; + if p == p.next || p.f == f then return p.name; p = p.next; )); -export getBinopName(f:binop):string := ( +export getBinopName(f:binop):Symbol := ( p := binopNameList; while true do ( - if p == p.next then return ""; - if p.f == f then return p.name; + if p == p.next || p.f == f then return p.name; p = p.next; )); -export getTernopName(f:ternop):string := ( +export getTernopName(f:ternop):Symbol := ( p := ternopNameList; while true do ( - if p == p.next then return ""; - if p.f == f then return p.name; + if p == p.next || p.f == f then return p.name; p = p.next; )); -export getMultopName(f:multop):string := ( +export getMultopName(f:multop):Symbol := ( p := multopNameList; while true do ( - if p == p.next then return ""; - if p.f == f then return p.name; + if p == p.next || p.f == f then return p.name; p = p.next; )); diff --git a/M2/Macaulay2/d/util.d b/M2/Macaulay2/d/util.d index c920c889679..70a318b085c 100644 --- a/M2/Macaulay2/d/util.d +++ b/M2/Macaulay2/d/util.d @@ -300,6 +300,7 @@ export toExpr(x:constucharstarOrNull) ::= toExpr(Ccode(constcharstarOrNull,"((co export toExpr(x:arrayZZ):Expr := new Sequence len length(x) do foreach i in x do provide toExpr(i); export arrayarrayZZ := array(arrayZZ); export toExpr(x:arrayarrayZZ):Expr := new Sequence len length(x) do foreach i in x do provide toExpr(i); +export toExpr(c:Code):Expr := Pseudocode(c) -- Local Variables: -- compile-command: "echo \"make: Entering directory \\`$M2BUILDDIR/Macaulay2/d'\" && make -C $M2BUILDDIR/Macaulay2/d util.o " diff --git a/M2/Macaulay2/m2/code.m2 b/M2/Macaulay2/m2/code.m2 index af6b1656aad..7579236ff43 100644 --- a/M2/Macaulay2/m2/code.m2 +++ b/M2/Macaulay2/m2/code.m2 @@ -15,12 +15,13 @@ limit := 4 -- TODO: also show _where_ a method is declared codeFunction := (key, func, level) -> if level <= limit then ( - if locate func === null then DIV{"function ", func, ": source code not available"} - else ( - dicts := localDictionaries func; - symbs := flatten apply(#dicts - 1, i -> sortByHash values dicts#i); - DIV flatten { - code locate func, + l := locate func; + c := code l; + dicts := localDictionaries func; + symbs := flatten apply(#dicts - 1, i -> sortByHash values dicts#i); + hooks := if key === null then {} else apply(listHooks(key, null), code); + DIV flatten { + if c =!= null then c else SPAN{"function ", func, ": ",if l =!= null and hasAttribute(func,ReverseDictionary) then l else ""," source code not available"}, if #symbs > 0 then INDENT listSymbols symbs, if codeHelper#?(functionBody func) then apply( codeHelper#(functionBody func) func, @@ -28,10 +29,9 @@ codeFunction := (key, func, level) -> if level <= limit then ( comment, BR{}, if instance(val, Function) then codeFunction(key, val, level+1) else hold val -- hold for OptionTable or Option }), - if key =!= null then INDENT apply(listHooks(key, null), code) + if #hooks>0 then INDENT hooks } ) - ) -- stores previously listed methods, hooks, or tests to be used by (code, ZZ) previousMethodsFound = null @@ -58,15 +58,7 @@ code FilePosition := x -> ( ) ); file = lines file; - while ( - file#?stop - and ( -- can improve this - l := set characters file#stop; - l #? ")" and isSubset(l, wp) - ) - ) do stop = stop + 1; if #file < stop then error("line number ",toString stop, " not found in file ", filename); - while stop >= start and file#(stop-1) === "" do stop = stop-1; DIV { x, ": --source code:", PRE M2CODE concatenate between_"\n" toList apply(start-1 .. stop-1, i -> file#i) @@ -251,7 +243,6 @@ debuggerUsageMessage = ///--debugger activation depth control: -- that produced an error code current -- source code of current expression value current -- execute current expression, obtain value - disassemble current -- display microcode of current expression currentString -- the string being evaluated by 'value', if -- an error occurred within it -- emacs commands in *M2* buffer: @@ -271,6 +262,28 @@ debuggerHook = entering -> ( ) ) +-- disassemble +fmtCode = method(Dispatch=>Thing) +fmtCode List := l -> new VerticalList from apply(l,fmtCode) +fmtCode Sequence := s -> RowExpression between(" ",apply(s,fmtCode)) +fmtCode Thing := identity +fmtCode Pseudocode := fmtCode @@ disassemble + +html Pseudocode := html @@ fmtCode +net Pseudocode := net @@ fmtCode +texMath Pseudocode := texMath @@ fmtCode +tex Pseudocode := tex @@ fmtCode +toString Pseudocode := toString @@ fmtCode + +Pseudocode _ ZZ := (x,i) -> ( + x=last disassemble x; + if class x =!= List then error "no such member"; + x=x#i; + if class x === Sequence then x=last x; + x + ) + + -- Local Variables: -- compile-command: "make -C $M2BUILDDIR/Macaulay2/m2 " -- End: diff --git a/M2/Macaulay2/m2/debugging.m2 b/M2/Macaulay2/m2/debugging.m2 index 6200c99691f..c1af4ecf969 100644 --- a/M2/Macaulay2/m2/debugging.m2 +++ b/M2/Macaulay2/m2/debugging.m2 @@ -233,10 +233,9 @@ generateAssertions List := y -> ( else lin )))^-1 -currentPosition = () -> new FilePosition from { currentFileName, currentRowNumber(), currentColumnNumber() } - -FilePosition = new Type of BasicList +-- FilePosition = new Type of BasicList -- defined in d FilePosition.synonym = "file position" +toExternalString FilePosition := toString FilePosition := net FilePosition := p -> concatenate( if match(" ", p#0) then format p#0 else p#0, @@ -244,6 +243,7 @@ net FilePosition := p -> concatenate( if #p>3 then ("-",toString p#3,":",toString p#4), -- if #p>5 then (" (",toString p#5,":",toString p#6,")") ) +currentPosition = () -> new FilePosition from { currentFileName, currentRowNumber(), currentColumnNumber() } locate' = locate -- defined in d/actors4.d locate = method(Dispatch => Thing, TypicalValue => FilePosition) @@ -252,7 +252,8 @@ locate FunctionBody:= locate Function := locate Pseudocode := locate Sequence := -locate Symbol := FilePosition => x -> if (x':=locate' x) =!= null then new FilePosition from x' +locate Symbol := FilePosition => locate' +locate Command := FilePosition => C -> locate'(C#0) locate List := List => x -> apply(x, locate) protect symbol locate diff --git a/M2/Macaulay2/m2/exports.m2 b/M2/Macaulay2/m2/exports.m2 index 6f87e15ebf2..b589db01199 100644 --- a/M2/Macaulay2/m2/exports.m2 +++ b/M2/Macaulay2/m2/exports.m2 @@ -338,6 +338,7 @@ export { "ProgramRun", "Prune", "Pseudocode", + "PseudocodeClosure", "QQ", "QRDecomposition", "Quotient", @@ -630,7 +631,6 @@ export { "difference", "dim", "directSum", - "disassemble", "dismiss", "divideByVariable", "do", diff --git a/M2/Macaulay2/m2/expressions.m2 b/M2/Macaulay2/m2/expressions.m2 index 126e5c77725..1ad64e8df52 100644 --- a/M2/Macaulay2/m2/expressions.m2 +++ b/M2/Macaulay2/m2/expressions.m2 @@ -587,60 +587,6 @@ toString'(Function, Table) := (fmt,m) -> concatenate( "}" ) ----------------------------------------------------------------------------- --- TODO: move this to latex.m2 -keywordTexMath = new HashTable from { -- both unary and binary keywords - symbol |- => "\\vdash ", - symbol .. => "\\,{.}{.}\\,", - symbol ..< => "\\,{.}{.}{<}\\,", - symbol <= => "\\le ", - symbol >= => "\\ge ", - symbol => => "\\Rightarrow ", - symbol ==> => "\\Longrightarrow ", - symbol <== => "\\Longleftarrow ", - symbol <==> => "\\Longleftrightarrow ", - symbol _> => "{}_>", - symbol _>= => "{}_>=", - symbol _< => "{}_<", - symbol _<= => "{}_<", - symbol ^> => "{}^>", - symbol ^>= => "{}^>=", - symbol ^< => "{}^<", - symbol ^<= => "{}^<", - symbol ** => "\\otimes ", - symbol ++ => "\\oplus ", - symbol != => "\\ne ", - symbol -> => "\\rightarrow ", - symbol <- => "\\leftarrow ", - symbol ===> => "{\\large\\Longrightarrow}", - symbol <=== => "{\\large\\Longleftarrow}", - symbol << => "\\ll ", - symbol >> => "\\gg ", - symbol ! => "!", - symbol ^! => "{}^!", - symbol _! => "{}_!", - symbol ~ => "\\sim ", - symbol ^~ => "{}^\\sim", - symbol _~ => "{}_\\sim", - --symbol ^# => "{}^\\sharp", - --symbol _# => "{}_\\sharp", - symbol ^** => "{}^{\\otimes}", -- temporary solution to KaTeX issue https://github.com/KaTeX/KaTeX/issues/3576 - symbol _ => "\\_", - symbol { => "\\{", - symbol } => "\\}", - symbol \ => "\\backslash ", - symbol \\ => "\\backslash\\backslash ", - symbol # => "\\#", - symbol #? => "\\#?", - symbol % => "\\%", - symbol & => "\\&", - symbol ^ => "\\wedge ", - symbol ^^ => "\\wedge\\wedge ", - symbol <| => "\\langle ", - symbol |> => "\\rangle ", - symbol _* => "{}_*", -- temporary solution to KaTeX issue https://github.com/KaTeX/KaTeX/issues/3576 - symbol ^* => "{}^*" -- temporary solution to KaTeX issue https://github.com/KaTeX/KaTeX/issues/3576 - } - BinaryOperation = new HeaderType of Expression -- {op,left,right} BinaryOperation.synonym = "binary operation expression" expressionValue BinaryOperation := (m) -> ( diff --git a/M2/Macaulay2/m2/hypertext.m2 b/M2/Macaulay2/m2/hypertext.m2 index f9a8e787a33..56710d8f732 100644 --- a/M2/Macaulay2/m2/hypertext.m2 +++ b/M2/Macaulay2/m2/hypertext.m2 @@ -393,8 +393,6 @@ hypertext Descent := x -> SPAN prepend( "style" => "display:inline-table;text-al , BR{}))) hypertext Time := x -> DIV { x#1, DIV ("-- ", toString x#0, " seconds", "class" => "token comment") } SAMPc = c -> x -> SAMP {toString x,"class"=>"token "|c} -hypertext Pseudocode := -hypertext CompiledFunctionBody := SAMPc "function" hypertext Command := hypertext FunctionBody := hypertext Function := f -> SAMP deepSplice { diff --git a/M2/Macaulay2/m2/startup.m2.in b/M2/Macaulay2/m2/startup.m2.in index 6c190053cad..292a26671a7 100644 --- a/M2/Macaulay2/m2/startup.m2.in +++ b/M2/Macaulay2/m2/startup.m2.in @@ -34,7 +34,7 @@ if firstTime then ( PackageDictionary#("Package$Core") = getGlobalSymbol(PackageDictionary, "Core"); ) -- we can't make this an else-clause, because then "Core" will be in the wrong dictionary -disassemble ( () -> debug Core ) +pseudocode ( () -> debug Core ) -- what is this for? if not firstTime then debug Core -- we need access to the private symbols (we remove the Core private dictionary later.) toString := value' getGlobalSymbol if firstTime then "simpleToString" else "toString" diff --git a/M2/Macaulay2/m2/typicalvalues.m2 b/M2/Macaulay2/m2/typicalvalues.m2 index c3df17f6b8b..5972c6c43a9 100644 --- a/M2/Macaulay2/m2/typicalvalues.m2 +++ b/M2/Macaulay2/m2/typicalvalues.m2 @@ -80,7 +80,7 @@ horizontalJoin BasicList := Net => horizontalJoin unstack Net := List => unstack localDictionaries Function := List => localDictionaries localDictionaries Symbol := List => localDictionaries -localDictionaries Pseudocode := List => localDictionaries +localDictionaries PseudocodeClosure := List => localDictionaries localDictionaries Dictionary := List => localDictionaries values HashTable := List => values merge(HashTable,HashTable,Function) := HashTable => merge @@ -151,7 +151,7 @@ fileMode(ZZ,String) := fileMode frames(Sequence) := frames frames(Symbol) := frames frames(Function) := frames -frames(Pseudocode) := frames +frames(PseudocodeClosure) := frames powermod(ZZ,ZZ,ZZ) := ZZ => powermod chk := (type,key) -> if type#?key then ( diff --git a/M2/Macaulay2/packages/Macaulay2Doc/debugging.m2 b/M2/Macaulay2/packages/Macaulay2Doc/debugging.m2 index 6e4180a8b7c..9ceaeda85b6 100644 --- a/M2/Macaulay2/packages/Macaulay2Doc/debugging.m2 +++ b/M2/Macaulay2/packages/Macaulay2Doc/debugging.m2 @@ -50,7 +50,7 @@ document { code f f 0 return - disassemble current + current step(-3) step step @@ -156,7 +156,7 @@ document { things that can be converted to strings and concatenated) is printed. Execution of the code is interrupted, and control is returned to top level. Here is an explicit example showing how this command is used:", - PRE///exampleCode = p -> ( + PRE M2CODE///exampleCode = p -> ( if not isPrime p then error "expected a prime integer"; if p == 2 diff --git a/M2/Macaulay2/packages/Macaulay2Doc/overview3.m2 b/M2/Macaulay2/packages/Macaulay2Doc/overview3.m2 index 1ffc15f080e..dfd6b66cc12 100644 --- a/M2/Macaulay2/packages/Macaulay2Doc/overview3.m2 +++ b/M2/Macaulay2/packages/Macaulay2Doc/overview3.m2 @@ -696,7 +696,7 @@ document { TO "code", TO "current", TO "currentFileName", - TO "disassemble", + TO "pseudocode", TO "edit", TO "error", TO "errorDepth", diff --git a/M2/Macaulay2/packages/Macaulay2Doc/overview4.m2 b/M2/Macaulay2/packages/Macaulay2Doc/overview4.m2 index ce88b8e704b..3b0afadb787 100644 --- a/M2/Macaulay2/packages/Macaulay2Doc/overview4.m2 +++ b/M2/Macaulay2/packages/Macaulay2Doc/overview4.m2 @@ -306,7 +306,7 @@ document { Key => "the debugger", with ", TO "break", ".", EXAMPLE "break", "The variable ", TO "errorDepth", " can be used to control how deep inside the code the debugger should be activated.", - SeeAlso => { "break", "end", "step", "continue", "return", "listLocalSymbols", "listUserSymbols", "code", "value", "disassemble", "errorDepth" } + SeeAlso => { "break", "end", "step", "continue", "return", "listLocalSymbols", "listUserSymbols", "code", "value", "pseudocode", "errorDepth" } } -- Local Variables: diff --git a/M2/Macaulay2/packages/Macaulay2Doc/repl.m2 b/M2/Macaulay2/packages/Macaulay2Doc/repl.m2 index 793922d6917..66188ab2b61 100644 --- a/M2/Macaulay2/packages/Macaulay2Doc/repl.m2 +++ b/M2/Macaulay2/packages/Macaulay2Doc/repl.m2 @@ -215,10 +215,10 @@ document { ///, SeeAlso => {mutable, "try"} } -document { Key => {frames,(frames, Symbol), (frames, Sequence), (frames, Pseudocode), (frames, Function)}, +document { Key => {frames,(frames, Symbol), (frames, Sequence), (frames, PseudocodeClosure), (frames, Function)}, Headline => "get the frames associated to a closure", Usage => "frames f", - Inputs => { "f" => {"() or ", ofClass{Symbol,Function,Pseudocode}}}, + Inputs => { "f" => {"() or ", ofClass{Symbol,Function,PseudocodeClosure}}}, Outputs => {{"a list of mutable lists, the frames attached to the closure ", TT "f", " or, if ", TT "f", " is ", TT "()", ", then the frames attached to the current lexical scope" }}, @@ -502,11 +502,11 @@ document { Key => LocalDictionary, have values; thus they may be referred to as dictionary closures.", SeeAlso => { localDictionaries, GlobalDictionary } } -document { Key => {localDictionaries,(localDictionaries, Symbol), (localDictionaries, Pseudocode), (localDictionaries, Dictionary), (localDictionaries, Function)}, +document { Key => {localDictionaries,(localDictionaries, Symbol), (localDictionaries, PseudocodeClosure), (localDictionaries, Dictionary), (localDictionaries, Function)}, Headline => "get local dictionaries", Usage => "localDictionaries f", Inputs => { - "f" => {"() or ", ofClass{Function,Symbol,Pseudocode,Dictionary}} + "f" => {"() or ", ofClass{Function,Symbol,PseudocodeClosure,Dictionary}} }, Outputs => { List => {"a list of the local dictionaries associated with the lexical scopes containing ", TT "f"} @@ -536,7 +536,7 @@ document { Key => listLocalSymbols, Headline => "display of local symbols and their values", SYNOPSIS ( Usage => "listLocalSymbols f", - Inputs => { "f" => {ofClass{Pseudocode,Symbol,Dictionary,Function}}}, + Inputs => { "f" => {ofClass{PseudocodeClosure,Symbol,Dictionary,Function}}}, Outputs => { Net => {"a compact display of the symbols in the local dictionaries attached to the closure ", TT "f", ", and their values"}}, EXAMPLE lines /// x:=3; y:="hi there"; z:=2^30; f = x->x; @@ -558,7 +558,7 @@ document { Key => listLocalSymbols, ), SYNOPSIS ( Usage => "listLocalSymbols(X,f)", - Inputs => { "X" => Type, "f" => {ofClass{Pseudocode,Symbol,Dictionary,Function}}}, + Inputs => { "X" => Type, "f" => {ofClass{PseudocodeClosure,Symbol,Dictionary,Function}}}, Outputs => { Net => {"a compact display of the symbols in the local dictionaries attached to the closure ", TT "f", ", and their values, provided their values are instances of the type ", TT "X"}}, EXAMPLE lines /// @@ -969,12 +969,12 @@ document { Key => symbol OutputDictionary, ///, SeeAlso => { "dictionaryPath" } } -document { Key => Pseudocode, +document { Key => {Pseudocode, PseudocodeClosure}, Headline => "the class of pseudocodes", "The Macaulay2 interpreter compiles its language into pseudocode, which is evaluated later, step by step. At each step, the evaluator is considering a pseudocode item. These pseudocode items are normally not available to the user, but - the internal function ", TO "disassemble", " can display their contents, the function ", TO "pseudocode", " can convert - a function closure to pseudocode, the function ", TO "value", " can evaluate it (bindings of values to local symbols + the internal function ", TO "pseudocode", " can convert + a function closure to pseudocode and display their contents, the function ", TO "value", " can evaluate it (bindings of values to local symbols are enclosed with the pseudocode), the operator ", TO "===", " can be used for equality testing, and when the debugger is activated after an error, the variable ", TO "current", " contains the pseudocode step whose execution produced the error.", } @@ -982,44 +982,38 @@ document { Key => pseudocode, Headline => "produce the pseudocode for a function", Usage => "pseudocode f", Inputs => { "f" => FunctionClosure }, - Outputs => { Pseudocode => { "the pseudocode of the function ", TT "f"} }, - SeeAlso => { disassemble }, + Outputs => { PseudocodeClosure => { "the pseudocode of the function ", TT "f"} }, EXAMPLE lines /// pseudocode resolution - disassemble oo - /// - } -document { Key => disassemble, - Headline => "disassemble pseudocode or a function", - Usage => "disassemble c", - Inputs => { "c" => Pseudocode }, - Outputs => { String => {"the disassembled form of ", TT "c"} }, - SeeAlso => { pseudocode }, + ///, + PARA { + "One can look at specific part of the code by using ", TT "_",":" + }, EXAMPLE lines /// - disassemble res + oo_4_1_1_0 + value oo ///, PARA { - "It may be useful to disassemble code during debugging, as in the following demonstration." + "It may be useful to look at code during debugging, as in the following demonstration." }, EXAMPLE lines /// load "Macaulay2Doc/demo1.m2" code g g 2 code current - disassemble current + current /// } document { Key => "current", Headline => "the pseudocode that produced an error", Usage => "current", - Outputs => { Pseudocode => { "the pseudocode that produced an error, or ", TO "null", ", if none" } }, + Outputs => { PseudocodeClosure => { "the pseudocode that produced an error, or ", TO "null", ", if none" } }, "Use ", TO "value", " to evaluate the code again, for debugging purposes.", EXAMPLE lines /// load "Macaulay2Doc/demo1.m2" code g g 2 code current - disassemble current value current x = 11 value current diff --git a/M2/Macaulay2/tests/ComputationsBook/monomialIdeals/test.out.expected b/M2/Macaulay2/tests/ComputationsBook/monomialIdeals/test.out.expected index ff130ba7667..4c6015d898f 100644 --- a/M2/Macaulay2/tests/ComputationsBook/monomialIdeals/test.out.expected +++ b/M2/Macaulay2/tests/ComputationsBook/monomialIdeals/test.out.expected @@ -165,7 +165,6 @@ o27 = -- code for method: dual(MonomialIdeal,List) -- Common code for functions created with >> to process options and arguments. uncurry(f, override (opts,args)) ) - ) | symbol class value location of symbol | ------ ----- ----- ------------------ | opts : OptionTable -- OptionTable{Strategy => 0} /Users/dan/src/M2/Macaulay2/m2/option.m2:6:4-6:7 diff --git a/M2/Macaulay2/tests/normal/capture.m2 b/M2/Macaulay2/tests/normal/capture.m2 index 0d8e9c94884..ef6977c2de2 100644 --- a/M2/Macaulay2/tests/normal/capture.m2 +++ b/M2/Macaulay2/tests/normal/capture.m2 @@ -21,7 +21,7 @@ o2 : Matrix K <-- K\n" | ".*", out)) -- printing errors (err, out) = capture "1/0" -assert(err and match("\\A\ni1 : 1/0\ncurrentString:1:2:\\(3\\):\\[.\\]: error: division by zero\n\\Z", out)) +assert(err and match("\\A\ni1 : 1/0\ncurrentString:1:1:\\(3\\):\\[.\\]: error: division by zero\n\\Z", out)) -- make sure runaway existing private symbols are not changed -- TODO: how can we prevent new methods or hooks from escaping capture?