/* * Copyright (c) 2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include #include namespace JS::Bytecode { class InstructionStreamIterator; class JS_API Interpreter { public: Interpreter(); ~Interpreter(); [[nodiscard]] Realm& realm() { return *m_running_execution_context->realm; } [[nodiscard]] Object& global_object() { return realm().global_object(); } [[nodiscard]] DeclarativeEnvironment& global_declarative_environment(); static VM& vm() { return VM::the(); } ThrowCompletionOr run(Script&, GC::Ptr lexical_environment_override = nullptr); ThrowCompletionOr run(SourceTextModule&); ThrowCompletionOr run_executable(ExecutionContext&, Executable&, u32 entry_point = 0); ThrowCompletionOr run_executable(ExecutionContext& context, Executable& executable, u32 entry_point, Value initial_accumulator_value) { context.registers_and_constants_and_locals_and_arguments_span()[0] = initial_accumulator_value; return run_executable(context, executable, entry_point); } ALWAYS_INLINE Value& accumulator() { return reg(Register::accumulator()); } Value& reg(Register const& r) { return m_running_execution_context->registers_and_constants_and_locals_and_arguments()[r.index()]; } Value reg(Register const& r) const { return m_running_execution_context->registers_and_constants_and_locals_and_arguments()[r.index()]; } ALWAYS_INLINE Value get(Operand op) const { return m_running_execution_context->registers_and_constants_and_locals_and_arguments()[op.raw()]; } ALWAYS_INLINE void set(Operand op, Value value) { m_running_execution_context->registers_and_constants_and_locals_and_arguments_span().data()[op.raw()] = value; } Value do_yield(Value value, Optional