|
| 1 | +#?if moar |
| 2 | +nqp::dispatch('boot-syscall', 'dispatcher-register', 'nqp-meth-call', -> $capture { |
| 3 | + # Try to find the method; complain if there's none found. |
| 4 | + my $obj := nqp::captureposarg($capture, 0); |
| 5 | + my str $name := nqp::captureposarg_s($capture, 1); |
| 6 | + my $meth := $obj.HOW.find_method($obj, $name); |
| 7 | + unless nqp::isconcrete($meth) { |
| 8 | + nqp::die("Method '$name' not found for invocant of class '{$obj.HOW.name($obj)}'"); |
| 9 | + } |
| 10 | + |
| 11 | + # Establish a guard on the invocant type and method name (however the name |
| 12 | + # may well be a literal, in which case this is free). |
| 13 | + nqp::dispatch('boot-syscall', 'dispatcher-guard-type', |
| 14 | + nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 0)); |
| 15 | + nqp::dispatch('boot-syscall', 'dispatcher-guard-literal', |
| 16 | + nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 1)); |
| 17 | + |
| 18 | + # Drop the first two arguments, which are the decontainerized invocant |
| 19 | + # and the method name. Then insert the resolved method and delegate to |
| 20 | + # nqp-call to invoke it. |
| 21 | + my $args := nqp::dispatch('boot-syscall', 'dispatcher-drop-arg', |
| 22 | + nqp::dispatch('boot-syscall', 'dispatcher-drop-arg', $capture, 0), |
| 23 | + 0); |
| 24 | + my $delegate := nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-obj', |
| 25 | + $args, 0, $meth); |
| 26 | + nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'nqp-call', $delegate); |
| 27 | +}); |
| 28 | + |
| 29 | +nqp::dispatch('boot-syscall', 'dispatcher-register', 'nqp-call', -> $capture { |
| 30 | + # Guard on the type of the callee. |
| 31 | + my $track-callee := nqp::dispatch('boot-syscall', 'dispatcher-track-arg', $capture, 0); |
| 32 | + nqp::dispatch('boot-syscall', 'dispatcher-guard-type', $track-callee); |
| 33 | + |
| 34 | + # Go by callee type to decide how to invoke it. |
| 35 | + my $callee := nqp::captureposarg($capture, 0); |
| 36 | + if nqp::istype($callee, NQPRoutine) { |
| 37 | + # Routine, maybe multi. |
| 38 | + # TODO multi |
| 39 | + my $track-do := nqp::dispatch('boot-syscall', 'dispatcher-track-attr', |
| 40 | + $track-callee, NQPRoutine, '$!do'); |
| 41 | + my $args := nqp::dispatch('boot-syscall', 'dispatcher-drop-arg', $capture, 0); |
| 42 | + my $delegate := nqp::dispatch('boot-syscall', 'dispatcher-insert-arg', |
| 43 | + $args, 0, $track-do); |
| 44 | + nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-code-constant', |
| 45 | + $delegate); |
| 46 | + } |
| 47 | + elsif nqp::istype($callee, NQPRegex) { |
| 48 | + # Regex, just unwrap the code handle and delegate. |
| 49 | + my $track-do := nqp::dispatch('boot-syscall', 'dispatcher-track-attr', |
| 50 | + $track-callee, NQPRegex, '$!do'); |
| 51 | + my $args := nqp::dispatch('boot-syscall', 'dispatcher-drop-arg', $capture, 0); |
| 52 | + my $delegate := nqp::dispatch('boot-syscall', 'dispatcher-insert-arg', |
| 53 | + $args, 0, $track-do); |
| 54 | + nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-code-constant', |
| 55 | + $delegate); |
| 56 | + } |
| 57 | + elsif nqp::iscoderef($callee) { |
| 58 | + # VM-level code handle. |
| 59 | + nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-code-constant', |
| 60 | + $capture); |
| 61 | + } |
| 62 | + else { |
| 63 | + nqp::die("Cannot invoke object of type '{$callee.HOW.name($callee)}'"); |
| 64 | + } |
| 65 | +}); |
| 66 | +#?endif |
0 commit comments