Created
February 5, 2017 23:25
-
-
Save LordAro/5a9d97bcc03a55e49eb32c14d185abbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint16_t machine::get_val(const operand_t &x) | |
{ | |
switch (x.which()) { | |
case 0: { // string | |
// much sad here. duplicates a lot of get_operand | |
std::string op = boost::get<std::string>(x); | |
if (op.find('+') != std::string::npos) { | |
size_t pos = op.find('+'); | |
return this->get_val(op.substr(0, pos)) + this->get_val(op.substr(pos + 1)); | |
} else if (op.size() > 2 && op.front() == '[' && op.back() == ']') { | |
return this->mem.at(this->get_val(op.substr(1, op.length() - 2))); | |
} else if (op.size() > 2 && op[0] == '0' && tolower(op[1]) == 'x' && is_hex(op.substr(2))) { | |
return static_cast<uint16_t>(std::stoul(op.substr(2), nullptr, 16)); | |
} else if (std::find(REG_T_STR.begin(), REG_T_STR.end(), op) != REG_T_STR.end()) { | |
return this->regs.at(static_cast<size_t>(find_reg(op))); | |
} | |
return this->find_label(op); | |
} | |
case 1: // reg | |
return this->regs.at(static_cast<size_t>(boost::get<reg_t>(x))); | |
case 2: // literal | |
return boost::get<uint16_t>(x); | |
} | |
throw "Could not get value??"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment