21#include <unordered_map>
24#include <fmt/ranges.h>
41 using namespace std::string_literals;
55 explicit VM(
State& state)
noexcept;
63 int run(
bool fail_with_exception =
false);
71 Value& operator[](
const std::string& name)
noexcept;
81 template <
typename... Args>
82 Value call(
const std::string& name, Args&&... args);
102 void exit(
int code)
noexcept;
110 return m_execution_contexts.front().get();
152 [[nodiscard]]
bool forceReloadPlugins()
const;
160 void usePromptFileForDebugger(
const std::string& path, std::ostream& os = std::cout);
172 return m_state.m_bytecode;
187 std::vector<std::unique_ptr<internal::Future>>
m_futures;
188 std::unique_ptr<internal::Debugger> m_debugger {
nullptr };
191 Value m_no_value = internal::Builtins::nil;
208 void init() noexcept;
230 [[nodiscard]] inline
Value* loadSymbolFromIndex(uint16_t index, internal::
ExecutionContext& context);
238 [[nodiscard]] inline
Value* loadConstAsPtr(uint16_t
id) const;
365 uint16_t findNearestVariableIdWithValue(const
Value& value, internal::
ExecutionContext& context) const noexcept;
367 [[noreturn]]
void throwArityError(
std::
size_t passed_arg_count,
std::
size_t expected_arg_count, internal::
ExecutionContext& context,
bool skip_function = true);
371 void showBacktraceWithException(const
std::exception& e, internal::
ExecutionContext& context);
380 [[nodiscard]]
std::optional<internal::
InstLoc> findSourceLocation(
std::
size_t ip,
std::
size_t pp) const;
382 [[nodiscard]]
std::
string debugShowSource() const;
412 inline
void callBuiltin(internal::
ExecutionContext& context, const
Value& builtin, uint16_t argc,
bool remove_return_address = true,
bool remove_builtin = true);
Host the declaration of all the ArkScript builtins.
Debugger used by the VM when an error or a breakpoint is reached.
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.
The virtual machine scope system.
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