36#include <gtest/gtest.h>
50 "import \"math.aw\";\n"
51 "let answer = add(40, 2);\n"});
60TEST(CompilerGenericDriver, RunsProgramThroughReusableFrontendContract)
66 Compiler_Driver_Action::Run));
71 " add = Function(add)\n"
72 " answer = Int(42)\n");
75 ASSERT_NE(hir,
nullptr);
76 EXPECT_NE(hir->text.find(
"HIRModule"), std::string::npos);
78 ASSERT_NE(order,
nullptr);
79 EXPECT_EQ(order->text,
83 const auto * surface = driver.
find_artifact(
"modules.surface");
84 ASSERT_NE(surface,
nullptr);
85 EXPECT_NE(surface->text.find(
"Module(main.aw)"), std::string::npos);
86 EXPECT_NE(surface->text.find(
"Module(math.aw)"), std::string::npos);
87 EXPECT_NE(surface->text.find(
"Function(add)"), std::string::npos);
88 EXPECT_NE(surface->text.find(
"Global(answer)"), std::string::npos);
89 const auto * linkage = driver.
find_artifact(
"modules.linkage");
90 ASSERT_NE(linkage,
nullptr);
91 EXPECT_NE(linkage->text.find(
"ModuleLinkage"), std::string::npos);
92 EXPECT_NE(linkage->text.find(
"Module(main.aw) order=1"), std::string::npos);
93 EXPECT_NE(linkage->text.find(
"Visible(Function(add)) from math.aw imported"),
95 EXPECT_NE(linkage->text.find(
"Visible(Global(answer)) from main.aw local"),
97 const auto * binding = driver.
find_artifact(
"modules.binding");
98 ASSERT_NE(binding,
nullptr);
99 EXPECT_NE(binding->text.find(
"ModuleBindings"), std::string::npos);
100 EXPECT_NE(binding->text.find(
"Bind(Function(add)) -> math.aw imported"),
102 EXPECT_NE(binding->text.find(
"Bind(Global(answer)) -> main.aw local"),
105 ASSERT_NE(names,
nullptr);
106 EXPECT_NE(names->text.find(
"ModuleNameTable"), std::string::npos);
107 EXPECT_NE(names->text.find(
"Name(Function(add)) -> math.aw imported"),
109 const auto * semantic = driver.
find_artifact(
"modules.semantic");
110 ASSERT_NE(semantic,
nullptr);
111 EXPECT_NE(semantic->text.find(
"ModuleSemanticEnvironment"), std::string::npos);
112 EXPECT_NE(semantic->text.find(
"Value(Function(add)) -> math.aw imported"),
121TEST(CompilerGenericDriver, EmitsBytecodeAndPortableCThroughReusableFrontendContract)
127 Compiler_Driver_Action::Emit_Bytecode));
130 const auto * bytecode = bytecode_driver.
find_artifact(
"bytecode");
131 ASSERT_NE(bytecode,
nullptr);
132 EXPECT_NE(bytecode->text.find(
"BytecodeModule"), std::string::npos);
137 options.c_backend_options.emit_main =
true;
141 Compiler_Driver_Action::Emit_C));
145 ASSERT_NE(c_artifact,
nullptr);
146 EXPECT_NE(c_artifact->text.find(
"main(void)"), std::string::npos);
147 EXPECT_NE(c_artifact->text.find(
"generic_driver_demo"), std::string::npos);
150TEST(CompilerGenericDriver, ReportsRuntimeFailuresThroughDriverMessages)
154 "let crash = 1 / 0;\n"});
159 EXPECT_FALSE(driver.
execute_sources(inputs, Compiler_Driver_Action::Run));
165 const auto * messages = driver.
find_artifact(
"driver.messages");
166 ASSERT_NE(messages,
nullptr);
167 EXPECT_NE(messages->text.find(
"run: HIR runtime execution failed: RUN007 division by zero"),
Reusable pipeline driver that operates on any Compiler_Frontend.
Reference frontend adapter that exposes the existing MVP language through Compiler_Frontend.
Reusable orchestration object built on top of Compiler_Frontend.
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.
const Compiler_Driver_Artifact * find_artifact(std::string_view label) const noexcept
Finds one artifact by exact label.
const Compiler_Bytecode_Module * bytecode_module() const noexcept
Returns the lowered bytecode module from the last run, when available.
const Compiler_C_Backend_Emission & c_emission() const noexcept
Returns the C emission payload from the last emit-c action.
const Compiler_Driver_Run_Output & run_output() const noexcept
Returns the run summary from the last run action.
Compiler_Frontend implementation backed by the current MVP language stack.
const DynArray< Compiler_Module_Descriptor > & module_descriptors() const noexcept override
Returns parsed module descriptors for reusable import orchestration.
const Compiler_Driver_Artifact * find_artifact(std::string_view label) const noexcept override
Finds one frontend artifact by exact label.
const DynArray< size_t > & module_merge_order() const noexcept override
Returns the dependency-first merge order from the last parse.
const DynArray< Compiler_Module_Metadata > & module_metadata() const noexcept override
Returns reusable metadata for the top-level surface of each module.
size_t size() const noexcept
Return the current dimension of array.
T & append()
Allocate a new entry to the end of array.
Main namespace for Aleph-w library functions.
static struct argp_option options[]
bool valid
Whether emission completed successfully.
std::string module_name
Prefix used to derive stable C identifiers.
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.
Configuration shared by all runs of Compiler_Generic_Driver.
Compiler_C_Backend_Options c_backend_options
Backend-C emission options used by emit-c.
Interpreter_Runtime_Error error
Structured runtime failure when flow == Runtime_Error.
bool ok() const noexcept
Returns whether this result represents a runtime failure.
std::string code
Stable runtime code such as RUN004.