Ejemplo n.º 1
0
// Looping assembly ("!do"). Has to be re-entrant.
static enum eos_t PO_do(void) {	// Now GotByte = illegal char
	loopcond_t	condition1,
			condition2;
	input_t		loop_input,
			*outer_input;
	char*		loop_body;
	bool		go_on;
	int		loop_start;// line number of loop pseudo opcode

	// Read head condition to buffer
	SKIPSPACE();
	store_condition(&condition1, CHAR_SOB);
	if(GotByte != CHAR_SOB)
		Throw_serious_error(exception_no_left_brace);
	// Remember line number of loop body,
	// then read block and get copy
	loop_start = Input_now->line_number;
	loop_body = Input_skip_or_store_block(TRUE);	// changes line number!
	// now GotByte = '}'
	NEXTANDSKIPSPACE();// Now GotByte = first non-blank char after block
	// Read tail condition to buffer
	store_condition(&condition2, CHAR_EOS);
	// now GotByte = CHAR_EOS
	// set up new input
	loop_input = *Input_now;// copy current input structure into new
	loop_input.source_is_ram = TRUE;	// set new byte source
	// remember old input
	outer_input = Input_now;
	// activate new input (not useable yet, as pointer and
	// line number are not yet set up)
	Input_now = &loop_input;
	do {
		// Check head condition
		go_on = check_condition(&condition1);
		if(go_on) {
			parse_ram_block(loop_start, loop_body);
			// Check tail condition
			go_on = check_condition(&condition2);
		}
	} while(go_on);
	// Free memory
	free(condition1.body);
	free(loop_body);
	free(condition2.body);
	// restore previous input:
	Input_now = outer_input;
	GotByte = CHAR_EOS;	// CAUTION! Very ugly kluge.
	// But by switching input, we lost the outer input's GotByte. We know
	// it was CHAR_EOS. We could just call GetByte() to get real input, but
	// then the main loop could choke on unexpected bytes. So we pretend
	// that we got the outer input's GotByte value magically back.
	return(AT_EOS_ANYWAY);
}
Ejemplo n.º 2
0
static bool check_conditions(dialogue_node* node) {
	for (auto& i : node->conditions.has_item) {
		if (!check_condition(i)) {
			return false;
		}
	}
	for (auto& i : node->conditions.stat_check) {
		if (!check_condition(i)) {
			return false;
		}
	}
	return true;
}
Ejemplo n.º 3
0
static void simpleexp(LexState* ls, expdesc* v)
{
	/* simpleexp -> NUMBER | STRING | NIL | true | false | ... |
		  constructor | FUNCTION body | primaryexp */
	switch (ls->t.token)
	{
		case TK_NUMBER:
		{
			init_exp(v, VKNUM, 0);
			v->u.nval = ls->t.seminfo.r;
			break;
		}
		case TK_STRING:
		{
			codestring(ls, v, ls->t.seminfo.ts);
			break;
		}
		case TK_NIL:
		{
			init_exp(v, VNIL, 0);
			break;
		}
		case TK_TRUE:
		{
			init_exp(v, VTRUE, 0);
			break;
		}
		case TK_FALSE:
		{
			init_exp(v, VFALSE, 0);
			break;
		}
		case TK_DOTS:	 /* vararg */
		{
			FuncState* fs = ls->fs;
			check_condition(ls, fs->f->is_vararg,
					"cannot use " LUA_QL("...") " outside a vararg function");
			fs->f->is_vararg &= ~VARARG_NEEDSARG;  /* don't need 'arg' */
			init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));
			break;
		}
		case '{':	 /* constructor */
		{
			constructor(ls, v);
			return;
		}
		case TK_FUNCTION:
		{
			luaX_next(ls);
			body(ls, v, 0, ls->linenumber);
			return;
		}
		default:
		{
			primaryexp(ls, v);
			return;
		}
	}
	luaX_next(ls);
}
Ejemplo n.º 4
0
static TString *str_checkname (LexState *ls) {
  TString *ts;
  check_condition(ls, (ls->t.token == TK_NAME), "<name> expected");
  ts = ls->t.seminfo.ts;
  next(ls);
  return ts;
}
Ejemplo n.º 5
0
static inline SEXP signal_condition(SEXP condition, const char * fun) {
    check_condition(condition);
    SEXP call = PROTECT(Rf_lang2(Rf_install(fun), condition));
    Rf_eval(call, R_GlobalEnv);
    UNPROTECT(1);
    return R_NilValue;
}
Ejemplo n.º 6
0
static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
  expdesc e;
  check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED,
                      "syntax error");
  if (testnext(ls, ',')) {  /* assignment -> `,' primaryexp assignment */
    struct LHS_assign nv;
    nv.prev = lh;
    primaryexp(ls, &nv.v);
    if (nv.v.k == VLOCAL)
      check_conflict(ls, lh, &nv.v);
    assignment(ls, &nv, nvars+1);
  }
  else {  /* assignment -> `=' explist1 */
    int nexps;
    checknext(ls, '=');
    nexps = explist1(ls, &e);
    if (nexps != nvars) {
      adjust_assign(ls, nvars, nexps, &e);
      if (nexps > nvars)
        ls->fs->freereg -= nexps - nvars;  /* remove extra values */
    }
    else {
      luaK_setoneret(ls->fs, &e);  /* close last expression */
      luaK_storevar(ls->fs, &lh->v, &e);
      return;  /* avoid default */
    }
  }
  init_exp(&e, VNONRELOC, ls->fs->freereg-1);  /* default assignment */
  luaK_storevar(ls->fs, &lh->v, &e);
}
Ejemplo n.º 7
0
void ldrb_inst(int inst, ARMProc *proc) {
	int i;
	int address;
	int (*func)(int, ARMProc *);
	int rd;
	int data;
	int **rd_ptr;

	if(!check_condition(proc, inst))
                return;

	ls_addr_modes = ls_addressing_dict();
	rd = getbits(inst, 12, 4);

	rd_ptr = &proc->r0;
	rd_ptr += rd;

	for(i = 0; i < LS_ADDRESSING_NUMBER; i++) {
                if(test_inst(ls_addr_modes[i], inst)) {
                        func = ls_addr_modes[i]->execute;
                        address = (*func)(inst, proc);
			break;
                }
        }

	data = read_mem(proc, address, 1);
	**rd_ptr = data;
}
Ejemplo n.º 8
0
void ldr_inst(int inst, ARMProc *proc) {
	int i;
	int address;
	int rd;
	int **rd_ptr;
	int (*func)(int, ARMProc *);
	int data;

	if(!check_condition(proc, inst))
                return;

	ls_addr_modes = ls_addressing_dict();

	for(i = 0; i < LS_ADDRESSING_NUMBER; i++) {
                if(test_inst(ls_addr_modes[i], inst)) {
			printf("Addressing mode: %d\n", i);
                        func = ls_addr_modes[i]->execute;
                        address = (*func)(inst, proc);
			break;
                }
        }

	rd = getbits(inst, 12, 4);
	rd_ptr = &proc->r0;
	rd_ptr += rd;

	data = read_mem(proc, address, 4);

	if(rd == 15) {
		**rd_ptr = data & 0xfffffffe;
	} else {
		**rd_ptr = data;
	}
}
Ejemplo n.º 9
0
static bool rtl88e_phy_config_rf_with_headerfile(struct adapter *adapt)
{
	u32 i;
	u32 array_len = ARRAY_SIZE(Array_RadioA_1T_8188E);
	u32 *array = Array_RadioA_1T_8188E;

	for (i = 0; i < array_len; i += 2) {
		u32 v1 = array[i];
		u32 v2 = array[i+1];

		if (v1 < 0xCDCDCDCD) {
			rtl8188e_config_rf_reg(adapt, v1, v2);
			continue;
		} else {
			if (!check_condition(adapt, array[i])) {
				READ_NEXT_PAIR(v1, v2, i);
				while (v2 != 0xDEAD && v2 != 0xCDEF &&
				       v2 != 0xCDCD && i < array_len - 2)
					READ_NEXT_PAIR(v1, v2, i);
				i -= 2;
			} else {
				READ_NEXT_PAIR(v1, v2, i);
				while (v2 != 0xDEAD && v2 != 0xCDEF &&
				       v2 != 0xCDCD && i < array_len - 2) {
						rtl8188e_config_rf_reg(adapt, v1, v2);
						READ_NEXT_PAIR(v1, v2, i);
				}

				while (v2 != 0xDEAD && i < array_len - 2)
					READ_NEXT_PAIR(v1, v2, i);
			}
		}
	}
	return true;
}
Ejemplo n.º 10
0
void perf_t(char dep) {
	unsigned int i;
	/*char dummy;
	gen_all_captures();*/
	gen_all();
	check_condition();
	dep--;

	for (i = tree.first_move[Ply];i < tree.first_move[Ply + 1];i++) {
		if (verify_move(tree.move_list[i].move)==0) continue;
			if (makemove(tree.move_list[i].move,0)) {
					/*print_board();
					printf("Press any key to continue:");
					 while (!kbhit());
					dummy=getch();*/
					Nodes++;

					if (dep)
						perf_t(dep);

					unmakemove();
					}

			}
	}
