diff --git a/src/protocol/ast.rs b/src/protocol/ast.rs index e137985fa110c6e2cea9a0f83be7cedf79aef88d..3bcc0b525893c980586cd57246693feb65892865 100644 --- a/src/protocol/ast.rs +++ b/src/protocol/ast.rs @@ -242,7 +242,7 @@ pub struct Root { } impl Root { - pub fn get_definition_ident(&self, h: &Heap, id: &[u8]) -> Option { + pub fn get_definition_by_ident(&self, h: &Heap, id: &[u8]) -> Option { for &def in self.definitions.iter() { if h[def].identifier().value.as_bytes() == id { return Some(def); @@ -932,7 +932,6 @@ pub struct StructDefinition { pub this: StructDefinitionId, pub defined_in: RootId, // Symbol scanning - pub span: InputSpan, pub identifier: Identifier, pub poly_vars: Vec, // Parsing @@ -941,10 +940,10 @@ pub struct StructDefinition { impl StructDefinition { pub(crate) fn new_empty( - this: StructDefinitionId, defined_in: RootId, span: InputSpan, + this: StructDefinitionId, defined_in: RootId, identifier: Identifier, poly_vars: Vec ) -> Self { - Self{ this, defined_in, span, identifier, poly_vars, fields: Vec::new() } + Self{ this, defined_in, identifier, poly_vars, fields: Vec::new() } } } @@ -965,7 +964,6 @@ pub struct EnumDefinition { pub this: EnumDefinitionId, pub defined_in: RootId, // Symbol scanning - pub span: InputSpan, pub identifier: Identifier, pub poly_vars: Vec, // Parsing @@ -974,10 +972,10 @@ pub struct EnumDefinition { impl EnumDefinition { pub(crate) fn new_empty( - this: EnumDefinitionId, defined_in: RootId, span: InputSpan, + this: EnumDefinitionId, defined_in: RootId, identifier: Identifier, poly_vars: Vec ) -> Self { - Self{ this, defined_in, span, identifier, poly_vars, variants: Vec::new() } + Self{ this, defined_in, identifier, poly_vars, variants: Vec::new() } } } @@ -993,7 +991,6 @@ pub struct UnionDefinition { pub this: UnionDefinitionId, pub defined_in: RootId, // Phase 1: symbol scanning - pub span: InputSpan, pub identifier: Identifier, pub poly_vars: Vec, // Phase 2: parsing @@ -1002,10 +999,10 @@ pub struct UnionDefinition { impl UnionDefinition { pub(crate) fn new_empty( - this: UnionDefinitionId, defined_in: RootId, span: InputSpan, + this: UnionDefinitionId, defined_in: RootId, identifier: Identifier, poly_vars: Vec ) -> Self { - Self{ this, defined_in, span, identifier, poly_vars, variants: Vec::new() } + Self{ this, defined_in, identifier, poly_vars, variants: Vec::new() } } } @@ -1071,6 +1068,37 @@ impl ExpressionInfoVariant { } } +#[derive(Debug)] +pub enum ProcedureSource { + FuncUserDefined, + CompUserDefined, + // Builtin functions, available to user + FuncGet, + FuncPut, + FuncFires, + FuncCreate, + FuncLength, + FuncAssert, + FuncPrint, + // Buitlin functions, not available to user + FuncSelectStart, + FuncSelectRegisterCasePort, + FuncSelectWait, + // Builtin components, available to user + CompRandomU32, // TODO: Remove, temporary thing + CompTcpClient, +} + +impl ProcedureSource { + pub(crate) fn is_builtin(&self) -> bool { + match self { + ProcedureSource::FuncUserDefined | ProcedureSource::CompUserDefined => false, + _ => true, + } + } +} + + /// Generic storage for functions, primitive components and composite /// components. // Note that we will have function definitions for builtin functions as well. In @@ -1080,12 +1108,11 @@ pub struct ProcedureDefinition { pub this: ProcedureDefinitionId, pub defined_in: RootId, // Symbol scanning - pub builtin: bool, pub kind: ProcedureKind, - pub span: InputSpan, pub identifier: Identifier, pub poly_vars: Vec, // Parser + pub source: ProcedureSource, pub return_type: Option, // present on functions, not components pub parameters: Vec, pub scope: ScopeId, @@ -1096,14 +1123,13 @@ pub struct ProcedureDefinition { impl ProcedureDefinition { pub(crate) fn new_empty( - this: ProcedureDefinitionId, defined_in: RootId, span: InputSpan, + this: ProcedureDefinitionId, defined_in: RootId, kind: ProcedureKind, identifier: Identifier, poly_vars: Vec ) -> Self { Self { this, defined_in, - builtin: false, - span, kind, identifier, poly_vars, + source: ProcedureSource::FuncUserDefined, return_type: None, parameters: Vec::new(), scope: ScopeId::new_invalid(), @@ -1813,7 +1839,7 @@ pub struct CallExpression { #[derive(Debug, Clone, PartialEq, Eq)] pub enum Method { - // Builtin, accessible by programmer + // Builtin function, accessible by programmer Get, Put, Fires, @@ -1821,10 +1847,13 @@ pub enum Method { Length, Assert, Print, - // Builtin, not accessible by programmer + // Builtin function, not accessible by programmer SelectStart, // SelectStart(total_num_cases, total_num_ports) SelectRegisterCasePort, // SelectRegisterCasePort(case_index, port_index, port_id) SelectWait, // SelectWait() -> u32 + // Builtin component, + ComponentRandomU32, + ComponentTcpClient, // User-defined UserFunction, UserComponent, @@ -1835,6 +1864,7 @@ impl Method { use Method::*; match self { Get | Put | Fires | Create | Length | Assert | Print => true, + ComponentRandomU32 | ComponentTcpClient => true, _ => false, } } @@ -1866,6 +1896,7 @@ pub enum Literal { True, False, Character(char), + Bytestring(Vec), String(StringRef<'static>), Integer(LiteralInteger), Struct(LiteralStruct),