mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:57:35 +00:00
Revert "LibJS: Add bytecode instruction handles"
This reverts commit a01bd35c67
.
This broke simple programs like:
function sum(a, b) { return a + b; }
console.log(sum(1, 2));
This commit is contained in:
parent
a01bd35c67
commit
b8a5ea1f8d
8 changed files with 79 additions and 81 deletions
|
@ -7,8 +7,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <LibJS/Bytecode/Block.h>
|
||||
#include <LibJS/Bytecode/Label.h>
|
||||
#include <LibJS/Bytecode/Register.h>
|
||||
#include <LibJS/Forward.h>
|
||||
|
||||
namespace JS::Bytecode {
|
||||
|
@ -20,15 +20,21 @@ public:
|
|||
Register allocate_register();
|
||||
|
||||
template<typename OpType, typename... Args>
|
||||
InstructionHandle<OpType> emit(Args&&... args)
|
||||
OpType& emit(Args&&... args)
|
||||
{
|
||||
return make_instruction<OpType>(0, forward<Args>(args)...);
|
||||
void* slot = next_slot();
|
||||
grow(sizeof(OpType));
|
||||
new (slot) OpType(forward<Args>(args)...);
|
||||
return *static_cast<OpType*>(slot);
|
||||
}
|
||||
|
||||
template<typename OpType, typename... Args>
|
||||
InstructionHandle<OpType> emit_with_extra_register_slots(size_t extra_register_slots, Args&&... args)
|
||||
OpType& emit_with_extra_register_slots(size_t extra_register_slots, Args&&... args)
|
||||
{
|
||||
return make_instruction<OpType>(extra_register_slots, forward<Args>(args)...);
|
||||
void* slot = next_slot();
|
||||
grow(sizeof(OpType) + extra_register_slots * sizeof(Register));
|
||||
new (slot) OpType(forward<Args>(args)...);
|
||||
return *static_cast<OpType*>(slot);
|
||||
}
|
||||
|
||||
Label make_label() const;
|
||||
|
@ -42,15 +48,8 @@ private:
|
|||
Generator();
|
||||
~Generator();
|
||||
|
||||
template<typename OpType, typename... Args>
|
||||
InstructionHandle<OpType> make_instruction(size_t extra_register_slots, Args&&... args)
|
||||
{
|
||||
auto& buffer = m_block->buffer();
|
||||
auto offset = buffer.size();
|
||||
buffer.resize(buffer.size() + sizeof(OpType) + extra_register_slots * sizeof(Register));
|
||||
new (buffer.data() + offset) OpType(forward<Args>(args)...);
|
||||
return InstructionHandle<OpType>(offset, m_block);
|
||||
}
|
||||
void grow(size_t);
|
||||
void* next_slot();
|
||||
|
||||
OwnPtr<Block> m_block;
|
||||
u32 m_next_register { 1 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue