1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 21:47:43 +00:00

LibJS/JIT: Compile the Decrement bytecode instruction

This commit is contained in:
Andreas Kling 2023-10-20 12:43:08 +02:00
parent 966b6f78a6
commit 12898f5aef
3 changed files with 22 additions and 0 deletions

View file

@ -354,9 +354,11 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable& executa
if (auto native_executable = executable.get_or_create_native_executable()) {
native_executable->run(vm());
#if 0
for (size_t i = 0; i < vm().running_execution_context().local_variables.size(); ++i) {
dbgln("%{}: {}", i, vm().running_execution_context().local_variables[i]);
}
#endif
} else {
run_bytecode();

View file

@ -175,6 +175,22 @@ void Compiler::compile_increment(Bytecode::Op::Increment const&)
check_exception();
}
static Value cxx_decrement(VM& vm, Value value)
{
auto old_value = TRY_OR_SET_EXCEPTION(value.to_numeric(vm));
if (old_value.is_number())
return Value(old_value.as_double() - 1);
return BigInt::create(vm, old_value.as_bigint().big_integer().minus(Crypto::SignedBigInteger { 1 }));
}
void Compiler::compile_decrement(Bytecode::Op::Decrement const&)
{
load_vm_register(ARG1, Bytecode::Register::accumulator());
m_assembler.native_call((void*)cxx_decrement);
store_vm_register(Bytecode::Register::accumulator(), RET);
check_exception();
}
void Compiler::check_exception()
{
// if (exception.is_empty()) goto no_exception;
@ -474,6 +490,9 @@ OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_execut
case Bytecode::Instruction::Type::Increment:
compiler.compile_increment(static_cast<Bytecode::Op::Increment const&>(op));
break;
case Bytecode::Instruction::Type::Decrement:
compiler.compile_decrement(static_cast<Bytecode::Op::Decrement const&>(op));
break;
case Bytecode::Instruction::Type::EnterUnwindContext:
compiler.compile_enter_unwind_context(static_cast<Bytecode::Op::EnterUnwindContext const&>(op));
break;

View file

@ -38,6 +38,7 @@ private:
void compile_jump(Bytecode::Op::Jump const&);
void compile_jump_conditional(Bytecode::Op::JumpConditional const&);
void compile_increment(Bytecode::Op::Increment const&);
void compile_decrement(Bytecode::Op::Decrement const&);
void compile_enter_unwind_context(Bytecode::Op::EnterUnwindContext const&);
void compile_leave_unwind_context(Bytecode::Op::LeaveUnwindContext const&);
void compile_throw(Bytecode::Op::Throw const&);