make_vallist.scm 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 (awb@cs.cmu.edu) ;;;
  34. ;;; Date: January 2001 ;;;
  35. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  36. ;;; ;;;
  37. ;;; Convert a lisp list/tree into a static cst_val const ;;;
  38. ;;; ;;;
  39. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  40. (defvar cells_count 0)
  41. (defvar cells_cache nil)
  42. (define (listtocstval name l ofile)
  43. "(listtocstval name l ofile)
  44. Converts a lisp list to static C code into ofile."
  45. (let ((ofdc (fopen ofile "w")))
  46. (format ofdc "/*******************************************************/\n")
  47. (format ofdc "/** Autogenerated list structure for %s */\n" name)
  48. (format ofdc "/*******************************************************/\n")
  49. (format ofdc "\n")
  50. (format ofdc "#include \"cst_string.h\"\n")
  51. (format ofdc "#include \"cst_val.h\"\n")
  52. (set! cells_count 0)
  53. (set! cells_cache nil)
  54. (format ofdc "\n\n")
  55. (cellstovals name l ofdc)
  56. (format ofdc "cst_val *%s = &%s_%04d;\n" name name cells_count)
  57. (format ofdc "\n\n")
  58. (fclose ofdc)
  59. ))
  60. (define (cellsnewname name)
  61. (set! cells_count (+ 1 cells_count))
  62. (format nil "%s_%04d" name cells_count))
  63. (define (cellstovals name l ofdc)
  64. (let (nn)
  65. (cond
  66. ((null l) "0")
  67. ((set! nn (assoc l cells_cache))
  68. (car (cdr nn)))
  69. ((consp l)
  70. (let ((c_ar (cellstovals name (car l) ofdc))
  71. (c_dr (cellstovals name (cdr l) ofdc))
  72. (n_name (cellsnewname name)))
  73. (if (not (string-equal "0" c_ar))
  74. (set! c_ar (string-append "(void *)&" c_ar)))
  75. (if (not (string-equal "0" c_dr))
  76. (set! c_dr (string-append "(void *)&" c_dr)))
  77. (format ofdc "DEF_STATIC_CONST_VAL_CONS(%s,%s,%s);\n"
  78. n_name
  79. c_ar
  80. c_dr)
  81. (set! cells_cache (cons (list l n_name)))
  82. n_name))
  83. ((symbol? l)
  84. (let ((n_name (cellsnewname name)))
  85. (format ofdc "DEF_STATIC_CONST_VAL_STRING(%s,\"%s\");\n"
  86. n_name l)
  87. (set! cells_cache (cons (list l n_name)))
  88. n_name))
  89. ((equal? 'string (typeof l))
  90. (let ((n_name (cellsnewname name)))
  91. (format ofdc "DEF_STATIC_CONST_VAL_STRING(%s,%l);\n"
  92. n_name l)
  93. (set! cells_cache (cons (list l n_name)))
  94. n_name))
  95. ((number? l)
  96. (let ((n_name (cellsnewname name)))
  97. (format ofdc "DEF_STATIC_CONST_VAL_FLOAT(%s,%s);\n"
  98. n_name l)
  99. (set! cells_cache (cons (list l n_name)))
  100. n_name))
  101. (t
  102. (format stderr "cannot convert to vals\n")
  103. (error l)))))
  104. (provide 'make_vallist)