12#include <fmt/ostream.h>
16 Welder::Welder(
const unsigned debug,
const std::vector<std::filesystem::path>& lib_env,
const uint16_t features) :
17 m_lib_env(lib_env), m_features(features),
20 m_import_solver(debug, lib_env),
21 m_macro_processor(debug),
22 m_ast_optimizer(debug),
23 m_name_resolver(debug),
24 m_logger(
"Welder", debug),
25 m_ir_optimizer(debug),
88 std::ofstream output(filename, std::ofstream::binary);
91 static_cast<std::streamsize
>(
m_bytecode.size() *
sizeof(uint8_t)));
103 std::stringstream stream;
117 path /=
"output.ark.ir";
119 path.replace_extension(
".ark.ir");
121 std::ofstream output(path);
Constants used by ArkScript.
ArkScript homemade exceptions.
Lots of utilities about the filesystem.
Handle imports, resolve them with modules and everything.
Optimizes a given ArkScript AST.
Handles the macros and their expansion in ArkScript source code.
In charge of welding everything needed to compile code.
bool computeAST(const std::string &filename, const std::string &code)
internal::ImportSolver m_import_solver
internal::Node m_computed_ast
Welder(unsigned debug, const std::vector< std::filesystem::path > &lib_env, uint16_t features=DefaultFeatures)
Create a new Welder.
internal::IROptimizer m_ir_optimizer
void registerSymbol(const std::string &name)
Register a symbol as a global in the compiler.
bool computeASTFromString(const std::string &code)
std::string textualIR() const noexcept
internal::Logger m_logger
std::vector< internal::IR::Block > m_ir
internal::NameResolutionPass m_name_resolver
std::filesystem::path m_root_file
internal::Compiler m_compiler
const bytecode_t & bytecode() const noexcept
internal::Parser m_parser
internal::IRCompiler m_ir_compiler
internal::MacroProcessor m_macro_processor
bool saveBytecodeToFile(const std::string &filename)
Save the generated bytecode to a given file.
bool generateBytecode()
Compile the AST processed by computeASTFromFile / computeASTFromString.
bool computeASTFromFile(const std::string &filename)
internal::Optimizer m_ast_optimizer
void dumpIRToFile() const
const internal::Node & ast() const noexcept
const std::vector< ValTableElem > & values() const noexcept
Return the value table pre-computed.
const std::vector< std::string > & symbols() const noexcept
Return the symbol table pre-computed.
void process(const Node &ast)
Start the compilation.
const std::vector< IR::Block > & intermediateRepresentation() const noexcept
Return the IR blocks (one per scope)
void dumpToStream(std::ostream &stream) const
Dump the IR given to process to an output stream.
const bytecode_t & bytecode() const noexcept
Return the constructed bytecode object.
void process(const std::vector< IR::Block > &pages, const std::vector< std::string > &symbols, const std::vector< ValTableElem > &values)
Turn a given IR into bytecode.
const std::vector< IR::Block > & intermediateRepresentation() const noexcept
Return the IR blocks (one per scope)
void process(const std::vector< IR::Block > &pages, const std::vector< std::string > &symbols, const std::vector< ValTableElem > &values)
Turn a given IR into bytecode.
void process(const Node &origin_ast) override
Start processing the given AST.
ImportSolver & setup(const std::filesystem::path &root, const std::vector< Import > &origin_imports)
Configure the ImportSolver.
const Node & ast() const noexcept override
Output of the compiler pass.
void info(const char *fmt, Args &&... args)
Write an info level log using fmtlib.
const Node & ast() const noexcept override
Return the modified AST.
void process(const Node &ast) override
Send the complete AST and work on it.
const Node & ast() const noexcept override
Unused overload that return the input AST (untouched as this pass only generates errors)
void process(const Node &ast) override
Start visiting the given AST, checking for mutability violation and unbound variables.
std::string addDefinedSymbol(const std::string &sym, bool is_mutable)
Register a symbol as defined, so that later we can throw errors on undefined symbols.
A node of an Abstract Syntax Tree for ArkScript.
const Node & ast() const noexcept override
Returns the modified AST.
void process(const Node &ast) override
Send the AST to the optimizer, then run the different optimization strategies on it.
void process(const std::string &filename, const std::string &code)
Parse the given code.
const Node & ast() const noexcept
const std::vector< Import > & imports() const
ARK_API void generate(const CodeError &e, std::ostream &os=std::cout, bool colorize=true)
Generate a diagnostic from an error and print it to the standard output.
std::string readFile(const std::string &name)
Helper to read a file.
NodeType
The different node types available.
constexpr uint16_t FeatureImportSolver
constexpr uint16_t FeatureIROptimizer
constexpr uint16_t FeatureMacroProcessor
constexpr uint16_t FeatureTestFailOnException
This feature should only be used in tests, to disable diagnostics generation and enable exceptions to...
std::vector< uint8_t > bytecode_t
constexpr uint16_t FeatureASTOptimizer
This is disabled so that embedding ArkScript does not prune nodes from the AST ; it is active in the ...
constexpr uint16_t FeatureDumpIR
constexpr uint16_t FeatureNameResolver
CodeError thrown by the compiler (parser, macro processor, optimizer, and compiler itself)