• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ GETARG_C函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中GETARG_C函数的典型用法代码示例。如果您正苦于以下问题:C++ GETARG_C函数的具体用法?C++ GETARG_C怎么用?C++ GETARG_C使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了GETARG_C函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: patchtestreg

static int patchtestreg (FuncState *fs, int node, int reg) {
  Instruction *i = getjumpcontrol(fs, node);
  if (GET_OPCODE(*i) != OP_TESTSET)
    return 0;  /* cannot patch other instructions */
  if (reg != NO_REG && reg != GETARG_B(*i))
    SETARG_A(*i, reg);
  else  /* no register to put value or register already has the value */
    *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));

  return 1;
}
开发者ID:ggreco,项目名称:lpcgame,代码行数:11,代码来源:lcode.c


示例2: luaV_finishOp

/*
** finish execution of an opcode interrupted by an yield
*/
void luaV_finishOp (lua_State *L) {
  CallInfo *ci = L->ci;
  StkId base = ci->u.l.base;
  Instruction inst = *(ci->u.l.savedpc - 1);  /* interrupted instruction */
  OpCode op = GET_OPCODE(inst);
  switch (op) {  /* finish its execution */
    case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV:
    case OP_MOD: case OP_POW: case OP_UNM: case OP_LEN:
    case OP_GETTABUP: case OP_GETTABLE: case OP_SELF: {
      setobjs2s(L, base + GETARG_A(inst), --L->top);
      break;
    }
    case OP_LE: case OP_LT: case OP_EQ: {
      int res = !l_isfalse(L->top - 1);
      L->top--;
      /* metamethod should not be called when operand is K */
      lua_assert(!ISK(GETARG_B(inst)));
      if (op == OP_LE &&  /* "<=" using "<" instead? */
          ttisnil(luaT_gettmbyobj(L, base + GETARG_B(inst), TM_LE)))
        res = !res;  /* invert result */
      lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP);
      if (res != GETARG_A(inst))  /* condition failed? */
        ci->u.l.savedpc++;  /* skip jump instruction */
      break;
    }
    case OP_CONCAT: {
      StkId top = L->top - 1;  /* top when 'call_binTM' was called */
      int b = GETARG_B(inst);      /* first element to concatenate */
      int total = cast_int(top - 1 - (base + b));  /* yet to concatenate */
      setobj2s(L, top - 2, top);  /* put TM result in proper position */
      if (total > 1) {  /* are there elements to concat? */
        L->top = top - 1;  /* top is one after last element (at top-2) */
        luaV_concat(L, total);  /* concat them (may yield again) */
      }
      /* move final result to final position */
      setobj2s(L, ci->u.l.base + GETARG_A(inst), L->top - 1);
      L->top = ci->top;  /* restore top */
      break;
    }
    case OP_TFORCALL: {
      lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_TFORLOOP);
      L->top = ci->top;  /* correct top */
      break;
    }
    case OP_CALL: {
      if (GETARG_C(inst) - 1 >= 0)  /* nresults >= 0? */
        L->top = ci->top;  /* adjust results */
      break;
    }
    case OP_TAILCALL: case OP_SETTABUP:  case OP_SETTABLE:
      break;
    default: lua_assert(0);
  }
}
开发者ID:lriki,项目名称:Volkoff,代码行数:57,代码来源:lvm.c


示例3: do_getinstruction

