21#include <unordered_map>
24#include <fmt/ranges.h>
40 using namespace std::string_literals;
54 explicit VM(
State& state)
noexcept;
62 int run(
bool fail_with_exception =
false);
70 Value& operator[](
const std::string& name)
noexcept;
80 template <
typename... Args>
81 Value call(
const std::string& name, Args&&... args);
101 void exit(
int code)
noexcept;
109 return m_execution_contexts.front().get();
151 [[nodiscard]]
bool forceReloadPlugins()
const;
163 return m_state.m_bytecode;
177 std::vector<std::unique_ptr<internal::Future>>
m_futures;
180 Value m_no_value = internal::Builtins::nil;
197 void init() noexcept;
219 [[nodiscard]] inline
Value* loadSymbolFromIndex(uint16_t index, internal::
ExecutionContext& context);
227 [[nodiscard]] inline
Value* loadConstAsPtr(uint16_t
id) const;
351 uint16_t findNearestVariableIdWithValue(const
Value& value, internal::
ExecutionContext& context) const noexcept;
353 [[noreturn]]
void throwArityError(
std::
size_t passed_arg_count,
std::
size_t expected_arg_count, internal::
ExecutionContext& context);
355 void showBacktraceWithException(const
std::exception& e, internal::
ExecutionContext& context);
364 std::optional<internal::
InstLoc> findSourceLocation(
std::
size_t ip,
std::
size_t pp) const;
366 std::
string debugShowSource() const;
395 inline
void callBuiltin(internal::
ExecutionContext& context, const
Value& builtin, uint16_t argc,
bool remove_return_address = true);
Host the declaration of all the ArkScript builtins.
Keeping track of the internal data needed by the VM.
Internal object to resolve asynchronously a function call in ArkScript.
The different instructions used by the compiler and virtual machine.
User defined literals for Ark internals.
Loads .dll/.so/.dynlib files.
State used by the virtual machine: it loads the bytecode, can compile it if needed,...
Default value type handled by the virtual machine.
Ark state to handle the dirty job of loading and compiling ArkScript code.
The ArkScript virtual machine, executing ArkScript bytecode.
internal::ExecutionContext * getDefaultContext()
Return a pointer to the first execution context, for the main thread of the app.
std::vector< std::unique_ptr< internal::Future > > m_futures
Storing the promises while we are resolving them.
int m_exit_code
VM exit code, defaults to 0. Can be changed through sys:exit
std::vector< std::shared_ptr< internal::SharedLibrary > > m_shared_lib_objects
std::vector< std::unique_ptr< internal::ExecutionContext > > m_execution_contexts
Value resolve(internal::ExecutionContext *context, const std::vector< Value > &n)
Resolves a function call (called by plugins and builtins)
const bytecode_t & bytecode() const
std::vector< uint8_t > bytecode_t