Re: The split opcode
Leopold Toetsch wrote: James deBoer [EMAIL PROTECTED] wrote: I would even go further than that and say that if we went with PGE::Rule's split, the split opcode should be obsoleted. All these function/method like opcodes will be refactured somewhen. WRT split (you write): PGE::Rule.split() in general $P0.split(...) where $P0 is a namespace or object that can split. For some bits of more performance a user could do: cl = getclass String cl.split(...) assuming that the current split on strings moves to the String class. Ok. If we are moving things like split into objects at some point in the future, should the split opcode be removed now? (I'm guessing the answer is yes, since split is one of the opcodes listed in your 'Too many opcodes' post of a few weeks back) At this point the split opcode doesn't really do anything useful, and any fixes/improvements to it would be lost when the logic is moved to String/PerlString/PythonString/... objects. - James
Re: The split opcode
Patrick R. Michaud wrote: On Fri, Dec 10, 2004 at 01:34:03PM -0500, James deBoer wrote: Currently, the split opcode is declared as 'split(out PMC, in STR, in STR)' where $2 is a regex. PGE, however, currently supports three types of regular expressions, and more are likely going to be added. So, which type of regular expression should split use? [...] A solution: Declare split as 'split(out PMC, in PMC, in STR)' where $2 would be a compiled PGE::Match object. This lets you pick what kind of regular expression you want to use. Slight correction: Thus far a PGE::Match object is the result of performing a match between a rule and target string, not the compiled form of the rule. At present a rule is just a subroutine that returns PGE::Match objects. Eventually we may have a PGE::Rule class for representing compiled rule objects, but we're not there yet. So, $2 would need to be a rule subroutine. Going beyond that, we might want to just have a split method for PGE::Rule objects, and leave the split opcode to do fast separation of strings based on constant strings. But I'm not entirely familiar with Parrot's opcode/MMD semantics so I'll follow others' leads on this one... Pm I would even go further than that and say that if we went with PGE::Rule's split, the split opcode should be obsoleted. I can't think of a place where splitting on constant strings is not a special case of splitting on a regular expression. Evaluating a very simple regular expression (i.e. a constant string) should be fast enough that it is not worth the effort to determine if a pattern can be sent through the split opcode instead of PGE::Rule.split(). However, using a split opcode that accepts a match subroutine has the advantage that the PGE is not strictly required. It would be possible to write your own subroutines if speed or code size were issues or if you had some other crazy requirements. This raises the question: How far do we want to let the PGE into our everyday lives? - James
The split opcode
Currently, the split opcode is declared as 'split(out PMC, in STR, in STR)' where $2 is a regex. PGE, however, currently supports three types of regular expressions, and more are likely going to be added. So, which type of regular expression should split use? The Perl6's split function will likely use slightly different regular expressions than TCL's split function or Python's. Picking any one regular expression (e.g Perl6's) will force the other languages to reimplement split's functionality. A solution: Declare split as 'split(out PMC, in PMC, in STR)' where $2 would be a compiled PGE::Match object. This lets you pick what kind of regular expression you want to use. An example using Perl6's regular expressions: .local string pattern .local string input .local pmc rulesub .local pmc array pattern = [\n ] # pattern to compile rulesub = p6rule_compile(pattern) # compile it to rulesub input = I held out my arm\nbut she laughed split array, rulesub, input # array will be a list of words in input Comments? Is there a simpler solution? Am I making a problem out of nothing? - James
Re: [perl #32545] [PATCH] [TODO] remove Perl dependancy on split opcode
Attached is a patch that changes the split opcode to use an Array instead of a PerlArray. It also updates the documentation to note this. All the tests still pass, and a grep in the languages/ directory shows that no language implementations are effected. - James Will Coleda (via RT) wrote: # New Ticket Created by Will Coleda # Please include the string: [perl #32545] # in the subject line of all future correspondence about this issue. # URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=32545 The split opcode currently uses a PerlArray to house its result. It should use a non-language specific class. ? classes/.array.pmc.swp Index: ops/string.ops === RCS file: /cvs/public/parrot/ops/string.ops,v retrieving revision 1.28 diff -u -r1.28 string.ops --- ops/string.ops 28 Sep 2004 11:26:49 - 1.28 +++ ops/string.ops 6 Dec 2004 19:16:59 - @@ -561,7 +561,7 @@ =item Bsplit(out PMC, in STR, in STR) -Create a new PerlArray PMC $1 by splitting the string $3 with +Create a new Array PMC $1 by splitting the string $3 with regexp $2. Currently implemented only for the empty string $2. =cut @@ -589,7 +589,7 @@ } op split(out PMC, in STR, in STR) :base_core { -PMC *res = $1 = pmc_new(interpreter, enum_class_PerlArray); +PMC *res = $1 = pmc_new(interpreter, enum_class_Array); STRING *r = $2; STRING *s = $3; int slen = string_length(interpreter, s); @@ -599,6 +599,7 @@ goto NEXT(); if (string_length(interpreter, r)) internal_exception(1, Unimplemented split by regex); +VTABLE_set_integer_native(interpreter, res, slen); for (i = 0; i slen; ++i) { STRING *p = string_substr(interpreter, s, i, 1, NULL, 0); /* TODO first set empty string, then replace */
Re: [perl #32769] [PATCH] Standardizes and improves the formatting of internal_exception() calls
D'oh, It looks like I missed a few cases and broken the test suite with this patch. I will post a new patch shortly. -James James deBoer (via RT) wrote: # New Ticket Created by James deBoer # Please include the string: [perl #32769] # in the subject line of all future correspondence about this issue. # URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=32769 Some calls to internal_exception will include a newline, others will not. The effect of this is that when some exceptions occur, parrot will exit without printing a newline, which is ugly. The fix I've attached is two-fold. First, it removes any newline passed to internal_exception. (This was a search and replace, I may have missed a few). Second, it modifies the the internal_exception function to print a newline after printing the error. - James
Re: [perl #32280] [PATCH] Detects presence of perldoc at configuration time
Sorry for the delay, but here is a revised patch to detect perldoc. - If Perldoc is detected, no warning messages will be printed and things will work as before - If Perldoc is not detected - Configure.pl will print a message saying that the docs will not be built - docs/ will not be built - When 'make docs' or 'make html' is run, a message will be echoed to the screen explaining that perldoc is required. James Leopold Toetsch wrote: Nicholas Clark [EMAIL PROTECTED] wrote: I don't like the build blowing up on me when there is no perldoc, and on some machines that I use I'm not in a position to change this. So, as opinions aren't really matching, let's try this approach: The configure step from that patch doesn't bail out, but prints a big fat warning about the lack of accessing perl and parrot docs, disables the parrot doc make target and continues. Nicholas Clark leo --- config_o2/auto/perldoc.pl 1969-12-31 19:00:00.0 -0500 +++ config/auto/perldoc.pl 2004-11-18 22:02:39.0 -0500 @@ -0,0 +1,36 @@ +#! perl -w +# Copyright: 2001-2004 The Perl Foundation. All Rights Reserved. + +=head1 NAME + +config/auto/perldoc - Perldoc + +=head1 DESCRIPTION + +Determines if Perldoc exists on the system. + +=cut + +package Configure::Step; + +use strict; +use vars qw($description @args); +use Parrot::Configure::Step ':auto'; + +$description=Determining if your system has perldoc installed...; + [EMAIL PROTECTED](verbose); + +sub runstep { + +my $a = `perldoc perldoc`; +unless ($a =~ m/perldoc/) { + Configure::Data-set(perldoc = 0); + Configure::Data-set(notperldoc = 1); +} else { +Configure::Data-set(perldoc = 1); + Configure::Data-set(notperldoc = 0); +} +} + +1; ? .MANIFEST.swp ? .Makefile.swp ? .config_perldoc.patch.swp ? config/auto/.headers.pl.swp ? config/auto/.perldoc.pl.swp ? config/auto/perldoc.pl ? config/gen/.makefiles.pl.swp ? config/gen/makefiles/.root.in.swp ? docs/.Makefile.swp ? icu/source/test/testdata/out ? lib/Parrot/Configure/.Step.pm.swp ? tools/dev/.install_files.pl.swp Index: MANIFEST === RCS file: /cvs/public/parrot/MANIFEST,v retrieving revision 1.772 diff -u -r1.772 MANIFEST --- MANIFEST 18 Nov 2004 07:01:10 - 1.772 +++ MANIFEST 19 Nov 2004 21:34:56 - @@ -158,6 +158,7 @@ config/auto/memalign/test_c.in[] config/auto/memalign/test_c2.in [] config/auto/pack.pl [] +config/auto/perldoc.pl[] config/auto/signal.pl [] config/auto/signal/test_1.in [] config/auto/signal/test_2.in [] Index: config/gen/makefiles.pl === RCS file: /cvs/public/parrot/config/gen/makefiles.pl,v retrieving revision 1.36 diff -u -r1.36 makefiles.pl --- config/gen/makefiles.pl 13 Sep 2004 05:25:51 - 1.36 +++ config/gen/makefiles.pl 19 Nov 2004 21:34:56 - @@ -88,34 +88,39 @@ genfile('config/gen/makefiles/parrot_compiler.in', 'languages/parrot_compiler/Makefile', commentType = '#', replace_slashes = 1); - - # set up docs/Makefile, partly based on the .ops in the root dir - - opendir OPS, ops or die opendir ops: $!; - my @ops = sort grep { !/^\./ /\.ops$/ } readdir OPS; - closedir OPS; - - my $pod = join , map { my $t = $_; $t =~ s/\.ops$/.pod/; ops/$t } @ops; - - Configure::Data-set(pod = $pod); - - genfile('config/gen/makefiles/docs.in', 'docs/Makefile', - commentType = '#'); - - Configure::Data-set(pod = undef); - - open MAKEFILE, docs/Makefile or die open docs/Makefile: $!; - - foreach my $ops (@ops) { - my $pod = $ops; - $pod =~ s/\.ops$/.pod/; - print MAKEFILE EOM; + my $perldoc = Configure::Data-get('perldoc'); + if ($perldoc) { +# set up docs/Makefile, partly based on the .ops in the root dir + +opendir OPS, ops or die opendir ops: $!; +my @ops = sort grep { !/^\./ /\.ops$/ } readdir OPS; +closedir OPS; + +my $pod = join , map { my $t = $_; $t =~ s/\.ops$/.pod/; ops/$t } @ops; + +Configure::Data-set(pod = $pod); + +genfile('config/gen/makefiles/docs.in', 'docs/Makefile', +commentType = '#'); + +Configure::Data-set(pod = undef); + +open MAKEFILE, docs/Makefile or die open docs/Makefile: $!; + +foreach my $ops (@ops) { +my $pod = $ops; +$pod =~ s/\.ops$/.pod/; +print MAKEFILE EOM; ops/$pod: ../ops/$ops perldoc -u ../ops/$ops ops/$pod -EOM - } - close MAKEFILE +EOM +} + +close MAKEFILE +} else { +print \nNo Perldoc, not generating a docs makefile.\n; +} } 1; Index: config/gen/makefiles/root.in === RCS file: /cvs/public/parrot/config/gen/makefiles/root.in,v retrieving revision 1.261 diff
Re: [perl #32278] [PATCH] Removes all she-bang lines from config/*.pl
Fair enough. Here is a [longer] patch to remove all of the she-bang lines, then. - James Brent Royal-Gordon via RT wrote: James deBoer [EMAIL PROTECTED] wrote: There are a number of .pl files within parrot/config. Some of them have a she-bang line at the beginning of the script, others do not. This patch simply adds '#! perl -w' to the top of any script that didn't have this line already. These scripts can only be run by Configure doing them. I don't think it really makes sense for them to have shebang lines. Index: config/auto/byteorder.pl === RCS file: /cvs/public/parrot/config/auto/byteorder.pl,v retrieving revision 1.2 diff -u -r1.2 byteorder.pl --- config/auto/byteorder.pl 26 Feb 2004 00:43:02 - 1.2 +++ config/auto/byteorder.pl 2 Nov 2004 02:45:42 - @@ -1,4 +1,3 @@ -#! perl -w # Copyright: 2001-2003 The Perl Foundation. All Rights Reserved. # $Id: byteorder.pl,v 1.2 2004/02/26 00:43:02 mikescott Exp $ @@ -46,4 +45,4 @@ } } -1; \ No newline at end of file +1; Index: config/auto/cgoto.pl === RCS file: /cvs/public/parrot/config/auto/cgoto.pl,v retrieving revision 1.17 diff -u -r1.17 cgoto.pl --- config/auto/cgoto.pl 25 Mar 2004 16:52:53 - 1.17 +++ config/auto/cgoto.pl 2 Nov 2004 02:45:42 - @@ -1,4 +1,3 @@ -#! perl -w # Copyright: 2001-2003 The Perl Foundation. All Rights Reserved. # $Id: cgoto.pl,v 1.17 2004/03/25 16:52:53 dan Exp $ Index: config/auto/env.pl === RCS file: /cvs/public/parrot/config/auto/env.pl,v retrieving revision 1.4 diff -u -r1.4 env.pl --- config/auto/env.pl 6 Mar 2004 22:24:30 - 1.4 +++ config/auto/env.pl 2 Nov 2004 02:45:42 - @@ -1,4 +1,3 @@ -#! perl -w # Copyright: 2001-2003 The Perl Foundation. All Rights Reserved. # $Id: env.pl,v 1.4 2004/03/06 22:24:30 brentdax Exp $ Index: config/auto/format.pl === RCS file: /cvs/public/parrot/config/auto/format.pl,v retrieving revision 1.3 diff -u -r1.3 format.pl --- config/auto/format.pl 26 Feb 2004 00:43:02 - 1.3 +++ config/auto/format.pl 2 Nov 2004 02:45:42 - @@ -1,4 +1,3 @@ -#! perl -w # Copyright: 2001-2003 The Perl Foundation. All Rights Reserved. # $Id: format.pl,v 1.3 2004/02/26 00:43:02 mikescott Exp $ Index: config/auto/funcptr.pl === RCS file: /cvs/public/parrot/config/auto/funcptr.pl,v retrieving revision 1.4 diff -u -r1.4 funcptr.pl --- config/auto/funcptr.pl 6 Mar 2004 22:24:30 - 1.4 +++ config/auto/funcptr.pl 2 Nov 2004 02:45:42 - @@ -1,4 +1,3 @@ -#! perl -w # Copyright: 2001-2003 The Perl Foundation. All Rights Reserved. # $Id: funcptr.pl,v 1.4 2004/03/06 22:24:30 brentdax Exp $ Index: config/auto/gc.pl === RCS file: /cvs/public/parrot/config/auto/gc.pl,v retrieving revision 1.8 diff -u -r1.8 gc.pl --- config/auto/gc.pl 7 Mar 2004 05:45:00 - 1.8 +++ config/auto/gc.pl 2 Nov 2004 02:45:42 - @@ -1,4 +1,3 @@ -#! perl -w # Copyright: 2001-2003 The Perl Foundation. All Rights Reserved. # $Id: gc.pl,v 1.8 2004/03/07 05:45:00 brentdax Exp $ Index: config/auto/gcc.pl === RCS file: /cvs/public/parrot/config/auto/gcc.pl,v retrieving revision 1.19 diff -u -r1.19 gcc.pl --- config/auto/gcc.pl 5 May 2004 07:27:47 - 1.19 +++ config/auto/gcc.pl 2 Nov 2004 02:45:42 - @@ -1,4 +1,3 @@ -#! perl -w # Copyright: 2001-2003 The Perl Foundation. All Rights Reserved. # $Id: gcc.pl,v 1.19 2004/05/05 07:27:47 leo Exp $ Index: config/auto/headers.pl === RCS file: /cvs/public/parrot/config/auto/headers.pl,v retrieving revision 1.18 diff -u -r1.18 headers.pl --- config/auto/headers.pl 8 Oct 2004 22:01:06 - 1.18 +++ config/auto/headers.pl 2 Nov 2004 02:45:42 - @@ -1,4 +1,3 @@ -#! perl -w # Copyright: 2001-2003 The Perl Foundation. All Rights Reserved. # $Id: headers.pl,v 1.18 2004/10/08 22:01:06 jrieks Exp $ Index: config/auto/snprintf.pl === RCS file: /cvs/public/parrot/config/auto/snprintf.pl,v retrieving revision 1.1 diff -u -r1.1 snprintf.pl --- config/auto/snprintf.pl 28 Sep 2004 08:51:45 - 1.1 +++ config/auto/snprintf.pl 2 Nov 2004 02:45:42 - @@ -1,4 +1,3 @@ -#! perl -w # Copyright: 2001-2003 The Perl Foundation. All Rights Reserved. # $Id: snprintf.pl,v 1.1 2004/09/28 08:51:45 leo Exp $ Index: config/gen/config_h.pl === RCS file: /cvs/public/parrot/config/gen/config_h.pl,v retrieving revision 1.13 diff -u -r1.13 config_h.pl --- config/gen/config_h.pl 31 May 2004 11:54:52 - 1.13