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/Test | |
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/Test')
-rw-r--r-- | jpl/Test/Makefile.PL | 84 | ||||
-rw-r--r-- | jpl/Test/Test.jpl | 122 |
2 files changed, 206 insertions, 0 deletions
diff --git a/jpl/Test/Makefile.PL b/jpl/Test/Makefile.PL new file mode 100644 index 0000000000..3dd1f84411 --- /dev/null +++ b/jpl/Test/Makefile.PL @@ -0,0 +1,84 @@ +#!/usr/bin/perl + +$JPL_HOME = $ENV{JPL_HOME} + or die "You have not run setvars to set your environment variables.\n" . + "See the JPL README file for more information.\n"; + +use Config; + +eval `$JPL_HOME/setvars -perl`; + +chop($WHAT = `pwd`); +$WHAT =~ s#.*/##; + +if ($^O eq 'linux') { + $flags = "-Dbool=char"; # avoid builtin bool altogether + $libs = "-lc -lm -ldl"; +} +else { + $flags = ""; + $libs = "-lc -lm -ldl"; +} +chop($cwd = `pwd`); +($jpldir = $cwd) =~ s#/[^/]*$##; + +open(MAKEFILE, ">Makefile"); + +print MAKEFILE <<"SUBS"; +CC = $Config{cc} +WHAT = $WHAT +PERL = perl$] +ARCHNAME = $Config{archname} +JAVA_HOME = $ENV{JAVA_HOME} +JPL_HOME = $ENV{JPL_HOME} +PERLARCHDIR = $Config{archlib} +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: .jpl .class + +.jpl.class: + $(PERL) -MJPL::Compile -e "file('$*.jpl')" + +all: $(WHAT).class lib$(WHAT).so + +debug: $(WHAT)_g.class lib$(WHAT)_g.so + +lib$(WHAT).so: $(WHAT).c $(JPL_HOME)/lib/$(ARCHNAME)/libPerlInterpreter.so + $(CC) $(FLAGS) $(INCL) $(WHAT).c \ + $(PERLARCHDIR)/CORE/libperl.so \ + $(JPL_HOME)/lib/$(ARCHNAME)/libPerlInterpreter.so \ + $(LIBS) \ + -o lib$(WHAT).so + +lib$(WHAT)_g.so: $(WHAT).c $(JPL_HOME)/lib/$(ARCHNAME)/libPerlInterpreter_g.so + $(CC) -g $(FLAGS) $(INCL) $(WHAT).c \ + $(PERLARCHDIR)/CORE/libperl.so \ + $(JPL_HOME)/lib/$(ARCHNAME)/libPerlInterpreter_g.so \ + $(LIBS) \ + -o lib$(WHAT)_g.so + +test: + +install: all + cp $(WHAT).class $(JPL_HOME)/lib + cp lib$(WHAT).so $(JPL_HOME)/lib/$(ARCHNAME) + cp $(WHAT).pl $(JPL_HOME)/perl + +clean: + rm -f $(WHAT).c $(WHAT).h \ + $(WHAT)*.class $(WHAT)*.pl lib$(WHAT).so $(WHAT)*.java + +distclean: clean + rm -f Makefile + +NOSUBS + +close MAKEFILE; diff --git a/jpl/Test/Test.jpl b/jpl/Test/Test.jpl new file mode 100644 index 0000000000..ab6a1ce56d --- /dev/null +++ b/jpl/Test/Test.jpl @@ -0,0 +1,122 @@ +import java.util.*; + +public class Test { + + int myint = 123; + double mydouble = 3.14159265; + String mystring = "my string"; + static String ourstring = "our string"; + static boolean embedded = false; + int array[] = {1,2,3}; + Vector v; + + public Test() { + + + v = new Vector(); + v.addElement("Hello"); + printfields(); + Vector x = perlTryVec(v); + x.addElement("World"); + Vector y = perlTryVec(x); + if (!embedded) System.err.println("Thank you, perlTryVec!"); + + if (!embedded) System.err.println(retchars()); + if (!embedded) System.err.println("Thank you, retchars!"); + + String[] s = retstrings(); + if (!embedded) System.err.println(s[0] + s[1] + s[2] + s[3]); + if (!embedded) System.err.println("Thank you, retstrings!"); + + Object[] o = retobjects(v, x, y); + if (!embedded) System.err.println(o[1]); + if (!embedded) System.err.println(o[3]); + if (!embedded) System.err.println(o[4]); + if (!embedded) System.err.println("Thank you, retobjects!"); + + passarray(s); + + if (!embedded) System.err.println(s[0] + s[1] + s[2] + s[3]); + if (!embedded) System.err.println("Thank you, passarray!"); + + printfields(); + if (!embedded) System.err.println("Thank you, printfields!"); + setfields(); + if (!embedded) System.err.println("Thank you, setfields!"); + printfields(); + if (!embedded) System.err.println("Thank you, printfields!"); + } + + perl Vector perlTryVec(Vector v) throws RuntimeException {{ + print "v is: $v\n"; + print "v isa: ", ref $v,"\n"; + + print "In perlTryVec() - Vector size is: ", $v->size([],['int']), "\n"; + @foo = times; + $size ||= getmeth('size', [], ['int']); + for ($i = 10000; $i; --$i) { + $x = $v->$size(); + } + @bar = times; + printf "%5.2fu %5.2fs\n", $bar[0] - $foo[0], $bar[1] - $foo[1]; + return $v; + }} + + perl char[] retchars() {{ + print "In retchars()\n"; + return [65,66,67]; + }} + + perl String[] retstrings() {{ + print "In retstrings()\n"; + return [1,2,3,"many"]; + }} + + perl Object[] retobjects(Vector v, Vector x, Vector y) {{ + print "In retstrings()\n"; + return [$v, $x, $y, "this is only a test", 123]; + }} + + perl void passarray(String[] s) {{ + print "In passarray()\n"; + print "s = $s\n"; + $t = GetObjectArrayElement($s,3); + print "t = $t\n"; + $x = GetStringUTFChars($t); + print "$x\n"; + $t = SetObjectArrayElement($s,3,NewStringUTF("infinity")); + }} + + perl void printfields() {{ + + $| = 1; + eval {print $self->v->toString____s(), "\n";}; + print $@ if $@; + + print $self->myint, "\n"; + print $self->mydouble, "\n"; + print $self->mystring, "\n"; + print JPL::Test->ourstring, "\n"; + + @nums = GetIntArrayElements($self->array()); + print "@nums\n"; + + @nums = unpack("i*", scalar GetIntArrayElements($self->array())); + print "@nums\n"; + }} + + perl void setfields() {{ + $self->myint(321); + $self->mydouble(2.7182918); + $self->mystring("MY STRING!!!"); + JPL::Test->ourstring("OUR STRING!!!"); + }} + + public static void main(String[] argv) { + if (java.lang.reflect.Array.getLength(argv) > 0 && + argv[0].equals("-nothanks")) + embedded = true; + Test f = new Test(); + if (!embedded) System.err.println("Thank you, Test!"); + } +} |