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.
68 lines
1.6 KiB
C++
68 lines
1.6 KiB
C++
#ifndef POLSERVER_INSTRUCTIONEMITTER_H
|
|
#define POLSERVER_INSTRUCTIONEMITTER_H
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#ifndef OBJMEMBERS_H
|
|
#include "objmembers.h"
|
|
#endif
|
|
#ifndef OBJMETHODS_H
|
|
#include "objmethods.h"
|
|
#endif
|
|
#ifndef __TOKENS_H
|
|
#include "tokens.h"
|
|
#endif
|
|
#include "compiler/codegen/CodeEmitter.h"
|
|
#include "compiler/codegen/DataEmitter.h"
|
|
#include "compiler/representation/CompiledScript.h"
|
|
|
|
namespace Pol::Bscript
|
|
{
|
|
class StoredToken;
|
|
}
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
{
|
|
class ModuleDeclarationRegistrar;
|
|
class ModuleFunctionDeclaration;
|
|
class Node;
|
|
class Variable;
|
|
class SourceLocation;
|
|
|
|
class InstructionEmitter
|
|
{
|
|
public:
|
|
InstructionEmitter( CodeSection& code, DataSection& data,
|
|
ModuleDeclarationRegistrar& );
|
|
|
|
void initialize_data();
|
|
|
|
void access_variable( const Variable& );
|
|
void array_declare();
|
|
void assign();
|
|
void call_method( const std::string& name, unsigned argument_count );
|
|
void call_method_id( MethodID method_id, unsigned argument_count );
|
|
void call_modulefunc( const ModuleFunctionDeclaration& );
|
|
void consume();
|
|
void declare_variable( const Variable& );
|
|
void progend();
|
|
void unary_operator( BTokenId );
|
|
void value( double );
|
|
void value( int );
|
|
void value( const std::string& );
|
|
|
|
private:
|
|
unsigned emit_data( const std::string& );
|
|
unsigned emit_token( BTokenId id, BTokenType type, unsigned offset = 0 );
|
|
unsigned append_token( StoredToken& );
|
|
|
|
CodeEmitter code_emitter;
|
|
DataEmitter data_emitter;
|
|
ModuleDeclarationRegistrar& module_declaration_registrar;
|
|
};
|
|
|
|
} // namespace Pol::Bscript::Compiler
|
|
|
|
#endif // POLSERVER_INSTRUCTIONEMITTER_H
|