Ejemplo n.º 11
0
static void compound (LexState *ls, struct LHS_assign *lh) {
  expdesc rh;
  int nexps;
  BinOpr op;

  check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED,
                      "syntax error");
  /* parse Compound operation. */
  op = getcompopr(ls->t.token);
  luaX_next(ls);

  /* parse right-hand expression */
  nexps = explist1(ls, &rh);
  check_condition(ls, nexps == 1, "syntax error");

  luaK_posfix(ls->fs, op, &(lh->v), &rh);
}
Ejemplo n.º 12
0
/*Verifica la correttezza della funzione di scacco*/
void check_correct() {
	char p0[] = "1k1r4/pp1b1R2/3qp1pp/8/3B4/4Q3/PPP2B2/3K4 w - - 0 1";
	char p1[] = "1k1r4/pp1b1R2/3qp1pp/8/3B4/3Q4/PPP2B2/3K4 w - - 0 1";

	set_position(p0);
	init_data();
	print_board();
	printf("In this position white king is under x attack\n");
	printf("Mizar saies:\n");
	check_condition();

	if (tree.check[Side][Ply])
		printf("king is in check\n");
	else
		printf("king is not in check\n");

	if (tree.verify[Ply])
		printf("do legality test in makemove\n");
	else
		printf("No legality test in makemove\n");

	set_position(p1);

	init_data();

	print_board();

	printf("In this position white king is not under x attack\n");

	printf("Mizar saies:\n");

	check_condition();

	if (tree.check[Side][Ply])
		printf("king is in check\n");
	else
		printf("king is not in check\n");

	if (tree.verify[Ply])
		printf("do legality test in makemove\n");
	else
		printf("No legality test in makemove\n");

	}
