[svn:parrot] r37084 - in trunk: . examples/pir
NotFound at svn.parrot.org
NotFound at svn.parrot.org
Mon Mar 2 22:39:15 UTC 2009
Author: NotFound
Date: Mon Mar 2 22:39:14 2009
New Revision: 37084
URL: https://trac.parrot.org/parrot/changeset/37084
Log:
[examples] pir example of HLL interoperability
Added:
trunk/examples/pir/interlangs.pir (contents, props changed)
Modified:
trunk/MANIFEST
trunk/MANIFEST.SKIP
Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST Mon Mar 2 21:56:33 2009 (r37083)
+++ trunk/MANIFEST Mon Mar 2 22:39:14 2009 (r37084)
@@ -1,7 +1,7 @@
# ex: set ro:
# $Id$
#
-# generated by tools/dev/mk_manifest_and_skip.pl Mon Mar 2 07:36:01 2009 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Mon Mar 2 22:35:00 2009 UT
#
# See tools/dev/install_files.pl for documentation on the
# format of this file.
@@ -704,6 +704,7 @@
examples/pir/genprog.bas [examples]
examples/pir/hanoi.pir [examples]
examples/pir/interlangs.bas [examples]
+examples/pir/interlangs.pir [examples]
examples/pir/io.pir [examples]
examples/pir/levenshtein.pir [examples]
examples/pir/life.pir [examples]
@@ -2859,7 +2860,7 @@
tools/dev/manicheck.pl []
tools/dev/mk_gitignore.pl []
tools/dev/mk_inno.pl []
-tools/dev/mk_inno_language.pl [devel]
+tools/dev/mk_inno_language.pl []
tools/dev/mk_language_shell.pl []
tools/dev/mk_manifest_and_skip.pl []
tools/dev/mk_native_pbc []
Modified: trunk/MANIFEST.SKIP
==============================================================================
--- trunk/MANIFEST.SKIP Mon Mar 2 21:56:33 2009 (r37083)
+++ trunk/MANIFEST.SKIP Mon Mar 2 22:39:14 2009 (r37084)
@@ -1,6 +1,6 @@
# ex: set ro:
# $Id$
-# generated by tools/dev/mk_manifest_and_skip.pl Fri Feb 27 12:48:05 2009 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Mon Mar 2 22:35:00 2009 UT
#
# This file should contain a transcript of the svn:ignore properties
# of the directories in the Parrot subversion repository. (Needed for
@@ -917,6 +917,12 @@
^languages/scheme/t/syn/.*\.scheme$
^languages/scheme/t/syn/.*\.scheme/
# generated from svn:ignore of 'languages/squaak/'
+^languages/squaak/.*\.c$
+^languages/squaak/.*\.c/
+^languages/squaak/.*\.exe$
+^languages/squaak/.*\.exe/
+^languages/squaak/.*\.iss$
+^languages/squaak/.*\.iss/
^languages/squaak/.*\.pbc$
^languages/squaak/.*\.pbc/
^languages/squaak/Makefile$
Added: trunk/examples/pir/interlangs.pir
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/examples/pir/interlangs.pir Mon Mar 2 22:39:14 2009 (r37084)
@@ -0,0 +1,115 @@
+# Copyright (C) 2009, Parrot Foundation.
+# $Id$
+
+# interlangs.pir
+# An example of language interoperability
+
+# First build perl6, ecmascript and pipp
+# Then do:
+# ../../parrot -L /yourparrotdir/languages/rakudo
+# -L /yourparrotdir/languages/ecmascript
+# -L /yourparrotdir/languages/pipp
+# interlangs.pir
+
+#-----------------------------------------------------------------------
+
+.sub main :main
+ .local pmc perl6func, jsfunc, pippfunc
+
+ say 'Loading languages and compiling...'
+ # Compile functions
+ perl6func = get_perl6_func()
+ jsfunc = get_js_func()
+ pippfunc = get_pipp_func()
+
+ # Call js and pipp functions directly
+ say "\nDirect calls\n"
+ jsfunc('pir')
+ pippfunc('pir')
+
+ # Pass js and pipp functions to perl6 function
+ say "\nCalls from perl6\n"
+ $S1 = perl6func('pir', jsfunc)
+ print 'Returned: '
+ say $S1
+ $S1 = perl6func('pir', pippfunc)
+ print 'Returned: '
+ say $S1
+
+ say "\nBye!"
+.end
+
+#-----------------------------------------------------------------------
+
+# Compile perl6 code that return a function,
+# execute it, and return the result.
+
+.sub get_perl6_func
+ load_bytecode 'perl6.pbc'
+ .local pmc compiler, code, function
+ compiler = compreg 'Perl6'
+ code = compiler.'compile'(<<'ENDCODE')
+sub ($a, $b)
+{
+ $b('perl6->' ~ $a);
+ 'Hello from a perl6 sub, ' ~ $a;
+};
+ENDCODE
+ function = code()
+ .return(function)
+.end
+
+#-----------------------------------------------------------------------
+
+# Compile ecmascript code that define a function,
+# execute it and get the function from the
+# js namespace.
+
+.sub get_js_func
+ load_bytecode 'js.pbc'
+ .local pmc compiler, code, block, ns, function
+ compiler = compreg 'JS'
+ code = compiler.'compile'(<<'JSCODE')
+function myecmascriptfunc(n)
+{
+ print ('Hello from ecmascript,', n);
+}
+JSCODE
+ block = code()
+ ns = get_root_global 'js'
+ function = ns['myecmascriptfunc']
+ .return(function)
+.end
+
+#-----------------------------------------------------------------------
+
+# Compile php code that define a function,
+# and get the function from the pipp
+# namespace
+
+.sub get_pipp_func
+ load_bytecode 'pipp.pbc'
+ .local pmc compiler, code, ns, function
+ compiler = compreg 'Pipp'
+ code = compiler.'compile'(<<'PIPPCODE')
+<?php
+function phpfunc($msg)
+{
+ echo "Hello from pipp, $msg\n";
+}
+?>
+PIPPCODE
+ ns = get_root_global 'pipp'
+ function = ns['phpfunc']
+ .return(function)
+.end
+
+#-----------------------------------------------------------------------
+# That's all folks!
+
+########################################################################
+# Local Variables:
+# mode: pir
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:
More information about the parrot-commits
mailing list