Exemple #1
0
void ring_vm_gc_checkupdatereference ( VM *pVM,List *pList )
{
	Item *pItem  ;
	/* Reference Counting to Destination before copy from Source */
	if ( ring_list_getint(pList,RING_VAR_TYPE) == RING_VM_POINTER ) {
		if ( ring_list_getint(pList,RING_VAR_PVALUETYPE) == RING_OBJTYPE_LISTITEM ) {
			pItem = (Item *) ring_list_getpointer(pList,RING_VAR_VALUE) ;
			ring_item_delete_gc(pVM->pRingState,pItem);
		}
	}
}
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_refmeta_isprivateattribute ( void *pPointer )
{
	List *pList  ;
	int x  ;
	char *cStr  ;
	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) ) {
			cStr = RING_API_GETSTRING(2) ;
			ring_string_lower(cStr);
			pList = ring_list_getlist(pList,RING_OBJECT_OBJECTDATA);
			for ( x = 3 ; x <= ring_list_getsize(pList) ; x++ ) {
				if ( strcmp(cStr,ring_list_getstring(ring_list_getlist(pList,x),RING_VAR_NAME))==0 ) {
					if ( ring_list_getint(ring_list_getlist(pList,x),RING_VAR_PRIVATEFLAG) == 1 ) {
						RING_API_RETNUMBER(1);
					}
					else {
						RING_API_RETNUMBER(0);
					}
					return ;
				}
			}
			RING_API_RETNUMBER(0);
		} else {
			RING_API_ERROR(RING_API_BADPARATYPE);
		}
	} else {
		RING_API_ERROR(RING_API_BADPARATYPE);
	}
}
Exemple #4
0
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("");
}
Exemple #5
0
void ring_parser_loadtoken ( Parser *pParser )
{
	List *pList  ;
	assert(pParser != NULL);
	pList = ring_list_getlist(pParser->Tokens,pParser->ActiveToken);
	pParser->TokenType = ring_list_getint(pList,1) ;
	pParser->TokenText = ring_list_getstring(pList,2) ;
}
Exemple #6
0
void ring_vm_catch ( VM *pVM,const char *cError )
{
	List *pList  ;
	pList = ring_list_getlist(pVM->pTry,ring_list_getsize(pVM->pTry));
	pVM->nPC = ring_list_getint(pList,1) ;
	ring_vm_restorestate(pVM,pList,2,RING_STATE_TRYCATCH);
	/* Define variable cCatchError to contain the error message */
	ring_list_setstring(ring_list_getlist(ring_list_getlist(pVM->pMem,1),6),3,cError);
	/* Tell C-API caller (CALL command) that catch happens! */
	pVM->nActiveCatch = 1 ;
	/* Catch Statements must be executed without try effects */
	ring_vm_done(pVM);
}
Exemple #7
0
void ring_vm_gc_checkreferences ( VM *pVM )
{
	int x  ;
	List *pList, *pList2  ;
	Item *pItem  ;
	/* Check References (Called when we delete a scope) */
	pList = ring_list_getlist(pVM->pMem,ring_list_getsize(pVM->pMem));
	for ( x = ring_list_getsize(pList) ; x >= 1 ; x-- ) {
		pList2 = ring_list_getlist(pList,x);
		if ( ring_list_getsize(pList2) == RING_VAR_LISTSIZE ) {
			if ( ring_list_getint(pList2,RING_VAR_TYPE) == RING_VM_POINTER ) {
				if ( ring_list_getint(pList2,RING_VAR_PVALUETYPE) == RING_OBJTYPE_LISTITEM ) {
					pItem = (Item *) ring_list_getpointer(pList2,RING_VAR_VALUE) ;
					#if GCLog
					printf( "GC CheckReferences - Free Memory %p \n",pItem ) ;
					#endif
					ring_item_delete_gc(pVM->pRingState,pItem);
				}
			}
		}
	}
}
Exemple #8
0
void ring_vm_deletescope ( VM *pVM )
{
	if ( ring_list_getsize(pVM->pMem) < 2 ) {
		puts("Internal Error - Deleting scope while no scope! ");
		exit(0);
	}
	/* Check References */
	ring_vm_gc_checkreferences(pVM);
	ring_list_deleteitem(pVM->pMem,ring_list_getsize(pVM->pMem));
	pVM->pActiveMem = ring_list_getlist(pVM->pMem,ring_list_getsize(pVM->pMem));
	/* Delete Local Scope information */
	ring_list_deleteitem(pVM->aScopeID,ring_list_getsize(pVM->aScopeID));
	pVM->nActiveScopeID = ring_list_getint(pVM->aScopeID,ring_list_getsize(pVM->aScopeID)) ;
}
Exemple #9
0
void ring_vm_savestate2 ( VM *pVM,List *pList )
{
	List *pThis  ;
	/* Save State */
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->pExitMark));
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->pLoopMark));
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->pTry));
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->aBraceObjects));
	ring_list_addpointer_gc(pVM->pRingState,pList,pVM->pBraceObject);
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->pObjState));
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nInsideBraceFlag);
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->aForStep));
	ring_list_addpointer_gc(pVM->pRingState,pList,pVM->pActiveMem);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nFuncExecute2);
	pVM->nInsideBraceFlag = 0 ;
	/* Save BlockFlag */
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nBlockFlag);
	ring_list_addpointer_gc(pVM->pRingState,pList,pVM->aPCBlockFlag);
	pVM->nBlockFlag = 0 ;
	pVM->aPCBlockFlag = ring_list_new_gc(pVM->pRingState,0);
	/* Save nPrivateFlag, set it to 0 (public not private) */
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nPrivateFlag);
	pVM->nPrivateFlag = 0 ;
	/* Save nCallClassInit */
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nCallClassInit);
	pVM->nCallClassInit = 0 ;
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nFuncExecute);
	ring_list_addpointer_gc(pVM->pRingState,pList,pVM->pAssignment);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nInClassRegion);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nActiveScopeID);
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->aScopeNewObj));
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->aScopeID));
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nLineNumber);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nBeforeEqual);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nNOAssignment);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nGetSetProperty);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nGetSetObjType);
	ring_list_addpointer_gc(pVM->pRingState,pList,pVM->pGetSetObject);
	ring_list_addpointer_gc(pVM->pRingState,pList,pVM->aLoadAddressScope);
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->pLoadAddressScope));
	/* Save This variable */
	pThis = ring_list_getlist(ring_vm_getglobalscope(pVM),RING_VM_STATICVAR_THIS) ;
	ring_list_addpointer_gc(pVM->pRingState,pList,ring_list_getpointer(pThis,RING_VAR_VALUE));
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getint(pThis,RING_VAR_PVALUETYPE));
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nCurrentGlobalScope);
	pVM->nInClassRegion = 0 ;
	pVM->pAssignment = NULL ;
	pVM->nNOAssignment = 0 ;
}
Exemple #10
0
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
		}
	}
}
Exemple #11
0
void ring_vm_savestate ( VM *pVM,List *pList )
{
	List *pThis  ;
	pList = ring_list_newlist_gc(pVM->pRingState,pList);
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->pMem));
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->pFuncCallList));
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nFuncExecute);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nSP);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nFuncSP);
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->pObjState));
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->aBraceObjects));
	ring_list_addpointer_gc(pVM->pRingState,pList,pVM->pBraceObject);
	ring_list_addpointer_gc(pVM->pRingState,pList,pVM->cFileName);
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->aPCBlockFlag));
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nBlockFlag);
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->aScopeNewObj));
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->aActivePackage));
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->aScopeID));
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nActiveScopeID);
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->pExitMark));
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->pLoopMark));
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->pTry));
	ring_list_addpointer_gc(pVM->pRingState,pList,pVM->pActiveMem);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nListStart);
	ring_list_addpointer_gc(pVM->pRingState,pList,pVM->pNestedLists);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nInsideBraceFlag);
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->aForStep));
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->aBeforeObjState));
	ring_list_addpointer_gc(pVM->pRingState,pList,pVM->aPCBlockFlag);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nLineNumber);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nInClassRegion);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nPrivateFlag);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nGetSetProperty);
	ring_list_addpointer_gc(pVM->pRingState,pList,pVM->pGetSetObject);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nGetSetObjType);
	ring_list_addpointer_gc(pVM->pRingState,pList,pVM->pAssignment);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nBeforeEqual);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nNOAssignment);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nFuncExecute2);
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nCallClassInit);
	ring_list_addpointer_gc(pVM->pRingState,pList,pVM->aLoadAddressScope);
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getsize(pVM->pLoadAddressScope));
	/* Save This variable */
	pThis = ring_list_getlist(ring_vm_getglobalscope(pVM),RING_VM_STATICVAR_THIS) ;
	ring_list_addpointer_gc(pVM->pRingState,pList,ring_list_getpointer(pThis,RING_VAR_VALUE));
	ring_list_addint_gc(pVM->pRingState,pList,ring_list_getint(pThis,RING_VAR_PVALUETYPE));
	ring_list_addint_gc(pVM->pRingState,pList,pVM->nCurrentGlobalScope);
}
Exemple #12
0
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) ;
}
Exemple #13
0
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"  ) ;
}
Exemple #14
0
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) ;
		}
	}
}
Exemple #15
0
void ring_objfile_updateclassespointers ( RingState *pRingState )
{
	int x,x2,x3,x4,lFound  ;
	List *pList, *pList2, *pList3  ;
	const char *cString  ;
	char cPackageName[400]  ;
	char cClassName[400]  ;
	/* Update Class Pointer in Code */
	lFound = 0 ;
	for ( x = 1 ; x <= ring_list_getsize(pRingState->pRingGenCode) ; x++ ) {
		pList = ring_list_getlist(pRingState->pRingGenCode,x);
		if ( ring_list_getint(pList,1) == ICO_NEWCLASS ) {
			cString = ring_list_getstring(pList,2);
			for ( x2 = 1 ; x2 <= ring_list_getsize(pRingState->pRingClassesMap) ; x2++ ) {
				pList2 = ring_list_getlist(pRingState->pRingClassesMap,x2);
				if ( strcmp(cString,ring_list_getstring(pList2,1)) == 0 ) {
					lFound = 0 ;
					ring_list_setpointer(pList,3,pList2);
					#ifdef DEBUG_OBJFILE
					puts("Pointer Updated ");
					#endif
					break ;
				}
			}
			/* If we can't find the list (the class is inside a package) */
			if ( lFound == 0 ) {
				ring_list_setpointer(pList,3,NULL);
			}
		}
	}
	/*
	**  Update Class Pointers in Classes Map when the class belong to a Package 
	**  This updates works when the class name is : packagename.classname 
	*/
	for ( x = 1 ; x <= ring_list_getsize(pRingState->pRingClassesMap) ; x++ ) {
		pList = ring_list_getlist(pRingState->pRingClassesMap,x);
		cString = ring_list_getstring(pList,1);
		if ( ring_list_getstringsize(pList,1)  > 400 ) {
			/* Avoid large names - we have limits (400 letters per package name - 400 letters for class name) */
			continue ;
		}
		for ( x2 = ring_list_getstringsize(pList,1) - 1 ; x2 >= 0 ; x2-- ) {
			if ( cString[x2] == '.' ) {
				/*
				**  Now we have a class name stored as packagename.classname 
				**  Get Package Name 
				*/
				for ( x3 = 0 ; x3 < x2 ; x3++ ) {
					cPackageName[x3] = cString[x3] ;
				}
				cPackageName[x2] = '\0' ;
				#ifdef DEBUG_OBJFILE
				printf( "Package Name %s \n  ",cPackageName ) ;
				#endif
				/* Get Class Name */
				for ( x3 = x2+1 ; x3 <= ring_list_getstringsize(pList,1) - 1 ; x3++ ) {
					cClassName[x3-x2-1] = cString[x3] ;
				}
				cClassName[ring_list_getstringsize(pList,1) - 1 - x2] = '\0' ;
				#ifdef DEBUG_OBJFILE
				printf( "Class Name %s \n  ",cClassName ) ;
				#endif
				/* Get The Package List */
				for ( x3 = 1 ; x3 <= ring_list_getsize(pRingState->pRingPackagesMap) ; x3++ ) {
					pList2 = ring_list_getlist(pRingState->pRingPackagesMap,x3);
					if ( strcmp(ring_list_getstring(pList2,1),cPackageName) == 0 ) {
						/* Get The Class List */
						pList2 = ring_list_getlist(pList2,2);
						for ( x4 = 1 ; x4 <= ring_list_getsize(pList2) ; x4++ ) {
							pList3 = ring_list_getlist(pList2,x4);
							if ( strcmp(ring_list_getstring(pList3,1),cClassName) == 0 ) {
								/* Now We have the Class - Update Pointer */
								ring_list_setpointer(pList,2,(void *) pList3);
								break ;
							}
						}
						break ;
					}
				}
			}
		}
	}
}
Exemple #16
0
void ring_vm_restorestate ( VM *pVM,List *pList,int nPos,int nFlag )
{
	List *pThis  ;
	pList = ring_list_getlist(pList,nPos);
	/* Set Scope */
	pVM->pActiveMem = (List *) ring_list_getpointer(pList,19) ;
	/*
	**  Delete Scopes using the correct function 
	**  We need to delete each scope using ring_vm_deletescope() - so don't use ring_vm_backstate 
	**  We also avoid doing this in the Class Region (After class name) 
	**  Because in the class region we don't use pVM->pMEM 
	*/
	if ( ! pVM->nInClassRegion ) {
		while ( ring_list_getlist(pVM->pMem,ring_list_getsize(pVM->pMem)) != pVM->pActiveMem ) {
			ring_vm_deletescope(pVM);
		}
	}
	/* We also return to the function call list */
	ring_vm_backstate(pVM,ring_list_getint(pList,2),pVM->pFuncCallList);
	/* Stack & Executing Functions */
	pVM->nFuncExecute = ring_list_getint(pList,3) ;
	pVM->nSP = ring_list_getint(pList,4) ;
	pVM->nFuncSP = ring_list_getint(pList,5) ;
	/* We also return to the Active Object */
	ring_vm_backstate(pVM,ring_list_getint(pList,6),pVM->pObjState);
	ring_vm_backstate(pVM,ring_list_getint(pList,7),pVM->aBraceObjects);
	pVM->pBraceObject = (List *) ring_list_getpointer(pList,8) ;
	/* FileName & Packages */
	pVM->cFileName = (char *) ring_list_getpointer(pList,9) ;
	/* aPCBlockFlag, aScopeNewObj , aActivePackage & aScopeID */
	if ( ((List *) ring_list_getpointer(pList,25)) != pVM->aPCBlockFlag ) {
		pVM->aPCBlockFlag = ring_list_delete_gc(pVM->pRingState,pVM->aPCBlockFlag);
		pVM->aPCBlockFlag = (List *) ring_list_getpointer(pList,25) ;
	}
	ring_vm_backstate(pVM,ring_list_getint(pList,10),pVM->aPCBlockFlag);
	pVM->nBlockFlag = ring_list_getint(pList,11) ;
	ring_vm_backstate(pVM,ring_list_getint(pList,12),pVM->aScopeNewObj);
	ring_vm_backstate(pVM,ring_list_getint(pList,13),pVM->aActivePackage);
	ring_vm_backstate(pVM,ring_list_getint(pList,14),pVM->aScopeID);
	pVM->nActiveScopeID = ring_list_getint(pList,15) ;
	/* Loop/Exit Mark */
	if ( nFlag != RING_STATE_EXIT ) {
		ring_vm_backstate(pVM,ring_list_getint(pList,16),pVM->pExitMark);
		ring_vm_backstate(pVM,ring_list_getint(pList,17),pVM->pLoopMark);
		/* For Step */
		ring_vm_backstate(pVM,ring_list_getint(pList,23),pVM->aForStep);
	}
	/* Try/Catch/Done */
	if ( nFlag != RING_STATE_TRYCATCH ) {
		ring_vm_backstate(pVM,ring_list_getint(pList,18),pVM->pTry);
	}
	/* List Status */
	pVM->nListStart = ring_list_getint(pList,20) ;
	if ( ring_list_getpointer(pList,21) != pVM->pNestedLists ) {
		pVM->pNestedLists = ring_list_delete_gc(pVM->pRingState,pVM->pNestedLists);
		pVM->pNestedLists = (List *) ring_list_getpointer(pList,21) ;
	}
	pVM->nInsideBraceFlag = ring_list_getint(pList,22) ;
	ring_vm_backstate(pVM,ring_list_getint(pList,24),pVM->aBeforeObjState);
	pVM->nLineNumber = ring_list_getint(pList,26) ;
	pVM->nInClassRegion = ring_list_getint(pList,27) ;
	pVM->nPrivateFlag = ring_list_getint(pList,28) ;
	pVM->nGetSetProperty = ring_list_getint(pList,29) ;
	pVM->pGetSetObject = (void *) ring_list_getpointer(pList,30) ;
	pVM->nGetSetObjType = ring_list_getint(pList,31) ;
	pVM->pAssignment = (void *) ring_list_getpointer(pList,32) ;
	pVM->nBeforeEqual = ring_list_getint(pList,33) ;
	pVM->nNOAssignment = ring_list_getint(pList,34) ;
	pVM->nFuncExecute2 = ring_list_getint(pList,35) ;
	pVM->nCallClassInit = ring_list_getint(pList,36) ;
	pVM->aLoadAddressScope = (List *) ring_list_getpointer(pList,37) ;
	ring_vm_backstate(pVM,ring_list_getint(pList,38),pVM->pLoadAddressScope);
	/* We restore the global scope befor the This variable, because This use global scope */
	pVM->nCurrentGlobalScope = ring_list_getint(pList,41) ;
	/* Restore This variable */
	pThis = ring_list_getlist(ring_vm_getglobalscope(pVM),RING_VM_STATICVAR_THIS) ;
	ring_list_setpointer_gc(pVM->pRingState,pThis,RING_VAR_VALUE,ring_list_getpointer(pList,39));
	ring_list_setint_gc(pVM->pRingState,pThis,RING_VAR_PVALUETYPE,ring_list_getint(pList,40));
}
Exemple #17
0
void ring_vm_restorestate2 ( VM *pVM,List *pList,int x )
{
	List *pThis  ;
	/* Restore State */
	ring_vm_backstate(pVM,ring_list_getint(pList,x),pVM->pExitMark);
	ring_vm_backstate(pVM,ring_list_getint(pList,x+1),pVM->pLoopMark);
	ring_vm_backstate(pVM,ring_list_getint(pList,x+2),pVM->pTry);
	ring_vm_backstate(pVM,ring_list_getint(pList,x+3),pVM->aBraceObjects);
	pVM->pBraceObject = (List *) ring_list_getpointer(pList,x+4) ;
	ring_vm_backstate(pVM,ring_list_getint(pList,x+5),pVM->pObjState);
	pVM->nInsideBraceFlag = ring_list_getint(pList,x+6) ;
	ring_vm_backstate(pVM,ring_list_getint(pList,x+7),pVM->aForStep);
	pVM->pActiveMem = (List *) ring_list_getpointer(pList,x+8) ;
	pVM->nFuncExecute2 = ring_list_getint(pList,x+9) ;
	/* Restore BlockFLag */
	pVM->aPCBlockFlag = ring_list_delete_gc(pVM->pRingState,pVM->aPCBlockFlag);
	pVM->nBlockFlag = ring_list_getint(pList,x+10) ;
	pVM->aPCBlockFlag = (List *) ring_list_getpointer(pList,x+11) ;
	/* Restore nPrivateFlag */
	pVM->nPrivateFlag = ring_list_getint(pList,x+12) ;
	/* Restore nCallClassInit */
	pVM->nCallClassInit = ring_list_getint(pList,x+13) ;
	pVM->nFuncExecute = ring_list_getint(pList,x+14) ;
	pVM->pAssignment = (void *) ring_list_getpointer(pList,x+15) ;
	pVM->nInClassRegion = ring_list_getint(pList,x+16) ;
	pVM->nActiveScopeID = ring_list_getint(pList,x+17) ;
	ring_vm_backstate(pVM,ring_list_getint(pList,x+18),pVM->aScopeNewObj);
	ring_vm_backstate(pVM,ring_list_getint(pList,x+19),pVM->aScopeID);
	pVM->nLineNumber = ring_list_getint(pList,x+20) ;
	pVM->nBeforeEqual = ring_list_getint(pList,x+21) ;
	pVM->nNOAssignment = ring_list_getint(pList,x+22) ;
	pVM->nGetSetProperty = ring_list_getint(pList,x+23) ;
	pVM->nGetSetObjType = ring_list_getint(pList,x+24) ;
	pVM->pGetSetObject = (void *) ring_list_getpointer(pList,x+25) ;
	pVM->aLoadAddressScope = (List *) ring_list_getpointer(pList,x+26) ;
	ring_vm_backstate(pVM,ring_list_getint(pList,x+27),pVM->pLoadAddressScope);
	/* Restore global scope, Must be before this because this depend on it */
	pVM->nCurrentGlobalScope = ring_list_getint(pList,x+30) ;
	/* Restore This variable */
	pThis = ring_list_getlist(ring_vm_getglobalscope(pVM),RING_VM_STATICVAR_THIS) ;
	ring_list_setpointer_gc(pVM->pRingState,pThis,RING_VAR_VALUE,ring_list_getpointer(pList,x+28));
	ring_list_setint_gc(pVM->pRingState,pThis,RING_VAR_PVALUETYPE,ring_list_getint(pList,x+29));
}
Exemple #18
0
int ring_vm_findvar2 ( VM *pVM,int x,List *pList2,const char *cStr )
{
	int nPC,nType  ;
	Item *pItem  ;
	List *pList  ;
	/*
	**  Now We have the variable List 
	**  The Scope of the search result 
	*/
	if ( ( x == 1 ) && (pVM->pActiveMem == ring_list_getlist(pVM->pMem,RING_MEMORY_GLOBALSCOPE)) ) {
		x = RING_VARSCOPE_GLOBAL ;
	}
	else if ( (x == 1) && (pVM->pActiveMem != ring_list_getlist(pVM->pMem,ring_list_getsize(pVM->pMem))) ) {
		x = RING_VARSCOPE_NEWOBJSTATE ;
	}
	pVM->nVarScope = x ;
	pVM->nSP++ ;
	if ( ring_list_getint(pList2,RING_VAR_TYPE) == RING_VM_POINTER ) {
		if ( pVM->nFirstAddress  == 1 ) {
			RING_VM_STACK_SETPVALUE(pList2);
			RING_VM_STACK_OBJTYPE = RING_OBJTYPE_VARIABLE ;
			return 1 ;
		}
		RING_VM_STACK_SETPVALUE(ring_list_getpointer(pList2,RING_VAR_VALUE ));
		RING_VM_STACK_OBJTYPE = ring_list_getint(pList2,RING_VAR_PVALUETYPE) ;
		/*
		**  Here we don't know the correct scope of the result 
		**  becauase a global variable may be a reference to local variable 
		**  And this case happens with setter/getter of the attributes using eval() 
		*/
		pVM->nVarScope = RING_VARSCOPE_NOTHING ;
	} else {
		/* Check Private Attributes */
		if ( ring_list_getint(pList2,RING_VAR_PRIVATEFLAG) == 1 ) {
			if ( pVM->nVarScope != RING_VARSCOPE_OBJSTATE ) {
				if ( ring_vm_oop_callmethodinsideclass(pVM) == 0 ) {
					ring_vm_error2(pVM,RING_VM_ERROR_USINGPRIVATEATTRIBUTE,cStr);
					return 0 ;
				}
			}
		}
		RING_VM_STACK_SETPVALUE(pList2);
		RING_VM_STACK_OBJTYPE = RING_OBJTYPE_VARIABLE ;
		/* Check Setter/Getter for Public Attributes */
		if ( pVM->nGetSetProperty == 1 ) {
			ring_vm_oop_setget(pVM,pList2);
		}
		else if ( ( x == RING_VARSCOPE_OBJSTATE ) && ( ring_vm_oop_callmethodinsideclass(pVM) == 0 ) ) {
			/* Accessing Object Attribute Using { } */
			if ( ring_list_getsize(pVM->aBraceObjects) > 0 ) {
				pList = ring_list_getlist(pVM->aBraceObjects,ring_list_getsize(pVM->aBraceObjects));
				/* Get Object List */
				pList = (List *) ring_list_getpointer(pList,RING_ABRACEOBJECTS_BRACEOBJECT);
				nType = ring_vm_oop_objtypefromobjlist(pList);
				/* Set Object Pointer & Type */
				if ( nType == RING_OBJTYPE_VARIABLE ) {
					pList = ring_vm_oop_objvarfromobjlist(pList);
					pVM->pGetSetObject = pList ;
				}
				else if ( nType == RING_OBJTYPE_LISTITEM ) {
					pItem = ring_vm_oop_objitemfromobjlist(pList);
					pVM->pGetSetObject = pItem ;
				}
				pVM->nGetSetObjType = nType ;
				/* Change Assignment Instruction to SetProperty */
				if ( RING_VM_IR_PARACOUNT >= 4 ) {
					if ( RING_VM_IR_READIVALUE(3) != 0 ) {
						nPC = pVM->nPC ;
						pVM->nPC = RING_VM_IR_READIVALUE(3) ;
						RING_VM_IR_LOAD ;
						RING_VM_IR_OPCODE = ICO_SETPROPERTY ;
						pVM->nPC = nPC ;
						RING_VM_IR_UNLOAD ;
						/* Avoid AssignmentPointer , we don't have assignment */
						pVM->nNOAssignment = 1 ;
					}
				}
				ring_vm_oop_setget(pVM,pList2);
			}
		}
	}
	return 1 ;
}