-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomputer.h
55 lines (44 loc) · 1.42 KB
/
computer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef JNP1_6_COMPUTER_H
#define JNP1_6_COMPUTER_H
#include "ooasm.h"
#include <ostream>
#include "computer_components.h"
// Implementation detail namespace concerning computer abstraction parts.
namespace computer {
using ooasm::Instruction;
// Derived class for processor with operations on ooasm instructions.
class Processor : public ProcessorAbstract {
public:
explicit Processor(Memory &_mem) : ProcessorAbstract(_mem) {}
void execute(const Instruction &ins) {
ins.execute(*this, mem);
}
void declare(const Instruction &ins) {
ins.declare(mem);
}
};
// Class for abstract computer being environment of ooasm execution.
class Computer {
public:
explicit Computer(size_t mem_size) : mem(mem_size), proc(mem) {}
void boot(const ooasm::Program &p) {
mem.wipe();
for (const std::shared_ptr<Instruction> &ins : p) {
proc.declare(*ins);
}
for (const std::shared_ptr<Instruction> &ins : p) {
proc.execute(*ins);
}
}
void memory_dump(std::ostream &os) const {
for (size_t i = 0; i < mem.size(); ++i) {
os << static_cast<long long>(mem.at(i)) << " ";
}
};
private:
Memory mem;
Processor proc;
};
}
using computer::Computer;
#endif //JNP1_6_COMPUTER_H