Declares a callable. If the callable is already defined, this ensures the new declaration matches the previous one and raises an error if not.
(
symtable: &mut LocalSymtable,
name: &VarRef,
name_pos: LineCol,
params: &[VarRef],
)
| 1083 | /// If the callable is already defined, this ensures the new declaration matches the previous one |
| 1084 | /// and raises an error if not. |
| 1085 | fn declare_callable( |
| 1086 | symtable: &mut LocalSymtable, |
| 1087 | name: &VarRef, |
| 1088 | name_pos: LineCol, |
| 1089 | params: &[VarRef], |
| 1090 | ) -> Result<()> { |
| 1091 | let mut syntax = vec![]; |
| 1092 | for (i, param) in params.iter().enumerate() { |
| 1093 | let sep = if i == params.len() - 1 { |
| 1094 | ArgSepSyntax::End |
| 1095 | } else { |
| 1096 | ArgSepSyntax::Exactly(ArgSep::Long) |
| 1097 | }; |
| 1098 | syntax.push(SingularArgSyntax::RequiredValue( |
| 1099 | RequiredValueSyntax { |
| 1100 | name: Cow::Owned(param.name.to_owned()), |
| 1101 | vtype: param.ref_type.unwrap_or(ExprType::Integer), |
| 1102 | }, |
| 1103 | sep, |
| 1104 | )); |
| 1105 | } |
| 1106 | |
| 1107 | let mut builder = CallableMetadataBuilder::new_dynamic(name.name.to_owned()) |
| 1108 | .with_dynamic_syntax(vec![(syntax, None)]); |
| 1109 | if let Some(ctype) = name.ref_type { |
| 1110 | builder = builder.with_return_type(ctype); |
| 1111 | } |
| 1112 | |
| 1113 | symtable.declare_user_callable(name, builder.build()).map_err(|e| Error::from_syms(e, name_pos)) |
| 1114 | } |
| 1115 | |
| 1116 | /// Compiles a single user-defined callable. |
| 1117 | fn compile_user_callable( |
no test coverage detected