36#include <gtest/gtest.h>
54 const auto file_id =
sm.add_virtual_file(
"main.aw", source);
56 const auto *
module = parser.parse_module();
63 return lowering.lower_module(module);
72 if (arguments.
size() != 2)
74 error.code =
"HOST001";
75 error.message =
"pair expects exactly 2 arguments";
99 "let value = add(20, 22);\n",
100 sm, dx, ast_ctx, hir_ctx, typed);
111 " add = Function(add)\n"
112 " value = Int(42)\n");
117 const auto called =
runtime.call(
"add", arguments);
119 EXPECT_EQ(called.value.kind, Interpreter_Value_Kind::Integer);
120 EXPECT_EQ(called.value.integer_value, 12);
132 "fn countdown(n) {\n"
138 "let result = countdown(3);\n",
139 sm, dx, ast_ctx, hir_ctx, typed);
146 const auto * result =
runtime.global_environment().lookup(
"result");
161 const auto called =
runtime.call(
"pair", arguments);
163 EXPECT_EQ(called.value.kind, Interpreter_Value_Kind::Tuple);
164 ASSERT_EQ(called.value.tuple_elements().size(), 2u);
165 EXPECT_EQ(called.value.tuple_elements().access(0).integer_value, 1);
166 EXPECT_EQ(called.value.tuple_elements().access(1).integer_value, 2);
200 "let doomed = explode(5);\n",
201 sm, dx, ast_ctx, hir_ctx, typed);
Lowering from the current MVP typed AST into the reusable HIR model.
Recursive-descent parser for the compiler-support MVP grammar.
Reusable runtime and structured evaluator for HIR-based interpreters.
Arena-backed ownership context for AST nodes.
Arena-backed ownership context for HIR nodes.
Lowers the MVP typed AST into HIR.
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.
Diagnostic accumulator and renderer.
bool has_errors() const noexcept
Returns whether any error or fatal diagnostic was emitted.
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.
Structured runtime for executing typed HIR.
Stores source files and resolves offsets into human-readable data.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Main namespace for Aleph-w library functions.
void error(const char *file, int line, const char *format,...)
Print an error message with file and line info.
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.
Structured runtime error.
static Interpreter_Value make_tuple(const DynArray< Interpreter_Value > &elements)
Builds a tuple runtime value by copying elements.
long long integer_value
Payload for Int values.
Interpreter_Value_Kind kind
Active value kind.
static Interpreter_Value make_integer(const long long i)
Builds an integer runtime value.