diff --git a/.idea/editor.xml b/.idea/editor.xml
index aa2a125..43702aa 100644
--- a/.idea/editor.xml
+++ b/.idea/editor.xml
@@ -27,6 +27,7 @@
+
diff --git a/src/assembler/assembler.cc b/src/assembler/assembler.cc
index f6d7df2..ed464ed 100644
--- a/src/assembler/assembler.cc
+++ b/src/assembler/assembler.cc
@@ -2,6 +2,14 @@
namespace tyche::as {
+Assembler::Assembler(std::string const& source)
+{
+}
+
+ByteArray Assembler::assemble() const
+{
+ return {};
+}
} // tyche
diff --git a/src/assembler/assembler.hh b/src/assembler/assembler.hh
index f717051..b5cd1bb 100644
--- a/src/assembler/assembler.hh
+++ b/src/assembler/assembler.hh
@@ -1,10 +1,17 @@
#ifndef TYCHE_ASSEMBLER_HH
#define TYCHE_ASSEMBLER_HH
+#include
+
+#include "../common/bytearray.hh"
+
namespace tyche::as {
class Assembler {
+public:
+ explicit Assembler(std::string const& source);
+ [[nodiscard]] ByteArray assemble() const;
};
} // tyche
diff --git a/src/assembler/tests.cc b/src/assembler/tests.cc
index b72a36f..0d0bec4 100644
--- a/src/assembler/tests.cc
+++ b/src/assembler/tests.cc
@@ -1,5 +1,52 @@
+#include "assembler.hh"
#include "gtest/gtest.h"
+#include "../bytecode/bytecodeprototype.hh"
+#include "../bytecode/bytecode.hh"
+#include "../vm/instruction.hh"
+
+using namespace tyche;
+using namespace tyche::as;
+using namespace tyche::bc;
+using namespace tyche::vm;
+
+TEST(Assember, Assembler)
+{
+ BytecodePrototype bp;
+ bp.constants.emplace_back(3.14f);
+ bp.constants.emplace_back("Hello world");
+ bp.functions.emplace_back(0, 0);
+ bp.functions.at(0).code.append_byte((uint8_t) Instruction::PushInt8);
+ bp.functions.at(0).code.append_int8(2);
+ bp.functions.at(0).code.append_byte((uint8_t) Instruction::PushInt8);
+ bp.functions.at(0).code.append_int8(3);
+ bp.functions.at(0).code.append_byte((uint8_t) Instruction::Sum);
+ bp.functions.at(0).code.append_byte((uint8_t) Instruction::Return);
+ bp.functions.emplace_back(0, 0);
+ bp.functions.at(1).code.append_byte((uint8_t) Instruction::PushInt16);
+ bp.functions.at(1).code.append_int16(5000);
+ bp.functions.at(1).code.append_byte((uint8_t) Instruction::Return);
+ ByteArray expected = Bytecode::generate(bp);
+
+ std::string src = R"(
+.const
+ 0: 3.14
+ 1: "Hello world"
+
+.function 0
+ pushi 2
+ pushi 3
+ sum
+ ret
+.function 1
+ pushi 5000
+ ret
+)";
+
+ ByteArray actual = Assembler(src).assemble();
+ ASSERT_EQ(expected, actual);
+}
+
int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
diff --git a/src/common/bytearray.hh b/src/common/bytearray.hh
index 3cf6ef6..5f7a2fd 100644
--- a/src/common/bytearray.hh
+++ b/src/common/bytearray.hh
@@ -47,6 +47,8 @@ public:
[[nodiscard]] std::string hexdump() const;
+ friend bool operator==(ByteArray const& lhs, ByteArray const& rhs) { return lhs.data_ == rhs.data_; }
+
private:
std::vector data_ {};
};