diff --git a/newrpl/compiler.c b/newrpl/compiler.c index 22afa4a..4e5d553 100644 --- a/newrpl/compiler.c +++ b/newrpl/compiler.c @@ -602,11 +602,14 @@ WORDPTR rplCompile(BYTEPTR string,BINT length, BINT addwrapper) while(InfixOpTop>(WORDPTR)ValidateTop){ if((TI_TYPE(*(InfixOpTop-1))==TITYPE_OPENBRACKET)) { // CHECK IF THE BRACKET IS THE RIGHT TYPE OF BRACKET - if((TI_TYPE(probe_tokeninfo)==TITYPE_CLOSEBRACKET) &&(*(InfixOpTop-2)!=Opcode)) { + if((TI_TYPE(probe_tokeninfo)==TITYPE_CLOSEBRACKET) &&(*(InfixOpTop-2)!=(Opcode-1))) { // MISMATCHED BRACKET TYPE + // SPECIAL CASE: ALLOW LISTBRACKET TO CLOSE CLISTBRACKETS + if(!((Opcode==CMD_LISTCLOSEBRACKET)&&(*(InfixOpTop-2)==CMD_CLISTOPENBRACKET))) { rplError(ERR_MISSINGBRACKET); LAMTop=LAMTopSaved; return 0; + } } break; } @@ -1272,6 +1275,7 @@ end_of_expression: case INFIX_STARTSYMBOLIC: rplDecompAppendChar('\''); if(Exceptions) break; + // DELIBERATE FALL THROUGH case INFIX_STARTEXPRESSION: { diff --git a/newrpl/lib-104-solvers.c b/newrpl/lib-104-solvers.c index 59f0a5c..c254a47 100644 --- a/newrpl/lib-104-solvers.c +++ b/newrpl/lib-104-solvers.c @@ -341,7 +341,7 @@ case NUMINT: // HERE THERE'S 8 VALUES ON THE STACK OVER THE RIGHT PART: D F(D) E F(E) AREA_L AREA_R NEWERR FALSE rplOverwriteData(1,L_ERR); - //*** TESTING: DO NOT HALVE THE ERROR EACH TIME + // *** TESTING: DO NOT HALVE THE ERROR EACH TIME //plPushData((WORDPTR)one_half_real); //rplCallOvrOperator(CMD_OVR_MUL); // L_ERR/2 //if(Exceptions) { DSTop=dstkptr; return; } @@ -802,7 +802,7 @@ case NUMINT: - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** /* char Buffer0[1000],Buffer1[1000],Buffer2[1000]; rplReadNumberAsReal(rplPeekData(3),&x1); @@ -814,7 +814,7 @@ case NUMINT: printf("INI: X=%s , Y=%s , F(P)=%s\n",Buffer0,Buffer1,Buffer2); fflush(stdout); */ - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** @@ -947,7 +947,7 @@ case NUMINT: if(gteReal(&fx,&x1) && ltReal(&fx,&x2)) { // REPLACE POINT AND CONTINUE /* - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** char Buffer0[1000],Buffer1[1000],Buffer2[1000]; rplReadNumberAsReal(rplPeekData(3),&x1); rplReadNumberAsReal(rplPeekData(2),&x2); @@ -957,7 +957,7 @@ case NUMINT: *formatReal(&fx,Buffer2,FMT_CODE,MAKELOCALE('.',' ',' ',','))=0; printf("REF: X=%s , Y=%s , F(P)=%s\n",Buffer0,Buffer1,Buffer2); fflush(stdout); - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** */ WORDPTR newpt=rplCreateListN(nvars+1,1,1); @@ -1008,7 +1008,7 @@ case NUMINT: // NOW REPLACE WORST POINT WITH P /* - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** char Buffer0[1000],Buffer1[1000],Buffer2[1000]; rplReadNumberAsReal(rplPeekData(3),&x1); rplReadNumberAsReal(rplPeekData(2),&x2); @@ -1018,7 +1018,7 @@ case NUMINT: *formatReal(&fx,Buffer2,FMT_CODE,MAKELOCALE('.',' ',' ',','))=0; printf("EXP: X=%s , Y=%s , F(P)=%s\n",Buffer0,Buffer1,Buffer2); fflush(stdout); - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** */ // REPLACE POINT AND CONTINUE WORDPTR newpt=rplCreateListN(nvars+1,1,1); @@ -1071,7 +1071,7 @@ case NUMINT: rplRemoveAtData(nvars+2,nvars+1); // KEEP P'' /* - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** char Buffer0[1000],Buffer1[1000],Buffer2[1000]; rplReadNumberAsReal(rplPeekData(3),&x1); rplReadNumberAsReal(rplPeekData(2),&x2); @@ -1081,7 +1081,7 @@ case NUMINT: *formatReal(&fx,Buffer2,FMT_CODE,MAKELOCALE('.',' ',' ',','))=0; printf("CON: X=%s , Y=%s , F(P)=%s\n",Buffer0,Buffer1,Buffer2); fflush(stdout); - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** */ @@ -1128,7 +1128,7 @@ case NUMINT: if(Exceptions) { DSTop=stksave; return; } /* - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** char Buffer0[1000],Buffer1[1000],Buffer2[1000]; rplReadNumberAsReal(rplPeekData(3),&x1); rplReadNumberAsReal(rplPeekData(2),&x2); @@ -1138,7 +1138,7 @@ case NUMINT: *formatReal(&fx,Buffer2,FMT_CODE,MAKELOCALE('.',' ',' ',','))=0; printf("SHR: X=%s , Y=%s , F(P)=%s\n",Buffer0,Buffer1,Buffer2); fflush(stdout); - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** */ // REPLACE POINT WORDPTR newpt=rplCreateListN(nvars+1,1,1); @@ -1301,7 +1301,7 @@ case NUMINT: // NOW REPLACE WORST POINT WITH P - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** /* { char Buffer0[1000],Buffer1[1000],Buffer2[1000]; @@ -1315,7 +1315,7 @@ case NUMINT: printf("EXP: X=%s , Y=%s , F(P)=%s\n",Buffer0,Buffer1,Buffer2); fflush(stdout); } */ - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** // REPLACE POINT AND CONTINUE WORDPTR newpt=rplCreateListN(nvars+1,1,1); @@ -1339,7 +1339,7 @@ case NUMINT: - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** /* char Buffer0[1000],Buffer1[1000],Buffer2[1000]; rplReadNumberAsReal(rplPeekData(3),&x1); @@ -1351,7 +1351,7 @@ case NUMINT: printf("P??: X=%s , Y=%s , F(P)=%s\n",Buffer0,Buffer1,Buffer2); fflush(stdout); */ - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** // REFLECTION DIDN'T IMPROVE ON OUR BEST POINT, FIND A POINT THROUGH GRADIENTS TO SEE IF WE CAN DO BETTER @@ -1446,7 +1446,7 @@ case NUMINT: if(Exceptions) { DSTop=stksave; return; } - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** /* { char Buffer0[1000],Buffer1[1000],Buffer2[1000]; @@ -1460,7 +1460,7 @@ case NUMINT: printf("GR?: X=%s , Y=%s , F(P)=%s\n",Buffer0,Buffer1,Buffer2); fflush(stdout); } */ - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** rplReadNumberAsReal(rplPeekData(1),&x1); // F(G') rplReadNumberAsReal(rplPeekData(nvars+2),&fx); // F(P) @@ -1480,7 +1480,7 @@ case NUMINT: if(ltReal(&fx,&x2)) { // REPLACE POINT AND CONTINUE - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** /* char Buffer0[1000],Buffer1[1000],Buffer2[1000]; rplReadNumberAsReal(rplPeekData(3),&x1); @@ -1492,7 +1492,7 @@ case NUMINT: printf("REF: X=%s , Y=%s , F(P)=%s\n",Buffer0,Buffer1,Buffer2); fflush(stdout); */ - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** WORDPTR newpt=rplCreateListN(nvars+1,1,1); @@ -1546,7 +1546,7 @@ case NUMINT: rplRemoveAtData(nvars+2,nvars+1); // KEEP P'' - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** /* char Buffer0[1000],Buffer1[1000],Buffer2[1000]; rplReadNumberAsReal(rplPeekData(3),&x1); @@ -1558,7 +1558,7 @@ case NUMINT: printf("CON: X=%s , Y=%s , F(P)=%s\n",Buffer0,Buffer1,Buffer2); fflush(stdout); */ - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** @@ -1605,7 +1605,7 @@ case NUMINT: if(Exceptions) { DSTop=stksave; return; } - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** /* char Buffer0[1000],Buffer1[1000],Buffer2[1000]; rplReadNumberAsReal(rplPeekData(3),&x1); @@ -1617,7 +1617,7 @@ case NUMINT: printf("SHR: X=%s , Y=%s , F(P)=%s\n",Buffer0,Buffer1,Buffer2); fflush(stdout); */ - //************************* DEBUG ONLY *************************** + // ************************* DEBUG ONLY *************************** // REPLACE POINT WORDPTR newpt=rplCreateListN(nvars+1,1,1); diff --git a/newrpl/lib-55-constants.c b/newrpl/lib-55-constants.c index 0ff2616..2af5a8e 100644 --- a/newrpl/lib-55-constants.c +++ b/newrpl/lib-55-constants.c @@ -65,6 +65,12 @@ INCLUDE_ROMOBJECT(LIB_MSGTABLE); INCLUDE_ROMOBJECT(LIB_HELPTABLE); INCLUDE_ROMOBJECT(lib55_menu); +INCLUDE_ROMOBJECT(lib55_pi); +INCLUDE_ROMOBJECT(lib55_i); +INCLUDE_ROMOBJECT(lib55_e); +INCLUDE_ROMOBJECT(lib55_j); + + // EXTERNAL EXPORTED OBJECT TABLE // UP TO 64 OBJECTS ALLOWED, NO MORE @@ -72,37 +78,25 @@ const WORDPTR const ROMPTR_TABLE[]={ (WORDPTR)LIB_HELPTABLE, (WORDPTR)LIB_MSGTABLE, (WORDPTR)lib55_menu, + // HERE ADD THE VALUES OF THE CONSTANTS AS RPL OBJECTS. ALL CONSTANTS NEED TO HAVE THEIR NUMERIC OBJECTS IN ROM + (WORDPTR)lib55_pi, + (WORDPTR)lib55_i, + (WORDPTR)lib55_e, + (WORDPTR)lib55_j, + 0 }; // CONVERT A CONSTANT TO A NUMBER // RETURNS EITHER A NEW OBJECT WITH THE NUMERIC REPRESENTATION OF THE CONSTANT -// OR THE SAME OBJECT AS BEFORE. MAY TRIGGER A GC BUT RETURNED POINTER IS SAFE FROM GC. - +// OR THE SAME OBJECT AS BEFORE. +// RETURNS OBJECTS IN ROM, VERY FAST, NEVER TRIGGERS GC OR ALLOCATES ANY MEMORY +// DRAWBACK: IT'S ALWAYS AT MAXIMUM PRECISION (2000 DIGITS) WORDPTR rplConstant2Number(WORDPTR object) { if(!ISCONSTANT(*object)) return object; - WORD saveopcode=CurOpcode; - rplPushDataNoGrow(object); - CurOpcode=object[1]; // GET THE OPCODE FOR THE SYMBOL - LIB_HANDLER(); - CurOpcode=saveopcode; - return rplPopData(); -} - -// PUT THE GIVEN CONSTANT INTO RReg[0] OR RReg[0] AND RReg[1] IF COMPLEX -// RETURNS 1 IF REAL, 1000+ANGLE_MODE IF COMPLEX - - -BINT rplConstant2NumberDirect(WORDPTR object) -{ - if(!ISCONSTANT(*object)) return 0; - WORD saveopcode=CurOpcode; - CurOpcode=object[1]|CONSTANT_DIRECT2NUMBER; // GET THE OPCODE FOR THE SYMBOL - LIB_HANDLER(); - CurOpcode=saveopcode; - return (BINT)RetNum; + return ROMPTR_TABLE[OPCODE(object[1])+3]; // GET THE OPCODE FOR THE SYMBOL } void LIB_HANDLER() @@ -138,9 +132,8 @@ void LIB_HANDLER() return; case OVR_NUM: { - WORDPTR obj=rplPeekData(1); - CurOpcode=obj[1]; // GET THE OPCODE FOR THE SYMBOL - break; // AND CONTINUE TO THE EXECUTION PART + rplOverwriteData(1,rplConstant2Number(rplPeekData(1))); + return; } case OVR_ISTRUE: @@ -194,88 +187,6 @@ void LIB_HANDLER() switch(OPCODE(CurOpcode)) { - case PICONST: - { - //@SHORT_DESC=Numeric constant π with twice the current system precision - //@NEW - - if(rplDepthData()<1) { rplError(ERR_BADARGCOUNT); return; } - REAL pi; - - decconst_PI(&pi); - - WORDPTR result=rplNewReal(&pi); - if(result) rplOverwriteData(1,result); - return; - - } - case PICONST | CONSTANT_DIRECT2NUMBER: - { - // PUT THE CONSTANT DIRECTLY INTO RReg[0] (REAL) OR RReg[0] AND [1] FOR COMPLEX - // RETURNS RetNum=1 IF REAL, 1000+ANGLE_MODE IF COMPLEX - REAL pi; - - decconst_PI(&pi); - copyReal(&RReg[0],&pi); - normalize(&RReg[0]); - return; - } - case ECONST: - { - //@SHORT_DESC=Numeric constant e at current system precision - //@NEW - - if(rplDepthData()<1) { rplError(ERR_BADARGCOUNT); return; } - - rplOneToRReg(0); - - hyp_exp(&RReg[0]); - - normalize(&RReg[0]); - - WORDPTR result=rplNewReal(&RReg[0]); - if(result) rplOverwriteData(1,result); - return; - - } - case ECONST | CONSTANT_DIRECT2NUMBER: - { - // PUT THE CONSTANT DIRECTLY INTO RReg[0] (REAL) OR RReg[0] AND [1] FOR COMPLEX - // RETURNS RetNum=1 IF REAL, 1000+ANGLE_MODE IF COMPLEX - rplOneToRReg(0); - - hyp_exp(&RReg[0]); - - normalize(&RReg[0]); - return; - } - - case ICONST: - case JCONST: - { - //@SHORT_DESC=Imaginary constant i = j = (0,1) - //@NEW - - if(rplDepthData()<1) { rplError(ERR_BADARGCOUNT); return; } - - rplOneToRReg(0); - rplZeroToRReg(1); - - WORDPTR result=rplNewComplex(&RReg[1],&RReg[0],ANGLENONE); - if(result) rplOverwriteData(1,result); - return; - - } - - case ICONST | CONSTANT_DIRECT2NUMBER: - case JCONST | CONSTANT_DIRECT2NUMBER: - { - // PUT THE CONSTANT DIRECTLY INTO RReg[0] (REAL) OR RReg[0] AND [1] FOR COMPLEX - // RETURNS RetNum=1 IF REAL, 1000+ANGLE_MODE IF COMPLEX - rplOneToRReg(0); - rplZeroToRReg(1); - return; - } // STANDARIZED OPCODES: diff --git a/newrpl/lib-56-symbolic.c b/newrpl/lib-56-symbolic.c index 5c0a3a1..66fbbbd 100644 --- a/newrpl/lib-56-symbolic.c +++ b/newrpl/lib-56-symbolic.c @@ -53,7 +53,10 @@ CMD(RULEAPPLY1,MKTOKENINFO(10,TITYPE_NOTALLOWED,2,2)), \ ECMD(GIVENTHAT,"|",MKTOKENINFO(1,TITYPE_BINARYOP_LEFT,2,15)), \ CMD(TRIGSIN,MKTOKENINFO(7,TITYPE_CASFUNCTION,1,2)), \ - CMD(ALLROOTS,MKTOKENINFO(8,TITYPE_CASFUNCTION,1,2)) + CMD(ALLROOTS,MKTOKENINFO(8,TITYPE_CASFUNCTION,1,2)), \ + ECMD(CLISTOPENBRACKET,"c{",MKTOKENINFO(2,TITYPE_OPENBRACKET,0,31)), \ + ECMD(CLISTCLOSEBRACKET,"}",MKTOKENINFO(1,TITYPE_CLOSEBRACKET,0,31)), \ + CMD(RANGE,MKTOKENINFO(5,TITYPE_FUNCTION,3,2)) // CMD(TEST,MKTOKENINFO(4,TITYPE_NOTALLOWED,1,2)) @@ -1172,7 +1175,7 @@ void LIB_HANDLER() rplSetExceptionHandler(IPtr+5); // SET THE EXCEPTION HANDLER TO THE SYMBEVAL1ERR WORD - if((Opcode==CMD_OPENBRACKET) || (Opcode==CMD_LISTOPENBRACKET)) { + if((Opcode==CMD_OPENBRACKET) || (Opcode==CMD_LISTOPENBRACKET) || (Opcode==CMD_CLISTOPENBRACKET)) { // SPECIAL CASE, THESE COMMANDS NEED THE NUMBER OF ARGUMENTS PUSHED ON THE STACK rplNewBINTPush(newdepth,DECBINT); @@ -1514,7 +1517,7 @@ void LIB_HANDLER() rplSetExceptionHandler(IPtr+3); // SET THE EXCEPTION HANDLER TO THE SYMBEVAL1ERR WORD - if((Opcode==CMD_OPENBRACKET) || (Opcode==CMD_LISTOPENBRACKET)) { + if((Opcode==CMD_OPENBRACKET) || (Opcode==CMD_LISTOPENBRACKET) || (Opcode==CMD_CLISTOPENBRACKET)) { // SPECIAL CASE, THESE COMMANDS NEED THE NUMBER OF ARGUMENTS PUSHED ON THE STACK rplNewBINTPush(newdepth,DECBINT); } @@ -1662,7 +1665,7 @@ void LIB_HANDLER() rplSetExceptionHandler(IPtr+3); // SET THE EXCEPTION HANDLER TO THE SYMBEVAL1ERR WORD - if((Opcode==CMD_OPENBRACKET) || (Opcode==CMD_LISTOPENBRACKET)) { + if((Opcode==CMD_OPENBRACKET) || (Opcode==CMD_LISTOPENBRACKET) || (Opcode==CMD_CLISTOPENBRACKET)) { // SPECIAL CASE, THESE COMMANDS NEED THE NUMBER OF ARGUMENTS PUSHED ON THE STACK rplNewBINTPush(newdepth,DECBINT); } @@ -1963,8 +1966,22 @@ void LIB_HANDLER() } rplCreateList(); - if(!Exceptions) rplListAutoExpand(rplPeekData(1)); + //if(!Exceptions) rplListAutoExpand(rplPeekData(1)); return; + + case CLISTOPENBRACKET: + //@SHORT_DESC=@HIDE + if(rplDepthData()<1) { + rplError(ERR_BADARGCOUNT); + return; + } + + rplCreateList(); + if(!Exceptions) rplListAutoExpand(rplPeekData(1)); + + return; + + case LISTCLOSEBRACKET: //@SHORT_DESC=@HIDE @@ -2029,7 +2046,130 @@ void LIB_HANDLER() return; } + case RANGE: + //@SHORT_DESC=Create a case-list of integers in the given range. + //@NEW + { + if(rplDepthData()<3) { + rplError(ERR_BADARGCOUNT); + return; + } + + WORDPTR argstart,argend,argstep; + + argstart=rplPeekData(3); + argend=rplPeekData(2); + argstep=rplPeekData(1); + + if( ISSYMBOLIC(*argstart)||ISIDENT(*argstart)||ISCONSTANT(*argstart) || + ISSYMBOLIC(*argend)||ISIDENT(*argend)||ISCONSTANT(*argend) || + ISSYMBOLIC(*argstep)||ISIDENT(*argstep)||ISCONSTANT(*argstep) + ) { + rplSymbApplyOperator(CurOpcode,3); + return; + } + + + if(ISBINT(*argstart)&&ISBINT(*argend)&&(ISBINT(*argstep))) + { + // ALL INTEGERS!, DO THIS FASTER + BINT64 start,end,step,k; + BINT size=1; + start=rplReadBINT(argstart); + end=rplReadBINT(argend); + step=rplReadBINT(argstep); + if(end=0) step=(end-start)*2; + } + else if(step<=0) step=(end-start)*2; + + if(step>0) { + for(k=start;k<=end;k+=step) { + if( (k<=MAX_SINT)&&(k>=MIN_SINT)) size+=1; + else size+=3; + } + } else { + for(k=start;k>=end;k+=step) { + if( (k<=MAX_SINT)&&(k>=MIN_SINT)) size+=1; + else size+=3; + } + + } + // HERE WE HAVE THE SIZE OF THE LIST + WORDPTR newlist=rplAllocTempOb(size),ptr; + if(!newlist) return; + newlist[0]=MKPROLOG(DOCASELIST,size); + newlist[size]=CMD_ENDLIST; + ptr=newlist+1; + if(step>0) { + for(k=start;k<=end;k+=step) { + ptr=rplWriteBINT(k,DECBINT,ptr); + } + } else { + for(k=start;k>=end;k+=step) { + ptr=rplWriteBINT(k,DECBINT,ptr); + } + } + + rplOverwriteData(3,newlist); + rplDropData(2); + return; + } + + // USE REAL NUMBERS, WE ARE DEALING WITH LARGE INTEGERS + REAL start,end,step; + BINT direction; + WORDPTR newlist=rplAllocTempOb(2),ptr; + if(!newlist) return; + ptr=newlist+1; + + rplReadNumberAsReal(argstart,&start); + if(Exceptions) return; + rplReadNumberAsReal(argend,&end); + if(Exceptions) return; + rplReadNumberAsReal(argstep,&step); + if(Exceptions) return; + + subReal(&RReg[0],&end,&start); + + if(RReg[0].flags&F_NEGATIVE) { + if(iszeroReal(&step) || !(step.flags&F_NEGATIVE)) addReal(&RReg[0],&RReg[0],&RReg[0]); // STEP=(END-REAL)*2 SO ONLY ONE POINT WILL BE RETURNED + else copyReal(&RReg[0],&step); + } + else { + if(iszeroReal(&step) || (step.flags&F_NEGATIVE)) addReal(&RReg[0],&RReg[0],&RReg[0]); // STEP=(END-REAL)*2 SO ONLY ONE POINT WILL BE RETURNED + else copyReal(&RReg[0],&step); + } + + + copyReal(&RReg[1],&start); + copyReal(&RReg[2],&end); + if(RReg[0].flags&F_NEGATIVE) direction=-1; + else direction=1; + do { + // ADD THE CURRENT NUMBER TO THE LIST + ScratchPointer1=newlist; + ScratchPointer2=ptr; + rplResizeLastObject(RReg[1].len+2); + if(Exceptions) return; + ptr=ScratchPointer2; + newlist=ScratchPointer1; + ptr=rplNewRealInPlace(&RReg[1],ptr); + addReal(&RReg[1],&RReg[1],&RReg[0]); + + } while(cmpReal(&RReg[1],&RReg[2])!=direction); + + newlist[0]=MKPROLOG(DOCASELIST,ptr-newlist); + newlist[ptr-newlist]=CMD_ENDLIST; + + + rplOverwriteData(3,newlist); + rplDropData(2); + return; + + + } @@ -2068,7 +2208,7 @@ void LIB_HANDLER() if(*tok==')') { if((TokenLen==1) && (CurrentConstruct==MKPROLOG(DOSYMB,0))) { - rplCompileAppend(MKOPCODE(LIBRARY_NUMBER,OPENBRACKET)); // INDICATE THE OPENING BRACKET TO MATCH + rplCompileAppend(MKOPCODE(LIBRARY_NUMBER,CLOSEBRACKET)); // INDICATE THE OPENING BRACKET TO MATCH RetNum=OK_CONTINUE; } else RetNum=ERR_NOTMINE; @@ -2083,6 +2223,14 @@ void LIB_HANDLER() return; } + if( (TokenLen==2) && (*tok=='c') && (tok[1]=='{')) { + if(CurrentConstruct==MKPROLOG(DOSYMB,0)) { + rplCompileAppend(MKOPCODE(LIBRARY_NUMBER,CLISTOPENBRACKET)); + RetNum=OK_CONTINUE; + } + else RetNum=ERR_NOTMINE; + return; + } if(*tok=='{') { if((TokenLen==1)&&(CurrentConstruct==MKPROLOG(DOSYMB,0))) { rplCompileAppend(MKOPCODE(LIBRARY_NUMBER,LISTOPENBRACKET)); @@ -2094,7 +2242,7 @@ void LIB_HANDLER() if(*tok=='}') { if((TokenLen==1)&&(CurrentConstruct==MKPROLOG(DOSYMB,0))) { // ISSUE A BUILDLIST OPERATOR - rplCompileAppend(MKOPCODE(LIBRARY_NUMBER,LISTOPENBRACKET)); + rplCompileAppend(MKOPCODE(LIBRARY_NUMBER,LISTCLOSEBRACKET)); RetNum=OK_CONTINUE; } else RetNum=ERR_NOTMINE; diff --git a/newrpl/lib-62-lists.c b/newrpl/lib-62-lists.c index 905a737..92a476e 100644 --- a/newrpl/lib-62-lists.c +++ b/newrpl/lib-62-lists.c @@ -3005,10 +3005,67 @@ void LIB_HANDLER() //DECOMPILE RETURNS // RetNum = enum DecompileErrors if(ISPROLOG(*DecompileObject)) { + + if(!ISAUTOEXPLIST(*DecompileObject)) rplDecompAppendString((BYTEPTR)"{"); else rplDecompAppendString((BYTEPTR)"c{"); - RetNum=OK_STARTCONSTRUCT; + BINT islistoflist=rplListHasLists(DecompileObject); + BINT depth=0,needseparator; + + if(islistoflist) needseparator=!rplDecompDoHintsWidth(HINT_NLAFTER|HINT_ADDINDENTAFTER); + else needseparator=!rplDecompDoHintsWidth(0); + if(needseparator) rplDecompAppendChar(' '); + + BINT offset=1,endoffset=rplObjSize(DecompileObject); + + while(offset" @#name allroots_rules { -'√.xX:→XROOT(ABS(.xX),2)*{1,-1}' -'.xX^(1/.iN):→XROOT(ABS(.xX),.iN)*е^(ARG(.xX)/.iN*і+RANGE(1,.iN,1))' +'√.xX:→XROOT(ABS(.xX),2)*c{1,-1}' +'.xX^(1/.iN):→XROOT(ABS(.xX),.iN)*е^(ARG(.xX)/.iN*і+∡360°/.iN*RANGE(1,.iN,1))' } diff --git a/newrpl/symbolic.c b/newrpl/symbolic.c index db74723..e814f12 100644 --- a/newrpl/symbolic.c +++ b/newrpl/symbolic.c @@ -492,7 +492,6 @@ WORDPTR rplSymbImplode(WORDPTR *exprstart) { if(addcount) { numobjects+=OBJSIZE(**stkptr)-1; addcount=0; } if((!ISBINT(**stkptr)) && (!ISPROLOG(**stkptr))) { addcount=1; ++numobjects; } - size+=rplObjSize(*stkptr); --stkptr; } @@ -516,13 +515,37 @@ WORDPTR rplSymbImplode(WORDPTR *exprstart) ++f; } else { - if(f==0) { - // FIRST OBJECT NEEDS A SYMBOLIC WRAPPER EVEN WITHOUT AN OPCODE - *newptr++=MKPROLOG(DOSYMB,rplObjSize(object)); + if(ISLIST(*object)) { + // CONVERT THE LIST INTO A SYMBOLIC LIST CONSTRUCTOR OPERATOR + *newptr++=MKPROLOG(DOSYMB,rplObjSize(object)-1); + if(ISAUTOEXPLIST(*object)) *newptr++=CMD_CLISTOPENBRACKET; + else *newptr++=CMD_LISTOPENBRACKET; + // NOW COPY THE OBJECTS IN THE LIST + WORDPTR endobj=rplSkipOb(object)-1; // STOP AT THE CMD_ENDLIST OBJECT + BINT k; + object++; + while(object!=endobj) { + if(*object==CMD_ENDLIST) { ++object; continue; } + if(ISLIST(*object)) { + *newptr++=MKPROLOG(DOSYMB,rplObjSize(object)-1); + if(ISAUTOEXPLIST(*object)) *newptr++=CMD_CLISTOPENBRACKET; + else *newptr++=CMD_LISTOPENBRACKET; + object++; + continue; + } + for(k=0;k0) && (s.leftidx<=s.leftnargs)) { @@ -3995,9 +4018,9 @@ do { } printf("\n"); fflush(stdout); #endif - //****************************************************** + // ****************************************************** // END DEBUG ONLY AREA - //****************************************************** + // ****************************************************** @@ -4048,9 +4071,9 @@ do { reloadPointers(DSTop,&s); - //****************************************************** + // ****************************************************** // DEBUG ONLY AREA - //****************************************************** + // ****************************************************** #ifdef RULEDEBUG printf("RESTARTMATCH: %d/%d,%d/%d",s.leftidx,s.leftnargs,s.rightidx,s.rightnargs); if((s.leftidx>0) && (s.leftidx<=s.leftnargs)) { @@ -4073,9 +4096,9 @@ do { } printf("\n"); fflush(stdout); #endif - //****************************************************** + // ****************************************************** // END DEBUG ONLY AREA - //****************************************************** + // ****************************************************** if(s.leftidx0) && (s.leftidx<=s.leftnargs)) { @@ -4134,9 +4157,9 @@ do { } printf("\n"); fflush(stdout); #endif - //****************************************************** + // ****************************************************** // END DEBUG ONLY AREA - //****************************************************** + // ****************************************************** @@ -4155,16 +4178,16 @@ do { DSTop=s.left- ( (s.leftnargs)? (1+s.leftnargs):0); baselevel=DSTop-DStkBottom; - //****************************************************** + // ****************************************************** // DEBUG ONLY AREA - //****************************************************** + // ****************************************************** #ifdef RULEDEBUG printf("RESTARTMATCH UP"); printf("\n"); fflush(stdout); #endif - //****************************************************** + // ****************************************************** // END DEBUG ONLY AREA - //****************************************************** + // ****************************************************** @@ -4177,9 +4200,9 @@ do { reloadPointers(DSTop,&s); - //****************************************************** + // ****************************************************** // DEBUG ONLY AREA - //****************************************************** + // ****************************************************** #ifdef RULEDEBUG printf("BACKTRACK: %d/%d,%d/%d",s.leftidx,s.leftnargs,s.rightidx,s.rightnargs); if((s.leftidx>0) && (s.leftidx<=s.leftnargs)) { @@ -4202,9 +4225,9 @@ do { } printf("\n"); fflush(stdout); #endif - //****************************************************** + // ****************************************************** // END DEBUG ONLY AREA - //****************************************************** + // ****************************************************** @@ -4236,32 +4259,32 @@ do { if(Exceptions) { rplCleanupSnapshots(stkbottom); DSTop=expression; LAMTop=lamsave; nLAMBase=lamcurrent; return 0; } - //****************************************************** + // ****************************************************** // DEBUG ONLY AREA - //****************************************************** + // ****************************************************** #ifdef RULEDEBUG printf("ARGUMENT ROT1"); printf("\n"); fflush(stdout); #endif - //****************************************************** + // ****************************************************** // END DEBUG ONLY AREA - //****************************************************** + // ****************************************************** } else { if(s.leftrot && (s.leftrot==s.leftnargs-s.leftidx)) { // ALL ARGUMENTS COMPLETE matchtype=BACKTRACK; - //****************************************************** + // ****************************************************** // DEBUG ONLY AREA - //****************************************************** + // ****************************************************** #ifdef RULEDEBUG printf("BACKTRACKED UP"); printf("\n"); fflush(stdout); #endif - //****************************************************** + // ****************************************************** // END DEBUG ONLY AREA - //****************************************************** + // ****************************************************** break; } @@ -4272,9 +4295,9 @@ do { // NON-COMMUTATIVE MATCH BACKTRACK FROM A SNAPSHOT, THIS SHOULD NEVER HAPPEN (???) - //****************************************************** + // ****************************************************** // DEBUG ONLY AREA - //****************************************************** + // ****************************************************** #ifdef RULEDEBUG printf("ERROR IN BACKTRACK: %d/%d,%d/%d",s.leftidx,s.leftnargs,s.rightidx,s.rightnargs); if((s.leftidx>0) && (s.leftidx<=s.leftnargs)) { @@ -4297,9 +4320,9 @@ do { } printf("\n"); fflush(stdout); #endif - //****************************************************** + // ****************************************************** // END DEBUG ONLY AREA - //****************************************************** + // ****************************************************** break; @@ -4340,9 +4363,9 @@ do { matchstarted=0; - //****************************************************** + // ****************************************************** // DEBUG ONLY AREA - //****************************************************** + // ****************************************************** #ifdef RULEDEBUG printf("BACKTRACKED: %d/%d,%d/%d",s.leftidx,s.leftnargs,s.rightidx,s.rightnargs); if((s.leftidx>0) && (s.leftidx<=s.leftnargs)) { @@ -4365,9 +4388,9 @@ do { } printf("\n"); fflush(stdout); #endif - //****************************************************** + // ****************************************************** // END DEBUG ONLY AREA - //****************************************************** + // ****************************************************** // CLEAN THE PREVIOUS ENVIRONMENT @@ -4386,16 +4409,16 @@ do { // KEEP BACKTRACKING DSTop=s.left- ( (s.leftnargs)? (1+s.leftnargs):0); // DROP ENTIRE LEVEL - //****************************************************** + // ****************************************************** // DEBUG ONLY AREA - //****************************************************** + // ****************************************************** #ifdef RULEDEBUG printf("BACKTRACKED UP"); printf("\n"); fflush(stdout); #endif - //****************************************************** + // ****************************************************** // END DEBUG ONLY AREA - //****************************************************** + // ****************************************************** } } break; @@ -4404,9 +4427,9 @@ do { { reloadPointers(DSTop,&s); - //****************************************************** + // ****************************************************** // DEBUG ONLY AREA - //****************************************************** + // ****************************************************** #ifdef RULEDEBUG printf("ARGDONE: %d/%d,%d/%d",s.leftidx,s.leftnargs,s.rightidx,s.rightnargs); if((s.leftidx>0) && (s.leftidx<=s.leftnargs)) { @@ -4429,9 +4452,9 @@ do { } printf("\n"); fflush(stdout); #endif - //****************************************************** + // ****************************************************** // END DEBUG ONLY AREA - //****************************************************** + // ****************************************************** ++s.leftidx; @@ -4447,9 +4470,9 @@ do { rplSymbReplaceMatchHere(rule,s.leftidx-s.rightnargs); if(Exceptions) { rplCleanupSnapshots(stkbottom); DSTop=expression; LAMTop=lamsave; nLAMBase=lamcurrent; return 0; } - //****************************************************** + // ****************************************************** // DEBUG ONLY AREA - //****************************************************** + // ****************************************************** #ifdef RULEDEBUG printf("REPLACED (EXTRA LEFT): "); WORDPTR string=rplDecompile(*DStkBottom,DECOMP_EDIT|DECOMP_NOHINTS); @@ -4461,9 +4484,9 @@ do { } printf("\n"); fflush(stdout); #endif - //****************************************************** + // ****************************************************** // END DEBUG ONLY AREA - //****************************************************** + // ****************************************************** // UPDATE ALL POINTERS AS THE EXPRESSION MOVED IN THE STACK baselevel=DSTop-DStkBottom; reloadPointers(DSTop,&s); @@ -4516,16 +4539,16 @@ do { if(Exceptions) { rplCleanupSnapshots(stkbottom); DSTop=expression; LAMTop=lamsave; nLAMBase=lamcurrent; return 0; } - //****************************************************** + // ****************************************************** // DEBUG ONLY AREA - //****************************************************** + // ****************************************************** #ifdef RULEDEBUG printf("ARGDONE UP"); printf("\n"); fflush(stdout); #endif - //****************************************************** + // ****************************************************** // END DEBUG ONLY AREA - //****************************************************** + // ****************************************************** } @@ -4596,9 +4619,9 @@ do { if( (s.leftidx-s.rightnargs>=1)&& (s.leftidx-s.rightnargs0) && (s.leftidx<=s.leftnargs)) { @@ -4710,9 +4733,9 @@ do { } printf("\n"); fflush(stdout); #endif - //****************************************************** + // ****************************************************** // END DEBUG ONLY AREA - //****************************************************** + // ****************************************************** // TODO: HANDLE THE CASE OF PARTIAL MATCH // ALL ARGUMENTS ARE DONE, PASS IT TO THE UPPER LEVEL