Skip to content

Commit

Permalink
LibJS: FDI bytecode WIP
Browse files Browse the repository at this point in the history
LibJS: FDI bytecode WIP CreateMappedArguments

LibJS: FDI bytecode WIP CreateRestParams

LibWeb: FDI bytecode WIP create variable for non-locals

LibJS: FDI bytecode WIP CreateUnmappedArguments

LibJS: FDI bytecode WIP fill arguments with js_undefined

LibJS: FDI bytecode WIP init annexB

LibJS: FDI bytecode WIP default params for bindings

LibJS: FDI bytecode WIP rest hack

LibJS: FDI bytecode WIP init annexB functions

LibWeb: FDI bytecode WIP

LibWeb: FDI bytecode WIP create lex env when needed

LibJS: FDI bytecode WIP mapped args length

LibJS: FDI bytecode WIP WIP

LibJS: FDI bytecode WIP comment out default params executables

LibJS: FDI bytecode WIP hmmmmmmm

LibJS: FDI bytecode WIP some progress

LibJS: FDI bytecode WIP some progress

LibJS: FDI bytecode WIP wat

LibJS: FDI bytecode WIP save argument count in copied EC

LibJS: FDI bytecode WIP dupes

LibJS: FDI bytecode WIP module wrappers fix

LibJS: FDI bytecode WIP some progress

LibJS: FDI bytecode WIP some progress

LibJS: FDI bytecode WIP some progress

LibJS: FDI bytecode WIP some cleanup

LibJS: FDI bytecode WIP some cleanup

LibJS: FDI bytecode WIP some cleanup

LibJS: FDI bytecode WIP some cleanup

LibJS: FDI bytecode WIP some cleanup
  • Loading branch information
kalenikaliaksandr committed May 8, 2024
1 parent 8d3eb93 commit ba01afe
Show file tree
Hide file tree
Showing 16 changed files with 570 additions and 440 deletions.
16 changes: 14 additions & 2 deletions Userland/Libraries/LibJS/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <LibJS/Bytecode/CodeGenerationError.h>
#include <LibJS/Bytecode/Executable.h>
#include <LibJS/Bytecode/IdentifierTable.h>
#include <LibJS/Bytecode/Op.h>
#include <LibJS/Bytecode/Operand.h>
#include <LibJS/Forward.h>
#include <LibJS/Heap/Handle.h>
Expand Down Expand Up @@ -710,6 +711,9 @@ class FunctionNode {
FunctionKind kind() const { return m_kind; }
UsesThis uses_this() const { return m_uses_this; }

virtual bool has_name() const = 0;
virtual Value instantiate_ordinary_function_expression(VM&, DeprecatedFlyString given_name) const = 0;

protected:
FunctionNode(RefPtr<Identifier const> name, ByteString source_text, NonnullRefPtr<Statement const> body, Vector<FunctionParameter> parameters, i32 function_length, FunctionKind kind, bool is_strict_mode, bool might_need_arguments_object, bool contains_direct_call_to_eval, bool is_arrow_function, Vector<DeprecatedFlyString> local_variables_names, UsesThis uses_this)
: m_name(move(name))
Expand Down Expand Up @@ -769,6 +773,12 @@ class FunctionDeclaration final

void set_should_do_additional_annexB_steps() { m_is_hoisted = true; }

bool has_name() const override { return true; }
Value instantiate_ordinary_function_expression(VM&, DeprecatedFlyString) const override
{
VERIFY_NOT_REACHED();
}

private:
bool m_is_hoisted { false };
};
Expand All @@ -790,9 +800,9 @@ class FunctionExpression final
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::Operand>> generate_bytecode(Bytecode::Generator&, Optional<Bytecode::Operand> preferred_dst = {}) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::Operand>> generate_bytecode_with_lhs_name(Bytecode::Generator&, Optional<Bytecode::IdentifierTableIndex> lhs_name, Optional<Bytecode::Operand> preferred_dst = {}) const;

bool has_name() const { return !name().is_empty(); }
bool has_name() const override { return !name().is_empty(); }

Value instantiate_ordinary_function_expression(VM&, DeprecatedFlyString given_name) const;
Value instantiate_ordinary_function_expression(VM&, DeprecatedFlyString given_name) const override;

private:
virtual bool is_function_expression() const override { return true; }
Expand Down Expand Up @@ -2181,6 +2191,8 @@ class SyntheticReferenceExpression final : public Expression {
Value m_value;
};

Bytecode::CodeGenerationErrorOr<void> generate_binding_pattern_bytecode(Bytecode::Generator& generator, BindingPattern const& pattern, Bytecode::Op::SetVariable::InitializationMode, Bytecode::Operand const& input_value, bool create_variables);

template<>
inline bool ASTNode::fast_is<NewExpression>() const { return is_new_expression(); }

Expand Down
4 changes: 1 addition & 3 deletions Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,6 @@ Bytecode::CodeGenerationErrorOr<Optional<Bytecode::Operand>> SuperCall::generate
return dst;
}

static Bytecode::CodeGenerationErrorOr<void> generate_binding_pattern_bytecode(Bytecode::Generator& generator, BindingPattern const& pattern, Bytecode::Op::SetVariable::InitializationMode, Bytecode::Operand const& input_value, bool create_variables);

Bytecode::CodeGenerationErrorOr<Optional<Bytecode::Operand>> AssignmentExpression::generate_bytecode(Bytecode::Generator& generator, Optional<Bytecode::Operand> preferred_dst) const
{
Bytecode::Generator::SourceLocationScope scope(generator, *this);
Expand Down Expand Up @@ -1410,7 +1408,7 @@ static Bytecode::CodeGenerationErrorOr<void> generate_array_binding_pattern_byte
return {};
}

static Bytecode::CodeGenerationErrorOr<void> generate_binding_pattern_bytecode(Bytecode::Generator& generator, BindingPattern const& pattern, Bytecode::Op::SetVariable::InitializationMode initialization_mode, Bytecode::Operand const& input_value, bool create_variables)
Bytecode::CodeGenerationErrorOr<void> generate_binding_pattern_bytecode(Bytecode::Generator& generator, BindingPattern const& pattern, Bytecode::Op::SetVariable::InitializationMode initialization_mode, Bytecode::Operand const& input_value, bool create_variables)
{
if (pattern.kind == BindingPattern::Kind::Object)
return generate_object_binding_pattern_bytecode(generator, pattern, initialization_mode, input_value, create_variables);
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibJS/Bytecode/CommonImplementations.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ inline ThrowCompletionOr<void> set_variable(
return {};
}

inline Value new_function(VM& vm, FunctionExpression const& function_node, Optional<IdentifierTableIndex> const& lhs_name, Optional<Operand> const& home_object)
inline Value new_function(VM& vm, FunctionNode const& function_node, Optional<IdentifierTableIndex> const& lhs_name, Optional<Operand> const& home_object)
{
Value value;

Expand Down
Loading

0 comments on commit ba01afe

Please sign in to comment.