diff --git a/src/protocol/parser/pass_definitions.rs b/src/protocol/parser/pass_definitions.rs index 6a97cc63dd144569b731a0250ff410a327728d4a..303d9ec425c5551f0e2a93ea8ba656fd2d27687a 100644 --- a/src/protocol/parser/pass_definitions.rs +++ b/src/protocol/parser/pass_definitions.rs @@ -284,8 +284,8 @@ impl PassDefinitions { let scope_id = ctx.heap.alloc_scope(|this| Scope::new(this, ScopeAssociation::Definition(definition_id))); // Assign everything in the preallocated AST node - let function = ctx.heap[definition_id].as_function_mut(); - function.return_type = parser_type; + let function = ctx.heap[definition_id].as_procedure_mut(); + function.return_type = Some(parser_type); function.parameters = parameters; function.scope = scope_id; function.body = body_id; @@ -321,7 +321,8 @@ impl PassDefinitions { let scope_id = ctx.heap.alloc_scope(|this| Scope::new(this, ScopeAssociation::Definition(definition_id))); // Assign everything in the AST node - let component = ctx.heap[definition_id].as_component_mut(); + let component = ctx.heap[definition_id].as_procedure_mut(); + debug_assert!(component.return_type.is_none()); component.parameters = parameters; component.scope = scope_id; component.body = body_id; @@ -758,7 +759,7 @@ impl PassDefinitions { if let Expression::Call(expression) = expression { // Allow both components and functions, as it makes more sense to // check their correct use in the validation and linking pass - if expression.method == Method::UserComponent || expression.method == Method::UserFunction { + if expression.method == Method::UserComponent || expression.method == Method::UserProcedure { call_id = expression.this; valid = true; } @@ -1576,28 +1577,11 @@ impl PassDefinitions { unique_id_in_definition: -1, }).upcast() }, - Definition::Component(_) => { - // Component instantiation - let func_span = parser_type.full_span; - let mut full_span = func_span; - let arguments = self.consume_expression_list( - module, iter, ctx, Some(&mut full_span.end) - )?; - - ctx.heap.alloc_call_expression(|this| CallExpression{ - this, func_span, full_span, - parser_type, - method: Method::UserComponent, - arguments, - definition: target_definition_id, - parent: ExpressionParent::None, - unique_id_in_definition: -1, - }).upcast() - }, - Definition::Function(function_definition) => { + Definition::Procedure(proc_def) => { // Check whether it is a builtin function - let method = if function_definition.builtin { - match function_definition.identifier.value.as_bytes() { + let procedure_id = proc_def.this; + let method = if proc_def.builtin { + match proc_def.identifier.value.as_bytes() { KW_FUNC_GET => Method::Get, KW_FUNC_PUT => Method::Put, KW_FUNC_FIRES => Method::Fires, @@ -1607,8 +1591,10 @@ impl PassDefinitions { KW_FUNC_PRINT => Method::Print, _ => unreachable!(), } + } else if proc_def.kind == ProcedureKind::Function { + Method::UserProcedure } else { - Method::UserFunction + Method::UserComponent }; // Function call: consume the arguments @@ -1620,7 +1606,7 @@ impl PassDefinitions { ctx.heap.alloc_call_expression(|this| CallExpression{ this, func_span, full_span, parser_type, method, arguments, - definition: target_definition_id, + procedure: procedure_id, parent: ExpressionParent::None, unique_id_in_definition: -1, }).upcast()