From: Jan Nieuwenhuizen <janneke@gnu.org>
To: guile-user@gnu.org
Subject: primitive eval with module => Unbound variable?
Date: Tue, 16 May 2017 23:59:01 +0200 [thread overview]
Message-ID: <87ziec4g62.fsf@gnu.org> (raw)
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?
Greetings,
janneke
--
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.com
next reply other threads:[~2017-05-16 21:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-16 21:59 Jan Nieuwenhuizen [this message]
2017-05-17 17:58 ` primitive eval with module => Unbound variable? Vladimir Zhbanov
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=87ziec4g62.fsf@gnu.org \
--to=janneke@gnu.org \
--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).