mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
Adds:
- ast/Argument: AST node for an argument passed to a function.
- ast/FunctionCall: AST node for a function call.
- codegen/ModuleDeclarationRegistrar: The code generator registers module function declarations with this in order to determine module indexes and function indexes for instructions.
- model/FunctionLink: this is a reference either:
- from: a FunctionCall or a FunctionReference
- to: a ModuleFunctionDeclaration or a UserFunction
- optimizer/ReferencedFunctionGatherer: a visitor that determines which module functions and user functions are referenced, by looking at function calls and function references.
Also:
- CodeGenerator registers module functions
- InstructionGenerator generates code for function calls
- InstructionEmitter generates TOK_FUNC instructions
- StoredTokenDecoder decodes TOK_FUNC instructions
After all of this, the compiler can compile print("hello, world");
44 lines
1.2 KiB
C++
44 lines
1.2 KiB
C++
#ifndef POLSERVER_MODULEDECLARATIONREGISTRAR_H
|
|
#define POLSERVER_MODULEDECLARATIONREGISTRAR_H
|
|
|
|
#include <map>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
{
|
|
class ModuleDescriptor;
|
|
class ModuleFunctionDeclaration;
|
|
class ModuleFunctionDescriptor;
|
|
|
|
class ModuleDeclarationRegistrar
|
|
{
|
|
public:
|
|
ModuleDeclarationRegistrar();
|
|
|
|
void register_module( const ModuleFunctionDeclaration& node );
|
|
void register_modulefunc( const ModuleFunctionDeclaration& );
|
|
|
|
std::vector<ModuleDescriptor> take_module_descriptors();
|
|
|
|
void lookup_or_register_module_function( const ModuleFunctionDeclaration& node,
|
|
unsigned& module_index, unsigned& function_index );
|
|
|
|
private:
|
|
struct EmittedModule
|
|
{
|
|
explicit EmittedModule(unsigned module_index);
|
|
~EmittedModule();
|
|
|
|
const unsigned module_index;
|
|
std::map<std::string, unsigned> function_name_to_index;
|
|
std::vector<ModuleFunctionDescriptor> function_declarations;
|
|
};
|
|
std::map<std::string, std::unique_ptr<EmittedModule>> registered_modules;
|
|
std::vector<std::string> module_names_in_order;
|
|
};
|
|
|
|
} // namespace Pol::Bscript::Compiler
|
|
|
|
#endif // POLSERVER_MODULEDECLARATIONREGISTRAR_H
|