diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index bde521997b2e5106181ba3f188786982d15f7c09..f628e7c21f64a040f7dea4b0fe7c027f60cb40bc 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -160,6 +160,32 @@ impl ProtocolDescription { }); } + /// Again a somewhat temporary method. Can be used by components to look up + /// the definition of a particular procedure. Intended use is to find the + /// DefinitionId/TypeId of builtin components. + pub(crate) fn find_procedure(&self, module_name: &[u8], proc_name: &[u8]) -> Option<(ProcedureDefinitionId, TypeId)> { + // Lookup type definition in module + let root_id = self.lookup_module_root(module_name)?; + let module = &self.heap[root_id]; + let definition_id = module.get_definition_by_ident(&self.heap, proc_name)?; + let definition = &self.heap[definition_id]; + + // Make sure the procedure is not polymorphic + if !definition.poly_vars().is_empty() { + return None; + } + if !definition.is_procedure() { + return None; + } + + // Lookup in type table + let definition = definition.as_procedure(); + let type_parts = [ConcreteTypePart::Component(definition.this, 0)]; + let type_id = self.types.get_monomorph_type_id(&definition.this.upcast(), &type_parts) + .expect("type ID for non-polymorphic procedure"); + return Some((definition.this, type_id)); + } + fn lookup_module_root(&self, module_name: &[u8]) -> Option { for module in self.modules.iter() { match &module.name {