mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-21 10:19:03 +03:00
LibJS/Bytecode: Add constants table to Bytecode::Executable
This commit is contained in:
parent
3466771492
commit
e46de4eb59
Notes:
sideshowbarker
2024-07-18 04:46:35 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/e46de4eb59 Pull-request: https://github.com/SerenityOS/serenity/pull/23259 Reviewed-by: https://github.com/trflynn89 ✅
@ -17,6 +17,7 @@ Executable::Executable(
|
||||
NonnullOwnPtr<IdentifierTable> identifier_table,
|
||||
NonnullOwnPtr<StringTable> string_table,
|
||||
NonnullOwnPtr<RegexTable> regex_table,
|
||||
Vector<Value> constants,
|
||||
NonnullRefPtr<SourceCode const> source_code,
|
||||
size_t number_of_property_lookup_caches,
|
||||
size_t number_of_global_variable_caches,
|
||||
@ -28,6 +29,7 @@ Executable::Executable(
|
||||
, string_table(move(string_table))
|
||||
, identifier_table(move(identifier_table))
|
||||
, regex_table(move(regex_table))
|
||||
, constants(move(constants))
|
||||
, source_code(move(source_code))
|
||||
, number_of_registers(number_of_registers)
|
||||
, is_strict_mode(is_strict_mode)
|
||||
|
@ -51,6 +51,7 @@ public:
|
||||
NonnullOwnPtr<IdentifierTable>,
|
||||
NonnullOwnPtr<StringTable>,
|
||||
NonnullOwnPtr<RegexTable>,
|
||||
Vector<Value> constants,
|
||||
NonnullRefPtr<SourceCode const>,
|
||||
size_t number_of_property_lookup_caches,
|
||||
size_t number_of_global_variable_caches,
|
||||
@ -69,6 +70,7 @@ public:
|
||||
NonnullOwnPtr<StringTable> string_table;
|
||||
NonnullOwnPtr<IdentifierTable> identifier_table;
|
||||
NonnullOwnPtr<RegexTable> regex_table;
|
||||
Vector<Value> constants;
|
||||
|
||||
NonnullRefPtr<SourceCode const> source_code;
|
||||
size_t number_of_registers { 0 };
|
||||
|
@ -62,6 +62,7 @@ CodeGenerationErrorOr<NonnullGCPtr<Executable>> Generator::generate(VM& vm, ASTN
|
||||
move(generator.m_identifier_table),
|
||||
move(generator.m_string_table),
|
||||
move(generator.m_regex_table),
|
||||
move(generator.m_constants),
|
||||
node.source_code(),
|
||||
generator.m_next_property_lookup_cache,
|
||||
generator.m_next_global_variable_cache,
|
||||
|
@ -241,6 +241,16 @@ public:
|
||||
[[nodiscard]] size_t next_environment_variable_cache() { return m_next_environment_variable_cache++; }
|
||||
[[nodiscard]] size_t next_property_lookup_cache() { return m_next_property_lookup_cache++; }
|
||||
|
||||
[[nodiscard]] Operand add_constant(Value value)
|
||||
{
|
||||
for (size_t i = 0; i < m_constants.size(); ++i) {
|
||||
if (m_constants[i] == value)
|
||||
return Operand(Operand::Type::Constant, i);
|
||||
}
|
||||
m_constants.append(value);
|
||||
return Operand(Operand::Type::Constant, m_constants.size() - 1);
|
||||
}
|
||||
|
||||
private:
|
||||
enum class JumpType {
|
||||
Continue,
|
||||
@ -267,6 +277,7 @@ private:
|
||||
NonnullOwnPtr<StringTable> m_string_table;
|
||||
NonnullOwnPtr<IdentifierTable> m_identifier_table;
|
||||
NonnullOwnPtr<RegexTable> m_regex_table;
|
||||
Vector<Value> m_constants;
|
||||
|
||||
u32 m_next_register { Register::reserved_register_count };
|
||||
u32 m_next_block { 1 };
|
||||
|
Loading…
Reference in New Issue
Block a user