Ejemplo n.º 1
0
void CMainFrame::OnSelectMenu(UINT nID)
{
	int nMenu=nID-MENU_START_ID;
	if(nMenu<0||nMenu>=aAllMenuItems.GetSize())
	{
		Message(String("ќшибка: идентификатор обработки меню не найден"));
		return;
	}
	
	try
	{

		CMyMenuItem element=aAllMenuItems[nMenu];
		if(element.nType==MENU_FUNCTION)
		{
			if(element.pRun)
			{
				int nRes=element.pRun->FindFunction(element.sFunction,0);
				if(nRes>=0)
					element.pRun->CallFunction(element.sFunction,element.vData);
				else
					OpenFormExt(element.sFunction,CValue());
			}
		}
		else
		if(element.nType==MENU_OBJECT)
			element.vObject.CallFunction(element.sFunction,&element.vData);
	}
	catch(CTranslateError *)
	{
		DoError();
	};
}
Ejemplo n.º 2
0
CString CChangeOrder::GetType(int nType)
{
	CString Ret;
	if(nType==ID_DYNBUTTON)
		Ret = "Кнопка";
	else if(nType==ID_DYNBUTTONGRID)
		Ret = "Grid";
	else if(nType==ID_DYNBUTTONTREE)
		Ret = "Дерево";
	else if(nType==ID_DYNBUTTONEDIT)
		Ret = "Поле ввода";
	else if(nType==ID_DYNBUTTONLABEL)
		Ret = "Текст";
	else if(nType==ID_DYNBUTTONCOMBO)
		Ret = "Поле со списком";
	else if(nType==ID_DYNBUTTONLISTBOX)
		Ret = "Список";
	else if(nType==ID_DYNBUTTONGROUP)
		Ret = "Рамка";
	else if(nType==ID_DYNBUTTONCHECK)
		Ret = "Флажок";
	else if(nType==ID_DYNBUTTONRADIO)
		Ret = "Радиокнопка";
	//else if(nType==ID_DYNBUTTONPROGRESS) // 23.10.2010
	//	Ret = "Прогресс"; // 23.10.2010
	//else if(nType==ID_DYNBUTTONSLIDER) // 23.10.2010
	//	Ret = "Ползунок"; // 23.10.2010
	//else if(nType==ID_DYNBUTTONFORMOBJECT) // 23.10.2010
	//	Ret = "Микроформа"; // 23.10.2010
	else
		Ret = CString(CValue(nType));
	return Ret;
}
Ejemplo n.º 3
0
/* -----------------------------------------------------------------------
 *  関数名  :  CLocalVariable::Erase
 *  機能概要:  指定された変数を消去します
 *
 *  実際に配列から消すわけではなく、空文字列を代入するだけです
 * -----------------------------------------------------------------------
 */
