1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:27:35 +00:00

LibJS: Defer Value construction until a Literal is executed

Remove the need to construct a full Value during parsing. This means
we don't have to worry about plumbing the heap into the parser.

The Literal ASTNode now has a bunch of subclasses that synthesize a
Value on demand.
This commit is contained in:
Andreas Kling 2020-03-12 12:19:11 +01:00
parent 4d942cc1d0
commit 425fd3ce51
3 changed files with 73 additions and 8 deletions

View file

@ -290,19 +290,56 @@ private:
};
class Literal : public Expression {
protected:
explicit Literal() {}
};
class BooleanLiteral final : public Literal {
public:
explicit Literal(Value value)
explicit BooleanLiteral(bool value)
: m_value(value)
{
}
virtual Value execute(Interpreter&) const override;
virtual void dump(int indent) const override;
private:
virtual const char* class_name() const override { return "BooleanLiteral"; }
bool m_value { false };
};
class NumericLiteral final : public Literal {
public:
explicit NumericLiteral(double value)
: m_value(value)
{
}
virtual Value execute(Interpreter&) const override;
virtual void dump(int indent) const override;
private:
virtual const char* class_name() const override { return "NumericLiteral"; }
double m_value { 0 };
};
class StringLiteral final : public Literal {
public:
explicit StringLiteral(String value)
: m_value(move(value))
{
}
virtual Value execute(Interpreter&) const override { return m_value; }
virtual Value execute(Interpreter&) const override;
virtual void dump(int indent) const override;
private:
virtual const char* class_name() const override { return "Literal"; }
virtual const char* class_name() const override { return "StringLiteral"; }
Value m_value;
String m_value;
};
class Identifier final : public Expression {