Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Eval runs basic perl5 code. The Makefile needs review to check if it can

be made more portable.
  • Loading branch information...
commit 1e1a24ea869334511e449354749934cbf5cd7518 1 parent 87f66df
@pmurias pmurias authored
View
6 Makefile
@@ -55,10 +55,14 @@ obj/Kernel.dll: $(patsubst %,lib/%,$(cskernel))
obj/CLRBackend.exe: $(patsubst %,lib/%,$(csbackend)) obj/Kernel.dll
$(CSC) /target:exe /lib:obj /out:obj/CLRBackend.exe /r:Kernel.dll \
$(patsubst %,lib/%,$(csbackend))
-perl5: obj/Perl5Interpreter.dll
+
+perl5: obj/Perl5Interpreter.dll obj/p5embed.so
obj/Perl5Interpreter.dll: obj/Kernel.dll lib/Perl5Interpreter.cs
gmcs /target:library /lib:obj /out:obj/Perl5Interpreter.dll /r:Kernel.dll lib/Perl5Interpreter.cs
+obj/p5embed.so: lib/p5embed.c
+ cc -shared -Wl,-soname,p5embed.so -o obj/p5embed.so lib/p5embed.c `perl -MExtUtils::Embed -e ccopts -e ldopts`
+
aot: all
mono --aot run/*.dll run/Niecza.exe
View
2  examples/perl5.pl
@@ -1,3 +1,3 @@
# Doesn't properly work yet
-eval("print \"Hello\";",:lang<perl5>);
+eval("print \"Hello \";",:lang<perl5>);
eval("print \"World\\n\";",:lang<perl5>);
View
4 lib/Builtins.cs
@@ -8,7 +8,7 @@
namespace Niecza {
public interface IForeignInterpreter {
- void eval(string code);
+ void Eval(string code);
}
class PosixWrapper {
static Assembly Mono_Posix;
@@ -954,7 +954,7 @@ class SubstrLValue: Variable {
System.Reflection.Assembly a = System.Reflection.Assembly.Load("Perl5Interpreter");
p5_interpreter = (IForeignInterpreter) a.CreateInstance("Perl5Interpreter");
}
- p5_interpreter.eval(r);
+ p5_interpreter.Eval(r);
return MakeInt(666);
}
View
17 lib/Perl5Interpreter.cs
@@ -1,9 +1,20 @@
using Niecza;
+using System.Runtime.InteropServices;
+
public class Perl5Interpreter : IForeignInterpreter {
+ [DllImport("obj/p5embed.so", EntryPoint="p5embed_initialize")]
+ public static extern void Initialize();
+
+ [DllImport("obj/p5embed.so", EntryPoint="p5embed_dispose")]
+ public static extern void Dispose();
+
+ [DllImport("obj/p5embed.so", EntryPoint="p5embed_eval")]
+ public static extern void EvalPerl5(string code);
+
public Perl5Interpreter() {
- System.Console.WriteLine("creating perl5 interpreter");
+ Initialize();
}
- public void eval(string code) {
- System.Console.WriteLine("evaling perl5 (NYI):"+code);
+ public void Eval(string code) {
+ EvalPerl5(code);
}
}
View
38 lib/p5embed.c
@@ -0,0 +1,38 @@
+#include <EXTERN.h>
+#include <perl.h>
+
+/* So that we can load XS using modules from our perl */
+EXTERN_C void xs_init (pTHX);
+
+EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
+
+EXTERN_C void
+xs_init(pTHX)
+{
+ char *file = __FILE__;
+ dXSUB_SYS;
+
+ /* DynaLoader is a special case */
+ newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
+}
+
+static PerlInterpreter *my_perl;
+void p5embed_initialize()
+{
+ PERL_SYS_INIT3(0,NULL,NULL);
+ PerlInterpreter* my_perl = perl_alloc();
+ PERL_SET_CONTEXT(my_perl);
+ perl_construct(my_perl);
+ char *embedding[] = { "", "-e", "0" };
+ perl_parse(my_perl, xs_init, 3, embedding, NULL);
+ PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
+ eval_pv("use lib 'perl5';use Niecza::Interoperability",TRUE);
+}
+
+void p5embed_eval(char* code) {
+ eval_pv(code,TRUE);
+}
+
+void p5embed_dispose()
+{
+}
View
3  perl5/Niecza/Interoperability.pm
@@ -0,0 +1,3 @@
+package Niecza::Interoperability;
+#BEGIN {print "ok 1 # loaded Niecza::Interoperability\n"}
+1;
Please sign in to comment.
Something went wrong with that request. Please try again.