Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add NQP op for checking if a capture has nameds.
  • Loading branch information
jnthn committed Apr 27, 2013
1 parent 2883303 commit 176fa67
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/vm/parrot/QAST/Operations.nqp
Expand Up @@ -1078,8 +1078,9 @@ QAST::Operations.add_core_pirop_mapping('captureposarg', 'set', 'PQi');
QAST::Operations.add_core_pirop_mapping('captureposarg_i', 'set', 'IQi');
QAST::Operations.add_core_pirop_mapping('captureposarg_n', 'set', 'NQi');
QAST::Operations.add_core_pirop_mapping('captureposarg_s', 'set', 'SQi');
QAST::Operations.add_core_pirop_mapping('captureexistsnamed', 'exists', 'IQs');
QAST::Operations.add_core_pirop_mapping('captureposprimspec', 'captureposprimspec', 'IPi');
QAST::Operations.add_core_pirop_mapping('captureexistsnamed', 'exists', 'IQs');
QAST::Operations.add_core_pirop_mapping('capturehasnameds', 'nqp_capturehasnameds', 'IP');

# Multiple dispatch related.
QAST::Operations.add_core_op('invokewithcapture', -> $qastcomp, $op {
Expand Down
24 changes: 22 additions & 2 deletions src/vm/parrot/ops/nqp.ops
Expand Up @@ -3135,11 +3135,10 @@ in one will take.
=cut

*/
inline op nqp_setdispatcher(in PMC) :base_core {
inline op nqp_setdispatcher(invar PMC) :base_core {
current_dispatcher = $1;
}


/*

=item nqp_takedispatcher(in STR)
Expand All @@ -3157,3 +3156,24 @@ inline op nqp_takedispatcher(in STR) :base_core {
current_dispatcher = NULL;
}
}

/*

=item nqp_capturehasnameds(out INT, invar PMC)

Checks if the specified capture has any named arguments.

=cut

*/
inline op nqp_capturehasnameds(out INT, invar PMC) :base_core {
PMC *capture = $2;
if (capture->vtable->base_type == enum_class_CallContext) {
Hash *nameds;
GETATTR_CallContext_hash(interp, capture, nameds);
$1 = nameds && Parrot_hash_size(interp, nameds) ? 1 : 0;
}
else {
$1 = 0;
}
}

0 comments on commit 176fa67

Please sign in to comment.