[svn:parrot] r38362 - in branches/pmc_pct: compilers/pmc compilers/pmc/src compilers/pmc/t config/gen/makefiles

bacek at svn.parrot.org bacek at svn.parrot.org
Sun Apr 26 02:24:24 UTC 2009


Author: bacek
Date: Sun Apr 26 02:24:23 2009
New Revision: 38362
URL: https://trac.parrot.org/parrot/changeset/38362

Log:
Use NQP for implementing PMC::Compiler. First step.

Added:
   branches/pmc_pct/compilers/pmc/src/compiler.pm
   branches/pmc_pct/compilers/pmc/t/04-header.t
Deleted:
   branches/pmc_pct/compilers/pmc/src/compiler.pir
Modified:
   branches/pmc_pct/compilers/pmc/pmc.pir
   branches/pmc_pct/config/gen/makefiles/pmc.in

Modified: branches/pmc_pct/compilers/pmc/pmc.pir
==============================================================================
--- branches/pmc_pct/compilers/pmc/pmc.pir	Sun Apr 26 02:10:53 2009	(r38361)
+++ branches/pmc_pct/compilers/pmc/pmc.pir	Sun Apr 26 02:24:23 2009	(r38362)
@@ -3,13 +3,32 @@
 
 .namespace [ 'PMC';'Compiler' ]
 
+.sub '__onload' :load :init
+    load_bytecode 'PGE.pbc'
+    load_bytecode 'PCT.pbc'
+    load_bytecode 'compilers/nqp/nqp.pbc'
+
+    .local pmc p6meta
+    p6meta = new 'P6metaclass'
+
+    p6meta.'new_class'('PMC::Compiler', 'parent'=>'PCT::HLLCompiler')
+
+    # Register grammar and action
+    $P0 = new [ 'PMC';'Compiler' ]
+    $P0.'language'('PMC')
+    $P0.'parsegrammar'('PMC::Grammar')
+    $P0.'parseactions'('PMC::Grammar::Actions')
+
+.end
+
+
 .sub 'main' :main
     .param pmc args
     $P0 = compreg 'PMC'
     .tailcall $P0.'command_line'(args, 'encoding'=>'utf8', 'transcode'=>'ascii')
 .end
 
-.include 'src/compiler.pir'
+.include 'src/gen_compiler.pir'
 .include 'src/nodes.pir'
 .include 'src/parser/gen_grammar.pir'
 .include 'src/parser/gen_actions.pir'

Deleted: branches/pmc_pct/compilers/pmc/src/compiler.pir
==============================================================================
--- branches/pmc_pct/compilers/pmc/src/compiler.pir	Sun Apr 26 02:24:23 2009	(r38361)
+++ /dev/null	00:00:00 1970	(deleted)
@@ -1,44 +0,0 @@
-# $Id$
-
-=head1 NAME
-
-Compiler for PMC
-
-=head1 DESCRIPTION
-
-Extends PCT::HLLCompiler with emit_something functions
-
-=cut
-
-.namespace [ 'PMC';'Compiler' ]
-
-.sub '__onload' :load :init
-    load_bytecode 'PGE.pbc'
-    load_bytecode 'PCT.pbc'
-    load_bytecode 'compilers/nqp/nqp.pbc'
-
-    .local pmc p6meta
-    p6meta = new 'P6metaclass'
-
-    p6meta.'new_class'('PMC::Compiler', 'parent'=>'PCT::HLLCompiler')
-
-
-    $P0 = new [ 'PMC';'Compiler' ]
-    $P0.'language'('PMC')
-    $P0.'parsegrammar'('PMC::Grammar')
-    $P0.'parseactions'('PMC::Grammar::Actions')
-
-.end
-
-
-=head1 COPYRIGHT
-
-Copyright (C) 2009, Parrot Foundation.
-
-=cut
-
-# Local Variables:
-#   mode: pir
-#   fill-column: 100
-# End:
-# vim: expandtab shiftwidth=4 ft=pir:

