[svn:parrot] r38739 - in branches/pmc_pct/compilers/pmcc: . src src/emitter src/parser t t/data
cotto at svn.parrot.org
cotto at svn.parrot.org
Wed May 13 05:40:40 UTC 2009
Author: cotto
Date: Wed May 13 05:40:38 2009
New Revision: 38739
URL: https://trac.parrot.org/parrot/changeset/38739
Log:
[pmcc] move ATTR serialization out of actions.pm
make pmcc aware of the name of the file it's compiling
add a cli option to specify the search path for .dump files
add stub stage to generate output files
Added:
branches/pmc_pct/compilers/pmcc/t/data/child.pmc (props changed)
- copied unchanged from r38731, branches/pmc_pct/compilers/pmcc/t/data/Child.pmc
branches/pmc_pct/compilers/pmcc/t/data/parent.pmc (props changed)
- copied unchanged from r38731, branches/pmc_pct/compilers/pmcc/t/data/Parent.pmc
Deleted:
branches/pmc_pct/compilers/pmcc/t/data/Child.pmc
branches/pmc_pct/compilers/pmcc/t/data/Parent.pmc
Modified:
branches/pmc_pct/compilers/pmcc/pmcc.pir
branches/pmc_pct/compilers/pmcc/src/emitter.pm
branches/pmc_pct/compilers/pmcc/src/emitter/pmc.pm
branches/pmc_pct/compilers/pmcc/src/nodes.pir
branches/pmc_pct/compilers/pmcc/src/parser/actions.pm
branches/pmc_pct/compilers/pmcc/t/05-header.t
branches/pmc_pct/compilers/pmcc/t/06-body.t
Modified: branches/pmc_pct/compilers/pmcc/pmcc.pir
==============================================================================
--- branches/pmc_pct/compilers/pmcc/pmcc.pir Wed May 13 04:47:08 2009 (r38738)
+++ branches/pmc_pct/compilers/pmcc/pmcc.pir Wed May 13 05:40:38 2009 (r38739)
@@ -17,6 +17,58 @@
$P0.'parsegrammar'('PMC::Grammar')
$P0.'parseactions'('PMC::Grammar::Actions')
+ #these stages aren't currently used
+ $P0.'removestage'('post')
+ $P0.'removestage'('pir')
+ $P0.'removestage'('evalpmc')
+
+ #add an extra stage to generate the c, h and dump files
+ $P0.'addstage'('generate_files', 'after'=>'past')
+
+ $P1 = split ' ', 'e=s pmc_path|p=s help|h target=s dumper=s trace|t=s encoding=s output|o=s combine version|v'
+ setattribute $P0, '@cmdoptions', $P1
+
+.end
+
+
+.sub 'generate_files' :method
+ .param pmc past
+ .param pmc adverbs :slurpy :named
+
+ .local pmc pmc_filename
+ pmc_filename = get_hll_global ['PMC';'Compiler'], '$filename'
+
+ .local string base_filename, dump_filename, c_filename, h_filename
+ .local string dump_contents, c_contents, h_contents
+ base_filename = pmc_filename.'replace'('.pmc', '')
+
+ dump_filename = concat base_filename, '.dump'
+ c_filename = concat base_filename, '.c'
+ h_filename = concat base_filename, '.h'
+
+ #XXX: do something interesting here
+
+
+.end
+
+.sub 'evalfiles' :method
+ .param pmc files
+ .param pmc args :slurpy
+ .param pmc adverbs :slurpy :named
+
+ .local string filename
+
+ $S0 = adverbs['pmc_path']
+ $P0 = split ',', $S0
+ set_hll_global ['PMC';'Compiler'], '@pmc_path', $P0
+
+ #TODO: DTRT if files is an array of filenames, although this isn't an expected use case
+ $P0 = clone files
+ set_hll_global ['PMC';'Compiler'], '$filename', $P0
+
+ .local pmc super_evalfiles
+ super_evalfiles = get_hll_global ['PCT';'HLLCompiler'], 'evalfiles'
+ .tailcall self.super_evalfiles(files, args, adverbs)
.end
Modified: branches/pmc_pct/compilers/pmcc/src/emitter.pm
==============================================================================
--- branches/pmc_pct/compilers/pmcc/src/emitter.pm Wed May 13 04:47:08 2009 (r38738)
+++ branches/pmc_pct/compilers/pmcc/src/emitter.pm Wed May 13 05:40:38 2009 (r38739)
@@ -47,6 +47,19 @@
$res;
}
+# Generate the ontents of a .dump file for self.
+method generate_dump($past) {
+ my $res;
+
+ my $name := $past.name();
+ my $filename := self.filename();
+
+ # Get emitter for (specific) PMC.
+ my $pmc_emitter := get_pmc_emitter($name, $past);
+
+ $pmc_emitter.generate_dump();
+}
+
method filename() {
our $?filename;
$?filename;
Modified: branches/pmc_pct/compilers/pmcc/src/emitter/pmc.pm
==============================================================================
--- branches/pmc_pct/compilers/pmcc/src/emitter/pmc.pm Wed May 13 04:47:08 2009 (r38738)
+++ branches/pmc_pct/compilers/pmcc/src/emitter/pmc.pm Wed May 13 05:40:38 2009 (r38739)
@@ -293,12 +293,37 @@
\"subclassed from a high-level PMC.\"); \\";
}
+#=item C<generate_dump_file>
+#
+#Generate the contents of a dump file for this PMC, which will contain any
+#information that's needed for determining inheritance.
+#
+#=cut
+
+method generate_dump() {
+ my $res := self.freeze_attrs();
+}
+
+method freeze_attrs() {
+ my $frozen;
+
+ #IWBNI nqp exposed freeze directly, but this is works too
+PIR q<
+ $P0 = self.'attrs'()
+ $S0 = freeze $P0
+ $P0 = find_lex '$frozen'
+ $P0 = $S0
+>;
+ return $frozen;
+}
+
#=item C<generate_c_file>
#
#Generate C file for PMC.
#
#=cut
+
method generate_c_file() {
my $res :=
self.generate_c_file_functions()
Modified: branches/pmc_pct/compilers/pmcc/src/nodes.pir
==============================================================================
--- branches/pmc_pct/compilers/pmcc/src/nodes.pir Wed May 13 04:47:08 2009 (r38738)
+++ branches/pmc_pct/compilers/pmcc/src/nodes.pir Wed May 13 05:40:38 2009 (r38739)
@@ -119,58 +119,58 @@
.tailcall self.'attr'('attrs',0,0)
.end
-=item C<serialize_attrs>
-store PMC ATTRs in a file.
-
-=cut
-
-.include 'library/JSON.pir'
-
-.sub 'serialize_attrs' :method
-
- .local string filename, pmcname
- .local pmc attrs, fh
-
- pmcname = self.'name'()
- attrs = self.'attrs'()
- $S0 = freeze attrs
-
- filename = concat pmcname, ".dump"
- fh = open filename, "w"
- print fh, $S0
- close fh
- .return ()
-
-.end
-
-=item C<unserialize_attrs>
+=item C<unfreeze_attrs>
unserialize a PMC's frozen ATTRs and add them to this PMC.
=cut
-.include 'except_types.pasm'
-
-.sub 'unserialize_attrs' :method
+.sub 'unfreeze_pmc_attrs' :method
.param string pmcname
- .local string filename
- .local pmc attrs, fh, eh
+ .local pmc pmc_path, attrs, fh, it, filename
+ .local string dumpname
+
+ #search through all dirs in @pmc_path, looking for a file
+ #named lc(pmcname) ~".dump"
- eh = new ['ExceptionHandler']
- eh.'handle_types'(.EXCEPTION_PIO_ERROR)
- set_addr eh, no_dump
-
- filename = concat pmcname, ".dump"
- push_eh eh
- fh = open filename
+ pmc_path = get_hll_global ['PMC';'Compiler'], '@pmc_path'
+ dumpname = pmcname
+ dumpname = downcase dumpname
+ dumpname = concat dumpname, '.dump'
+ #print "looking for "
+ #say dumpname
+
+ fh = new ['FileHandle']
+ it = iter pmc_path
+
+ path_loop:
+ unless it goto dump_not_found
+ filename = shift it
+ concat filename, "/"
+ concat filename, dumpname
+ push_eh iter_next
+ #print "trying to open "
+ #print filename
+ #print " ..."
+ fh.'open'(filename)
+ goto dump_found
+
+ iter_next:
+ pop_eh
+ #say "failed"
+ goto path_loop
+
+ dump_found:
pop_eh
+ #say "succeeded"
+
$S0 = fh.'readall'()
close fh
- .local pmc it, attr
+ .local pmc attr
.local string type, name
.local int is_fp
@@ -189,7 +189,7 @@
iter_done:
.return ()
- no_dump:
+ dump_not_found:
printerr "WARNING: couldn't read .dump for "
printerr pmcname
printerr ".pmc\n"
Modified: branches/pmc_pct/compilers/pmcc/src/parser/actions.pm
==============================================================================
--- branches/pmc_pct/compilers/pmcc/src/parser/actions.pm Wed May 13 04:47:08 2009 (r38738)
+++ branches/pmc_pct/compilers/pmcc/src/parser/actions.pm Wed May 13 05:40:38 2009 (r38739)
@@ -20,9 +20,6 @@
else {
# TODO Set c_header and c_coda
make $?PMC;
- # FIXME We shouldn't call this during parsing.
- # It belongs to high-level command-line tool.
- $?PMC.serialize_attrs();
}
}
@@ -39,7 +36,7 @@
#say("traits " ~$/);
if $key eq 'extends' {
$?PMC.parents().push(~$<identifier>);
- $?PMC.unserialize_attrs(~$<identifier>);
+ $?PMC.unfreeze_pmc_attrs(~$<identifier>);
}
elsif $key eq 'provides' {
}
Modified: branches/pmc_pct/compilers/pmcc/t/05-header.t
==============================================================================
--- branches/pmc_pct/compilers/pmcc/t/05-header.t Wed May 13 04:47:08 2009 (r38738)
+++ branches/pmc_pct/compilers/pmcc/t/05-header.t Wed May 13 05:40:38 2009 (r38739)
@@ -10,6 +10,10 @@
plan(6)
+ $P0 = new ['ResizableStringArray']
+ $P0 = split ',', 't/data'
+ set_hll_global ['PMC';'Compiler'], '@pmc_path', $P0
+
.local string filename
filename = 't/data/class00.pmc'
$S0 = _slurp(filename)
@@ -39,15 +43,28 @@
$S0 = _slurp(filename)
check_one_header(filename, $S0, attr_macro, "ATTR macro generated")
- #make sure the dump for Parent is generated
+ #generate the dump for Parent
.local pmc emitter, capture
- filename = 't/data/Parent.pmc'
+ filename = 't/data/parent.pmc'
+
+ $P0 = new ['String']
+ $P0 = filename
+ set_hll_global ['PMC';'Compiler'], '$filename', $P0
+
$S0 = _slurp(filename)
(emitter, capture) = get_emitter_and_capture(filename, $S0, 'past')
- emitter.'generate_h_file'(capture)
+ $S0 = emitter.'generate_dump'(capture)
+ filename = 't/data/parent.dump'
+ $P0 = open filename, "w"
+ print $P0, $S0
+ close $P0
#test that parent ATTRs are included in children, and in the right order
- filename = 't/data/Child.pmc'
+ filename = 't/data/child.pmc'
+
+ $P0 = new ['String']
+ $P0 = filename
+ set_hll_global ['PMC';'Compiler'], '$filename', $P0
$S0 = _slurp(filename)
attr_struct = 'parent_1\;.*parent_2\;.*parent_3\;.*child_1\;.*child_2\;.*child_3\;'
check_one_header(filename, $S0, attr_struct, "parent/child ATTR ordering")
@@ -65,7 +82,7 @@
.local pmc emitter, capture
(emitter, capture) = get_emitter_and_capture(name, source, 'past')
$S0 = emitter.'generate_h_file'(capture)
- say $S0
+ #say $S0
like($S0, pattern, message)
.end
Modified: branches/pmc_pct/compilers/pmcc/t/06-body.t
==============================================================================
--- branches/pmc_pct/compilers/pmcc/t/06-body.t Wed May 13 04:47:08 2009 (r38738)
+++ branches/pmc_pct/compilers/pmcc/t/06-body.t Wed May 13 05:40:38 2009 (r38739)
@@ -12,6 +12,10 @@
.local string filename
+ $P0 = new ['ResizableStringArray']
+ $P0 = split ',', 't/data'
+ set_hll_global ['PMC';'Compiler'], '@pmc_path', $P0
+
filename = 't/data/class08.pmc'
$S0 = _slurp(filename)
@@ -41,7 +45,7 @@
.local pmc emitter, capture
(emitter, capture) = get_emitter_and_capture(name, source, 'past')
$S0 = emitter.'generate_c_file'(capture)
- say $S0
+ #say $S0
like($S0, pattern, message)
.end
Deleted: branches/pmc_pct/compilers/pmcc/t/data/Child.pmc
==============================================================================
--- branches/pmc_pct/compilers/pmcc/t/data/Child.pmc Wed May 13 05:40:38 2009 (r38738)
+++ /dev/null 00:00:00 1970 (deleted)
@@ -1,5 +0,0 @@
-pmclass Child extends Parent{
- ATTR INTVAL child_1;
- ATTR FLOATVAL child_2;
- ATTR STRING* child_3;
-}
Deleted: branches/pmc_pct/compilers/pmcc/t/data/Parent.pmc
==============================================================================
--- branches/pmc_pct/compilers/pmcc/t/data/Parent.pmc Wed May 13 05:40:38 2009 (r38738)
+++ /dev/null 00:00:00 1970 (deleted)
@@ -1,5 +0,0 @@
-pmclass Parent {
- ATTR FLOATVAL parent_1;
- ATTR INTVAL parent_2;
- ATTR STRING* parent_3;
-}
Copied: branches/pmc_pct/compilers/pmcc/t/data/child.pmc (from r38731, branches/pmc_pct/compilers/pmcc/t/data/Child.pmc)
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/pmc_pct/compilers/pmcc/t/data/child.pmc Wed May 13 05:40:38 2009 (r38739, copy of r38731, branches/pmc_pct/compilers/pmcc/t/data/Child.pmc)
@@ -0,0 +1,5 @@
+pmclass Child extends Parent{
+ ATTR INTVAL child_1;
+ ATTR FLOATVAL child_2;
+ ATTR STRING* child_3;
+}
Copied: branches/pmc_pct/compilers/pmcc/t/data/parent.pmc (from r38731, branches/pmc_pct/compilers/pmcc/t/data/Parent.pmc)
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/pmc_pct/compilers/pmcc/t/data/parent.pmc Wed May 13 05:40:38 2009 (r38739, copy of r38731, branches/pmc_pct/compilers/pmcc/t/data/Parent.pmc)
@@ -0,0 +1,5 @@
+pmclass Parent {
+ ATTR FLOATVAL parent_1;
+ ATTR INTVAL parent_2;
+ ATTR STRING* parent_3;
+}
More information about the parrot-commits
mailing list