[Ecls-list] [PATCH] write large strings as arrays of character codes
Ariel Badichi
vermilionrush at gmail.com
Mon Dec 28 03:20:08 UTC 2009
More compiler-friendly. For example, Visual C++ chokes on string
literals larger than 64K characters, but can take a big array of
chars.
---
This lets me to compile cl-opengl (after some minor tweaking) with
ECL/Visual C++.
src/cmp/cmpmain.lsp | 4 +-
src/cmp/cmpwt.lsp | 63 +++++++++++++++++++++++++++++++++-----------------
2 files changed, 43 insertions(+), 24 deletions(-)
diff --git a/src/cmp/cmpmain.lsp b/src/cmp/cmpmain.lsp
index c7b6f3a..b4f09db 100755
--- a/src/cmp/cmpmain.lsp
+++ b/src/cmp/cmpmain.lsp
@@ -404,7 +404,7 @@ filesystem or in the database of ASDF modules."
(with-standard-io-syntax
(setq epilogue-code
(with-output-to-string (stream)
- (princ "{ const char *lisp_code = " stream)
+ (princ "{ const char lisp_code[] = " stream)
(wt-filtered-data (write-to-string epilogue-code) stream)
(princ ";
cl_object output;
@@ -420,7 +420,7 @@ output = si_safe_eval(2, ecl_read_from_cstring(lisp_code), Cnil);
(with-standard-io-syntax
(setq prologue-code
(with-output-to-string (stream)
- (princ "{ const char *lisp_code = " stream)
+ (princ "{ const char lisp_code[] = " stream)
(wt-filtered-data (write-to-string prologue-code) stream)
(princ ";
cl_object output;
diff --git a/src/cmp/cmpwt.lsp b/src/cmp/cmpwt.lsp
index 234b8d0..ef619d8 100644
--- a/src/cmp/cmpwt.lsp
+++ b/src/cmp/cmpwt.lsp
@@ -90,28 +90,47 @@
(let ((N (length string))
(wt-data-column 80))
(incf *wt-string-size* (1+ N)) ; 1+ accounts for a blank space
- (format stream (if one-liner "\"" "~%\""))
- (dotimes (i N)
- (decf wt-data-column)
- (when (< wt-data-column 0)
- (format stream "\"~% \"")
- (setq wt-data-column 79))
- (let ((x (aref string i)))
- (cond
- ((or (< (char-code x) 32)
- (> (char-code x) 127))
- (case x
- ; We avoid a trailing backslash+newline because some preprocessors
- ; remove them.
- (#\Newline (princ "\\n" stream))
- (#\Tab (princ "\\t" stream))
- (t (format stream "\\~3,'0o" (char-code x)))))
- ((char= x #\\)
- (princ "\\\\" stream))
- ((char= x #\")
- (princ "\\\"" stream))
- (t (princ x stream)))))
- (princ (if one-liner "\"" " \"") stream)
+ (cond ((< N 510)
+ ; C89 recommends a minimum limit of 509 characters per
+ ; string literal.
+ (format stream (if one-liner "\"" "~%\""))
+ (dotimes (i N)
+ (decf wt-data-column)
+ (when (< wt-data-column 0)
+ (format stream "\"~% \"")
+ (setq wt-data-column 79))
+ (let ((x (aref string i)))
+ (cond
+ ((or (< (char-code x) 32)
+ (> (char-code x) 127))
+ (case x
+ ; We avoid a trailing backslash+newline because
+ ; some preprocessors remove them.
+ (#\Newline (princ "\\n" stream))
+ (#\Tab (princ "\\t" stream))
+ (t (format stream "\\~3,'0o" (char-code x)))))
+ ((char= x #\\)
+ (princ "\\\\" stream))
+ ((char= x #\")
+ (princ "\\\"" stream))
+ (t (princ x stream)))))
+ (princ (if one-liner "\"" " \"") stream))
+ (t
+ ; Write the string as an array of character codes and
+ ; hope that the compiler can take it.
+ (format stream "{~% ")
+ (flet ((write-octet (x)
+ (decf wt-data-column 6)
+ (when (< wt-data-column 0)
+ (format stream "~% ")
+ (setq wt-data-column (- 80 6)))
+ (format stream "0x~2,'0X, " x)))
+ (dotimes (i N)
+ (write-octet (char-code (aref string i))))
+ (unless one-liner
+ (write-octet #x20))
+ (write-octet #x00))
+ (format stream "~%}")))
string))
;;; ======================================================================
--
1.6.0.2.1172.ga5ed0
More information about the ecl-devel
mailing list