43#ifndef COMPILER_MVP_FRONTEND_H
44#define COMPILER_MVP_FRONTEND_H
97 const std::string &
code,
99 const std::string ¬e =
"",
100 const std::string &help =
"")
103 if (
not note.empty())
105 if (
not help.empty())
120 return static_cast<size_t>(-1);
143 for (
size_t i = 0; i < result.issues.size(); ++i)
145 const auto &
issue = result.issues.access(i);
149 "cannot resolve import '" +
issue.dependency_name +
"'",
150 "known sources must match import names exactly");
154 "cyclic import involving '" +
issue.module_name +
"' and '"
155 +
issue.dependency_name +
"'",
156 "imports currently form one acyclic source-order graph");
159 for (
size_t i = 0; i < result.order.size(); ++i)
176 const auto *
module = parsed_modules.access(module_index);
177 if (module ==
nullptr)
181 first_span = module->span;
182 if (module->span.is_valid())
185 for (
size_t j = 0; j <
module->type_declarations.size(); ++j)
187 for (
size_t j = 0; j <
module->functions.size(); ++j)
189 for (
size_t j = 0; j <
module->statements.size(); ++j)
256 append_error(
"frontend: no input sources were provided");
260 for (
size_t i = 0; i <
inputs.size(); ++i)
285 auto *
module = parser.parse_module();
292 if (module !=
nullptr)
294 if (module !=
nullptr)
295 for (
size_t j = 0; j <
module->imports.size(); ++j)
297 const auto *
decl =
module->imports.access(j);
303 if (module !=
nullptr)
305 for (
size_t j = 0; j <
module->type_declarations.size(); ++j)
307 const auto *
decl =
module->type_declarations.access(j);
314 for (
size_t j = 0; j <
module->functions.size(); ++j)
316 const auto *
fn =
module->functions.access(j);
323 for (
size_t j = 0; j <
module->statements.size(); ++j)
325 const auto *stmt =
module->statements.access(j);
373 append_error(
"ir: null IR module produced by lowering");
438 for (
size_t i =
artifacts_.size(); i > 0; --i)
457 std::ostringstream
out;
Reusable interface for language frontends that plug into common drivers.
Lowering from the current MVP typed AST into the reusable HIR model.
Lowering from the current MVP HIR into the reusable explicit IR model.
Reusable source-name module dependency resolution helpers.
Recursive-descent parser for the compiler-support MVP grammar.
size_t size_t int32_t * out
Arena-backed ownership context for AST nodes.
T * make(Args &&...args)
Allocates and constructs an AST node of type T.
void reset() noexcept
Reclaims all memory and destroys managed nodes.
Abstract language frontend that can feed reusable drivers.
Arena-backed ownership context for HIR nodes.
void reset() noexcept
Destroys all tracked objects and rewinds the arena.
Lowers the MVP typed AST into HIR.
Arena-backed ownership context for IR nodes.
void reset() noexcept
Destroys all tracked objects and rewinds the arena.
Lowers typed HIR into explicit-value IR.
Compiler_Frontend implementation backed by the current MVP language stack.
DynArray< std::string > errors_
Compiler_HIR_Context hir_ctx
void merge_modules_from_order()
std::string diagnostics_text() const
Renders accumulated diagnostics as plain text.
Compiler_Ast_Context ast_ctx
DynArray< std::string > warnings_
bool lower_hir() override
Lowers the analyzed program into common HIR.
const DynArray< Compiler_Module_Descriptor > & module_descriptors() const noexcept override
Returns parsed module descriptors for reusable import orchestration.
DynArray< Compiler_Module_Descriptor > module_descriptors_
Compiler_MVP_Frontend_Options config
bool parse() override
Parses all previously loaded sources.
bool lower_ir() override
Lowers the analyzed program into common IR.
const Compiler_MVP_Frontend_Options & options() const noexcept
Returns the immutable frontend configuration.
const Compiler_Type_Context * type_context() const noexcept override
Returns the optional shared type context for dumps and backends.
Diagnostic_Engine diagnostics
bool resolve_import_order()
Diagnostic_Engine * diagnostic_engine() noexcept override
Returns the diagnostic engine populated by the frontend.
bool load_sources(const DynArray< Compiler_Driver_Source > &inputs) override
Registers the ordered input sources for the next run.
DynArray< std::string > source_names
void record_ast_artifacts()
DynArray< Compiler_Module_Metadata > module_metadata_
size_t arena_size() const noexcept
Returns the configured shared arena size.
const DynArray< Compiler_Module * > & parsed_ast_modules() const noexcept
const Compiler_HIR_Module * hir_module() const noexcept override
Returns the lowered HIR module from the last run, when available.
const DynArray< std::string > & warnings() const noexcept override
Returns non-fatal frontend-level warnings.
bool analyze() override
Runs semantic analysis on the parsed program.
const Compiler_Driver_Artifact * find_artifact(std::string_view label) const noexcept override
Finds one frontend artifact by exact label.
const Compiler_IR_Module * ir_module() const noexcept override
Returns the lowered IR module from the last run, when available.
Compiler_Module * merged_ast_
const DynArray< std::string > & errors() const noexcept override
Returns hard frontend-level errors outside the diagnostic engine.
void clear() noexcept override
Clears all frontend-owned state from the previous run.
Compiler_Typed_Semantic_Analyzer typed
const Compiler_Module * merged_ast_module() const noexcept
void record_import_order_artifact()
const Diagnostic_Engine * diagnostic_engine() const noexcept override
Returns the diagnostic engine populated by the frontend.
DynArray< Compiler_Driver_Artifact > artifacts_
Compiler_IR_Context ir_ctx
Compiler_HIR_Module * hir_module_
void append_error(const std::string &text)
DynArray< size_t > merge_order_
const DynArray< size_t > & module_merge_order() const noexcept override
Returns the dependency-first merge order from the last parse.
size_t find_source_index(std::string_view name) const noexcept
void record_text_artifact(const std::string &label, std::string text)
void emit_driver_diagnostic(const Source_Span &span, const std::string &code, const std::string &message, const std::string ¬e="", const std::string &help="")
DynArray< Compiler_Module * > parsed_modules
const char * name() const noexcept override
Returns the stable frontend name.
const DynArray< Compiler_Driver_Artifact > & artifacts() const noexcept override
Returns all frontend-produced artifacts from the last run.
DynArray< Source_File_Id > source_file_ids
Compiler_MVP_Frontend(const Compiler_MVP_Frontend_Options &options={}, const size_t arena_size=1<< 20)
Constructs the reference MVP frontend.
Compiler_IR_Module * ir_module_
const DynArray< Compiler_Module_Metadata > & module_metadata() const noexcept override
Returns reusable metadata for the top-level surface of each module.
Recursive-descent parser that produces an AST in Compiler_Ast_Context.
Context owning all compiler type nodes.
Inference-oriented semantic pass for the MVP compiler front-end.
void analyze_module(const Compiler_Module *module)
Runs the typed semantic analysis for module.
void clear() noexcept
Clears all inferred state and substitutions.
std::string dump_inference() const
Dumps inferred function, parameter, and binding types.
const Compiler_Type_Context & type_context() const noexcept
Returns the internal type context.
Diagnostic_Builder & code(const std::string &value)
Sets the stable diagnostic code.
size_t emit() const noexcept
Finalizes the builder and returns the diagnostic index.
Diagnostic_Builder & help(const std::string &msg)
Appends a help line.
Diagnostic_Builder & note(const std::string &msg)
Appends a note line.
Diagnostic accumulator and renderer.
void clear() noexcept
Removes all accumulated diagnostics and resets counters.
void render_plain(std::ostream &out) const
Renders all diagnostics as deterministic plain text.
bool has_errors() const noexcept
Returns whether any error or fatal diagnostic was emitted.
Diagnostic_Builder error(const Source_Span &span, const std::string &msg)
Starts an error diagnostic.
void clear() noexcept
Empties the container.
size_t size() const noexcept
Return the current dimension of array.
T & access(const size_t i) const noexcept
Fast access without checking allocation and bound_min_clock checking.
T & append()
Allocate a new entry to the end of array.
bool is_empty() const noexcept
Return true if the array is empty.
Stores source files and resolves offsets into human-readable data.
Source_File_Id add_virtual_file(const std::string &name, const std::string &text)
Registers an in-memory source file.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
std::string artifact_label(const std::string &prefix, const size_t index, const std::string &name)
bool merge_report(const std::string &stage, const Report &report, DynArray< std::string > &errors, DynArray< std::string > &warnings)
void append_artifact(DynArray< Compiler_Driver_Artifact > &artifacts, const std::string &label, std::string text)
Main namespace for Aleph-w library functions.
std::string compiler_dump_module(const Compiler_Module *module)
Dumps a parsed module in a deterministic text format.
Source_Span compiler_merge_spans(const Source_Span &lhs, const Source_Span &rhs) noexcept
Merges two spans from the same source file.
void message(const char *file, int line, const char *format,...)
Print an informational message with file and line info.
std::string compiler_dump_ir_module(const Compiler_IR_Module *module, const Compiler_Type_Context *types=nullptr)
Dumps all lowered IR in one module deterministically.
@ Import
One concrete import "name"; declaration.
@ Let
Variable declaration and optional initialization.
Compiler_IR_Validation_Report validate_ir_module(const Compiler_IR_Module &module)
Validates all functions in one lowered IR module.
and
Check uniqueness with explicit hash + equality functors.
std::string compiler_render_module_order(const DynArray< size_t > &order, const DynArray< Compiler_Module_Descriptor > &modules)
Renders one deterministic text artifact for a module order.
Compiler_Module_Resolution_Result compiler_resolve_module_order(const DynArray< Compiler_Module_Descriptor > &modules)
Resolves one dependency-first order for exact-name module imports.
std::string code(Node *root)
Compute a string with the Lukasiewicz`s word of a tree.
std::string compiler_dump_hir_module(const Compiler_HIR_Module *module, const Compiler_Type_Context &types)
Dumps one HIR module in a deterministic text format.
Source_Span span
Source region covered by this node.
Stable text artifact produced during one pipeline run.
Lowered IR module with shared global slots and functions.
Node representing a local variable binding.
Options used by the MVP frontend adapter.
Compiler_Parser_Options parser_options
Parser configuration used for every parsed file.
Compiler_Typed_Semantic_Options typed_semantic_options
Typed semantic options shared by the frontend.
One module descriptor consumed by the reusable resolver.
std::string name
Stable module/source name.
Node representing a complete translation unit or module.
std::string source_name
User-facing source name that produced the module.
DynArray< Compiler_Type_Decl * > type_declarations
Top-level type declarations.
DynArray< Compiler_Stmt * > statements
Optional top-level code.
DynArray< Compiler_Function_Decl * > functions
Top-level function definitions.
Parser configuration knobs for the MVP grammar.
Options controlling the typed semantic pass.
Half-open byte range inside a source file.