Permalink
Browse files

Very basic :from<java> support.

The objects are decidedly lacking in sugar so far, not to mention the
marshalling of Perl 6 types will need a lot of work. But you can do:

    use java::lang::System:from<java>;
    say System.currentTimeMillis();

And it works.
  • Loading branch information...
1 parent 42c2152 commit d3b14a7458e1c421d2d447fea798512d99448ce3 @jnthn jnthn committed Aug 5, 2013
Showing with 32 additions and 2 deletions.
  1. +30 −0 src/vm/jvm/Perl6/JavaModuleLoader.nqp
  2. +2 −2 tools/build/Makefile-JVM.in
View
30 src/vm/jvm/Perl6/JavaModuleLoader.nqp
@@ -0,0 +1,30 @@
+class Perl6::JavaModuleLoader {
+ my $interop;
+
+ method load_module($module_name, %opts, *@GLOBALish, :$line, :$file?) {
+ # Load interop support if needed.
+ $interop := nqp::jvmbootinterop() unless nqp::isconcrete($interop);
+
+ # Try to get hold of the type.
+ my @parts := nqp::split('::', $module_name);
+ my $jname := nqp::join('.', @parts);
+ my $type := try $interop.typeForName($jname);
+ if $type =:= NQPMu {
+ nqp::die("Could not locate Java module $jname");
+ }
+
+ # Return unit-like thing with an EXPORT::DEFAULT.
+ nqp::hash('EXPORT', make_package('EXPORT',
+ nqp::hash('DEFAULT', make_package('DEFAULT',
+ nqp::hash(@parts[nqp::elems(@parts) - 1], $type)))))
+ }
+
+ sub make_package($name, %who) {
+ my $pkg := nqp::knowhow().new_type(:$name);
+ $pkg.HOW.compose($pkg);
+ nqp::setwho($pkg, %who);
+ $pkg
+ }
+}
+
+Perl6::ModuleLoader.register_language_module_loader('java', Perl6::JavaModuleLoader);
View
4 tools/build/Makefile-JVM.in
@@ -227,8 +227,8 @@ $(RUNTIME_JAR): $(RUNTIME_JAVAS)
$(JAVAC) -source 1.7 -cp $(NQP_JARS) -g -d bin $(RUNTIME_JAVAS)
$(JAR) cf0 rakudo-runtime.jar -C bin/ .
-$(PERL6_ML_JAR): src/Perl6/ModuleLoader.nqp src/vm/jvm/ModuleLoaderVMConfig.nqp
- $(PERL) $(GEN_CAT) src/vm/jvm/ModuleLoaderVMConfig.nqp src/Perl6/ModuleLoader.nqp > src/gen/ModuleLoader.nqp
+$(PERL6_ML_JAR): src/Perl6/ModuleLoader.nqp src/vm/jvm/ModuleLoaderVMConfig.nqp src/vm/jvm/Perl6/JavaModuleLoader.nqp
+ $(PERL) $(GEN_CAT) src/vm/jvm/ModuleLoaderVMConfig.nqp src/Perl6/ModuleLoader.nqp src/vm/jvm/Perl6/JavaModuleLoader.nqp > src/gen/ModuleLoader.nqp
$(NQP) --target=jar --output=$(PERL6_ML_JAR) --encoding=utf8 \
src/gen/ModuleLoader.nqp

0 comments on commit d3b14a7

Please sign in to comment.