static int do_getinstruction(lua_State *L)	/** getinstruction(f,i) */
{
 const Proto* f=Pget(L,1);
 int pc=luaL_checkinteger(L,2);
 if (pc<=0 || pc>f->sizecode || f->code==NULL) return 0;
 pc--;
 {
 const Instruction* code=f->code;
 Instruction i=code[pc];
 OpCode o=GET_OPCODE(i);
 int a=GETARG_A(i);
 int b=GETARG_B(i);
 int c=GETARG_C(i);
 int bx=GETARG_Bx(i);
 int sbx=GETARG_sBx(i);
 int line=getline(f,pc);
 if (line>0) lua_pushinteger(L,line); else lua_pushnil(L);
 lua_pushstring(L,luaP_opnames[o]);
 switch (getOpMode(o))
 {
  case iABC:
   lua_pushinteger(L,a);
   if (getBMode(o)!=OpArgN) lua_pushinteger(L,ISK(b) ? (-1-INDEXK(b)) : b);
   else lua_pushnil(L);
   if (getCMode(o)!=OpArgN) lua_pushinteger(L,ISK(c) ? (-1-INDEXK(c)) : c);
   else lua_pushnil(L);
   break;
  case iABx:
   lua_pushinteger(L,a);
   if (getBMode(o)==OpArgK) lua_pushinteger(L,-1-bx); else lua_pushinteger(L,bx);
   lua_pushnil(L);
   break;
  case iAsBx:
   if (o!=OP_JMP) lua_pushinteger(L,a);
   lua_pushinteger(L,sbx);
   lua_pushnil(L);
   break;
 }
 switch (o)
 {
   case OP_JMP:
   case OP_FORLOOP:
   case OP_FORPREP:
    lua_pop(L,1);
    lua_pushinteger(L,sbx+pc+2);
    lua_pushnil(L);
    break;
   default:
    break;
 }
 }
 return 5;
}
开发者ID:Stevie-O,项目名称:SharpLua,代码行数:53,代码来源:lbci.c


示例4: luaK_setoneret

/*
** Fix an expression to return one result.
** If expression is not a multi-ret expression (function call or
** vararg), it already returns one result, so nothing needs to be done.
** Function calls become VNONRELOC expressions (as its result comes
** fixed in the base register of the call), while vararg expressions
** become VRELOCABLE (as OP_VARARG puts its results where it wants).
** (Calls are created returning one result, so that does not need
** to be fixed.)
*/
void luaK_setoneret (FuncState *fs, expdesc *e) {
  if (e->k == VCALL) {  /* expression is an open function call? */
    /* already returns 1 value */
    lua_assert(GETARG_C(getinstruction(fs, e)) == 2);
    e->k = VNONRELOC;  /* result has fixed position */
    e->u.info = GETARG_A(getinstruction(fs, e));
  }
  else if (e->k == VVARARG) {
    SETARG_B(getinstruction(fs, e), 2);
    e->k = VRELOCABLE;  /* can relocate its simple result */
  }
}
开发者ID:celskeggs,项目名称:selkie,代码行数:22,代码来源:lcode.c


示例5: ci_func

static const char *getobjname (CallInfo *ci, int stackpos, const char **name) {
    if (isLua(ci)) {  /* a Lua function? */
        Proto *p = ci_func(ci)->l.p;
        int pc = currentpc(ci);
        Instruction i;
        *name = luaF_getlocalname(p, stackpos+1, pc);
        if (*name)  /* is a local? */
            return "local";
        i = luaG_symbexec(p, pc, stackpos);  /* try symbolic execution */
        lua_assert(pc != -1);
        switch (GET_OPCODE(i)) {
        case OP_GETGLOBAL: {
            int g = GETARG_Bx(i);  /* global index */
            lua_assert(ttisstring(&p->k[g]));
            *name = svalue(&p->k[g]);
            return "global";
        }
        case OP_MOVE: {
            int a = GETARG_A(i);
            int b = GETARG_B(i);  /* move from `b' to `a' */
            if (b < a)
                return getobjname(ci, b, name);  /* get name for `b' */
            break;
        }
        case OP_GETTABLE: {
            int k = GETARG_C(i);  /* key index */
            *name = kname(p, k);
            return "field";
        }
        case OP_SELF: {
            int k = GETARG_C(i);  /* key index */
            *name = kname(p, k);
            return "method";
        }
        default:
            break;
        }
    }
    return NULL;  /* no useful name found */
}
开发者ID:0xmono,项目名称:miranda-ng,代码行数:40,代码来源:ldebug.c


示例6: Opcode

