polserver/pol-core/bscript/compiler/optimizer/Optimizer.h
Eric Swanson a77ddd028e
New compiler: Add optimized unary expressions (#244)
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.
2020-08-26 19:24:47 -07:00

31 lines
565 B
C++

#ifndef POLSERVER_OPTIMIZER_H
#define POLSERVER_OPTIMIZER_H
#include "compiler/ast/NodeVisitor.h"
#include <memory>
namespace Pol::Bscript::Compiler
{
class Report;
class CompilerWorkspace;
class Optimizer : public NodeVisitor
{
public:
explicit Optimizer( Report& );
void optimize( CompilerWorkspace& );
void visit_children( Node& ) override;
void visit_unary_operator( UnaryOperator& ) override;
std::unique_ptr<Node> optimized_replacement;
private:
Report& report;
};
} // namespace Pol::Bscript::Compiler
#endif // POLSERVER_OPTIMIZER_H