| 1 | % -*- mode: latex; -*- |
|---|
| 2 | % http://en.wikibooks.org/wiki/LaTeX/ |
|---|
| 3 | \documentclass[10pt]{book} |
|---|
| 4 | % also need to have cm-super installed for high quality rendering |
|---|
| 5 | |
|---|
| 6 | %\usepackage[LGR,T1]{fontenc} |
|---|
| 7 | \usepackage[utf8]{inputenc} |
|---|
| 8 | |
|---|
| 9 | \usepackage{abcl} |
|---|
| 10 | |
|---|
| 11 | \usepackage{hyperref} % Put this one last, it redefines lots of internals |
|---|
| 12 | |
|---|
| 13 | \begin{document} |
|---|
| 14 | \title{Armed Bear Common Lisp User Manual} |
|---|
| 15 | \date{Version 1.9.3 DRAFT \\ |
|---|
| 16 | \smallskip |
|---|
| 17 | Unreleased} |
|---|
| 18 | \author{Mark Evenson \and Erik H\"{u}lsmann \and Rudolf Schlatte \and |
|---|
| 19 | Alessio Stalla \and Ville Voutilainen} |
|---|
| 20 | |
|---|
| 21 | \maketitle |
|---|
| 22 | |
|---|
| 23 | \tableofcontents |
|---|
| 24 | |
|---|
| 25 | %%Preface to the first edition, abcl-1.0 |
|---|
| 26 | \subsection{Preface to the First Edition} |
|---|
| 27 | \textsc{ABCL} 1.0 was released at the European Common Lisp Meeting |
|---|
| 28 | in Amsterdam in 2011. |
|---|
| 29 | |
|---|
| 30 | %%Preface to the second edition, abcl-1.1 |
|---|
| 31 | \subsection{Preface to the Second Edition} |
|---|
| 32 | \textsc{ABCL} 1.1 now contains \textsc{(A)MOP}. We hope you enjoy! |
|---|
| 33 | --The Mgmt. |
|---|
| 34 | |
|---|
| 35 | %%Preface to the Third edition, abcl-1.2 |
|---|
| 36 | \subsection{Preface to the Third Edition} |
|---|
| 37 | The implementation now contains a performant and conforming |
|---|
| 38 | implementation of \textsc{(A)MOP} to the point of inclusion in |
|---|
| 39 | \textsc{CLOSER-MOP}'s test suite. |
|---|
| 40 | |
|---|
| 41 | %%Preface to the Fourth edition, abcl-1.3. |
|---|
| 42 | \subsection{Preface to the Fourth Edition} |
|---|
| 43 | |
|---|
| 44 | \textsc{ABCL} 1.3 now implements an optimized implementation of the |
|---|
| 45 | \code{org.armedbear.lisp.LispStack} abstraction thanks to Dmitry |
|---|
| 46 | Nadezhin which runs on ORCL \textsc{JVMs} from \textsc{Java 5} through |
|---|
| 47 | \textsc{Java 8}. |
|---|
| 48 | |
|---|
| 49 | %%Preface to the Fifth edition, abcl-1.4 |
|---|
| 50 | \subsection{Preface to the Fifth Edition} |
|---|
| 51 | |
|---|
| 52 | \textsc{ABCL} 1.4 consolidates eighteen months of production bug-fixes, |
|---|
| 53 | and substantially improves the support for invoking external |
|---|
| 54 | processes via \code{SYS:RUN-PROGRAM}. |
|---|
| 55 | |
|---|
| 56 | %%Preface to the Sixth edition, abcl-1.5 |
|---|
| 57 | \subsection{Preface to the Sixth Edition} |
|---|
| 58 | |
|---|
| 59 | With the sixth major release of the implementation, we make the |
|---|
| 60 | following explicit revision of our compatibility to the underlying |
|---|
| 61 | \textsc{JVM}. Since we are an open source implementation, we insist |
|---|
| 62 | on possible open access to the sources from with an \textsc{JDK} may |
|---|
| 63 | both be built and run upon. This requirement is no longer met by Java |
|---|
| 64 | 5, so henceforth with the release of \textsc{ABCL} 1.5, we will |
|---|
| 65 | support \textsc{Java 6}, \textsc{Java 7} and \textsc{Java 8} runtimes. |
|---|
| 66 | |
|---|
| 67 | %%Preface to the Seventh edition, abcl-1.6 |
|---|
| 68 | \subsection{Preface to the Seventh Edition} |
|---|
| 69 | |
|---|
| 70 | Long overdue, we turn our Java to 11. |
|---|
| 71 | |
|---|
| 72 | Reflecting the management's best estimates as to implementation most |
|---|
| 73 | easily available to the potential \textsc{ABCL} 1.6 User, the Seventh |
|---|
| 74 | release implementation works best with \textsc{Java 8} or \textsc{Java 11} |
|---|
| 75 | runtimes. Since freely available implementations of jdk6 and jdk7 |
|---|
| 76 | exist, we still strive to maintain compatibility with the Java 6 and |
|---|
| 77 | Java 7 runtime environments but those environments are less tested. |
|---|
| 78 | The User may need to use the facilities of the \textsc{ABCL-BUILD} contrib to |
|---|
| 79 | recompile the implementation locally in more exotic runtimes (see |
|---|
| 80 | Section~\ref{section:abcl-build} page~\pageref{section:abcl-build}). |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | %%Preface to the Eighth edition, abcl-1.7 |
|---|
| 84 | \subsection{Preface to the Eighth Edition} |
|---|
| 85 | Since the implementation now runs comfortably on \textsc{openjdk6}, |
|---|
| 86 | \textsc{openjdk7}, \textsc{openjdk8}, \textsc{openjdk11}, and |
|---|
| 87 | \textsc{openjdk14}, we take advantage of the presence of the |
|---|
| 88 | \code{java.nio} package introduced in \textsc{Java 5}. We have |
|---|
| 89 | overhauled the implementation to use these abstractions for arrays |
|---|
| 90 | specialized on commonly used unsigned-byte types, adding two |
|---|
| 91 | additional keyword arguments useful in their construction to |
|---|
| 92 | \code{cl:make-array}.\footnote{See \ref{section:make-array} on page |
|---|
| 93 | \pageref{section:make-array}}. |
|---|
| 94 | |
|---|
| 95 | %%Preface to the Ninth edition, abcl-1.8.0 |
|---|
| 96 | \subsection{Preface to the Ninth Edition} |
|---|
| 97 | With the Ninth Edition of the implementation we now support building |
|---|
| 98 | and running with \textsc{openjdk15}. This is intended as the last |
|---|
| 99 | major release to support the \textsc{openjdk6}, \textsc{openjdk7}, and |
|---|
| 100 | \textsc{openjdk8} platforms. |
|---|
| 101 | |
|---|
| 102 | The implementation of the \code{EXT:JAR-PATHNAME} and |
|---|
| 103 | \code{EXT:URL-PATHNAME} sub-types of \code{cl:PATHNAME} has been fixed |
|---|
| 104 | to the point that arbitrary references to \textsc{ZIP} archives within |
|---|
| 105 | archives now work for most read-only operations (\code{CL:PROBE-FILE}, |
|---|
| 106 | \code{CL:TRUENAME}, \code{CL:OPEN}, \code{CL:LOAD}, |
|---|
| 107 | \code{CL:FILE-WRITE-DATE}, \code{CL:DIRECTORY}, and |
|---|
| 108 | \code{CL:MERGE-PATHNAMES}). The previous versions of the |
|---|
| 109 | implementation relied on the ability for \code{java.net.URL} to open |
|---|
| 110 | streams of an archive within an archive, behavior that was silently |
|---|
| 111 | dropped after Java 5, and consequently hasn't worked on common |
|---|
| 112 | platforms supported by the Bear in a long time. This restores the |
|---|
| 113 | feasibility of accessing fasls from within jar files \footnote{Examine |
|---|
| 114 | the ASDF-JAR contrib in section \ref{section:asdf-jar} on page |
|---|
| 115 | \pageref{section:asdf-jar} for a recipe for packaging and accessing |
|---|
| 116 | such artifacts.}. |
|---|
| 117 | |
|---|
| 118 | %%Preface to the Tenth edition, abcl-1.9.0 |
|---|
| 119 | \subsection{Preface to the Tenth Edition} |
|---|
| 120 | |
|---|
| 121 | For the Tenth edition, we have explicitly tested the stable, Long Term |
|---|
| 122 | Support (``LTS'') versions of the \textsc{OpenJDK}, namely \textsc{openjdk8}, |
|---|
| 123 | \textsc{openjdk11}, and \textsc{openjdk17}. We intend to drop one or |
|---|
| 124 | more of these platforms for the next edition in order to more |
|---|
| 125 | completely overhaul the implementations use of compare and swap on |
|---|
| 126 | memory originally allocated outside the hosting \textsc{JVM}. As such, the |
|---|
| 127 | Tenth edition is built released with openjdk8 but should run best on |
|---|
| 128 | \textsc{openjdk17}. |
|---|
| 129 | |
|---|
| 130 | \chapter{Introduction} |
|---|
| 131 | |
|---|
| 132 | Armed Bear Common Lisp (\textsc{ABCL}) is an implementation of |
|---|
| 133 | \textsc{Common Lisp} that runs on the Java Virtual Machine |
|---|
| 134 | (\textsc{JVM}). \textsc{ABCL} compiles \textsc{Common Lisp} to |
|---|
| 135 | \textsc{Java} byte-code\footnote{The class files produced by the |
|---|
| 136 | compiler have a byte-code version of ``49.0''.}, with an efficiency |
|---|
| 137 | that varies upon the hosting JVM implementation. \textsc{ABCL} |
|---|
| 138 | supports building and running on the \textsc{openjdk8}, |
|---|
| 139 | \textsc{openjdk11}, and \textsc{openjdk17} \textsc{JVM} |
|---|
| 140 | implementations\footnote{The codebase runs and compiles on every |
|---|
| 141 | historical openjdk from \textsc{openjdk6} through \textsc{openjdk8}, |
|---|
| 142 | does *not* run on either\textsc{openjdk9} or either\textsc{openjdk10}, |
|---|
| 143 | but then runs on every openjdk released as of May 2022 with minor |
|---|
| 144 | adjustments}. As of May 2022, we are using the Adoptium community |
|---|
| 145 | \cite{adoptium} binary releases which provides perhaps the least |
|---|
| 146 | encumbered installation of unencumbered openjdk implementations. |
|---|
| 147 | |
|---|
| 148 | Armed Bear provides the following integration methods for interfacing |
|---|
| 149 | with Java code and libraries: |
|---|
| 150 | \begin{itemize} |
|---|
| 151 | \item Lisp code can create Java objects and call their methods (see |
|---|
| 152 | Section~\ref{section:lisp-java}, page~\pageref{section:lisp-java}). |
|---|
| 153 | \item Java code can call Lisp functions and generic functions, either |
|---|
| 154 | directly (Section~\ref{section:calling-lisp-from-java}, |
|---|
| 155 | page~\pageref{section:calling-lisp-from-java}) or via \texttt{JSR-223} |
|---|
| 156 | (Section~\ref{section:java-scripting-api}, |
|---|
| 157 | page~\pageref{section:java-scripting-api}). |
|---|
| 158 | \item \code{jinterface-implementation} creates Lisp-side implementations |
|---|
| 159 | of Java interfaces that can be used as listeners for Swing classes and |
|---|
| 160 | similar. |
|---|
| 161 | \item \code{java:jnew-runtime-class} can inject fully synthetic Java |
|---|
| 162 | classes--and their objects-- into the current JVM process whose |
|---|
| 163 | behavior is specified via closures expressed in \textsc{Common |
|---|
| 164 | Lisp}. \footnote{Parts of the current implementation are not fully |
|---|
| 165 | finished, so the status of some interfaces here should be treated |
|---|
| 166 | with skepticism if you run into problems.} |
|---|
| 167 | |
|---|
| 168 | \end{itemize} |
|---|
| 169 | \textsc{ABCL} is supported by the Lisp library manager |
|---|
| 170 | \textsc{Quicklisp}\footnote{\url{http://quicklisp.org/}} and can run many of the |
|---|
| 171 | programs and libraries provided therein out-of-the-box. |
|---|
| 172 | |
|---|
| 173 | \section{Conformance} |
|---|
| 174 | \label{section:conformance} |
|---|
| 175 | |
|---|
| 176 | \subsection{ANSI Common Lisp} |
|---|
| 177 | \textsc{ABCL} is currently a (non)-conforming \textsc{ANSI} Common Lisp |
|---|
| 178 | implementation due to the following known issues: |
|---|
| 179 | |
|---|
| 180 | \begin{itemize} |
|---|
| 181 | \item The generic function signatures of the \code{CL:DOCUMENTATION} |
|---|
| 182 | symbol do not match the specification. |
|---|
| 183 | \item The \code{CL:TIME} form does not return a proper |
|---|
| 184 | \code{CL:VALUES} environment to its caller. |
|---|
| 185 | \item When merging pathnames and the defaults point to a |
|---|
| 186 | \code{EXT:JAR-PATHNAME}, we set the \code{DEVICE} of the result to |
|---|
| 187 | \code{:UNSPECIFIC} if the pathname to be be merged does not contain |
|---|
| 188 | a specified \code{DEVICE}, does not contain a specified \code{HOST}, |
|---|
| 189 | does contain a relative \code{DIRECTORY}, and we are not running on |
|---|
| 190 | a \textsc{MSFT} Windows platform.\footnote{The intent of this rather |
|---|
| 191 | arcane sounding deviation from conformance is so that the result of |
|---|
| 192 | a merge won't fill in a \code{DEVICE} with the wrong "default device |
|---|
| 193 | for the host" in the sense of the fourth paragraph in the |
|---|
| 194 | \textsc{CLHS} description of MERGE-PATHNAMES (see in \cite{CLHS} the |
|---|
| 195 | paragraph beginning "If the PATHNAME explicitly specifies a host and |
|---|
| 196 | not a deviceâŠ"). A future version of the implementation may return |
|---|
| 197 | to conformance by using the \code{HOST} value to reflect the type |
|---|
| 198 | explicitly. See \ref{section:jar-pathname} on page |
|---|
| 199 | \pageref{section:jar-pathname} for further information.} |
|---|
| 200 | |
|---|
| 201 | \end{itemize} |
|---|
| 202 | |
|---|
| 203 | Somewhat confusingly, this statement of non-conformance in the |
|---|
| 204 | accompanying user documentation fulfills the requirements that |
|---|
| 205 | \textsc{ABCL} is a conforming ANSI Common Lisp implementation according |
|---|
| 206 | to the Common Lisp Hyper-Spec~\cite{CLHS}. Clarifications to this point |
|---|
| 207 | are solicited. |
|---|
| 208 | |
|---|
| 209 | \textsc{ABCL} aims to be be a fully conforming \textsc{ANSI} Common |
|---|
| 210 | Lisp implementation. Any other behavior should be reported as a bug. |
|---|
| 211 | |
|---|
| 212 | \subsection{Contemporary Common Lisp} |
|---|
| 213 | In addition to \textsc{ANSI} conformance, \textsc{ABCL} strives to implement |
|---|
| 214 | features expected of a contemporary \textsc{Common Lisp}, i.e. a Lisp of the |
|---|
| 215 | post-2005 Renaissance. |
|---|
| 216 | |
|---|
| 217 | The following known problems detract from \textsc{ABCL} being a proper |
|---|
| 218 | contemporary Common Lisp. |
|---|
| 219 | \begin{itemize} |
|---|
| 220 | \item An incomplete implementation of interactive debugging |
|---|
| 221 | mechanisms, namely a no-op version of \code{STEP}\footnote{Somewhat |
|---|
| 222 | surprisingly allowed by \textsc{ANSI}}, the inability to inspect |
|---|
| 223 | local variables in a given call frame, and the inability to resume a |
|---|
| 224 | halted computation at an arbitrarily selected call frame. |
|---|
| 225 | \item Incomplete streams abstraction, in that \textsc{ABCL} needs a |
|---|
| 226 | suitable abstraction between \textsc{ANSI} and \textsc{Gray streams} |
|---|
| 227 | with a runtime switch for the beyond conforming |
|---|
| 228 | behavior\footnote{The streams could be optimized to the |
|---|
| 229 | \textsc{JVM} NIO \cite{nio} abstractions at great profit for |
|---|
| 230 | binary byte-level manipulations.}. |
|---|
| 231 | \item Incomplete documentation: source code is missing doc-strings from |
|---|
| 232 | all exported symbols from the \code{EXTENSIONS}, \code{SYSTEM}, |
|---|
| 233 | \code{JAVA}, \code{MOP}, and \code{THREADS} packages. This user |
|---|
| 234 | manual is currently in draft status. |
|---|
| 235 | \end{itemize} |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | \section{License} |
|---|
| 240 | |
|---|
| 241 | \textsc{ABCL} is licensed under the terms of the \textsc{GPL} v2 of |
|---|
| 242 | June 1991 with an added ``classpath-exception'' clause (see the file |
|---|
| 243 | \texttt{COPYING} in the source distribution\footnote{See |
|---|
| 244 | \url{http://abcl.org/svn/trunk/tags/1.9.2/COPYING}} for the license, |
|---|
| 245 | term 13 in the same file for the classpath exception). This license |
|---|
| 246 | broadly means that you must distribute the sources to \textsc{ABCL}, |
|---|
| 247 | including any changes you make, together with a program that includes |
|---|
| 248 | \textsc{ABCL}, but that you are not required to distribute the sources |
|---|
| 249 | of the whole program. Submitting your changes upstream to the \textsc{ABCL} |
|---|
| 250 | development team is actively encouraged and very much appreciated, of |
|---|
| 251 | course. |
|---|
| 252 | |
|---|
| 253 | \section{Contributors} |
|---|
| 254 | |
|---|
| 255 | \begin{itemize} |
|---|
| 256 | \item Dmitry Nadezhin |
|---|
| 257 | \item Philipp Marek \texttt{Thanks for the mark-up, and review of the Manual} |
|---|
| 258 | \item Douglas Miles \texttt{Thanks for the whacky IKVM stuff and keeping the flame alive |
|---|
| 259 | in the dark years.} |
|---|
| 260 | \item Alan Ruttenberg \texttt{Thanks for JSS.} |
|---|
| 261 | \item Olof-Joachim Frahm |
|---|
| 262 | \item Jonathan Cunningham |
|---|
| 263 | \item Uthar |
|---|
| 264 | \item Alejandro Zamora Fonseca \texttt{Thanks for ABCL-STEPPER, and all the patches.} |
|---|
| 265 | \item phoe |
|---|
| 266 | \item jackdaniel |
|---|
| 267 | \item Robert Munyer |
|---|
| 268 | \item Eric Timmons (daewok) |
|---|
| 269 | \item contrapunctus |
|---|
| 270 | \item Scott Burson |
|---|
| 271 | \item Samuel Hunter |
|---|
| 272 | \item Phil Eaton |
|---|
| 273 | \item jpellegrini |
|---|
| 274 | |
|---|
| 275 | |
|---|
| 276 | \item Andr\'as Simon (piso) |
|---|
| 277 | \item and of course \emph{Peter Graves} |
|---|
| 278 | \end{itemize} |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | \chapter{Running ABCL} |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | \textsc{ABCL} is packaged as a single jar file usually named either |
|---|
| 285 | \texttt{abcl.jar} or possibly something like \texttt{abcl-1.9.2.jar} if |
|---|
| 286 | using a versioned package on the local file-system from your system |
|---|
| 287 | vendor. This jar file can be executed from the command line to obtain a |
|---|
| 288 | \textsc{REPL}\footnote{Read-Eval Print Loop, a Lisp command-line}, viz: |
|---|
| 289 | |
|---|
| 290 | \index{REPL} |
|---|
| 291 | |
|---|
| 292 | \begin{listing-shell} |
|---|
| 293 | cmd$ java -jar abcl.jar |
|---|
| 294 | \end{listing-shell} %$ unconfuse Emacs syntax highlighting |
|---|
| 295 | |
|---|
| 296 | \emph{N.b.} for the proceeding command to work, the \texttt{java} |
|---|
| 297 | executable needs to be in your path. |
|---|
| 298 | |
|---|
| 299 | To facilitate the use of ABCL in tool chains such as SLIME~\cite{slime} |
|---|
| 300 | (the Superior Lisp Interaction Mode for Emacs), we provide both a Bourne |
|---|
| 301 | shell script and a \textsc{DOS} batch file. If you or your |
|---|
| 302 | administrator adjusted the path properly, ABCL may be executed simply |
|---|
| 303 | as: |
|---|
| 304 | |
|---|
| 305 | \begin{listing-shell} |
|---|
| 306 | cmd$ abcl |
|---|
| 307 | \end{listing-shell}%$ |
|---|
| 308 | |
|---|
| 309 | Probably the easiest way of setting up an editing environment using the |
|---|
| 310 | \textsc{Emacs} editor is to use \textsc{Quicklisp} and follow the instructions at |
|---|
| 311 | \url{http://www.quicklisp.org/beta/#slime}. |
|---|
| 312 | |
|---|
| 313 | \section{Command Line Options} |
|---|
| 314 | |
|---|
| 315 | ABCL recognizes the following command line options: |
|---|
| 316 | |
|---|
| 317 | \index{Command Line Options} |
|---|
| 318 | |
|---|
| 319 | \begin{description} |
|---|
| 320 | % FIXME move this fuggliness to our macros. sigh. |
|---|
| 321 | \item \code{--help} \\ |
|---|
| 322 | displays a help message. |
|---|
| 323 | \item \code{--noinform} \\ |
|---|
| 324 | Suppresses the printing of startup information and banner. |
|---|
| 325 | \item \code{--noinit} \\ |
|---|
| 326 | suppresses the loading of the \verb+~/.abclrc+ startup file. |
|---|
| 327 | \item \code{--nosystem} \\ |
|---|
| 328 | suppresses loading the \texttt{system.lisp} customization file. |
|---|
| 329 | \item \code{--eval FORM} \\ |
|---|
| 330 | evaluates \textsc{form} before initializing the REPL. |
|---|
| 331 | \item \code{--load FILE} \\ |
|---|
| 332 | loads the file \textsc{file} before initializing the REPL. |
|---|
| 333 | \item \code{--load-system-file FILE} \\ loads the system |
|---|
| 334 | file\footnote{System files have a distinguished PATHNAME resolution |
|---|
| 335 | mechanism based on the location of the \texttt{system.lisp} source |
|---|
| 336 | unit} FILE before initializing the REPL. |
|---|
| 337 | \item \code{--batch} \\evaluates forms specified by arguments and in |
|---|
| 338 | the initialization file \verb+~/.abclrc+, and then exits without |
|---|
| 339 | starting a \textsc{REPL}. |
|---|
| 340 | \end{description} |
|---|
| 341 | |
|---|
| 342 | All of the command line arguments following the occurrence of \verb+--+ |
|---|
| 343 | are passed unprocessed into a list of strings accessible via the |
|---|
| 344 | variable \code{EXT:*COMMAND-LINE-ARGUMENT-LIST*} from within ABCL. |
|---|
| 345 | |
|---|
| 346 | \section{Initialization} |
|---|
| 347 | |
|---|
| 348 | If the \textsc{ABCL} process is started without the |
|---|
| 349 | \code{--noinit} flag, it attempts to load a file |
|---|
| 350 | named \code{.abclrc} in the user's home directory and then interpret |
|---|
| 351 | its contents. |
|---|
| 352 | |
|---|
| 353 | The user's home directory is determined by the value of the JVM system |
|---|
| 354 | property \texttt{user.home}. This value may or may not correspond |
|---|
| 355 | to the value of the \texttt{HOME} system environment variable, at the |
|---|
| 356 | discretion of the JVM implementation that \textsc{ABCL} finds itself |
|---|
| 357 | hosted upon. |
|---|
| 358 | |
|---|
| 359 | \chapter{Interaction with the Hosting JVM} |
|---|
| 360 | |
|---|
| 361 | % Plan of Attack |
|---|
| 362 | % |
|---|
| 363 | % describe calling Java from Lisp, and calling Lisp from Java, |
|---|
| 364 | % probably in two separate sections. Presumably, we can partition our |
|---|
| 365 | % audience into those who are more comfortable with Java, and those |
|---|
| 366 | % that are more comfortable with Lisp |
|---|
| 367 | |
|---|
| 368 | The Armed Bear Common Lisp implementation is hosted on a Java Virtual |
|---|
| 369 | Machine. This chapter describes the mechanisms by which the |
|---|
| 370 | implementation interacts with that hosting mechanism. |
|---|
| 371 | |
|---|
| 372 | \section{Lisp to Java} |
|---|
| 373 | \label{section:lisp-java} |
|---|
| 374 | |
|---|
| 375 | \textsc{ABCL} offers a number of mechanisms to interact with Java from its |
|---|
| 376 | Lisp environment. It allows calling both instance and static methods |
|---|
| 377 | of Java objects, manipulation of instance and static fields on Java |
|---|
| 378 | objects, and construction of new Java objects. |
|---|
| 379 | |
|---|
| 380 | When calling Java routines, some values will automatically be |
|---|
| 381 | converted by the FFI\footnote{Foreign Function Interface is the term |
|---|
| 382 | of art for the part of a \textsc{Lisp} implementation which implements |
|---|
| 383 | calling code written in other languages, typically normalized to the |
|---|
| 384 | local C compiler calling conventions.} from \textsc{Lisp} values to Java |
|---|
| 385 | values. These conversions typically apply to strings, integers and |
|---|
| 386 | floats. Other values need to be converted to their \textsc{Java} equivalents by |
|---|
| 387 | the programmer before calling the Java object method. Java values |
|---|
| 388 | returned to \textsc{Lisp} are also generally converted back to their Lisp |
|---|
| 389 | counterparts. Some operators make an exception to this rule and do not |
|---|
| 390 | perform any conversion; those are the ``raw'' counterparts of certain |
|---|
| 391 | FFI functions and are recognizable by their name ending with |
|---|
| 392 | \code{-RAW}. |
|---|
| 393 | |
|---|
| 394 | \subsection{Low-level Java API} |
|---|
| 395 | |
|---|
| 396 | This subsection covers the low-level API available after evaluating |
|---|
| 397 | \code{(require :java)}. A higher level \textsc{Java} API, developed by Alan |
|---|
| 398 | Ruttenberg, is available in the \code{contrib/jss} directory and described |
|---|
| 399 | later in this document, see Section~\ref{section:jss} on page |
|---|
| 400 | \pageref{section:jss}. |
|---|
| 401 | |
|---|
| 402 | \subsubsection{Calling Java Object Methods} |
|---|
| 403 | |
|---|
| 404 | There are two ways to call a Java object method in the low-level (basic) API: |
|---|
| 405 | |
|---|
| 406 | \begin{itemize} |
|---|
| 407 | \item Call a specific method reference (which was previously acquired) |
|---|
| 408 | \item Dynamic dispatch using the method name and the call-specific |
|---|
| 409 | arguments provided by finding the best match (see |
|---|
| 410 | Section~\ref{section:param-matching-for-ffi}). |
|---|
| 411 | \end{itemize} |
|---|
| 412 | |
|---|
| 413 | \code{JAVA:JMETHOD} is used to acquire a specific method reference. The |
|---|
| 414 | function takes two or more arguments. The first is a Java class |
|---|
| 415 | designator (a \code{JAVA:JAVA-CLASS} object returned by |
|---|
| 416 | \code{JAVA:JCLASS} or a string naming a Java class). The second is a |
|---|
| 417 | string naming the method. |
|---|
| 418 | |
|---|
| 419 | Any arguments beyond the first two should be strings naming Java |
|---|
| 420 | classes, with one exception as listed in the next paragraph. These |
|---|
| 421 | classes specify the types of the arguments for the method. |
|---|
| 422 | |
|---|
| 423 | When \code{JAVA:JMETHOD} is called with three parameters and the last |
|---|
| 424 | parameter is an integer, the first method by that name and matching |
|---|
| 425 | number of parameters is returned. |
|---|
| 426 | |
|---|
| 427 | Once a method reference has been acquired, it can be invoked using |
|---|
| 428 | \code{JAVA:JCALL}, which takes the method as the first argument. The |
|---|
| 429 | second argument is the object instance to call the method on, or |
|---|
| 430 | \code{NIL} in case of a static method. Any remaining parameters are |
|---|
| 431 | used as the remaining arguments for the call. |
|---|
| 432 | |
|---|
| 433 | \subsubsection{Calling Java object methods: dynamic dispatch} |
|---|
| 434 | |
|---|
| 435 | The second way of calling Java object methods is by using dynamic dispatch. |
|---|
| 436 | In this case \code{JAVA:JCALL} is used directly without acquiring a method |
|---|
| 437 | reference first. In this case, the first argument provided to \code{JAVA:JCALL} |
|---|
| 438 | is a string naming the method to be called. The second argument is the instance |
|---|
| 439 | on which the method should be called and any further arguments are used to |
|---|
| 440 | select the best matching method and dispatch the call. |
|---|
| 441 | |
|---|
| 442 | \subsubsection{Dynamic dispatch: Caveats} |
|---|
| 443 | |
|---|
| 444 | Dynamic dispatch is performed by using the Java reflection |
|---|
| 445 | API\footnote{The Java reflection API is found in the |
|---|
| 446 | \code{java.lang.reflect} package}. Generally the dispatch works |
|---|
| 447 | fine, but there are corner cases where the API does not correctly |
|---|
| 448 | reflect all the details involved in calling a Java method. An example |
|---|
| 449 | is the following Java code: |
|---|
| 450 | |
|---|
| 451 | \begin{listing-java} |
|---|
| 452 | ZipFile jar = new ZipFile("/path/to/some.jar"); |
|---|
| 453 | Object els = jar.entries(); |
|---|
| 454 | Method method = els.getClass().getMethod("hasMoreElements"); |
|---|
| 455 | method.invoke(els); |
|---|
| 456 | \end{listing-java} |
|---|
| 457 | |
|---|
| 458 | Even though the method \code{hasMoreElements()} is public in |
|---|
| 459 | \code{Enumeration}, the above code fails with |
|---|
| 460 | |
|---|
| 461 | \begin{listing-java} |
|---|
| 462 | java.lang.IllegalAccessException: Class ... can |
|---|
| 463 | not access a member of class java.util.zip.ZipFile\$2 with modifiers |
|---|
| 464 | "public" |
|---|
| 465 | at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65) |
|---|
| 466 | at java.lang.reflect.Method.invoke(Method.java:583) |
|---|
| 467 | at ... |
|---|
| 468 | \end{listing-java} |
|---|
| 469 | |
|---|
| 470 | This is because the method has been overridden by a non-public class and |
|---|
| 471 | the reflection API, unlike \texttt{javac}, is not able to handle such a case. |
|---|
| 472 | |
|---|
| 473 | While code like that is uncommon in Java, it is typical of ABCL's FFI |
|---|
| 474 | calls. The code above corresponds to the following Lisp code: |
|---|
| 475 | |
|---|
| 476 | \begin{listing-lisp} |
|---|
| 477 | (let ((jar (jnew "java.util.zip.ZipFile" "/path/to/some.jar"))) |
|---|
| 478 | (let ((els (jcall "entries" jar))) |
|---|
| 479 | (jcall "hasMoreElements" els))) |
|---|
| 480 | \end{listing-lisp} |
|---|
| 481 | |
|---|
| 482 | except that the dynamic dispatch part is not shown. |
|---|
| 483 | |
|---|
| 484 | To avoid such pitfalls, all Java objects in \textsc{ABCL} carry an extra |
|---|
| 485 | field representing the ``intended class'' of the object. That class is |
|---|
| 486 | used first by \code{JAVA:JCALL} and similar to resolve methods; the |
|---|
| 487 | actual class of the object is only tried if the method is not found in |
|---|
| 488 | the intended class. Of course, the intended class is always a |
|---|
| 489 | super-class of the actual class -- in the worst case, they coincide. The |
|---|
| 490 | intended class is deduced by the return type of the method that |
|---|
| 491 | originally returned the Java object; in the case above, the intended |
|---|
| 492 | class of \code{ELS} is \code{java.util.Enumeration} because that is the |
|---|
| 493 | return type of the \code{entries} method. |
|---|
| 494 | |
|---|
| 495 | While this strategy is generally effective, there are cases where the |
|---|
| 496 | intended class becomes too broad to be useful. The typical example |
|---|
| 497 | is the extraction of an element from a collection, since methods in |
|---|
| 498 | the collection API erase all types to \code{Object}. The user can |
|---|
| 499 | always force a more specific intended class by using the \code{JAVA:JCOERCE} |
|---|
| 500 | operator. |
|---|
| 501 | |
|---|
| 502 | % \begin{itemize} |
|---|
| 503 | % \item Java values are accessible as objects of type JAVA:JAVA-OBJECT. |
|---|
| 504 | % \item The Java FFI presents a Lisp package (JAVA) with many useful |
|---|
| 505 | % symbols for manipulating the artifacts of expectation on the JVM, |
|---|
| 506 | % including creation of new objects \ref{JAVA:JNEW}, \ref{JAVA:JMETHOD}), the |
|---|
| 507 | % introspection of values \ref{JAVA:JFIELD}, the execution of methods |
|---|
| 508 | % (\ref{JAVA:JCALL}, \ref{JAVA:JCALL-RAW}, \ref{JAVA:JSTATIC}) |
|---|
| 509 | % \item The JSS package (\ref{JSS}) in contrib introduces a convenient macro |
|---|
| 510 | % syntax \ref{JSS:SHARPSIGN_DOUBLEQUOTE_MACRO} for accessing Java |
|---|
| 511 | % methods, and additional convenience functions. |
|---|
| 512 | % \item Java classes and libraries may be dynamically added to the |
|---|
| 513 | % classpath at runtime (JAVA:ADD-TO-CLASSPATH). |
|---|
| 514 | % \end{itemize} |
|---|
| 515 | |
|---|
| 516 | \subsubsection{Calling Java class static methods} |
|---|
| 517 | |
|---|
| 518 | Like non-static methods, references to static methods can be acquired by |
|---|
| 519 | using the \code{JAVA:JMETHOD} primitive. Static methods are called with |
|---|
| 520 | \code{JAVA:JSTATIC} instead of \code{JAVA:JCALL}. |
|---|
| 521 | |
|---|
| 522 | Like \code{JAVA:JCALL}, \code{JAVA:JSTATIC} supports dynamic dispatch by |
|---|
| 523 | passing the name of the method as a string instead of passing a method reference. |
|---|
| 524 | The parameters should be values to pass in the function call instead of |
|---|
| 525 | a specification of classes for each parameter. |
|---|
| 526 | |
|---|
| 527 | \subsubsection{Parameter matching for FFI dynamic dispatch} |
|---|
| 528 | \label{section:param-matching-for-ffi} |
|---|
| 529 | |
|---|
| 530 | The algorithm used to resolve the best matching method given the name |
|---|
| 531 | and the arguments' types is the same as described in the Java Language |
|---|
| 532 | Specification. Any deviation should be reported as a bug. |
|---|
| 533 | |
|---|
| 534 | % ###TODO reference to correct JLS section |
|---|
| 535 | |
|---|
| 536 | \subsubsection{Instantiating Java objects} |
|---|
| 537 | |
|---|
| 538 | \textsc{Java} objects can be instantiated (created) from \textsc{Lisp} by calling |
|---|
| 539 | a constructor from the class of the object to be created. The |
|---|
| 540 | \code{JAVA:JCONSTRUCTOR} primitive is used to acquire a constructor |
|---|
| 541 | reference. Its arguments specify the types of arguments of the constructor |
|---|
| 542 | method the same way as with \code{JAVA:JMETHOD}. |
|---|
| 543 | |
|---|
| 544 | The obtained constructor is passed as an argument to \code{JAVA:JNEW}, |
|---|
| 545 | together with any arguments. \code{JAVA:JNEW} can also be invoked with |
|---|
| 546 | a string naming the class as its first argument. |
|---|
| 547 | |
|---|
| 548 | \subsubsection{Accessing Java object and class fields} |
|---|
| 549 | |
|---|
| 550 | Fields in Java objects can be accessed using the getter and setter |
|---|
| 551 | functions \code{JAVA:JFIELD} and \code{(SETF JAVA:JFIELD)}. Static |
|---|
| 552 | (class) fields are accessed the same way, but with a class object or |
|---|
| 553 | string naming a class as first argument. |
|---|
| 554 | |
|---|
| 555 | Like \code{JAVA:JCALL} and friends, values returned from these accessors carry |
|---|
| 556 | an intended class around, and values which can be converted to Lisp values will |
|---|
| 557 | be converted. |
|---|
| 558 | |
|---|
| 559 | \section{Java to Lisp} |
|---|
| 560 | |
|---|
| 561 | This section describes the various ways that one interacts with \textsc{Lisp} |
|---|
| 562 | from \textsc{Java} code. In order to access the \textsc{Lisp} world from \textsc{Java}, one needs |
|---|
| 563 | to be aware of a few things, the most important ones being listed below: |
|---|
| 564 | |
|---|
| 565 | \begin{itemize} |
|---|
| 566 | \item All Lisp values are descendants of \code{LispObject}. |
|---|
| 567 | \item Lisp symbols are accessible either via static members of the |
|---|
| 568 | \code{Symbol} class, or by dynamically introspecting a \code{Package} |
|---|
| 569 | object. |
|---|
| 570 | \item The Lisp dynamic environment may be saved via |
|---|
| 571 | \code{LispThread.bindSpecial(Binding)} and restored via |
|---|
| 572 | \code{LispThread.resetSpecialBindings(Mark)}. |
|---|
| 573 | \item Functions can be executed by invoking \code{LispObject.execute(args |
|---|
| 574 | [...])} |
|---|
| 575 | \end{itemize} |
|---|
| 576 | |
|---|
| 577 | \subsection{Calling Lisp from Java} |
|---|
| 578 | \label{section:calling-lisp-from-java} |
|---|
| 579 | |
|---|
| 580 | Note: the entire \textsc{ABCL} \textsc{Lisp} system implementation in |
|---|
| 581 | \textsc{Java} is resident in the \texttt{org.armedbear.lisp} package, |
|---|
| 582 | but the following code snippets do not show the relevant import |
|---|
| 583 | statements in the interest of brevity. An example of the import |
|---|
| 584 | statement would be |
|---|
| 585 | \begin{listing-java} |
|---|
| 586 | import org.armedbear.lisp.*; |
|---|
| 587 | \end{listing-java} |
|---|
| 588 | to potentially import all the JVM symbol from the \code{org.armedbear.lisp} |
|---|
| 589 | namespace. |
|---|
| 590 | |
|---|
| 591 | There can only ever be a single Lisp interpreter per \textsc{JVM} instance. A |
|---|
| 592 | reference to this interpreter is obtained by calling the static method |
|---|
| 593 | \code{Interpreter.createInstance()}. |
|---|
| 594 | |
|---|
| 595 | \begin{listing-java} |
|---|
| 596 | Interpreter interpreter = Interpreter.createInstance(); |
|---|
| 597 | \end{listing-java} |
|---|
| 598 | |
|---|
| 599 | If this method has already been invoked in the lifetime of the current |
|---|
| 600 | Java process it will return \texttt{null}, so if you are writing \textsc{Java} |
|---|
| 601 | whose life-cycle is a bit out of your control (like in a \textsc{Java} servlet), |
|---|
| 602 | a safer invocation pattern might be: |
|---|
| 603 | |
|---|
| 604 | \begin{listing-java} |
|---|
| 605 | Interpreter interpreter = Interpreter.getInstance(); |
|---|
| 606 | if (interpreter == null) { |
|---|
| 607 | interpreter = Interpreter.createInstance(); |
|---|
| 608 | } |
|---|
| 609 | \end{listing-java} |
|---|
| 610 | |
|---|
| 611 | |
|---|
| 612 | The Lisp \code{eval} primitive may simply be passed strings for evaluation: |
|---|
| 613 | |
|---|
| 614 | \begin{listing-java} |
|---|
| 615 | String line = "(load \"file.lisp\")"; |
|---|
| 616 | LispObject result = interpreter.eval(line); |
|---|
| 617 | \end{listing-java} |
|---|
| 618 | |
|---|
| 619 | Notice that all possible return values from an arbitrary Lisp |
|---|
| 620 | computation are collapsed into a single return value. Doing useful |
|---|
| 621 | further computation on the \code{LispObject} depends on knowing what the |
|---|
| 622 | result of the computation might be. This usually involves some amount |
|---|
| 623 | of \code{instanceof} introspection, and forms a whole topic to itself |
|---|
| 624 | (see Section~\ref{topic:Introspecting a LispObject}, |
|---|
| 625 | page~\pageref{topic:Introspecting a LispObject}). |
|---|
| 626 | |
|---|
| 627 | Using \code{eval} involves the Lisp interpreter. Lisp functions may |
|---|
| 628 | also be directly invoked by Java method calls as follows. One simply |
|---|
| 629 | locates the package containing the symbol, obtains a reference to the |
|---|
| 630 | symbol, and then invokes the \code{execute()} method with the desired |
|---|
| 631 | parameters. |
|---|
| 632 | |
|---|
| 633 | \begin{listing-java} |
|---|
| 634 | interpreter.eval("(defun foo (msg)" + |
|---|
| 635 | "(format nil \"You told me '~A'~%\" msg))"); |
|---|
| 636 | Package pkg = Packages.findPackage("CL-USER"); |
|---|
| 637 | Symbol foo = pkg.findAccessibleSymbol("FOO"); |
|---|
| 638 | Function fooFunction = (Function)foo.getSymbolFunction(); |
|---|
| 639 | JavaObject parameter = new JavaObject("Lisp is fun!"); |
|---|
| 640 | LispObject result = fooFunction.execute(parameter); |
|---|
| 641 | // How to get the "naked string value"? |
|---|
| 642 | System.out.println("The result was " + result.writeToString()); |
|---|
| 643 | \end{listing-java} |
|---|
| 644 | |
|---|
| 645 | If one is calling a function in the CL package, the syntax can become |
|---|
| 646 | considerably simpler. If we can locate the instance of definition in |
|---|
| 647 | the ABCL Java source, we can invoke the symbol directly. For instance, |
|---|
| 648 | to tell if a \code{LispObject} is (Lisp) \texttt{NIL}, we can invoke the |
|---|
| 649 | CL function \code{NULL} in the following way: |
|---|
| 650 | |
|---|
| 651 | |
|---|
| 652 | \begin{listing-java} |
|---|
| 653 | boolean nullp(LispObject object) { |
|---|
| 654 | LispObject result = Primitives.NULL.execute(object); |
|---|
| 655 | if (result == NIL) { |
|---|
| 656 | return false; |
|---|
| 657 | } |
|---|
| 658 | return true; |
|---|
| 659 | } |
|---|
| 660 | \end{listing-java} |
|---|
| 661 | |
|---|
| 662 | Note, that the symbol \code{nil} is explicitly named in the |
|---|
| 663 | \textsc{Java} namespace as \code{Symbol.NIL} but is always present in |
|---|
| 664 | the local namespace in its unadorned form for the convenience of the |
|---|
| 665 | User. |
|---|
| 666 | |
|---|
| 667 | \subsubsection{Multiple Values} |
|---|
| 668 | |
|---|
| 669 | After a call to a function that returns Lisp multiple values, the |
|---|
| 670 | values are associated with the executing \code{LispThread} until the |
|---|
| 671 | next call into Lisp. One may access the values object as a list of |
|---|
| 672 | \code{LispObject} instances via a call to \code{getValues()} on that |
|---|
| 673 | thread reference |
|---|
| 674 | as evidenced by the following code: |
|---|
| 675 | |
|---|
| 676 | \begin{listing-java} |
|---|
| 677 | |
|---|
| 678 | org.armedbear.lisp.Package cl = Packages.findPackage("CL"); |
|---|
| 679 | Symbol valuesSymbol = cl.findAccessibleSymbol("VALUES"); |
|---|
| 680 | LispObject[] valuesArgs = { |
|---|
| 681 | LispInteger.getInstance(1), LispInteger.getInstance(2) |
|---|
| 682 | }; |
|---|
| 683 | // equivalent to ``(values 1 2)'' |
|---|
| 684 | LispObject result = valuesSymbol.execute(valuesArgs); |
|---|
| 685 | LispObject[] values = LispThread.currentThread().getValues(); |
|---|
| 686 | for (LispObject value: values) { |
|---|
| 687 | System.out.println("value ==> " + value.printObject()); |
|---|
| 688 | } |
|---|
| 689 | \end{listing-java} |
|---|
| 690 | |
|---|
| 691 | \subsubsection{Introspecting a LispObject} |
|---|
| 692 | \label{topic:Introspecting a LispObject} |
|---|
| 693 | |
|---|
| 694 | We present various patterns for introspecting an arbitrary |
|---|
| 695 | \code{LispObject} which can hold the result of every Lisp evaluation |
|---|
| 696 | into semantics that Java can meaningfully deal with. |
|---|
| 697 | |
|---|
| 698 | \paragraph{LispObject as \code{boolean}} |
|---|
| 699 | |
|---|
| 700 | If the \code{LispObject} is to be interpreted as a generalized boolean |
|---|
| 701 | value, one can use \code{getBooleanValue()} to convert to Java: |
|---|
| 702 | |
|---|
| 703 | \begin{listing-java} |
|---|
| 704 | LispObject object = Symbol.NIL; |
|---|
| 705 | boolean javaValue = object.getBooleanValue(); |
|---|
| 706 | \end{listing-java} |
|---|
| 707 | |
|---|
| 708 | Since in Lisp any value other than \code{NIL} means "true", Java |
|---|
| 709 | equality can also be used, which is a bit easier to type and better in |
|---|
| 710 | terms of information it conveys to the compiler: |
|---|
| 711 | |
|---|
| 712 | \begin{listing-java} |
|---|
| 713 | boolean javaValue = (object != Symbol.NIL); |
|---|
| 714 | \end{listing-java} |
|---|
| 715 | |
|---|
| 716 | \paragraph{LispObject as a list} |
|---|
| 717 | |
|---|
| 718 | If \code{LispObject} is a list, it will have the type \code{Cons}. One |
|---|
| 719 | can then use the \code{copyToArray} method to make things a bit more |
|---|
| 720 | suitable for Java iteration. |
|---|
| 721 | |
|---|
| 722 | \begin{listing-java} |
|---|
| 723 | LispObject result = interpreter.eval("'(1 2 4 5)"); |
|---|
| 724 | if (result instanceof Cons) { |
|---|
| 725 | LispObject array[] = ((Cons)result.copyToArray()); |
|---|
| 726 | ... |
|---|
| 727 | } |
|---|
| 728 | \end{listing-java} |
|---|
| 729 | |
|---|
| 730 | A more Lispy way to iterate down a list is to use the \code{cdr()} access |
|---|
| 731 | function just as like one would traverse a list in Lisp:; |
|---|
| 732 | |
|---|
| 733 | \begin{listing-java} |
|---|
| 734 | LispObject result = interpreter.eval("'(1 2 4 5)"); |
|---|
| 735 | while (result != Symbol.NIL) { |
|---|
| 736 | doSomething(result.car()); |
|---|
| 737 | result = result.cdr(); |
|---|
| 738 | } |
|---|
| 739 | \end{listing-java} |
|---|
| 740 | |
|---|
| 741 | \section{Java Scripting API (JSR-223)} |
|---|
| 742 | \label{section:java-scripting-api} |
|---|
| 743 | |
|---|
| 744 | ABCL can be built with support for JSR-223~\cite{jsr-223}, which offers |
|---|
| 745 | a language-agnostic API to invoke other languages from Java. The binary |
|---|
| 746 | distribution download-able from ABCL's home page is built with JSR-223 |
|---|
| 747 | support. If you're building ABCL from source on a pre-1.6 JVM, you need |
|---|
| 748 | to have a JSR-223 implementation in your classpath (such as Apache |
|---|
| 749 | Commons BSF 3.x or greater) in order to build ABCL with JSR-223 support; |
|---|
| 750 | otherwise, this feature will not be built. |
|---|
| 751 | |
|---|
| 752 | This section describes the design decisions behind the ABCL JSR-223 |
|---|
| 753 | support. It is not a description of what JSR-223 is or a tutorial on |
|---|
| 754 | how to use it. See |
|---|
| 755 | \url{http://abcl.org/trac/browser/trunk/abcl/examples/jsr-223} |
|---|
| 756 | for example usage. |
|---|
| 757 | |
|---|
| 758 | \subsection{Conversions} |
|---|
| 759 | |
|---|
| 760 | In general, ABCL's implementation of the JSR-223 API performs implicit |
|---|
| 761 | conversion from Java objects to Lisp objects when invoking Lisp from |
|---|
| 762 | Java, and the opposite when returning values from Java to Lisp. This |
|---|
| 763 | potentially reduces coupling between user code and ABCL. To avoid such |
|---|
| 764 | conversions, wrap the relevant objects in \code{JavaObject} instances. |
|---|
| 765 | |
|---|
| 766 | \subsection{Implemented JSR-223 interfaces} |
|---|
| 767 | |
|---|
| 768 | JSR-223 defines three main interfaces, of which two (\code{Invocable} |
|---|
| 769 | and \code{Compilable}) are optional. ABCL implements all the three |
|---|
| 770 | interfaces - \code{ScriptEngine} and the two optional ones - almost |
|---|
| 771 | completely. While the JSR-223 API is not specific to a single scripting |
|---|
| 772 | language, it was designed with languages with a more or less Java-like |
|---|
| 773 | object model in mind: languages such as JavaScript, Python, Ruby, which |
|---|
| 774 | have a concept of "class" or "object" with "fields" and "methods". Lisp |
|---|
| 775 | is a bit different, so certain adaptations were made, and in one case a |
|---|
| 776 | method has been left unimplemented since it does not map at all to Lisp. |
|---|
| 777 | |
|---|
| 778 | \subsubsection{The ScriptEngine} |
|---|
| 779 | |
|---|
| 780 | The main interface defined by JSR-223, \code{javax.script.ScriptEngine}, |
|---|
| 781 | is implemented by the class |
|---|
| 782 | \code{org.armedbear.lisp.scripting.AbclScriptEngine}. \code{AbclScriptEngine} |
|---|
| 783 | is a singleton, reflecting the fact that ABCL is a singleton as |
|---|
| 784 | well. You can obtain an instance of \code{AbclScriptEngine} using the |
|---|
| 785 | \code{AbclScriptEngineFactory} or by using the service provider |
|---|
| 786 | mechanism through \code{ScriptEngineManager} (refer to the |
|---|
| 787 | \texttt{javax.script} documentation). |
|---|
| 788 | |
|---|
| 789 | \subsection{Start-up and configuration file} |
|---|
| 790 | |
|---|
| 791 | At start-up (i.e. when its constructor is invoked, as part of the |
|---|
| 792 | static initialization phase of \code{AbclScriptEngineFactory}) the |
|---|
| 793 | ABCL script engine attempts to load an "init file" from the classpath |
|---|
| 794 | (\texttt{/abcl-script-config.lisp}). If present, this file can be used |
|---|
| 795 | to customize the behavior of the engine, by setting a number of |
|---|
| 796 | variables in the \code{ABCL-SCRIPT} package. Here is a list of the |
|---|
| 797 | available variables: |
|---|
| 798 | |
|---|
| 799 | \begin{description} |
|---|
| 800 | \item[\texttt{*use-throwing-debugger*}] controls whether ABCL uses a |
|---|
| 801 | non-standard debugging hook function to throw a Java exception |
|---|
| 802 | instead of dropping into the debugger in case of unhandled error |
|---|
| 803 | conditions. |
|---|
| 804 | \begin{itemize} |
|---|
| 805 | \item Default value: \texttt{T} |
|---|
| 806 | \item Rationale: it is more convenient for Java programmers using |
|---|
| 807 | Lisp as a scripting language to have it return exceptions to Java |
|---|
| 808 | instead of handling them in the Lisp world. |
|---|
| 809 | \item Known Issues: the non-standard debugger hook has been reported |
|---|
| 810 | to misbehave in certain circumstances, so consider disabling it if |
|---|
| 811 | it doesn't work for you. |
|---|
| 812 | \end{itemize} |
|---|
| 813 | \item[\texttt{*launch-swank-at-startup*}] If true, Swank will be launched at |
|---|
| 814 | startup. See \texttt{*swank-dir*} and \texttt{*swank-port*}. |
|---|
| 815 | \begin{itemize} |
|---|
| 816 | \item Default value: \texttt{NIL} |
|---|
| 817 | \end{itemize} |
|---|
| 818 | \item[\texttt{*swank-dir*}] The directory where Swank is installed. Must be set |
|---|
| 819 | if \texttt{*launch-swank-at-startup*} is true. |
|---|
| 820 | \item[\texttt{*swank-port*}] The port where Swank will listen for |
|---|
| 821 | connections. Must be set if \texttt{*launch-swank-at-startup*} is |
|---|
| 822 | true. |
|---|
| 823 | \begin{itemize} |
|---|
| 824 | \item Default value: 4005 |
|---|
| 825 | \end{itemize} |
|---|
| 826 | \end{description} |
|---|
| 827 | |
|---|
| 828 | Additionally, at startup the AbclScriptEngine will \code{(require |
|---|
| 829 | 'asdf)} - in fact, it uses asdf to load Swank. |
|---|
| 830 | |
|---|
| 831 | \subsection{Evaluation} |
|---|
| 832 | |
|---|
| 833 | Code is read and evaluated in the package \code{ABCL-SCRIPT-USER}. This |
|---|
| 834 | packages \texttt{USE}s the \code{COMMON-LISP}, \code{JAVA} and |
|---|
| 835 | \code{ABCL-SCRIPT} packages. Future versions of the script engine might |
|---|
| 836 | make this default package configurable. The \code{CL:LOAD} function is |
|---|
| 837 | used under the hood for evaluating code, and thus the behavior of |
|---|
| 838 | \code{LOAD} is guaranteed. This allows, among other things, |
|---|
| 839 | \code{IN-PACKAGE} forms to change the package in which the loaded code |
|---|
| 840 | is read. |
|---|
| 841 | |
|---|
| 842 | It is possible to evaluate code in what JSR-223 calls a |
|---|
| 843 | ``ScriptContext'' (basically a flat environment of name$\rightarrow$value |
|---|
| 844 | pairs). This context is used to establish special bindings for all the |
|---|
| 845 | variables defined in it; since variable names are strings from Java's |
|---|
| 846 | point of view, they are first interned using \code{READ-FROM-STRING} with, as |
|---|
| 847 | usual, \code{ABCL-SCRIPT-USER} as the default package. Variables are declared |
|---|
| 848 | special because CL's \code{LOAD}, \code{EVAL} and \code{COMPILE} |
|---|
| 849 | functions work in a null lexical environment and would ignore |
|---|
| 850 | non-special bindings. |
|---|
| 851 | |
|---|
| 852 | Contrary to what the function \code{LOAD} does, evaluation of a series |
|---|
| 853 | of forms returns the value of the last form instead of T, so the |
|---|
| 854 | evaluation of short scripts does the Right Thing. |
|---|
| 855 | |
|---|
| 856 | \subsection{Compilation} |
|---|
| 857 | |
|---|
| 858 | \code{AbclScriptEngine} implements the \code{javax.script.Compilable} |
|---|
| 859 | interface. Currently it only supports compilation using temporary |
|---|
| 860 | files. Compiled code, returned as an instance of |
|---|
| 861 | \texttt{javax.script.CompiledScript}, is read, compiled and executed |
|---|
| 862 | by default in the \code{abcl-script-user} package, just like evaluated |
|---|
| 863 | code. In contrast to evaluated code, though, due to the way the |
|---|
| 864 | \textsc{ABCL} compiler works, compiled code contains no reference to |
|---|
| 865 | top-level self-evaluating objects (like numbers or strings). Thus, |
|---|
| 866 | when evaluated, a piece of compiled code will return the value of the |
|---|
| 867 | last non-self-evaluating form: for example the code |
|---|
| 868 | ``\code{(do-something) 42}'' will return 42 when interpreted, but will |
|---|
| 869 | return the result of (do-something) when compiled and later |
|---|
| 870 | evaluated. To ensure consistency of behavior between interpreted and |
|---|
| 871 | compiled code, make sure the last form is always a compound form - at |
|---|
| 872 | least \code{(identity some-literal-object)}. Note that this issue |
|---|
| 873 | should not matter in real code, where it is unlikely that a top-level |
|---|
| 874 | self-evaluating form will appear as the last form in a file (in fact, |
|---|
| 875 | the Common Lisp load function always returns \code{t} upon success; |
|---|
| 876 | with \textsc{JSR-223} this policy has been changed to make evaluation |
|---|
| 877 | of small code snippets work as intended). |
|---|
| 878 | |
|---|
| 879 | \subsection{Invocation of functions and methods} |
|---|
| 880 | |
|---|
| 881 | AbclScriptEngine implements the \code{javax.script.Invocable} |
|---|
| 882 | interface, which allows to directly call Lisp functions and methods, |
|---|
| 883 | and to obtain Lisp implementations of Java interfaces. This is only |
|---|
| 884 | partially possible with Lisp since it has functions, but not methods - |
|---|
| 885 | not in the traditional Object Oriented sense, at least, since Lisp methods are not |
|---|
| 886 | attached to objects but belong to generic functions. Thus, the method |
|---|
| 887 | \code{invokeMethod()} is not implemented and throws an |
|---|
| 888 | \texttt{UnsupportedOperationException} when called. The \code{invokeFunction()} |
|---|
| 889 | method should be used to call both regular and generic functions. |
|---|
| 890 | |
|---|
| 891 | \subsection{Implementation of Java interfaces in Lisp} |
|---|
| 892 | |
|---|
| 893 | ABCL can use the Java reflection-based proxy feature to implement Java |
|---|
| 894 | interfaces in Lisp. It has several built-in ways to implement an |
|---|
| 895 | interface, and supports definition of new ones. The |
|---|
| 896 | \code{JAVA:JMAKE-PROXY} generic function is used to make such |
|---|
| 897 | proxies. It has the following signature: |
|---|
| 898 | |
|---|
| 899 | \code{jmake-proxy interface implementation \&optional lisp-this ==> proxy} |
|---|
| 900 | |
|---|
| 901 | \code{interface} is a Java interface metaobject (e.g. obtained by |
|---|
| 902 | invoking \code{jclass}) or a string naming a Java |
|---|
| 903 | interface. \code{implementation} is the object used to implement the |
|---|
| 904 | interface - several built-in methods of jmake-proxy exist for various |
|---|
| 905 | types of implementations. \code{lisp-this} is an object passed to the |
|---|
| 906 | closures implementing the Lisp "methods" of the interface, and |
|---|
| 907 | defaults to \code{NIL}. |
|---|
| 908 | |
|---|
| 909 | The returned proxy is an instance of the interface, with methods |
|---|
| 910 | implemented with Lisp functions. |
|---|
| 911 | |
|---|
| 912 | Built-in interface-implementation types include: |
|---|
| 913 | |
|---|
| 914 | \begin{itemize} |
|---|
| 915 | \item a single Lisp function which, upon invocation of any method in |
|---|
| 916 | the interface, will be passed the method name, the Lisp-this object, |
|---|
| 917 | and all the parameters. Useful for interfaces with a single method, |
|---|
| 918 | or to implement custom interface-implementation strategies. |
|---|
| 919 | \item a hash-map of method-name $\rightarrow$ Lisp function mappings. Function |
|---|
| 920 | signature is \code{(lisp-this \&rest args)}. |
|---|
| 921 | \item a Lisp package. The name of the Java method to invoke is first |
|---|
| 922 | transformed in an idiomatic Lisp name (\code{javaMethodName} becomes |
|---|
| 923 | \code{JAVA-METHOD-NAME}) and a symbol with that name is searched in |
|---|
| 924 | the package. If it exists and is \code{FBOUND}, the corresponding function |
|---|
| 925 | will be called. Function signature is as the hash-table case. |
|---|
| 926 | \end{itemize} |
|---|
| 927 | |
|---|
| 928 | This functionality is exposed by the class \code{AbclScriptEngine} via |
|---|
| 929 | the two methods \code{getInterface(Class)} and |
|---|
| 930 | \code{getInterface(Object, Class)}. The former returns an interface |
|---|
| 931 | implemented with the current Lisp package, the latter allows the |
|---|
| 932 | programmer to pass an interface-implementation object which will in turn |
|---|
| 933 | be passed to the \code{jmake-proxy} generic function. |
|---|
| 934 | |
|---|
| 935 | |
|---|
| 936 | \section{Implementation Extension Dictionaries} |
|---|
| 937 | |
|---|
| 938 | As outlined by the \textsc{CLHS} \textsc{ANSI} conformance guidelines, |
|---|
| 939 | we document the extensions to the Armed Bear Common Lisp |
|---|
| 940 | implementation made accessible to the user by virtue of being an |
|---|
| 941 | exported symbol in the \code{java}, \code{threads}, or |
|---|
| 942 | \code{extensions} packages. Additional, higher-level information |
|---|
| 943 | about the extensions afforded by the implementation can be found in |
|---|
| 944 | \ref{chapter:beyond-ansi} on page \pageref{chapter:beyond-ansi}. |
|---|
| 945 | |
|---|
| 946 | \subsection{The JAVA Dictionary} |
|---|
| 947 | |
|---|
| 948 | The symbols exported from the the \code{JAVA} package constitute the |
|---|
| 949 | primary mechanism to interact with Java language constructs within the |
|---|
| 950 | hosting virtual machine. |
|---|
| 951 | |
|---|
| 952 | \subsubsection{Modifying the JVM CLASSPATH} |
|---|
| 953 | |
|---|
| 954 | The \code{JAVA:ADD-TO-CLASSPATH} generic functions allows one to add the |
|---|
| 955 | specified pathname or list of pathnames to the current classpath |
|---|
| 956 | used by \textsc{ABCL}, allowing the dynamic loading of \textsc{JVM} objects: |
|---|
| 957 | |
|---|
| 958 | \begin{listing-lisp} |
|---|
| 959 | CL-USER> (add-to-classpath "/path/to/some.jar") |
|---|
| 960 | \end{listing-lisp} |
|---|
| 961 | |
|---|
| 962 | N.b \code{ADD-TO-CLASSPATH} only affects the classloader used by \textsc{ABCL} |
|---|
| 963 | (the value of the special variable \code{JAVA:*CLASSLOADER*}. It has |
|---|
| 964 | no effect on \textsc{Java} code outside \textsc{ABCL}. |
|---|
| 965 | |
|---|
| 966 | \subsubsection{Creating a synthetic Java Class at Runtime} |
|---|
| 967 | |
|---|
| 968 | For details on the mechanism available to create a fully synthetic |
|---|
| 969 | Java class at runtime can be found in \code{JAVA:JNEW-RUNTIME-CLASS} |
|---|
| 970 | on \ref{JAVA:JNEW-RUNTIME-CLASS}. |
|---|
| 971 | |
|---|
| 972 | % include autogen docs for the JAVA package. |
|---|
| 973 | \include{java} |
|---|
| 974 | |
|---|
| 975 | \subsection{The THREADS Dictionary} |
|---|
| 976 | |
|---|
| 977 | The extensions for handling multi-threaded execution are collected in |
|---|
| 978 | the \code{THREADS} package. Most of the abstractions in Doug Lea's |
|---|
| 979 | excellent \code{java.util.concurrent} packages may be manipulated |
|---|
| 980 | directly via the JSS contrib to great effect \cite{lea-1998} |
|---|
| 981 | |
|---|
| 982 | \subsubsection{Threading Models} |
|---|
| 983 | \index{Threading Models} The interface afforded by |
|---|
| 984 | \code{threads:make-thread} constructs a thread according to the |
|---|
| 985 | current value of \code{THREADS:*THREADING-MODEL*}. Nominally such |
|---|
| 986 | threads are constructed under the the default \code{:NATIVE} value, by |
|---|
| 987 | which a thread of execution native to the underlying platform is |
|---|
| 988 | associated with each \code{LISP-THREAD}. When the value |
|---|
| 989 | \code{:VIRTUAL-THREADS} is present in \code{CL:*FEATURES*}, the user |
|---|
| 990 | may spawn the lighter weight virtual threads by setting |
|---|
| 991 | \code{THREADS:*THREADING-MODEL*} to \code{:VIRTUAL} before invoking |
|---|
| 992 | the \code{THREADS:MAKE-THREAD} interface\footnote{This facility is |
|---|
| 993 | made available at runtime in \textsc{openjdk19} and later when enabled |
|---|
| 994 | via the runtime \code{--enable-features} flag}. |
|---|
| 995 | |
|---|
| 996 | % include autogen docs for the THREADS package. |
|---|
| 997 | \include{threads} |
|---|
| 998 | |
|---|
| 999 | \subsection{The EXTENSIONS Dictionary} |
|---|
| 1000 | |
|---|
| 1001 | The symbols in the \code{extensions} package (often referenced by its |
|---|
| 1002 | shorter nickname \code{ext}) constitutes extensions to the |
|---|
| 1003 | \textsc{ANSI} standard that are potentially useful to the user. They |
|---|
| 1004 | include functions for manipulating network sockets, running external |
|---|
| 1005 | programs, registering object finalizers, constructing reference weakly |
|---|
| 1006 | held by the garbage collector and others. |
|---|
| 1007 | |
|---|
| 1008 | See \cite{RHODES2007} for a generic function interface to the native |
|---|
| 1009 | \textsc{JVM} contract for \code{java.util.List}. |
|---|
| 1010 | |
|---|
| 1011 | % include autogen docs for the EXTENSIONS package. |
|---|
| 1012 | \include{extensions} |
|---|
| 1013 | |
|---|
| 1014 | \chapter{Beyond ANSI} |
|---|
| 1015 | \label{chapter:beyond-ansi} |
|---|
| 1016 | |
|---|
| 1017 | Naturally, in striving to be a useful contemporary \textsc{Common |
|---|
| 1018 | Lisp} implementation, \textsc{ABCL} endeavors to include extensions |
|---|
| 1019 | beyond the ANSI specification which are either widely adopted or are |
|---|
| 1020 | especially useful in working with the hosting \textsc{JVM}. This |
|---|
| 1021 | chapter documents such extensions beyond ANSI conformation. |
|---|
| 1022 | |
|---|
| 1023 | \section{Compiler to Java Virtual Machine Bytecode} |
|---|
| 1024 | |
|---|
| 1025 | The \code{CL:COMPILE-FILE} interface emits a packed fasl \footnote{The |
|---|
| 1026 | term ``fasl'' is short for ``fast loader'', which in \textsc{Common |
|---|
| 1027 | Lisp} implementations refers} format whose \code{CL:PATHNAME} has |
|---|
| 1028 | the \code{TYPE} ``abcl''. Structurally, \textsc{ABCL}'s fasls are |
|---|
| 1029 | operating system neutral byte archives packaged in the zip compression |
|---|
| 1030 | format which contain artifacts whose loading \code{CL:LOAD} |
|---|
| 1031 | understands. Internally, our fasls contain a piece of Lisp that |
|---|
| 1032 | \code{CL:LOAD} interprets as instructions to load the Java classes |
|---|
| 1033 | emitted by the \textsc{ABCL} Lisp compiler. The classes emitted by |
|---|
| 1034 | the \textsc{ABCL} compiler have a JVM class file version of ``49.0''. |
|---|
| 1035 | |
|---|
| 1036 | % TODO check on what the compiler is currently emitting |
|---|
| 1037 | |
|---|
| 1038 | \subsection{Compiler Diagnostics} |
|---|
| 1039 | |
|---|
| 1040 | By default, the interface to the compiler does not signal warnings |
|---|
| 1041 | that result in its invocation, outputing diagnostics to the standard |
|---|
| 1042 | reporting stream. The generalized boolean |
|---|
| 1043 | \code{JVM:*RESIGNAL-COMPILER-WARNINGS*} provides the interface to |
|---|
| 1044 | enabling the compiler to signal all warnings. |
|---|
| 1045 | |
|---|
| 1046 | \subsection{Decompilation} |
|---|
| 1047 | |
|---|
| 1048 | \label{CL:DISASSEMBLE} |
|---|
| 1049 | Since \textsc{ABCL} compiles to JVM bytecode, the |
|---|
| 1050 | \code{CL:DISASSEMBLE} function provides introspection for the result |
|---|
| 1051 | of that compilation. By default the implementation attempts to find |
|---|
| 1052 | and use the \code{javap} command line tool shipped as part of the Java |
|---|
| 1053 | Development Kit to disassemble the results. Code for the use of |
|---|
| 1054 | additional JVM bytecode introspection tools is packaged as part of the |
|---|
| 1055 | ABCL-INTROSPECT contrib. After loading one of these tools via ASDF, |
|---|
| 1056 | the \code{SYS:CHOOSE-DISASSEMBLER} function can be used to select the |
|---|
| 1057 | tool used by \code{CL:DISASSEMBLE}. See |
|---|
| 1058 | \ref{abcl-introspect-disassemblers} |
|---|
| 1059 | on \pageref{abcl-introspect-disassemblers} for further details. |
|---|
| 1060 | |
|---|
| 1061 | \section{Pathname} |
|---|
| 1062 | \index{PATHNAME} |
|---|
| 1063 | |
|---|
| 1064 | \textsc{ABCL} extends its implementation of \textsc{ANSI} |
|---|
| 1065 | \code{PATHNAME} objects in order to allow read-only access to sources |
|---|
| 1066 | of bytes available via URIs \footnote{A \textsc{URI} is essentially a |
|---|
| 1067 | super-set of what is commonly understood as a \textsc{URL}. We |
|---|
| 1068 | sometimes use the term URL as shorthand in describing the URL |
|---|
| 1069 | Pathnames, even though the corresponding encoding is more akin to a |
|---|
| 1070 | URI as described in RFC3986 \cite{rfc3986}.} and to enable the |
|---|
| 1071 | addressing of arbitrarily recursive entries within \textsc{ZIP} |
|---|
| 1072 | archives. These implementation decisions are encapsulated by the |
|---|
| 1073 | specialization of \code{CL:PATHNAME} as the \code{EXT:URL-PATHNAME} |
|---|
| 1074 | and the \code{EXT:JAR-PATHNAME} types. |
|---|
| 1075 | |
|---|
| 1076 | % RDF description of type hierarchy |
|---|
| 1077 | % TODO Render via some LaTeX mode for graphviz? |
|---|
| 1078 | \begin{verbatim} |
|---|
| 1079 | @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . |
|---|
| 1080 | @prefix ext: <http://abcl.org/cl/package/extensions/> . |
|---|
| 1081 | @prefix cl: <http://abcl.org/cl/package/common-lisp/> . |
|---|
| 1082 | |
|---|
| 1083 | <ext:jar-pathname> rdfs:subClassOf <ext:url-pathname> . |
|---|
| 1084 | <ext:url-pathname> rdfs:subClassOf <cl:pathname> . |
|---|
| 1085 | <cl:logical-pathname> rdfs:subClassOf <cl:pathname> . |
|---|
| 1086 | \end{verbatim} |
|---|
| 1087 | |
|---|
| 1088 | The \code{EXT:URL-PATHAME} object utilizes the standard \textsc{JVM} |
|---|
| 1089 | implementation of \code{java.net.URL} to access resources named by the |
|---|
| 1090 | ``file'', ``http'', ``https'', ``jar'', and ``ftp'' schemes. |
|---|
| 1091 | Additional protocol handlers for other may be installed at runtime by |
|---|
| 1092 | having \textsc{JVM} symbols present in the |
|---|
| 1093 | \code{sun.net.protocol.dynamic}\footnote{See \cite{maso2000} for more |
|---|
| 1094 | details. \url{https://stackoverflow.com/questions/41784555/print-all-supported-url-schemes-in-java8} |
|---|
| 1095 | contains a more up-to-date description.} The namestring of a |
|---|
| 1096 | \code{EXT:URL-PATHNAME} object is equivalent to the string |
|---|
| 1097 | serialization of its representation encoded via the ``percent |
|---|
| 1098 | encoding'' rules of URIs\footnote{See |
|---|
| 1099 | \url{https://url.spec.whatwg.org/\#percent-encoded-bytes} for a |
|---|
| 1100 | description of this process.}. |
|---|
| 1101 | |
|---|
| 1102 | The \code{EXT:JAR-PATHNAME} extension utilizes the specialization of |
|---|
| 1103 | \code{EXT:URL-PATHNAME} to provide access to components of |
|---|
| 1104 | \textsc{ZIP} archives, of which the \textsc{JAR} (Java ARchive) format |
|---|
| 1105 | is a super-set. \footnote{JAR archive utilize the ZIP format for |
|---|
| 1106 | packing and compression adding procedures to add supporting metadata |
|---|
| 1107 | in a manifest which is standardized text file stored at a canonical |
|---|
| 1108 | location within the archive.} \textsc{JAR} archives are typically |
|---|
| 1109 | used to aggregate many Java class files and associated metadata and |
|---|
| 1110 | resources (text, images, etc.) into one file for distribution. |
|---|
| 1111 | \textsc{ABCL} is typically packaged as a \textsc{JAR} archive and |
|---|
| 1112 | emits its fasls as \textsc{ZIP} files. |
|---|
| 1113 | |
|---|
| 1114 | Both the \code{EXT:URL-PATHNAME} and \code{EXT:JAR-PATHNAME} |
|---|
| 1115 | specializations may be broadly used anywhere a \code{CL:PATHNAME} is |
|---|
| 1116 | accepted with the general caveat that stream obtained via |
|---|
| 1117 | \code{CL:OPEN} on either sub-type cannot be the target of write |
|---|
| 1118 | operations. |
|---|
| 1119 | |
|---|
| 1120 | \subsubsection{URL-PATHNAME} |
|---|
| 1121 | \label{EXTENSIONS:URL-PATHNAME} |
|---|
| 1122 | \index{URL-PATHNAME} |
|---|
| 1123 | |
|---|
| 1124 | A \code{URL-PATHNAME} denotes a source of bytes addressable by its |
|---|
| 1125 | corresponding namestring interpreted as a \textsc{URI}. |
|---|
| 1126 | |
|---|
| 1127 | A \code{EXT:URL-PATHNAME} always has a \code{HOST} component that is a |
|---|
| 1128 | property list. The values of the \code{HOST} property list are always |
|---|
| 1129 | character strings. The allowed keys have the following meanings: |
|---|
| 1130 | |
|---|
| 1131 | \begin{description} |
|---|
| 1132 | \item[:SCHEME] Scheme of URI ("http", "ftp", "bundle", etc.) |
|---|
| 1133 | \item[:AUTHORITY] Valid authority according to the URI scheme. For |
|---|
| 1134 | "http" this could be "example.org:8080". |
|---|
| 1135 | \item[:QUERY] The query of the \textsc{URI} |
|---|
| 1136 | \item[:FRAGMENT] The fragment portion of the \textsc{URI} |
|---|
| 1137 | \end{description} |
|---|
| 1138 | |
|---|
| 1139 | If the \textsc{:SCHEME} property is missing, it is assumed to be |
|---|
| 1140 | ``file'' denoting a reference to a file on the local file-system and |
|---|
| 1141 | will be normalized as such in any pathname subjected to |
|---|
| 1142 | \code{TRUENAME} resolution. |
|---|
| 1143 | |
|---|
| 1144 | In order to encapsulate the implementation decisions for these |
|---|
| 1145 | meanings, the following functions provide a SETF-able API for |
|---|
| 1146 | reading and writing such values: \code{URL-PATHNAME-QUERY}, |
|---|
| 1147 | \code{URL-PATHNAME-FRAGMENT}, \code{URL-PATHNAME-AUTHORITY}, and |
|---|
| 1148 | \code{URL-PATHNAME-SCHEME}. The specific sub-type of a Pathname may |
|---|
| 1149 | be determined with the predicates \code{PATHNAME-URL-P} and |
|---|
| 1150 | \code{PATHNAME-JAR-P}. |
|---|
| 1151 | |
|---|
| 1152 | \label{EXTENSIONS:URL-PATHNAME-SCHEME} |
|---|
| 1153 | \index{URL-PATHNAME-SCHEME} |
|---|
| 1154 | |
|---|
| 1155 | \label{EXTENSIONS:URL-PATHNAME-FRAGMENT} |
|---|
| 1156 | \index{URL-PATHNAME-FRAGMENT} |
|---|
| 1157 | |
|---|
| 1158 | \label{EXTENSIONS:URL-PATHNAME-AUTHORITY} |
|---|
| 1159 | \index{URL-PATHNAME-AUTHORITY} |
|---|
| 1160 | |
|---|
| 1161 | \label{EXTENSIONS:PATHNAME-URL-P} |
|---|
| 1162 | \index{PATHNAME-URL-P} |
|---|
| 1163 | |
|---|
| 1164 | \label{EXTENSIONS:URL-PATHNAME-QUERY} |
|---|
| 1165 | \index{URL-PATHNAME-QUERY} |
|---|
| 1166 | |
|---|
| 1167 | Any results of canonicalization procedures performed on a object of |
|---|
| 1168 | type \code{EXT:URL-PATHNAME} via local or network resolutions |
|---|
| 1169 | discarded between attempts (i.e. the implementation does not attempt |
|---|
| 1170 | to cache the results of current name resolution of the URI for |
|---|
| 1171 | underlying resource unless it is requested to be resolved.) Upon |
|---|
| 1172 | resolution, any canonicalization procedures followed in resolving the |
|---|
| 1173 | resource (e.g. following redirects) are discarded. Users may |
|---|
| 1174 | programatically initiate a new, local computation of the resolution of |
|---|
| 1175 | the resource by applying the \code{CL:TRUENAME} function to a |
|---|
| 1176 | \code{EXT:URL-PATHNAME} object. Depending on the reliability and |
|---|
| 1177 | properties of your local \textsc{REST} infrastructure, these results |
|---|
| 1178 | may not necessarily be idempotent over time\footnote {See |
|---|
| 1179 | \cite{uri-pathname} for the design and implementation notes for the |
|---|
| 1180 | technical details}. A future implementation may attempt to expose an |
|---|
| 1181 | API to observer/customize the content negotiation initiated during |
|---|
| 1182 | retrieval of the representation of a given resource, which is |
|---|
| 1183 | currently handled at the application level. |
|---|
| 1184 | |
|---|
| 1185 | The implementation of \code{EXT:URL-PATHNAME} allows the \textsc{ABCL} |
|---|
| 1186 | user to dynamically load code from the network. For example, |
|---|
| 1187 | \textsc{Quicklisp} (\cite{quicklisp}) may be completely installed from |
|---|
| 1188 | the \textsc{REPL} to download and execute the Quicklisp setup code via: |
|---|
| 1189 | |
|---|
| 1190 | \begin{listing-lisp} |
|---|
| 1191 | CL-USER> (load "https://beta.quicklisp.org/quicklisp.lisp") |
|---|
| 1192 | \end{listing-lisp} |
|---|
| 1193 | |
|---|
| 1194 | \label{section:jar-pathname} |
|---|
| 1195 | |
|---|
| 1196 | \subsubsection{JAR-PATHNAME} |
|---|
| 1197 | \label{section:JAR-PATHNAME} |
|---|
| 1198 | \index{JAR-PATHNAME} |
|---|
| 1199 | |
|---|
| 1200 | In \textsc{ABCL}, the \code{DEVICE} can be either a string either |
|---|
| 1201 | denoting a drive letter or a UNC mount under \textsc{DOS} or a list of |
|---|
| 1202 | one or more elements. If \code{DEVICE} is a list, it denotes a |
|---|
| 1203 | \code{EXT:JAR-PATHNAME}. |
|---|
| 1204 | |
|---|
| 1205 | The implementation extends the \textsc{ANSI} specification with |
|---|
| 1206 | \textsc{EXT:JAR-PATHNAME} by utilizing its \code{DEVICE} to contain a |
|---|
| 1207 | list of pathnames denoting the location of and relative address within |
|---|
| 1208 | a \textsc{ZIP} archive. The first member of this list will be a |
|---|
| 1209 | \code{EXT:URL-PATHNAME} designates the root source of bytes encoded |
|---|
| 1210 | via the \textsc{ZIP} compression algorithm. This reference can either |
|---|
| 1211 | be to a file located on the local file-system or as a remote source |
|---|
| 1212 | via an stream-oriented messaging protocol such as \textsc{https}. The |
|---|
| 1213 | remainder of the \code{DEVICE} list contains ``traditional'' |
|---|
| 1214 | \code{CL:PATHNAME} objects denoting successive relative archive paths. |
|---|
| 1215 | This allows pathnames to reference an entry in an arbitrarily nested |
|---|
| 1216 | ZIP archives, which is the case when the an ABCL fasl is included in |
|---|
| 1217 | in a jar archive. |
|---|
| 1218 | |
|---|
| 1219 | In order to implement useful behavior of merging with pathname |
|---|
| 1220 | defaults, the implementation will contain the \code{:UNSPECIFIC} |
|---|
| 1221 | keyword in any TRUENAME that wasn't explicitly merging with a |
|---|
| 1222 | \code{EXT:JAR-PATHNAME}. Therefore, the implementation extends the |
|---|
| 1223 | semantics for the usual merge semantics when |
|---|
| 1224 | \code{*DEFAULT-PATHNAME-DEFAULTS*} contains a \code{EXT:JAR-PATHNAME} |
|---|
| 1225 | with the ``do what I mean'' algorithm described in |
|---|
| 1226 | \ref{section:conformance} on page \pageref{section:conformance}. |
|---|
| 1227 | |
|---|
| 1228 | The namestring representation of \code{EXT:JAR-PATHNAME} references |
|---|
| 1229 | use successive ``jar'' prefixes and corresponding ``!'' suffixes to |
|---|
| 1230 | encapsulate successive locations. Described broadly, a |
|---|
| 1231 | \code{EXT:JAR-PATHNAME} encapsulates the \textsc{URL} describing the |
|---|
| 1232 | location of the archive and a possible entry within that archive. |
|---|
| 1233 | |
|---|
| 1234 | \begin{verbatim} |
|---|
| 1235 | jar:<url>!/[<entry>] |
|---|
| 1236 | \end{verbatim} |
|---|
| 1237 | |
|---|
| 1238 | The \textsc{URL} usually has the ``file'' scheme, but remote locations |
|---|
| 1239 | expressed in the ``https'' or ``http'' are also allowed. |
|---|
| 1240 | |
|---|
| 1241 | Subsequent entries within an archive are denoted via prefixing |
|---|
| 1242 | additional ``jar'' schemes and suffixing the associated path. |
|---|
| 1243 | \begin{verbatim} |
|---|
| 1244 | jar:jar:<url>!/<entry0>!/[<entry1>] |
|---|
| 1245 | jar:jar:jar:<url>!/<entry0>!/<entry1>!/[<entry2>] |
|---|
| 1246 | \end{verbatim} |
|---|
| 1247 | |
|---|
| 1248 | |
|---|
| 1249 | \section{Package-Local Nicknames} |
|---|
| 1250 | \label{section:package-local-nicknames} |
|---|
| 1251 | |
|---|
| 1252 | ABCL allows giving packages local nicknames which allow short and |
|---|
| 1253 | easy-to-use names to be used without fear of name conflict associated |
|---|
| 1254 | with normal nicknames.\footnote{Package-local nicknames were |
|---|
| 1255 | originally developed in SBCL.} |
|---|
| 1256 | |
|---|
| 1257 | A local nickname is valid only when inside the package for which it |
|---|
| 1258 | has been specified. Different packages can use same local nickname for |
|---|
| 1259 | different global names, or different local nickname for same global |
|---|
| 1260 | name. |
|---|
| 1261 | |
|---|
| 1262 | Symbol \code{:package-local-nicknames} in \code{*features*} denotes the |
|---|
| 1263 | support for this feature. |
|---|
| 1264 | |
|---|
| 1265 | \index{DEFPACKAGE} |
|---|
| 1266 | The options to \code{defpackage} are extended with a new option |
|---|
| 1267 | \code{:local-nicknames (local-nickname actual-package-name)*}. |
|---|
| 1268 | |
|---|
| 1269 | The new package has the specified local nicknames for the corresponding |
|---|
| 1270 | actual packages. |
|---|
| 1271 | |
|---|
| 1272 | Example: |
|---|
| 1273 | \begin{listing-lisp} |
|---|
| 1274 | (defpackage :bar (:intern "X")) |
|---|
| 1275 | (defpackage :foo (:intern "X")) |
|---|
| 1276 | (defpackage :quux (:use :cl) |
|---|
| 1277 | (:local-nicknames (:bar :foo) (:foo :bar))) |
|---|
| 1278 | (find-symbol "X" :foo) ; => FOO::X |
|---|
| 1279 | (find-symbol "X" :bar) ; => BAR::X |
|---|
| 1280 | (let ((*package* (find-package :quux))) |
|---|
| 1281 | (find-symbol "X" :foo)) ; => BAR::X |
|---|
| 1282 | (let ((*package* (find-package :quux))) |
|---|
| 1283 | (find-symbol "X" :bar)) ; => FOO::X |
|---|
| 1284 | \end{listing-lisp} |
|---|
| 1285 | |
|---|
| 1286 | \index{PACKAGE-LOCAL-NICKNAMES} |
|---|
| 1287 | --- Function: \textbf{package-local-nicknames} [\textbf{ext}] \textit{package-designator} |
|---|
| 1288 | |
|---|
| 1289 | \begin{adjustwidth}{5em}{5em} |
|---|
| 1290 | Returns an ALIST of \code{(local-nickname . actual-package)} |
|---|
| 1291 | describing the nicknames local to the designated package. |
|---|
| 1292 | |
|---|
| 1293 | When in the designated package, calls to \code{find-package} with any |
|---|
| 1294 | of the local-nicknames will return the corresponding actual-package |
|---|
| 1295 | instead. This also affects all implied calls to \code{find-package}, |
|---|
| 1296 | including those performed by the reader. |
|---|
| 1297 | |
|---|
| 1298 | When printing a package prefix for a symbol with a package local |
|---|
| 1299 | nickname, the local nickname is used instead of the real name in order |
|---|
| 1300 | to preserve print-read consistency. |
|---|
| 1301 | \end{adjustwidth} |
|---|
| 1302 | |
|---|
| 1303 | \index{PACKAGE-LOCALLY-NICKNAMED-BY-LIST} |
|---|
| 1304 | --- Function: \textbf{package-locally-nicknamed-by-list} [\textbf{ext}] \textit{package-designator} |
|---|
| 1305 | |
|---|
| 1306 | \begin{adjustwidth}{5em}{5em} |
|---|
| 1307 | Returns a list of packages which have a local nickname for the |
|---|
| 1308 | designated package. |
|---|
| 1309 | \end{adjustwidth} |
|---|
| 1310 | |
|---|
| 1311 | \index{ADD-PACKAGE-LOCAL-NICKNAME} |
|---|
| 1312 | --- Function: \textbf{add-package-local-nickname} [\textbf{ext}] \textit{local-nickname actual-package \&optional package-designator} |
|---|
| 1313 | |
|---|
| 1314 | \begin{adjustwidth}{5em}{5em} |
|---|
| 1315 | Adds \code{local-nickname} for \code{actual-package} in the designated |
|---|
| 1316 | package, defaulting to current package. \code{local-nickname} must be |
|---|
| 1317 | a string designator, and \code{actual-package} must be a package |
|---|
| 1318 | designator. |
|---|
| 1319 | |
|---|
| 1320 | Returns the designated package. |
|---|
| 1321 | |
|---|
| 1322 | Signals an error if \code{local-nickname} is already a package local |
|---|
| 1323 | nickname for a different package, or if \code{local-nickname} is one |
|---|
| 1324 | of "CL", "COMMON-LISP", or, "KEYWORD", or if \code{local-nickname} is |
|---|
| 1325 | a global name or nickname for the package to which the nickname would |
|---|
| 1326 | be added. |
|---|
| 1327 | |
|---|
| 1328 | When in the designated package, calls to \code{find-package} with the |
|---|
| 1329 | \code{local-nickname} will return the package the designated |
|---|
| 1330 | \code{actual-package} instead. This also affects all implied calls to |
|---|
| 1331 | \code{find-package}, including those performed by the reader. |
|---|
| 1332 | |
|---|
| 1333 | When printing a package prefix for a symbol with a package local |
|---|
| 1334 | nickname, local nickname is used instead of the real name in order to |
|---|
| 1335 | preserve print-read consistency. |
|---|
| 1336 | \end{adjustwidth} |
|---|
| 1337 | |
|---|
| 1338 | \index{REMOVE-PACKAGE-LOCAL-NICKNAME} |
|---|
| 1339 | --- Function: \textbf{remove-package-local-nickname} [\textbf{ext}] \textit{old-nickname \&optional package-designator} |
|---|
| 1340 | |
|---|
| 1341 | \begin{adjustwidth}{5em}{5em} |
|---|
| 1342 | If the designated package had \code{old-nickname} as a local nickname |
|---|
| 1343 | for another package, it is removed. Returns true if the nickname |
|---|
| 1344 | existed and was removed, and \code{nil} otherwise. |
|---|
| 1345 | \end{adjustwidth} |
|---|
| 1346 | |
|---|
| 1347 | \section{Extensible Sequences} |
|---|
| 1348 | |
|---|
| 1349 | The SEQUENCE package fully implements Christopher Rhodes' proposal for |
|---|
| 1350 | extensible sequences. These user extensible sequences are used |
|---|
| 1351 | directly in \code{java-collections.lisp} provide these CLOS |
|---|
| 1352 | abstractions on the standard Java collection classes as defined by the |
|---|
| 1353 | \code{java.util.List} contract. |
|---|
| 1354 | |
|---|
| 1355 | %% an Example of using java.util.Lisp in Lisp would be nice |
|---|
| 1356 | |
|---|
| 1357 | This extension is not automatically loaded by the implementation. It |
|---|
| 1358 | may be loaded via: |
|---|
| 1359 | |
|---|
| 1360 | \begin{listing-lisp} |
|---|
| 1361 | CL-USER> (require :java-collections) |
|---|
| 1362 | \end{listing-lisp} |
|---|
| 1363 | |
|---|
| 1364 | if both extensible sequences and their application to Java collections |
|---|
| 1365 | is required, or |
|---|
| 1366 | |
|---|
| 1367 | \begin{listing-lisp} |
|---|
| 1368 | CL-USER> (require :extensible-sequences) |
|---|
| 1369 | \end{listing-lisp} |
|---|
| 1370 | |
|---|
| 1371 | if only the extensible sequences API as specified in \cite{RHODES2007} is |
|---|
| 1372 | required. |
|---|
| 1373 | |
|---|
| 1374 | Note that \code{(require :java-collections)} must be issued before |
|---|
| 1375 | \code{java.util.List} or any subclass is used as a specializer in a \textsc{CLOS} |
|---|
| 1376 | method definition (see the section below). |
|---|
| 1377 | |
|---|
| 1378 | See Rhodes2007 \cite{RHODES2007} for the an overview of the |
|---|
| 1379 | abstractions of the \code{java.util.collection} package afforded by |
|---|
| 1380 | \code{JAVA-COLLECTIONS}. |
|---|
| 1381 | |
|---|
| 1382 | \section{Extensions to CLOS} |
|---|
| 1383 | |
|---|
| 1384 | \subsection{Metaobject Protocol} |
|---|
| 1385 | |
|---|
| 1386 | \textsc{ABCL} implements the metaobject protocol for \textsc{CLOS} as |
|---|
| 1387 | specified in \textsc{(A)MOP}. The symbols are exported from the |
|---|
| 1388 | package \code{MOP}. |
|---|
| 1389 | |
|---|
| 1390 | Contrary to the AMOP specification and following \textsc{SBCL}'s lead, |
|---|
| 1391 | the metaclass \code{funcallable-standard-object} has |
|---|
| 1392 | \code{funcallable-standard-class} as metaclass instead of |
|---|
| 1393 | \code{standard-class}. |
|---|
| 1394 | |
|---|
| 1395 | \textsc{ABCL}'s fidelity to the AMOP specification is codified as part |
|---|
| 1396 | of Pascal Costanza's \code{closer-mop} \ref{closer-mop} \cite{closer-mop}. |
|---|
| 1397 | |
|---|
| 1398 | \subsection{Specializing on Java classes} |
|---|
| 1399 | |
|---|
| 1400 | There is an additional syntax for specializing the parameter of a |
|---|
| 1401 | generic function on a java class, viz. \code{(java:jclass |
|---|
| 1402 | CLASS-STRING)} where \code{CLASS-STRING} is a string naming a Java |
|---|
| 1403 | class in dotted package form. |
|---|
| 1404 | |
|---|
| 1405 | For instance the following specialization would perhaps allow one to |
|---|
| 1406 | print more information about the contents of a \code{java.util.Collection} |
|---|
| 1407 | object |
|---|
| 1408 | |
|---|
| 1409 | \begin{listing-lisp} |
|---|
| 1410 | (defmethod print-object ((coll (java:jclass "java.util.Collection")) |
|---|
| 1411 | stream) |
|---|
| 1412 | ;;; ... |
|---|
| 1413 | ) |
|---|
| 1414 | \end{listing-lisp} |
|---|
| 1415 | |
|---|
| 1416 | If the class had been loaded via a classloader other than the original |
|---|
| 1417 | the class you wish to specialize on, one needs to specify the |
|---|
| 1418 | classloader as an optional third argument. |
|---|
| 1419 | |
|---|
| 1420 | \begin{listing-lisp} |
|---|
| 1421 | |
|---|
| 1422 | (defparameter *other-classloader* |
|---|
| 1423 | (jcall "getBaseLoader" cl-user::*classpath-manager*)) |
|---|
| 1424 | |
|---|
| 1425 | (defmethod print-object |
|---|
| 1426 | ((device-id (java:jclass "dto.nbi.service.hdm.alcatel.com.NBIDeviceID" |
|---|
| 1427 | *other-classloader*)) |
|---|
| 1428 | stream) |
|---|
| 1429 | ;;; ... |
|---|
| 1430 | ) |
|---|
| 1431 | \end{listing-lisp} |
|---|
| 1432 | |
|---|
| 1433 | \subsection{Subtypes of \code{mop:specializer}} |
|---|
| 1434 | |
|---|
| 1435 | The implementation allows generic method specializers which extend the |
|---|
| 1436 | \code{mop:specializer} type. See \cite{custom-specializers} for |
|---|
| 1437 | justification and usage examples for such an abstraction. |
|---|
| 1438 | |
|---|
| 1439 | \section{Extensions to the Reader} |
|---|
| 1440 | |
|---|
| 1441 | We implement a special hexadecimal escape sequence for specifying 32 |
|---|
| 1442 | bit characters to the Lisp reader\footnote{This represents a |
|---|
| 1443 | compromise with contemporary in 2011 32bit hosting architectures for |
|---|
| 1444 | which we wish to make text processing efficient. Should the User |
|---|
| 1445 | require more control over \textsc{UNICODE} processing we recommend Edi Weisz' |
|---|
| 1446 | excellent work with \textsc|{FLEXI-STREAMS} which we fully support}, namely we |
|---|
| 1447 | allow a sequences of the form \verb~#\U~\emph{\texttt{xxxx}} to be processed |
|---|
| 1448 | by the reader as character whose code is specified by the hexadecimal |
|---|
| 1449 | digits \emph{\texttt{xxxx}}. The hexadecimal sequence may be one to four digits |
|---|
| 1450 | long. |
|---|
| 1451 | |
|---|
| 1452 | % Why doesn't ALEXANDRIA work? Good question: Alexandria from |
|---|
| 1453 | % Quicklisp 2010-10-07 fails a number of tests: |
|---|
| 1454 | %% Form: (ALEXANDRIA.0.DEV:TYPE= 'LIST '(OR NULL CONS)) |
|---|
| 1455 | %% Expected values: T |
|---|
| 1456 | %% T |
|---|
| 1457 | %% Actual values: NIL |
|---|
| 1458 | %% T. |
|---|
| 1459 | %% Test ALEXANDRIA-TESTS::TYPE=.3 failed |
|---|
| 1460 | %% Form: (ALEXANDRIA.0.DEV:TYPE= 'NULL '(AND SYMBOL LIST)) |
|---|
| 1461 | %% Expected values: T |
|---|
| 1462 | %% T |
|---|
| 1463 | %% Actual values: NIL |
|---|
| 1464 | %% NIL. |
|---|
| 1465 | |
|---|
| 1466 | |
|---|
| 1467 | Note that that the reader escaped sequence is never output by the |
|---|
| 1468 | implementation. Instead, the implementation emits the bytes |
|---|
| 1469 | corresponding Unicode character is output for characters whose code is |
|---|
| 1470 | greater than \code{0x00ff}. |
|---|
| 1471 | |
|---|
| 1472 | \section{Overloading of the CL:REQUIRE Mechanism} |
|---|
| 1473 | |
|---|
| 1474 | The \code{CL:REQUIRE} mechanism is overloaded by attaching the |
|---|
| 1475 | following behavior to the execution of \code{REQUIRE} on these symbols: |
|---|
| 1476 | |
|---|
| 1477 | \begin{description}[style=nextline] |
|---|
| 1478 | |
|---|
| 1479 | \item[\code{ASDF}] Loads the \textsc{ASDF} version shipped with the |
|---|
| 1480 | implementation. After the evaluation of this symbols, symbols |
|---|
| 1481 | passed to \code{CL:REQUIRE} which are otherwise unresolved, are |
|---|
| 1482 | passed to ASDF for a chance for resolution. This means, for |
|---|
| 1483 | instance if \code{CL-PPCRE} can be located as a loadable |
|---|
| 1484 | \textsc{ASDF} system \code{(require :cl-ppcre)} is equivalent to |
|---|
| 1485 | \code{(asdf:load-system :cl-ppcre)}. |
|---|
| 1486 | |
|---|
| 1487 | \item[\code{ABCL-CONTRIB}] Locates and pushes the top-level contents |
|---|
| 1488 | of ``abcl-contrib.jar'' into the \textsc{ASDF} central registry. |
|---|
| 1489 | |
|---|
| 1490 | \begin{description}[style=nextline] |
|---|
| 1491 | |
|---|
| 1492 | \item[\code{abcl-asdf}] Functions for loading \textsc{JVM} |
|---|
| 1493 | artifacts dynamically by extending \textsc{ASDF}. See |
|---|
| 1494 | \ref{section:abcl-asdf} on page \pageref{section:abcl-asdf}. |
|---|
| 1495 | |
|---|
| 1496 | \item[\code{asdf-jar}] Package addressable \textsc{JVM} artifacts via |
|---|
| 1497 | \code{abcl-asdf} descriptions as a single binary artifact |
|---|
| 1498 | including recursive dependencies. See \ref{sec:asdf-jar} on |
|---|
| 1499 | page \pageref{section:asdf-jar}. |
|---|
| 1500 | |
|---|
| 1501 | \item[\code{jna}] Allows the Java Native Interface |
|---|
| 1502 | (\textsc{JNI}) facility to provide C-style linkage to other |
|---|
| 1503 | operating system shared objects by dynamically loading the |
|---|
| 1504 | 'jna.jar' artifact via Maven\footnote{This loading can be |
|---|
| 1505 | inhibited if, at runtime, the Java class corresponding |
|---|
| 1506 | ``:classname'' clause of the system definition is present.} |
|---|
| 1507 | |
|---|
| 1508 | \item[\code{quicklisp-abcl}] Loads \textsc{Quicklisp} by |
|---|
| 1509 | possibly initiating a network download via |
|---|
| 1510 | \code{EXT:URL-PATHMAME}. |
|---|
| 1511 | |
|---|
| 1512 | \item[\code{jfli}] A descendant of Rich Hickey's pre-Clojure |
|---|
| 1513 | work on the JVM. |
|---|
| 1514 | |
|---|
| 1515 | \item[\code{jss}] Introduces dynamic inspection of present |
|---|
| 1516 | symbols via the \code{SHARPSIGN-QUOTATION\_MARK} macros as |
|---|
| 1517 | Java Syntax Sucks. See \ref{section:jss} on page |
|---|
| 1518 | \pageref{sections:jss} for more details. |
|---|
| 1519 | |
|---|
| 1520 | \item[\code{abcl-introspect}] Provides a framework for |
|---|
| 1521 | introspecting runtime Java and Lisp object values. Include |
|---|
| 1522 | packaging for installing and using java decompilation tools |
|---|
| 1523 | for use with \code{CL:DISASSEMBLE}. See |
|---|
| 1524 | \ref{section:abcl-introspect} on |
|---|
| 1525 | \pageref{section:abcl-introspect} for further information. |
|---|
| 1526 | |
|---|
| 1527 | \item[\code{abcl-build}] Provides a toolkit for building ABCL |
|---|
| 1528 | from source, as well as installing the necessary tools for |
|---|
| 1529 | such builds. See \ref{section:abcl-build} on page |
|---|
| 1530 | \pageref{section:abcl-build}. |
|---|
| 1531 | |
|---|
| 1532 | \item[\code{named-readtables}] Provides a namespace for |
|---|
| 1533 | readtables akin to the already-existing namespace of packages. |
|---|
| 1534 | See \ref{section:named-readtables} on |
|---|
| 1535 | \pageref{section:named-readtables} for further information. |
|---|
| 1536 | |
|---|
| 1537 | \item[\code{posix-syscalls}] Provides and demonstrates the |
|---|
| 1538 | scaffolding for extending the implementation by use of direct |
|---|
| 1539 | syscalls via the foreign function interface (FFI) afforded by |
|---|
| 1540 | the JNA library. Upon loading this system, new implementations |
|---|
| 1541 | of the \code{EXT:GETENV} and \code{UIOP/OS:GETENV} functions are |
|---|
| 1542 | installed which use FFI to directly call the \sc{posix} syscalls |
|---|
| 1543 | where available, which allows environment variables to be set. |
|---|
| 1544 | \index{POSIX-SYSCALLS} |
|---|
| 1545 | |
|---|
| 1546 | \end{description} |
|---|
| 1547 | \end{description} |
|---|
| 1548 | |
|---|
| 1549 | The user may extend the \code{CL:REQUIRE} mechanism by pushing |
|---|
| 1550 | function hooks into \code{SYSTEM:*MODULE-PROVIDER-FUNCTIONS*}. Each |
|---|
| 1551 | such hook function takes a single argument containing the symbol |
|---|
| 1552 | passed to \code{CL:REQUIRE} and returns a non-\code{NIL} value if it |
|---|
| 1553 | can successful resolve the symbol. |
|---|
| 1554 | |
|---|
| 1555 | \section{JSS extension of the Reader by SHARPSIGN-DOUBLE-QUOTE} |
|---|
| 1556 | |
|---|
| 1557 | The JSS contrib constitutes an additional, optional extension to the |
|---|
| 1558 | reader in the definition of the \code{SHARPSIGN-DOUBLE-QUOTE} |
|---|
| 1559 | (``\#\"'') reader macro. See section \ref{section:jss} on page |
|---|
| 1560 | \pageref{section:jss} for more information. |
|---|
| 1561 | |
|---|
| 1562 | \section{ASDF} |
|---|
| 1563 | |
|---|
| 1564 | asdf-3.3.7 (see \cite{asdf}) is packaged as core component of |
|---|
| 1565 | \textsc{ABCL}, but not loaded by default, as it relies on the |
|---|
| 1566 | \textsc{CLOS} subsystem which can take a bit of time to |
|---|
| 1567 | start \footnote{While this time is ``merely'' on the order of seconds |
|---|
| 1568 | for contemporary 2011 machines, for applications that need to |
|---|
| 1569 | initialize quickly, for example a web server, this time might be |
|---|
| 1570 | unnecessarily long}. The packaged \textsc{ASDF} may be loaded by the |
|---|
| 1571 | \textsc{ANSI} \code{REQUIRE} mechanism as follows: |
|---|
| 1572 | |
|---|
| 1573 | \begin{listing-lisp} |
|---|
| 1574 | CL-USER> (require :asdf) |
|---|
| 1575 | \end{listing-lisp} |
|---|
| 1576 | |
|---|
| 1577 | \section{Extension to CL:MAKE-ARRAY} |
|---|
| 1578 | \label{section:make-array} |
|---|
| 1579 | \index{MAKE-ARRAY} |
|---|
| 1580 | |
|---|
| 1581 | With the \code{:nio} feature is present\footnote{Available starting in |
|---|
| 1582 | the Eighth Edition (aka abcl-1.7.0) and indicated by the presence of |
|---|
| 1583 | \code{:nio} in \code{cl:*features*}}, the implementation adds two |
|---|
| 1584 | keyword arguments to \code{cl:make-array}, viz. \code{:nio-buffer} and |
|---|
| 1585 | \code{:nio-direct}. |
|---|
| 1586 | |
|---|
| 1587 | With the \code{:nio-buffer} keyword, the user is able to pass |
|---|
| 1588 | instances of of \code{java.nio.ByteBuffer} and its subclasses for the |
|---|
| 1589 | storage of vectors and arrays specialized on the byte-vector |
|---|
| 1590 | types satisfying |
|---|
| 1591 | |
|---|
| 1592 | \begin{listing-lisp} |
|---|
| 1593 | (or |
|---|
| 1594 | (unsigned-byte 8) |
|---|
| 1595 | (unsigned-byte 16) |
|---|
| 1596 | (unsigned-byte 32)) |
|---|
| 1597 | \end{listing-lisp} |
|---|
| 1598 | |
|---|
| 1599 | As an example, the following would use the \code{:nio-buffer} as |
|---|
| 1600 | follows to create a 16 byte vector using the created byte-buffer for |
|---|
| 1601 | storage: |
|---|
| 1602 | |
|---|
| 1603 | \begin{listing-lisp} |
|---|
| 1604 | (let* ((length 16) |
|---|
| 1605 | (byte-buffer (java:jstatic "allocate" "java.nio.ByteBuffer" length))) |
|---|
| 1606 | (make-array length :element-type '(unsigned-byte 8) :nio-buffer byte-buffer)) |
|---|
| 1607 | \end{listing-lisp} |
|---|
| 1608 | |
|---|
| 1609 | This feature is available in CFFI\footnote{Available at runtime via |
|---|
| 1610 | \textsc{Quicklisp}} via |
|---|
| 1611 | \code{CFFI-SYS:MAKE-SHAREABLE-BYTE-VECTOR}\footnote{Implemented in |
|---|
| 1612 | \url{https://github.com/cffi/cffi/commit/47136ad9a97c2df98dbcd13a068e14489ced5b03}} |
|---|
| 1613 | |
|---|
| 1614 | \begin{description}[style=nextline] |
|---|
| 1615 | |
|---|
| 1616 | \item[\code{:nio-buffer NIO-BUFFER}] |
|---|
| 1617 | |
|---|
| 1618 | Initializes the contents of the new vector or array with the contents |
|---|
| 1619 | of \code{NIO-BUFFER} which needs to be a reference to a |
|---|
| 1620 | \code{java-object} of class \code{java.nio.ByteBuffer}. |
|---|
| 1621 | |
|---|
| 1622 | \item[\code{:nio-direct NIO-DIRECT-P}] |
|---|
| 1623 | |
|---|
| 1624 | When \code{NIO-DIRECT-P} is non-\code{nil}, constructs a |
|---|
| 1625 | java.nio.Buffer as a ``direct'' buffer. The buffers returned by this |
|---|
| 1626 | method typically have somewhat higher allocation and deallocation |
|---|
| 1627 | costs than non-direct buffers. The contents of direct buffers may |
|---|
| 1628 | reside outside of the normal garbage-collected heap, and so their |
|---|
| 1629 | impact upon the memory footprint of an application might not be |
|---|
| 1630 | obvious. It is therefore recommended that direct buffers be allocated |
|---|
| 1631 | primarily for large, long-lived buffers that are subject to the |
|---|
| 1632 | underlying system's native I/O operations. In general it is best to |
|---|
| 1633 | allocate direct buffers only when they yield a measurable gain in |
|---|
| 1634 | program performance. |
|---|
| 1635 | |
|---|
| 1636 | \end{description} |
|---|
| 1637 | |
|---|
| 1638 | |
|---|
| 1639 | \chapter{Contrib} |
|---|
| 1640 | |
|---|
| 1641 | The \textsc{ABCL} contrib is packaged as a separate jar archive usually named |
|---|
| 1642 | \code{abcl-contrib.jar} or possibly something like |
|---|
| 1643 | \code{abcl-contrib-1.9.2.jar}. The contrib jar is not loaded by the |
|---|
| 1644 | implementation by default, and must be first initialized by the |
|---|
| 1645 | \code{REQUIRE} mechanism before using any specific contrib: |
|---|
| 1646 | |
|---|
| 1647 | \begin{listing-lisp} |
|---|
| 1648 | CL-USER> (require :abcl-contrib) |
|---|
| 1649 | \end{listing-lisp} |
|---|
| 1650 | |
|---|
| 1651 | \section{abcl-asdf} |
|---|
| 1652 | \label{section:abcl-asdf} |
|---|
| 1653 | \index{ABCL-ASDF} |
|---|
| 1654 | |
|---|
| 1655 | This contrib enables an additional syntax for \textsc{ASDF} system |
|---|
| 1656 | definition which dynamically loads \textsc{JVM} artifacts such as jar |
|---|
| 1657 | archives via encapsulation by the Maven build tool. The Maven Aether |
|---|
| 1658 | component can also be directly manipulated by the function associated |
|---|
| 1659 | with the \code{ABCL-ASDF:RESOLVE-DEPENDENCIES} symbol. |
|---|
| 1660 | |
|---|
| 1661 | %ABCL specific contributions to ASDF system definition mainly |
|---|
| 1662 | %concerned with finding JVM artifacts such as jar archives to be |
|---|
| 1663 | %dynamically loaded. |
|---|
| 1664 | |
|---|
| 1665 | |
|---|
| 1666 | When loaded, \textsc{ABCL-ASDF} adds the following objects to |
|---|
| 1667 | \textsc{ASDF}: \code{JAR-FILE}, \code{JAR-DIRECTORY}, |
|---|
| 1668 | \code{CLASS-FILE-DIRECTORY} and \code{MVN}, exporting them (and |
|---|
| 1669 | others) as public symbols. |
|---|
| 1670 | |
|---|
| 1671 | \subsection{Referencing Maven Artifacts via ASDF} |
|---|
| 1672 | |
|---|
| 1673 | Maven artifacts may be referenced within \textsc{ASDF} system |
|---|
| 1674 | definitions, as the following example references the |
|---|
| 1675 | \code{log4j-1.4.9.jar} JVM artifact which provides a widely-used |
|---|
| 1676 | abstraction for handling logging systems: |
|---|
| 1677 | |
|---|
| 1678 | \begin{listing-lisp} |
|---|
| 1679 | ;;;; -*- Mode: LISP -*- |
|---|
| 1680 | (require :asdf) |
|---|
| 1681 | (in-package :cl-user) |
|---|
| 1682 | |
|---|
| 1683 | (asdf:defsystem :log4j |
|---|
| 1684 | :defsystem-depends-on (abcl-asdf) |
|---|
| 1685 | :components ((:mvn "log4j/log4j" :version "1.4.9"))) |
|---|
| 1686 | \end{listing-lisp} |
|---|
| 1687 | |
|---|
| 1688 | \subsection{API} |
|---|
| 1689 | |
|---|
| 1690 | We define an API for \textsc{ABCL-ASDF} as consisting of the following |
|---|
| 1691 | \textsc{ASDF} classes: |
|---|
| 1692 | |
|---|
| 1693 | \code{JAR-DIRECTORY}, \code{JAR-FILE}, and |
|---|
| 1694 | \code{CLASS-FILE-DIRECTORY} for JVM artifacts that have a currently |
|---|
| 1695 | valid pathname representation. |
|---|
| 1696 | |
|---|
| 1697 | Both the \code{MVN} and \code{IRI} classes descend from |
|---|
| 1698 | \code{ASDF-COMPONENT}, but do not directly have a file-system location. |
|---|
| 1699 | |
|---|
| 1700 | For use outside of ASDF system definitions, we currently define one |
|---|
| 1701 | method, \code{ABCL-ASDF:RESOLVE-DEPENDENCIES} which locates, |
|---|
| 1702 | downloads, caches, and then loads into the currently executing JVM |
|---|
| 1703 | process all recursive dependencies annotated in the Maven |
|---|
| 1704 | \code{pom.xml} graph. |
|---|
| 1705 | |
|---|
| 1706 | \subsection{Directly Instructing Maven to Download JVM Artifacts} |
|---|
| 1707 | |
|---|
| 1708 | Bypassing \textsc{ASDF}, one can directly issue requests for the Maven |
|---|
| 1709 | artifacts to be downloaded |
|---|
| 1710 | |
|---|
| 1711 | \begin{listing-lisp} |
|---|
| 1712 | CL-USER> (abcl-asdf:resolve-dependencies "com.google.gwt" |
|---|
| 1713 | "gwt-user") |
|---|
| 1714 | WARNING: Using LATEST for unspecified version. |
|---|
| 1715 | "/Users/evenson/.m2/repository/com/google/gwt/gwt-user/2.9.0/gwt-user-2.9 |
|---|
| 1716 | .0.jar:/Users/evenson/.m2/repository/com/google/jsinterop/jsinterop-annot |
|---|
| 1717 | ations/2.0.0/jsinterop-annotations-2.0.0.jar:/Users/evenson/.m2/repositor |
|---|
| 1718 | y/javax/validation/validation-api/1.0.0.GA/validation-api-1.0.0.GA.jar:/U |
|---|
| 1719 | sers/evenson/.m2/repository/javax/validation/validation-api/1.0.0.GA/vali |
|---|
| 1720 | dation-api-1.0.0.GA-sources.jar:/Users/evenson/.m2/repository/javax/servl |
|---|
| 1721 | et/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar:/Users/evenson/.m2 |
|---|
| 1722 | /repository/org/w3c/css/sac/1.3/sac-1.3.jar" |
|---|
| 1723 | \end{listing-lisp} |
|---|
| 1724 | |
|---|
| 1725 | To actually load the dependency into the current process, use the |
|---|
| 1726 | \code{JAVA:ADD-TO-CLASSPATH} generic function: |
|---|
| 1727 | |
|---|
| 1728 | \begin{listing-lisp} |
|---|
| 1729 | CL-USER> (java:add-to-classpath |
|---|
| 1730 | (abcl-asdf:resolve-dependencies "com.google.gwt" |
|---|
| 1731 | "gwt-user")) |
|---|
| 1732 | \end{listing-lisp} |
|---|
| 1733 | |
|---|
| 1734 | Notice that all recursive dependencies have been located and installed |
|---|
| 1735 | locally from the network as well. |
|---|
| 1736 | |
|---|
| 1737 | More extensive documentations and examples can be found at |
|---|
| 1738 | \url{http://abcl.org/svn/tags/1.9.2/contrib/abcl-asdf/README.markdown}. |
|---|
| 1739 | |
|---|
| 1740 | \section{asdf-jar} |
|---|
| 1741 | \label{section:asdf-jar} |
|---|
| 1742 | \index{ASDF-JAR} |
|---|
| 1743 | |
|---|
| 1744 | The asdf-jar contrib provides a system for packaging \textsc{ASDF} |
|---|
| 1745 | systems into jar archives for \textsc{ABCL}. Given a running |
|---|
| 1746 | \textsc{ABCL} image with loadable \textsc{ASDF} systems the code in |
|---|
| 1747 | this package will recursively package all the required source and |
|---|
| 1748 | fasls in a jar archive. |
|---|
| 1749 | |
|---|
| 1750 | The documentation for this contrib can be found at |
|---|
| 1751 | \url{http://abcl.org/svn/tags/1.9.2/contrib/asdf-jar/README.markdown}. |
|---|
| 1752 | |
|---|
| 1753 | \section{jss} |
|---|
| 1754 | \label{section:jss} |
|---|
| 1755 | \index{JSS} |
|---|
| 1756 | |
|---|
| 1757 | To one used to the more universal syntax of s-expr pairs upon which |
|---|
| 1758 | the definition of read and compile time macros is quite |
|---|
| 1759 | natural \footnote{See Graham's ``On Lisp'' |
|---|
| 1760 | http://lib.store.yahoo.net/lib/paulgraham/onlisp.pdf.}, the syntax |
|---|
| 1761 | available to the \textsc{Java} programmer may be said to suck. To |
|---|
| 1762 | alleviate this situation, the \textsc{JSS} contrib introduces the |
|---|
| 1763 | \code{SHARPSIGN-DOUBLE-QUOTE} (\code{\#"}) reader macro, which allows |
|---|
| 1764 | the the specification of the name of invoking function as the first |
|---|
| 1765 | element of the relevant s-expr which tends to be more congruent to how |
|---|
| 1766 | Lisp programmers seem to be wired to think. |
|---|
| 1767 | |
|---|
| 1768 | While quite useful, we don't expect that the \textsc{JSS} contrib will |
|---|
| 1769 | be the last experiment in wrangling \textsc{Java} from \textsc{Common |
|---|
| 1770 | Lisp}. |
|---|
| 1771 | |
|---|
| 1772 | \subsection{JSS usage} |
|---|
| 1773 | |
|---|
| 1774 | An example of using \textsc{JSS} to enumerate the \textsc{Java} |
|---|
| 1775 | runtime system properties: |
|---|
| 1776 | |
|---|
| 1777 | \begin{listing-lisp} |
|---|
| 1778 | CL-USER> (require :abcl-contrib) |
|---|
| 1779 | ==> ("ABCL-CONTRIB") |
|---|
| 1780 | CL-USER> (require :jss) |
|---|
| 1781 | ==> ("JSS") |
|---|
| 1782 | CL-USER) (#"getProperties" 'java.lang.System) |
|---|
| 1783 | ==> #<java.util.Properties {java.runtime.name=Java.... {2FA21ACF}> |
|---|
| 1784 | CL-USER) (#"propertyNames" (#"getProperties" 'java.lang.System)) |
|---|
| 1785 | ==> #<java.util.Hashtable$Enumerator java.util.Has.... {36B4361A}> |
|---|
| 1786 | \end{listing-lisp} %$ <-- un-confuse Emacs font-lock |
|---|
| 1787 | |
|---|
| 1788 | Some more information on jss can be found in its documentation at |
|---|
| 1789 | \url{http://abcl.org/svn/tags/1.9.2/contrib/jss/README.markdown} |
|---|
| 1790 | |
|---|
| 1791 | \section{jfli} |
|---|
| 1792 | \label{section:jfli} |
|---|
| 1793 | |
|---|
| 1794 | The contrib contains a pure-Java version of \textsc{JFLI}, apparently |
|---|
| 1795 | a descendant of Rich Hickey's early experimentations with using Java |
|---|
| 1796 | from Common Lisp. |
|---|
| 1797 | |
|---|
| 1798 | \url{http://abcl.org/svn/tags/1.9.2/contrib/jfli/README}. |
|---|
| 1799 | |
|---|
| 1800 | \section{abcl-introspect} |
|---|
| 1801 | \label{section:abcl-introspect} |
|---|
| 1802 | \index{ABCL-INTROSPECT} |
|---|
| 1803 | |
|---|
| 1804 | \textsc{ABCL-INTROSPECT} offers more extensive functionality for |
|---|
| 1805 | inspecting the state of the implementation, most notably in |
|---|
| 1806 | integration with \textsc{SLIME}, where the backtrace mechanism is |
|---|
| 1807 | augmented to the point that local variables are inspectable. |
|---|
| 1808 | |
|---|
| 1809 | A compiled function is an instance of a class, which has multiple |
|---|
| 1810 | instances if it represents a closure, or a single instance if it |
|---|
| 1811 | represents a non-closed-over function. |
|---|
| 1812 | |
|---|
| 1813 | The \textsc{ABCL} compiler stores constants that are used in function |
|---|
| 1814 | execution as private java fields. This includes symbols used to invoke |
|---|
| 1815 | function, locally-defined functions (such as via \code{LABEL} or |
|---|
| 1816 | \code{flet}) and string and other literal objects. |
|---|
| 1817 | \textsc{ABCL-INTROSPECT} implements a ``do what I mean'' API for |
|---|
| 1818 | introspecting these constants. |
|---|
| 1819 | |
|---|
| 1820 | \textsc{ABCL-INTROSPECT} provides access to those internal values, and |
|---|
| 1821 | uses them in at least two ways. First, to annotate locally defined |
|---|
| 1822 | functions with the top-level function they are defined within, and |
|---|
| 1823 | second to search for callers of a given function \footnote{ Since \textsc{Java} |
|---|
| 1824 | functions are strings, local fields also have these strings. In the |
|---|
| 1825 | context of looking for callers of a function you can also give a |
|---|
| 1826 | string that names a java method. Same caveat re: false positives.} |
|---|
| 1827 | . This may yield some false positives, such as when a symbol that |
|---|
| 1828 | names a function is also used for some other purpose. It can also have |
|---|
| 1829 | false negatives, as when a function is inlined. Still, it's pretty |
|---|
| 1830 | useful. The second use to to find source locations for frames in the |
|---|
| 1831 | debugger. If the source location for a local function is asked for the |
|---|
| 1832 | location of its 'owner' is instead returns. |
|---|
| 1833 | |
|---|
| 1834 | In order to record information about local functions, \textsc{ABCL} |
|---|
| 1835 | defines a function-plist, which is for the most part unused, but is |
|---|
| 1836 | used here with set of keys indicating where the local function was |
|---|
| 1837 | defined and in what manner, i.e. as normal local function, as a method |
|---|
| 1838 | function, or as an initarg function. There may be other places |
|---|
| 1839 | functions are stashed away (defstructs come to mind) and this file |
|---|
| 1840 | should be added to to take them into account as they are discovered. |
|---|
| 1841 | |
|---|
| 1842 | \textsc{ABCL-INTROSPECT} does not depend on \textsc{JSS}, but provides |
|---|
| 1843 | a bit of jss-specific functionality if \textsc{JSS} *is* loaded. |
|---|
| 1844 | |
|---|
| 1845 | \subsection{Implementations for CL:DISASSEMBLE} |
|---|
| 1846 | \label{abcl-introspect-disassemblers} |
|---|
| 1847 | \index{CL:DISASSEMBLE} |
|---|
| 1848 | |
|---|
| 1849 | The following \textsc{ASDF} systems packages various external tools that may be |
|---|
| 1850 | selected by the \code{SYS:CHOOSE-DISASSEMBLER} interface: |
|---|
| 1851 | |
|---|
| 1852 | \begin{enumerate} |
|---|
| 1853 | \item \code{objectweb} |
|---|
| 1854 | \item \code{jad} |
|---|
| 1855 | \item \code{javap} |
|---|
| 1856 | \item \code{fernweb} |
|---|
| 1857 | \item \code{cfr} |
|---|
| 1858 | \item \code{procyon} |
|---|
| 1859 | \end{enumerate} |
|---|
| 1860 | |
|---|
| 1861 | To use one of these tools, first load the system via \textsc{ASDF} |
|---|
| 1862 | (and/or \textsc{Quicklisp}), then use the |
|---|
| 1863 | \code{SYS:CHOOSE-DISASSEMBLER} function to select the keyword that |
|---|
| 1864 | appears in \code{SYS:*DISASSEMBLERS*}. |
|---|
| 1865 | \begin{listing-lisp} |
|---|
| 1866 | CL-USER> (require :abcl-contrib)(asdf:load-system :objectweb) |
|---|
| 1867 | CL-USER> sys:*disassemblers* |
|---|
| 1868 | ((:OBJECTWEB |
|---|
| 1869 | . ABCL-INTROSPECT/JVM/TOOLS/OBJECTWEB:DISASSEMBLE-CLASS-BYTES) |
|---|
| 1870 | (:SYSTEM-JAVAP . SYSTEM:DISASSEMBLE-CLASS-BYTES)) |
|---|
| 1871 | CL-USER> (sys:choose-disassembler :objectweb) |
|---|
| 1872 | ABCL-INTROSPECT/JVM/TOOLS/OBJECTWEB:DISASSEMBLE-CLASS-BYTES |
|---|
| 1873 | CL-USER> (disassemble 'cons) |
|---|
| 1874 | ; // class version 52.0 (52) |
|---|
| 1875 | ; // access flags 0x30 |
|---|
| 1876 | ; final class org/armedbear/lisp/Primitives$pf_cons extends org/armedbear/lisp/Primitive { |
|---|
| 1877 | ; |
|---|
| 1878 | ; // access flags 0x1A |
|---|
| 1879 | ; private final static INNERCLASS org/armedbear/lisp/Primitives$pf_cons org/armedbear/lisp/Primitives pf_cons |
|---|
| 1880 | ; |
|---|
| 1881 | ; // access flags 0x0 |
|---|
| 1882 | ; <init>()V |
|---|
| 1883 | ; ALOAD 0 |
|---|
| 1884 | ; GETSTATIC org/armedbear/lisp/Symbol.CONS : Lorg/armedbear/lisp/Symbol; |
|---|
| 1885 | ; LDC "object-1 object-2" |
|---|
| 1886 | ; INVOKESPECIAL org/armedbear/lisp/Primitive.<init> (Lorg/armedbear/lisp/Symbol;Ljava/lang/String;)V |
|---|
| 1887 | ; RETURN |
|---|
| 1888 | ; MAXSTACK = 3 |
|---|
| 1889 | ; MAXLOCALS = 1 |
|---|
| 1890 | ; |
|---|
| 1891 | ; // access flags 0x1 |
|---|
| 1892 | ; public execute(Lorg/armedbear/lisp/LispObject;Lorg/armedbear/lisp/LispObject;)Lorg/armedbear/lisp/LispObject; |
|---|
| 1893 | ; NEW org/armedbear/lisp/Cons |
|---|
| 1894 | ; DUP |
|---|
| 1895 | ; ALOAD 1 |
|---|
| 1896 | ; ALOAD 2 |
|---|
| 1897 | ; INVOKESPECIAL org/armedbear/lisp/Cons.<init> (Lorg/armedbear/lisp/LispObject;Lorg/armedbear/lisp/LispObject;)V |
|---|
| 1898 | ; ARETURN |
|---|
| 1899 | ; MAXSTACK = 4 |
|---|
| 1900 | ; MAXLOCALS = 3 |
|---|
| 1901 | ; } |
|---|
| 1902 | NIL |
|---|
| 1903 | \end{listing-lisp} |
|---|
| 1904 | |
|---|
| 1905 | |
|---|
| 1906 | \url{http://abcl.org/svn/tags/1.9.2/contrib/abcl-introspect/}. |
|---|
| 1907 | |
|---|
| 1908 | \section{abcl-build} |
|---|
| 1909 | \label{section:abcl-build} |
|---|
| 1910 | \index{ABCL-BUILD} |
|---|
| 1911 | |
|---|
| 1912 | |
|---|
| 1913 | \textsc{ABCL-BUILD} constitutes a new implementation for the original |
|---|
| 1914 | Lisp-hosted \textsc{ABCL} build system API in the package |
|---|
| 1915 | \code{ABCL-BUILD} that uses the same build artifacts as all of the |
|---|
| 1916 | other current builds. |
|---|
| 1917 | |
|---|
| 1918 | \subsection{ABCL-BUILD Utilities} |
|---|
| 1919 | |
|---|
| 1920 | \textsc{ABCL-BUILD} consolidates various utilities that are useful |
|---|
| 1921 | for system construction, namely |
|---|
| 1922 | |
|---|
| 1923 | \begin{itemize} |
|---|
| 1924 | |
|---|
| 1925 | \item The ability to introspect the invocation of given executable in |
|---|
| 1926 | the current implementation process PATH. |
|---|
| 1927 | |
|---|
| 1928 | \item Downloading and unpackaging selected JVM artifacts, namely the |
|---|
| 1929 | Ant and Maven build tools. The \code{ABCL-BUILD:WITH-ANT} and |
|---|
| 1930 | \code{ABCL-BUILD:WITH-MVN} macros abstracts this installation |
|---|
| 1931 | procedure conveniently away from the User. |
|---|
| 1932 | |
|---|
| 1933 | \item The beginnings of a generic framework to download arbitrary |
|---|
| 1934 | archives from the network. |
|---|
| 1935 | \end{itemize} |
|---|
| 1936 | |
|---|
| 1937 | \url{http://abcl.org/svn/tags/1.9.2/contrib/abcl-build/}. |
|---|
| 1938 | |
|---|
| 1939 | \section{named-readtables} |
|---|
| 1940 | \label{section:named-readtables} |
|---|
| 1941 | \index{NAMED-READTABLES} |
|---|
| 1942 | |
|---|
| 1943 | \code{NAMED-READTABLES} is a library that provides a namespace for |
|---|
| 1944 | readtables akin to the already-existing namespace of packages. |
|---|
| 1945 | |
|---|
| 1946 | This contrib was included from the source available from |
|---|
| 1947 | \url{https://github.com/melisgl/named-readtables/}. |
|---|
| 1948 | |
|---|
| 1949 | See \url{http://abcl.org/svn/tags/1.9.2/contrib/named-readtables/} for |
|---|
| 1950 | more information. |
|---|
| 1951 | |
|---|
| 1952 | \chapter{History} |
|---|
| 1953 | \index{History} |
|---|
| 1954 | |
|---|
| 1955 | \textsc{ABCL} was originally the extension language for the J editor, which was |
|---|
| 1956 | started in 1998 by Peter Graves. Sometime in 2003, a whole lot of |
|---|
| 1957 | code that had previously not been released publicly was suddenly |
|---|
| 1958 | committed that enabled ABCL to be plausibly termed an emergent ANSI |
|---|
| 1959 | Common Lisp implementation candidate. |
|---|
| 1960 | |
|---|
| 1961 | From 2006 to 2008, Peter manned the development lists, incorporating |
|---|
| 1962 | patches as made sense. After a suitable search, Peter nominated Erik |
|---|
| 1963 | H\"{u}lsmann to take over the project. |
|---|
| 1964 | |
|---|
| 1965 | In 2008, the implementation was transferred to the current |
|---|
| 1966 | maintainers, who have striven to improve its usability as a |
|---|
| 1967 | contemporary Common Lisp implementation. |
|---|
| 1968 | |
|---|
| 1969 | On October 22, 2011, with the publication of this Manual explicitly |
|---|
| 1970 | stating the conformance of Armed Bear Common Lisp to \textsc{ANSI}, we |
|---|
| 1971 | released abcl-1.0.0. We released abcl-1.0.1 as a maintenance release |
|---|
| 1972 | on January 10, 2012. |
|---|
| 1973 | |
|---|
| 1974 | In December 2012, we revised the implementation by adding |
|---|
| 1975 | \textsc{(A)MOP} with the release of abcl-1.1.0. We released |
|---|
| 1976 | abcl-1.1.1 as a maintenance release on February 14, 2013. |
|---|
| 1977 | |
|---|
| 1978 | At the beginning of June 2013, we enhanced the stability of the |
|---|
| 1979 | implementation with the release of abcl-1.2.1. |
|---|
| 1980 | |
|---|
| 1981 | In March 2014, we introduced the Fourth Edition of the implementation |
|---|
| 1982 | with abcl-1.3.0. At the end of April 2014, we released abcl-1.3.1 as |
|---|
| 1983 | a maintenance release. |
|---|
| 1984 | |
|---|
| 1985 | In October 2016 we blessed the current \textsc{svn} trunk |
|---|
| 1986 | \url{http://abcl.org/svn/trunk/} as 1.4.0, which includes the |
|---|
| 1987 | community contributions from Vihbu, Olof, Pipping, and Cyrus. We |
|---|
| 1988 | gingerly stepped into current century by establishing \textsc{git} |
|---|
| 1989 | bridges to the source repositories available via the URIs |
|---|
| 1990 | \url{https://github.com/armedbear/abcl/} and |
|---|
| 1991 | \url{https://gitlab.common-lisp.net/abcl/abcl/} so that pull requests |
|---|
| 1992 | for enhancements to the implementation many be more easily |
|---|
| 1993 | facilitated. |
|---|
| 1994 | |
|---|
| 1995 | In June 2017, we released ABCL 1.5.0 which dropped support for running |
|---|
| 1996 | upon Java 5. |
|---|
| 1997 | |
|---|
| 1998 | Against the falling canvas of 2019 we released ABCL 1.6.0 which |
|---|
| 1999 | provided compatibility with Java 11 while skipping Java 9 and 10. In |
|---|
| 2000 | April 2020, we offered abcl-1.6.1 as a maintenance release for usage |
|---|
| 2001 | around ELS2020. |
|---|
| 2002 | |
|---|
| 2003 | With the overhaul the implementation of arrays specialized on |
|---|
| 2004 | \code{(or (unsigned-byte 8) (unsigned-byte 16) (unsigned-byte 32))} to |
|---|
| 2005 | using \code{java.nio.Buffer} objects, we deemed the implementation |
|---|
| 2006 | worthy to bless with release as abcl-1.7.0 in June 2020. We released |
|---|
| 2007 | abcl-1.7.1 as a maintenance release in July 2020. |
|---|
| 2008 | |
|---|
| 2009 | We released abcl-1.8.0 under the darkening storms of October 2020. |
|---|
| 2010 | |
|---|
| 2011 | Halfway through the $\pi$ $\alpha$ $\nu$ $\delta$ $\eta$ $\mu$ o |
|---|
| 2012 | $\zeta$ \cite{pandemos}, we dyslexic worker bears untied abcl-1.9.0. |
|---|
| 2013 | We released abcl-1.9.1 as a maintenance release in February 2023. In |
|---|
| 2014 | June 2023, among other fixes, we substantially improved our GRAY-STREAM |
|---|
| 2015 | support in abcl-1.9.2. |
|---|
| 2016 | |
|---|
| 2017 | \appendix |
|---|
| 2018 | |
|---|
| 2019 | \chapter{The MOP Dictionary} |
|---|
| 2020 | |
|---|
| 2021 | \include{mop} |
|---|
| 2022 | |
|---|
| 2023 | \chapter{The SYSTEM Dictionary} |
|---|
| 2024 | |
|---|
| 2025 | The public interfaces in this package are subject to change with |
|---|
| 2026 | \textsc{ABCL} 2.0 |
|---|
| 2027 | |
|---|
| 2028 | \include{system} |
|---|
| 2029 | |
|---|
| 2030 | \chapter{The JSS Dictionary} |
|---|
| 2031 | |
|---|
| 2032 | These public interfaces are provided by the JSS contrib. |
|---|
| 2033 | |
|---|
| 2034 | \include{jss} |
|---|
| 2035 | |
|---|
| 2036 | \bibliography{abcl} |
|---|
| 2037 | \bibliographystyle{alpha} |
|---|
| 2038 | |
|---|
| 2039 | \printindex |
|---|
| 2040 | |
|---|
| 2041 | \end{document} |
|---|