| 1 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 2 |
;;; ;;; |
| 3 |
;;; Language Technologies Institute ;;; |
| 4 |
;;; Carnegie Mellon University ;;; |
| 5 |
;;; Copyright (c) 2001 ;;; |
| 6 |
;;; All Rights Reserved. ;;; |
| 7 |
;;; ;;; |
| 8 |
;;; Permission is hereby granted, free of charge, to use and distribute ;;; |
| 9 |
;;; this software and its documentation without restriction, including ;;; |
| 10 |
;;; without limitation the rights to use, copy, modify, merge, publish, ;;; |
| 11 |
;;; distribute, sublicense, and/or sell copies of this work, and to ;;; |
| 12 |
;;; permit persons to whom this work is furnished to do so, subject to ;;; |
| 13 |
;;; the following conditions: ;;; |
| 14 |
;;; 1. The code must retain the above copyright notice, this list of ;;; |
| 15 |
;;; conditions and the following disclaimer. ;;; |
| 16 |
;;; 2. Any modifications must be clearly marked as such. ;;; |
| 17 |
;;; 3. Original authors' names are not deleted. ;;; |
| 18 |
;;; 4. The authors' names are not used to endorse or promote products ;;; |
| 19 |
;;; derived from this software without specific prior written ;;; |
| 20 |
;;; permission. ;;; |
| 21 |
;;; ;;; |
| 22 |
;;; CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK ;;; |
| 23 |
;;; DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ;;; |
| 24 |
;;; ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT ;;; |
| 25 |
;;; SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE ;;; |
| 26 |
;;; FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ;;; |
| 27 |
;;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ;;; |
| 28 |
;;; AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ;;; |
| 29 |
;;; ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF ;;; |
| 30 |
;;; THIS SOFTWARE. ;;; |
| 31 |
;;; ;;; |
| 32 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 33 |
;;; Author: Alan W Black ([email protected]) ;;; |
| 34 |
;;; Date: January 2001 ;;; |
| 35 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 36 |
;;; ;;; |
| 37 |
;;; Convert a lisp list/tree into a static cst_val const ;;; |
| 38 |
;;; ;;; |
| 39 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 40 |
|
| 41 |
(defvar cells_count 0) |
| 42 |
(defvar cells_cache nil) |
| 43 |
|
| 44 |
(define (listtocstval name l ofile) |
| 45 |
"(listtocstval name l ofile) |
| 46 |
Converts a lisp list to static C code into ofile." |
| 47 |
(let ((ofdc (fopen ofile "w"))) |
| 48 |
(format ofdc "/*******************************************************/\n") |
| 49 |
(format ofdc "/** Autogenerated list structure for %s */\n" name) |
| 50 |
(format ofdc "/*******************************************************/\n") |
| 51 |
(format ofdc "\n") |
| 52 |
(format ofdc "#include \"cst_string.h\"\n") |
| 53 |
(format ofdc "#include \"cst_val.h\"\n") |
| 54 |
|
| 55 |
(set! cells_count 0) |
| 56 |
(set! cells_cache nil) |
| 57 |
|
| 58 |
(format ofdc "\n\n") |
| 59 |
|
| 60 |
(cellstovals name l ofdc) |
| 61 |
(format ofdc "cst_val *%s = &%s_%04d;\n" name name cells_count) |
| 62 |
|
| 63 |
(format ofdc "\n\n") |
| 64 |
|
| 65 |
(fclose ofdc) |
| 66 |
)) |
| 67 |
|
| 68 |
(define (cellsnewname name) |
| 69 |
(set! cells_count (+ 1 cells_count)) |
| 70 |
(format nil "%s_%04d" name cells_count)) |
| 71 |
|
| 72 |
(define (cellstovals name l ofdc) |
| 73 |
(let (nn) |
| 74 |
(cond |
| 75 |
((null l) "0") |
| 76 |
((set! nn (assoc l cells_cache)) |
| 77 |
(car (cdr nn))) |
| 78 |
((consp l) |
| 79 |
(let ((c_ar (cellstovals name (car l) ofdc)) |
| 80 |
(c_dr (cellstovals name (cdr l) ofdc)) |
| 81 |
(n_name (cellsnewname name))) |
| 82 |
(if (not (string-equal "0" c_ar)) |
| 83 |
(set! c_ar (string-append "(void *)&" c_ar))) |
| 84 |
(if (not (string-equal "0" c_dr)) |
| 85 |
(set! c_dr (string-append "(void *)&" c_dr))) |
| 86 |
(format ofdc "DEF_STATIC_CONST_VAL_CONS(%s,%s,%s);\n" |
| 87 |
n_name |
| 88 |
c_ar |
| 89 |
c_dr) |
| 90 |
(set! cells_cache (cons (list l n_name))) |
| 91 |
n_name)) |
| 92 |
((symbol? l) |
| 93 |
(let ((n_name (cellsnewname name))) |
| 94 |
(format ofdc "DEF_STATIC_CONST_VAL_STRING(%s,\"%s\");\n" |
| 95 |
n_name l) |
| 96 |
(set! cells_cache (cons (list l n_name))) |
| 97 |
n_name)) |
| 98 |
((equal? 'string (typeof l)) |
| 99 |
(let ((n_name (cellsnewname name))) |
| 100 |
(format ofdc "DEF_STATIC_CONST_VAL_STRING(%s,%l);\n" |
| 101 |
n_name l) |
| 102 |
(set! cells_cache (cons (list l n_name))) |
| 103 |
n_name)) |
| 104 |
((number? l) |
| 105 |
(let ((n_name (cellsnewname name))) |
| 106 |
(format ofdc "DEF_STATIC_CONST_VAL_FLOAT(%s,%s);\n" |
| 107 |
n_name l) |
| 108 |
(set! cells_cache (cons (list l n_name))) |
| 109 |
n_name)) |
| 110 |
(t |
| 111 |
(format stderr "cannot convert to vals\n") |
| 112 |
(error l))))) |
| 113 |
|
| 114 |
(provide 'make_vallist) |