├── .gitignore
├── CREDITS
├── Configure.pl
├── LICENSE
├── README.pod
├── STATUS
├── build
├── Makefile.in
├── PARROT_REVISION
├── gen_bootstrap.pl
├── gen_parrot.pl
├── gen_setting.pl
└── lib
│ └── Rakudo
│ └── CompareRevisions.pm
├── docs
└── bootstrapping.pod
├── examples
├── fib.nqp
├── hello_world.nqp
├── json.nqp
├── load_bytecode.nqp
└── loops.nqp
├── src
├── HLL.pir
├── HLL
│ ├── Actions.pm
│ ├── Compiler.pm
│ └── Grammar.pm
├── NQP
│ ├── Actions.pm
│ ├── Compiler.pir
│ └── Grammar.pm
├── PAST
│ ├── Compiler-Regex.pir
│ └── Regex.pir
├── Regex.pir
├── Regex
│ ├── Cursor-builtins.pir
│ ├── Cursor-protoregex-peek.pir
│ ├── Cursor.pir
│ ├── Dumper.pir
│ ├── Match.pir
│ ├── Method.pir
│ ├── P6Regex.pir
│ ├── P6Regex
│ │ ├── Actions.pm
│ │ └── Grammar.pm
│ └── constants.pir
├── cheats
│ ├── hll-compiler.pir
│ ├── hll-grammar.pir
│ ├── nqp-builtins.pir
│ └── parrot-callcontext.pir
├── gen
│ └── IGNOREME
├── setting
│ ├── Hash.pm
│ ├── IO.pm
│ ├── Regex.pm
│ └── ResizablePMCArray.pm
└── stage0
│ ├── HLL-s0.pir
│ ├── NQP-s0.pir
│ ├── P6Regex-s0.pir
│ ├── Regex-s0.pir
│ └── nqp-setting.nqp
├── t
├── hll
│ ├── 01-language.t
│ ├── 02-modules.t
│ ├── 03-exports.t
│ └── 04-import.t
├── nqp
│ ├── 01-literals.t
│ ├── 02-if.t
│ ├── 03-if-else.t
│ ├── 04-unless.t
│ ├── 05-comments.t
│ ├── 06-args-pos.t
│ ├── 07-boolean.t
│ ├── 08-blocks.t
│ ├── 09-var.t
│ ├── 10-cmp.t
│ ├── 11-sub.t
│ ├── 12-logical.t
│ ├── 13-op.t
│ ├── 14-while.t
│ ├── 15-list.t
│ ├── 16-ternary.t
│ ├── 17-positional.t
│ ├── 18-associative.t
│ ├── 19-inline.t
│ ├── 20-return.t
│ ├── 21-contextual.t
│ ├── 22-optional-args.t
│ ├── 23-named-args.t
│ ├── 24-module.t
│ ├── 25-class.t
│ ├── 26-methodops.t
│ ├── 27-self.t
│ ├── 28-subclass.t
│ ├── 29-make.t
│ ├── 30-pirop.t
│ ├── 31-grammar.t
│ ├── 32-protoregex.t
│ ├── 33-init.t
│ ├── 34-rxcodeblock.t
│ ├── 35-prefix-sigil.t
│ ├── 36-callable.t
│ ├── 37-slurpy.t
│ ├── 38-quotes.t
│ ├── 39-pointy.t
│ ├── 40-lists.t
│ ├── 41-flat.t
│ ├── 42-cond-loop.t
│ ├── 43-package-var.t
│ ├── 44-try-catch.t
│ ├── 45-smartmatch.t
│ ├── 46-charspec.t
│ ├── 47-loop-control.t
│ ├── 48-closure.t
│ ├── 49-regex-interpolation.t
│ ├── 50-regex.t
│ ├── 51-multi.t
│ ├── 52-vtable.t
│ └── 67-threads.t
├── p6regex
│ ├── 01-regex.t
│ ├── rx_backtrack
│ ├── rx_basic
│ ├── rx_captures
│ ├── rx_charclass
│ ├── rx_goal
│ ├── rx_lookarounds
│ ├── rx_metachars
│ ├── rx_modifiers
│ ├── rx_quantifiers
│ ├── rx_subrules
│ └── rx_syntax
└── setting
│ ├── 01-resizablepmcarray.t
│ ├── 02-hash.t
│ ├── 03-io.t
│ ├── 04-regex.t
│ └── 05-subst.t
└── tools
└── analyze-parse
/.gitignore:
--------------------------------------------------------------------------------
1 | Makefile
2 | /parrot
3 | /parrot_install
4 | .*.swp
5 | *.c
6 | *.o
7 | Regex.pbc
8 | HLL.pbc
9 | P6Regex
10 | P6Regex.pbc
11 | nqp
12 | nqp.pbc
13 | nqp-setting.pbc
14 | src/gen/*.pir
15 | src/gen/*.nqp
16 | src/stage1
17 | src/stage2
18 |
--------------------------------------------------------------------------------
/CREDITS:
--------------------------------------------------------------------------------
1 | =pod
2 |
3 | Following in the steps of other open source projects that
4 | eventually take over the world, here is the partial list
5 | of people who have contributed to Rakudo and its supporting
6 | works. It is sorted by name and formatted to allow easy
7 | grepping and beautification by scripts.
8 | The fields are: name (N), email (E), web-address (W),
9 | description (D), subversion username (U) and snail-mail
10 | address (S).
11 |
12 | Thanks,
13 |
14 | The NQP Team
15 | PS: Yes, this looks remarkably like the Linux CREDITS format
16 | PPS: This file is encoded in UTF-8
17 |
18 | ----------
19 | N: Daniel Arbelo Arrocha
20 | U: darbelo
21 | E: arbelo@gmail.com
22 | D: Minor code contributions (plumage)
23 |
24 | N: Geoff Broadwell
25 | U: japhb
26 | E: geoff@broadwell.org
27 | D: Initial design and implementation of Plumage.
28 |
29 | N: Jonathan "Duke" Leto
30 | U: leto
31 | D: Perl 6 (Rakudo Perl) developer
32 | E: jonathan@leto.net
33 |
34 | N: Jonathan Scott Duff
35 | U: perlpilot
36 | D: Perl 6 (Rakudo Perl) developer
37 | E: duff@pobox.com
38 |
39 | N: Patrick R. Michaud
40 | U: pmichaud
41 | D: Perl 6 (Rakudo Perl) lead developer, pumpking
42 | E: pmichaud@pobox.com
43 |
44 | N: Stefan O'Rear
45 | U: sorear
46 | D: Lexical persistance, POD, and other miscellaneous contributions
47 | E: stefanor@cox.net
48 |
49 | N: Stephen Weeks
50 | U: tene
51 | E: tene@allalone.org
52 | D: Assorted contributions (plumage)
53 |
54 | N: Vasily Chekalkin
55 | U: bacek
56 | D: Work on bringing Settings to NQP based on Plumage's NQPUtils.
57 | E: bacek@bacek.com
58 |
59 | =cut
60 |
--------------------------------------------------------------------------------
/Configure.pl:
--------------------------------------------------------------------------------
1 | #! perl
2 | # Copyright (C) 2009 The Perl Foundation
3 |
4 | use 5.008;
5 | use strict;
6 | use warnings;
7 | use Getopt::Long;
8 | use Cwd;
9 | use lib "build/lib";
10 | use Rakudo::CompareRevisions qw(compare_parrot_revs);
11 |
12 | MAIN: {
13 | my %options;
14 | GetOptions(\%options, 'help!', 'parrot-config=s',
15 | 'gen-parrot!', 'gen-parrot-prefix=s', 'gen-parrot-option=s@');
16 |
17 | # Print help if it's requested
18 | if ($options{'help'}) {
19 | print_help();
20 | exit(0);
21 | }
22 |
23 | # Determine the revision of Parrot we require
24 | open my $REQ, "build/PARROT_REVISION"
25 | || die "cannot open build/PARROT_REVISION\n";
26 | my ($reqsvn, $reqpar) = split(' ', <$REQ>);
27 | close $REQ;
28 |
29 | # Update/generate parrot build if needed
30 | if ($options{'gen-parrot'}) {
31 | my @opts = @{ $options{'gen-parrot-option'} || [] };
32 | my $prefix = $options{'gen-parrot-prefix'} || cwd()."/parrot_install";
33 | # parrot's Configure.pl mishandles win32 backslashes in --prefix
34 | $prefix =~ s{\\}{/}g;
35 | my @command = ($^X, "build/gen_parrot.pl", "--prefix=$prefix", ($^O !~ /win32/i ? "--optimize" : ()), @opts);
36 |
37 | print "Generating Parrot ...\n";
38 | print "@command\n\n";
39 | system @command;
40 | }
41 |
42 | # Get a list of parrot-configs to invoke.
43 | my @parrot_config_exe = qw(
44 | parrot_install/bin/parrot_config
45 | ../../parrot_config
46 | parrot_config
47 | );
48 | if (exists $options{'gen-parrot-prefix'}) {
49 | unshift @parrot_config_exe,
50 | $options{'gen-parrot-prefix'} . '/bin/parrot_config';
51 | }
52 |
53 | if ($options{'parrot-config'} && $options{'parrot-config'} ne '1') {
54 | @parrot_config_exe = ($options{'parrot-config'});
55 | }
56 |
57 | # Get configuration information from parrot_config
58 | my %config = read_parrot_config(@parrot_config_exe);
59 |
60 | my $parrot_errors = '';
61 | if (!%config) {
62 | $parrot_errors .= "Unable to locate parrot_config\n";
63 | }
64 | elsif (compare_parrot_revs($reqsvn, $config{'git_describe'}) > 0 &&
65 |
66 | ($reqpar eq '' || version_int($reqpar) > version_int($config{'VERSION'}))) {
67 | $parrot_errors .= "Parrot revision $reqsvn required (currently $config{'git_describe'})\n";
68 | }
69 |
70 | if ($parrot_errors) {
71 | die <<"END";
72 | ===SORRY!===
73 | $parrot_errors
74 | To automatically checkout (git) and build a copy of parrot $reqsvn,
75 | try re-running Configure.pl with the '--gen-parrot' option.
76 | Or, use the '--parrot-config' option to explicitly specify
77 | the location of parrot_config to be used to build NQP.
78 |
79 | END
80 | }
81 |
82 | # Verify the Parrot installation is sufficient for building NQP
83 | verify_parrot(%config);
84 |
85 | # Create the Makefile using the information we just got
86 | create_makefile(%config);
87 | my $make = $config{'make'};
88 |
89 | {
90 | no warnings;
91 | print "Cleaning up ...\n";
92 | if (open my $CLEAN, '-|', "$make clean") {
93 | my @slurp = <$CLEAN>;
94 | close $CLEAN;
95 | }
96 | }
97 |
98 | print <<"END";
99 |
100 | You can now use '$make' to build NQP.
101 | After that, you can use '$make test' to run some local tests.
102 |
103 | END
104 | exit 0;
105 |
106 | }
107 |
108 |
109 | sub read_parrot_config {
110 | my @parrot_config_exe = @_;
111 | my %config = ();
112 | for my $exe (@parrot_config_exe) {
113 | no warnings;
114 | if (open my $PARROT_CONFIG, '-|', "$exe --dump") {
115 | print "\nReading configuration information from $exe ...\n";
116 | while (<$PARROT_CONFIG>) {
117 | if (/(\w+) => '(.*)'/) { $config{$1} = $2 }
118 | }
119 | close $PARROT_CONFIG or die $!;
120 | last if %config;
121 | }
122 | }
123 | return %config;
124 | }
125 |
126 |
127 | sub verify_parrot {
128 | print "Verifying Parrot installation...\n";
129 | my %config = @_;
130 | my $PARROT_VERSION = $config{'versiondir'};
131 | my $PARROT_LIB_DIR = $config{'libdir'}.$PARROT_VERSION;
132 | my $PARROT_SRC_DIR = $config{'srcdir'}.$PARROT_VERSION;
133 | my $PARROT_INCLUDE_DIR = $config{'includedir'}.$PARROT_VERSION;
134 | my $PARROT_TOOLS_DIR = "$PARROT_LIB_DIR/tools";
135 | my @required_files = (
136 | "$PARROT_LIB_DIR/library/PGE/Perl6Grammar.pbc",
137 | "$PARROT_LIB_DIR/library/PCT/HLLCompiler.pbc",
138 | "$PARROT_TOOLS_DIR/build/ops2c.pl",
139 | "$PARROT_TOOLS_DIR/build/pmc2c.pl",
140 | "$PARROT_SRC_DIR",
141 | "$PARROT_SRC_DIR/pmc",
142 | "$PARROT_INCLUDE_DIR",
143 | "$PARROT_INCLUDE_DIR/pmc",
144 | );
145 | my @missing;
146 | for my $reqfile (@required_files) {
147 | push @missing, " $reqfile" unless -e $reqfile;
148 | }
149 | if (@missing) {
150 | my $missing = join("\n", @missing);
151 | die <<"END";
152 |
153 | ===SORRY!===
154 | I'm missing some needed files from the Parrot installation:
155 | $missing
156 | (Perhaps you need to use Parrot's "make install-dev" or
157 | install the "parrot-devel" package for your system?)
158 |
159 | END
160 | }
161 | }
162 |
163 | # Generate a Makefile from a configuration
164 | sub create_makefile {
165 | my %config = @_;
166 |
167 | my $maketext = slurp( 'build/Makefile.in' );
168 |
169 | $config{'win32_libparrot_copy'} = $^O eq 'MSWin32' ? 'copy $(PARROT_BIN_DIR)\libparrot.dll .' : '';
170 | $maketext =~ s/@(\w+)@/$config{$1}/g;
171 | if ($^O eq 'MSWin32') {
172 | $maketext =~ s{/}{\\}g;
173 | $maketext =~ s{\\\*}{\\\\*}g;
174 | $maketext =~ s{http:\S+}{ do {my $t = $&; $t =~ s'\\'/'g; $t} }eg;
175 | }
176 |
177 | my $outfile = 'Makefile';
178 | print "\nCreating $outfile ...\n";
179 | open(my $MAKEOUT, '>', $outfile) ||
180 | die "Unable to write $outfile\n";
181 | print {$MAKEOUT} $maketext;
182 | close $MAKEOUT or die $!;
183 |
184 | return;
185 | }
186 |
187 | sub slurp {
188 | my $filename = shift;
189 |
190 | open my $fh, '<', $filename or die "Unable to read $filename\n";
191 | local $/ = undef;
192 | my $maketext = <$fh>;
193 | close $fh or die $!;
194 |
195 | return $maketext;
196 | }
197 |
198 | sub version_int {
199 | sprintf('%d%03d%03d', split(/\./, $_[0]))
200 | }
201 |
202 |
203 | # Print some help text.
204 | sub print_help {
205 | print <<'END';
206 | Configure.pl - NQP Configure
207 |
208 | General Options:
209 | --help Show this text
210 | --gen-parrot Download and build a copy of Parrot to use
211 | --gen-parrot-option='--option=value'
212 | Set parrot config option when using --gen-parrot
213 | --parrot-config=(config)
214 | Use configuration information from config
215 | END
216 |
217 | return;
218 | }
219 |
220 | # Local Variables:
221 | # mode: cperl
222 | # cperl-indent-level: 4
223 | # fill-column: 100
224 | # End:
225 | # vim: expandtab shiftwidth=4:
226 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The Artistic License 2.0
2 |
3 | Copyright (c) 2000-2006, The Perl Foundation.
4 |
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | This license establishes the terms under which a given free software
11 | Package may be copied, modified, distributed, and/or redistributed.
12 | The intent is that the Copyright Holder maintains some artistic
13 | control over the development of that Package while still keeping the
14 | Package available as open source and free software.
15 |
16 | You are always permitted to make arrangements wholly outside of this
17 | license directly with the Copyright Holder of a given Package. If the
18 | terms of this license do not permit the full use that you propose to
19 | make of the Package, you should contact the Copyright Holder and seek
20 | a different licensing arrangement.
21 |
22 | Definitions
23 |
24 | "Copyright Holder" means the individual(s) or organization(s)
25 | named in the copyright notice for the entire Package.
26 |
27 | "Contributor" means any party that has contributed code or other
28 | material to the Package, in accordance with the Copyright Holder's
29 | procedures.
30 |
31 | "You" and "your" means any person who would like to copy,
32 | distribute, or modify the Package.
33 |
34 | "Package" means the collection of files distributed by the
35 | Copyright Holder, and derivatives of that collection and/or of
36 | those files. A given Package may consist of either the Standard
37 | Version, or a Modified Version.
38 |
39 | "Distribute" means providing a copy of the Package or making it
40 | accessible to anyone else, or in the case of a company or
41 | organization, to others outside of your company or organization.
42 |
43 | "Distributor Fee" means any fee that you charge for Distributing
44 | this Package or providing support for this Package to another
45 | party. It does not mean licensing fees.
46 |
47 | "Standard Version" refers to the Package if it has not been
48 | modified, or has been modified only in ways explicitly requested
49 | by the Copyright Holder.
50 |
51 | "Modified Version" means the Package, if it has been changed, and
52 | such changes were not explicitly requested by the Copyright
53 | Holder.
54 |
55 | "Original License" means this Artistic License as Distributed with
56 | the Standard Version of the Package, in its current version or as
57 | it may be modified by The Perl Foundation in the future.
58 |
59 | "Source" form means the source code, documentation source, and
60 | configuration files for the Package.
61 |
62 | "Compiled" form means the compiled bytecode, object code, binary,
63 | or any other form resulting from mechanical transformation or
64 | translation of the Source form.
65 |
66 |
67 | Permission for Use and Modification Without Distribution
68 |
69 | (1) You are permitted to use the Standard Version and create and use
70 | Modified Versions for any purpose without restriction, provided that
71 | you do not Distribute the Modified Version.
72 |
73 |
74 | Permissions for Redistribution of the Standard Version
75 |
76 | (2) You may Distribute verbatim copies of the Source form of the
77 | Standard Version of this Package in any medium without restriction,
78 | either gratis or for a Distributor Fee, provided that you duplicate
79 | all of the original copyright notices and associated disclaimers. At
80 | your discretion, such verbatim copies may or may not include a
81 | Compiled form of the Package.
82 |
83 | (3) You may apply any bug fixes, portability changes, and other
84 | modifications made available from the Copyright Holder. The resulting
85 | Package will still be considered the Standard Version, and as such
86 | will be subject to the Original License.
87 |
88 |
89 | Distribution of Modified Versions of the Package as Source
90 |
91 | (4) You may Distribute your Modified Version as Source (either gratis
92 | or for a Distributor Fee, and with or without a Compiled form of the
93 | Modified Version) provided that you clearly document how it differs
94 | from the Standard Version, including, but not limited to, documenting
95 | any non-standard features, executables, or modules, and provided that
96 | you do at least ONE of the following:
97 |
98 | (a) make the Modified Version available to the Copyright Holder
99 | of the Standard Version, under the Original License, so that the
100 | Copyright Holder may include your modifications in the Standard
101 | Version.
102 |
103 | (b) ensure that installation of your Modified Version does not
104 | prevent the user installing or running the Standard Version. In
105 | addition, the Modified Version must bear a name that is different
106 | from the name of the Standard Version.
107 |
108 | (c) allow anyone who receives a copy of the Modified Version to
109 | make the Source form of the Modified Version available to others
110 | under
111 |
112 | (i) the Original License or
113 |
114 | (ii) a license that permits the licensee to freely copy,
115 | modify and redistribute the Modified Version using the same
116 | licensing terms that apply to the copy that the licensee
117 | received, and requires that the Source form of the Modified
118 | Version, and of any works derived from it, be made freely
119 | available in that license fees are prohibited but Distributor
120 | Fees are allowed.
121 |
122 |
123 | Distribution of Compiled Forms of the Standard Version
124 | or Modified Versions without the Source
125 |
126 | (5) You may Distribute Compiled forms of the Standard Version without
127 | the Source, provided that you include complete instructions on how to
128 | get the Source of the Standard Version. Such instructions must be
129 | valid at the time of your distribution. If these instructions, at any
130 | time while you are carrying out such distribution, become invalid, you
131 | must provide new instructions on demand or cease further distribution.
132 | If you provide valid instructions or cease distribution within thirty
133 | days after you become aware that the instructions are invalid, then
134 | you do not forfeit any of your rights under this license.
135 |
136 | (6) You may Distribute a Modified Version in Compiled form without
137 | the Source, provided that you comply with Section 4 with respect to
138 | the Source of the Modified Version.
139 |
140 |
141 | Aggregating or Linking the Package
142 |
143 | (7) You may aggregate the Package (either the Standard Version or
144 | Modified Version) with other packages and Distribute the resulting
145 | aggregation provided that you do not charge a licensing fee for the
146 | Package. Distributor Fees are permitted, and licensing fees for other
147 | components in the aggregation are permitted. The terms of this license
148 | apply to the use and Distribution of the Standard or Modified Versions
149 | as included in the aggregation.
150 |
151 | (8) You are permitted to link Modified and Standard Versions with
152 | other works, to embed the Package in a larger work of your own, or to
153 | build stand-alone binary or bytecode versions of applications that
154 | include the Package, and Distribute the result without restriction,
155 | provided the result does not expose a direct interface to the Package.
156 |
157 |
158 | Items That are Not Considered Part of a Modified Version
159 |
160 | (9) Works (including, but not limited to, modules and scripts) that
161 | merely extend or make use of the Package, do not, by themselves, cause
162 | the Package to be a Modified Version. In addition, such works are not
163 | considered parts of the Package itself, and are not subject to the
164 | terms of this license.
165 |
166 |
167 | General Provisions
168 |
169 | (10) Any use, modification, and distribution of the Standard or
170 | Modified Versions is governed by this Artistic License. By using,
171 | modifying or distributing the Package, you accept this license. Do not
172 | use, modify, or distribute the Package, if you do not accept this
173 | license.
174 |
175 | (11) If your Modified Version has been derived from a Modified
176 | Version made by someone other than you, you are nevertheless required
177 | to ensure that your Modified Version complies with the requirements of
178 | this license.
179 |
180 | (12) This license does not grant you the right to use any trademark,
181 | service mark, tradename, or logo of the Copyright Holder.
182 |
183 | (13) This license includes the non-exclusive, worldwide,
184 | free-of-charge patent license to make, have made, use, offer to sell,
185 | sell, import and otherwise transfer the Package with respect to any
186 | patent claims licensable by the Copyright Holder that are necessarily
187 | infringed by the Package. If you institute patent litigation
188 | (including a cross-claim or counterclaim) against any party alleging
189 | that the Package constitutes direct or contributory patent
190 | infringement, then this Artistic License to you shall terminate on the
191 | date that such litigation is filed.
192 |
193 | (14) Disclaimer of Warranty:
194 | THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS
195 | IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
196 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
197 | NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL
198 | LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL
199 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
200 | DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF
201 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
202 |
--------------------------------------------------------------------------------
/README.pod:
--------------------------------------------------------------------------------
1 | =head1 DEPRECATION NOTICE
2 |
3 | These days, NQP-rx is unmaintained; active development happens in
4 | nqp at L. This repository only serves
5 | as a historical document, and/or an implicit lesson in compiler design.
6 |
7 | =head1 NQP-rx - Not Quite Perl (6)
8 |
9 | NQP-rx is Copyright (C) 2009 by The Perl Foundation. See F
10 | for licensing details.
11 |
12 | This is "Not Quite Perl" -- a compiler for quickly generating PIR
13 | routines from Perl6-like code. The key feature of NQP-rx is that it's
14 | designed to be a very small compiler (as compared with, say, perl6
15 | or Rakudo) and is focused on being a high-level way to create
16 | transformers for Parrot (especially hll compilers). In addition,
17 | unlike Rakudo, NQP-rx attempts to restrict itself to generating code
18 | that can run in Parrot without the existence of any NQP-specific
19 | runtime libraries.
20 |
21 | =head2 Building from source
22 |
23 | NQP-rx comes bundled with Parrot, so if you have a recent Parrot
24 | distribution you likely also have a copy of NQP-rx. Inside of a
25 | Parrot installation NQP-rx is known as C.
26 |
27 | To build NQP-rx from source, you'll just need a C utility
28 | and Perl 5.8 or newer. To automatically obtain and build Parrot
29 | you may also need a subversion (svn) client.
30 |
31 | To obtain NQP-rx directly from its repository:
32 |
33 | $ git clone git://github.com/perl6/nqp-rx.git
34 |
35 | If you don't have git installed, you can get a tarball or zip
36 | of NQP from github by visiting http://github.com/perl6/nqp-rx/tree/master
37 | and clicking "Download". Then unpack the tarball or zip.
38 |
39 | Once you have a copy of NQP-rx, build it as follows:
40 |
41 | $ cd nqp-rx
42 | $ perl Configure.pl --gen-parrot
43 | $ make
44 |
45 | This will create a "nqp" or "nqp.exe" executable in the
46 | current (nqp-rx) directory. Programs can then be run from
47 | the build directory using a command like:
48 |
49 | $ ./nqp hello.pl
50 |
51 | The C<--gen-parrot> option above tells Configure.pl to automatically
52 | download and build the most appropriate version of Parrot into a
53 | local "parrot/" subdirectory, install that Parrot into the
54 | "parrot_install/" subdirectory, and use that for building NQP-rx.
55 | It's okay to use the C<--gen-parrot> option on later invocations
56 | of Configure.pl; the configure system will re-build Parrot only
57 | if a newer version is needed for whatever version of Rakudo you're
58 | working with.
59 |
60 | You can use C<--parrot-config=/path/to/parrot_config> instead
61 | of C<--gen-parrot> to use an already installed Parrot for building
62 | NQP. This installed Parrot must include its development
63 | environment; typically this is done via Parrot's C
64 | target or by installing prebuilt C and/or C
65 | packages. The version of the already installed Parrot must satisfy a
66 | minimum specified by the NQP-rx being built -- Configure.pl will
67 | verify this for you. Released versions of NQP-rx always build
68 | against the latest release of Parrot; checkouts of the HEAD revision
69 | from github often require a version of Parrot that is newer than
70 | the most recent Parrot monthly release.
71 |
72 | Once built, NQP-rx's C target will install NQP-rx
73 | and its libraries into the Parrot installation that was used to
74 | create it. Until this step is performed, the "nqp" executable
75 | created by C above can only be reliably run from the root of
76 | NQP-rx's build directory. After C is performed
77 | the executable can be run from any directory (as long as the
78 | Parrot installation that was used to create it remains intact).
79 |
80 | If the NQP-rx compiler is invoked without an explicit script to
81 | run, it enters a small interactive mode that allows statements
82 | to be executed from the command line.
83 |
84 | =head2 Differences from previous version of NQP
85 |
86 | * Sub declarations are now lexical ("my") by default, use
87 | "our sub xyz() { ... }" if you want package-scoped subroutines.
88 |
89 | * The PIR q<...>; construct is gone. Use Q:PIR or pir::opcode(...)
90 | instead.
91 |
92 | * The mainline code of modules is no longer tagged as ":load :init"
93 | by default. Use INIT { ... } for any code that you want to be
94 | run automatically at startup.
95 |
96 | * Cuddled else's are no longer valid Perl 6, 'else' requires a
97 | space after it.
98 |
99 | * Double-quoted strings now interpolate $-variables.
100 |
101 |
102 |
--------------------------------------------------------------------------------
/STATUS:
--------------------------------------------------------------------------------
1 | 2009-10-09:
2 |
3 | At the moment, nqp-rx is configured to build an executable called
4 | "p6regex", which is a Perl 6 regular expression compiler for Parrot.
5 | Yes, Parrot already has a Perl 6 regular expression compiler (PGE);
6 | this one is different in that it will be self-hosting and based on
7 | PAST/POST generation.
8 |
9 | Building the system is similar to building Rakudo:
10 |
11 | $ perl Configure.pl --gen-parrot
12 | $ make
13 |
14 | This builds a "p6regex" executable, which can be used to view
15 | the results of compiling various regular expressions. Like Rakudo,
16 | p6regex accepts --target=parse, --target=past, and --target=pir, to
17 | see the results of compiling various regular expressions. For example,
18 |
19 | $ ./p6regex --target=parse
20 | > abcde*f
21 |
22 | will display the parse tree for the regular expression "abcde*f". Similarly,
23 |
24 | $ ./p6regex --target=pir
25 | > abcde*f
26 |
27 | will display the PIR subroutine generated to match the regular
28 | expression "abcde*f".
29 |
30 | At the moment there's not an easy command-line tool for doing matches
31 | against the compiled regular expression; that should be coming soon
32 | as nqp-rx gets a little farther along.
33 |
34 | The test suite can be run via "make test" -- because the new regex
35 | engine is incomplete, we expect quite a few failures (which should
36 | diminish as we add new features to the project).
37 |
38 | The key files for the p6regex compiler are:
39 |
40 | src/Regex/P6Regex/Grammar.pm # regular expression parse grammar
41 | src/Regex/P6Regex/Actions.pm # actions to create PAST from parse
42 |
43 |
44 | Things that work (2009-10-15, 06h16 UTC):
45 |
46 | * bare literal strings
47 | * quantifiers *, +, ?, *:, +:, ?:, *?, +?, ??, *!, +!, ?!
48 | * dot
49 | * \d, \s, \w, \n, \D, \S, \W, \N
50 | * brackets for grouping
51 | * alternation (|| works, | cheats)
52 | * anchors ^, ^^, $, $$, <<, >>
53 | * backslash-quoted punctuation
54 | * #-comments (mostly)
55 | * obsolete backslash sequences \A \Z \z \Q
56 | * \b, \B, \e, \E, \f, \F, \h, \H, \r, \R, \t, \T, \v, \V
57 | * enumerated character lists <[ab0..9]>
58 | * character class compositions <+foo-bar+[xyz]>
59 | * quantified by numeric range
60 | * quantified by separator
61 | * capturing subrules
62 | * capturing subpatterns
63 | * capture aliases
64 | * cut rule
65 | * Match objects created lazily
66 | * built-in methods etc.
67 | * :ignorecase
68 | * :sigspace
69 | * :ratchet
70 | * single-quoted literals (without quotes)
71 |
--------------------------------------------------------------------------------
/build/Makefile.in:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2006-2009, The Perl Foundation.
2 | #
3 |
4 | PARROT_ARGS =
5 |
6 | # values from parrot_config
7 | PARROT_BIN_DIR = @bindir@
8 | PARROT_VERSION = @versiondir@
9 | PARROT_INCLUDE_DIR = @includedir@$(PARROT_VERSION)
10 | PARROT_LIB_DIR = @libdir@$(PARROT_VERSION)
11 | PARROT_SRC_DIR = @srcdir@$(PARROT_VERSION)
12 | PARROT_LIBRARY_DIR = $(PARROT_LIB_DIR)/library
13 | HAS_ICU = @has_icu@
14 |
15 | CC = @cc@
16 | CFLAGS = @ccflags@ @cc_shared@ @cc_debug@ @ccwarn@ @cc_hasjit@ @gc_flag@
17 | EXE = @exe@
18 | LD = @ld@
19 | LDFLAGS = @ldflags@ @ld_debug@
20 | LD_LOAD_FLAGS = @ld_load_flags@
21 | LIBPARROT = @inst_libparrot_ldflags@
22 | O = @o@
23 | LOAD_EXT = @load_ext@
24 | PERL = @perl@
25 | CP = @cp@
26 | MV = @mv@
27 | RM_F = @rm_f@
28 | MKPATH = $(PERL) -MExtUtils::Command -e mkpath
29 | CHMOD = $(PERL) -MExtUtils::Command -e chmod
30 |
31 | # locations of parrot resources
32 | PARROT = $(PARROT_BIN_DIR)/parrot$(EXE)
33 | PARROT_NQP = $(PARROT_BIN_DIR)/parrot_nqp$(EXE)
34 | PBC_TO_EXE = $(PARROT_BIN_DIR)/pbc_to_exe$(EXE)
35 | PARROT_TOOLS_DIR = $(PARROT_LIB_DIR)/tools
36 | PARROT_PERL_LIB = $(PARROT_TOOLS_DIR)/lib
37 |
38 | NQP_LANG_DIR = $(PARROT_LIB_DIR)/languages/nqp
39 |
40 | REGEX_SOURCES = \
41 | src/Regex.pir \
42 | src/Regex/constants.pir \
43 | src/Regex/Cursor.pir \
44 | src/Regex/Cursor-builtins.pir \
45 | src/Regex/Cursor-protoregex-peek.pir \
46 | src/Regex/Match.pir \
47 | src/Regex/Method.pir \
48 | src/Regex/Dumper.pir \
49 | src/PAST/Regex.pir \
50 | src/PAST/Compiler-Regex.pir \
51 |
52 | HLL_SOURCES = \
53 | src/HLL.pir \
54 | src/cheats/hll-compiler.pir \
55 | src/cheats/hll-grammar.pir \
56 | src/cheats/parrot-callcontext.pir \
57 | src/HLL/Grammar.pm \
58 | src/HLL/Actions.pm \
59 | src/HLL/Compiler.pm \
60 |
61 | P6REGEX_SOURCES = \
62 | src/Regex/P6Regex.pir \
63 | src/Regex/P6Regex/Grammar.pm \
64 | src/Regex/P6Regex/Actions.pm \
65 |
66 | HLLGRAMMAR_SOURCES = \
67 | src/HLL/Grammar.pm \
68 | src/HLL/Actions.pm \
69 | src/cheats/hll-grammar.pir \
70 |
71 | NQP_SOURCES = \
72 | src/NQP/Grammar.pm \
73 | src/NQP/Actions.pm \
74 | src/NQP/Compiler.pir \
75 |
76 | SETTING_SOURCES = \
77 | src/setting/ResizablePMCArray.pm \
78 | src/setting/Hash.pm \
79 | src/setting/Regex.pm \
80 | src/setting/IO.pm \
81 |
82 | SETTING_NQP = src/gen/nqp-setting.nqp
83 | SETTING_PIR = src/gen/nqp-setting.pir
84 | SETTING_PBC = nqp-setting.pbc
85 |
86 | STAGE0_SOURCES = \
87 | src/stage0/Regex-s0.pir \
88 | src/stage0/HLL-s0.pir \
89 | src/stage0/P6Regex-s0.pir \
90 | src/stage0/NQP-s0.pir
91 |
92 | STAGE0 = src/stage0
93 | STAGE1 = src/stage1
94 | STAGE2 = src/stage2
95 |
96 | REGEX_PBC = Regex.pbc
97 |
98 | HLL_PBC = HLL.pbc
99 | HLLGRAMMAR_G = gen/hllgrammar-grammar.pir
100 | HLLGRAMMAR_A = gen/hllgrammar-actions.pir
101 |
102 | HLLCOMPILER_PIR = gen/hllcompiler.pir
103 |
104 | P6REGEX_PBC = P6Regex.pbc
105 | P6REGEX_G = gen/p6regex-grammar.pir
106 | P6REGEX_A = gen/p6regex-actions.pir
107 |
108 | P6GRAMMAR_PBC = P6Grammar.pbc
109 | P6GRAMMAR_G = gen/p6grammar-grammar.pir
110 | P6GRAMMAR_A = gen/p6grammar-actions.pir
111 |
112 | NQP_PBC = nqp.pbc
113 | NQP_G = gen/nqp-grammar.pir
114 | NQP_A = gen/nqp-actions.pir
115 | NQP_EXE = nqp$(EXE)
116 |
117 | STAGE0_PBCS = $(STAGE0)/$(HLL_PBC) $(STAGE0)/$(P6REGEX_PBC) $(STAGE0)/$(NQP_PBC) $(STAGE0)/$(REGEX_PBC)
118 | STAGE1_PBCS = $(STAGE1)/$(HLL_PBC) $(STAGE1)/$(P6REGEX_PBC) $(STAGE1)/$(NQP_PBC) $(REGEX_PBC)
119 | STAGE2_PBCS = $(STAGE2)/$(HLL_PBC) $(STAGE2)/$(P6REGEX_PBC) $(STAGE2)/$(NQP_PBC) $(REGEX_PBC)
120 | ALL_PBCS = $(HLL_PBC) $(P6REGEX_PBC) $(NQP_PBC)
121 |
122 | CLEANUPS = \
123 | *.manifest \
124 | *.pdb \
125 | $(REGEX_PBC) \
126 | $(HLL_PBC) \
127 | $(P6REGEX_PBC) \
128 | P6Regex$(EXE) \
129 | $(P6GRAMMAR_PBC) \
130 | P6Grammar$(EXE) \
131 | nqp.pbc \
132 | nqp$(EXE) \
133 | *.c\
134 | *.o\
135 | src/stage0/*.pbc \
136 | src/stage1/gen/* \
137 | src/stage1/*.pbc \
138 | src/stage2/gen/* \
139 | src/stage2/*.pbc \
140 | src/gen/*.pir \
141 | src/gen/*.nqp \
142 |
143 | all: $(NQP_EXE) $(SETTING_PBC)
144 |
145 | install: all
146 | $(MKPATH) $(DESTDIR)$(NQP_LANG_DIR)
147 | $(CP) nqp.pbc $(DESTDIR)$(NQP_LANG_DIR)/nqprx.pbc
148 | $(CP) $(P6REGEX_PBC) $(DESTDIR)$(PARROT_LIBRARY_DIR)/$(P6REGEX_PBC)
149 | $(CP) $(REGEX_PBC) $(DESTDIR)$(PARROT_LIBRARY_DIR)/$(REGEX_PBC)
150 | $(CP) $(HLL_PBC) $(DESTDIR)$(PARROT_LIBRARY_DIR)/$(HLL_PBC)
151 | $(MKPATH) $(DESTDIR)$(PARROT_BIN_DIR)
152 | $(CP) $(NQP_EXE) $(DESTDIR)$(PARROT_BIN_DIR)/nqp$(EXE)
153 | $(CHMOD) 755 $(DESTDIR)$(PARROT_BIN_DIR)/nqp$(EXE)
154 |
155 | stage0: $(STAGE0)
156 | stage1: $(STAGE1)
157 | stage2: $(STAGE2)
158 |
159 | $(REGEX_PBC): $(REGEX_SOURCES)
160 | $(PARROT) -o $(REGEX_PBC) $(REGEX_SOURCES)
161 |
162 | $(STAGE0): $(STAGE0_PBCS)
163 |
164 | $(STAGE0_PBCS): $(STAGE0_SOURCES)
165 | $(PARROT) -o $(STAGE0)/$(REGEX_PBC) src/stage0/Regex-s0.pir
166 | $(PARROT) -o $(STAGE0)/$(HLL_PBC) src/stage0/HLL-s0.pir
167 | $(PARROT) -o $(STAGE0)/$(P6REGEX_PBC) src/stage0/P6Regex-s0.pir
168 | $(PARROT) -o $(STAGE0)/$(NQP_PBC) src/stage0/NQP-s0.pir
169 |
170 | $(STAGE1): $(STAGE1_PBCS)
171 |
172 | $(STAGE1)/$(HLL_PBC): $(STAGE0_PBCS) $(HLL_SOURCES)
173 | $(MKPATH) $(STAGE1)/gen
174 | $(PARROT) --library=$(STAGE0) $(STAGE0)/$(NQP_PBC) \
175 | --target=pir --output=$(STAGE1)/$(HLLGRAMMAR_G) \
176 | src/HLL/Grammar.pm
177 | $(PARROT) --library=$(STAGE0) $(STAGE0)/$(NQP_PBC) \
178 | --target=pir --output=$(STAGE1)/$(HLLGRAMMAR_A) \
179 | src/HLL/Actions.pm
180 | $(PARROT) --library=$(STAGE0) $(STAGE0)/$(NQP_PBC) \
181 | --target=pir --output=$(STAGE1)/$(HLLCOMPILER_PIR) \
182 | src/HLL/Compiler.pm
183 | $(PARROT) --include=$(STAGE1) -o $(STAGE1)/$(HLL_PBC) \
184 | src/HLL.pir
185 |
186 | $(STAGE1)/$(P6REGEX_PBC): $(STAGE0_PBCS) $(P6REGEX_SOURCES)
187 | $(MKPATH) $(STAGE1)/gen
188 | $(PARROT) --library=$(STAGE0) $(STAGE0)/$(NQP_PBC) \
189 | --target=pir --output=$(STAGE1)/$(P6REGEX_G) \
190 | src/Regex/P6Regex/Grammar.pm
191 | $(PARROT) --library=$(STAGE0) $(STAGE0)/$(NQP_PBC) \
192 | --target=pir --output=$(STAGE1)/$(P6REGEX_A) \
193 | src/Regex/P6Regex/Actions.pm
194 | $(PARROT) --include=$(STAGE1) -o $(STAGE1)/$(P6REGEX_PBC) \
195 | src/Regex/P6Regex.pir
196 |
197 | $(STAGE1)/$(NQP_PBC): $(STAGE0_PBCS) $(NQP_SOURCES)
198 | $(MKPATH) $(STAGE1)/gen
199 | $(PARROT) --library=$(STAGE0) $(STAGE0)/$(NQP_PBC) \
200 | --target=pir --output=$(STAGE1)/$(NQP_G) \
201 | src/NQP/Grammar.pm
202 | $(PARROT) --library=$(STAGE0) $(STAGE0)/$(NQP_PBC) \
203 | --target=pir --output=$(STAGE1)/$(NQP_A) \
204 | src/NQP/Actions.pm
205 | $(PARROT) --include=$(STAGE1) -o $(STAGE1)/$(NQP_PBC) \
206 | src/NQP/Compiler.pir
207 |
208 | $(STAGE2): $(STAGE2_PBCS)
209 |
210 | $(STAGE2)/$(HLL_PBC): $(STAGE1_PBCS) $(HLL_SOURCES)
211 | $(MKPATH) $(STAGE2)/gen
212 | $(PARROT) --library=$(STAGE1) $(STAGE1)/$(NQP_PBC) \
213 | --target=pir --output=$(STAGE2)/$(HLLGRAMMAR_G) \
214 | src/HLL/Grammar.pm
215 | $(PARROT) --library=$(STAGE1) $(STAGE1)/$(NQP_PBC) \
216 | --target=pir --output=$(STAGE2)/$(HLLGRAMMAR_A) \
217 | src/HLL/Actions.pm
218 | $(PARROT) --library=$(STAGE1) $(STAGE1)/$(NQP_PBC) \
219 | --target=pir --output=$(STAGE2)/$(HLLCOMPILER_PIR) \
220 | src/HLL/Compiler.pm
221 | $(PARROT) --include=$(STAGE2) -o $(STAGE2)/$(HLL_PBC) \
222 | src/HLL.pir
223 |
224 | $(STAGE2)/$(P6REGEX_PBC): $(STAGE1_PBCS) $(P6REGEX_SOURCES)
225 | $(MKPATH) $(STAGE2)/gen
226 | $(PARROT) --library=$(STAGE1) $(STAGE1)/$(NQP_PBC) \
227 | --target=pir --output=$(STAGE2)/$(P6REGEX_G) \
228 | src/Regex/P6Regex/Grammar.pm
229 | $(PARROT) --library=$(STAGE1) $(STAGE1)/$(NQP_PBC) \
230 | --target=pir --output=$(STAGE2)/$(P6REGEX_A) \
231 | src/Regex/P6Regex/Actions.pm
232 | $(PARROT) --include=$(STAGE2) -o $(STAGE2)/$(P6REGEX_PBC) \
233 | src/Regex/P6Regex.pir
234 |
235 | $(STAGE2)/$(NQP_PBC): $(STAGE1_PBCS) $(NQP_SOURCES)
236 | $(MKPATH) $(STAGE2)/gen
237 | $(PARROT) --library=$(STAGE1) $(STAGE1)/$(NQP_PBC) \
238 | --target=pir --output=$(STAGE2)/$(NQP_G) \
239 | src/NQP/Grammar.pm
240 | $(PARROT) --library=$(STAGE1) $(STAGE1)/$(NQP_PBC) \
241 | --target=pir --output=$(STAGE2)/$(NQP_A) \
242 | src/NQP/Actions.pm
243 | $(PARROT) --include=$(STAGE2) -o $(STAGE2)/$(NQP_PBC) \
244 | src/NQP/Compiler.pir
245 |
246 | $(ALL_PBCS): $(REGEX_PBC) $(STAGE2_PBCS)
247 | $(CP) $(STAGE2)/$(HLL_PBC) .
248 | $(CP) $(STAGE2)/$(P6REGEX_PBC) .
249 | $(CP) $(STAGE2)/$(NQP_PBC) .
250 |
251 | $(NQP_EXE): $(NQP_PBC)
252 | $(PBC_TO_EXE) $(NQP_PBC)
253 |
254 | $(SETTING_NQP): $(SETTING_SOURCES)
255 | $(PERL) build/gen_setting.pl $(SETTING_SOURCES) > $(SETTING_NQP)
256 | $(SETTING_PIR): $(SETTING_NQP) $(NQP_PBC)
257 | $(PARROT) $(NQP_PBC) --target=pir -o $(SETTING_PIR) $(SETTING_NQP)
258 | $(SETTING_PBC): $(SETTING_PIR)
259 | $(PARROT) -o $(SETTING_PBC) $(SETTING_PIR)
260 |
261 |
262 | bootstrap-files: $(STAGE2_PBCS) $(SETTING_NQP)
263 | $(PERL) build/gen_bootstrap.pl src/Regex.pir >src/stage0/Regex-s0.pir
264 | $(PERL) build/gen_bootstrap.pl src/HLL.pir >src/stage0/HLL-s0.pir
265 | $(PERL) build/gen_bootstrap.pl src/Regex/P6Regex.pir >src/stage0/P6Regex-s0.pir
266 | $(PERL) build/gen_bootstrap.pl src/NQP/Compiler.pir >src/stage0/NQP-s0.pir
267 | $(PERL) build/gen_bootstrap.pl $(SETTING_NQP) >src/stage0/nqp-setting.nqp
268 |
269 |
270 | ## testing
271 |
272 | test: all core-test setting-test p6regex-test
273 |
274 | test-loud: all core-test-loud setting-test-loud p6regex-test-loud
275 |
276 | core-test: $(NQP_EXE)
277 | prove -r --exec ./$(NQP_EXE) t/nqp t/hll
278 |
279 | core-test-loud: $(NQP_EXE)
280 | prove -r -v --exec ./$(NQP_EXE) t/nqp t/hll
281 |
282 | p6regex-test: $(P6REGEX_PBC)
283 | prove -r --exec $(PARROT) t/p6regex
284 |
285 | p6regex-test-loud: $(P6REGEX_PBC)
286 | prove -r -v --exec $(PARROT) t/p6regex
287 |
288 | setting-test: $(NQP_EXE) $(SETTING_PBC)
289 | prove -r --exec ./$(NQP_EXE) t/setting
290 |
291 | setting-test-loud: $(NQP_EXE) $(SETTING_PBC)
292 | prove -r -v --exec ./$(NQP_EXE) t/setting
293 |
294 | ## cleaning
295 |
296 | clean:
297 | $(RM_F) $(CLEANUPS)
298 |
299 | distclean: realclean
300 |
301 | realclean: clean
302 | $(RM_F) Makefile
303 |
304 | testclean:
305 |
--------------------------------------------------------------------------------
/build/PARROT_REVISION:
--------------------------------------------------------------------------------
1 | RELEASE_3_4_0-266-gfb77d3c
2 |
--------------------------------------------------------------------------------
/build/gen_bootstrap.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | # Copyright (C) 2009, Patrick R. Michaud.
3 |
4 | use strict;
5 | use warnings;
6 |
7 |
8 | foreach my $file (@ARGV) {
9 | make_bootstrap($file);
10 | }
11 |
12 | 0;
13 |
14 | sub make_bootstrap {
15 | my $filename = shift;
16 | open my $fh, '<', $filename or die "Unable to read $filename\n";
17 |
18 | while (<$fh>) {
19 | if (m{^\.include '(src/[^']*)'}) {
20 | print "### $_";
21 | make_bootstrap($1);
22 | }
23 | elsif (m{^\.include '(gen/[^']*)'}) {
24 | print "### $_";
25 | make_bootstrap("src/stage2/$1");
26 | }
27 | else { print; }
28 | }
29 | }
30 |
31 |
32 |
--------------------------------------------------------------------------------
/build/gen_parrot.pl:
--------------------------------------------------------------------------------
1 | #! perl
2 | # Copyright (C) 2009 The Perl Foundation
3 |
4 | =head1 TITLE
5 |
6 | gen_parrot.pl - script to obtain and build Parrot for Rakudo
7 |
8 | =head2 SYNOPSIS
9 |
10 | perl gen_parrot.pl [--parrot --configure=options]
11 |
12 | =head2 DESCRIPTION
13 |
14 | Maintains an appropriate copy of Parrot in the parrot/ subdirectory.
15 | The revision of Parrot to be used in the build is given by the
16 | build/PARROT_REVISION file.
17 |
18 | =cut
19 |
20 | use strict;
21 | use warnings;
22 | use 5.008;
23 |
24 | use lib "build/lib";
25 | use Rakudo::CompareRevisions qw(compare_parrot_revs);
26 |
27 | # Work out slash character to use.
28 | my $slash = $^O eq 'MSWin32' ? '\\' : '/';
29 |
30 | ## determine what revision of Parrot we require
31 | open my $REQ, "build/PARROT_REVISION"
32 | || die "cannot open build/PARROT_REVISION\n";
33 | my ($req, $reqpar) = split(' ', <$REQ>);
34 | close $REQ;
35 |
36 | {
37 | no warnings;
38 | if (open my $REV, '-|', "parrot_install${slash}bin${slash}parrot_config git_describe") {
39 | my $revision = <$REV>;
40 | close $REV;
41 | $revision =~ s/\s.*//s;
42 | if (compare_parrot_revs($revision, $req) >= 0) {
43 | print "Parrot $revision already available ($req required)\n";
44 | exit(0);
45 | }
46 | }
47 | }
48 |
49 | print "Checking out Parrot $req via git...\n";
50 | if (-d 'parrot') {
51 | if (-d 'parrot/.svn') {
52 | die "===SORRY===\n"
53 | ."Your 'parrot' directory is still an SVN repository.\n"
54 | ."Parrot switched to git recently; in order to replace your\n"
55 | ."repository by a git repository, please manually delete\n"
56 | ."the 'parrot' directory, and then re-run the command that caused\n"
57 | ."this error message\n";
58 | }
59 | system_or_die(qw(git fetch));
60 | } else {
61 | system_or_die(qw(git clone git://github.com/parrot/parrot.git parrot));
62 | }
63 |
64 | chdir('parrot') || die "Can't chdir to 'parrot': $!";
65 |
66 | system_or_die(qw(git checkout), $req);
67 |
68 | ## If we have a Makefile from a previous build, do a 'make realclean'
69 | if (-f 'Makefile') {
70 | my %config = read_parrot_config();
71 | my $make = $config{'make'};
72 | if ($make) {
73 | print "\nPerforming '$make realclean' ...\n";
74 | system_or_die($make, "realclean");
75 | }
76 | }
77 |
78 | print "\nConfiguring Parrot ...\n";
79 | my @config_command = ($^X, 'Configure.pl', @ARGV);
80 | print "@config_command\n";
81 | system_or_die( @config_command );
82 |
83 | print "\nBuilding Parrot ...\n";
84 | my %config = read_parrot_config();
85 | my $make = $config{'make'} or exit(1);
86 | system_or_die($make, 'install-dev');
87 |
88 | sub read_parrot_config {
89 | my %config = ();
90 | if (open my $CFG, "config_lib.pir") {
91 | while (<$CFG>) {
92 | if (/P0\["(.*?)"], "(.*?)"/) { $config{$1} = $2 }
93 | }
94 | close $CFG;
95 | }
96 | %config;
97 | }
98 |
99 | sub system_or_die {
100 | my @cmd = @_;
101 |
102 | system( @cmd ) == 0
103 | or die "Command failed (status $?): @cmd\n";
104 | }
105 |
--------------------------------------------------------------------------------
/build/gen_setting.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | # Copyright (C) 2008, The Perl Foundation.
3 | #
4 |
5 | use strict;
6 | use warnings;
7 |
8 | my @files = @ARGV;
9 |
10 | print <<"END_SETTING";
11 | #! nqp
12 |
13 | # This file automatically generated by $0 in the nqp-rx project.
14 |
15 | END_SETTING
16 |
17 | my %classnames;
18 | foreach my $file (@files) {
19 | print "# From $file\n\n";
20 | open(my $fh, "<", $file) or die $!;
21 | local $/;
22 | my $x = <$fh>;
23 | close $fh;
24 | print $x;
25 | }
26 |
27 | print "\n# vim: set ft=perl6 nomodifiable :\n";
28 |
--------------------------------------------------------------------------------
/build/lib/Rakudo/CompareRevisions.pm:
--------------------------------------------------------------------------------
1 | package Rakudo::CompareRevisions;
2 | use strict;
3 | use warnings;
4 |
5 | use base qw(Exporter);
6 | our @EXPORT_OK = qw(compare_parrot_revs parse_parrot_git_describe);
7 |
8 | sub parse_parrot_git_describe {
9 | my $g = shift;
10 | my $sep = qr/[_\W]/;
11 | $g =~ /^REL(?:EASE)?$sep(\d+)$sep(\d+)$sep(\d+)(?:-(\d+)-g[a-f0-9]*)?$/
12 | or die "Invalid revision specifier: '$g' "
13 | ."(expected something of format RELEASE_1_2_3-123-gdeadbee)\n";
14 | my @c = ($1, $2, $3, $4 || 0);
15 | return @c;
16 | }
17 |
18 | sub compare_parrot_revs {
19 | my ($aa, $bb) = @_;
20 | return 1 if $bb =~ /^r?\d+$/;
21 | return -1 if $aa =~ /^r?\d+$/;
22 | my @a = parse_parrot_git_describe($aa);
23 | my @b = parse_parrot_git_describe($bb);
24 | for (0..3) {
25 | my $cmp = $a[$_] <=> $b[$_];
26 | return $cmp if $cmp;
27 | }
28 | return 0;
29 | }
30 |
31 | 1;
32 |
--------------------------------------------------------------------------------
/docs/bootstrapping.pod:
--------------------------------------------------------------------------------
1 | =head1 Bootstrapping procedure for nqp-rx
2 |
3 | NPQ-rx is a bootstrapped compiler, which means that it uses itself to compile
4 | itself.
5 |
6 | To make the first compilation possible, a compiled version of the compiler is
7 | stored in F and included in the source code repository.
8 | Also the parrot virtual machine ships the same
9 | C files.
10 |
11 | When you make changes to the compiler, eventually you need to update these
12 | I files.
13 |
14 | Here is how you proceed to update the bootstrapping files nqp-rx and parrot.
15 | At any stage, if C fails, don't go ahead with the following steps,
16 | but fix the problem first.
17 |
18 | =over
19 |
20 | =item *
21 |
22 | Make your changes, run C
23 |
24 | =item *
25 |
26 | Run C and C
27 |
28 | =item *
29 |
30 | Commit the non-bootstrap files that you modified yourself
31 |
32 | =item *
33 |
34 | Commit the bootstrap files
35 |
36 | =item *
37 |
38 | Copy the I files over to parrot:
39 |
40 | cp src/stage0/*.pir $PARROT_SRC/ext/nqp-rx/src/stage0
41 |
42 | =item *
43 |
44 | In the parrot source, run C and commit
45 |
46 | =back
47 |
48 | References: L
49 |
--------------------------------------------------------------------------------
/examples/fib.nqp:
--------------------------------------------------------------------------------
1 | #! nqp
2 |
3 | sub fib($n) {
4 | $n < 2 ?? $n !! fib($n-1) + fib($n - 2);
5 | }
6 |
7 | my $N := 29;
8 |
9 | my $t0 := pir::time__N();
10 | my $z := fib($N);
11 | my $t1 := pir::time__N();
12 |
13 | pir::say("fib($N) = " ~ fib($N));
14 | pir::say("time = " ~ ($t1-$t0));
15 |
--------------------------------------------------------------------------------
/examples/hello_world.nqp:
--------------------------------------------------------------------------------
1 | #!nqp
2 |
3 | say("Hello, awesome Not Quite Perl 6 World!");
4 |
--------------------------------------------------------------------------------
/examples/json.nqp:
--------------------------------------------------------------------------------
1 | #! nqp
2 |
3 | # A JSON compiler written in NQP. To use this compiler, first
4 | # precompile the code to PIR, then run that:
5 | #
6 | # $ nqp --target=pir json.nqp >json.pir
7 | # $ parrot json.pir
8 | #
9 | # It can then be turned into a .pbc to be available as load_language:
10 | #
11 | # $ parrot -o json.pbc json.pir
12 | # $ cp json.pbc /lib//languages
13 | #
14 |
15 | INIT {
16 | pir::load_bytecode('P6Regex.pbc');
17 | pir::load_bytecode('dumper.pbc');
18 | }
19 |
20 | grammar JSON::Grammar is HLL::Grammar {
21 | rule TOP { }
22 |
23 | proto token value { <...> }
24 |
25 | token value:sym { }
26 |
27 | token value:sym {
28 | '-'?
29 | [ <[1..9]> <[0..9]>+ | <[0..9]> ]
30 | [ '.' <[0..9]>+ ]?
31 | [ <[Ee]> <[+\-]>? <[0..9]>+ ]?
32 | }
33 |
34 | rule value:sym {
35 | '[' [ ** ',' ]? ']'
36 | }
37 |
38 | rule value:sym