Selaa lähdekoodia

LibJS/JIT: Compile the ToNumeric bytecode instruction

Andreas Kling 1 vuosi sitten
vanhempi
commit
b2602a4bae

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

@@ -386,6 +386,19 @@ void Compiler::compile_get_by_id(Bytecode::Op::GetById const& op)
     check_exception();
     check_exception();
 }
 }
 
 
+static Value cxx_to_numeric(VM& vm, Value value)
+{
+    return TRY_OR_SET_EXCEPTION(value.to_numeric(vm));
+}
+
+void Compiler::compile_to_numeric(Bytecode::Op::ToNumeric const&)
+{
+    load_vm_register(ARG1, Bytecode::Register::accumulator());
+    m_assembler.native_call((void*)cxx_to_numeric);
+    store_vm_register(Bytecode::Register::accumulator(), RET);
+    check_exception();
+}
+
 OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_executable)
 OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_executable)
 {
 {
     if (getenv("LIBJS_NO_JIT"))
     if (getenv("LIBJS_NO_JIT"))
@@ -453,6 +466,9 @@ OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_execut
             case Bytecode::Instruction::Type::GetById:
             case Bytecode::Instruction::Type::GetById:
                 compiler.compile_get_by_id(static_cast<Bytecode::Op::GetById const&>(op));
                 compiler.compile_get_by_id(static_cast<Bytecode::Op::GetById const&>(op));
                 break;
                 break;
+            case Bytecode::Instruction::Type::ToNumeric:
+                compiler.compile_to_numeric(static_cast<Bytecode::Op::ToNumeric const&>(op));
+                break;
 
 
 #define DO_COMPILE_COMMON_BINARY_OP(TitleCaseName, snake_case_name)                              \
 #define DO_COMPILE_COMMON_BINARY_OP(TitleCaseName, snake_case_name)                              \
     case Bytecode::Instruction::Type::TitleCaseName:                                             \
     case Bytecode::Instruction::Type::TitleCaseName:                                             \

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

@@ -41,6 +41,7 @@ private:
     void compile_enter_unwind_context(Bytecode::Op::EnterUnwindContext const&);
     void compile_enter_unwind_context(Bytecode::Op::EnterUnwindContext const&);
     void compile_leave_unwind_context(Bytecode::Op::LeaveUnwindContext const&);
     void compile_leave_unwind_context(Bytecode::Op::LeaveUnwindContext const&);
     void compile_throw(Bytecode::Op::Throw const&);
     void compile_throw(Bytecode::Op::Throw const&);
+    void compile_to_numeric(Bytecode::Op::ToNumeric const&);
 
 
 #define DO_COMPILE_COMMON_BINARY_OP(OpTitleCase, op_snake_case) \
 #define DO_COMPILE_COMMON_BINARY_OP(OpTitleCase, op_snake_case) \
     void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);
     void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);