2023-09-20 11:31:35 +00:00
|
|
|
#ifndef fk_MODULE_HPP
|
|
|
|
#define fk_MODULE_HPP
|
|
|
|
|
|
|
|
#include "commons.hpp"
|
|
|
|
#include "Lexer.hpp"
|
|
|
|
#include "Parser.hpp"
|
|
|
|
#include "Compiler.hpp"
|
|
|
|
#include "VM.hpp"
|
2023-09-20 15:17:13 +00:00
|
|
|
#include "SymTable.hpp"
|
2023-09-20 11:31:35 +00:00
|
|
|
|
|
|
|
namespace fk
|
|
|
|
{
|
|
|
|
FK_ERROR(module_error);
|
|
|
|
|
|
|
|
class Module
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit Module(std::filesystem::path source_path);
|
|
|
|
virtual ~Module();
|
|
|
|
|
2023-09-23 17:21:55 +00:00
|
|
|
std::shared_ptr<Compiler> compiler() const { return m_compiler; }
|
2023-09-22 12:17:21 +00:00
|
|
|
std::shared_ptr<Program> program() const { return m_program; }
|
|
|
|
std::shared_ptr<SymTable> sym() const { return m_sym; }
|
2023-09-22 11:27:13 +00:00
|
|
|
std::shared_ptr<VM> vm() const { return m_vm; }
|
|
|
|
|
2023-09-23 17:21:55 +00:00
|
|
|
std::shared_ptr<Module> get_mod(std::string const& name);
|
|
|
|
|
2023-09-20 11:31:35 +00:00
|
|
|
void build();
|
|
|
|
|
2023-09-20 15:17:13 +00:00
|
|
|
void import_std();
|
|
|
|
void import_library(std::filesystem::path lib_path);
|
|
|
|
|
2023-09-23 17:21:55 +00:00
|
|
|
std::shared_ptr<Module> register_module(std::string const& name);
|
|
|
|
|
2023-09-20 15:17:13 +00:00
|
|
|
void register_function(std::string const& name, native_t native);
|
2023-09-20 19:21:51 +00:00
|
|
|
void register_macro(std::string const& name, macro_t macro);
|
2023-09-20 15:17:13 +00:00
|
|
|
|
2023-09-20 11:31:35 +00:00
|
|
|
private:
|
|
|
|
std::filesystem::path m_source_path;
|
|
|
|
std::string m_source;
|
2023-09-21 20:26:13 +00:00
|
|
|
Loc m_loc {m_source_path, 1};
|
2023-09-20 11:31:35 +00:00
|
|
|
std::shared_ptr<Lexer> m_lexer = std::make_shared<Lexer>(m_loc);
|
|
|
|
std::shared_ptr<Parser> m_parser = std::make_shared<Parser>(*m_lexer);
|
2023-09-20 15:17:13 +00:00
|
|
|
std::shared_ptr<SymTable> m_sym = std::make_shared<SymTable>();
|
2023-09-23 17:21:55 +00:00
|
|
|
std::shared_ptr<Compiler> m_compiler = std::make_shared<Compiler>(*this,
|
|
|
|
m_sym);
|
2023-09-20 11:31:35 +00:00
|
|
|
std::shared_ptr<Node> m_ast;
|
2023-09-22 12:17:21 +00:00
|
|
|
std::shared_ptr<VM> m_vm = std::make_shared<VM>(*this);
|
|
|
|
std::shared_ptr<Program> m_program = std::make_shared<Program>();
|
2023-09-23 17:21:55 +00:00
|
|
|
std::unordered_map<std::string, std::shared_ptr<Module>> m_native_modules;
|
|
|
|
|
2023-09-20 11:31:35 +00:00
|
|
|
std::string load_sources();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|