
// should only be included by ablexec.h

//--------------------------------------------------------------------


namespace ABL
{
	extern bool          IncludeDebugInfo;
	extern long       FileNumber;

	inline SymTableNodePtr getCodeSymTableNodePtr (void)
	{

		SymTableNodePtr* nodePtrPtr = (SymTableNodePtr*)codeSegmentPtr;

		SymTableNodePtr nodePtr = *nodePtrPtr;
		codeSegmentPtr += sizeof(SymTableNodePtr);
		return(nodePtr);
	}

//***************************************************************************

	inline long getCodeStatementMarker (void)
	{

		//------------------------------------------
		// NOTE: If there's a problem, we return -1.

		long lineNum = -1;
		if (codeToken == TKN_STATEMENT_MARKER)
		{
			if (IncludeDebugInfo)
			{
				FileNumber = *((unsigned char*)codeSegmentPtr);
				codeSegmentPtr += sizeof(unsigned char);
				lineNum = *((long*)codeSegmentPtr);
				codeSegmentPtr += sizeof(long);
			}
		}
		return(lineNum);
	}

//***************************************************************************

	inline char* getCodeAddressMarker (void)
	{

		Address address = NULL;

		if (codeToken == TKN_ADDRESS_MARKER)
		{
			address = *((long*)codeSegmentPtr) + codeSegmentPtr - 1;
			codeSegmentPtr += sizeof(Address);
		}
		return(address);
	}

//***************************************************************************

	inline long getCodeInteger (void)
	{

		long value = *((long*)codeSegmentPtr);
		codeSegmentPtr += sizeof(long);
		return(value);
	}

//***************************************************************************

	inline char* getCodeAddress (void)
	{

		Address address = *((long*)codeSegmentPtr) + codeSegmentPtr - 1;
		codeSegmentPtr += sizeof(long);
		return(address);
	}

//***************************************************************************
// STACK routines
//***************************************************************************

	inline void pop (void)
	{

		--tos;
	}

//***************************************************************************

	inline void getCodeToken (void)
	{

		codeToken = (TokenCodeType)*codeSegmentPtr;
		codeSegmentPtr++;
	}

//***************************************************************************

	inline void pushInteger (long value)
	{

		StackItemPtr valuePtr = ++tos;

		if (valuePtr >= &stack[MAXSIZE_STACK])
			runtimeError(ABL_ERR_RUNTIME_STACK_OVERFLOW);
		valuePtr->integer = value;
	}

//***************************************************************************

	inline void pushReal (float value)
	{

		StackItemPtr valuePtr = ++tos;

		if (valuePtr >= &stack[MAXSIZE_STACK])
			runtimeError(ABL_ERR_RUNTIME_STACK_OVERFLOW);
		valuePtr->real = value;
	}

//***************************************************************************

	inline void pushByte (char value)
	{

		StackItemPtr valuePtr = ++tos;

		if (valuePtr >= &stack[MAXSIZE_STACK])
			runtimeError(ABL_ERR_RUNTIME_STACK_OVERFLOW);
		valuePtr->byte = value;
	}

//***************************************************************************

	inline void pushAddress (Address address)
	{

		StackItemPtr valuePtr = ++tos;

		if (valuePtr >= &stack[MAXSIZE_STACK])
			runtimeError(ABL_ERR_RUNTIME_STACK_OVERFLOW);
		valuePtr->address = address;
	}

//***************************************************************************

	inline void pushBoolean (bool value)
	{

		StackItemPtr valuePtr = ++tos;

		if (valuePtr >= &stack[MAXSIZE_STACK])
			runtimeError(ABL_ERR_RUNTIME_STACK_OVERFLOW);
		valuePtr->integer = (value ? 1 : 0);
	}

};