Ejemplo n.º 13
0
/*
 * swp_handler logs the id of calling process, dissects the instruction, sanity
 * checks the memory location, calls emulate_swpX for the actual operation and
 * deals with fixup/error handling before returning
 */
static int swp_handler(struct pt_regs *regs, unsigned int instr)
{
	unsigned int address, destreg, data, type;
	unsigned int res = 0;

	perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, 0, regs, regs->ARM_pc);

	if (current->pid != previous_pid) {
		pr_debug("\"%s\" (%ld) uses deprecated SWP{B} instruction\n",
			 current->comm, (unsigned long)current->pid);
		previous_pid = current->pid;
	}

	/* Ignore the instruction if it fails its condition code check */
	if (!check_condition(regs, instr)) {
		regs->ARM_pc += 4;
		return 0;
	}

	address = regs->uregs[EXTRACT_REG_NUM(instr, RN_OFFSET)];
	data	= regs->uregs[EXTRACT_REG_NUM(instr, RT2_OFFSET)];
	destreg = EXTRACT_REG_NUM(instr, RT_OFFSET);

	type = instr & TYPE_SWPB;

	pr_debug("addr in r%d->0x%08x, dest is r%d, source in r%d->0x%08x)\n",
		 EXTRACT_REG_NUM(instr, RN_OFFSET), address,
		 destreg, EXTRACT_REG_NUM(instr, RT2_OFFSET), data);

	/* Check access in reasonable access range for both SWP and SWPB */
	if (!access_ok(VERIFY_WRITE, (address & ~3), 4)) {
		pr_debug("SWP{B} emulation: access to %p not allowed!\n",
			 (void *)address);
		res = -EFAULT;
	} else {
		res = emulate_swpX(address, &data, type);
	}

	if (res == 0) {
		/*
		 * On successful emulation, revert the adjustment to the PC
		 * made in kernel/traps.c in order to resume execution at the
		 * instruction following the SWP{B}.
		 */
		regs->ARM_pc += 4;
		regs->uregs[destreg] = data;
	} else if (res == -EFAULT) {
		/*
		 * Memory errors do not mean emulation failed.
		 * Set up signal info to return SEGV, then return OK
		 */
		set_segfault(regs, address);
	}

	return 0;
}
Ejemplo n.º 14
0
int wpl_text_chunks::condition::output_json (
		wpl_text_state *state,
		const set<wpl_value*> &vars,
		wpl_text_chunk_it *it,
		wpl_value *final_result
) {
	if (check_condition (state, it->get_pos())) {
		 state->run_text_output_json(get_text(), it->get_pos(), vars, final_result);
	}

	return WPL_OP_NO_RETURN;
}
Ejemplo n.º 15
0
int wpl_text_chunks::condition::run (
		wpl_text_state *state,
		int index,
		wpl_value *final_result,
		wpl_io &io
) {
	int ret = WPL_OP_NO_RETURN;
	if (check_condition (state, index)) {
		ret = state->run_text(get_text(), index, final_result, io);
	}
	return ret;
}
Ejemplo n.º 16
0
static int assignment (LexState *ls, struct LHS_assign *lh, int nvars,
                       lu_byte *from_var)
{
  expdesc e;
  int from = 0;
  check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED,
                      "syntax error");
  if (testnext(ls, ',')) {  /* assignment -> `,' primaryexp assignment */
    struct LHS_assign nv;
    nv.prev = lh;
    primaryexp(ls, &nv.v);
    if (nv.v.k == VLOCAL)
      check_conflict(ls, lh, &nv.v);
    luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls,
                    "variables in assignment");
    from = assignment(ls, &nv, nvars+1, from_var);
  }
  else {  /* assignment -> IN primaryexp | `=' explist1 */
    int nexps;
    if (testnext(ls, TK_IN)) {
      new_localvarliteral(ls, "(from)", 0);
      primaryexp(ls, &e);
      luaK_exp2nextreg(ls->fs, &e);
      *from_var = ls->fs->nactvar;
      adjustlocalvars(ls, 1);

      luaK_setoneret(ls->fs, &e);  /* close last expression */
      getfrom(ls, &e, &lh->v);
      luaK_storevar(ls->fs, &lh->v, &e);
      return 1;  /* avoid default */
    }
    else {
      checknext(ls, '=');
      nexps = explist1(ls, &e);
    }

    if (nexps == nvars) {
      luaK_setoneret(ls->fs, &e);  /* close last expression */
      luaK_storevar(ls->fs, &lh->v, &e);
      return 0;  /* avoid default */
    }
    else {
      adjust_assign(ls, nvars, nexps, &e);
      if (nexps > nvars)
        ls->fs->freereg -= nexps - nvars;  /* remove extra values */
    }
  }
  init_exp(&e, VNONRELOC, ls->fs->freereg-1);  /* default assignment */
  if (from) getfrom(ls, &e, &lh->v);
   luaK_storevar(ls->fs, &lh->v, &e);
  return from;
}
Ejemplo n.º 17
0
void ldm1_inst(int inst, ARMProc *proc) {
	int i;
	LSMAddrResult *result;
	LSMAddrResult *(*func)(int, ARMProc *);
	int register_list;
	int address;
	int start_address;
	int end_address;
	int value;
	int **reg;

	if(!check_condition(proc, inst))
                return;

	register_list = getbits(inst, 0, 16);
	lsm_addr_modes = lsm_addressing_dict();
	reg = &proc->r0;

	for(i = 0; i < LSM_ADDRESSING_NUMBER; i++) {
                if(test_inst(lsm_addr_modes[i], inst)) {
                        func = lsm_addr_modes[i]->execute;
                        result = (*func)(inst, proc);
			break;
                }
        }

	start_address = result->start_address;
	end_address   = result->end_address;

	address = start_address;

	for(i = 0; i < 15; i++) {
		if(getbit(register_list, i)) {
			**(reg + i) = read_mem(proc, address, 4);
			address += 4;
		}
	}

	if(getbit(register_list, 15)) {
		value = read_mem(proc, address, 4);
		*proc->pc = value & 0xFFFFFFFE;
		address += 4;
	}

	if(end_address != address - 4) {
		fprintf(stderr, "Load memory error");
	}

}
Ejemplo n.º 18
0
Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff) {
  struct LexState lexstate;
  struct FuncState funcstate;
  lexstate.buff = buff;
  lexstate.nestlevel = 0;
  luaX_setinput(L, &lexstate, z, luaS_new(L, zname(z)));
  open_func(&lexstate, &funcstate);
  next(&lexstate);  /* read first token */
  chunk(&lexstate);
  check_condition(&lexstate, (lexstate.t.token == TK_EOS), "<eof> expected");
  close_func(&lexstate);
  lua_assert(funcstate.prev == NULL);
  lua_assert(funcstate.f->nups == 0);
  lua_assert(lexstate.nestlevel == 0);
  return funcstate.f;
}
Ejemplo n.º 19
0
static void assignment (LexState *ls, struct LHS_assign *lh, int nvars, BinOpr *opr) {
  expdesc e;
  check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED,
                      "syntax error");
  if (testnext(ls, ',')) {  /* assignment -> `,' primaryexp assignment */
    struct LHS_assign nv;
    nv.prev = lh;
    primaryexp(ls, &nv.v);
    if (nv.v.k == VLOCAL)
      check_conflict(ls, lh, &nv.v);
    assignment(ls, &nv, nvars+1, opr);
  }
  else {  /* assignment -> `=' explist1 */
    int nexps;

	*opr = OPR_NOBINOPR;
	switch(ls->t.token)
	{
	case '=': break;
	case TK_CONCATASSIGN: *opr = OPR_CONCAT; break;
	case TK_ADDASSIGN: *opr = OPR_ADD; break;
	case TK_SUBASSIGN: *opr = OPR_SUB; break;
	case TK_MULASSIGN: *opr = OPR_MUL; break;
	case TK_DIVASSIGN: *opr = OPR_DIV; break;
	case TK_POWASSIGN: *opr = OPR_POW; break;
	case TK_MODASSIGN: *opr = OPR_MOD; break;
	default:
		luaX_syntaxerror(ls, "unexpected symbol");
		break;
	};
	luaX_next(ls);
    nexps = explist1(ls, &e);
    if (nexps != nvars) {
      adjust_assign(ls, nvars, nexps, &e);
      if (nexps > nvars)
        ls->fs->freereg -= nexps - nvars;  /* remove extra values */
    }
    else {
      luaK_setoneret(ls->fs, &e);  /* close last expression */
      luaK_storevar(ls->fs, &lh->v, &e, *opr);
      return;  /* avoid default */
    }
  }
  init_exp(&e, VNONRELOC, ls->fs->freereg-1);  /* default assignment */
  luaK_storevar(ls->fs, &lh->v, &e, *opr);
}
Ejemplo n.º 20
0
static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
  expdesc e;
  check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED,
                      "syntax error");
  if (testnext(ls, ',')) {  /* assignment -> `,' primaryexp assignment */
    struct LHS_assign nv;
    nv.prev = lh;
    primaryexp(ls, &nv.v);
    if (nv.v.k == VLOCAL)
      check_conflict(ls, lh, &nv.v);
    luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls,
                    "variables in assignment");
    assignment(ls, &nv, nvars+1);
  }
  else {  /* assignment -> `=' explist1 */
    int nexps;
      
      /* hook for inc_assignment */
      if(nvars==1) {
          switch(ls->t.token) {
              case '+': case '-': case '*': case '/': case TK_CONCAT:
                  inc_assignment(ls,lh);
                  /* If you're using Shook's table unpack patch, return 0 here.*/
                  return;
          }
      }
      
    checknext(ls, '=');
    nexps = explist1(ls, &e);
    if (nexps != nvars) {
      adjust_assign(ls, nvars, nexps, &e);
      if (nexps > nvars)
        ls->fs->freereg -= nexps - nvars;  /* remove extra values */
    }
    else {
      luaK_setoneret(ls->fs, &e);  /* close last expression */
      luaK_storevar(ls->fs, &lh->v, &e);
      return;  /* avoid default */
    }
  }
  init_exp(&e, VNONRELOC, ls->fs->freereg-1);  /* default assignment */
  luaK_storevar(ls->fs, &lh->v, &e);
}
Ejemplo n.º 21
0
static void getfrom (LexState *ls, expdesc *e, expdesc *v)
{
  expdesc key;
  int k = v->k;

  if (k == VLOCAL) {
    codestring(ls, &key, getlocvar(ls->fs, v->u.s.info).varname);
  }
  else if (k == VUPVAL) {
    codestring(ls, &key, ls->fs->f->upvalues[v->u.s.info]);
  }
  else if (k== VGLOBAL) {
    init_exp(&key, VK, v->u.s.info);
  }
  else {
    check_condition(ls, VLOCAL <= k && k <= VGLOBAL,
                        "syntax error in from vars");
  }
  luaK_indexed(ls->fs, e, &key);
}
Ejemplo n.º 22
0
void bl_inst(int inst, ARMProc *proc) {
	int l;
	int signed_immed_24;
	int branch_addr;

	if(!check_condition(proc, inst))
		return;
	l = getbit(inst, 24);
	signed_immed_24 = getbits(inst, 0, 24);

	if(l) {
		*proc->lr = *proc->pc;
	}

	branch_addr = sign_extend(signed_immed_24, 24, 30);

	branch_addr <<= 2;


	*proc->pc += 4 + branch_addr;
}
Ejemplo n.º 23
0
/*Genera le mosse della Root e le ordina*/
void root(){
	int d,next;
	RMOVEL m;
	unsigned int c;
	
	/*siamo sotto scacco?*/
    check_condition();

	/*generiamo le mosse della root*/
	gen_all();

	/*validiamo, inseriamo nella lista e attribuiamo un valore*/
	tree.last_root_move=0;
	for (c=0;c<tree.first_move[1];c++) {
        if(!makemove(tree.move_list[c].move,0))continue;
		tree.root_move_list[tree.last_root_move].move=tree.move_list[c].move;
		tree.root_move_list[c].scorec=-quiesce(-INF,+INF,0);
		tree.root_move_list[c].scoren=0;
		tree.last_root_move++;
		unmakemove();
	}

	/*ordiniamo*/
	d=1;
	do {
		next=0;
		for (c=0;c<((tree.last_root_move)-d);c++) {
			if (tree.root_move_list[c].scorec<tree.root_move_list[c+1].scorec) {
				m=tree.root_move_list[c];
				tree.root_move_list[c]=tree.root_move_list[c+1];
				tree.root_move_list[c+1]=m;
				next=1;
			}
		}
		d++;
	} while (next);
}
Ejemplo n.º 24
0
static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
  expdesc e;
  check_condition(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED,
                      "syntax error");
  if (testnext(ls, ',')) {  /* assignment -> `,' primaryexp assignment */
    struct LHS_assign nv;
    nv.prev = lh;
    primaryexp(ls, &nv.v);
    if (nv.v.k == VLOCAL)
      check_conflict(ls, lh, &nv.v);
    luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls,
                    "variables in assignment");
    assignment(ls, &nv, nvars+1);
  }
  else {  /* assignment -> `=' explist1 */
    int nexps;
#if LUA_MUTATION_OPERATORS
    luaX_next(ls); /* consume `=' token. */
#else
    checknext(ls, '=');
#endif /* LUA_MUTATION_OPERATORS */
    nexps = explist1(ls, &e);
    if (nexps != nvars) {
      adjust_assign(ls, nvars, nexps, &e);
      if (nexps > nvars)
        ls->fs->freereg -= nexps - nvars;  /* remove extra values */
    }
    else {
      luaK_setoneret(ls->fs, &e);  /* close last expression */
      luaK_storevar(ls->fs, &lh->v, &e);
      return;  /* avoid default */
    }
  }
  init_exp(&e, VNONRELOC, ls->fs->freereg-1);  /* default assignment */
  luaK_storevar(ls->fs, &lh->v, &e);
}
Ejemplo n.º 25
0
static void
compute_ifcond_extent(TextNode *node)
{
    TextNode *condnode = node->data.ifnode->cond;
    TextNode *tln = gLineNode;
    int store_x = text_x, store_y = text_y, lh = present_line_height;
    int then_x, then_y;

    /*
     * This routine checks the value of the condition and swaps in the else
     * or the then depending
     */

    /*
     * we have to compute the maximum width and height of the rest of the
     * text and stuff
     */
    push_group_stack();
    if (gInLine && node->space)
        text_x += inter_word_space;
    compute_text_extent(node->data.ifnode->thennode);
    then_x = text_x;
    then_y = text_y;
    text_x = store_x;
    text_y = store_y;
    present_line_height = lh;
    gLineNode = tln;
    if (gInLine && node->space)
        text_x += inter_word_space;
    compute_text_extent(node->data.ifnode->elsenode);
    /* Now choose the best one that is biggest and put it into ifnode */
    if (then_y > text_y) {
        node->y = then_y;
        node->x = then_x;
    }
    else if (text_y > then_y) {
        node->y = text_y;
        node->x = text_x;
    }
    else if (text_x > then_x) {
        node->y = text_y;
        node->x = text_x;
    }
    else {
        node->y = then_y;
        node->x = then_x;
    }
    /* restore everything */
    text_x = store_x;
    text_y = store_y;
    present_line_height = lh;
    gLineNode = tln;
    node->width = 0;

    if_node = node;
    if (gInLine && node->space)
        text_x += inter_word_space;
    if (check_condition(condnode)) {
        node->next = node->data.ifnode->thennode;
    }
    else {
        node->next = node->data.ifnode->elsenode;
    }
    pop_group_stack();
}
Ejemplo n.º 26
0
    void SimpleInterpreter::run(ostream &out) {
        stack.resize(50);
        bytecodes.clear();
        indices.clear();
        vars.clear();
        bytecodes.push_back(bytecode);
        indices.push_back(0);
        contextID.push_back(0);
        callsCounter.push_back(0);
        SP = 0;

        while (!bytecodes.empty()) {
            indexType &currentIndex = indices.back();
            Bytecode &bytecode = *bytecodes.back();
            Instruction instruction = bytecode.getInsn(currentIndex);
            size_t instructionLength = bytecodeLength(instruction);
#ifdef LOG_INTERPRETER
            const char* bcName = bytecodeName(instruction, 0);
            cout << "index: " << currentIndex << ", instruction: " << bcName << endl;
#endif
            switch (instruction) {
                case BC_DLOAD: pushVariable(bytecode.getDouble(currentIndex + 1));
                    break;
                case BC_ILOAD: pushVariable(bytecode.getInt64(currentIndex + 1));
                    break;
                case BC_SLOAD: pushVariable(constantById(bytecode.getUInt16(currentIndex + 1)).c_str());
                    break;
                case BC_DLOAD0: pushVariable(0.0);
                    break;
                case BC_ILOAD0: pushVariable((signedIntType) 0);
                    break;
                case BC_SLOAD0: pushVariable("");
                    break;
                case BC_DLOAD1: pushVariable(1.0);
                    break;
                case BC_ILOAD1: pushVariable((signedIntType) 1);
                    break;
                case BC_DLOADM1: pushVariable(-1.0);
                    break;
                case BC_ILOADM1: pushVariable((signedIntType) - 1);
                    break;
                case BC_DADD: binary_operation(VT_DOUBLE, add<double>);
                    break;
                case BC_IADD: binary_operation(VT_INT, add < signedIntType > );
                    break;
                case BC_DSUB: binary_operation(VT_DOUBLE, sub<double>);
                    break;
                case BC_ISUB: binary_operation(VT_INT, sub < signedIntType > );
                    break;
                case BC_DMUL: binary_operation(VT_DOUBLE, mul<double>);
                    break;
                case BC_IMUL: binary_operation(VT_INT, mul < signedIntType > );
                    break;
                case BC_DDIV: binary_operation(VT_DOUBLE, _div<double>);
                    break;
                case BC_IDIV: binary_operation(VT_INT, _div < signedIntType > );
                    break;
                case BC_IMOD: binary_operation(VT_INT, mod < signedIntType > );
                    break;
                case BC_DNEG: unary_operation(VT_DOUBLE, neg<double>);
                    break;
                case BC_INEG: unary_operation(VT_INT, neg < signedIntType > );
                    break;
                case BC_IAOR: binary_operation(VT_INT, _or < signedIntType > );
                    break;
                case BC_IAAND: binary_operation(VT_INT, _and < signedIntType > );
                    break;
                case BC_IAXOR: binary_operation(VT_INT, _xor < signedIntType > );
                    break;
                case BC_IPRINT: out << popVariable().getIntValue();
                    out.flush();
                    break;
                case BC_DPRINT: out << popVariable().getDoubleValue();
                    out.flush();
                    break;
                case BC_SPRINT: out << popVariable().getStringValue();
                    out.flush();
                    break;
                case BC_SWAP: {
                    auto v1 = popVariable();
                    auto v2 = popVariable();
                    pushVariable(v1);
                    pushVariable(v2);
                    break;
                }
                case BC_STOREDVAR0:
                case BC_STOREIVAR0:
                case BC_STORESVAR0: storeVariable(0);
                    break;
                case BC_STOREDVAR1:
                case BC_STOREIVAR1:
                case BC_STORESVAR1: storeVariable(1);
                    break;
                case BC_STOREDVAR2:
                case BC_STOREIVAR2:
                case BC_STORESVAR2: storeVariable(2);
                    break;
                case BC_STOREDVAR3:
                case BC_STOREIVAR3:
                case BC_STORESVAR3: storeVariable(3);
                    break;
                case BC_LOADDVAR:
                case BC_LOADIVAR:
                case BC_LOADSVAR: pushVariable(loadVariable(bytecode.getUInt16(currentIndex + 1)));
                    break;
                case BC_LOADDVAR0:
                case BC_LOADIVAR0:
                case BC_LOADSVAR0: pushVariable(loadVariable(0));
                    break;
                case BC_LOADDVAR1:
                case BC_LOADIVAR1:
                case BC_LOADSVAR1: pushVariable(loadVariable(1));
                    break;
                case BC_LOADIVAR2:
                case BC_LOADSVAR2:
                case BC_LOADDVAR2: pushVariable(loadVariable(2));
                    break;
                case BC_LOADDVAR3:
                case BC_LOADIVAR3:
                case BC_LOADSVAR3: pushVariable(loadVariable(3));
                    break;
                case BC_STOREDVAR:
                case BC_STOREIVAR:
                case BC_STORESVAR: storeVariable(bytecode.getUInt16(currentIndex + 1));
                    break;
                case BC_LOADCTXDVAR:
                case BC_LOADCTXIVAR:
                case BC_LOADCTXSVAR: pushVariable(loadVariable(bytecode.getUInt16(currentIndex + 1), bytecode.getUInt16(currentIndex + 3)));
                    break;
                case BC_STORECTXDVAR:
                case BC_STORECTXIVAR:
                case BC_STORECTXSVAR: storeVariable(bytecode.getUInt16(currentIndex + 1), bytecode.getUInt16(currentIndex + 3));
                    break;
                case BC_DCMP: binary_operation<double, signedIntType>(VT_DOUBLE, _cmp<double>);
                    break;
                case BC_ICMP: binary_operation(VT_INT, _cmp < signedIntType > );
                    break;
                case BC_JA: {
                    currentIndex += bytecode.getInt16(currentIndex + 1) + 1;
                    continue;
                }
                case BC_IFICMPNE: {
                    if (!check_condition(_neq<signedIntType>))
                        break;
                    currentIndex += bytecode.getInt16(currentIndex + 1) + 1;
                    continue;
                }
                case BC_IFICMPE: {
                    if (!check_condition(_eq<signedIntType>))
                        break;
                    currentIndex += bytecode.getInt16(currentIndex + 1) + 1;
                    continue;
                }
                case BC_IFICMPG: {
                    if (!check_condition(_g<signedIntType>))
                        break;
                    currentIndex += bytecode.getInt16(currentIndex + 1) + 1;
                    continue;
                }
                case BC_IFICMPGE: {
                    if (!check_condition(_ge<signedIntType>))
                        break;
                    currentIndex += bytecode.getInt16(currentIndex + 1) + 1;
                    continue;
                }
                case BC_IFICMPL: {
                    if (!check_condition(_l<signedIntType>))
                        break;
                    currentIndex += bytecode.getInt16(currentIndex + 1) + 1;
                    continue;
                }
                case BC_IFICMPLE: {
                    if (!check_condition(_le<signedIntType>))
                        break;
                    currentIndex += bytecode.getInt16(currentIndex + 1) + 1;
                    continue;
                }
                case BC_STOP: {
                    indices.clear();
                    bytecodes.clear();
                    continue;
                }
                case BC_CALLNATIVE: {
                    callNative(bytecode.getUInt16(currentIndex + 1));
                    break;
                }
                case BC_CALL: {
                    TranslatedFunction *f = functionById(bytecode.getUInt16(currentIndex + 1));
                    bytecodes.push_back(static_cast<BytecodeFunction *>(f)->bytecode());
                    indices.push_back(0);
                    contextID.push_back(f->id());
                    detectCallWithFunctionID(contextID.back());
                    continue;
                }
                case BC_RETURN: {
                    indices.pop_back();
                    bytecodes.pop_back();
                    if (!indices.empty()) {
                        indices.back() += bytecodeLength(BC_CALL);
                    }
                    if (callsCounter[contextID.back()] > 0) {
                        callsCounter[contextID.back()]--;
                    }
                    contextID.pop_back();
                    continue;
                }
                case BC_I2D: pushVariable((double) popVariable().getIntValue());
                    break;
                case BC_D2I: pushVariable((signedIntType) popVariable().getDoubleValue());
                    break;
                case BC_S2I: pushVariable((signedIntType) popVariable().getStringValue());
                    break;
                case BC_BREAK: break;
                case BC_INVALID: throw InterpretationError("BC_Invalid instruction");
                default: throw InterpretationError(string("Unknown interpreting instruction: ") + bytecodeName(instruction, 0));
            }
            currentIndex += instructionLength;
        }
    }
