Build Prolog Cafe with Buck

Creating the Eclipse project configuration is trivial as there are
no dependencies for Prolog Cafe beyond its single source directory
and the JVM.

Change-Id: I64b2349437daae11e543133e631a22e4e3c96255
diff --git a/.buckconfig b/.buckconfig
new file mode 100644
index 0000000..7b75112
--- /dev/null
+++ b/.buckconfig
@@ -0,0 +1,5 @@
+[alias]
+  all = //:all
+
+[buildfile]
+  includes = //bootstrap.defs
diff --git a/.buckversion b/.buckversion
new file mode 100644
index 0000000..9c09744
--- /dev/null
+++ b/.buckversion
@@ -0,0 +1 @@
+79d36de9f5284f6e833cca81867d6088a25685fb
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..40c5bcb
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="java"/>
+	<classpathentry kind="lib" path="buck-out/gen/lib__builtin__output/builtin.jar"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+	<classpathentry kind="output" path="buck-out/eclipse/classes"/>
+</classpath>
diff --git a/.gitignore b/.gitignore
index 94ab043..30a487e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,29 +1,2 @@
-*.jar
-*.class
-
-/.classpath
-/.project
 /.settings
-/target
-
-/bin/am2j.plc
-/bin/am2j.plj
-/bin/pl2am.plc
-/bin/pl2am.plj
-/doc/javadoc
-/src/builtin/builtins.am
-/src/builtin/builtins/
-/src/builtin/system.am
-/src/builtin/system/
-/src/compiler/am2j.am
-/src/compiler/am2j.plc
-/src/compiler/am2j.plj
-/src/compiler/am2j.qsav
-/src/compiler/am2j/
-/src/compiler/pl2am.am
-/src/compiler/pl2am.plc
-/src/compiler/pl2am.plj
-/src/compiler/pl2am.qsav
-/src/compiler/pl2am/
-/src/compiler/system.pl
-/src/compiler/system.qlf
+/buck-out
diff --git a/.project b/.project
new file mode 100644
index 0000000..39e9c97
--- /dev/null
+++ b/.project
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+  <name>prolog-cafe</name>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+  </natures>
+</projectDescription>
diff --git a/BUCK b/BUCK
new file mode 100644
index 0000000..995b151
--- /dev/null
+++ b/BUCK
@@ -0,0 +1,69 @@
+SRC = 'java/com/googlecode/prolog_cafe/'
+
+genrule(
+  name = 'all',
+  cmd = ':>all',
+  deps = [
+    ':compiler',
+    ':runtime',
+  ],
+  out = '__fake.all__',
+)
+
+java_binary(
+  name = 'runtime',
+  deps = [
+    ':builtin',
+    ':lang',
+  ],
+)
+
+java_library(
+  name = 'lang',
+  srcs = glob([SRC + 'lang/*.java']),
+)
+
+java_library(
+  name = 'builtin',
+  srcs = glob([SRC + 'builtin/*.java']) + [
+    ':builtin_srcs',
+    ':system_srcs',
+  ],
+  deps = [':lang'],
+)
+
+pl2j(
+  name = 'builtin_srcs',
+  src = 'src/builtin/builtins.pl',
+  out = 'builtins.src.zip',
+)
+
+pl2j(
+  name = 'system_srcs',
+  src = 'src/builtin/system.pl',
+  out = 'system.src.zip',
+)
+
+java_library(
+  name = 'compiler',
+  srcs = glob([SRC + 'compiler/*.java']) + [
+    ':pl2am_srcs',
+    ':am2j_srcs',
+  ],
+  deps = [
+    ':builtin',
+    ':lang',
+  ],
+)
+
+pl2j(
+  name = 'pl2am_srcs',
+  src = 'src/compiler/pl2am.pl',
+  out = 'pl2am.src.zip',
+)
+
+pl2j(
+  name = 'am2j_srcs',
+  src = 'src/compiler/am2j.pl',
+  out = 'am2j.src.zip',
+)
diff --git a/Makefile b/Makefile
deleted file mode 100644
index d291d06..0000000
--- a/Makefile
+++ /dev/null
@@ -1,125 +0,0 @@
-################################################################
-# Makefile
-################################################################
-# PROLOG - the command of Prolog system 
-#        ::= sicstus | swipl | pl | prolog | ...
-# PSYSTEM- the type of Prolog system 
-#        ::= 'SICStus' | 'SWI-Prolog' | 'Others'
-
-PROLOG  = swipl
-PSYSTEM = 'SWI-Prolog'
-# PROLOG  = sicstus
-# PSYSTEM = 'SICStus'
-# PROLOG  = prolog
-# PSYSTEM = 'Others'
-
-JAVA      = java
-JAVAC     = javac
-JAVACOPTS = -d .
-JAR       = jar
-JAROPTS   = cf
-
-PWD := $(shell pwd)
-################################################################
-all: plc lang builtin compiler plcafe plj
-
-plc:
-	(cd src/compiler; $(MAKE) plc \
-	PROLOG='$(PROLOG)' PSYSTEM='$(PSYSTEM)')
-	cp src/compiler/pl2am.plc bin/
-	cp src/compiler/am2j.plc bin/
-
-lang:
-	(cd src/lang; $(MAKE) lang \
-	JAVAC='$(JAVAC)' JAVACOPTS='$(JAVACOPTS)' \
-	JAR='$(JAR)' JAROPTS='$(JAROPTS)')
-	cp src/lang/lang.jar .
-
-gen-builtin:
-	(cd src/builtin && $(MAKE) gen-builtin)
-builtin:
-	(cd src/builtin; $(MAKE) builtin \
-	JAVAC='$(JAVAC)' JAVACOPTS='$(JAVACOPTS) -classpath $(PWD)/lang.jar' \
-	JAR='$(JAR)' JAROPTS='$(JAROPTS)')
-	cp src/builtin/builtin.jar .
-
-gen-compiler:
-	(cd src/compiler && $(MAKE) gen-compiler)
-compiler:
-	(cd src/compiler; $(MAKE) compiler \
-	JAVAC='$(JAVAC)' \
-	JAVACOPTS='$(JAVACOPTS) -classpath $(PWD)/lang.jar:$(PWD)/builtin.jar' \
-	JAR='$(JAR)' JAROPTS='$(JAROPTS)')
-	cp src/compiler/compiler.jar .
-
-plcafe:
-	$(JAVAC) $(JAVACOPTS) \
-	  src/lang/*.java \
-	  src/builtin/*.java \
-	  src/compiler/*.java \
-	  target/generated-sources/prologcafe-builtin/com/googlecode/prolog_cafe/builtin/*.java \
-	  target/generated-sources/prologcafe-pl2am/com/googlecode/prolog_cafe/compiler/pl2am/*.java \
-	  target/generated-sources/prologcafe-am2j/com/googlecode/prolog_cafe/compiler/am2j/*.java
-	$(JAR) $(JAROPTS) plcafe.jar com/googlecode/prolog_cafe
-
-plj:
-	(cd src/compiler; $(MAKE) plj PROLOG='$(JAVA)')
-	cp src/compiler/pl2am.plj bin/
-	cp src/compiler/am2j.plj bin/
-################################################################
-clean:
-	(cd src/builtin; $(MAKE) clean)
-	(cd src/lang; $(MAKE) clean)
-	(cd src/compiler; $(MAKE) clean)
-	-rm -f bin/pl2am.plc
-	-rm -f bin/am2j.plc
-	-rm -f -r com
-	-rm -f core *~
-	-rm -r -f target
-
-realclean: clean
-	(cd src/builtin; $(MAKE) realclean)
-	(cd src/lang; $(MAKE) realclean)
-	(cd src/compiler; $(MAKE) realclean)
-	-rm -f -r doc/javadoc
-	-rm -f bin/pl2am.plj
-	-rm -f bin/am2j.plj
-	-rm -f plcafe.jar
-	-rm -f compiler.jar
-	-rm -f builtin.jar
-	-rm -f lang.jar
-################################################################
-ex:
-	(cd examples;  $(MAKE) all)
-################################################################
-JAVADOC      = javadoc
-JAVADOCOPTS  = -J-Xmx100m \
-	       -locale en_US -d doc/javadoc -breakiterator \
-               -windowtitle $(WINDOWTITLE) -doctitle $(DOCTITLE) \
-               -header $(HEADER) -bottom $(BOTTOM)
-
-WINDOWTITLE  = 'Prolog Cafe v1.2 API Specification'
-DOCTITLE     = 'Prolog Cafe v1.2 API Specification'
-HEADER       = '<b><font color="red">Prolog Cafe v1.2</font></b><br>'
-BOTTOM       = '<font size="-1"> \
-                 Copyright (C) 1997-2009 \
-                 <a href="http://kaminari.istc.kobe-u.ac.jp/banbara.html">M.BANBARA</a> and \
-                 <a href="http://bach.istc.kobe-u.ac.jp/tamura.html">N.TAMURA</a> \
-               </font>'
-
-javadoc: 
-	$(JAVADOC) $(JAVADOCOPTS) src/lang/*.java \
-	src/compiler/Compiler.java
-################################################################
-VER = 1.2.5
-DIR = PrologCafe$(VER)
-TGZ = PrologCafe$(VER).tgz
-ZIP = PrologCafe$(VER).zip
-
-tar: clean
-	(cd ..; tar cfz $(DIR)/$(TGZ) $(DIR)/*)
-
-zip: clean
-	(cd ..; zip -r $(DIR)/$(ZIP) $(DIR)/*)
-################################################################
-# END
diff --git a/README b/README
deleted file mode 100644
index 62fdcdd..0000000
--- a/README
+++ /dev/null
@@ -1,19 +0,0 @@
-################################################################
-  README
-################################################################
-
-* Prolog Cafe Web Page
-  http://kaminari.istc.kobe-u.ac.jp/PrologCafe/
-
-* Install
-  http://kaminari.istc.kobe-u.ac.jp/PrologCafe/install_en.html
-
-* Prolog Cafe User Manual
-  http://kaminari.istc.kobe-u.ac.jp/PrologCafe/manual_en.html
-
-* Prolog Cafe API Specification
-  ./doc/javadoc/index.html
-
---
-Mutsunori BANBARA
-
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..585a67b
--- /dev/null
+++ b/README.md
@@ -0,0 +1,16 @@
+# Prolog Cafe
+
+A fork of Mutsunori BANBARA's [PrologCafe][1] to support
+Gerrit Code Review's customizable project rules.
+
+[1]: http://kaminari.istc.kobe-u.ac.jp/PrologCafe/
+
+## Build
+
+To bootstrap [Buck] and [SWI-Prolog] >= 6.6.4 must be installed and
+then build the runtime and compiler with:
+
+    buck build all
+
+[Buck]: https://github.com/facebook/buck/
+[SWI-Prolog]: http://www.swi-prolog.org/
diff --git a/bootstrap.defs b/bootstrap.defs
new file mode 100644
index 0000000..53a8331
--- /dev/null
+++ b/bootstrap.defs
@@ -0,0 +1,60 @@
+# Translating Prolog into WAM-based Intermediate Code
+def pl2am(name, src, out):
+  from os.path import basename, dirname
+
+  genrule(
+    name = name,
+    out = out,
+    cmd = 'echo "go :- '
+      + 'load_files(['
+        + "'$SRCDIR/src/compiler/package_fx.pl',"
+        + "'$SRCDIR/src/builtin/system.pl',"
+        + "'$SRCDIR/src/compiler/pl2am.pl'"
+      + ']),'
+      + 'pl2am(['
+        + "'%s'," % basename(src)
+        + "'$OUT',"
+        + '[ed,ac,ie,rc,idx]'
+      + ']).'
+      + '">$TMP/go.pl;'
+      + 'cd $SRCDIR/%s;' % dirname(src)
+      + 'swipl --quiet -g go,halt -t "halt(1)" $TMP/go.pl',
+    srcs = [
+      'src/compiler/package_fx.pl',
+      'src/compiler/pl2am.pl',
+      'src/builtin/system.pl',
+      src,
+    ],
+  )
+
+# Translating WAM-based Intermediate Code into Java
+def am2j(name, am, out):
+  genrule(
+    name = name,
+    out = out,
+    cmd = 'echo "go :- '
+      + 'load_files(['
+        + "'$SRCDIR/src/compiler/am2j.pl'"
+      + ']),'
+      + 'am2j(['
+        + "'$(location %s)'," % am
+        + "'$TMP/java'"
+      + ']).'
+      + '">$TMP/go.pl;'
+      + 'mkdir $TMP/java;'
+      + 'swipl --quiet -g go,halt -t "halt(1)" $TMP/go.pl;'
+      + 'cd $TMP/java; zip -qr $OUT .',
+    srcs = ['src/compiler/am2j.pl'],
+  )
+
+def pl2j(name, src, out):
+  pl2am(
+    name = name + '.am',
+    src = src,
+    out = name + '.am',
+  )
+  am2j(
+    name = name,
+    am = ':' + name + '.am',
+    out = out,
+  )
diff --git a/java_src/com/googlecode/prolog_cafe b/java/com/googlecode/prolog_cafe
similarity index 100%
rename from java_src/com/googlecode/prolog_cafe
rename to java/com/googlecode/prolog_cafe
diff --git a/pom.xml b/pom.xml
deleted file mode 100644
index 6a10f35..0000000
--- a/pom.xml
+++ /dev/null
@@ -1,145 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <modelVersion>4.0.0</modelVersion>
-  <groupId>com.googlecode.prolog-cafe</groupId>
-  <artifactId>PrologCafe</artifactId>
-  <packaging>jar</packaging>
-  <version>1.3</version>
-  <name>Prolog Cafe</name>
-
-  <mailingLists>
-    <mailingList>
-      <name>repo-discuss mailing list</name>
-      <post>repo-discuss@googlegroups.com</post>
-      <archive>https://groups.google.com/group/repo-discuss/about</archive>
-    </mailingList>
-  </mailingLists>
-
-  <build>
-    <sourceDirectory>java_src</sourceDirectory>
-
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-antrun-plugin</artifactId>
-        <version>1.6</version>
-        <executions>
-          <execution>
-            <id>clean_prolog</id>
-            <phase>clean</phase>
-            <configuration>
-              <target>
-                <exec executable="make">
-                  <arg value="realclean" />
-                </exec>
-              </target>
-            </configuration>
-            <goals>
-              <goal>run</goal>
-            </goals>
-          </execution>
-          <execution>
-            <id>build_prolog</id>
-            <phase>generate-sources</phase>
-            <configuration>
-              <target>
-                <exec executable="make">
-                  <arg value="plc" />
-                  <arg value="gen-builtin" />
-                  <arg value="gen-compiler" />
-                </exec>
-              </target>
-            </configuration>
-            <goals>
-              <goal>run</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>build-helper-maven-plugin</artifactId>
-        <version>1.5</version>
-        <executions>
-          <execution>
-            <id>add-source</id>
-            <phase>generate-sources</phase>
-            <goals>
-              <goal>add-source</goal>
-            </goals>
-            <configuration>
-              <sources>
-                <source>target/generated-sources/prologcafe-builtin</source>
-                <source>target/generated-sources/prologcafe-pl2am</source>
-                <source>target/generated-sources/prologcafe-am2j</source>
-              </sources>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-compiler-plugin</artifactId>
-        <version>2.3.2</version>
-        <configuration>
-          <source>1.6</source>
-          <target>1.6</target>
-          <encoding>UTF-8</encoding>
-          <debug>false</debug>
-          <optimize>true</optimize>
-        </configuration>
-      </plugin>
-
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-source-plugin</artifactId>
-        <version>2.1.2</version>
-        <configuration>
-          <includes>
-            <include>**/*.java</include>
-            <include>**/*.pl</include>
-          </includes>
-          <excludes>
-            <exclude>com/googlecode/prolog_cafe/compiler/am2j/**/*.java</exclude>
-            <exclude>com/googlecode/prolog_cafe/compiler/pl2am/**/*.java</exclude>
-          </excludes>
-        </configuration>
-        <executions>
-          <execution>
-            <goals>
-              <goal>jar</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-
-    <extensions>
-        <extension>
-            <groupId>org.apache.maven.wagon</groupId>
-            <artifactId>wagon-webdav-jackrabbit</artifactId>
-            <version>1.0-beta-6</version>
-        </extension>
-    </extensions>
-  </build>
-
-  <distributionManagement>
-    <snapshotRepository>
-      <id>gerrit-snapshot-repository</id>
-      <name>gerrit Snapshot Repository</name>
-      <url>dav:https://gerrit-maven-repository.googlecode.com/svn/</url>
-      <uniqueVersion>true</uniqueVersion>
-    </snapshotRepository>
-
-    <repository>
-      <id>gerrit-maven-repository</id>
-      <name>gerrit Maven Repository</name>
-      <url>dav:https://gerrit-maven-repository.googlecode.com/svn/</url>
-      <uniqueVersion>true</uniqueVersion>
-    </repository>
-  </distributionManagement>
-</project>
diff --git a/src/builtin/Makefile b/src/builtin/Makefile
deleted file mode 100644
index 52593c6..0000000
--- a/src/builtin/Makefile
+++ /dev/null
@@ -1,42 +0,0 @@
-################################################################
-#	Makefile for Prolog Cafe
-################################################################
-
-################################################################
-# The following two definitions will be overridden.
-#
-# JAVAC : the command of Java compiler system
-#          (ex. javac)
-# JAR   : the command of Jar archive system
-#          (ex. jar)
-#
-JAVAC     = javac
-JAVACOPTS = -d . -Xlint -classpath $$PLCAFEDIR/lang.jar:$$CLASSPATH
-JAR       = jar
-JAROPTS   = cf
-T         = ../../target/generated-sources/prologcafe-builtin
-P         = com/googlecode/prolog_cafe/builtin
-################################################################
-.SUFFIXES:
-.SUFFIXES: .am .pl $(SUFFIXES)
-
-am_objects = builtins.am \
-	system.am \
-
-.pl.am:
-	../../bin/pl2am.plc -v -O $< $@
-	-mkdir -p $(T)
-	../../bin/am2j.plc -v -d $(T) $@
-
-builtin: gen-builtin
-	$(JAVAC) $(JAVACOPTS) *.java $(T)/$(P)/*.java
-	$(JAR) $(JAROPTS) builtin.jar $(P)
-gen-builtin: $(am_objects)
-
-clean:
-	-rm -f -r $(T)
-	-rm -f -r com
-	-rm -f Base/core Base/*~ Base/*.class
-	-rm -f core *~ *.am *.jar *.class
-
-realclean: clean
diff --git a/src/compiler/Makefile b/src/compiler/Makefile
deleted file mode 100644
index d4e1257..0000000
--- a/src/compiler/Makefile
+++ /dev/null
@@ -1,59 +0,0 @@
-################################################################
-#	Makefile for Prolog Cafe
-################################################################
-
-################################################################
-# The following two definitions will be overridden.
-#
-# PROLOG : the command of Prolog system 
-#          (ex. sicstus, swipl, or prolog)
-# PSYSTEM: the type of Prolog system 
-#          (ex. 'SICStus', 'SWI-Prolog' or others)
-#
-PROLOG  = sicstus
-PSYSTEM = 'SICStus'
-#PROLOG  = swipl
-#PSYSTEM = 'SWI-Prolog'
-
-# JAVAC : the command of Java compiler system (ex. javac)
-# JAR   : the command of Jar archive system (ex. jar)
-JAVAC     = javac
-JAVACOPTS = -d . -Xlint -classpath $$PLCAFEDIR/lang.jar:$$PLCAFEDIR/builtin.jar:$$CLASSPATH
-JAR       = jar
-JAROPTS   = cvf
-# JAVA  : the command of Java Virtual Machine (ex. java)
-JAVA      = java
-T         = ../../target/generated-sources/prologcafe
-P         = com/googlecode/prolog_cafe/compiler
-################################################################
-.SUFFIXES:
-.SUFFIXES: .plj .txt .am .plc .pl $(SUFFIXES)
-
-.pl.plc:
-	cp ../builtin/system.pl  .
-	./comp_pl -v `pwd`/$*.pl `pwd`/$*.plc $(PROLOG) $(PSYSTEM)
-
-.pl.am:
-	../../bin/pl2am.plc -v -O $< $@
-	-mkdir $T-$*
-	../../bin/am2j.plc -v -d $T-$* $@
-
-.txt.plj:
-	./comp_pl -v `pwd`/$*.pl `pwd`/$*.plj $(JAVA) 'PrologCafe'
-
-plc: pl2am.plc am2j.plc
-
-compiler: gen-compiler
-	$(JAVAC) $(JAVACOPTS) *.java $T-pl2am/$P/pl2am/*.java $T-am2j/$P/am2j/*.java
-	$(JAR) $(JAROPTS) compiler.jar $P
-gen-compiler: pl2am.am am2j.am
-
-plj: pl2am.plj am2j.plj
-
-clean:
-	-rm -f -r com
-	-rm -f core *~ *.ql *.sav *.plc *.qlf *.qsav *.am *.plj *.jar system.pl
-
-realclean: clean
-
-
diff --git a/src/compiler/am2j.txt b/src/compiler/am2j.txt
deleted file mode 100644
index 5d4227a..0000000
--- a/src/compiler/am2j.txt
+++ /dev/null
@@ -1,116 +0,0 @@
-#! /usr/bin/perl
-use strict;
-use Getopt::Long;
-
-# options
-my @optlist = ("h|help!","v|verbose!","d=s","J=s");
-my $result = GetOptions @optlist;
-our ($opt_h, $opt_v, $opt_d, $opt_J);
-
-# -h option || check the number of arguments
-if ($opt_h || @ARGV != 1 ) {
-    usage();
-    exit 1;
-}
-
-# local variables
-my $echo = "/bin/echo";
-my $am_file = $ARGV[0];
-
-my %env;
-&init();
-
-# -d option
-if ($opt_d && (! -d $opt_d)) {
-    &error("directory $opt_d does not exist.");
-}
-
-# -J option
-if ($opt_J) {
-    if ($opt_J =~ /(-cp|-classpath)\s+/) {
-	&error("can not use $1 in -J option");
-    }
-    $env{"system_opts"} .= " $opt_J";
-}
-
-# main
-if (! -e $am_file) {
-    &error("file $am_file does not exist.");
-}
-
-my $arg;
-if ($env{"goal"}) {
-    $arg .= $env{"goal"} . " ";
-}
-$arg .= "[\'$am_file\'";
-if ($opt_d) { # check -d option
-    $arg .= ", \'$opt_d\'";
-}
-$arg .= "].";
-
-my $cmd = "$echo \"$arg\" | " . $env{"system"};
-if ($env{"system_opts"}) {
-    $cmd .= " " . $env{"system_opts"};
-}
-if ($env{"system_args"}) {
-    $cmd .= " " . $env{"system_args"};
-}
-if (! $opt_v) {# check -v option
-    $cmd .= " 2> /dev/null";
-}
-
-&message("{START translating $am_file --> Java}");
-&message($cmd);
-system($cmd) && error("translation fails");
-&message("{END translating $am_file --> Java}\n");
-
-exit 0;
-
-# sub
-sub usage {
-    print "\nUsage: $0 [-options] am_file\n";
-    print "\n where options include:\n";
-    print "\t-h -help         : print this help message\n";
-    print "\t-v -verbose      : enable verbose output\n";
-    print "\t-d directory     : set the destination directory for am_file.\n";
-    print "\t                 : The destination directory must already exist\n";
-    print "\t-J option        : option must be enclosed by '.\n";
-    print "\t                 : pass option to the Java Virtual Machine\n";
-    print "\t                 : (ex. -J '-Xmx100m -verbose:gc')\n";
-    print "\n";
-}
-
-sub message {
-    my ($x) = @_;
-    if ($opt_v) { # check -v option
-	print "\% $x\n";
-    }
-}
-
-sub error {
-    my ($x) = @_;
-    print "\% ERROR: $x: $0\n";
-    exit 1;
-}
-
-#sub init {
-#    %env = (
-#	"goal",        "",
-#	"system",      "/Users/banbara/prog/plcafe/PrologCafe095/src/compiler/am2j.sav",
-#	"system_opts", "",
-#	"system_args", "",
-#	);
-#    %env = (
-#	"goal",        "load('/Users/banbara/prog/plcafe/PrologCafe095/src/compiler/pl2am.ql'), main. ",
-#	"system",      "sicstus",
-#	"system_opts", "",
-#	"system_args", "",
-#	);
-#    %env = (
-#	"goal",        "",
-#	"system",      "java",
-#	"system_opts", "-cp \$PLCAFEDIR/plcafe.jar:\$CLASSPATH",
-#	"system_args", "com.googlecode.prolog_cafe.lang.PrologMain com.googlecode.prolog_cafe.compiler.pl2am:main",
-#	);
-#}
-
diff --git a/src/compiler/comp_pl b/src/compiler/comp_pl
deleted file mode 100755
index d61fc91..0000000
--- a/src/compiler/comp_pl
+++ /dev/null
@@ -1,154 +0,0 @@
-#! /usr/bin/perl
-use strict;
-use Getopt::Long;
-use File::Copy;
-
-# options
-my @optlist = ("h|help!","v|verbose!");
-my $result = GetOptions @optlist;
-our ($opt_h, $opt_v);
-
-# -h option || check the number of arguments
-if ($opt_h || @ARGV < 2 || @ARGV > 4) {
-    usage();
-    exit 1;
-}
-
-# get arguments
-my $prolog_file   = $ARGV[0];
-my $command_file  = $ARGV[1];
-my $prolog        = $ARGV[2];
-my $prolog_system = $ARGV[3];
-
-# check arguments
-if (! -e $prolog_file) {
-    &error("File $prolog_file does not exist");
-}
-
-if (! $prolog) {
-    $prolog = "prolog";
-}
-
-if (! $prolog_system) {
-    $prolog_system = "Unknown";
-}
-
-# main
-my $nosuffix = $prolog_file;
-$nosuffix =~ s/.pl$//g;
-my $cmd_temp = $nosuffix . ".txt";
-
-if ($prolog_system eq "SICStus" || $prolog_system eq "SWI-Prolog") { # SICStus or SWI-Prolog
-    my $wam;
-    my $dump;
-    my $goal;
-    my $goal2;
-    if ($prolog_system eq "SICStus") {
-	$wam  = $nosuffix . ".ql";
-	$dump = $nosuffix . ".sav";
-	#$goal = "\"[operators], fcompile(\'$prolog_file\'), load(\'$wam\'), save_program(\'$dump\', main), halt.\"";
-	$goal = "\"[operators], fcompile([\'$prolog_file\',system]), load(\'$wam\'), load(system), save_program(\'$dump\', main), halt.\"";
-	$goal2 = "load(\'$wam\'), main.";
-    }
-    if ($prolog_system eq "SWI-Prolog") {
-	$wam  = $nosuffix . ".qlf";
-	$dump = $nosuffix . ".qsav";
-#	$goal = "\"[operators], qcompile(\'$prolog_file\'), load_files(\'$wam\'), qsave_program(\'$dump\', [goal=main]), halt.\"";
-	$goal = "\"[operators], qcompile([\'$prolog_file\',system]), load_files(\'$wam\'), load_files(system),qsave_program(\'$dump\', [goal=main]), halt.\"";
-	$goal2 = "load_files(\'$wam\'), main.";
-    }
-    &message("unlink $wam, $dump");
-    unlink $wam, $dump;
-    my $cmd = "echo $goal | $prolog";
-    if (! $opt_v) {# check -v option
-	$cmd .= " 2> /dev/null";
-    }
-    &message("making $wam, $dump");
-    &message($cmd);
-    system($cmd);
-    if (-e $dump) { # saving program succeeds
-	unlink $wam;
-	&message("making $command_file");
-	&mk_command($command_file, $cmd_temp, undef, $dump, undef, undef);
-	chmod 0755, $command_file;
-	exit 0;
-    } elsif (-e $wam) { # compilation succeeds, but saving program fails
-	&message("making $command_file");
-	&mk_command($command_file, $cmd_temp, $goal2, $prolog, undef, undef);
-	chmod 0755, $command_file;
-	exit 0;
-    } else {
-	&error("$0 fails");
-    }
-} elsif ($prolog_system eq "PrologCafe") {
-    my $file;
-    my $system_opts;
-    my $system_args;
-    # set $system_opts
-    #$system_opts = "-cp \\\$PLCAFEDIR/lang.jar:\\\$PLCAFEDIR/builtin.jar:\\\$PLCAFEDIR/compiler.jar";
-    $system_opts = "-cp \\\$PLCAFEDIR/plcafe.jar";
-    if ($prolog_file =~ m|.*/(.*).pl$|i) {
-	$file = $1;
-    } else {
-	&error("invalid prolog file found, $prolog_file");
-    }
-    # set $system_args
-    $system_args = "com.googlecode.prolog_cafe.lang.PrologMain com.googlecode.prolog_cafe.compiler.$file:main";
-    &message("making $command_file");
-    &mk_command($command_file, $cmd_temp, undef, $prolog, $system_opts, $system_args);
-    chmod 0755, $command_file;
-    exit 0;    
-} else {
-    my $goal3 = "[\'$prolog_file\',system], main.";
-#    my $goal3 = "[\'$prolog_file\'], main.";
-    &message("making $command_file");
-    &mk_command($command_file, $cmd_temp, $goal3, $prolog, undef, undef);
-    chmod 0755, $command_file;
-    exit 0;
-}
-
-exit 0;
-
-# sub
-sub usage {
-    print "\nUsage: $0 [-options] prolog_file command_file [prolog] [prolog_system]\n";
-    print "\n where options include:\n";
-    print "\t-h -help         : print this help message\n";
-    print "\t-v -verbose      : enable verbose output\n";
-    print "\n where prolog is the command of Prolog system:\n";
-    print "\t(ex.) sicstus, pl, swipl, prolog...\n";
-    print "\n where prolog_system include:\n";
-    print "\tSICStus\n";
-    print "\tSWI-Prolog\n\n";
-}
-
-sub message {
-    my ($x) = @_;
-    if ($opt_v) { # check -v option
-	print "\% $x\n";
-    }
-}
-
-sub error {
-    my ($x) = @_;
-    print "\% ERROR: $x\n";
-    exit(1);
-}
-
-sub mk_command {
-    my ($command_file, $command_temp, @val) = @_;
-    my @key = ("goal", "system", "system_opts", "system_args");
-    copy($command_temp, $command_file) || &error("can not copy $command_temp to $command_file");
-    open(OUT, ">>$command_file") || &error("can not open $command_file");
-    print OUT "sub init {\n";
-    print OUT "\t%env = (\n";
-    for (my $i=0; $i < scalar(@key); $i++) {
-	next if (! $val[$i]);
-	print OUT "\t\t\"$key[$i]\", \"$val[$i]\",\n";
-    }
-    print OUT "\t)\n";
-    print OUT "}\n";
-    close(OUT) || &error("can not close $command_file");
-}
-
-
diff --git a/src/compiler/package_fx.pl b/src/compiler/package_fx.pl
new file mode 100644
index 0000000..213b784
--- /dev/null
+++ b/src/compiler/package_fx.pl
@@ -0,0 +1,2 @@
+:- op(1150,  fx, (package)).
+package(_).
diff --git a/src/compiler/pl2am.pl b/src/compiler/pl2am.pl
index 65ebf0b..96cac36 100644
--- a/src/compiler/pl2am.pl
+++ b/src/compiler/pl2am.pl
@@ -169,7 +169,6 @@
 :- dynamic fail_flag/0.  % used for generating label(fail/0) or not
 
 % :- module('com.googlecode.prolog_cafe.compiler.pl2am', [main/0,pl2am/1]).
