UP | HOME

Date: [2020-07-06 Mon]

Common Lisp Implementation

Table of Contents

(Source)

1. Strategy 1

1.1. Create a small core in C

  • Use C malloc() to allocate CL Objects
  • Use the Boehm-Demers-Weiser conservative garbage collector to reclaim memory of dead objects.

1.2. Managing the dynamic run-time environment

Environment consists:

  • Bindings for special variables
  • Tags for catch used by throw
  • exit points defined by tagbody and block
  • entries for unwind-protect
  • Signal handlers and restarts

Dynamic environment can be allocated on the heap as a linked list of entries. However,

  • catch and throw can be implemented using block and return-from.
  • Signal handlers and restarts (i.e. the entire condition system) can be implemented using special variables.

Unwinding the stack (throw, go, return-from) can be implemented using setjmp/longjmp. (See man page)

1.3. Allocators, predicates, accessors

for built-in data type.

  • Fixnums, bignums, ratios, floats, complex numbers
  • Characters
  • Symbols, packages.
  • Conses, arrays, hash tables
  • Streams

1.4. Reader

Its complicated. So two options:

  • Write a subset of the reader in C. Replace with a full reader written in Common Lisp later.
  • Write the final reader in C, but leave out complicated standard reader macros that can be written CL later

1.5. Printer

(Same as 1.4)

1.6. Evaluator

Several possible implementations:

  • A direct interpreter written in C
  • A compiler generating native machine code
  • A compiler generating byte codes, combined with a byte-code interpreter written in C.

1.6.1. Direct Imterpreter

  • Relatively Simple
  • Slow
  • Cross Evaluation not possible

1.6.2. A compiler generating native machine code

  • Hard to write
  • Requires knowledge of C ABI
  • Makes tail-call optimization somewhat difficult

1.6.3. Compiler generating byte codes

  • Relatively simple to write
  • Resonably fast
  • Tail-call optimization easier

2. Strategy 1 (Complications)

CL does not have a unique set of basic operators. There are many possible choices. A long list of possible choices.

How and when do we define the macro defmacro?


Backlinks


You can send your feedback, queries here