Logical::Logical(CompilerState& cs, Stack& stack) :
    Opcode(cs, stack),
    ra_(stack.GetR(GETARG_A(cs.instr_))),
    rkb_(stack.GetRK(GETARG_B(cs.instr_))),
    rkc_(stack.GetRK(GETARG_C(cs.instr_))),
    trytm_(cs.CreateSubBlock("trytm")) {
    
    assert(GET_OPCODE(cs.instr_) == OP_BAND ||
           GET_OPCODE(cs.instr_) == OP_BOR ||
           GET_OPCODE(cs.instr_) == OP_BXOR ||
           GET_OPCODE(cs.instr_) == OP_SHL ||
           GET_OPCODE(cs.instr_) == OP_SHR);
}
开发者ID:gligneul,项目名称:Lua-Low-Level,代码行数:13,代码来源:llllogical.cpp


示例7: CompileCmp

void Compiler::CompileCmp(const std::string& function) {
    auto& rkb = stack_.GetRK(GETARG_B(cs_.instr_));
    auto& rkc = stack_.GetRK(GETARG_C(cs_.instr_));
    auto args = {cs_.values_.state, rkb.GetTValue(), rkc.GetTValue()};
    auto result = cs_.CreateCall(function, args, "result");
    stack_.Update();

    auto a = cs_.MakeInt(GETARG_A(cs_.instr_));
    auto cmp = cs_.B_.CreateICmpNE(result, a, "cmp");
    auto nextblock = cs_.blocks_[cs_.curr_ + 2];
    auto jmpblock = cs_.blocks_[cs_.curr_ + 1];
    cs_.B_.CreateCondBr(cmp, nextblock, jmpblock);
}
开发者ID:gligneul,项目名称:Lua-Low-Level,代码行数:13,代码来源:lllcompiler.cpp


示例8: Opcode

Arith::Arith(CompilerState& cs, Stack& stack) :
    Opcode(cs, stack),
    ra_(stack.GetR(GETARG_A(cs.instr_))),
    rkb_(stack.GetRK(GETARG_B(cs.instr_))),
    rkc_(stack.GetRK(GETARG_C(cs.instr_))),
    x_(rkb_),
    y_(rkc_),
    check_y_(cs.CreateSubBlock("check_y")),
    intop_(cs.CreateSubBlock("intop", check_y_)),
    floatop_(cs.CreateSubBlock("floatop", intop_)),
    tmop_(cs.CreateSubBlock("tmop", floatop_)),
    x_int_(nullptr),
    x_float_(nullptr) {
}
开发者ID:gligneul,项目名称:Lua-Low-Level,代码行数:14,代码来源:lllarith.cpp


示例9: GETARG_A

void Compiler::CompileCall() {
    int a = GETARG_A(cs_.instr_);
    int b = GETARG_B(cs_.instr_);
    if (b != 0)
        cs_.SetTop(a + b);
    auto& ra = stack_.GetR(a);
    auto args = {
        cs_.values_.state,
        ra.GetTValue(),
        cs_.MakeInt(GETARG_C(cs_.instr_) - 1)
    };
    cs_.CreateCall("luaD_callnoyield", args);
    stack_.Update();
}
开发者ID:gligneul,项目名称:Lua-Low-Level,代码行数:14,代码来源:lllcompiler.cpp


示例10: patchtestreg

/* Patch register of test instructions. */
static int patchtestreg (FuncState *fs, int node, int reg) {
  Instruction *i = getjumpcontrol(fs, node);
  if (GET_OPCODE(*i) != OP_TESTSET)
    return 0;  /* cannot patch other instructions */
  if (reg != NO_REG && reg != GETARG_B(*i)) {
    SETARG_A(*i, reg);
    DEBUG_CODEGEN(raviY_printf(fs, "[?]* %o ; set A to %d\n", *i, reg));
  }
  else  /* no register to put value or register already has the value */ {
    *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));
    DEBUG_CODEGEN(raviY_printf(fs, "[?]* %o ; generate OP_TEST\n", *i));
  }

  return 1;
}
开发者ID:galek,项目名称:ravi,代码行数:16,代码来源:lcode.c


示例11: patch_irep

