guile-user
[Top][All Lists]
Advanced

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

primitive eval with module => Unbound variable?


From: Jan Nieuwenhuizen
Subject: primitive eval with module => Unbound variable?
Date: Tue, 16 May 2017 23:59:01 +0200

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 <address@hidden> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | AvatarĀ® http://AvatarAcademy.com



reply via email to

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