Skip to content

Commit

Permalink
LibJS: Fail compilation earlier when trying to emit with wrong arguments
Browse files Browse the repository at this point in the history
This makes the compilation backtraces a lot nicer, and allows clangd to
see the mistake as well.
  • Loading branch information
Hendiadyoin1 authored and awesomekling committed May 8, 2024
1 parent af94e4c commit e1aecff
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Userland/Libraries/LibJS/Bytecode/Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Generator {
};

template<typename OpType, typename... Args>
requires(requires { OpType(declval<Args>()...); })
void emit(Args&&... args)
{
VERIFY(!is_current_block_terminated());
Expand All @@ -81,6 +82,7 @@ class Generator {
}

template<typename OpType, typename ExtraSlotType, typename... Args>
requires(requires { OpType(declval<Args>()...); })
void emit_with_extra_slots(size_t extra_slot_count, Args&&... args)
{
VERIFY(!is_current_block_terminated());
Expand All @@ -96,12 +98,14 @@ class Generator {
}

template<typename OpType, typename... Args>
requires(requires { OpType(declval<Args>()...); })
void emit_with_extra_operand_slots(size_t extra_operand_slots, Args&&... args)
{
emit_with_extra_slots<OpType, Operand>(extra_operand_slots, forward<Args>(args)...);
}

template<typename OpType, typename... Args>
requires(requires { OpType(declval<Args>()...); })
void emit_with_extra_value_slots(size_t extra_operand_slots, Args&&... args)
{
emit_with_extra_slots<OpType, Value>(extra_operand_slots, forward<Args>(args)...);
Expand Down

0 comments on commit e1aecff

Please sign in to comment.