Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ABCL support #52

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
notifications:
email: false
language: generic
language: java
sudo: required
env:
global:
Expand All @@ -14,6 +14,11 @@ matrix:
- MAKE_BUILD_TARGET=all
- SHEN=./shen
install:
- wget https://abcl.org/releases/1.8.0/abcl-bin-1.8.0.tar.gz
- tar xzf abcl-bin-1.8.0.tar.gz --strip-components=1 --wildcards *.jar
- printf '#!/bin/bash\njava -jar ./abcl.jar $@' > abcl
- chmod a+x abcl
- PATH=$PATH:$(pwd)
- wget http://mr.gy/blog/clozure-cl_1.11_amd64.deb
- sudo dpkg -i clozure-cl_1.11_amd64.deb
- wget http://http.us.debian.org/debian/pool/main/s/sbcl/sbcl_1.3.14-2+b1_amd64.deb
Expand Down
36 changes: 34 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ ifeq ($(OSName),windows)
Slash=\\\\
ArchiveSuffix=.zip
BinarySuffix=.exe
All=clisp ccl sbcl
All=abcl clisp ccl sbcl
PS=powershell.exe -Command
else
Slash=/
ArchiveSuffix=.tar.gz
BinarySuffix=
All=clisp ccl ecl sbcl
All=abcl clisp ccl ecl sbcl
ifeq ($(OSName),freebsd)
All=ccl ecl sbcl
else ifeq ($(OSName),openbsd)
Expand All @@ -52,6 +52,7 @@ else
endif
endif

ABCL=abcl
CCL=ccl
CLISP=clisp
ECL=ecl
Expand All @@ -74,11 +75,13 @@ KernelArchiveName=$(KernelFolderName)$(ArchiveSuffix)
KernelArchiveUrl=$(UrlRoot)/$(KernelTag)/$(KernelArchiveName)
BinaryName=shen$(BinarySuffix)

ShenABCL=.$(Slash)bin$(Slash)abcl$(Slash)shen.jar
ShenCLisp=.$(Slash)bin$(Slash)clisp$(Slash)$(BinaryName)
ShenCCL=.$(Slash)bin$(Slash)ccl$(Slash)$(BinaryName)
ShenECL=.$(Slash)bin$(Slash)ecl$(Slash)$(BinaryName)
ShenSBCL=.$(Slash)bin$(Slash)sbcl$(Slash)$(BinaryName)

RunABCL=java -jar $(ShenABCL) --
RunCLisp=$(ShenCLisp) --clisp-m 10MB
RunCCL=$(ShenCCL)
RunECL=$(ShenECL)
Expand All @@ -97,6 +100,9 @@ SourceReleaseName=shen-cl-$(GitVersion)-sources
.PHONY: all
all: $(All)

.PHONY: abcl
abcl: build-abcl test-abcl

.PHONY: clisp
clisp: build-clisp test-clisp

Expand Down Expand Up @@ -151,6 +157,20 @@ endif
# Build an implementation
#

.PHONY: build-abcl
build-abcl:
$(ABCL) --load boot.lsp
# NOTE: this depends on CLASSPATH being set
# java is not finding classes from abcl.jar
# refer to https://abcl-dev.blogspot.com/2009/09/loading-fasls-from-jar-files.html

# can run with abcl... (load "bin/abcl/shen.abcl")... (IN-PACKAGE :SHEN)... (|shen-cl.toplevel|)
# but gets FATAL ERROR and exits

# javac -d bin/abcl src/ShenABCL.java
# cp src/ShenABCLManifest.txt bin/abcl
# cd bin/abcl; jar cfm shen.jar ShenABCLManifest.txt ShenABCL.class shen.abcl

.PHONY: build-clisp
build-clisp:
$(CLISP) -i boot.lsp
Expand All @@ -171,6 +191,12 @@ build-sbcl:
# Test an implementation
#

.PHONY: test-abcl
test-abcl:
# NOTE: test-abcl disabled since build is not working
# $(RunABCL) $(Tests)
echo 'test-abcl disabled'

