[svn:parrot] r44691 - in branches/ops_pct/compilers/opsc: src/Ops src/Ops/Trans t

bacek at svn.parrot.org bacek at svn.parrot.org
Sat Mar 6 11:48:05 UTC 2010


Author: bacek
Date: Sat Mar  6 11:48:04 2010
New Revision: 44691
URL: https://trac.parrot.org/parrot/changeset/44691

Log:
Add emiting init_func and dynload

Modified:
   branches/ops_pct/compilers/opsc/src/Ops/Emitter.pm
   branches/ops_pct/compilers/opsc/src/Ops/Trans.pm
   branches/ops_pct/compilers/opsc/src/Ops/Trans/C.pm
   branches/ops_pct/compilers/opsc/t/06-emitter.t

Modified: branches/ops_pct/compilers/opsc/src/Ops/Emitter.pm
==============================================================================
--- branches/ops_pct/compilers/opsc/src/Ops/Emitter.pm	Sat Mar  6 11:47:36 2010	(r44690)
+++ branches/ops_pct/compilers/opsc/src/Ops/Emitter.pm	Sat Mar  6 11:48:04 2010	(r44691)
@@ -22,6 +22,9 @@
     my $base_ops_stub := $base ~ '_ops' ~ $suffix;
     my $base_ops_h    := $base_ops_stub ~ '.h';
 
+    self<base>    := $base;
+    self<suffix>  := $suffix;
+    self<bs>      := $base ~ $suffix;
 
     self<include> := "parrot/oplib/$base_ops_h";
     self<header>  := (~%flags<dir>) ~ "include/" ~ self<include>;
@@ -48,6 +51,10 @@
 method sym_export() { self<sym_export> };
 method init_func()  { self<init_func> };
 
+method base()       { self<base> };
+method suffix()     { self<suffix> };
+method bs()         { self<bs> };
+
 method print_c_header_file() {
     my $fh := pir::open__PSs(self<header>, 'w') || die("Can't open filehandle");
     self.emit_c_header_file($fh);
@@ -84,6 +91,12 @@
 
 method emit_c_source_file($fh) {
     self._emit_source_preamble($fh);
+
+    self.trans.emit_source_part($fh);
+
+    self._emit_init_func($fh);
+    self._emit_dymanic_lib_load($fh);
+    self._emit_coda($fh);
 }
 
 method _emit_source_preamble($fh) {
@@ -110,6 +123,61 @@
     $fh.print(self.ops_file.preamble);
 }
 
+method _emit_init_func($fh) {
+
+    my $init1    := self.trans.init_func_init1;
+    my $dispatch := self.trans.init_func_disaptch;
+
+    # TODO There is a bug in NQP about \{ 
+    $fh.print(q|
+op_lib_t *
+| ~ self.init_func ~ q|(PARROT_INTERP, long init) {
+    /* initialize and return op_lib ptr */
+    if (init == 1) {
+| ~ $init1 ~ q|
+        return &| ~ self.bs ~q|op_lib;
+    }
+    /* set op_lib to the passed ptr (in init) */
+    else if (init) {
+| ~ $dispatch ~ q|
+    }
+    /* deinit - free resources */
+    else {
+        hop_deinit(interp);
+    }
+    return NULL;
+}
+
+|);
+}
+
+method _emit_dymanic_lib_load($fh) {
+
+    if ! self.flags<dynamic> {
+        return;
+    }
+
+    my $load_func := join('_',
+            q{Parrot}, q{lib}, self.base, q{ops} ~ self.suffix, q{load}, );
+    $fh.print(qq|
+/*
+ * dynamic lib load function - called once
+ */
+{self.sym_export} PMC*
+$load_func(PARROT_INTERP);
+
+{self.sym_export} PMC*
+$load_func(PARROT_INTERP)
+| ~ q|
+{
+    PMC *const lib = Parrot_pmc_new(interp, enum_class_ParrotLibrary);
+    ((Parrot_ParrotLibrary_attributes*)PMC_data(lib))->oplib_init = (void *) | ~ self.init_func ~q|;
+    dynop_register(interp, lib);
+    return lib;
+}
+|);
+}
+
 # given a headerfile name like "include/parrot/oplib/core_ops.h", this
 # returns a string like "PARROT_OPLIB_CORE_OPS_H_GUARD"
 method _generate_guard_macro_name() {

Modified: branches/ops_pct/compilers/opsc/src/Ops/Trans.pm
==============================================================================
--- branches/ops_pct/compilers/opsc/src/Ops/Trans.pm	Sat Mar  6 11:47:36 2010	(r44690)
+++ branches/ops_pct/compilers/opsc/src/Ops/Trans.pm	Sat Mar  6 11:48:04 2010	(r44691)
@@ -26,5 +26,9 @@
 
 method source_preamble() { '' }
 
+method emit_source_part($fh) { die('...') }
+
+method init_func_init1() { '' }
+method init_func_disaptch() { '' }
 
 # vim: expandtab shiftwidth=4 ft=perl6:

Modified: branches/ops_pct/compilers/opsc/src/Ops/Trans/C.pm
==============================================================================
--- branches/ops_pct/compilers/opsc/src/Ops/Trans/C.pm	Sat Mar  6 11:47:36 2010	(r44690)
+++ branches/ops_pct/compilers/opsc/src/Ops/Trans/C.pm	Sat Mar  6 11:48:04 2010	(r44691)
@@ -78,4 +78,7 @@
 /
 }
 
+method emit_source_part($fh) {
+}
+
 # vim: expandtab shiftwidth=4 ft=perl6:

Modified: branches/ops_pct/compilers/opsc/t/06-emitter.t
==============================================================================
--- branches/ops_pct/compilers/opsc/t/06-emitter.t	Sat Mar  6 11:47:36 2010	(r44690)
+++ branches/ops_pct/compilers/opsc/t/06-emitter.t	Sat Mar  6 11:48:04 2010	(r44691)
@@ -56,6 +56,6 @@
 
 ok($source ~~ /static \s int \s get_op/, 'Trans::C preamble generated');
 
-#say($source);
+say($source);
 
 # vim: expandtab shiftwidth=4 ft=perl6:


More information about the parrot-commits mailing list