Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Compiler_HIR_Model.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
41#ifndef COMPILER_HIR_MODEL_H
42#define COMPILER_HIR_MODEL_H
43
44#include <sstream>
45#include <string>
46#include <string_view>
47#include <utility>
48
49#include <Compiler_Operator.H>
50#include <Compiler_Types.H>
51#include <ah-arena.H>
52#include <ah-errors.H>
53#include <tpl_dynArray.H>
54
55namespace Aleph {
57inline Source_Span compiler_hir_merge_spans(const Source_Span &lhs, const Source_Span &rhs) noexcept
58{
59 if (not lhs.is_valid())
60 return rhs;
61 if (not rhs.is_valid())
62 return lhs;
63 return lhs.file_id == rhs.file_id ? Source_Span{lhs.file_id, lhs.begin, rhs.end} : lhs;
64}
65
71
74{
75 Invalid,
78 Unary,
79 Binary,
80 Call
81};
82
85{
86 Invalid,
87 Eval,
88 Let,
89 Return,
90 Block,
91 If,
92 While,
93 Break,
95};
96
99{
100 Integer,
101 String,
102 Character,
103 Bool,
104 Unit
105};
106
108inline const char *compiler_hir_expr_kind_name(const Compiler_HIR_Expr_Kind kind) noexcept
109{
110 switch (kind)
111 {
113 return "Invalid";
115 return "Constant";
117 return "Variable";
119 return "Unary";
121 return "Binary";
123 return "Call";
124 }
125
126 return "Unknown";
127}
128
130inline const char *compiler_hir_stmt_kind_name(const Compiler_HIR_Stmt_Kind kind) noexcept
131{
132 switch (kind)
133 {
135 return "Invalid";
137 return "Eval";
139 return "Let";
141 return "Return";
143 return "Block";
145 return "If";
147 return "While";
149 return "Break";
151 return "Continue";
152 }
153
154 return "Unknown";
155}
156
158inline const char *compiler_hir_constant_kind_name(const Compiler_HIR_Constant_Kind kind) noexcept
159{
160 switch (kind)
161 {
163 return "Integer";
165 return "String";
167 return "Char";
169 return "Bool";
171 return "Unit";
172 }
173
174 return "Unknown";
175}
176
179{
181
182 explicit Compiler_HIR_Node(const Source_Span &sp = {}) noexcept : span(sp) {}
183};
184
187{
189 {
190 void *ptr = nullptr;
191 void (*destroy)(void *) noexcept = nullptr;
192 };
193
196
197public:
203 explicit Compiler_HIR_Context(const size_t arena_size = AhArenaAllocator::DEFAULT_SIZE)
204 : arena(arena_size)
205 {}
206
209
214
222 template <typename T, typename... Args>
224 {
225 T *ptr = allocate<T>(arena, std::forward<Args>(args)...);
226 ah_runtime_error_unless(ptr != nullptr) << "Compiler_HIR_Context: arena allocation failed";
227
228 owned.append({ptr,
229 [](void *raw) noexcept
230 {
231 static_cast<T *>(raw)->~T();
232 }});
233 return ptr;
234 }
235
238 {
239 for (size_t i = owned.size(); i > 0; --i)
240 {
241 auto &[ptr, destroy] = owned.access(i - 1);
242 if (destroy != nullptr and ptr != nullptr)
243 destroy(ptr);
244 }
245 owned.clear();
246 arena.reset();
247 }
248
251 {
252 return arena.allocated_size();
253 }
254
257 {
258 return arena.capacity();
259 }
260};
261
274
285
293
311
314{
315 std::string name;
317
319 const Compiler_Type_Id ty = 0,
320 const Source_Span &sp = {}) noexcept
323 {}
324};
325
343
366
386
394
397{
399
401 const Source_Span &sp = {}) noexcept
403 expr(value)
404 {}
405};
406
409{
410 std::string name;
414
415 Compiler_HIR_Let_Stmt(std::string value = "",
416 const Compiler_Type_Id ty = 0,
417 const Source_Span &name_sp = {},
418 Compiler_HIR_Expr *init = nullptr,
419 const Source_Span &sp = {}) noexcept
421 sp.is_valid()
422 ? sp
424 : name_sp)),
426 {}
427};
428
431{
433
435 const Source_Span &sp = {}) noexcept
437 sp.is_valid() ? sp : (expr != nullptr ? expr->span : Source_Span())),
438 value(expr)
439 {}
440};
441
454
480
483{
487
489 Compiler_HIR_Stmt *stmt = nullptr,
490 const Source_Span &kw = {}) noexcept
493 stmt != nullptr
494 ? stmt->span
495 : (cond != nullptr ? cond->span : Source_Span()))),
496 condition(cond), body(stmt), keyword_span(kw)
497 {}
498};
499
507
515
523
526{
527 std::string name;
532
533 Compiler_HIR_Function(std::string value = "",
534 const Compiler_Type_Id ty = 0,
535 const Source_Span &name_sp = {},
536 Compiler_HIR_Block_Stmt *block = nullptr,
537 const Source_Span &sp = {}) noexcept
539 sp.is_valid()
540 ? sp
541 : compiler_hir_merge_spans(name_sp, block != nullptr ? block->span : Source_Span())),
542 name(std::move(value)), name_span(name_sp), type_id(ty), body(block)
543 {}
544};
545
554
555namespace Compiler_HIR_Detail {
556inline std::string escape_text(std::string_view text)
557{
558 std::string escaped;
559 escaped.reserve(text.size());
560 for (const char ch : text)
561 switch (ch)
562 {
563 case '\\':
564 escaped += "\\\\";
565 break;
566 case '"':
567 escaped += "\\\"";
568 break;
569 case '\n':
570 escaped += "\\n";
571 break;
572 case '\r':
573 escaped += "\\r";
574 break;
575 case '\t':
576 escaped += "\\t";
577 break;
578 default:
579 escaped.push_back(ch);
580 }
581 return escaped;
582}
583
584inline void append_indent(std::ostream &out, const size_t indent)
585{
586 out << std::string(indent, ' ');
587}
588
589inline std::string type_text(const Compiler_Type_Context *types, const Compiler_Type_Id id)
590{
591 if (types == nullptr)
592 return "<no-types>";
593 if (id == 0)
594 return "<unknown-type>";
595 return types->to_string(id);
596}
597
598inline void dump_expr(const Compiler_HIR_Expr *expr,
599 std::ostream &out,
600 const size_t indent,
601 const Compiler_Type_Context *types);
602
603inline void dump_stmt(const Compiler_HIR_Stmt *stmt,
604 std::ostream &out,
605 const size_t indent,
606 const Compiler_Type_Context *types);
607
608inline void dump_expr(const Compiler_HIR_Expr *expr,
609 std::ostream &out,
610 const size_t indent,
611 const Compiler_Type_Context *types)
612{
613 append_indent(out, indent);
614 if (expr == nullptr)
615 {
616 out << "<null-hir-expr>\n";
617 return;
618 }
619
620 switch (expr->kind)
621 {
623 out << "InvalidExpr: " << type_text(types, expr->type_id) << '\n';
624 break;
625
627 {
628 const auto *node = static_cast<const Compiler_HIR_Constant_Expr *>(expr);
629 out << "Constant(" << compiler_hir_constant_kind_name(node->constant_kind);
630 if (node->constant_kind == Compiler_HIR_Constant_Kind::Bool)
631 out << ", " << (node->bool_value ? "true" : "false");
632 else if (node->constant_kind != Compiler_HIR_Constant_Kind::Unit)
633 out << ", " << node->text;
634 out << "): " << type_text(types, node->type_id) << '\n';
635 break;
636 }
637
639 {
640 const auto *node = static_cast<const Compiler_HIR_Variable_Expr *>(expr);
641 out << "Variable(" << node->name << "): " << type_text(types, node->type_id) << '\n';
642 break;
643 }
644
646 {
647 const auto *node = static_cast<const Compiler_HIR_Unary_Expr *>(expr);
648 out << "Unary(" << compiler_operator_name(node->op)
649 << "): " << type_text(types, node->type_id) << '\n';
650 dump_expr(node->operand, out, indent + 2, types);
651 break;
652 }
653
655 {
656 const auto *node = static_cast<const Compiler_HIR_Binary_Expr *>(expr);
657 out << "Binary(" << compiler_operator_name(node->op)
658 << "): " << type_text(types, node->type_id) << '\n';
659 dump_expr(node->left, out, indent + 2, types);
660 dump_expr(node->right, out, indent + 2, types);
661 break;
662 }
663
665 {
666 const auto *node = static_cast<const Compiler_HIR_Call_Expr *>(expr);
667 out << "Call: " << type_text(types, node->type_id) << '\n';
668 append_indent(out, indent + 2);
669 out << "Callee:\n";
670 dump_expr(node->callee, out, indent + 4, types);
671 append_indent(out, indent + 2);
672 out << "Args:\n";
673 for (size_t i = 0; i < node->arguments.size(); ++i)
674 dump_expr(node->arguments.access(i), out, indent + 4, types);
675 break;
676 }
677 }
678}
679
680inline void dump_stmt(const Compiler_HIR_Stmt *stmt,
681 std::ostream &out,
682 const size_t indent,
683 const Compiler_Type_Context *types)
684{
685 append_indent(out, indent);
686 if (stmt == nullptr)
687 {
688 out << "<null-hir-stmt>\n";
689 return;
690 }
691
692 switch (stmt->kind)
693 {
695 out << "InvalidStmt\n";
696 break;
697
699 {
700 const auto *node = static_cast<const Compiler_HIR_Eval_Stmt *>(stmt);
701 out << "Eval\n";
702 dump_expr(node->expr, out, indent + 2, types);
703 break;
704 }
705
707 {
708 const auto *node = static_cast<const Compiler_HIR_Let_Stmt *>(stmt);
709 out << "Let(" << node->name << "): " << type_text(types, node->binding_type) << '\n';
710 if (node->initializer != nullptr)
711 dump_expr(node->initializer, out, indent + 2, types);
712 break;
713 }
714
716 {
717 const auto *node = static_cast<const Compiler_HIR_Return_Stmt *>(stmt);
718 out << "Return\n";
719 if (node->value != nullptr)
720 dump_expr(node->value, out, indent + 2, types);
721 break;
722 }
723
725 {
726 const auto *node = static_cast<const Compiler_HIR_Block_Stmt *>(stmt);
727 out << "Block\n";
728 for (size_t i = 0; i < node->statements.size(); ++i)
729 dump_stmt(node->statements.access(i), out, indent + 2, types);
730 break;
731 }
732
734 {
735 const auto *node = static_cast<const Compiler_HIR_If_Stmt *>(stmt);
736 out << "If\n";
737 append_indent(out, indent + 2);
738 out << "Condition:\n";
739 dump_expr(node->condition, out, indent + 4, types);
740 append_indent(out, indent + 2);
741 out << "Then:\n";
742 dump_stmt(node->then_branch, out, indent + 4, types);
743 if (node->else_branch != nullptr)
744 {
745 append_indent(out, indent + 2);
746 out << "Else:\n";
747 dump_stmt(node->else_branch, out, indent + 4, types);
748 }
749 break;
750 }
751
753 {
754 const auto *node = static_cast<const Compiler_HIR_While_Stmt *>(stmt);
755 out << "While\n";
756 append_indent(out, indent + 2);
757 out << "Condition:\n";
758 dump_expr(node->condition, out, indent + 4, types);
759 append_indent(out, indent + 2);
760 out << "Body:\n";
761 dump_stmt(node->body, out, indent + 4, types);
762 break;
763 }
764
766 out << "Break\n";
767 break;
768
770 out << "Continue\n";
771 break;
772 }
773}
774} // namespace Compiler_HIR_Detail
775
777inline std::string compiler_dump_hir_expr(const Compiler_HIR_Expr *expr,
778 const Compiler_Type_Context &types)
779{
780 std::ostringstream out;
781 Compiler_HIR_Detail::dump_expr(expr, out, 0, &types);
782 return out.str();
783}
784
786inline std::string compiler_dump_hir_stmt(const Compiler_HIR_Stmt *stmt,
787 const Compiler_Type_Context &types)
788{
789 std::ostringstream out;
790 Compiler_HIR_Detail::dump_stmt(stmt, out, 0, &types);
791 return out.str();
792}
793
795inline std::string compiler_dump_hir_function(const Compiler_HIR_Function *function,
796 const Compiler_Type_Context &types)
797{
798 std::ostringstream out;
799 if (function == nullptr)
800 {
801 out << "<null-hir-function>\n";
802 return out.str();
803 }
804
805 out << "Function(" << function->name << "): " << types.to_string(function->type_id) << '\n';
806 if (function->parameters.size() > 0)
807 {
808 out << " Params:";
809 for (size_t i = 0; i < function->parameters.size(); ++i)
810 {
811 const auto &param = function->parameters.access(i);
812 if (i > 0)
813 out << ",";
814 out << " " << param.name << ": " << types.to_string(param.type_id);
815 }
816 out << '\n';
817 }
818 out << " Body:\n";
819 Compiler_HIR_Detail::dump_stmt(function->body, out, 4, &types);
820 return out.str();
821}
822
824inline std::string compiler_dump_hir_module(const Compiler_HIR_Module *module,
825 const Compiler_Type_Context &types)
826{
827 std::ostringstream out;
828 if (module == nullptr)
829 {
830 out << "<null-hir-module>\n";
831 return out.str();
832 }
833
834 out << "HIRModule\n";
835 for (size_t i = 0; i < module->functions.size(); ++i)
836 {
838 const auto *function = module->functions.access(i);
839 if (function == nullptr)
840 {
841 out << "Function: <null>\n";
842 continue;
843 }
844 out << "Function(" << function->name << "): " << types.to_string(function->type_id) << '\n';
845 if (function->parameters.size() > 0)
846 {
848 out << "Params:";
849 for (size_t j = 0; j < function->parameters.size(); ++j)
850 {
851 const auto &param = function->parameters.access(j);
852 if (j > 0)
853 out << ",";
854 out << " " << param.name << ": " << types.to_string(param.type_id);
855 }
856 out << '\n';
857 }
859 out << "Body:\n";
860 Compiler_HIR_Detail::dump_stmt(function->body, out, 6, &types);
861 }
862
863 for (size_t i = 0; i < module->statements.size(); ++i)
864 Compiler_HIR_Detail::dump_stmt(module->statements.access(i), out, 2, &types);
865 return out.str();
866}
867} // namespace Aleph
868
869#endif
Reusable operator vocabulary shared by HIR, IR, and backend layers.
Stable type graph for the compiler-support MVP.
Memory arena for fast bulk allocations.
Exception handling system with formatted messages for Aleph-w.
#define ah_runtime_error_unless(C)
Throws std::runtime_error if condition does NOT hold.
Definition ah-errors.H:255
size_t size_t int32_t value
Definition ca-c-api.h:116
size_t size_t int32_t * out
Definition ca-c-api.h:120
Arena allocator for fast bump-pointer allocation.
Definition ah-arena.H:122
void reset() noexcept
Reset arena, making all memory available again.
Definition ah-arena.H:256
size_t capacity() const noexcept
Get total arena capacity.
Definition ah-arena.H:407
size_t allocated_size() const noexcept
Get total bytes currently allocated.
Definition ah-arena.H:395
static constexpr size_t DEFAULT_SIZE
Default arena size (1 MB).
Definition ah-arena.H:133
Arena-backed ownership context for HIR nodes.
Compiler_HIR_Context & operator=(const Compiler_HIR_Context &)=delete
T * make(Args &&...args)
Allocates and constructs one HIR object.
DynArray< Owned_Object > owned
void reset() noexcept
Destroys all tracked objects and rewinds the arena.
Compiler_HIR_Context(const size_t arena_size=AhArenaAllocator::DEFAULT_SIZE)
Constructs a context with arena_size bytes.
size_t allocated_size() const noexcept
Returns bytes currently consumed in the arena.
size_t capacity() const noexcept
Returns total arena capacity in bytes.
Compiler_HIR_Context(const Compiler_HIR_Context &)=delete
Context owning all compiler type nodes.
std::string to_string(const Compiler_Type_Id id) const
Renders one type to a deterministic human-readable string.
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
void dump_expr(const Compiler_HIR_Expr *expr, std::ostream &out, const size_t indent, const Compiler_Type_Context *types)
void dump_stmt(const Compiler_HIR_Stmt *stmt, std::ostream &out, const size_t indent, const Compiler_Type_Context *types)
std::string escape_text(std::string_view text)
std::string type_text(const Compiler_Type_Context *types, const Compiler_Type_Id id)
void append_indent(std::ostream &out, const size_t indent)
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
const char * compiler_hir_stmt_kind_name(const Compiler_HIR_Stmt_Kind kind) noexcept
Returns a stable debug name for an HIR statement kind.
const char * compiler_hir_expr_kind_name(const Compiler_HIR_Expr_Kind kind) noexcept
Returns a stable debug name for an HIR expression kind.
@ Binary
dst <- op(lhs, rhs)
@ Return
Return one register value.
@ Call
dst <- callee(args...)
@ String
String literal payload.
@ Character
Character literal payload.
@ Invalid
Uninitialized register/slot or explicit invalid placeholder.
Source_Span compiler_hir_merge_spans(const Source_Span &lhs, const Source_Span &rhs) noexcept
Merges two spans without depending on the parser-oriented AST layer.
const char * compiler_operator_name(const Compiler_Operator_Kind kind) noexcept
Returns a stable debug name for one operator kind.
@ While
Loop while a condition is true.
@ If
Conditional execution.
@ Continue
Skip to the next iteration of the innermost loop.
@ Let
Variable declaration and optional initialization.
@ Block
Scoped sequence of statements.
@ Break
Immediate exit from the innermost loop.
std::string compiler_dump_hir_function(const Compiler_HIR_Function *function, const Compiler_Type_Context &types)
Dumps one HIR function in a deterministic text format.
and
Check uniqueness with explicit hash + equality functors.
Compiler_HIR_Constant_Kind
Kinds of HIR constants.
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:105
size_t Compiler_Type_Id
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_HIR_Expr_Kind
Kinds of HIR expressions.
std::string compiler_dump_hir_expr(const Compiler_HIR_Expr *expr, const Compiler_Type_Context &types)
Dumps one HIR expression in a deterministic text format.
Field< int > Integer
Definition ahField.H:136
const char * compiler_hir_constant_kind_name(const Compiler_HIR_Constant_Kind kind) noexcept
Returns a stable debug name for an HIR constant kind.
Compiler_HIR_Stmt_Kind
Kinds of HIR statements.
static std::atomic< bool > init
Definition hash-fct.C:54
std::string compiler_dump_hir_stmt(const Compiler_HIR_Stmt *stmt, const Compiler_Type_Context &types)
Dumps one HIR statement in a deterministic text format.
Compiler_Operator_Kind
Stable operator kinds shared by reusable compiler layers.
STL namespace.
Compiler_HIR_Expr * left
Left operand.
Source_Span operator_span
Span of the operator token.
Compiler_Operator_Kind op
Binary operator kind.
Compiler_HIR_Expr * right
Right operand.
Compiler_HIR_Binary_Expr(Compiler_HIR_Expr *lhs=nullptr, const Compiler_Operator_Kind k=Compiler_Operator_Kind::Invalid, const Compiler_Type_Id ty=0, const Source_Span &op_sp={}, Compiler_HIR_Expr *rhs=nullptr) noexcept
Structured block statement.
Source_Span rbrace_span
Span of ‘’}'`.
Compiler_HIR_Block_Stmt(const Source_Span &lbrace={}, const Source_Span &rbrace={}) noexcept
DynArray< Compiler_HIR_Stmt * > statements
Nested statements.
Source_Span lbrace_span
Span of ‘’{'`.
Compiler_HIR_Break_Stmt(const Source_Span &sp={}) noexcept
Typed function call expression.
Compiler_HIR_Expr * callee
Called expression.
Compiler_HIR_Call_Expr(Compiler_HIR_Expr *func=nullptr, const Compiler_Type_Id ty=0, const Source_Span &lparen={}, const Source_Span &rparen={}) noexcept
DynArray< Compiler_HIR_Expr * > arguments
Call arguments.
Source_Span rparen_span
Span of ‘’)'`.
Source_Span lparen_span
Span of ‘’('`.
bool bool_value
Decoded boolean value for Bool constants.
std::string text
Original or normalized constant spelling.
Compiler_HIR_Constant_Kind constant_kind
Constant category.
Compiler_HIR_Constant_Expr(const Compiler_HIR_Constant_Kind k=Compiler_HIR_Constant_Kind::Unit, const Compiler_Type_Id ty=0, std::string value="", const Source_Span &sp={}, const bool b=false) noexcept
Compiler_HIR_Continue_Stmt(const Source_Span &sp={}) noexcept
Expression statement in HIR.
Compiler_HIR_Eval_Stmt(Compiler_HIR_Expr *value=nullptr, const Source_Span &sp={}) noexcept
Compiler_HIR_Expr * expr
Evaluated expression.
Base class for HIR expressions.
Compiler_HIR_Expr(const Compiler_HIR_Expr_Kind k=Compiler_HIR_Expr_Kind::Invalid, const Compiler_Type_Id ty=0, const Source_Span &sp={}) noexcept
Compiler_HIR_Expr_Kind kind
Runtime node kind.
Compiler_Type_Id type_id
Inferred or resolved type.
std::string name
Function name.
DynArray< Compiler_HIR_Param > parameters
Parameters in declaration order.
Compiler_Type_Id type_id
Full function type.
Compiler_HIR_Function(std::string value="", const Compiler_Type_Id ty=0, const Source_Span &name_sp={}, Compiler_HIR_Block_Stmt *block=nullptr, const Source_Span &sp={}) noexcept
Compiler_HIR_Block_Stmt * body
Function body.
Source_Span name_span
Span of the function name.
Structured conditional statement.
Compiler_HIR_If_Stmt(Compiler_HIR_Expr *cond=nullptr, Compiler_HIR_Stmt *then_stmt=nullptr, Compiler_HIR_Stmt *else_stmt=nullptr, const Source_Span &if_sp={}, const Source_Span &else_sp={}) noexcept
Compiler_HIR_Stmt * then_branch
True branch.
Source_Span if_span
Span of if.
Source_Span else_span
Span of else, if present.
Compiler_HIR_Stmt * else_branch
Optional false branch.
Compiler_HIR_Expr * condition
Condition expression.
Invalid HIR expression placeholder.
Compiler_HIR_Invalid_Expr(const Compiler_Type_Id ty=0, const Source_Span &sp={}) noexcept
Invalid HIR statement placeholder.
Compiler_HIR_Invalid_Stmt(const Source_Span &sp={}) noexcept
Typed lexical binding statement.
Compiler_Type_Id binding_type
Inferred binding type.
Compiler_HIR_Expr * initializer
Optional initializer.
Source_Span name_span
Span of the binding name.
std::string name
Bound identifier.
Compiler_HIR_Let_Stmt(std::string value="", const Compiler_Type_Id ty=0, const Source_Span &name_sp={}, Compiler_HIR_Expr *init=nullptr, const Source_Span &sp={}) noexcept
Compiler_HIR_Module(const Source_Span &sp={}) noexcept
DynArray< Compiler_HIR_Function * > functions
Lowered top-level functions.
DynArray< Compiler_HIR_Stmt * > statements
Lowered top-level statements.
Base node carrying a source span.
Source_Span span
Source region associated with the HIR node.
Compiler_HIR_Node(const Source_Span &sp={}) noexcept
Parameter metadata for one HIR function.
Source_Span span
Parameter source span.
Compiler_Type_Id type_id
Inferred or declared parameter type.
std::string name
Parameter name.
Compiler_HIR_Return_Stmt(Compiler_HIR_Expr *expr=nullptr, const Source_Span &sp={}) noexcept
Compiler_HIR_Expr * value
Returned value, or nullptr.
Base class for HIR statements.
Compiler_HIR_Stmt(const Compiler_HIR_Stmt_Kind k=Compiler_HIR_Stmt_Kind::Invalid, const Source_Span &sp={}) noexcept
Compiler_HIR_Stmt_Kind kind
Runtime node kind.
Compiler_HIR_Expr * operand
Operand expression.
Compiler_HIR_Unary_Expr(const Compiler_Operator_Kind k=Compiler_Operator_Kind::Invalid, const Compiler_Type_Id ty=0, const Source_Span &op_sp={}, Compiler_HIR_Expr *expr=nullptr) noexcept
Compiler_Operator_Kind op
Unary operator kind.
Source_Span operator_span
Span of the operator token.
Typed variable reference expression.
Source_Span name_span
Span of the original identifier.
Compiler_HIR_Variable_Expr(std::string value="", const Compiler_Type_Id ty=0, const Source_Span &sp={}) noexcept
std::string name
Variable or function name.
Structured while-loop statement.
Compiler_HIR_While_Stmt(Compiler_HIR_Expr *cond=nullptr, Compiler_HIR_Stmt *stmt=nullptr, const Source_Span &kw={}) noexcept
Compiler_HIR_Stmt * body
Loop body.
Source_Span keyword_span
Span of while.
Compiler_HIR_Expr * condition
Loop condition.
Half-open byte range inside a source file.
Definition ah-source.H:100
Source_File_Id file_id
Stable file identifier; 0 means invalid.
Definition ah-source.H:101
static int * k
Lazy and scalable dynamic array implementation.