Powered by SmartDoc

Command Utilities

June 2008
Mutsunori BANBARA and Naoyuki TAMURA
Kobe University, JAPAN

In this section, we present basic tools, written in Perl, that are useful to develop Prolog Cafe applications. Table 1[Summary of Basic tools] shows the summary of them.

Summary of Basic tools
Command Description
plcafe Prolog Cafe application launcher
pljava Prolog to Java translator
pljavac Compile Prolog Cafe applications into Java bytecode
plcomp Prolog to Java bytecode compiler
pljar Create a Java archive (JAR) file of Prolog

We use a list concatenation program in List 1[append.pl] as an example through this section.

append.pl
append([], Zs, Zs).
append([X|Xs], Ys, [X|Zs]) :- append(Xs, Ys, Zs).

Preliminary

Check if Perl 5 or higher is installed.

> perl -version
This is perl, v5.8.6 built for darwin-thread-multi-2level
(with 4 registered patches, see perl -V for more detail)
Copyright 1987-2004, Larry Wall
...

Set the environment variable PATH.

bash
> export PATH=$PLCAFEDIR/bin:$PATH
> echo $PATH
/home/banbara/PrologCafeX.Y.Z/bin:....

Check if the setup succeeds or not by launching a small Prolog interpreter.

> plcafe
...
| ?- halt.
bye

plcafe - Prolog Cafe application launcher

Usage

plcafe [options] [class] [argument...]
options
Command line options
class
Class name to be invoked
argument
Argument that is passed to the main function

Description

The plcafe command launches a Prolog Cafe application. If no argument is given, it launches a small interpreter.

> plcafe
...
| ?- 

Options