static void
patch_irep(mrb_state *mrb, mrb_irep *irep, int bnest)
{
  size_t i;
  mrb_code c;

  for (i = 0; i < irep->rlen; i++) {
    patch_irep(mrb, irep->reps[i], bnest + 1);
  }

  for (i = 0; i < irep->ilen; i++) {
    c = irep->iseq[i];
    switch(GET_OPCODE(c)){
    case OP_SEND:
      if (GETARG_C(c) != 0) {
        break;
      }
      {
        mrb_code arg = search_variable(mrb, irep->syms[GETARG_B(c)], bnest);
        if (arg != 0) {
          /* must replace */
          irep->iseq[i] = MKOPCODE(OP_GETUPVAR) | MKARG_A(GETARG_A(c)) | arg;
        }
      }
      break;

    case OP_MOVE:
      /* src part */
      if (GETARG_B(c) < irep->nlocals) {
        mrb_code arg = search_variable(mrb, irep->lv[GETARG_B(c) - 1].name, bnest);
        if (arg != 0) {
          /* must replace */
          irep->iseq[i] = MKOPCODE(OP_GETUPVAR) | MKARG_A(GETARG_A(c)) | arg;
        }
      }
      /* dst part */
      if (GETARG_A(c) < irep->nlocals) {
        mrb_code arg = search_variable(mrb, irep->lv[GETARG_A(c) - 1].name, bnest);
        if (arg != 0) {
          /* must replace */
          irep->iseq[i] = MKOPCODE(OP_SETUPVAR) | MKARG_A(GETARG_B(c)) | arg;
        }
      }
      break;
    }
  }
}
开发者ID:AE9RB,项目名称:mruby-complex,代码行数:47,代码来源:eval.c


示例12: print_op

/* helper function to print out the opcode
 * as well as the arguments
 */
static void print_op(bInst op)
{
    int args = opcode_args[GET_OPCODE(op)];
    printf("\t%s", opcode_names[GET_OPCODE(op)]);
    if (args == ARG_NONE)
        return;
    if (HASARG_A(args))
        printf(" %d", GETARG_A(op));
    if (HASARG_B(args))
        printf(" %d", GETARG_B(op));
    if (HASARG_C(args))
        printf(" %d", GETARG_C(op));
    if (HASARG_Bx(args))
        printf(" %d", GETARG_Bx(op));
    if (HASARG_sBx(args))
        printf(" %d", GETARG_sBx(op));
    return;
}
开发者ID:erik,项目名称:bijou,代码行数:21,代码来源:block.c


示例13: ju_bytecode

/* local op, a, b, c, test = jit.util.bytecode(func, pc) */
static int ju_bytecode(lua_State *L)
{
  Proto *pt = check_LCL(L)->l.p;
  int pc = luaL_checkint(L, 2);
  if (pc >= 1 && pc <= pt->sizecode) {
    Instruction ins = pt->code[pc-1];
    OpCode op = GET_OPCODE(ins);
    if (pc > 1 && (((int)OP_SETLIST) << POS_OP) ==
	(pt->code[pc-2] & (MASK1(SIZE_OP,POS_OP) | MASK1(SIZE_C,POS_C)))) {
      lua_pushstring(L, luaP_opnames[OP_SETLIST]);
      lua_pushnumber(L, (lua_Number)ins);  /* Fake extended op. */
      return 1;
    }
    if (op >= NUM_OPCODES) return 0;  /* Just in case. */
    lua_pushstring(L, luaP_opnames[op]);
    lua_pushinteger(L, GETARG_A(ins));
    switch (getOpMode(op)) {
    case iABC: {
      int b = GETARG_B(ins), c = GETARG_C(ins);
      switch (getBMode(op)) {
      case OpArgN: lua_pushnil(L); break;
      case OpArgK: if (ISK(b)) b = -1-INDEXK(b);
      case OpArgR: case OpArgU: lua_pushinteger(L, b); break;
      }
      switch (getCMode(op)) {
      case OpArgN: lua_pushnil(L); break;
      case OpArgK: if (ISK(c)) c = -1-INDEXK(c);
      case OpArgR: case OpArgU: lua_pushinteger(L, c); break;
      }
      lua_pushboolean(L, testTMode(op));
      return 5;
    }
    case iABx: {
      int bx = GETARG_Bx(ins);
      lua_pushinteger(L, getBMode(op) == OpArgK ? -1-bx : bx);
      return 3;
    }
    case iAsBx:
      lua_pushinteger(L, GETARG_sBx(ins));
      return 3;
    }
  }
  return 0;
}
开发者ID:Neoniet,项目名称:upspring,代码行数:45,代码来源:ljitlib.c


