polserver/pol-core/bscript/compiler/codegen/CodeEmitter.cpp
turleypol cccf84dfc8
Fewer compile warnings (#413)
* added escriptgrammar as external lib where it belongs. Silenced warnings.

* bscript compiler warning fixes

* special include file to get rid of gcc warnings about antlr4

* misc windows warnings

* time specifc warnings

* buildfix + apple warnings

* never trust apple

* windows debug build warnings

* some windows clang warnings

* last warning fix
2021-08-28 22:26:15 +02:00

30 lines
696 B
C++

#include "CodeEmitter.h"
#include "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