void ring_vm_jumpvarplenum ( VM *pVM ) { List *pVar ; double nNum1,nNum2 ; pVar = (List *) RING_VM_IR_READP ; nNum1 = ring_list_getdouble(pVM->aForStep,ring_list_getsize(pVM->aForStep)); /* Check Data */ if ( ring_list_isstring(pVar,RING_VAR_VALUE) ) { nNum2 = ring_vm_stringtonum(pVM,ring_list_getstring(pVar,RING_VAR_VALUE)); } else if ( ring_list_isnumber(pVar,RING_VAR_VALUE) ) { nNum2 = ring_list_getdouble(pVar,RING_VAR_VALUE) ; } else { ring_vm_error(pVM,RING_VM_ERROR_FORLOOPDATATYPE); return ; } if ( nNum1 < 0 ) { if ( ! (nNum2 >= RING_VM_IR_READDVALUE(2)) ) { /* Jump */ pVM->nPC = RING_VM_IR_READIVALUE(3) ; } } else { if ( ! (nNum2 <= RING_VM_IR_READDVALUE(2)) ) { /* Jump */ pVM->nPC = RING_VM_IR_READIVALUE(3) ; } } }
void ring_vm_inclpjump ( VM *pVM ) { List *pVar ; double nNum1,nNum2 ; /* Check Scope Life Time */ if ( RING_VM_IR_READIVALUE(4) != pVM->nActiveScopeID ) { RING_VM_IR_OPCODE = ICO_INCJUMP ; ring_list_deliteminsidelist_gc(pVM->pRingState,pVM->aNewByteCodeItems,RING_VM_IR_ITEM(3)); ring_list_deliteminsidelist_gc(pVM->pRingState,pVM->aNewByteCodeItems,RING_VM_IR_ITEM(4)); #if RING_SHOWICFINAL RING_VM_IR_PARACOUNT = RING_VM_IR_PARACOUNT - 2 ; ring_list_deleteitem_gc(pVM->pRingState,RING_VM_IR_LIST,ring_list_getsize(RING_VM_IR_LIST)); ring_list_deleteitem_gc(pVM->pRingState,RING_VM_IR_LIST,ring_list_getsize(RING_VM_IR_LIST)); #endif pVM->nPC-- ; return ; } pVar = (List *) RING_VM_IR_READPVALUE(3) ; nNum1 = ring_list_getdouble(pVM->aForStep,ring_list_getsize(pVM->aForStep)); /* Check Data */ if ( ring_list_isstring(pVar,RING_VAR_VALUE) ) { nNum2 = ring_vm_stringtonum(pVM,ring_list_getstring(pVar,RING_VAR_VALUE)); } else if ( ring_list_isnumber(pVar,RING_VAR_VALUE) ) { nNum2 = ring_list_getdouble(pVar,RING_VAR_VALUE) ; } else { ring_vm_error(pVM,RING_VM_ERROR_FORLOOPDATATYPE); return ; } ring_list_setdouble_gc(pVM->pRingState,pVar,RING_VAR_VALUE,nNum2 + nNum1); /* Jump */ pVM->nPC = RING_VM_IR_READIVALUE(2) ; }
void ring_vm_jumpvarlenum ( VM *pVM ) { List *pVar ; double nNum1,nNum2 ; if ( ring_vm_findvar(pVM, RING_VM_IR_READC ) == 0 ) { ring_vm_newvar(pVM, RING_VM_IR_READC); } nNum1 = ring_list_getdouble(pVM->aForStep,ring_list_getsize(pVM->aForStep)); /* Change Instruction for Performance */ if ( pVM->nVarScope == RING_VARSCOPE_GLOBAL ) { /* Replace JumpVarLENum with JumpVarPLENum for better performance */ if ( nNum1 == 1.0 ) { RING_VM_IR_OPCODE = ICO_JUMPVARPLENUMSTEP1 ; } else { RING_VM_IR_OPCODE = ICO_JUMPVARPLENUM ; } ring_item_setpointer_gc(pVM->pRingState,RING_VM_IR_ITEM(1),RING_VM_STACK_READP); } else if ( pVM->nVarScope == RING_VARSCOPE_LOCAL ) { /* Replace JumpVarLENum with JumpVarLPLENum for better performance */ RING_VM_IR_OPCODE = ICO_JUMPVARLPLENUM ; ring_item_setpointer_gc(pVM->pRingState,RING_VM_IR_ITEM(4),RING_VM_STACK_READP); ring_item_setint_gc(pVM->pRingState,RING_VM_IR_ITEM(5),ring_list_getint(pVM->aScopeID,ring_list_getsize(pVM->aScopeID))); #if RING_SHOWICFINAL RING_VM_IR_PARACOUNT = RING_VM_IR_PARACOUNT + 2 ; ring_list_addpointer_gc(pVM->pRingState,RING_VM_IR_LIST,RING_VM_STACK_READP); ring_list_addint_gc(pVM->pRingState,RING_VM_IR_LIST,ring_list_getint(pVM->aScopeID,ring_list_getsize(pVM->aScopeID))); #endif } pVar = (List *) RING_VM_STACK_READP ; RING_VM_STACK_POP ; /* Check Data */ if ( ring_list_isstring(pVar,RING_VAR_VALUE) ) { nNum2 = ring_vm_stringtonum(pVM,ring_list_getstring(pVar,RING_VAR_VALUE)); ring_list_setdouble_gc(pVM->pRingState,pVar,RING_VAR_VALUE,nNum2); } else if ( ring_list_isnumber(pVar,RING_VAR_VALUE) ) { nNum2 = ring_list_getdouble(pVar,RING_VAR_VALUE) ; } else { ring_vm_error(pVM,RING_VM_ERROR_FORLOOPDATATYPE); return ; } if ( nNum1 < 0 ) { if ( ! (nNum2 >= RING_VM_IR_READDVALUE(2)) ) { /* Jump */ pVM->nPC = RING_VM_IR_READIVALUE(3) ; } } else { if ( ! (nNum2 <= RING_VM_IR_READDVALUE(2)) ) { /* Jump */ pVM->nPC = RING_VM_IR_READIVALUE(3) ; } } }
void ring_vm_pushpv ( VM *pVM ) { List *pVar ; pVar = (List *) RING_VM_IR_READP ; pVM->nSP++ ; if ( ring_list_isstring(pVar,RING_VAR_VALUE) ) { RING_VM_STACK_PUSHCVAR ; } else if ( ring_list_isnumber(pVar,RING_VAR_VALUE) ) { RING_VM_STACK_PUSHNVAR ; } }
void ring_parser_icg_showoutput ( List *pListGenCode,int nStatus ) { int x,y,nCount,nCount2 ; List *pList ; assert(pListGenCode != NULL); /* Header */ printf( "\n\n" ) ; ring_print_line(); if ( nStatus == 1 ) { puts("Byte Code - Before Execution by the VM"); } else { puts("Byte Code - After Execution by the VM"); } ring_print_line(); nCount = ring_list_getsize(pListGenCode); if ( nCount > 0 ) { printf( "\n %6s %10s %10s\n", "PC","OPCode","Data" ) ; for ( x = 1 ; x <= nCount ; x++ ) { pList = ring_list_getlist(pListGenCode,x); nCount2 = ring_list_getsize(pList); printf( "\n %6d %10s ", x , RING_IC_OP[ring_list_getint(pList,1)] ) ; if ( nCount2 > 1 ) { for ( y = 2 ; y <= nCount2 ; y++ ) { if ( ring_list_isstring(pList,y) ) { printf( " %5s ",ring_list_getstring(pList,y) ) ; } else if ( ring_list_isnumber(pList,y) ) { if ( ring_list_isdouble(pList,y) ) { printf( " %f",ring_list_getdouble(pList,y) ) ; } else { printf( " %5d ",ring_list_getint(pList,y) ) ; } } else { printf( " %5p ",ring_list_getpointer(pList,y) ) ; } } } } printf( "\n" ) ; } /* End */ puts(""); ring_print_line(); puts(""); }
void ring_vm_incpjump ( VM *pVM ) { List *pVar ; double nNum1,nNum2 ; pVar = (List *) RING_VM_IR_READP ; nNum1 = ring_list_getdouble(pVM->aForStep,ring_list_getsize(pVM->aForStep)); /* Check Data */ if ( ring_list_isstring(pVar,RING_VAR_VALUE) ) { nNum2 = ring_vm_stringtonum(pVM,ring_list_getstring(pVar,RING_VAR_VALUE)); } else if ( ring_list_isnumber(pVar,RING_VAR_VALUE) ) { nNum2 = ring_list_getdouble(pVar,RING_VAR_VALUE) ; } else { ring_vm_error(pVM,RING_VM_ERROR_FORLOOPDATATYPE); return ; } ring_list_setdouble_gc(pVM->pRingState,pVar,RING_VAR_VALUE,nNum2 + nNum1); /* Jump */ pVM->nPC = RING_VM_IR_READIVALUE(2) ; }
void ring_objfile_writelist ( List *pList,FILE *fObj ) { List *pList2 ; int x,x2 ; char *cString ; char cKey[11] ; strcpy(cKey,"ringstring"); fprintf( fObj , "{\n" ) ; /* Write List Items */ for ( x = 1 ; x <= ring_list_getsize(pList) ; x++ ) { pList2 = ring_list_getlist(pList,x); fprintf( fObj , "[T]\n" ) ; for ( x2 = 1 ; x2 <= ring_list_getsize(pList2) ; x2++ ) { if ( ring_list_isstring(pList2,x2) ) { fprintf( fObj , "[S][%d]" , ring_list_getstringsize(pList2,x2) ) ; /* Encrypt String */ cString = ring_list_getstring(pList2,x2) ; ring_objfile_xorstring(cString,ring_list_getstringsize(pList2,x2),cKey,10); fwrite( ring_list_getstring(pList2,x2) , 1 , ring_list_getstringsize(pList2,x2) , fObj ); /* Decrypt String */ ring_objfile_xorstring(cString,ring_list_getstringsize(pList2,x2),cKey,10); fprintf( fObj , "\n" ) ; } else if ( ring_list_isint(pList2,x2) ) { fprintf( fObj , "[I]%d\n" , ring_list_getint(pList2,x2) ) ; } else if ( ring_list_isdouble(pList2,x2) ) { fprintf( fObj , "[D]%f\n" , ring_list_getdouble(pList2,x2) ) ; } else if ( ring_list_ispointer(pList2,x2) ) { fprintf( fObj , "[P]%p\n" , (void *) ring_list_getpointer(pList2,x2) ) ; } else if ( ring_list_islist(pList2,x2) ) { fprintf( fObj , "[L]\n" ) ; ring_objfile_writelist(ring_list_getlist(pList2,x2) ,fObj); } } fprintf( fObj , "[E]\n" ) ; } fprintf( fObj , "}\n" ) ; }
void ring_vm_incjump ( VM *pVM ) { List *pVar ; double nNum1,nNum2 ; if ( ring_vm_findvar(pVM, RING_VM_IR_READC ) == 0 ) { ring_vm_newvar(pVM, RING_VM_IR_READC); } nNum1 = ring_list_getdouble(pVM->aForStep,ring_list_getsize(pVM->aForStep)); /* Change Instruction for Performance */ if ( pVM->nVarScope == RING_VARSCOPE_GLOBAL ) { /* Replace ICO_INCJUMP with IncPJUMP for better performance */ if ( nNum1 == 1.0 ) { RING_VM_IR_OPCODE = ICO_INCPJUMPSTEP1 ; } else { RING_VM_IR_OPCODE = ICO_INCPJUMP ; } ring_item_setpointer_gc(pVM->pRingState,RING_VM_IR_ITEM(1),RING_VM_STACK_READP); } else if ( pVM->nVarScope == RING_VARSCOPE_LOCAL ) { /* Replace ICO_INCJUMP with IncLPJUMP for better performance */ RING_VM_IR_OPCODE = ICO_INCLPJUMP ; ring_item_setpointer_gc(pVM->pRingState,RING_VM_IR_ITEM(3),RING_VM_STACK_READP); ring_item_setint_gc(pVM->pRingState,RING_VM_IR_ITEM(4),ring_list_getint(pVM->aScopeID,ring_list_getsize(pVM->aScopeID))); } pVar = (List *) RING_VM_STACK_READP ; RING_VM_STACK_POP ; /* Check Data */ if ( ring_list_isstring(pVar,RING_VAR_VALUE) ) { nNum2 = ring_vm_stringtonum(pVM,ring_list_getstring(pVar,RING_VAR_VALUE)); ring_list_setdouble_gc(pVM->pRingState,pVar,RING_VAR_VALUE,nNum2); } else if ( ring_list_isnumber(pVar,RING_VAR_VALUE) ) { nNum2 = ring_list_getdouble(pVar,RING_VAR_VALUE) ; } else { ring_vm_error(pVM,RING_VM_ERROR_FORLOOPDATATYPE); return ; } ring_list_setdouble_gc(pVM->pRingState,pVar,RING_VAR_VALUE,nNum2 +nNum1); /* Jump */ pVM->nPC = RING_VM_IR_READIVALUE(2) ; }
void ring_vm_refmeta_addattribute ( void *pPointer ) { List *pList, *pList2 ; char *cStr ; int x ; if ( RING_API_PARACOUNT != 2 ) { RING_API_ERROR(RING_API_BADPARACOUNT); return ; } if ( RING_API_ISLIST(1) ) { pList = RING_API_GETLIST(1) ; if ( ring_vm_oop_isobject(pList) ) { pList = ring_list_getlist(pList,RING_OBJECT_OBJECTDATA); if ( RING_API_ISSTRING(2) ) { cStr = RING_API_GETSTRING(2) ; ring_string_lower(cStr); /* Create Variable List */ ring_vm_newvar2(cStr,pList); } else if ( RING_API_ISLIST(2) ) { pList2 = RING_API_GETLIST(2) ; for ( x = 1 ; x <= ring_list_getsize(pList2) ; x++ ) { if ( ring_list_isstring(pList2,x) ) { cStr = ring_list_getstring(pList2,x); ring_string_lower(cStr); /* Create Variable List */ ring_vm_newvar2(cStr,pList); } } } else { RING_API_ERROR(RING_API_BADPARATYPE); } } else { RING_API_ERROR(RING_API_BADPARATYPE); } } else { RING_API_ERROR(RING_API_BADPARATYPE); } }
void ring_vm_restorestack ( VM *pVM,List *pList ) { int x ; List *pList2 ; pVM->nSP = 0 ; if ( ring_list_getsize(pList) == 0 ) { return ; } for ( x = ring_list_getsize(pList) ; x >= 1 ; x-- ) { if ( ring_list_isstring(pList,x) ) { RING_VM_STACK_PUSHCVALUE(ring_list_getstring(pList,x)); } else if ( ring_list_isnumber(pList,x) ) { RING_VM_STACK_PUSHNVALUE(ring_list_getdouble(pList,x)); } else if ( ring_list_islist(pList,x) ) { pList2 = ring_list_getlist(pList,x); RING_VM_STACK_PUSHPVALUE(ring_list_getpointer(pList2,1)); RING_VM_STACK_OBJTYPE = ring_list_getint(pList2,2) ; } } }
void ring_vm_jumpvarlplenum ( VM *pVM ) { List *pVar ; double nNum1,nNum2 ; /* Check Scope Life Time */ if ( RING_VM_IR_READIVALUE(5) != pVM->nActiveScopeID ) { RING_VM_IR_OPCODE = ICO_JUMPVARLENUM ; #if RING_SHOWICFINAL RING_VM_IR_PARACOUNT = RING_VM_IR_PARACOUNT - 2 ; ring_list_deleteitem_gc(pVM->pRingState,RING_VM_IR_LIST,ring_list_getsize(RING_VM_IR_LIST)); ring_list_deleteitem_gc(pVM->pRingState,RING_VM_IR_LIST,ring_list_getsize(RING_VM_IR_LIST)); #endif pVM->nPC-- ; return ; } pVar = (List *) RING_VM_IR_READPVALUE(4) ; nNum1 = ring_list_getdouble(pVM->aForStep,ring_list_getsize(pVM->aForStep)); /* Check Data */ if ( ring_list_isstring(pVar,RING_VAR_VALUE) ) { nNum2 = ring_vm_stringtonum(pVM,ring_list_getstring(pVar,RING_VAR_VALUE)); } else if ( ring_list_isnumber(pVar,RING_VAR_VALUE) ) { nNum2 = ring_list_getdouble(pVar,RING_VAR_VALUE) ; } else { ring_vm_error(pVM,RING_VM_ERROR_FORLOOPDATATYPE); return ; } if ( nNum1 < 0 ) { if ( ! (nNum2 >= RING_VM_IR_READDVALUE(2)) ) { /* Jump */ pVM->nPC = RING_VM_IR_READIVALUE(3) ; } } else { if ( ! (nNum2 <= RING_VM_IR_READDVALUE(2)) ) { /* Jump */ pVM->nPC = RING_VM_IR_READIVALUE(3) ; } } }
void ring_vm_refmeta_getattribute ( void *pPointer ) { List *pList ; char *cStr ; int x ; if ( RING_API_PARACOUNT != 2 ) { RING_API_ERROR(RING_API_BADPARACOUNT); return ; } if ( RING_API_ISLIST(1) && RING_API_ISSTRING(2) ) { pList = RING_API_GETLIST(1) ; if ( ring_vm_oop_isobject(pList) ) { pList = ring_list_getlist(pList,RING_OBJECT_OBJECTDATA); cStr = RING_API_GETSTRING(2) ; ring_string_lower(cStr); for ( x = 1 ; x <= ring_list_getsize(pList) ; x++ ) { if ( strcmp(ring_list_getstring(ring_list_getlist(pList,x),RING_VAR_NAME),cStr) == 0 ) { pList = ring_list_getlist(pList,x) ; if ( ring_list_isnumber(pList,RING_VAR_VALUE) ) { RING_API_RETNUMBER(ring_list_getdouble(pList,RING_VAR_VALUE)); } else if ( ring_list_isstring(pList,RING_VAR_VALUE) ) { RING_API_RETSTRING2(ring_list_getstring(pList,RING_VAR_VALUE),ring_list_getstringsize(pList,RING_VAR_VALUE)); } else if ( ring_list_islist(pList,RING_VAR_VALUE) ) { RING_API_RETLIST(ring_list_getlist(pList,RING_VAR_VALUE)); } return ; } } RING_API_ERROR("Error : Property is not found!"); } else { RING_API_ERROR(RING_API_BADPARATYPE); } } else { RING_API_ERROR(RING_API_BADPARATYPE); } }
void ring_parser_icg_duplicate ( Parser *pParser,int nStart,int nEnd ) { List *pList,*pList2 ; int x ; #if RING_SHOWIC int y,nCount2 ; #endif assert(pParser != NULL); if ( (nStart <= nEnd) && ( nEnd <= ring_parser_icg_instructionscount(pParser) ) ) { for ( x = nStart ; x <= nEnd ; x++ ) { pList = ring_list_newlist(pParser->GenCode); pList2 = ring_list_getlist(pParser->GenCode,x); ring_list_copy(pList,pList2); #if RING_SHOWIC nCount2 = ring_list_getsize(pList); printf( "\n %6d [ %s ] ", ring_list_getsize(pParser->GenCode) , RING_IC_OP[ring_list_getint(pList,1)] ) ; if ( nCount2 > 1 ) { for ( y = 2 ; y <= nCount2 ; y++ ) { if ( ring_list_isstring(pList,y) ) { printf( " Operand : %s ",ring_list_getstring(pList,y) ) ; } else if ( ring_list_isnumber(pList,y) ) { if ( ring_list_isdouble(pList,y) ) { printf( " Operand : %f ",ring_list_getdouble(pList,y) ) ; } else { printf( " Operand : %5d ",ring_list_getint(pList,y) ) ; } } else { printf( " Operand : %5p ",ring_list_getpointer(pList,y) ) ; } } } #endif } } }