This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
&CORE::foo() for nullary functions
authorFather Chrysostomos <sprout@cpan.org>
Wed, 17 Aug 2011 19:32:33 +0000 (12:32 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 18 Aug 2011 13:50:20 +0000 (06:50 -0700)
commit7fa5bd9b5ba9d950fb8f72ee787a1d83167753b8
treebeccb6e9ced69d5de10f575ef585abada67c8db8
parentdeb8a388bf9e4429400eaf01ad745964d9d291d2
&CORE::foo() for nullary functions

This commit makes nullary subs in the CORE package callable with
ampersand syntax and through references--except for wantarray, which
is more complicated and will have its own commit.

It does this by creating an op tree like this:

$ ./perl -Ilib -MO=Concise,CORE::times -e 'BEGIN{\&CORE::times}'
CORE::times:
3  <1> leavesub[1 ref] K/REFC,1 ->(end)
-     <@> lineseq K ->3
1        <$> coreargs(IV 310) v ->2
2        <0> tms ->3
-e syntax OK

The coreargs op checks to make sure there are no arguments, for now.
The 310 is the op number for times (OP_TMS).

There is no nextstate op, because we want to inherit hints from
the caller.

The __FILE__, __LINE__ and __PACKAGE__ directives are implemented
like this:

$ ./perl -Ilib -MO=Concise,CORE::__FILE__ -e 'BEGIN{\&CORE::__FILE__}'
CORE::__FILE__:
7  <1> leavesub[1 ref] K/REFC,1 ->(end)
-     <@> lineseq K ->7
1        <$> coreargs(PV "__FILE__") v ->2
6        <2> lslice K/2 ->7
-           <1> ex-list lK ->4
2              <0> pushmark s ->3
3              <$> const(IV 1) s ->4
-           <1> ex-list lK ->6
4              <0> pushmark s ->5
5              <0> caller[t1] l ->6
-e syntax OK

The lslice op and its children are equivalent to (caller)[1].
MANIFEST
gv.c
pp.c
t/op/coreinline.t
t/op/coresubs.t [new file with mode: 0644]