summaryrefslogtreecommitdiff
path: root/op.c
Commit message (Collapse)AuthorAgeFilesLines
* mark blockhooks API as experimentalZefram2010-12-131-1/+1
|
* [perl #68658] attributes turn "state" into "my"Father Chrysostomos2010-12-081-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This is for two reasons: • In S_my_kid, the attribute-handling code comes before the code that marks the padop as being a state instead of a my, which it knows to do based on the value of PL_parser->in_my. The attribute-handling code begins by setting PL_parser->in_my to FALSE, preventing the code that follows from doing its job. So now PL_parser->in_my is read at the top of S_my_kid, before the attribute code, with the statehood recorded in a boolean. Then the code that marks the padop as being state checks that boolean instead of in_my. • A lexical variable declaration that has an attribute and is assigned to in the same expression compiles to something similar to: (attributes->import(... \$x ...), my $x) = 3; where the list is actually in scalar context, returning the my $x which is then assigned to (something that cannot be expressed directly in Perl syntax). So Perl_ck_sassign needs to take that list op into account when creating the ‘once’ op that actually makes state assignment work. Up till now it was just looking for a padsv on its LHS. This commit makes it check also for a list op whose last item is a padsv.
* Avoid setting PL_cv_has_eval unnecessarilyFather Chrysostomos2010-12-071-1/+1
| | | | | | | | | | Quoting op.c: /* /$x/ may cause an eval, since $x might be qr/(?{..})/ */ But the (?{..})’s compilation is only ever reached in the scope of ‘use re 'eval'’, so we can avoid setting PL_cv_has_eval (and the slight overhead that entails) when that pragma is off.
* [perl #77762] Constant assignment warningFather Chrysostomos2010-11-301-1/+2
| | | | | | | | | | | | With this patch: $ ./perl -we 'sub A () {1}; if (0) {my $foo = A or die}' $ ./perl -we 'sub A () {1}; if (0) {my $foo = 1 or die}' Found = in conditional, should be == at -e line 1. Since the value of a constant may not be known at the time the program is written, it should be perfectly acceptable to do a constant assign- ment in a conditional.
* [perl #63540] bizarre closure lossageFather Chrysostomos2010-11-291-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | main::b in this example shows a null op that has the if() statement attached to it. $ perl -MO=Concise,a,b -e 'my $x;sub a {$x}; sub b{if($x){}0}' main::a: 3 <1> leavesub[1 ref] K/REFC,1 ->(end) - <@> lineseq KP ->3 1 <;> nextstate(main 2 -e:1) v ->2 2 <0> padsv[$x:FAKE:] ->3 main::b: a <1> leavesub[1 ref] K/REFC,1 ->(end) - <@> lineseq KP ->a 4 <;> nextstate(main 5 -e:1) v ->5 - <1> null vK/1 ->8 6 <|> and(other->7) vK/1 ->8 5 <0> padsv[$x:FAKE:] s ->6 - <@> scope vK ->- 7 <0> stub v ->8 8 <;> nextstate(main 5 -e:1) v ->9 9 <$> const[IV 0] s ->a -e syntax OK Perl_op_const_sv has: if (type == OP_NEXTSTATE || type == OP_NULL || type == OP_PUSHMARK) continue; It traverses from the null to the const. The const’s op_next pointer points to the leavesub, so it is taken to be a constant. It returns to newATTRSUB, which turns on CvCONST without assigning a constant value. Later, cv_clone (called by pp_anoncode) calls op_const_sv again. The latter returns the SV from the first PADSV it finds, which is the $x in if($x). This commit stops op_const_sv from skipping over null ops that have children.
* [perl #79178] STORE/FETCH of tie()d hash get stringified keyFather Chrysostomos2010-11-271-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | This bug has been present in non-threaded builds for a long time. Change 38bb37b9aa introduced it to threaded builds. $hash{...} makes its operand a shared-PV scalar if it is an OP_CONST. But \"foo" is also an OP_CONST, as is anything generated with use constant. This is the sort of thing that results: $ perl5.8.5 -MO=Concise -e '$a{\"foo"}' 7 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 6 <2> helem vK/2 ->7 4 <1> rv2hv sKR/1 ->5 3 <$> gv(*a) s ->4 5 <$> const(PVIV "SCALAR(0x81b378)") s ->6 -e syntax OK (My 5.8.5 installation is non-threaded.) See the "SCALAR(0x81b378)" in there? So this commit skips that optimisation if the key is ROK or if it is a PVMG or higher.
* [perl #78908] Reinstate mod for one more stable releaseFather Chrysostomos2010-11-261-0/+8
|
* Clarify op_lvalue’s docsFather Chrysostomos2010-11-261-4/+8
| | | | as requested by Reini Urban [perl #78908]
* [perl #78810] PERLDB_NOOPT ignored by adjacent nextstate optimisationFather Chrysostomos2010-11-261-1/+1
| | | | | As mentioned in the RT ticket, ac56e7d did not take PERLDB_NOOPT into account.
* Make BEGIN {require 5.12.0} behave as documented.Nicholas Clark2010-11-251-1/+24
| | | | | | Previously in a BEGIN block, require was behaving identically to use 5.12.0 - ie erroneously executing the use feature ':5.12.0'; and use strict; use warnings behaviour, which only use was documented to provide.
* Refactor newATTRSUB()'s logic for grafting a sub definition to an existing stubNicholas Clark2010-11-181-5/+20
| | | | | | | | | | | Previously it was using cv_undef() to (partially) free the target CV (the pre-existing stub), before donating it the padlist and outside pointers from the source CV (the definition, just compiled), and then freeing up the remains of the source CV. Instead, explicitly exchange padlist and outside pointers, explicitly assign other fields that need changing (file and stash), and assert that various CvFLAGS are as we expect them.
* Convert newSUB() to a macro wrapping Perl_newATTRSUB()Nicholas Clark2010-11-171-6/+0
| | | | | Provide a Perl_newSUB() function in mathoms.c for anyone referencing it by its full name.
* Move Perl_cv_undef() from op.c to pad.cNicholas Clark2010-11-161-68/+0
| | | | This will allow the non-API function Perl_pad_undef to be inlined into it.
* Zero new XOPs xop_desc will never be invalidFlorian Ragwitz2010-11-151-1/+1
| | | | Even if the xop description couldn't be fetched from PL_custom_op_descs.
* Document the new custom op functions.Ben Morrow2010-11-141-0/+15
|
* Improve custom OP support.Ben Morrow2010-11-141-29/+63
| | | | | | | | | | | | | | | | | Change the custom op registrations from two separate hashes to one hash holding structure pointers, and add API functions to register ops and look them up. This will make it easier to add new properties of custom ops in the future. Copy entries across from the old hashes where necessary, to preserve compatibility. Add two new properties, in addition to the already-existing 'name' and 'description': 'class' and 'peep'. 'class' is one of the OA_*OP constants, and allows B and other introspection mechanisms to work with custom ops that aren't BASEOPs. 'peep' is a pointer to a function that will be called for ops of this type from Perl_rpeep. Adjust B.xs to take account of the new properties, and also to give custom ops their registered name rather than simply 'custom'.
* y///rFather Chrysostomos2010-11-021-9/+24
|
* Don’t capitalise words in the middle of an error messageFather Chrysostomos2010-11-021-1/+1
|
* Allow push/pop/keys/etc to act on referencesDavid Golden2010-10-311-14/+71
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | All built-in functions that operate directly on array or hash containers now also accept hard references to arrays or hashes: |----------------------------+---------------------------| | Traditional syntax | Terse syntax | |----------------------------+---------------------------| | push @$arrayref, @stuff | push $arrayref, @stuff | | unshift @$arrayref, @stuff | unshift $arrayref, @stuff | | pop @$arrayref | pop $arrayref | | shift @$arrayref | shift $arrayref | | splice @$arrayref, 0, 2 | splice $arrayref, 0, 2 | | keys %$hashref | keys $hashref | | keys @$arrayref | keys $arrayref | | values %$hashref | values $hashref | | values @$arrayref | values $arrayref | | ($k,$v) = each %$hashref | ($k,$v) = each $hashref | | ($k,$v) = each @$arrayref | ($k,$v) = each $arrayref | |----------------------------+---------------------------| This allows these built-in functions to act on long dereferencing chains or on the return value of subroutines without needing to wrap them in C<@{}> or C<%{}>: push @{$obj->tags}, $new_tag; # old way push $obj->tags, $new_tag; # new way for ( keys %{$hoh->{genres}{artists}} ) {...} # old way for ( keys $hoh->{genres}{artists} ) {...} # new way For C<push>, C<unshift> and C<splice>, the reference will auto-vivify if it is not defined, just as if it were wrapped with C<@{}>. Calling C<keys> or C<values> directly on a reference gives a substantial performance improvement over explicit dereferencing. For C<keys>, C<values>, C<each>, when overloaded dereferencing is present, the overloaded dereference is used instead of dereferencing the underlying reftype. Warnings are issued about assumptions made in the following three ambiguous cases: (a) If both %{} and @{} overloading exists, %{} is used (b) If %{} overloading exists on a blessed arrayref, %{} is used (c) If @{} overloading exists on a blessed hashref, @{} is used
* Don't fold constants in sprintf() if locales are usedNiko Tyni2010-10-271-0/+1
| | | | | Commit c427f4d2d4575fbc8a5190932fe321136c7597b3 in 5.10.1 made sprintf() ignore LC_NUMERIC for numeric constants.
* new API functions op_scope and op_lvalueZefram2010-10-261-45/+63
| | | | | | The function scope() goes into the API as op_scope(), and mod() goes into the API as op_lvalue(). Both marked experimental, because their behaviour is a little quirky and not trivially dequirkable.
* add CvSTASH_set() macro and make CvSTASH() rvalue onlyZefram2010-10-251-5/+1
| | | | | | Now that CvSTASH requires backreference bookkeeping, stop people from directly assigning to it (by using CvSTASH() as an lvalue), and instead force them to use CvSTASH_set().
* stop passing line numbers into op constructor functionsZefram2010-10-251-11/+8
| | | | | | | | | Remove the line number parameter from newWHILEOP() and newFOROP() functions. Instead, the line number for the impending COP is set by parser code after constructing the ops. (In fact the parser was doing this anyway in most cases.) This brings newWHILEOP() and newFOROP() in line with the other op constructors, in that they do not concern themselves with COPs.
* refactor and regularise label/statement grammarZefram2010-10-251-8/+4
| | | | | | | | | | | | | | | | | | | | Refactoring of the grammar around statements. New production <barestmt> encompasses a statement without label. It includes all statement types, including declarations, with no unnecessary intermediate non-terminals. It generates an op tree for the statement's content, with no leading state op. The <fullstmt> production has just one rule, consisting of optional label followed by <barestmt>. It puts a state op on the front of the statement's content ops. To support the regular statement op structure, the op sequence for for(;;) loops no longer has a second state op between the initialisation and the loop. Instead, the unstack op type is slightly adapted to achieve the stack clearing without a state op. The newFOROP() constructor function no longer generates a state op, that now being the job of the <fullstmt> production. Consequently it no longer takes a parameter stating what label is to go in the state op. This brings it in line with the other op constructors.
* [perl #77810] Scalars vs globsFather Chrysostomos2010-10-241-0/+2
| | | | | | | | | | Stop *{} from returning globs with the SVf_FAKE flag on. It removes three tests from t/op/gv.t (that I added) that test buggy edge cases that can no longer occur. It also modifies tests in t/io/defout.t to keep them passing. I am not sure that test script serves any purpose any more.
* Add single-term prototypeDavid Golden2010-10-211-0/+12
| | | | | | | | | | | | | | | | The C<+> prototype is a special alternative to C<$> that will act like C<\[@%]> when given a literal array or hash variable, but will otherwise force scalar context on the argument. This is useful for functions which should accept either a literal array or an array reference as the argument: sub smartpush (+@) { my $aref = shift; die "Not an array or arrayref" unless ref $aref eq 'ARRAY'; push @$aref, @_; } When using the C<+> prototype, your function must check that the argument is of an acceptable type.
* full API for cop hint hashesZefram2010-10-211-11/+6
| | | | | | | | | | | | | Expose cop hint hashes as a type COPHH, with a cophh_* API which is a macro layer over the refcounted_he_* API. The documentation for cophh_* describes purely API-visible behaviour, whereas the refcounted_he_* documentation describes the functions mainly in terms of the implementation. Revise the cop_hints_* API, using the flags parameter consistently and reimplementing in terms of cophh_*. Use the cophh_* and cop_hints_* functions consistently where appropriate. [Modified by the committer to update two calls to Perl_refcounted_he_fetch recently added to newPMOP.]
* [perl #78072] use re '/xism';Father Chrysostomos2010-10-211-0/+13
|
* add lex_start to the APIZefram2010-10-211-1/+1
| | | | | lex_start() is added to the API, marked experimental, and documented. It also gains a flags parameter for foreseeable future use.
* remove filter inheritance option from lex_startZefram2010-10-211-1/+1
| | | | | | | | The only uses of lex_start that had the new_filter parameter false, to make the new lexer context share source filters with the previous lexer context, were uses with rsfp null, which therefore never invoked source filters. Inheriting source filters from a logically unrelated file seems like a silly idea anyway.
* fix indentation for prototype switch statementsDavid Golden2010-10-191-148/+148
|
* Add LINKLIST to the API.Ben Morrow2010-10-121-10/+21
| | | | | Also rename the underlying function to op_linklist, to match the other API op functions.
* APIify op list constructorsZefram2010-10-121-56/+99
| | | | | | Put into the API op_append_elem, op_prepend_elem, and op_append_list. All renamed from op_-less internal names. Parameter types for op_append_list changed to match the rest of the op API and avoid some casting.
* Remove some excess cleverness from the Bhk macros.Ben Morrow2010-10-101-3/+3
| | | | | | | | | Allowing BhkENTRY(bhk, start) to look up the bhk_start member defeats much of the point of having a bhk_ prefix in the first place: if a member is added later called (say) 'bhk_die', any invocation of BhkENTRY(bhk, die) will expand to BhkENTRY(bhk, Perl_die) because of the API macros. Requiring BhkENTRY(bhk, bhk_start), while tedious, is much safer.
* plugin mechanism to rewrite calls to a subroutineZefram2010-10-101-245/+533
| | | | | | | | | | | | | | | | | | | | | | | | New magic type PERL_MAGIC_checkcall attaches a function to a CV, which will be called as the second half of the op checker for an entersub op calling that CV. Default state, in the absence of this magic, is to process the CV's prototype if it has one, or apply list context to all the arguments if not. New API functions cv_get_call_checker() and cv_set_call_checker() provide a clean interface to this facility, hiding the internal use of magic. Expose in the API the new functions rv2cv_op_cv(), ck_entersub_args_list(), ck_entersub_args_proto(), and ck_entersub_args_proto_or_list(), which are meaningful segments of standard entersub op checking and are likely to be useful in plugged-in call checker functions. Expose new API function op_contextualize(), which is a public interface to the internal scalar()/list()/scalarvoid() functions. This API is likely to be required in most plugged-in call checker functions. Incidentally add new function mg_free_type(), in the API, which will remove magic of one type from an SV. (mg_free() removes all magic, and there isn't anything else more selective.)
* Remove MEMBER_TO_FPTR.Ben Morrow2010-10-061-3/+3
| | | | This is left over from PERL_OBJECT (see beeff2, 16c915, and so on).
* Move OP prototypes from pp_proto.h to proto.hNicholas Clark2010-09-271-0/+2
| | | | | | | | | | | | Make embed.pl fully responsible for generating prototypes and embedding macros for pp_* and ck_* functions, placing them in embed.h and proto.h opcode.pl no longer generates pp_proto.h Remove the (effectively) duplicate explicit entries for (all but 2) ck_* functions from embed.fnc We can't actually remove pp_proto.h from the distribution *yet*, as ExtUtils::MM_Unix and ExtUtils::MM_VMS have hardcoded lists of the installed headers. Once this is resolved, we can.
* Add /d, /l, /u (infixed) regex modifiersKarl Williamson2010-09-221-1/+5
| | | | | | | | | | | | This patch adds recognition of these modifiers, with appropriate action for d and l. u does nothing useful yet. This allows for the interpolation of a regex into another one without losing the character set semantics that it was compiled with, as for the first time, the semantics is now specified in the stringification as one of these modifiers. To this end, it allocates an unused bit in the structures. The off- sets change so as to not disturb other bits.
* [perl #20444] regex not evaluated in constant ?:Father Chrysostomos2010-09-201-3/+13
| | | | | | | | | | | | $text =~ ( 1 ? /phoo/ : /bear/) used to be constant-folded to $text =~ /phoo/ This patch solves the problem by marking match and subst ops as OPf_SPECIAL during constant folding, so the =~ operator can tell not to take possession of it.
* add hv_copy_hints_hv and save_hints to the APIZefram2010-09-161-1/+1
|
* In Perl_ck_subr(), no need to create/set o3 in the !proto block.Nicholas Clark2010-09-141-5/+2
| | | | | A good optimising compiler can already spot this, but removing dead code makes it easier for the humans.
* In Perl_ck_subr, remove delete_op, unused since assertions were removed.Nicholas Clark2010-09-131-10/+0
| | | | | The implementation of assertions was (mostly) removed in 584420f022db5722. It turns out that b1233c72f2dabb53 didn't remove the last vestige of it.
* In Perl_ck_subr(), move to once place all setting of bits in o->op_private.Nicholas Clark2010-09-131-3/+5
| | | | | | The later conditional setting of HINT_STRICT_REFS and of OPpENTERSUB_DB are unaffected by any code triggered by cvop->op_type. Moving them together lets the C compiler produce better code.
* In Perl_ck_subr(), consolidate all the prototype code in one if block.Nicholas Clark2010-09-131-10/+10
| | | | | This reveals that there is no need to set the variable prev when looping for the !proto case.
* In Perl_ck_subr(), hoist the if (proto) check outside of the while loop.Nicholas Clark2010-09-131-17/+37
| | | | | | Prototype checking is currently 165 lines of code. The rest of the while loop is 19, including comments. It's much easier to see how prototype checking fits into the structure this way, *and* it avoids a repeated if check inside a loop.
* fix a couple of -Dmad compiler warningsDavid Mitchell2010-09-121-4/+6
|
* Fix RT #77468: Smart matching on slicesDavid Leadbeater2010-09-071-0/+12
| | | | | | ref_array_or_hash did not take aslice or hslice OPs into account; wrap them in an anonlist so that smart matching has a reference as it expects.
* Refactor Perl_store_cop_label() to avoid exposing struct refcounted_he *.Nicholas Clark2010-09-011-2/+1
| | | | | | | Instead pass in a COP, as suggested by Ben Morrow. Also add length and flags parameters, and remove the comment suggesting this change. The underlying storage mechanism can honour length and UTF8/not, so there is no harm in exposing this one level higher.
* Peephole optimise adjacent pairs of nextstate ops.Nicholas Clark2010-08-271-1/+53
| | | | | | | | | | | | | | | | | | | | | Previously, in code such as use constant DEBUG=>0; sub GAK { warn if DEBUG; print "stuff\n"; } the ops for C<warn if DEBUG;> would be folded to a null op (ex-const), but the nextstate op would remain, resulting in a runtime op dispatch of nextstate, nextstate, ... The execution of a sequence of nexstate ops is indistinguishable from just the last nextstate op, so teach the peephole optimiser to eliminate the first of a pair of nextstate ops. (Except where the first carries a label, as labels mustn't be eliminated by the optimiser, and label usage isn't conclusively known at compile time.)
* make recursive part of peephole optimiser hookableZefram2010-08-261-9/+16
| | | | | | | | New variable PL_rpeepp makes it possible for extensions to hook the per-op-chain part of the peephole optimiser (which recurses into side chains). The existing variable PL_peepp still allows hooking the per-sub part of the peephole optimiser, maintaining perfect backward compatibility.