guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: guile-vm 0.3


From: Keisuke Nishida
Subject: Re: guile-vm 0.3
Date: Tue, 03 Apr 2001 19:11:40 -0400
User-agent: Wanderlust/2.4.0 (Rio) SEMI/1.13.7 (Awazu) FLIM/1.13.2 (Kasanui) Emacs/21.0.99 (i686-pc-linux-gnu) MULE/5.0 (SAKAKI)

At Tue, 03 Apr 2001 17:38:39 -0400,
Keisuke Nishida wrote:
> 
> All top-level variables are linked with the current module.
> Probably this is all you have to do to support the current
> module system.
> 
> Maybe I'll do it right now.

Okay, it's now ready, somehow:

  % guile-vm
  Standard Scheme (R5RS + syntax-case) interpreter 0.3 on Guile 1.4.1
  Copyright (C) 2001 Free Software Foundation, Inc.

  Enter `,help' for help.
  address@hidden> (define foo 1)
  address@hidden> foo
  $1 = 1
  address@hidden> (define (foo x y) (+ x y))
  address@hidden> (foo 1 2)
  $2 = 3
  address@hidden> ,x foo
  Disassembly of #<program 0x80ac6d8>:

  args = 2  rest = 0  locals = 0

  Bytecode:

     0    local-ref 1
     2    local-ref:0
     3    object-ref 0
     5    variable-ref
     6    tail-call 2

  Objects:

     0    (+ . #<primitive-procedure +>)

Try with the following ~/.guile:

  (define-module (guile-user))

  (if (string=? (car (command-line)) "guile-vm")
      (begin
        (use-modules (system repl repl))
        (use-modules (language r5rs expand))
        (start-repl 'r5rs)
        (quit)))

The r5rs translator uses the latest syntax-case expander,
which supports the `module' and `import' syntaxes (though
I haven't tried them yet.)

You can write your modules as follows:

  ---- fib.scm ---------------------------
  (define-module (fib)
    :use-module (system base language)
    :use-module (language r5rs expand)
    :export (fib))

  (hacked-load-in "/somewhere/fib.gm" 'r5rs)
  ----------------------------------------

  ---- fib.gm ----------------------------
  (define (fib n)
    (if (< n 2) 1 (+ (fib (1- n)) (fib (- n 2)))))
  ----------------------------------------

Now, you can use it as a Guile module:

  % guile
  guile> (use-modules (fib))
  guile> (fib 10)
  $1 = 89
  guile> fib
  $1 = #<program 0x814db9c>

The procedure `hacked-load-in' above automatically compiles
the source file if it has been modified, save the compiled
code, and loads it.  Thus, `fib' is a VM program, not a
Guile's closure, as shown above.

Hey, it works already, although it seems there are bugs,
and the load speed is very slow (this can be fixed).

Probably it's a good idea to use my VM this way for the moment.
Unfortunately, I'll be pretty busy during this month, so I'll
do this work in May.  Do you want to wait, or hack my horrible
code?

My VM still lacks some important features, especially exception
handling.  This must be implemented before it becomes ready for
use.

Kei



reply via email to

[Prev in Thread] Current Thread [Next in Thread]