()
| 1454 | return get_ten() + 20 |
| 1455 | } |
| 1456 | "#; |
| 1457 | |
| 1458 | let module_c = r#" |
| 1459 | external add_twenty: () -> i32 |
| 1460 | |
| 1461 | main: () -> i32 { |
| 1462 | return add_twenty() + 12 |
| 1463 | } |
| 1464 | "#; |
| 1465 | |
| 1466 | let a_result = pipeline.compile(module_a).expect("a compile"); |
| 1467 | let (_, a_tokens) = pipeline |
| 1468 | .compile_ir_to_assembly_with_tokens(&a_result.ir_program) |
| 1469 | .expect("valid IR layout"); |
| 1470 | let a_obj = pipeline.assemble_named("a", &a_tokens).expect("a assemble"); |
| 1471 | |
| 1472 | let b_result = pipeline.compile(module_b).expect("b compile"); |
| 1473 | let (_, b_tokens) = pipeline |
| 1474 | .compile_ir_to_assembly_with_tokens(&b_result.ir_program) |
| 1475 | .expect("valid IR layout"); |
| 1476 | let b_obj = pipeline.assemble_named("b", &b_tokens).expect("b assemble"); |
| 1477 | |
| 1478 | let c_result = pipeline.compile(module_c).expect("c compile"); |
| 1479 | let (_, c_tokens) = pipeline |
| 1480 | .compile_ir_to_assembly_with_tokens(&c_result.ir_program) |
| 1481 | .expect("valid IR layout"); |
| 1482 | let c_obj = pipeline.assemble_named("c", &c_tokens).expect("c assemble"); |
| 1483 | |
| 1484 | let mut modules: Vec<(&str, &AssembledOutput)> = |
| 1485 | stdlib_objs.iter().map(|(n, o)| (n.as_str(), o)).collect(); |
| 1486 | modules.push(("a", &a_obj)); |
| 1487 | modules.push(("b", &b_obj)); |
| 1488 | modules.push(("c", &c_obj)); |
| 1489 | let linked = pipeline |
| 1490 | .link_assembled_objects_named("chain", &modules) |
| 1491 | .expect("link"); |
| 1492 | |
| 1493 | let mut vm = VirtualMachine::new(&linked); |
| 1494 | let run = vm.run(5_000_000); |
| 1495 | let exit = match run.termination { |
| 1496 | RunOutcome::Halted(code) => Some(code), |
| 1497 | RunOutcome::TimedOut => None, |
| 1498 | RunOutcome::Fault(error) => panic!("VM fault: {error}"), |
| 1499 | }; |
| 1500 | // 10 + 20 + 12 = 42 |
| 1501 | assert_eq!(exit, Some(42), "3-module chain should return 42"); |
| 1502 | } |
| 1503 | |
| 1504 | /// A global declared `external` elsewhere must resolve to the same storage: |
| 1505 | /// B's direct write plus A's `bump` land in one cell (21 + 21 = 42). |
| 1506 | #[test] |
| 1507 | fn cross_module_external_global_shared_storage() { |
| 1508 | let mut pipeline = CompilationPipeline::new(); |
| 1509 | pipeline.set_write_artifacts(false); |
| 1510 | |
| 1511 | let stdlib_objs = |
| 1512 | CompilationPipeline::compile_stdlib_objects(TargetMode::Hosted).expect("stdlib compile"); |
nothing calls this directly
no test coverage detected