int main(int argc, char *argv[]) { setJump(); if (argc > 1) recur(2); doJump(); printf("Back at main\n"); exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { int nvar; register int rvar; volatile int vvar; nvar = 111; rvar = 222; vvar = 333; if (setjmp(env) == 0) { nvar = 777; rvar = 888; vvar = 999; doJump(nvar, rvar, vvar); } else { printf("After longjmp(): nvar=%d rvar=%d vvar=%d\n", nvar, rvar, vvar); } exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { int nvar; register int rvar; /* Allocated in register if possible */ volatile int vvar; nvar = 111; rvar = 222; vvar = 333; if (setjmp(env) == 0) { /* Code executed after setjmp() */ nvar = 777; rvar = 888; vvar = 999; doJump(nvar, rvar, vvar); } else { /* Code executed after longjmp() */ printf("After longjmp(): nvar=%d rvar=%d vvar=%d\n", nvar, rvar, vvar); } exit(EXIT_SUCCESS); }
int main(int argc, char** argv) { int nvar; register int rvar; // Allocate to register if it can volatile int vvar; nvar = 111; rvar = 222; vvar = 333; /* Run afger setjmp() */ if (setjmp(env) == 0) { nvar = 777; rvar = 888; vvar = 999; doJump(nvar, rvar, vvar); }else { printf("After longjmp(): nvar=%d, rvar=%d, vvar=%d\n", nvar, rvar, vvar); } exit(EXIT_SUCCESS); }
/* * setjmp调用只能再无需临时存储的表达式中使用,例如: * s = setjmp(env); //这个语句是不符合标准的,setjmp只能再下面一些语境中使用: * 1.if switch while等控制表达式 * 2.一元操作符! * 3.比较操作符 * 4.独立的函数调用 * * 注意: * longjmp调用不能跳转到一个已经返回的函数中 SUSv3规定: 如果从嵌套的信号处理器中调用longjmp函数,则该程序是行为 * 未定义的 * * 编译器优化导致longjmp操作过程中经过优化的变量被赋以错误值,解决办法就是设置这些变量为voliate.告诉编译器不对其进行 * 优化 */ int main(int argc,char *argv[]) { int nvar; register int rvar; volatile int vvar; nvar = 111; rvar = 222; vvar = 333; if(setjmp(env) == 0) { nvar = 777; rvar = 888; vvar = 999; doJump(nvar,rvar,vvar); } else { printf("after longjmp(): nvar=%d rvar=%d vvar=%d\n",nvar,rvar,vvar); } exit(EXIT_SUCCESS); //int ret = setjmp(env); //WARN /* switch(setjmp(env)) { case 0: printf("Calling f1() after initial setjmp()\n"); f1(argc); break; case 1: printf("We jumped back from f1()\n"); break; case 2: printf("We jumped back from f2()\n"); break; } */ }
int main(int argc, char *argv[]) { int nvar; register int rvar; // allocate in register if possible volatile int vvar; // allocate in see text nvar = 111; rvar = 222; vvar = 333; // code executed after setjmp() if (setjmp(env) == 0) { nvar = 777; rvar = 888; vvar = 999; doJump(nvar, rvar, vvar); // coming from doJump } else { printf("After longjmp(): nvar=%d, rvar=%d, vvar=%d\n", nvar, rvar, vvar); } exit(EXIT_SUCCESS); }
void Player::step(float frame, float time) { this->time = time; applyImpulse(frame); run->apply(skeleton.get(), time, true); skeleton->getRootBone()->x = X_OFFSET; skeleton->getRootBone()->y = Y_OFFSET; skeleton->updateWorldTransform(); b2Vec2 speed = body->GetLinearVelocity(); sync(); if(speed.y > 1 && !isGrounded()) { setState(PlayerFalling); } else if(state == PlayerFalling && speed.y > -0.1){ setState(PlayerStanding); } else if(state == PlayerPreJump){ if(time > jumpStart + 0.05) doJump(); } else if(state == PlayerRunning && (impulse == ImpulseNone || impulse == ImpulseBoth) && speed.x < 0.1 && speed.x > -0.1){ setState(PlayerStanding); } }
void Interpreter::Start() { // initialization method = GetFrame()->GetMethod(); currentBytecodes = method->GetBytecodes(); void* loopTargets[] = { &&LABEL_BC_HALT, &&LABEL_BC_DUP, &&LABEL_BC_PUSH_LOCAL, &&LABEL_BC_PUSH_ARGUMENT, &&LABEL_BC_PUSH_FIELD, &&LABEL_BC_PUSH_BLOCK, &&LABEL_BC_PUSH_CONSTANT, &&LABEL_BC_PUSH_GLOBAL, &&LABEL_BC_POP, &&LABEL_BC_POP_LOCAL, &&LABEL_BC_POP_ARGUMENT, &&LABEL_BC_POP_FIELD, &&LABEL_BC_SEND, &&LABEL_BC_SUPER_SEND, &&LABEL_BC_RETURN_LOCAL, &&LABEL_BC_RETURN_NON_LOCAL, &&LABEL_BC_JUMP_IF_FALSE, &&LABEL_BC_JUMP_IF_TRUE, &&LABEL_BC_JUMP }; goto *loopTargets[currentBytecodes[bytecodeIndexGlobal]]; // // THIS IS THE former interpretation loop LABEL_BC_HALT: PROLOGUE(1); return; // handle the halt bytecode LABEL_BC_DUP: PROLOGUE(1); doDup(); DISPATCH_NOGC(); LABEL_BC_PUSH_LOCAL: PROLOGUE(3); doPushLocal(bytecodeIndexGlobal - 3); DISPATCH_NOGC(); LABEL_BC_PUSH_ARGUMENT: PROLOGUE(3); doPushArgument(bytecodeIndexGlobal - 3); DISPATCH_NOGC(); LABEL_BC_PUSH_FIELD: PROLOGUE(2); doPushField(bytecodeIndexGlobal - 2); DISPATCH_NOGC(); LABEL_BC_PUSH_BLOCK: PROLOGUE(2); doPushBlock(bytecodeIndexGlobal - 2); DISPATCH_GC(); LABEL_BC_PUSH_CONSTANT: PROLOGUE(2); doPushConstant(bytecodeIndexGlobal - 2); DISPATCH_NOGC(); LABEL_BC_PUSH_GLOBAL: PROLOGUE(2); doPushGlobal(bytecodeIndexGlobal - 2); DISPATCH_GC(); LABEL_BC_POP: PROLOGUE(1); doPop(); DISPATCH_NOGC(); LABEL_BC_POP_LOCAL: PROLOGUE(3); doPopLocal(bytecodeIndexGlobal - 3); DISPATCH_NOGC(); LABEL_BC_POP_ARGUMENT: PROLOGUE(3); doPopArgument(bytecodeIndexGlobal - 3); DISPATCH_NOGC(); LABEL_BC_POP_FIELD: PROLOGUE(2); doPopField(bytecodeIndexGlobal - 2); DISPATCH_NOGC(); LABEL_BC_SEND: PROLOGUE(2); doSend(bytecodeIndexGlobal - 2); DISPATCH_GC(); LABEL_BC_SUPER_SEND: PROLOGUE(2); doSuperSend(bytecodeIndexGlobal - 2); DISPATCH_GC(); LABEL_BC_RETURN_LOCAL: PROLOGUE(1); doReturnLocal(); DISPATCH_NOGC(); LABEL_BC_RETURN_NON_LOCAL: PROLOGUE(1); doReturnNonLocal(); DISPATCH_NOGC(); LABEL_BC_JUMP_IF_FALSE: PROLOGUE(5); doJumpIfFalse(bytecodeIndexGlobal - 5); DISPATCH_NOGC(); LABEL_BC_JUMP_IF_TRUE: PROLOGUE(5); doJumpIfTrue(bytecodeIndexGlobal - 5); DISPATCH_NOGC(); LABEL_BC_JUMP: PROLOGUE(5); doJump(bytecodeIndexGlobal - 5); DISPATCH_NOGC(); } VMFrame* Interpreter::PushNewFrame(VMMethod* method) { SetFrame(GetUniverse()->NewFrame(GetFrame(), method)); return GetFrame(); }
void Interpreter::doJumpIfTrue(long bytecodeIndex) { vm_oop_t value = GetFrame()->Pop(); if (value == load_ptr(trueObject)) doJump(bytecodeIndex); }
static COLDFIRE_DISPATCH_FN(morphJSR) {doJump(info->instruction, info->thisPC, True, info->instrSize, info->type);}