-h
-help
Print help message
-v
-verbose
Enable verbose output
-cp classpath
-classpath classpath
Set a list of directories, Jar archives, and Zip archives to search for class files. Class path entries (classpath) must be separated by colons (:).
> plcafe -cp $PLCAFEDIR/examples/prolog/maketen.jar
...
| ?- ex.
[1,1,5,8]  10=8/(1-1/5)
[1,1,9,9]  10=9*(1+1/9)
...
yes
| ?- 
-rt
-runtime
Boot the runtime system only, not including the compiler system.
-t predicate_indicator
-toplevel predicate_indicator
Set a top-level goal to the main function of runtime system. The entry predicate_indicator is a goal name, or package and goal name separated by a colon (:). If this option is given, the arguments class and argument of plcafe command must be empty.
> plcafe -t ex -cp $PLCAFEDIR/examples/prolog/maketen.jar
...
[1,1,5,8]  10=8/(1-1/5)
[1,1,9,9]  10=9*(1+1/9)
...
>
-J options
Pass options to the java command. The entry options is an option list must be enclosed by single-quote (') .
> plcafe -J '-Xmx100m -verbose:gc' -t ex -cp \
    $PLCAFEDIR/examples/prolog/maketen.jar
[GC 512K->215K(1984K), 0.0025620 secs]
[GC 724K->437K(1984K), 0.0015267 secs]
[GC 949K->469K(1984K), 0.0013030 secs]
...
[1,1,5,8]  10=8/(1-1/5)
...
[GC 1106K->599K(1984K), 0.0003398 secs]
[GC 1111K->594K(1984K), 0.0002695 secs]
[GC 1106K->594K(1984K), 0.0001862 secs]
...
[9,9,9,9]  10=(9+9*9)/9
>

pljava - Prolog to Java translator

Usage

pljava [options] [prolog_files]
options
Command line options
prolog_files
One or more prolog files to be translated

Description

The pljava command translates Prolog files into Java files. Each predicate f/n, a java file named PRED_f_n.java will be created in the current directory.

For example, the following session translates the program of List 1[append.pl] into Java.

> ls
append.pl
> pljava append.pl
> ls
PRED_append_3.java      append.pl
>   

Options

-h
-help
Print help message
-v
-verbose
Enable verbose output
-S
Output WAM-like abstract machine code. For each of input prolog files, a file suffixed by ".am" will be created.
> ls
append.pl
> pljava -S append.pl
> ls
PRED_append_3.java      append.am               append.pl
> 
-d directory
Set the destination directory for java files. The directory must already exist. The pljava does not create it.
> mkdir work
> ls
append.pl       work
> pljava -d work append.pl
> ls -R
append.pl       work

./work:
PRED_append_3.java
> 
-J options
Pass options to the java command. The entry options is an option list must be enclosed by single-quote (') . For example, -J '-Xmx100m -verbose:gc'.

pljavac - Compile Prolog Cafe applications into Java bytecode

Usage

pljavac [options] [source_files]
options
Command line options
source_files
One or more source files to be compiled

Description

The pljavac command compiles Java programs including Prolog Cafe API into Java bytecode class files.

For example, the following session compiles the program of List 1[append.pl] into Java bytecode class files

> ls
append.pl
> pljava append.pl
> pljavac *.java
> ls
PRED_append_3.class             PRED_append_3_top.class
PRED_append_3.java              PRED_append_3_var.class
PRED_append_3_1.class           PRED_append_3_var_1.class
PRED_append_3_2.class           append.pl
> plcafe -cp .
...
| ?- append([prolog], [java], X).
X = [prolog,java] ? 
yes
| ?- 

Options

-h
-help
Print help message
-v
-verbose
Enable verbose output
-cp classpath
-classpath classpath
Set a list of directories, Jar archives, and Zip archives to search for class files. Class path entries (classpath) must be separated by colons (:).
-C options
Pass options to the javac command. The entry options is an option list must be enclosed by single-quote (') . For example, -C '-deprecation'.

plcomp - Prolog to Java bytecode compiler

Usage

plcomp [options] [prolog_files]
options
Command line options
prolog_files
One or more prolog files to be compiled

Description

The plcomp behaves as follows:

  1. translates Prolog files into Java files by invoking the pljava command.
  2. compiles those Java files into Java bytecode class files by invoking the pljavac command.

For example, the following session compiles the program of List 1[append.pl] into Java bytecode class files.

> ls
append.pl
> plcomp append.pl
> ls
PRED_append_3.class             PRED_append_3_top.class
PRED_append_3.java              PRED_append_3_var.class
PRED_append_3_1.class           PRED_append_3_var_1.class
PRED_append_3_2.class           append.pl
> plcafe -cp .
...
| ?- append([stag], [beetle], X).
X = [stag,beetle] ? 
yes
| ?- 

Options

-h
-help
Print help message
-v
-verbose
Enable verbose output
-d directory
Set the destination directory for java files and bytecode class files, and make it if no exist.
> ls
append.pl
> plcomp -d xxx append.pl
> ls -R
append.pl       xxx

./xxx:
PRED_append_3.class             PRED_append_3_top.class
PRED_append_3.java              PRED_append_3_var.class
PRED_append_3_1.class           PRED_append_3_var_1.class
PRED_append_3_2.class
> 
-J options
Pass options to the java command. The entry options is an option list must be enclosed by single-quote (') . For example, -J '-Xmx100m -verbose:gc'.
-cp classpath
-classpath classpath
Set a list of directories, Jar archives, and Zip archives to search for class files. Class path entries (classpath) must be separated by colons (:).
-C options
Pass options to the javac command. The entry options is an option list must be enclosed by single-quote (').
> ls
append.pl
> mkdir zzz
> plcomp -d xxx -C '-d zzz' append.pl
> ls -R
append.pl       xxx             zzz

./xxx:
PRED_append_3.java

./zzz:
PRED_append_3.class             PRED_append_3_top.class
PRED_append_3_1.class           PRED_append_3_var.class
PRED_append_3_2.class           PRED_append_3_var_1.class
>

pljar - Create a Java archive (JAR) file of Prolog

Usage

pljar [options] [jar_file] [prolog_files]
options
Command line options
jar_file
Jar file to be created
prolog_files
One or more prolog files to be compiled

Description

The pljar command first translates Prolog files into Java files, then compiles those Java files into bytecode class files, and finally creates a JAR archive file of the class files.

The execution of 'pljar xxx.jar file.pl' behaves as follows:

  1. Makes two directories.
    mkdir xxx xxx/classes
  2. Compiles file.pl into Java bytecode class files by invoking the plcomp command.
    plcomp -C '-d xxx/classes' -d xxx file.pl
  3. Creates a JAR file xxx.jar by invoking the jar command.
    jar cf xxx.jar -C xxx/classes .

For example, the following session creates a JAR file for the program of List 1[append.pl].

> ls
append.pl
> pljar append.jar append.pl
> ls -R
append          append.jar      append.pl

./append:
PRED_append_3.java      classes

./append/classes:
PRED_append_3.class             PRED_append_3_top.class
PRED_append_3_1.class           PRED_append_3_var.class
PRED_append_3_2.class           PRED_append_3_var_1.class
> plcafe -cp append.jar
...
| ?- append([prolog], [cafe], X).
X = [prolog,cafe] ? 
yes
| ?- 

Options

-h
-help
Print help message
-v
-verbose
Enable verbose output
-J options
Pass options to the java command. The entry options is an option list must be enclosed by single-quote (') . For example, -J '-Xmx100m -verbose:gc'.
-cp classpath
-classpath classpath
Set a list of directories, Jar archives, and Zip archives to search for class files. Class path entries (classpath) must be separated by colons (:).
-C options
Pass options to the javac command. The entry options is an option list must be enclosed by single-quote (').