Ejemplo n.º 27
0
static void primaryexp (LexState *ls, expdesc *v) {
  /* primaryexp ->
        prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */
  FuncState *fs = ls->fs;
  prefixexp(ls, v);
  for (;;) {
    switch (ls->t.token) {
      case '.': {  /* field */
        field(ls, v);
        break;
      }
      case '[': {  /* `[' exp1 `]' */
        expdesc key;
        luaK_exp2anyreg(fs, v);
        yindex(ls, &key);
        luaK_indexed(fs, v, &key);
        break;
      }
      case ':': {  /* `:' NAME funcargs */
        expdesc key;
        luaX_next(ls);
        checkname(ls, &key);
        luaK_self(fs, v, &key);
        funcargs(ls, v);
        break;
      }
#if LUA_WIDESTRING
      case '(': case TK_STRING: case TK_WSTRING: case '{': {  /* funcargs */
#else
      case '(': case TK_STRING: case '{': {  /* funcargs */
#endif /* LUA_WIDESTRING */
        luaK_exp2nextreg(fs, v);
        funcargs(ls, v);
        break;
      }
      default: return;
    }
  }
}


static void simpleexp (LexState *ls, expdesc *v) {
#if LUA_WIDESTRING
  /* simpleexp -> NUMBER | STRING | WSTRING | NIL | true | false | ... |
                  constructor | FUNCTION body | primaryexp */
#else
  /* simpleexp -> NUMBER | STRING | NIL | true | false | ... |
                  constructor | FUNCTION body | primaryexp */
#endif /* LUA_WIDESTRING */
  switch (ls->t.token) {
    case TK_NUMBER: {
      init_exp(v, VKNUM, 0);
      v->u.nval = ls->t.seminfo.r;
      break;
    }
    case TK_STRING: {
      codestring(ls, v, ls->t.seminfo.ts);
      break;
    }
#if LUA_WIDESTRING
    case TK_WSTRING: {
      codewstring(ls, v, ls->t.seminfo.ts);
      break;
    }
#endif /* LUA_WIDESTRING */
    case TK_NIL: {
      init_exp(v, VNIL, 0);
      break;
    }
    case TK_TRUE: {
      init_exp(v, VTRUE, 0);
      break;
    }
    case TK_FALSE: {
      init_exp(v, VFALSE, 0);
      break;
    }
    case TK_DOTS: {  /* vararg */
      FuncState *fs = ls->fs;
      check_condition(ls, fs->f->is_vararg,
                      "cannot use " LUA_QL("...") " outside a vararg function");
      fs->f->is_vararg &= ~VARARG_NEEDSARG;  /* don't need 'arg' */
      init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));
      break;
    }
    case '{': {  /* constructor */
      constructor(ls, v);
      return;
    }
    case TK_FUNCTION: {
      luaX_next(ls);
      body(ls, v, 0, ls->linenumber);
      return;
    }
    default: {
      primaryexp(ls, v);
      return;
    }
  }
  luaX_next(ls);
}


