Ejemplo n.º 1
0
NODE(sl_node_var_t, var)
{
    size_t frame;
    sl_compile_state_t* xcs = cs;
    size_t index = 0xCAFE;
    SLVAL err;
    frame = 0;
    while(xcs) {
        if(sl_st_lookup(xcs->vars, (sl_st_data_t)node->name, (sl_st_data_t*)&index)) {
            if(frame == 0) {
                op_mov(cs, index, dest);
            } else {
                op_get_outer(cs, frame, index, dest);
                mark_upper_scopes_as_closure_unsafe(cs, frame);
            }
            return;
        }
        xcs = xcs->parent;
        frame++;
    }
    err = sl_make_formatted_string(cs->vm, "Undefined variable %QV", node->name);
    err = sl_make_error2(cs->vm, cs->vm->lib.NameError, err);
    sl_error_add_frame(cs->vm, err, sl_make_cstring(cs->vm, "<compiler>"), sl_make_cstring(cs->vm, (char*)cs->section->filename), sl_make_int(cs->vm, node->base.line));
    sl_throw(cs->vm, err);
}
Ejemplo n.º 2
0
void Interpreter::step()
{
	if (instruction >= file->getCodeWordCount()) return;
	
	if (system->getTick() < waitUntil)
		return;
	
	const uint16_t *code = file->getCode();
	
	if (code[instruction] & (1 << 11))
	{
		// Short format	
		unsigned opcode = (code[instruction] & 0x0700) >> 8;
		int argDiff = (int8_t) (code[instruction] & 0xFF);
		uint16_t arguments[2];
		switch(opcode)
		{
			case 0: // SHORT_OP_MOV
				arguments[0] = argDiff + code[instruction + 1];
				arguments[1] = code[instruction + 1];
				instruction += 2;
				op_mov(0, arguments);
				break;
			case 1: // SHORT_OP_ACQUIRE
				arguments[0] = argDiff;
				instruction += 1;
				op_acquire(0, arguments);
				break;
			case 2: // SHORT_OP_RELEASE
				arguments[0] = argDiff;
				instruction += 1;
				op_release(0, arguments);
				break;
			case 3: // SHORT_OP_SUBCALL
				arguments[0] = argDiff + code[instruction + 1]; // Subroutine
				arguments[1] = code[instruction + 1]; // Caller ID
				instruction += 2; // Instruction has to be on the next before
				// branching to subroutine so it can be used as return inst.
				op_subcall(0, arguments);
				break;
			default:
				throw std::runtime_error("Invalid short opcode.");
		}		
	}
Ejemplo n.º 3
0
void Step()
{
	Opcodes OP = (Opcodes)Fetch8();
	//printf("%08X:%08X\n", Registers[sp], Registers[pc]);
	switch (OP)
	{
	case O_NOP:
		op_nop();
		break;
	case O_MOV:
		op_mov();
		break;
	case O_ADD:
		op_add();
		break;
	case O_SUB:
		op_sub();
		break;
	case O_MUL:
		op_mul();
		break;
	case O_DIV:
		op_div();
		break;
	case O_LI:
		op_li();
		break;
	case O_MOVF:
		op_movf();
		break;
	case O_ADDF:
		op_addf();
		break;
	case O_SUBF:
		op_subf();
		break;
	case O_MULF:
		op_mulf();
		break;
	case O_DIVF:
		op_divf();
		break;
	case O_LIF:
		op_lif();
		break;
	case O_XOR:
		op_xor();
		break;
	case O_AND:
		op_and();
		break;
	case O_MOD:
		op_mod();
		break;
	case O_OR:
		op_or();
		break;
	case O_NOT:
		op_not();
		break;
	case O_SHR:
		op_shr();
		break;
	case O_SHL:
		op_shl();
		break;
	case O_PUSH:
		op_push();
		break;
	case O_POP:
		op_pop();
		break;
	case O_STB:
		op_stb();
		break;
	case O_LDB:
		op_ldb();
		break;
	case O_STH:
		op_sth();
		break;
	case O_LDH:
		op_ldh();
		break;
	case O_STW:
		op_stw();
		break;
	case O_LDW:
		op_ldw();
		break;
	case O_LDF:
		op_ldf();
		break;
	case O_STF:
		op_stf();
		break;
	case O_CMP:
		op_cmp();
		break;
	case O_B:
		op_b(0);
		break;
	case O_BC:
		op_b(1);
		break;
	case O_BEQ:
		op_bcond(ctr0_eq);
		break;
	case O_BNE:
		op_bcond(ctr0_ne);
		break;
	case O_BGT:
		op_bcond(ctr0_gt);
		break;
	case O_BLT:
		op_bcond(ctr0_lt);
		break;
	case O_BTC:
		op_btc();
		break;
	case O_INC:
		op_inc();
		break;
	case O_DEC:
		op_dec();
		break;
	default:
		Error("Error: Unknown Opcode PC = %d OP = %08X\n", Registers[pc], OP);
	}

	Ticks++;
}