Permalink
Browse files

Fix $/ lookup more properly.

  • Loading branch information...
1 parent f81a127 commit 383409d0644c15b0c47dcf314c8a006e04899f2a @jnthn jnthn committed Mar 13, 2013
Showing with 34 additions and 5 deletions.
  1. +5 −5 src/core/Regex.pm
  2. +29 −0 src/ops/perl6.ops
View
@@ -1,13 +1,13 @@
my class Regex {
multi method ACCEPTS(Regex:D \SELF: Mu \topic) {
- my $dollar_slash := pir::find_dynamic_lex_relative__PPs(
+ my $dollar_slash := pir::find_caller_lex_relative__PPs(
nqp::ctxcaller(nqp::ctxcaller(nqp::ctx())),
'$/');
$dollar_slash = SELF.(Cursor."!cursor_init"(topic, :c(0))).MATCH_SAVE;
}
multi method ACCEPTS(Regex:D \SELF: @a) {
- my $dollar_slash := pir::find_dynamic_lex_relative__PPs(
+ my $dollar_slash := pir::find_caller_lex_relative__PPs(
nqp::ctxcaller(nqp::ctxcaller(nqp::ctx())),
'$/');
for @a {
@@ -17,7 +17,7 @@ my class Regex {
Nil;
}
multi method ACCEPTS(Regex:D \SELF: %h) {
- my $dollar_slash := pir::find_dynamic_lex_relative__PPs(
+ my $dollar_slash := pir::find_caller_lex_relative__PPs(
nqp::ctxcaller(nqp::ctxcaller(nqp::ctx())),
'$/');
for %h.keys {
@@ -28,10 +28,10 @@ my class Regex {
}
multi method Bool(Regex:D:) {
- my $dollar_slash := pir::find_dynamic_lex_relative__PPs(
+ my $dollar_slash := pir::find_caller_lex_relative__PPs(
nqp::ctxcaller(nqp::ctxcaller(nqp::ctx())),
'$/');
- my $dollar_underscore := pir::find_dynamic_lex_relative__PPs(
+ my $dollar_underscore := pir::find_caller_lex_relative__PPs(
nqp::ctxcaller(nqp::ctxcaller(nqp::ctx())),
'$_');
$dollar_slash = $dollar_underscore.match(self);
View
@@ -2120,6 +2120,35 @@ inline op find_dynamic_lex_relative(out PMC, in PMC, in STR) :base_core {
}
/*
+
+=item find_caller_lex_relative(out PMC, in PMC, in STR)
+
+Finds the lexical named $3 relative to scope $2, following the caller
+chain but also seraching the outer chain for each caller. Places it in $1.
+Places a NULL PMC in $1 if it is not found.
+
+=cut
+
+*/
+inline op find_caller_lex_relative(out PMC, in PMC, in STR) :base_core {
+ STRING * const lex_name = $3;
+ PMC * ctx = $2;
+ PMC * result = PMCNULL;
+
+ for (; !PMC_IS_NULL(ctx) && PMC_IS_NULL(result);
+ ctx = Parrot_pcc_get_caller_ctx(interp, ctx))
+ {
+ PMC * const lex_pad = sub_find_pad(interp, lex_name, ctx);
+ if (!PMC_IS_NULL(lex_pad)) {
+ result = VTABLE_get_pmc_keyed_str(interp, lex_pad, lex_name);
+ }
+ if (!result)
+ result = PMCNULL;
+ }
+ $1 = result;
+}
+
+/*
* Local variables:
* c-file-style: "parrot"
* End:

0 comments on commit 383409d

Please sign in to comment.