MCPcopy Create free account
hub / github.com/MayaPosch/NymphCast / WriteByteCode

Method WriteByteCode

src/server/angelscript/angelscript/source/as_restore.cpp:5025–5484  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5023}
5024
5025void asCWriter::WriteByteCode(asCScriptFunction *func)
5026{
5027 asDWORD *bc = func->scriptData->byteCode.AddressOf();
5028 size_t length = func->scriptData->byteCode.GetLength();
5029
5030 // The length cannot be stored, because it is platform dependent,
5031 // instead we store the number of instructions
5032 asUINT count = bytecodeNbrByPos[bytecodeNbrByPos.GetLength()-1] + 1;
5033 WriteEncodedInt64(count);
5034
5035 asDWORD *startBC = bc;
5036 while( length )
5037 {
5038 asDWORD tmpBC[4]; // The biggest instructions take up 4 DWORDs
5039 asDWORD c = *(asBYTE*)bc;
5040
5041 // Copy the instruction to a temp buffer so we can work on it before saving
5042 memcpy(tmpBC, bc, asBCTypeSize[asBCInfo[c].type]*sizeof(asDWORD));
5043
5044 if( c == asBC_ALLOC ) // PTR_DW_ARG
5045 {
5046 // Translate the object type
5047 asCObjectType *ot = *(asCObjectType**)(tmpBC+1);
5048 *(asPWORD*)(tmpBC+1) = FindTypeInfoIdx(ot);
5049
5050 // Translate the constructor func id, unless it is 0
5051 if( *(int*)&tmpBC[1+AS_PTR_SIZE] != 0 )
5052 {
5053 // Increment 1 to the translated function id, as 0 will be reserved for no function
5054 *(int*)&tmpBC[1+AS_PTR_SIZE] = 1+FindFunctionIndex(engine->scriptFunctions[*(int*)&tmpBC[1+AS_PTR_SIZE]]);
5055 }
5056 }
5057 else if( c == asBC_REFCPY || // PTR_ARG
5058 c == asBC_RefCpyV || // wW_PTR_ARG
5059 c == asBC_OBJTYPE ) // PTR_ARG
5060 {
5061 // Translate object type pointers into indices
5062 *(asPWORD*)(tmpBC+1) = FindTypeInfoIdx(*(asCObjectType**)(tmpBC+1));
5063 }
5064 else if( c == asBC_JitEntry ) // PTR_ARG
5065 {
5066 // We don't store the JIT argument
5067 *(asPWORD*)(tmpBC+1) = 0;
5068 }
5069 else if( c == asBC_TYPEID || // DW_ARG
5070 c == asBC_Cast ) // DW_ARG
5071 {
5072 // Translate type ids into indices
5073 *(int*)(tmpBC+1) = FindTypeIdIdx(*(int*)(tmpBC+1));
5074 }
5075 else if( c == asBC_ADDSi || // W_DW_ARG
5076 c == asBC_LoadThisR ) // W_DW_ARG
5077 {
5078 // Translate property offsets into indices
5079 *(((short*)tmpBC)+1) = (short)FindObjectPropIndex(*(((short*)tmpBC)+1), *(int*)(tmpBC+1), bc);
5080
5081 // Translate type ids into indices
5082 *(int*)(tmpBC+1) = FindTypeIdIdx(*(int*)(tmpBC+1));

Callers

nothing calls this directly

Calls 11

CastToObjectTypeFunction · 0.85
AdjustOffsetMethod · 0.80
MoveToMethod · 0.80
GetTypeInfoOfLocalVarMethod · 0.80
PushLastMethod · 0.80
PopLastMethod · 0.80
SetRepeatCountMethod · 0.80
SetNextTypeMethod · 0.80
AddressOfMethod · 0.45
GetLengthMethod · 0.45

Tested by

no test coverage detected