opl16gen.cpp

来自「在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己」· C++ 代码 · 共 2,125 行 · 第 1/5 页

CPP
2,125
字号
// OPL16GEN.CPP
//
// Copyright (c) 1997-2000 Symbian Ltd. All rights reserved.
//
// The 16 bit OPL Qcode Generator class. Converts Parser PCODE
// into the real McCoy Qcode.

#include "opl16.h"

#include <s32file.h>
#include <apparc.h>
#include <apgicnfl.h>
#include <apmstd.h>
#include <apfdef.h>
#include <charconv.h> // Unicode charconv

enum TOpl16BackEndPanic
	{
	// TOpl16QcodeGenerator
	EOpl16GenUnknownPCode,
	EOpl16GenUnknownConstantType,
	EOpl16StackError, // Error keeping track of the stack depth
	
	EOpl16BackEndReentrantStart,
	EOpl16BackEndAppState,
	EOpl16BackEndProcState,
	EOpl16BackEndBodyState,
	
	//
	EOpl16Opl1993NoOpx,

	// Eval back end
	EOpl16EvalBackEndBuffers
	};


////////////////////////////////////////////////////////////////
//
// TGlobalType - for putting out the type of a Global or external Symbol
//
////////////////////////////////////////////////////////////////
// Flag to indicate that a global or external variable (i.e. an indirected reference)
// is actually an array - or'd in with the variable type
const TInt KOpl16IndirectArrayFlag=0x80;

class TGlobalType
	{
public:
	TGlobalType(COplSymbol* aSymbol);
	inline void ExternalizeL(RWriteStream& aStream) const { aStream.WriteUint16L(iType);}
private:
	TInt iType;
	};

TGlobalType::TGlobalType(COplSymbol*aSymbol)
	{
	iType=aSymbol->Type();
	if (aSymbol->Token()==TOplToken::EArray)
		iType|=KOpl16IndirectArrayFlag;
	}
/////////////////////////////////////////////////////////////////
//
// Opo write stream - allows a RBufWriteStream to be patched
//
/////////////////////////////////////////////////////////////////
const TUint KOpl16PatchValue=KMaxTUint32; // To be patched with good value
TStreamPos ROpoWriteStream::AddPatchL(TBool a32BitPatch)
//
// Reserves space in a stream for a 32 bit value to be patched later
//
	{
	
	TStreamPos aPatchPos(SizeL());
	if (a32BitPatch)
		WriteUint32L(KOpl16PatchValue);
	else
		WriteUint16L(KOpl16PatchValue);
	return aPatchPos;
	}


void ROpoWriteStream::PatchL(TStreamPos aPos, TUint aValue,TBool a32BitPatch)
	{
// ????
	
	Sink()->SeekL(MStreamBuf::EWrite,aPos);

	if (a32BitPatch)
		WriteUint32L(aValue);
	else
		WriteUint16L(aValue);
	Sink()->SeekL(MStreamBuf::EWrite,EStreamEnd);
	}

void ROpoWriteStream::PatchCheckedUidL(TCheckedUid& aCheckedUid)
//
// FOR NOW - this is a bit of a horrible kludge that comes out of trying to
// embed the old file format in what looks to be a stream store.
//
	{
	
	Sink()->SeekL(MStreamBuf::EWrite,EStreamBeginning);
	ExternalizeL(aCheckedUid,*this);
	Sink()->SeekL(MStreamBuf::EWrite,EStreamEnd);
	}

TInt ROpoWriteStream::SizeL()
//
// Checks the size
//
	{
	
	return Sink()->SeekL(0,EStreamEnd).Offset();
	}


//////////////////////////////////////////////////////////////////
//
// TCode16 - Class for externalizing qcodes
//
/////////////////////////////////////////////////////////////////
const TInt KOpl16ExtendedQcodeFlag=0x100;

const TUint KOpl16LeftSideReference=0x04;
const TUint KOpl16ExternalReference=0x08;
const TUint KOpl16ArrayReference=0x10;

const TUint KOpl16EndOfFieldList=0xff;

