1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:38:11 +00:00

LibJS: Add bytecode instructions for a bunch of unary operators

~, !, +, -, typeof, and void.
This commit is contained in:
Linus Groh 2021-06-07 19:53:47 +01:00
parent 54fc7079c6
commit fa9bad912e
5 changed files with 175 additions and 1 deletions

View file

@ -127,6 +127,32 @@ void BitwiseXor::execute(Bytecode::Interpreter& interpreter) const
interpreter.reg(m_dst) = bitwise_xor(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
}
void BitwiseNot::execute(Bytecode::Interpreter& interpreter) const
{
interpreter.reg(m_dst) = bitwise_not(interpreter.global_object(), interpreter.reg(m_src));
}
void Not::execute(Bytecode::Interpreter& interpreter) const
{
interpreter.reg(m_dst) = Value(!interpreter.reg(m_src).to_boolean());
}
void UnaryPlus::execute(Bytecode::Interpreter& interpreter) const
{
interpreter.reg(m_dst) = Value(unary_plus(interpreter.global_object(), interpreter.reg(m_src)));
}
void UnaryMinus::execute(Bytecode::Interpreter& interpreter) const
{
interpreter.reg(m_dst) = Value(unary_minus(interpreter.global_object(), interpreter.reg(m_src)));
}
void Typeof::execute(Bytecode::Interpreter& interpreter) const
{
auto& vm = interpreter.global_object().vm();
interpreter.reg(m_dst) = Value(js_string(vm, interpreter.reg(m_src).typeof()));
}
void NewString::execute(Bytecode::Interpreter& interpreter) const
{
interpreter.reg(m_dst) = js_string(interpreter.vm(), m_string);
@ -308,6 +334,31 @@ String BitwiseXor::to_string() const
return String::formatted("BitwiseXor dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
}
String BitwiseNot::to_string() const
{
return String::formatted("BitwiseNot dst:{}, src:{}", m_dst, m_src);
}
String Not::to_string() const
{
return String::formatted("Not dst:{}, src:{}", m_dst, m_src);
}
String UnaryPlus::to_string() const
{
return String::formatted("UnaryPlus dst:{}, src:{}", m_dst, m_src);
}
String UnaryMinus::to_string() const
{
return String::formatted("UnaryMinus dst:{}, src:{}", m_dst, m_src);
}
String Typeof::to_string() const
{
return String::formatted("Typeof dst:{}, src:{}", m_dst, m_src);
}
String NewString::to_string() const
{
return String::formatted("NewString dst:{}, string:\"{}\"", m_dst, m_string);