diff options
| Commit | 6e19bb560d474736d45f5be011ff0830c7019991 (patch) | |
|---|---|---|
| Author | 2018-11-05 23:34:00 +0200 | |
| Committer | 2018-11-05 23:34:00 +0200 | |
| Files | 42d29cf1c4e6a535ba526f434debaac3a70df2c6 /src/spasm_impl.hpp | |
| IPL-6e19bb560d474736d45f5be011ff0830c7019991.tar IPL-6e19bb560d474736d45f5be011ff0830c7019991.tar.gz IPL-6e19bb560d474736d45f5be011ff0830c7019991.zip | ||
Squashed 'spasm/' content from commit 08ee95d
git-subtree-dir: spasm
git-subtree-split: 08ee95d89054ba0d33697d613799a0a013aedf89
1 files changed, 97 insertions, 0 deletions
| -rw-r--r-- | src/spasm_impl.hpp | 97 |
diff --git a/src/spasm_impl.hpp b/src/spasm_impl.hpp new file mode 100644 index 0000000..78c5d08 --- /dev/null +++ b/src/spasm_impl.hpp @@ -0,0 +1,97 @@ +#ifndef SPASM_IMPL_HPP +#define SPASM_IMPL_HPP + +#include <iostream> + +#include "dstack.hpp" +#include "frames.hpp" +#include "types.hpp" + +namespace SpasmImpl +{ +//! The Abstract Stack Machine +/*! +** The machine contains a data stack for operations and control flow and +** frame stack for function calls (including parameter passing) and local +** variables and return stack for the addresses of the returns. +*/ +class Spasm +{ + public: + Spasm(); + Spasm(PC_t, + const byte*, + std::istream& = std::cin, + std::ostream& = std::cout); + Spasm(const Spasm&); + ~Spasm(); + Spasm& operator=(const Spasm&); + + void run(); + + const Dstack& get_dstack() const; + + private: + //! Operations (opcodes) of the machine + static Operation operations[]; + + //! number of operations + static PC_t op_size; + + //! Program counter - points the current opcode + PC_t pc; + + //! size of the program bytecode + PC_t bc_size; + + //! bytecode of the program + byte* bytecode; + + //! Data stack for arithmetic operations and control flow + Dstack data_stack; + + //! Return stack for the addresses of the returns + Rstack_t return_stack; + + //! Stack for the frame of the functions + FrameStack frame; + + //! Input stream for read () operation + std::istream* istr; + + //! Output stream for print () opertion + std::ostream* ostr; + + void push(); + void pop(); + void dup(); + + void print(); + void read(); + + void plus(); + void minus(); + void multiply(); + void divide(); + void modulus(); + + void gotrue(); + void gofalse(); + void go(); + + void call(); + void ret(); + + void load(); + void store(); + + void less(); + void lesseq(); + + // private method for copying and deleting an object + void copybc(const Spasm&); + void deleteobj(); +}; + +} // namespace SpasmImpl +#endif // #ifndef SPASM_IMPL_HPP |
