polserver/pol-core/bscript/compiler/codegen/CodeEmitter.cpp
turleypol 1463b76c7c
Includes are now all relative to pol-core basefolder (#906)
* all except pol

* pol and includes under defines

* something weird has happened

* remove own folder from include searchpath

* fixed remaining, adapted include style for external headers

* missing include
2026-07-25 23:01:18 +02:00

30 lines
729 B
C++

#include "bscript/compiler/codegen/CodeEmitter.h"
#include "bscript/StoredToken.h"
namespace Pol::Bscript::Compiler
{
CodeEmitter::CodeEmitter( CodeSection& code ) : code( code ) {}
unsigned CodeEmitter::append( const StoredToken& st )
{
auto index = next_address();
code.push_back( st );
return index;
}
void CodeEmitter::update_offset( unsigned index, unsigned offset )
{
code[index].offset = static_cast<unsigned short>( offset );
}
unsigned CodeEmitter::next_address() const
{
size_t index = code.size();
if ( index > std::numeric_limits<unsigned>::max() ) {
throw std::runtime_error( "Instruction count overflow" );
}
return static_cast<unsigned>( index );
}
} // namespace Pol::Bscript::Compiler