Skip to content
Browse files

Very minimal implementation of the 'soft' pragma, but enough that we'…

…ll be able to use it to make wrap.t happy.
  • Loading branch information...
1 parent 57697e2 commit 3bfb7a68d6652911baf98d4061865e3888a0e35e @jnthn jnthn committed Aug 4, 2012
Showing with 35 additions and 3 deletions.
  1. +9 −3 src/Perl6/Actions.pm
  2. +7 −0 src/Perl6/Grammar.pm
  3. +1 −0 src/Perl6/Optimizer.pm
  4. +18 −0 src/core/Routine.pm
View
12 src/Perl6/Actions.pm
@@ -1877,9 +1877,15 @@ class Perl6::Actions is HLL::Actions {
if $t.ast { $*W.ex-handle($t, { ($t.ast)($code) }) }
}
- # Add inlining information if it's inlinable.
+ # Add inlining information if it's inlinable; also mark soft if the
+ # appropriate pragma is in effect.
if $<deflongname> {
- self.add_inlining_info_if_possible($/, $code, $block, @params);
+ if $*SOFT {
+ $*W.find_symbol(['&infix:<does>'])($code, $*W.find_symbol(['SoftRoutine']));
+ }
+ else {
+ self.add_inlining_info_if_possible($/, $code, $block, @params);
+ }
}
my $closure := block_closure(reference_to_code_object($code, $past));
@@ -1958,7 +1964,7 @@ class Perl6::Actions is HLL::Actions {
nqp::die("Routines using pseudo-stashes are not inlinable");
}
else {
- return $node;
+ return $node.node ?? clear_node(clone_qast($node)) !! $node;
}
}
View
7 src/Perl6/Grammar.pm
@@ -427,6 +427,7 @@ grammar Perl6::Grammar is HLL::Grammar {
:my $*ALLOW_CODE := 0; # pod stuff
:my $*POD_IN_FORMATTINGCODE := 0; # pod stuff
:my $*IN_REGEX_ASSERTION := 0;
+ :my $*SOFT := 0; # is the soft pragma in effect
# Various interesting scopes we'd like to keep to hand.
:my $*GLOBALish;
@@ -759,6 +760,12 @@ grammar Perl6::Grammar is HLL::Grammar {
$*MONKEY_TYPING := 1;
$longname := "";
}
+ elsif $longname.Str eq 'soft' {
+ # This is an approximation; need to pay attention to argument
+ # list really.
+ $*SOFT := 1;
+ $longname := "";
+ }
elsif $longname.Str eq 'FORBID_PIR' ||
$longname.Str eq 'Devel::Trace' ||
$longname.Str eq 'fatal' {
View
1 src/Perl6/Optimizer.pm
@@ -503,6 +503,7 @@ class Perl6::Optimizer {
if $call.named -> $name {
$inlined.named($name);
}
+
$inlined
}
View
18 src/core/Routine.pm
@@ -1,5 +1,12 @@
my class X::Routine::Unwrap { ... }
+my role HardRoutine {
+ method soft() { False }
+}
+my role SoftRoutine {
+ method soft() { True }
+}
+
my class Routine {
method of() { self.signature.returns }
method returns() { self.signature.returns }
@@ -48,6 +55,10 @@ my class Routine {
$perl
}
+ method soft() {
+ Mu
+ }
+
method wrap(&wrapper) {
my class WrapHandle {
has $!dispatcher;
@@ -75,6 +86,13 @@ my class Routine {
}
}
+ # We can't wrap a hardened routine (that is, one that's been
+ # marked inlinable).
+ if nqp::istype(self, HardRoutine) {
+ die "Cannot wrap a HardRoutine, since it may have been inlined; " ~
+ "use the 'soft' pragma to avoid marking routines has hard.";
+ }
+
# If we're not wrapped already, do the initial dispatcher
# creation.
unless nqp::istype(self, Wrapped) {

0 comments on commit 3bfb7a6

Please sign in to comment.
Something went wrong with that request. Please try again.