static UnOpr getunopr (int op) {
  switch (op) {
    case TK_NOT: return OPR_NOT;
    case '-': return OPR_MINUS;
    case '#': return OPR_LEN;
    default: return OPR_NOUNOPR;
  }
}


static BinOpr getbinopr (int op) {
  switch (op) {
    case '+': return OPR_ADD;
    case '-': return OPR_SUB;
    case '*': return OPR_MUL;
    case '/': return OPR_DIV;
    case '%': return OPR_MOD;
#if LUA_BITFIELD_OPS
    case '&': return OPR_BAND;
    case '|': return OPR_BOR;
    case TK_XOR: return OPR_BXOR;
    case TK_SHL: return OPR_BSHL;
    case TK_SHR: return OPR_BSHR;
#endif /* LUA_BITFIELD_OPS */
    case '^': return OPR_POW;
    case TK_CONCAT: return OPR_CONCAT;
    case TK_NE: return OPR_NE;
    case TK_EQ: return OPR_EQ;
    case '<': return OPR_LT;
    case TK_LE: return OPR_LE;
    case '>': return OPR_GT;
    case TK_GE: return OPR_GE;
    case TK_AND: return OPR_AND;
    case TK_OR: return OPR_OR;
    default: return OPR_NOBINOPR;
  }
}


