Skip to content

Commit

Permalink
Move Perk to git; start work on converting actions.pm to Perl 6
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdolan committed Feb 11, 2009
1 parent 93c60a6 commit 04561b2
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 122 deletions.
13 changes: 10 additions & 3 deletions Makefile
Expand Up @@ -29,11 +29,14 @@ export MACOSX_DEPLOYMENT_TARGET := 10.4
PARROT_DYNEXT = $(BUILD_DIR)/runtime/parrot/dynext PARROT_DYNEXT = $(BUILD_DIR)/runtime/parrot/dynext
PGE_LIBRARY = $(BUILD_DIR)/runtime/parrot/library/PGE PGE_LIBRARY = $(BUILD_DIR)/runtime/parrot/library/PGE
PERL6GRAMMAR = $(PGE_LIBRARY)/Perl6Grammar.pbc 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 PCT = $(BUILD_DIR)/runtime/parrot/library/PCT.pbc


PMC_DIR = src/pmc PMC_DIR = src/pmc


ACTION_COMPILER = $(BUILD_DIR)/compilers/nqp/nqp.pbc
#ACTION_COMPILER = perl6.pbc

all: perk.pbc all: perk.pbc


PERK_GROUP = $(PMC_DIR)/perk_group$(LOAD_EXT) PERK_GROUP = $(PMC_DIR)/perk_group$(LOAD_EXT)
Expand All @@ -54,13 +57,17 @@ BUILTINS_PIR = \
perk.pbc: $(PARROT) $(SOURCES) perk.pbc: $(PARROT) $(SOURCES)
$(PARROT) $(PARROT_ARGS) -o perk.pbc perk.pir $(PARROT) $(PARROT_ARGS) -o perk.pbc perk.pir



perl6.pbc: $(RAKUDO)
$(CP) $< $@

src/gen_grammar.pir: $(PERL6GRAMMAR) src/parser/grammar.pg src/gen_grammar.pir: $(PERL6GRAMMAR) src/parser/grammar.pg
$(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR) \ $(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR) \
--output=src/gen_grammar.pir \ --output=src/gen_grammar.pir \
src/parser/grammar.pg \ src/parser/grammar.pg \


src/gen_actions.pir: $(NQP) $(PCT) src/parser/actions.pm src/gen_actions.pir: $(ACTION_COMPILER) $(PCT) src/parser/actions.pm
$(PARROT) $(PARROT_ARGS) $(NQP) --output=src/gen_actions.pir \ $(PARROT) $(PARROT_ARGS) $(ACTION_COMPILER) --output=src/gen_actions.pir \
--target=pir src/parser/actions.pm --target=pir src/parser/actions.pm


src/gen_builtins.pir: $(BUILTINS_PIR) src/gen_builtins.pir: $(BUILTINS_PIR)
Expand Down
7 changes: 7 additions & 0 deletions 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 This is an implementation of the Java programming language. It is not
intended to be an implementation of the Java virtual machine, however, intended to be an implementation of the Java virtual machine, however,
so it will not be interoperable with existing JavaVM bytecode. so it will not be interoperable with existing JavaVM bytecode.
Expand Down
20 changes: 10 additions & 10 deletions perk.pir
@@ -1,27 +1,27 @@
=head1 TITLE =head1 TITLE


perk.pir - A perk compiler. perk.pir - A Java compiler targetting Parrot.


=head2 Description =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 This file includes the parsing and grammar rules from
the src/ directory, loads the relevant PGE libraries, 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 =head2 Functions


=over 4 =over 4


=item onload() =item onload()


Creates the perk compiler using a C<PCT::HLLCompiler> Creates the Perk compiler using a C<PCT::HLLCompiler>
object. object.


=cut =cut


.namespace [ 'perk';'Compiler' ] .namespace [ 'Perk';'Compiler' ]


.loadlib 'perk_group' .loadlib 'perk_group'


Expand All @@ -30,22 +30,22 @@ object.


