interface
| 6283 | |
| 6284 | // interface |
| 6285 | int asCContext::GetArgsOnStackCount(asUINT stackLevel) |
| 6286 | { |
| 6287 | // Clear cache |
| 6288 | m_argsOnStackCache.SetLength(0); |
| 6289 | m_argsOnStackCacheProgPos = 0; |
| 6290 | m_argsOnStackCacheFunc = 0; |
| 6291 | |
| 6292 | // Don't return anything if there is no bytecode, e.g. before calling Execute() |
| 6293 | if (m_regs.programPointer == 0) return asERROR; |
| 6294 | |
| 6295 | if (stackLevel >= GetCallstackSize()) return asINVALID_ARG; |
| 6296 | |
| 6297 | asCScriptFunction* func; |
| 6298 | asDWORD* sf; |
| 6299 | asDWORD* sp; |
| 6300 | asDWORD* progPointer; |
| 6301 | if (stackLevel == 0) |
| 6302 | { |
| 6303 | func = m_currentFunction; |
| 6304 | sf = m_regs.stackFramePointer; |
| 6305 | sp = m_regs.stackPointer; |
| 6306 | progPointer = m_regs.programPointer; |
| 6307 | } |
| 6308 | else |
| 6309 | { |
| 6310 | asPWORD* s = m_callStack.AddressOf() + (GetCallstackSize() - stackLevel - 1) * CALLSTACK_FRAME_SIZE; |
| 6311 | func = (asCScriptFunction*)s[1]; |
| 6312 | sf = (asDWORD*)s[0]; |
| 6313 | sp = (asDWORD*)s[3]; |
| 6314 | progPointer = (asDWORD*)s[2]; |
| 6315 | } |
| 6316 | |
| 6317 | // Determine the highest stack position for local variables |
| 6318 | // asCScriptFunction::variableSpace give this value |
| 6319 | // If the stack pointer is higher than that, then there are data pushed on the stack |
| 6320 | asUINT stackPos = asDWORD(sf - sp) - func->scriptData->variableSpace; |
| 6321 | if (stackPos == 0) |
| 6322 | return 0; |
| 6323 | |
| 6324 | // If a function is already being called at a higher call stack position, subtract the args for that function |
| 6325 | asCScriptFunction* calledFunc = 0; |
| 6326 | if (stackLevel == 1) |
| 6327 | calledFunc = m_currentFunction; |
| 6328 | else if( stackLevel > 1 ) |
| 6329 | { |
| 6330 | asPWORD *s = m_callStack.AddressOf() + (GetCallstackSize() - stackLevel - 2) * CALLSTACK_FRAME_SIZE; |
| 6331 | calledFunc = (asCScriptFunction*)s[1]; |
| 6332 | } |
| 6333 | if( calledFunc ) |
| 6334 | stackPos -= calledFunc->GetSpaceNeededForArguments() + (calledFunc->DoesReturnOnStack() ? AS_PTR_SIZE : 0) + (calledFunc->GetObjectType() ? AS_PTR_SIZE : 0); |
| 6335 | |
| 6336 | // Cache the list of arg types by func pointer and program position |
| 6337 | m_argsOnStackCacheFunc = func; |
| 6338 | m_argsOnStackCacheProgPos = asUINT(progPointer - &func->scriptData->byteCode[0]); |
| 6339 | |
| 6340 | // Iteratively search for functions that will be called until all values on the arg has been determined |
| 6341 | asUINT progPos = asUINT(progPointer - &func->scriptData->byteCode[0]); |
| 6342 | while( stackPos > 0 ) |