mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
* Update grammar * Update expression handling for uninit * update existing tests * Add new tests * Remove fullpath from escriptgrammar generation comment * fix tests * Update eScript guide * Declare escript version 0x11 * Add core-changes * Add `true` and `false` to grammar * true/false implementation * Fix existing tests * Add new tests * Update core changes * add docs * Fix BooleanValue::describe_to * bool optimizations * optimize uninit * remove unused var assignments * Update grammar for case labels for uninit, booleans * Fix case label handling for uninit, true, false * Tests * Fix compiler version display v1.1700000017881393 -> v1.17 * optimize boolean binary operations * fix unary boolean optimizer * add boolean, uninit optimizer test * Use new fmt lib apis * Fix compiler warning * really fix warning lol * Add Executor[Module]::getParam for bools, FindSubstance test
66 lines
1.9 KiB
C++
66 lines
1.9 KiB
C++
#include "CaseJumpDataBlock.h"
|
|
|
|
#include "tokens.h"
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
{
|
|
void CaseJumpDataBlock::on_boolean_value_jump_to( bool value, uint16_t address )
|
|
{
|
|
auto* p = reinterpret_cast<std::byte*>( &address );
|
|
data.push_back( p[0] );
|
|
data.push_back( p[1] );
|
|
data.push_back( std::byte{ CASE_TYPE_BOOL } );
|
|
data.push_back( std::byte{ value } );
|
|
}
|
|
|
|
void CaseJumpDataBlock::on_integer_value_jump_to( int32_t value, uint16_t address )
|
|
{
|
|
auto* p = reinterpret_cast<std::byte*>( &address );
|
|
data.push_back( p[0] );
|
|
data.push_back( p[1] );
|
|
data.push_back( std::byte{CASE_TYPE_LONG} );
|
|
p = reinterpret_cast<std::byte*>( &value );
|
|
data.push_back( p[0] );
|
|
data.push_back( p[1] );
|
|
data.push_back( p[2] );
|
|
data.push_back( p[3] );
|
|
}
|
|
|
|
void CaseJumpDataBlock::on_string_value_jump_to( const std::string& value, uint16_t address )
|
|
{
|
|
if ( value.size() >= 254 )
|
|
{
|
|
throw std::runtime_error( "String expressions in CASE statements must be <= 253 characters." );
|
|
}
|
|
auto* p = reinterpret_cast<std::byte*>( &address );
|
|
data.push_back( p[0] );
|
|
data.push_back( p[1] );
|
|
data.push_back( std::byte{ CASE_TYPE_STRING } );
|
|
data.push_back( static_cast<std::byte>( value.size() ) );
|
|
|
|
data.insert( data.end(), reinterpret_cast<const std::byte*>( value.c_str() ),
|
|
reinterpret_cast<const std::byte*>( value.c_str() + value.size() ) );
|
|
}
|
|
|
|
void CaseJumpDataBlock::on_uninitialized_value_jump_to( uint16_t address )
|
|
{
|
|
auto* p = reinterpret_cast<std::byte*>( &address );
|
|
data.push_back( p[0] );
|
|
data.push_back( p[1] );
|
|
data.push_back( std::byte{ CASE_TYPE_UNINIT } );
|
|
}
|
|
|
|
void CaseJumpDataBlock::on_default_jump_to( uint16_t address )
|
|
{
|
|
auto* p = reinterpret_cast<std::byte*>( &address );
|
|
data.push_back( p[0] );
|
|
data.push_back( p[1] );
|
|
data.push_back( std::byte{CASE_TYPE_DEFAULT} );
|
|
}
|
|
|
|
const std::vector<std::byte>& CaseJumpDataBlock::get_data() const
|
|
{
|
|
return data;
|
|
}
|
|
|
|
} // namespace Pol::Bscript::Compiler
|