⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pushoc.cpp

📁 在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己的开发
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// PUSHOC.CPP
//
// Copyright (c) 1997-2002 Symbian Ltd. All rights reserved.

#include <e32std.h>
#include <opcodes.h>
#include <module.h>
#include <oplrdef.h>
#include "frame.h"
#include "oplutil.h"

void OpCode::SimpleDirectRightSideInt(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.Push(OplUtil::GetWord(aFramePtr->VarAddrRel(aRuntime.IP16())));
	}

void OpCode::SimpleDirectRightSideLong(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.Push(OplUtil::GetLong(aFramePtr->VarAddrRel(aRuntime.IP16())));
	}

void OpCode::SimpleDirectRightSideFloat(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.Push(OplUtil::GetFloat(aFramePtr->VarAddrRel(aRuntime.IP16())));
	}

void OpCode::SimpleDirectRightSideString(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.Push((TText*)(aFramePtr->VarAddrRel(aRuntime.IP16())));
	}

void OpCode::SimpleDirectLeftSideInt(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.PushRef(*(TInt16*)(aFramePtr->VarAddrRel(aRuntime.IP16())));
	aStack.Push((TInt16)0); // not a field
	}

void OpCode::SimpleDirectLeftSideLong(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.PushRef(*(TInt32*)(aFramePtr->VarAddrRel(aRuntime.IP16())));
	aStack.Push((TInt16)0); // not a field
	}

void OpCode::SimpleDirectLeftSideFloat(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.PushRef(*(TReal64*)(aFramePtr->VarAddrRel(aRuntime.IP16())));
	aStack.Push((TInt16)0); // not a field
	}

void OpCode::SimpleDirectLeftSideString(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	TUint8* ptr=(TUint8*)aFramePtr->VarAddrRel(aRuntime.IP16()); // ptr can be misaligned.
	__ASSERT_ISALIGNED(ptr);
	TInt16 maxLen=OplUtil::GetWord(ptr-(1+KOplAlignment));
	__ASSERT_DEBUG(maxLen>0,AlignPanic(KErrOplAlignBadLength));
	__ASSERT_DEBUG(maxLen<=KOplMaxStrLen,AlignPanic(KErrOplAlignBadLength));
	aStack.Push(maxLen);
	aStack.PushRef((TText*)ptr);
	aStack.Push((TInt16)0); // not a field
	}

void OpCode::SimpleInDirectRightSideInt(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.Push(OplUtil::GetWord(aFramePtr->VarAddrInd(aRuntime.IP16())));
	}

void OpCode::SimpleInDirectRightSideLong(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.Push(OplUtil::GetLong(aFramePtr->VarAddrInd(aRuntime.IP16())));
	}

void OpCode::SimpleInDirectRightSideFloat(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.Push(OplUtil::GetFloat(aFramePtr->VarAddrInd(aRuntime.IP16())));
	}

void OpCode::SimpleInDirectRightSideString(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.Push((TText*)(aFramePtr->VarAddrInd(aRuntime.IP16())));
	}

LOCAL_C const TAny* _ptrGlobal(COplRuntime& aRuntime,TOplType& aType)
	{
	TUint8* ip=(TUint8*)aRuntime.IP();
	// Get a word-aligned copy of the name at the current IP.
	TBuf<KMaxGlobalName> name;
	name.SetLength(*ip);
	Mem::Copy((TUint8*)name.Ptr(),ip+1+KOplAlignment,*ip*sizeof(TText));

	aRuntime.IncIP(*ip*sizeof(TText)+1+KOplAlignment);
	aType=TOplType(aRuntime.IP16());
	const TAny* ptr=aRuntime.GlobalTbl().Find(name,aType);
	if (ptr==NULL)
		{
		aRuntime.SetErrorBuffer(&name);
		User::Leave(KOplErrUndef);
		}
	return ptr;
	}

void OpCode::EvalExternalRightSideRef(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	TOplType type;
	TUint8* ptr=(TUint8*)_ptrGlobal(aRuntime,type);
	switch (type)
		{
	case EWord:
		aStack.Push(OplUtil::GetWord(ptr));
		break;
	case ELong:
		aStack.Push(OplUtil::GetLong(ptr));
		break;
	case EReal:
		aStack.Push(OplUtil::GetFloat(ptr));
		break;
	case EString:
		aStack.Push((OplString)ptr);
		break;
	case EWordArray:
		aStack.Push(*(TInt16*)GetElementL(ptr,aStack.PopInt16(),sizeof(TInt16)));
		break;
	case ELongArray:
		aStack.Push(*(TInt32*)GetElementL(ptr,aStack.PopInt16(),sizeof(TInt32)));
		break;
	case ERealArray:
		aStack.Push(*(TReal64*)GetElementL(ptr,aStack.PopInt16(),sizeof(TReal64)));
		break;
	case EStringArray:
		{
		TInt index=aStack.PopInt16();
		if (index>OplUtil::GetWord(ptr-(3+KOplAlignment))||index<1)
			User::Leave(KOplErrSubs);
		TInt len=*(ptr-(1+KOplAlignment));
		aStack.Push((TText*)JumpToIndex(ptr,index,len*sizeof(TText)+1+KOplAlignment));
		break;
		}
	default:
		User::Leave(KOplErrInvalidArgs);
		break;
		}
	}

