| 500 | }; |
| 501 | |
| 502 | void Context::runInitScript ( ) { |
| 503 | DAS_ASSERTF(insideContext==0,"can't run init script on the locked context"); |
| 504 | char * EP, *SP; |
| 505 | if(!stack.push(globalInitStackSize,EP,SP)) { |
| 506 | throw_error("stack overflow in the initialization script"); |
| 507 | return; |
| 508 | } |
| 509 | vec4f args[2] = { |
| 510 | cast<void *>::from(this), |
| 511 | cast<bool>::from(sharedOwner) // only init shared if we are the owner |
| 512 | }; |
| 513 | abiArg = args; |
| 514 | abiCMRES = nullptr; |
| 515 | if (globals) memset(globals, 0, globalsSize); |
| 516 | if ( aotInitScript ) { |
| 517 | aotInitScript->eval(*this); |
| 518 | } else if ( jitInitScript ) { |
| 519 | jitInitScript(this); |
| 520 | } else { |
| 521 | #if DAS_ENABLE_STACK_WALK |
| 522 | FuncInfo finfo; |
| 523 | memset(&finfo, 0, sizeof(finfo)); |
| 524 | finfo.name = (char *) "Context::runInitScript"; |
| 525 | // TODO: init arguments? |
| 526 | #endif |
| 527 | for ( int i=0, is=totalVariables; i!=is && !stopFlags; ++i ) { |
| 528 | auto & pv = globalVariables[i]; |
| 529 | if ( pv.init ) { |
| 530 | if ( sharedOwner || !pv.shared ) { |
| 531 | #if DAS_ENABLE_STACK_WALK |
| 532 | finfo.stackSize = globalInitStackSize; |
| 533 | Prologue * pp = (Prologue *)stack.sp(); |
| 534 | pp->info = &finfo; |
| 535 | pp->arguments = nullptr; // TODO: args |
| 536 | pp->cmres = nullptr; |
| 537 | pp->line = &pv.init->debugInfo; |
| 538 | #endif |
| 539 | pv.init->eval(*this); |
| 540 | #if DAS_ENABLE_STACK_WALK |
| 541 | pp->info = nullptr; |
| 542 | #endif |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | } |
| 547 | abiArg = nullptr; |
| 548 | stack.pop(EP,SP); |
| 549 | // run init functions |
| 550 | for ( int j=0, js=totalInitFunctions; j!=js && !stopFlags; ++j ) { |
| 551 | auto & pf = initFunctions[j]; |
| 552 | callOrFastcall(pf, nullptr, 0); |
| 553 | } |
| 554 | // now, share the data |
| 555 | if ( sharedOwner && shared ) { |
| 556 | SharedDataWalker sdw; |
| 557 | for ( int i=0, is=totalVariables; i!=is; ++i ) { |
| 558 | auto & pv = globalVariables[i]; |
| 559 | if ( pv.init && pv.shared ) { |