ECL = (Not Only) Embeddable Common Lisp

ECL = (Not Only) Embeddable Common Lisp

ECL = (not only) Embeddable Common Lisp Juan José García Ripoll http://ecls.sourceforge.net Outline ● Introduction ● ECL's family tree and history ● ECL's current philosophy & design ● Salient features ● Future trends ● Outlook & questions About the maintainer ● Self-educated in different languages Lisp/Scheme, C, C++, ML... ● Work heavily focused on numerical analysis MATLAB, Yorick, ... ● Came to lisp searching for interactive environments that could evolve into numerical programming ones Scheme, ML, CMUCL, GCL, EcoLisp, ... ● Some experience on free projects ECL, OS/2 Gnu ports, Doom port, ... ECL Family tree 1st implementation of CLT. KCL Yuasa and M. Hagiya W. Schelter AKCL EcoLisp G. Attardi W. Schelter GCL ECLS JJGR GCL Team ECL Projects merge Traditional *CL design ● Big chunk of memory Lisp image contains everything DATA ● A core is written in C Interpreted manually. Lisp Code Compiled ● Lisp code compiled to C Lisp code (lists) by a compiler written in lisp. Support Interpreter (C) Library (C) ● Binaries loaded as data ● Whole image can be Operating System dumped and restored. Traditional *CL design Pros: Cons: ✔ Portable (C) backend. ✗ What is portable C? ✔ Fast loading of images. ✗ Low-level knowledge of each OS ✔ Full control of memory & any GC strategy. ✗ Randomized memory, non-exec memory... ✔ It follows “tradition” ✗ Need to talk to other libraries. ✗ Maintainability ECL's new design Interpreted Lisp Code DATA (bytecodes) Compiled User's FASL Lisp code or programs Foreign Support libraries Interpreter (C) Library (C) Operating System ECL's design ● Lisp has to coexist with other libraries. DATA ● ECL knows about foreign datatypes. ● We know how to find and talk to those libraries ● Foreign OS will not allow us full libraries control of memory. ● GC can be performed by Operating System external libraries. ECL's design ● Binary and data Interpreted separate Lisp Code DATA (bytecodes) ● Pack everything into a standalone library ● Library can be used from other binaries / ECL Core applications Common-Lisp library ● Similar to C (C++) philosophy ● Comes with a Operating System bytecodes interpreter and compiler ECL's design ● Compiled files are Interpreted just binaries loaded Lisp Code DATA by the OS. (bytecodes) ● They are linked to the ECL library User's FASL – lisp objects creation or programs and manipulation – talk to other binaries ● No difference bw. embedding ECL and Operating System its ordinary use. Portability ● Memory management delegated to a GC library ● Use of standard C compilation and linking facilities ● Minimalistic assumptions on architecture – We can make pointer ⇆ integer conversions – C functions can be called with any # arguments ● Anything nonportable is optional & detected at configuration time. – Binary file handling using OS facilities if available ● dlopen, Mach Kernel, etc – Sockets, CLX, long floats, ... Portability ● Memory mLiannux,agem Nenett /dFree/elegaOtedpen to aB GCSD ,library Windows' MSVC++, ● Use of standard C compilation and linking facilities Cyg/Mingwin, ● Minimalistic assuMacmp OtioSn sX, o nS aolarirchites.ctu.. re – We can make pointer ⇆ integer conversions – C functions Icanntel b e32/ called64 biwithts an, PPCy # argu, ments ● Anything nonportaSpable isrc, op AtioRnMal ..&. detected at configuration time. – Binary file hanWishdling liussint: gC OelSl (faciPS3)lities, if available AIX, iPhone ● dlopen, Mach Kernel, etc – Sockets, CLX, long floats, ... Compiled code ● One C function per lisp cl_object cl_negate(cl_object x) function. { cl_object y = ● Use of standard C ecl_minus(MAKE_FIXNUM(0), constructs. x); NVALUES = 1; ● return (VALUES(0)=x); Up to 64 args in C stack, } rest in interpreter stack. cl_object cl_floor(cl_narg narg, ...) ● Return first value directly, { rest in a thread-local array. cl_va_list args; cl_va_start(args,narg,0,narg); ● Also closures, unboxed ... NVALUES = 2; types, inlined C code... VALUES(1) = rem; return (VALUES(0)=div); } Interpreter ● Interpreter, compiler, code ✗ Uses 45 bytecodes, but walker, stepper & tracer in only about 20 essential under 4kloc. > (defun plus1 (x) (+ x 1)) > (si:bc-disassemble #'plus1) ● Handles all special forms Name: PLUS1 Required: X Documentation: NIL ● Support for some macros Declarations: NIL 0 BLOCK 11,PLUS1 such as do, dotimes,... 3 PUSHV 1 5 PUSH '1 ● The C library supplies 7 CALLG 2,+ 10 EXIT FRAME object handling functions. 11 EXIT ● Lisp library adds macros ✗ Very stable, but can be and remaining functions. improved. Memory management ● Can be completely abstracted – alloc_atomic(), alloc(), finalization registration,... ● Currently focused on Boehm-Weiser GC – Conservative → works well with foreign libraries – Fast, supports heavy loads – Used in other projects: GCJ, w3m, ... – We still do not use 100% potential ● But you could plug in your favourite GC library Data representation (0.9k) 32/64.. bit 1 pointer to CONS 0 1 Large enough to fit most of Unicode character code 1 0 characters: 30 bits fixnum 1 1 Immediate integers. pointer to object 0 0 All other boxed types: bignums, arrays, instances, functions, ... Two bits of information contain some type information and distinguish immediate types. Data representation (0.9k) 32/64.. bit 1 pointer to CONS 0 1 CAR CDR character code 1 0 No type information / overhead fixnum 1 1 Rest of type information, bits for some flags and also information for GC. pointer to object 0 0 HEADER Note that there are objects of various Other data sizes, containing also references. Data representation (0.9k) 15 Time (m) Consed (Gb) 10 -20% -40% 5 0 ECL 0.9j ECL 0.9k CLISP 2.43 SBCL 1.0.10 Performance of Paul Dietz's ANSI Common Lisp, with various implementations, all tested in a Mac OS X 10.4.8 (Tiger) Data representation (0.9k) 15 Time (m) NIL is fixed word Consed (Gb) 10 Smaller CONS -20% -40% 5 Safety dropped to get here 0 ECL 0.9j ECL 0.9k CLISP 2.43 SBCL 1.0.10 Performance of Paul Dietz's ANSI Common Lisp, with various implWe ementationcan learns, all tested in a Mac OS X 10.4.8 (Tiger) from this GC! SUBTYPEP: Type lattice ● Following Henry Baker's paper, types are represented as sets, with some types being elementary. ● To each set a binary tag is associated – (tag (AND T1 T2)) = (LOGIAND (tag T1) (tag T2)) – (tag (OR T1 T2)) = (LOGIOR (tag T1) (tag T2)) – (tag (NOT T1)) = (LOGNOT (tag T1)) ● SUBTYPEP only fails with recursive types – T1 = (OR (CONS INTEGER T1) NIL) ● Works with CLOS. CLOS ● ECL's implementation derives from a stripped down Portable Common Loops (PCL) ● We have redesigned and extended everything – Remember to avoid use of COMPILE! ● Everything in ANSI specification is now provided: – standard classes and objects – generic functions – complex method combinations ● Everything in AMOP, except for custom dispatch. CLOS dispatch ● Thread local method dispatch cache, shared by all generic functions – It can be larger and thus more efficient – It cleans itself based on a generation counter ● Function call objects – Collect arguments to a generic function – Are passed around without further consing – Can be efficiently used to invoke a C function – Dynamic extent Environments ● Contain roots to all data cl_global ● One global environment – packages, symbols, list cl_env (1) of libraries, etc. ● One environment per interp. stack execution line bind stack – Stacks, bindings, lexical environment... printer stack ● Might be sandboxed at different levels. cl_env (2) Multithreading mp:process ● Native POSIX threads cl_global ● Each thread has access to its own environment cl_env (1) ● Global variable bindings in a hash interp. stack – Not too inefficient bind stack ● Still a lot to improve: printer stack – Signals, safety... cl_env (2) Binary files function ● One entry function. ● Constants in text form. ecl_codeblock ● Each binary associated to a lisp structure. data string ● When all functions are garbage collected, the lisp data binary file is as well. array ● If the binary file was in a entry point DLL, it is closed. DLL handle / ● Completely independent file name of binaries' purpose. System building: bootstraping ● The ECL interpreter can Core Bytecodes Lisp handle all Common Lisp. library interpreter lib. files ● Core functionality provided by C library. Lisp 2 C ● ecl_min Rest by the lisp library compiler interpreted. ● With this we can run the Compiled compiler and compile the lisp lib. whole library. ● Extremely robust libecl.so / libecl.a System building ● ECL knows about the linking abilities of each Object Other system files flags / libs – no libtool (sucks!) ● A function links object files creating C:BUILDER – programs – static libraries Program FASL – shared libraries Shared/ static lib – bundles (FASL) System building (require 'c) (defvar *sources* '("file1.lsp" "file2.lsp")) (defvar *objects* (loop for i in *sources* collect (compile-file i :system-p t))) (c::builder :program "test" :lisp-files *objects* :epilogue-code '(format t "~%CLOSING~%")) System building ● Similar features built into Other our port of ASDF ASDF flags / libs ● MAKE-BUILD takes a system definition file and builds programs, libraries, FASL ASDF:MAKE-BUILD ● Can build monolithic systems containing all dependencies. Program FASL Shared/ ● Still under development static lib System building (require 'asdf) (require 'c) (asdf:defsystem test :components ((:file "file1") (:file "file2"))) (asdf:make-build :test :type :program :epilogue-code '(format t "~%CLOSING~%")) FFI = foreign functions & callbacks Way 1: use C Problems: ● Generate wrappers for ● Lispers themselves: each

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    43 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us