develooper Front page | perl.cvs.parrot | Postings from January 2009

[svn:parrot] r36114 - in trunk/languages/pipp: . t

From:
bernhard
Date:
January 28, 2009 12:23
Subject:
[svn:parrot] r36114 - in trunk/languages/pipp: . t
Message ID:
20090128202330.6BA00CB9AE@x12.develooper.com
Author: bernhard
Date: Wed Jan 28 12:23:29 2009
New Revision: 36114

Modified:
   trunk/languages/pipp/pipp.pir
   trunk/languages/pipp/t/harness

Log:
[Pipp] Re-add some more code for PHC support


Modified: trunk/languages/pipp/pipp.pir
==============================================================================
--- trunk/languages/pipp/pipp.pir	(original)
+++ trunk/languages/pipp/pipp.pir	Wed Jan 28 12:23:29 2009
@@ -2,7 +2,7 @@
 
 =head1 NAME
 
-pipp.pir - driver program for Pipp
+pipp.pir - driver program for Pipp, PCT and PHC variants
 
 =head1 SYNOPSIS
 
@@ -12,11 +12,26 @@
 
    ./pipp t/in_php/01_sea_only.t
 
+   ./pipp --variant=pct t/in_php/01_sea_only.t
+
+   ./pipp --variant=phc t/in_php/01_sea_only.t
+   ./pipp --run-nqp        t.nqp
+
 =head1 DESCRIPTION
 
 pipp.pbc is the driver for Pipp.
 
-Parse PHP and generate PAST with the Parrot compiler toolkit.
+=head1 Variants
+
+=head2 Pipp pct
+
+Parse PHP with the Parrot compiler toolkit. This is the default variant.
+
+=head2 Pipp phc
+
+Take XML from phc and transform it with XSLT to PIR setting up PAST.
+Run the PAST with the help of PCT.
+
 
 =head1 SEE ALSO
 
@@ -142,14 +157,45 @@
     output = opt['output']
 
     # look at commandline and decide what to do
-    .local string cmd, err_msg
+    .local string cmd, err_msg, variant
     .local int ret
 
     # run the NQP-code when called with --run-nqp
     $I0 = defined opt['run-nqp']
     if  $I0                   goto RUN_NQP
 
-    # use the Parrot Compiler Toolkit
+    # check for the variant from the commandline or from the environment
+    $I0 = defined opt['variant']
+    unless $I0 goto GET_VARIANT_FROM_ENV
+        variant = opt['variant']
+        goto GOT_VARIANT
+GET_VARIANT_FROM_ENV:
+    .local pmc env
+    env = new 'Env'
+    $I0 = exists env['PIPP_VARIANT']
+    unless $I0 goto USE_DEFAULT_VARIANT
+        variant = env['PIPP_VARIANT']
+        goto GOT_VARIANT
+USE_DEFAULT_VARIANT:
+    variant = 'pct'
+    goto GOT_VARIANT
+
+GOT_VARIANT:
+    if variant == 'antlr3'    goto VARIANT_ANTLR3
+    if variant == 'ANTLR3'    goto VARIANT_ANTLR3
+    if variant == 'antlr'     goto VARIANT_ANTLR3
+    if variant == 'ANTLR'     goto VARIANT_ANTLR3
+    if variant == 'pct'       goto VARIANT_PCT
+    if variant == 'PCT'       goto VARIANT_PCT
+    if variant == 'phc'       goto VARIANT_PHC
+    if variant == 'PHC'       goto VARIANT_PHC
+    err_msg = "Unknown pipp variant: '"
+    err_msg .= variant
+    err_msg .= "'."
+    goto ERROR
+
+VARIANT_PCT:
+    # use the Parrot Compiler Toolkit by default
     .local pmc pipp_compiler
     pipp_compiler = compreg 'Pipp'
 
@@ -162,6 +208,34 @@
     # $P0( args )
     .tailcall pipp_compiler.'command_line'( args, 'target' => target, 'output' => output )
 
