Beispiel #1
0
static std::vector<uint8> AsVector(std::basic_stringstream<Char>& stream)
{
    auto str = stream.str();
    return std::vector<uint8>((const uint8*)AsPointer(str.begin()), (const uint8*)AsPointer(str.end()));
}
Beispiel #2
0
	}
}

static void print_assembly(std::string data) {
	auto iter = data.begin();
	for (; iter != data.end(); iter+=INSTRUCTION_WIDTH) {
		Instruction* instruction = (Instruction*)&data[iter - data.begin()];
		std::cout << instruction->toString() << std::endl;
	}
}

TEST_CASE("assemble expressions", "[asm expr]") {
	ast::expr_t expr = lang::parse("a = 2;");
	assembler::AssembleVisitor v;
	expr->accept(&v);
	std::basic_stringstream<char> expected;
	//expected << Push(Field(field_type::global, v.getGlobalId(value::none()), 0)); // local: global
	//expected << Push(Field(field_type::global, v.getGlobalId(value::none()), 0)); // local: this
	expected << Push(Field(field_type::global, v.getGlobalId(value::none()), 0)); // local: a
	expected << Push(Field(field_type::global, v.getGlobalId(value::integer(2)), 0));
	expected << Push(Field(field_type::reg|field_type::referance, reg::ebp, 2));
	expected << Pop(Field(field_type::reg, reg::a, 0));
	expected << Mov(Field(field_type::global, v.getGlobalId(value::string("__assign_value__")), 0),
					Field(field_type::reg, reg::b, 0));
	expected << Call(Field(field_type::reg, reg::a, 0),
					 Field(field_type::reg, reg::b, 0), 1);
	expected << Pop(Field(field_type::reg, reg::m, 0));

	test_assembly(expected.str(), v.stream.str(), v);
}
Beispiel #3
0
inline void rewind(std::basic_stringstream<Ch, Tr, Alloc> &ss)
{
  ss.clear();
  ss.seekg(0, std::ios::beg);
}