$P0 = get_hll_global ['PCT'], 'HLLCompiler' $P0 = get_hll_global ['PCT'], 'HLLCompiler'
$P1 = $P0.'new'() $P1 = $P0.'new'()
$P1.'language'('perk') $P1.'language'('Perk')
$P1.'parsegrammar'('perk::Grammar') $P1.'parsegrammar'('Perk::Grammar')
$P1.'parseactions'('perk::Grammar::Actions') $P1.'parseactions'('Perk::Grammar::Actions')
.end .end
=item main(args :slurpy) :main =item main(args :slurpy) :main
Start compilation by passing any command line C<args> Start compilation by passing any command line C<args>
to the perk compiler. to the Perk compiler.
=cut =cut
.sub 'main' :main .sub 'main' :main
.param pmc args .param pmc args
$P0 = compreg 'perk' $P0 = compreg 'Perk'
$P1 = $P0.'command_line'(args) $P1 = $P0.'command_line'(args)
.end .end
Expand Down
206 changes: 100 additions & 106 deletions src/parser/actions.pm
Expand Up @@ -2,11 +2,7 @@


=begin comments =begin comments
perk::Grammar::Actions - ast transformations for perk Perk::Grammar::Actions - ast transformations for perk
********
THIS INITIAL VERSION IS PURELY DEBUG CODE! There is no real implementation here yet...
********
This file contains the methods that are used by the parse grammar This file contains the methods that are used by the parse grammar
to build the PAST representation of an perk program. to build the PAST representation of an perk program.
Expand All @@ -18,122 +14,122 @@ value of the comment is passed as the second argument to the method.
=end comments =end comments


class perk::Grammar::Actions; class Perk::Grammar::Actions;


method TOP($/) { method TOP($/) {
make $( $<compilationUnit> ); make $( $<compilationUnit> );
} }


method compilationUnit($/) { method compilationUnit($/) {
my $outer := PAST::Block.new( :node($/) ); my $outer := PAST::Block.new( :node($/) );
if $<classOrInterfaceDeclaration> { if $<classOrInterfaceDeclaration> {
$outer.push($( $<classOrInterfaceDeclaration> )); $outer.push($( $<classOrInterfaceDeclaration> ));
} }
if $<typeDeclaration> { if $<typeDeclaration> {
for $<typeDeclaration> { for $<typeDeclaration> {
if $_<classOrInterfaceDeclaration> { if $_<classOrInterfaceDeclaration> {
$outer.push($( $_<classOrInterfaceDeclaration> )); $outer.push($( $_<classOrInterfaceDeclaration> ));
} }
} }
} }
make $outer; make $outer;
} }


method packageDeclaration($/) { method packageDeclaration($/) {
say('package'); say('package');
} }


method annotation($/) { method annotation($/) {
say('annot:'); say('annot:');
say($<annotationName>); say($<annotationName>);
} }


method importDeclaration($/) { method importDeclaration($/) {
say($/); say($/);
} }


method classOrInterfaceDeclaration($/) { method classOrInterfaceDeclaration($/) {
if $<classDeclaration> { if $<classDeclaration> {
make $( $<classDeclaration> ); make $( $<classDeclaration> );
} }
else { else {
make $( $<interfaceDeclaration> ); make $( $<interfaceDeclaration> );
} }
} }


method fieldDeclaration($/) { method fieldDeclaration($/) {
say('field:'); say('field:');
say($/); say($/);
} }


method methodDeclaration($/) { method methodDeclaration($/) {
say('method:'); say('method:');
say($<Identifier>); say($<Identifier>);
} }


method block($/) { method block($/) {
my $statements := PAST::Stmts.new( :node($/) ); my $statements := PAST::Stmts.new( :node($/) );
if $<blockStatement> { if $<blockStatement> {
for $<blockStatement> { for $<blockStatement> {
$statements.push($( $_ )); $statements.push($( $_ ));
} }
} }
make PAST::Block.new( $statements ); make PAST::Block.new( $statements );
} }


method expression($/) { method expression($/) {
make PAST::Stmts.new(); make PAST::Stmts.new();
} }


