summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Bytecode/Op.cpp
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-06-09 06:49:58 +0430
committerAndreas Kling <kling@serenityos.org>2021-06-09 09:07:29 +0200
commit01e8f0889acf9fc0c84402793ecf96859c737f9a (patch)
treed3451229cdfd0117929b2216ca91a011a34e2d9e /Userland/Libraries/LibJS/Bytecode/Op.cpp
parentd7a25cdb82ff5326236934dd6e99e1a1b2bef3fe (diff)
downloadserenity-01e8f0889acf9fc0c84402793ecf96859c737f9a.zip
LibJS: Generate bytecode in basic blocks instead of one big block
This limits the size of each block (currently set to 1K), and gets us closer to a canonical, more easily analysable bytecode format. As a result of this, "Labels" are now simply entries to basic blocks. Since there is no more 'conditional' jump (as all jumps are always taken), JumpIf{True,False} are unified to JumpConditional, and JumpIfNullish is renamed to JumpNullish. Also fixes #7914 as a result of reimplementing the loop logic.
Diffstat (limited to 'Userland/Libraries/LibJS/Bytecode/Op.cpp')
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Op.cpp57
1 files changed, 25 insertions, 32 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp
index 60733de8e2..ce4903c8e2 100644
--- a/Userland/Libraries/LibJS/Bytecode/Op.cpp
+++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp
@@ -174,31 +174,29 @@ void PutById::execute(Bytecode::Interpreter& interpreter) const
void Jump::execute(Bytecode::Interpreter& interpreter) const
{
- interpreter.jump(*m_target);
+ interpreter.jump(*m_true_target);
}
-void JumpIfFalse::execute(Bytecode::Interpreter& interpreter) const
+void JumpConditional::execute(Bytecode::Interpreter& interpreter) const
{
- VERIFY(m_target.has_value());
- auto result = interpreter.accumulator();
- if (!result.to_boolean())
- interpreter.jump(m_target.value());
-}
-
-void JumpIfTrue::execute(Bytecode::Interpreter& interpreter) const
-{
- VERIFY(m_target.has_value());
+ VERIFY(m_true_target.has_value());
+ VERIFY(m_false_target.has_value());
auto result = interpreter.accumulator();
if (result.to_boolean())
- interpreter.jump(m_target.value());
+ interpreter.jump(m_true_target.value());
+ else
+ interpreter.jump(m_false_target.value());
}
-void JumpIfNotNullish::execute(Bytecode::Interpreter& interpreter) const
+void JumpNullish::execute(Bytecode::Interpreter& interpreter) const
{
- VERIFY(m_target.has_value());
+ VERIFY(m_true_target.has_value());
+ VERIFY(m_false_target.has_value());
auto result = interpreter.accumulator();
- if (!result.is_nullish())
- interpreter.jump(m_target.value());
+ if (result.is_nullish())
+ interpreter.jump(m_true_target.value());
+ else
+ interpreter.jump(m_false_target.value());
}
void Call::execute(Bytecode::Interpreter& interpreter) const
@@ -321,28 +319,23 @@ String GetById::to_string() const
String Jump::to_string() const
{
- return String::formatted("Jump {}", *m_target);
-}
-
-String JumpIfFalse::to_string() const
-{
- if (m_target.has_value())
- return String::formatted("JumpIfFalse target:{}", m_target.value());
- return "JumpIfFalse target:<empty>";
+ if (m_true_target.has_value())
+ return String::formatted("Jump {}", *m_true_target);
+ return String::formatted("Jump <empty>");
}
-String JumpIfTrue::to_string() const
+String JumpConditional::to_string() const
{
- if (m_target.has_value())
- return String::formatted("JumpIfTrue target:{}", m_target.value());
- return "JumpIfTrue result:{}, target:<empty>";
+ auto true_string = m_true_target.has_value() ? String::formatted("{}", *m_true_target) : "<empty>";
+ auto false_string = m_false_target.has_value() ? String::formatted("{}", *m_false_target) : "<empty>";
+ return String::formatted("JumpConditional true:{} false:{}", true_string, false_string);
}
-String JumpIfNotNullish::to_string() const
+String JumpNullish::to_string() const
{
- if (m_target.has_value())
- return String::formatted("JumpIfNotNullish target:{}", m_target.value());
- return "JumpIfNotNullish target:<empty>";
+ auto true_string = m_true_target.has_value() ? String::formatted("{}", *m_true_target) : "<empty>";
+ auto false_string = m_false_target.has_value() ? String::formatted("{}", *m_false_target) : "<empty>";
+ return String::formatted("JumpNullish null:{} nonnull:{}", true_string, false_string);
}
String Call::to_string() const