class TQcode16
	{
public:
	TQcode16(TUint aCode) : iCode(aCode) {}
	enum TCode
		{
		EIdentifier=0x00,
		EField=0x20,
		EConstant=0x28,
		ESpecial=0x2c, 

		ELessThan=0x30,
		ELessThanEq=0x34,
		EGreaterThan=0x38,
		EGreaterThanEq=0x3c,
		EEqual=0x40,
		ENotEqual=0x44,
		EAddition=0x48,
		ESubtraction=0x4c,
		EStackByteAsWord=0x4f,
		EMultiply=0x50,
		ECallProcedure=0x53,
		EDivide=0x54,
		EFunctionCall=0x57,
		EPower=0x58,
		EBranchFalse=0x5b,
		EAnd=0x5c,
		EStackByteAsLong=0x5f,

		EOr=0x60,
		EStackWordAsLong=0x63,
		ENot=0x64,
		EDebugStatement16=0x67,
		EUnaryMinus=0x68,
		ECallProcByName=0x6b,
		EPercLess=0x6c,
		EPercGreater=0x6d,
		EPercPlus=0x6e,
		EPercMinus=0x6f,

		EPercMultiply=0x70,
		EPercDivide=0x71,
		EReturnNull=0x74,

		ELongToWord=0x78,
		EDoubleToWord=0x79,
		EDoubleToLong=0x7a,
		EWordToLong=0x7b,


		EWordToDouble=0x7c,
		ELongToDouble=0x7d,
		ELongToUword=0x7e,
		EDoubleToUword=0x7f,

		EDropValue=0x80,
		EAssign=0x84,
		EPrintValue=0x88,
		ELprintValue=0x8c,

		EPrintSpace=0x90,
		ELprintSpace=0x91,
		EPrintCrLf=0x92,
		ELprintCrLf=0x93,
		EInput=0x94,
		EPokeWord=0x98,
		EPokeLong=0x99,
		EPokeDouble=0x9a,
		EPokeString=0x9b,
		EPokeByte=0x9c,
		EAppend=0x9d,
		EAt=0x9e,
		EBack=0x9f,

		EBeep=0xa0,
		EClose=0xa1,
		ECls=0xa2,
		ECompress=0xa3,
		ECopy=0xa4,
		ECreate=0xa5,
		ECursor=0xa6,
		EDelete=0xa7,
		EErase=0xa8,
		EEscape=0xa9,
		EFirst=0xaa,
		EVector=0xab,
		ELast=0xac,
		ELclose=0xad,
		ELoadm=0xae,
		ELopen=0xaf,

		ENext=0xb0,
		EOnerr=0xb1,
		EOff=0xb2,
		EOffTime=0xb3,
		EOpen=0xb4,
		EPause=0xb5,
		EPosition=0xb6,
		EIoSignal=0xb7,
		ERaise=0xb8,
		ERandomize=0xb9,
		ERename=0xba,
		EStop=0xbb,
		ETrap=0xbc,
		EUpdate=0xbd,
		EUse=0xbe,
		EGoto=0xbf,

		EReturnValue=0xc0,
		EUnloadm=0xc1,
		EEdit=0xc2,
		EScreen=0xc3,
		EOpenr=0xc4,
		EgSaveBit=0xc5,
		EgClose=0xc6,
		EgUse=0xc7,
		EgSetWin=0xc8,
		EgVisible=0xc9,
		EgFont=0xca,
		EgUnloadFont=0xcb,
		EgGMode=0xcc,
		EgTMode=0xcd,
		EgStyle=0xce,
		EgOrder=0xcf,

		EgInfo=0xd0,
		EgCls=0xd1,
		EgAt=0xd2,
		EgMove=0xd3,
		EgPrint=0xd4,
		EgPrintSpace=0xd8,
		EgPrintB=0xd9,
		EgLineBy=0xda,
		EgBox=0xdb,
		EgCircle=0xdc,
		EgEllipse=0xdd,
		EgPoly=0xde,
		EgFill=0xdf,

		EgPatt=0xe0,
		EgCopy=0xe1,
		EgScroll=0xe2,
		EgUpdate=0xe3,
		EGetEvent=0xe4,
		EgLineTo=0xe5,
		EgPeekLine=0xe6,
		EgScreen=0xe7,
		EIoWaitStat=0xe8,
		EIoYield=0xe9,
		EmInit=0xea,
		EmCard=0xeb,
		EdInit=0xec,
		EdItem=0xed,
		ESetName=0xee,
		EStatusWin=0xef,

		EBusy=0xf0,
		ELock=0xf1,
		EgInvert=0xf2,
		EgXPrint=0xf3,
		EgBorder=0xf4,
		EgClock=0xf5,
		EMemoryRight=0xf6,
		EMemoryLeft=0xf7,
		EMkDir=0xf8,
		ERmDir=0xf9,
		ESetPath=0xfa,
		ESecsToDate=0xfb,
		EgIPrint=0xfc,
		EExtended=0xff,

		EgGrey = KOpl16ExtendedQcodeFlag,
		EDefaultWin,
		EDiamInit,
		EDiamPos,
		EFont,
		EStyle,
		EUseSprite,
		EAppendSprite,
		EDrawSprite,
		EChangeSprite,
		EPosSprite,
		ECloseSprite,
		EFreeAlloc,
		ELinkLib,
		ECache,
		EgButton,

		EgXBorder,
		EgDrawObject,
		EOdbInfo,
		ECacheTidy,
		EScreenInfo,
		ECacheHdr,
		ECacheRec,
		EdInitS,
		EOpxCall,
		EDebugStatement32,
		EModify,
		EInsert,
		ECancel,
		EPut,
		EDeleteTable,
		EGotoMark,
		
		EKillMark,	// 0x120
		EReturnFromEval,
		EGetEvent32,
		EGetEventa32,
		EGcolor,
		ESetflags,
		ESetdoc,
		EDaysToDate,
		EGinfo32,
		EIowaitstat32,
		ECompact,
		EBeginTrans,
		ECommitTrans, 
		ERollBack,
		EClearflags,
		EPointerFilter,

		EmCasc,  // 0x130
		EEvalRightSideExternal,
		EEvalLeftSideExternal,
//		EdCheckBox,
		EgSetPenWidth,
		EdEditMulti,
		EGcolorinfo,
		EGcolorbackground,
		EmCardX,
		ESetHelp,
		EShowHelp,
		ESetHelpUid
		};

	enum TDialogItem
		{
		EDlgText,
		EDlgChoice,
		EDlgLong,
		EDlgFloat,
		EDlgTime,
		EDlgDate,
		EDlgEdit,
		EDlgSedit,
		EDlgIinput,
		EDlgFile,
		EDlgButtons,
		EDlgPosition
		};
	enum TFuncNumber
		{
		EAddr=0x0,
		EAsc=0x1,
		ECall=0x2,
		ECount=0x3,
		EDay=0x4,
		EDow=0x5,
		EEof=0x6,
		EErr=0x7,
		EExist=0x8,
		EFind=0x9,
		EGet=0xA,
		EIoA=0xB,
		EIoW=0xC,
		EIoOpen=0xD,
		EIoWrite=0xE,
		EIoRead=0xF,
		EIoClose=0x10,
		EIoWait=0x11,
		EHour=0x12,
		EKey=0x13,
		ELen=0x14,
		ELoc=0x15,
		EMinute=0x16,
		EMonth=0x17,
		EPeekB=0x18,
		EPeekW=0x19,
		EPos=0x1A,
		ERecSize=0x1B,
		ESecond=0x1C,
		EUsr=0x1D,
		EYear=0x1E,
		ESAddr=0x1F,
		EWeek=0x20,
		EIoSeek=0x21,
		EKMod=0x22,
		EKeyA=0x23,
		EKeyC=0x24,
		EIoOpenX=0x25,
		EgCreate=0x26,
		EgCreateBit=0x27,
		EgLoadBit=0x28,
		EgLoadFont=0x29,
		EgRank=0x2A,

⌨️ 快捷键说明

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