+lilypond-devel for visibility. On Sat, Feb 1, 2020 at 10:54 AM Han-Wen Nienhuys <hanw...@gmail.com> wrote: > > Here is an example that shows better how things work, and what might > be the cause of my problems. Is it right that programmatically set > contents of "current-module" are not serialized into the compiled > file? > > (define (run-at-compile-time cmd) > (module-define! (current-module) (string->symbol cmd) #t) > (format (current-error-port) "I-am-called-at-compile-time ~a\n" cmd)) > > (define (runtime-call cmd) > (format (current-error-port) "I-am-called-at-runtime ~a\n" cmd) > (format (current-error-port) "val ~a\n" > (module-ref (current-module) (string->symbol cmd)))) > > (defmacro foo (cmd . rest) > (run-at-compile-time cmd) > `(runtime-call ,cmd)) > > (foo "xy") > > $ guile1.8 ew.scm > I-am-called-at-compile-time xy > I-am-called-at-runtime xy > val #t > > this is compatible with 2.2 without compilation, > > $ GUILE_AUTO_COMPILE=0 guile2.2 ew.scm > I-am-called-at-compile-time xy > I-am-called-at-runtime xy > val #t > > but compilation fails > > $ GUILE_AUTO_COMPILE=1 guile2.2 ew.scm > ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0 > ;;; or pass the --no-auto-compile argument to disable. > ;;; compiling /home/hanwen/vc/lilypond/ew.scm > ;;; WARNING: compilation of /home/hanwen/vc/lilypond/ew.scm failed: > ;;; Unbound variable: run-at-compile-time > > $ guild2.2 compile ew.scm > Backtrace: > In system/base/target.scm: > 57:6 19 (with-target _ _) > In system/base/compile.scm: > .. > Unbound variable: run-at-compile-time > > > If I encapsulate the run-at-compile-time definition with > > (eval-when > (compile eval) > > it works if I remove the module manipulation, but the module-ref > doesn't work. It looks like the settings from module-define! are not > serialized into the byte code, so I can't have code that relies on > correspondence between module-define driven from macros and module-ref > during evaluation. > > [hanwen@localhost lilypond]$ guild2.2 compile ew.scm > I-am-called-at-compile-time xy > wrote > `/home/hanwen/.cache/guile/ccache/2.2-LE-8-3.A/home/hanwen/vc/lilypond/ew.scm.go' > [hanwen@localhost lilypond]$ GUILE_AUTO_COMPILE=0 guile2.2 ew.scm > I-am-called-at-runtime xy > Backtrace: > 6 (apply-smob/1 #<catch-closure 56514b4c37a0>) > In ice-9/boot-9.scm: > 705:2 5 (call-with-prompt ("prompt") #<procedure 56514b4d5c60 …> …) > In ice-9/eval.scm: > 619:8 4 (_ #(#(#<directory (guile-user) 56514b591140>))) > In ice-9/boot-9.scm: > 2312:4 3 (save-module-excursion #<procedure 56514b54b330 at ice-…>) > 3832:12 2 (_) > In ew.scm: > 10:10 1 (runtime-call "xy") > In unknown file: > 0 (scm-error misc-error #f "~A ~S ~S ~S" ("No variabl…" …) …) > > ERROR: In procedure scm-error: > No variable named xy in #<directory (guile-user) 56514b591140> >
-- Han-Wen Nienhuys - hanw...@gmail.com - http://www.xs4all.nl/~hanwen