summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-06-07 21:18:19 +0100
committerLinus Groh <mail@linusgroh.de>2021-06-07 21:18:35 +0100
commit9c0d83d11dd8eb79c00aa6d7de5df399c52c172d (patch)
treee617e5ec13a1888999f0263989d71840e5c8ec16 /Userland
parent5e996de8c688ab4db56f3b54cc0d3486011115b3 (diff)
downloadserenity-9c0d83d11dd8eb79c00aa6d7de5df399c52c172d.zip
LibJS: Add bytecode generation for BinaryOp::InstanceOf
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp5
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Instruction.h3
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Op.cpp10
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Op.h19
4 files changed, 35 insertions, 2 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
index cffcf1a7b5..0a7dc29003 100644
--- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
+++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
@@ -113,8 +113,11 @@ Optional<Bytecode::Register> BinaryExpression::generate_bytecode(Bytecode::Gener
case BinaryOp::In:
generator.emit<Bytecode::Op::In>(dst_reg, *lhs_reg, *rhs_reg);
return dst_reg;
+ case BinaryOp::InstanceOf:
+ generator.emit<Bytecode::Op::InstanceOf>(dst_reg, *lhs_reg, *rhs_reg);
+ return dst_reg;
default:
- TODO();
+ VERIFY_NOT_REACHED();
}
}
diff --git a/Userland/Libraries/LibJS/Bytecode/Instruction.h b/Userland/Libraries/LibJS/Bytecode/Instruction.h
index bb52b84cc9..11d0bf2978 100644
--- a/Userland/Libraries/LibJS/Bytecode/Instruction.h
+++ b/Userland/Libraries/LibJS/Bytecode/Instruction.h
@@ -49,7 +49,8 @@
O(LeftShift) \
O(RightShift) \
O(UnsignedRightShift) \
- O(In)
+ O(In) \
+ O(InstanceOf)
namespace JS::Bytecode {
diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp
index f44086f3e9..1e8d6878bd 100644
--- a/Userland/Libraries/LibJS/Bytecode/Op.cpp
+++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp
@@ -163,6 +163,11 @@ void In::execute(Bytecode::Interpreter& interpreter) const
interpreter.reg(m_dst) = in(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
}
+void InstanceOf::execute(Bytecode::Interpreter& interpreter) const
+{
+ interpreter.reg(m_dst) = instance_of(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));
@@ -405,6 +410,11 @@ String In::to_string() const
return String::formatted("In dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
}
+String InstanceOf::to_string() const
+{
+ return String::formatted("In dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
+}
+
String BitwiseNot::to_string() const
{
return String::formatted("BitwiseNot dst:{}, src:{}", m_dst, m_src);
diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h
index 998e344d0e..7dd8cb945c 100644
--- a/Userland/Libraries/LibJS/Bytecode/Op.h
+++ b/Userland/Libraries/LibJS/Bytecode/Op.h
@@ -449,6 +449,25 @@ private:
Register m_src2;
};
+class InstanceOf final : public Instruction {
+public:
+ InstanceOf(Register dst, Register src1, Register src2)
+ : Instruction(Type::InstanceOf)
+ , m_dst(dst)
+ , m_src1(src1)
+ , m_src2(src2)
+ {
+ }
+
+ void execute(Bytecode::Interpreter&) const;
+ String to_string() const;
+
+private:
+ Register m_dst;
+ Register m_src1;
+ Register m_src2;
+};
+
class BitwiseNot final : public Instruction {
public:
BitwiseNot(Register dst, Register src)