[Openmcl-devel] getting CCL ready for CS graphics courses

Alexander Repenning ralex at cs.colorado.edu
Sat Jan 10 07:58:24 UTC 2009


On Jan 10, 2009, at 12:02 AM, Terje Norderhaug wrote:

> On Jan 9, 2009, at 10:20 PM, Alexander Repenning wrote:
>> On Jan 8, 2009, at 6:37 PM, Terje Norderhaug wrote:
>>> On Jan 8, 2009, at 5:05 PM, Alexander Repenning wrote:
>>>> At least for the vector caveat we have a solution. The approach
>>>> taken
>>>> may sound a bit crazy. We are implementing vector constants with a
>>>> combination of Lisp readers and Universally Unique Identifiers.
>>>> Perhaps not super elegant, there is bound to be a better
>>>> solution, but
>>>> it works.  Code at the end. A call to a vector function looks like
>>>> this
>>>>
>>>> (glColor3fv {0.5 0.1 0.8})
>>>>
>>>> which is pretty close to what students "know" from C. The only  
>>>> issue
>>>> is that getting the cached value is not that fast. The hash table
>>>> access it the bottleneck.
>>>
>>> What about only looking up the value at compile time? As in:
>>>
>>> (glColor3fv #.{0.5 0.1 0.8})
>>
>> I don't think the Lisp compiler could handle that because it would
>> try to dump a foreign  pointer.
>
> You may get beyond that by defining a make-load-form for your
> representation of the gl vectors.

that is true. One problem is that I do not have my own class to for  
the foreign type. However, a foreign pointer is of the built in class  
macptr. A make-load-form could easily be written for that class for  
instance by dumping the pointer content as sequence of byes. When  
running the compiled code each time the a new pointer would be  
allocated and initialization would take place. This would be slow and  
a wicket memory leak.

When the C compiler sees an expression like

glColor3fv ({0.5 0.1 0.8})

it will put a 3 float vector constant into some static memory space,  
not the heap

This is simple is C but tricky in Lisp. The Lisp compiler does not  
provide a simple means to define a raw float vector constant that  
would end up in static space. To achieve some similar in Lisp

(glColor3fv {0.5 0.1 0.8}) will be expanded into:

(glColor3fv  (GET-CACHED-VECTOR 78533C19-BA5D-481A-9C54-5690D0A0F25E  
0.5 0.1 0.8))

the GET-CACHED-VECTOR uses a globally unique identifier, e.g.,   
78533C19-BA5D-481A-9C54-5690D0A0F25E to store and retrieve the 3  
floats in a hash table. This way the foreign pointer get created and  
returned the first time glColor3fv is called. Every consecutive call  
will return the same, hash table cached value. The net result is  
essentially the same as in C, a vector constant.

Alex







>
>
> -- Terje Norderhaug
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>

Prof. Alexander Repenning

University of Colorado
Computer Science Department
Boulder, CO 80309-430

vCard: http://www.cs.colorado.edu/~ralex/AlexanderRepenning.vcf


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.clozure.com/pipermail/openmcl-devel/attachments/20090110/56c85e08/attachment.html>


More information about the Openmcl-devel mailing list