stdlib beginnings (heap alloc)

This commit is contained in:
2026-07-01 22:36:03 +02:00
parent 870f946b52
commit 78fb661d1a
5 changed files with 147 additions and 64 deletions
+34
View File
@@ -2062,6 +2062,40 @@ milestone_24_rejects_invalid_forms :: proc(t: ^testing.T) {
}
}
@(test)
milestone_25_heap_compiles_and_runs :: proc(t: ^testing.T) {
output := "/tmp/brolang-test-heap"
defer _ = os.remove(output)
status := compiler_core.compile_package("examples/programs/heap", output)
testing.expect_value(t, status, 0)
state := run_executable(output)
testing.expect_value(t, state.exit_code, 0)
}
@(test)
milestone_25_heap_emits_libc_alloc_declarations :: proc(t: ^testing.T) {
sources := source.init_store()
defer source.destroy_store(&sources)
diagnostics := source.init_store_diagnostics(&sources)
defer source.destroy_diagnostics(&diagnostics)
symbols := symbol.init_table()
defer symbol.destroy_table(&symbols)
ast_module, loaded := loader.load("examples/programs/heap", &sources, &diagnostics, &symbols)
defer ast.destroy_module(&ast_module)
testing.expect(t, loaded)
hir_module := checker.check(&ast_module, &diagnostics, &symbols)
defer hir.destroy_module(&hir_module)
ir_module := lower.lower(&hir_module)
defer ir.destroy_module(&ir_module)
llvm_text := llvm.emit(&ir_module, &diagnostics, &symbols)
defer delete(llvm_text)
testing.expect_value(t, len(diagnostics.items), 0)
testing.expect(t, strings.contains(llvm_text, "declare ptr @malloc(i64)"))
testing.expect(t, strings.contains(llvm_text, "declare void @free(ptr)"))
}
@(test)
control_flow_compiles_and_runs :: proc(t: ^testing.T) {
output := "/tmp/brolang-test-control-flow"