[svn:parrot] r39375 - in branches/pmc_pct: compilers/vtdumper compilers/vtdumper/src compilers/vtdumper/src/parser config/gen/makefiles
cotto at svn.parrot.org
cotto at svn.parrot.org
Thu Jun 4 02:05:33 UTC 2009
Author: cotto
Date: Thu Jun 4 02:05:33 2009
New Revision: 39375
URL: https://trac.parrot.org/parrot/changeset/39375
Log:
[vtdumper] implement actions.pm for the vtable.tbl compiler
Added:
branches/pmc_pct/compilers/vtdumper/src/function.pir
Modified:
branches/pmc_pct/compilers/vtdumper/src/parser/actions.pm
branches/pmc_pct/compilers/vtdumper/src/parser/grammar.pg
branches/pmc_pct/compilers/vtdumper/vtdumper.pir
branches/pmc_pct/config/gen/makefiles/vtdumper.in
Added: branches/pmc_pct/compilers/vtdumper/src/function.pir
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/pmc_pct/compilers/vtdumper/src/function.pir Thu Jun 4 02:05:33 2009 (r39375)
@@ -0,0 +1,123 @@
+# $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'('VTable::Function', 'parent'=>'PAST::Node')
+
+ .return ()
+.end
+
+=head1 NODES
+
+=head2 C<VTable::Function>
+
+PAST node representing one VTABLE function
+
+=cut
+
+.namespace [ 'VTable';'Function' ]
+
+.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
+ $P1 = new 'ResizablePMCArray'
+ res.'attr'('arguments', $P1, 1)
+
+ $P1 = new 'ResizableStringArray'
+ res.'attr'('attributes', $P1, 1)
+
+ $P1 = new 'String'
+ res.'attr'('section', $P1, 1)
+
+ .return (res)
+.end
+
+=item C<add_argument>
+
+Add a function argument to PMC.
+
+=cut
+
+.sub 'add_argument' :method
+ .param pmc argument
+
+ $P0 = self.'attr'('arguments', 0, 0)
+ push $P0, argument
+ done:
+ .return ()
+.end
+
+=item C<add_attribute>
+
+Add an attribute to this VTABLE function, checking for duplicates.
+
+=cut
+
+.sub 'add_attribute' :method
+ .param string name
+
+ .local pmc it, key
+ .local string s_key
+
+ $P0 = self.'attr'('attributes', 0, 0)
+ it = iter $P0
+ iter_loop:
+ unless it goto iter_done
+ key = shift it
+ s_key = key
+ eq name, s_key, done
+ unless $I0 goto done
+ goto iter_loop
+ iter_done:
+ push $P0, name
+ done:
+ .return ()
+.end
+
+=item C<set_section>
+
+Set the section where this VTABLE function lives.
+
+=cut
+
+.sub 'set_section' :method
+ .param string name
+
+ $P0 = self.'attr'('section', 0, 0)
+ $P0 = name
+ done:
+ .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/vtdumper/src/parser/actions.pm
==============================================================================
--- branches/pmc_pct/compilers/vtdumper/src/parser/actions.pm Thu Jun 4 01:46:27 2009 (r39374)
+++ branches/pmc_pct/compilers/vtdumper/src/parser/actions.pm Thu Jun 4 02:05:33 2009 (r39375)
@@ -1,13 +1,60 @@
# Copyright (C) 2009, Parrot Foundation.
# $Id$
-class PMC::Grammar::Actions;
+class VTable::Grammar::Actions;
method TOP($/) {
- #say("TOP");
- make $( $<pmc> );
+ make $<sections>.ast;
}
+method sections($/, $key) {
+
+ our $?FUNCTIONS;
+ our $?SECTION_NAME := "MAIN";
+
+ if $key eq 'begin' {
+ $?FUNCTIONS := PAST::Block.new(:node($/));
+ }
+ elsif $key eq 'end' {
+ make $?FUNCTIONS;
+ }
+}
+
+method section($/) {
+ our $?SECTION_NAME;
+ our $?SECTION_ATTRIBUTES;
+
+ $?SECTION_NAME := ~$/<identifier>;
+ $?SECTION_ATTRIBUTES := $/<attribute>;
+}
+
+
+method vtable_func($/) {
+ our $?FUNCTIONS;
+ our $?SECTION_NAME;
+ our $?SECTION_ATTRIBUTES;
+
+ my $function := VTable::Function.new( :node( $/ ),
+ :name( ~$/<identifier> ),
+ :returns( $/<type> ),
+ );
+ for $/<attribute> {
+ $function.add_attribute(~$_<identifier>);
+ }
+
+ for $?SECTION_ATTRIBUTES {
+ $function.add_attribute(~$_<identifier>);
+ }
+
+ for $/<argument> {
+ $function.add_argument($_);
+ }
+
+ $function.set_section($?SECTION_NAME);
+
+ $?FUNCTIONS.push($function);
+
+}
# Local Variables:
# mode: pir
Modified: branches/pmc_pct/compilers/vtdumper/src/parser/grammar.pg
==============================================================================
--- branches/pmc_pct/compilers/vtdumper/src/parser/grammar.pg Thu Jun 4 01:46:27 2009 (r39374)
+++ branches/pmc_pct/compilers/vtdumper/src/parser/grammar.pg Thu Jun 4 02:05:33 2009 (r39375)
@@ -4,7 +4,7 @@
grammar VTable::Grammar is PCT::Grammar;
token TOP {
- <vtable_or_section>*
+ <sections>
[ $ || <panic: 'Syntax error'> ]
{*}
}
@@ -29,21 +29,15 @@
rule vtable_func {
- <type> <identifier> '(' <args> ')' <attribute>* {*}
+ <type> <identifier> '(' <argument>* ')' <attribute>* {*}
}
rule type {
[ 'struct' | 'union' ]? <identifier> '*'?
}
-rule args {
- [ <arg> [ ',' <args> ]?
- |
- ]
-}
-
-rule arg {
- <type> <identifier>
+rule argument {
+ <type> <identifier> ','?
}
token identifier {
Modified: branches/pmc_pct/compilers/vtdumper/vtdumper.pir
==============================================================================
--- branches/pmc_pct/compilers/vtdumper/vtdumper.pir Thu Jun 4 01:46:27 2009 (r39374)
+++ branches/pmc_pct/compilers/vtdumper/vtdumper.pir Thu Jun 4 02:05:33 2009 (r39375)
@@ -71,6 +71,8 @@
.tailcall $P0.'command_line'(args, 'encoding'=>'utf8', 'transcode'=>'ascii')
.end
+
+.include 'src/function.pir'
.include 'src/parser/gen_grammar.pir'
.include 'src/parser/gen_actions.pir'
Modified: branches/pmc_pct/config/gen/makefiles/vtdumper.in
==============================================================================
--- branches/pmc_pct/config/gen/makefiles/vtdumper.in Thu Jun 4 01:46:27 2009 (r39374)
+++ branches/pmc_pct/config/gen/makefiles/vtdumper.in Thu Jun 4 02:05:33 2009 (r39375)
@@ -18,6 +18,7 @@
vtdumper.pir \
src/parser/gen_grammar.pir \
src/parser/gen_actions.pir \
+ src/function.pir
# the default target
vtdumper.pbc: $(PARROT) $(PGE_LIBRARY)/Perl6Grammar.pir $(SOURCES)
@@ -61,7 +62,7 @@
testclean:
CLEANUPS := \
- pmc.pbc \
+ vtdumper.pbc \
src/parser/gen_grammar.pir \
src/parser/gen_actions.pir \
More information about the parrot-commits
mailing list