-package(_). 
 :- package 'com.googlecode.prolog_cafe.compiler.pl2am'.
 
 :- public main/0, pl2am/1.
diff --git a/src/compiler/pl2am.txt b/src/compiler/pl2am.txt
deleted file mode 100644
index 0a3c01e..0000000
--- a/src/compiler/pl2am.txt
+++ /dev/null
@@ -1,137 +0,0 @@
-#! /usr/bin/perl
-use strict;
-use Getopt::Long;
-
-# options
-my @optlist = ("h|help!","v|verbose!","copts=s","O!","J=s");
-my $result = GetOptions @optlist;
-our ($opt_h, $opt_v, $opt_copts, $opt_O, $opt_J);
-
-# -h option || check the number of arguments
-if ($opt_h || @ARGV != 2 ) {
-    usage();
-    exit 1;
-}
-
-# local variables
-my $echo = "/bin/echo";
-my $copts = "[]";
-my $prolog_file = $ARGV[0];
-my $am_file = $ARGV[1];
-
-my %env;
-&init();
-
-# -copts option
-if ($opt_copts) {
-    my @x =  split(":", $opt_copts);
-    foreach (@x) {
-	s/^\s+//;
-	s/\s+$//;
-    }
-    foreach my $op (@x) {
-	if ($op !~ /^ed|ac|ie|rc|idx|clo$/) {
-	    &error("invalid option found, $op.");
-	}
-    }
-    $copts = "[" . join(",", @x) . "]";
-} 
-
-# -O option
-if ($opt_O) {
-#    $copts = "[ed,ac,ie,rc,idx,clo]";
-    $copts = "[ed,ac,ie,rc,idx]";
-#    $copts = "[ed,ac,ie,rc]";
-}
-
-# -J option
-if ($opt_J) {
-    if ($opt_J =~ /(-cp|-classpath)\s+/) {
-	&error("can not use $1 in -J option");
-    }
-    $env{"system_opts"} .= " $opt_J";
-}
-
-# main
-if (! -e $prolog_file) {
-    &error("file $prolog_file does not exist.");
-}
-
-my $arg;
-if ($env{"goal"}) {
-    $arg .= $env{"goal"} . " ";
-}
-$arg .= "[\'$prolog_file\', \'$am_file\', $copts].";
-my $cmd = "$echo \"$arg\" | " . $env{"system"};
-if ($env{"system_opts"}) {
-    $cmd .= " " . $env{"system_opts"};
-}
-if ($env{"system_args"}) {
-    $cmd .= " " . $env{"system_args"};
-}
-if (! $opt_v) {# check -v option
-    $cmd .= " 2> /dev/null";
-}
-
-&message("{START translating $prolog_file --> $am_file}");
-&message($cmd);
-system($cmd) && error("translation fails");
-&message("{END translating $prolog_file --> $am_file}\n");
-
-exit 0;
-
-# sub
-sub usage {
-    print "\nUsage: $0 [-options] prolog_file am_file\n";
-    print "\n where options include:\n";
-    print "\t-h -help         : print this help message\n";
-    print "\t-v -verbose      : enable verbose output\n";
-    print "\t-copts[:ed|ac|rc|ie|idx|clo]\n";
-    print "\t                 : enable each optimised compilation\n";
-    print "\t                 :   ed  = eliminate disjunctions\n";
-    print "\t                 :   ac  = arithmetic compilation\n";
-    print "\t                 :   rc  = optimise recursive call\n";
-    print "\t                 :   ie  = inline expansion\n";
-    print "\t                 :   idx = switch_on_hash (2nd. level indexing) \n";
-    print "\t                 :   clo = generate closure for meta predicates\n";
-    print "\t-O               : enable all optimised compilation\n";
-    print "\t-J option        : option must be enclosed by '.\n";
-    print "\t                 : pass option to the Java Virtual Machine\n";
-    print "\t                 : (ex. -J '-Xmx100m -verbose:gc')\n";
-    print "\n";
-}
-
-sub message {
-    my ($x) = @_;
-    if ($opt_v) { # check -v option
-	print "\% $x\n";
-    }
-}
-
-sub error {
-    my ($x) = @_;
-    print "\% ERROR: $x: $0\n";
-    exit 1;
-}
-
-#sub init {
-#    %env = (
-#	"goal",        "",
-#	"system",      "/Users/banbara/prog/plcafe/PrologCafe095/src/compiler/pl2am.sav",
-#	"system_opts", "",
-#	"system_args", "",
-#	);
-#    %env = (
-#	"goal",        "load('/Users/banbara/prog/plcafe/PrologCafe095/src/compiler/pl2am.ql'), main.",
-#	"system",      "sicstus",
-#	"system_opts", "",
-#	"system_args", "",
-#	);
-#    %env = (
-#	"goal",        "",
-#	"system",      "java",
-#	"system_opts", "-cp \$PLCAFEDIR/plcafe.jar:\$CLASSPATH",
-#	"system_args", "com.googlecode.prolog_cafe.lang.PrologMain com.googlecode.prolog_cafe.compiler.pl2am:main",
-#	);
-#}
-
diff --git a/src/lang/Makefile b/src/lang/Makefile
deleted file mode 100644
index 9fde585..0000000
--- a/src/lang/Makefile
+++ /dev/null
@@ -1,28 +0,0 @@
-################################################################
-#	Makefile for Prolog Cafe
-################################################################
-
-################################################################
-# The following two definitions will be overridden.
-#
-# JAVAC : the command of Java compiler system
-#          (ex. javac)
-# JAR   : the command of Jar archive system
-#          (ex. jar)
-#
-JAVAC     = javac
-JAVACOPTS = -d . -Xlint
-JAR       = jar
-JAROPTS   = cvf
-################################################################
-lang: 
-	$(JAVAC)  $(JAVACOPTS) *.java
-	$(JAR) $(JAROPTS) lang.jar com/googlecode/prolog_cafe/lang/
-
-clean:
-	-rm -f -r com
-	-rm -f core *~ *.class *.jar
-
-realclean: clean
-
-