示例14: CompileTestset

void Compiler::CompileTestset() {
    auto checkbool = cs_.CreateSubBlock("checkbool");
    auto checkfalse = cs_.CreateSubBlock("checkfalse", checkbool);
    auto fail = cs_.CreateSubBlock("set", checkfalse);
    auto success = cs_.blocks_[cs_.curr_ + 2];

    auto& r = stack_.GetR(GETARG_B(cs_.instr_));
    if (GETARG_C(cs_.instr_)) {
        auto isnil = r.HasTag(LUA_TNIL);
        cs_.B_.CreateCondBr(isnil, success, checkbool);

        cs_.B_.SetInsertPoint(checkbool);
        auto isbool = r.HasTag(LUA_TBOOLEAN);
        cs_.B_.CreateCondBr(isbool, checkfalse, fail);

        cs_.B_.SetInsertPoint(checkfalse);
        auto bvalue = r.GetBoolean();
        auto isfalse = cs_.B_.CreateICmpEQ(bvalue, cs_.MakeInt(0));
        cs_.B_.CreateCondBr(isfalse, success, fail);
    } else {
        auto isnil = r.HasTag(LUA_TNIL);
        cs_.B_.CreateCondBr(isnil, fail, checkbool);

        cs_.B_.SetInsertPoint(checkbool);
        auto isbool = r.HasTag(LUA_TBOOLEAN);
        cs_.B_.CreateCondBr(isbool, checkfalse, success);

        cs_.B_.SetInsertPoint(checkfalse);
        auto bvalue = r.GetBoolean();
        auto isfalse = cs_.B_.CreateICmpEQ(bvalue, cs_.MakeInt(0));
        cs_.B_.CreateCondBr(isfalse, fail, success);
    }

    cs_.B_.SetInsertPoint(fail);
    auto& ra = stack_.GetR(GETARG_A(cs_.instr_));
    ra.Assign(r);
    cs_.B_.CreateBr(cs_.blocks_[cs_.curr_ + 1]);
}
开发者ID:gligneul,项目名称:Lua-Low-Level,代码行数:38,代码来源:lllcompiler.cpp


示例15: luaK_patchlistaux

static void luaK_patchlistaux (FuncState *fs, int list,
          int ttarget, int treg, int ftarget, int freg, int dtarget) {
  while (list != NO_JUMP) {
    int next = luaK_getjump(fs, list);
    Instruction *i = getjumpcontrol(fs, list);
    if (GET_OPCODE(*i) != OP_TEST) {
      lua_assert(dtarget != NO_JUMP);
      luaK_fixjump(fs, list, dtarget);  /* jump to default target */
    }
    else {
      if (GETARG_C(*i)) {
        lua_assert(ttarget != NO_JUMP);
        patchtestreg(i, treg);
        luaK_fixjump(fs, list, ttarget);
      }
      else {
        lua_assert(ftarget != NO_JUMP);
        patchtestreg(i, freg);
        luaK_fixjump(fs, list, ftarget);
      }
    }
    list = next;
  }
}
开发者ID:yuanxiubin1128,项目名称:mmo-resourse,代码行数:24,代码来源:lcode.c


示例16: patchtestreg

static void patchtestreg (Instruction *i, int reg) {
  if (reg != NO_REG)
    SETARG_A(*i, reg);
  else  /* no register to put value; change TESTSET to TEST */
    *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i));
}
开发者ID:OLR-xray,项目名称:XRay-NEW,代码行数:6,代码来源:lcode.c


示例17: luaV_execute

