mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 14:58:46 +00:00
LibJS: Implement bytecode generation for UpdateExpression :^)
Added Increment and Decrement bytecode ops to support this. Postfix updates use a temporary register to preserve the original value. Note that this patch only implements Identifier updates. Member expression updates are a TODO.
This commit is contained in:
parent
5c98f979c6
commit
59eedd6de0
Notes:
sideshowbarker
2024-07-18 12:34:29 +09:00
Author: https://github.com/awesomekling
Commit: 59eedd6de0
5 changed files with 88 additions and 1 deletions
|
@ -231,6 +231,30 @@ void Return::execute(Bytecode::Interpreter& interpreter) const
|
|||
interpreter.do_return(interpreter.accumulator().value_or(js_undefined()));
|
||||
}
|
||||
|
||||
void Increment::execute(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
auto old_value = interpreter.accumulator().to_numeric(interpreter.global_object());
|
||||
if (interpreter.vm().exception())
|
||||
return;
|
||||
|
||||
if (old_value.is_number())
|
||||
interpreter.accumulator() = Value(old_value.as_double() + 1);
|
||||
else
|
||||
interpreter.accumulator() = js_bigint(interpreter.vm().heap(), old_value.as_bigint().big_integer().plus(Crypto::SignedBigInteger { 1 }));
|
||||
}
|
||||
|
||||
void Decrement::execute(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
auto old_value = interpreter.accumulator().to_numeric(interpreter.global_object());
|
||||
if (interpreter.vm().exception())
|
||||
return;
|
||||
|
||||
if (old_value.is_number())
|
||||
interpreter.accumulator() = Value(old_value.as_double() - 1);
|
||||
else
|
||||
interpreter.accumulator() = js_bigint(interpreter.vm().heap(), old_value.as_bigint().big_integer().minus(Crypto::SignedBigInteger { 1 }));
|
||||
}
|
||||
|
||||
String Load::to_string() const
|
||||
{
|
||||
return String::formatted("Load {}", m_src);
|
||||
|
@ -349,4 +373,14 @@ String Return::to_string() const
|
|||
return "Return";
|
||||
}
|
||||
|
||||
String Increment::to_string() const
|
||||
{
|
||||
return "Increment";
|
||||
}
|
||||
|
||||
String Decrement::to_string() const
|
||||
{
|
||||
return "Decrement";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue