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

Method call_value

aiscript-vm/src/vm/state.rs:1323–1369  ·  view source on GitHub ↗
(
        &mut self,
        callee: Value<'gc>,
        args_count: u8,
        keyword_args_count: u8,
    )

Source from the content-addressed store, hash-verified

1321 }
1322
1323 fn call_value(
1324 &mut self,
1325 callee: Value<'gc>,
1326 args_count: u8,
1327 keyword_args_count: u8,
1328 ) -> Result<(), VmError> {
1329 let args_slot_count = (args_count + keyword_args_count * 2) as usize;
1330 match callee {
1331 Value::BoundMethod(bound) => {
1332 // inserts the receiver into the new CallFrame's slot zero.
1333 // normally, the receiver is 'self' or 'super' keyword.
1334 /*
1335 Diagram for this: scone.topping("berries", "cream");
1336
1337 stackTop
1338 |
1339 <-- -1 --> <------ argCount ----> |
1340 0 1 2 3 v
1341 | | | |
1342 v v v v
1343 +----------+-----------+-----------+---
1344 | script |fn topping()| "berries" | "cream"
1345 +----------+-----------+-----------+---
1346 ^ ^
1347 | |
1348 +-------------------------------+
1349 topping Callframe
1350 */
1351 self.stack[self.stack_top - args_slot_count - 1] = bound.receiver;
1352 self.call(bound.method, args_count, keyword_args_count)
1353 }
1354 Value::Closure(closure) => self.call(closure, args_count, keyword_args_count),
1355 Value::NativeFunction(function) => {
1356 // Calculate total arguments slots (positional + keyword pairs)
1357 let total_args = args_count + keyword_args_count * 2;
1358 let args = self.pop_stack_n(total_args as usize);
1359 let result = function(self, args).map_err(|err| match err {
1360 VmError::CompileError => err,
1361 VmError::RuntimeError(message) => self.runtime_error(message.into()),
1362 })?;
1363 self.stack_top -= 1; // Remove the function
1364 self.push_stack(result);
1365 Ok(())
1366 }
1367 _ => Err(self.runtime_error("Can only call functions and classes.".into())),
1368 }
1369 }
1370
1371 fn invoke_from_class(
1372 &mut self,

Callers 3

dispatch_nextMethod · 0.80
invoke_from_classMethod · 0.80
invokeMethod · 0.80

Calls 4

pop_stack_nMethod · 0.80
runtime_errorMethod · 0.80
push_stackMethod · 0.80
callMethod · 0.45

Tested by

no test coverage detected