guile-user
[Top][All Lists]
Advanced

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

Re: primitive eval with module => Unbound variable?


From: Vladimir Zhbanov
Subject: Re: primitive eval with module => Unbound variable?
Date: Wed, 17 May 2017 20:58:42 +0300
User-agent: Mutt/1.5.23 (2014-03-12)

On Tue, May 16, 2017 at 11:59:01PM +0200, Jan Nieuwenhuizen wrote:
> Hi!
> 
> My Mescc C compiler produces from C
> 
>     int main () {return 0;}
> 
> a list of functions (lambdas), that are called with text-address,
> data-address, globals, functions to produce lists of x86 instructions:
> 
>     #<procedure 2a61a80 at ice-9/eval.scm:345:13 (a b c d e)>
>     => (85 137 229 131 236 64)
>     #<procedure 2a859c0 at ice-9/eval.scm:345:13 (a b c d e)>
>     => (184 0 0 0 0)
>     #<procedure 2aada20 at ice-9/eval.scm:345:13 (a b c d e)>
>     => (80)
>     #<procedure 2ace560 at ice-9/eval.scm:345:13 (a b c d e)>
>     ...
> 
> I hoped to instead produce intermediate results in a sexp that can be
> written to file (like .o object files).  So instead of evaluating
> the lambdas, I tried quoting them to now produce
> 
> ==>
> 
>    (lambda (f g ta t d) (list 85 137 229 131 236 64))
>    (lambda (f g ta t d) (list 184 0 0 0 0))
>    (lambda (f g ta t d) (list 80))
>    (lambda (f g ta t d) (i386:push-global-address (+ (data-offset 
> "s:scaffold/mesmes" g) d)))
>    ...
> 
> and primitive-eval and run them later....  However, when I do this,
> i386:push-global-address is an Unbound variable.  Here's a small test
> that demonstrates my problem
> 
> --8<---------------cut here---------------start------------->8---
> ;; this works without define-module:
> ;; guile -e 'main' -s foo.scm
> 
> ;; uncomment define-module below and run:
> ;; guile -e '(@ (foo) main)' -s foo.scm
> ;;   => ERROR: Unbound variable: bar
> ;; (define-module (foo)  #:export (main))
> 
> (define (bar) (display "bar!!!\n"))
> 
> (define foo '(lambda (x) (bar)))
> 
> (define (main . rest)
>   (let ()
>     (format (current-error-port) "eval: foo=~s\n" foo)
>     (let ((x (primitive-eval foo)))
>       (format (current-error-port) "  =>~s\n" x)
>       (x 0))))
> --8<---------------cut here---------------end--------------->8---
> 
> This code works when not put in a module; make it a module and I get
> 
>     => ERROR: Unbound variable: bar
> 
> What should I be doing differently?
> 

I've found two working variants:

First:
--------------------------------8<--------------------------------
(define-module (foo)  #:export (main)) ; this is as is
...
(define foo '(lambda (x) ((@@ (foo) bar))))
...
-------------------------------->8--------------------------------

Second:
--------------------------------8<--------------------------------
(define-module (foo)  #:export (main bar)) ; export bar
...
(define foo '(lambda (x) ((@ (foo) bar))))
...
-------------------------------->8--------------------------------

It seems bar is not exported when guile tries to eval (compile?)
the code. Should it compile it here?

-- 
  Vladimir



reply via email to

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