Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:rakudo/rakudo
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Apr 3, 2009
2 parents 903a782 + 881ed3d commit fff26a1
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 208 deletions.
1 change: 1 addition & 0 deletions build/Makefile.in
Expand Up @@ -119,6 +119,7 @@ SETTING = \
src/setting/Match.pm \
src/setting/Object.pm \
src/setting/Pair.pm \
src/setting/Range.pm \
src/setting/Str.pm \
src/setting/Whatever.pm \

Expand Down
96 changes: 67 additions & 29 deletions docs/compiler_overview.pod
Expand Up @@ -12,20 +12,20 @@ The Rakudo compiler is constructed from four major components:

=item 1.

the parse grammar (src/parser/grammar.pg, src/parser/*.pir)
The main compiler object (perl6.pir)

=item 2.

a set of action methods to transform the parse tree into an abstract syntax
tree (src/parser/actions.pm)
The parse grammar (src/parser/grammar.pg, src/parser/*.pir)

=item 3.

the main compiler object (perl6.pir)
A set of action methods to transform the parse tree into an abstract syntax
tree (src/parser/actions.pm)

=item 4.

builtin functions and runtime support (src/setting/, src/builtins/,
Builtin functions and runtime support (src/setting/, src/builtins/,
src/classes/, src/pmc/)

=back
Expand All @@ -34,6 +34,26 @@ The F<Makefile> takes care of compiling all of the individual
components into compiled form and linking them together to
form the F<perl6.pbc> executable.


=head2 Main compiler

The Perl 6 compiler object itself, in F<perl6.pir>, drives the parsing and
action methods. The compiler is an instance of C<PCT::HLLCompiler>, which
provides a standard framework for parsing, optimization, and command line
argument handling for Parrot compilers. The C<onload> subroutine in
F<perl6.pir> simply creates a new C<PCT::HLLCompiler> object, registers it as
the C<Perl6> compiler, and sets it to use the C<Perl6::Grammar> and
C<Perl6::Grammar::Actions> classes defined above.

The C<main> subroutine in perl6.pir is used when Rakudo is invoked
from the command line -- it simply passes control to the C<Perl6>
compiler object registered by the C<onload> subroutine.

Lastly, the C<perl6.pir> source uses PIR C<.include> directives
to pull in the PIR sources for the parse grammar, action methods,
and runtime builtin functions.


=head2 Parse grammar

The parse grammar is written using a mix of Perl 6 regular
Expand Down Expand Up @@ -71,12 +91,13 @@ rule in the grammar.

=head2 Action methods

The action methods (in F<src/parser/actions.pm>) are used to
convert the nodes of the parse tree (produced by the parse grammar)
into an equivalent abstract syntax tree (PAST) representation. The
action methods are where the Rakudo compiler does the bulk of the work
of creating an executable program. Action methods are written in
Perl 6, but we use NQP to compile them into PIR as F<src/gen_actions.pir>.
The action methods (in F<src/parser/actions.pm>) are used to convert the nodes
of the parse tree (produced by the parse grammar) into an equivalent Parrot
Abstract Syntax Tree (PAST) representation, which is then passed on to Parrot.

The action methods are where the Rakudo compiler does the bulk of the work of
creating an executable program. Action methods are written in Perl 6, but we
use NQP to compile them into PIR as F<src/gen_actions.pir>.

When Rakudo is compiling a Perl 6 program, action methods are invoked
by the C< {*} > symbols in the parse grammar. Each C< {*} > in a rule
Expand Down Expand Up @@ -166,24 +187,41 @@ NQP can't or won't support, then that will probably be a good
point to switch.)


=head2 Main compiler
=head2 How a program is executed by the compiler

Driving the parser and action methods is the Perl 6 compiler
object itself, in F<perl6.pir>. The compiler is an instance of
C<PCT::HLLCompiler>, which provides a standard framework for
parsing, optimization, and command line argument handling for
Parrot compilers. The C<onload> subroutine in F<perl6.pir>
simply creates a new C<PCT::HLLCompiler> object, registers it
as the C<Perl6> compiler, and sets it to use the C<Perl6::Grammar>
and C<Perl6::Grammar::Actions> classes defined above.
This is a rough outline of how Rakudo executes a program.

The C<main> subroutine in perl6.pir is used when Rakudo is invoked
from the command line -- it simply passes control to the C<Perl6>
compiler object registered by the C<onload> subroutine.
=over 4

Lastly, the C<perl6.pir> source uses PIR C<.include> directives
to pull in the PIR sources for the parse grammar, action methods,
and runtime builtin functions.
=item 1.

The main compiler object (perl6.pir) looks at any parameters and slurps in your program.

=item 2.

The program passes through the parser (as defined in the parse grammar
(src/parser/grammar.pg, src/parser/*.pir). This outputs the parse tree.

=item 3.

Action methods transform the parse tree into a Parrot Abstract Syntax
Tree (PAST).

=item 4.

The PAST is provided to Parrot, which does its thing.

=item 5.

The PAST includes references to builtin functions and runtime support. These
are also provided to Parrot.

=back

The PAST representation is the
final stage of processing in Rakudo itself. The PAST datastructure is then
passed on to Parrot directly. Parrot does the remainder of the work translating
from PAST to pir and then to bytecode.


=head2 Builtin functions and runtime support
Expand All @@ -209,9 +247,9 @@ Perl 6 program would expect to have available when it is run.

=head2 Still to be documented

* Rakudo PMCs
* The relationship between Parrot classes and Rakudo classes
* Protoobject implementation and basic class hierarchy
* Rakudo PMCs
* The relationship between Parrot classes and Rakudo classes
* Protoobject implementation and basic class hierarchy

=head1 AUTHORS

Expand Down
1 change: 1 addition & 0 deletions docs/spectest-progress.csv
Expand Up @@ -315,3 +315,4 @@
"2009-03-31 00:00",c015556,8039,0,340,1819,10198,15518,339
"2009-04-01 00:00",78cb4c3,8049,0,342,1819,10210,15518,340
"2009-04-02 00:00",64e33af,8049,0,342,1819,10210,15518,340
"2009-04-03 00:00",913094f,8081,0,342,1816,10239,15534,344
181 changes: 2 additions & 179 deletions src/classes/Range.pir
Expand Up @@ -13,97 +13,14 @@ src/classes/Range.pir - methods for the Range class
.sub '' :anon :load :init
.local pmc p6meta, rangeproto
p6meta = get_hll_global ['Perl6Object'], '$!P6META'
rangeproto = p6meta.'new_class'('Range', 'parent'=>'Any', 'attr'=>'$!from $!to $!from_exclusive $!to_exclusive')
rangeproto = p6meta.'new_class'('Range', 'parent'=>'Any', 'attr'=>'$!by $!from $!to $!from_exclusive $!to_exclusive')
rangeproto.'!IMMUTABLE'()
.end

=head2 Methods

=over 4

=item ACCEPTS(topic)

Determines if topic is within the range or equal to the range.

=cut

.sub 'ACCEPTS' :method
.param pmc topic

$I0 = isa topic, 'Range'
unless $I0 goto value_in_range_check
$I0 = self.'from'()
$I1 = topic.'from'()
if $I0 != $I1 goto false
$I0 = self.'to'()
$I1 = topic.'to'()
if $I0 != $I1 goto false
$P0 = getattribute self, "$!from_exclusive"
$P1 = getattribute topic, "$!from_exclusive"
if $P0 != $P1 goto false
$P0 = getattribute self, "$!to_exclusive"
$P1 = getattribute topic, "$!to_exclusive"
if $P0 != $P1 goto false
goto true

value_in_range_check:
$I0 = self.'!from_test'(topic)
unless $I0 goto false
$I0 = self.'!to_test'(topic)
unless $I0 goto false

true:
$P0 = get_hll_global ['Bool'], 'True'
.return ($P0)
false:
$P0 = get_hll_global ['Bool'], 'False'
.return ($P0)
.end


=item clone() (vtable method)

Create a clone of the Range.

=cut

.sub 'clone' :method :vtable
$P0 = self.'!cloneattr'('$!from $!to $!from_exclusive $!to_exclusive')
.return ($P0)
.end

=item from()

=item to()

Gets the beginning or end of the range.

=cut

.sub 'from' :method
$P0 = getattribute self, '$!from'
.return ($P0)
.end

.sub 'to' :method
$P0 = getattribute self, '$!to'
.return ($P0)
.end


=item iterator() (vtable function)

Return an iterator for the Range. Since Ranges are already
iterators, we can just return a clone.

=cut

.sub 'iterator' :method :vtable('get_iter')
$P0 = clone self
.return ($P0)
.end


=item list()

Generate the Range in list context. Currently we generate all
Expand All @@ -126,65 +43,13 @@ just return a clone of the Range.
.end


=item max()

=item min()

=item minmax()

=cut

.namespace ['Range']

.sub 'max' :method
.tailcall self.'to'()
.end

.sub 'min' :method
.tailcall self.'from'()
.end

.sub 'minmax' :method
$P0 = self.'from'()
$P1 = self.'to'()
$P2 = get_hll_global 'list'
.tailcall $P2($P0, $P1)
.end


=item perl()

Returns a Perl representation of the Range.

=cut

.sub 'perl' :method
.local string result, tmp
.local pmc from, fromexc, toexc, to
from = getattribute self, '$!from'
fromexc = getattribute self, '$!from_exclusive'
toexc = getattribute self, '$!to_exclusive'
to = getattribute self, '$!to'
result = from.'perl'()
unless fromexc goto dots
result .= '^'
dots:
result .= '..'
unless toexc goto end
result .= '^'
end:
tmp = to.'perl'()
result .= tmp
.return (result)
.end


=item pop() (vtable_method)

Generate the next element at the end of the Range.

=cut

.namespace ['Range']
.sub 'pop' :method :vtable('pop_pmc')
.local pmc to, toexc, value
to = getattribute self, '$!to'
Expand All @@ -201,21 +66,6 @@ Generate the next element at the end of the Range.
.end


=item reverse()

Generate the range in reverse sequence. (This is wrong for now--
really what should happen is that we invert .from and .to and
switch the :by argument.)

=cut

.namespace ['Range']
.sub 'reverse' :method
$P0 = self.'list'()
.tailcall $P0.'reverse'()
.end


=item shift() (vtable_method)

Generate the next element at the front of the Range.
Expand All @@ -238,25 +88,6 @@ Generate the next element at the front of the Range.
.end


=item true()

Return true if there are any more values to iterate over.

=cut

.sub 'true' :method :vtable('get_bool')
.local pmc from, fromexc
from = getattribute self, '$!from'
fromexc = getattribute self, '$!from_exclusive'
unless fromexc goto have_value
from = clone from
'postfix:++'(from)
have_value:
$I0 = self.'!to_test'(from)
.return ($I0)
.end
=back

=head2 Operators
Expand Down Expand Up @@ -405,8 +236,6 @@ honoring exclusive flags.

=item VTABLE_get_number (vtable method)

=item VTABLE_get_string (vtable method)
=cut

.sub '' :method :vtable('get_integer')
Expand All @@ -421,12 +250,6 @@ honoring exclusive flags.
.return ($N0)
.end

.sub '' :method :vtable('get_string')
$P0 = self.'list'()
$S0 = $P0
.return ($S0)
.end
=back

=cut
Expand Down

0 comments on commit fff26a1

Please sign in to comment.