unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: guile-devel <guile-devel@gnu.org>
Subject: vm branch now uses vm repl by default
Date: Tue, 09 Sep 2008 08:48:50 +0200	[thread overview]
Message-ID: <m38wu195m5.fsf@pobox.com> (raw)

Hi,

I've enabled the VM repl by default on the vm branch. Here's a brief
annotated tour:

    $ ./pre-inst-guile
    Guile Scheme interpreter 0.5 on Guile 1.9.0
    Copyright (C) 2001-2008 Free Software Foundation, Inc.

    Enter `,help' for help.

A very pleasant introduction, no? And totally configurable with a nice
programming interface.

    scheme@(guile-user)> 'foo
    $1 = foo

A normal repl. The `scheme' indicates the current language, and
(guile-user) is the current module. The $1 = foo is from the history
module. If you don't have this in your ~/.guile, you really really want
it:

    (use-modules (ice-9 readline) (ice-9 history))
    (activate-readline)

Anyway, moving on:

    scheme@(guile-user)> (lambda () (pk a #:bar))
    $2 = #<program b755ecf8>

Entering in expressions actually compiles and executes them. In this
case we compiled and loaded a thunk. Compiled procedures are "programs",
and print as such.

    scheme@(guile-user)> (define a '(a . pair))
    scheme@(guile-user)> ($2)

    ;;; ((a . pair) #:bar)
    $3 = #:bar

Procedures resolve toplevel bindings lazily, as in the interpreter, so
you get letrec semantics in the repl.

    scheme@(guile-user)> ,x $2

There is a wealth of meta-commands at the repl, commands that start with
`,'. This command, `,x', is an abbreviation for `,disassemble'. Its
output is this:

    Disassembly of #<program b755ecf8>:

    nargs = 0  nrest = 0  nlocs = 0  nexts = 0

The program has no arguments, no rest arguments, no local variables, and
no external (lexically-bound) variables.

    Bytecode:

       0    (late-variable-ref 0)
       2    (late-variable-ref 1)
       4    (object-ref 2)                  ;; #:bar
       6    (tail-call 2)

    Objects:

       0    #<variable b80057f0 value: #<program b8005858>>
       1    #<variable b7569af0 value: (a . pair)>
       2    #:bar

Late-variable-ref looks at a cell in the object vector. If it is a
symbol, it is resolved relative to the module that was current when the
program was made. The object cell is then replaced with the resulting
resolved variable. Here we see that objects 0 and 1 were already
resolved. Object 2 is just the constant, #:bar.

All of the ref instructions push their values on the stack. Call
instructions pop off arguments, if any, then call the program on the top
of the stack. In this case it is a tail call.

    Sources:

       8    #(1 11 #f)

Some instructions are annotated with source information. In this case,
when the instruction pointer is at 8 (right after the tail-call -- one
byte for tail-call and one for the number of arguments, 2), the original
source was at line 1 and column 11 in an unnamed port (stdin in this
case).

    scheme@(guile-user)> ,option interp #t
    scheme@(guile-user)> ,option
    trace	#f
    interp	#t

Here we tell the repl that, given the option, we prefer to interpret
rather than compile. Of course, if the current language doesn't support
compilation, we always interpret.

    scheme@(guile-user)> (lambda () (pk a #:bar))
    $4 = #<procedure #f ()>

An interpreted procedure, like in olden times.

Happy hacking!

Andy
-- 
http://wingolog.org/




             reply	other threads:[~2008-09-09  6:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-09  6:48 Andy Wingo [this message]
2008-09-09  8:27 ` vm branch now uses vm repl by default Neil Jerram
2008-09-09 17:59   ` Andy Wingo
2008-09-09 22:27     ` Neil Jerram
2008-09-09  8:41 ` Ludovic Courtès
2008-09-09 18:13   ` Andy Wingo
2008-09-09 21:01     ` Ludovic Courtès
2008-09-10 19:05       ` Andy Wingo
2008-09-09 22:43 ` Neil Jerram
2008-09-10 18:51   ` Andy Wingo
2008-09-10 21:24     ` Neil Jerram

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m38wu195m5.fsf@pobox.com \
    --to=wingo@pobox.com \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).