Syntax in 'src64/'

A look at PicoLisp ASM and how the 64-bit Interpreter binary is built
If you start digging into the sources of 64-bit PicoLisp (e.g. "src64/flow.l"), you'll notice that most of the code doesn't have parens. Why? Because this is assembly and not Lisp (though the normal Lisp reader is used to parse the sources).

Assembly language is not a functional language, i.e. the individual instructions do not "return" a value. So a fully paranthized syntax is useless and just tedious.

Following the Makefile

In essence, the above assembly language is translated by a generic assembler - which is written in PicoLisp - to some target assembly language (normally GNU assembler for the given platform), which in turn is assembled by the platform's assembler and linked to a binary executable.

It works like this:

In "src64/Makefile" a shell script "mkAsm" is called. This script tries to locate some PicoLisp executable to do the assembly. It tries "/usr/bin/pil", "../pil" and "../ersatz/pil", in that order. When found, it is used to run "mkAsm.l", which loads "lib/asm.l" and some other stuff.

"lib/asm.l" (in "src64/") is the generic assembler. It produces the target assembly code (or C code in case of the emulator), by calling the function 'build' with the interpreter's source files in "src64/".

'build' sets up the output environment, and calls 'run' to execute the "Prg" body, which is simply a 'load' in "mkAsm.l". That is, the sources are indeed 'load'ed (at least they start to do so), because the first expression in e.g. "flow.l":

   (code 'redefMsgEC)

is a call to 'code'. 'code' is a variation of 'section'. Each section (which can be 'code' or 'data') extends till the first non-atomic expression is reached (the next call to 'code').

'section' (in "src64/lib/asm.l") is the actual workhorse of the assembler. If you look at it, you see it calls 'read' to parse the assembly sources, build the '*Program', do some optimizations, and finally output it with the 'apply' call at the end.

Browsing the ASM

When looking at the sources with 'vi', e.g.

   $ pil +
   : (vi 'vi)

you can navigate by moving the cursor to some identifier and hitting Shift-K. Then 'vi' will jump to that source. This will give access to all Lisp and ASM code reachable from that point.

In case of the 'vi' code above, you may press Shift-K on 'call', then move down to 'execArgsE_SXZ' and press Shift-K again. Shift-Q will pop you back.

The assembly instructions and internal structures of the interpreter are well documented.

https://picolisp.com/wiki/?src64

09apr17   erik