diff --git a/src/protocol/eval/executor.rs b/src/protocol/eval/executor.rs index 0adc2ab8e4b87ff2b35cf6bea6f6286f39e49683..a3ff4fdb1d881b97dd0aebbfe8115871e5a5f51c 100644 --- a/src/protocol/eval/executor.rs +++ b/src/protocol/eval/executor.rs @@ -28,6 +28,7 @@ pub(crate) enum ExprInstruction { pub(crate) struct Frame { pub(crate) definition: ProcedureDefinitionId, pub(crate) monomorph_type_id: TypeId, + pub(crate) monomorph_index: usize, 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 @@ -476,8 +477,8 @@ impl Prompt { }, Expression::Select(expr) => { let subject= cur_frame.expr_values.pop_back().unwrap(); - 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; + let mono_data = &heap[cur_frame.definition].monomorphs[cur_frame.monomorph_index]; + let field_idx = mono_data.expr_info[expr.type_index as usize].variant.as_select() as u32; // Note: same as above: clone if value lives on expr stack, simply // refer to it if it already lives on the stack/heap. @@ -524,8 +525,9 @@ impl Prompt { } Literal::Integer(lit_value) => { use ConcreteTypePart as CTP; - 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; + let mono_data = &heap[cur_frame.definition].monomorphs[cur_frame.monomorph_index]; + let type_id = mono_data.expr_info[expr.type_index as usize].type_id; + let concrete_type = &types.get_monomorph(type_id).concrete_type; debug_assert_eq!(concrete_type.parts.len(), 1); match concrete_type.parts[0] { @@ -572,14 +574,15 @@ impl Prompt { cur_frame.expr_values.push_back(value); }, Expression::Cast(expr) => { - 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; + let mono_data = &heap[cur_frame.definition].monomorphs[cur_frame.monomorph_index]; + let type_id = mono_data.expr_info[expr.type_index as usize].type_id; + let concrete_type = &types.get_monomorph(type_id).concrete_type; // Typechecking reduced this to two cases: either we // have casting noop (same types), or we're casting // between integer/bool/char types. let subject = cur_frame.expr_values.pop_back().unwrap(); - match apply_casting(&mut self.store, output_type, &subject) { + match apply_casting(&mut self.store, concrete_type, &subject) { Ok(value) => cur_frame.expr_values.push_back(value), Err(msg) => { return Err(EvalError::new_error_at_expr(self, modules, heap, expr.this.upcast(), msg)); @@ -745,7 +748,7 @@ impl Prompt { debug_assert_eq!(heap[expr.procedure].parameters.len(), cur_frame.expr_values.len()); debug_assert_eq!(heap[cur_frame.position].as_new().expression, expr.this) }, - Method::UserProcedure => { + Method::UserFunction => { // Push a new frame. Note that all expressions have // been pushed to the front, so they're in the order // of the definition. @@ -763,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_type_id); - let call_data = &mono_data.expr_data[expr.unique_id_in_definition as usize]; + 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; // Push the new frame and reserve its stack size - let new_frame = Frame::new(heap, expr.procedure, call_data.type_id); + let new_frame = Frame::new(heap, expr.procedure, type_id); let new_stack_size = new_frame.max_stack_size; self.frames.push(new_frame); self.store.cur_stack_boundary = new_stack_boundary; @@ -1025,8 +1028,8 @@ impl Prompt { "mismatch in expr stack size and number of arguments for new statement" ); - 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]; + 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; // Note that due to expression value evaluation they exist in // reverse order on the stack. @@ -1038,7 +1041,6 @@ impl Prompt { // Construct argument group, thereby copying heap regions let argument_group = ValueGroup::from_store(&self.store, &args); - // println!("Creating {} with\n{:#?}", heap[call_expr.definition].identifier().value.as_str(), argument_group); // Clear any heap regions for arg in &args { @@ -1047,7 +1049,7 @@ impl Prompt { cur_frame.position = stmt.next; - Ok(EvalContinuation::NewComponent(call_expr.procedure, expr_data.type_id, argument_group)) + Ok(EvalContinuation::NewComponent(call_expr.procedure, type_id, argument_group)) }, Statement::Expression(stmt) => { // The expression has just been completely evaluated. Some