Added: branches/pmc_pct/compilers/pmc/src/compiler.pm
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/pmc_pct/compilers/pmc/src/compiler.pm	Sun Apr 26 02:24:23 2009	(r38362)
@@ -0,0 +1,64 @@
+# Copyright (C) 2009, Parrot Foundation.
+# $Id$
+
+# Main PMC compiler.
+
+class PMC::Compiler;
+
+
+# Generate .h file for pmc.
+method generate_h_file() {
+    my $res;
+
+    #my $self; PIR q< store_lex "$self", self >;
+    my $filename := self.filename();
+    $res := dont_edit($filename);
+
+    $res := $res ~ c_code_coda();
+
+    $res;
+}
+
+method filename() {
+    our $?filename;
+    $?filename;
+}
+
+method set_filename($name) {
+    our $?filename := $name;
+}
+
+# Generate don't edit warning
+sub dont_edit($filename) {
+     "/* ex: set ro ft=c:\n"
+    ~" * !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!\n"
+    ~" *\n"
+    ~" * This file is generated automatically from '" ~$filename ~"'\n"
+    ~" * by Divine Intervention.\n"
+    ~" *\n"
+    ~" * Any changes made here will be lost!\n"
+    ~" *\n"
+    ~" */\n";
+}
+
+#=item C<c_code_coda()>
+#
+#Returns the Parrot C code coda
+#
+#=back
+#
+#=cut
+sub c_code_coda() {
+     "/*\n"
+    ~" * Local variables:\n"
+    ~" *   c-file-style: parrot\n"
+    ~" * End:\n"
+    ~" * vim: expandtab shiftwidth=4:\n"
+    ~" */\n"
+}
+
+# Local Variables:
+#   mode: perl6
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Added: branches/pmc_pct/compilers/pmc/t/04-header.t
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/pmc_pct/compilers/pmc/t/04-header.t	Sun Apr 26 02:24:23 2009	(r38362)
@@ -0,0 +1,30 @@
+#!parrot
+# Check generating header for parsed PMC
+
+.include 'compilers/pmc/t/common.pir'
+
+.sub 'main' :main
+.include 'test_more.pir'
+load_bytecode 'compilers/pmc/pmc.pbc'
+    .local int total
+
+    plan(1)
+
+    $S0 = _slurp('compilers/pmc/t/data/class00.pmc')
+    .local pmc compiler
+    compiler = compreg 'PMC'
+    compiler.'parse'($S0, 'target'=>'past')
+
+    $S0 = compiler.'generate_h_file'()
+    like($S0, "'DO NOT EDIT THIS FILE'", "Warning generated")
+.end
+
+
+# Don't forget to update plan!
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:

Modified: branches/pmc_pct/config/gen/makefiles/pmc.in
==============================================================================
--- branches/pmc_pct/config/gen/makefiles/pmc.in	Sun Apr 26 02:10:53 2009	(r38361)
+++ branches/pmc_pct/config/gen/makefiles/pmc.in	Sun Apr 26 02:24:23 2009	(r38362)
@@ -19,7 +19,7 @@
   src/parser/gen_grammar.pir \
   src/parser/gen_actions.pir \
   src/nodes.pir \
-  src/compiler.pir \
+  src/gen_compiler.pir \
   src/builtins.pir
 
 # the default target
@@ -37,6 +37,10 @@
 	$(PARROT) $(PARROT_ARGS) $(NQP) --output=src/parser/gen_actions.pir \
 	    --target=pir src/parser/actions.pm
 
+src/gen_compiler.pir: $(NQP) $(PCT) src/compiler.pm
+	$(PARROT) $(PARROT_ARGS) $(NQP) --output=src/gen_compiler.pir \
+	    --target=pir src/compiler.pm
+
 
 # This is a listing of all targets, that are meant to be called by users
 help:
@@ -66,7 +70,9 @@
 
 CLEANUPS := \
   pmc.pbc \
-  src/parser/grammar.pir
+  src/parser/gen_grammar.pir \
+  src/parser/gen_actions.pir \
+  src/gen_compiler.pir
 
 
 clean:


More information about the parrot-commits mailing list