From 75615a80530719fe579934c87f2a5c40f27b555f Mon Sep 17 00:00:00 2001 From: Hazem Krimi Date: Thu, 26 Mar 2026 13:17:19 +0100 Subject: [PATCH] feat: vm translator types --- src/types.hpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/types.hpp 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;