Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Exporting a single sub works.

  • Loading branch information...
commit d05a5fe59747d5b9dc2103c57b42191c4791b53b 1 parent 3da37be
Paweł Murias authored
2  lib/CodeGen.cs
View
@@ -3692,7 +3692,7 @@ public class DowncallReceiver : CallReceiver {
return new string[0];
return Builtins.UnboxLoS(bv.v);
}
- public static object unit_use_from_perl5(object[] args) {
+ public static object unit_use_perl5_module(object[] args) {
string name = (string)args[2];
Variable code = Kernel.BoxAnyMO<string>("Niecza::Interoperability::use_module('"+name+"')", Kernel.StrMO);
string sub = Kernel.UnboxAny<string>(Builtins.eval_perl5(code).Fetch());
2  lib/Perl5Interpreter.cs
View
@@ -187,7 +187,7 @@ int argument_n
if (name == "postcircumfix:<( )>") {
int context = 1;
- if (named != null && named["context"] != null) {
+ if (named != null && named.ContainsKey("context") && named["context"] != null) {
context = Context(named["context"]);
}
IntPtr[] args = MarshalPositionals(pos);
4 perl5/Niecza/Interoperability.pm
View
@@ -4,12 +4,12 @@ use Package::Stash;
my $id = 0;
sub use_module {
my ($module) = @_;
- my $stash = Package::Stash->new('Niecza::Stash::Interopability::TMP'.$id++);
+ my $stash = Package::Stash->new('main');#'Niecza::Stash::Interopability::TMP'.$id++);
eval("package ".$stash->name.";use $module;");
warn $@ if $@;
my @subs = $stash->list_all_symbols('CODE');
for my $symbol (@subs) {
- say "importing sub $symbol from $module";
+ #say "importing sub $symbol from $module";
}
$subs[0];
}
33 src/NieczaActions.pm6
View
@@ -3376,6 +3376,28 @@ method statement_control:when ($/) {
body => self.inliney_call($/, $<xblock>.ast[1]));
}
+method use_from_perl5($/,$name) {
+ my $sub = $*CURLEX<!sub>;
+ my $func = $*unit.use_perl5_module($name);
+
+ my $placeholder = $*unit.create_sub(
+ outer => $sub,
+ cur_pkg => $sub.cur_pkg,
+ name => "placeholder",
+ class => 'Code');
+
+ my $p5code = '\\&'~$func;
+ my $p5sub = $OpCallSub.new(pos=>$/,invocant=>mklex($/,'&eval'),args=>[$OpStringLiteral.new(text=>$p5code),$OpSimplePair.new(key=>'lang',value=>$OpStringLiteral.new(text=>'perl5'))]);
+ $placeholder.add_my_name('|capture');
+ my $sig = $Sig.new(params => [$SigParameter.new(flags=>$Sig::SLURPY_CAP,name=>'|capture',slot=>'|capture')]);
+ $placeholder.set_signature($sig);
+ my $args = mkcall($/,'&prefix:<|>',mklex($/,'|capture'));
+ my $body = $OpCallSub.new(pos=>$/, invocant => $p5sub,args=>[$args]);
+
+ $placeholder.finish($body);
+
+ $*CURLEX<!sub>.add_my_sub($func,$placeholder);
+}
method statement_control:use ($/) {
make $OpStatementList.new;
return if $<version>; # just ignore these
@@ -3383,20 +3405,11 @@ method statement_control:use ($/) {
my $name = $<module_name>.ast<name>;
my $args = $<arglist> ?? $<arglist>.ast !! [];
- my $sub = $*CURLEX<!sub>;
- my $placeholder = $*unit.create_sub(
- outer => $sub,
- cur_pkg => $sub.cur_pkg,
- name => "placeholder",
- class => 'Code');
- $placeholder.finish($OpStatementList.new);
# support loading modules from perl5
if $<module_name><longname><colonpair> -> $pairs {
if $pairs[0].<identifier> eq 'from' && $pairs[0].<coloncircumfix><circumfix><nibble> eq 'perl5' {
- my $func = $*unit.use_from_perl5($name);
- say "importing $func from p5 land";
- $*CURLEX<!sub>.add_my_sub($func,$placeholder);
+ self.use_from_perl5($/,$name);
return;
} else {
$/.CURSOR.sorry("NYI");
Please sign in to comment.
Something went wrong with that request. Please try again.