mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
Adds: - UnaryOperator: AST node for unary operators -, ++, --, and so forth - UnaryOperatorOptimizer: optimizes a unary operator with its operand - now integer and float negation, and integer inversion - later x[y]++ to a single instruction Also: - automatically include basic.em, which includes some parameter defaults like -1. This allows the compiler to generate output for a hello, world script with the exact same .ecl output as the legacy compiler.
35 lines
791 B
C++
35 lines
791 B
C++
#ifndef POLSERVER_UNARYOPERATOROPTIMIZER_H
|
|
#define POLSERVER_UNARYOPERATOROPTIMIZER_H
|
|
|
|
#include "compiler/ast/NodeVisitor.h"
|
|
|
|
#include <memory>
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
{
|
|
class Expression;
|
|
class Identifier;
|
|
class IntegerValue;
|
|
class FloatValue;
|
|
class UnaryOperator;
|
|
|
|
class UnaryOperatorOptimizer : public NodeVisitor
|
|
{
|
|
public:
|
|
explicit UnaryOperatorOptimizer( UnaryOperator& unary_operator );
|
|
|
|
std::unique_ptr<Expression> optimize();
|
|
|
|
void visit_children( Node& ) override;
|
|
void visit_float_value( FloatValue& literal ) override;
|
|
void visit_integer_value( IntegerValue& literal ) override;
|
|
|
|
private:
|
|
std::unique_ptr<Expression> optimized_result;
|
|
|
|
UnaryOperator& unary_operator;
|
|
};
|
|
|
|
} // namespace Pol::Bscript::Compiler
|
|
|
|
#endif // POLSERVER_UNARYOPERATOROPTIMIZER_H
|