summaryrefslogtreecommitdiff
path: root/op.c
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* document several optree construction functionsZefram2010-08-231-2/+329
|
* Remove CALL_FPTR and CPERLscope.Ben Morrow2010-08-201-3/+3
| | | | | | | | | | | | | | | | These are left from PERL_OBJECT, which was an implementation of multiplicity using C++ objects. PERL_OBJECT was removed in 5.8, but the macros seem to have been cargo-culted all over the core (including in places where they would have been inappropriate originally). Since they now do exactly nothing, it's cleaner to remove them. I have left the definitions in perl.h, under #ifndef PERL_CORE, since some CPAN XS code uses them (also often incorrectly). I have also left STATIC alone, since it seems potentially more useful and is much more ingrained. The only appearance of these macros this patch doesn't touch is in Devel-PPPort, because that's a CPAN module.
* fix [perl #74118] $[ assignment not noisy enoughZefram2010-08-161-0/+1
| | | | | Warn about list assignment to $[, as in "($[)=1", in addition to scalar assignment such as "$[=1".
* Revert "Make the peep recurse via PL_peepp"Florian Ragwitz2010-08-161-19/+8
| | | | | | | | | | | | | This reverts commit 65bfe90c4b4ea5706a50067179e60d4e8de6807a. While it made a few of the things I wanted possible, a couple of other things one might need to do and I thought this change would enable don't actually work. Thanks Zefram for pointing out my mistake. Conflicts: ext/XS-APItest/APItest.xs op.c
* C89 doesn't allow static dynamic initialization of complete structsH.Merijn Brand2010-08-021-4/+6
| | | | Signed-off-by: H.Merijn Brand <h.m.brand@xs4all.nl>
* Make the peep recurse via PL_peeppFlorian Ragwitz2010-07-251-8/+17
| | | | | | | | | | | Also allows extensions, when delegating to Perl_peep, to specify what function it should use when recursing into a part of the op tree. The usecase for this are extensions like namespace::alias, which need to hook into the peep to do their thing. With this change they can stop copying the whole peep only to add tiny bits of new behaviour to it, allowing them to work easier on a large variety of perls, without having to maintain one peep which works on all of them (which is HARD!).
* [perl #76478] silence compiler warningDavid Mitchell2010-07-231-1/+1
| | | | | Intel's icc compiler is too clever for its own good. Silence a false positive 'may be used undefined' warning.
* add CvGV_set() macro and make CvGV() rvalue onlyDavid Mitchell2010-07-181-4/+4
| | | | | | Now that CvGV can sometimes be reference counted, stop people from directly assigning to it (by using CvGV as an lvalue), and instead force them to use CvGV_set()
* add CVf_CVGV_RC flagDavid Mitchell2010-07-181-2/+2
| | | | | | | | | | | | | after the recent commit 803f274831f937654d48f8cf0468521cbf8f5dff, the CvGV field is sometimes reference counted. Since it was intended that the reference counting would happen only for anonymous CVs, the CVf_ANON flag was co-opted to indicate whether RC was being used. This is not entirely robust; for example, sub __ANON__ {} is a non-anon sub which points to the same GV used by anon subs, which while itself doesn't directly break things, shows that the potential for breakage is there. So add a separate flag just to indicate the reference count status of the CvGV field.
* protect CvGV weakref with backrefDavid Mitchell2010-07-141-8/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Each CV usually has a pointer, CvGV(cv), back to the GV that corresponds to the CV's name (or to *foo::__ANON__ for anon CVs). This pointer wasn't reference counted, to avoid loops. This could leave it dangling if the GV is deleted. We fix this by: For named subs, adding backref magic to the GV, so that when the GV is freed, it can trigger processing the CV's CvGV field. This processing consists of: if it looks like the freeing of the GV is about to trigger freeing of the CV too, set it to NULL; otherwise make it point to *foo::__ANON__ (and set CvAONON(cv)). For anon subs, make CvGV a strong reference, i.e. increment the refcnt of *foo::__ANON__. This doesn't cause a loop, since in this case the __ANON__ glob doesn't point to the CV. This also avoids dangling pointers if someone does an explicit 'delete $foo::{__ANON__}'. Note that there was already some partial protection for CvGV with commit f1c32fec87699aee2eeb638f44135f21217d2127. This worked by anonymising any corresponding CV when freeing a stash or stash entry. This had two drawbacks. First it didn't fix CVs that were anonmous or that weren't currently pointed to by the GV (e.g. after local *foo), and second, it caused *all* CVs to get anonymised during cleanup, even the ones that would have been deleted shortly afterwards anyway. This commit effectively removes that former commit, while reusing a bit of the actual anonymising code.
* protect CvSTASH weakref with backrefsDavid Mitchell2010-07-141-0/+4
| | | | | | | | | | | | | | Each CV usually has a pointer, CvSTASH, back to the stash that it was complied in. This pointer isn't reference counted, to avoid loops. Which can leave it dangling if the stash is deleted. There is already protection for the similar GvSTASH field in GVs: the stash has an array of backrefs, xhv_backreferences, pointing to the GVs whose GvSTASHes point to it, and which is used to zero all the GvSTASH fields should the stash be deleted. All this patch does is also add the CVs with CvSTASH to that stash's backref list too.
* Document the blockhook functions and macros.Ben Morrow2010-07-121-0/+11
|
* Wrap PL_blockhooks in an API function.Ben Morrow2010-07-121-0/+8
| | | | | This should help prevent people from thinking they can get cute with the contents.
* Generic hooks into Perl_block_{start,end}.Ben Morrow2010-07-121-2/+12
| | | | | | | | | | These take the form of a vtable pushed onto the new PL_blockhooks array. This could probably do with a API around it later. Separate pre_end and post_end hooks are needed to capture globals before the stack is unwound (like needblockscope in the existing code). The intention is that once a vtable is installed it never gets removed, so where necessary extensions using this will need to use a hinthv element to determine whether to do anything or not.
* glob crashes when %File::Glob:: is emptyFather Chrysostomos2010-06-071-5/+6
| | | | | | | | In 5.6.2, a failure to find a CORE::GLOBAL::glob after loading File::Glob would result in a fallback to external glob via pp_glob. Now it crashes. The attached patch should fix this.
* Eliminate some newSV(0)s by merging the SV allocation with first modification.Nicholas Clark2010-05-301-5/+4
|