module scheme // Enter an ordinary fixed-arity closure through its existing activation API. // Frame growth, control protocols and rejected calls retain the complete // dispatcher. The activation API owns reuse, allocation and lifetime rules. // Specialize by caller so sharing the source does not make the C optimizer // outline the hot dispatch entry when another bridge starts using it. @[direct_array_access; inline] fn (mut m Machine) enter_cached_closure[T](vm &VM, argc int, tail bool) bool { $if vile_native ? { // The optional backend must see this call before any VM shortcut. if !isnil(vm.native_execution_scope) { return false } } base := m.stack.len - argc - 1 callable := m.stack[base] if callable.tag != .procedure { return false } p := callable.procedure_pointer() if p.mode != .closure || voidptr(p.owner) != voidptr(vm.owner) { return false } function := p.function if isnil(function.code) || function.rest || !isnil(function.star) || function.goops_next_slot >= 0 || function.goops_needs_next || argc != function.params { return false } if vm.options.max_steps > 0 && m.steps >= vm.options.max_steps { return false } if m.goops_pending_next.tag != .unspecified { return false } if !tail && ((vm.options.max_frames > 0 && m.frames.len >= vm.options.max_frames) || m.frames.len == m.frames.cap) { return false } m.steps++ mut scope := m.activation_for(function, p.env, tail) for i in 0 .. function.params { scope.slots[i] = m.stack[base + 1 + i] } if !tail { m.append_reserved_frame(CallFrame{function: m.function, env: m.env, ip: m.ip, base: m.base}) m.base = base } m.truncate(if tail { m.base } else { base }) m.function = function m.env = scope m.ip = 0 $if T is PlainMachineLoop { // The ordinary closure transition already changes the machine registers. // Keep complete numeric-loop execution here, outside global-load dispatch. if argc == 2 && !isnil(function.integer_tail) { _ = m.fuse_integer_tail_loop(vm) } } return true }