Skip to content
Browse files

Move Perk to git; start work on converting actions.pm to Perl 6

  • Loading branch information...
1 parent 93c60a6 commit 04561b2ec1369b555edcf4a938f4bf7590054c73 @chrisdolan committed Feb 10, 2009
Showing with 130 additions and 122 deletions.
  1. +10 −3 Makefile
  2. +7 −0 README
  3. +10 −10 perk.pir
  4. +100 −106 src/parser/actions.pm
  5. +1 −1 src/parser/grammar.pg
  6. +2 −2 t/harness
View
13 Makefile
@@ -29,11 +29,14 @@ export MACOSX_DEPLOYMENT_TARGET := 10.4
PARROT_DYNEXT = $(BUILD_DIR)/runtime/parrot/dynext
PGE_LIBRARY = $(BUILD_DIR)/runtime/parrot/library/PGE
PERL6GRAMMAR = $(PGE_LIBRARY)/Perl6Grammar.pbc
-NQP = $(BUILD_DIR)/compilers/nqp/nqp.pbc
+RAKUDO = $(BUILD_DIR)/languages/rakudo/perl6.pbc
PCT = $(BUILD_DIR)/runtime/parrot/library/PCT.pbc
PMC_DIR = src/pmc
+ACTION_COMPILER = $(BUILD_DIR)/compilers/nqp/nqp.pbc
+#ACTION_COMPILER = perl6.pbc
+
all: perk.pbc
PERK_GROUP = $(PMC_DIR)/perk_group$(LOAD_EXT)
@@ -54,13 +57,17 @@ BUILTINS_PIR = \
perk.pbc: $(PARROT) $(SOURCES)
$(PARROT) $(PARROT_ARGS) -o perk.pbc perk.pir
+
+perl6.pbc: $(RAKUDO)
+ $(CP) $< $@
+
src/gen_grammar.pir: $(PERL6GRAMMAR) src/parser/grammar.pg
$(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR) \
--output=src/gen_grammar.pir \
src/parser/grammar.pg \
-src/gen_actions.pir: $(NQP) $(PCT) src/parser/actions.pm
- $(PARROT) $(PARROT_ARGS) $(NQP) --output=src/gen_actions.pir \
+src/gen_actions.pir: $(ACTION_COMPILER) $(PCT) src/parser/actions.pm
+ $(PARROT) $(PARROT_ARGS) $(ACTION_COMPILER) --output=src/gen_actions.pir \
--target=pir src/parser/actions.pm
src/gen_builtins.pir: $(BUILTINS_PIR)
View
7 README
@@ -1,3 +1,10 @@
++--------------------------------------------------------+
+| NOTE: I've moved development from googlecode to github |
++--------------------------------------------------------+
+See: http://github.com/chrisdolan/perk/tree/master
+ git clone git://github.com/chrisdolan/perk.git
+
+
This is an implementation of the Java programming language. It is not
intended to be an implementation of the Java virtual machine, however,
so it will not be interoperable with existing JavaVM bytecode.
View
20 perk.pir
@@ -1,27 +1,27 @@
=head1 TITLE
-perk.pir - A perk compiler.
+perk.pir - A Java compiler targetting Parrot.
=head2 Description
-This is the base file for the perk compiler.
+This is the base file for the Perk compiler.
This file includes the parsing and grammar rules from
the src/ directory, loads the relevant PGE libraries,
-and registers the compiler under the name 'perk'.
+and registers the compiler under the name 'Perk'.
=head2 Functions
=over 4
=item onload()
-Creates the perk compiler using a C<PCT::HLLCompiler>
+Creates the Perk compiler using a C<PCT::HLLCompiler>
object.
=cut
-.namespace [ 'perk';'Compiler' ]
+.namespace [ 'Perk';'Compiler' ]
.loadlib 'perk_group'
@@ -30,22 +30,22 @@ object.
$P0 = get_hll_global ['PCT'], 'HLLCompiler'
$P1 = $P0.'new'()
- $P1.'language'('perk')
- $P1.'parsegrammar'('perk::Grammar')
- $P1.'parseactions'('perk::Grammar::Actions')
+ $P1.'language'('Perk')
+ $P1.'parsegrammar'('Perk::Grammar')
+ $P1.'parseactions'('Perk::Grammar::Actions')
.end
=item main(args :slurpy) :main
Start compilation by passing any command line C<args>
-to the perk compiler.
+to the Perk compiler.
=cut
.sub 'main' :main
.param pmc args
- $P0 = compreg 'perk'
+ $P0 = compreg 'Perk'
$P1 = $P0.'command_line'(args)
.end
View
206 src/parser/actions.pm
@@ -2,11 +2,7 @@
=begin comments
-perk::Grammar::Actions - ast transformations for perk
-
-********
-THIS INITIAL VERSION IS PURELY DEBUG CODE! There is no real implementation here yet...
-********
+Perk::Grammar::Actions - ast transformations for perk
This file contains the methods that are used by the parse grammar
to build the PAST representation of an perk program.
@@ -18,122 +14,122 @@ value of the comment is passed as the second argument to the method.
=end comments
-class perk::Grammar::Actions;
+class Perk::Grammar::Actions;
method TOP($/) {
make $( $<compilationUnit> );
-}
+}
method compilationUnit($/) {
- my $outer := PAST::Block.new( :node($/) );
- if $<classOrInterfaceDeclaration> {
- $outer.push($( $<classOrInterfaceDeclaration> ));
- }
- if $<typeDeclaration> {
- for $<typeDeclaration> {
- if $_<classOrInterfaceDeclaration> {
- $outer.push($( $_<classOrInterfaceDeclaration> ));
- }
- }
- }
+ my $outer := PAST::Block.new( :node($/) );
+ if $<classOrInterfaceDeclaration> {
+ $outer.push($( $<classOrInterfaceDeclaration> ));
+ }
+ if $<typeDeclaration> {
+ for $<typeDeclaration> {
+ if $_<classOrInterfaceDeclaration> {
+ $outer.push($( $_<classOrInterfaceDeclaration> ));
+ }
+ }
+ }
make $outer;
-}
+}
method packageDeclaration($/) {
say('package');
-}
+}
method annotation($/) {
say('annot:');
say($<annotationName>);
-}
+}
method importDeclaration($/) {
say($/);
-}
-
-method classOrInterfaceDeclaration($/) {
- if $<classDeclaration> {
- make $( $<classDeclaration> );
- }
- else {
- make $( $<interfaceDeclaration> );
- }
-}
+}
+
+method classOrInterfaceDeclaration($/) {
+ if $<classDeclaration> {
+ make $( $<classDeclaration> );
+ }
+ else {
+ make $( $<interfaceDeclaration> );
+ }
+}
method fieldDeclaration($/) {
say('field:');
say($/);
-}
+}
method methodDeclaration($/) {
say('method:');
say($<Identifier>);
-}
+}
method block($/) {
- my $statements := PAST::Stmts.new( :node($/) );
- if $<blockStatement> {
- for $<blockStatement> {
- $statements.push($( $_ ));
- }
- }
+ my $statements := PAST::Stmts.new( :node($/) );
+ if $<blockStatement> {
+ for $<blockStatement> {
+ $statements.push($( $_ ));
+ }
+ }
make PAST::Block.new( $statements );
-}
+}
method expression($/) {
make PAST::Stmts.new();
-}
+}
method parExpression($/) {
say('parExpression:');
say($/);
-}
+}
method blockStatement($/, $key) {
make $( $/{$key} );
-}
+}
method localVariableDeclaration($/) {
say('local:');
say($/);
-}
-
-method classDeclaration($/, $key) {
- make $( $/{$key} );
-}
+}
+
+method classDeclaration($/, $key) {
+ make $( $/{$key} );
+}
method normalClassDeclaration($/) {
- my $class := $( $<classBody> );
- $class.loadinit().push(
- PAST::Op.new(
- :pasttype('call'),
- :name('!create_class'),
- ~$<Identifier>
- )
- );
- $class.namespace(~$<Identifier>);
+ my $class := $( $<classBody> );
+ $class.loadinit().push(
+ PAST::Op.new(
+ :pasttype('call'),
+ :name('!create_class'),
+ ~$<Identifier>
+ )
+ );
+ $class.namespace(~$<Identifier>);
make $class;
-}
-
-method classBody($/) {
- my $body := PAST::Block.new( :node($/) );
- for $<classBodyDeclaration> {
- $body.push($( $_ ));
- }
- make $body;
-}
-
-method classBodyDeclaration($/, $key) {
- if $key eq 'staticinit' {
- my $block := $( $<block> );
- $block.pirflags(':load :init');
- make $block;
- }
- else {
- make $( $<memberDecl> );
- }
-}
+}
+
+method classBody($/) {
+ my $body := PAST::Block.new( :node($/) );
+ for $<classBodyDeclaration> {
+ $body.push($( $_ ));
+ }
+ make $body;
+}
+
+method classBodyDeclaration($/, $key) {
+ if $key eq 'staticinit' {
+ my $block := $( $<block> );
+ $block.pirflags(':load :init');
+ make $block;
+ }
+ else {
+ make $( $<memberDecl> );
+ }
+}
method arrayCreatorRest($/) {
say('arrayCreatorRest, expr:');
@@ -154,36 +150,34 @@ method switchLabel($/, $key) {
} elsif ($key eq 'default') {
say('default');
}
-}
-
-method memberDecl($/, $key) {
- my $past := $( $/{$key} );
- if $<Identifier> {
- $past.name(~$<Identifier>);
- }
- make $past;
-}
-
-method voidMethodDeclaratorRest($/) {
- my $block := $( $<methodBody> );
- # XXX Params
- make $block;
-}
-
-method methodBody($/) {
- make $( $<block> );
-}
-
-method statement($/) {
- # XXX loads to fill out here
- make $( $<statementExpression> );
-}
-
-method statementExpression($/) {
- make $( $<expression> );
-}
-
+}
+
+method memberDecl($/, $key) {
+ my $past := $( $/{$key} );
+ if $<Identifier> {
+ $past.name(~$<Identifier>);
+ }
+ make $past;
+}
+
+method voidMethodDeclaratorRest($/) {
+ my $block := $( $<methodBody> );
+ # XXX Params
+ make $block;
+}
+
+method methodBody($/) {
+ make $( $<block> );
+}
+
+method statement($/) {
+ # XXX loads to fill out here
+ make $( $<statementExpression> );
+}
+method statementExpression($/) {
+ make $( $<expression> );
+}
# Local Variables:
# mode: cperl
View
2 src/parser/grammar.pg
@@ -36,7 +36,7 @@ This is the grammar for perk written as a sequence of Perl 6 rules.
=end overview
-grammar perk::Grammar is PCT::Grammar;
+grammar Perk::Grammar is PCT::Grammar;
rule TOP {
<compilationUnit>
View
4 t/harness
@@ -8,6 +8,6 @@ use warnings;
use 5.008;
use lib qw( . lib ../lib ../../lib ../../lib );
-use Parrot::Test::Harness language => 'perk',
- compiler => 'perk.pbc';
+use Parrot::Test::Harness language => 'Perk',
+ compiler => 'perk.pbc';

0 comments on commit 04561b2

Please sign in to comment.
Something went wrong with that request. Please try again.