21#include <unordered_map>
24#include <fmt/ranges.h>
39 using namespace std::string_literals;
53 explicit VM(
State& state)
noexcept;
61 int run(
bool fail_with_exception =
false);
69 Value& operator[](
const std::string& name)
noexcept;
79 template <
typename... Args>
80 Value call(
const std::string& name, Args&&... args);
100 void exit(
int code)
noexcept;
108 return m_execution_contexts.front().get();
150 [[nodiscard]]
bool forceReloadPlugins()
const;
158 [[noreturn]]
static void throwVMError(
internal::ErrorKind kind,
const std::string& message);
171 std::vector<std::unique_ptr<internal::Future>>
m_futures;
174 Value m_no_value = internal::Builtins::nil;
191 void init() noexcept;
213 [[nodiscard]] inline
Value* loadSymbolFromIndex(uint16_t index, internal::
ExecutionContext& context);
221 [[nodiscard]] inline
Value* loadConstAsPtr(uint16_t
id) const;
343 uint16_t findNearestVariableIdWithValue(const
Value& value, internal::
ExecutionContext& context) const noexcept;
345 [[noreturn]]
void throwArityError(std::
size_t passed_arg_count, std::
size_t expected_arg_count, internal::
ExecutionContext& context);
347 void showBacktraceWithException(const std::exception& e, internal::
ExecutionContext& context);
356 std::optional<internal::
InstLoc> findSourceLocation(std::
size_t ip, std::
size_t pp);
358 std::
string debugShowSource();
367 void backtrace(internal::
ExecutionContext& context, std::ostream& os = std::cout,
bool colorize = true);
387 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.
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 auto False
ArkScript False value.
const auto Nil
ArkScript Nil value.
const auto True
ArkScript True value.