void _Compile_JmpCall_Using_RStack ( byte * jmpToAddr ) { // push rstack here + 5 so RET can jmp back _Compile_MoveImm_To_Reg ( EAX, &Rsp, CELL ) ; // the lvalue of Rsp Compile_ADDI ( MEM, EAX, 0, CELL, BYTE ) ; // add 4 to Rsp Compile_ADDI ( REG, EAX, 0, CELL, BYTE ) ; // //_Compile_Move_Reg_To_Reg ( int32 dstReg, int32 srcReg ) ; _Compile_MoveImm_To_Reg ( ECX, Here + x, CELL ) ; // x : number of bytes to the first byte after the jmp instruction _Compile_Move_Reg_To_Rm ( EAX, 0, ECX ) ; _Compile_JumpToAddress ( byte * jmpToAddr ) ; }
void Do_ObjectOffset ( Word * word, int32 reg ) { Compiler * compiler = _Context_->Compiler0 ; int32 offset = word->AccumulatedOffset ; Compile_ADDI ( REG, reg, 0, offset, CELL ) ; compiler->AccumulatedOffsetPointer = ( int32* ) ( Here - CELL ) ; // offset will be calculated as we go along by ClassFields and Array accesses }
void _Compiler_AddLocalFrame ( Compiler * compiler ) { _Compile_Move_Reg_To_StackN ( DSP, 1, FP ) ; // save pre fp _Compile_LEA ( FP, DSP, 0, LocalVarIndex_Disp ( 1 ) ) ; // set new fp Compile_ADDI ( REG, DSP, 0, ( compiler->LocalsFrameSize + 1 ) * CELL, CELL ) ; // 1 : fp - add stack frame -- this value is going to be reset compiler->FrameSizeCellOffset = ( int32* ) ( Here - CELL ) ; // in case we have to add to the framesize with nested locals }
void _Compiler_RemoveLocalFrame ( Compiler * compiler ) { int32 parameterVarsSubAmount, returnValueFlag ; Compiler_SetLocalsFrameSize_AtItsCellOffset ( compiler ) ; parameterVarsSubAmount = ( compiler->NumberOfParameterVariables * CELL ) ; if ( GetState ( _Context_, C_SYNTAX ) && ( ! String_Equal ( compiler->CurrentWord->S_ContainingNamespace->Name, "void" ) ) ) { SetState ( compiler, RETURN_TOS, true ) ; } //returnValueFlag = rvf = ( _Context_->CurrentRunWord->CProperty & C_RETURN ) || ( GetState ( compiler, RETURN_TOS | RETURN_EAX ) ) || IsWordRecursive || compiler->ReturnVariableWord ; returnValueFlag = ( _Context_->CurrentlyRunningWord->CProperty & C_RETURN ) || ( GetState ( compiler, RETURN_TOS | RETURN_EAX ) ) || IsWordRecursive || compiler->ReturnVariableWord ; Word * word = compiler->ReturnVariableWord ; #if 0 if ( GetState ( _Context_->Compiler0, SAVE_ESP ) ) { _Compile_ESP_Restore ( ) ; } #endif if ( word ) { _Compile_GetVarLitObj_RValue_To_Reg ( word, EAX, 0 ) ; // nb. these variables have no lasting lvalue - they exist on the stack - therefore we can only return there rvalue } //else if ( compiler->NumberOfParameterVariables && returnValueFlag && ( ! compiler->NumberOfRegisterVariables ) && ( ! GetState ( compiler, RETURN_EAX ) ) ) else if ( compiler->NumberOfParameterVariables && returnValueFlag && ( ! GetState ( compiler, RETURN_EAX ) ) ) { #if 0 // for some unknown reason this code will overwrite the function call address also byte add_esi_eax [ ] = { 0x01, 0x06 } ; //0106 add [esi], eax byte * here = _Q_CodeByteArray->EndIndex ; if ( memcmp ( add_esi_eax, here - 2, 2 ) ) { //_ByteArray_UnAppendSpace ( _Q_CodeByteArray, 2 ) ; SetHere ( Here - 2 ) ; _Compile_X_Group1 ( ADD, REG, MEM, EAX, DSP, 0, 0, CELL ) ; // result is on TOS } //{returnValueFlag ++ ; rvf = 0 ;} //else #else Compile_Move_TOS_To_EAX ( DSP ) ; // save TOS to EAX so we can set return it as TOS below #endif //else { parameterVarsSubAmount += CELL ; rvf = 0 ; } } else if ( GetState ( compiler, RETURN_TOS ) ) { Compile_Move_TOS_To_EAX ( DSP ) ; } _Compile_LEA ( DSP, FP, 0, - LocalVarIndex_Disp ( 1 ) ) ; // restore sp - release locals stack frame _Compile_Move_StackN_To_Reg ( FP, DSP, 1 ) ; // restore the saved pre fp - cf AddLocalsFrame // remove the incoming parameters -- like in C parameterVarsSubAmount -= returnValueFlag * CELL ; // reduce the subtract amount to make room for the return value if ( parameterVarsSubAmount > 0 ) { Compile_SUBI ( REG, DSP, 0, parameterVarsSubAmount, CELL ) ; // remove stack variables } else if ( parameterVarsSubAmount < 0 ) { Compile_ADDI ( REG, DSP, 0, - parameterVarsSubAmount, CELL ) ; // add a place on the stack for return value } //if ( rvf && returnValueFlag && ( ! GetState ( compiler, RETURN_EAX ) ) ) if ( returnValueFlag && ( ! GetState ( compiler, RETURN_EAX ) ) ) { // nb : stack was already adjusted accordingly for this above by reducing the SUBI subAmount or adding if there weren't any parameter variables Compile_Move_EAX_To_TOS ( DSP ) ; } }