static const struct {
  lu_byte left;  /* left priority for each binary operator */
  lu_byte right; /* right priority */
} priority[] = {  /* ORDER OPR */
#if LUA_BITFIELD_OPS
   {8, 8}, {8, 8}, {8, 8}, {8, 8}, {8, 8},  /* bitwise operators */
#endif /* LUA_BITFIELD_OPS */
   {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7},  /* `+' `-' `/' `%' */
   {10, 9}, {5, 4},                 /* power and concat (right associative) */
   {3, 3}, {3, 3},                  /* equality and inequality */
   {3, 3}, {3, 3}, {3, 3}, {3, 3},  /* order */
   {2, 2}, {1, 1}                   /* logical (and/or) */
};

#define UNARY_PRIORITY	8  /* priority for unary operators */


/*
** subexpr -> (simpleexp | unop subexpr) { binop subexpr }
** where `binop' is any binary operator with a priority higher than `limit'
*/
static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) {
  BinOpr op;
  UnOpr uop;
  enterlevel(ls);
  uop = getunopr(ls->t.token);
  if (uop != OPR_NOUNOPR) {
    luaX_next(ls);
    subexpr(ls, v, UNARY_PRIORITY);
    luaK_prefix(ls->fs, uop, v);
  }
  else simpleexp(ls, v);
  /* expand while operators have priorities higher than `limit' */
  op = getbinopr(ls->t.token);
  while (op != OPR_NOBINOPR && priority[op].left > limit) {
    expdesc v2;
    BinOpr nextop;
    luaX_next(ls);
    luaK_infix(ls->fs, op, v);
    /* read sub-expression with higher priority */
    nextop = subexpr(ls, &v2, priority[op].right);
    luaK_posfix(ls->fs, op, v, &v2);
    op = nextop;
  }
  leavelevel(ls);
  return op;  /* return first untreated operator */
}