Skip to content
Browse files

Evaling perl5 code loads the Perl5Interpreter class.

Perl5 interop support is built with "make perl5"
  • Loading branch information...
1 parent 2802b4e commit e5a3ec51eecf4a11375ddd131c360e353f776cb3 @pmurias pmurias committed
Showing with 24 additions and 1 deletion.
  1. +3 −0 Makefile
  2. +3 −0 examples/perl5.pl
  3. +9 −1 lib/Builtins.cs
  4. +9 −0 lib/Perl5Interpreter.cs
View
3 Makefile
@@ -55,6 +55,9 @@ 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
+obj/Perl5Interpreter.dll: obj/Kernel.dll lib/Perl5Interpreter.cs
+ gmcs /target:library /lib:obj /out:obj/Perl5Interpreter.dll /r:Kernel.dll lib/Perl5Interpreter.cs
aot: all
mono --aot run/*.dll run/Niecza.exe
View
3 examples/perl5.pl
@@ -0,0 +1,3 @@
+# Doesn't properly work yet
+eval("print \"Hello\";",:lang<perl5>);
+eval("print \"World\\n\";",:lang<perl5>);
View
10 lib/Builtins.cs
@@ -7,6 +7,9 @@
using System.Runtime.CompilerServices;
namespace Niecza {
+ public interface ForeignInterpreter {
+ void eval(string code);
+ }
class PosixWrapper {
static Assembly Mono_Posix;
static Type Syscall, AccessModes, Stat;
@@ -937,6 +940,7 @@ class SubstrLValue: Variable {
}
static Func<Variable,Variable> eval_perl5_d = eval_perl5;
+ static ForeignInterpreter p5_interpreter;
public static Variable eval_perl5(Variable v) {
// Cargo culted to get the string from the argument
@@ -946,7 +950,11 @@ class SubstrLValue: Variable {
return HandleSpecial1(v,o1, eval_perl5_d);
string r = o1.mo.mro_raw_Str.Get(v);
- System.Console.WriteLine("evaling perl5 code (NYI):"+r);
+ if (p5_interpreter == null) {
+ System.Reflection.Assembly a = System.Reflection.Assembly.LoadFrom("obj/Perl5Interpreter.dll");
+ p5_interpreter = (ForeignInterpreter) a.CreateInstance("Perl5Interpreter");
+ }
+ p5_interpreter.eval(r);
return MakeInt(666);
}
View
9 lib/Perl5Interpreter.cs
@@ -0,0 +1,9 @@
+using Niecza;
+public class Perl5Interpreter : ForeignInterpreter {
+ public Perl5Interpreter() {
+ System.Console.WriteLine("creating perl5 interpreter");
+ }
+ public void eval(string code) {
+ System.Console.WriteLine("evaling perl5 (NYI):"+code);
+ }
+}

0 comments on commit e5a3ec5

Please sign in to comment.
Something went wrong with that request. Please try again.