diff --git a/src/protocol/eval/executor.rs b/src/protocol/eval/executor.rs index ac845a93c1640ab5270a557c106b806c13b5618b..9bda8f7069a6e45e9f51dcb19b4f8757f94517f2 100644 --- a/src/protocol/eval/executor.rs +++ b/src/protocol/eval/executor.rs @@ -27,7 +27,7 @@ pub(crate) enum ExprInstruction { #[derive(Debug, Clone)] pub(crate) struct Frame { pub(crate) definition: DefinitionId, - pub(crate) monomorph_idx: i32, + pub(crate) monomorph_type_id: TypeId, pub(crate) position: StatementId, pub(crate) expr_stack: VecDeque, // hack for expression evaluation, evaluated by popping from back pub(crate) expr_values: VecDeque, // hack for expression results, evaluated by popping from front/back @@ -36,7 +36,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: DefinitionId, monomorph_idx: i32) -> Self { + pub fn new(heap: &Heap, definition_id: DefinitionId, monomorph_type_id: TypeId) -> Self { let definition = &heap[definition_id]; let (outer_scope_id, first_statement_id) = match definition { Definition::Component(definition) => (definition.scope, definition.body), @@ -64,7 +64,7 @@ impl Frame { Frame{ definition: definition_id, - monomorph_idx, + monomorph_type_id, position: first_statement_id.upcast(), expr_stack: VecDeque::with_capacity(128), expr_values: VecDeque::with_capacity(128), @@ -211,7 +211,7 @@ pub enum EvalContinuation { // Returned only in non-sync mode ComponentTerminated, SyncBlockStart, - NewComponent(DefinitionId, i32, ValueGroup), + NewComponent(DefinitionId, TypeId, ValueGroup), NewChannel, } @@ -224,14 +224,14 @@ pub struct Prompt { } impl Prompt { - pub fn new(_types: &TypeTable, heap: &Heap, def: DefinitionId, monomorph_idx: i32, args: ValueGroup) -> Self { + pub fn new(_types: &TypeTable, heap: &Heap, def: DefinitionId, 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, monomorph_idx); + let new_frame = Frame::new(heap, def, type_id); let max_stack_size = new_frame.max_stack_size; prompt.frames.push(new_frame); args.into_store(&mut prompt.store); @@ -479,7 +479,7 @@ impl Prompt { }, Expression::Select(expr) => { let subject= cur_frame.expr_values.pop_back().unwrap(); - let mono_data = types.get_procedure_monomorph(cur_frame.monomorph_idx); + let mono_data = types.get_procedure_monomorph(cur_frame.monomorph_type_id); let field_idx = mono_data.expr_data[expr.unique_id_in_definition as usize].field_or_monomorph_idx as u32; // Note: same as above: clone if value lives on expr stack, simply @@ -527,7 +527,7 @@ impl Prompt { } Literal::Integer(lit_value) => { use ConcreteTypePart as CTP; - let def_types = types.get_procedure_monomorph(cur_frame.monomorph_idx); + let def_types = types.get_procedure_monomorph(cur_frame.monomorph_type_id); let concrete_type = &def_types.expr_data[expr.unique_id_in_definition as usize].expr_type; debug_assert_eq!(concrete_type.parts.len(), 1); @@ -575,7 +575,7 @@ impl Prompt { cur_frame.expr_values.push_back(value); }, Expression::Cast(expr) => { - let mono_data = types.get_procedure_monomorph(cur_frame.monomorph_idx); + let mono_data = types.get_procedure_monomorph(cur_frame.monomorph_type_id); let output_type = &mono_data.expr_data[expr.unique_id_in_definition as usize].expr_type; // Typechecking reduced this to two cases: either we @@ -766,11 +766,11 @@ impl Prompt { } // Determine the monomorph index of the function we're calling - let mono_data = types.get_procedure_monomorph(cur_frame.monomorph_idx); + let mono_data = types.get_procedure_monomorph(cur_frame.monomorph_type_id); let call_data = &mono_data.expr_data[expr.unique_id_in_definition as usize]; // Push the new frame and reserve its stack size - let new_frame = Frame::new(heap, expr.definition, call_data.field_or_monomorph_idx); + let new_frame = Frame::new(heap, expr.definition, call_data.type_id); let new_stack_size = new_frame.max_stack_size; self.frames.push(new_frame); self.store.cur_stack_boundary = new_stack_boundary; @@ -834,13 +834,13 @@ impl Prompt { Statement::Local(stmt) => { match stmt { LocalStatement::Memory(stmt) => { - if cfg!(debug_assertions) { + dbg_code!({ let variable = &heap[stmt.variable]; debug_assert!(match self.store.read_ref(ValueId::Stack(variable.unique_id_in_scope as u32)) { Value::Unassigned => false, _ => true, }); - } + }); cur_frame.position = stmt.next; Ok(EvalContinuation::Stepping) @@ -1030,7 +1030,7 @@ impl Prompt { "mismatch in expr stack size and number of arguments for new statement" ); - let mono_data = types.get_procedure_monomorph(cur_frame.monomorph_idx); + let mono_data = types.get_procedure_monomorph(cur_frame.monomorph_type_id); let expr_data = &mono_data.expr_data[call_expr.unique_id_in_definition as usize]; // Note that due to expression value evaluation they exist in @@ -1052,7 +1052,7 @@ impl Prompt { cur_frame.position = stmt.next; - Ok(EvalContinuation::NewComponent(call_expr.definition, expr_data.field_or_monomorph_idx, argument_group)) + Ok(EvalContinuation::NewComponent(call_expr.definition, expr_data.type_id, argument_group)) }, Statement::Expression(stmt) => { // The expression has just been completely evaluated. Some