Re: low level VM and disassemble

2015-08-26 Thread Alexander Burger
Hi Erik,

 that wouldn't be very useful. Though it's good to know it can be done. I
 was more curious if a dump of the PiocLisp ASM was possible, say for a
 top-level REPL call (e.g. '(mapc println (1 2 3))).

Ah, that is the misunderstanding!

An expression like (mapc println (1 2 3)) involves absolutely no such
code at all. In fact, this *IS* the code.

That's why some people call Lisp a high-level assembly language.

Lisp-code like (mapc println (1 2 3)) is directly interpreted. This
sequence of parentheses and characters like 'm', 'a', 'p' etc. are just
a representation of the internal s-epr structure. The reader converts it
to

   +-+-+ +-+-+ +-+-+
   |  |  |  ---+--- |  |  |  ---+--- |  |  |  /  |
   +--+--+-+ +--+--+-+ +--+--+-+
  | | |
  V V V
mapc println   +-+-+ +-+-+ 
+-+-+
   |  1  |  ---+--- |  2  |  ---+--- |  3 
 |  /  |
   +-+-+ +-+-+ 
+-+-+

and, when printed, it shows up as (mapc println (1 2 3)) again. The
tokens 'mapc' and 'println' here denote references to the cell
structures of those symbols.

These are the internal pointer structures, and there is nothing else
below them. No assembly code to be disassembled. 'print'ing the above
structure *IS* the disassembly.

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: low level VM and disassemble

2015-08-26 Thread Erik Gustafson
Oooh. Ok, that clarifies things. I've got some homework tonight then.
Time to read the PL ref again with all of this in mind!

Thanks Alex.

On Wed, Aug 26, 2015 at 1:49 PM, Alexander Burger a...@software-lab.de
wrote:

 Hi Erik,

  that wouldn't be very useful. Though it's good to know it can be done. I
  was more curious if a dump of the PiocLisp ASM was possible, say for a
  top-level REPL call (e.g. '(mapc println (1 2 3))).

 Ah, that is the misunderstanding!

 An expression like (mapc println (1 2 3)) involves absolutely no such
 code at all. In fact, this *IS* the code.

 That's why some people call Lisp a high-level assembly language.

 Lisp-code like (mapc println (1 2 3)) is directly interpreted. This
 sequence of parentheses and characters like 'm', 'a', 'p' etc. are just
 a representation of the internal s-epr structure. The reader converts it
 to

+-+-+ +-+-+ +-+-+
|  |  |  ---+--- |  |  |  ---+--- |  |  |  /  |
+--+--+-+ +--+--+-+ +--+--+-+
   | | |
   V V V
 mapc println   +-+-+ +-+-+
  +-+-+
|  1  |  ---+--- |  2  |  ---+---
 |  3  |  /  |
+-+-+ +-+-+
  +-+-+

 and, when printed, it shows up as (mapc println (1 2 3)) again. The
 tokens 'mapc' and 'println' here denote references to the cell
 structures of those symbols.

 These are the internal pointer structures, and there is nothing else
 below them. No assembly code to be disassembled. 'print'ing the above
 structure *IS* the disassembly.

 ♪♫ Alex
 --
 UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe



Re: low level VM and disassemble

2015-08-26 Thread Erik Gustafson
Hi all,

Thanks for the responses. I have been reading the docs and using 'vi' (like
a n00b, see below) to navigate the sources. Sounds like a bit more time and
patience is needed on my part :)

I wasn't so much interested in a dump of the generated native ASM; I agree
that wouldn't be very useful. Though it's good to know it can be done. I
was more curious if a dump of the PiocLisp ASM was possible, say for a
top-level REPL call (e.g. '(mapc println (1 2 3))). But it sounds like it
is not, as the PL ASM kicks out generated ASM as soon as the VM is built.
My mental model of things down there is a bit fuzzy yet.

I was not aware I could use Shift-K/Q to hop around so easily. Thanks for
the tip! I had just been calling vi, quitting, calling vi with the next,
quitting... heh. Sounds like this is a better way to chase those cells
around than dump anyway. I'll keep at it.

Many thanks,
Erik

On Wednesday, August 26, 2015, John Duncan duncan.j...@gmail.com wrote:

 I think, Erik, you should review the PicoLisp Reference about evaluation.
 In PicoLisp, everything is interpreted except primitive functions which are
 either implemented in C (32-bit) or assembly (64-bit). So the source you
 see in the lisp files is the same as what the compiler will execute, except
 that data structures are built and symbols resolved during (read).

 The relevant part of the manual is here:
 http://software-lab.de/doc/ref.html#ev

 John

 On Wed, Aug 26, 2015 at 1:00 AM, Alexander Burger a...@software-lab.de
 javascript:_e(%7B%7D,'cvml','a...@software-lab.de'); wrote:

 Hi Erik,

  I imagine something like CL's 'disassemble' that, given an arbitrary
 lisp
  expression, returns the sequence of VM instructions the expression maps
 to.

 To extend a little what Tomas and Andreas said:

 I think it is not so very useful to look at the generated native ASM
 code, as it more or less maps 1:1 to the PicoLisp assembly, and the
 latter is more readable.

 Still, you can easily disassemble the executable:

$ objdump -S bin/picolisp |view -


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

$ pil +
: (vi 'vi)

 you can navigate by moving the cursor to some identifier and hit Shift-K

Re: low level VM and disassemble

2015-08-25 Thread Alexander Burger
Hi Erik,

 I imagine something like CL's 'disassemble' that, given an arbitrary lisp
 expression, returns the sequence of VM instructions the expression maps to.

To extend a little what Tomas and Andreas said:

I think it is not so very useful to look at the generated native ASM
code, as it more or less maps 1:1 to the PicoLisp assembly, and the
latter is more readable.

Still, you can easily disassemble the executable:

   $ objdump -S bin/picolisp |view -


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

   $ pil +
   : (vi 'vi)

you can navigate by moving the cursor to some identifier and hit 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

With Shift-Q you can pop back.

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: low level VM and disassemble

2015-08-25 Thread Tomas Hlavaty
Hi Erik,

one of the immediate steps for pil64 compilation goes through asm file.
You can study that.  Otherwise picolisp doesn't have a disassembler and
it also doesn't have a compiler.

Cheers,

Tomas

Erik Gustafson erik.d.gustaf...@gmail.com writes:

 Hi List,

 I'd like to develop a better intuition for how things work in
 the lower levels of 64bit PicoLisp, how cells are passed between
 registers, and all that. I need to spend more time with the code
 in /src64 and going over the docs, obviously. Any other ways you
 all have found to be effective in developing that sense? 'trace'
 and 'debug' have been very helpful, but they seem to operate on
 a higher level. 

 I imagine something like CL's 'disassemble' that, given an
 arbitrary lisp expression, returns the sequence of VM
 instructions the expression maps to. Would something like this
 be possible to implement? If so, where might be a good place to
 start exploring? 

 Or is this another existing feature that I've managed to miss
 this whole time? :) 

 Thanks,
 Erik 
--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe