[svn:parrot] r39285 - in trunk: . runtime/parrot/languages runtime/parrot/languages/parrot

tene at svn.parrot.org tene at svn.parrot.org
Sun May 31 07:54:02 UTC 2009


Author: tene
Date: Sun May 31 07:54:01 2009
New Revision: 39285
URL: https://trac.parrot.org/parrot/changeset/39285

Log:
Add a 'parrot' compiler object that can be used from HLLs to load
properly-configured PIR libraries.

Added:
   trunk/runtime/parrot/languages/
   trunk/runtime/parrot/languages/parrot/
   trunk/runtime/parrot/languages/parrot/parrot.pir
Modified:
   trunk/MANIFEST

Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST	Sun May 31 06:02:18 2009	(r39284)
+++ trunk/MANIFEST	Sun May 31 07:54:01 2009	(r39285)
@@ -1142,6 +1142,7 @@
 runtime/parrot/include/fp_equality.pasm                     [library]
 runtime/parrot/include/hllmacros.pir                        [library]
 runtime/parrot/include/test_more.pir                        [library]
+runtime/parrot/languages/parrot/parrot.pir                  [library]
 runtime/parrot/library/CGI/QueryHash.pir                    [library]
 runtime/parrot/library/Config/JSON.pir                      [library]
 runtime/parrot/library/Crow.pir                             [library]

Added: trunk/runtime/parrot/languages/parrot/parrot.pir
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/runtime/parrot/languages/parrot/parrot.pir	Sun May 31 07:54:01 2009	(r39285)
@@ -0,0 +1,90 @@
+.HLL 'parrot'
+.namespace ['Parrot';'Compiler']
+
+.sub 'load' :anon :load :init
+    # I'm not sure if this is completely right...
+    .local pmc p6meta, c
+    load_bytecode 'PCT.pbc'
+    p6meta = get_hll_global 'P6metaclass'
+    c = p6meta.'new_class'('Parrot::Compiler', 'parent'=>'PCT::HLLCompiler')
+    c.'language'('parrot')
+.end
+
+.sub 'fetch-library' :method
+    .param pmc request
+    .local pmc name, library, inc_hash
+    .local string file
+    name = request['name']
+    file = join '/', name
+    file = concat file, '.pir'
+    push_eh fail
+    load_bytecode file
+    pop_eh
+    library = new 'Hash'
+    library['name'] = name
+    library['filename'] = file
+    # If this fails, we should build a hash of DEFAULT and ALL => the normal ns
+    $P0 = get_hll_global name, 'EXPORT'
+    library['symbols'] = $P0
+    $P0 = get_hll_namespace name
+    library['namespace'] = $P0
+    .return (library)
+  fail:
+    # TODO: better fail?
+    .return (0)
+.end
+
+.sub 'export-symbols' :method
+    .param string list
+    # This should accept a tag...
+    .local pmc syms, i, ns, relns, exportns
+    # We should default to all symbols when none are specified
+    syms = split ' ', list
+    i = getinterp
+    ns = i['namespace';1]
+    relns = new 'ResizablePMCArray'
+    relns.'push'('EXPORT')
+    # This could be a loop, I guess...
+    relns.'push'('ALL')
+    exportns = ns.'make_namespace'(relns)
+    ns.'export_to'(exportns, syms)
+    relns.'pop'()
+    relns.'push'('DEFAULT')
+    exportns = ns.'make_namespace'(relns)
+    ns.'export_to'(exportns, syms)
+.end
+
+# TODO Should this provide support for loading HLL libraries?
+
+=head1 NAME
+
+languages/parrot/parrot.pir - Compiler object for interop between HLLs and
+Parrot-hosted languages
+
+=head1 SYNOPSIS
+
+    # NameSpace MUST match path!
+    .namespace ['Foo']
+    .sub 'load' :anon :load :init
+        .local pmc c
+        load_language 'parrot'
+        c = compreg 'parrot'
+        c.'export-symbols'('dance leap')
+    .end
+
+    .sub 'dance'
+        say 'lol dancing'
+    .end
+
+    .sub 'leap'
+        say 'like dancing, but fancier'
+    .end
+
+=cut
+
+# Local Variables:
+#   mode: pir
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:
+


More information about the parrot-commits mailing list