diff --git a/src/protocol/eval/executor.rs b/src/protocol/eval/executor.rs index 9bda8f7069a6e45e9f51dcb19b4f8757f94517f2..0adc2ab8e4b87ff2b35cf6bea6f6286f39e49683 100644 --- a/src/protocol/eval/executor.rs +++ b/src/protocol/eval/executor.rs @@ -26,7 +26,7 @@ pub(crate) enum ExprInstruction { #[derive(Debug, Clone)] pub(crate) struct Frame { - pub(crate) definition: DefinitionId, + pub(crate) definition: ProcedureDefinitionId, pub(crate) monomorph_type_id: TypeId, pub(crate) position: StatementId, pub(crate) expr_stack: VecDeque, // hack for expression evaluation, evaluated by popping from back @@ -36,13 +36,10 @@ 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_type_id: TypeId) -> Self { + pub fn new(heap: &Heap, definition_id: ProcedureDefinitionId, 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), - Definition::Function(definition) => (definition.scope, definition.body), - _ => unreachable!("initializing frame with {:?} instead of a function/component", definition), - }; + let outer_scope_id = definition.scope; + let first_statement_id = definition.body; // Another not-so-pretty thing that has to be replaced somewhere in the // future... @@ -211,7 +208,7 @@ pub enum EvalContinuation { // Returned only in non-sync mode ComponentTerminated, SyncBlockStart, - NewComponent(DefinitionId, TypeId, ValueGroup), + NewComponent(ProcedureDefinitionId, TypeId, ValueGroup), NewChannel, } @@ -224,7 +221,7 @@ pub struct Prompt { } impl Prompt { - pub fn new(_types: &TypeTable, heap: &Heap, def: DefinitionId, 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(), @@ -291,7 +288,7 @@ impl Prompt { // Checking if we're at the end of execution let cur_frame = self.frames.last_mut().unwrap(); if cur_frame.position.is_invalid() { - if heap[cur_frame.definition].is_function() { + if heap[cur_frame.definition].kind == ProcedureKind::Function { todo!("End of function without return, return an evaluation error"); } return Ok(EvalContinuation::ComponentTerminated); @@ -745,10 +742,10 @@ impl Prompt { Method::UserComponent => { // This is actually handled by the evaluation // of the statement. - debug_assert_eq!(heap[expr.definition].parameters().len(), cur_frame.expr_values.len()); + 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::UserFunction => { + Method::UserProcedure => { // Push a new frame. Note that all expressions have // been pushed to the front, so they're in the order // of the definition. @@ -770,7 +767,7 @@ impl Prompt { 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.type_id); + let new_frame = Frame::new(heap, expr.procedure, 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; @@ -779,7 +776,7 @@ impl Prompt { // To simplify the logic a little bit we will now // return and ask our caller to call us again return Ok(EvalContinuation::Stepping); - }, + } } }, Expression::Variable(expr) => { @@ -977,7 +974,6 @@ impl Prompt { Ok(EvalContinuation::Stepping) }, Statement::Return(_stmt) => { - debug_assert!(heap[cur_frame.definition].is_function()); debug_assert_eq!(cur_frame.expr_values.len(), 1, "expected one expr value for return statement"); // The preceding frame has executed a call, so is expecting the @@ -1024,9 +1020,8 @@ impl Prompt { }, Statement::New(stmt) => { let call_expr = &heap[stmt.expression]; - debug_assert!(heap[call_expr.definition].is_component()); debug_assert_eq!( - cur_frame.expr_values.len(), heap[call_expr.definition].parameters().len(), + cur_frame.expr_values.len(), heap[call_expr.procedure].parameters.len(), "mismatch in expr stack size and number of arguments for new statement" ); @@ -1052,7 +1047,7 @@ impl Prompt { cur_frame.position = stmt.next; - Ok(EvalContinuation::NewComponent(call_expr.definition, expr_data.type_id, argument_group)) + Ok(EvalContinuation::NewComponent(call_expr.procedure, expr_data.type_id, argument_group)) }, Statement::Expression(stmt) => { // The expression has just been completely evaluated. Some