From: Vladimir Zhbanov <vzhbanov@gmail.com>
To: guile-user@gnu.org
Subject: Re: primitive eval with module => Unbound variable?
Date: Wed, 17 May 2017 20:58:42 +0300 [thread overview]
Message-ID: <20170517175842.GA15012@localhost.localdomain> (raw)
In-Reply-To: <87ziec4g62.fsf@gnu.org>
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
next prev parent reply other threads:[~2017-05-17 17:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-16 21:59 primitive eval with module => Unbound variable? Jan Nieuwenhuizen
2017-05-17 17:58 ` Vladimir Zhbanov [this message]
2017-05-17 19:44 ` Andy Wingo
2017-05-18 4:54 ` Jan Nieuwenhuizen
2017-05-22 19:45 ` Andy Wingo
2017-05-22 20:19 ` Jan Nieuwenhuizen
2017-05-22 19:48 ` Andy Wingo
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=20170517175842.GA15012@localhost.localdomain \
--to=vzhbanov@gmail.com \
--cc=guile-user@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).