method parExpression($/) { method parExpression($/) {
say('parExpression:'); say('parExpression:');
say($/); say($/);
} }


method blockStatement($/, $key) { method blockStatement($/, $key) {
make $( $/{$key} ); make $( $/{$key} );
} }


method localVariableDeclaration($/) { method localVariableDeclaration($/) {
say('local:'); say('local:');
say($/); say($/);
} }


method classDeclaration($/, $key) { method classDeclaration($/, $key) {
make $( $/{$key} ); make $( $/{$key} );
} }


method normalClassDeclaration($/) { method normalClassDeclaration($/) {
my $class := $( $<classBody> ); my $class := $( $<classBody> );
$class.loadinit().push( $class.loadinit().push(
PAST::Op.new( PAST::Op.new(
:pasttype('call'), :pasttype('call'),
:name('!create_class'), :name('!create_class'),
~$<Identifier> ~$<Identifier>
) )
); );
$class.namespace(~$<Identifier>); $class.namespace(~$<Identifier>);
make $class; make $class;
} }


method classBody($/) { method classBody($/) {
my $body := PAST::Block.new( :node($/) ); my $body := PAST::Block.new( :node($/) );
for $<classBodyDeclaration> { for $<classBodyDeclaration> {
$body.push($( $_ )); $body.push($( $_ ));
} }
make $body; make $body;
} }


method classBodyDeclaration($/, $key) { method classBodyDeclaration($/, $key) {
if $key eq 'staticinit' { if $key eq 'staticinit' {
my $block := $( $<block> ); my $block := $( $<block> );
$block.pirflags(':load :init'); $block.pirflags(':load :init');
make $block; make $block;
} }
else { else {
make $( $<memberDecl> ); make $( $<memberDecl> );
} }
} }


method arrayCreatorRest($/) { method arrayCreatorRest($/) {
say('arrayCreatorRest, expr:'); say('arrayCreatorRest, expr:');
Expand All @@ -154,36 +150,34 @@ method switchLabel($/, $key) {
} elsif ($key eq 'default') { } elsif ($key eq 'default') {
say('default'); say('default');
} }
} }


method memberDecl($/, $key) { method memberDecl($/, $key) {
my $past := $( $/{$key} ); my $past := $( $/{$key} );
if $<Identifier> { if $<Identifier> {
$past.name(~$<Identifier>); $past.name(~$<Identifier>);
} }
make $past; make $past;
} }


method voidMethodDeclaratorRest($/) { method voidMethodDeclaratorRest($/) {
my $block := $( $<methodBody> ); my $block := $( $<methodBody> );
# XXX Params # XXX Params
make $block; make $block;
} }


method methodBody($/) { method methodBody($/) {
make $( $<block> ); make $( $<block> );
} }


method statement($/) { method statement($/) {
# XXX loads to fill out here # XXX loads to fill out here
make $( $<statementExpression> ); make $( $<statementExpression> );
} }

method statementExpression($/) {
make $( $<expression> );
}



method statementExpression($/) {
make $( $<expression> );
}


# Local Variables: # Local Variables:
# mode: cperl # mode: cperl
Expand Down
2 changes: 1 addition & 1 deletion src/parser/grammar.pg
Expand Up @@ -36,7 +36,7 @@ This is the grammar for perk written as a sequence of Perl 6 rules.


=end overview =end overview


grammar perk::Grammar is PCT::Grammar; grammar Perk::Grammar is PCT::Grammar;


rule TOP { rule TOP {
<compilationUnit> <compilationUnit>
Expand Down
4 changes: 2 additions & 2 deletions t/harness
Expand Up @@ -8,6 +8,6 @@ use warnings;
use 5.008; use 5.008;


use lib qw( . lib ../lib ../../lib ../../lib ); use lib qw( . lib ../lib ../../lib ../../lib );
use Parrot::Test::Harness language => 'perk', use Parrot::Test::Harness language => 'Perk',
compiler => 'perk.pbc'; compiler => 'perk.pbc';


0 comments on commit 04561b2

Please sign in to comment.