Website Summary Files Commits Branches @commit @diff @stats
path: root / spasm / src / spasm_impl.hpp
diff options
context:
space:
mode:
Commite7c2a14f3e424f1ef1109d7634ece820a058e862 (patch)
Author
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-11-13 23:52:40 +0200
Committer
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-11-13 23:52:40 +0200
Files587a120e78e7c0d50c381d8f38bf0665ed8733a7 /spasm/src/spasm_impl.hpp
IPL-e7c2a14f3e424f1ef1109d7634ece820a058e862.tar
IPL-e7c2a14f3e424f1ef1109d7634ece820a058e862.tar.gz
IPL-e7c2a14f3e424f1ef1109d7634ece820a058e862.zip
Parentfa077610dfe8b59eb2af069d2f3e92b4790a21d2 (diff)
Implemented call and ret opcodes
1 files changed, 13 insertions, 6 deletions
-rw-r--r--spasm/src/spasm_impl.hpp19
diff --git a/spasm/src/spasm_impl.hpp b/spasm/src/spasm_impl.hpp
index 1e1d3ef..75fb4c4 100644
--- a/spasm/src/spasm_impl.hpp
+++ b/spasm/src/spasm_impl.hpp
@@ -3,7 +3,6 @@
#include <iostream>
-#include "frames.hpp"
#include "types.hpp"
namespace SpasmImpl
@@ -15,6 +14,7 @@ enum OpCodes : char
Pop,
PopTo,
Push,
+ Alloc,
Print,
Read,
Call,
@@ -30,7 +30,10 @@ enum OpCodes : char
Mod,
Less,
LessEq,
+ LastIndex = LessEq,
};
+static_assert(LastIndex < 0x3f, "Too many opcodes");
+
//! The Abstract Stack Machine
/*!
** The machine contains a data stack for operations and control flow and
@@ -74,11 +77,15 @@ class Spasm
//! Frame pointer - the start of the stack for the current function
data_t* m_FP = nullptr;
- //! Return stack for the addresses of the returns
- Rstack_t return_stack;
+ struct Frame {
+ PC_t ReturnAddress;
+ PC_t FramePointer;
+ PC_t StackPointer;
+ };
- //! Stack for the frame of the functions
- FrameStack frame;
+ typedef std::stack<Frame> FrameStack;
+ //! Stack for function frames
+ FrameStack m_Frames;
//! Input stream for read () operation
std::istream* istr;
@@ -104,7 +111,7 @@ class Spasm
void gofalse(reg_t a0, reg_t a1);
void go(reg_t a0);
- void call();
+ void call(reg_t a0);
void ret(reg_t a0);
void load();