Website Summary Files Commits Branches @commit @diff @stats
path: root / spasm / src / asm / bytecode.hpp
diff options
context:
space:
mode:
Commitc3252e63c296d1133254f4973fe7e3bf52cc6c1a (patch)
Author
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-11-05 23:34:00 +0200
Committer
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-11-05 23:34:00 +0200
Files67c6bfc067696562aded70f66d25899f3f70a1c8 /spasm/src/asm/bytecode.hpp
IPL-c3252e63c296d1133254f4973fe7e3bf52cc6c1a.tar
IPL-c3252e63c296d1133254f4973fe7e3bf52cc6c1a.tar.gz
IPL-c3252e63c296d1133254f4973fe7e3bf52cc6c1a.zip
Parentc9912fdb174e1580629e00cacab6bc4ed480e643 (diff)
Parent6e19bb560d474736d45f5be011ff0830c7019991 (diff)
Merge commit '6e19bb560d474736d45f5be011ff0830c7019991' as 'spasm'
1 files changed, 87 insertions, 0 deletions
-rw-r--r--spasm/src/asm/bytecode.hpp87
diff --git a/spasm/src/asm/bytecode.hpp b/spasm/src/asm/bytecode.hpp
new file mode 100644
index 0000000..c08da46
--- /dev/null
+++ b/spasm/src/asm/bytecode.hpp
@@ -0,0 +1,87 @@
+#ifndef BYTECODE_HPP
+#define BYTECODE_HPP
+
+#include <fstream>
+#include <iostream>
+#include <string>
+#include <vector>
+
+namespace SpasmImpl
+{
+namespace ASM
+{
+class Bytecode_Stream
+{
+ public:
+ typedef unsigned char byte;
+ enum Opcode_t : byte
+ {
+ halt = 0,
+ push,
+ pop,
+ dup,
+ print,
+ read,
+ plus,
+ minus,
+ multiply,
+ divide,
+ modulus,
+ gotrue,
+ gofalse,
+ go,
+ call,
+ ret,
+ load,
+ store,
+ less,
+ lesseq
+ };
+
+
+ virtual ~Bytecode_Stream();
+ virtual void push_opcode(Opcode_t) = 0;
+ virtual void push_integer(int) = 0;
+ virtual void push_location(size_t) = 0;
+ virtual void set_location(size_t, size_t) = 0;
+ virtual size_t size() const = 0;
+}; // class Bytecode_Stream
+
+class Bytecode_File : public Bytecode_Stream
+{
+ public:
+ Bytecode_File(const std::string&);
+
+ virtual void push_opcode(Opcode_t);
+ virtual void push_integer(int);
+
+ private:
+ Bytecode_File(const Bytecode_File&);
+ Bytecode_File& operator=(const Bytecode_File&);
+ void push_byte(Bytecode_Stream::byte);
+
+ std::ofstream _bytecode;
+
+}; // class Bytecode_File
+
+class Bytecode_Memory : public Bytecode_Stream
+{
+ public:
+ virtual void push_opcode(Opcode_t);
+ virtual void push_integer(int);
+ virtual void push_location(size_t);
+ virtual void set_location(size_t, size_t);
+ virtual size_t size() const;
+
+ typedef std::vector<Bytecode_Stream::byte> Bytecode;
+ const Bytecode& bytecode() const;
+
+ private:
+ void push_byte(Bytecode_Stream::byte);
+
+ std::vector<Bytecode_Stream::byte> _bytecode;
+}; // class Bytecode_Memory
+} // namespace ASM
+} // namespace SpasmImpl
+
+#endif // BYTECODE_HPP