Permalink
Browse files

Initial version of perk, adapted from http://svn.chrisdolan.net/langu…

…ages/java/

It just parses (slowly but accurately) and generates no PAST.


git-svn-id: https://squawk.googlecode.com/svn/trunk/perk@3 4fec983b-2331-0410-8aff-915880dc51bf
  • Loading branch information...
cjdolan
cjdolan committed Jan 15, 2009
0 parents commit 56805f4a6af9c1229f9cbe479c2984d0a3a1564d
Showing with 1,404 additions and 0 deletions.
  1. +131 −0 Makefile
  2. +12 −0 README
  3. +127 −0 config/makefiles/root.in
  4. +85 −0 parse_tests/test.pl
  5. +66 −0 perk.pir
  6. +31 −0 src/builtins/say.pir
  7. +100 −0 src/parser/actions.pm
  8. +13 −0 src/parser/grammar-oper.pg
  9. +819 −0 src/parser/grammar.pg
  10. +7 −0 t/00-sanity.t
  11. +13 −0 t/harness
131 Makefile
@@ -0,0 +1,131 @@
+# ex: set ro ft=make:
+# DO NOT EDIT THIS FILE
+# Generated by Parrot::Configure::Compiler from languages/perk/config/makefiles/root.in
+
+## $Id$
+
+## arguments we want to run parrot with
+PARROT_ARGS =
+
+## configuration settings
+BUILD_DIR = /Users/chris/Work/parrot
+LOAD_EXT = .bundle
+O = .o
+
+## Setup some commands
+LN_S = /bin/ln -s
+PERL = perl
+RM_RF = $(PERL) -MExtUtils::Command -e rm_rf
+CP = $(PERL) -MExtUtils::Command -e cp
+PARROT = ../../parrot
+CAT = $(PERL) -MExtUtils::Command -e cat
+BUILD_DYNPMC = $(PERL) $(BUILD_DIR)/tools/build/dynpmc.pl
+RECONFIGURE = $(PERL) $(BUILD_DIR)/tools/dev/reconfigure.pl
+
+# MACOSX_DEPLOYMENT_TARGET must be defined for OS X compilation/linking
+export MACOSX_DEPLOYMENT_TARGET := 10.4
+
+## places to look for things
+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
+PCT = $(BUILD_DIR)/runtime/parrot/library/PCT.pbc
+
+PMC_DIR = src/pmc
+
+all: perk.pbc
+
+PERK_GROUP = $(PMC_DIR)/perk_group$(LOAD_EXT)
+
+SOURCES = perk.pir \
+ src/gen_grammar.pir \
+ src/gen_actions.pir \
+ src/gen_builtins.pir \
+# $(PERK_GROUP)
+
+BUILTINS_PIR = \
+ src/builtins/say.pir \
+
+# PMCS = perk
+# PMC_SOURCES = $(PMC_DIR)/perk.pmc
+
+# the default target
+perk.pbc: $(PARROT) $(SOURCES)
+ $(PARROT) $(PARROT_ARGS) -o perk.pbc perk.pir
+
+src/gen_grammar.pir: $(PERL6GRAMMAR) src/parser/grammar.pg src/parser/grammar-oper.pg
+ $(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR) \
+ --output=src/gen_grammar.pir \
+ src/parser/grammar.pg \
+ src/parser/grammar-oper.pg \
+
+src/gen_actions.pir: $(NQP) $(PCT) src/parser/actions.pm
+ $(PARROT) $(PARROT_ARGS) $(NQP) --output=src/gen_actions.pir \
+ --target=pir src/parser/actions.pm
+
+src/gen_builtins.pir: $(BUILTINS_PIR)
+ $(CAT) $(BUILTINS_PIR) >src/gen_builtins.pir
+
+$(PERK_GROUP): $(PARROT) $(PMC_SOURCES)
+ cd $(PMC_DIR) && $(BUILD_DYNPMC) generate $(PMCS)
+ cd $(PMC_DIR) && $(BUILD_DYNPMC) compile $(PMCS)
+ cd $(PMC_DIR) && $(BUILD_DYNPMC) linklibs $(PMCS)
+ cd $(PMC_DIR) && $(BUILD_DYNPMC) copy --destination=$(PARROT_DYNEXT) $(PMCS)
+
+# regenerate the Makefile
+Makefile: config/makefiles/root.in
+ cd $(BUILD_DIR) && $(RECONFIGURE) --step=gen::languages --languages=perk
+
+# This is a listing of all targets, that are meant to be called by users
+help:
+ @echo ""
+ @echo "Following targets are available for the user:"
+ @echo ""
+ @echo " all: perk.pbc"
+ @echo " This is the default."
+ @echo "Testing:"
+ @echo " test: Run the test suite."
+ @echo " testclean: Clean up test results."
+ @echo ""
+ @echo "Cleaning:"
+ @echo " clean: Basic cleaning up."
+ @echo " realclean: Removes also files generated by 'Configure.pl'"
+ @echo " distclean: Removes also anything built, in theory"
+ @echo ""
+ @echo "Misc:"
+ @echo " help: Print this help message."
+ @echo ""
+
+test: all
+ $(PERL) t/harness
+
+# this target has nothing to do
+testclean:
+
+CLEANUPS = \
+ perk.pbc \
+ src/gen_grammar.pir \
+ src/gen_actions.pir \
+ src/gen_builtins.pir \
+ $(PMC_DIR)/*.h \
+ $(PMC_DIR)/*.c \
+ $(PMC_DIR)/*.dump \
+ $(PMC_DIR)/*$(O) \
+ $(PMC_DIR)/*$(LOAD_EXT) \
+ $(PMC_DIR)/*.exp \
+ $(PMC_DIR)/*.ilk \
+ $(PMC_DIR)/*.manifest \
+ $(PMC_DIR)/*.pdb \
+ $(PMC_DIR)/*.lib \
+
+
+clean: testclean
+ $(RM_RF) $(CLEANUPS)
+
+realclean: clean
+ $(RM_RF) Makefile
+
+distclean: realclean
+
+
12 README
@@ -0,0 +1,12 @@
+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.
+
+The parser is heavily influenced by an ANTLR grammar for Java 1.5.
+
+ http://www.antlr.org/grammar/1152141644268/Java.g
+
+From those roots, though, it's been modified to be more tightly
+coupled with Parrot and has been enhanced to support more syntax from
+the Java Language Specification, 3rd edition to parse a wider variety
+of Java sources (i.e. Java 1.6 and beyond).
@@ -0,0 +1,127 @@
+## $Id$
+
+## arguments we want to run parrot with
+PARROT_ARGS =
+
+## configuration settings
+BUILD_DIR = @build_dir@
+LOAD_EXT = @load_ext@
+O = @o@
+
+## Setup some commands
+LN_S = @lns@
+PERL = @perl@
+RM_RF = @rm_rf@
+CP = @cp@
+PARROT = ../../parrot@exe@
+CAT = $(PERL) -MExtUtils::Command -e cat
+BUILD_DYNPMC = $(PERL) $(BUILD_DIR)/tools/build/dynpmc.pl
+RECONFIGURE = $(PERL) $(BUILD_DIR)/tools/dev/reconfigure.pl
+#CONDITIONED_LINE(darwin):
+#CONDITIONED_LINE(darwin):# MACOSX_DEPLOYMENT_TARGET must be defined for OS X compilation/linking
+#CONDITIONED_LINE(darwin):export MACOSX_DEPLOYMENT_TARGET := @osx_version@
+
+## places to look for things
+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
+PCT = $(BUILD_DIR)/runtime/parrot/library/PCT.pbc
+
+PMC_DIR = src/pmc
+
+all: perk.pbc
+
+PERK_GROUP = $(PMC_DIR)/perk_group$(LOAD_EXT)
+
+SOURCES = perk.pir \
+ src/gen_grammar.pir \
+ src/gen_actions.pir \
+ src/gen_builtins.pir \
+# $(PERK_GROUP)
+
+BUILTINS_PIR = \
+ src/builtins/say.pir \
+
+# PMCS = perk
+# PMC_SOURCES = $(PMC_DIR)/perk.pmc
+
+# the default target
+perk.pbc: $(PARROT) $(SOURCES)
+ $(PARROT) $(PARROT_ARGS) -o perk.pbc perk.pir
+
+src/gen_grammar.pir: $(PERL6GRAMMAR) src/parser/grammar.pg src/parser/grammar-oper.pg
+ $(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR) \
+ --output=src/gen_grammar.pir \
+ src/parser/grammar.pg \
+ src/parser/grammar-oper.pg \
+
+src/gen_actions.pir: $(NQP) $(PCT) src/parser/actions.pm
+ $(PARROT) $(PARROT_ARGS) $(NQP) --output=src/gen_actions.pir \
+ --target=pir src/parser/actions.pm
+
+src/gen_builtins.pir: $(BUILTINS_PIR)
+ $(CAT) $(BUILTINS_PIR) >src/gen_builtins.pir
+
+$(PERK_GROUP): $(PARROT) $(PMC_SOURCES)
+ cd $(PMC_DIR) && $(BUILD_DYNPMC) generate $(PMCS)
+ cd $(PMC_DIR) && $(BUILD_DYNPMC) compile $(PMCS)
+ cd $(PMC_DIR) && $(BUILD_DYNPMC) linklibs $(PMCS)
+ cd $(PMC_DIR) && $(BUILD_DYNPMC) copy --destination=$(PARROT_DYNEXT) $(PMCS)
+
+# regenerate the Makefile
+Makefile: config/makefiles/root.in
+ cd $(BUILD_DIR) && $(RECONFIGURE) --step=gen::languages --languages=perk
+
+# This is a listing of all targets, that are meant to be called by users
+help:
+ @echo ""
+ @echo "Following targets are available for the user:"
+ @echo ""
+ @echo " all: perk.pbc"
+ @echo " This is the default."
+ @echo "Testing:"
+ @echo " test: Run the test suite."
+ @echo " testclean: Clean up test results."
+ @echo ""
+ @echo "Cleaning:"
+ @echo " clean: Basic cleaning up."
+ @echo " realclean: Removes also files generated by 'Configure.pl'"
+ @echo " distclean: Removes also anything built, in theory"
+ @echo ""
+ @echo "Misc:"
+ @echo " help: Print this help message."
+ @echo ""
+
+test: all
+ $(PERL) t/harness
+
+# this target has nothing to do
+testclean:
+
+CLEANUPS = \
+ perk.pbc \
+ src/gen_grammar.pir \
+ src/gen_actions.pir \
+ src/gen_builtins.pir \
+ $(PMC_DIR)/*.h \
+ $(PMC_DIR)/*.c \
+ $(PMC_DIR)/*.dump \
+ $(PMC_DIR)/*$(O) \
+ $(PMC_DIR)/*$(LOAD_EXT) \
+ $(PMC_DIR)/*.exp \
+ $(PMC_DIR)/*.ilk \
+ $(PMC_DIR)/*.manifest \
+ $(PMC_DIR)/*.pdb \
+ $(PMC_DIR)/*.lib \
+
+
+clean: testclean
+ $(RM_RF) $(CLEANUPS)
+
+realclean: clean
+ $(RM_RF) Makefile
+
+distclean: realclean
+
+
@@ -0,0 +1,85 @@
+#!/usr/bin/perl -w
+
+use strict;
+use FindBin qw($Bin);
+use File::Find;
+use File::Slurp;
+use File::Which;
+
+# If -f is specified, re-run failures even if we already recorded a failure
+my $force = @ARGV && $ARGV[0] eq '-f' && shift;
+
+my $filter = shift;
+
+## Pick a folder full of .java files to try to parse
+my $javadir = "$Bin/openjdk/jdk/src/share/classes";
+
+if (! -e $javadir) {
+ die "No OpenJDK source code found at\n" .
+ " $javadir\n" .
+ "Download and unpack code from http://openjdk.java.net/ and try again\n";
+}
+
+my $parrotexe = File::Which::which 'parrot';
+if (!$parrotexe) {
+ for my $i (1..5) {
+ my $candidate = $Bin . ('/..' x $i) . '/parrot';
+ if (-x $candidate) {
+ $parrotexe = $candidate;
+ last;
+ }
+ }
+ if (!$parrotexe) {
+ die "Can't find parrot\n";
+ }
+}
+
+my $outdir = "$Bin/testout";
+mkdir $outdir;
+mkdir "$outdir/bad";
+mkdir "$outdir/good";
+my $perkcode = "$Bin/../perk.pbc";
+find({wanted => sub {
+ return if ! m/\.java\z/;
+ return if m/-/; # can't handle invalid Java files with dashes in the file names
+ return if $filter && !m{\A$javadir/$filter};
+ #if (m{sun/nio/cs/ext/(GB18030|EUC_TW|IBM\d+|Johab|HKSCS_2001|MS\d+).java\z}xms) {
+ if (m{sun/nio/cs/ext/\w+.java\z}xms) {
+ print "SKIPPED $_\n";
+ return;
+ }
+ print "$_\n";
+ my $esc = $_;
+ $esc =~ s{\A $javadir/}{}xms;
+ $esc =~ s{/}{.}gxms;
+ $esc =~ s{\.java\z}{}xms;
+ my $goodfile = "$outdir/good/$esc";
+ my $badfile = "$outdir/bad/$esc";
+ if (-e $badfile) {
+ return if !$force && ! -z $badfile && -M $badfile < -M $perkcode;
+ unlink $badfile;
+ unlink $badfile . '.java';
+ }
+ return if -e $goodfile;
+ my $ret = system("'$parrotexe' '$perkcode' $_ > '$badfile'");
+ my $exit = $?;
+ if ( $ret == 0 ) {
+ rename($badfile, $goodfile);
+ } else {
+ print "Returned error: $ret\n";
+ if ($exit == -1) {
+ print "Failed to launch\n";
+ unlink $badfile;
+ exit -1;
+ } elsif ($exit & 127) {
+ print "died with signal ", ($exit & 127), "\n";
+ unlink $badfile;
+ exit -1;
+ } else {
+ print "exit value: ", ($exit >> 8), "\n";
+ #sleep 1;
+ write_file($badfile . '.java', scalar read_file($_));
+ }
+ }
+ return;
+}, no_chdir => 1}, $javadir);
Oops, something went wrong.

0 comments on commit 56805f4

Please sign in to comment.