+VARIANT_PHC:
+    .local string phc_src_dir
+    phc_src_dir =  concat build_dir, '/languages/pipp/src/phc'
+
+    # work with the XML generated by PHC, the PHP Compiler
+    err_msg = 'Creating XML-AST with phc failed'
+    cmd = 'phc --dump-ast-xml '
+    concat cmd, source_fn
+    concat cmd, '> pipp_phc_ast.xml'
+    ret = spawnw cmd
+    if ret goto ERROR
+
+    err_msg = 'Creating XML-PAST with xsltproc failed'
+    cmd  = 'xsltproc '
+    cmd .= phc_src_dir
+    cmd .= '/phc_xml_to_past_xml.xsl pipp_phc_ast.xml > pipp_phc_past.xml'
+    ret = spawnw cmd
+    if ret goto ERROR
+
+    err_msg = 'Creating NQP with xsltproc failed'
+    cmd  = 'xsltproc '
+    cmd .= phc_src_dir
+    cmd .= '/past_xml_to_past_nqp.xsl  pipp_phc_past.xml  > pipp_phc_past.nqp'
+    ret = spawnw cmd
+    if ret goto ERROR
+
+    .tailcall run_nqp( 'pipp_phc_past.nqp', target )
+
 RUN_NQP:
     .tailcall run_nqp( php_source_fn, target )
 
@@ -235,6 +309,7 @@
 
     # Pipp specific command line options
     push getopts, 'f=s'                # source file
+    push getopts, 'variant=s'          # switch between variants
     push getopts, 'target=s'           # compilation target, used during development
     push getopts, 'run-nqp'            # run PAST set up in NQP
     push getopts, 'output|o=s'

Modified: trunk/languages/pipp/t/harness
==============================================================================
--- trunk/languages/pipp/t/harness	(original)
+++ trunk/languages/pipp/t/harness	Wed Jan 28 12:23:29 2009
@@ -11,6 +11,10 @@
 
   cd languages/pipp && perl t/harness 
 
+  cd languages/pipp && perl t/harness --with-phc
+
+  cd languages/pipp && perl t/harness --with-pct
+
   cd languages/pipp && perl t/harness --verbose t/hello.t 
 
 =head1 DESCRIPTION
@@ -22,6 +26,9 @@
 If I'm called with no args, I run the complete suite.
 
 Otherwise I run the tests that were passed on the command line.
+The options C<--with-pct> and C<--with-phc> select
+the variant of Pipp. Default is the PCT variant, using the
+Parrot Compiler Toolkit.
 
 =cut
 
@@ -41,7 +48,7 @@
 use Parrot::Test;
 
 my ( $files_flag, $master_flag, $send_to_smolder_flag, $archive_flag, $verbose_flag );
-my ( $php_flag, $pct_flag);
+my ( $php_flag, $pct_flag, $phc_flag);
 GetOptions(
     'files'           => \$files_flag,
     'master'          => \$master_flag,          # unused, but passed by languages/t/harness
@@ -49,6 +56,7 @@
     'archive'         => \$archive_flag,
     'verbose'         => \$verbose_flag,
     'with-pct'        => \$pct_flag,
+    'with-phc'        => \$phc_flag,
     'with-php'        => \$php_flag,
 );
 
@@ -73,6 +81,10 @@
          $ENV{PARROT_PIPP_TEST_MODULE} = 'Parrot::Test::Pipp::PHP';
          @cmd = qw{ php-cgi -q -C -n } ;
     }
+    elsif ( $phc_flag ) {
+        $ENV{PARROT_PIPP_TEST_MODULE} = 'Parrot::Test::Pipp::Phc';
+        push @cmd, '--variant=phc';
+    }
     elsif ( $pct_flag ) {
         $ENV{PARROT_PIPP_TEST_MODULE} = 'Parrot::Test::Pipp::PCT';
     }



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About