unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* primitive eval with module => Unbound variable?
@ 2017-05-16 21:59 Jan Nieuwenhuizen
  2017-05-17 17:58 ` Vladimir Zhbanov
  2017-05-17 19:44 ` Andy Wingo
  0 siblings, 2 replies; 7+ messages in thread
From: Jan Nieuwenhuizen @ 2017-05-16 21:59 UTC (permalink / raw)
  To: guile-user

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



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-05-22 20:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-16 21:59 primitive eval with module => Unbound variable? Jan Nieuwenhuizen
2017-05-17 17:58 ` 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

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).