unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Issue with compiling to scheme
@ 2013-08-02 19:39 mark
  2013-08-03 17:12 ` mark.d.witmer
  0 siblings, 1 reply; 4+ messages in thread
From: mark @ 2013-08-02 19:39 UTC (permalink / raw)
  To: guile-user


I'm running into a problem creating custom languages that compile to
Scheme. I have an example here of a simple compiler that takes any
Scheme expression and generates code for creating a Guile module. If I
compile a file using this language and reference the resulting module
from another one that's just written in normal Scheme, it works the
first time when the normal Scheme file gets autocompiled and then fails
subsequently when the cached compiled Scheme file is loaded, telling me
that any reference I make to a symbol defined in (guile) from my
compiled non-Scheme module is undefined.

This is rather hard to explain, so I've tried to boil this down to a
couple really short files.

First, this is the language spec:

(define-module (language test-lang spec)
  #:use-module (system base language)
  #:export (test-lang))

(define (compile-scheme exp env opts)
  (values
   `(begin (define-module (test-lang lang)) (display (+ 1 2)))
   env env))

(define-language test-lang
  #:title "test-lang"
  #:reader (lambda (port env) (read port))
  #:compilers `((scheme . ,compile-scheme))
  #:printer write)

All it does is take any arbitrary expression and generate a scheme
module that when loaded will display the number 3 (just for the
sake of an example).

I created a file test-lang/lang.scm with one expression in it and
compiled it. That created a cached .go file that defined the module.

Then I wrote the following script and ran it:

#! /home/mark/build/guile-2.0/bin/guile -s
!#
(use-modules (test-lang lang))

(display "Success")

The first time, it displayed 3 and then "Success". The second time I got
an error while it was doing primitive-load-path for
test-lang/lang.scm.go, telling me that 'display' is undefined.

Does anyone know if this is a problem with the compiler or am I not
using it propertly? I'm still not very clear on how compiled files
reference their environments. It seems like the module defined in my
non-Scheme file is completely empty when it gets loaded from another
compiled file.

This happens with my xml-xcb binding language as well, which makes it
hard to write applications that actually use it! I've been stuck
including --fresh-auto-compile in my scripts, which is not a very good
solution for the long term.

Thanks

-- 
Mark Witmer



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

end of thread, other threads:[~2013-08-13 18:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-02 19:39 Issue with compiling to scheme mark
2013-08-03 17:12 ` mark.d.witmer
2013-08-12 13:17   ` Thien-Thi Nguyen
2013-08-13 18:09     ` mark

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