diff --git a/src/protocol/eval/executor.rs b/src/protocol/eval/executor.rs index a3ff4fdb1d881b97dd0aebbfe8115871e5a5f51c..913be03fa88e408a2ac4bc3b71832f87bfbfaf8d 100644 --- a/src/protocol/eval/executor.rs +++ b/src/protocol/eval/executor.rs @@ -37,7 +37,7 @@ pub(crate) struct Frame { impl Frame { /// Creates a new execution frame. Does not modify the stack in any way. - pub fn new(heap: &Heap, definition_id: ProcedureDefinitionId, monomorph_type_id: TypeId) -> Self { + pub fn new(heap: &Heap, definition_id: ProcedureDefinitionId, monomorph_type_id: TypeId, monomorph_index: u32) -> Self { let definition = &heap[definition_id]; let outer_scope_id = definition.scope; let first_statement_id = definition.body; @@ -63,6 +63,7 @@ impl Frame { Frame{ definition: definition_id, monomorph_type_id, + monomorph_index: monomorph_index as usize, position: first_statement_id.upcast(), expr_stack: VecDeque::with_capacity(128), expr_values: VecDeque::with_capacity(128), @@ -222,14 +223,15 @@ pub struct Prompt { } impl Prompt { - pub fn new(_types: &TypeTable, heap: &Heap, def: ProcedureDefinitionId, type_id: TypeId, args: ValueGroup) -> Self { + pub fn new(types: &TypeTable, heap: &Heap, def: ProcedureDefinitionId, type_id: TypeId, args: ValueGroup) -> Self { let mut prompt = Self{ frames: Vec::new(), store: Store::new(), }; // Maybe do typechecking in the future? - let new_frame = Frame::new(heap, def, type_id); + let monomorph_index = types.get_monomorph(type_id).variant.as_procedure().monomorph_index; + let new_frame = Frame::new(heap, def, type_id, monomorph_index); let max_stack_size = new_frame.max_stack_size; prompt.frames.push(new_frame); args.into_store(&mut prompt.store); @@ -767,10 +769,10 @@ impl Prompt { // Determine the monomorph index of the function we're calling let mono_data = &heap[cur_frame.definition].monomorphs[cur_frame.monomorph_index]; - let type_id = mono_data.expr_info[expr.type_index as usize].variant.as_procedure().0; + let (type_id, monomorph_index) = mono_data.expr_info[expr.type_index as usize].variant.as_procedure(); // Push the new frame and reserve its stack size - let new_frame = Frame::new(heap, expr.procedure, type_id); + let new_frame = Frame::new(heap, expr.procedure, type_id, monomorph_index); let new_stack_size = new_frame.max_stack_size; self.frames.push(new_frame); self.store.cur_stack_boundary = new_stack_boundary; @@ -1029,7 +1031,7 @@ impl Prompt { ); let mono_data = &heap[cur_frame.definition].monomorphs[cur_frame.monomorph_index]; - let type_id = mono_data.expr_info[expr.type_index as usize].variant.as_procedure().0; + let type_id = mono_data.expr_info[call_expr.type_index as usize].variant.as_procedure().0; // Note that due to expression value evaluation they exist in // reverse order on the stack.