Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Compiler_Driver.H
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
63#ifndef COMPILER_DRIVER_H
64#define COMPILER_DRIVER_H
65
66#include <sstream>
67#include <string>
68#include <string_view>
69#include <utility>
70
71#include <Bytecode.H>
72#include <Compiler_Backend_C.H>
77#include <Compiler_Parser.H>
78#include <Interpreter_Runtime.H>
79#include <tpl_dynArray.H>
80
81namespace Aleph {
96
97namespace Compiler_Driver_Detail {}
98
107{
117 size_t arena_bytes_ = 0;
118
126
134
135 void append_error(const std::string &text)
136 {
137 errors_.append(text);
138 }
139
140 void append_warning(const std::string &text)
141 {
142 warnings_.append(text);
143 }
144
146 const std::string &code,
147 const std::string &message,
148 const std::string &note = "",
149 const std::string &help = "")
150 {
151 auto builder = diagnostics_.error(span, message).code(code);
152 if (not note.empty())
153 builder.note(note);
154 if (not help.empty())
155 builder.help(help);
156 builder.emit();
157 }
158
159 void record_text_artifact(const std::string &label, std::string text)
160 {
162 }
163
164 size_t find_source_index(std::string_view name) const noexcept
165 {
166 for (size_t i = 0; i < source_names_.size(); ++i)
167 if (source_names_.access(i) == name)
168 return i;
169 return static_cast<size_t>(-1);
170 }
171
173 {
175 for (size_t i = 0; i < source_names_.size(); ++i)
176 modules.append({source_names_.access(i), {}});
178 }
179
181 {
182 for (size_t i = 0; i < parsed_modules_.size(); ++i)
183 record_text_artifact(Compiler_Driver_Detail::artifact_label("ast", i, source_names_.access(i)),
184 compiler_dump_module(parsed_modules_.access(i)));
185
186 record_import_order_artifact();
187 record_text_artifact("ast", compiler_dump_module(merged_ast_));
188 }
189
191 {
192 merge_order_.clear();
193
195 for (size_t i = 0; i < parsed_modules_.size(); ++i)
196 {
198 module.name = source_names_.access(i);
199 const auto *parsed = parsed_modules_.access(i);
200 if (parsed != nullptr)
201 for (size_t j = 0; j < parsed->imports.size(); ++j)
202 {
203 const auto *decl = parsed->imports.access(j);
204 if (decl == nullptr or decl->kind != Compiler_Import_Decl_Kind::Import)
205 continue;
206 module.imports.append({decl->module_name, decl->module_name_span});
207 }
208 modules.append(std::move(module));
209 }
210
211 const auto result = compiler_resolve_module_order(modules);
212 for (size_t i = 0; i < result.issues.size(); ++i)
213 {
214 const auto &issue = result.issues.access(i);
216 emit_driver_diagnostic(issue.span,
217 "DRV001",
218 "cannot resolve import '" + issue.dependency_name + "'",
219 "known sources must match import names exactly");
220 else
221 emit_driver_diagnostic(issue.span,
222 "DRV002",
223 "cyclic import involving '" + issue.module_name + "' and '"
224 + issue.dependency_name + "'",
225 "imports currently form one acyclic source-order graph");
226 }
227
228 for (size_t i = 0; i < result.order.size(); ++i)
229 merge_order_.append(result.order.access(i));
230
231 return result.valid and not diagnostics_.has_errors();
232 }
233
235 {
236 merged_ast_ = ast_ctx_.make<Compiler_Module>();
237 merged_ast_->source_name = "<merged>";
238
241
242 for (size_t i = 0; i < merge_order_.size(); ++i)
243 {
244 const auto module_index = merge_order_.access(i);
245 const auto *module = parsed_modules_.access(module_index);
246 if (module == nullptr)
247 continue;
248
249 if (not first_span.is_valid() and module->span.is_valid())
250 first_span = module->span;
251 if (module->span.is_valid())
252 last_span = module->span;
253
254 for (size_t j = 0; j < module->type_declarations.size(); ++j)
255 merged_ast_->type_declarations.append(module->type_declarations.access(j));
256 for (size_t j = 0; j < module->functions.size(); ++j)
257 merged_ast_->functions.append(module->functions.access(j));
258 for (size_t j = 0; j < module->statements.size(); ++j)
259 merged_ast_->statements.append(module->statements.access(j));
260 }
261
262 if (first_span.is_valid())
264 }
265
267 {
268 std::ostringstream out;
269 diagnostics_.render_plain(out);
270 record_text_artifact("diagnostics", out.str());
271 }
272
274 {
275 record_text_artifact("driver.messages",
276 Compiler_Driver_Detail::render_messages(errors_, warnings_));
277 }
278
280 {
281 parsed_modules_.clear();
282
283 for (size_t i = 0; i < source_file_ids_.size(); ++i)
284 {
286 ast_ctx_, sources_, source_file_ids_.access(i), &diagnostics_, config_.parser_options);
287 parsed_modules_.append(parser.parse_module());
288 }
289
290 if (not resolve_import_order())
291 {
292 if (merge_order_.is_empty())
293 for (size_t i = 0; i < parsed_modules_.size(); ++i)
294 merge_order_.append(i);
295 }
296
297 merge_modules_from_order();
298
299 record_ast_artifacts();
300 return not diagnostics_.has_errors();
301 }
302
304 {
305 typed_.analyze_module(merged_ast_);
306 record_text_artifact("typed-sema", typed_.dump_inference());
307 return not diagnostics_.has_errors();
308 }
309
311 {
312 Compiler_HIR_Lowering lowering(hir_ctx_, typed_);
313 hir_module_ = lowering.lower_module(merged_ast_);
314 record_text_artifact("hir", compiler_dump_hir_module(hir_module_, typed_.type_context()));
315 return hir_module_ != nullptr;
316 }
317
318 bool lower_ir()
319 {
321 ir_module_ = lowering.lower_module(hir_module_);
322 record_text_artifact("ir", compiler_dump_ir_module(ir_module_, &typed_.type_context()));
323
324 if (ir_module_ == nullptr)
325 {
326 append_error("ir: null IR module produced by lowering");
327 return false;
328 }
329
330 const auto report = validate_ir_module(*ir_module_);
331 return Compiler_Driver_Detail::merge_report("ir", report, errors_, warnings_);
332 }
333
335 {
337 bytecode_module_ = lowering.lower_module(ir_module_);
338 record_text_artifact("bytecode",
339 compiler_dump_bytecode_module(bytecode_module_, &typed_.type_context()));
340
341 if (bytecode_module_ == nullptr)
342 {
343 append_error("bytecode: null bytecode module produced by lowering");
344 return false;
345 }
346
347 const auto report = validate_bytecode_module(*bytecode_module_);
348 return Compiler_Driver_Detail::merge_report("bytecode", report, errors_, warnings_);
349 }
350
351 bool emit_c()
352 {
353 c_emission_ = compiler_emit_c_module(ir_module_, config_.c_backend_options);
354 record_text_artifact("emit-c", c_emission_.source);
355 return Compiler_Driver_Detail::merge_report("emit-c", c_emission_, errors_, warnings_);
356 }
357
359 {
360 run_output_ = {};
361 run_output_.executed = true;
362 run_output_.result = runtime_.evaluate_module(hir_module_);
363 if (run_output_.result.ok())
364 run_output_.value_text = interpreter_value_to_string(run_output_.result.value);
365 else
366 run_output_.value_text = "";
367 run_output_.globals_text = interpreter_dump_globals(runtime_);
368
369 record_text_artifact("run.result", Compiler_Driver_Detail::render_run_result(run_output_));
370 record_text_artifact("run.globals", run_output_.globals_text);
371 return run_output_.result.ok();
372 }
373
375 {
376 if (run_output_.result.ok())
377 return;
378
379 std::string message = "run: HIR runtime execution failed";
380 if (not run_output_.result.error.code.empty() or not run_output_.result.error.message.empty())
381 {
382 message += ":";
383 if (not run_output_.result.error.code.empty())
384 message += " " + run_output_.result.error.code;
385 if (not run_output_.result.error.message.empty())
386 {
387 if (not run_output_.result.error.code.empty())
388 message += " ";
389 message += run_output_.result.error.message;
390 }
391 }
392 append_error(message);
393 }
394
396 {
397 last_action_ = action;
398 record_driver_messages_artifact();
399 record_diagnostics_artifact();
400 return ok();
401 }
402
404 {
405 if (inputs.is_empty())
406 {
407 append_error("driver: no input sources were provided");
408 return false;
409 }
410
411 for (size_t i = 0; i < inputs.size(); ++i)
412 {
413 const auto &input = inputs.access(i);
414 if (find_source_index(input.name) != static_cast<size_t>(-1))
415 {
416 append_error("driver: duplicate input source name '" + input.name + "'");
417 return false;
418 }
419 source_names_.append(input.name);
420 source_file_ids_.append(sources_.add_virtual_file(input.name, input.text));
421 }
422
423 return true;
424 }
425
426public:
433 const size_t arena_size = 1 << 20)
434 : config_(options), diagnostics_(sources_), ast_ctx_(arena_size), hir_ctx_(arena_size),
435 ir_ctx_(arena_size), bytecode_ctx_(arena_size),
436 typed_(&diagnostics_, options.typed_semantic_options),
437 runtime_(&diagnostics_, options.runtime_options), arena_bytes_(arena_size)
438 {}
439
442
445 {
446 return config_;
447 }
448
451 {
452 return arena_bytes_;
453 }
454
457 {
458 parsed_modules_.clear();
459 merge_order_.clear();
460 source_names_.clear();
461 source_file_ids_.clear();
462 artifacts_.clear();
463 errors_.clear();
464 warnings_.clear();
465
466 merged_ast_ = nullptr;
467 hir_module_ = nullptr;
468 ir_module_ = nullptr;
469 bytecode_module_ = nullptr;
470 c_emission_ = {};
471 run_output_ = {};
473
474 runtime_.reset();
475 runtime_.set_diagnostics(&diagnostics_);
476 typed_.clear();
477 diagnostics_.clear();
478 ast_ctx_.reset();
479 hir_ctx_.reset();
480 ir_ctx_.reset();
481 bytecode_ctx_.reset();
482 sources_ = Source_Manager();
483 }
484
486 bool bind_host_function(const std::string &name,
487 const Interpreter_Host_Function callback,
488 void *user_data = nullptr)
489 {
490 return runtime_.bind_host_function(name, callback, user_data);
491 }
492
502 {
503 clear();
504 if (not prepare_inputs(inputs))
505 return finalize(action);
506 if (not parse_registered_sources())
507 return finalize(action);
509 return finalize(action);
510
511 if (not run_typed_semantics())
512 return finalize(action);
514 return finalize(action);
515
516 if (not lower_hir())
517 {
518 append_error("hir: failed to lower merged AST to HIR");
519 return finalize(action);
520 }
522 return finalize(action);
523
525 {
526 if (not execute_hir_runtime())
527 append_run_failure_if_needed();
528 return finalize(action);
529 }
530
531 if (not lower_ir())
532 return finalize(action);
534 return finalize(action);
535
536 switch (action)
537 {
539 (void) lower_bytecode();
540 return finalize(action);
541
543 (void) emit_c();
544 return finalize(action);
545
551 return finalize(action);
552 }
553
554 append_error("driver: reached unreachable action dispatch");
555 return finalize(action);
556 }
557
566 {
567 clear();
568 if (paths.is_empty())
569 {
570 append_error("driver: no input file paths were provided");
571 return finalize(action);
572 }
573
574 for (size_t i = 0; i < paths.size(); ++i)
575 {
576 const auto &path = paths.access(i);
577 if (find_source_index(path) != static_cast<size_t>(-1))
578 {
579 append_error("driver: duplicate input file path '" + path + "'");
580 return finalize(action);
581 }
582 source_names_.append(path);
583 source_file_ids_.append(sources_.load_file(path));
584 }
585
586 if (not parse_registered_sources())
587 return finalize(action);
589 return finalize(action);
590
591 if (not run_typed_semantics())
592 return finalize(action);
594 return finalize(action);
595
596 if (not lower_hir())
597 {
598 append_error("hir: failed to lower merged AST to HIR");
599 return finalize(action);
600 }
602 return finalize(action);
603
605 {
606 if (not execute_hir_runtime())
607 append_run_failure_if_needed();
608 return finalize(action);
609 }
610
611 if (not lower_ir())
612 return finalize(action);
614 return finalize(action);
615
617 {
618 (void) lower_bytecode();
619 return finalize(action);
620 }
621
623 {
624 (void) emit_c();
625 return finalize(action);
626 }
627
628 append_error("driver: reached unreachable file-action dispatch");
629 return finalize(action);
630 }
631
633 bool execute_source(const std::string &name,
634 const std::string &text,
636 {
638 inputs.append({name, text});
639 return execute_sources(inputs, action);
640 }
641
644 {
645 return errors_.is_empty() and not diagnostics_.has_errors();
646 }
647
650 {
651 return last_action_;
652 }
653
656 {
657 return sources_;
658 }
659
662 {
663 return diagnostics_;
664 }
665
668 {
669 return typed_;
670 }
671
674 {
675 return parsed_modules_;
676 }
677
680 {
681 return merged_ast_;
682 }
683
686 {
687 return hir_module_;
688 }
689
692 {
693 return ir_module_;
694 }
695
698 {
699 return bytecode_module_;
700 }
701
704 {
705 return c_emission_;
706 }
707
710 {
711 return run_output_;
712 }
713
716 {
717 return errors_;
718 }
719
722 {
723 return warnings_;
724 }
725
728 {
729 return artifacts_;
730 }
731
737 [[nodiscard]] const Compiler_Driver_Artifact *find_artifact(std::string_view label) const noexcept
738 {
739 for (size_t i = artifacts_.size(); i > 0; --i)
740 if (artifacts_.access(i - 1).label == label)
741 return &artifacts_.access(i - 1);
742 return nullptr;
743 }
744
746 [[nodiscard]] std::string diagnostics_text() const
747 {
748 std::ostringstream out;
749 diagnostics_.render_plain(out);
750 return out.str();
751 }
752};
753} // namespace Aleph
754
755#endif
Reusable bytecode format and lowering from Compiler_IR_Model.H.
Portable C backend that emits standalone C from Compiler_IR_Model.H.
Shared contracts used by reusable compiler frontends and 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.
Reusable runtime and structured evaluator for HIR-based interpreters.
size_t size_t int32_t * out
Definition ca-c-api.h:120
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.
Arena-backed ownership context for bytecode functions and modules.
Definition Bytecode.H:254
void reset() noexcept
Resets the arena and destroys all tracked objects.
Definition Bytecode.H:298
Lowers explicit IR into register-based bytecode.
Definition Bytecode.H:581
Reusable orchestration object for compiler pipeline experiments.
void append_warning(const std::string &text)
Compiler_Ast_Context ast_ctx_
void clear() noexcept
Clears all stage outputs while preserving host prelude bindings.
bool execute_source(const std::string &name, const std::string &text, const Compiler_Driver_Action action=Compiler_Driver_Action::Run)
Convenience overload for a single in-memory source.
size_t arena_size() const noexcept
Returns the arena size shared by the internal contexts.
Diagnostic_Engine diagnostics_
Compiler_HIR_Module * hir_module_
const Compiler_Bytecode_Module * bytecode_module() const noexcept
Returns the lowered bytecode module from the last run, when available.
DynArray< Source_File_Id > source_file_ids_
Interpreter_Runtime runtime_
std::string diagnostics_text() const
Renders diagnostics from the last run as plain text.
const Compiler_Module * merged_ast_module() const noexcept
Returns the merged AST module from the last run.
DynArray< std::string > warnings_
const Compiler_Driver_Options & options() const noexcept
Returns the immutable construction-time configuration.
Compiler_Driver(const Compiler_Driver &)=delete
const Compiler_Driver_Run_Output & run_output() const noexcept
Returns the run summary from the last run action.
const Diagnostic_Engine & diagnostic_engine() const noexcept
Returns the diagnostic engine populated by the last run.
const Compiler_C_Backend_Emission & c_emission() const noexcept
Returns the C emission payload from the last emit-c action.
DynArray< std::string > source_names_
void emit_driver_diagnostic(const Source_Span &span, const std::string &code, const std::string &message, const std::string &note="", const std::string &help="")
DynArray< Compiler_Driver_Artifact > artifacts_
void record_text_artifact(const std::string &label, std::string text)
Compiler_Driver & operator=(const Compiler_Driver &)=delete
Compiler_Driver_Options config_
const DynArray< Compiler_Module * > & parsed_ast_modules() const noexcept
Returns the parsed per-file AST modules from the last run.
size_t find_source_index(std::string_view name) const noexcept
const Compiler_Driver_Artifact * find_artifact(std::string_view label) const noexcept
Finds one artifact by label.
DynArray< std::string > errors_
const Compiler_Typed_Semantic_Analyzer & typed_analysis() const noexcept
Returns the typed semantic analyzer state from the last run.
bool ok() const noexcept
Returns whether the last driver action finished successfully.
Compiler_Typed_Semantic_Analyzer typed_
Compiler_C_Backend_Emission c_emission_
Compiler_Driver_Action last_action() const noexcept
Returns the last requested action.
bool execute_sources(const DynArray< Compiler_Driver_Source > &inputs, const Compiler_Driver_Action action=Compiler_Driver_Action::Run)
Runs the pipeline over in-memory sources.
Compiler_Driver_Run_Output run_output_
Compiler_Bytecode_Module * bytecode_module_
const DynArray< std::string > & errors() const noexcept
Returns non-diagnostic driver-level hard errors.
Compiler_Bytecode_Context bytecode_ctx_
Compiler_Module * merged_ast_
bool finalize(const Compiler_Driver_Action action)
Compiler_HIR_Context hir_ctx_
bool bind_host_function(const std::string &name, const Interpreter_Host_Function callback, void *user_data=nullptr)
Binds one host function into the persistent runtime prelude.
const DynArray< Compiler_Driver_Artifact > & artifacts() const noexcept
Returns all recorded artifacts from the last run.
void append_error(const std::string &text)
const Compiler_IR_Module * ir_module() const noexcept
Returns the lowered IR module from the last run, when available.
Compiler_Driver(const Compiler_Driver_Options &options={}, const size_t arena_size=1<< 20)
Constructs a driver with one stable set of pipeline options.
DynArray< Compiler_Module * > parsed_modules_
const Source_Manager & source_manager() const noexcept
Returns the shared source manager for the last run.
bool prepare_inputs(const DynArray< Compiler_Driver_Source > &inputs)
const Compiler_HIR_Module * hir_module() const noexcept
Returns the lowered HIR module from the last run, when available.
Compiler_IR_Module * ir_module_
const DynArray< std::string > & warnings() const noexcept
Returns non-fatal driver-level warnings.
bool execute_files(const DynArray< std::string > &paths, const Compiler_Driver_Action action=Compiler_Driver_Action::Run)
Runs the pipeline over source files loaded from disk.
Compiler_IR_Context ir_ctx_
Compiler_Driver_Action last_action_
DynArray< size_t > merge_order_
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.
Recursive-descent parser that produces an AST in Compiler_Ast_Context.
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.
Structured runtime for executing typed HIR.
void set_diagnostics(Diagnostic_Engine *dx) noexcept
Sets the optional diagnostic sink for runtime failures.
bool bind_host_function(const std::string &name, const Interpreter_Host_Function callback, void *user_data=nullptr)
Defines one host function in the persistent prelude.
void reset() noexcept
Clears globals and the call stack while preserving host bindings.
Interpreter_Execution_Result evaluate_module(const Compiler_HIR_Module *module)
Evaluates one HIR module and leaves its globals installed.
Stores source files and resolves offsets into human-readable data.
Definition ah-source.H:184
Source_File_Id load_file(const std::string &path)
Loads a file from disk and registers it.
Definition ah-source.H:276
Source_File_Id add_virtual_file(const std::string &name, const std::string &text)
Registers an in-memory source file.
Definition ah-source.H:258
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
std::string render_messages(const DynArray< std::string > &errors, const DynArray< std::string > &warnings)
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)
std::string render_run_result(const Compiler_Driver_Run_Output &output)
void append_artifact(DynArray< Compiler_Driver_Artifact > &artifacts, const std::string &label, std::string text)
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
Compiler_Driver_Action
High-level actions supported by compiler pipeline drivers.
@ Emit_C
Lower to IR and emit portable C.
@ IR
Stop after lowering to explicit IR.
@ Parse_Only
Stop after parsing and publish AST/frontend artifacts.
@ Run
Execute the lowered HIR module with Interpreter_Runtime.
@ Emit_Bytecode
Lower to IR and emit reusable bytecode.
@ Sema_Only
Stop after semantic analysis.
@ HIR
Stop after lowering to typed HIR.
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.
Definition ahDefs.C:95
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.
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_bytecode_module(const Compiler_Bytecode_Module *module, const Compiler_Type_Context *types=nullptr)
Dumps all lowered bytecode in one module deterministically.
Definition Bytecode.H:1081
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.
Compiler_Bytecode_Validation_Report validate_bytecode_module(const Compiler_Bytecode_Module &module)
Validates all bytecode functions in one module.
Definition Bytecode.H:900
bool(*)(void *user_data, const DynArray< Interpreter_Value > &arguments, Interpreter_Value &result, Interpreter_Runtime_Error &error) Interpreter_Host_Function
Host callback signature used by runtime built-ins or embeddings.
std::string interpreter_dump_globals(const Interpreter_Runtime &runtime)
Dumps the globals currently installed in one runtime.
std::string interpreter_value_to_string(const Interpreter_Value &value)
Formats one runtime value deterministically for dumps and tests.
Compiler_C_Backend_Emission compiler_emit_c_module(const Compiler_IR_Module *module, const Compiler_C_Backend_Options &options={}, const Compiler_Type_Context *types=nullptr)
Convenience wrapper that emits one IR module to portable C.
static struct argp_option options[]
Definition ntreepic.C:1886
Source_Span span
Source region covered by this node.
Bytecode module sharing global slot layout with the source IR module.
Definition Bytecode.H:246
Result of one C backend emission request.
std::string source
Final generated C translation unit.
Options that control one C backend emission request.
Stable text artifact produced during one pipeline run.
Immutable configuration shared by all runs of one driver object.
Compiler_C_Backend_Options c_backend_options
Backend-C emission options used by emit-c.
Compiler_Typed_Semantic_Options typed_semantic_options
Typed semantic options shared by the driver.
Compiler_Parser_Options parser_options
Parser configuration used for every parsed file.
Interpreter_Runtime_Options runtime_options
Runtime limits used by run.
Structured output of a run action.
std::string value_text
Stable rendering of the produced value.
std::string globals_text
Stable dump of the final globals environment.
Interpreter_Execution_Result result
Raw runtime result.
bool executed
Whether the current driver action actually executed code.
Lowered IR module with shared global slots and functions.
One module descriptor consumed by the reusable resolver.
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.
Interpreter_Runtime_Error error
Structured runtime failure when flow == Runtime_Error.
Interpreter_Value value
Produced runtime value when relevant.
bool ok() const noexcept
Returns whether this result represents a runtime failure.
std::string code
Stable runtime code such as RUN004.
std::string message
Human-readable runtime message.
Runtime options for the HIR evaluator.
Half-open byte range inside a source file.
Definition ah-source.H:100
Lazy and scalable dynamic array implementation.