void luaV_execute (lua_State *L, int nexeccalls) {
  LClosure *cl;
  StkId base;
  TValue *k;
  const Instruction *pc;
 reentry:  /* entry point */
  lua_assert(isLua(L->ci));
  pc = L->savedpc;
  cl = &clvalue(L->ci->func)->l;
  base = L->base;
  k = cl->p->k;
  /* main loop of interpreter */
  for (;;) {
    const Instruction i = *pc++;
    StkId ra;
    if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
        (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {
      traceexec(L, pc);
      if (L->status == LUA_YIELD) {  /* did hook yield? */
        L->savedpc = pc - 1;
        return;
      }
      base = L->base;
    }
    /* warning!! several calls may realloc the stack and invalidate `ra' */
    ra = RA(i);
    lua_assert(base == L->base && L->base == L->ci->base);
    lua_assert(base <= L->top && L->top <= L->stack + L->stacksize);
    lua_assert(L->top == L->ci->top || luaG_checkopenop(i));
    switch (GET_OPCODE(i)) {
      case OP_MOVE: {
        setobjs2s(L, ra, RB(i));
        continue;
      }
      case OP_LOADK: {
        setobj2s(L, ra, KBx(i));
        continue;
      }
      case OP_LOADBOOL: {
        setbvalue(ra, GETARG_B(i));
        if (GETARG_C(i)) pc++;  /* skip next instruction (if C) */
        continue;
      }
      case OP_LOADNIL: {
        TValue *rb = RB(i);
        do {
          setnilvalue(rb--);
        } while (rb >= ra);
        continue;
      }
      case OP_GETUPVAL: {
        int b = GETARG_B(i);
        setobj2s(L, ra, cl->upvals[b]->v);
        continue;
      }
      case OP_GETGLOBAL: {
        TValue g;
        TValue *rb = KBx(i);
        sethvalue(L, &g, cl->env);
        lua_assert(ttisstring(rb));
        Protect(luaV_gettable(L, &g, rb, ra));
        continue;
      }
      case OP_GETTABLE: {
        Protect(luaV_gettable(L, RB(i), RKC(i), ra));
        continue;
      }
      case OP_SETGLOBAL: {
        TValue g;
        sethvalue(L, &g, cl->env);
        lua_assert(ttisstring(KBx(i)));
        Protect(luaV_settable(L, &g, KBx(i), ra));
        continue;
      }
      case OP_SETUPVAL: {
        UpVal *uv = cl->upvals[GETARG_B(i)];
        setobj(L, uv->v, ra);
        luaC_barrier(L, uv, ra);
        continue;
      }
      case OP_SETTABLE: {
        Protect(luaV_settable(L, ra, RKB(i), RKC(i)));
        continue;
      }
      case OP_NEWTABLE: {
        int b = GETARG_B(i);
        int c = GETARG_C(i);
        sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c)));
        Protect(luaC_checkGC(L));
        continue;
      }
      case OP_SELF: {
        StkId rb = RB(i);
        setobjs2s(L, ra+1, rb);
        Protect(luaV_gettable(L, rb, RKC(i), ra));
        continue;
      }
      case OP_ADD: {
        arith_op(luai_numadd, TM_ADD);
        continue;
//.........这里部分代码省略.........
开发者ID:angryzor,项目名称:luajit-tilepro64,代码行数:101,代码来源:lvm.c


示例18: luaV_execute

StkId luaV_execute (lua_State *L) {
  LClosure *cl;
  TObject *k;
  const Instruction *pc;
 callentry:  /* entry point when calling new functions */
  L->ci->u.l.pc = &pc;
  if (L->hookmask & LUA_MASKCALL)
    luaD_callhook(L, LUA_HOOKCALL, -1);
 retentry:  /* entry point when returning to old functions */
  lua_assert(L->ci->state == CI_SAVEDPC ||
             L->ci->state == (CI_SAVEDPC | CI_CALLING));
  L->ci->state = CI_HASFRAME;  /* activate frame */
  pc = L->ci->u.l.savedpc;
  cl = &clvalue(L->base - 1)->l;
  k = cl->p->k;
  /* main loop of interpreter */
  for (;;) {
    const Instruction i = *pc++;
    StkId base, ra;
    if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
        (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {
      traceexec(L);
      if (L->ci->state & CI_YIELD) {  /* did hook yield? */
        L->ci->u.l.savedpc = pc - 1;
        L->ci->state = CI_YIELD | CI_SAVEDPC;
        return NULL;
      }
    }
    /* warning!! several calls may realloc the stack and invalidate `ra' */
    base = L->base;
    ra = RA(i);
    lua_assert(L->ci->state & CI_HASFRAME);
    lua_assert(base == L->ci->base);
    lua_assert(L->top <= L->stack + L->stacksize && L->top >= base);
    lua_assert(L->top == L->ci->top ||
         GET_OPCODE(i) == OP_CALL ||   GET_OPCODE(i) == OP_TAILCALL ||
         GET_OPCODE(i) == OP_RETURN || GET_OPCODE(i) == OP_SETLISTO);
    switch (GET_OPCODE(i)) {
      case OP_MOVE: {
        setobjs2s(ra, RB(i));
        break;
      }
      case OP_LOADK: {
        setobj2s(ra, KBx(i));
        break;
      }
      case OP_LOADBOOL: {
        setbvalue(ra, GETARG_B(i));
        if (GETARG_C(i)) pc++;  /* skip next instruction (if C) */
        break;
      }
      case OP_LOADNIL: {
        TObject *rb = RB(i);
        do {
          setnilvalue(rb--);
        } while (rb >= ra);
        break;
      }
      case OP_GETUPVAL: {
        int b = GETARG_B(i);
        setobj2s(ra, cl->upvals[b]->v);
        break;
      }
      case OP_GETGLOBAL: {
        TObject *rb = KBx(i);
        const TObject *v;
        lua_assert(ttisstring(rb) && ttistable(&cl->g));
        v = luaH_getstr(hvalue(&cl->g), tsvalue(rb));
        if (!ttisnil(v)) { setobj2s(ra, v); }
        else
          setobj2s(XRA(i), luaV_index(L, &cl->g, rb, 0));
        break;
      }
      case OP_GETTABLE: {
        StkId rb = RB(i);
        TObject *rc = RKC(i);
        if (ttistable(rb)) {
          const TObject *v = luaH_get(hvalue(rb), rc);
          if (!ttisnil(v)) { setobj2s(ra, v); }
          else
            setobj2s(XRA(i), luaV_index(L, rb, rc, 0));
        }
        else
          setobj2s(XRA(i), luaV_getnotable(L, rb, rc, 0));
        break;
      }
      case OP_SETGLOBAL: {
        lua_assert(ttisstring(KBx(i)) && ttistable(&cl->g));
        luaV_settable(L, &cl->g, KBx(i), ra);
        break;
      }
      case OP_SETUPVAL: {
        int b = GETARG_B(i);
        setobj(cl->upvals[b]->v, ra);  /* write barrier */
        break;
      }
      case OP_SETTABLE: {
        luaV_settable(L, ra, RKB(i), RKC(i));
        break;
      }
//.........这里部分代码省略.........
开发者ID:TheWaWaR,项目名称:my-lua5.0,代码行数:101,代码来源:lvm.c


示例19: PrintCode

static void PrintCode(const Proto* f)
{
 const Instruction* code=f->code;
 int pc,n=f->sizecode;
 for (pc=0; pc<n; pc++)
 {
  Instruction i=code[pc];
  OpCode o=GET_OPCODE(i);
  int a=GETARG_A(i);
  int b=GETARG_B(i);
  int c=GETARG_C(i);
  int ax=GETARG_Ax(i);
  int bx=GETARG_Bx(i);
  int sbx=GETARG_sBx(i);
  int line=getfuncline(f,pc);
  printf("\t%d\t",pc+1);
  if (line>0) printf("[%d]\t",line); else printf("[-]\t");
  printf("%-9s\t",luaP_opnames[o]);
  switch (getOpMode(o))
  {
   case iABC:
    printf("%d",a);
    if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (MYK(INDEXK(b))) : b);
    if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (MYK(INDEXK(c))) : c);
    break;
   case iABx:
    printf("%d",a);
    if (getBMode(o)==OpArgK) printf(" %d",MYK(bx));
    if (getBMode(o)==OpArgU) printf(" %d",bx);
    break;
   case iAsBx:
    printf("%d %d",a,sbx);
    break;
   case iAx:
    printf("%d",MYK(ax));
    break;
  }
  switch (o)
  {
   case OP_LOADK:
    printf("\t; "); PrintConstant(f,bx);
    break;
   case OP_GETUPVAL:
   case OP_SETUPVAL:
    printf("\t; %s",UPVALNAME(b));
    break;
   case OP_GETTABUP:
    printf("\t; %s",UPVALNAME(b));
    if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); }
    break;
   case OP_SETTABUP:
    printf("\t; %s",UPVALNAME(a));
    if (ISK(b)) { printf(" "); PrintConstant(f,INDEXK(b)); }
    if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); }
    break;
   case OP_GETTABLE:
   case OP_SELF:
    if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); }
    break;
   case OP_SETTABLE:
   case OP_ADD:
   case OP_SUB:
   case OP_MUL:
   case OP_POW:
   case OP_DIV:
   case OP_IDIV:
   case OP_BAND:
   case OP_BOR:
   case OP_BXOR:
   case OP_SHL:
   case OP_SHR:
   case OP_EQ:
   case OP_LT:
   case OP_LE:
    if (ISK(b) || ISK(c))
    {
     printf("\t; ");
     if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-");
     printf(" ");
     if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-");
    }
    break;
   case OP_JMP:
   case OP_FORLOOP:
   case OP_FORPREP:
   case OP_TFORLOOP:
    printf("\t; to %d",sbx+pc+2);
    break;
   case OP_CLOSURE:
    printf("\t; %p",VOID(f->p[bx]));
    break;
   case OP_SETLIST:
    if (c==0) printf("\t; %d",(int)code[++pc]); else printf("\t; %d",c);
    break;
   case OP_EXTRAARG:
    printf("\t; "); PrintConstant(f,ax);
    break;
   default:
    break;
  }