void	CLocalVariable::Erase(const wstring &name)
{
	int	id, dp;
	GetIndex(name, id, dp);
	if (id >= 0)
		SetValue(name, CValue());
}
Ejemplo n.º 4
0
CValue CValueContext::GetAttribute(int nVar)//получение значения атрибута
{
	if(nVar>=0&&pRun)
	{
		int iContLocalCount=aContVarList.GetSizeArray();
		
		if(nVar<LOCAL_ATTRIBUTE)
			return pRun->GetAttribute(nVar);
		else
			if(nVar>LOCAL_ATTRIBUTE)
				return aContValueList.GetAt(nVar-LOCAL_ATTRIBUTE);
			else
				return CValue();

	}
	else
		return CValue();
}
Ejemplo n.º 5
0
CValue	CLocalVariable::GetValue(const wstring &name)
{
	int	dp, id;
	GetIndex(name, id, dp);
	if (id >= 0)
		return stack[dp].substack[id].v;

	return CValue();
}
Ejemplo n.º 6
0
void CMetadata::AddToMeta(CString Str)
{
	CValue *pCurPos=&vMeta;

	int nPoint=Str.ReverseFind('.');
	CString csType;
	if(nPoint>0)
	{
		csType=mUpper(Str.Mid(nPoint));
		Str=Str.Left(nPoint);
	}

	CString csName;
	int nIndex1=0;
	int nIndex2=Str.Find("\\",nIndex1);
	while(nIndex2>0)
	{
		csName=Str.Mid(nIndex1,nIndex2-nIndex1);

		if(pCurPos->GetType()!=TYPE_ARRAY)
			pCurPos->CreateObject("Структура");
		pCurPos=&pCurPos->GetAt(csName);
		

		nIndex1=nIndex2+1;
		nIndex2=Str.Find("\\",nIndex1);
	}
	csName=Str.Mid(nIndex1);
	if(pCurPos->GetType()!=TYPE_ARRAY)
		pCurPos->CreateObject("Структура");

	if(csType!=".ATR")//&&csType!=".INF") 
	{
		if(pCurPos->GetAt(csName).GetType()!=TYPE_ARRAY)
			pCurPos->SetAt(csName,CValue());
	}
	else
	if(csType==".ATR") 
	{
		CMetaObject *pObj=GetMetaObject(Str,csName,1);
		if(pObj)
		{
			CValue Val;
			Val.LoadFromString(pObj->csAttr);
			Val.SetAt(String("#"),1);//признак атрибута
			pCurPos->SetAt(csName,Val);

			Val.SetAt("Идентификатор",String(csName));
			Val.SetAt("Синоним",String(pObj->csAlias));
			Val.SetAt("Комментарий",String(pObj->csComment));
		}
	}
}
Ejemplo n.º 7
0
CValue CValueContext::Method(int iName,CValue **p)
{
	if(iName==EXT_ATTRIBUTE_CALL)
	{
		int n=FindAttribute(p[0]->GetString());
		//if(n<0)
		//	Error(CString("Атрибут ")+p[0]->GetString()+" не найден");
		if(p[1]->nType==0)
		{
			//Message(CValue(n));
			return GetAttribute(n);
		}
		else
			{
				SetAttribute(n,*p[1]);
			}
		return CValue();
	}
	if(iName>=0&&pRun)
		return pRun->CallFunction(iName,p);
	return CValue();
}
Ejemplo n.º 8
0
int  CValueContext::FindAttribute(CString csName)
{
	if(pRun)
	{
		int iName=(int)pRun->pByteCode->VarList[mUpper(csName)]-1;
		//Message(CValue(csName+" "+CValue(iName)));
		if(iName==-1)
		{
			int iSize=aContVarList.GetSizeArray();
			for (int iIndex=1;iIndex<=iSize;iIndex++)
				if(mUpper(aContVarList.GetAt(iIndex).GetString())==csName)
				{ 
					return (int)LOCAL_ATTRIBUTE+iIndex;
				}
			aContVarList.SetAt(iSize+1,CValue(csName));
			aContValueList.SetAt(iSize+1,CValue());
			return (int)LOCAL_ATTRIBUTE+iSize+1;
		}
		return iName;
	}
	else
		return -1;
}
Ejemplo n.º 9
0
SICALLBACK aaOcean_Term( CRef& in_ctxt )
{
    Context ctxt( in_ctxt );

    // get ocean pointer from user-data and do clean up
    CValue userData = ctxt.GetUserData( );
    aaOcean *pOcean = (aaOcean *)(CValue::siPtrType)ctxt.GetUserData();
    if(pOcean)
        delete pOcean;  
    pOcean = 0;
    ctxt.PutUserData( CValue() );
    Application().LogMessage(L"[aaOcean ICE] : Successfully cleaned up memory");

    return CStatus::OK;
}
Ejemplo n.º 10
0
void DecomLU_PV_C(int n,CValue *a, int *ip, int &emptyLineNumber)
//  -----  LU-decomposition of non-sparse matrix.
//    n - dimension of system
//    a - square matrix stored by rows (i.e 1st row, 2nd row and so on)
//    ip - array of row exchanges
//    emptyLineNumber - < 0 for case OK,
//          otherwise - number of "bad" line in the system
// Warnings:
//  1. indices of matrix and arrays are zero-based,
//     i.e. each index varies in range [0...n-1].
//  2. memory for "a" and "ip" must be allocated beyond this module.
{
    CValue zero(0.,0.);
    emptyLineNumber = -1;
    if (n > 0) ip[n-1] = 1;
    if (n > 1)
    {  for (int k = 0; k < n - 1; k++) // k - the column number
       {  int kp1 = k + 1;
          int m = k;
// Find a maximum value in the column
          for (int i = kp1; i < n; i ++)
            if (CMod(a[i*n+k]) > CMod(a[m*n+k])) m = i;
          ip[k] = m;
          CValue t = a[m*n+k];
          if (m != k) a[m*n+k] = a[k*n+k];
          if (t == zero)
          { emptyLineNumber = k;
            return;
          }
//   Put the maximum value in diagonal
          a[k*n+k] = t;
          t = CValue(1.,0.) / t;
          for (int i1 = kp1; i1 < n; i1++)
               a[i1*n+k] *= t;
//   Exchanging rows
          for (int j = kp1; j < n; j++)
          { t = a[m*n+j];
            a[m*n+j] = a[k*n+j];
            a[k*n+j] = t;
            if (t == zero) continue;
            for(int i = kp1; i < n; i++)
                a[i*n+j] -= (a[i*n+k]*t);
          }
        } // end of for (k = ...
    }
    if (a[(n-1)*n+n-1] == zero) emptyLineNumber = (n - 1);
}
Ejemplo n.º 11
0
void CChangeOrder::ReLoadGrid()
{

	CCellID curCell=m_Grid.GetFocusCell();
	m_Grid.SetRowCount(1);
	m_Grid.SetRowCount(aList.GetSize()+1);
	m_Grid.SetItemText(0,0,"Слой");
	m_Grid.SetItemText(0,1,"Тип");
	m_Grid.SetItemText(0,2,"Заголовок");
	m_Grid.SetItemText(0,3,"Идентификатор");
	//m_Grid.SetFixedBkColor(COLOR_MENUTEXT);
	
	for(int i=0;i<aList.GetSize();i++)
	{
		m_Grid.SetItemText(i+1,0,aList[i].csLayer);
		m_Grid.SetItemText(i+1,1,GetType((int)Number(CValue(aList[i].csType)).GetNumber()));
		m_Grid.SetItemText(i+1,2,aList[i].csCapture);
		m_Grid.SetItemText(i+1,3,aList[i].csId);
	}

	m_Grid.SetFocusCell(curCell);
}
Ejemplo n.º 12
0
void CVirtualMachine::setReturnValue(float value) { pushValue(CValue(value)); }
Ejemplo n.º 13
0
#include "CVarManager.h"

