Discussion:
[Larceny-users] library form for gl.scm
Eduardo Cavazos
2009-02-05 05:38:42 UTC
Permalink
Hello,

So far, I've been using 'gl.scm' without a 'library' form. I tried this one:

----------------------------------------------------------------------
(library

(larceny gl)

(export GL_FALSE ...)

(import (rnrs base)
(rnrs io simple)
(err5rs records syntactic))

; Rest of the file here...
)
----------------------------------------------------------------------

But it did Larceny doesn't seem to like it:

~ # larceny -- /scratch/_gl-larceny-library.scm
Larceny v0.97b1 (beta test) (Aug 25 2008 07:06:36, precise:Linux:unified)
ERROR detected during macro expansion:
Definition out of context
(define GL_FALSE 0)
larceny.heap, built on Mon Aug 25 07:08:14 EDT 2008

Any suggestions?

Ed
William D Clinger
2009-02-05 15:28:02 UTC
Permalink
Post by Eduardo Cavazos
Larceny v0.97b1 (beta test) (Aug 25 2008 07:06:36, precise:Linux:unified)
Definition out of context
(define GL_FALSE 0)
larceny.heap, built on Mon Aug 25 07:08:14 EDT 2008
Any suggestions?
In the body of an R6RS library, all definitions must precede
any expressions that appear at the top level of the body.
The code at http://proteus.freeshell.org/_gl-larceny-a.scm
begins with

(foreign-file "/usr/X11R7/lib/libGL.so.1")

When your code is inserted into a library, you end up with
definitions following an expression, which implementations
of the R6RS are required to reject. (See R6RS section 5.5.)
The workaround is to replace that expression by something
like

(define ignored1
(foreign-file "/usr/X11R7/lib/libGL.so.1"))

We are sorry for the inconvenience. Maybe this will change
in an R7RS.

Will
Felix Klock
2009-02-05 16:02:27 UTC
Permalink
Will (cc'ing larceny-users and Ed)-
Post by William D Clinger
The workaround is to replace that expression by something
like
(define ignored1
(foreign-file "/usr/X11R7/lib/libGL.so.1"))
Wouldn't moving the foreign-file invocation to another library (and
adding a corresponding import to this library) also fix the problem?

This is not a completely absurd suggestion; someone might want to make
a different version of the gl interface, but both versions of the
interface are likely to want to load up the same version of the
libGL.so shared object code library.

-Felix
Eduardo Cavazos
2009-02-05 16:23:29 UTC
Permalink
Post by William D Clinger
The workaround is to replace that expression by something
like
(define ignored1
(foreign-file "/usr/X11R7/lib/libGL.so.1"))
Hmmm... that didn't seem to work for me.

To make this concrete, here's the simplest possible test case that
demonstrates the problem.

If I load it via either one of these:

~ # larceny -- /scratch/_gl-test-case-a.scm

~ # larceny -err5rs -- /scratch/_gl-test-case-a.scm

I get this error:

ERROR detected during macro expansion:
Definition out of context
(define libGL (foreign-file "libGL.so.1"))

----------------------------------------------------------------------
(library

(larceny gl)

(export GL_TRUE glBegin)

(import (rnrs base)
(rnrs io simple)
(err5rs records syntactic))

(define libGL (foreign-file "libGL.so.1"))

(define GL_TRUE #x1)

(define-function void glBegin (int))

)
----------------------------------------------------------------------
William D Clinger
2009-02-05 16:39:32 UTC
Permalink
Post by Eduardo Cavazos
~ # larceny -- /scratch/_gl-test-case-a.scm
~ # larceny -err5rs -- /scratch/_gl-test-case-a.scm
Definition out of context
(define libGL (foreign-file "libGL.so.1"))
Sorry, I had missed that you were loading the file
via Larceny's -- hack. That hack works only in R5RS
and ERR5RS modes; in either mode the file is loaded
as R5RS code, so the library form looks like a call
to a procedure named "library". Definitions are
illegal in the argument positions of procedure calls,
so you're getting an R5RS syntax error.

Now that all of the forms in the body of the library
are definitions, you should be able to load the file
into ERR5RS mode like this:

# larceny -err5rs
ERR5RS mode (no libraries have been imported)
Post by Eduardo Cavazos
(import (rnrs) (larceny load))
(load "/scratch/_gl-test-case-a.scm")
You could also rename the file so it ends with .sls,
place it in a directory named larceny, and add the
parent of the larceny directory to your library path.
Then you could import it like this:

# larceny -path <dir> -err5rs
ERR5RS mode (no libraries have been imported)
Post by Eduardo Cavazos
(import (rnrs) (larceny gl))
We should probably add a library macro to Larceny's
standard heap, and define that macro so the error
message will tell you the problem came from trying
to use the library syntax in R5RS mode.

Will
Eduardo Cavazos
2009-02-05 17:20:10 UTC
Permalink
Success!

This test case library works. I put it in 'lib' and named it
'gl-test.sls'. Also note, I had to add a '(primitives ...)' form to the
import clause to get it to work.

I'm able to load it like so:

~ # larceny -err5rs
Larceny v0.97b1 (beta test) (Aug 25 2008 07:06:36, precise:Linux:unified)
larceny.heap, built on Mon Aug 25 07:08:14 EDT 2008
ERR5RS mode (no libraries have been imported)
(import (rnrs) (gl-test))
The contents of 'gl-test.sls' are below. If this looks good, I'll model
the full 'gl.sls' on it.

----------------------------------------------------------------------
(library

(gl-test)

(export GL_TRUE glBegin)

(import (rnrs base)
(rnrs io simple)
(err5rs records syntactic)

(primitives foreign-file
foreign-procedure))

(define libGL (foreign-file "libGL.so.1"))

(define GL_TRUE #x1)

(define-syntax define-function
(syntax-rules ()
((_ ret name args)
(define name (foreign-procedure (symbol->string 'name) 'args
'ret)))))

(define-function void glBegin (int))

)
----------------------------------------------------------------------
Loading...