The Picolisp Machine

Computing | Picolisp | The Picolisp Reference | ASM | Pil Tutorials |

One of the key features of the picolisp language is that high-level constructs of the language directly map to the underlying machinery, making the whole system both understandable and predictable.

Also please note that there are still a number of possible errors in this Document, it is under active development

Data Types

These are the fundamental datatypes in Picolisp:

                       cell
                        |
            +-----------+-----------+
            |           |           |
         Number       Symbol       Pair
        S010 S100      1000        0000
       (cnt | big)      |
                        |
   +--------+----- --------+-----------+
   |        |              |           |
  NIL   Internal       Transient    External
              \           /            |
             0010 Short name        1010 Short name
             0100 Long name         1000 Properties
             0000 Properties

The Cell

The most fundamental datatype is the cell which is the building block for all other data types.

         +-----+-----+
         | CAR | CDR |
         +-----+-----+

Consider memory as an array of bytes growing downwards.

each x, c, i is a bit (0 or 1)
x means "address  bit, unimportant if it is 0 or 1"
i mean  "special  bit for the Interpreter"
c means "contents bit"
S means "Sign bit, 1 means negative, 0 positive"


          Them Address are 64 bits in Length                                          the lowest 4 bits are used by the interpreter
                                                                                      to figure out which type the value is
                                                                                                    |
             B8       B7       B6       B5       B4       B3       B2       B1              ContentsV
--------------------------------------------------------------------------------------------------------
ADDRESS: xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxx 0000, BYTE  0: cccc iiii  |
         xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxx 0001, BYTE  1: cccc cccc  |
         xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxx 0010, BYTE  2: cccc cccc  |
         xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxx 0011, BYTE  3: cccc cccc  |__ CAR (8 Bytes long, 64 bits)
         xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxx 0100, BYTE  4: cccc cccc  |
         xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxx 0101, BYTE  5: cccc cccc  |
         xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxx 0110, BYTE  6: cccc cccc  |
         xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxx 0111, BYTE  7: cccc cccc  |
--------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------
ADDRESS: xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxx 1000, BYTE  8: cccc iiii  |
         xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxx 1001, BYTE  9: cccc cccc  |
         xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxx 1010, BYTE 10: cccc cccc  |
         xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxx 1011, BYTE 11: cccc cccc  |__ CDR (8 Bytes long, 64 bits)
         xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxx 1100, BYTE 12: cccc cccc  |
         xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxx 1101, BYTE 13: cccc cccc  |
         xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxx 1110, BYTE 14: cccc cccc  |
         xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxx 1111, BYTE 15: cccc cccc  |
--------------------------------------------------------------------------------------------------------__ Beginning of Next Cell
ADDRESS: xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxx1 0000, BYTE 16: cccc iiii  |
         xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxx1 0001, BYTE 17: cccc cccc  |
                                                                                                       V

The Same Contents can be written linearly like:
          BYTE 7   BYTE 6   BYTE 5   BYTE 4   BYTE 3   BYTE 2   BYTE 1   BYTE 0

   pair  cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccc 0000

   cnt   cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccc S010

   big   cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccc S100

   sym   cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccc 1000



The lowest bit (M) of a cell is set for garbage collection.

                                                                          [bit0]
                                                                            |
         B8       B7       B6       B5       B4       B3       B2       B1  |
      xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxx000M
                                                                            |
                                                                            v
                                                    [Mark for garbage collection]



Numbers

Internally, numeric values of up to 60 bits are stored in "short" numbers or count (CNT)

                                                                         [bit1 set]
                                                                           |
         B8       B7       B6       B5       B4       B3       B2       B1 |
      xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxS010  - 10 = 2 in Binary
                                                                         |
                                                                         v
                                                                   [sign-bit]


 BYTE 1: xxxxS010
 BYTE 2: xxxxxxxx
 BYTE 3: xxxxxxxx
 BYTE 4: xxxxxxxx
 BYTE 5: xxxxxxxx
 BYTE 6: xxxxxxxx
 BYTE 7: xxxxxxxx
 BYTE 8: xxxxxxxx

i.e. the value is directly represented in the pointer, and doesn't take any heap space.

Numbers larger than 60 bits are called "big nums" and are stored like this:


         Bignum
         |
         V
      +-----+-----+
      | DIG |  |  |
      +-----+--+--+
               |
               V
            +-----+-----+
            | DIG |  |  |
            +-----+--+--+
                     |
                     V
                  +-----+-----+
                  | DIG | CNT |
                  +-----+-----+


                                                                        [bit2 set]
                                                                          |
         B8       B7       B6       B5       B4       B3       B2       B1|
      xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxS100    - 100 = 4 in binary
                                                                         |
                                                                         v
                                                                   [sign-bit]

Symbols


           Symbol
            |
            V
      +-----+-----+
      |  /  | VAL |  Getting the Value of a symbol is super efficient as the
      +-----+-----+  pointer points directly to it.
          _____
         |     |
         V     V
      +-----+-----+
      | CAR | CDR |
      +-----+-----+
         |
         V
       'tail' is kept in the CAR


                                                                       [bit3 set]
                                                                         |
         B8       B7       B6       B5       B4       B3       B2      B1|
      xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxx1000  - 1000 = 8 in binary
                                                                         |
                                                                         v
                                                         Notice the Symbol always
                                                         points to the 8th Byte

Property Lists and Symbol Names
').

The characters of the symbol's name itself identify the physical location of the external object. In both cases, the database file (and possibly the hyphen) are omitted for the first (default) file.

Memory Management

mark-and-sweep garbage collector

http://thevikidtruth.com/wiki/?pilmachine

10oct17   admin