#include "ConVar.h"

#include <assert.h>

ConVar sv_cheats("sv_cheats", CValue(false), CVAR_FSERVER, "server value if cheats are enabled");

CVarManager::CVarManager() : IEventListener("cvarmanager")
{

}

CVarManager& CVarManager::Instance()
{
    static CVarManager _CVarManager;
    return _CVarManager;
}

void CVarManager::handleEvent(Event& e)
{
    if (strcmp(e.getID(), "set") == 0) {
        on_setcvar(e);
    }
}

void CVarManager::on_setcvar(Event& pArgs)
{
    std::string strIdentifier = pArgs[0].toChar();//pArgs.strVariable.c_str();
    std::string strValue = pArgs[1].toChar();//.strValue.c_str();
Ejemplo n.º 14
0
CValue *GetVariable( CStr &var, BOOL create, int *position, BOOL local )
{
	int     pos, startPos;
	bool	oldStyle = false, reference = false, isPtr = false;
	CStr entryName;
	CMapStrToValue *map = NULL;
	CValue  *value;
	CValue *dummy;

	pos = 0;
	if ( !local )
	{
		if ( LocalVariables != NULL && LocalVariables->Lookup( L"%AUTOLOCAL%", dummy ) )
			local = TRUE;
	}

	// Skip spaces
	while ( pos < var.GetLength() && GetCharacterType( var[pos] ) == CInterpreter::CHAR_WHITESPACE ) pos++;
	
	if ( pos < var.GetLength() && var[pos] == L'%' )
	{
		oldStyle = true;
		pos++;
		while ( pos < var.GetLength() && GetCharacterType( var[pos] ) == CInterpreter::CHAR_WHITESPACE ) pos++;
	}
	
	if ( create && pos < var.GetLength() && var[pos] == L'[' )
	{
		reference = true;
		pos++;
		while ( pos < var.GetLength() && GetCharacterType( var[pos] ) == CInterpreter::CHAR_WHITESPACE ) pos++;
	}

	startPos = pos;
	// Skip all valid variable name characters
	while (    pos < var.GetLength()
		    && (   GetCharacterType( var[pos] ) == CInterpreter::CHAR_ALPHA
			    || GetCharacterType( var[pos] ) == CInterpreter::CHAR_DIGIT
				|| GetCharacterType( var[pos] ) == CInterpreter::CHAR_UNDERSCORE
				|| (var[pos] == L':' && (pos == startPos || pos == startPos + 1 ))
			)
		  ) pos++;
	// Skip Regex variable name characters
	if ((var[pos]==L'$') && (pos+1<var.GetLength())){
		if (   var[pos+1] == L'&' 
			|| var[pos+1] == L'`' 
			|| var[pos+1] == L'\'' 
			|| var[pos+1] == L'+' 
			|| var[pos+1] == L'_'
			)pos +=2;
		else{
			int i=0;
			for (i=1;i<=3;i++){
				if ( pos+i<var.GetLength() && var[pos+i] >=L'0' && var[pos+i]<=L'9') { /* do nothing */ }else break;
			}
			pos+=i;
		}
	}
	
	// Skip spaces
	while ( pos < var.GetLength() && GetCharacterType( var[pos] ) == CInterpreter::CHAR_WHITESPACE ) pos++;

	//jwz:add for Global Variable
	if (var[startPos]==L':' && var[startPos+1]==L':'){
		local = FALSE;
		startPos +=2;
	}

	// No array index?
	if ( pos == -1 || pos >= var.GetLength() || var[pos] != L'[' )
	{
		entryName = var;

		if ( pos != -1 && pos <= var.GetLength() )
			entryName = var.Mid( startPos, pos-startPos );


		entryName.TrimLeft();
		entryName.TrimRight();

		if ( position != NULL ) 
			*position = pos;

		if ( entryName.IsEmpty())
		{
			VarError = L"Empty variable name not allowed";
			if ( position != NULL ) *position = -1;
			return NULL;
		}

		entryName.MakeUpper();

		if ( local && LocalVariables != NULL && LocalVariables->Lookup( L"%GL_" + entryName + L"%", dummy ) ) //predefined GLOBAL declare variable
		{
			local = FALSE;
		}

		if ( local && LocalVariables != NULL && LocalVariables->Lookup( entryName, value ) ) {}
		else if ( local == FALSE && Variables.Lookup( entryName, value ) ) {}
		else
		{
			if ( create )
			{
				// MessageBox( NULL, L"%GL_" + entryName + L"%", L"Debug", MB_OK );
				if ( LocalVariables != NULL && local )
				{
					LocalVariables->SetAt( entryName, CValue() );
					LocalVariables->Lookup( entryName, value );
				}
				else
				{
					Variables.SetAt( entryName, CValue() );
					Variables.Lookup( entryName, value );
				}
			}
			else
				value = NULL;
		}
	}
	else
	{
		entryName = var.Mid( startPos, pos-startPos );
		entryName.TrimLeft(); entryName.TrimRight();
		entryName.MakeUpper();

		if ( entryName.IsEmpty() )
		{
			VarError = L"'[' without array name";
			if ( position != NULL ) *position = -1;
			value = NULL;
		}
		else
		{
			if ( local && LocalVariables != NULL && LocalVariables->Lookup( L"%GL_" + entryName + L"%", dummy ) )
			{
				local = FALSE;
			}

			if ( local && LocalVariables != NULL && LocalVariables->Lookup( entryName, value ) ) {}
			else if ( local == FALSE && Variables.Lookup( entryName, value ) ) {}
			else
			{
				if ( create )
				{
					if ( LocalVariables != NULL && local )
					{
						LocalVariables->SetAt( entryName, CValue() );
						LocalVariables->Lookup( entryName, value );
					}
					else
					{
						Variables.SetAt( entryName, CValue() );
						Variables.Lookup( entryName, value );
					}
				}
				else
					value = NULL;
			}

			if ( value != NULL )
				map = value->GetMap();

			while ( pos != -1 && pos < var.GetLength() && var[pos] == L'[' )
			{
				startPos = pos+1;
				CStr arrIdxExpr = var.Mid( startPos );
				CInterpreter parser;

				entryName = (LPCTSTR)parser.EvaluateExpression( arrIdxExpr, FALSE );

				if ( parser.GetError() != 0 )
				{
					VarError = parser.GetErrorMessage();
					if ( position != NULL ) *position = -1;
					value = NULL;
					break;
				}

				if ( entryName.IsEmpty() != 0 )
				{
					VarError = L"Array index is empty";
					if ( position != NULL ) *position = -1;
					value = NULL;
					break;
				}

				pos = startPos + parser.GetErrorPosition();
				if ( var[pos] != L']' )
				{
					VarError = L"Missing ']'";
					if ( position != NULL ) *position = -1;
					value = NULL;
					break;
				}

				if ( position != NULL ) *position = pos+1;
				while ( pos < var.GetLength() && parser.GetCharacterType( var[pos] ) == CInterpreter::CHAR_WHITESPACE ) pos++;

				entryName.MakeUpper();
				BOOL isArray = FALSE;
				if ( pos <= var.GetLength() && var[pos+1] == L'[' )
				{
					isArray = TRUE;
					pos++;
				}

				if ( value != NULL )
				{
					if ( map != NULL )
					{
						if ( map->Lookup( entryName, value ) == FALSE )
						{
							if ( create )
							{
								map->SetAt( entryName, CValue() );
								map->Lookup( entryName, value );
								if ( isArray )
									map = value->GetMap();
							}
							else
								value = NULL;
						}
						else
							if ( isArray ) map = value->GetMap();
					}
				}
			}
		}
	}

	if ( create && reference && value != NULL )
	{
		while ( pos < var.GetLength() && GetCharacterType( var[pos] ) == CInterpreter::CHAR_WHITESPACE ) pos++;
		if ( pos < var.GetLength() && var[pos] == L']' )
		{
			pos++;
			CStr referredVar = (CStr)*value;
			value = GetVariable( referredVar, create );
		}
		else
		{
			VarError = L"Missing ']'";
			pos = -1;
			if ( position != NULL ) *position = -1;
			value = NULL;
		}
	}

	if ( oldStyle && value != NULL )
	{
		while ( pos < var.GetLength() && GetCharacterType( var[pos] ) == CInterpreter::CHAR_WHITESPACE ) pos++;
		if ( pos < var.GetLength() && var[pos] == L'%' )
		{
			pos++;
			//CStr referredVar = (LPCTSTR)value;
			//value = GetVariable( referredVar, create );
		}
		else
		{
			VarError = L"Missing '%'";
			pos = -1;
			if ( position != NULL ) *position = -1;
			value = NULL;
		}
	}
	return value;
}
Ejemplo n.º 15
0
BOOL SetVariable( CStr &varName, LPCTSTR value )
{
	return SetVariable( varName, CValue(value) );
}
Ejemplo n.º 16
0
CMapStrToValue *CreateAndInitLocalVariables()
{
	CMapStrToValue *local = new CMapStrToValue();

	local->SetAt( L"%GL_TRUE%",   CValue(1L) );
	local->SetAt( L"%GL_FALSE%",  CValue(1L) );
	local->SetAt( L"%GL_ON%",     CValue(1L) );
	local->SetAt( L"%GL_OFF%",    CValue(1L) );
	local->SetAt( L"%GL_YES%",    CValue(1L) );
	local->SetAt( L"%GL_NO%",     CValue(1L) );
	local->SetAt( L"%GL_CANCEL%", CValue(1L) );
	local->SetAt( L"%GL_PI%",	  CValue(1L) );
	local->SetAt( L"%GL_SQRT2%",  CValue(1L) );
	local->SetAt( L"%GL_PHI%",	  CValue(1L) );
	local->SetAt( L"%GL_EULER%",  CValue(1L) );
	local->SetAt( L"%GL_HKCU%",   CValue(1L) );
	local->SetAt( L"%GL_HKLM%",   CValue(1L) );
	local->SetAt( L"%GL_HKCR%",   CValue(1L) );
	local->SetAt( L"%GL_HKUS%",   CValue(1L) );
	local->SetAt( L"%GL_BYTES%",  CValue(1L) );
	local->SetAt( L"%GL_KB%",     CValue(1L) );
	local->SetAt( L"%GL_MB%",     CValue(1L) );
	local->SetAt( L"%GL_GB%",     CValue(1L) );
	local->SetAt( L"%GL_ST_HIDDEN%",  CValue(1L) );
	local->SetAt( L"%GL_ST_LIST%",    CValue(1L) );
	local->SetAt( L"%GL_ST_MESSAGE%", CValue(1L) );
	local->SetAt( L"%GL_DC_FILES%",   CValue(1L) );
	local->SetAt( L"%GL_DC_DIRS%",    CValue(1L) );
	local->SetAt( L"%GL_DC_ALL%",     CValue(1L) );
	local->SetAt( L"%GL_VAR_EMPTY",  CValue(1L) );
	local->SetAt( L"%GL_VAR_INT",    CValue(1L) );
	local->SetAt( L"%GL_VAR_FLOAT",  CValue(1L) );
	local->SetAt( L"%GL_VAR_STRING", CValue(1L) );
	local->SetAt( L"%GL_VAR_ARRAY",  CValue(1L) );
	local->SetAt( L"%GL_VAR_FILE",   CValue(1L) );
	local->SetAt( L"%GL_VAR_WINDOW", CValue(1L) );
	local->SetAt( L"%AUTOLOCAL%", CValue(1L) );

	return local;
}
Ejemplo n.º 17
0
CMyClient::~CMyClient()
{
	Close(CValue(),0);
}
Ejemplo n.º 18
0
CValue::operator = (__int64 Val)
{
	SetValue(CValue(Val));
}
Ejemplo n.º 19
0
 CValue operator =(const TYPE& value)
 {
     return CValue(value);
 }
Ejemplo n.º 20
0
bool CVirtualMachine::execute()
{
  // Cache current function
  const SFunction &currentFunction = m_functions.at(m_currentFunctionIndex);

  // Default current instruction to implicit return
  SInstruction instruction;
  instruction.id = EInstruction::Ret;

  // Check for out of bounds instruction index
  if (currentFunction.instructionSize > m_currentInstructionIndex)
  {
    // Retrieve current instruction
    instruction = currentFunction.instructions.at(m_currentInstructionIndex);
  }

  // Debug
  // printRuntimeStack();
  std::cout << "Executing instruction " << toString(instruction) << std::endl;

  switch (instruction.id)
  {
  case EInstruction::Nop:
    ++m_currentInstructionIndex;
    break;

  case EInstruction::Break:
    // Not implemented
    ++m_currentInstructionIndex;
    break;

  case EInstruction::Exit:
    // Return false to signal end of script
    return false;
    break;

  case EInstruction::Movv:
    // Move variable to variable
    // Arg 0 is variable index of destination
    // Arg 1 is variable index of source
    m_runtimeStack[m_currentRuntimeStackBaseIndex +
                   *((uint32_t *)&instruction.args[0])] =
        m_runtimeStack.at(m_currentRuntimeStackBaseIndex +
                          *((uint32_t *)&instruction.args[1]));
    break;

  case EInstruction::Movi:
    // Move integer to variable
    // Arg 0 is variable index of destination
    // Arg 1 is source integer value
    m_runtimeStack[m_currentRuntimeStackBaseIndex +
                   *((uint32_t *)&instruction.args[0])] = instruction.args[1];
    break;

  case EInstruction::Movf:
    // Move float to variable
    // Arg 0 is variable index of destination
    // Arg 1 is source float value
    m_runtimeStack[m_currentRuntimeStackBaseIndex +
                   *((uint32_t *)&instruction.args[0])] =
        *((float *)&instruction.args[1]);
    break;

  case EInstruction::Movs:
    // Move string to variable
    // Arg 0 is variable index of destination
    // Arg 1 is source index of string
    m_runtimeStack[m_currentRuntimeStackBaseIndex +
                   *((uint32_t *)&instruction.args[0])] =
        m_strings.at(*((uint32_t *)&instruction.args[1]));
    ++m_currentInstructionIndex;
    break;

  case EInstruction::Pushi:
    // Push signed 32 bit integer value to
    // Arg 0 is integer value
    pushValue(CValue(instruction.args[0]));
    ++m_currentInstructionIndex;
    break;

  case EInstruction::Pushf:
    // Arg 0 is float value
    pushValue(CValue(*((float *)&instruction.args[0])));
    ++m_currentInstructionIndex;
    break;

  case EInstruction::Pushv:
    // Arg 0 is variable index
    pushValue(m_runtimeStack.at(m_currentRuntimeStackBaseIndex +
                                *((uint32_t *)&instruction.args[0])));
    ++m_currentInstructionIndex;
    break;

  case EInstruction::Pushs:
    // Arg 0 is string index
    pushValue(m_strings.at(*((uint32_t *)&instruction.args[0])));
    ++m_currentInstructionIndex;
    break;

  case EInstruction::Pop:
    // Remove top element from runtime stack
    m_runtimeStack.pop_back();
    ++m_currentInstructionIndex;
    break;

  case EInstruction::Popv:
  {
    // Remove top of the stack and store it in variable
    // Arg 0 is variable index
    m_runtimeStack[m_currentRuntimeStackBaseIndex +
                   *((uint32_t *)&instruction.args[0])] = m_runtimeStack.back();
    m_runtimeStack.pop_back();
    ++m_currentInstructionIndex;
  }
  break;

  case EInstruction::Call:
  {
    // Push current function index, next instruction index and base stack index
    // for
    // return call.
    m_callStack.push(SFunctionFrame(m_currentFunctionIndex,
                                    m_currentInstructionIndex + 1,
                                    m_currentRuntimeStackBaseIndex));
    // Arg 0 is function index of the called function
    m_currentFunctionIndex = *((uint32_t *)&instruction.args[0]);
    // Reset instruction index
    m_currentInstructionIndex = 0;
    // Set new runtime stack base index for the called function
    uint32_t runtimeStackSize = static_cast<uint32_t>(m_runtimeStack.size());
    m_currentRuntimeStackBaseIndex = runtimeStackSize;
    // Modify by function parameter size
    const SFunction &newCurrentFunction =
        m_functions.at(m_currentFunctionIndex);
    m_currentRuntimeStackBaseIndex -= newCurrentFunction.parameterSize;
    // Resize runtime stack with local stack size of called function
    m_runtimeStack.resize(runtimeStackSize + newCurrentFunction.stackSize -
                          newCurrentFunction.parameterSize);
    break;
  }

  case EInstruction::Calle:
  {
    // Call external, arg 0 is extern function index
    const SExternFunction &externFunction =
        m_externFunctions.at(instruction.args[0]);

    // Check if function exists
    // TODO Check if arg count ok
    auto entry = m_externFunctionsMap.find(externFunction.name);
    if (entry == m_externFunctionsMap.end())
    {
      // Function does not exist
      std::cout << "The extern function '" << externFunction.name
                << "' does not exist." << std::endl;
      return false;
    }
    // Call if found
    entry->second->call(*this);
    ++m_currentInstructionIndex;
    break;
  }
  case EInstruction::Ret:
    // Return from script function
    if (m_callStack.empty())
    {
      // Empty stack indicates either error state or end of script
      return false;
    }
    // Resize runtime stack to remove local function variables.
    m_runtimeStack.resize(m_currentRuntimeStackBaseIndex);

    // Retrieve function index of previous function
    m_currentFunctionIndex = m_callStack.top().functionIndex;
    // Restore active function index
    m_currentInstructionIndex = m_callStack.top().instructionIndex;
    // Restore runtime stack base index for the active function
    m_currentRuntimeStackBaseIndex = m_callStack.top().runtimeStackBaseIndex;
    m_callStack.pop();
    break;

  case EInstruction::Retv:
  {
    // Returns variable from script function
    if (m_callStack.empty())
    {
      // Empty stack indicates either error state or end of script
      return false;
    }
    // Arg 0 is local variable index
    // Store return value at local stack position 0
    uint32_t varIndex = *((uint32_t *)&instruction.args[0]);
    if (varIndex != 0)
    {
      m_runtimeStack[m_currentRuntimeStackBaseIndex + 1] =
          m_runtimeStack.at(m_currentRuntimeStackBaseIndex + varIndex);
    }

    // Resize runtime stack to remove local function variables but the one
    // holding the return value.
    m_runtimeStack.resize(m_currentRuntimeStackBaseIndex + 1);

    // Retrieve function index of previous function
    m_currentFunctionIndex = m_callStack.top().functionIndex;
    // Restore active function index
    m_currentInstructionIndex = m_callStack.top().instructionIndex;
    // Restore runtime stack base index for the active function
    m_currentRuntimeStackBaseIndex = m_callStack.top().runtimeStackBaseIndex;
    m_callStack.pop();
    break;
  }

  case EInstruction::Reti:
  {
    // Returns variable from script function
    if (m_callStack.empty())
    {
      // Empty stack indicates either error state or end of script
      return false;
    }
    // Arg 0 is integer constant
    // Store return value at local stack position 0
    m_runtimeStack[m_currentRuntimeStackBaseIndex + 1] =
        *((int32_t *)&instruction.args[0]);

    // Resize runtime stack to remove local function variables but the one
    // holding the return value.
    m_runtimeStack.resize(m_currentRuntimeStackBaseIndex + 1);

    // Retrieve function index of previous function
    m_currentFunctionIndex = m_callStack.top().functionIndex;
    // Restore active function index
    m_currentInstructionIndex = m_callStack.top().instructionIndex;
    // Restore runtime stack base index for the active function
    m_currentRuntimeStackBaseIndex = m_callStack.top().runtimeStackBaseIndex;
    m_callStack.pop();
    break;
  }

  case EInstruction::Add:
  {
    CValue x;
    // 2 Values needed
    if (!popValue(x) || m_runtimeStack.empty())
    {
      return false;
    }
    m_runtimeStack.back() += x;
    ++m_currentInstructionIndex;
  }
  break;

  case EInstruction::Sub:
  {
    CValue x;
    // 2 Values needed
    if (!popValue(x) || m_runtimeStack.empty())
    {
      return false;
    }
    m_runtimeStack.back() -= x;
    ++m_currentInstructionIndex;
  }
  break;

  case EInstruction::Mul:
    // Not implemented
    return false;
    break;

  case EInstruction::Div:
    // Not implemented
    return false;
    break;
  case EInstruction::Inc:
    // Not implemented
    return false;
    break;
  case EInstruction::Dec:
    // Not implemented
    return false;
    break;

  case EInstruction::And:
    // Not implemented
    return false;
    break;
  case EInstruction::Or:
    // Not implemented
    return false;
    break;
  case EInstruction::Not:
    // Not implemented
    return false;
    break;
  case EInstruction::Xor:
    // Not implemented
    return false;
    break;

  case EInstruction::Jmp:
    // Not implemented
    return false;
    break;
  case EInstruction::Je:
  {
    // Compare top 2 values from stack, x == y
    CValue y;
    CValue x;
    if (!popValue(y) || !popValue(x))
    {
      // Not enough values on stack
      return false;
    }
    if (x == y)
    {
      // Arg 0 is target instruction index for jump
      uint32_t jumpIndex = *((uint32_t *)&instruction.args[0]);
      m_currentInstructionIndex = jumpIndex;
    }
    else
    {
      ++m_currentInstructionIndex;
    }
  }
  break;
  case EInstruction::Jne:
  {
    // Compare top 2 values from stack, x != y
    CValue y;
    CValue x;
    if (!popValue(y) || !popValue(x))
    {
      // Not enough values on stack
      return false;
    }
    if (x != y)
    {
      // Arg 0 is target instruction index for jump
      uint32_t jumpIndex = *((uint32_t *)&instruction.args[0]);
      m_currentInstructionIndex = jumpIndex;
    }
    else
    {
      ++m_currentInstructionIndex;
    }
  }
  break;
  case EInstruction::Jle:
  {
    // Compare top 2 values from stack, x <= y
    CValue y;
    CValue x;
    if (!popValue(y) || !popValue(x))
    {
      // Not enough values on stack
      return false;
    }
    if (x <= y)
    {
      // Arg 0 is target instruction index for jump
      uint32_t jumpIndex = *((uint32_t *)&instruction.args[0]);
      m_currentInstructionIndex = jumpIndex;
    }
    else
    {
      ++m_currentInstructionIndex;
    }
  }
  break;

  default:
    assert(false);
    return false;
  }

  return true;
}
Ejemplo n.º 21
0
CValue CMonEventSet::RetrieveValue(const string& key)
{
	// We should not get here
	assert(0);
	return CValue();
}
Ejemplo n.º 22
0
void CVirtualMachine::setReturnValue(const std::string &value)
{
  pushValue(CValue(value));
}
Ejemplo n.º 23
0
CValue CValueControl::Method(int iName,CValue **p)
{
    if(!pWnd)
        Error("Не было привязки окна CWnd!");
    CValue Ret;
    switch(iName)
    {
    case enVisible:
    {
        Ret=Visible();
        if(p[0]->nType!=TYPE_EMPTY)
            Visible(p[0]->GetNumber());
        break;
    }
    case enEnable:
    {
        Ret=Enable();
        if(p[0]->nType!=TYPE_EMPTY)
            Enable(p[0]->GetNumber());
        break;
    }
    case enColor:
    {
        Ret=Color();
        if(p[0]->nType!=TYPE_EMPTY)
            Color(p[0]->GetNumber(),p[1]->GetNumber(),p[2]->GetNumber());
        break;
    }
    case enCaption:
    {
        Ret=String(Caption());
        if(p[0]->nType!=TYPE_EMPTY)
        {
            Caption(p[0]->GetString());
        }
        break;
    }
    case enEnableEdit:
    {
        Ret=EnableEdit();
        if(p[0]->nType!=TYPE_EMPTY)
            EnableEdit(p[0]->GetNumber());
        break;
    }
    case enMask:
    {
        //Ret=Mask();
        if(p[0]->nType!=TYPE_EMPTY)
            Ret=String(Mask(p[0]->GetString()));
        break;
    }
    case enClose:
    {
        Close();
        break;
    }
    case enModif:
    {
        int nSet=-1;
        if(p[0]->nType!=TYPE_EMPTY)
            nSet=p[0]->GetNumber();
        return Modify(nSet);
    }
    case enFocus:
    {
        ((CWnd*)pWnd)->SetFocus();
    }
    case enSetControlRect:
    {
        int x, y, nWidth, nHeight;
        x=p[0]->GetNumber();
        y=p[1]->GetNumber();
        nWidth=p[2]->GetNumber();
        nHeight=p[3]->GetNumber();
        ASSERT(pWnd);
        ((CWnd*)pWnd)->MoveWindow(x, y, nWidth, nHeight,1);
        ((CWnd*)pWnd)->RedrawWindow();
        break;
    }
    case enGetControlRect:
    {
        CRect mRect(0,0,0,0);
        ASSERT(pWnd);
        ((CWnd*)pWnd)->GetWindowRect(&mRect);
        CWnd* pParentWnd=((CWnd*)pWnd)->GetParent();
        pParentWnd->ScreenToClient(&mRect);
        *p[0] = CValue(mRect.left);
        *p[1] = CValue(mRect.top);
        *p[2] = CValue(mRect.right - mRect.left);
        *p[3] = CValue(mRect.bottom - mRect.top);
        break;
    }
    }
    return Ret;
}