MCPcopy Index your code
hub / github.com/endbasic/endbasic / declare_callable

Function declare_callable

core/src/compiler/top.rs:1085–1114  ·  view source on GitHub ↗

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],
)

Source from the content-addressed store, hash-verified

1083/// If the callable is already defined, this ensures the new declaration matches the previous one
1084/// and raises an error if not.
1085fn 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.
1117fn compile_user_callable(

Callers 1

compile_stmtFunction · 0.85

Calls 8

iterMethod · 0.80
pushMethod · 0.80
with_dynamic_syntaxMethod · 0.80
with_return_typeMethod · 0.80
declare_user_callableMethod · 0.80
enumerateMethod · 0.45
lenMethod · 0.45
buildMethod · 0.45

Tested by

no test coverage detected