.PHONY: test-clisp
test-clisp:
$(RunCLisp) $(Tests)
Expand All @@ -191,6 +217,12 @@ test-sbcl:
# Run an implementation
#

.PHONY: run-abcl
run-abcl:
# NOTE: run-abcl disabled since build is not working
# $(RunABCL) $(Args)
echo 'run-abcl disabled'

.PHONY: run-clisp
run-clisp:
$(RunCLisp) $(Args)
Expand Down
4 changes: 3 additions & 1 deletion PREREQUISITES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO: cover ABCL in this doc

# Prerequisites

* For [BSD](#bsd)
Expand Down Expand Up @@ -36,7 +38,7 @@ If the version of SBCL available throught `apt` is too old, a sufficiently new v

## macOS

CLisp, Clozure, ECL and SBCL can be acquired through Homebrew with `brew install clisp clozure-cl ecl sbcl`.
ABCL, CLisp, Clozure, ECL and SBCL can be acquired through Homebrew with `brew install abcl clisp clozure-cl ecl sbcl`.

## Windows

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

This codebase currently supports the following implementations:

* [Armed Bear Common Lisp](https://abcl.org/)
* [GNU CLisp](http://www.clisp.org/)
* [Clozure Common Lisp](http://ccl.clozure.com/)
* [Embeddable Common Lisp](https://common-lisp.net/project/ecl/)
Expand Down Expand Up @@ -52,7 +53,7 @@ The `Makefile` automates all build and test operations.
| `run-X` | Start Shen REPL. |
| `release` | Creates archive of compiled binaries. |

`X` can be `clisp`, `ccl`, `ecl`, `sbcl` or it can be `all`, which will run the command for all of the preceding.
`X` can be `abcl`, `clisp`, `ccl`, `ecl`, `sbcl` or it can be `all`, which will run the command for all of the preceding.

`precompile` is only required when bootstraping Shen/CL from this repository, the source release includes the precompiled files. The `SHEN` variable has to be defined and point to a working Shen executable that will be used to precompile the kernel and compiler code.

Expand Down
24 changes: 20 additions & 4 deletions boot.lsp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
; Implementation-Specific Declarations
;

#+abcl
(progn
(defvar *compiled-files* nil)
(defconstant compiled-suffix ".abcl")
(defconstant binary-path "./bin/abcl/")
(defconstant concatenated-fasl-path (format nil "~Ashen~A" binary-path compiled-suffix))
(defconstant executable-name #+windows "shen.exe" #-windows "shen"))

#+clisp
(progn
(defconstant compiled-suffix ".fas")
Expand All @@ -56,7 +64,7 @@

#+ccl
(progn
(defconstant compiled-suffix (format nil "~a" *.fasl-pathname*))
(defconstant compiled-suffix (format nil "~A" *.fasl-pathname*))
(defconstant binary-path "./bin/ccl/")
(defconstant executable-name #+windows "shen.exe" #-windows "shen"))

Expand Down Expand Up @@ -85,8 +93,10 @@

#-ecl
(defun compile-lsp (file)
(let ((lsp-file (format nil "~A~A.lsp" binary-path file)))
(compile-file lsp-file)))
(let ((lsp-file (format nil "~A~A.lsp" binary-path file))
(fas-file (format nil "~A~A~A" binary-path file compiled-suffix)))
(compile-file lsp-file)
#+abcl (push fas-file *compiled-files*)))

#+ecl
(defun compile-lsp (file)
Expand Down Expand Up @@ -164,9 +174,10 @@
(|shen-cl.initialise|)
(|shen.x.features.initialise| '(
|shen/cl|
#+abcl |shen/cl.abcl|
#+clisp |shen/cl.clisp|
#+sbcl |shen/cl.sbcl|
#+ccl |shen/cl.ccl|
#+sbcl |shen/cl.sbcl|
)))

(fmakunbound 'compile-lsp)
Expand All @@ -179,6 +190,11 @@

(defconstant executable-path (format nil "~A~A" binary-path executable-name))

#+abcl
(progn
(system:concatenate-fasls (reverse *compiled-files*) concatenated-fasl-path)
(ext:quit))

#+clisp
(progn
(ext:saveinitmem
Expand Down
27 changes: 27 additions & 0 deletions src/ShenABCL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Based on code by Didier Verna found at
// https://www.didierverna.net/blog/index.php?post/2011/01/22/Towards-ABCL-Standalone-Executables

import java.util.stream.Stream;
import org.armedbear.lisp.*;

public class ShenABCL {
public static void main(String[] args) {
Runnable runShen = () -> {
try {
LispObject cmdline = Stream.of(args)
.reduce(Lisp.NIL.getSymbolValue(), (x, y) -> new Cons(y, x), (z, w) -> z)
.nreverse();
Lisp._COMMAND_LINE_ARGUMENT_LIST_.setSymbolValue(cmdline);
Interpreter.createInstance();
Load.load(ShenABCL.class.getResourceAsStream("shen.abcl"));
} catch (ProcessingTerminated e) {
System.exit(e.getStatus());
} catch (Exception e) {
System.err.println("Uncaught Exception:");
e.printStackTrace();
System.exit(1);
}
};
new Thread(null, runShen, "shen-abcl", 4194304L).start();
}
}
3 changes: 3 additions & 0 deletions src/ShenABCLManifest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Sealed: true
Main-Class: ShenABCL
6 changes: 6 additions & 0 deletions src/overwrite.lsp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@
(setf acc (funcall (funcall (funcall f k) v) acc))) dict)
acc))

#+abcl
(defun |cl.exit| (code)
(ext:quit :status code))

#+clisp
(defun |cl.exit| (code)
(ext:exit code))
Expand Down Expand Up @@ -254,8 +258,10 @@
vec))

; Amend the REPL credits message to explain exit command
#-abcl
(setf (symbol-function '|shen-cl.original-credits|) #'|shen.credits|)

#-abcl
(defun |shen.credits| ()
(|shen-cl.original-credits|)
(format t "exit REPL with (cl.exit)"))
Expand Down
2 changes: 1 addition & 1 deletion src/package.lsp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

(defpackage :shen
(:documentation "This is the package in which the Shen language operates.")
#+clisp
#+(or abcl clisp)
(:use :common-lisp
:ext)
#+ccl
Expand Down
20 changes: 18 additions & 2 deletions src/primitives.lsp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
(defvar |*port*| "3.0.3")
(defvar |*porters*| "Mark Tarver, Robert Koeninger and Bruno Deferrari")

#+abcl
(progn
(defvar |*implementation*| "ABCL")
(defvar |*release*| (lisp-implementation-version))
(defvar |*os*| (or #+windows "Windows" #+linux "Linux" #+darwin "macOS" #+unix "Unix" "Unknown")))

#+clisp
(progn
(defvar |*implementation*| "GNU CLisp")
Expand Down Expand Up @@ -204,9 +210,20 @@
(t
nil)))

#+abcl
(defun |write-byte| (byte s)
(write-byte (code-char s) s))

#+abcl
(defun |read-byte| (s)
(let ((ch (read-char s nil -1)))
(if (eq -1 ch) ch (char-code ch))))

#-abcl
(defun |write-byte| (byte s)
(write-byte byte s))

#-abcl
(defun |read-byte| (s)
(read-byte s nil -1))

Expand Down Expand Up @@ -362,7 +379,6 @@
(defun |shen-cl.read-eval| (str)
(car (last (mapc #'|eval| (|read-from-string| str)))))


(defun |shen-cl.toplevel-interpret-args| (args)
(|trap-error|
(let ((result (|shen.x.launcher.launch-shen| args)))
Expand Down Expand Up @@ -398,7 +414,7 @@
(let ((args (cons (car (coerce (ext:argv) 'list)) ext:*args*)))
(|shen-cl.toplevel-interpret-args| args)))))

#+ccl
#+(or abcl ccl)
(handler-bind ((warning #'muffle-warning))
(|shen-cl.toplevel-interpret-args| *command-line-argument-list*))

Expand Down