mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
* compile time optimization: int with doubles and strings doubles with ints and strings strings with ints and doubles * bool with other types, more unary ops, float branch optimizer * more tests fixed bool to dbl compare * output cleanup more tests * optimize string values in if statements, optimize ternary operator * optimize elvis, addes missing files, code cleanup * use array to keep unoptimized if branch in funcexpr tests * missing include * better readable testdata * removed file * optimize while and dowhile loops if predicate is a compile time known value * cleaner variant of loop optimization? * added ConstantPredicateLoop Node used by the optimizer for constant loop predicates optimize repeat until loop change tests to run the loops more then once to be sure they work correctly * test break/continue with label for constant-loop * docs
40 lines
1.1 KiB
C++
40 lines
1.1 KiB
C++
#include "ConstantPredicateLoop.h"
|
|
|
|
|
|
#include "bscript/compiler/ast/Block.h"
|
|
#include "bscript/compiler/ast/NodeVisitor.h"
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
{
|
|
ConstantPredicateLoop::ConstantPredicateLoop( const SourceLocation& source_location,
|
|
std::string label, std::unique_ptr<Block> block,
|
|
bool endless )
|
|
: LoopStatement( source_location, std::move( label ) ), _endless( endless )
|
|
{
|
|
children.reserve( 1 );
|
|
children.push_back( std::move( block ) );
|
|
}
|
|
|
|
void ConstantPredicateLoop::accept( NodeVisitor& visitor )
|
|
{
|
|
visitor.visit_constant_loop( *this );
|
|
}
|
|
|
|
void ConstantPredicateLoop::describe_to( std::string& w ) const
|
|
{
|
|
fmt::format_to( std::back_inserter( w ), "constant-loop ({})",
|
|
is_endless() ? "endless" : "fallthrough" );
|
|
if ( !get_label().empty() )
|
|
fmt::format_to( std::back_inserter( w ), "(label:{})", get_label() );
|
|
}
|
|
|
|
Block& ConstantPredicateLoop::block()
|
|
{
|
|
return child<Block>( 0 );
|
|
}
|
|
|
|
bool ConstantPredicateLoop::is_endless() const
|
|
{
|
|
return _endless;
|
|
}
|
|
} // namespace Pol::Bscript::Compiler
|