4 (use-modules (figl parse)
8 ((srfi srfi-1) #:select (append-map))
15 (print-disable 'escape-newlines)
17 (define (list-intersperse src-l elem)
18 (if (null? src-l) src-l
19 (let loop ((l (cdr src-l)) (dest (cons (car src-l) '())))
20 (if (null? l) (reverse dest)
21 (loop (cdr l) (cons (car l) (cons elem dest)))))))
23 (define (module-name->scm-name mod-name)
24 (string-join (list (abs-top-srcdir)
26 (symbol->string mod-name)
30 (define (module-name->texi-name mod-name)
32 (in-vicinity (abs-top-srcdir) "doc")
33 (string-append "low-level-" (symbol->string mod-name) "-enums.texi")))
35 (define (strip-bit name)
36 (let ((str (symbol->string name)))
38 ((string-suffix? "-bit" str)
39 (string->symbol (substring str 0 (- (string-length str) 4))))
40 ((string-suffix? "-bits" str)
41 (string->symbol (substring str 0 (- (string-length str) 5))))
44 (define (bitfield? enum)
45 (and-map (match-lambda ((name . value) (strip-bit name)))
46 (gl-enumeration-values enum)))
48 (define (write-scm mod-name enums port)
50 ;;; figl -*- mode: scheme; coding: utf-8 -*-
51 ;;; Copyright (C) 2013 Andy Wingo <wingo@pobox.com>
53 ;;; Figl is free software: you can redistribute it and/or modify it
54 ;;; under the terms of the GNU Lesser General Public License as
55 ;;; published by the Free Software Foundation, either version 3 of the
56 ;;; License, or (at your option) any later version.
58 ;;; Figl is distributed in the hope that it will be useful, but WITHOUT
59 ;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
60 ;;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
61 ;;; Public License for more details.
63 ;;; You should have received a copy of the GNU Lesser General Public
64 ;;; License along with this program. If not, see
65 ;;; <http://www.gnu.org/licenses/>.
67 ;;; Derived from the API specifications at www.opengl.org/registry/api/.
69 ;;; Automatically generated; you probably don't want to edit this. To
70 ;;; update, run \"make update-enums\" in the top-level build tree.
75 `(define-module (figl ,mod-name enums)
76 #:use-module (figl runtime)
77 #:export ,(map gl-enumeration-category enums))
84 `(define-bitfield ,(gl-enumeration-category enum)
86 ((name . value) (list (strip-bit name) value)))
87 (gl-enumeration-values enum)))
88 `(define-enumeration ,(gl-enumeration-category enum)
90 ((name . value) (list name value)))
91 (gl-enumeration-values enum))))
96 (define (write-texi mod-name enums port)
100 (para "The functions from this section may be had by loading "
102 (example "(use-modules (figl " ,(object->string mod-name) " enums)")
106 `(defmac (% (name ,(symbol->string (gl-enumeration-category enum)))
107 (arguments "bit..."))
109 "Bitfield constructor. The symbolic " (var "bit")
110 " arguments are replaced with their corresponding numeric "
111 "values and combined with " (code "logior") " at "
112 "compile-time. The symbolic arguments known to this "
113 "bitfield constructor are:")
117 `(code ,(symbol->string (strip-bit name))))
118 (map car (gl-enumeration-values enum)))
121 `(defmac (% (name ,(symbol->string (gl-enumeration-category enum)))
124 "Enumerated value. The symbolic " (var "enum") "argument "
125 "is replaced with its corresponding numeric value at "
126 "compile-time. The symbolic arguments known to this "
127 "enumerated value form are:")
130 (map (lambda (name) `(code ,(symbol->string name)))
131 (map car (gl-enumeration-values enum)))
137 (define (write-enumerations mod-name enums)
138 (call-with-output-file (module-name->scm-name mod-name)
140 (write-scm mod-name enums port)))
141 (call-with-output-file (module-name->texi-name mod-name)
143 (write-texi mod-name enums port))))
146 (write-enumerations 'gl (parse-gl-enumerations "enum.spec"))
147 (write-enumerations 'glx (parse-gl-enumerations "glxenum.spec")))
150 (apply main (command-line)))