[svn:parrot] r38350 - in branches/pmc_pct: compilers/pmc compilers/pmc/src compilers/pmc/src/parser config/gen/makefiles
bacek at svn.parrot.org
bacek at svn.parrot.org
Sat Apr 25 10:41:45 UTC 2009
Author: bacek
Date: Sat Apr 25 10:41:44 2009
New Revision: 38350
URL: https://trac.parrot.org/parrot/changeset/38350
Log:
Initial implementation of PAST creating.
Added:
branches/pmc_pct/compilers/pmc/src/nodes.pir
Modified:
branches/pmc_pct/compilers/pmc/README.pod
branches/pmc_pct/compilers/pmc/pmc.pir
branches/pmc_pct/compilers/pmc/src/parser/actions.pm
branches/pmc_pct/config/gen/makefiles/pmc.in
Modified: branches/pmc_pct/compilers/pmc/README.pod
==============================================================================
--- branches/pmc_pct/compilers/pmc/README.pod Sat Apr 25 10:33:46 2009 (r38349)
+++ branches/pmc_pct/compilers/pmc/README.pod Sat Apr 25 10:41:44 2009 (r38350)
@@ -16,6 +16,16 @@
=back
+Implemented (fsvo) PAST nodes.
+
+=over 4
+
+=item C<PAST::PMC>
+
+PMC class by it self. Contains C<@traits>, C<@parents>, C<@vtable> methods and C<@method>s.
+
+=back
+
=head1 AUTHORS
Vasily "bacek" Chekalkin is creator of initial version.
Modified: branches/pmc_pct/compilers/pmc/pmc.pir
==============================================================================
--- branches/pmc_pct/compilers/pmc/pmc.pir Sat Apr 25 10:33:46 2009 (r38349)
+++ branches/pmc_pct/compilers/pmc/pmc.pir Sat Apr 25 10:41:44 2009 (r38350)
@@ -21,6 +21,7 @@
.tailcall $P0.'command_line'(args, 'encoding'=>'utf8', 'transcode'=>'ascii')
.end
+.include 'src/nodes.pir'
.include 'src/parser/gen_grammar.pir'
.include 'src/parser/gen_actions.pir'
.include 'src/builtins.pir'
Added: branches/pmc_pct/compilers/pmc/src/nodes.pir
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/pmc_pct/compilers/pmc/src/nodes.pir Sat Apr 25 10:41:44 2009 (r38350)
@@ -0,0 +1,138 @@
+# $Id$
+
+=head1 NAME
+
+PAST - Parrot abstract syntax tree for PMC.
+
+=head1 DESCRIPTION
+
+PAST nodes for PMC.
+
+=cut
+
+.sub '' :anon :load :init
+ ## create the classes
+ .local pmc p6meta
+ p6meta = new 'P6metaclass'
+
+ p6meta.'new_class'('PMC::Class', 'parent'=>'PAST::Node')
+
+ .return ()
+.end
+
+=head1 NODES
+
+=head2 C<PMC::Class>
+
+PMC class by it self.
+
+=cut
+
+.namespace [ 'PMC';'Class' ]
+
+.sub 'new' :method
+ .param pmc children :slurpy
+ .param pmc adverbs :slurpy :named
+
+ .local pmc res
+ $P0 = self.'HOW'()
+ $P0 = getattribute $P0, 'parrotclass'
+ res = new $P0
+ res.'init'(children :flat, adverbs :flat :named)
+
+ # Initialize various attributes
+ $P3 = new 'ResizableStringArray'
+ res.'attr'('parents', $P3, $I0)
+
+ $P4 = new 'Hash'
+ res.'attr'('vtables', $P4, $I0)
+
+ $P5 = new 'Hash'
+ res.'attr'('methods', $P5, $I0)
+
+ $P6 = new 'ResizableStringArray'
+ res.'attr'('provides', $P6, $I0)
+
+ .return (res)
+.end
+
+=item C<parents>
+
+Get PMC parents.
+
+=cut
+
+.sub 'parents' :method
+ .tailcall self.'attr'('parents',0,0)
+.end
+
+=item C<vtables>
+
+Get PMC vtable methods.
+
+=cut
+
+.sub 'vtables' :method
+ .tailcall self.'attr'('vtables',0,0)
+.end
+
+=item C<methods>
+
+Get PMC methods.
+
+=cut
+
+.sub 'methods' :method
+ .tailcall self.'attr'('methods',0,0)
+.end
+
+=item C<provides>
+
+Get PMC provided interfaces.
+
+=cut
+
+.sub 'provides' :method
+ .tailcall self.'attr'('provides',0,0)
+.end
+
+
+=item C<set_trait>
+
+Set boolean trait
+
+=cut
+
+.sub 'trait' :method
+ .param string name
+ .param int value :optional
+ .param int has_value :opt_flag
+ .tailcall self.'attr'(name, value, has_value)
+.end
+
+=item C<add_vtable>
+
+Add VTABLE method to PMC.
+
+=cut
+
+.sub 'add_vtable' :method
+ .param string name
+ .param pmc method
+
+ $P0 = self.'attr'('vtables', 0, 0)
+ $P0[name] = method
+ .return ()
+.end
+
+=head1 COPYRIGHT
+
+Copyright (C) 2009, Parrot Foundation.
+
+=cut
+
+# Local Variables:
+# mode: pir
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:
Modified: branches/pmc_pct/compilers/pmc/src/parser/actions.pm
==============================================================================
--- branches/pmc_pct/compilers/pmc/src/parser/actions.pm Sat Apr 25 10:33:46 2009 (r38349)
+++ branches/pmc_pct/compilers/pmc/src/parser/actions.pm Sat Apr 25 10:41:44 2009 (r38350)
@@ -8,10 +8,17 @@
make $( $<pmc> );
}
-method pmc($/) {
- #say("pmc");
- my $pmc := PAST::Block.new( :blocktype('declaration'), :node($/) );
- make $pmc;
+method pmc($/, $key) {
+ our $?PMC;
+
+ if $key eq 'begin' {
+ $?PMC := PMC::Class.new(
+ :name(~$<identifier>)
+ );
+ }
+ else {
+ make $?PMC;
+ }
}
method c_header($/) {
@@ -21,14 +28,45 @@
make $past;
}
-method pmc_class($/) {
- my $past := PAST::Block.new( :blocktype('declaration'), :node($/) );
- make $past;
+method traits($/, $key) {
+ our $?PMC;
+
+ #say("traits " ~$/);
+ if $key eq 'extends' {
+ $?PMC.parents().push(~$<identifier>);
+ }
+ elsif $key eq 'provides' {
+ }
+ elsif $key eq 'group' {
+ }
+ elsif $key eq 'lib' {
+ }
+ else {
+ $?PMC.trait(~$/, 1);
+ }
+}
+
+method body_part($/, $key) {
+ our $?PMC;
+
+ my $m := $/{$key}.ast;
+ if $key eq 'vtable' {
+ $?PMC.add_vtable($m.name, $m);
+ }
+ elsif $key eq 'method' {
+ }
}
method vtable($/) {
- #say('VABLE ' ~$<c_signature>);
- my $past := PAST::Block.new( :blocktype('declaration'), :node($/) );
+ #say('VABLE ' ~$<c_signature><identifier>);
+ my $past := PAST::Block.new(
+ :name(~$<c_signature><identifier>),
+ :blocktype('method'),
+ :node($/),
+ PAST::Op.new(
+ :inline(~$<c_body>)
+ )
+ );
make $past;
}
@@ -44,12 +82,6 @@
make $past;
}
-method body($/) {
- #say("body");
- my $past := PAST::Block.new( :blocktype('declaration'), :node($/) );
- make $past;
-}
-
method c_body($/) {
#say("c_body: " ~ $/);
my $past := PAST::Block.new( :blocktype('declaration'), :node($/) );
Modified: branches/pmc_pct/config/gen/makefiles/pmc.in
==============================================================================
--- branches/pmc_pct/config/gen/makefiles/pmc.in Sat Apr 25 10:33:46 2009 (r38349)
+++ branches/pmc_pct/config/gen/makefiles/pmc.in Sat Apr 25 10:41:44 2009 (r38350)
@@ -18,6 +18,7 @@
pmc.pir \
src/parser/gen_grammar.pir \
src/parser/gen_actions.pir \
+ src/nodes.pir \
src/builtins.pir
# the default target
More information about the parrot-commits
mailing list