47 explicit VM(
State& state)
noexcept;
55 int run(
bool fail_with_exception =
false);
63 Value& operator[](
const std::string& name)
noexcept;
73 template <
typename... Args>
74 Value call(
const std::string& name, Args&&... args);
94 void exit(
int code)
noexcept;
102 return m_execution_contexts.front().get();
144 [[nodiscard]]
bool forceReloadPlugins()
const;
152 void usePromptFileForDebugger(
const std::string& path, std::ostream& os = std::cout);
160 [[noreturn]]
static void throwVMError(
internal::ErrorKind kind,
const std::string& message);
164 return m_state.m_bytecode;
179 std::vector<std::unique_ptr<internal::Future>>
m_futures;
180 std::unique_ptr<internal::Debugger> m_debugger {
nullptr };
183 Value m_no_value = internal::Builtins::nil;
196 template <
bool WithDebugger>
202 throw Error(
"Stack overflow. You could consider rewriting your function to make use of tail-call optimization.");
204 throw Error(
"Stack overflow. Are you trying to call a function with too many arguments?");
211 void init() noexcept;
233 [[nodiscard]] inline ARK_ALWAYS_INLINE
Value* loadSymbolFromIndex(uint16_t index, internal::
ExecutionContext& context);
241 [[nodiscard]] inline ARK_ALWAYS_INLINE
Value* loadConstAsPtr(uint16_t
id) const;
272 [[nodiscard]]
Value getField(
Value* closure, uint16_t
id, const internal::
ExecutionContext& context,
bool push_with_env = false);
373 inline
void callBuiltin(internal::
ExecutionContext& context, const
Value& builtin, uint16_t argc,
bool remove_return_address = true,
bool remove_builtin = true);
396 uint16_t findNearestVariableIdWithValue(const
Value& value, internal::
ExecutionContext& context) const noexcept;
398 [[noreturn]]
void throwArityError(
std::
size_t passed_arg_count,
std::
size_t expected_arg_count, internal::
ExecutionContext& context,
bool skip_function = true);
402 void showBacktraceWithException(const
std::exception& e, internal::
ExecutionContext& context);
411 [[nodiscard]]
std::optional<internal::
InstLoc> findSourceLocation(
std::
size_t ip,
std::
size_t pp) const;
413 [[nodiscard]]
std::
string debugShowSource() const;
Keeping track of the internal data needed by the VM.
Value resolve(internal::ExecutionContext *context, const std::vector< Value > &n)
Resolves a function call (called by plugins and builtins)
Value call(const std::string &name, Args &&... args)
Call a function from ArkScript, by giving it arguments.