feat(pbs): implement first-class functions and explicit captures
This commit is contained in:
@@ -40,6 +40,7 @@ fn main() {
|
||||
verify_pbs_fixtures(&root);
|
||||
verify_pbs_structured_fixtures(&root);
|
||||
verify_pbs_resource_refusals(&root);
|
||||
verify_pbs_closure_frames(&root);
|
||||
for name in [
|
||||
"minimal",
|
||||
"jump-end",
|
||||
@@ -542,7 +543,7 @@ fn verify_pbs_fixtures(root: &std::path::Path) {
|
||||
|
||||
fn verify_pbs_structured_fixtures(root: &std::path::Path) {
|
||||
use prometeu_vm::LogicalFrameEndingReason as End;
|
||||
let success = ["array-cycle", "array-nested", "optional-flow", "struct-contract", "service-contract",
|
||||
let success = ["closure-import", "closure-installed", "closure-groups", "closure-isolation", "closure-fields", "closure-functions", "closure-snapshot", "closure-objects", "closure-nested", "array-cycle", "array-nested", "optional-flow", "struct-contract", "service-contract",
|
||||
"optional-tuple", "tuple-storage", "optional-intrinsics", "optional-lazy", "array-context",
|
||||
"binding-scope", "overloads", "single-evaluation", "long-boundaries", "gc-roots", "native-groups", "contract-elements", "imports", "global-array", "installed-example", "return-overloads", "inferred-optional-tuple", "inline-integers"];
|
||||
for name in success.into_iter().chain(["negative-index", "past-end", "negative-length", "large-length"]) {
|
||||
@@ -587,7 +588,7 @@ fn verify_pbs_structured_fixtures(root: &std::path::Path) {
|
||||
|
||||
fn verify_pbs_resource_refusals(root: &std::path::Path) {
|
||||
use prometeu_vm::{LogicalFrameEndingReason as End, resource_budget::{RuntimeLimits, RuntimeResource}};
|
||||
for name in ["array-cycle", "tuple-storage", "struct-contract"] {
|
||||
for name in ["closure-objects", "array-cycle", "tuple-storage", "struct-contract"] {
|
||||
for resource in [RuntimeResource::GuestBytes, RuntimeResource::HandleSlots] {
|
||||
for limit in [0, 1, 2] {
|
||||
let bytes = std::fs::read(root.join(format!("pbs-structured-{name}.pbx"))).unwrap();
|
||||
@@ -610,3 +611,22 @@ fn verify_pbs_resource_refusals(root: &std::path::Path) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn verify_pbs_closure_frames(root: &std::path::Path) {
|
||||
use prometeu_vm::LogicalFrameEndingReason as End;
|
||||
let bytes = std::fs::read(root.join("closure-frame-lifecycle.pbx")).expect("mandatory closure frame fixture");
|
||||
let image = ValidatedProgramImage::load(&bytes, &mut LoadBudget::new(LoadLimits::default()), caps::NONE).unwrap();
|
||||
let mut vm = VirtualMachine::from_image(image, Default::default());
|
||||
for frame in 0..3 {
|
||||
vm.prepare_boot_call().unwrap();
|
||||
let report = vm.run_budget(2_000_000, &mut NoNative, &mut HostContext::new(None)).unwrap();
|
||||
assert!(matches!(report.reason, End::Halted | End::EndOfRom), "frame {frame}: {report:?}");
|
||||
assert!(vm.operand_stack_top(1).is_empty(), "frame root returns void");
|
||||
let snapshot = vm.resource_snapshot();
|
||||
assert!(snapshot.gc.collections >= frame + 1, "frame {frame}: {:?}", snapshot.gc);
|
||||
assert!(snapshot.gc.reclaimed >= (frame + 1) * 1200, "frame {frame}: {:?}", snapshot.gc);
|
||||
if frame == 0 { assert!(vm.heap().len() >= 3, "array, closure and capture survive root return"); }
|
||||
else { assert_eq!(vm.heap().len(), 1, "only the empty global array remains after closure release"); }
|
||||
}
|
||||
println!("PBS CLOSURE FRAME LIFECYCLE/RETENTION/GC PASS");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user