[svn:parrot] r39520 - trunk/runtime/parrot/library

japhb at svn.parrot.org japhb at svn.parrot.org
Fri Jun 12 07:45:32 UTC 2009


Author: japhb
Date: Fri Jun 12 07:45:31 2009
New Revision: 39520
URL: https://trac.parrot.org/parrot/changeset/39520

Log:
[OpenGL] improve ambiguous names; support new experimental HLL export

Modified:
   trunk/runtime/parrot/library/OpenGL.pir

Modified: trunk/runtime/parrot/library/OpenGL.pir
==============================================================================
--- trunk/runtime/parrot/library/OpenGL.pir	Fri Jun 12 07:41:49 2009	(r39519)
+++ trunk/runtime/parrot/library/OpenGL.pir	Fri Jun 12 07:45:31 2009	(r39520)
@@ -90,7 +90,8 @@
 .sub _opengl_init :load
     load_bytecode 'OpenGL_funcs.pbc'
     _load_opengl_libs()
-    _wrap_all_opengl_entry_points()
+    _wrap_opengl_entry_points()
+    _export_opengl_functions()
 .end
 
 
@@ -173,13 +174,13 @@
 .end
 
 
-=item _wrap_all_opengl_entry_points()
+=item _wrap_opengl_entry_points()
 
 Create NCI wrappers for all GL, GLU, and GLUT functions
 
 =cut
 
-.sub _wrap_all_opengl_entry_points
+.sub _wrap_opengl_entry_points
     .local pmc namespace
     namespace = get_namespace
 
@@ -246,6 +247,59 @@
 
 =over 4
 
+=item _export_opengl_functions()
+
+Marks all OpenGL/GLU/GLUT functions as exported (to the default export tags,
+currently ALL and DEFAULT).  Unmangles callback names, so that the importing
+namespaces see the standard names instead of the mangled versions.  Called
+at :load time by _opengl_init().
+
+=cut
+
+.sub _export_opengl_functions
+    .local pmc     gl_namespace
+    gl_namespace = get_namespace
+
+    .local pmc     gl_ns_iterator, export_list, export_renames
+    .local string  symbol, prefix
+    gl_ns_iterator = iter gl_namespace
+    export_list    = new 'ResizableStringArray'
+    export_renames = new 'Hash'
+
+    # Prepare list of symbols and hash of renames for export
+  symbol_loop:
+    unless gl_ns_iterator goto symbol_loop_end
+    symbol = shift gl_ns_iterator
+
+    # For now, only handle symbols starting with 'gl'
+    prefix = substr symbol, 0, 2
+    unless prefix == 'gl' goto symbol_loop
+
+    # Special-case callbacks
+    prefix = substr symbol, 0, 6
+    if prefix == 'glutcb' goto rename_callbacks
+
+    # Add all other matching symbols to export list
+    push export_list, symbol
+    goto symbol_loop
+
+    # Rename all 'glutcb*' symbols to 'glut*'
+  rename_callbacks:
+    .local string renamed
+    renamed = clone symbol
+    substr renamed, 4, 2, ''
+    export_renames[symbol] = renamed
+    goto symbol_loop
+  symbol_loop_end:
+
+    # Mark all symbols and renames for export
+    .local pmc parrot
+    load_language 'parrot'
+    parrot = compreg 'parrot'
+    parrot.'export'(export_list)
+    parrot.'export'(export_renames)
+.end
+
 =item _export_all_functions(pmc to_namespace :optional)
 
 Export all OpenGL/GLU/GLUT functions to the target C<namespace>.  Unmangles
@@ -268,24 +322,24 @@
     .local pmc     gl_namespace
     gl_namespace = get_namespace
 
-    .local pmc     iterator, export_list, export_renames
-    .local string  symbol, tag
-    iterator       = iter gl_namespace
+    .local pmc     gl_ns_iterator, export_list, export_renames
+    .local string  symbol, prefix
+    gl_ns_iterator = iter gl_namespace
     export_list    = new 'ResizableStringArray'
     export_renames = new 'Hash'
 
     # Prepare list of symbols and hash of renames for export
   symbol_loop:
-    unless iterator goto symbol_loop_end
-    symbol = shift iterator
+    unless gl_ns_iterator goto symbol_loop_end
+    symbol = shift gl_ns_iterator
 
     # For now, only handle symbols starting with 'gl'
-    tag = substr symbol, 0, 2
-    unless tag == 'gl' goto symbol_loop
+    prefix = substr symbol, 0, 2
+    unless prefix == 'gl' goto symbol_loop
 
     # Special-case callbacks
-    tag = substr symbol, 0, 6
-    if tag == 'glutcb' goto rename_callbacks
+    prefix = substr symbol, 0, 6
+    if prefix == 'glutcb' goto rename_callbacks
 
     # Add all other matching symbols to export list
     push export_list, symbol


More information about the parrot-commits mailing list