diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 1998-11-30 01:30:44 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1998-11-30 01:30:44 +0000 |
commit | 93e0cdbd0f68fd8d8d75c3510f7893c1ebaa26ae (patch) | |
tree | a6c84af1c502bc73fa1730324995f4e1fcb207b3 /jpl/PerlInterpreter | |
parent | a8710ca18eb34a984d0dfab8503448f77a53b379 (diff) | |
parent | 57dea26d80db9a1b455ef89cc843930fe18b0369 (diff) | |
download | perl-93e0cdbd0f68fd8d8d75c3510f7893c1ebaa26ae.tar.gz |
branch jpl from perlext to perl
p4raw-id: //depot/perl@2410
Diffstat (limited to 'jpl/PerlInterpreter')
-rw-r--r-- | jpl/PerlInterpreter/Makefile | 43 | ||||
-rw-r--r-- | jpl/PerlInterpreter/Makefile.PL | 70 | ||||
-rw-r--r-- | jpl/PerlInterpreter/PerlInterpreter.c | 129 | ||||
-rw-r--r-- | jpl/PerlInterpreter/PerlInterpreter.h | 29 | ||||
-rw-r--r-- | jpl/PerlInterpreter/PerlInterpreter.java | 21 |
5 files changed, 292 insertions, 0 deletions
diff --git a/jpl/PerlInterpreter/Makefile b/jpl/PerlInterpreter/Makefile new file mode 100644 index 0000000000..a615fe173d --- /dev/null +++ b/jpl/PerlInterpreter/Makefile @@ -0,0 +1,43 @@ +WHAT = PerlInterpreter +JAVA_HOME = /usr/local/java +JPL_HOME = /usr/local/jpl +ARCHNAME = sun4-solaris +PERLARCHDIR = /usr/local/lib/perl5/sun4-solaris/5.00404 +CC = gcc +FLAGS = -fPIC -R /usr/local/lib/perl5/sun4-solaris/5.00404/CORE -G -L/usr/local/lib +INCL = -I$(PERLARCHDIR)/CORE \ + -I$(JAVA_HOME)/include \ + -I$(JAVA_HOME)/include/solaris \ + -I$(JAVA_HOME)/include/genunix +LIBS = -lc -lm -ldl + +.SUFFIXES: .java .class + +.java.class: + javac $*.java + +.class.h: + javah -jni $* + +all: PerlInterpreter.class libPerlInterpreter.so + +PerlInterpreter.class: PerlInterpreter.java + +PerlInterpreter.h: PerlInterpreter.class + +libPerlInterpreter.so: PerlInterpreter.c PerlInterpreter.h + $(CC) $(FLAGS) $(INCL) PerlInterpreter.c \ + $(PERLARCHDIR)/auto/DynaLoader/DynaLoader.a \ + $(LIBS) \ + -o libPerlInterpreter.so + +test: + +install: all + mkdir -p $(JPL_HOME)/lib/$(ARCHNAME) + cp libPerlInterpreter.so $(JPL_HOME)/lib/$(ARCHNAME) + cp $(WHAT).class $(JPL_HOME)/lib + +clean: + rm -f libPerlInterpreter.so + rm -f PerlInterpreter.class diff --git a/jpl/PerlInterpreter/Makefile.PL b/jpl/PerlInterpreter/Makefile.PL new file mode 100644 index 0000000000..76852c6cc8 --- /dev/null +++ b/jpl/PerlInterpreter/Makefile.PL @@ -0,0 +1,70 @@ +#!/usr/bin/perl + +$JPL_SRC = ".."; + +use Config; + +eval `$JPL_SRC/setvars -perl`; + +if ($^O eq 'linux') { + $flags = "-Dbool=char"; # avoid builtin bool altogether + $libs = "-lc -lm -ldl"; +} +else { + $flags = ""; + $libs = "-lc -lm -ldl"; +} + +open(MAKEFILE, ">Makefile"); + +print MAKEFILE <<"SUBS"; +WHAT = PerlInterpreter +JAVA_HOME = $ENV{JAVA_HOME} +JPL_HOME = $ENV{JPL_HOME} +ARCHNAME = $Config{archname} +PERLARCHDIR = $Config{archlib} +CC = $Config{cc} +FLAGS = $Config{cccdlflags} $Config{ccdlflags} $Config{lddlflags} $flags +INCL = -I\$(PERLARCHDIR)/CORE \\ + -I\$(JAVA_HOME)/include \\ + -I\$(JAVA_HOME)/include/$^O \\ + -I\$(JAVA_HOME)/include/genunix +LIBS = $libs + +SUBS + + +print MAKEFILE <<'NOSUBS'; +.SUFFIXES: .java .class + +.java.class: + javac $*.java + +.class.h: + javah -jni $* + +all: PerlInterpreter.class libPerlInterpreter.so + +PerlInterpreter.class: PerlInterpreter.java + +PerlInterpreter.h: PerlInterpreter.class + +libPerlInterpreter.so: PerlInterpreter.c PerlInterpreter.h + $(CC) $(FLAGS) $(INCL) PerlInterpreter.c \ + $(PERLARCHDIR)/auto/DynaLoader/DynaLoader.a \ + $(LIBS) \ + -o libPerlInterpreter.so + +test: + +install: all + mkdir -p $(JPL_HOME)/lib/$(ARCHNAME) + cp libPerlInterpreter.so $(JPL_HOME)/lib/$(ARCHNAME) + cp $(WHAT).class $(JPL_HOME)/lib + +clean: + rm -f libPerlInterpreter.so + rm -f PerlInterpreter.class +NOSUBS + +close MAKEFILE; diff --git a/jpl/PerlInterpreter/PerlInterpreter.c b/jpl/PerlInterpreter/PerlInterpreter.c new file mode 100644 index 0000000000..8bf3f5f17a --- /dev/null +++ b/jpl/PerlInterpreter/PerlInterpreter.c @@ -0,0 +1,129 @@ +/* + * "The Road goes ever on and on, down from the door where it began." + */ + +#include "PerlInterpreter.h" +#include <dlfcn.h> + +#include "EXTERN.h" +#include "perl.h" + +#ifndef EXTERN_C +# ifdef __cplusplus +# define EXTERN_C extern "C" +# else +# define EXTERN_C extern +# endif +#endif + +static void xs_init _((void)); +static PerlInterpreter *my_perl; + +int jpldebug = 0; +JNIEnv *jplcurenv; + +JNIEXPORT void JNICALL +Java_PerlInterpreter_init(JNIEnv *env, jobject obj, jstring js) +{ + int exitstatus; + int argc = 3; + SV* envsv; + SV* objsv; + + static char *argv[] = {"perl", "-e", "1", 0}; + + if (getenv("JPLDEBUG")) + jpldebug = atoi(getenv("JPLDEBUG")); + + if (jpldebug) + fprintf(stderr, "init\n"); + + if (!dlopen("libperl.so", RTLD_LAZY|RTLD_GLOBAL)) { + fprintf(stderr, "%s\n", dlerror()); + exit(1); + } + + if (PL_curinterp) + return; + + perl_init_i18nl10n(1); + + if (!PL_do_undump) { + my_perl = perl_alloc(); + if (!my_perl) + exit(1); + perl_construct( my_perl ); + PL_perl_destruct_level = 0; + } + + exitstatus = perl_parse( my_perl, xs_init, argc, argv, (char **) NULL ); + + if (!exitstatus) + Java_PerlInterpreter_eval(env, obj, js); + +} + +JNIEXPORT void JNICALL +Java_PerlInterpreter_eval(JNIEnv *env, jobject obj, jstring js) +{ + SV* envsv; + SV* objsv; + dSP; + jbyte* jb; + + ENTER; + SAVETMPS; + + jplcurenv = env; + envsv = perl_get_sv("JPL::_env_", 1); + sv_setiv(envsv, (IV)(void*)env); + objsv = perl_get_sv("JPL::_obj_", 1); + sv_setiv(objsv, (IV)(void*)obj); + + jb = (jbyte*)(*env)->GetStringUTFChars(env,js,0); + + if (jpldebug) + fprintf(stderr, "eval %s\n", (char*)jb); + + perl_eval_pv( (char*)jb, 0 ); + + if (SvTRUE(ERRSV)) { + jthrowable newExcCls; + + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + + newExcCls = (*env)->FindClass(env, "java/lang/RuntimeException"); + if (newExcCls) + (*env)->ThrowNew(env, newExcCls, SvPV(ERRSV,PL_na)); + } + + (*env)->ReleaseStringUTFChars(env,js,jb); + FREETMPS; + LEAVE; + +} + +/* +JNIEXPORT jint JNICALL +Java_PerlInterpreter_eval(JNIEnv *env, jobject obj, jint ji) +{ + op = (OP*)(void*)ji; + op = (*op->op_ppaddr)(); + return (jint)(void*)op; +} +*/ + +/* Register any extra external extensions */ + +/* Do not delete this line--writemain depends on it */ +EXTERN_C void boot_DynaLoader _((CV* cv)); +EXTERN_C void boot_JNI _((CV* cv)); + +static void +xs_init() +{ + char *file = __FILE__; + dXSUB_SYS; + newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); +} diff --git a/jpl/PerlInterpreter/PerlInterpreter.h b/jpl/PerlInterpreter/PerlInterpreter.h new file mode 100644 index 0000000000..22fdf526dc --- /dev/null +++ b/jpl/PerlInterpreter/PerlInterpreter.h @@ -0,0 +1,29 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include <jni.h> +/* Header for class PerlInterpreter */ + +#ifndef _Included_PerlInterpreter +#define _Included_PerlInterpreter +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: PerlInterpreter + * Method: init + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_PerlInterpreter_init + (JNIEnv *, jobject, jstring); + +/* + * Class: PerlInterpreter + * Method: eval + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_PerlInterpreter_eval + (JNIEnv *, jobject, jstring); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/jpl/PerlInterpreter/PerlInterpreter.java b/jpl/PerlInterpreter/PerlInterpreter.java new file mode 100644 index 0000000000..c26a4f2ba4 --- /dev/null +++ b/jpl/PerlInterpreter/PerlInterpreter.java @@ -0,0 +1,21 @@ +class PerlInterpreter { + static boolean initted = false; + + public native void init(String s); + public native void eval(String s); + +// public native long op(long i); + + public PerlInterpreter fetch () { + if (!initted) { + init("$JPL::DEBUG = $ENV{JPLDEBUG}"); + initted = true; + } + return this; + } + + static { + System.loadLibrary("PerlInterpreter"); + } +} + |