Exemplo n.º 1
0
Arquivo: qbrt.cpp Projeto: zhaobr/qbrt
void execute_lcontext(OpContext &ctx, const lcontext_instruction &i)
{
	const char *name = fetch_string(ctx.resource(), i.hashtag);
	qbrt_value *dst(ctx.dstvalue(i.reg));
	Failure *fail;
	if (!dst) {
		fail = FAIL_REGISTER404(ctx.module_name()
				, ctx.function_name(), ctx.pc());
		fail->debug << "invalid register: " << i.reg;
		ctx.fail_frame(fail);
		return;
	}

	qbrt_value *src = ctx.get_context(name);
	if (src) {
		qbrt_value::ref(*dst, *src);
	} else {
		fail = NEW_FAILURE("unknown_context", ctx.module_name()
				, ctx.function_name(), ctx.pc());
		fail->debug << "cannot find context variable: " << name;
		qbrt_value::fail(*dst, fail);
		cerr << fail->debug_msg() << endl;
	}

	ctx.pc() += lcontext_instruction::SIZE;
}
Exemplo n.º 2
0
Arquivo: qbrt.cpp Projeto: zhaobr/qbrt
void execute_stracc(OpContext &ctx, const stracc_instruction &i)
{
	RETURN_FAILURE(ctx, i.dst);
	RETURN_FAILURE(ctx, i.src);

	Failure *f;
	qbrt_value &dst(*ctx.dstvalue(i.dst));
	const qbrt_value &src(*ctx.srcvalue(i.src));

	int op_pc(ctx.pc());
	ctx.pc() += stracc_instruction::SIZE;

	if (dst.type->id != VT_STRING) {
		f = FAIL_TYPE(ctx.module_name(), ctx.function_name(), op_pc);
		f->debug << "stracc destination is not a string";
		qbrt_value::i(f->exit_code, 1);
		ctx.fail_frame(f);
		return;
	}

	ostringstream out;
	switch (src.type->id) {
		case VT_STRING:
			*dst.data.str += *src.data.str;
			break;
		case VT_INT:
			out << src.data.i;
			*dst.data.str += out.str();
			break;
		case VT_VOID:
			f = FAIL_TYPE(ctx.module_name(), ctx.function_name()
					, op_pc);
			f->debug << "cannot append void to string";
			cerr << f->debug_msg() << endl;
			qbrt_value::fail(dst, f);
			break;
		default:
			f = FAIL_TYPE(ctx.module_name(), ctx.function_name()
					, op_pc);
			f->debug << "stracc source type is not supported: "
				<< (int) src.type->id;
			cerr << f->debug_msg() << endl;
			qbrt_value::fail(dst, f);
			break;
	}
}
Exemplo n.º 3
0
Arquivo: qbrt.cpp Projeto: zhaobr/qbrt
void execute_ctuple(OpContext &ctx, const ctuple_instruction &i)
{
	qbrt_value *dst(ctx.dstvalue(i.dst));
	if (!dst) {
		Failure *f = FAIL_REGISTER404(ctx.module_name()
				, ctx.function_name(), ctx.pc());
		f->debug << "invalid register: " << i.dst;
		ctx.fail_frame(f);
		cerr << f->debug_msg() << endl;
		return;
	}

	qbrt_value::tuple(*dst, new Tuple(i.size));
	ctx.pc() += ctuple_instruction::SIZE;
}