/* * Copyright (c) 2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include namespace JS::Bytecode { class InstructionStreamIterator; class JS_API Interpreter { public: explicit Interpreter(VM&); ~Interpreter(); [[nodiscard]] Realm& realm() { return *m_running_execution_context->realm; } [[nodiscard]] Object& global_object() { return *m_running_execution_context->global_object; } [[nodiscard]] DeclarativeEnvironment& global_declarative_environment() { return *m_running_execution_context->global_declarative_environment; } VM& vm() { return m_vm; } VM const& vm() const { return m_vm; } ThrowCompletionOr run(Script&, GC::Ptr lexical_environment_override = nullptr); ThrowCompletionOr run(SourceTextModule&); ThrowCompletionOr run_executable(ExecutionContext&, Executable&, Optional entry_point); ThrowCompletionOr run_executable(ExecutionContext& context, Executable& executable, Optional 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()); } ALWAYS_INLINE Value& saved_return_value() { return reg(Register::saved_return_value()); } 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()]; } [[nodiscard]] Value get(Operand) const; void set(Operand, Value); Value do_yield(Value value, Optional