hi!
I have wrapper.scm (which is compiled code), and test.scm (which is interpreted)
i.e. (compile-file-to-c "wrapper"); (link-flat '("wrapper ...) output: "blah.o1.c"); gcc -shared -fPIC ... blah.o1.c -o blah.o1
test.scm: (load "blah") ...
and I run everything with "gsi test.scm"
Now, here's the problem. In test.scm, I need to call a glutDisplayFunc, which requires a _C_ callback. Okay, so I define function with (c-define (c-disp ...) ... (disp)). (disp) is the scheme funfction that does the real workd; c-disp is a c wrapper around disp. Since test.scm is interpted, I have to put it in wrapper.scm -- however, I want to keep disp in test.scm (rapid prototypinhg, changing it on the fly, etc ...). Question is, how can I get c-disp (which is in wrapper.scm) to get call (disp), which is in test.scm?
if I just do wrapper.scm:
(c-define (c-disp) () void "f" "" (disp))
and test.scm: (load "graphics")
;(c-define (c-disp) () void "f" "" (disp))
(define (disp) (glClear GL_COLOR_BUFFER_BIT) (glutWireTeapot 0.5))
and run gsi test.scm, I get:
$gsi test.scm *** WARNING -- Variable "format" used in module "wrapper-s" is undefined
so the question is ... how can i get compile scheme code to 'wait' in order to call interpted scheme code?
thanks!
Afficher les réponses par date
Sorry, that last line should say:
gsi test.scm *** WARNING -- Variable "disp" used in module "wrapper-s" is undefined
On Mon, Jan 19, 2009 at 5:43 PM, symbolic expression < symbolic.expression@gmail.com> wrote:
hi!
I have wrapper.scm (which is compiled code), and test.scm (which is interpreted)
i.e. (compile-file-to-c "wrapper"); (link-flat '("wrapper ...) output: "blah.o1.c"); gcc -shared -fPIC ... blah.o1.c -o blah.o1
test.scm: (load "blah") ...
and I run everything with "gsi test.scm"
Now, here's the problem. In test.scm, I need to call a glutDisplayFunc, which requires a _C_ callback. Okay, so I define function with (c-define (c-disp ...) ... (disp)). (disp) is the scheme funfction that does the real workd; c-disp is a c wrapper around disp. Since test.scm is interpted, I have to put it in wrapper.scm -- however, I want to keep disp in test.scm (rapid prototypinhg, changing it on the fly, etc ...). Question is, how can I get c-disp (which is in wrapper.scm) to get call (disp), which is in test.scm?
if I just do wrapper.scm:
(c-define (c-disp) () void "f" "" (disp))
and test.scm: (load "graphics")
;(c-define (c-disp) () void "f" "" (disp))
(define (disp) (glClear GL_COLOR_BUFFER_BIT) (glutWireTeapot 0.5))
and run gsi test.scm, I get:
$gsi test.scm *** WARNING -- Variable "format" used in module "wrapper-s" is undefined
so the question is ... how can i get compile scheme code to 'wait' in order to call interpted scheme code?
thanks!
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
The warning is just a warning. It's a common message from Gambit when dynamically loading libraries. The issue is that when a library is loaded, it references a few functions which don't exist yet. Most likely these requirements will fulfilled by loading other libraries which define those functions. For example:
;;test.scm (c-define (foo) () void "foo" "" (bar))
;;test2.scm (define (bar) (display "hello"))
% gsc test.scm % gsi Gambit v4.3.2
(load "test")
*** WARNING -- Variable "bar" used in module "test.o1" is undefined "~/test.o1"
(load "test2")
"~/test2.scm"
(foo)
hello>
So it's probably just a timing issue. You could add `(load "test")' at the top of wrapper.scm and compile wrapper.scm, and then run `gsi wrapper.o1' instead.
On Jan 19, 2009, at 8:48 PM, TongKe Xue wrote:
Sorry, that last line should say:
gsi test.scm *** WARNING -- Variable "disp" used in module "wrapper-s" is undefined
On Mon, Jan 19, 2009 at 5:43 PM, symbolic expression <symbolic.expression@gmail.com
wrote:
hi!
I have wrapper.scm (which is compiled code), and test.scm (which is interpreted)
i.e. (compile-file-to-c "wrapper"); (link-flat '("wrapper ...) output: "blah.o1.c"); gcc -shared -fPIC ... blah.o1.c -o blah.o1
test.scm: (load "blah") ...
and I run everything with "gsi test.scm"
Now, here's the problem. In test.scm, I need to call a glutDisplayFunc, which requires a _C_ callback. Okay, so I define function with (c-define (c-disp ...) ... (disp)). (disp) is the scheme funfction that does the real workd; c-disp is a c wrapper around disp. Since test.scm is interpted, I have to put it in wrapper.scm -- however, I want to keep disp in test.scm (rapid prototypinhg, changing it on the fly, etc ...). Question is, how can I get c-disp (which is in wrapper.scm) to get call (disp), which is in test.scm?
if I just do wrapper.scm:
(c-define (c-disp) () void "f" "" (disp))
and test.scm: (load "graphics")
;(c-define (c-disp) () void "f" "" (disp))
(define (disp) (glClear GL_COLOR_BUFFER_BIT) (glutWireTeapot 0.5))
and run gsi test.scm, I get:
$gsi test.scm *** WARNING -- Variable "format" used in module "wrapper-s" is undefined
so the question is ... how can i get compile scheme code to 'wait' in order to call interpted scheme code?
thanks!
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
On 20-Jan-09, at 1:32 AM, James Long wrote:
The warning is just a warning. It's a common message from Gambit when dynamically loading libraries. The issue is that when a library is loaded, it references a few functions which don't exist yet. Most likely these requirements will fulfilled by loading other libraries which define those functions. For example:
;;test.scm (c-define (foo) () void "foo" "" (bar))
;;test2.scm (define (bar) (display "hello"))
% gsc test.scm % gsi Gambit v4.3.2
(load "test")
*** WARNING -- Variable "bar" used in module "test.o1" is undefined "~/test.o1"
(load "test2")
"~/test2.scm"
(foo)
hello>
So it's probably just a timing issue. You could add `(load "test")' at the top of wrapper.scm and compile wrapper.scm, and then run `gsi wrapper.o1' instead.
That's correct. To avoid these warnings you can:
1) Load the files in reverse dependency order (i.e. load test2.scm before test.o1). This can also be done on the command line with:
gsi test2 test
2) Use the procedure "load-quietly" which you can define and use like this:
(define (load-quietly path) (##load path (lambda (script-line script-path) #f) #t #t #t))
(load-quietly "test") (load-quietly "test2")
Marc
You could define a 'hook' the way emacs and guile do.
;wrapper.scm (define disp-hook (list (lambda () (void))))
(define (add-hook hook thunk) (set-cdr! hook (cons thunk '())))
(define (run-hook hook) (for-each (lambda (p) (p)) hook))
(c-define (c-disp) () void "f" "" (run-hook disp-hook))
;test.scm (load "graphics")
(define (disp) (glClear GL_COLOR_BUFFER_BIT) (glutWireTeapot 0.5))
(add-hook disp-hook disp)
On Mon, Jan 19, 2009 at 5:43 PM, symbolic expression symbolic.expression@gmail.com wrote:
so the question is ... how can i get compile scheme code to 'wait' in order to call interpted scheme code?
thanks!
On 19-Jan-09, at 8:57 PM, Frederick LeMaster wrote:
You could define a 'hook' the way emacs and guile do.
;wrapper.scm (define disp-hook (list (lambda () (void))))
(define (add-hook hook thunk) (set-cdr! hook (cons thunk '())))
(define (run-hook hook) (for-each (lambda (p) (p)) hook))
(c-define (c-disp) () void "f" "" (run-hook disp-hook))
;test.scm (load "graphics")
(define (disp) (glClear GL_COLOR_BUFFER_BIT) (glutWireTeapot 0.5))
(add-hook disp-hook disp)
Nice solution! Another approach, which preserves the GLUT API, is to replace
(define glutDisplayFunc (c-lambda ((function () void)) void "glutDisplayFunc"))
with
(define (glutDisplayFunc func) (real-glutDisplayFunc (scheme-void-function->c-void-function func)))
(define real-glutDisplayFunc (c-lambda ((function () void)) void "glutDisplayFunc"))
(define (scheme-void-function->c-void-function func) (set! scheme-void-function func) c-void-function)
(c-define (c-void-function) () void "c_void_function" "" (scheme-void-function))
(define scheme-void-function #f)
Note that with this approach only one callback can be installed but that's OK because GLUT has a single display callback.
In a more general context you could use the following scheme-void- function->c-void-function procedure definition which allocates C functions from a pool of 5 predefined functions (basically a poor implementation of C closures):
(c-define (f0) () void "f0" "" (f 0)) (c-define (f1) () void "f1" "" (f 1)) (c-define (f2) () void "f2" "" (f 2)) (c-define (f3) () void "f3" "" (f 3)) (c-define (f4) () void "f4" "" (f 4))
(define c-void-functions (vector f0 f1 f2 f3 f4)) (define scheme-void-functions (vector #f #f #f #f #f))
(define (f i) ((vector-ref scheme-void-functions i)))
(define (scheme-void-function->c-void-function func) (let loop ((i 0)) (if (< i (vector-length scheme-void-functions)) (if (vector-ref scheme-void-functions i) (loop (+ i 1)) (begin (vector-set! scheme-void-functions i func) (vector-ref c-void-functions i))) (error "can't convert Scheme function to C function" func))))
The limit of 5 could of course be increased, but some limit will exist unless you are willing to accept a non-portable solution.
Gambit's C-interface actually includes code to convert any Scheme function to a C function by using the technique of dynamic code generation. This feature is disabled by default because it is a non- portable solution (it supports x86, SPARC and PowerPC) and it hasn't been tested thoroughly (check ___make_c_closure in lib/os_dyn.c for details). If you want to try it out you'll have to build Gambit from scratch using this (rather cryptic) invocation of the configure script:
CC="gcc -D___WORD_SIZE=___WORD_WIDTH" ./configure
If you do try it out, please let me know how it works out.
Marc