==================== idInterpreter::EnterFunction Returns the new program statement counter NOTE: If this is called from within a event called by this interpreter, the function arguments will be invalid after calling this function. ==================== */
| 592 | ==================== |
| 593 | */ |
| 594 | void idInterpreter::EnterFunction( const function_t *func, bool clearStack ) { |
| 595 | int c; |
| 596 | prstack_t *stack; |
| 597 | |
| 598 | if ( clearStack ) { |
| 599 | Reset(); |
| 600 | } |
| 601 | if ( popParms ) { |
| 602 | PopParms( popParms ); |
| 603 | popParms = 0; |
| 604 | } |
| 605 | |
| 606 | if ( callStackDepth >= MAX_STACK_DEPTH ) { |
| 607 | Error( "call stack overflow" ); |
| 608 | } |
| 609 | |
| 610 | stack = &callStack[ callStackDepth ]; |
| 611 | |
| 612 | stack->s = instructionPointer + 1; // point to the next instruction to execute |
| 613 | stack->f = currentFunction; |
| 614 | stack->stackbase = localstackBase; |
| 615 | |
| 616 | callStackDepth++; |
| 617 | if ( callStackDepth > maxStackDepth ) { |
| 618 | maxStackDepth = callStackDepth; |
| 619 | } |
| 620 | |
| 621 | if ( !func ) { |
| 622 | Error( "NULL function" ); |
| 623 | } |
| 624 | |
| 625 | if ( debug ) { |
| 626 | if ( currentFunction ) { |
| 627 | gameLocal.Printf( "%d: call '%s' from '%s'(line %d)%s\n", gameLocal.time, func->Name(), currentFunction->Name(), |
| 628 | gameLocal.program.GetStatement( instructionPointer ).linenumber, clearStack ? " clear stack" : "" ); |
| 629 | } else { |
| 630 | gameLocal.Printf( "%d: call '%s'%s\n", gameLocal.time, func->Name(), clearStack ? " clear stack" : "" ); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | currentFunction = func; |
| 635 | assert( !func->eventdef ); |
| 636 | NextInstruction( func->firstStatement ); |
| 637 | |
| 638 | // allocate space on the stack for locals |
| 639 | // parms are already on stack |
| 640 | c = func->locals - func->parmTotal; |
| 641 | assert( c >= 0 ); |
| 642 | |
| 643 | if ( localstackUsed + c > LOCALSTACK_SIZE ) { |
| 644 | Error( "EnterFuncton: locals stack overflow\n" ); |
| 645 | } |
| 646 | |
| 647 | // initialize local stack variables to zero |
| 648 | memset( &localstack[ localstackUsed ], 0, c ); |
| 649 | |
| 650 | localstackUsed += c; |
| 651 | localstackBase = localstackUsed - func->locals; |
no test coverage detected