void ring_vm_mod ( VM *pVM ) { double nNum1=0,nNum2=0 ; String *cStr1 ; char cStr2[100] ; char cStr3[100] ; if ( RING_VM_STACK_ISNUMBER ) { nNum1 = RING_VM_STACK_READN ; RING_VM_STACK_POP ; if ( nNum1 == 0 ) { ring_vm_error(pVM,RING_VM_ERROR_DIVIDEBYZERO); return ; } if ( RING_VM_STACK_ISNUMBER ) { nNum2 = RING_VM_STACK_READN ; } else if ( RING_VM_STACK_ISSTRING ) { nNum2 = ring_vm_stringtonum(pVM,RING_VM_STACK_READC); } else if ( RING_VM_STACK_ISPOINTER ) { ring_vm_expr_npoo(pVM,"%",nNum1); return ; } } else if ( RING_VM_STACK_ISSTRING ) { cStr1 = ring_string_new2(RING_VM_STACK_READC,RING_VM_STACK_STRINGSIZE) ; nNum1 = ring_vm_stringtonum(pVM,RING_VM_STACK_READC); RING_VM_STACK_POP ; if ( RING_VM_STACK_ISSTRING ) { nNum2 = ring_vm_stringtonum(pVM,RING_VM_STACK_READC); } else if ( RING_VM_STACK_ISNUMBER ) { nNum2 = RING_VM_STACK_READN ; } else if ( RING_VM_STACK_ISPOINTER ) { ring_vm_expr_spoo(pVM,"%",ring_string_get(cStr1),ring_string_size(cStr1)); ring_string_delete(cStr1); return ; } ring_string_delete(cStr1); } else if ( RING_VM_STACK_ISPOINTER ) { ring_vm_expr_ppoo(pVM,"%"); return ; } /* Check Overflow */ if ( ( strlen(ring_vm_numtostring(pVM,nNum1,cStr2)) >= 15 ) || (strlen(ring_vm_numtostring(pVM,nNum2,cStr3)) >= 15 ) ) { ring_vm_error(pVM,RING_VM_ERROR_NUMERICOVERFLOW); return ; } RING_VM_STACK_SETNVALUE(fmod(nNum2 , nNum1)); }
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_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_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_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_sum ( VM *pVM ) { String *cStr1,*cStr2 ; double nNum1,nNum2 ; char cStr3[100] ; /* ** Description ** We can sum string + number ---> string , number + string ---> number ** string/number + nl ---> string ** list + string/number ---> add item to the list ** list1 + list2 ---> add list2 items to list 1 */ if ( RING_VM_STACK_ISSTRING ) { cStr1 = ring_string_new2(RING_VM_STACK_READC,RING_VM_STACK_STRINGSIZE) ; RING_VM_STACK_POP ; if ( RING_VM_STACK_ISSTRING ) { cStr2 = ring_string_new2(RING_VM_STACK_READC,RING_VM_STACK_STRINGSIZE) ; ring_string_add2(cStr2,ring_string_get(cStr1),ring_string_size(cStr1)); RING_VM_STACK_SETCVALUE2(ring_string_get(cStr2),ring_string_size(cStr2)); ring_string_delete(cStr2); } else if ( RING_VM_STACK_ISNUMBER ) { nNum2 = RING_VM_STACK_READN ; if ( strcmp(ring_string_get(cStr1),"\n") == 0 ) { cStr2 = ring_string_new("") ; ring_string_add(cStr2,ring_vm_numtostring(pVM,nNum2,cStr3)); ring_string_add(cStr2,ring_string_get(cStr1)); RING_VM_STACK_SETCVALUE(ring_string_get(cStr2)); ring_string_delete(cStr2); } else { RING_VM_STACK_SETNVALUE(nNum2 + ring_vm_stringtonum(pVM,ring_string_get(cStr1))); } } else if ( RING_VM_STACK_ISPOINTER ) { ring_vm_expr_spoo(pVM,"+",ring_string_get(cStr1),ring_string_size(cStr1)); ring_string_delete(cStr1); return ; } ring_string_delete(cStr1); } else if ( RING_VM_STACK_ISNUMBER ) { nNum1 = RING_VM_STACK_READN ; RING_VM_STACK_POP ; if ( RING_VM_STACK_ISNUMBER ) { nNum2 = RING_VM_STACK_READN ; RING_VM_STACK_SETNVALUE(nNum1+nNum2); } else if ( RING_VM_STACK_ISSTRING ) { cStr2 = ring_string_new(RING_VM_STACK_READC) ; ring_vm_numtostring(pVM,nNum1,cStr3); ring_string_add(cStr2,cStr3); RING_VM_STACK_SETCVALUE(ring_string_get(cStr2)); ring_string_delete(cStr2); } else if ( RING_VM_STACK_ISPOINTER ) { ring_vm_expr_npoo(pVM,"+",nNum1); return ; } } else if ( RING_VM_STACK_ISPOINTER ) { ring_vm_expr_ppoo(pVM,"+"); return ; } else { ring_vm_error(pVM,RING_VM_ERROR_BADVALUES); return ; } }