Home | History | Annotate | Line # | Download | only in lisp
README revision 1.1
      1  1.1  mrg $XFree86: xc/programs/xedit/lisp/README,v 1.12 2002/11/23 08:26:47 paulo Exp $
      2  1.1  mrg 
      3  1.1  mrg LAST UPDATED:	$Date: 2008/07/30 04:16:26 $
      4  1.1  mrg 
      5  1.1  mrg 
      6  1.1  mrg     SUMMARY
      7  1.1  mrg 
      8  1.1  mrg   This is a small lisp interpreter for xedit. It implements a subset of
      9  1.1  mrg Common Lisp and the xedit package implements several of the basic Emacs
     10  1.1  mrg lisp functions.
     11  1.1  mrg 
     12  1.1  mrg (shared modules not broken, but needs a redesign for better performance,
     13  1.1  mrg  but won't be made available in the default build probably for a long time,
     14  1.1  mrg  it would be really better to generate the interface dinamically, and/or just
     15  1.1  mrg  link agains't the required libraries and use a ffi interface)
     16  1.1  mrg +------------------------------------------------------------------------
     17  1.1  mrg |   It has a very simple method for loading shared modules, slightly based on
     18  1.1  mrg | the XFree86 loader code, that is currently disabled by default. To enable it,
     19  1.1  mrg | edit lisp.cf and change BuildSharedLispModules to YES.
     20  1.1  mrg |
     21  1.1  mrg |   Assuming you have built it with BuildSharedLispModules enabled, you can build
     22  1.1  mrg | a small test application can be built in this directory running "make lsp".
     23  1.1  mrg | Two lisp programs are available in the test directory. To test the programs
     24  1.1  mrg | run "./lsp test/hello.lsp" or "./lsp test/widgets.lsp".
     25  1.1  mrg +------------------------------------------------------------------------
     26  1.1  mrg 
     27  1.1  mrg   Currently, it should be used as an helper and/or a small calculator embedded
     28  1.1  mrg in xedit. For the future it should be possible to write entire interfaces
     29  1.1  mrg in the xedit text buffers.
     30  1.1  mrg 
     31  1.1  mrg 
     32  1.1  mrg     USAGE SUMMARY
     33  1.1  mrg 
     34  1.1  mrg   To evaluate lisp expressions, put the text cursor just after the
     35  1.1  mrg lisp expression and press:
     36  1.1  mrg C-x,C-e	- will evaluate it, and print the result to the message window
     37  1.1  mrg C-j	- will evaluate it, and print the result to the edit window, any
     38  1.1  mrg 	  errors are printed to the message window.
     39  1.1  mrg C-g	- will send an SIGINT to the lisp process, and that process will
     40  1.1  mrg 	  stop whatever it was processing and jump to the toplevel,
     41  1.1  mrg 	  to wait for more input.
     42  1.1  mrg 
     43  1.1  mrg Note that C-j will only work in the *scratch* buffer.
     44  1.1  mrg 
     45  1.1  mrg 
     46  1.1  mrg      NOTES
     47  1.1  mrg 
     48  1.1  mrg   The improvements to xedit including the several possibilites to extend
     49  1.1  mrg the editor using Lisp are expected to allow making of xedit a versatile
     50  1.1  mrg text editor for programming, but there is code being (slowly) developed
     51  1.1  mrg that should also make it useable as a small word processor, for things
     52  1.1  mrg like WYSIWYG html, etc.
     53  1.1  mrg   The xedit development is being done very slowly, maybe it will get
     54  1.1  mrg somewhere someday, but it is a pet/hobby project, there is no intention
     55  1.1  mrg of making of it an end user editor (the idea is to make it an useful
     56  1.1  mrg development tool).
     57  1.1  mrg   In some aspects the development is trying to mimic several Emacs
     58  1.1  mrg features, but there is no intention of competition (if xedit ever get
     59  1.1  mrg something better than Emacs, I hope that it serves as a motivation to
     60  1.1  mrg make of Emacs an even better editor), actually it is expected to explore
     61  1.1  mrg different areas and use alternate solutions for the implementation.
     62  1.1  mrg   Most work in a computer is done in a text editor and the more the editor
     63  1.1  mrg can help the user the better.
     64  1.1  mrg 
     65  1.1  mrg 
     66  1.1  mrg (debugger is broken and very slow, no prevision for fixing it, but is
     67  1.1  mrg  expected to work correctly for interpreted only code)
     68  1.1  mrg +------------------------------------------------------------------------
     69  1.1  mrg |     DEBUGGER
     70  1.1  mrg |
     71  1.1  mrg |   There is a, currently, very simple debugger implement in the interpreter.
     72  1.1  mrg | The debugger is now optional, and off by default. To make it available,
     73  1.1  mrg | you need to recompile with -DDEBUGGER.
     74  1.1  mrg | To use the debugger, run the lsp sample program as "./lsp -d", and optionally
     75  1.1  mrg | pass a second parameter, for the file to be interpreted. Once the debugger
     76  1.1  mrg | prompt is visible, type "help" for a summary of options. To leave the debugger
     77  1.1  mrg | type "continue".
     78  1.1  mrg |   Note that the debugger is still very simple, it won't work from xedit, and
     79  1.1  mrg | won't drop to the debugger on "fatal errors". It allows adding breakpoints to
     80  1.1  mrg | functions and watchpoints to variables. Support for changing data and going to
     81  1.1  mrg | the debugger on fatal errors should be added at some time.
     82  1.1  mrg +------------------------------------------------------------------------
     83  1.1  mrg 
     84  1.1  mrg 
     85  1.1  mrg     COMPILER
     86  1.1  mrg 
     87  1.1  mrg   Now there is a very simple bytecode compiler. It is far from finished, but
     88  1.1  mrg for simple code can show significant better performance.
     89  1.1  mrg   There is not yet an interface to compile entire files and no interface to
     90  1.1  mrg store the generated bytecode in disk. There is an interface to bytecode
     91  1.1  mrg compile toplevel forms as a LAMBDA NIL, but it is not yet exported.
     92  1.1  mrg   If your code needs to call GO/RETURN/RETURN-FROM as the result of an EVAL,
     93  1.1  mrg it must jump to code in the interpreter, after compiling all calls to
     94  1.1  mrg GO/RETURN/RETURN-FROM are just stack adjusting and jumps in the bytecode.
     95  1.1  mrg CATCH/THROW and UNWIND-PROTECT are running as interpreted code for now, so it
     96  1.1  mrg is safe to use these, but code in such blocks is not compiled/optimized
     97  1.1  mrg (not even macro expansion is done, as it understands that while not compiled,
     98  1.1  mrg everything is candidate to redefinition at any time).
     99  1.1  mrg   To compile the code, just write a function, and compile it, example:
    100  1.1  mrg 
    101  1.1  mrg 	(defun fact (n)
    102  1.1  mrg 	    (if (< n 2)
    103  1.1  mrg 		1
    104  1.1  mrg 		(* n (fact (1- n)))
    105  1.1  mrg 	    )
    106  1.1  mrg 	)
    107  1.1  mrg 	FACT
    108  1.1  mrg 
    109  1.1  mrg 	(compile 'fact)
    110  1.1  mrg 	FACT
    111  1.1  mrg 	NIL
    112  1.1  mrg 	NIL
    113  1.1  mrg 
    114  1.1  mrg 	(disassemble 'fact)
    115  1.1  mrg 	Function FACT:
    116  1.1  mrg 	1 required argument: N
    117  1.1  mrg 	0 optional arguments
    118  1.1  mrg 	0 keyword parameters
    119  1.1  mrg 	No rest argument
    120  1.1  mrg 
    121  1.1  mrg 	Bytecode header:
    122  1.1  mrg 	1 element used in the stack
    123  1.1  mrg 	2 elements used in the builtin stack
    124  1.1  mrg 	0 elements used in the protected stack
    125  1.1  mrg 	Constant 0 = 1
    126  1.1  mrg 	Constant 1 = (2)
    127  1.1  mrg 	Symbol 0 = N
    128  1.1  mrg 	Builtin 0 = *
    129  1.1  mrg 	Builtin 1 = 1-
    130  1.1  mrg 	Builtin 2 = <
    131  1.1  mrg 
    132  1.1  mrg 	Initial stack:
    133  1.1  mrg 	0 = N
    134  1.1  mrg 
    135  1.1  mrg 	Bytecode stream:
    136  1.1  mrg 	   0  LOAD&PUSH (0)
    137  1.1  mrg 	   2  LOADCON&PUSH [1]	    ;  (2)
    138  1.1  mrg 	   4  CALL 2 [2]	    ;  <
    139  1.1  mrg 	   7  JUMPNIL 8
    140  1.1  mrg 	  10  LOADCON [0]	    ;  1
    141  1.1  mrg 	  12  NOOP
    142  1.1  mrg 	  13  JUMP 19
    143  1.1  mrg 	  16  LOAD&PUSH (0)
    144  1.1  mrg 	  18  LOAD&PUSH (0)
    145  1.1  mrg 	  20  CALL 1 [1]	    ;  1-
    146  1.1  mrg 	  23  LET* [0]		    ;  N
    147  1.1  mrg 	  25  LETREC 1
    148  1.1  mrg 	  27  UNLET 1
    149  1.1  mrg 	  29  BCONS1
    150  1.1  mrg 	  30  CALL 1 [0]	    ;  *
    151  1.1  mrg 	  33  RETURN
    152  1.1  mrg 	FACT
    153  1.1  mrg 
    154  1.1  mrg 
    155  1.1  mrg   There are several optimizations that should be done at some time, I don't
    156  1.1  mrg think adding NOOP opcodes will help everywhere to make aligned memory reads
    157  1.1  mrg of shorts and ints.
    158  1.1  mrg   It should have explicitly visible registers, not the abstraction of "the
    159  1.1  mrg current value", so the code generator can choose register allocation for
    160  1.1  mrg loop control variables, commonly used variables, etc, for example. Jumps
    161  1.1  mrg should have 3 types: byte relative, 2 bytes relative and 4 bytes relative.
    162  1.1  mrg For now there is only 2 byte relative jumps, byte relative jumps
    163  1.1  mrg can show a significant performance increase, but they are disable until
    164  1.1  mrg it is decided how inlined functions will work, if it just updates the bytecode
    165  1.1  mrg header and cut&past the bytecode, jumps must be updated, and some jumps
    166  1.1  mrg may not fit anymore in a byte.
    167  1.1  mrg 
    168  1.1  mrg 
    169  1.1  mrg     OPTIMIZATION
    170  1.1  mrg 
    171  1.1  mrg   There are plenty of possibilities to make the interpreter run faster. Some
    172  1.1  mrg optimizations that can make it run quite faster in certain cases are:
    173  1.1  mrg   o Better object memory layout and gc. The current memory allocation code
    174  1.1  mrg     is very bad, it try to keep 3 times more free objects than the currently
    175  1.1  mrg     used number, this can consume a lot of memory. The reason is to reduce
    176  1.1  mrg     the gc time cost so that it will in average miss only one in every 4
    177  1.1  mrg     collect tries.
    178  1.1  mrg   o Implement real vectors, currently they are just a list, so it cannot
    179  1.1  mrg     just deference a given index, and gc time is very long also.
    180  1.1  mrg   o Most lists are never changed once created, it could somehow add an index
    181  1.1  mrg     field in the cons cell, so that NTH/NTHCDR/LENGTH like code could just
    182  1.1  mrg     deference the correct object, instead of traversing the CDR of every
    183  1.1  mrg     cons. This would probably require implementing lists as vectors, while
    184  1.1  mrg     making it easy to deference would make life harder when deleting/inserting
    185  1.1  mrg     sublists in a list. It should also better be done in a way that does
    186  1.1  mrg     not require a lot of objects allocated linearly.
    187  1.1  mrg 
    188  1.1  mrg 
    189  1.1  mrg     HELPING
    190  1.1  mrg 
    191  1.1  mrg   Send comments and code to me (paulo (a] XFree86.Org) or to the XFree86
    192  1.1  mrg mailing/patch lists.
    193  1.1  mrg 
    194  1.1  mrg --
    195  1.1  mrg Paulo
    196