calculate_captures

Function calculate_captures 

Source
pub fn calculate_captures(
    body_effect: &Effect,
    call_effect: &Effect,
) -> Result<Vec<Type>, String>
Expand description

Calculate capture types for a closure

Given:

  • body_effect: what the quotation body needs (e.g., Int Int -- Int)
  • call_effect: what the call site will provide (e.g., Int -- Int)

Returns:

  • captures: types to capture from creation stack (e.g., [Int])

§Capture Ordering

Captures are returned bottom-to-top (deepest value first). This matches how push_closure pops from the stack:

Stack at creation: ( ...rest bottom top )
push_closure pops top-down: pop top, pop bottom
Stores as: env[0]=top, env[1]=bottom (reversed)
Closure function pushes: push env[0], push env[1]
Result: bottom is deeper, top is shallower (correct order)

§Errors

Returns an error if the call site provides more values than the body needs.