mirror of
https://git.code.sf.net/p/newrpl/sources
synced 2024-11-16 19:51:25 +01:00
Added binary op decompiler
This commit is contained in:
parent
af661ae166
commit
d9b1491ec2
5 changed files with 69 additions and 0 deletions
42
compiler.c
42
compiler.c
|
@ -780,7 +780,49 @@ end_of_expression:
|
|||
break;
|
||||
}
|
||||
case INFIX_BINARYLEFT:
|
||||
{
|
||||
LIBHANDLER handler;
|
||||
// ADD THE OPERATOR AFTER THE LEFT OPERAND
|
||||
BINT libnum=LIBNUM(*(InfixOpTop-2));
|
||||
SavedDecompObject=DecompileObject;
|
||||
DecompileObject=InfixOpTop-2;
|
||||
CurOpcode=MKOPCODE(libnum,OPCODE_DECOMPILE);
|
||||
handler=rplGetLibHandler(libnum);
|
||||
RetNum=-1;
|
||||
|
||||
if(handler) (*handler)();
|
||||
|
||||
DecompileObject=SavedDecompObject;
|
||||
// IGNORE THE RESULT OF DECOMPILATION
|
||||
if(RetNum!=OK_CONTINUE) {
|
||||
rplDecompAppendString((BYTEPTR)"##INVALID##");
|
||||
}
|
||||
|
||||
// NOW CHECK IF THE RIGHT ARGUMENT IS INDEED THE LAST ONE
|
||||
WORDPTR afternext=rplSkipOb(DecompileObject);
|
||||
WORDPTR EndofExpression = rplSkipOb(*(InfixOpTop-4));
|
||||
|
||||
|
||||
if(afternext==EndofExpression) {
|
||||
// THE NEXT ELEMENT IS THE LAST (IT SHOULD ALWAYS BE IF THE BINARY OPERATOR HAS ONLY 2 ARGUMENTS
|
||||
// BUT WE CAN PACK MORE TERMS ON THE SAME '+' OR '*' THIS WAY
|
||||
infixmode=INFIX_BINARYRIGHT;
|
||||
}
|
||||
// IF IT'S NOT, THEN KEEP IT AS THE LEFT OPERATOR FOR THE NEXT ARGUMENT
|
||||
break;
|
||||
|
||||
}
|
||||
case INFIX_BINARYRIGHT:
|
||||
{
|
||||
// WE KNOW THIS IS THE LAST ARGUMENT
|
||||
// POP EXPRESSION FROM THE STACK
|
||||
InfixOpTop-=4;
|
||||
// RESTORE PREVIOUS EXPRESSION STATE
|
||||
infixmode=InfixOpTop[1];
|
||||
DecompileObject=rplSkipOb(*InfixOpTop);
|
||||
goto end_of_expression;
|
||||
}
|
||||
break;
|
||||
case INFIX_POSTFIXARG:
|
||||
case INFIX_PREFIXARG:
|
||||
case INFIX_POSTFIXOP:
|
||||
|
|
|
@ -164,6 +164,10 @@ void LIB_HANDLER()
|
|||
case OPCODE_PROBETOKEN:
|
||||
libProbeCmds(LIBRARY_NUMBER,LIB_NAMES,LIB_TOKENINFO,LIB_NUMCMDS);
|
||||
return;
|
||||
case OPCODE_GETINFO:
|
||||
libGetInfo(*DecompileObject,LIB_NAMES,LIB_OPCODES,LIB_TOKENINFO,LIB_NUMCMDS);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
RetNum=ERR_NOTMINE;
|
||||
|
|
21
lib-common.c
21
lib-common.c
|
@ -74,3 +74,24 @@ void libProbeCmds(BINT libnum,char *libnames[],BINT tokeninfo[],int numcmds)
|
|||
}
|
||||
RetNum=ERR_NOTMINE;
|
||||
}
|
||||
|
||||
void libGetInfo(WORD opcode,char *libnames[],WORD libopcodes[],BINT tokeninfo[],int numcmds)
|
||||
{
|
||||
int idx;
|
||||
int len;
|
||||
opcode=OPCODE(opcode);
|
||||
for(idx=0;idx<numcmds;++idx)
|
||||
{
|
||||
if(libopcodes[idx]==opcode)
|
||||
{
|
||||
if(tokeninfo) {
|
||||
RetNum=OK_TOKENINFO | tokeninfo[idx];
|
||||
} else {
|
||||
len=strlen(libnames[idx]);
|
||||
RetNum=OK_TOKENINFO | MKTOKENINFO(len,TITYPE_NOTALLOWED,0,0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
RetNum=ERR_NOTMINE;
|
||||
}
|
||||
|
|
|
@ -109,6 +109,7 @@ enum CompileErrors {
|
|||
extern void libCompileCmds(BINT libnum, char *libnames[], WORD libopcodes[], int numcmds);
|
||||
extern void libDecompileCmds( char *libnames[], WORD libopcodes[], int numcmds);
|
||||
extern void libProbeCmds(BINT libnum, char *libnames[], BINT tokeninfo[], int numcmds);
|
||||
extern void libGetInfo(WORD opcode,char *libnames[],WORD libopcodes[],BINT tokeninfo[],int numcmds);
|
||||
|
||||
|
||||
// SOME BASIC OBJECT TYPES HERE NEEDED FOR COMPILER
|
||||
|
|
|
@ -32,6 +32,7 @@ extern WORDPTR GC_PTRUpdate[MAX_GC_PTRUPDATE];
|
|||
#define SettingsDir GC_PTRUpdate[10]
|
||||
#define SystemFlags GC_PTRUpdate[11]
|
||||
#define LastCompiledObject GC_PTRUpdate[12]
|
||||
#define SavedDecompObject GC_PTRUpdate[12]
|
||||
#define ScratchPointer1 GC_PTRUpdate[13]
|
||||
#define ScratchPointer2 GC_PTRUpdate[14]
|
||||
#define ScratchPointer3 GC_PTRUpdate[15]
|
||||
|
|
Loading…
Reference in a new issue