picolisp

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/picolisp.git/
Log | Files | Refs | README | LICENSE

commit aaf01d10c2e626c218881906fab7fa43b5565e35
parent a6911033f74e76637a06ac3db7ad4ed667c1e879
Author: Commit-Bot <unknown>
Date:   Fri,  5 Nov 2010 13:38:52 +0000

Automatic commit from picoLisp.tgz, From: Fri, 05 Nov 2010 13:38:52 GMT
Diffstat:
MCREDITS | 3+++
Mdoc/ref.html | 87++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
Mdoc/refE.html | 6+++---
Mersatz/PicoLisp.java | 2262+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
Mersatz/README | 13+++++++++----
Mersatz/fun.src | 209++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mersatz/mkJar | 3++-
Mersatz/picolisp.jar | 0
Mersatz/sys.src | 306++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
9 files changed, 1854 insertions(+), 1035 deletions(-)

diff --git a/CREDITS b/CREDITS @@ -21,3 +21,6 @@ Tomas Hlavaty <kvietaag@seznam.cz> # Spanish localization and emacs picolisp-mode Armadillo <tc.rucho@gmail.com> + +# Documentation +Christophe Gragnic <christophegragnic@yahoo.fr> diff --git a/doc/ref.html b/doc/ref.html @@ -126,7 +126,7 @@ except for the total memory size of the host machine. <dt>Dynamic <dd>Behavior should be as dynamic as possible ("run"-time vs. "compile"-time). -All decisions are delayed till runtime where possible. This involves matters +All decisions are delayed until runtime where possible. This involves matters like memory management, dynamic symbol binding, and late method binding. <dt>Practical @@ -188,12 +188,16 @@ mark bit for garbage collection. form a "free list". To create higher level data types at runtime, cells are taken from that free list, and returned by the garbage collector when they are no longer needed. All memory management is done via that free list; there are no -additional buffers, string spaces or special memory areas (With two exceptions: -A certain fixed area of memory is set aside to contain the executable code and -global variables of the interpreter itself, and a standard push down stack for -return addresses and temporary storage. Both are not directly accessible by the -programmer). +additional buffers, string spaces or special memory areas, with two exceptions: +<p><ul> +<li>A certain fixed area of memory is set aside to contain the executable code +and global variables of the interpreter itself, and + +<li>a standard push down stack for return addresses and temporary storage. Both +are not directly accessible by the programmer). + +</ul> <p><hr> <h3><a name="data">Data Types</a></h3> @@ -201,9 +205,9 @@ programmer). <p>On the virtual machine level, PicoLisp supports <p><ul> -<li>three base data types: Numbers, Symbols and Cons Pairs (Lists) -<li>the three scope variations of symbols: Internal, Transient and External -<li>and the special symbol <code>NIL</code>. +<li>three base data types: Numbers, Symbols and Cons Pairs (Lists), +<li>the three scope variations of symbols: Internal, Transient and External, and +<li>the special symbol <code>NIL</code>. </ul> <p>They are all built from the single cell data structure, and all runtime data @@ -284,7 +288,7 @@ from the cell's start address. Therefore, the bit pattern of a symbol will be: <p>Thus, a symbol is recognized by the interpreter when bit(2) is non-zero. -<p>A property is a key-value-pair, represented as a cell in the symbol's tail. +<p>A property is a key-value pair, represented as a cell in the symbol's tail. This is called a "property list". The property list may be terminated by a number representing the symbol's name. In the following example, a symbol with the name <code>"abc"</code> has three properties: A KEY/VAL cell, a cell with @@ -412,9 +416,9 @@ href="refN.html#new">new</a></code> functions. <p><hr> <h5><a name="external">External Symbols</a></h5> -<p>External symbols reside in a database file (or a similar resources (see -<code><a href="refE.html#*Ext">*Ext</a></code>)), and are loaded into memory - -and written back to the file - dynamically as needed, and transparent to the +<p>External symbols reside in a database file (or a similar resources, see +<code><a href="refE.html#*Ext">*Ext</a></code>), and are loaded into memory - +and written back to the file - dynamically as needed, and transparently to the programmer. <p>The interpreter recognizes external symbols internally by an additional tag @@ -423,7 +427,7 @@ bit in the tail structure. <p>There cannot be two different external symbols with the same name. External symbols are maintained in index structures while they are loaded into memory, and have their external location (disk file and block offset) directly coded -into their names. +into their names (more details <a href="#external-io">here</a>). <p>Initially, a new external symbol's VAL is <code>NIL</code>, unless otherwise specified at creation time. @@ -439,7 +443,7 @@ arrays, trees, stacks or queues. <p>In contrast to lists, numbers and symbols are collectively called "Atoms". <p>Typically, the CDR of each cell in a list points to the following cell, -except for the last cell which points <code>NIL</code>. If, however, the CDR of +except for the last cell which points to <code>NIL</code>. If, however, the CDR of the last cell points to an atom, that cell is called a "dotted pair" (because of its I/O syntax with a dot '.' between the two values). @@ -548,7 +552,7 @@ $ ./dbg myProject.l -main <p>In any case, the directory part of the first file name supplied on the command line (normally, the path to "lib.l") is remembered internally as the -<u>PicoLisp Home Directory</u>. This path is later automatically substituted for +<i>PicoLisp Home Directory</i>. This path is later automatically substituted for any leading "<code>@</code>" character in file name arguments to I/O functions (see <code><a href="refP.html#path">path</a></code>). @@ -578,7 +582,8 @@ character. Everything up to the end of that line will be ignored by the reader. <code>}#</code>. -<p>Here is the I/O syntax for the individual PicoLisp data types: +<p>Here is the I/O syntax for the individual PicoLisp data types (numbers, +symbols and lists) and for read-macros: <p><hr> @@ -697,7 +702,7 @@ completely with : (off *Tsm) </code></pre> -<p>Keyboard input of transient symbols is always via the double quote key. +<p>Keyboard input of transient symbols is always done via the double quote key. <p>A transient symbol may be used (and, in double quote representation, also look) like a string constant in other languages. However, it is a real symbol, @@ -707,7 +712,7 @@ and may be assigned a value or a function definition, and properties. not need to be quoted for evaluation: <pre><code> -: <u>This is a string</u> # "This is a string" if *Tsm is off +: <u>This is a string</u> # Would be "This is a string" if *Tsm were off -> <u>This is a string</u> </code></pre> @@ -721,10 +726,11 @@ This may cause unexpected behavior: -> 12345 </code></pre> -<p>The name of a transient symbol can contain any character except zero. A -double quote character can be escaped with a backslash '<code>\</code>', and a -backslash itself has to be escaped with another backslash. Control characters -can be written with a preceding hat '<code>^</code>' character. +<p>The name of a transient symbol can contain any character except the +null-byte. A double quote character can be escaped with a backslash +'<code>\</code>', and a backslash itself has to be escaped with another +backslash. Control characters can be written with a preceding hat +'<code>^</code>' character. <pre><code> : <u>We^Ird\\Str\"ing</u> @@ -813,8 +819,9 @@ because many functions won't terminate or will crash when given such a list. <h4><a name="macro-io">Read-Macros</a></h4> <p>Read-macros in PicoLisp are special forms that are recognized by the reader, -and modify its behavior. Note that they take effect immediately while reading an -expression, and are not seen by the <code>eval</code> in the main loop. +and modify its behavior. Note that they take effect immediately while <code><a +href="refR.html#read">read</a></code>ing an expression, and are not seen by the +<code>eval</code> in the main loop. <p>The most prominent read-macro in Lisp is the single quote character <code>'</code>, which expands to a call of the <code><a @@ -926,7 +933,7 @@ PicoLisp is <p><dl> <dt>either -<dd>a <u>number</u>. When a number is used as a function, it is simply taken as +<dd>a <i>number</i>. When a number is used as a function, it is simply taken as a pointer to executable code that will be called with the list of (unevaluated) arguments as its single parameter. It is up to that code to evaluate the arguments, or not. Some functions do not evaluate their arguments (e.g. @@ -934,7 +941,7 @@ arguments, or not. Some functions do not evaluate their arguments (e.g. <code>setq</code>). <dt>or -<dd>a <u>lambda expression</u>. A lambda expression is a list, whose CAR is +<dd>a <i>lambda expression</i>. A lambda expression is a list, whose CAR is either a symbol or a list of symbols, and whose CDR is a list of expressions. Note: In contrast to other Lisp implementations, the symbol LAMBDA itself does not exist in PicoLisp but is implied from context. @@ -950,11 +957,11 @@ like the <code>*</code> in: -> 6 </code></pre> -<p>Inspecting the VAL of <code>*</code>, however, gives +<p>Inspecting the VAL of <code>*</code> gives <pre><code> : * # Get the VAL of the symbol '*' --> 67291944 +-> 67318096 </code></pre> <p>The VAL of <code>*</code> is a number. In fact, it is the numeric @@ -1000,14 +1007,18 @@ whose VAL is used then. It is also legal, though quite dangerous, to use the code-pointer directly: <pre><code> -: car --> 67306152 -: ((* 2 33653076) (1 2 3)) +: * +-> 67318096 +: ((* 2 33659048) 1 2 3) +-> 1 +: ((quote . 67318096) 1 2 3) -> 1 +: ((quote . 1234) (1 2 3)) +Segmentation fault </code></pre> <p>When an executable function is defined in Lisp itself, we call it a <a -name="lambda"><u>lambda expression</u></a>. A lambda expression always has a +name="lambda"><i>lambda expression</i></a>. A lambda expression always has a list of executable expressions as its CDR. The CAR, however, must be a either a list of symbols, or a single symbol, and it controls the evaluation of the arguments to the executable function according to the following rules: @@ -1075,7 +1086,7 @@ bind all other arguments (unevaluated) to <code>Z</code>: (list X Y Z) ) # Return a list of all arguments -> foo : (foo (+ 1 2) (+ 3 4) (+ 5 6)) --> (3 7 ((+ 5 6))) # two arguments are evaluated +-> (3 7 ((+ 5 6))) # Only the first two arguments are evaluated </code></pre> <p>Or, a single argument followed by a variable number of arguments: @@ -1088,8 +1099,8 @@ bind all other arguments (unevaluated) to <code>Z</code>: -> foo : (foo (+ 1 2) (+ 3 4) (+ 5 6)) 3 # X -7 # Next arg -11 +7 # next argument +11 # and the last argument -> 11 </code></pre> @@ -1110,7 +1121,7 @@ and exit points, and preserve their environment between invocations. functions, and (re)invoked as needed. In this regard coroutines are similar to "continuations" in other languages. -<p>When the goes out of scope, the coroutine will be garabage collected. In +<p>When the tag goes out of scope, the coroutine will be garabage collected. In cases where this is desired, using a <a href="#transient">transient</a> symbol for the tag is recommended. @@ -1159,7 +1170,7 @@ href="refD.html#debug">debug</a></code>, <code><a href="refE.html#e">e</a></code>, <code><a href="ref_.html#^">^</a></code> and <code><a href="refD.html#*Dbg">*Dbg</a></code> -<p>Other interrups may be handled by <code><a +<p>Other interrupts may be handled by <code><a href="refA.html#alarm">alarm</a></code>, <code><a href="refS.html#sigio">sigio</a></code>, <code><a href="refH.html#*Hup">*Hup</a></code> and <code><a diff --git a/doc/refE.html b/doc/refE.html @@ -131,9 +131,9 @@ If <code>cnt</code> is given, only that many bytes are actually echoed. In case of two <code>cnt</code> arguments, the first one specifies the number of bytes to skip in the input stream. Otherwise, if one or more <code>sym</code> arguments are given, the echo process stops as soon as one of the symbol's names -is encountered in the input stream (in that case, the name will be read (and -that symbol returned), but not written). Returns non-<code>NIL</code> if the -operation was successfully completed. +is encountered in the input stream. In this case the name will be read and +returned, but not written. Returns non-<code>NIL</code> if the operation was +successfully completed. <pre><code> : (in "x.l" (echo)) # Display file on console diff --git a/ersatz/PicoLisp.java b/ersatz/PicoLisp.java @@ -1,13 +1,18 @@ -// 01nov10abu +// 05nov10abu // (c) Software Lab. Alexander Burger -import java.io.*; -import java.net.*; import java.util.*; import java.math.*; +import java.io.*; +import java.net.*; +import java.nio.*; +import java.nio.channels.*; +import java.nio.channels.spi.*; +import java.lang.reflect.*; /* Ersatz PicoLisp Interpreter (Poor Man's PicoLisp) */ public class PicoLisp { + final static Console Term = System.console(); final static HashMap<String,Symbol> Intern = new HashMap<String,Symbol>(); final static HashMap<String,Symbol> Transient = new HashMap<String,Symbol>(); final static byte MonLen[] = new byte[] {31,31,28,31,30,31,30,31,31,30,31,30,31}; @@ -40,10 +45,11 @@ public class PicoLisp { static Catch Catch; static Env Env = new Env(); + static StringBuilder Line; static Process[] Pids = new Process[12]; static PicoLispReader[] InFiles = new PicoLispReader[12]; static PicoLispWriter[] OutFiles = new PicoLispWriter[12]; - final static PicoLispReader StdIn = new PicoLispReader(System.in, 0); + final static PicoLispReader StdIn = new PicoLispReader(System.in, 0, null, 0); final static PicoLispWriter StdOut = new PicoLispWriter(System.out, 1); final static PicoLispWriter StdErr = new PicoLispWriter(System.err, 2); static PicoLispReader InFile = StdIn; @@ -59,290 +65,301 @@ public class PicoLisp { public static void main(String[] argv) { Argv = argv; - init(); mkSymbol(new Number("2"), "quit", Intern); - mkSymbol(new Number("3"), "args", Intern); - mkSymbol(new Number("4"), "next", Intern); - mkSymbol(new Number("5"), "arg", Intern); - mkSymbol(new Number("6"), "rest", Intern); - mkSymbol(new Number("7"), "date", Intern); - mkSymbol(new Number("8"), "time", Intern); - mkSymbol(new Number("9"), "usec", Intern); - mkSymbol(new Number("10"), "file", Intern); - mkSymbol(new Number("11"), "version", Intern); - mkSymbol(new Number("12"), "apply", Intern); - mkSymbol(new Number("13"), "pass", Intern); - mkSymbol(new Number("14"), "maps", Intern); - mkSymbol(new Number("15"), "map", Intern); - mkSymbol(new Number("16"), "mapc", Intern); - mkSymbol(new Number("17"), "maplist", Intern); - mkSymbol(new Number("18"), "mapcar", Intern); - mkSymbol(new Number("19"), "mapcon", Intern); - mkSymbol(new Number("20"), "mapcan", Intern); - mkSymbol(new Number("21"), "filter", Intern); - mkSymbol(new Number("22"), "extract", Intern); - mkSymbol(new Number("23"), "seek", Intern); - mkSymbol(new Number("24"), "find", Intern); - mkSymbol(new Number("25"), "pick", Intern); - mkSymbol(new Number("26"), "cnt", Intern); - mkSymbol(new Number("27"), "sum", Intern); - mkSymbol(new Number("28"), "maxi", Intern); - mkSymbol(new Number("29"), "mini", Intern); - mkSymbol(new Number("30"), "fish", Intern); - mkSymbol(new Number("31"), "by", Intern); - mkSymbol(new Number("32"), "as", Intern); - mkSymbol(new Number("33"), "lit", Intern); - mkSymbol(new Number("34"), "eval", Intern); - mkSymbol(new Number("35"), "run", Intern); - mkSymbol(new Number("36"), "def", Intern); - mkSymbol(new Number("37"), "de", Intern); - mkSymbol(new Number("38"), "dm", Intern); - mkSymbol(new Number("39"), "box", Intern); - mkSymbol(new Number("40"), "new", Intern); - mkSymbol(new Number("41"), "type", Intern); - mkSymbol(new Number("42"), "isa", Intern); - mkSymbol(new Number("43"), "method", Intern); - mkSymbol(new Number("44"), "send", Intern); - mkSymbol(new Number("45"), "try", Intern); - mkSymbol(new Number("46"), "super", Intern); - mkSymbol(new Number("47"), "extra", Intern); - mkSymbol(new Number("48"), "with", Intern); - mkSymbol(new Number("49"), "bind", Intern); - mkSymbol(new Number("50"), "job", Intern); - mkSymbol(new Number("51"), "let", Intern); - mkSymbol(new Number("52"), "let?", Intern); - mkSymbol(new Number("53"), "use", Intern); - mkSymbol(new Number("54"), "and", Intern); - mkSymbol(new Number("55"), "or", Intern); - mkSymbol(new Number("56"), "nand", Intern); - mkSymbol(new Number("57"), "nor", Intern); - mkSymbol(new Number("58"), "xor", Intern); - mkSymbol(new Number("59"), "bool", Intern); - mkSymbol(new Number("60"), "not", Intern); - mkSymbol(new Number("61"), "nil", Intern); - mkSymbol(new Number("62"), "t", Intern); - mkSymbol(new Number("63"), "prog", Intern); - mkSymbol(new Number("64"), "prog1", Intern); - mkSymbol(new Number("65"), "prog2", Intern); - mkSymbol(new Number("66"), "if", Intern); - mkSymbol(new Number("67"), "if2", Intern); - mkSymbol(new Number("68"), "ifn", Intern); - mkSymbol(new Number("69"), "when", Intern); - mkSymbol(new Number("70"), "unless", Intern); - mkSymbol(new Number("71"), "cond", Intern); - mkSymbol(new Number("72"), "nond", Intern); - mkSymbol(new Number("73"), "case", Intern); - mkSymbol(new Number("74"), "state", Intern); - mkSymbol(new Number("75"), "while", Intern); - mkSymbol(new Number("76"), "until", Intern); - mkSymbol(new Number("77"), "do", Intern); - mkSymbol(new Number("78"), "loop", Intern); - mkSymbol(new Number("79"), "at", Intern); - mkSymbol(new Number("80"), "for", Intern); - mkSymbol(new Number("81"), "catch", Intern); - mkSymbol(new Number("82"), "throw", Intern); - mkSymbol(new Number("83"), "finally", Intern); - mkSymbol(new Number("84"), "!", Intern); - mkSymbol(new Number("85"), "e", Intern); - mkSymbol(new Number("86"), "$", Intern); - mkSymbol(new Number("87"), "sys", Intern); - mkSymbol(new Number("88"), "call", Intern); - mkSymbol(new Number("89"), "ipid", Intern); - mkSymbol(new Number("90"), "opid", Intern); - mkSymbol(new Number("91"), "kill", Intern); - mkSymbol(new Number("92"), "bye", Intern); - mkSymbol(new Number("93"), "name", Intern); - mkSymbol(new Number("94"), "sp?", Intern); - mkSymbol(new Number("95"), "pat?", Intern); - mkSymbol(new Number("96"), "fun?", Intern); - mkSymbol(new Number("97"), "getd", Intern); - mkSymbol(new Number("98"), "all", Intern); - mkSymbol(new Number("99"), "intern", Intern); - mkSymbol(new Number("100"), "====", Intern); - mkSymbol(new Number("101"), "box?", Intern); - mkSymbol(new Number("102"), "str?", Intern); - mkSymbol(new Number("103"), "zap", Intern); - mkSymbol(new Number("104"), "chop", Intern); - mkSymbol(new Number("105"), "pack", Intern); - mkSymbol(new Number("106"), "glue", Intern); - mkSymbol(new Number("107"), "text", Intern); - mkSymbol(new Number("108"), "pre?", Intern); - mkSymbol(new Number("109"), "sub?", Intern); - mkSymbol(new Number("110"), "val", Intern); - mkSymbol(new Number("111"), "set", Intern); - mkSymbol(new Number("112"), "setq", Intern); - mkSymbol(new Number("113"), "xchg", Intern); - mkSymbol(new Number("114"), "on", Intern); - mkSymbol(new Number("115"), "off", Intern); - mkSymbol(new Number("116"), "onOff", Intern); - mkSymbol(new Number("117"), "zero", Intern); - mkSymbol(new Number("118"), "one", Intern); - mkSymbol(new Number("119"), "default", Intern); - mkSymbol(new Number("120"), "push", Intern); - mkSymbol(new Number("121"), "push1", Intern); - mkSymbol(new Number("122"), "pop", Intern); - mkSymbol(new Number("123"), "cut", Intern); - mkSymbol(new Number("124"), "del", Intern); - mkSymbol(new Number("125"), "queue", Intern); - mkSymbol(new Number("126"), "fifo", Intern); - mkSymbol(new Number("127"), "idx", Intern); - mkSymbol(new Number("128"), "lup", Intern); - mkSymbol(new Number("129"), "put", Intern); - mkSymbol(new Number("130"), "get", Intern); - mkSymbol(new Number("131"), "prop", Intern); - mkSymbol(new Number("132"), ";", Intern); - mkSymbol(new Number("133"), "=:", Intern); - mkSymbol(new Number("134"), ":", Intern); - mkSymbol(new Number("135"), "::", Intern); - mkSymbol(new Number("136"), "putl", Intern); - mkSymbol(new Number("137"), "getl", Intern); - mkSymbol(new Number("138"), "meta", Intern); - mkSymbol(new Number("139"), "low?", Intern); - mkSymbol(new Number("140"), "upp?", Intern); - mkSymbol(new Number("141"), "lowc", Intern); - mkSymbol(new Number("142"), "uppc", Intern); - mkSymbol(new Number("143"), "fold", Intern); - mkSymbol(new Number("144"), "car", Intern); - mkSymbol(new Number("145"), "cdr", Intern); - mkSymbol(new Number("146"), "caar", Intern); - mkSymbol(new Number("147"), "cadr", Intern); - mkSymbol(new Number("148"), "cdar", Intern); - mkSymbol(new Number("149"), "cddr", Intern); - mkSymbol(new Number("150"), "caaar", Intern); - mkSymbol(new Number("151"), "caadr", Intern); - mkSymbol(new Number("152"), "cadar", Intern); - mkSymbol(new Number("153"), "caddr", Intern); - mkSymbol(new Number("154"), "cdaar", Intern); - mkSymbol(new Number("155"), "cdadr", Intern); - mkSymbol(new Number("156"), "cddar", Intern); - mkSymbol(new Number("157"), "cdddr", Intern); - mkSymbol(new Number("158"), "caaaar", Intern); - mkSymbol(new Number("159"), "caaadr", Intern); - mkSymbol(new Number("160"), "caadar", Intern); - mkSymbol(new Number("161"), "caaddr", Intern); - mkSymbol(new Number("162"), "cadaar", Intern); - mkSymbol(new Number("163"), "cadadr", Intern); - mkSymbol(new Number("164"), "caddar", Intern); - mkSymbol(new Number("165"), "cadddr", Intern); - mkSymbol(new Number("166"), "cdaaar", Intern); - mkSymbol(new Number("167"), "cdaadr", Intern); - mkSymbol(new Number("168"), "cdadar", Intern); - mkSymbol(new Number("169"), "cdaddr", Intern); - mkSymbol(new Number("170"), "cddaar", Intern); - mkSymbol(new Number("171"), "cddadr", Intern); - mkSymbol(new Number("172"), "cdddar", Intern); - mkSymbol(new Number("173"), "cddddr", Intern); - mkSymbol(new Number("174"), "nth", Intern); - mkSymbol(new Number("175"), "con", Intern); - mkSymbol(new Number("176"), "cons", Intern); - mkSymbol(new Number("177"), "conc", Intern); - mkSymbol(new Number("178"), "circ", Intern); - mkSymbol(new Number("179"), "rot", Intern); - mkSymbol(new Number("180"), "list", Intern); - mkSymbol(new Number("181"), "need", Intern); - mkSymbol(new Number("182"), "range", Intern); - mkSymbol(new Number("183"), "full", Intern); - mkSymbol(new Number("184"), "make", Intern); - mkSymbol(new Number("185"), "made", Intern); - mkSymbol(new Number("186"), "chain", Intern); - mkSymbol(new Number("187"), "link", Intern); - mkSymbol(new Number("188"), "yoke", Intern); - mkSymbol(new Number("189"), "copy", Intern); - mkSymbol(new Number("190"), "mix", Intern); - mkSymbol(new Number("191"), "append", Intern); - mkSymbol(new Number("192"), "delete", Intern); - mkSymbol(new Number("193"), "delq", Intern); - mkSymbol(new Number("194"), "replace", Intern); - mkSymbol(new Number("195"), "strip", Intern); - mkSymbol(new Number("196"), "split", Intern); - mkSymbol(new Number("197"), "reverse", Intern); - mkSymbol(new Number("198"), "flip", Intern); - mkSymbol(new Number("199"), "trim", Intern); - mkSymbol(new Number("200"), "clip", Intern); - mkSymbol(new Number("201"), "head", Intern); - mkSymbol(new Number("202"), "tail", Intern); - mkSymbol(new Number("203"), "stem", Intern); - mkSymbol(new Number("204"), "fin", Intern); - mkSymbol(new Number("205"), "last", Intern); - mkSymbol(new Number("206"), "==", Intern); - mkSymbol(new Number("207"), "n==", Intern); - mkSymbol(new Number("208"), "=", Intern); - mkSymbol(new Number("209"), "<>", Intern); - mkSymbol(new Number("210"), "=0", Intern); - mkSymbol(new Number("211"), "=T", Intern); - mkSymbol(new Number("212"), "n0", Intern); - mkSymbol(new Number("213"), "nT", Intern); - mkSymbol(new Number("214"), "<", Intern); - mkSymbol(new Number("215"), "<=", Intern); - mkSymbol(new Number("216"), ">", Intern); - mkSymbol(new Number("217"), ">=", Intern); - mkSymbol(new Number("218"), "max", Intern); - mkSymbol(new Number("219"), "min", Intern); - mkSymbol(new Number("220"), "atom", Intern); - mkSymbol(new Number("221"), "pair", Intern); - mkSymbol(new Number("222"), "lst?", Intern); - mkSymbol(new Number("223"), "num?", Intern); - mkSymbol(new Number("224"), "sym?", Intern); - mkSymbol(new Number("225"), "flg?", Intern); - mkSymbol(new Number("226"), "member", Intern); - mkSymbol(new Number("227"), "memq", Intern); - mkSymbol(new Number("228"), "mmeq", Intern); - mkSymbol(new Number("229"), "sect", Intern); - mkSymbol(new Number("230"), "diff", Intern); - mkSymbol(new Number("231"), "index", Intern); - mkSymbol(new Number("232"), "offset", Intern); - mkSymbol(new Number("233"), "length", Intern); - mkSymbol(new Number("234"), "size", Intern); - mkSymbol(new Number("235"), "assoc", Intern); - mkSymbol(new Number("236"), "asoq", Intern); - mkSymbol(new Number("237"), "rank", Intern); - mkSymbol(new Number("238"), "match", Intern); - mkSymbol(new Number("239"), "fill", Intern); - mkSymbol(new Number("240"), "prove", Intern); - mkSymbol(new Number("241"), "->", Intern); - mkSymbol(new Number("242"), "unify", Intern); - mkSymbol(new Number("243"), "sort", Intern); - mkSymbol(new Number("244"), "format", Intern); - mkSymbol(new Number("245"), "+", Intern); - mkSymbol(new Number("246"), "-", Intern); - mkSymbol(new Number("247"), "inc", Intern); - mkSymbol(new Number("248"), "dec", Intern); - mkSymbol(new Number("249"), "*", Intern); - mkSymbol(new Number("250"), "*/", Intern); - mkSymbol(new Number("251"), "/", Intern); - mkSymbol(new Number("252"), "%", Intern); - mkSymbol(new Number("253"), ">>", Intern); - mkSymbol(new Number("254"), "lt0", Intern); - mkSymbol(new Number("255"), "ge0", Intern); - mkSymbol(new Number("256"), "gt0", Intern); - mkSymbol(new Number("257"), "abs", Intern); - mkSymbol(new Number("258"), "bit?", Intern); - mkSymbol(new Number("259"), "&", Intern); - mkSymbol(new Number("260"), "|", Intern); - mkSymbol(new Number("261"), "x|", Intern); - mkSymbol(new Number("262"), "seed", Intern); - mkSymbol(new Number("263"), "rand", Intern); - mkSymbol(new Number("264"), "path", Intern); - mkSymbol(new Number("265"), "read", Intern); - mkSymbol(new Number("266"), "char", Intern); - mkSymbol(new Number("267"), "skip", Intern); - mkSymbol(new Number("268"), "line", Intern); - mkSymbol(new Number("269"), "load", Intern); - mkSymbol(new Number("270"), "in", Intern); - mkSymbol(new Number("271"), "out", Intern); - mkSymbol(new Number("272"), "ctl", Intern); - mkSymbol(new Number("273"), "open", Intern); - mkSymbol(new Number("274"), "close", Intern); - mkSymbol(new Number("275"), "prin", Intern); - mkSymbol(new Number("276"), "prinl", Intern); - mkSymbol(new Number("277"), "space", Intern); - mkSymbol(new Number("278"), "print", Intern); - mkSymbol(new Number("279"), "printsp", Intern); - mkSymbol(new Number("280"), "println", Intern); - mkSymbol(new Number("281"), "flush", Intern); - mkSymbol(new Number("282"), "connect", Intern); - MaxFun = 282; - USec = System.nanoTime() / 1000; + mkSymbol(new Number("3"), "public", Intern); + mkSymbol(new Number("4"), "java", Intern); + mkSymbol(new Number("5"), "byte:", Intern); + mkSymbol(new Number("6"), "char:", Intern); + mkSymbol(new Number("7"), "int:", Intern); + mkSymbol(new Number("8"), "long:", Intern); + mkSymbol(new Number("9"), "double:", Intern); + mkSymbol(new Number("10"), "big:", Intern); + mkSymbol(new Number("11"), "data", Intern); + mkSymbol(new Number("12"), "args", Intern); + mkSymbol(new Number("13"), "next", Intern); + mkSymbol(new Number("14"), "arg", Intern); + mkSymbol(new Number("15"), "rest", Intern); + mkSymbol(new Number("16"), "date", Intern); + mkSymbol(new Number("17"), "time", Intern); + mkSymbol(new Number("18"), "usec", Intern); + mkSymbol(new Number("19"), "file", Intern); + mkSymbol(new Number("20"), "version", Intern); + mkSymbol(new Number("21"), "apply", Intern); + mkSymbol(new Number("22"), "pass", Intern); + mkSymbol(new Number("23"), "maps", Intern); + mkSymbol(new Number("24"), "map", Intern); + mkSymbol(new Number("25"), "mapc", Intern); + mkSymbol(new Number("26"), "maplist", Intern); + mkSymbol(new Number("27"), "mapcar", Intern); + mkSymbol(new Number("28"), "mapcon", Intern); + mkSymbol(new Number("29"), "mapcan", Intern); + mkSymbol(new Number("30"), "filter", Intern); + mkSymbol(new Number("31"), "extract", Intern); + mkSymbol(new Number("32"), "seek", Intern); + mkSymbol(new Number("33"), "find", Intern); + mkSymbol(new Number("34"), "pick", Intern); + mkSymbol(new Number("35"), "cnt", Intern); + mkSymbol(new Number("36"), "sum", Intern); + mkSymbol(new Number("37"), "maxi", Intern); + mkSymbol(new Number("38"), "mini", Intern); + mkSymbol(new Number("39"), "fish", Intern); + mkSymbol(new Number("40"), "by", Intern); + mkSymbol(new Number("41"), "as", Intern); + mkSymbol(new Number("42"), "lit", Intern); + mkSymbol(new Number("43"), "eval", Intern); + mkSymbol(new Number("44"), "run", Intern); + mkSymbol(new Number("45"), "def", Intern); + mkSymbol(new Number("46"), "de", Intern); + mkSymbol(new Number("47"), "dm", Intern); + mkSymbol(new Number("48"), "box", Intern); + mkSymbol(new Number("49"), "new", Intern); + mkSymbol(new Number("50"), "type", Intern); + mkSymbol(new Number("51"), "isa", Intern); + mkSymbol(new Number("52"), "method", Intern); + mkSymbol(new Number("53"), "send", Intern); + mkSymbol(new Number("54"), "try", Intern); + mkSymbol(new Number("55"), "super", Intern); + mkSymbol(new Number("56"), "extra", Intern); + mkSymbol(new Number("57"), "with", Intern); + mkSymbol(new Number("58"), "bind", Intern); + mkSymbol(new Number("59"), "job", Intern); + mkSymbol(new Number("60"), "let", Intern); + mkSymbol(new Number("61"), "let?", Intern); + mkSymbol(new Number("62"), "use", Intern); + mkSymbol(new Number("63"), "and", Intern); + mkSymbol(new Number("64"), "or", Intern); + mkSymbol(new Number("65"), "nand", Intern); + mkSymbol(new Number("66"), "nor", Intern); + mkSymbol(new Number("67"), "xor", Intern); + mkSymbol(new Number("68"), "bool", Intern); + mkSymbol(new Number("69"), "not", Intern); + mkSymbol(new Number("70"), "nil", Intern); + mkSymbol(new Number("71"), "t", Intern); + mkSymbol(new Number("72"), "prog", Intern); + mkSymbol(new Number("73"), "prog1", Intern); + mkSymbol(new Number("74"), "prog2", Intern); + mkSymbol(new Number("75"), "if", Intern); + mkSymbol(new Number("76"), "if2", Intern); + mkSymbol(new Number("77"), "ifn", Intern); + mkSymbol(new Number("78"), "when", Intern); + mkSymbol(new Number("79"), "unless", Intern); + mkSymbol(new Number("80"), "cond", Intern); + mkSymbol(new Number("81"), "nond", Intern); + mkSymbol(new Number("82"), "case", Intern); + mkSymbol(new Number("83"), "state", Intern); + mkSymbol(new Number("84"), "while", Intern); + mkSymbol(new Number("85"), "until", Intern); + mkSymbol(new Number("86"), "do", Intern); + mkSymbol(new Number("87"), "loop", Intern); + mkSymbol(new Number("88"), "at", Intern); + mkSymbol(new Number("89"), "for", Intern); + mkSymbol(new Number("90"), "catch", Intern); + mkSymbol(new Number("91"), "throw", Intern); + mkSymbol(new Number("92"), "finally", Intern); + mkSymbol(new Number("93"), "!", Intern); + mkSymbol(new Number("94"), "e", Intern); + mkSymbol(new Number("95"), "$", Intern); + mkSymbol(new Number("96"), "sys", Intern); + mkSymbol(new Number("97"), "call", Intern); + mkSymbol(new Number("98"), "ipid", Intern); + mkSymbol(new Number("99"), "opid", Intern); + mkSymbol(new Number("100"), "kill", Intern); + mkSymbol(new Number("101"), "bye", Intern); + mkSymbol(new Number("102"), "name", Intern); + mkSymbol(new Number("103"), "sp?", Intern); + mkSymbol(new Number("104"), "pat?", Intern); + mkSymbol(new Number("105"), "fun?", Intern); + mkSymbol(new Number("106"), "getd", Intern); + mkSymbol(new Number("107"), "all", Intern); + mkSymbol(new Number("108"), "intern", Intern); + mkSymbol(new Number("109"), "====", Intern); + mkSymbol(new Number("110"), "box?", Intern); + mkSymbol(new Number("111"), "str?", Intern); + mkSymbol(new Number("112"), "zap", Intern); + mkSymbol(new Number("113"), "chop", Intern); + mkSymbol(new Number("114"), "pack", Intern); + mkSymbol(new Number("115"), "glue", Intern); + mkSymbol(new Number("116"), "text", Intern); + mkSymbol(new Number("117"), "pre?", Intern); + mkSymbol(new Number("118"), "sub?", Intern); + mkSymbol(new Number("119"), "val", Intern); + mkSymbol(new Number("120"), "set", Intern); + mkSymbol(new Number("121"), "setq", Intern); + mkSymbol(new Number("122"), "xchg", Intern); + mkSymbol(new Number("123"), "on", Intern); + mkSymbol(new Number("124"), "off", Intern); + mkSymbol(new Number("125"), "onOff", Intern); + mkSymbol(new Number("126"), "zero", Intern); + mkSymbol(new Number("127"), "one", Intern); + mkSymbol(new Number("128"), "default", Intern); + mkSymbol(new Number("129"), "push", Intern); + mkSymbol(new Number("130"), "push1", Intern); + mkSymbol(new Number("131"), "pop", Intern); + mkSymbol(new Number("132"), "cut", Intern); + mkSymbol(new Number("133"), "del", Intern); + mkSymbol(new Number("134"), "queue", Intern); + mkSymbol(new Number("135"), "fifo", Intern); + mkSymbol(new Number("136"), "idx", Intern); + mkSymbol(new Number("137"), "lup", Intern); + mkSymbol(new Number("138"), "put", Intern); + mkSymbol(new Number("139"), "get", Intern); + mkSymbol(new Number("140"), "prop", Intern); + mkSymbol(new Number("141"), ";", Intern); + mkSymbol(new Number("142"), "=:", Intern); + mkSymbol(new Number("143"), ":", Intern); + mkSymbol(new Number("144"), "::", Intern); + mkSymbol(new Number("145"), "putl", Intern); + mkSymbol(new Number("146"), "getl", Intern); + mkSymbol(new Number("147"), "meta", Intern); + mkSymbol(new Number("148"), "low?", Intern); + mkSymbol(new Number("149"), "upp?", Intern); + mkSymbol(new Number("150"), "lowc", Intern); + mkSymbol(new Number("151"), "uppc", Intern); + mkSymbol(new Number("152"), "fold", Intern); + mkSymbol(new Number("153"), "car", Intern); + mkSymbol(new Number("154"), "cdr", Intern); + mkSymbol(new Number("155"), "caar", Intern); + mkSymbol(new Number("156"), "cadr", Intern); + mkSymbol(new Number("157"), "cdar", Intern); + mkSymbol(new Number("158"), "cddr", Intern); + mkSymbol(new Number("159"), "caaar", Intern); + mkSymbol(new Number("160"), "caadr", Intern); + mkSymbol(new Number("161"), "cadar", Intern); + mkSymbol(new Number("162"), "caddr", Intern); + mkSymbol(new Number("163"), "cdaar", Intern); + mkSymbol(new Number("164"), "cdadr", Intern); + mkSymbol(new Number("165"), "cddar", Intern); + mkSymbol(new Number("166"), "cdddr", Intern); + mkSymbol(new Number("167"), "caaaar", Intern); + mkSymbol(new Number("168"), "caaadr", Intern); + mkSymbol(new Number("169"), "caadar", Intern); + mkSymbol(new Number("170"), "caaddr", Intern); + mkSymbol(new Number("171"), "cadaar", Intern); + mkSymbol(new Number("172"), "cadadr", Intern); + mkSymbol(new Number("173"), "caddar", Intern); + mkSymbol(new Number("174"), "cadddr", Intern); + mkSymbol(new Number("175"), "cdaaar", Intern); + mkSymbol(new Number("176"), "cdaadr", Intern); + mkSymbol(new Number("177"), "cdadar", Intern); + mkSymbol(new Number("178"), "cdaddr", Intern); + mkSymbol(new Number("179"), "cddaar", Intern); + mkSymbol(new Number("180"), "cddadr", Intern); + mkSymbol(new Number("181"), "cdddar", Intern); + mkSymbol(new Number("182"), "cddddr", Intern); + mkSymbol(new Number("183"), "nth", Intern); + mkSymbol(new Number("184"), "con", Intern); + mkSymbol(new Number("185"), "cons", Intern); + mkSymbol(new Number("186"), "conc", Intern); + mkSymbol(new Number("187"), "circ", Intern); + mkSymbol(new Number("188"), "rot", Intern); + mkSymbol(new Number("189"), "list", Intern); + mkSymbol(new Number("190"), "need", Intern); + mkSymbol(new Number("191"), "range", Intern); + mkSymbol(new Number("192"), "full", Intern); + mkSymbol(new Number("193"), "make", Intern); + mkSymbol(new Number("194"), "made", Intern); + mkSymbol(new Number("195"), "chain", Intern); + mkSymbol(new Number("196"), "link", Intern); + mkSymbol(new Number("197"), "yoke", Intern); + mkSymbol(new Number("198"), "copy", Intern); + mkSymbol(new Number("199"), "mix", Intern); + mkSymbol(new Number("200"), "append", Intern); + mkSymbol(new Number("201"), "delete", Intern); + mkSymbol(new Number("202"), "delq", Intern); + mkSymbol(new Number("203"), "replace", Intern); + mkSymbol(new Number("204"), "strip", Intern); + mkSymbol(new Number("205"), "split", Intern); + mkSymbol(new Number("206"), "reverse", Intern); + mkSymbol(new Number("207"), "flip", Intern); + mkSymbol(new Number("208"), "trim", Intern); + mkSymbol(new Number("209"), "clip", Intern); + mkSymbol(new Number("210"), "head", Intern); + mkSymbol(new Number("211"), "tail", Intern); + mkSymbol(new Number("212"), "stem", Intern); + mkSymbol(new Number("213"), "fin", Intern); + mkSymbol(new Number("214"), "last", Intern); + mkSymbol(new Number("215"), "==", Intern); + mkSymbol(new Number("216"), "n==", Intern); + mkSymbol(new Number("217"), "=", Intern); + mkSymbol(new Number("218"), "<>", Intern); + mkSymbol(new Number("219"), "=0", Intern); + mkSymbol(new Number("220"), "=T", Intern); + mkSymbol(new Number("221"), "n0", Intern); + mkSymbol(new Number("222"), "nT", Intern); + mkSymbol(new Number("223"), "<", Intern); + mkSymbol(new Number("224"), "<=", Intern); + mkSymbol(new Number("225"), ">", Intern); + mkSymbol(new Number("226"), ">=", Intern); + mkSymbol(new Number("227"), "max", Intern); + mkSymbol(new Number("228"), "min", Intern); + mkSymbol(new Number("229"), "atom", Intern); + mkSymbol(new Number("230"), "pair", Intern); + mkSymbol(new Number("231"), "lst?", Intern); + mkSymbol(new Number("232"), "num?", Intern); + mkSymbol(new Number("233"), "sym?", Intern); + mkSymbol(new Number("234"), "flg?", Intern); + mkSymbol(new Number("235"), "member", Intern); + mkSymbol(new Number("236"), "memq", Intern); + mkSymbol(new Number("237"), "mmeq", Intern); + mkSymbol(new Number("238"), "sect", Intern); + mkSymbol(new Number("239"), "diff", Intern); + mkSymbol(new Number("240"), "index", Intern); + mkSymbol(new Number("241"), "offset", Intern); + mkSymbol(new Number("242"), "length", Intern); + mkSymbol(new Number("243"), "size", Intern); + mkSymbol(new Number("244"), "assoc", Intern); + mkSymbol(new Number("245"), "asoq", Intern); + mkSymbol(new Number("246"), "rank", Intern); + mkSymbol(new Number("247"), "match", Intern); + mkSymbol(new Number("248"), "fill", Intern); + mkSymbol(new Number("249"), "prove", Intern); + mkSymbol(new Number("250"), "->", Intern); + mkSymbol(new Number("251"), "unify", Intern); + mkSymbol(new Number("252"), "sort", Intern); + mkSymbol(new Number("253"), "format", Intern); + mkSymbol(new Number("254"), "+", Intern); + mkSymbol(new Number("255"), "-", Intern); + mkSymbol(new Number("256"), "inc", Intern); + mkSymbol(new Number("257"), "dec", Intern); + mkSymbol(new Number("258"), "*", Intern); + mkSymbol(new Number("259"), "*/", Intern); + mkSymbol(new Number("260"), "/", Intern); + mkSymbol(new Number("261"), "%", Intern); + mkSymbol(new Number("262"), ">>", Intern); + mkSymbol(new Number("263"), "lt0", Intern); + mkSymbol(new Number("264"), "ge0", Intern); + mkSymbol(new Number("265"), "gt0", Intern); + mkSymbol(new Number("266"), "abs", Intern); + mkSymbol(new Number("267"), "bit?", Intern); + mkSymbol(new Number("268"), "&", Intern); + mkSymbol(new Number("269"), "|", Intern); + mkSymbol(new Number("270"), "x|", Intern); + mkSymbol(new Number("271"), "seed", Intern); + mkSymbol(new Number("272"), "rand", Intern); + mkSymbol(new Number("273"), "path", Intern); + mkSymbol(new Number("274"), "read", Intern); + mkSymbol(new Number("275"), "wait", Intern); + mkSymbol(new Number("276"), "char", Intern); + mkSymbol(new Number("277"), "skip", Intern); + mkSymbol(new Number("278"), "line", Intern); + mkSymbol(new Number("279"), "load", Intern); + mkSymbol(new Number("280"), "in", Intern); + mkSymbol(new Number("281"), "out", Intern); + mkSymbol(new Number("282"), "ctl", Intern); + mkSymbol(new Number("283"), "open", Intern); + mkSymbol(new Number("284"), "close", Intern); + mkSymbol(new Number("285"), "prin", Intern); + mkSymbol(new Number("286"), "prinl", Intern); + mkSymbol(new Number("287"), "space", Intern); + mkSymbol(new Number("288"), "print", Intern); + mkSymbol(new Number("289"), "printsp", Intern); + mkSymbol(new Number("290"), "println", Intern); + mkSymbol(new Number("291"), "flush", Intern); + mkSymbol(new Number("292"), "port", Intern); + mkSymbol(new Number("293"), "accept", Intern); + mkSymbol(new Number("294"), "connect", Intern); + MaxFun = 294; + init(); for (boolean first = true; ; first = false) { try { if (first) @@ -364,6 +381,35 @@ public class PicoLisp { Home = s.substring(0, i+1); break; } + try { + if (Term != null) { + final Pipe p = Pipe.open(); + StdIn.Chan = p.source(); + StdIn.Ops = SelectionKey.OP_READ; + (new Thread() { + public void run() { + for (;;) { + String s = Term.readLine(); + if (s == null) + Line = null; + else { + Line = new StringBuilder(s); + Line.append('\n'); + } + try {p.sink().write(ByteBuffer.allocate(1));} + catch (IOException e) {giveup(e);} + } + } + } ).start(); + } + } + catch (IOException e) {giveup(e);} + USec = System.nanoTime() / 1000; + } + + final static void giveup(Exception e) { + System.err.println(e); + System.exit(1); } final static Any bye(int n) { @@ -376,6 +422,66 @@ public class PicoLisp { return null; /* Brain-dead Java */ } + final static int waitFd(Any ex, int fd, int ms) { + int i; + Selector sel; + Any task = Env.Task, at = At.Car; + try { + for (;;) { + sel = Selector.open(); + int t = ms >= 0? ms : Integer.MAX_VALUE; + if (fd >= 0 && InFiles[fd] != null) + InFiles[fd].register(sel); + for (Any x = Env.Task = Run.Car; x instanceof Cell; x = x.Cdr) { + if (memq(x.Car, task) == null) { + if ((i = ((Number)x.Car.Car).Cnt) < 0) { + if ((i = ((Number)x.Car.Cdr.Car).Cnt) < t) + t = i; + } + else if (i != fd) { + if (i < InFiles.length && InFiles[i] != null) + InFiles[i].register(sel); + } + } + } + long d = System.currentTimeMillis(); + if (t == 0) + sel.selectNow(); + else + sel.select(t); + t = (int)(System.currentTimeMillis() - d); + if (ms > 0 && (ms -= t) < 0) + ms = 0; + for (Any x = Env.Task; x instanceof Cell; x = x.Cdr) { + if (memq(x.Car, task) == null) { + if ((i = ((Number)x.Car.Car).Cnt) < 0) { + if ((i = ((Number)x.Car.Cdr.Car).Cnt - t) > 0) + ((Number)x.Car.Cdr.Car).Cnt = i; + else { + ((Number)x.Car.Cdr.Car).Cnt = -((Number)x.Car.Car).Cnt; + At.Car = x.Car.Car; + x.Car.Cdr.Cdr.prog(); + } + } + else if (i != fd) { + if (i < InFiles.length && InFiles[i] != null && InFiles[i].isReady(sel)) { + At.Car = x.Car.Car; + x.Car.Cdr.prog(); + } + } + } + } + if (ms == 0 || fd < 0 || InFiles[fd] != null && InFiles[fd].isReady(sel)) + break; + sel.close(); + } + } + catch (IOException e) {giveup(e);} + At.Car = at; + Env.Task = task; + return ms; + } + final static long initSeed(Any x) { long n; for (n = 0; x instanceof Cell; x = x.Cdr) @@ -539,7 +645,7 @@ public class PicoLisp { unwind(null); Env.Args = null; Env.Next = 0; - Env.Make = Env.Yoke = null; + Env.Task = Env.Make = Env.Yoke = null; } final static Any err(Any ex, Any x, String msg) { @@ -591,6 +697,8 @@ public class PicoLisp { final static Any execError(Any x) {return err(null, x, "Can't execute");} final static Any protError(Any x) {return err(null, x, "Protected symbol");} final static Any symError(Any x) {return err(null, x, "Symbol expected");} + final static Any argError(Any ex, Any x) {return err(ex, x, "Bad argument");} + final static Any cntError(Any ex, Any x) {return err(ex, x, "Small number expected");} final static void needVar(Any ex, Any x) {if (x instanceof Number) err(ex, x, "Variable expected");} final static void badFd(Any ex, Any x) {err(ex, x, "Bad FD");} @@ -690,6 +798,14 @@ public class PicoLisp { return i; } + final static Any mkSocket(SocketChannel chan) throws IOException { + int i = allocFd(); + Socket sock = chan.socket(); + new PicoLispReader(sock.getInputStream(), i, chan, SelectionKey.OP_READ); + new PicoLispWriter(sock.getOutputStream(), i); + return new Number(i); + } + final static Any mkChar(char c) {return new Symbol(null, "" + c);} final static Any mkStr(String nm) {return nm == null || nm.length() == 0? Nil : new Symbol(null, nm);} final static Any mkStr(StringBuilder sb) {return mkStr(sb.toString());} @@ -726,33 +842,10 @@ public class PicoLisp { if ((x = x.Cdr) instanceof Cell) ign = firstChar(x.Car.eval()); } - StringBuilder sb = new StringBuilder(); - if (z instanceof Number) { - String s = z.toString(); - if (s.charAt(0) == '-') { - sb.append('-'); - s = s.substring(1); - } - if ((scl = s.length() - scl - 1) < 0) { - sb.append('0'); - sb.append(sep); - while (scl < -1) { - sb.append('0'); - ++scl; - } - } - for (int i = 0;;) { - sb.append(s.charAt(i++)); - if (i == s.length()) - return mkStr(sb); - if (scl == 0) - sb.append(sep); - else if (ign != '\0' && scl > 0 && scl % 3 == 0) - sb.append(ign); - --scl; - } - } + if (z instanceof Number) + return mkStr(((Number)z).toString(scl,sep,ign)); String s = z.name(); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); ++i) { char c = s.charAt(i); if (c != ign) @@ -1460,30 +1553,59 @@ public class PicoLisp { LineNumberReader Rd; String Name; char Eof1, Eof2; - int Fd, Chr, Src; + int Fd, Chr, Src, Ops; + SelectableChannel Chan; + SelectionKey Key; - PicoLispReader(Reader rd, String nm, int fd) { - Rd = new LineNumberReader(rd); + PicoLispReader(Reader rd, String nm, int fd, SelectableChannel chan, int ops) { + if (rd != null) + Rd = new LineNumberReader(rd); Name = nm; - if (fd < 0) - fd = allocFd(); InFiles[Fd = fd] = this; + Chan = chan; + Ops = ops; } - PicoLispReader(InputStream in, int fd) { - this(new InputStreamReader(in), null, fd); + PicoLispReader(InputStream in, int fd, SelectableChannel chan, int ops) { + this(in == null? null : new InputStreamReader(in), null, fd, chan, ops); } PicoLispReader(String s, char eof1, char eof2) { - this(new StringReader(s), null, -1); + Rd = new LineNumberReader(new StringReader(s)); Eof1 = eof1; Eof2 = eof2; } + final boolean register(Selector sel) { + if (Ops != 0) { + try { + Chan.configureBlocking(false); + Key = Chan.register(sel, Ops); + return true; + } + catch (IOException e) {} + } + return false; + } + + final boolean isReady(Selector sel) { + boolean rdy = false; + if (Key != null) { + rdy = (Key.readyOps() & Ops) != 0; + Key.cancel(); + try{Chan.configureBlocking(true);} + catch (IOException e) {} + } + return rdy; + } + final void close() { try { + if (Chan != null) + Chan.close(); + if (Rd != null) + Rd.close(); InFiles[Fd] = null; - Rd.close(); } catch (IOException e) {closeErr(e);} } @@ -1492,7 +1614,22 @@ public class PicoLisp { final int get() { try { - if ((Chr = Rd.read()) < 0) { + if (this != StdIn || Term == null) + Chr = Rd.read(); + else { + if (Line == null) { + waitFd(null, 0, -1); + ((Pipe.SourceChannel)StdIn.Chan).read(ByteBuffer.allocate(1)); + } + if (Line == null) + Chr = -1; + else { + Chr = Line.charAt(0); + if (Line.deleteCharAt(0).length() == 0) + Line = null; + } + } + if (Chr < 0) { if ((Chr = Eof1) != 0) Eof1 = '\0'; else if ((Chr = Eof2) != 0) @@ -1733,8 +1870,6 @@ public class PicoLisp { PicoLispWriter(PrintWriter wr, String nm, int fd) { Wr = wr; Name = nm; - if (fd < 0) - fd = allocFd(); OutFiles[Fd = fd] = this; } @@ -1743,8 +1878,8 @@ public class PicoLisp { } final void close() { - OutFiles[Fd] = null; Wr.close(); + OutFiles[Fd] = null; } final void print(Any x) {Wr.print(x.toString());} @@ -1773,7 +1908,7 @@ public class PicoLisp { final static class Env { int Next, ArgC, Trace; Bind Bind; - Any Arg, Args[], Cls, Key, Make, Yoke; + Any Arg, Args[], Cls, Key, Task, Make, Yoke; InFrame InFrames; OutFrame OutFrames; @@ -1784,6 +1919,7 @@ public class PicoLisp { Bind = env.Bind; Arg = env.Arg; Args = env.Args; Cls = env.Cls; Key = env.Key; + Task = env.Task; Make = env.Make; Yoke = env.Yoke; InFrames = env.InFrames; OutFrames = env.OutFrames; } @@ -1932,566 +2068,590 @@ public class PicoLisp { return doMeth(ex); case 2: // quit return do2(ex); - case 3: // args - return Env.Next < Env.ArgC? T : Nil; - case 4: // next + case 3: // public + return do3(ex); + case 4: // java return do4(ex); - case 5: // arg + case 5: // byte: return do5(ex); - case 6: // rest + case 6: // char: return do6(ex); - case 7: // date + case 7: // int: return do7(ex); - case 8: // time + case 8: // long: return do8(ex); - case 9: // usec + case 9: // double: return do9(ex); - case 10: // file + case 10: // big: return do10(ex); - case 11: // version + case 11: // data return do11(ex); - case 12: // apply - return do12(ex); - case 13: // pass + case 12: // args + return Env.Next < Env.ArgC? T : Nil; + case 13: // next return do13(ex); - case 14: // maps + case 14: // arg return do14(ex); - case 15: // map + case 15: // rest return do15(ex); - case 16: // mapc + case 16: // date return do16(ex); - case 17: // maplist + case 17: // time return do17(ex); - case 18: // mapcar + case 18: // usec return do18(ex); - case 19: // mapcon + case 19: // file return do19(ex); - case 20: // mapcan + case 20: // version return do20(ex); - case 21: // filter + case 21: // apply return do21(ex); - case 22: // extract + case 22: // pass return do22(ex); - case 23: // seek + case 23: // maps return do23(ex); - case 24: // find + case 24: // map return do24(ex); - case 25: // pick + case 25: // mapc return do25(ex); - case 26: // cnt + case 26: // maplist return do26(ex); - case 27: // sum + case 27: // mapcar return do27(ex); - case 28: // maxi + case 28: // mapcon return do28(ex); - case 29: // mini + case 29: // mapcan return do29(ex); - case 30: // fish + case 30: // filter return do30(ex); - case 31: // by + case 31: // extract return do31(ex); - case 32: // as + case 32: // seek return do32(ex); - case 33: // lit + case 33: // find return do33(ex); - case 34: // eval + case 34: // pick return do34(ex); - case 35: // run + case 35: // cnt return do35(ex); - case 36: // def + case 36: // sum return do36(ex); - case 37: // de + case 37: // maxi return do37(ex); - case 38: // dm + case 38: // mini return do38(ex); - case 39: // box + case 39: // fish return do39(ex); - case 40: // new + case 40: // by return do40(ex); - case 41: // type + case 41: // as return do41(ex); - case 42: // isa + case 42: // lit return do42(ex); - case 43: // method + case 43: // eval return do43(ex); - case 44: // send + case 44: // run return do44(ex); - case 45: // try + case 45: // def return do45(ex); - case 46: // super + case 46: // de return do46(ex); - case 47: // extra + case 47: // dm return do47(ex); - case 48: // with + case 48: // box return do48(ex); - case 49: // bind + case 49: // new return do49(ex); - case 50: // job + case 50: // type return do50(ex); - case 51: // let + case 51: // isa return do51(ex); - case 52: // let? + case 52: // method return do52(ex); - case 53: // use + case 53: // send return do53(ex); - case 54: // and + case 54: // try return do54(ex); - case 55: // or + case 55: // super return do55(ex); - case 56: // nand + case 56: // extra return do56(ex); - case 57: // nor + case 57: // with return do57(ex); - case 58: // xor + case 58: // bind return do58(ex); - case 59: // bool + case 59: // job return do59(ex); - case 60: // not + case 60: // let return do60(ex); - case 61: // nil + case 61: // let? return do61(ex); - case 62: // t + case 62: // use return do62(ex); - case 63: // prog - return ex.Cdr.prog(); - case 64: // prog1 + case 63: // and + return do63(ex); + case 64: // or return do64(ex); - case 65: // prog2 + case 65: // nand return do65(ex); - case 66: // if + case 66: // nor return do66(ex); - case 67: // if2 + case 67: // xor return do67(ex); - case 68: // ifn + case 68: // bool return do68(ex); - case 69: // when + case 69: // not return do69(ex); - case 70: // unless + case 70: // nil return do70(ex); - case 71: // cond + case 71: // t return do71(ex); - case 72: // nond - return do72(ex); - case 73: // case + case 72: // prog + return ex.Cdr.prog(); + case 73: // prog1 return do73(ex); - case 74: // state + case 74: // prog2 return do74(ex); - case 75: // while + case 75: // if return do75(ex); - case 76: // until + case 76: // if2 return do76(ex); - case 77: // do + case 77: // ifn return do77(ex); - case 78: // loop - return loop(ex.Cdr); - case 79: // at + case 78: // when + return do78(ex); + case 79: // unless return do79(ex); - case 80: // for + case 80: // cond return do80(ex); - case 81: // catch + case 81: // nond return do81(ex); - case 82: // throw + case 82: // case return do82(ex); - case 83: // finally + case 83: // state return do83(ex); - case 84: // ! + case 84: // while return do84(ex); - case 85: // e + case 85: // until return do85(ex); - case 86: // $ + case 86: // do return do86(ex); - case 87: // sys - return do87(ex); - case 88: // call + case 87: // loop + return loop(ex.Cdr); + case 88: // at return do88(ex); - case 89: // ipid + case 89: // for return do89(ex); - case 90: // opid + case 90: // catch return do90(ex); - case 91: // kill + case 91: // throw return do91(ex); - case 92: // bye + case 92: // finally return do92(ex); - case 93: // name + case 93: // ! return do93(ex); - case 94: // sp? + case 94: // e return do94(ex); - case 95: // pat? + case 95: // $ return do95(ex); - case 96: // fun? + case 96: // sys return do96(ex); - case 97: // getd + case 97: // call return do97(ex); - case 98: // all + case 98: // ipid return do98(ex); - case 99: // intern + case 99: // opid return do99(ex); - case 100: // ==== + case 100: // kill return do100(ex); - case 101: // box? + case 101: // bye return do101(ex); - case 102: // str? + case 102: // name return do102(ex); - case 103: // zap + case 103: // sp? return do103(ex); - case 104: // chop + case 104: // pat? return do104(ex); - case 105: // pack + case 105: // fun? return do105(ex); - case 106: // glue + case 106: // getd return do106(ex); - case 107: // text + case 107: // all return do107(ex); - case 108: // pre? + case 108: // intern return do108(ex); - case 109: // sub? + case 109: // ==== return do109(ex); - case 110: // val - return ex.Cdr.Car.eval().Car; - case 111: // set + case 110: // box? + return do110(ex); + case 111: // str? return do111(ex); - case 112: // setq + case 112: // zap return do112(ex); - case 113: // xchg + case 113: // chop return do113(ex); - case 114: // on + case 114: // pack return do114(ex); - case 115: // off + case 115: // glue return do115(ex); - case 116: // onOff + case 116: // text return do116(ex); - case 117: // zero + case 117: // pre? return do117(ex); - case 118: // one + case 118: // sub? return do118(ex); - case 119: // default - return do119(ex); - case 120: // push + case 119: // val + return ex.Cdr.Car.eval().Car; + case 120: // set return do120(ex); - case 121: // push1 + case 121: // setq return do121(ex); - case 122: // pop + case 122: // xchg return do122(ex); - case 123: // cut + case 123: // on return do123(ex); - case 124: // del + case 124: // off return do124(ex); - case 125: // queue + case 125: // onOff return do125(ex); - case 126: // fifo + case 126: // zero return do126(ex); - case 127: // idx + case 127: // one return do127(ex); - case 128: // lup + case 128: // default return do128(ex); - case 129: // put + case 129: // push return do129(ex); - case 130: // get + case 130: // push1 return do130(ex); - case 131: // prop + case 131: // pop return do131(ex); - case 132: // ; + case 132: // cut return do132(ex); - case 133: // =: + case 133: // del return do133(ex); - case 134: // : + case 134: // queue return do134(ex); - case 135: // :: + case 135: // fifo return do135(ex); - case 136: // putl + case 136: // idx return do136(ex); - case 137: // getl + case 137: // lup return do137(ex); - case 138: // meta + case 138: // put return do138(ex); - case 139: // low? + case 139: // get return do139(ex); - case 140: // upp? + case 140: // prop return do140(ex); - case 141: // lowc + case 141: // ; return do141(ex); - case 142: // uppc + case 142: // =: return do142(ex); - case 143: // fold + case 143: // : return do143(ex); - case 144: // car + case 144: // :: + return do144(ex); + case 145: // putl + return do145(ex); + case 146: // getl + return do146(ex); + case 147: // meta + return do147(ex); + case 148: // low? + return do148(ex); + case 149: // upp? + return do149(ex); + case 150: // lowc + return do150(ex); + case 151: // uppc + return do151(ex); + case 152: // fold + return do152(ex); + case 153: // car return ex.Cdr.Car.eval().Car; - case 145: // cdr + case 154: // cdr return ex.Cdr.Car.eval().Cdr; - case 146: // caar + case 155: // caar return ex.Cdr.Car.eval().Car.Car; - case 147: // cadr + case 156: // cadr return ex.Cdr.Car.eval().Cdr.Car; - case 148: // cdar + case 157: // cdar return ex.Cdr.Car.eval().Car.Cdr; - case 149: // cddr + case 158: // cddr return ex.Cdr.Car.eval().Cdr.Cdr; - case 150: // caaar - return do150(ex); - case 151: // caadr - return do151(ex); - case 152: // cadar - return do152(ex); - case 153: // caddr - return do153(ex); - case 154: // cdaar - return do154(ex); - case 155: // cdadr - return do155(ex); - case 156: // cddar - return do156(ex); - case 157: // cdddr - return do157(ex); - case 158: // caaaar - return do158(ex); - case 159: // caaadr + case 159: // caaar return do159(ex); - case 160: // caadar + case 160: // caadr return do160(ex); - case 161: // caaddr + case 161: // cadar return do161(ex); - case 162: // cadaar + case 162: // caddr return do162(ex); - case 163: // cadadr + case 163: // cdaar return do163(ex); - case 164: // caddar + case 164: // cdadr return do164(ex); - case 165: // cadddr + case 165: // cddar return do165(ex); - case 166: // cdaaar + case 166: // cdddr return do166(ex); - case 167: // cdaadr + case 167: // caaaar return do167(ex); - case 168: // cdadar + case 168: // caaadr return do168(ex); - case 169: // cdaddr + case 169: // caadar return do169(ex); - case 170: // cddaar + case 170: // caaddr return do170(ex); - case 171: // cddadr + case 171: // cadaar return do171(ex); - case 172: // cdddar + case 172: // cadadr return do172(ex); - case 173: // cddddr + case 173: // caddar return do173(ex); - case 174: // nth + case 174: // cadddr return do174(ex); - case 175: // con + case 175: // cdaaar return do175(ex); - case 176: // cons + case 176: // cdaadr return do176(ex); - case 177: // conc + case 177: // cdadar return do177(ex); - case 178: // circ + case 178: // cdaddr return do178(ex); - case 179: // rot + case 179: // cddaar return do179(ex); - case 180: // list + case 180: // cddadr return do180(ex); - case 181: // need + case 181: // cdddar return do181(ex); - case 182: // range + case 182: // cddddr return do182(ex); - case 183: // full + case 183: // nth return do183(ex); - case 184: // make + case 184: // con return do184(ex); - case 185: // made + case 185: // cons return do185(ex); - case 186: // chain + case 186: // conc return do186(ex); - case 187: // link + case 187: // circ return do187(ex); - case 188: // yoke + case 188: // rot return do188(ex); - case 189: // copy + case 189: // list return do189(ex); - case 190: // mix + case 190: // need return do190(ex); - case 191: // append + case 191: // range return do191(ex); - case 192: // delete + case 192: // full return do192(ex); - case 193: // delq + case 193: // make return do193(ex); - case 194: // replace + case 194: // made return do194(ex); - case 195: // strip + case 195: // chain return do195(ex); - case 196: // split + case 196: // link return do196(ex); - case 197: // reverse + case 197: // yoke return do197(ex); - case 198: // flip + case 198: // copy return do198(ex); - case 199: // trim + case 199: // mix return do199(ex); - case 200: // clip + case 200: // append return do200(ex); - case 201: // head + case 201: // delete return do201(ex); - case 202: // tail + case 202: // delq return do202(ex); - case 203: // stem + case 203: // replace return do203(ex); - case 204: // fin + case 204: // strip return do204(ex); - case 205: // last + case 205: // split return do205(ex); - case 206: // == + case 206: // reverse return do206(ex); - case 207: // n== + case 207: // flip return do207(ex); - case 208: // = + case 208: // trim return do208(ex); - case 209: // <> + case 209: // clip return do209(ex); - case 210: // =0 + case 210: // head return do210(ex); - case 211: // =T + case 211: // tail return do211(ex); - case 212: // n0 + case 212: // stem return do212(ex); - case 213: // nT + case 213: // fin return do213(ex); - case 214: // < + case 214: // last return do214(ex); - case 215: // <= + case 215: // == return do215(ex); - case 216: // > + case 216: // n== return do216(ex); - case 217: // >= + case 217: // = return do217(ex); - case 218: // max + case 218: // <> return do218(ex); - case 219: // min + case 219: // =0 return do219(ex); - case 220: // atom + case 220: // =T return do220(ex); - case 221: // pair + case 221: // n0 return do221(ex); - case 222: // lst? + case 222: // nT return do222(ex); - case 223: // num? + case 223: // < return do223(ex); - case 224: // sym? + case 224: // <= return do224(ex); - case 225: // flg? + case 225: // > return do225(ex); - case 226: // member + case 226: // >= return do226(ex); - case 227: // memq + case 227: // max return do227(ex); - case 228: // mmeq + case 228: // min return do228(ex); - case 229: // sect + case 229: // atom return do229(ex); - case 230: // diff + case 230: // pair return do230(ex); - case 231: // index + case 231: // lst? return do231(ex); - case 232: // offset + case 232: // num? return do232(ex); - case 233: // length + case 233: // sym? return do233(ex); - case 234: // size + case 234: // flg? return do234(ex); - case 235: // assoc + case 235: // member return do235(ex); - case 236: // asoq + case 236: // memq return do236(ex); - case 237: // rank + case 237: // mmeq return do237(ex); - case 238: // match + case 238: // sect return do238(ex); - case 239: // fill + case 239: // diff return do239(ex); - case 240: // prove + case 240: // index return do240(ex); - case 241: // -> + case 241: // offset return do241(ex); - case 242: // unify + case 242: // length return do242(ex); - case 243: // sort + case 243: // size return do243(ex); - case 244: // format + case 244: // assoc return do244(ex); - case 245: // + + case 245: // asoq return do245(ex); - case 246: // - + case 246: // rank return do246(ex); - case 247: // inc + case 247: // match return do247(ex); - case 248: // dec + case 248: // fill return do248(ex); - case 249: // * + case 249: // prove return do249(ex); - case 250: // */ + case 250: // -> return do250(ex); - case 251: // / + case 251: // unify return do251(ex); - case 252: // % + case 252: // sort return do252(ex); - case 253: // >> + case 253: // format return do253(ex); - case 254: // lt0 + case 254: // + return do254(ex); - case 255: // ge0 + case 255: // - return do255(ex); - case 256: // gt0 + case 256: // inc return do256(ex); - case 257: // abs + case 257: // dec return do257(ex); - case 258: // bit? + case 258: // * return do258(ex); - case 259: // & + case 259: // */ return do259(ex); - case 260: // | + case 260: // / return do260(ex); - case 261: // x| + case 261: // % return do261(ex); - case 262: // seed + case 262: // >> return do262(ex); - case 263: // rand + case 263: // lt0 return do263(ex); - case 264: // path + case 264: // ge0 return do264(ex); - case 265: // read + case 265: // gt0 return do265(ex); - case 266: // char + case 266: // abs return do266(ex); - case 267: // skip + case 267: // bit? return do267(ex); - case 268: // line + case 268: // & return do268(ex); - case 269: // load + case 269: // | return do269(ex); - case 270: // in + case 270: // x| return do270(ex); - case 271: // out + case 271: // seed return do271(ex); - case 272: // ctl + case 272: // rand return do272(ex); - case 273: // open + case 273: // path return do273(ex); - case 274: // close + case 274: // read return do274(ex); - case 275: // prin + case 275: // wait return do275(ex); - case 276: // prinl + case 276: // char return do276(ex); - case 277: // space + case 277: // skip return do277(ex); - case 278: // print + case 278: // line return do278(ex); - case 279: // printsp + case 279: // load return do279(ex); - case 280: // println + case 280: // in return do280(ex); - case 281: // flush + case 281: // out return do281(ex); - case 282: // connect + case 282: // ctl return do282(ex); + case 283: // open + return do283(ex); + case 284: // close + return do284(ex); + case 285: // prin + return do285(ex); + case 286: // prinl + return do286(ex); + case 287: // space + return do287(ex); + case 288: // print + return do288(ex); + case 289: // printsp + return do289(ex); + case 290: // println + return do290(ex); + case 291: // flush + return do291(ex); + case 292: // port + return do292(ex); + case 293: // accept + return do293(ex); + case 294: // connect + return do294(ex); default: return undefined(this, ex); } @@ -2521,18 +2681,200 @@ public class PicoLisp { return err(null, (ex = ex.Cdr) instanceof Cell? ex.Car.eval() : null, str); } - final static Any do4(Any ex) { // next + final static Any do3(Any ex) { // public + Any x, y, z; + Symbol s; + Object o; + y = (x = ex.Cdr).Car.eval(); + z = (x = x.Cdr).Car.eval(); + try { + if ((s = (Symbol)y).Obj != null) + o = s.Obj.getClass().getField(z.name()).get(s.Obj); + else { + java.lang.Class cls = java.lang.Class.forName(s.Name); + o = cls.getField(z.name()).get(cls); + } + return new Symbol(o); + } + catch (Exception e) {return err(ex, null, e.toString());} + } + + final static Any do4(Any ex) { // java + int i, j, k; + Any x, y, z; + Symbol s; + Number num; + Any[] v; + Object o; + y = (x = ex.Cdr).Car.eval(); + z = (x = x.Cdr).Car.eval(); + for (v = new Any[6], i = 0; (x = x.Cdr) instanceof Cell;) + v = append(v, i++, x.Car.eval()); + Object[] arg = new Object[i]; + Class[] par = new Class[i]; + while (--i >= 0) { + if (v[i] == Nil || v[i] == T) { + arg[i] = v[i] == T; + par[i] = Boolean.TYPE; + } + else if (v[i] instanceof Number) { + if ((num = (Number)v[i]).Big != null) + cntError(ex, num); + arg[i] = new Integer(num.Cnt); + par[i] = Integer.TYPE; + } + else if (v[i] instanceof Cell) { + k = (int)v[i].length(); + if (v[i].Car instanceof Number) { + arg[i] = new int[k]; + for (j = 0; j < k; ++j, v[i] = v[i].Cdr) + Array.setInt(arg[i], j, ((Number)v[i].Car).Cnt); + } + else if (v[i].Car instanceof Cell) + argError(ex, v[i]); + else if ((s = (Symbol)v[i].Car).Obj == null) { + arg[i] = Array.newInstance(s.Name.getClass(), k); + for (j = 0; j < k; ++j, v[i] = v[i].Cdr) + Array.set(arg[i], j, ((Symbol)v[i].Car).Name); + } + else { + if (s.Obj instanceof Byte) + arg[i] = Array.newInstance(Byte.TYPE, k); + else if (s.Obj instanceof Character) + arg[i] = Array.newInstance(Character.TYPE, k); + else if (s.Obj instanceof Integer) + arg[i] = Array.newInstance(Integer.TYPE, k); + else if (s.Obj instanceof Long) + arg[i] = Array.newInstance(Long.TYPE, k); + else + arg[i] = Array.newInstance(s.Obj.getClass(), k); + for (j = 0; j < k; ++j, v[i] = v[i].Cdr) + Array.set(arg[i], j, ((Symbol)v[i].Car).Obj); + } + par[i] = arg[i].getClass(); + } + else if ((s = (Symbol)v[i]).Obj == null) + par[i] = (arg[i] = s.Name).getClass(); + else { + arg[i] = s.Obj; + if (s.Obj instanceof Byte) + par[i] = Byte.TYPE; + else if (s.Obj instanceof Character) + par[i] = Character.TYPE; + else if (s.Obj instanceof Integer) + par[i] = Integer.TYPE; + else if (s.Obj instanceof Long) + par[i] = Long.TYPE; + else + par[i] = s.Obj.getClass(); + } + } + try { + if (z == T) + return new Symbol(java.lang.Class.forName(y.name()).getConstructor(par).newInstance(arg)); + Method m = (s = (Symbol)y).Obj == null? java.lang.Class.forName(s.Name).getMethod(z.name(),par) : s.Obj.getClass().getMethod(z.name(),par); + o = m.invoke(s.Obj, arg); + if (m.getReturnType() == Void.TYPE) + return Nil; + return new Symbol(o); + } + catch (Exception e) {return err(ex, null, e.toString());} + } + + final static Any do5(Any ex) { // byte: + Any x; + x = ex.Cdr.Car.eval(); + return new Symbol(new Byte(x instanceof Number? (byte)((Number)x).Cnt : (byte)x.name().charAt(0))); + } + + final static Any do6(Any ex) { // char: + Any x; + x = ex.Cdr.Car.eval(); + return new Symbol(new Character(x instanceof Number? (char)((Number)x).Cnt : x.name().charAt(0))); + } + + final static Any do7(Any ex) { // int: + return new Symbol(new Integer(evInt(ex.Cdr))); + } + + final static Any do8(Any ex) { // long: + return new Symbol(new Long(evLong(ex.Cdr))); + } + + final static Any do9(Any ex) { // double: + Number num; + num = (Number)((ex = ex.Cdr).Car.eval()); + return new Symbol(new Double(num.toString(evInt(ex.Cdr), '.', '\0'))); + } + + final static Any do10(Any ex) { // big: + Number num; + num = (Number)(ex.Cdr.Car.eval()); + return new Symbol(num.Big == null? big(num.Cnt) : num.Big); + } + + final static Any do11(Any ex) { // data + int i, j; + Any x, y; + Symbol s; + x = Nil; + if ((y = ex.Cdr.Car.eval()) instanceof Symbol && (s = (Symbol)y).Obj != null) { + if (s.Obj instanceof Byte) + x = new Number(((Byte)s.Obj).byteValue()); + else if (s.Obj instanceof Character) + x = new Number(((Character)s.Obj).charValue()); + else if (s.Obj instanceof Integer) + x = new Number(((Integer)s.Obj).intValue()); + else if (s.Obj instanceof Long) + x = new Number(((Long)s.Obj).longValue()); + else if (s.Obj instanceof Double) + x = strToNum(Double.toString(((Double)s.Obj).doubleValue()), evInt(ex.Cdr.Cdr)); + else if (s.Obj instanceof BigInteger) + x = new Number((BigInteger)s.Obj); + else if (s.Obj instanceof String) + x = mkStr((String)s.Obj); + else if (s.Obj instanceof byte[]) { + byte[] a = (byte[])s.Obj; + for (i = a.length; --i >= 0;) + x = new Cell(new Number(a[i]), x); + } + else if (s.Obj instanceof char[]) { + char[] a = (char[])s.Obj; + for (i = a.length; --i >= 0;) + x = new Cell(new Number(a[i]), x); + } + else if (s.Obj instanceof int[]) { + int[] a = (int[])s.Obj; + for (i = a.length; --i >= 0;) + x = new Cell(new Number(a[i]), x); + } + else if (s.Obj instanceof long[]) { + long[] a = (long[])s.Obj; + for (i = a.length; --i >= 0;) + x = new Cell(new Number(a[i]), x); + } + else if (s.Obj instanceof double[]) { + double[] a = (double[])s.Obj; + j = evInt(ex.Cdr.Cdr); + for (i = a.length; --i >= 0;) + x = new Cell(strToNum(Double.toString(a[i]), i), x); + } + } + return x; + } + + final static Any do13(Any ex) { // next return Env.Next < Env.ArgC? (Env.Arg = Env.Args[Env.Next++]) : Nil; } - final static Any do5(Any ex) { // arg + final static Any do14(Any ex) { // arg int i; if (ex.Cdr instanceof Cell) return (i = evInt(ex.Cdr)+Env.Next-1) >= 0 && i < Env.ArgC? Env.Args[i] : Nil; return Env.Arg; } - final static Any do6(Any ex) { // rest + final static Any do15(Any ex) { // rest int i; Any x; for (x = Nil, i = Env.ArgC; --i >= Env.Next;) @@ -2540,7 +2882,7 @@ public class PicoLisp { return x; } - final static Any do7(Any ex) { // date + final static Any do16(Any ex) { // date int i, j; Any x, z; if (!((x = ex.Cdr) instanceof Cell)) { @@ -2562,7 +2904,7 @@ public class PicoLisp { return date(i, j, evInt(x.Cdr)); } - final static Any do8(Any ex) { // time + final static Any do17(Any ex) { // time int i, j; Any x, z; if (!((x = ex.Cdr) instanceof Cell)) @@ -2580,11 +2922,11 @@ public class PicoLisp { return time(i, j, x.Cdr instanceof Cell? evInt(x.Cdr) : 0); } - final static Any do9(Any ex) { // usec + final static Any do18(Any ex) { // usec return new Number(System.nanoTime()/1000 - USec); } - final static Any do10(Any ex) { // file + final static Any do19(Any ex) { // file int i; Any x; if (InFile.Name == null) @@ -2595,7 +2937,7 @@ public class PicoLisp { return new Cell(mkStr("./"), new Cell(mkStr(InFile.Name), x)); } - final static Any do11(Any ex) { // version + final static Any do20(Any ex) { // version int i; Any x; if (ex.Cdr.Car.eval() == Nil) { @@ -2609,7 +2951,7 @@ public class PicoLisp { return x; } - final static Any do12(Any ex) { // apply + final static Any do21(Any ex) { // apply int i; Any w, x, y; Any[] v; @@ -2624,7 +2966,7 @@ public class PicoLisp { return w.apply(ex, false, v, i); } - final static Any do13(Any ex) { // pass + final static Any do22(Any ex) { // pass int i, j; Any w, x; Any[] v; @@ -2636,7 +2978,7 @@ public class PicoLisp { return w.apply(ex, false, v, i); } - final static Any do14(Any ex) { // maps + final static Any do23(Any ex) { // maps int i, j, k; Any w, x, y; Symbol s; @@ -2661,7 +3003,7 @@ public class PicoLisp { return x; } - final static Any do15(Any ex) { // map + final static Any do24(Any ex) { // map int i, j; Any w, x, y; Any[] v; @@ -2681,7 +3023,7 @@ public class PicoLisp { return x; } - final static Any do16(Any ex) { // mapc + final static Any do25(Any ex) { // mapc int i, j; Any w, x, y; Any[] v; @@ -2701,7 +3043,7 @@ public class PicoLisp { return x; } - final static Any do17(Any ex) { // maplist + final static Any do26(Any ex) { // maplist int i, j; Any w, x, z; Any[] v; @@ -2725,7 +3067,7 @@ public class PicoLisp { return z; } - final static Any do18(Any ex) { // mapcar + final static Any do27(Any ex) { // mapcar int i, j; Any w, x, z; Any[] v; @@ -2749,7 +3091,7 @@ public class PicoLisp { return z; } - final static Any do19(Any ex) { // mapcon + final static Any do28(Any ex) { // mapcon int i, j; Any w, x, z; Any[] v; @@ -2781,7 +3123,7 @@ public class PicoLisp { return z; } - final static Any do20(Any ex) { // mapcan + final static Any do29(Any ex) { // mapcan int i, j; Any w, x, z; Any[] v; @@ -2813,7 +3155,7 @@ public class PicoLisp { return z; } - final static Any do21(Any ex) { // filter + final static Any do30(Any ex) { // filter int i, j; Any w, x, z; Any[] v; @@ -2844,7 +3186,7 @@ public class PicoLisp { return z; } - final static Any do22(Any ex) { // extract + final static Any do31(Any ex) { // extract int i, j; Any w, x, y, z; Any[] v; @@ -2875,7 +3217,7 @@ public class PicoLisp { return z; } - final static Any do23(Any ex) { // seek + final static Any do32(Any ex) { // seek int i, j; Any w, x; Any[] v; @@ -2896,7 +3238,7 @@ public class PicoLisp { return Nil; } - final static Any do24(Any ex) { // find + final static Any do33(Any ex) { // find int i, j; Any w, x; Any[] v; @@ -2917,7 +3259,7 @@ public class PicoLisp { return Nil; } - final static Any do25(Any ex) { // pick + final static Any do34(Any ex) { // pick int i, j; Any w, x; Any[] v; @@ -2938,7 +3280,7 @@ public class PicoLisp { return Nil; } - final static Any do26(Any ex) { // cnt + final static Any do35(Any ex) { // cnt int i, j; long n; Any w, x; @@ -2961,7 +3303,7 @@ public class PicoLisp { return new Number(n); } - final static Any do27(Any ex) { // sum + final static Any do36(Any ex) { // sum int i, j; Any w, x, y; Number num; @@ -2984,7 +3326,7 @@ public class PicoLisp { return num; } - final static Any do28(Any ex) { // maxi + final static Any do37(Any ex) { // maxi int i, j; Any w, x, y, z; Any[] v; @@ -3008,7 +3350,7 @@ public class PicoLisp { return z; } - final static Any do29(Any ex) { // mini + final static Any do38(Any ex) { // mini int i, j; Any w, x, y, z; Any[] v; @@ -3033,7 +3375,7 @@ public class PicoLisp { return z; } - final static Any do30(Any ex) { // fish + final static Any do39(Any ex) { // fish Any w; Any[] v; w = ex.Cdr.Car.eval(); @@ -3041,7 +3383,7 @@ public class PicoLisp { return fish(ex, w, v, Nil); } - final static Any do31(Any ex) { // by + final static Any do40(Any ex) { // by int i, j; Any w, x, y, z; Any[] v; @@ -3068,16 +3410,16 @@ public class PicoLisp { return z; } - final static Any do32(Any ex) { // as + final static Any do41(Any ex) { // as return ex.Cdr.Car.eval() == Nil? Nil : ex.Cdr.Cdr; } - final static Any do33(Any ex) { // lit + final static Any do42(Any ex) { // lit Any x; return (x = ex.Cdr.Car.eval()) instanceof Number || x == Nil || x == T || x instanceof Cell && x.Car instanceof Number? x : new Cell(Quote, x); } - final static Any do34(Any ex) { // eval + final static Any do43(Any ex) { // eval Any y; if ((y = (ex = ex.Cdr).Car.eval()) instanceof Number) return y; @@ -3086,7 +3428,7 @@ public class PicoLisp { return evRun(true, y, evInt(ex.Cdr), ex.Cdr.Cdr.Car.eval()); } - final static Any do35(Any ex) { // run + final static Any do44(Any ex) { // run Any y; if ((y = (ex = ex.Cdr).Car.eval()) instanceof Number) return y; @@ -3095,7 +3437,7 @@ public class PicoLisp { return evRun(false, y, evInt(ex.Cdr), ex.Cdr.Cdr.Car.eval()); } - final static Any do36(Any ex) { // def + final static Any do45(Any ex) { // def Any w, x, y; Symbol s; s = (Symbol)(ex = ex.Cdr).Car.eval(); @@ -3116,13 +3458,13 @@ public class PicoLisp { return s; } - final static Any do37(Any ex) { // de + final static Any do46(Any ex) { // de ex = ex.Cdr; redefine((Symbol)ex.Car, ex.Cdr); return ex.Car; } - final static Any do38(Any ex) { // dm + final static Any do47(Any ex) { // dm Any x, y; Symbol s, t; if (!((x = ex.Cdr).Car instanceof Cell)) { @@ -3165,11 +3507,11 @@ public class PicoLisp { return s; } - final static Any do39(Any ex) { // box + final static Any do48(Any ex) { // box return mkSymbol(ex.Cdr.Car.eval()); } - final static Any do40(Any ex) { // new + final static Any do49(Any ex) { // new Any x; Symbol s; s = mkSymbol((ex = ex.Cdr).Car.eval()); @@ -3185,7 +3527,7 @@ public class PicoLisp { return s; } - final static Any do41(Any ex) { // type + final static Any do50(Any ex) { // type Any x, y, z; if ((x = ex.Cdr.Car.eval()) instanceof Symbol) { z = x = x.Car; @@ -3207,7 +3549,7 @@ public class PicoLisp { return Nil; } - final static Any do42(Any ex) { // isa + final static Any do51(Any ex) { // isa Any x, y; x = (ex = ex.Cdr).Car.eval(); if ((y = ex.Cdr.Car.eval()) instanceof Symbol) { @@ -3223,7 +3565,7 @@ public class PicoLisp { return Nil; } - final static Any do43(Any ex) { // method + final static Any do52(Any ex) { // method Any x, y; x = (ex = ex.Cdr).Car.eval(); y = ex.Cdr.Car.eval(); @@ -3231,7 +3573,7 @@ public class PicoLisp { return (x = method(y)) == null? Nil : x; } - final static Any do44(Any ex) { // send + final static Any do53(Any ex) { // send Any x, y, z; y = (x = ex.Cdr).Car.eval(); z = (x = x.Cdr).Car.eval(); @@ -3241,7 +3583,7 @@ public class PicoLisp { return evMethod(z, y, x.Cdr); } - final static Any do45(Any ex) { // try + final static Any do54(Any ex) { // try Any x, y; x = (ex = ex.Cdr).Car.eval(); if ((y = (ex = ex.Cdr).Car.eval()) instanceof Symbol) { @@ -3252,7 +3594,7 @@ public class PicoLisp { return Nil; } - final static Any do46(Any ex) { // super + final static Any do55(Any ex) { // super Any w, x, y, z; TheKey = Env.Key; x = Env.Cls == null? This.Car : Env.Cls.Car.Car; @@ -3272,7 +3614,7 @@ public class PicoLisp { } } - final static Any do47(Any ex) { // extra + final static Any do56(Any ex) { // extra Any x, y, z; TheKey = Env.Key; if ((x = extra(This.Car)) == null || x == T) @@ -3284,7 +3626,7 @@ public class PicoLisp { return x; } - final static Any do48(Any ex) { // with + final static Any do57(Any ex) { // with Any x; Bind bnd; if ((x = ex.Cdr.Car.eval()) != Nil) { @@ -3298,7 +3640,7 @@ public class PicoLisp { return x; } - final static Any do49(Any ex) { // bind + final static Any do58(Any ex) { // bind int i; Any x, y, z; Bind bnd; @@ -3331,7 +3673,7 @@ public class PicoLisp { return x; } - final static Any do50(Any ex) { // job + final static Any do59(Any ex) { // job int i; Any w, x, y, z; Bind bnd; @@ -3353,7 +3695,7 @@ public class PicoLisp { return x; } - final static Any do51(Any ex) { // let + final static Any do60(Any ex) { // let int i; Any x, y, z; Bind bnd; @@ -3379,7 +3721,7 @@ public class PicoLisp { return x; } - final static Any do52(Any ex) { // let? + final static Any do61(Any ex) { // let? Any x, y, z; Bind bnd; z = (x = ex.Cdr).Car; @@ -3394,7 +3736,7 @@ public class PicoLisp { return y; } - final static Any do53(Any ex) { // use + final static Any do62(Any ex) { // use int i; Any x, y; Bind bnd; @@ -3417,7 +3759,7 @@ public class PicoLisp { return x; } - final static Any do54(Any ex) { // and + final static Any do63(Any ex) { // and Any w; ex = ex.Cdr; do { @@ -3428,7 +3770,7 @@ public class PicoLisp { return w; } - final static Any do55(Any ex) { // or + final static Any do64(Any ex) { // or Any w; ex = ex.Cdr; do @@ -3438,7 +3780,7 @@ public class PicoLisp { return Nil; } - final static Any do56(Any ex) { // nand + final static Any do65(Any ex) { // nand Any w; ex = ex.Cdr; do { @@ -3449,7 +3791,7 @@ public class PicoLisp { return Nil; } - final static Any do57(Any ex) { // nor + final static Any do66(Any ex) { // nor Any w; ex = ex.Cdr; do @@ -3461,18 +3803,18 @@ public class PicoLisp { return T; } - final static Any do58(Any ex) { // xor + final static Any do67(Any ex) { // xor Any x, y; y = (x = ex.Cdr).Car.eval(); x = x.Cdr.Car.eval(); return y == Nil ^ x == Nil? T : Nil; } - final static Any do59(Any ex) { // bool + final static Any do68(Any ex) { // bool return ex.Cdr.Car.eval() == Nil? Nil : T; } - final static Any do60(Any ex) { // not + final static Any do69(Any ex) { // not Any w; if ((w = ex.Cdr.Car.eval()) == Nil) return T; @@ -3480,24 +3822,24 @@ public class PicoLisp { return Nil; } - final static Any do61(Any ex) { // nil + final static Any do70(Any ex) { // nil ex.Cdr.prog(); return Nil; } - final static Any do62(Any ex) { // t + final static Any do71(Any ex) { // t ex.Cdr.prog(); return T; } - final static Any do64(Any ex) { // prog1 + final static Any do73(Any ex) { // prog1 Any w; w = At.Car = ex.Cdr.Car.eval(); ex.Cdr.Cdr.prog(); return w; } - final static Any do65(Any ex) { // prog2 + final static Any do74(Any ex) { // prog2 Any w; (ex = ex.Cdr).Car.eval(); w = At.Car = (ex = ex.Cdr).Car.eval(); @@ -3505,7 +3847,7 @@ public class PicoLisp { return w; } - final static Any do66(Any ex) { // if + final static Any do75(Any ex) { // if Any w; if ((w = (ex = ex.Cdr).Car.eval()) == Nil) return ex.Cdr.Cdr.prog(); @@ -3513,7 +3855,7 @@ public class PicoLisp { return ex.Cdr.Car.eval(); } - final static Any do67(Any ex) { // if2 + final static Any do76(Any ex) { // if2 Any w; if ((w = (ex = ex.Cdr).Car.eval()) == Nil) { if ((w = (ex = ex.Cdr).Car.eval()) == Nil) @@ -3528,7 +3870,7 @@ public class PicoLisp { return ex.Cdr.Car.eval(); } - final static Any do68(Any ex) { // ifn + final static Any do77(Any ex) { // ifn Any w; if ((w = (ex = ex.Cdr).Car.eval()) != Nil) { At.Car = w; @@ -3537,7 +3879,7 @@ public class PicoLisp { return ex.Cdr.Car.eval(); } - final static Any do69(Any ex) { // when + final static Any do78(Any ex) { // when Any w; if ((w = (ex = ex.Cdr).Car.eval()) == Nil) return Nil; @@ -3545,7 +3887,7 @@ public class PicoLisp { return ex.Cdr.prog(); } - final static Any do70(Any ex) { // unless + final static Any do79(Any ex) { // unless Any w; if ((w = (ex = ex.Cdr).Car.eval()) != Nil) return Nil; @@ -3553,7 +3895,7 @@ public class PicoLisp { return ex.Cdr.prog(); } - final static Any do71(Any ex) { // cond + final static Any do80(Any ex) { // cond Any w; while ((ex = ex.Cdr) instanceof Cell) if ((w = ex.Car.Car.eval()) != Nil) { @@ -3563,7 +3905,7 @@ public class PicoLisp { return Nil; } - final static Any do72(Any ex) { // nond + final static Any do81(Any ex) { // nond Any w; while ((ex = ex.Cdr) instanceof Cell) { if ((w = ex.Car.Car.eval()) == Nil) @@ -3573,7 +3915,7 @@ public class PicoLisp { return Nil; } - final static Any do73(Any ex) { // case + final static Any do82(Any ex) { // case Any x, y; At.Car = (ex = ex.Cdr).Car.eval(); while ((ex = ex.Cdr) instanceof Cell) { @@ -3590,7 +3932,7 @@ public class PicoLisp { return Nil; } - final static Any do74(Any ex) { // state + final static Any do83(Any ex) { // state Any w, x, y, z; z = (x = ex.Cdr).Car.eval(); while ((x = x.Cdr) instanceof Cell) { @@ -3606,7 +3948,7 @@ public class PicoLisp { return Nil; } - final static Any do75(Any ex) { // while + final static Any do84(Any ex) { // while Any w, x, y; x = (ex = ex.Cdr).Car; ex = ex.Cdr; @@ -3618,7 +3960,7 @@ public class PicoLisp { return y; } - final static Any do76(Any ex) { // until + final static Any do85(Any ex) { // until Any w, x, y; x = (ex = ex.Cdr).Car; ex = ex.Cdr; @@ -3629,7 +3971,7 @@ public class PicoLisp { return y; } - final static Any do77(Any ex) { // do + final static Any do86(Any ex) { // do long n; Any w, x, y; if ((x = (ex = ex.Cdr).Car.eval()) == Nil) @@ -3661,7 +4003,7 @@ public class PicoLisp { return y; } - final static Any do79(Any ex) { // at + final static Any do88(Any ex) { // at Any x; Number num; x = (ex = ex.Cdr).Car.eval(); @@ -3673,7 +4015,7 @@ public class PicoLisp { return ex.Cdr.prog(); } - final static Any do80(Any ex) { // for + final static Any do89(Any ex) { // for int i; Any w, x, y, z; Bind bnd; @@ -3786,7 +4128,7 @@ public class PicoLisp { return y; } - final static Any do81(Any ex) { // catch + final static Any do90(Any ex) { // catch Any x, y; new Catch(y = (x = ex.Cdr).Car.eval(), Zero, Env); try { @@ -3806,13 +4148,13 @@ public class PicoLisp { } } - final static Any do82(Any ex) { // throw + final static Any do91(Any ex) { // throw Any x, y; y = (x = ex.Cdr).Car.eval(); throw new Control(ex, y, x.Cdr.Car.eval()); } - final static Any do83(Any ex) { // finally + final static Any do92(Any ex) { // finally Any x, y; new Catch(null, y = (x = ex.Cdr).Car, Env); x = x.Cdr.prog(); @@ -3821,7 +4163,7 @@ public class PicoLisp { return x; } - final static Any do84(Any ex) { // ! + final static Any do93(Any ex) { // ! Any x; x = ex.Cdr; if (Dbg.Car != Nil) @@ -3829,7 +4171,7 @@ public class PicoLisp { return x.eval(); } - final static Any do85(Any ex) { // e + final static Any do94(Any ex) { // e Any w, x, y, z; if (!Break) err(ex, null, "No Break"); @@ -3848,7 +4190,7 @@ public class PicoLisp { return z; } - final static Any do86(Any ex) { // $ + final static Any do95(Any ex) { // $ int i; Any x; ex = ex.Cdr; @@ -3878,11 +4220,11 @@ public class PicoLisp { return x; } - final static Any do87(Any ex) { // sys + final static Any do96(Any ex) { // sys return mkStr(System.getenv(evString(ex.Cdr))); } - final static Any do88(Any ex) { // call + final static Any do97(Any ex) { // call int i, j; Any x; j = (int)(x = ex.Cdr).length(); @@ -3897,15 +4239,15 @@ public class PicoLisp { return i == 0? T : Nil; } - final static Any do89(Any ex) { // ipid + final static Any do98(Any ex) { // ipid return Env.InFrames != null && Env.InFrames.Pid > 1? new Number(Env.InFrames.Pid) : Nil; } - final static Any do90(Any ex) { // opid + final static Any do99(Any ex) { // opid return Env.OutFrames != null && Env.OutFrames.Pid > 1? new Number(Env.OutFrames.Pid) : Nil; } - final static Any do91(Any ex) { // kill + final static Any do100(Any ex) { // kill int i; if (Pids[i = evInt(ex = ex.Cdr)] == null) return Nil; @@ -3915,13 +4257,13 @@ public class PicoLisp { return T; } - final static Any do92(Any ex) { // bye + final static Any do101(Any ex) { // bye Any x; x = ex.Cdr.Car.eval(); return bye(x == Nil? 0 : ((Number)x).Cnt); } - final static Any do93(Any ex) { // name + final static Any do102(Any ex) { // name Any x, y; Symbol s; y = (x = ex.Cdr).Car.eval(); @@ -3929,35 +4271,35 @@ public class PicoLisp { return mkStr(y.name()); if ((s = ((Symbol)y)).Name != null && Intern.get(s.Name) == s) err(ex, s, "Can't rename"); - ((Symbol)(x = x.Car.eval())).Name = s.Name; + s.Name = ((Symbol)(x = x.Car.eval())).Name; return s; } - final static Any do94(Any ex) { // sp? + final static Any do103(Any ex) { // sp? return isBlank(ex.Cdr.Car.eval())? T : Nil; } - final static Any do95(Any ex) { // pat? + final static Any do104(Any ex) { // pat? Any x; return ((x = ex.Cdr.Car.eval()) instanceof Symbol) && firstChar(x) == '@'? x : Nil; } - final static Any do96(Any ex) { // fun? + final static Any do105(Any ex) { // fun? return funq(ex.Cdr.Car.eval()); } - final static Any do97(Any ex) { // getd + final static Any do106(Any ex) { // getd Any x; if (!((x = ex.Cdr.Car.eval()) instanceof Symbol)) return Nil; return funq(x.Car) != Nil? x.Car : Nil; // ... reflection } - final static Any do98(Any ex) { // all + final static Any do107(Any ex) { // all return all(ex.Cdr.Car.eval() == Nil? Intern : Transient); } - final static Any do99(Any ex) { // intern + final static Any do108(Any ex) { // intern Symbol s, t; String str; s = (Symbol)ex.Cdr.Car.eval(); @@ -3969,7 +4311,7 @@ public class PicoLisp { return s; } - final static Any do100(Any ex) { // ==== + final static Any do109(Any ex) { // ==== Any x, y; Transient.clear(); for (x = ex.Cdr; x instanceof Cell; x = x.Cdr) { @@ -3979,24 +4321,24 @@ public class PicoLisp { return Nil; } - final static Any do101(Any ex) { // box? + final static Any do110(Any ex) { // box? Any x; return ((x = ex.Cdr.Car.eval()) instanceof Symbol) && x.name().length() == 0? x : Nil; } - final static Any do102(Any ex) { // str? + final static Any do111(Any ex) { // str? Any x; return ((x = ex.Cdr.Car.eval()) instanceof Symbol) && Intern.get(x.name()) == null? x : Nil; } - final static Any do103(Any ex) { // zap + final static Any do112(Any ex) { // zap Symbol s; s = (Symbol)ex.Cdr.Car.eval(); Intern.remove(s.name()); return s; } - final static Any do104(Any ex) { // chop + final static Any do113(Any ex) { // chop Any x, y; String str; x = ex.Cdr.Car.eval(); @@ -4011,7 +4353,7 @@ public class PicoLisp { return x; } - final static Any do105(Any ex) { // pack + final static Any do114(Any ex) { // pack StringBuilder sb; sb = new StringBuilder(); for (ex = ex.Cdr; ex instanceof Cell; ex = ex.Cdr) @@ -4019,7 +4361,7 @@ public class PicoLisp { return mkStr(sb); } - final static Any do106(Any ex) { // glue + final static Any do115(Any ex) { // glue Any x, y; StringBuilder sb; x = ex.Cdr.Car.eval(); @@ -4032,7 +4374,7 @@ public class PicoLisp { return mkStr(sb); } - final static Any do107(Any ex) { // text + final static Any do116(Any ex) { // text int i, j, k; char c; String str; @@ -4061,21 +4403,21 @@ public class PicoLisp { return mkStr(sb); } - final static Any do108(Any ex) { // pre? + final static Any do117(Any ex) { // pre? Any x; String str; str = evString(ex = ex.Cdr); return (x = ex.Cdr.Car.eval()).name().startsWith(str)? x : Nil; } - final static Any do109(Any ex) { // sub? + final static Any do118(Any ex) { // sub? Any x; String str; str = evString(ex = ex.Cdr); return (x = ex.Cdr.Car.eval()).name().indexOf(str) >= 0? x : Nil; } - final static Any do111(Any ex) { // set + final static Any do120(Any ex) { // set Any x, y; x = ex.Cdr; do { @@ -4086,7 +4428,7 @@ public class PicoLisp { return y.Car; } - final static Any do112(Any ex) { // setq + final static Any do121(Any ex) { // setq Any x, y; x = ex.Cdr; do { @@ -4097,7 +4439,7 @@ public class PicoLisp { return y.Car; } - final static Any do113(Any ex) { // xchg + final static Any do122(Any ex) { // xchg Any w, x, y, z; x = ex.Cdr; do { @@ -4108,7 +4450,7 @@ public class PicoLisp { return w; } - final static Any do114(Any ex) { // on + final static Any do123(Any ex) { // on Any x; x = ex.Cdr; do @@ -4117,7 +4459,7 @@ public class PicoLisp { return T; } - final static Any do115(Any ex) { // off + final static Any do124(Any ex) { // off Any x; x = ex.Cdr; do @@ -4126,7 +4468,7 @@ public class PicoLisp { return Nil; } - final static Any do116(Any ex) { // onOff + final static Any do125(Any ex) { // onOff Any x, y; x = ex.Cdr; do @@ -4135,7 +4477,7 @@ public class PicoLisp { return y; } - final static Any do117(Any ex) { // zero + final static Any do126(Any ex) { // zero Any x; x = ex.Cdr; do @@ -4144,7 +4486,7 @@ public class PicoLisp { return Zero; } - final static Any do118(Any ex) { // one + final static Any do127(Any ex) { // one Any x; x = ex.Cdr; do @@ -4153,7 +4495,7 @@ public class PicoLisp { return One; } - final static Any do119(Any ex) { // default + final static Any do128(Any ex) { // default Any x, y; x = ex.Cdr; do { @@ -4166,7 +4508,7 @@ public class PicoLisp { return y.Car; } - final static Any do120(Any ex) { // push + final static Any do129(Any ex) { // push Any x, y, z; needVar(ex, y = (x = ex.Cdr).Car.eval()); do @@ -4175,7 +4517,7 @@ public class PicoLisp { return z; } - final static Any do121(Any ex) { // push1 + final static Any do130(Any ex) { // push1 Any x, y, z; needVar(ex, y = (x = ex.Cdr).Car.eval()); do @@ -4185,7 +4527,7 @@ public class PicoLisp { return z; } - final static Any do122(Any ex) { // pop + final static Any do131(Any ex) { // pop Any x, y; needVar(ex, x = ex.Cdr.Car.eval()); if ((y = x.Car) instanceof Cell) { @@ -4195,7 +4537,7 @@ public class PicoLisp { return y; } - final static Any do123(Any ex) { // cut + final static Any do132(Any ex) { // cut long n; Any x, y, z; if ((n = evLong(ex.Cdr)) <= 0) @@ -4210,7 +4552,7 @@ public class PicoLisp { return x.Car; } - final static Any do124(Any ex) { // del + final static Any do133(Any ex) { // del Any w, lst, x, y, z; w = ex.Cdr.Car.eval(); needVar(ex, x = ex.Cdr.Cdr.Car.eval()); @@ -4226,7 +4568,7 @@ public class PicoLisp { return x.Car; } - final static Any do125(Any ex) { // queue + final static Any do134(Any ex) { // queue Any x, y; needVar(ex, x = ex.Cdr.Car.eval()); y = ex.Cdr.Cdr.Car.eval(); @@ -4239,7 +4581,7 @@ public class PicoLisp { return y; } - final static Any do126(Any ex) { // fifo + final static Any do135(Any ex) { // fifo Any x, y, z, lst; needVar(ex, y = (x = ex.Cdr).Car.eval()); if ((x = x.Cdr) instanceof Cell) { @@ -4267,7 +4609,7 @@ public class PicoLisp { return z; } - final static Any do127(Any ex) { // idx + final static Any do136(Any ex) { // idx Any x, y; needVar(ex, x = (ex = ex.Cdr).Car.eval()); if (!((ex = ex.Cdr) instanceof Cell)) @@ -4276,7 +4618,7 @@ public class PicoLisp { return idx(x, y, ex.Cdr instanceof Cell? (ex.Cdr.Car.eval() == Nil? -1 : +1) : 0); } - final static Any do128(Any ex) { // lup + final static Any do137(Any ex) { // lup int i; Any x, y, z; x = (ex = ex.Cdr).Car.eval(); @@ -4296,7 +4638,7 @@ public class PicoLisp { return Nil; } - final static Any do129(Any ex) { // put + final static Any do138(Any ex) { // put Any x, y; x = (ex = ex.Cdr).Car.eval(); for (;;) { @@ -4307,7 +4649,7 @@ public class PicoLisp { } } - final static Any do130(Any ex) { // get + final static Any do139(Any ex) { // get Any x; x = (ex = ex.Cdr).Car.eval(); while ((ex = ex.Cdr) instanceof Cell) @@ -4315,7 +4657,7 @@ public class PicoLisp { return x; } - final static Any do131(Any ex) { // prop + final static Any do140(Any ex) { // prop Any x; x = (ex = ex.Cdr).Car.eval(); while ((ex = ex.Cdr).Cdr instanceof Cell) @@ -4323,7 +4665,7 @@ public class PicoLisp { return x.prop(ex.Car.eval()); } - final static Any do132(Any ex) { // ; + final static Any do141(Any ex) { // ; Any x; x = (ex = ex.Cdr).Car.eval(); while ((ex = ex.Cdr) instanceof Cell) @@ -4331,7 +4673,7 @@ public class PicoLisp { return x; } - final static Any do133(Any ex) { // =: + final static Any do142(Any ex) { // =: Any x, y; for (x = This.Car;;) { y = (ex = ex.Cdr).Car; @@ -4341,7 +4683,7 @@ public class PicoLisp { } } - final static Any do134(Any ex) { // : + final static Any do143(Any ex) { // : Any x; x = This.Car; do @@ -4350,7 +4692,7 @@ public class PicoLisp { return x; } - final static Any do135(Any ex) { // :: + final static Any do144(Any ex) { // :: Any x; x = This.Car; while ((ex = ex.Cdr).Cdr instanceof Cell) @@ -4358,7 +4700,7 @@ public class PicoLisp { return x.prop(ex.Car); } - final static Any do136(Any ex) { // putl + final static Any do145(Any ex) { // putl Any x; x = (ex = ex.Cdr).Car.eval(); while ((ex = ex.Cdr).Cdr instanceof Cell) @@ -4366,7 +4708,7 @@ public class PicoLisp { return x.putl(ex.Car.eval()); } - final static Any do137(Any ex) { // getl + final static Any do146(Any ex) { // getl Any x; x = (ex = ex.Cdr).Car.eval(); while ((ex = ex.Cdr) instanceof Cell) @@ -4374,7 +4716,7 @@ public class PicoLisp { return x.getl(); } - final static Any do138(Any ex) { // meta + final static Any do147(Any ex) { // meta Any x, y; if ((x = (ex = ex.Cdr).Car.eval()) instanceof Symbol) x = x.Car; @@ -4383,17 +4725,17 @@ public class PicoLisp { return x; } - final static Any do139(Any ex) { // low? + final static Any do148(Any ex) { // low? Any x; return (x = ex.Cdr.Car.eval()) instanceof Symbol && Character.isLowerCase(firstChar(x))? x : Nil; } - final static Any do140(Any ex) { // upp? + final static Any do149(Any ex) { // upp? Any x; return (x = ex.Cdr.Car.eval()) instanceof Symbol && Character.isUpperCase(firstChar(x))? x : Nil; } - final static Any do141(Any ex) { // lowc + final static Any do150(Any ex) { // lowc int i, j; Any x; String str; @@ -4406,7 +4748,7 @@ public class PicoLisp { return mkStr(sb); } - final static Any do142(Any ex) { // uppc + final static Any do151(Any ex) { // uppc int i, j; Any x; String str; @@ -4419,7 +4761,7 @@ public class PicoLisp { return mkStr(sb); } - final static Any do143(Any ex) { // fold + final static Any do152(Any ex) { // fold int i, j, k; char c; Any x; @@ -4442,103 +4784,103 @@ public class PicoLisp { return mkStr(sb); } - final static Any do150(Any ex) { // caaar + final static Any do159(Any ex) { // caaar return ex.Cdr.Car.eval().Car.Car.Car; } - final static Any do151(Any ex) { // caadr + final static Any do160(Any ex) { // caadr return ex.Cdr.Car.eval().Cdr.Car.Car; } - final static Any do152(Any ex) { // cadar + final static Any do161(Any ex) { // cadar return ex.Cdr.Car.eval().Car.Cdr.Car; } - final static Any do153(Any ex) { // caddr + final static Any do162(Any ex) { // caddr return ex.Cdr.Car.eval().Cdr.Cdr.Car; } - final static Any do154(Any ex) { // cdaar + final static Any do163(Any ex) { // cdaar return ex.Cdr.Car.eval().Car.Car.Cdr; } - final static Any do155(Any ex) { // cdadr + final static Any do164(Any ex) { // cdadr return ex.Cdr.Car.eval().Cdr.Car.Cdr; } - final static Any do156(Any ex) { // cddar + final static Any do165(Any ex) { // cddar return ex.Cdr.Car.eval().Car.Cdr.Cdr; } - final static Any do157(Any ex) { // cdddr + final static Any do166(Any ex) { // cdddr return ex.Cdr.Car.eval().Cdr.Cdr.Cdr; } - final static Any do158(Any ex) { // caaaar + final static Any do167(Any ex) { // caaaar return ex.Cdr.Car.eval().Car.Car.Car.Car; } - final static Any do159(Any ex) { // caaadr + final static Any do168(Any ex) { // caaadr return ex.Cdr.Car.eval().Cdr.Car.Car.Car; } - final static Any do160(Any ex) { // caadar + final static Any do169(Any ex) { // caadar return ex.Cdr.Car.eval().Car.Cdr.Car.Car; } - final static Any do161(Any ex) { // caaddr + final static Any do170(Any ex) { // caaddr return ex.Cdr.Car.eval().Cdr.Cdr.Car.Car; } - final static Any do162(Any ex) { // cadaar + final static Any do171(Any ex) { // cadaar return ex.Cdr.Car.eval().Car.Car.Cdr.Car; } - final static Any do163(Any ex) { // cadadr + final static Any do172(Any ex) { // cadadr return ex.Cdr.Car.eval().Cdr.Car.Cdr.Car; } - final static Any do164(Any ex) { // caddar + final static Any do173(Any ex) { // caddar return ex.Cdr.Car.eval().Car.Cdr.Cdr.Car; } - final static Any do165(Any ex) { // cadddr + final static Any do174(Any ex) { // cadddr return ex.Cdr.Car.eval().Cdr.Cdr.Cdr.Car; } - final static Any do166(Any ex) { // cdaaar + final static Any do175(Any ex) { // cdaaar return ex.Cdr.Car.eval().Car.Car.Car.Cdr; } - final static Any do167(Any ex) { // cdaadr + final static Any do176(Any ex) { // cdaadr return ex.Cdr.Car.eval().Cdr.Car.Car.Cdr; } - final static Any do168(Any ex) { // cdadar + final static Any do177(Any ex) { // cdadar return ex.Cdr.Car.eval().Car.Cdr.Car.Cdr; } - final static Any do169(Any ex) { // cdaddr + final static Any do178(Any ex) { // cdaddr return ex.Cdr.Car.eval().Cdr.Cdr.Car.Cdr; } - final static Any do170(Any ex) { // cddaar + final static Any do179(Any ex) { // cddaar return ex.Cdr.Car.eval().Car.Car.Cdr.Cdr; } - final static Any do171(Any ex) { // cddadr + final static Any do180(Any ex) { // cddadr return ex.Cdr.Car.eval().Cdr.Car.Cdr.Cdr; } - final static Any do172(Any ex) { // cdddar + final static Any do181(Any ex) { // cdddar return ex.Cdr.Car.eval().Car.Cdr.Cdr.Cdr; } - final static Any do173(Any ex) { // cddddr + final static Any do182(Any ex) { // cddddr return ex.Cdr.Car.eval().Cdr.Cdr.Cdr.Cdr; } - final static Any do174(Any ex) { // nth + final static Any do183(Any ex) { // nth Any x; x = (ex = ex.Cdr).Car.eval(); for (;;) { @@ -4551,13 +4893,13 @@ public class PicoLisp { } } - final static Any do175(Any ex) { // con + final static Any do184(Any ex) { // con Any x; x = ex.Cdr.Car.eval(); return x.Cdr = ex.Cdr.Cdr.Car.eval(); } - final static Any do176(Any ex) { // cons + final static Any do185(Any ex) { // cons Any x, y; y = x = new Cell((ex = ex.Cdr).Car.eval(), Nil); while ((ex = ex.Cdr).Cdr instanceof Cell) @@ -4566,7 +4908,7 @@ public class PicoLisp { return y; } - final static Any do177(Any ex) { // conc + final static Any do186(Any ex) { // conc Any x, y, z; z = x = (ex = ex.Cdr).Car.eval(); while ((ex = ex.Cdr) instanceof Cell) { @@ -4581,7 +4923,7 @@ public class PicoLisp { return z; } - final static Any do178(Any ex) { // circ + final static Any do187(Any ex) { // circ Any x, y; y = x = new Cell((ex = ex.Cdr).Car.eval(), Nil); while ((ex = ex.Cdr) instanceof Cell) @@ -4590,7 +4932,7 @@ public class PicoLisp { return y; } - final static Any do179(Any ex) { // rot + final static Any do188(Any ex) { // rot int i; Any w, x, y, z; w = y = (ex = ex.Cdr).Car.eval(); @@ -4605,7 +4947,7 @@ public class PicoLisp { return w; } - final static Any do180(Any ex) { // list + final static Any do189(Any ex) { // list Any x, y; x = y = new Cell((ex = ex.Cdr).Car.eval(), Nil); while ((ex = ex.Cdr) instanceof Cell) @@ -4613,7 +4955,7 @@ public class PicoLisp { return y; } - final static Any do181(Any ex) { // need + final static Any do190(Any ex) { // need long n; Any x, y, z; n = evLong(ex = ex.Cdr); @@ -4636,7 +4978,7 @@ public class PicoLisp { return z; } - final static Any do182(Any ex) { // range + final static Any do191(Any ex) { // range Any x, y; Number num; num = (Number)(y = (x = ex.Cdr).Car.eval()); @@ -4652,7 +4994,7 @@ public class PicoLisp { return y; } - final static Any do183(Any ex) { // full + final static Any do192(Any ex) { // full Any x; for (x = ex.Cdr.Car.eval(); x instanceof Cell; x = x.Cdr) if (x.Car == Nil) @@ -4660,7 +5002,7 @@ public class PicoLisp { return T; } - final static Any do184(Any ex) { // make + final static Any do193(Any ex) { // make Any x, y, z; x = Env.Make; Env.Make = Nil; y = Env.Yoke; Env.Yoke = Nil; @@ -4671,7 +5013,7 @@ public class PicoLisp { return z; } - final static Any do185(Any ex) { // made + final static Any do194(Any ex) { // made Any x; if ((x = ex.Cdr) instanceof Cell) { Env.Yoke = x.Car.eval(); @@ -4683,7 +5025,7 @@ public class PicoLisp { return Env.Yoke; } - final static Any do186(Any ex) { // chain + final static Any do195(Any ex) { // chain Any x, y; ex = ex.Cdr; do { @@ -4698,7 +5040,7 @@ public class PicoLisp { return x; } - final static Any do187(Any ex) { // link + final static Any do196(Any ex) { // link Any x; ex = ex.Cdr; do { @@ -4711,7 +5053,7 @@ public class PicoLisp { return x; } - final static Any do188(Any ex) { // yoke + final static Any do197(Any ex) { // yoke Any x; ex = ex.Cdr; do { @@ -4723,7 +5065,7 @@ public class PicoLisp { return x; } - final static Any do189(Any ex) { // copy + final static Any do198(Any ex) { // copy Any w, x, y, z; if (!((x = ex.Cdr.Car.eval()) instanceof Cell)) return x; @@ -4735,7 +5077,7 @@ public class PicoLisp { return w; } - final static Any do190(Any ex) { // mix + final static Any do199(Any ex) { // mix Any x, y, z; if (!((y = (ex = ex.Cdr).Car.eval()) instanceof Cell) && y != Nil) return y; @@ -4747,7 +5089,7 @@ public class PicoLisp { return z; } - final static Any do191(Any ex) { // append + final static Any do200(Any ex) { // append Any x, y, z; for (ex = ex.Cdr; (z = ex.Cdr) instanceof Cell; ex = z) { if ((x = ex.Car.eval()) instanceof Cell) { @@ -4766,7 +5108,7 @@ public class PicoLisp { return ex.Car.eval(); } - final static Any do192(Any ex) { // delete + final static Any do201(Any ex) { // delete Any w, x, y, z; y = (x = ex.Cdr).Car.eval(); if (!((x = x.Cdr.Car.eval()) instanceof Cell)) @@ -4785,7 +5127,7 @@ public class PicoLisp { return w; } - final static Any do193(Any ex) { // delq + final static Any do202(Any ex) { // delq Any w, x, y, z; y = (x = ex.Cdr).Car.eval(); if (!((x = x.Cdr.Car.eval()) instanceof Cell)) @@ -4804,7 +5146,7 @@ public class PicoLisp { return w; } - final static Any do194(Any ex) { // replace + final static Any do203(Any ex) { // replace int i, j; Any w, x, y, z; Any[] v; @@ -4827,13 +5169,13 @@ public class PicoLisp { return w; } - final static Any do195(Any ex) { // strip + final static Any do204(Any ex) { // strip Any x; for (x = ex.Cdr.Car.eval(); x instanceof Cell && x.Car == Quote && x != x.Cdr; x = x.Cdr); return x; } - final static Any do196(Any ex) { // split + final static Any do205(Any ex) { // split int i, j; Any x, y, z; Any[] v; @@ -4867,7 +5209,7 @@ public class PicoLisp { return res; } - final static Any do197(Any ex) { // reverse + final static Any do206(Any ex) { // reverse Any x, y; x = ex.Cdr.Car.eval(); for (y = Nil; x instanceof Cell; x = x.Cdr) @@ -4875,7 +5217,7 @@ public class PicoLisp { return y; } - final static Any do198(Any ex) { // flip + final static Any do207(Any ex) { // flip int i; Any x, y, z; if (!((y = (ex = ex.Cdr).Car.eval()) instanceof Cell) || !((z = y.Cdr) instanceof Cell)) @@ -4898,17 +5240,17 @@ public class PicoLisp { return z; } - final static Any do199(Any ex) { // trim + final static Any do208(Any ex) { // trim return trim(ex.Cdr.Car.eval()); } - final static Any do200(Any ex) { // clip + final static Any do209(Any ex) { // clip Any x; for (x = ex.Cdr.Car.eval(); x instanceof Cell && isBlank(x.Car); x = x.Cdr); return trim(x); } - final static Any do201(Any ex) { // head + final static Any do210(Any ex) { // head int i; Any x, y, z; if ((z = (x = ex.Cdr).Car.eval()) == Nil) @@ -4934,7 +5276,7 @@ public class PicoLisp { return z; } - final static Any do202(Any ex) { // tail + final static Any do211(Any ex) { // tail int i; Any x, y, z; if ((z = (x = ex.Cdr).Car.eval()) == Nil) @@ -4964,7 +5306,7 @@ public class PicoLisp { return x; } - final static Any do203(Any ex) { // stem + final static Any do212(Any ex) { // stem int i, j; Any x, y; Any[] v; @@ -4980,13 +5322,13 @@ public class PicoLisp { return y; } - final static Any do204(Any ex) { // fin + final static Any do213(Any ex) { // fin Any x; for (x = ex.Cdr.Car.eval(); x instanceof Cell; x = x.Cdr); return x; } - final static Any do205(Any ex) { // last + final static Any do214(Any ex) { // last Any x; if (!((x = ex.Cdr.Car.eval()) instanceof Cell)) return x; @@ -4995,7 +5337,7 @@ public class PicoLisp { return x.Car; } - final static Any do206(Any ex) { // == + final static Any do215(Any ex) { // == Any x, y; y = (x = ex.Cdr).Car.eval(); while ((x = x.Cdr) instanceof Cell) @@ -5004,7 +5346,7 @@ public class PicoLisp { return T; } - final static Any do207(Any ex) { // n== + final static Any do216(Any ex) { // n== Any x, y; y = (x = ex.Cdr).Car.eval(); while ((x = x.Cdr) instanceof Cell) @@ -5013,7 +5355,7 @@ public class PicoLisp { return Nil; } - final static Any do208(Any ex) { // = + final static Any do217(Any ex) { // = Any x, y; y = (x = ex.Cdr).Car.eval(); while ((x = x.Cdr) instanceof Cell) @@ -5022,7 +5364,7 @@ public class PicoLisp { return T; } - final static Any do209(Any ex) { // <> + final static Any do218(Any ex) { // <> Any x, y; y = (x = ex.Cdr).Car.eval(); while ((x = x.Cdr) instanceof Cell) @@ -5031,24 +5373,24 @@ public class PicoLisp { return Nil; } - final static Any do210(Any ex) { // =0 + final static Any do219(Any ex) { // =0 Any x; return ex.Cdr.Car.eval().equal(Zero)? Zero : Nil; } - final static Any do211(Any ex) { // =T + final static Any do220(Any ex) { // =T return T == ex.Cdr.Car.eval()? T : Nil; } - final static Any do212(Any ex) { // n0 + final static Any do221(Any ex) { // n0 return ex.Cdr.Car.eval().equal(Zero)? Nil : T; } - final static Any do213(Any ex) { // nT + final static Any do222(Any ex) { // nT return T == ex.Cdr.Car.eval()? Nil : T; } - final static Any do214(Any ex) { // < + final static Any do223(Any ex) { // < Any x, y, z; y = (x = ex.Cdr).Car.eval(); while ((x = x.Cdr) instanceof Cell) { @@ -5060,7 +5402,7 @@ public class PicoLisp { return T; } - final static Any do215(Any ex) { // <= + final static Any do224(Any ex) { // <= Any x, y, z; y = (x = ex.Cdr).Car.eval(); while ((x = x.Cdr) instanceof Cell) { @@ -5072,7 +5414,7 @@ public class PicoLisp { return T; } - final static Any do216(Any ex) { // > + final static Any do225(Any ex) { // > Any x, y; x = (ex = ex.Cdr).Car.eval(); while (ex.Cdr instanceof Cell) { @@ -5084,7 +5426,7 @@ public class PicoLisp { return T; } - final static Any do217(Any ex) { // >= + final static Any do226(Any ex) { // >= Any x, y, z; y = (x = ex.Cdr).Car.eval(); while ((x = x.Cdr) instanceof Cell) { @@ -5096,7 +5438,7 @@ public class PicoLisp { return T; } - final static Any do218(Any ex) { // max + final static Any do227(Any ex) { // max Any x, y; for (y = (ex = ex.Cdr).Car.eval(); (ex = ex.Cdr) instanceof Cell;) if ((x = ex.Car.eval()).compare(y) > 0) @@ -5104,7 +5446,7 @@ public class PicoLisp { return y; } - final static Any do219(Any ex) { // min + final static Any do228(Any ex) { // min Any x, y; for (y = (ex = ex.Cdr).Car.eval(); (ex = ex.Cdr) instanceof Cell;) if ((x = ex.Car.eval()).compare(y) < 0) @@ -5112,48 +5454,48 @@ public class PicoLisp { return y; } - final static Any do220(Any ex) { // atom + final static Any do229(Any ex) { // atom return ex.Cdr.Car.eval() instanceof Cell? Nil : T; } - final static Any do221(Any ex) { // pair + final static Any do230(Any ex) { // pair Any x; return (x = ex.Cdr.Car.eval()) instanceof Cell? x : Nil; } - final static Any do222(Any ex) { // lst? + final static Any do231(Any ex) { // lst? Any x; return (x = ex.Cdr.Car.eval()) instanceof Cell || x == Nil? T : Nil; } - final static Any do223(Any ex) { // num? + final static Any do232(Any ex) { // num? Any x; return (x = ex.Cdr.Car.eval()) instanceof Number? x : Nil; } - final static Any do224(Any ex) { // sym? + final static Any do233(Any ex) { // sym? Any x; return (x = ex.Cdr.Car.eval()) instanceof Symbol || x == Nil? T : Nil; } - final static Any do225(Any ex) { // flg? + final static Any do234(Any ex) { // flg? Any x; return (x = ex.Cdr.Car.eval()) == Nil || x == T? T : Nil; } - final static Any do226(Any ex) { // member + final static Any do235(Any ex) { // member Any x; x = (ex = ex.Cdr).Car.eval(); return (x = member(x, ex.Cdr.Car.eval())) == null? Nil : x; } - final static Any do227(Any ex) { // memq + final static Any do236(Any ex) { // memq Any x; x = (ex = ex.Cdr).Car.eval(); return (x = memq(x, ex.Cdr.Car.eval())) == null? Nil : x; } - final static Any do228(Any ex) { // mmeq + final static Any do237(Any ex) { // mmeq Any x, y, z; x = (ex = ex.Cdr).Car.eval(); for (y = (ex = ex.Cdr).Car.eval(); x instanceof Cell; x = x.Cdr) @@ -5162,7 +5504,7 @@ public class PicoLisp { return Nil; } - final static Any do229(Any ex) { // sect + final static Any do238(Any ex) { // sect Any w, x, y, z; y = (x = ex.Cdr).Car.eval(); z = x.Cdr.Car.eval(); @@ -5178,7 +5520,7 @@ public class PicoLisp { return w; } - final static Any do230(Any ex) { // diff + final static Any do239(Any ex) { // diff Any w, x, y, z; y = (x = ex.Cdr).Car.eval(); z = x.Cdr.Car.eval(); @@ -5194,14 +5536,14 @@ public class PicoLisp { return w; } - final static Any do231(Any ex) { // index + final static Any do240(Any ex) { // index int i; Any x, y; y = (x = ex.Cdr).Car.eval(); return (i = indx(y, x.Cdr.Car.eval())) == 0? Nil : new Number(i); } - final static Any do232(Any ex) { // offset + final static Any do241(Any ex) { // offset int i; Any x, y; y = (x = ex.Cdr).Car.eval(); @@ -5212,16 +5554,16 @@ public class PicoLisp { return Nil; } - final static Any do233(Any ex) { // length + final static Any do242(Any ex) { // length long n; return (n = ex.Cdr.Car.eval().length()) >= 0? new Number(n) : T; } - final static Any do234(Any ex) { // size + final static Any do243(Any ex) { // size return new Number(ex.Cdr.Car.eval().size()); } - final static Any do235(Any ex) { // assoc + final static Any do244(Any ex) { // assoc Any x, y, z; y = (x = ex.Cdr).Car.eval(); x = x.Cdr.Car.eval(); @@ -5231,7 +5573,7 @@ public class PicoLisp { return Nil; } - final static Any do236(Any ex) { // asoq + final static Any do245(Any ex) { // asoq Any x, y, z; y = (x = ex.Cdr).Car.eval(); x = x.Cdr.Car.eval(); @@ -5241,7 +5583,7 @@ public class PicoLisp { return Nil; } - final static Any do237(Any ex) { // rank + final static Any do246(Any ex) { // rank Any w, x, y, z; w = (x = ex.Cdr).Car.eval(); y = (x = x.Cdr).Car.eval(); @@ -5261,19 +5603,19 @@ public class PicoLisp { return z.Car; } - final static Any do238(Any ex) { // match + final static Any do247(Any ex) { // match Any x, y; y = (x = ex.Cdr).Car.eval(); return match(y, x.Cdr.Car.eval())? T : Nil; } - final static Any do239(Any ex) { // fill + final static Any do248(Any ex) { // fill Any x, y; y = (x = ex.Cdr).Car.eval(); return (x = fill(y, x.Cdr.Car.eval())) == null? y : x; } - final static Any do240(Any ex) { // prove + final static Any do249(Any ex) { // prove int i; Any x, y; if (!((y = (ex = ex.Cdr).Car.eval()) instanceof Cell)) @@ -5369,7 +5711,7 @@ public class PicoLisp { return x; } - final static Any do241(Any ex) { // -> + final static Any do250(Any ex) { // -> int i; Any x; if (!(ex.Cdr.Cdr.Car instanceof Number)) @@ -5379,18 +5721,18 @@ public class PicoLisp { return lookup((Number)x.Car, ex.Cdr.Car); } - final static Any do242(Any ex) { // unify + final static Any do251(Any ex) { // unify Any x; x = ex.Cdr.Car.eval(); return unify((Number)Pnl.Cdr.Car, x, (Number)Pnl.Car, x)? Penv : Nil; } - final static Any do243(Any ex) { // sort + final static Any do252(Any ex) { // sort Any x; return (x = ex.Cdr.Car.eval()) instanceof Cell && x.Cdr instanceof Cell? sort(ex, x, ex.Cdr.Cdr.Car.eval()) : x; } - final static Any do244(Any ex) { // format + final static Any do253(Any ex) { // format int i; Any x, y; x = (ex = ex.Cdr).Car.eval(); @@ -5398,7 +5740,7 @@ public class PicoLisp { return format(x, i, ex.Cdr); } - final static Any do245(Any ex) { // + + final static Any do254(Any ex) { // + Any x; Number num; if ((x = (ex = ex.Cdr).Car.eval()) == Nil) @@ -5409,7 +5751,7 @@ public class PicoLisp { return num; } - final static Any do246(Any ex) { // - + final static Any do255(Any ex) { // - Any x; Number num; if ((x = (ex = ex.Cdr).Car.eval()) == Nil) @@ -5425,7 +5767,7 @@ public class PicoLisp { return num; } - final static Any do247(Any ex) { // inc + final static Any do256(Any ex) { // inc Any x, y; if ((x = (ex = ex.Cdr).Car.eval()) == Nil) return Nil; @@ -5445,7 +5787,7 @@ public class PicoLisp { return y; } - final static Any do248(Any ex) { // dec + final static Any do257(Any ex) { // dec Any x, y; if ((x = (ex = ex.Cdr).Car.eval()) == Nil) return Nil; @@ -5465,7 +5807,7 @@ public class PicoLisp { return y; } - final static Any do249(Any ex) { // * + final static Any do258(Any ex) { // * Any x; Number num; if ((x = (ex = ex.Cdr).Car.eval()) == Nil) @@ -5476,7 +5818,7 @@ public class PicoLisp { return num; } - final static Any do250(Any ex) { // */ + final static Any do259(Any ex) { // */ Any x; Number num; if ((x = (ex = ex.Cdr).Car.eval()) == Nil) @@ -5489,7 +5831,7 @@ public class PicoLisp { } } - final static Any do251(Any ex) { // / + final static Any do260(Any ex) { // / Any x; Number num; if ((x = (ex = ex.Cdr).Car.eval()) == Nil) @@ -5500,7 +5842,7 @@ public class PicoLisp { return num; } - final static Any do252(Any ex) { // % + final static Any do261(Any ex) { // % Any x; Number num; if ((x = (ex = ex.Cdr).Car.eval()) == Nil) @@ -5511,7 +5853,7 @@ public class PicoLisp { return num; } - final static Any do253(Any ex) { // >> + final static Any do262(Any ex) { // >> int i; Any x; i = evInt(ex = ex.Cdr); @@ -5520,26 +5862,26 @@ public class PicoLisp { return ((Number)x).shift(i); } - final static Any do254(Any ex) { // lt0 + final static Any do263(Any ex) { // lt0 Any x; return (x = ex.Cdr.Car.eval()) instanceof Number && x.compare(Zero) < 0? x : Nil; } - final static Any do255(Any ex) { // ge0 + final static Any do264(Any ex) { // ge0 Any x; return (x = ex.Cdr.Car.eval()) instanceof Number && x.compare(Zero) >= 0? x : Nil; } - final static Any do256(Any ex) { // gt0 + final static Any do265(Any ex) { // gt0 Any x; return (x = ex.Cdr.Car.eval()) instanceof Number && x.compare(Zero) > 0? x : Nil; } - final static Any do257(Any ex) { // abs + final static Any do266(Any ex) { // abs return ((Number)ex.Cdr.Car.eval()).abs(); } - final static Any do258(Any ex) { // bit? + final static Any do267(Any ex) { // bit? Any x; Number num; num = (Number)(ex = ex.Cdr).Car.eval(); @@ -5549,7 +5891,7 @@ public class PicoLisp { return num; } - final static Any do259(Any ex) { // & + final static Any do268(Any ex) { // & Any x; Number num; if ((x = (ex = ex.Cdr).Car.eval()) == Nil) @@ -5560,7 +5902,7 @@ public class PicoLisp { return num; } - final static Any do260(Any ex) { // | + final static Any do269(Any ex) { // | Any x; Number num; if ((x = (ex = ex.Cdr).Car.eval()) == Nil) @@ -5571,7 +5913,7 @@ public class PicoLisp { return num; } - final static Any do261(Any ex) { // x| + final static Any do270(Any ex) { // x| Any x; Number num; if ((x = (ex = ex.Cdr).Car.eval()) == Nil) @@ -5582,13 +5924,13 @@ public class PicoLisp { return num; } - final static Any do262(Any ex) { // seed + final static Any do271(Any ex) { // seed long n; n = initSeed(ex.Cdr.Car.eval()) * 6364136223846793005L + 1; return new Number(Seed = n); } - final static Any do263(Any ex) { // rand + final static Any do272(Any ex) { // rand Any x; Seed = Seed * 6364136223846793005L + 1; if ((x = (ex = ex.Cdr).Car.eval()) == Nil) @@ -5598,11 +5940,11 @@ public class PicoLisp { return new Number(((Number)x).Cnt + (int)(Seed >>> 33) % (evInt(ex.Cdr) + 1 - ((Number)x).Cnt)); } - final static Any do264(Any ex) { // path + final static Any do273(Any ex) { // path return mkStr(path(evString(ex.Cdr))); } - final static Any do265(Any ex) { // read + final static Any do274(Any ex) { // read Any x, y; if (!((x = ex.Cdr) instanceof Cell)) x = InFile.read('\0'); @@ -5616,7 +5958,17 @@ public class PicoLisp { return x; } - final static Any do266(Any ex) { // char + final static Any do275(Any ex) { // wait + int i; + Any x, y; + i = (y = (x = ex.Cdr).Car.eval()) == Nil? -1 : xInt(y); + for (x = x.Cdr; (y = x.prog()) == Nil;) + if ((i = waitFd(ex, -1, i)) == 0) + return x.prog(); + return y; + } + + final static Any do276(Any ex) { // char Any x; if (!((ex = ex.Cdr) instanceof Cell)) { if (InFile.Chr == 0) @@ -5630,13 +5982,13 @@ public class PicoLisp { return x == T? mkChar((char)0x10000) : new Number(firstChar(x)); } - final static Any do267(Any ex) { // skip + final static Any do277(Any ex) { // skip char c; c = firstChar(ex.Cdr.Car.eval()); return InFile.skip(c) < 0? Nil : mkChar(c); } - final static Any do268(Any ex) { // line + final static Any do278(Any ex) { // line int i; Any x, y, z; StringBuilder sb; @@ -5660,7 +6012,7 @@ public class PicoLisp { } } - final static Any do269(Any ex) { // load + final static Any do279(Any ex) { // load Any x, y; x = ex.Cdr; do { @@ -5672,7 +6024,7 @@ public class PicoLisp { return y; } - final static Any do270(Any ex) { // in + final static Any do280(Any ex) { // in Any x; Env.pushInFile((x = ex.Cdr).Car.eval().rdOpen(ex)); x = x.Cdr.prog(); @@ -5680,7 +6032,7 @@ public class PicoLisp { return x; } - final static Any do271(Any ex) { // out + final static Any do281(Any ex) { // out Any x; Env.pushOutFile((x = ex.Cdr).Car.eval().wrOpen(ex)); x = x.Cdr.prog(); @@ -5688,19 +6040,19 @@ public class PicoLisp { return x; } - final static Any do272(Any ex) { // ctl + final static Any do282(Any ex) { // ctl return ex.Cdr.Cdr.prog(); // No locking } - final static Any do273(Any ex) { // open + final static Any do283(Any ex) { // open String str; str = evString(ex.Cdr); - try {return new Number(new PicoLispReader(new FileReader(str), str, -1).Fd);} + try {return new Number(new PicoLispReader(new FileReader(str), str, allocFd(), null, 0).Fd);} catch (IOException e) {} return Nil; } - final static Any do274(Any ex) { // close + final static Any do284(Any ex) { // close int i; Any x; if ((i = xInt(x = ex.Cdr.Car.eval())) >= 0 && i < InFiles.length) { @@ -5718,20 +6070,20 @@ public class PicoLisp { return Nil; } - final static Any do275(Any ex) { // prin + final static Any do285(Any ex) { // prin Any x, y; for (y = Nil; (ex = ex.Cdr) instanceof Cell; OutFile.Wr.print((y = ex.Car.eval()).name())); return y; } - final static Any do276(Any ex) { // prinl + final static Any do286(Any ex) { // prinl Any x, y; for (y = Nil; (ex = ex.Cdr) instanceof Cell; OutFile.Wr.print((y = ex.Car.eval()).name())); OutFile.newline(); return y; } - final static Any do277(Any ex) { // space + final static Any do287(Any ex) { // space int i; Any x; if ((x = ex.Cdr.Car.eval()) == Nil) { @@ -5743,7 +6095,7 @@ public class PicoLisp { return x; } - final static Any do278(Any ex) { // print + final static Any do288(Any ex) { // print Any x, y; OutFile.print(y = (x = ex.Cdr).Car.eval()); while ((x = x.Cdr) instanceof Cell) { @@ -5753,7 +6105,7 @@ public class PicoLisp { return y; } - final static Any do279(Any ex) { // printsp + final static Any do289(Any ex) { // printsp Any x, y; x = ex.Cdr; do { @@ -5763,7 +6115,7 @@ public class PicoLisp { return y; } - final static Any do280(Any ex) { // println + final static Any do290(Any ex) { // println Any x, y; OutFile.print(y = (x = ex.Cdr).Car.eval()); while ((x = x.Cdr) instanceof Cell) { @@ -5774,17 +6126,37 @@ public class PicoLisp { return y; } - final static Any do281(Any ex) { // flush + final static Any do291(Any ex) { // flush return OutFile.Wr.checkError()? Nil : T; } - final static Any do282(Any ex) { // connect + final static Any do292(Any ex) { // port + ex = ex.Cdr; // ... + try { + ServerSocketChannel chan = ServerSocketChannel.open();; + chan.socket().bind(new InetSocketAddress(evInt(ex))); + return new Number(new PicoLispReader(null, allocFd(), chan, SelectionKey.OP_ACCEPT).Fd); + } + catch (IOException e) {} + return Nil; + } + + final static Any do293(Any ex) { // accept + int i; + Any x; + if ((i = xInt(x = ex.Cdr.Car.eval())) < 0 || i >= InFiles.length || InFiles[i] == null || InFiles[i].Chan == null) + err(ex, x, "Bad socket"); + try {return mkSocket(((ServerSocketChannel)InFiles[i].Chan).accept());} + catch (IOException e) {} + return Nil; + } + + final static Any do294(Any ex) { // connect int i; try { - Socket sock = new Socket(evString(ex.Cdr), evInt(ex.Cdr.Cdr)); - i = new PicoLispReader(sock.getInputStream(), -1).Fd; - new PicoLispWriter(sock.getOutputStream(), i); - return new Number(i); + SocketChannel chan = SocketChannel.open(); + if (chan.connect(new InetSocketAddress(evString(ex.Cdr), evInt(ex.Cdr.Cdr)))) + return mkSocket(chan); } catch (IOException e) {} return Nil; @@ -5878,6 +6250,33 @@ public class PicoLisp { final String name() {return Big == null? Integer.toString(Cnt) : Big.toString();} final public String toString() {return name();} + final public String toString(int scl, char sep, char ign) { + String s = name(); + StringBuilder sb = new StringBuilder(); + if (s.charAt(0) == '-') { + sb.append('-'); + s = s.substring(1); + } + if ((scl = s.length() - scl - 1) < 0) { + sb.append('0'); + sb.append(sep); + while (scl < -1) { + sb.append('0'); + ++scl; + } + } + for (int i = 0;;) { + sb.append(s.charAt(i++)); + if (i == s.length()) + return sb.toString(); + if (scl == 0) + sb.append(sep); + else if (ign != '\0' && scl > 0 && scl % 3 == 0) + sb.append(ign); + --scl; + } + } + final Number abs() { if (Big == null) { if (Cnt >= 0) @@ -6011,6 +6410,7 @@ public class PicoLisp { } final static class Symbol extends Any { + Object Obj; Any Prop[]; String Name; @@ -6019,6 +6419,11 @@ public class PicoLisp { Name = nm; } + Symbol(Object obj) { + Car = this; + Obj = obj; + } + final Any put(Any key, Any val) { if (key.equal(Zero)) Car = val; @@ -6189,7 +6594,18 @@ public class PicoLisp { return Car.apply(ex, cf, v, n); } - final boolean equal(Any x) {return this == x || (x instanceof Symbol) && Name.equals(((Symbol)x).Name);} + final boolean equal(Any x) { + if (x == this) + return true; + if (x instanceof Symbol) { + Symbol s = (Symbol)x; + if (Name != null) + return Name.equals(s.Name); + if (Obj != null) + return Obj.equals(s.Obj); + } + return false; + } final int compare(Any x) { if (x == this) @@ -6207,15 +6623,15 @@ public class PicoLisp { return a.compareTo(b); } - final long length() {return Name == null? 0 : Name.length();} - final long size() {return Name == null? 0 : Name.getBytes().length;} + final long length() {return name().length();} + final long size() {return name().getBytes().length;} final InFrame rdOpen(Any ex) { try { - String nm = path(Name); + String nm = path(name()); if (nm.charAt(0) == '+') nm = nm.substring(1); // No file reader with "rw" mode - return new InFrame(new PicoLispReader(new FileReader(nm), nm, -1), 1); + return new InFrame(new PicoLispReader(new FileReader(nm), nm, allocFd(), null, 0), 1); } catch (IOException e) { err(ex, this, "Read open error"); @@ -6225,10 +6641,10 @@ public class PicoLisp { final OutFrame wrOpen(Any ex) { try { - String nm = path(Name); + String nm = path(name()); if (nm.charAt(0) == '+') - return new OutFrame(new PicoLispWriter(new PrintWriter(new FileWriter(nm.substring(1), true)), nm, -1), 1); - return new OutFrame(new PicoLispWriter(new PrintWriter(nm), nm, -1), 1); + return new OutFrame(new PicoLispWriter(new PrintWriter(new FileWriter(nm.substring(1), true)), nm, allocFd()), 1); + return new OutFrame(new PicoLispWriter(new PrintWriter(nm), nm, allocFd()), 1); } catch (IOException e) { err(ex, this, "Write open error"); @@ -6236,11 +6652,21 @@ public class PicoLisp { } } - final String name() {return Name == null? "" : Name;} + final String name() {return Name != null? Name : Obj == null? "" : Obj.toString();} final public String toString() { - if (Name == null) - return "$" + hashCode(); + if (Name == null) { + String s; + if (Obj == null) + return "$" + hashCode(); + int i = (s = Obj.getClass().toString()).lastIndexOf('.'); + if (i >= 0) + s = s.substring(i + 1); + if (s.startsWith("class ")) + s = s.substring(6); + return "$" + s; + + } if (Intern.get(Name) == this) { if (Name.equals(".")) return "\\."; @@ -6254,7 +6680,7 @@ public class PicoLisp { return sb.toString(); } StringBuilder sb = new StringBuilder(); - sb.append("\""); + sb.append('\"'); for (int i = 0; i < Name.length(); ++i) { char c = Name.charAt(i); if (c == '\\' || c == '^' || c == '"') @@ -6265,7 +6691,7 @@ public class PicoLisp { {sb.append('^'); c |= 0x40;} sb.append(c); } - sb.append("\""); + sb.append('\"'); return sb.toString(); } @@ -6273,9 +6699,9 @@ public class PicoLisp { Any x, y; PicoLispReader rd; if (s == null) - rd = new PicoLispReader(Name, '\n', ']'); + rd = new PicoLispReader(name(), '\n', ']'); else - rd = new PicoLispReader(Name, '\0', '\0'); + rd = new PicoLispReader(name(), '\0', '\0'); if (skp) rd.get(); if (s == null) @@ -6578,7 +7004,7 @@ public class PicoLisp { x = x.Cdr; } int pid = allocPid(); - return new InFrame(new PicoLispReader((Pids[pid] = Runtime.getRuntime().exec(cmd)).getInputStream(), -1), pid); + return new InFrame(new PicoLispReader((Pids[pid] = Runtime.getRuntime().exec(cmd)).getInputStream(), allocFd(), null, 0), pid); } catch (IOException e) { err(ex, this, "Pipe read open error"); @@ -6596,7 +7022,7 @@ public class PicoLisp { x = x.Cdr; } int pid = allocPid(); - return new OutFrame(new PicoLispWriter((Pids[pid] = Runtime.getRuntime().exec(cmd)).getOutputStream(), -1), pid); + return new OutFrame(new PicoLispWriter((Pids[pid] = Runtime.getRuntime().exec(cmd)).getOutputStream(), allocFd()), pid); } catch (IOException e) { err(ex, this, "Pipe write open error"); diff --git a/ersatz/README b/ersatz/README @@ -1,11 +1,12 @@ -30oct10abu +03nov10abu (c) Software Lab. Alexander Burger Ersatz PicoLisp =============== -Ersatz PicoLisp is a version of PicoLisp completely written in Java. +Ersatz PicoLisp is a version of PicoLisp completely written in Java. It requires +a 1.6 Java Runtime Environment. It should be the last resort when there is no other way to run a "real" PicoLisp. Also, it may be used to bootstrap the 64-bit version, which requires a @@ -16,8 +17,12 @@ of memory at startup (600 MB vs. 3 MB), and needs 2.5 to 4 times the space for runtime Lisp data. But efficiency was not a major goal. Instead, performance was often sacrificed in favor of simpler or more modular structures. -There is no support for child processes ('fork'), interprocess communication -('tell', 'hear', 'ipc' etc.) and databases (external symbols). +There is no support for + +- raw console inpt ('key') and line editing +- child processes ('fork') +- interprocess communication ('tell', 'hear', 'ipc' etc.) +- databases (external symbols) Invocation diff --git a/ersatz/fun.src b/ersatz/fun.src @@ -1,4 +1,4 @@ -# 01nov10abu +# 05nov10abu # (c) Software Lab. Alexander Burger # Ersatz PicoLisp Functions @@ -9,6 +9,175 @@ quit (str) str = evString(ex = ex.Cdr); return err(null, (ex = ex.Cdr) instanceof Cell? ex.Car.eval() : null, str); +# (public 'obj 'any) -> obj +# (public 'cls 'any) -> obj +public (x y z s o) + y = (x = ex.Cdr).Car.eval(); + z = (x = x.Cdr).Car.eval(); + try { + if ((s = (Symbol)y).Obj != null) + o = s.Obj.getClass().getField(z.name()).get(s.Obj); + else { + java.lang.Class cls = java.lang.Class.forName(s.Name); + o = cls.getField(z.name()).get(cls); + } + return new Symbol(o); + } + catch (Exception e) {return err(ex, null, e.toString());} + +# (java 'cls 'T 'any ..) -> obj +# (java 'cls 'msg 'any ..) -> obj +# (java 'obj 'msg 'any ..) -> obj +java (num i j k x y z s v o) + y = (x = ex.Cdr).Car.eval(); + z = (x = x.Cdr).Car.eval(); + for (v = new Any[6], i = 0; (x = x.Cdr) instanceof Cell;) + v = append(v, i++, x.Car.eval()); + Object[] arg = new Object[i]; + Class[] par = new Class[i]; + while (--i >= 0) { + if (v[i] == Nil || v[i] == T) { + arg[i] = v[i] == T; + par[i] = Boolean.TYPE; + } + else if (v[i] instanceof Number) { + if ((num = (Number)v[i]).Big != null) + cntError(ex, num); + arg[i] = new Integer(num.Cnt); + par[i] = Integer.TYPE; + } + else if (v[i] instanceof Cell) { + k = (int)v[i].length(); + if (v[i].Car instanceof Number) { + arg[i] = new int[k]; + for (j = 0; j < k; ++j, v[i] = v[i].Cdr) + Array.setInt(arg[i], j, ((Number)v[i].Car).Cnt); + } + else if (v[i].Car instanceof Cell) + argError(ex, v[i]); + else if ((s = (Symbol)v[i].Car).Obj == null) { + arg[i] = Array.newInstance(s.Name.getClass(), k); + for (j = 0; j < k; ++j, v[i] = v[i].Cdr) + Array.set(arg[i], j, ((Symbol)v[i].Car).Name); + } + else { + if (s.Obj instanceof Byte) + arg[i] = Array.newInstance(Byte.TYPE, k); + else if (s.Obj instanceof Character) + arg[i] = Array.newInstance(Character.TYPE, k); + else if (s.Obj instanceof Integer) + arg[i] = Array.newInstance(Integer.TYPE, k); + else if (s.Obj instanceof Long) + arg[i] = Array.newInstance(Long.TYPE, k); + else + arg[i] = Array.newInstance(s.Obj.getClass(), k); + for (j = 0; j < k; ++j, v[i] = v[i].Cdr) + Array.set(arg[i], j, ((Symbol)v[i].Car).Obj); + } + par[i] = arg[i].getClass(); + } + else if ((s = (Symbol)v[i]).Obj == null) + par[i] = (arg[i] = s.Name).getClass(); + else { + arg[i] = s.Obj; + if (s.Obj instanceof Byte) + par[i] = Byte.TYPE; + else if (s.Obj instanceof Character) + par[i] = Character.TYPE; + else if (s.Obj instanceof Integer) + par[i] = Integer.TYPE; + else if (s.Obj instanceof Long) + par[i] = Long.TYPE; + else + par[i] = s.Obj.getClass(); + } + } + try { + if (z == T) + return new Symbol(java.lang.Class.forName(y.name()).getConstructor(par).newInstance(arg)); + Method m = (s = (Symbol)y).Obj == null? java.lang.Class.forName(s.Name).getMethod(z.name(),par) : s.Obj.getClass().getMethod(z.name(),par); + o = m.invoke(s.Obj, arg); + if (m.getReturnType() == Void.TYPE) + return Nil; + return new Symbol(o); + } + catch (Exception e) {return err(ex, null, e.toString());} + +# (byte: 'num|sym) -> obj +byte: (x) + x = ex.Cdr.Car.eval(); + return new Symbol(new Byte(x instanceof Number? (byte)((Number)x).Cnt : (byte)x.name().charAt(0))); + +# (char: 'num|sym) -> obj +char: (x) + x = ex.Cdr.Car.eval(); + return new Symbol(new Character(x instanceof Number? (char)((Number)x).Cnt : x.name().charAt(0))); + +# (int: 'num) -> obj +int: () + return new Symbol(new Integer(evInt(ex.Cdr))); + +# (long: 'num) -> obj +long: () + return new Symbol(new Long(evLong(ex.Cdr))); + +# (double: 'num 'cnt) -> obj +double: (num) + num = (Number)((ex = ex.Cdr).Car.eval()); + return new Symbol(new Double(num.toString(evInt(ex.Cdr), '.', '\0'))); + +# (big: 'num) -> obj +big: (num) + num = (Number)(ex.Cdr.Car.eval()); + return new Symbol(num.Big == null? big(num.Cnt) : num.Big); + +# (data 'obj ['cnt]) -> any +data (i j x y s) + x = Nil; + if ((y = ex.Cdr.Car.eval()) instanceof Symbol && (s = (Symbol)y).Obj != null) { + if (s.Obj instanceof Byte) + x = new Number(((Byte)s.Obj).byteValue()); + else if (s.Obj instanceof Character) + x = new Number(((Character)s.Obj).charValue()); + else if (s.Obj instanceof Integer) + x = new Number(((Integer)s.Obj).intValue()); + else if (s.Obj instanceof Long) + x = new Number(((Long)s.Obj).longValue()); + else if (s.Obj instanceof Double) + x = strToNum(Double.toString(((Double)s.Obj).doubleValue()), evInt(ex.Cdr.Cdr)); + else if (s.Obj instanceof BigInteger) + x = new Number((BigInteger)s.Obj); + else if (s.Obj instanceof String) + x = mkStr((String)s.Obj); + else if (s.Obj instanceof byte[]) { + byte[] a = (byte[])s.Obj; + for (i = a.length; --i >= 0;) + x = new Cell(new Number(a[i]), x); + } + else if (s.Obj instanceof char[]) { + char[] a = (char[])s.Obj; + for (i = a.length; --i >= 0;) + x = new Cell(new Number(a[i]), x); + } + else if (s.Obj instanceof int[]) { + int[] a = (int[])s.Obj; + for (i = a.length; --i >= 0;) + x = new Cell(new Number(a[i]), x); + } + else if (s.Obj instanceof long[]) { + long[] a = (long[])s.Obj; + for (i = a.length; --i >= 0;) + x = new Cell(new Number(a[i]), x); + } + else if (s.Obj instanceof double[]) { + double[] a = (double[])s.Obj; + j = evInt(ex.Cdr.Cdr); + for (i = a.length; --i >= 0;) + x = new Cell(strToNum(Double.toString(a[i]), i), x); + } + } + return x; + # (args) -> flg args T return Env.Next < Env.ArgC? T : Nil; @@ -1302,7 +1471,7 @@ name (x y s) return mkStr(y.name()); if ((s = ((Symbol)y)).Name != null && Intern.get(s.Name) == s) err(ex, s, "Can't rename"); - ((Symbol)(x = x.Car.eval())).Name = s.Name; + s.Name = ((Symbol)(x = x.Car.eval())).Name; return s; # (sp? 'any) -> flg @@ -2818,6 +2987,14 @@ read (x y) InFile.Chr = 0; return x; +# (wait ['cnt] . prg) -> any +wait (i x y) + i = (y = (x = ex.Cdr).Car.eval()) == Nil? -1 : xInt(y); + for (x = x.Cdr; (y = x.prog()) == Nil;) + if ((i = waitFd(ex, -1, i)) == 0) + return x.prog(); + return y; + # (char) -> sym # (char 'cnt) -> sym # (char T) -> sym @@ -2892,7 +3069,7 @@ ctl () # (open 'any) -> cnt | NIL open (str) str = evString(ex.Cdr); - try {return new Number(new PicoLispReader(new FileReader(str), str, -1).Fd);} + try {return new Number(new PicoLispReader(new FileReader(str), str, allocFd(), null, 0).Fd);} catch (IOException e) {} return Nil; @@ -2966,13 +3143,31 @@ flush () return OutFile.Wr.checkError()? Nil : T; ############ net ############ +# (port ['T] 'cnt|(cnt . cnt) ['var]) -> cnt +port () + ex = ex.Cdr; // ... + try { + ServerSocketChannel chan = ServerSocketChannel.open();; + chan.socket().bind(new InetSocketAddress(evInt(ex))); + return new Number(new PicoLispReader(null, allocFd(), chan, SelectionKey.OP_ACCEPT).Fd); + } + catch (IOException e) {} + return Nil; + +# (accept 'cnt) -> cnt | NIL +accept (i x) + if ((i = xInt(x = ex.Cdr.Car.eval())) < 0 || i >= InFiles.length || InFiles[i] == null || InFiles[i].Chan == null) + err(ex, x, "Bad socket"); + try {return mkSocket(((ServerSocketChannel)InFiles[i].Chan).accept());} + catch (IOException e) {} + return Nil; + # (connect 'any 'cnt) -> cnt | NIL connect (i) try { - Socket sock = new Socket(evString(ex.Cdr), evInt(ex.Cdr.Cdr)); - i = new PicoLispReader(sock.getInputStream(), -1).Fd; - new PicoLispWriter(sock.getOutputStream(), i); - return new Number(i); + SocketChannel chan = SocketChannel.open(); + if (chan.connect(new InetSocketAddress(evString(ex.Cdr), evInt(ex.Cdr.Cdr)))) + return mkSocket(chan); } catch (IOException e) {} return Nil; diff --git a/ersatz/mkJar b/ersatz/mkJar @@ -1,5 +1,5 @@ #!../bin/picolisp ../lib.l -# 29oct10abu +# 04nov10abu # (c) Software Lab. Alexander Burger (load "@ext.l" "@src64/version.l") @@ -77,6 +77,7 @@ (local Vars "StringBuilder" '(sb)) (local Vars "Any[]" '(v)) (local Vars "Bind" '(bnd)) + (local Vars "Object" '(o)) (while (line) (prinl " " @) ) (prinl " }") diff --git a/ersatz/picolisp.jar b/ersatz/picolisp.jar Binary files differ. diff --git a/ersatz/sys.src b/ersatz/sys.src @@ -1,13 +1,18 @@ -// 01nov10abu +// 05nov10abu // (c) Software Lab. Alexander Burger -import java.io.*; -import java.net.*; import java.util.*; import java.math.*; +import java.io.*; +import java.net.*; +import java.nio.*; +import java.nio.channels.*; +import java.nio.channels.spi.*; +import java.lang.reflect.*; /* Ersatz PicoLisp Interpreter (Poor Man's PicoLisp) */ public class PicoLisp { + final static Console Term = System.console(); final static HashMap<String,Symbol> Intern = new HashMap<String,Symbol>(); final static HashMap<String,Symbol> Transient = new HashMap<String,Symbol>(); final static byte MonLen[] = new byte[] {31,31,28,31,30,31,30,31,31,30,31,30,31}; @@ -40,10 +45,11 @@ public class PicoLisp { static Catch Catch; static Env Env = new Env(); + static StringBuilder Line; static Process[] Pids = new Process[12]; static PicoLispReader[] InFiles = new PicoLispReader[12]; static PicoLispWriter[] OutFiles = new PicoLispWriter[12]; - final static PicoLispReader StdIn = new PicoLispReader(System.in, 0); + final static PicoLispReader StdIn = new PicoLispReader(System.in, 0, null, 0); final static PicoLispWriter StdOut = new PicoLispWriter(System.out, 1); final static PicoLispWriter StdErr = new PicoLispWriter(System.err, 2); static PicoLispReader InFile = StdIn; @@ -59,9 +65,8 @@ public class PicoLisp { public static void main(String[] argv) { Argv = argv; - init(); <SYM> 1 - USec = System.nanoTime() / 1000; + init(); for (boolean first = true; ; first = false) { try { if (first) @@ -83,6 +88,35 @@ public class PicoLisp { Home = s.substring(0, i+1); break; } + try { + if (Term != null) { + final Pipe p = Pipe.open(); + StdIn.Chan = p.source(); + StdIn.Ops = SelectionKey.OP_READ; + (new Thread() { + public void run() { + for (;;) { + String s = Term.readLine(); + if (s == null) + Line = null; + else { + Line = new StringBuilder(s); + Line.append('\n'); + } + try {p.sink().write(ByteBuffer.allocate(1));} + catch (IOException e) {giveup(e);} + } + } + } ).start(); + } + } + catch (IOException e) {giveup(e);} + USec = System.nanoTime() / 1000; + } + + final static void giveup(Exception e) { + System.err.println(e); + System.exit(1); } final static Any bye(int n) { @@ -95,6 +129,66 @@ public class PicoLisp { return null; /* Brain-dead Java */ } + final static int waitFd(Any ex, int fd, int ms) { + int i; + Selector sel; + Any task = Env.Task, at = At.Car; + try { + for (;;) { + sel = Selector.open(); + int t = ms >= 0? ms : Integer.MAX_VALUE; + if (fd >= 0 && InFiles[fd] != null) + InFiles[fd].register(sel); + for (Any x = Env.Task = Run.Car; x instanceof Cell; x = x.Cdr) { + if (memq(x.Car, task) == null) { + if ((i = ((Number)x.Car.Car).Cnt) < 0) { + if ((i = ((Number)x.Car.Cdr.Car).Cnt) < t) + t = i; + } + else if (i != fd) { + if (i < InFiles.length && InFiles[i] != null) + InFiles[i].register(sel); + } + } + } + long d = System.currentTimeMillis(); + if (t == 0) + sel.selectNow(); + else + sel.select(t); + t = (int)(System.currentTimeMillis() - d); + if (ms > 0 && (ms -= t) < 0) + ms = 0; + for (Any x = Env.Task; x instanceof Cell; x = x.Cdr) { + if (memq(x.Car, task) == null) { + if ((i = ((Number)x.Car.Car).Cnt) < 0) { + if ((i = ((Number)x.Car.Cdr.Car).Cnt - t) > 0) + ((Number)x.Car.Cdr.Car).Cnt = i; + else { + ((Number)x.Car.Cdr.Car).Cnt = -((Number)x.Car.Car).Cnt; + At.Car = x.Car.Car; + x.Car.Cdr.Cdr.prog(); + } + } + else if (i != fd) { + if (i < InFiles.length && InFiles[i] != null && InFiles[i].isReady(sel)) { + At.Car = x.Car.Car; + x.Car.Cdr.prog(); + } + } + } + } + if (ms == 0 || fd < 0 || InFiles[fd] != null && InFiles[fd].isReady(sel)) + break; + sel.close(); + } + } + catch (IOException e) {giveup(e);} + At.Car = at; + Env.Task = task; + return ms; + } + final static long initSeed(Any x) { long n; for (n = 0; x instanceof Cell; x = x.Cdr) @@ -258,7 +352,7 @@ public class PicoLisp { unwind(null); Env.Args = null; Env.Next = 0; - Env.Make = Env.Yoke = null; + Env.Task = Env.Make = Env.Yoke = null; } final static Any err(Any ex, Any x, String msg) { @@ -310,6 +404,8 @@ public class PicoLisp { final static Any execError(Any x) {return err(null, x, "Can't execute");} final static Any protError(Any x) {return err(null, x, "Protected symbol");} final static Any symError(Any x) {return err(null, x, "Symbol expected");} + final static Any argError(Any ex, Any x) {return err(ex, x, "Bad argument");} + final static Any cntError(Any ex, Any x) {return err(ex, x, "Small number expected");} final static void needVar(Any ex, Any x) {if (x instanceof Number) err(ex, x, "Variable expected");} final static void badFd(Any ex, Any x) {err(ex, x, "Bad FD");} @@ -409,6 +505,14 @@ public class PicoLisp { return i; } + final static Any mkSocket(SocketChannel chan) throws IOException { + int i = allocFd(); + Socket sock = chan.socket(); + new PicoLispReader(sock.getInputStream(), i, chan, SelectionKey.OP_READ); + new PicoLispWriter(sock.getOutputStream(), i); + return new Number(i); + } + final static Any mkChar(char c) {return new Symbol(null, "" + c);} final static Any mkStr(String nm) {return nm == null || nm.length() == 0? Nil : new Symbol(null, nm);} final static Any mkStr(StringBuilder sb) {return mkStr(sb.toString());} @@ -445,33 +549,10 @@ public class PicoLisp { if ((x = x.Cdr) instanceof Cell) ign = firstChar(x.Car.eval()); } - StringBuilder sb = new StringBuilder(); - if (z instanceof Number) { - String s = z.toString(); - if (s.charAt(0) == '-') { - sb.append('-'); - s = s.substring(1); - } - if ((scl = s.length() - scl - 1) < 0) { - sb.append('0'); - sb.append(sep); - while (scl < -1) { - sb.append('0'); - ++scl; - } - } - for (int i = 0;;) { - sb.append(s.charAt(i++)); - if (i == s.length()) - return mkStr(sb); - if (scl == 0) - sb.append(sep); - else if (ign != '\0' && scl > 0 && scl % 3 == 0) - sb.append(ign); - --scl; - } - } + if (z instanceof Number) + return mkStr(((Number)z).toString(scl,sep,ign)); String s = z.name(); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); ++i) { char c = s.charAt(i); if (c != ign) @@ -1179,30 +1260,59 @@ public class PicoLisp { LineNumberReader Rd; String Name; char Eof1, Eof2; - int Fd, Chr, Src; + int Fd, Chr, Src, Ops; + SelectableChannel Chan; + SelectionKey Key; - PicoLispReader(Reader rd, String nm, int fd) { - Rd = new LineNumberReader(rd); + PicoLispReader(Reader rd, String nm, int fd, SelectableChannel chan, int ops) { + if (rd != null) + Rd = new LineNumberReader(rd); Name = nm; - if (fd < 0) - fd = allocFd(); InFiles[Fd = fd] = this; + Chan = chan; + Ops = ops; } - PicoLispReader(InputStream in, int fd) { - this(new InputStreamReader(in), null, fd); + PicoLispReader(InputStream in, int fd, SelectableChannel chan, int ops) { + this(in == null? null : new InputStreamReader(in), null, fd, chan, ops); } PicoLispReader(String s, char eof1, char eof2) { - this(new StringReader(s), null, -1); + Rd = new LineNumberReader(new StringReader(s)); Eof1 = eof1; Eof2 = eof2; } + final boolean register(Selector sel) { + if (Ops != 0) { + try { + Chan.configureBlocking(false); + Key = Chan.register(sel, Ops); + return true; + } + catch (IOException e) {} + } + return false; + } + + final boolean isReady(Selector sel) { + boolean rdy = false; + if (Key != null) { + rdy = (Key.readyOps() & Ops) != 0; + Key.cancel(); + try{Chan.configureBlocking(true);} + catch (IOException e) {} + } + return rdy; + } + final void close() { try { + if (Chan != null) + Chan.close(); + if (Rd != null) + Rd.close(); InFiles[Fd] = null; - Rd.close(); } catch (IOException e) {closeErr(e);} } @@ -1211,7 +1321,22 @@ public class PicoLisp { final int get() { try { - if ((Chr = Rd.read()) < 0) { + if (this != StdIn || Term == null) + Chr = Rd.read(); + else { + if (Line == null) { + waitFd(null, 0, -1); + ((Pipe.SourceChannel)StdIn.Chan).read(ByteBuffer.allocate(1)); + } + if (Line == null) + Chr = -1; + else { + Chr = Line.charAt(0); + if (Line.deleteCharAt(0).length() == 0) + Line = null; + } + } + if (Chr < 0) { if ((Chr = Eof1) != 0) Eof1 = '\0'; else if ((Chr = Eof2) != 0) @@ -1452,8 +1577,6 @@ public class PicoLisp { PicoLispWriter(PrintWriter wr, String nm, int fd) { Wr = wr; Name = nm; - if (fd < 0) - fd = allocFd(); OutFiles[Fd = fd] = this; } @@ -1462,8 +1585,8 @@ public class PicoLisp { } final void close() { - OutFiles[Fd] = null; Wr.close(); + OutFiles[Fd] = null; } final void print(Any x) {Wr.print(x.toString());} @@ -1492,7 +1615,7 @@ public class PicoLisp { final static class Env { int Next, ArgC, Trace; Bind Bind; - Any Arg, Args[], Cls, Key, Make, Yoke; + Any Arg, Args[], Cls, Key, Task, Make, Yoke; InFrame InFrames; OutFrame OutFrames; @@ -1503,6 +1626,7 @@ public class PicoLisp { Bind = env.Bind; Arg = env.Arg; Args = env.Args; Cls = env.Cls; Key = env.Key; + Task = env.Task; Make = env.Make; Yoke = env.Yoke; InFrames = env.InFrames; OutFrames = env.OutFrames; } @@ -1763,6 +1887,33 @@ public class PicoLisp { final String name() {return Big == null? Integer.toString(Cnt) : Big.toString();} final public String toString() {return name();} + final public String toString(int scl, char sep, char ign) { + String s = name(); + StringBuilder sb = new StringBuilder(); + if (s.charAt(0) == '-') { + sb.append('-'); + s = s.substring(1); + } + if ((scl = s.length() - scl - 1) < 0) { + sb.append('0'); + sb.append(sep); + while (scl < -1) { + sb.append('0'); + ++scl; + } + } + for (int i = 0;;) { + sb.append(s.charAt(i++)); + if (i == s.length()) + return sb.toString(); + if (scl == 0) + sb.append(sep); + else if (ign != '\0' && scl > 0 && scl % 3 == 0) + sb.append(ign); + --scl; + } + } + final Number abs() { if (Big == null) { if (Cnt >= 0) @@ -1896,6 +2047,7 @@ public class PicoLisp { } final static class Symbol extends Any { + Object Obj; Any Prop[]; String Name; @@ -1904,6 +2056,11 @@ public class PicoLisp { Name = nm; } + Symbol(Object obj) { + Car = this; + Obj = obj; + } + final Any put(Any key, Any val) { if (key.equal(Zero)) Car = val; @@ -2074,7 +2231,18 @@ public class PicoLisp { return Car.apply(ex, cf, v, n); } - final boolean equal(Any x) {return this == x || (x instanceof Symbol) && Name.equals(((Symbol)x).Name);} + final boolean equal(Any x) { + if (x == this) + return true; + if (x instanceof Symbol) { + Symbol s = (Symbol)x; + if (Name != null) + return Name.equals(s.Name); + if (Obj != null) + return Obj.equals(s.Obj); + } + return false; + } final int compare(Any x) { if (x == this) @@ -2092,15 +2260,15 @@ public class PicoLisp { return a.compareTo(b); } - final long length() {return Name == null? 0 : Name.length();} - final long size() {return Name == null? 0 : Name.getBytes().length;} + final long length() {return name().length();} + final long size() {return name().getBytes().length;} final InFrame rdOpen(Any ex) { try { - String nm = path(Name); + String nm = path(name()); if (nm.charAt(0) == '+') nm = nm.substring(1); // No file reader with "rw" mode - return new InFrame(new PicoLispReader(new FileReader(nm), nm, -1), 1); + return new InFrame(new PicoLispReader(new FileReader(nm), nm, allocFd(), null, 0), 1); } catch (IOException e) { err(ex, this, "Read open error"); @@ -2110,10 +2278,10 @@ public class PicoLisp { final OutFrame wrOpen(Any ex) { try { - String nm = path(Name); + String nm = path(name()); if (nm.charAt(0) == '+') - return new OutFrame(new PicoLispWriter(new PrintWriter(new FileWriter(nm.substring(1), true)), nm, -1), 1); - return new OutFrame(new PicoLispWriter(new PrintWriter(nm), nm, -1), 1); + return new OutFrame(new PicoLispWriter(new PrintWriter(new FileWriter(nm.substring(1), true)), nm, allocFd()), 1); + return new OutFrame(new PicoLispWriter(new PrintWriter(nm), nm, allocFd()), 1); } catch (IOException e) { err(ex, this, "Write open error"); @@ -2121,11 +2289,21 @@ public class PicoLisp { } } - final String name() {return Name == null? "" : Name;} + final String name() {return Name != null? Name : Obj == null? "" : Obj.toString();} final public String toString() { - if (Name == null) - return "$" + hashCode(); + if (Name == null) { + String s; + if (Obj == null) + return "$" + hashCode(); + int i = (s = Obj.getClass().toString()).lastIndexOf('.'); + if (i >= 0) + s = s.substring(i + 1); + if (s.startsWith("class ")) + s = s.substring(6); + return "$" + s; + + } if (Intern.get(Name) == this) { if (Name.equals(".")) return "\\."; @@ -2139,7 +2317,7 @@ public class PicoLisp { return sb.toString(); } StringBuilder sb = new StringBuilder(); - sb.append("\""); + sb.append('\"'); for (int i = 0; i < Name.length(); ++i) { char c = Name.charAt(i); if (c == '\\' || c == '^' || c == '"') @@ -2150,7 +2328,7 @@ public class PicoLisp { {sb.append('^'); c |= 0x40;} sb.append(c); } - sb.append("\""); + sb.append('\"'); return sb.toString(); } @@ -2158,9 +2336,9 @@ public class PicoLisp { Any x, y; PicoLispReader rd; if (s == null) - rd = new PicoLispReader(Name, '\n', ']'); + rd = new PicoLispReader(name(), '\n', ']'); else - rd = new PicoLispReader(Name, '\0', '\0'); + rd = new PicoLispReader(name(), '\0', '\0'); if (skp) rd.get(); if (s == null) @@ -2463,7 +2641,7 @@ public class PicoLisp { x = x.Cdr; } int pid = allocPid(); - return new InFrame(new PicoLispReader((Pids[pid] = Runtime.getRuntime().exec(cmd)).getInputStream(), -1), pid); + return new InFrame(new PicoLispReader((Pids[pid] = Runtime.getRuntime().exec(cmd)).getInputStream(), allocFd(), null, 0), pid); } catch (IOException e) { err(ex, this, "Pipe read open error"); @@ -2481,7 +2659,7 @@ public class PicoLisp { x = x.Cdr; } int pid = allocPid(); - return new OutFrame(new PicoLispWriter((Pids[pid] = Runtime.getRuntime().exec(cmd)).getOutputStream(), -1), pid); + return new OutFrame(new PicoLispWriter((Pids[pid] = Runtime.getRuntime().exec(cmd)).getOutputStream(), allocFd()), pid); } catch (IOException e) { err(ex, this, "Pipe write open error");