1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 13:27:35 +00:00

LibJS: Compile the NewBigInt bytecode instruction

This commit is contained in:
Idan Horowitz 2023-10-28 19:58:36 +03:00 committed by Andreas Kling
parent d200361620
commit 2b65a80ecb
3 changed files with 20 additions and 0 deletions

View file

@ -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;
};

View file

@ -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;

View file

@ -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&);