11#ifndef ARK_VM_STATE_HPP
12#define ARK_VM_STATE_HPP
16#include <unordered_map>
40 explicit State(
const std::vector<std::filesystem::path>& libenv = {})
noexcept;
50 bool feed(
const std::string& bytecode_filename,
bool fail_with_exception =
false);
60 bool feed(
const bytecode_t& bytecode,
bool fail_with_exception =
false);
70 bool doFile(
const std::string& file_path, uint16_t features =
DefaultFeatures);
80 bool doString(
const std::string& code, uint16_t features =
DefaultFeatures);
95 void setArgs(
const std::vector<std::string>& args)
noexcept;
102 void setDebug(
unsigned level)
noexcept;
109 void setLibDirs(
const std::vector<std::filesystem::path>& libenv)
noexcept;
115 void reset()
noexcept;
138 [[nodiscard]]
bool compile(
const std::string& file,
const std::string& output, uint16_t features)
const;
142 throw Error(
"StateError: " + message);
169 [[nodiscard]]
inline constexpr uint8_t
inst(
const std::size_t pp,
const std::size_t ip)
const noexcept
171 return m_code[pp * m_max_page_size + ip];
Common code for the compiler.
Constants used by ArkScript.
ArkScript homemade exceptions.
Wrapper object for user-defined functions.
Default value type handled by the virtual machine.
This class is just a helper to.
std::function< Value(std::vector< Value > &, VM *)> CallbackType
Ark state to handle the dirty job of loading and compiling ArkScript code.
std::vector< std::filesystem::path > m_libenv
std::vector< Value > m_constants
static void throwStateError(const std::string &message)
std::vector< internal::InstLoc > m_inst_locations
std::vector< std::string > m_filenames
std::unordered_map< std::string, Value > m_binded
Values binded to the State, to be used by the VM.
constexpr uint8_t inst(const std::size_t pp, const std::size_t ip) const noexcept
Get an instruction in a given page, with a given instruction pointer.
std::vector< std::string > m_symbols
std::size_t m_max_page_size
The ArkScript virtual machine, executing ArkScript bytecode.
constexpr uint16_t DefaultFeatures
std::vector< uint8_t > bytecode_t