MIXAL
machine_pesudo.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include "machine.h"
3 
9 namespace mixal {
10 
12 void Computer::executeEQU(ParsedResult* instruction) {
13  if (!instruction->address.evaluated()) {
14  if (!instruction->address.evaluate(_constants)) {
15  throw RuntimeError(_lineOffset, "Unresolved symbol found while parsing EQU: " + instruction->rawAddress);
16  }
17  }
18  _constants[instruction->rawLocation] = AtomicValue(instruction->address.result().value);
19 }
20 
22 void Computer::executeORIG(ParsedResult* instruction) {
23  if (!instruction->address.evaluated()) {
24  if (!instruction->address.evaluate(_constants)) {
25  throw RuntimeError(_lineOffset, "Unresolved symbol found while parsing ORIG: " + instruction->rawAddress);
26  }
27  }
28  int lineOffset = _lineOffset;
29  _lineOffset = instruction->address.result().value;
30  if (instruction->rawLocation.length() > 0) {
31  if (instruction->rawAddress.find('*') == std::string::npos) {
32  if (!instruction->rawLocation.empty()) {
33  _constants[instruction->rawLocation] = AtomicValue(instruction->address.result().value);
34  }
35  } else {
36  // When there is a `*` in the address, the location should equal to the `*` value before the calculation.
37  _constants[instruction->rawLocation] = AtomicValue(lineOffset);
38  }
39  } else {
40  std::string symbol = getPesudoSymbolname();
41  _constants[symbol] = AtomicValue(instruction->address.result().value);
42  }
43 }
44 
46 void Computer::executeCON(ParsedResult* instruction) {
47  if (!instruction->address.evaluated()) {
48  if (!instruction->address.evaluate(_constants)) {
49  throw RuntimeError(_lineOffset, "Unresolved symbol found while parsing CON: " + instruction->rawAddress);
50  }
51  }
52  memory[_lineOffset].set(instruction->address.result().value);
53  if (!instruction->rawLocation.empty()) {
54  _constants[instruction->rawLocation] = AtomicValue(_lineOffset);
55  }
56  ++_lineOffset;
57 }
58 
59 }; // namespace mixal
mixal::Computer::memory
ComputerWord memory[NUM_MEMORY]
Definition: machine.h:38
machine.h
The virtual machine.
mixal::ComputerWord::set
void set(int32_t value)
Definition: memory.cpp:178