MCPcopy Create free account
hub / github.com/aspizu/goboscript / func

Method func

src/codegen/sb3.rs:986–1058  ·  view source on GitHub ↗
(&mut self, s: S, d: D, func: &Func, definition: &[Stmt])

Source from the content-addressed store, hash-verified

984 }
985
986 pub fn func(&mut self, s: S, d: D, func: &Func, definition: &[Stmt]) -> io::Result<()> {
987 let this_id = self.id.new_id();
988 let prototype_id = self.id.new_id();
989 let next_id = self.id.new_id();
990 self.begin_node(
991 Node::new("procedures_definition", this_id)
992 .some_next_id((!definition.is_empty()).then_some(next_id))
993 .top_level(true),
994 )?;
995 self.begin_inputs()?;
996 write!(self, r#""custom_block":[1,{prototype_id}]"#)?;
997 self.end_obj()?; // inputs
998 self.end_obj()?; // node
999 let mut qualified_args: Vec<(SmolStr, NodeID)> = Vec::new();
1000 for arg in &func.args {
1001 match &arg.type_ {
1002 Type::Value => {
1003 let arg_id = self.id.new_id();
1004 self.begin_node(
1005 Node::new("argument_reporter_string_number", arg_id)
1006 .parent_id(prototype_id)
1007 .shadow(true),
1008 )?;
1009 self.single_field("VALUE", &arg.name)?;
1010 self.end_obj()?; // node
1011 qualified_args.push((arg.name.clone(), arg_id));
1012 }
1013 Type::Struct {
1014 name: type_name,
1015 span: type_span,
1016 } => {
1017 let Some(struct_) = s.get_struct(type_name) else {
1018 d.report(
1019 DiagnosticKind::UnrecognizedStruct(type_name.clone()),
1020 type_span,
1021 );
1022 continue;
1023 };
1024 for field in &struct_.fields {
1025 let qualified_arg_name = qualify_struct_var_name(&field.name, &arg.name);
1026 let arg_id = self.id.new_id();
1027 self.begin_node(
1028 Node::new("argument_reporter_string_number", arg_id)
1029 .parent_id(prototype_id)
1030 .shadow(true),
1031 )?;
1032 self.single_field("VALUE", &qualified_arg_name)?;
1033 self.end_obj()?; // node
1034 qualified_args.push((qualified_arg_name, arg_id));
1035 }
1036 }
1037 }
1038 }
1039 self.begin_node(
1040 Node::new("procedures_prototype", prototype_id)
1041 .parent_id(this_id)
1042 .shadow(true),
1043 )?;

Callers 1

spriteMethod · 0.80

Calls 15

newFunction · 0.85
qualify_struct_var_nameFunction · 0.85
write_comma_ioFunction · 0.85
new_idMethod · 0.80
begin_nodeMethod · 0.80
top_levelMethod · 0.80
some_next_idMethod · 0.80
begin_inputsMethod · 0.80
end_objMethod · 0.80
shadowMethod · 0.80
parent_idMethod · 0.80
single_fieldMethod · 0.80

Tested by

no test coverage detected