void OpCode::EvalExternalLeftSideRef(CStack& /*aStack*/, COplRuntime& /*aRuntime*/, CFrame* /*aFramePtr*/)
	{
	// EvalExternalLeftSideRef not yet supported
	User::Leave(KOplErrInvalidArgs);
	}

void OpCode::SimpleInDirectLeftSideInt(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.PushRef(*(TInt16*)(aFramePtr->VarAddrInd(aRuntime.IP16())));
	aStack.Push((TInt16)0); // not a field
	}

void OpCode::SimpleInDirectLeftSideLong(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.PushRef(*(TInt32*)(aFramePtr->VarAddrInd(aRuntime.IP16())));
	aStack.Push((TInt16)0); // not a field
	}

void OpCode::SimpleInDirectLeftSideFloat(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.PushRef(*(TReal64*)(aFramePtr->VarAddrInd(aRuntime.IP16())));
	aStack.Push((TInt16)0); // not a field
	}

void OpCode::SimpleInDirectLeftSideString(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	TUint8* ptr=(TUint8*)(aFramePtr->VarAddrInd(aRuntime.IP16()));
	__ASSERT_ISALIGNED(ptr);
	TInt16 maxLen=OplUtil::GetWord(ptr-(1+KOplAlignment));
	__ASSERT_DEBUG(maxLen!=0,AlignPanic(KErrOplAlignBadLength));
	__ASSERT_DEBUG(maxLen<=KOplMaxStrLen,AlignPanic(KErrOplAlignBadLength));
	aStack.Push(maxLen);
	aStack.PushRef((TText*)ptr);
	aStack.Push((TInt16)0); // not a field
	}

void OpCode::ArrayDirectRightSideInt(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.Push(OplUtil::GetWord(GetElementL(aFramePtr->VarAddrRel(aRuntime.IP16()),aStack.PopInt16(),sizeof(TInt16))));
	}

void OpCode::ArrayDirectRightSideLong(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.Push(OplUtil::GetLong(GetElementL(aFramePtr->VarAddrRel(aRuntime.IP16()),aStack.PopInt16(),sizeof(TInt32))));
	}

void OpCode::ArrayDirectRightSideFloat(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.Push(OplUtil::GetFloat(GetElementL(aFramePtr->VarAddrRel(aRuntime.IP16()),aStack.PopInt16(),sizeof(TReal64))));
	}

void OpCode::ArrayDirectRightSideString(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	TUint8* ptr=(TUint8*)aFramePtr->VarAddrRel(aRuntime.IP16());
	TInt index=aStack.PopInt16();
	TInt16 maxIndex=OplUtil::GetWord(ptr-(3+KOplAlignment));
	if (index>maxIndex||index<1)
		User::Leave(KOplErrSubs);
	aStack.Push((TText*)JumpToIndex(ptr,index,OplUtil::GetWord(ptr-(1+KOplAlignment))*sizeof(TText)+1+KOplAlignment));
	}

void OpCode::ArrayDirectLeftSideInt(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.PushRef(*(TInt16*)(GetElementL(aFramePtr->VarAddrRel(aRuntime.IP16()),aStack.PopInt16(),sizeof(TInt16))));
	aStack.Push((TInt16)0); // not a field
	}

void OpCode::ArrayDirectLeftSideLong(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.PushRef(*(TInt32*)GetElementL(aFramePtr->VarAddrRel(aRuntime.IP16()),aStack.PopInt16(),sizeof(TInt32)));
	aStack.Push((TInt16)0); // not a field
	}

void OpCode::ArrayDirectLeftSideFloat(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.PushRef(*(TReal64*)GetElementL(aFramePtr->VarAddrRel(aRuntime.IP16()),aStack.PopInt16(),sizeof(TReal64)));
	aStack.Push((TInt16)0); // not a field
	}

void OpCode::ArrayDirectLeftSideString(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	TUint8* ptr=(TUint8*)aFramePtr->VarAddrRel(aRuntime.IP16());
	TInt index=aStack.PopInt16();
	TInt16 maxIndex=OplUtil::GetWord(ptr-(3+KOplAlignment));
	if (index>maxIndex||index<1)
		User::Leave(KOplErrSubs);
	TInt16 maxLen=OplUtil::GetWord(ptr-(1+KOplAlignment));
	aStack.Push(maxLen); //len of string in chars
	aStack.PushRef((TText*)JumpToIndex(ptr,index,maxLen*sizeof(TText)+1+KOplAlignment));
	aStack.Push((TInt16)0); // not a field
	}

void OpCode::ArrayInDirectRightSideInt(CStack& aStack, COplRuntime& aRuntime, CFrame* aFramePtr)
	{
	aStack.Push(OplUtil::GetWord(GetElementL(aFramePtr->VarAddrInd(aRuntime.IP16()),aStack.PopInt16(),sizeof(TInt16))));
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -