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/Sample | |
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/Sample')
-rw-r--r-- | jpl/Sample/Makefile.PL | 84 | ||||
-rw-r--r-- | jpl/Sample/Sample.jpl | 48 |
2 files changed, 132 insertions, 0 deletions
diff --git a/jpl/Sample/Makefile.PL b/jpl/Sample/Makefile.PL new file mode 100644 index 0000000000..944c7e180d --- /dev/null +++ b/jpl/Sample/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 *.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/Sample/Sample.jpl b/jpl/Sample/Sample.jpl new file mode 100644 index 0000000000..a09520141f --- /dev/null +++ b/jpl/Sample/Sample.jpl @@ -0,0 +1,48 @@ +class Sample { + public static void main(String[] args) { + Sample sam = new Sample(); + System.out.println(sam.foo("manny","moe","jack")); + System.out.println(sam.foo(1)); + System.out.println(sam.foo(3.0)); + sam.foo(); + } + + public static int thrice(int i) { + return i * 3; + } + + perl void foo() {{ + use POSIX; + print "TZ = ", POSIX::tzname(), "\n"; + print "Got to ${self}->foo() method\n"; + print "foo__I(2) = ", $self->foo__I__I(2),"\n"; + print "thrice(123) = ", JPL::Sample->thrice__I__I(123), "\n"; + print "thrice(12) = ", JPL::Sample->thrice__I__I(12), "\n"; + print $self->foo__sss__s("MANNY", "MOE", "JACK"), "\n"; + print 41 + $self->foo__sss__s("1", "2", "3"), "\n"; + print "Perl version is $]\n"; + }} + + perl int foo(int a) {{ + $a + $a; + }} + + perl double foo(double a) {{ + use JPL::Class 'java::util::Random'; + $rng = java::util::Random->new(); + print "RNG = $rng\n"; + print $rng->nextDouble____D(), "\n"; + print $rng->nextDouble____D(), "\n"; + print $rng->nextDouble____D(), "\n"; + print $rng->nextDouble____D(), "\n"; + return $a * $a; + }} + + perl String foo( String a, + String b, + String c ) {{ + print "a = $a, b = $b, c = $c\n"; + join "+", $a, $b, $c; + }} + +} |