소스 검색

LibJS/JIT: Compile the IteratorClose instruction

Simon Wanner 1 년 전
부모
커밋
c697ff61f6
3개의 변경된 파일28개의 추가작업 그리고 1개의 파일을 삭제
  1. 3 0
      Userland/Libraries/LibJS/Bytecode/Op.h
  2. 23 0
      Userland/Libraries/LibJS/JIT/Compiler.cpp
  3. 2 1
      Userland/Libraries/LibJS/JIT/Compiler.h

+ 3 - 0
Userland/Libraries/LibJS/Bytecode/Op.h

@@ -1343,6 +1343,9 @@ public:
     ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
     DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
 
+    Completion::Type completion_type() const { return m_completion_type; }
+    Optional<Value> const& completion_value() const { return m_completion_value; }
+
 private:
     Completion::Type m_completion_type { Completion::Type::Normal };
     Optional<Value> m_completion_value;

+ 23 - 0
Userland/Libraries/LibJS/JIT/Compiler.cpp

@@ -1283,6 +1283,29 @@ void Compiler::compile_iterator_result_value(Bytecode::Op::IteratorResultValue c
     check_exception();
 }
 
+static Value cxx_iterator_close(VM& vm, Value iterator, Completion::Type completion_type, Optional<Value> const& completion_value)
+{
+    auto iterator_object = TRY_OR_SET_EXCEPTION(iterator.to_object(vm));
+    auto iterator_record = Bytecode::object_to_iterator(vm, iterator_object);
+
+    // FIXME: Return the value of the resulting completion. (Note that m_completion_value can be empty!)
+    TRY_OR_SET_EXCEPTION(iterator_close(vm, iterator_record, Completion { completion_type, completion_value, {} }));
+    return {};
+}
+
+void Compiler::compile_iterator_close(Bytecode::Op::IteratorClose const& op)
+{
+    load_vm_register(ARG1, Bytecode::Register::accumulator());
+    m_assembler.mov(
+        Assembler::Operand::Register(ARG2),
+        Assembler::Operand::Imm(to_underlying(op.completion_type())));
+    m_assembler.mov(
+        Assembler::Operand::Register(ARG3),
+        Assembler::Operand::Imm(bit_cast<u64>(&op.completion_value())));
+    native_call((void*)cxx_iterator_close);
+    check_exception();
+}
+
 void Compiler::jump_to_exit()
 {
     m_assembler.jump(m_exit_label);

+ 2 - 1
Userland/Libraries/LibJS/JIT/Compiler.h

@@ -111,7 +111,8 @@ private:
         O(IteratorResultDone, iterator_result_done)                              \
         O(ThrowIfNotObject, throw_if_not_object)                                 \
         O(ThrowIfNullish, throw_if_nullish)                                      \
-        O(IteratorResultValue, iterator_result_value)
+        O(IteratorResultValue, iterator_result_value)                            \
+        O(IteratorClose, iterator_close)
 
 #    define DECLARE_COMPILE_OP(OpTitleCase, op_snake_case) \
         void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);