[svn:parrot] r39407 - trunk/runtime/parrot/languages/parrot
tene at svn.parrot.org
tene at svn.parrot.org
Fri Jun 5 20:43:12 UTC 2009
Author: tene
Date: Fri Jun 5 20:43:10 2009
New Revision: 39407
URL: https://trac.parrot.org/parrot/changeset/39407
Log:
Add a utility method to the parrot compiler to load libraries into the local namespace
Modified:
trunk/runtime/parrot/languages/parrot/parrot.pir
Modified: trunk/runtime/parrot/languages/parrot/parrot.pir
==============================================================================
--- trunk/runtime/parrot/languages/parrot/parrot.pir Fri Jun 5 13:44:31 2009 (r39406)
+++ trunk/runtime/parrot/languages/parrot/parrot.pir Fri Jun 5 20:43:10 2009 (r39407)
@@ -61,6 +61,46 @@
ns.'export_to'(exportns, syms)
.end
+.sub 'import' :method :multi(_,_)
+ .param pmc library
+ .local pmc i, targetns
+ i = getinterp
+ targetns = i['namespace';1]
+ .tailcall self.'import'('parrot',library,'targetns'=>targetns)
+.end
+
+.sub 'import' :method :multi(_,_,_)
+ .param string lang
+ .param pmc library
+ .param pmc targetns :named('targetns') :optional
+ .local pmc name, compiler, library, imports
+ $S0 = library
+ name = split '::', $S0
+ compiler = compreg lang
+ unless null targetns goto has_targetns
+ $P0 = getinterp
+ targetns = $P0['namespace';1]
+ has_targetns:
+ library = compiler.'load_library'(name)
+ imports = library['symbols']
+ imports = imports['DEFAULT']
+ .local pmc ns_iter, item
+ ns_iter = iter imports
+ import_loop:
+ unless ns_iter goto import_loop_end
+ $S0 = shift ns_iter
+ $P0 = imports[$S0]
+ targetns[$S0] = $P0
+ goto import_loop
+ import_loop_end:
+ #foreignlibns = library['namespace']
+ #if null foreignlibns goto no_foreign_ns
+ #$S0 = pop name
+ #set_hll_global name, $S0, foreignlibns
+ #no_foreign_ns:
+ .return (library)
+.end
+
# TODO Should this provide support for loading HLL libraries?
=head1 NAME
More information about the parrot-commits
mailing list