|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Small example frontend for a line-oriented language. More...
#include <Compiler_Line_Frontend.H>
Classes | |
| struct | Function_Definition |
| struct | Let_Definition |
| struct | Operand |
| struct | Parsed_Source |
Public Member Functions | |
| Compiler_Line_Frontend (const size_t arena_size=1<< 20) | |
| Constructs a line-oriented frontend with reusable HIR/IR arena storage. | |
| const char * | name () const noexcept override |
| Returns the stable frontend name. | |
| void | clear () noexcept override |
| Resets all frontend-owned state so the instance can be reused. | |
| bool | load_sources (const DynArray< Compiler_Driver_Source > &inputs) override |
| Registers ordered in-memory sources for the next compilation run. | |
| bool | parse () override |
| Parses all registered sources, builds module descriptors and metadata, resolves import order, and records a parse artifact. | |
| bool | analyze () override |
| Performs semantic validation: duplicate declarations, module linking, name binding, and operand resolution. | |
| bool | lower_hir () override |
| Lowers the analyzed line program into a reusable HIR module. | |
| bool | lower_ir () override |
| Lowers the analyzed line program into a reusable flat IR module. | |
| Diagnostic_Engine * | diagnostic_engine () noexcept override |
| Returns the mutable diagnostic engine for this frontend. | |
| const Diagnostic_Engine * | diagnostic_engine () const noexcept override |
| Returns the read-only diagnostic engine for this frontend. | |
| const Compiler_Type_Context * | type_context () const noexcept override |
| Returns the shared type context used by the line frontend. | |
| const Compiler_HIR_Module * | hir_module () const noexcept override |
| Returns the HIR module produced by the last lower_hir() call. | |
| const Compiler_IR_Module * | ir_module () const noexcept override |
| Returns the IR module produced by the last lower_ir() call. | |
| const DynArray< Compiler_Module_Descriptor > & | module_descriptors () const noexcept override |
| Returns the module descriptors built during parse(). | |
| const DynArray< size_t > & | module_merge_order () const noexcept override |
| Returns the dependency-resolved merge order from the last parse(). | |
| const DynArray< Compiler_Module_Metadata > & | module_metadata () const noexcept override |
| Returns the module metadata built during parse(). | |
| const DynArray< Compiler_Driver_Artifact > & | artifacts () const noexcept override |
| Returns all frontend-produced artifacts from the last run. | |
| const Compiler_Driver_Artifact * | find_artifact (std::string_view label) const noexcept override |
| Finds one frontend artifact by exact label (last-write wins). | |
| const DynArray< std::string > & | errors () const noexcept override |
| Returns hard frontend-level errors collected outside the diagnostic engine. | |
| const DynArray< std::string > & | warnings () const noexcept override |
| Returns non-fatal frontend-level warnings. | |
Public Member Functions inherited from Aleph::Compiler_Frontend | |
| virtual | ~Compiler_Frontend ()=default |
Private Types | |
| enum class | Operand_Kind { Integer , Variable } |
Static Private Member Functions | |
| static std::string | trim_copy (std::string_view text) |
| static std::string | trim_quotes_copy (std::string_view text) |
| static DynArray< std::string > | split_tokens (std::string_view text) |
| static bool | parse_integer (std::string_view text, long long &value) noexcept |
| static bool | is_identifier_start (const unsigned char ch) noexcept |
| static bool | is_identifier_continue (const unsigned char ch) noexcept |
| static bool | parse_identifier (std::string_view text) noexcept |
| static Compiler_Operator_Kind | parse_operator_name (std::string_view text) noexcept |
| static bool | parse_operand (std::string_view text, const Source_Span &span, Operand &out) |
Private Attributes | |
| Source_Manager | sources_ |
| Diagnostic_Engine | diagnostics_ |
| Compiler_Type_Context | types_ |
| Compiler_HIR_Context | hir_ctx_ |
| Compiler_IR_Context | ir_ctx_ |
| size_t | arena_bytes_ = 0 |
| DynArray< std::string > | source_names_ |
| DynArray< Source_File_Id > | source_ids_ |
| DynArray< Compiler_Module_Descriptor > | module_descriptors_ |
| DynArray< Compiler_Module_Metadata > | module_metadata_ |
| DynArray< Parsed_Source > | parsed_sources_ |
| DynArray< Function_Definition > | functions_ |
| DynArray< Let_Definition > | lets_ |
| DynArray< size_t > | merge_order_ |
| DynArray< Compiler_Driver_Artifact > | artifacts_ |
| DynArray< std::string > | errors_ |
| DynArray< std::string > | warnings_ |
| Compiler_HIR_Module * | hir_module_ = nullptr |
| Compiler_IR_Module * | ir_module_ = nullptr |
Small example frontend for a line-oriented language.
The frontend is intentionally conservative and only supports integer values plus fixed-arity binary functions. Its main purpose is to show how a completely different frontend can plug into Compiler_Generic_Driver without depending on the MVP parser or typed AST.
Definition at line 80 of file Compiler_Line_Frontend.H.
|
strongprivate |
| Enumerator | |
|---|---|
| Integer | |
| Variable | |
Definition at line 82 of file Compiler_Line_Frontend.H.
|
inlineexplicit |
Constructs a line-oriented frontend with reusable HIR/IR arena storage.
| arena_size | Byte capacity for each of the HIR and IR arenas (default: 1 MiB). |
Definition at line 659 of file Compiler_Line_Frontend.H.
|
inlineoverridevirtual |
Performs semantic validation: duplicate declarations, module linking, name binding, and operand resolution.
Implements Aleph::Compiler_Frontend.
Definition at line 797 of file Compiler_Line_Frontend.H.
References Aleph::DynArray< T >::access(), Aleph::blossom_maximum_cardinality_matching(), Aleph::compiler_bind_module_surfaces(), Aleph::compiler_build_module_name_table(), Aleph::compiler_build_module_semantic_environment(), Aleph::compiler_link_module_surfaces(), Aleph::Compiler_Symbol_Bindings::declare(), Aleph::Compiler_Symbol_Bindings::enter_scope(), Aleph::Diagnostic_Engine::has_errors(), Aleph::DynArray< T >::size(), and Aleph::Compiler_Symbol_Bindings::symbol().
Definition at line 236 of file Compiler_Line_Frontend.H.
References Aleph::DynArray< T >::append(), and errors_.
Referenced by load_sources().
|
inlineoverridevirtualnoexcept |
Returns all frontend-produced artifacts from the last run.
Implements Aleph::Compiler_Frontend.
Definition at line 1124 of file Compiler_Line_Frontend.H.
|
inlineprivate |
Definition at line 626 of file Compiler_Line_Frontend.H.
References Aleph::blossom_maximum_cardinality_matching(), Integer, Aleph::Compiler_Type_Context::integer_type(), Aleph::Compiler_Line_Frontend::Operand::integer_value, Aleph::Compiler_Line_Frontend::Operand::kind, Aleph::Compiler_Line_Frontend::Operand::span, Aleph::Compiler_Line_Frontend::Operand::text, and types_.
|
inlineprivate |
Definition at line 633 of file Compiler_Line_Frontend.H.
References Aleph::blossom_maximum_cardinality_matching(), Integer, Aleph::Compiler_Type_Context::integer_type(), Aleph::Compiler_Line_Frontend::Operand::integer_value, Aleph::Compiler_Line_Frontend::Operand::kind, Aleph::Compiler_Line_Frontend::Operand::span, Aleph::Compiler_Line_Frontend::Operand::text, and types_.
|
inlineoverridevirtualnoexcept |
Resets all frontend-owned state so the instance can be reused.
After this call source registrations, parsed declarations, HIR/IR modules, artifacts, diagnostics, and type context are all discarded.
Implements Aleph::Compiler_Frontend.
Definition at line 680 of file Compiler_Line_Frontend.H.
References artifacts_, Aleph::Diagnostic_Engine::clear(), Aleph::Compiler_Type_Context::clear(), Aleph::DynArray< T >::clear(), diagnostics_, errors_, functions_, hir_ctx_, hir_module_, ir_ctx_, ir_module_, lets_, merge_order_, module_descriptors_, module_metadata_, parsed_sources_, Aleph::Compiler_HIR_Context::reset(), Aleph::Compiler_IR_Context::reset(), source_ids_, source_names_, sources_, types_, and warnings_.
|
inlineoverridevirtualnoexcept |
Returns the read-only diagnostic engine for this frontend.
Implements Aleph::Compiler_Frontend.
Definition at line 1053 of file Compiler_Line_Frontend.H.
|
inlineoverridevirtualnoexcept |
Returns the mutable diagnostic engine for this frontend.
Implements Aleph::Compiler_Frontend.
Definition at line 1043 of file Compiler_Line_Frontend.H.
|
inlineprivate |
Definition at line 531 of file Compiler_Line_Frontend.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::compiler_operator_name(), functions_, Aleph::Compiler_Line_Frontend::Let_Definition::Integer, lets_, and out.
|
inlineprivate |
Definition at line 554 of file Compiler_Line_Frontend.H.
References functions_, lets_, and out.
|
inlineprivate |
Definition at line 246 of file Compiler_Line_Frontend.H.
References Aleph::Diagnostic_Builder::code(), Aleph::code(), diagnostics_, Aleph::Diagnostic_Builder::emit(), Aleph::Diagnostic_Engine::error(), and Aleph::message().
Referenced by parse_function_line(), parse_import_line(), parse_let_line(), parse_source_file(), resolve_import_order(), validate_operand_in_function(), and validate_top_level_operand().
|
inlineoverridevirtualnoexcept |
Returns hard frontend-level errors collected outside the diagnostic engine.
Implements Aleph::Compiler_Frontend.
Definition at line 1148 of file Compiler_Line_Frontend.H.
|
inlineoverridevirtualnoexcept |
Finds one frontend artifact by exact label (last-write wins).
| label | Exact label string to search for. |
Implements Aleph::Compiler_Frontend.
Definition at line 1135 of file Compiler_Line_Frontend.H.
References Aleph::DynArray< T >::access(), and Aleph::DynArray< T >::size().
|
inlineprivatenoexcept |
Definition at line 251 of file Compiler_Line_Frontend.H.
References Aleph::DynArray< T >::access(), name(), Aleph::DynArray< T >::size(), and source_names_.
Referenced by load_sources().
|
inlineprivate |
Definition at line 481 of file Compiler_Line_Frontend.H.
References Aleph::DynArray< T >::access(), Aleph::blossom_maximum_cardinality_matching(), functions_, lets_, merge_order_, parsed_sources_, and Aleph::DynArray< T >::size().
|
inlineoverridevirtualnoexcept |
Returns the HIR module produced by the last lower_hir() call.
Implements Aleph::Compiler_Frontend.
Definition at line 1073 of file Compiler_Line_Frontend.H.
|
inlineoverridevirtualnoexcept |
Returns the IR module produced by the last lower_ir() call.
Implements Aleph::Compiler_Frontend.
Definition at line 1083 of file Compiler_Line_Frontend.H.
|
inlinestaticprivatenoexcept |
Definition at line 206 of file Compiler_Line_Frontend.H.
References Aleph::blossom_maximum_cardinality_matching().
Referenced by parse_identifier().
|
inlinestaticprivatenoexcept |
Definition at line 201 of file Compiler_Line_Frontend.H.
References Aleph::blossom_maximum_cardinality_matching().
Referenced by parse_identifier().
|
inlineoverridevirtual |
Registers ordered in-memory sources for the next compilation run.
| inputs | Non-empty array of named source texts; duplicate names are rejected. |
inputs is empty or contains a duplicate name (an error is appended via append_error in both cases). Implements Aleph::Compiler_Frontend.
Definition at line 710 of file Compiler_Line_Frontend.H.
References Aleph::Source_Manager::add_virtual_file(), Aleph::DynArray< T >::append(), append_error(), Aleph::blossom_maximum_cardinality_matching(), find_source_index(), source_ids_, source_names_, and sources_.
|
inlineoverridevirtual |
Lowers the analyzed line program into a reusable HIR module.
Implements Aleph::Compiler_Frontend.
Definition at line 863 of file Compiler_Line_Frontend.H.
References Aleph::DynArray< T >::access(), Aleph::blossom_maximum_cardinality_matching(), Aleph::compiler_dump_hir_module(), Aleph::Compiler_Type_Context::integer_type(), Aleph::Compiler_Type_Context::make_function_type(), and Aleph::DynArray< T >::size().
|
inlineoverridevirtual |
Lowers the analyzed line program into a reusable flat IR module.
Implements Aleph::Compiler_Frontend.
Definition at line 923 of file Compiler_Line_Frontend.H.
References Aleph::DynArray< T >::access(), Aleph::DynArray< T >::append(), Aleph::blossom_maximum_cardinality_matching(), Aleph::compiler_dump_ir_module(), Aleph::compiler_ir_invalid_id(), Aleph::exit(), Aleph::Compiler_IR_Module::functions, Aleph::Compiler_Type_Context::integer_type(), Aleph::DynArray< T >::is_empty(), Aleph::Compiler_Type_Context::make_function_type(), Aleph::Compiler_Driver_Detail::merge_report(), Aleph::DynArray< T >::size(), Aleph::validate_ir_module(), and value.
|
inlineoverridevirtualnoexcept |
Returns the module descriptors built during parse().
Reimplemented from Aleph::Compiler_Frontend.
Definition at line 1093 of file Compiler_Line_Frontend.H.
|
inlineoverridevirtualnoexcept |
Returns the dependency-resolved merge order from the last parse().
Reimplemented from Aleph::Compiler_Frontend.
Definition at line 1103 of file Compiler_Line_Frontend.H.
|
inlineoverridevirtualnoexcept |
Returns the module metadata built during parse().
Reimplemented from Aleph::Compiler_Frontend.
Definition at line 1113 of file Compiler_Line_Frontend.H.
Returns the stable frontend name.
"line". Implements Aleph::Compiler_Frontend.
Definition at line 668 of file Compiler_Line_Frontend.H.
Referenced by find_source_index().
|
inlineoverridevirtual |
Parses all registered sources, builds module descriptors and metadata, resolves import order, and records a parse artifact.
Implements Aleph::Compiler_Frontend.
Definition at line 741 of file Compiler_Line_Frontend.H.
References Aleph::DynArray< T >::access(), Aleph::blossom_maximum_cardinality_matching(), Aleph::DynArray< T >::clear(), Aleph::Function, functions_, Aleph::Global, lets_, merge_order_, module_descriptors_, module_metadata_, Aleph::Compiler_Line_Frontend::Parsed_Source::name, Aleph::Compiler_Module_Metadata::name, Aleph::Compiler_Module_Descriptor::name, parse_source_file(), parsed_sources_, Aleph::DynArray< T >::size(), source_ids_, and source_names_.
|
inlineprivate |
Definition at line 294 of file Compiler_Line_Frontend.H.
References Aleph::DynArray< T >::access(), Aleph::blossom_maximum_cardinality_matching(), emit_error(), Aleph::Invalid, Aleph::Compiler_Line_Frontend::Function_Definition::left_param, Aleph::Compiler_Line_Frontend::Function_Definition::lhs, Aleph::Compiler_Line_Frontend::Function_Definition::module_name, Aleph::Compiler_Line_Frontend::Function_Definition::name, Aleph::Compiler_Line_Frontend::Function_Definition::name_span, Aleph::Compiler_Line_Frontend::Function_Definition::op, parse_identifier(), parse_operand(), parse_operator_name(), Aleph::Compiler_Line_Frontend::Function_Definition::rhs, Aleph::Compiler_Line_Frontend::Function_Definition::right_param, Aleph::DynArray< T >::size(), and Aleph::Compiler_Line_Frontend::Function_Definition::span.
Referenced by parse_source_file().
|
inlinestaticprivatenoexcept |
Definition at line 211 of file Compiler_Line_Frontend.H.
References Aleph::blossom_maximum_cardinality_matching(), is_identifier_continue(), and is_identifier_start().
Referenced by parse_function_line(), parse_let_line(), and parse_operand().
|
inlineprivate |
Definition at line 280 of file Compiler_Line_Frontend.H.
References Aleph::DynArray< T >::access(), Aleph::blossom_maximum_cardinality_matching(), emit_error(), Aleph::DynArray< T >::size(), and trim_quotes_copy().
Referenced by parse_source_file().
|
inlinestaticprivatenoexcept |
Definition at line 190 of file Compiler_Line_Frontend.H.
References Aleph::and, and value.
Referenced by parse_let_line(), and parse_operand().
|
inlineprivate |
Definition at line 356 of file Compiler_Line_Frontend.H.
References Aleph::DynArray< T >::access(), Aleph::Compiler_Line_Frontend::Let_Definition::arg1, Aleph::Compiler_Line_Frontend::Let_Definition::arg2, Aleph::blossom_maximum_cardinality_matching(), Aleph::Compiler_Line_Frontend::Let_Definition::Call, Aleph::Compiler_Line_Frontend::Let_Definition::callee, emit_error(), Aleph::Compiler_Line_Frontend::Let_Definition::Integer, Aleph::Compiler_Line_Frontend::Let_Definition::integer_value, Aleph::Compiler_Line_Frontend::Let_Definition::kind, Aleph::Compiler_Line_Frontend::Let_Definition::module_name, Aleph::Compiler_Line_Frontend::Let_Definition::name, Aleph::Compiler_Line_Frontend::Let_Definition::name_span, parse_identifier(), parse_integer(), parse_operand(), Aleph::DynArray< T >::size(), Aleph::Compiler_Line_Frontend::Let_Definition::span, and value.
Referenced by parse_source_file().
|
inlinestaticprivate |
Definition at line 259 of file Compiler_Line_Frontend.H.
References Aleph::blossom_maximum_cardinality_matching(), Integer, out, parse_identifier(), parse_integer(), value, and Variable.
Referenced by parse_function_line(), and parse_let_line().
|
inlinestaticprivatenoexcept |
Definition at line 223 of file Compiler_Line_Frontend.H.
References Aleph::Invalid, Aleph::Minus, Aleph::Plus, Aleph::Slash, and Aleph::Star.
Referenced by parse_function_line().
|
inlineprivate |
Definition at line 437 of file Compiler_Line_Frontend.H.
References Aleph::and, Aleph::blossom_maximum_cardinality_matching(), diagnostics_, emit_error(), Aleph::Source_Span::file_id, Aleph::Source_Manager::file_text(), Aleph::Diagnostic_Engine::has_errors(), parse_function_line(), parse_import_line(), parse_let_line(), sources_, split_tokens(), and trim_copy().
Referenced by parse().
|
inlineprivate |
Definition at line 496 of file Compiler_Line_Frontend.H.
References Aleph::compiler_render_module_order(), merge_order_, module_descriptors_, and record_text_artifact().
|
inlineprivate |
Definition at line 241 of file Compiler_Line_Frontend.H.
References Aleph::Compiler_Driver_Detail::append_artifact(), and artifacts_.
Referenced by record_import_order_artifact().
|
inlineprivate |
Definition at line 502 of file Compiler_Line_Frontend.H.
References Aleph::and, Aleph::DynArray< T >::append(), Aleph::blossom_maximum_cardinality_matching(), Aleph::DynArray< T >::clear(), Aleph::compiler_resolve_module_order(), diagnostics_, emit_error(), Aleph::Diagnostic_Engine::has_errors(), Aleph::DynArray< T >::is_empty(), merge_order_, Aleph::Missing_Dependency, module_descriptors_, and parsed_sources_.
|
inlinestaticprivate |
Definition at line 180 of file Compiler_Line_Frontend.H.
References Aleph::DynArray< T >::append(), and Aleph::blossom_maximum_cardinality_matching().
Referenced by parse_source_file().
|
inlinestaticprivate |
Definition at line 160 of file Compiler_Line_Frontend.H.
References Aleph::and.
Referenced by parse_source_file().
|
inlinestaticprivate |
Definition at line 173 of file Compiler_Line_Frontend.H.
References Aleph::and.
Referenced by parse_import_line().
|
inlineoverridevirtualnoexcept |
Returns the shared type context used by the line frontend.
Implements Aleph::Compiler_Frontend.
Definition at line 1063 of file Compiler_Line_Frontend.H.
|
inlineprivate |
Definition at line 598 of file Compiler_Line_Frontend.H.
References emit_error(), Integer, Aleph::Compiler_Line_Frontend::Operand::kind, Aleph::Compiler_Symbol_Bindings::lookup(), Aleph::Compiler_Line_Frontend::Function_Definition::name, Aleph::Compiler_Line_Frontend::Operand::span, and Aleph::Compiler_Line_Frontend::Operand::text.
|
inlineprivate |
Definition at line 563 of file Compiler_Line_Frontend.H.
References Aleph::and, Aleph::blossom_maximum_cardinality_matching(), Aleph::Compiler_Line_Frontend::Let_Definition::Call, Aleph::compiler_emit_module_name_resolution_diagnostic(), Aleph::compiler_lookup_module_value(), Aleph::compiler_resolve_module_name(), diagnostics_, Aleph::Function, Aleph::Diagnostic_Engine::has_errors(), lets_, resolution, Aleph::Resolved, validate_top_level_operand(), and value.
|
inlineprivate |
Definition at line 615 of file Compiler_Line_Frontend.H.
References emit_error(), Integer, and Aleph::Compiler_Line_Frontend::Operand::kind.
Referenced by validate_top_level_calls().
|
inlineoverridevirtualnoexcept |
Returns non-fatal frontend-level warnings.
Implements Aleph::Compiler_Frontend.
Definition at line 1158 of file Compiler_Line_Frontend.H.
|
private |
Definition at line 143 of file Compiler_Line_Frontend.H.
|
private |
Definition at line 153 of file Compiler_Line_Frontend.H.
Referenced by clear(), and record_text_artifact().
|
private |
Definition at line 139 of file Compiler_Line_Frontend.H.
Referenced by clear(), emit_error(), parse_source_file(), resolve_import_order(), and validate_top_level_calls().
|
private |
Definition at line 154 of file Compiler_Line_Frontend.H.
Referenced by append_error(), and clear().
|
private |
Definition at line 150 of file Compiler_Line_Frontend.H.
Referenced by clear(), dump_parsed_program(), dump_semantic_state(), flatten_program_in_import_order(), and parse().
|
private |
Definition at line 141 of file Compiler_Line_Frontend.H.
Referenced by clear().
|
private |
Definition at line 157 of file Compiler_Line_Frontend.H.
Referenced by clear().
|
private |
Definition at line 142 of file Compiler_Line_Frontend.H.
Referenced by clear().
|
private |
Definition at line 158 of file Compiler_Line_Frontend.H.
Referenced by clear().
|
private |
Definition at line 151 of file Compiler_Line_Frontend.H.
Referenced by clear(), dump_parsed_program(), dump_semantic_state(), flatten_program_in_import_order(), parse(), and validate_top_level_calls().
|
private |
Definition at line 152 of file Compiler_Line_Frontend.H.
Referenced by clear(), flatten_program_in_import_order(), parse(), record_import_order_artifact(), and resolve_import_order().
|
private |
Definition at line 147 of file Compiler_Line_Frontend.H.
Referenced by clear(), parse(), record_import_order_artifact(), and resolve_import_order().
|
private |
Definition at line 148 of file Compiler_Line_Frontend.H.
|
private |
Definition at line 149 of file Compiler_Line_Frontend.H.
Referenced by clear(), flatten_program_in_import_order(), parse(), and resolve_import_order().
|
private |
Definition at line 146 of file Compiler_Line_Frontend.H.
Referenced by clear(), load_sources(), and parse().
|
private |
Definition at line 145 of file Compiler_Line_Frontend.H.
Referenced by clear(), find_source_index(), load_sources(), and parse().
|
private |
Definition at line 138 of file Compiler_Line_Frontend.H.
Referenced by clear(), load_sources(), and parse_source_file().
|
private |
Definition at line 140 of file Compiler_Line_Frontend.H.
Referenced by build_hir_operand(), build_ir_operand(), and clear().
|
private |
Definition at line 155 of file Compiler_Line_Frontend.H.
Referenced by clear().