ArkScript
A small, fast, functional and scripting language for video games
Welder.hpp
Go to the documentation of this file.
1/**
2 * @file Welder.hpp
3 * @author Alexandre Plateau ([email protected])
4 * @brief In charge of welding everything needed to compile code
5 * @version 0.5
6 * @date 2023-03-26
7 *
8 * @copyright Copyright (c) 2023-2024
9 *
10 */
11
12#ifndef ARK_COMPILER_WELDER_HPP
13#define ARK_COMPILER_WELDER_HPP
14
15#include <string>
16#include <vector>
17#include <filesystem>
18
25#include <Ark/Constants.hpp>
26#include <Ark/Logger.hpp>
31
32namespace Ark
33{
34 /**
35 * @brief The welder joins all the compiler passes
36 */
37 class ARK_API Welder final
38 {
39 public:
40 /**
41 * @brief Create a new Welder
42 * @param debug debug level
43 * @param lib_env list of paths to the standard library
44 * @param features feature flags to toggle features on/off
45 */
46 Welder(unsigned debug, const std::vector<std::filesystem::path>& lib_env, uint16_t features = DefaultFeatures);
47
48 /**
49 * @brief Register a symbol as a global in the compiler
50 *
51 * @param name
52 */
53 void registerSymbol(const std::string& name);
54
55 /**
56 *
57 * @param filename
58 * @return true on success
59 */
60 bool computeASTFromFile(const std::string& filename);
61
62 /**
63 *
64 * @param code
65 * @return true on success
66 */
67 bool computeASTFromString(const std::string& code);
68
69 /**
70 * @brief Compile the AST processed by computeASTFromFile / computeASTFromString
71 * @return true on success
72 */
73 bool generateBytecode();
74
75 /**
76 * @brief Save the generated bytecode to a given file
77 * @param filename
78 * @return true on success
79 */
80 bool saveBytecodeToFile(const std::string& filename);
81
82 [[nodiscard]] const internal::Node& ast() const noexcept;
83 [[nodiscard]] const bytecode_t& bytecode() const noexcept;
84
85 private:
86 std::vector<std::filesystem::path> m_lib_env;
87 uint16_t m_features;
88
89 std::filesystem::path m_root_file;
90 std::vector<std::string> m_imports;
91 std::vector<internal::IR::Block> m_ir;
94
100
105
106 void dumpIRToFile() const;
107
108 bool computeAST(const std::string& filename, const std::string& code);
109 };
110} // namespace Ark
111
112#endif
Common code for the compiler.
ArkScript compiler is in charge of transforming the AST into bytecode.
Constants used by ArkScript.
Compile the intermediate representation to bytecode.
Optimize IR based on IR entity grouped by 2 (or more)
Handle imports, resolve them with modules and everything.
Internal logger.
#define ARK_API
Definition Module.hpp:28
AST node used by the parser, optimizer and compiler.
Optimizes a given ArkScript AST.
Parse ArkScript code, but do not handle any import declarations.
Handles the macros and their expansion in ArkScript source code.
The welder joins all the compiler passes.
Definition Welder.hpp:38
internal::ImportSolver m_import_solver
Definition Welder.hpp:96
internal::Node m_computed_ast
Definition Welder.hpp:93
internal::IROptimizer m_ir_optimizer
Definition Welder.hpp:102
std::vector< std::string > m_imports
Definition Welder.hpp:90
internal::Logger m_logger
Definition Welder.hpp:101
std::vector< internal::IR::Block > m_ir
Definition Welder.hpp:91
internal::NameResolutionPass m_name_resolver
Definition Welder.hpp:99
std::filesystem::path m_root_file
Definition Welder.hpp:89
internal::Compiler m_compiler
Definition Welder.hpp:104
internal::Parser m_parser
Definition Welder.hpp:95
internal::IRCompiler m_ir_compiler
Definition Welder.hpp:103
internal::MacroProcessor m_macro_processor
Definition Welder.hpp:97
uint16_t m_features
Definition Welder.hpp:87
internal::Optimizer m_ast_optimizer
Definition Welder.hpp:98
bytecode_t m_bytecode
Definition Welder.hpp:92
std::vector< std::filesystem::path > m_lib_env
Definition Welder.hpp:86
The ArkScript bytecode compiler.
Definition Compiler.hpp:36
The class handling the macros definitions and calls, given an AST.
Definition Processor.hpp:32
A node of an Abstract Syntax Tree for ArkScript.
Definition Node.hpp:30
The ArkScript AST optimizer.
Definition Optimizer.hpp:31
constexpr uint16_t DefaultFeatures
Definition Constants.hpp:59
std::vector< uint8_t > bytecode_t
Definition Common.hpp:22