jcw@cvl.UUCP (Jay C. Weber) (07/20/84)
This is the fairly portable C implementation of XLISP that I mentioned a little while ago. I received literally dozens of replies voicing interest, and only one snide message asking me not to post it. So here it is, written by David Betz, who I believe works for DEC and may be on the net. If you have any sort of system that has a C compiler and not LISP, give this a look over. It has been written pretty nicely, and is rumored to have been successfully ported to a number of systems, including an Apple with Aztec C, an IBM PC with CI-C86, a Vax 11/780 with Berkeley Unix, etc. (although I only have experrience with getting it going with CI-C86 and Unix). This portion contains a sample Unix Makefile, code for LONGJMP on an IBM PC under CI-C86, and the XLISP document (already roffed). Tear at the dotted line and run sh(1) over it. Jay Weber ..!seismo!rlgvax!cvl!jcw ..!seismo!rochester!jay jay@rochester.arpa P.S. My posting this does not mean that I support it. Problems with it would be more appropriately addressed to the author, although I don't know the whereabouts or disposition of him. ----------------------------------------------------- : Run this shell script with "sh" not "csh" PATH=:/bin:/usr/bin:/usr/ucb export PATH /bin/echo 'Extracting Makefile' sed 's/^X//' <<'//go.sysin dd *' >Makefile X# X# Makefile for David Betz' XLISP interpreter X# XCFLAGS = -I. -Dunix -O X XOBJS=xlisp.o xldmem.o xleval.o xlread.o xlio.o xlprin.o xlbind.o xlstr.o\ X xlfio.o xlsubr.o xlfmath.o xllist.o xlobj.o xlkmap.o xldebug.o X Xxlisp :$(OBJS) X cc -o xlisp $(OBJS) //go.sysin dd * /bin/chmod 664 Makefile /bin/echo -n ' '; /bin/ls -ld Makefile /bin/echo 'Extracting longjmp.asm' sed 's/^X//' <<'//go.sysin dd *' >longjmp.asm X XCODE SEGMENT BYTE PUBLIC X ASSUME CS:CODE X X PUBLIC setjmp, longjmp X Xsetjmp PROC NEAR X X POP AX ; Fetch return address from stack X POP BX ; Buffer pointer X X MOV [BX],BP ; Save BP X MOV [BX+2],SP ; , SP at return X MOV [BX+4],AX ; and IP X X PUSH BX ; Restore stack X PUSH AX X RET X Xsetjmp ENDP X X Xlongjmp PROC NEAR X X POP AX X POP BX X MOV BP,[BX] X MOV SP,[BX+2] X PUSH AX X X MOV AX,[BX+4] X JMP AX X Xlongjmp ENDP X XCODE ENDS X END //go.sysin dd * /bin/chmod 664 longjmp.asm /bin/echo -n ' '; /bin/ls -ld longjmp.asm /bin/echo 'Extracting xlisp.doc' sed 's/^X//' <<'//go.sysin dd *' >xlisp.doc X X X X X XLISP: An Experimental Object Oriented Language X X X by X David Betz X 114 Davenport Ave. X Manchester, NH 03103 X X (603) 625-4691 X X X XLISP is an experimental programming language combining some X of the features of LISP with an object oriented extension X capability. It was implemented to allow experimentation X with object oriented programming on small computers. There X are currently implementations running on the PDP-11 under X RSX-11, RT-11, and UNIX V7, on the VAX-11 under VAX/VMS and X Berkeley VAX/UNIX and on the Z-80 running CP/M-80. It is X completely written in the programming language 'C' and is X believed to be easily extended with user written builtin X functions and classes. It is available free of charge and X is in the public domain. X X Many traditional LISP functions are built into XLISP. In X addition, XLISP defines the object classes 'Object', X 'Class', and 'Keymap' as primitives. 'Object' is the only X class that has no superclass and hence is the root of the X class heirarchy tree. 'Class' is the class of which all X classes are instances (it is the only object that is an X instance of itself). 'Keymap' is a class whose instances X are mappings from input key sequences to messages. X X This document is intended to be a brief description of X XLISP. It assumes some knowledge of LISP and some X understanding of the concepts of object oriented X programming. X X XLISP: An Experimental Object Oriented Language Page 2 X XLISP Command Loop X X X When XLISP is started, it issues the following prompt: X X > X X This indicates that XLISP is waiting for an expression to be X typed. When an incomplete expression has been typed (one X where the left and right parens don't match) XLISP changes X its prompt to: X X n> X X where n is an integer indicating how many levels of parens X remain unclosed. X X When a complete expression has been entered, XLISP attempts X to evaluate that expression. If the expression evaluates X successfully, XLISP prints the result of the evaluation and X then returns to the initial prompt waiting for another X expression to be typed. X X Input can be aborted at any time by typing the EOF key. X Another EOF will exit from XLISP. X X XLISP: An Experimental Object Oriented Language Page 3 X DATA TYPES AND THE EVALUATOR X X X XLISP data types X X There are several different data types available to XLISP X programmers. X X X o symbols X X o strings X X o integers X X o objects X X o file pointers X X o lists X X o subrs (builtin functions) X X X The XLISP evaluator X X The process of evaluation in XLISP: X X o Integers, strings, objects, file pointers, and X subrs evaluate to themselves X X o Symbols evaluate to the value associated with their X current binding X X o Lists are evaluated by evaluating the first element X of the list X X o If it evaluates to a subr, the builtin function X is executed using the remaining list elements X as arguments (they are evaluated by the subr X itself) X X o If it evaluates to a list, the list is assumed X to be a function definition and the function is X evaluated using the values of the remaining X list elements as arguments X X o If it evaluates to an object, the second list X element is evaluated and used as a message X selector. The message formed by combining the X selector with the values of the remaining list X elements is sent to the object. X X X X XLISP: An Experimental Object Oriented Language Page 4 X LEXICAL CONVENTIONS X X X XLISP lexical conventions: X X The following conventions are followed when entering XLISP X programs: X X Comments in XLISP code begin with a semi-colon character and X continue to the end of the line. X X Symbol names in XLISP can consist of any sequence of X non-blank printable characters except the following: X X ( ) . ' " ; X X Symbol names must not begin with a digit. X X Integer literals consist of a sequence of digits optionally X beginning with a '+' or '-'. The range of values an integer X can represent is limited by the size of a C 'int' on the X machine that XLISP is running on. X X Literal strings are sequences of characters surrounded by X double quotes. Within quoted strings the '\' character is X used to allow non-printable characters to be included. The X codes recognized are: X X \\ means the character '\' X \n means newline X \t means tab X \r means return X \e means escape X \nnn means the character whose octal code is nnn X X The single quote character can be used as a shorthand for a X call on the function 'quote': X X 'foo X is equivalent to: X (quote foo) X X XLISP: An Experimental Object Oriented Language Page 5 X OBJECTS X X X Objects: X X Definitions: X X o selector - a symbol used to select an appropriate X method X X o message - a selector and a list of actual arguments X X o method - the code that implements a message X X Since XLISP was created to provide a simple basis for X experimenting with object oriented programming, one of the X primitive data types included was 'object'. In XLISP, an X object consists of a data structure containing a pointer to X the object's class as well as a list containing the values X of the object's instance variables. X X Officially, there is no way to see inside an object (look at X the values of its instance variables). The only way to X communicate with an object is by sending it a message. When X the XLISP evaluator evaluates a list the value of whose X first element is an object, it interprets the value of the X second element of the list (which must be a symbol) as the X message selector. The evaluator determines the class of the X receiving object and attempts to find a method corresponding X to the message selector in the set of messages defined for X that class. If the message is not found in the object's X class and the class has a super-class, the search continues X by looking at the messages defined for the super-class. X This process continues from one super-class to the next X until a method for the message is found. If no method is X found, an error occurs. X X When a method is found, the evaluator binds the receiving X object to the symbol 'self', binds the class in which the X method was found to the symbol 'msgclass', and evaluates the X method using the remaining elements of the original list as X arguments to the method. These arguments are always X evaluated prior to being bound to their corresponding formal X arguments. The result of evaluating the method becomes the X result of the expression. X X XLISP: An Experimental Object Oriented Language Page 6 X OBJECTS X X X Classes: X X Object THE TOP OF THE CLASS HEIRARCHY X X Messages: X X print THE DEFAULT OBJECT PRINT ROUTINE X returns the object X X show SHOW AN OBJECT'S INSTANCE VARIABLES X returns the object X X class RETURN THE CLASS OF AN OBJECT X returns the class of the object X X isnew THE DEFAULT OBJECT INITIALIZATION ROUTINE X returns the object X X sendsuper <sel> [<args>...] SEND SUPERCLASS A MESSAGE X <sel> the message selector X <args> the message arguments X returns the result of sending the message X X X Class THE CLASS OF ALL OBJECT CLASSES (including itself) X X Messages: X X new CREATE A NEW INSTANCE OF A CLASS X returns the new class object X X isnew [<scls>] INITIALIZE A NEW CLASS X <scls> the superclass X returns the new class object X X answer <msg> <fargs> <code> ADD A MESSAGE TO A CLASS X <msg> the message symbol X <fargs> the formal argument list X this list is of the form: X (<farg>... [/ <local>...]) X where X <farg> a formal argument X <local> a local variable X <code> a list of executable expressions X returns the object X X ivars <vars> DEFINE THE LIST OF INSTANCE VARIABLES X <vars> the list of instance variable symbols X returns the object X X cvars <vars> DEFINE THE LIST OF CLASS VARIABLES X <vars> the list of class variable symbols X returns the object X X XLISP: An Experimental Object Oriented Language Page 7 X OBJECTS X X X When a new instance of a class is created by sending the X message 'new' to an existing class, the message 'isnew' X followed by whatever parameters were passed to the 'new' X message is sent to the newly created object. X X When a new class is created by sending the 'new' message to X the object 'Class', an optional parameter may be specified X indicating of which class the newly generated class is to be X a subclass. If this parameter is omitted, the new class X will be a subclass of 'Object'. X X Example: X X ; create 'Foo' as a subclass of 'Object' X (setq Foo (Class 'new)) X X ; create 'Bar' as a subclass of 'Foo' X (setq Bar (Class 'new Foo)) X X A class inherits all instance variables, class variables, X and methods from its super-class. X X XLISP: An Experimental Object Oriented Language Page 8 X OBJECTS X X X The 'Keymap' Class: X X A keymap is data structure that translates a sequence of X keystrokes into a message. X X In order to create a keymap: X X (setq km (Keymap 'new)) X X In order to add a key definition to a keymap (km): X X (km 'key "\eA" 'up) X (km 'key "\eB" 'down) X (km 'key "\eC" 'right) X (km 'key "\eD" 'left) X X Executing a keymap: X X (setq env (list ob1 ob2 ob3 ob4)) X (km 'process env) X X When the process message is sent, its method enters a X character input loop calling kbin to get single unechoed X characters from the keyboard. When a sequence of characters X is found that matches one of the sequences defined in a key X function call, the corresponding message is sent. The X method tries to send the message to each of the objects in X the environment list. It stops when it finds an object that X knows how to answer the message. Along with the message X selector given in the key definition, the sequence of X matched characters is passed as a single string parameter. X X Keymap X X new CREATE A NEW KEYMAP X returns a new keymap X X isnew INITIALIZE THE NEW KEYMAP X returns the keymap X X key <kstr> <ksym> ADD A KEY DEFINITION TO A KEYMAP X <kstr> the string defining the key X <ksym> the symbol for the message X returns the keymap X X process <envlist> PROCESS INPUT USING A KEYMAP X <envlist> list of active objects X returns the keymap when a message evaluates to nil X X XLISP: An Experimental Object Oriented Language Page 9 X SYMBOLS X X X Symbols: X X X o self - the current object (within a message X context) X X o msgclass - the class in which the current method X was found X X o currentenv - the environment list for the current X invocation of kmprocess X X o oblist - the object list X X X XLISP: An Experimental Object Oriented Language Page 10 X FUNCTIONS X X X Utility functions: X X (load <fname>) LOAD AN XLISP SOURCE FILE X <fname> the filename string X returns the filename X X (mem) SHOW MEMORY ALLOCATION STATISTICS X returns nil X X (gc) FORCE GARBAGE COLLECTION X returns nil X X (alloc <num>) CHANGE NUMBER OF NODES TO ALLOCATE IN EACH SEGMENT X <num> the number of nodes to allocate X returns the old number of nodes to allocate X X (expand <num>) EXPAND MEMORY BY ADDING SEGMENTS X <num> the number of segments to add X returns the number of segments added X X XLISP: An Experimental Object Oriented Language Page 11 X FUNCTIONS X X X Functions: X X (eval <expr>) EVALUATE AN XLISP EXPRESSION X <expr> the expression to be evaluated X returns the result of evaluating the expression X X (set <sym> <expr>) SET THE VALUE OF A SYMBOL X <sym> the symbol being set X <expr> the new value X returns the new value X X (setq <qsym> <expr>) SET THE VALUE OF A SYMBOL X <qsym> the symbol being set (quoted) X <expr> the new value X returns the new value X X (print <expr>...) PRINT A LIST OF VALUES X <expr> the expressions to be printed X returns nil X X (princ <expr>...) PRINT A LIST OF VALUES WITHOUT QUOTING X <expr> the expressions to be printed X returns nil X X (quote <expr>) RETURN AN EXPRESSION UNEVALUATED X or X '<expr> X <expr> the expression to be quoted (quoted) X returns <expr> unevaluated X X (if <texpr> <expr1> [ <expr2> ]) EXECUTE EXPRESSIONS CONDITIONALLY X <texpr> test expression X <expr1> expression evaluated if texpr is non-nil or non-zero X <expr2> expression evaluated if texpr is nil or zero X returns the value of the expression evaluated X X (while <texpr> <expr>...) ITERATE WHILE AN EXPRESSION IS TRUE X <texpr> test expression evaluated at start of each iteration X <expr> expressions evaluated as long as <texpr> evaluates to X non-nil or non-zero X returns the result of the last expression evaluated X X (repeat <iexpr> <expr>...) ITERATE USING A REPEAT COUNT X <iexpr> integer expression indicating the repeat count X <expr> expressions evaluated <iexpr> times X returns the result of the last expression evaluated X X (foreach <qsym> <list> <expr>...) ITERATE FOR EACH ELEMENT IN A LIST X <qsym> symbol to assign each list element to (quoted) X <list> list to iterate through X <expr> expressions evaluated for each element in the list X returns the result of the last expression evaluated X X XLISP: An Experimental Object Oriented Language Page 12 X FUNCTIONS X X X (defun <qsym> <qfargs> <expr>...) DEFINE A NEW FUNCTION X <qsym> symbol to be defined (quoted) X <qfargs> list of formal arguments (quoted) X this list is of the form: X (<farg>... [/ <local>...]) X where X <farg> is a formal argument X <local> is a local variable X <expr> expressions constituting the body of the X function (quoted) X returns the function symbol X X (cond <pair>...) EVALUATE CONDITIONALLY X <pair> pair consisting of: X (<pred> <expr>) X where X <pred> is a predicate expression X <expr> is evaluated if the predicate X is not nil X returns the value of the first expression whose predicate X is not nil X X (exit) EXIT XLISP X returns never returns X X XLISP: An Experimental Object Oriented Language Page 13 X FUNCTIONS X X X I/O Functions: X X (fopen <fname> <mode>) OPEN A FILE X <fname> the file name string X <mode> the open mode string X returns a file pointer X X (fclose <fp>) CLOSE A FILE X <fp> the file pointer X returns nil X X (getc [<fp>]) GET A CHARACTER FROM A FILE X <fp> the file pointer (default is stdin) X returns the character (integer) X X (putc <ch> [<fp>]) PUT A CHARACTER TO A FILE X <ch> the character to put (integer) X <fp> the file pointer (default is stdout) X returns the character (integer) X X (fgets [<fp>]) GET A STRING FROM A FILE X <fp> the file pointer (default is stdin) X returns the input string X X (fputs <str> [<fp>]) PUT A STRING TO A FILE X <str> the string to output X <fp> the file pointer (default is stdout) X returns the string X X XLISP: An Experimental Object Oriented Language Page 14 X FUNCTIONS X X X String Functions: X X (strcat <expr>...) CONCATENATE STRINGS X <expr> string expressions X returns result of concatenating the strings X X (strlen <expr>) COMPUTE THE LENGTH OF A STRING X <expr> the string expression X returns the length of the string X X (substr <expr> <sexpr> [<lexpr>]) RETURN SUBSTRING X <expr> string expression X <sexpr> starting position X <lexpr> optional length (default is rest of string) X returns substring starting at <sexpr> for <lexpr> X X (ascii <expr>) NUMERIC VALUE OF CHARACTER X <expr> string expression X returns numeric value of first character (according to ASCII) X X (chr <expr>) CHARACTER EQUIVALENT OF ASCII VALUE X <expr> numeric expression X returns one character string with ASCII equivalent of <expr> X X (atoi <expr>) CONVERT AN ASCII STRING TO AN INTEGER X <expr> string expression X returns the integer value of the string expression X X (itoa <expr>) CONVERT AN INTEGER TO AN ASCII STRING X <expr> integer expression X returns the string representation of the integer value X X XLISP: An Experimental Object Oriented Language Page 15 X FUNCTIONS X X X List Functions: X X (head <expr>) RETURN THE HEAD ELEMENT OF A LIST X or X (car <expr) X <expr> the list X returns the first element of the list X X (tail <expr>) RETURN THE TAIL ELEMENTS OF A LIST X or X (cdr <expr>) X <expr> the list X returns the list minus the first element X X (list <expr>...) CREATE A LIST OF VALUES X <expr> evaluated expressions to be combined into a list X returns the new list X X (nth <n> <list>) RETURN THE NTH ELEMENT OF A LIST X <n> the number of the element to return X <list> the list to return the nth element of X returns the nth element or nil if the list isn't that long X X (append <expr>...) APPEND LISTS X <expr> lists whose elements are to be appended X returns the new list X X (cons <e1> <e2>) CONSTRUCT A NEW LIST ELEMENT X <e1> becomes the head (car) of the new list X <e2> becomes the tail (cdr) of the new list X returns the new list X X (null <expr>) CHECKS FOR AN EMPTY LIST X <expr> the list to check X returns t if the list is empty, nil otherwise X X (atom <expr>) CHECKS FOR AN ATOM (ANYTHING THAT ISN'T A LIST) X <expr> the expression to check X returns t if the value is an atom, nil otherwise X X (listp <expr>) CHECKS FOR A LIST X <expr> the expression to check X returns t if the value is a list, nil otherwise X X XLISP: An Experimental Object Oriented Language Page 16 X FUNCTIONS X X X (type <expr>) RETURNS THE TYPE OF THE EXPRESSION X <expr> the expression to return the type of X returns nil if the value is nil otherwise one of the symbols: X SYM for symbols X OBJ for objects X LIST for list nodes X KMAP for keymap nodes X SUBR for internal subroutine nodes X STR for string nodes X INT for integer nodes X FPTR for file pointer nodes X X (eq <expr1> <expr2>) CHECKS FOR THE EXPRESSIONS BEING THE SAME X <expr1> the first expression X <expr2> the second expression X returns t if they are equal, nil otherwise X X (equal <expr1> <expr2>) CHECKS FOR THE EXPRESSIONS BEING EQUAL X <expr1> the first expression X <expr2> the second expression X returns t if they are equal, nil otherwise X X (read [ <str> ]) READ AN XLISP EXPRESSION X <str> the string to use as input (optional) X returns the expression read X X (reverse <expr>) REVERSE A LIST X <expr> the list to reverse X returns a new list in the reverse order X X (length <expr>) FIND THE LENGTH OF A LIST X <expr> the list to find the length of X returns the length X X XLISP: An Experimental Object Oriented Language Page 17 X FUNCTIONS X X X Arithmetic Functions: X X (+ <expr>...) ADD A LIST OF VALUES X <expr> expressions to be added X returns the result of the addition X X (- <expr>...) SUBTRACT A LIST OF VALUES X <expr> expressions to be subtracted X returns the result of the subtraction X X (* <expr>...) MULTIPLY A LIST OF VALUES X <expr> expressions to be multiplied X returns the result of the multiplication X X (/ <expr>...) DIVIDE A LIST OF VALUES X <expr> expressions to be divided X returns the result of the division X X (% <expr>...) MODulus A LIST OF VALUES X <expr> expressions to be MODulused X returns the result of mod X X (& <expr>...) THE BITWISE AND OF A LIST OF VALUES X <expr> expressions to be ANDed X returns the bit by bit ANDing of expressions X X (| <expr...) THE BITWISE OR OF A LIST OF VALUES X <expr> expressions to be ORed X returns the bit by bit ORing of expressions X X (~ <expr>) THE BITWISE NOT OF A VALUE X <expr> expression to be NOTed X returns the bit by bit inversion of expression X X (min <expr>...) THE SMALLEST OF A LIST OF VALUES X <expr> expressions to be checked X returns the smallest value of the list X X (max <expr>...) THE LARGEST OF A LIST OF VALUES X <expr> expressions to be checked X returns the largest value of the list X X (abs <expr>) THE ABSOLUTE VALUE OF AN EXPRESSION X <expr> integer expression X returns the absolute value of the expression X X XLISP: An Experimental Object Oriented Language Page 18 X FUNCTIONS X X X Boolean Functions: X X (&& <expr>...) THE LOGICAL AND OF A LIST OF VALUES X <expr> expressions to be ANDed X returns the result of anding the expressions X (evaluation of expressions stops after the first X expression that evaluates to false) X X (|| <expr>...) THE LOGICAL OR OF A LIST OF VALUES X <expr> expressions to be ORed X returns the result of oring the expressions X (evaluation of expressions stops after the first X expression that evaluates to true) X X (! <expr>) THE LOGICAL NOT OF A VALUE X <expr> expression to be NOTed X return logical not of <expr> X X XLISP: An Experimental Object Oriented Language Page 19 X FUNCTIONS X X X Relational Functions: X X The relational functions can be used to compare integers and X strings. The functions '==' and '!=' can also be used to X compare other types. The result of these comparisons is X computed the same way as for 'eq'. X X (< <e1> <e2>) TEST FOR LESS THAN X <e1> the left operand of the comparison X <e2> the right operand of the comparison X returns the result of comparing <e1> with <e2> X X (<= <e1> <e2>) TEST FOR LESS THAN OR EQUAL TO X <e1> the left operand of the comparison X <e2> the right operand of the comparison X returns the result of comparing <e1> with <e2> X X (== <e1> <e2>) TEST FOR EQUAL TO X <e1> the left operand of the comparison X <e2> the right operand of the comparison X returns the result of comparing <e1> with <e2> X X (!= <e1> <e2>) TEST FOR NOT EQUAL TO X <e1> the left operand of the comparison X <e2> the right operand of the comparison X returns the result of comparing <e1> with <e2> X X (>= <e1> <e2>) TEST FOR GREATER THAN OR EQUAL TO X <e1> the left operand of the comparison X <e2> the right operand of the comparison X returns the result of comparing <e1> with <e2> X X (> <e1> <e2>) TEST FOR GREATER THAN X <e1> the left operand of the comparison X <e2> the right operand of the comparison X returns the result of comparing <e1> with <e2> //go.sysin dd * /bin/chmod 664 xlisp.doc /bin/echo -n ' '; /bin/ls -ld xlisp.doc