//.........这里部分代码省略.........
开发者ID:bysdxt,项目名称:xLua,代码行数:101,代码来源:luac.c


示例20: mrb_run


//.........这里部分代码省略.........
      NEXT;
    }

    CASE(OP_GETCONST) {
      /* A B    R(A) := constget(Sym(B)) */
      regs[GETARG_A(i)] = mrb_vm_const_get(mrb, syms[GETARG_Bx(i)]);
      NEXT;
    }

    CASE(OP_SETCONST) {
      /* A B    constset(Sym(B),R(A)) */
      mrb_vm_const_set(mrb, syms[GETARG_Bx(i)], regs[GETARG_A(i)]);
      NEXT;
    }

    CASE(OP_GETMCNST) {
      /* A B C  R(A) := R(C)::Sym(B) */
      int a = GETARG_A(i);

      regs[a] = mrb_const_get(mrb, regs[a], syms[GETARG_Bx(i)]);
      NEXT;
    }

    CASE(OP_SETMCNST) {
      /* A B C  R(A+1)::Sym(B) := R(A) */
      int a = GETARG_A(i);

      mrb_const_set(mrb, regs[a+1], syms[GETARG_Bx(i)], regs[a]);
      NEXT;
    }

    CASE(OP_GETUPVAR) {
      /* A B C  R(A) := uvget(B,C) */
      regs[GETARG_A(i)] = uvget(mrb, GETARG_C(i), GETARG_B(i));
      NEXT;
    }

    CASE(OP_SETUPVAR) {
      /* A B C  uvset(B,C,R(A)) */
      uvset(mrb, GETARG_C(i), GETARG_B(i), regs[GETARG_A(i)]);
      NEXT;
    }

    CASE(OP_JMP) {
      /* sBx    pc+=sBx */
      pc += GETARG_sBx(i);
      JUMP;
    }

    CASE(OP_JMPIF) {
      /* A sBx  if R(A) pc+=sBx */
      if (mrb_test(regs[GETARG_A(i)])) {
        pc += GETARG_sBx(i);
        JUMP;
      }
      NEXT;
    }

    CASE(OP_JMPNOT) {
      /* A sBx  if R(A) pc+=sBx */
      if (!mrb_test(regs[GETARG_A(i)])) {
        pc += GETARG_sBx(i);
        JUMP;
      }
      NEXT;
    }
开发者ID:kstephens,项目名称:mruby,代码行数:67,代码来源:vm.c



注:本文中的GETARG_C函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ GETARRAYNUM函数代码示例发布时间:2022-05-30
下一篇:
C++ GETARG_Bx函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap