diff --git a/src/types.hpp b/src/types.hpp new file mode 100644 index 0000000..0cba471 --- /dev/null +++ b/src/types.hpp @@ -0,0 +1,53 @@ +#include +#include + +enum CommandType { + ADD, + SUB, + NEG, + + EQ, + GT, + LT, + + AND, + OR, + NOT, + + PUSH, + POP, +}; + +enum SegmentType { + LCL, + ARG, + THIS, + THAT, + STATIC, + CONSTANT, + TEMP, + POINTER, +}; + +std::unordered_map const commandTypes = { + {"add", CommandType::ADD}, {"sub", CommandType::SUB}, + {"neg", CommandType::NEG}, {"eq", CommandType::EQ}, + {"gt", CommandType::GT}, {"lt", CommandType::LT}, + {"and", CommandType::AND}, {"or", CommandType::OR}, + {"not", CommandType::NOT}, {"push", CommandType::PUSH}, + {"pop", CommandType::POP}, +}; + +std::unordered_map const segmentTypes = { + {"local", SegmentType::LCL}, {"argument", SegmentType::ARG}, + {"this", SegmentType::THIS}, {"that", SegmentType::THAT}, + {"static", SegmentType::STATIC}, {"constant", SegmentType::CONSTANT}, + {"temp", SegmentType::TEMP}, {"pointer", SegmentType::POINTER}, +}; + +typedef struct { + std::string line; + std::string type; + std::string segment; + int index; +} Command;