From fc877ec1c9edaa7da781e8504f629108f29f642a Mon Sep 17 00:00:00 2001 From: claudio Date: Sat, 8 Aug 2015 20:31:54 -0400 Subject: [PATCH] More progress in decimal port. --- firmware/hal_keyboard.c | 2 +- newrpl/compiler.c | 34 ++++---- newrpl/decimal.c | 134 ++++---------------------------- newrpl/lib-24-string.c | 2 +- newrpl/lib-28-dirs.c | 2 + newrpl/lib-30-complex.c | 1 + newrpl/lib-32-symbolic.c | 1 + newrpl/lib-4080-localenv.c | 1 + newrpl/lib-4090-overloaded.c | 1 + newrpl/lib-48-matrix.c | 4 +- newrpl/lib-50-lists.c | 1 + newrpl/lib-64-precision.c | 1 + newrpl/lib-65-development.c | 1 + newrpl/lib-66-transcendentals.c | 1 + newrpl/lib-68-flags.c | 1 + newrpl/lib-70-binary.c | 1 + newrpl/lib-72-stack.c | 1 + newrpl/lib-eight-docol.c | 1 + newrpl/lib-nine-docol2.c | 1 + newrpl/lib-ten-reals.c | 35 +++++---- newrpl/lib-twelve-bint.c | 1 + newrpl/lib-twenty-lam.c | 1 + newrpl/lib-two-ident.c | 1 + newrpl/libraries.h | 7 +- newrpl/newrpl.h | 10 ++- newrpl/romlibs.c | 18 +++-- 26 files changed, 98 insertions(+), 166 deletions(-) diff --git a/firmware/hal_keyboard.c b/firmware/hal_keyboard.c index 4ea7c82..0f3220b 100644 --- a/firmware/hal_keyboard.c +++ b/firmware/hal_keyboard.c @@ -757,7 +757,7 @@ void downKeyHandler(BINT keymsg) if(rplDepthData()>=1) { WORDPTR ptr=rplPeekData(1); - WORDPTR text=rplDecompile(ptr,0); + WORDPTR text=rplDecompile(ptr,DECOMP_EDIT); if(Exceptions) { halShowErrorMsg(); Exceptions=0; diff --git a/newrpl/compiler.c b/newrpl/compiler.c index 78733d4..e019750 100644 --- a/newrpl/compiler.c +++ b/newrpl/compiler.c @@ -848,12 +848,12 @@ void rplDecompAppendString2(BYTEPTR str,BINT len) #define SAVED_POINTERS 4 -WORDPTR rplDecompile(WORDPTR object,BINT embedded) +WORDPTR rplDecompile(WORDPTR object,BINT flags) { LIBHANDLER han; BINT infixmode=0; WORDPTR *SavedRSTop; - if(embedded) { + if(flags&DECOMP_EMBEDDED) { SavedRSTop=RSTop; // SAVE ALL DECOMPILER POINTERS @@ -879,7 +879,7 @@ WORDPTR rplDecompile(WORDPTR object,BINT embedded) // START DECOMPILE LOOP // CREATE A STRING AT THE END OF TEMPOB - if(!embedded) CompileEnd=TempObEnd; + if(!(flags&DECOMP_EMBEDDED)) CompileEnd=TempObEnd; // SKIPOB TO DETERMINE END OF COMPILATION EndOfObject=rplSkipOb(object); @@ -888,7 +888,7 @@ WORDPTR rplDecompile(WORDPTR object,BINT embedded) *ValidateTop++=DecompileObject; // STORE START OF OBJECT FOR QUICK SKIPPING // HERE ALL POINTERS ARE STORED IN GC-UPDATEABLE AREA - if(!embedded) { + if(!(flags&DECOMP_EMBEDDED)) { // CREATE EMPTY STRING AT END OF TEMPOB rplCompileAppend(MKPROLOG(DOSTRING,0)); DecompStringEnd=CompileEnd; @@ -901,7 +901,7 @@ WORDPTR rplDecompile(WORDPTR object,BINT embedded) // CALL LIBRARY HANDLER TO DECOMPILE han=rplGetLibHandler(LIBNUM(*DecompileObject)); - CurOpcode=MKOPCODE(0,OPCODE_DECOMPILE); + CurOpcode=MKOPCODE(0,(flags&DECOMP_EDIT)? OPCODE_DECOMPEDIT:OPCODE_DECOMPILE); if(ValidateTop>RSTop) CurrentConstruct=**(ValidateTop-1); else CurrentConstruct=0; @@ -918,7 +918,7 @@ WORDPTR rplDecompile(WORDPTR object,BINT embedded) if(RStkSize<=(ValidateTop-RStk)) growRStk(ValidateTop-RStk+RSTKSLACK); if(Exceptions) { LAMTop=LAMTopSaved; - if(embedded) { + if(flags&DECOMP_EMBEDDED) { // RESTORE ALL POINTERS BEFORE RETURNING SavedDecompObject=*--RSTop; LAMTopSaved=(WORDPTR *)*--RSTop; @@ -947,7 +947,7 @@ WORDPTR rplDecompile(WORDPTR object,BINT embedded) if(!infixmode) InfixOpTop=ValidateTop; if(RStkSize<=(InfixOpTop+1-(WORDPTR)RStk)) growRStk(InfixOpTop-(WORDPTR)RStk+RSTKSLACK); if(Exceptions) { LAMTop=LAMTopSaved; - if(embedded) { + if(flags&DECOMP_EMBEDDED) { // RESTORE ALL POINTERS BEFORE RETURNING SavedDecompObject=*--RSTop; LAMTopSaved=(WORDPTR *)*--RSTop; @@ -1005,7 +1005,7 @@ end_of_expression: if(RStkSize<=(InfixOpTop+1-(WORDPTR)RStk)) growRStk(InfixOpTop-(WORDPTR)RStk+RSTKSLACK); if(Exceptions) { LAMTop=LAMTopSaved; - if(embedded) { + if(flags&DECOMP_EMBEDDED) { // RESTORE ALL POINTERS BEFORE RETURNING SavedDecompObject=*--RSTop; LAMTopSaved=(WORDPTR *)*--RSTop; @@ -1075,14 +1075,14 @@ end_of_expression: break; case TITYPE_PREFIXOP: // DECOMPILE THE OPERATOR NOW! - CurOpcode=MKOPCODE(LIBNUM(*DecompileObject),OPCODE_DECOMPILE); + CurOpcode=MKOPCODE(LIBNUM(*DecompileObject),(flags&DECOMP_EDIT)? OPCODE_DECOMPEDIT:OPCODE_DECOMPILE); (*handler)(); // IGNORE THE RESULT OF DECOMPILATION if(RetNum!=OK_CONTINUE) { Exceptions|=EX_BADOPCODE; ExceptionPointer=IPtr; LAMTop=LAMTopSaved; // RESTORE ENVIRONMENTS - if(embedded) { + if(flags&DECOMP_EMBEDDED) { // RESTORE ALL POINTERS BEFORE RETURNING SavedDecompObject=*--RSTop; LAMTopSaved=(WORDPTR *)*--RSTop; @@ -1100,7 +1100,7 @@ end_of_expression: case TITYPE_FUNCTION: default: // DECOMPILE THE OPERATOR NOW, THEN ADD PARENTHESIS FOR THE LIST - CurOpcode=MKOPCODE(LIBNUM(*DecompileObject),OPCODE_DECOMPILE); + CurOpcode=MKOPCODE(LIBNUM(*DecompileObject),(flags&DECOMP_EDIT)? OPCODE_DECOMPEDIT:OPCODE_DECOMPILE); RetNum=-1; if(handler) (*handler)(); // IGNORE THE RESULT OF DECOMPILATION @@ -1163,7 +1163,7 @@ end_of_expression: if(no_output==0) { BINT libnum=LIBNUM(Operator); DecompileObject=&Operator; - CurOpcode=MKOPCODE(libnum,OPCODE_DECOMPILE); + CurOpcode=MKOPCODE(libnum,(flags&DECOMP_EDIT)? OPCODE_DECOMPEDIT:OPCODE_DECOMPILE); handler=rplGetLibHandler(libnum); RetNum=-1; @@ -1233,7 +1233,7 @@ end_of_expression: BINT libnum=LIBNUM(Operator); DecompileObject=&Operator; - CurOpcode=MKOPCODE(libnum,OPCODE_DECOMPILE); + CurOpcode=MKOPCODE(libnum,(flags&DECOMP_EDIT)? OPCODE_DECOMPEDIT:OPCODE_DECOMPILE); handler=rplGetLibHandler(libnum); RetNum=-1; @@ -1349,7 +1349,7 @@ end_of_expression: BINT libnum=LIBNUM(*(InfixOpTop-2)); SavedDecompObject=DecompileObject; DecompileObject=InfixOpTop-2; - CurOpcode=MKOPCODE(libnum,OPCODE_DECOMPILE); + CurOpcode=MKOPCODE(libnum,(flags&DECOMP_EDIT)? OPCODE_DECOMPEDIT:OPCODE_DECOMPILE); handler=rplGetLibHandler(libnum); RetNum=-1; @@ -1460,7 +1460,7 @@ end_of_expression: // DONE, HERE WE HAVE THE STRING FINISHED - if(!embedded) { + if(!(flags&DECOMP_EMBEDDED)) { // STORE THE SIZE OF THE STRING IN WORDS IN THE PROLOG *(CompileEnd-1)=MKPROLOG(DOSTRING+((-(WORD)DecompStringEnd)&3),(((WORD)DecompStringEnd-(WORD)CompileEnd)+3)>>2); CompileEnd=rplSkipOb(CompileEnd-1); @@ -1474,7 +1474,7 @@ end_of_expression: // ENLARGE TEMPOB AS NEEDED growTempOb((BINT)(CompileEnd-TempOb)+TEMPOBSLACK); if(Exceptions) { - if(embedded) { + if(flags&DECOMP_EMBEDDED) { // RESTORE ALL POINTERS BEFORE RETURNING SavedDecompObject=*--RSTop; LAMTopSaved=(WORDPTR *)*--RSTop; @@ -1486,7 +1486,7 @@ end_of_expression: } } - if(embedded) { + if(flags&DECOMP_EMBEDDED) { // RESTORE ALL POINTERS BEFORE RETURNING SavedDecompObject=*--RSTop; LAMTopSaved=(WORDPTR *)*--RSTop; diff --git a/newrpl/decimal.c b/newrpl/decimal.c index 4eb6b13..5a306fe 100644 --- a/newrpl/decimal.c +++ b/newrpl/decimal.c @@ -1604,6 +1604,7 @@ void add_real(REAL *r,REAL *a,REAL *b) skipbwords=totalwords; totalwords=((Context.precdigits+7)>>3)+2; skipbwords-=totalwords; + result->flags|=F_APPROX; } // COPY THE VAULE a TO THE result @@ -1632,11 +1633,18 @@ void add_real(REAL *r,REAL *a,REAL *b) else add_long(result->data+totalwords-alen+wordshift+skipbwords,b->data+skipbwords,b->len-skipbwords); } + } else { + // THERE'S NO OVERLAP WITHIN THE CURRENT PRECISION + // DON'T DO THE ADDITION, BUT MARK THE RESULT AS APPROXIMATED + + result->flags|=F_APPROX; + + } // NO CARRY CORRECTION result->len=totalwords; - result->flags|=F_NOTNORMALIZED; + result->flags|=F_NOTNORMALIZED | ((a->flags|b->flags)&F_APPROX); result->exp=a->exp-((totalwords-a->len)<<3); // NO ROUNDING OR TRUNCATION @@ -3512,7 +3520,7 @@ BINT ltReal(REAL *a,REAL *b) int digits_a,digits_b; digits_a=sig_digits(a->data[a->len-1])+((a->len-1)<<3)+a->exp; - digits_b=sig_digits(b->data[b->len-1])+((b->len-1)<<3)+a->exp; + digits_b=sig_digits(b->data[b->len-1])+((b->len-1)<<3)+b->exp; if(digits_a>digits_b) { // ABS(A)>ABS(B) @@ -3606,126 +3614,12 @@ BINT gtReal(REAL *a,REAL *b) BINT lteReal(REAL *a,REAL *b) { - // TEST 1, SIGN - if((a->flags^b->flags)&F_NEGATIVE) { - // BOTH NUMBERS HAVE DIFFERENT SIGNS - if(a->flags&F_NEGATIVE) return 1; - else return 0; - } - - // NUMBERS HAVE THE SAME SIGNS - - // CHECK FOR SPECIALS - if((a->flags|b->flags)&F_NOTANUMBER) { - // IF ANY OF THE NUMBERS IS NOT A NUMBER, THE COMPARISON MAKES NO SENSE - // COMPARISONS ARE ALWAYS FALSE - return 0; - } - if(a->flags&F_INFINITY) { - if(a->flags&F_NEGATIVE) { - // A <= B - return 1; - } - else { - // A >= B - if(b->flags&F_INFINITY) return 1; - return 0; - } - } - - // TEST 2, POSITION OF THE MOST SIGNIFICANT DIGIT - - int digits_a,digits_b; - - digits_a=sig_digits(a->data[a->len-1])+((a->len-1)<<3)+a->exp; - digits_b=sig_digits(b->data[b->len-1])+((b->len-1)<<3)+a->exp; - - if(digits_a>digits_b) { - // ABS(A)>ABS(B) - if(a->flags&F_NEGATIVE) return 1; // Aflags&F_NEGATIVE) return 0; // A>B - return 1; - } - - // HERE NUMBERS HAVE THE SAME SIGN AND SAME ORDER OF MAGNITUDE - // NEED TO DO A SUBTRACTION - REAL c; - c.data=allocRegister(); - - sub_real(&c,a,b); - - normalize(&c); - - if(c.len==1 && c.data[0]==0) { freeRegister(c.data); return 1; } - freeRegister(c.data); - if(c.flags&F_NEGATIVE) return 1; - return 0; +return !gtReal(a,b); } BINT gteReal(REAL *a,REAL *b) { - // TEST 1, SIGN - if((a->flags^b->flags)&F_NEGATIVE) { - // BOTH NUMBERS HAVE DIFFERENT SIGNS - if(a->flags&F_NEGATIVE) return 0; - else return 1; - } - - // NUMBERS HAVE THE SAME SIGNS - - // CHECK FOR SPECIALS - if((a->flags|b->flags)&F_NOTANUMBER) { - // IF ANY OF THE NUMBERS IS NOT A NUMBER, THE COMPARISON MAKES NO SENSE - // COMPARISONS ARE ALWAYS FALSE - return 0; - } - if(a->flags&F_INFINITY) { - if(!(a->flags&F_NEGATIVE)) { - // A >= B - return 1; - } - else { - // A <= B - if(b->flags&F_INFINITY) return 1; - return 0; - } - } - - // TEST 2, POSITION OF THE MOST SIGNIFICANT DIGIT - - int digits_a,digits_b; - - digits_a=sig_digits(a->data[a->len-1])+((a->len-1)<<3)+a->exp; - digits_b=sig_digits(b->data[b->len-1])+((b->len-1)<<3)+a->exp; - - if(digits_a>digits_b) { - // ABS(A)>ABS(B) - if(a->flags&F_NEGATIVE) return 0; // Aflags&F_NEGATIVE) return 1; // A>B - return 0; - } - - // HERE NUMBERS HAVE THE SAME SIGN AND SAME ORDER OF MAGNITUDE - // NEED TO DO A SUBTRACTION - REAL c; - c.data=allocRegister(); - - sub_real(&c,a,b); - - normalize(&c); - - if(c.len==1 && c.data[0]==0) { freeRegister(c.data); return 1; } // A==B - freeRegister(c.data); - if(c.flags&F_NEGATIVE) return 0; - return 1; + return !ltReal(a,b); } BINT eqReal(REAL *a,REAL *b) @@ -3753,7 +3647,7 @@ BINT eqReal(REAL *a,REAL *b) int digits_a,digits_b; digits_a=sig_digits(a->data[a->len-1])+((a->len-1)<<3)+a->exp; - digits_b=sig_digits(b->data[b->len-1])+((b->len-1)<<3)+a->exp; + digits_b=sig_digits(b->data[b->len-1])+((b->len-1)<<3)+b->exp; if(digits_a!=digits_b) return 0; @@ -3810,7 +3704,7 @@ BINT cmpReal(REAL *a,REAL *b) int digits_a,digits_b; digits_a=sig_digits(a->data[a->len-1])+((a->len-1)<<3)+a->exp; - digits_b=sig_digits(b->data[b->len-1])+((b->len-1)<<3)+a->exp; + digits_b=sig_digits(b->data[b->len-1])+((b->len-1)<<3)+b->exp; if(digits_a>digits_b) { // ABS(A)>ABS(B) diff --git a/newrpl/lib-24-string.c b/newrpl/lib-24-string.c index dadefa4..76c406f 100644 --- a/newrpl/lib-24-string.c +++ b/newrpl/lib-24-string.c @@ -422,7 +422,7 @@ void LIB_HANDLER() // THIS IS UNREACHABLE CODE HERE } - + case OPCODE_DECOMPEDIT: case OPCODE_DECOMPILE: // DECOMPILE RECEIVES: // DecompileObject = Ptr to prolog of object to decompile diff --git a/newrpl/lib-28-dirs.c b/newrpl/lib-28-dirs.c index 4035260..686ca10 100644 --- a/newrpl/lib-28-dirs.c +++ b/newrpl/lib-28-dirs.c @@ -385,6 +385,8 @@ void LIB_HANDLER() libCompileCmds(LIBRARY_NUMBER,(char **)LIB_NAMES,NULL,LIB_NUMBEROFCMDS); return; + case OPCODE_DECOMPEDIT: + case OPCODE_DECOMPILE: // DECOMPILE RECEIVES: // DecompileObject = Ptr to prolog of object to decompile diff --git a/newrpl/lib-30-complex.c b/newrpl/lib-30-complex.c index 01d0f03..a43c3ba 100644 --- a/newrpl/lib-30-complex.c +++ b/newrpl/lib-30-complex.c @@ -737,6 +737,7 @@ void LIB_HANDLER() libCompileCmds(LIBRARY_NUMBER,(char **)LIB_NAMES,NULL,LIB_NUMBEROFCMDS); return; + case OPCODE_DECOMPEDIT: case OPCODE_DECOMPILE: // DECOMPILE RECEIVES: diff --git a/newrpl/lib-32-symbolic.c b/newrpl/lib-32-symbolic.c index e13e417..56fe472 100644 --- a/newrpl/lib-32-symbolic.c +++ b/newrpl/lib-32-symbolic.c @@ -894,6 +894,7 @@ void LIB_HANDLER() libCompileCmds(LIBRARY_NUMBER,(char **)LIB_NAMES,NULL,LIB_NUMBEROFCMDS); return; + case OPCODE_DECOMPEDIT: case OPCODE_DECOMPILE: // DECOMPILE RECEIVES: diff --git a/newrpl/lib-4080-localenv.c b/newrpl/lib-4080-localenv.c index 845d96c..ff272fc 100644 --- a/newrpl/lib-4080-localenv.c +++ b/newrpl/lib-4080-localenv.c @@ -125,6 +125,7 @@ void LIB_HANDLER() RetNum=ERR_NOTMINE; return; + case OPCODE_DECOMPEDIT: case OPCODE_DECOMPILE: // DECOMPILE RECEIVES: diff --git a/newrpl/lib-4090-overloaded.c b/newrpl/lib-4090-overloaded.c index 1ec4145..ed26483 100644 --- a/newrpl/lib-4090-overloaded.c +++ b/newrpl/lib-4090-overloaded.c @@ -174,6 +174,7 @@ void LIB_HANDLER() libCompileCmds(LIBRARY_NUMBER,(char **)LIB_NAMES,(WORDPTR)LIB_OPCODES,LIB_NUMCMDS); return; + case OPCODE_DECOMPEDIT: case OPCODE_DECOMPILE: diff --git a/newrpl/lib-48-matrix.c b/newrpl/lib-48-matrix.c index fc1627f..721f0f2 100644 --- a/newrpl/lib-48-matrix.c +++ b/newrpl/lib-48-matrix.c @@ -1165,6 +1165,7 @@ void LIB_HANDLER() libCompileCmds(LIBRARY_NUMBER,(char **)LIB_NAMES,NULL,LIB_NUMBEROFCMDS); return; + case OPCODE_DECOMPEDIT: case OPCODE_DECOMPILE: // DECOMPILE RECEIVES: @@ -1175,6 +1176,7 @@ void LIB_HANDLER() // RetNum = enum DecompileErrors + if(ISPROLOG(*DecompileObject)) { rplDecompAppendString((BYTEPTR)"[ "); BINT rows=MATROWS(*(DecompileObject+1)),cols=MATCOLS(*(DecompileObject+1)); @@ -1193,7 +1195,7 @@ void LIB_HANDLER() { BINT offset=*(DecompileObject+2+i*cols+j); - rplDecompile(DecompileObject+offset,1); // RUN EMBEDDED + rplDecompile(DecompileObject+offset,DECOMP_EMBEDDED | ((CurOpcode==OPCODE_DECOMPEDIT)? DECOMP_EDIT:0)); // RUN EMBEDDED if(Exceptions) { RetNum=ERR_INVALID; return; } rplDecompAppendChar(' '); } diff --git a/newrpl/lib-50-lists.c b/newrpl/lib-50-lists.c index b66122c..09df1d3 100644 --- a/newrpl/lib-50-lists.c +++ b/newrpl/lib-50-lists.c @@ -2580,6 +2580,7 @@ void LIB_HANDLER() libCompileCmds(LIBRARY_NUMBER,(char **)LIB_NAMES,NULL,LIB_NUMBEROFCMDS); return; + case OPCODE_DECOMPEDIT: case OPCODE_DECOMPILE: // DECOMPILE RECEIVES: diff --git a/newrpl/lib-64-precision.c b/newrpl/lib-64-precision.c index b708bdf..7d81be7 100644 --- a/newrpl/lib-64-precision.c +++ b/newrpl/lib-64-precision.c @@ -197,6 +197,7 @@ void LIB_HANDLER() libCompileCmds(LIBRARY_NUMBER,(char **)LIB_NAMES,NULL,LIB_NUMBEROFCMDS); return; + case OPCODE_DECOMPEDIT: case OPCODE_DECOMPILE: // DECOMPILE RECEIVES: diff --git a/newrpl/lib-65-development.c b/newrpl/lib-65-development.c index d2523f8..dc7f8d8 100644 --- a/newrpl/lib-65-development.c +++ b/newrpl/lib-65-development.c @@ -318,6 +318,7 @@ void LIB_HANDLER() libCompileCmds(LIBRARY_NUMBER,(char **)LIB_NAMES,NULL,LIB_NUMBEROFCMDS); return; + case OPCODE_DECOMPEDIT: case OPCODE_DECOMPILE: // DECOMPILE RECEIVES: diff --git a/newrpl/lib-66-transcendentals.c b/newrpl/lib-66-transcendentals.c index 086e972..741b9aa 100644 --- a/newrpl/lib-66-transcendentals.c +++ b/newrpl/lib-66-transcendentals.c @@ -697,6 +697,7 @@ void LIB_HANDLER() libCompileCmds(LIBRARY_NUMBER,(char **)LIB_NAMES,NULL,LIB_NUMBEROFCMDS); return; + case OPCODE_DECOMPEDIT: case OPCODE_DECOMPILE: // DECOMPILE RECEIVES: diff --git a/newrpl/lib-68-flags.c b/newrpl/lib-68-flags.c index fc2eb52..9ccda92 100644 --- a/newrpl/lib-68-flags.c +++ b/newrpl/lib-68-flags.c @@ -684,6 +684,7 @@ void LIB_HANDLER() libCompileCmds(LIBRARY_NUMBER,(char **)LIB_NAMES,NULL,LIB_NUMBEROFCMDS); return; + case OPCODE_DECOMPEDIT: case OPCODE_DECOMPILE: // DECOMPILE RECEIVES: diff --git a/newrpl/lib-70-binary.c b/newrpl/lib-70-binary.c index 0073e73..8d7c040 100644 --- a/newrpl/lib-70-binary.c +++ b/newrpl/lib-70-binary.c @@ -726,6 +726,7 @@ void LIB_HANDLER() libCompileCmds(LIBRARY_NUMBER,(char **)LIB_NAMES,NULL,LIB_NUMBEROFCMDS); return; + case OPCODE_DECOMPEDIT: case OPCODE_DECOMPILE: // DECOMPILE RECEIVES: diff --git a/newrpl/lib-72-stack.c b/newrpl/lib-72-stack.c index 334c626..9f2756a 100644 --- a/newrpl/lib-72-stack.c +++ b/newrpl/lib-72-stack.c @@ -409,6 +409,7 @@ void LIB_HANDLER() libCompileCmds(LIBRARY_NUMBER,(char **)LIB_NAMES,NULL,LIB_NUMBEROFCMDS); return; + case OPCODE_DECOMPEDIT: case OPCODE_DECOMPILE: // DECOMPILE RECEIVES: diff --git a/newrpl/lib-eight-docol.c b/newrpl/lib-eight-docol.c index 2733524..20fbb65 100644 --- a/newrpl/lib-eight-docol.c +++ b/newrpl/lib-eight-docol.c @@ -157,6 +157,7 @@ void LIB_HANDLER() // SINCE THIS IS THE LAST LIBRARY TO BE EVALUATED, DO ONE LAST PASS TO COMPILE IT AS AN IDENT // EITHER LAM OR IN USEROB return; + case OPCODE_DECOMPEDIT: case OPCODE_DECOMPILE: // DECOMPILE RECEIVES: diff --git a/newrpl/lib-nine-docol2.c b/newrpl/lib-nine-docol2.c index 5edceb0..768c186 100644 --- a/newrpl/lib-nine-docol2.c +++ b/newrpl/lib-nine-docol2.c @@ -817,6 +817,7 @@ void LIB_HANDLER() + case OPCODE_DECOMPEDIT: case OPCODE_DECOMPILE: // DECOMPILE RECEIVES: diff --git a/newrpl/lib-ten-reals.c b/newrpl/lib-ten-reals.c index 8d9fcef..ee6a75e 100644 --- a/newrpl/lib-ten-reals.c +++ b/newrpl/lib-ten-reals.c @@ -449,21 +449,16 @@ void LIB_HANDLER() BINT isapprox=0; BINT tlen=TokenLen; - if(strptr[tlen-1]=='.') { - // NUMBERS ENDING IN A DOT ARE APPROXIMATED - isapprox|=APPROX_BIT; - --tlen; - } - - newRealFromText(&RReg[0],(char *)TokenStart,tlen); + if(RReg[0].flags&F_ERROR) { // THERE WAS SOME ERROR DURING THE CONVERSION, PROBABLY A SYNTAX ERROR RetNum=ERR_NOTMINE; return; } + if(RReg[0].flags&F_APPROX) isapprox=APPROX_BIT; // WRITE THE PROLOG rplCompileAppend(MKPROLOG(LIBRARY_NUMBER|isapprox,1+RReg[0].len)); // PACK THE INFORMATION @@ -480,6 +475,9 @@ void LIB_HANDLER() RetNum=OK_CONTINUE; return; } + + case OPCODE_DECOMPEDIT: + case OPCODE_DECOMPILE: // DECOMPILE RECEIVES: // DecompileObject = Ptr to WORD of object to decompile @@ -503,25 +501,32 @@ void LIB_HANDLER() BigNumLimit.exp=12; SmallNumLimit.exp=-4; - BINT *Format; + BINT Format; - if(ltReal(&realnum,&SmallNumLimit)) Format=&FmtSmall; - else if(gtReal(&realnum,&BigNumLimit)) Format=&FmtLarge; - else Format=&FmtNormal; + if(ltReal(&realnum,&SmallNumLimit)) Format=FmtSmall; + else if(gtReal(&realnum,&BigNumLimit)) Format=FmtLarge; + else Format=FmtNormal; + + if(CurOpcode==OPCODE_DECOMPEDIT) Format|=FMT_CODE; // ESTIMATE THE MAXIMUM STRING LENGTH AND RESERVE THE MEMORY - BYTEPTR string=(BYTEPTR)DecompStringEnd; + BYTEPTR string; - BINT len=formatlengthReal(&realnum,*Format); + BINT len=formatlengthReal(&realnum,Format); - rplDecompAppendString2(string,len); + // RESERVE THE MEMORY FIRST + rplDecompAppendString2(DecompStringEnd,len); + + // NOW USE IT + string=(BYTEPTR)DecompStringEnd; + string-=len; if(Exceptions) { RetNum=ERR_INVALID; return; } - DecompStringEnd=(WORDPTR) formatReal(&realnum,string,*Format,Locale); + DecompStringEnd=(WORDPTR) formatReal(&realnum,string,Format,Locale); RetNum=OK_CONTINUE; diff --git a/newrpl/lib-twelve-bint.c b/newrpl/lib-twelve-bint.c index f95ac6a..4ea754c 100644 --- a/newrpl/lib-twelve-bint.c +++ b/newrpl/lib-twelve-bint.c @@ -958,6 +958,7 @@ void LIB_HANDLER() rplCompileAppend((WORD)( (result>>32)&0xffffffff)); RetNum=OK_CONTINUE; return; + case OPCODE_DECOMPEDIT: case OPCODE_DECOMPILE: // DECOMPILE RECEIVES: diff --git a/newrpl/lib-twenty-lam.c b/newrpl/lib-twenty-lam.c index 84d0b29..df1ec36 100644 --- a/newrpl/lib-twenty-lam.c +++ b/newrpl/lib-twenty-lam.c @@ -897,6 +897,7 @@ void LIB_HANDLER() libCompileCmds(LIBRARY_NUMBER,(char **)LIB_NAMES,NULL,LIB_NUMBEROFCMDS); return; + case OPCODE_DECOMPEDIT: case OPCODE_DECOMPILE: // DECOMPILE RECEIVES: diff --git a/newrpl/lib-two-ident.c b/newrpl/lib-two-ident.c index f4bc1f1..2b7c520 100644 --- a/newrpl/lib-two-ident.c +++ b/newrpl/lib-two-ident.c @@ -294,6 +294,7 @@ void LIB_HANDLER() return; + case OPCODE_DECOMPEDIT: case OPCODE_DECOMPILE: // DECOMPILE RECEIVES: diff --git a/newrpl/libraries.h b/newrpl/libraries.h index 2623e85..0edb222 100644 --- a/newrpl/libraries.h +++ b/newrpl/libraries.h @@ -21,9 +21,10 @@ #define OPCODE_COMPILE 0x7FFFF #define OPCODE_COMPILECONT 0x7FFFE #define OPCODE_DECOMPILE 0x7FFFD -#define OPCODE_VALIDATE 0x7FFFC -#define OPCODE_PROBETOKEN 0x7FFFB -#define OPCODE_GETINFO 0x7FFFA +#define OPCODE_DECOMPEDIT 0x7FFFC +#define OPCODE_VALIDATE 0x7FFFB +#define OPCODE_PROBETOKEN 0x7FFFA +#define OPCODE_GETINFO 0x7FFF9 #define OPCODE_LIBREMOVE 0x7FFF1 #define OPCODE_LIBINSTALL 0x7FFF0 diff --git a/newrpl/newrpl.h b/newrpl/newrpl.h index dc6eac7..6446fd2 100644 --- a/newrpl/newrpl.h +++ b/newrpl/newrpl.h @@ -100,6 +100,11 @@ extern "C" { #include "sysvars.h" + + + + + // INTERNAL TRANSCENDENTAL FUNCTIONS void hyp_exp(REAL *); void hyp_ln(REAL *); @@ -147,15 +152,18 @@ extern void shrinkTempBlocks(WORD newtotalsize); // COMPILER FUNCTIONS IN COMPILER.C + extern WORDPTR rplCompile(BYTEPTR string, BINT len, BINT addwrapper); extern void rplCompileAppend(WORD word); extern WORDPTR rplCompileAppendWords(BINT nwords); extern void rplCompileRemoveWords(BINT nwords); +#define DECOMP_EMBEDDED 1 +#define DECOMP_EDIT 2 // DECOMPILER FUNCTIONS -extern WORDPTR rplDecompile(WORDPTR object, BINT embedded); +extern WORDPTR rplDecompile(WORDPTR object, BINT flags); extern void rplDecompAppendChar(BYTE c); extern void rplDecompAppendString(BYTEPTR str); extern void rplDecompAppendString2(BYTEPTR str,BINT len); diff --git a/newrpl/romlibs.c b/newrpl/romlibs.c index 83b5c44..1684764 100644 --- a/newrpl/romlibs.c +++ b/newrpl/romlibs.c @@ -39,6 +39,7 @@ extern void lib72_handler(); extern void lib4080_handler(); extern void lib4090_handler(); + void dummy_libhandler() { if(ISPROLOG(CurOpcode)) return; @@ -51,15 +52,18 @@ switch(OPCODE(CurOpcode)) // -------------------- // LIBRARIES ARE FORCED TO ALWAYS HANDLE THE STANDARD OPCODES + case OPCODE_LIBINSTALL: + RetNum=ERR_INVALID; + return; - case OPCODE_COMPILE: - RetNum=ERR_NOTMINE; - return; - - case OPCODE_DECOMPILE: - RetNum=ERR_INVALID; - return; } + + RetNum=ERR_INVALID; + Exceptions|=EX_BADOPCODE; + ExceptionPointer=IPtr; + return; + + }