Author: bernhard
Date: Sun Jan 29 04:32:54 2006
New Revision: 11368
Added:
trunk/languages/bc/Bc.java
Modified:
trunk/MANIFEST
trunk/MANIFEST.SKIP
trunk/languages/bc/ (props changed)
trunk/languages/bc/README
trunk/languages/bc/bc.py
trunk/languages/bc/config/makefiles/root.in
trunk/languages/bc/docs/antlr_3.pod
trunk/languages/bc/lib/Parrot/Test/Bc.pm
trunk/languages/bc/lib/Parrot/Test/Bc/Antlr2.pm
trunk/languages/bc/lib/Parrot/Test/Bc/Antlr3.pm
trunk/languages/bc/lib/Parrot/Test/Bc/Posix.pm
trunk/languages/bc/t/ (props changed)
trunk/languages/bc/t/basic.t
trunk/languages/bc/t/harness
Log:
More preparations for starting work
on an ANTLR3 based implementation of 'bc'.
Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST (original)
+++ trunk/MANIFEST Sun Jan 29 04:32:54 2006
@@ -739,6 +739,7 @@ languages/bc/MAINTAINER
languages/bc/README
[bc]
languages/bc/TODO
[bc]
languages/bc/VERSION
[bc]
+languages/bc/Bc.java
[bc]
languages/bc/bc.py
[bc]
languages/bc/config/makefiles/root.in
[bc]
languages/bc/docs/antlr_3.pod
[bc]
Modified: trunk/MANIFEST.SKIP
==============================================================================
--- trunk/MANIFEST.SKIP (original)
+++ trunk/MANIFEST.SKIP Sun Jan 29 04:32:54 2006
@@ -1,5 +1,5 @@
# $Id$
-# generated by tools/dev/gen_manifest_skip.pl Sat Jan 28 19:18:20 2006
+# generated by tools/dev/gen_manifest_skip.pl Sun Jan 29 12:50:54 2006
#
# This file should contain a transcript of the svn:ignore properties
# of the directories in the Parrot subversion repository. (Needed for
@@ -98,7 +98,6 @@
^.*\.exp$
^.*\.exp/
# generated from svn:ignore of 'LICENSES/'
-# generated from svn:ignore of 'blib/lib/'
# generated from svn:ignore of 'compilers/'
# generated from svn:ignore of 'compilers/ast/'
^compilers/ast/.*\.flag$
@@ -242,9 +241,9 @@
# generated from svn:ignore of 'docs/html/languages/jako/lib/Jako/Construct/'
# generated from svn:ignore of 'docs/html/languages/jako/t/'
# generated from svn:ignore of 'docs/html/languages/lua/'
-# generated from svn:ignore of 'docs/html/languages/lua/classes/'
# generated from svn:ignore of 'docs/html/languages/lua/doc/'
# generated from svn:ignore of 'docs/html/languages/lua/lib/'
+# generated from svn:ignore of 'docs/html/languages/lua/pmc/'
# generated from svn:ignore of 'docs/html/languages/lua/t/'
# generated from svn:ignore of 'docs/html/languages/lua/t/Parrot/Test/'
# generated from svn:ignore of 'docs/html/languages/lua/t/lib/'
@@ -460,6 +459,8 @@
^languages/amber/lib/kernel/pmc/.*\.so$
^languages/amber/lib/kernel/pmc/.*\.so/
# generated from svn:ignore of 'languages/bc/'
+^languages/bc/Bc\.class$
+^languages/bc/Bc\.class/
^languages/bc/Makefile$
^languages/bc/Makefile/
# generated from svn:ignore of 'languages/bc/config/'
@@ -486,12 +487,10 @@
# generated from svn:ignore of 'languages/bc/t/'
^languages/bc/t/.*\.bc$
^languages/bc/t/.*\.bc/
-^languages/bc/t/.*\.antlr2_out$
-^languages/bc/t/.*\.antlr2_out/
+^languages/bc/t/.*\.out$
+^languages/bc/t/.*\.out/
^languages/bc/t/.*\.pir$
^languages/bc/t/.*\.pir/
-^languages/bc/t/.*\.posix_out$
-^languages/bc/t/.*\.posix_out/
# generated from svn:ignore of 'languages/befunge/'
^languages/befunge/befunge\.pbc$
^languages/befunge/befunge\.pbc/
Added: trunk/languages/bc/Bc.java
==============================================================================
--- (empty file)
+++ trunk/languages/bc/Bc.java Sun Jan 29 04:32:54 2006
@@ -0,0 +1,17 @@
+// $Id$
+
+import org.antlr.runtime.*;
+
+public class Bc
+{
+ public static void main(String[] args) throws Exception
+ {
+ CharStream input = new ANTLRFileStream(args[0]);
+ System.out.println( "1" );
+ // SimpleCLexer lex = new SimpleCLexer(input);
+ // CommonTokenStream tokens = new CommonTokenStream(lex);
+ // System.out.println("tokens="+tokens);
+ // SimpleC parser = new SimpleC(tokens);
+ // parser.program();
+ }
+}
Modified: trunk/languages/bc/README
==============================================================================
--- trunk/languages/bc/README (original)
+++ trunk/languages/bc/README Sun Jan 29 04:32:54 2006
@@ -36,3 +36,10 @@ Documentation:
Sparse documentation is available in docs/parrot_bc.pod.
Rumblings on ANTLR 3 are in docs/antlr_3.pod.
+
+ANTLR 3 is under development. The easiest backend seems to be Java. So for now
there is a 'build_java' and
+'test_java' targets. Be sure to do a
+
+ export
CLASSPATH=/home/bernhard/devel/ANTLR/v3/antlr-3.0ea7/lib/antlr-3.0ea7.jar:/home/bernhard/devel/ANTLR/v3/antlr-3.0ea7/lib/antlr-2.7.5.jar:/home/bernhard/devel/ANTLR/v3/antlr-3.0ea7/lib/stringtemplate-2.3b4.jar:$CLASSPATH
+
+first.
Modified: trunk/languages/bc/bc.py
==============================================================================
--- trunk/languages/bc/bc.py (original)
+++ trunk/languages/bc/bc.py Sun Jan 29 04:32:54 2006
@@ -81,8 +81,8 @@ def main():
bc_fn = bc_filenames[0]
bc_fh = open(bc_fn, 'r')
regexp = re.compile( r"\.bc$" )
- pir_fh = open( regexp.sub(".pir", bc_fn), 'w' )
- past_pir_fh = open( regexp.sub("_past.pir", bc_fn), 'w' )
+ no_past_fh = open( regexp.sub("_antlr2_no_past.pir", bc_fn), 'w' )
+ past_fh = open( regexp.sub("_antlr2.pir", bc_fn), 'w' )
L = bc.BcLexer.Lexer(bc_fh)
P = bc.BcParser.Parser(L)
@@ -108,7 +108,7 @@ def main():
BcW = bc.BcTreeWalker.Walker();
BcW.gen_pir(ast);
pir_ast = BcW.getAST()
- sys.stdout = pir_fh
+ sys.stdout = no_past_fh
print """
##!/usr/bin/env parrot
@@ -152,7 +152,7 @@ def main():
# Now dump PIR, that uses PAST
# TODO: This is a dummy implementation right now
- sys.stdout = past_pir_fh
+ sys.stdout = past_fh
visitor = Visitor() # Construct Visitor after reassigning sys.stdout
BcW.gen_antlr_past(ast);
antlr_past = BcW.getAST()
Modified: trunk/languages/bc/config/makefiles/root.in
==============================================================================
--- trunk/languages/bc/config/makefiles/root.in (original)
+++ trunk/languages/bc/config/makefiles/root.in Sun Jan 29 04:32:54 2006
@@ -21,14 +21,18 @@ help:
@echo ""
@echo "Following targets are available for the user:"
@echo ""
+ @echo "Building:"
@echo " all: BcLexer.py and BcParser.py"
@echo " This is the default."
+ @echo " build_python: Build implementation in Python"
@echo ""
- @echo " maintain: Generate Python runtime files"
- @echo " Needs ANTLR and Python"
+ @echo " build_java: Build implementation in Java"
@echo ""
@echo "Testing:"
@echo " test: Run the test suite."
+ @echo " test_python: Run the test suite for Parrot bc in Python."
+ @echo " test_java: Run the test suite for Parrot bc in Java."
+ @echo " test_posix: Run the test suite for POSIX bc."
@echo ""
@echo "Cleaning:"
@echo " clean: Basic cleaning up."
@@ -37,14 +41,40 @@ help:
@echo "Misc:"
@echo " help: Print this help message."
@echo ""
+ @echo "Only for maintainer:"
+ @echo " maintain: Generate Python runtime files"
+ @echo " Needs ANTLR and Python"
+ @echo ""
+
+test: test_python test_posix test_java
+
+test_python: build_python
+ cd .. && $(PERL) -I../lib -I bc/lib bc/t/harness --with-python
+
+test_posix:
+ cd .. && $(PERL) -I../lib -I bc/lib bc/t/harness --with-posix
+
+test_java: build_java
+ cd .. && $(PERL) -I../lib -I bc/lib bc/t/harness --with-java
-test: build
- cd .. && $(PERL) -I../lib -I bc/lib bc/t/harness --use-gnu-bc
+# For smoke testing build only the Implementation in Python
+build: build_python
-build:
+build_python:
# Nothing to do
-maintain: $(PYTHON_RUNTIME_FILES)
+build_java: Bc.class
+
+Bc.class:
+ @echo 'Be sure to set CLASSPATH first'
+ javac Bc.java
+
+maintain: maintain_python maintain_java
+
+maintain_python: $(PYTHON_RUNTIME_FILES)
+
+maintain_java:
+# Nothing to do yet
# BcLexer.py will be created too
# TODO: antlr_past2pir_past shouldn't need BcLexerTokenTypes.txt
@@ -53,11 +83,18 @@ $(PYTHON_RUNTIME_FILES): grammar/antlr_2
$(CP) python/lib/bc/BcLexerTokenTypes.txt python/lib/antlr_past2pir_past
antlr -o python/lib/antlr_past2pir_past
grammar/antlr_2/antlr_past2pir_past.g
-clean:
+clean: clean_python clean_java
+ $(RM_RF) \
+ "t/*.bc" "t/*.pir" "t/*.out" "t/*.out"
+
+clean_python:
$(RM_RF) \
"python/lib/bc/*.pyc" \
- "python/lib/antlr_past2pir_past/*.pyc" \
- "t/*.bc" "t/*.pir" "t/*.posix_out" "t/*.parrot_out"
+ "python/lib/antlr_past2pir_past/*.pyc"
+
+clean_java:
+ $(RM_RF) \
+ "*.class"
realclean: clean
$(RM_RF) \
Modified: trunk/languages/bc/docs/antlr_3.pod
==============================================================================
--- trunk/languages/bc/docs/antlr_3.pod (original)
+++ trunk/languages/bc/docs/antlr_3.pod Sun Jan 29 04:32:54 2006
@@ -8,7 +8,13 @@ This are some rumblings on using ANTLR 3
=head1 ANTLR 3
-=head1 Lexer
+=head2 Running
+
+ export
CLASSPATH=/home/bernhard/devel/ANTLR/v3/antlr-3.0ea7/lib/antlr-3.0ea7.jar:/home/bernhard/devel/ANTLR/v3/antlr-3.0ea7/lib/antlr-2.7.5.jar:/home/bernhard/devel/ANTLR/v3/antlr-3.0ea7/lib/stringtemplate-2.3b4.jar:$CLASSPATH
+
+And see Makefile.
+
+=head2 Lexer
The lexer specification can be in the parser specification.
A lexer grammar is automatically generated.
@@ -20,7 +26,13 @@ A lexer grammar is automatically generat
=head2 StringTemplate
-=head2 Backends
+=head1 ANTLR Backends
+
+=head2 Java
+
+=head2 Python
+
+=head2 Perl5
=head1 ANTLR and Parrot
Modified: trunk/languages/bc/lib/Parrot/Test/Bc.pm
==============================================================================
--- trunk/languages/bc/lib/Parrot/Test/Bc.pm (original)
+++ trunk/languages/bc/lib/Parrot/Test/Bc.pm Sun Jan 29 04:32:54 2006
@@ -27,14 +27,14 @@ Call 'Parrot bc' and 'POSIX bc'.
A kind of factory, that finds the proper subclass of Parrot::Test::Bc.
XXX: Do not configure with environment variables.
+Use Antlr2 in smoke testing.
=cut
sub new {
- return $ENV{PARROT_BC_TEST_PROG} ?
- ( bless {}, 'Parrot::Test::Bc::Posix' )
- :
- ( bless {}, 'Parrot::Test::Bc::Antlr2' );
+ my $test_module = $ENV{'PARROT_BC_TEST_MODULE'} ||
'Parrot::Test::Bc::Antlr2';
+
+ return bless {}, $test_module;
}
my %language_test_map = (
@@ -52,30 +52,31 @@ foreach my $func ( keys %language_test_m
my $count = $self->{builder}->current_test + 1;
- # flatten filenames (don't use directories)
- # The 'with_past' option indicates which on should be tested
- my $bc_out_fn = $self->get_out_fn( $count );
- my @test_prog = $self->get_test_prog( $count, $options{with_past} );
+ # These are the thing that depend on the actual Bc implementation
+ my $out_fn = $self->get_out_fn( $count, \%options );
+ my @test_prog = $self->get_test_prog( $count, \%options );
+ $self->set_todo( \%options );
-
# This does not create byte code, but bc code
- my $parrotdir = dirname( $self->{parrot} );
- my $lang_fn = Parrot::Test::per_test( '.bc', $count );
- Parrot::Test::generate_code( $code, $parrotdir, $count, $lang_fn );
+ {
+ my $parrotdir = dirname( $self->{parrot} );
+ my $lang_fn = Parrot::Test::per_test( '.bc', $count );
+ Parrot::Test::generate_code( $code, $parrotdir, $count, $lang_fn );
+ }
# STDERR is written into same output file
# die Dumper( [EMAIL PROTECTED] );
my $exit_code = Parrot::Test::run_command(
[EMAIL PROTECTED],
CD => $self->{relpath},
- STDOUT => $bc_out_fn,
- STDERR => $bc_out_fn
+ STDOUT => $out_fn,
+ STDERR => $out_fn
);
my $builder_func = $language_test_map{$func};
# That's the reason for: no strict 'refs';
my $pass = $self->{builder}->$builder_func(
- Parrot::Test::slurp_file($bc_out_fn),
+ Parrot::Test::slurp_file($out_fn),
$output,
$desc
);
Modified: trunk/languages/bc/lib/Parrot/Test/Bc/Antlr2.pm
==============================================================================
--- trunk/languages/bc/lib/Parrot/Test/Bc/Antlr2.pm (original)
+++ trunk/languages/bc/lib/Parrot/Test/Bc/Antlr2.pm Sun Jan 29 04:32:54 2006
@@ -8,23 +8,35 @@ use base 'Parrot::Test::Bc';
sub get_out_fn {
my $self = shift;
- my ( $count ) = @_;
+ my ( $count, $options ) = @_;
- return Parrot::Test::per_test( '.antlr2_out', $count );
+ return $options->{with_past} ?
+ Parrot::Test::per_test( '_antlr2.out', $count )
+ :
+ Parrot::Test::per_test( '_antlr2_no_past.out', $count );
}
sub get_test_prog {
my $self = shift;
- my ( $count, $with_past ) = @_;
+ my ( $count, $options ) = @_;
my $lang_fn = Parrot::Test::per_test( '.bc', $count );
- my $pir_fn = $with_past ?
- Parrot::Test::per_test( '_past.pir', $count )
+ my $pir_fn = $options->{with_past} ?
+ Parrot::Test::per_test( '_antlr2.pir', $count )
:
- Parrot::Test::per_test( '.pir', $count );
+ Parrot::Test::per_test( '_antlr2_no_past.pir',
$count );
return ( "python languages/bc/bc.py languages/${lang_fn}",
"$self->{parrot} languages/${pir_fn}" );
}
+
+
+sub set_todo {
+ my $self = shift;
+ my ( $options ) = @_;
+
+ return;
+}
+
1;
Modified: trunk/languages/bc/lib/Parrot/Test/Bc/Antlr3.pm
==============================================================================
--- trunk/languages/bc/lib/Parrot/Test/Bc/Antlr3.pm (original)
+++ trunk/languages/bc/lib/Parrot/Test/Bc/Antlr3.pm Sun Jan 29 04:32:54 2006
@@ -6,5 +6,33 @@ use strict;
use base 'Parrot::Test::Bc';
+sub get_out_fn {
+ my $self = shift;
+ my ( $count, $options ) = @_;
+
+ return Parrot::Test::per_test( '_antlr3.out', $count );
+}
+
+sub get_test_prog {
+ my $self = shift;
+ my ( $count, $options ) = @_;
+
+ my $lang_fn = Parrot::Test::per_test( '.bc', $count );
+
+ return ( "java Bc languages/${lang_fn}", );
+}
+
+
+sub set_todo {
+ my $self = shift;
+ my ( $options ) = @_;
+
+ if ( ! $options->{with_antlr3} ) {
+ # $self->{builder}->todo_skip( 'Not implemented with ANTLR3' );
+ }
+
+ return;
+}
+
1;
Modified: trunk/languages/bc/lib/Parrot/Test/Bc/Posix.pm
==============================================================================
--- trunk/languages/bc/lib/Parrot/Test/Bc/Posix.pm (original)
+++ trunk/languages/bc/lib/Parrot/Test/Bc/Posix.pm Sun Jan 29 04:32:54 2006
@@ -8,19 +8,33 @@ use base 'Parrot::Test::Bc';
sub get_out_fn {
my $self = shift;
- my ( $count ) = @_;
+ my ( $count, $options ) = @_;
- return Parrot::Test::per_test( '.posix_out', $count );
+ return Parrot::Test::per_test( '_posix.out', $count );
}
sub get_test_prog {
my $self = shift;
- my ( $count ) = @_;
+ my ( $count, $options ) = @_;
my $lang_fn = Parrot::Test::per_test( '.bc', $count );
my $test_prog_args = $ENV{TEST_PROG_ARGS} || '';
- return ( "$ENV{PARROT_BC_TEST_PROG} ${test_prog_args}
languages/${lang_fn}" );
+ my $posix_bc = ($^O =~ /MSWin32/) ?
+ 'bc'
+ :
+ 'bc --standard --quiet';
+
+ return ( "$posix_bc ${test_prog_args} languages/${lang_fn}" );
+}
+
+
+
+sub set_todo {
+ my $self = shift;
+ my ( $options ) = @_;
+
+ return;
}
1;
Modified: trunk/languages/bc/t/basic.t
==============================================================================
--- trunk/languages/bc/t/basic.t (original)
+++ trunk/languages/bc/t/basic.t Sun Jan 29 04:32:54 2006
@@ -45,7 +45,7 @@ sub run_tests {
my @tests = (
# multiple lines
- [ '1', [ 1 ], 'one line', with_past => 1 ],
+ [ '1', [ 1 ], 'one line', with_past => 1, with_antlr3 => 1 ],
[ "1\n2", [ 1, 2 ], 'two lines', with_past => 1 ],
[ "1\n2\n3\n4\n\n5\n6\n7", [ 1, 2, 3, 4, 5, 6, 7 ], 'seven lines',
with_past => 1 ],
Modified: trunk/languages/bc/t/harness
==============================================================================
--- trunk/languages/bc/t/harness (original)
+++ trunk/languages/bc/t/harness Sun Jan 29 04:32:54 2006
@@ -10,7 +10,11 @@ languages/bc/t/harness - A harness for P
cd languages && perl -I../lib bc/t/harness
- cd languages && perl -I../lib bc/t/harness --use-gnu-bc
+ cd languages && perl -I../lib bc/t/harness --with-posix
+
+ cd languages && perl -I../lib bc/t/harness --with-python
+
+ cd languages && perl -I../lib bc/t/harness --with-java
cd languages && perl -I../lib bc/t/harness \
bc/t/basic/integer.t
@@ -46,8 +50,15 @@ if ( grep { m/^--files$/ } @ARGV ) {
} else {
my @files;
# TODO: use Getopt::Long or such
- my $use_gnu_bc = ( grep { m/^--use-gnu-bc$/ } @ARGV ) ? 1 : 0;
- @ARGV = grep { ! m/^--use-gnu-bc$/ } @ARGV;
+ my $with_posix = ( grep { m/^--with-posix$/ } @ARGV ) ? 1 : 0;
+ @ARGV = grep { ! m/^--with-posix$/ } @ARGV;
+
+ my $with_python = ( grep { m/^--with-python$/ } @ARGV ) ? 1 : 0;
+ @ARGV = grep { ! m/^--with-python$/ } @ARGV;
+
+ my $with_java = ( grep { m/^--with-java$/ } @ARGV ) ? 1 : 0;
+ @ARGV = grep { ! m/^--with-java$/ } @ARGV;
+
if ( scalar(@ARGV) ) {
# Someone specified tests for me to run.
@files = grep { -f $_ } @ARGV
@@ -64,21 +75,21 @@ if ( grep { m/^--files$/ } @ARGV ) {
}
}
- # Always test Parrot bc
- eval
- {
- $ENV{PARROT_BC_TEST_PROG} = '';
- Test::Harness::runtests( @files ) if scalar( @files );
- };
# XXX There should be a better to indicate which implementation should be
used
- if ( $use_gnu_bc ) {
- if ($^O =~ /MSWin32/) {
- $ENV{PARROT_BC_TEST_PROG} = 'bc';
- } else {
- $ENV{PARROT_BC_TEST_PROG} = 'bc --standard --quiet';
- }
- Test::Harness::runtests( @files ) if scalar( @files );
+ if ( $with_posix ) {
+ $ENV{'PARROT_BC_TEST_MODULE'} = 'Parrot::Test::Bc::Posix';
}
+ elsif ( $with_java ) {
+ $ENV{'PARROT_BC_TEST_MODULE'} = 'Parrot::Test::Bc::Antlr3';
+ }
+ elsif ( $with_python ) {
+ $ENV{'PARROT_BC_TEST_MODULE'} = 'Parrot::Test::Bc::Antlr2';
+ }
+ else {
+ $ENV{'PARROT_BC_TEST_MODULE'} = 'Parrot::Test::Bc::Antlr2';
+ }
+
+ Test::Harness::runtests( @files ) if scalar( @files );
}
=head1 HISTORY