moved comment parsing to first pass, to save program space
This commit is contained in:
parent
9c4bd366b6
commit
eeeaf894e0
@ -36,6 +36,8 @@ std::string interpreter::eval(std::istream& in, bool& done) {
|
||||
for (std::string line; std::getline(in, line); ++_pc) {
|
||||
if (line[0] == ':') {
|
||||
_labels.emplace(line.substr(1), _pc--);
|
||||
} else if (line[0] == '#') { // check comment
|
||||
_pc--;
|
||||
} else {
|
||||
_prog.push_back(line);
|
||||
}
|
||||
@ -47,12 +49,6 @@ std::string interpreter::eval(std::istream& in, bool& done) {
|
||||
// fetch next instruction
|
||||
std::string code {_prog[_pc]};
|
||||
|
||||
// check comment
|
||||
if (code[0] == '#') {
|
||||
_pc++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// check literal int
|
||||
if (std::isdigit(code[0])) {
|
||||
_stack.push_back(code);
|
||||
|
Loading…
x
Reference in New Issue
Block a user