MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / invoke

Method invoke

aiscript-vm/src/vm/state.rs:1388–1547  ·  view source on GitHub ↗
(
        &mut self,
        name: InternedString<'gc>,
        args_count: u8,
        keyword_args_count: u8,
    )

Source from the content-addressed store, hash-verified

1386 }
1387
1388 fn invoke(
1389 &mut self,
1390 name: InternedString<'gc>,
1391 args_count: u8,
1392 keyword_args_count: u8,
1393 ) -> Result<(), VmError> {
1394 let args_slot_count = (args_count + keyword_args_count * 2) as usize;
1395 let receiver = *self.peek(args_slot_count);
1396 match receiver {
1397 Value::String(_) | Value::IoString(_) => {
1398 let mut args = Vec::new();
1399
1400 // Collect arguments
1401 for _ in 0..args_count {
1402 args.push(self.pop_stack());
1403 }
1404 args.reverse(); // Restore argument order
1405
1406 // Pop the receiver and keyword args
1407 self.stack_top -= keyword_args_count as usize * 2 + 1;
1408
1409 // Dispatch to string method
1410 let result = self
1411 .builtin_methods
1412 .invoke_string_method(self.mc, name, receiver, args)?;
1413 self.push_stack(result);
1414 Ok(())
1415 }
1416 Value::List(_) => {
1417 // Array method handling
1418 let mut args = Vec::new();
1419
1420 // Collect arguments
1421 for _ in 0..args_count {
1422 args.push(self.pop_stack());
1423 }
1424 args.reverse(); // Restore argument order
1425
1426 // Pop the receiver and keyword args
1427 self.stack_top -= keyword_args_count as usize * 2 + 1;
1428
1429 // Dispatch to array method
1430 let result = self
1431 .builtin_methods
1432 .invoke_array_method(self.mc, name, receiver, args)?;
1433 self.push_stack(result);
1434 Ok(())
1435 }
1436 Value::Class(class) => {
1437 if let Some(value) = class.borrow().static_methods.get(&name) {
1438 self.call_value(*value, args_count, keyword_args_count)
1439 } else {
1440 Err(self.runtime_error(
1441 format!(
1442 "Undefined static method '{}' of class '{}'.",
1443 name,
1444 class.borrow().name,
1445 )

Callers 1

dispatch_nextMethod · 0.80

Calls 14

run_agentFunction · 0.85
pushMethod · 0.80
pop_stackMethod · 0.80
invoke_string_methodMethod · 0.80
push_stackMethod · 0.80
invoke_array_methodMethod · 0.80
call_valueMethod · 0.80
runtime_errorMethod · 0.80
invoke_from_classMethod · 0.80
get_exportMethod · 0.80
check_argsMethod · 0.80
peekMethod · 0.45

Tested by

no test coverage detected