Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Merge remote branch 'bacek/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Apr 28, 2010
2 parents d823fc2 + 8600657 commit 4271e79
Show file tree
Hide file tree
Showing 17 changed files with 565 additions and 21 deletions.
34 changes: 32 additions & 2 deletions build/Makefile.in
Expand Up @@ -78,6 +78,13 @@ STAGE0_SOURCES = \
src/stage0/P6Regex-s0.pir \
src/stage0/NQP-s0.pir

SETTINGS_SOURCES = \
src/settings/Array.pm \
src/settings/Functions.pm \
src/settings/Hash.pm \
src/settings/String.pm \
src/settings/IO.pm

STAGE0 = src/stage0
STAGE1 = src/stage1
STAGE2 = src/stage2
Expand All @@ -103,6 +110,10 @@ NQP_G = gen/nqp-grammar.pir
NQP_A = gen/nqp-actions.pir
NQP_EXE = nqp$(EXE)

SETTINGS_PBC = nqp-settings.pbc
SETTINGS_GEN = src/gen/settings.pm
SETTINGS_PIR = src/gen/settings.pir

STAGE0_PBCS = $(STAGE0)/$(HLL_PBC) $(STAGE0)/$(P6REGEX_PBC) $(STAGE0)/$(NQP_PBC) $(STAGE0)/$(REGEX_PBC)
STAGE1_PBCS = $(STAGE1)/$(HLL_PBC) $(STAGE1)/$(P6REGEX_PBC) $(STAGE1)/$(NQP_PBC) $(REGEX_PBC)
STAGE2_PBCS = $(STAGE2)/$(HLL_PBC) $(STAGE2)/$(P6REGEX_PBC) $(STAGE2)/$(NQP_PBC) $(REGEX_PBC)
Expand All @@ -114,6 +125,7 @@ CLEANUPS = \
$(REGEX_PBC) \
$(HLL_PBC) \
$(P6REGEX_PBC) \
$(SETTINGS_PBC) \
P6Regex$(EXE) \
$(P6GRAMMAR_PBC) \
P6Grammar$(EXE) \
Expand All @@ -127,15 +139,17 @@ CLEANUPS = \
src/stage2/gen/* \
src/stage2/*.pbc \
src/gen/*.pir \
src/gen/*.pm

all: $(NQP_EXE)
all: $(NQP_EXE) $(SETTINGS_PBC)

install: all
$(MKPATH) $(DESTDIR)$(NQP_LANG_DIR)
$(CP) nqp.pbc $(DESTDIR)$(NQP_LANG_DIR)/nqprx.pbc
$(CP) $(P6REGEX_PBC) $(DESTDIR)$(PARROT_LIBRARY_DIR)/$(P6REGEX_PBC)
$(CP) $(REGEX_PBC) $(DESTDIR)$(PARROT_LIBRARY_DIR)/$(REGEX_PBC)
$(CP) $(HLL_PBC) $(DESTDIR)$(PARROT_LIBRARY_DIR)/$(HLL_PBC)
$(CP) $(SETTINGS_PBC) $(DESTDIR)$(PARROT_LIBRARY_DIR)/$(SETTINGS_PBC)
$(MKPATH) $(DESTDIR)$(PARROT_BIN_DIR)
$(CP) $(NQP_EXE) $(DESTDIR)$(PARROT_BIN_DIR)/nqp$(EXE)
$(CHMOD) 755 $(DESTDIR)$(PARROT_BIN_DIR)/nqp$(EXE)
Expand Down Expand Up @@ -239,6 +253,16 @@ $(ALL_PBCS): $(REGEX_PBC) $(STAGE2_PBCS)
$(NQP_EXE): $(NQP_PBC)
$(PBC_TO_EXE) $(NQP_PBC)

$(SETTINGS_GEN): $(SETTINGS_SOURCES)
$(PERL) build/gen_settings.pl $(SETTINGS_SOURCES) > $(SETTINGS_GEN)

$(SETTINGS_PIR): $(SETTINGS_GEN) $(NQP_PBC)
$(PARROT) $(NQP_PBC) --target=pir -o $(SETTINGS_PIR) $(SETTINGS_GEN)

$(SETTINGS_PBC): $(SETTINGS_PIR)
$(PARROT) -o $(SETTINGS_PBC) $(SETTINGS_PIR)


bootstrap-files: $(STAGE2_PBCS)
$(PERL) build/gen_bootstrap.pl src/Regex.pir >src/stage0/Regex-s0.pir
$(PERL) build/gen_bootstrap.pl src/HLL.pir >src/stage0/HLL-s0.pir
Expand All @@ -250,7 +274,7 @@ bootstrap-files: $(STAGE2_PBCS)

test: core-test

test-loud: core-test-loud p6regex-test-loud
test-loud: core-test-loud p6regex-test-loud settings-test-loud

core-test: $(NQP_EXE)
prove -r --exec ./$(NQP_EXE) t/nqp t/hll
Expand All @@ -264,6 +288,12 @@ p6regex-test: $(P6REGEX_PBC)
p6regex-test-loud: $(P6REGEX_PBC)
prove -r -v --exec $(PARROT) t/p6regex

settings-test: $(SETTINGS_PBC) $(NQP_EXE)
prove -r --exec ./$(NQP_EXE) t/settings

settings-test-loud: $(SETTINGS_PBC) $(NQP_EXE)
prove -r -v --exec ./$(NQP_EXE) t/settings

## cleaning

clean:
Expand Down
26 changes: 26 additions & 0 deletions build/gen_settings.pl
@@ -0,0 +1,26 @@
#!/usr/bin/perl
# Copyright (C) 2008, The Perl Foundation.
# $Id$

use strict;
use warnings;

my @files = @ARGV;

print <<"END_SETTING";

# This file automatically generated by $0.

END_SETTING

my %classnames;
foreach my $file (@files) {
print "# From $file\n\n";
open(my $fh, "<", $file) or die $!;
local $/;
my $x = <$fh>;
close $fh;
print $x;
}

print "\n# vim: set ft=perl6 nomodifiable :\n";
2 changes: 1 addition & 1 deletion src/Regex/Cursor-protoregex-peek.pir
Expand Up @@ -82,7 +82,7 @@ Perform a match for protoregex C<name>.
cand_done:
token_next:
unless token > '' goto fail
chopn token, 1
token = chopn token, 1
goto token_loop

done:
Expand Down
2 changes: 1 addition & 1 deletion src/Regex/P6Regex/Actions.pm
Expand Up @@ -383,7 +383,7 @@ method assertion:sym<name>($/) {
$I0 = index $S0, ':sym<'
add $I0, 5
$S0 = substr $S0, $I0
chopn $S0, 1
$S0 = chopn $S0, 1
%r = box $S0
};
$past := PAST::Regex.new(
Expand Down
2 changes: 1 addition & 1 deletion src/cheats/hll-compiler.pir
Expand Up @@ -81,7 +81,7 @@
sigil = substr $S0, 0, 1
$I0 = index '$@%&', sigil
if $I0 < 0 goto sigil_done
substr $S0, 0, 1, ''
$S0 = replace $S0, 0, 1, ''
ns[0] = $S0
$S0 = ns[-1]
$S0 = concat sigil, $S0
Expand Down
2 changes: 1 addition & 1 deletion src/cheats/hll-grammar.pir
Expand Up @@ -337,7 +337,7 @@ position C<pos>.
.end


.sub 'quotemod_check' :method
.sub 'quotemod_check' :method :nsentry
.param string mod

$P0 = find_dynamic_lex '%*QUOTEMOD'
Expand Down
60 changes: 60 additions & 0 deletions src/settings/Array.pm
@@ -0,0 +1,60 @@
=begin

=head2 Array Methods
These methods extend the native NQP Array class to support more of the basic
functionality expected for Perl 6 Hashes.

=end

module ResizablePMCArray {


=begin

=over 4
=item @reversed := @array.reverse
Return a C<@reversed> copy of the C<@array>.

=end

method reverse () {
my @reversed;
for self { @reversed.unshift($_); }
@reversed;
}

=begin

=item $string := @array.join($join_string)
Join C<@array> using C<$join_string>

=end

method join ($join_string) {
return Q:PIR{
$P0 = find_lex '$join_string'
$S0 = $P0
$S1 = join $S0, self
%r = box $S1
}
}
=begin
=back
=end
}
sub join($join_string, *@list) { @list.join($join_string) }
sub list(*@list) { @list };
# vim: ft=perl6
111 changes: 111 additions & 0 deletions src/settings/Functions.pm
@@ -0,0 +1,111 @@
#! nqp

=begin

=head2 Basic Functions
These functions provide basic functionality that would be part of the standard
setting in Perl 6, but are not provided with NQP by default.

=over 4
=item @mapped := map(&code, @originals)
Pretty much as you would expect, except there is no flattening or other
coersion, due to the current semantics of NQP. This means that every
application of C<&code> to an item in the C<@originals> produces exactly
one entry in the C<@mapped> output.

=end

sub map (&code, @originals) {
my @mapped;

for @originals {
@mapped.push(&code($_));
}

return @mapped;
}


=begin

=item @matches := grep(&code, @all)
Select all members of C<@all> for which C<&code($member)> returns true.
Order is retained, and duplicates are handled independently.

=end

sub grep (&code, @all) {
my @matches;

for @all {
@matches.push($_) if &code($_);
}

return @matches;
}


=begin

=item $result := reduce(&code, @array, $initial?)
Loop over the C<@array>, applying the binary function C<&code> to the current
C<$result> and next element of the C<@array>, each time saving the return
value of the C<&code> as the new C<$result>. When all elements of the array
have been processed, the last C<$result> computed is returned.

If an C<$initial> value is supplied, it is used as the starting value for
C<$result> when iterating over the C<@array>. This automatically works with
any length C<@array>, even an empty one.

Without an C<$initial> value, C<reduce()> applies the C<&code> to the first two
elements in the C<@array> to determine the inital C<$result> (and skips these
first two elements when looping). If the C<@array> has only one element, it
is returned directly as the final C<$result>. If the C<@array> is empty, the
C<$result> is an undefined value.

=end

sub reduce (&code, @array, *@initial) {
my $init_elems := pir::elements(@initial);
if $init_elems > 1 {
pir::die('Only one initial value allowed in reduce()');
}
elsif $init_elems == 1 {
return _reduce(&code, @array, @initial[0]);
}
else {
my $array_elems := pir::elements(@array);
if $array_elems == 0 {
return my $undef;
}
elsif $array_elems == 1 {
return @array[0];
}
else {
my $initial := &code(@array[0], @array[1]);
my $iter := pir::iter__PP(@array);

pir::shift($iter);
pir::shift($iter);

return _reduce(&code, $iter, $initial);
}
}
}

sub _reduce(&code, $iter, $initial) {
my $result := $initial;

for $iter {
$result := &code($result, $_);
}

return $result;
}

# vim: ft=perl6

0 comments on commit 4271e79

Please sign in to comment.