Permalink
Browse files

Argumentless method call on perl5 objects.

  • Loading branch information...
1 parent 16ef0c8 commit 4266b4443c6d9bc655a3a179bde7d96592101b19 @pmurias pmurias committed Sep 24, 2011
Showing with 81 additions and 12 deletions.
  1. +21 −3 examples/perl5.pl
  2. +2 −4 lib/Builtins.cs
  3. +38 −3 lib/Perl5Interpreter.cs
  4. +20 −2 lib/p5embed.c
View
@@ -1,3 +1,21 @@
-# Doesn't properly work yet
-eval("print \"Hello \";",:lang<perl5>);
-eval("print \"World\\n\";",:lang<perl5>);
+eval(q:to/PERL5/,:lang<perl5>);
+ print "Hel"."lo ";
+ PERL5
+eval(q:to/PERL5/,:lang<perl5>);
+ print "World\n";
+ PERL5
+
+eval(q:to/PERL5/,:lang<perl5>);
+use strict;
+use warnings;
+package Foo;
+sub baz {
+ my ($self,$arg) = @_;
+ print "calling method\n";
+}
+sub new {
+ bless {},"Foo";
+}
+PERL5
+my $foo = eval(:lang<perl5>,'Foo->new');
+$foo.baz(eval(:lang<perl5>,'"Hello World"'));
View
@@ -8,7 +8,7 @@
namespace Niecza {
public interface IForeignInterpreter {
- void Eval(string code);
+ Variable Eval(string code);
}
class PosixWrapper {
static Assembly Mono_Posix;
@@ -954,9 +954,7 @@ class SubstrLValue: Variable {
System.Reflection.Assembly a = System.Reflection.Assembly.Load("Perl5Interpreter");
p5_interpreter = (IForeignInterpreter) a.CreateInstance("Perl5Interpreter");
}
- p5_interpreter.Eval(r);
-
- return MakeInt(666);
+ return p5_interpreter.Eval(r);
}
// we don't need to do nominal checking stuff here because this
@@ -1,5 +1,6 @@
using Niecza;
using System.Runtime.InteropServices;
+using System;
public class Perl5Interpreter : IForeignInterpreter {
[DllImport("obj/p5embed.so", EntryPoint="p5embed_initialize")]
@@ -9,15 +10,49 @@ public class Perl5Interpreter : IForeignInterpreter {
public static extern void Dispose();
[DllImport("obj/p5embed.so", EntryPoint="p5embed_eval")]
- public static extern void EvalPerl5(string code);
+ public static extern IntPtr EvalPerl5(string code);
+
+
public Perl5Interpreter() {
Initialize();
}
~Perl5Interpreter() {
Dispose();
}
- public void Eval(string code) {
- EvalPerl5(code);
+ public Variable Eval(string code) {
+ return new SVVariable(EvalPerl5(code));
+ }
+}
+
+public class SVVariable : Variable {
+ public IntPtr sv;
+ public SVVariable(IntPtr _sv) {
+ sv = _sv;
+ }
+ public override P6any Fetch() {
+ return new SVany(sv);
+ }
+ public override void Store(P6any v) {
+ }
+ public override Variable GetVar() {
+ return Kernel.BoxAnyMO<Variable>(this, Kernel.ScalarMO);
+
}
}
+public class SVany : P6any {
+ [DllImport("obj/p5embed.so", EntryPoint="p5method_call")]
+ public static extern IntPtr MethodCall(string code,IntPtr invocant);
+
+ public IntPtr sv;
+ public override Frame InvokeMethod(Frame caller, string name,
+ Variable[] pos, VarHash named) {
+ MethodCall(name,sv);
+ return caller;
+ }
+ public SVany(IntPtr _sv) {
+ mo = Kernel.AnyMO;
+ sv = _sv;
+ }
+}
+
View
@@ -29,8 +29,8 @@ void p5embed_initialize()
eval_pv("use lib 'perl5';use Niecza::Interoperability",TRUE);
}
-void p5embed_eval(char* code) {
- eval_pv(code,TRUE);
+SV* p5embed_eval(char* code) {
+ return eval_pv(code,TRUE);
}
void p5embed_dispose()
@@ -39,3 +39,21 @@ void p5embed_dispose()
perl_free(my_perl);
PERL_SYS_TERM();
}
+
+void p5method_call(char* name,SV* invocant) {
+ dSP;
+
+ SvREFCNT_inc(invocant);
+
+ /*ENTER;
+ SAVETMPS;*/
+
+ PUSHMARK(SP);
+ XPUSHs(invocant);
+ PUTBACK;
+
+ call_method(name,G_DISCARD);
+
+ /*FREETMPS;
+ LEAVE;*/
+}

0 comments on commit 4266b44

Please sign in to comment.