Quellcode durchsuchen

LibJS: Compile the NewBigInt bytecode instruction

Idan Horowitz vor 1 Jahr
Ursprung
Commit
2b65a80ecb

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

@@ -256,6 +256,8 @@ public:
     ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
     DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
 
+    Crypto::SignedBigInteger const& bigint() const { return m_bigint; }
+
 private:
     Crypto::SignedBigInteger m_bigint;
 };

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

@@ -637,6 +637,20 @@ void Compiler::compile_new_regexp(Bytecode::Op::NewRegExp const& op)
     store_vm_register(Bytecode::Register::accumulator(), RET);
 }
 
+static Value cxx_new_bigint(VM& vm, Crypto::SignedBigInteger const& bigint)
+{
+    return BigInt::create(vm, bigint);
+}
+
+void Compiler::compile_new_bigint(Bytecode::Op::NewBigInt const& op)
+{
+    m_assembler.mov(
+        Assembler::Operand::Register(ARG1),
+        Assembler::Operand::Imm(bit_cast<u64>(&op.bigint())));
+    native_call((void*)cxx_new_bigint);
+    store_vm_register(Bytecode::Register::accumulator(), RET);
+}
+
 static Value cxx_new_object(VM& vm)
 {
     auto& realm = *vm.current_realm();
@@ -1106,6 +1120,9 @@ OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_execut
             case Bytecode::Instruction::Type::NewRegExp:
                 compiler.compile_new_regexp(static_cast<Bytecode::Op::NewRegExp const&>(op));
                 break;
+            case Bytecode::Instruction::Type::NewBigInt:
+                compiler.compile_new_bigint(static_cast<Bytecode::Op::NewBigInt const&>(op));
+                break;
             case Bytecode::Instruction::Type::GetById:
                 compiler.compile_get_by_id(static_cast<Bytecode::Op::GetById const&>(op));
                 break;

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

@@ -99,6 +99,7 @@ private:
     void compile_new_array(Bytecode::Op::NewArray const&);
     void compile_new_function(Bytecode::Op::NewFunction const&);
     void compile_new_regexp(Bytecode::Op::NewRegExp const&);
+    void compile_new_bigint(Bytecode::Op::NewBigInt const&);
 
     void compile_get_by_id(Bytecode::Op::GetById const&);
     void compile_get_by_value(Bytecode::Op::GetByValue const&);