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;
49 bool feed(
const std::string& bytecode_filename);
68 bool doFile(
const std::string& file, uint16_t features =
DefaultFeatures);
78 bool doString(
const std::string& code, uint16_t features =
DefaultFeatures);
93 void setArgs(
const std::vector<std::string>& args)
noexcept;
100 void setDebug(
unsigned level)
noexcept;
107 void setLibDirs(
const std::vector<std::filesystem::path>& libenv)
noexcept;
113 void reset()
noexcept;
136 [[nodiscard]]
bool compile(
const std::string& file,
const std::string& output, uint16_t features)
const;
140 throw Error(
"StateError: " + message);
167 [[nodiscard]]
inline constexpr uint8_t
inst(
const std::size_t pp,
const std::size_t ip)
const noexcept
169 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