diff options
| author | Richard M. Stallman | 1994-12-24 05:58:05 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-12-24 05:58:05 +0000 |
| commit | d82e848c3416fe0b8cc5c839104ff0188f7e5266 (patch) | |
| tree | d28cae6a21bd644c868f56b1c994de59078129aa /lisp | |
| parent | 5fe4899af75bdd5ad057d35f0b4f2f322b1dc2d7 (diff) | |
| download | emacs-d82e848c3416fe0b8cc5c839104ff0188f7e5266.tar.gz emacs-d82e848c3416fe0b8cc5c839104ff0188f7e5266.zip | |
(byte-compile-dest-file): New variable.
(byte-compile-file): Bind that var, early on.
(byte-compile-dynamic): New variable.
(byte-compile-dynamic-docstrings): New variable.
(byte-compile-close-variables): Bind byte-compile-dynamic,
byte-compile-dynamic-docstrings, and byte-compiler-compatibility.
(byte-compile-file): Call normal-mode, not set-auto-mode.
(byte-compile-output-docform): New arguments PREFACE, NAME, SPECINDEX,
QUOTED. Callers changed. Output doc strings as references to the .elc
file itself, using #@ and #$ constructs.
(byte-compile-output-as-comment): New function.
(byte-compile-insert-header): Don't save-excursion.
Insert at point, and move point. Insert extra newline at end.
(byte-compile-from-buffer): Insert the header before compilation.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/emacs-lisp/bytecomp.el | 422 |
1 files changed, 260 insertions, 162 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 4966ca6e98b..e2b315f3868 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el | |||
| @@ -246,6 +246,29 @@ t means do all optimizations. | |||
| 246 | "*If non-nil, the optimizer may delete forms that may signal an error. | 246 | "*If non-nil, the optimizer may delete forms that may signal an error. |
| 247 | This includes variable references and calls to functions such as `car'.") | 247 | This includes variable references and calls to functions such as `car'.") |
| 248 | 248 | ||
| 249 | (defvar byte-compile-dynamic nil | ||
| 250 | "*If non-nil, compile function bodies so they load lazily. | ||
| 251 | They are hidden comments in the compiled file, and brought into core when the | ||
| 252 | function is called. | ||
| 253 | |||
| 254 | To enable this option, make it a file-local variable | ||
| 255 | in the source file you want it to apply to. | ||
| 256 | For example, add -*-byte-compile-dynamic: t;-*- on the first line. | ||
| 257 | |||
| 258 | When this option is true, if you load the compiled file and then move it, | ||
| 259 | the functions you loaded will not be able to run.") | ||
| 260 | |||
| 261 | (defvar byte-compile-dynamic-docstrings t | ||
| 262 | "*If non-nil, compile doc strings for lazy access. | ||
| 263 | We bury the doc strings of functions and variables | ||
| 264 | inside comments in the file, and bring them into core only when they | ||
| 265 | are actually needed. | ||
| 266 | |||
| 267 | When this option is true, if you load the compiled file and then move it, | ||
| 268 | you won't be able to find the documentation of anything in that file. | ||
| 269 | |||
| 270 | This option is enabled by default because it reduces Emacs memory usage.") | ||
| 271 | |||
| 249 | (defvar byte-optimize-log nil | 272 | (defvar byte-optimize-log nil |
| 250 | "*If true, the byte-compiler will log its optimizations into *Compile-Log*. | 273 | "*If true, the byte-compiler will log its optimizations into *Compile-Log*. |
| 251 | If this is 'source, then only source-level optimizations will be logged. | 274 | If this is 'source, then only source-level optimizations will be logged. |
| @@ -677,8 +700,9 @@ otherwise pop it") | |||
| 677 | 700 | ||
| 678 | ;;; byte compiler messages | 701 | ;;; byte compiler messages |
| 679 | 702 | ||
| 680 | (defconst byte-compile-current-form nil) | 703 | (defvar byte-compile-current-form nil) |
| 681 | (defconst byte-compile-current-file nil) | 704 | (defvar byte-compile-current-file nil) |
| 705 | (defvar byte-compile-dest-file nil) | ||
| 682 | 706 | ||
| 683 | (defmacro byte-compile-log (format-string &rest args) | 707 | (defmacro byte-compile-log (format-string &rest args) |
| 684 | (list 'and | 708 | (list 'and |
| @@ -899,7 +923,7 @@ otherwise pop it") | |||
| 899 | (sig (and def (byte-compile-arglist-signature | 923 | (sig (and def (byte-compile-arglist-signature |
| 900 | (if (eq 'lambda (car-safe def)) | 924 | (if (eq 'lambda (car-safe def)) |
| 901 | (nth 1 def) | 925 | (nth 1 def) |
| 902 | (if (compiled-function-p def) | 926 | (if (byte-code-function-p def) |
| 903 | (aref def 0) | 927 | (aref def 0) |
| 904 | '(&rest def)))))) | 928 | '(&rest def)))))) |
| 905 | (ncall (length (cdr form)))) | 929 | (ncall (length (cdr form)))) |
| @@ -934,7 +958,7 @@ otherwise pop it") | |||
| 934 | (let ((sig1 (byte-compile-arglist-signature | 958 | (let ((sig1 (byte-compile-arglist-signature |
| 935 | (if (eq 'lambda (car-safe old)) | 959 | (if (eq 'lambda (car-safe old)) |
| 936 | (nth 1 old) | 960 | (nth 1 old) |
| 937 | (if (compiled-function-p old) | 961 | (if (byte-code-function-p old) |
| 938 | (aref old 0) | 962 | (aref old 0) |
| 939 | '(&rest def))))) | 963 | '(&rest def))))) |
| 940 | (sig2 (byte-compile-arglist-signature (nth 2 form)))) | 964 | (sig2 (byte-compile-arglist-signature (nth 2 form)))) |
| @@ -1019,6 +1043,10 @@ otherwise pop it") | |||
| 1019 | ;; | 1043 | ;; |
| 1020 | (byte-compile-verbose byte-compile-verbose) | 1044 | (byte-compile-verbose byte-compile-verbose) |
| 1021 | (byte-optimize byte-optimize) | 1045 | (byte-optimize byte-optimize) |
| 1046 | (byte-compile-compatibility byte-compile-compatibility) | ||
| 1047 | (byte-compile-dynamic byte-compile-dynamic) | ||
| 1048 | (byte-compile-dynamic-docstrings | ||
| 1049 | byte-compile-dynamic-docstrings) | ||
| 1022 | ;; (byte-compile-generate-emacs19-bytecodes | 1050 | ;; (byte-compile-generate-emacs19-bytecodes |
| 1023 | ;; byte-compile-generate-emacs19-bytecodes) | 1051 | ;; byte-compile-generate-emacs19-bytecodes) |
| 1024 | (byte-compile-warnings (if (eq byte-compile-warnings t) | 1052 | (byte-compile-warnings (if (eq byte-compile-warnings t) |
| @@ -1150,7 +1178,10 @@ With prefix arg (noninteractively: 2nd arg), load the file after compiling." | |||
| 1150 | (if byte-compile-verbose | 1178 | (if byte-compile-verbose |
| 1151 | (message "Compiling %s..." filename)) | 1179 | (message "Compiling %s..." filename)) |
| 1152 | (let ((byte-compile-current-file filename) | 1180 | (let ((byte-compile-current-file filename) |
| 1153 | target-file input-buffer output-buffer) | 1181 | target-file input-buffer output-buffer |
| 1182 | byte-compile-dest-file) | ||
| 1183 | (setq target-file (byte-compile-dest-file filename)) | ||
| 1184 | (setq byte-compile-dest-file target-file) | ||
| 1154 | (save-excursion | 1185 | (save-excursion |
| 1155 | (setq input-buffer (get-buffer-create " *Compiler Input*")) | 1186 | (setq input-buffer (get-buffer-create " *Compiler Input*")) |
| 1156 | (set-buffer input-buffer) | 1187 | (set-buffer input-buffer) |
| @@ -1158,8 +1189,9 @@ With prefix arg (noninteractively: 2nd arg), load the file after compiling." | |||
| 1158 | (insert-file-contents filename) | 1189 | (insert-file-contents filename) |
| 1159 | ;; Run hooks including the uncompression hook. | 1190 | ;; Run hooks including the uncompression hook. |
| 1160 | ;; If they change the file name, then change it for the output also. | 1191 | ;; If they change the file name, then change it for the output also. |
| 1161 | (let ((buffer-file-name filename)) | 1192 | (let ((buffer-file-name filename) |
| 1162 | (set-auto-mode) | 1193 | (enable-local-eval nil)) |
| 1194 | (normal-mode) | ||
| 1163 | (setq filename buffer-file-name))) | 1195 | (setq filename buffer-file-name))) |
| 1164 | (setq byte-compiler-error-flag nil) | 1196 | (setq byte-compiler-error-flag nil) |
| 1165 | ;; It is important that input-buffer not be current at this call, | 1197 | ;; It is important that input-buffer not be current at this call, |
| @@ -1174,11 +1206,6 @@ With prefix arg (noninteractively: 2nd arg), load the file after compiling." | |||
| 1174 | (goto-char (point-max)) | 1206 | (goto-char (point-max)) |
| 1175 | (insert "\n") ; aaah, unix. | 1207 | (insert "\n") ; aaah, unix. |
| 1176 | (let ((vms-stmlf-recfm t)) | 1208 | (let ((vms-stmlf-recfm t)) |
| 1177 | (setq target-file (byte-compile-dest-file filename)) | ||
| 1178 | ;;; (or byte-compile-overwrite-file | ||
| 1179 | ;;; (condition-case () | ||
| 1180 | ;;; (delete-file target-file) | ||
| 1181 | ;;; (error nil))) | ||
| 1182 | (if (file-writable-p target-file) | 1209 | (if (file-writable-p target-file) |
| 1183 | (let ((kanji-flag nil)) ; for nemacs, from Nakagawa Takayuki | 1210 | (let ((kanji-flag nil)) ; for nemacs, from Nakagawa Takayuki |
| 1184 | (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt)) | 1211 | (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt)) |
| @@ -1191,12 +1218,7 @@ With prefix arg (noninteractively: 2nd arg), load the file after compiling." | |||
| 1191 | (if (file-exists-p target-file) | 1218 | (if (file-exists-p target-file) |
| 1192 | "cannot overwrite file" | 1219 | "cannot overwrite file" |
| 1193 | "directory not writable or nonexistent") | 1220 | "directory not writable or nonexistent") |
| 1194 | target-file))) | 1221 | target-file)))) |
| 1195 | ;;; (or byte-compile-overwrite-file | ||
| 1196 | ;;; (condition-case () | ||
| 1197 | ;;; (set-file-modes target-file (file-modes filename)) | ||
| 1198 | ;;; (error nil))) | ||
| 1199 | ) | ||
| 1200 | (kill-buffer (current-buffer))) | 1222 | (kill-buffer (current-buffer))) |
| 1201 | (if (and byte-compile-generate-call-tree | 1223 | (if (and byte-compile-generate-call-tree |
| 1202 | (or (eq t byte-compile-generate-call-tree) | 1224 | (or (eq t byte-compile-generate-call-tree) |
| @@ -1252,115 +1274,104 @@ With argument, insert value in current buffer after the form." | |||
| 1252 | 1274 | ||
| 1253 | (defun byte-compile-from-buffer (inbuffer &optional filename) | 1275 | (defun byte-compile-from-buffer (inbuffer &optional filename) |
| 1254 | ;; Filename is used for the loading-into-Emacs-18 error message. | 1276 | ;; Filename is used for the loading-into-Emacs-18 error message. |
| 1255 | (let (outbuffer) | 1277 | (let (outbuffer |
| 1256 | (let (;; Prevent truncation of flonums and lists as we read and print them | 1278 | ;; Prevent truncation of flonums and lists as we read and print them |
| 1257 | (float-output-format nil) | 1279 | (float-output-format nil) |
| 1258 | (case-fold-search nil) | 1280 | (case-fold-search nil) |
| 1259 | (print-length nil) | 1281 | (print-length nil) |
| 1260 | ;; Simulate entry to byte-compile-top-level | 1282 | ;; Simulate entry to byte-compile-top-level |
| 1261 | (byte-compile-constants nil) | 1283 | (byte-compile-constants nil) |
| 1262 | (byte-compile-variables nil) | 1284 | (byte-compile-variables nil) |
| 1263 | (byte-compile-tag-number 0) | 1285 | (byte-compile-tag-number 0) |
| 1264 | (byte-compile-depth 0) | 1286 | (byte-compile-depth 0) |
| 1265 | (byte-compile-maxdepth 0) | 1287 | (byte-compile-maxdepth 0) |
| 1266 | (byte-compile-output nil) | 1288 | (byte-compile-output nil) |
| 1267 | ;; #### This is bound in b-c-close-variables. | 1289 | ;; #### This is bound in b-c-close-variables. |
| 1268 | ;; (byte-compile-warnings (if (eq byte-compile-warnings t) | 1290 | ;; (byte-compile-warnings (if (eq byte-compile-warnings t) |
| 1269 | ;; byte-compile-warning-types | 1291 | ;; byte-compile-warning-types |
| 1270 | ;; byte-compile-warnings)) | 1292 | ;; byte-compile-warnings)) |
| 1271 | ) | 1293 | ) |
| 1272 | (byte-compile-close-variables | 1294 | (byte-compile-close-variables |
| 1273 | (save-excursion | 1295 | (save-excursion |
| 1274 | (setq outbuffer | 1296 | (setq outbuffer |
| 1275 | (set-buffer (get-buffer-create " *Compiler Output*"))) | 1297 | (set-buffer (get-buffer-create " *Compiler Output*"))) |
| 1276 | (erase-buffer) | 1298 | (erase-buffer) |
| 1277 | ;; (emacs-lisp-mode) | 1299 | ;; (emacs-lisp-mode) |
| 1278 | (setq case-fold-search nil) | 1300 | (setq case-fold-search nil) |
| 1279 | 1301 | (and filename (byte-compile-insert-header filename)) | |
| 1280 | ;; This is a kludge. Some operating systems (OS/2, DOS) need to | 1302 | |
| 1281 | ;; write files containing binary information specially. | 1303 | ;; This is a kludge. Some operating systems (OS/2, DOS) need to |
| 1282 | ;; Under most circumstances, such files will be in binary | 1304 | ;; write files containing binary information specially. |
| 1283 | ;; overwrite mode, so those OS's use that flag to guess how | 1305 | ;; Under most circumstances, such files will be in binary |
| 1284 | ;; they should write their data. Advise them that .elc files | 1306 | ;; overwrite mode, so those OS's use that flag to guess how |
| 1285 | ;; need to be written carefully. | 1307 | ;; they should write their data. Advise them that .elc files |
| 1286 | (setq overwrite-mode 'overwrite-mode-binary)) | 1308 | ;; need to be written carefully. |
| 1287 | (displaying-byte-compile-warnings | 1309 | (setq overwrite-mode 'overwrite-mode-binary)) |
| 1288 | (save-excursion | 1310 | (displaying-byte-compile-warnings |
| 1289 | (set-buffer inbuffer) | 1311 | (save-excursion |
| 1290 | (goto-char 1) | 1312 | (set-buffer inbuffer) |
| 1291 | (while (progn | 1313 | (goto-char 1) |
| 1292 | (while (progn (skip-chars-forward " \t\n\^l") | 1314 | |
| 1293 | (looking-at ";")) | 1315 | ;; Compile the forms from the input buffer. |
| 1294 | (forward-line 1)) | 1316 | (while (progn |
| 1295 | (not (eobp))) | 1317 | (while (progn (skip-chars-forward " \t\n\^l") |
| 1296 | (byte-compile-file-form (read inbuffer))) | 1318 | (looking-at ";")) |
| 1297 | ;; Compile pending forms at end of file. | 1319 | (forward-line 1)) |
| 1298 | (byte-compile-flush-pending) | 1320 | (not (eobp))) |
| 1299 | (and filename (byte-compile-insert-header filename)) | 1321 | (byte-compile-file-form (read inbuffer))) |
| 1300 | (byte-compile-warn-about-unresolved-functions) | 1322 | |
| 1301 | ;; always do this? When calling multiple files, it | 1323 | ;; Compile pending forms at end of file. |
| 1302 | ;; would be useful to delay this warning until all have | 1324 | (byte-compile-flush-pending) |
| 1303 | ;; been compiled. | 1325 | (byte-compile-warn-about-unresolved-functions) |
| 1304 | (setq byte-compile-unresolved-functions nil))) | 1326 | ;; SHould we always do this? When calling multiple files, it |
| 1305 | (save-excursion | 1327 | ;; would be useful to delay this warning until all have |
| 1306 | (set-buffer outbuffer) | 1328 | ;; been compiled. |
| 1307 | (goto-char (point-min))))) | 1329 | (setq byte-compile-unresolved-functions nil)))) |
| 1308 | outbuffer)) | 1330 | outbuffer)) |
| 1309 | ;;; (if (not eval) | ||
| 1310 | ;;; outbuffer | ||
| 1311 | ;;; (while (condition-case nil | ||
| 1312 | ;;; (progn (setq form (read outbuffer)) | ||
| 1313 | ;;; t) | ||
| 1314 | ;;; (end-of-file nil)) | ||
| 1315 | ;;; (eval form)) | ||
| 1316 | ;;; (kill-buffer outbuffer) | ||
| 1317 | ;;; nil)))) | ||
| 1318 | 1331 | ||
| 1319 | (defun byte-compile-insert-header (filename) | 1332 | (defun byte-compile-insert-header (filename) |
| 1320 | (save-excursion | 1333 | (set-buffer outbuffer) |
| 1321 | (set-buffer outbuffer) | 1334 | (goto-char 1) |
| 1322 | (goto-char 1) | 1335 | ;; |
| 1323 | ;; | 1336 | ;; The magic number of .elc files is ";ELC", or 0x3B454C43. After that is |
| 1324 | ;; The magic number of .elc files is ";ELC", or 0x3B454C43. After that is | 1337 | ;; the file-format version number (18 or 19) as a byte, followed by some |
| 1325 | ;; the file-format version number (18 or 19) as a byte, followed by some | 1338 | ;; nulls. The primary motivation for doing this is to get some binary |
| 1326 | ;; nulls. The primary motivation for doing this is to get some binary | 1339 | ;; characters up in the first line of the file so that `diff' will simply |
| 1327 | ;; characters up in the first line of the file so that `diff' will simply | 1340 | ;; say "Binary files differ" instead of actually doing a diff of two .elc |
| 1328 | ;; say "Binary files differ" instead of actually doing a diff of two .elc | 1341 | ;; files. An extra benefit is that you can add this to /etc/magic: |
| 1329 | ;; files. An extra benefit is that you can add this to /etc/magic: | 1342 | ;; |
| 1330 | ;; | 1343 | ;; 0 string ;ELC GNU Emacs Lisp compiled file, |
| 1331 | ;; 0 string ;ELC GNU Emacs Lisp compiled file, | 1344 | ;; >4 byte x version %d |
| 1332 | ;; >4 byte x version %d | 1345 | ;; |
| 1333 | ;; | 1346 | (insert |
| 1334 | (insert | 1347 | ";ELC" |
| 1335 | ";ELC" | 1348 | (if (byte-compile-version-cond byte-compile-compatibility) 18 19) |
| 1336 | (if (byte-compile-version-cond byte-compile-compatibility) 18 19) | 1349 | "\000\000\000\n" |
| 1337 | "\000\000\000\n" | 1350 | ) |
| 1338 | ) | 1351 | (insert ";;; compiled by " user-mail-address " on " |
| 1339 | (insert ";;; compiled by " user-mail-address " on " | 1352 | (current-time-string) "\n;;; from file " filename "\n") |
| 1340 | (current-time-string) "\n;;; from file " filename "\n") | 1353 | (insert ";;; emacs version " emacs-version ".\n") |
| 1341 | (insert ";;; emacs version " emacs-version ".\n") | 1354 | (insert ";;; bytecomp version " byte-compile-version "\n;;; " |
| 1342 | (insert ";;; bytecomp version " byte-compile-version "\n;;; " | 1355 | (cond |
| 1343 | (cond | 1356 | ((eq byte-optimize 'source) "source-level optimization only") |
| 1344 | ((eq byte-optimize 'source) "source-level optimization only") | 1357 | ((eq byte-optimize 'byte) "byte-level optimization only") |
| 1345 | ((eq byte-optimize 'byte) "byte-level optimization only") | 1358 | (byte-optimize "optimization is on") |
| 1346 | (byte-optimize "optimization is on") | 1359 | (t "optimization is off")) |
| 1347 | (t "optimization is off")) | 1360 | (if (byte-compile-version-cond byte-compile-compatibility) |
| 1348 | (if (byte-compile-version-cond byte-compile-compatibility) | 1361 | "; compiled with Emacs 18 compatibility.\n" |
| 1349 | "; compiled with Emacs 18 compatibility.\n" | 1362 | ".\n")) |
| 1350 | ".\n")) | 1363 | (if (not (byte-compile-version-cond byte-compile-compatibility)) |
| 1351 | (if (not (byte-compile-version-cond byte-compile-compatibility)) | 1364 | (insert ";;; this file uses opcodes which do not exist in Emacs 18.\n" |
| 1352 | (insert ";;; this file uses opcodes which do not exist in Emacs 18.\n" | 1365 | ;; Have to check if emacs-version is bound so that this works |
| 1353 | ;; Have to check if emacs-version is bound so that this works | 1366 | ;; in files loaded early in loadup.el. |
| 1354 | ;; in files loaded early in loadup.el. | 1367 | "\n(if (and (boundp 'emacs-version)\n" |
| 1355 | "\n(if (and (boundp 'emacs-version)\n" | 1368 | "\t (or (and (boundp 'epoch::version) epoch::version)\n" |
| 1356 | "\t (or (and (boundp 'epoch::version) epoch::version)\n" | 1369 | "\t (string-lessp emacs-version \"19\")))\n" |
| 1357 | "\t (string-lessp emacs-version \"19\")))\n" | 1370 | " (error \"`" |
| 1358 | " (error \"`" | 1371 | ;; This escapes all backslashes in FILENAME. Needed on Windows. |
| 1359 | ;; This escapes all backslashes in FILENAME. Needed on Windows. | 1372 | (substring (prin1-to-string filename) 1 -1) |
| 1360 | (substring (prin1-to-string filename) 1 -1) | 1373 | "' was compiled for Emacs 19\"))\n\n" |
| 1361 | "' was compiled for Emacs 19\"))\n" | 1374 | ))) |
| 1362 | )) | ||
| 1363 | )) | ||
| 1364 | 1375 | ||
| 1365 | 1376 | ||
| 1366 | (defun byte-compile-output-file-form (form) | 1377 | (defun byte-compile-output-file-form (form) |
| @@ -1372,7 +1383,8 @@ With argument, insert value in current buffer after the form." | |||
| 1372 | ;; it here. | 1383 | ;; it here. |
| 1373 | (if (and (memq (car-safe form) '(defun defmacro defvar defconst autoload)) | 1384 | (if (and (memq (car-safe form) '(defun defmacro defvar defconst autoload)) |
| 1374 | (stringp (nth 3 form))) | 1385 | (stringp (nth 3 form))) |
| 1375 | (byte-compile-output-docform '("\n(" 3 ")") form) | 1386 | (byte-compile-output-docform nil nil '("\n(" 3 ")") form nil |
| 1387 | (eq (car form) 'autoload)) | ||
| 1376 | (let ((print-escape-newlines t) | 1388 | (let ((print-escape-newlines t) |
| 1377 | (print-readably t) ; print #[] for bytecode, 'x for (quote x) | 1389 | (print-readably t) ; print #[] for bytecode, 'x for (quote x) |
| 1378 | (print-gensym nil)) ; this is too dangerous for now | 1390 | (print-gensym nil)) ; this is too dangerous for now |
| @@ -1380,27 +1392,67 @@ With argument, insert value in current buffer after the form." | |||
| 1380 | (prin1 form outbuffer) | 1392 | (prin1 form outbuffer) |
| 1381 | nil))) | 1393 | nil))) |
| 1382 | 1394 | ||
| 1383 | (defun byte-compile-output-docform (info form) | 1395 | (defun byte-compile-output-docform (preface name info form specindex quoted) |
| 1384 | ;; Print a form with a doc string. INFO is (prefix doc-index postfix). | 1396 | ;; Print a form with a doc string. INFO is (prefix doc-index postfix). |
| 1397 | ;; If PREFACE and NAME are non-nil, print them too, | ||
| 1398 | ;; before INFO and the FORM but after the doc string itself. | ||
| 1399 | ;; If SPECINDEX is non-nil, it is the index in FORM | ||
| 1400 | ;; of the function bytecode string. In that case, | ||
| 1401 | ;; we output that argument and the following argument (the constants vector) | ||
| 1402 | ;; together, for lazy loading. | ||
| 1403 | ;; QUOTED says that we have to put a quote before the | ||
| 1404 | ;; list that represents a doc string reference. | ||
| 1405 | ;; `autoload' needs that. | ||
| 1385 | (set-buffer | 1406 | (set-buffer |
| 1386 | (prog1 (current-buffer) | 1407 | (prog1 (current-buffer) |
| 1387 | (set-buffer outbuffer) | 1408 | (set-buffer outbuffer) |
| 1388 | (insert (car info)) | 1409 | (let (position) |
| 1389 | (let ((docl (nthcdr (nth 1 info) form)) | 1410 | |
| 1390 | (print-escape-newlines t) | 1411 | ;; Insert the doc string, and make it a comment with #@LENGTH. |
| 1391 | (print-readably t) ; print #[] for bytecode, 'x for (quote x) | 1412 | (and (>= (nth 1 info) 0) |
| 1392 | (print-gensym nil)) ; this is too dangerous for now | 1413 | byte-compile-dynamic-docstrings |
| 1393 | (prin1 (car form) outbuffer) | 1414 | (progn |
| 1394 | (while (setq form (cdr form)) | 1415 | ;; Make the doc string start at beginning of line |
| 1395 | (insert " ") | 1416 | ;; for make-docfile's sake. |
| 1396 | (if (eq form docl) | 1417 | (insert "\n") |
| 1397 | (let ((print-escape-newlines nil)) | 1418 | (setq position |
| 1398 | (goto-char (prog1 (1+ (point)) | 1419 | (byte-compile-output-as-comment |
| 1399 | (prin1 (car form) outbuffer))) | 1420 | (nth (nth 1 info) form) nil)))) |
| 1400 | (insert "\\\n") | 1421 | |
| 1401 | (goto-char (point-max))) | 1422 | (if preface |
| 1402 | (prin1 (car form) outbuffer)))) | 1423 | (progn |
| 1403 | (insert (nth 2 info)))) | 1424 | (insert preface) |
| 1425 | (prin1 name outbuffer))) | ||
| 1426 | (insert (car info)) | ||
| 1427 | (let ((print-escape-newlines t) | ||
| 1428 | (print-readably t) ; print #[] for bytecode, 'x for (quote x) | ||
| 1429 | (print-gensym nil) ; this is too dangerous for now | ||
| 1430 | (index 0)) | ||
| 1431 | (prin1 (car form) outbuffer) | ||
| 1432 | (while (setq form (cdr form)) | ||
| 1433 | (setq index (1+ index)) | ||
| 1434 | (insert " ") | ||
| 1435 | (cond ((and (numberp specindex) (= index specindex)) | ||
| 1436 | (let ((position | ||
| 1437 | (byte-compile-output-as-comment | ||
| 1438 | (cons (car form) (nth 1 form)) | ||
| 1439 | t))) | ||
| 1440 | (princ (format "(#$ . %d) nil" position) outbuffer) | ||
| 1441 | (setq form (cdr form)) | ||
| 1442 | (setq index (1+ index)))) | ||
| 1443 | ((= index (nth 1 info)) | ||
| 1444 | (if position | ||
| 1445 | (princ (format (if quoted "'(#$ . %d)" "(#$ . %d)") | ||
| 1446 | position) | ||
| 1447 | outbuffer) | ||
| 1448 | (let ((print-escape-newlines nil)) | ||
| 1449 | (goto-char (prog1 (1+ (point)) | ||
| 1450 | (prin1 (car form) outbuffer))) | ||
| 1451 | (insert "\\\n") | ||
| 1452 | (goto-char (point-max))))) | ||
| 1453 | (t | ||
| 1454 | (prin1 (car form) outbuffer))))) | ||
| 1455 | (insert (nth 2 info))))) | ||
| 1404 | nil) | 1456 | nil) |
| 1405 | 1457 | ||
| 1406 | (defun byte-compile-keep-pending (form &optional handler) | 1458 | (defun byte-compile-keep-pending (form &optional handler) |
| @@ -1591,36 +1643,82 @@ With argument, insert value in current buffer after the form." | |||
| 1591 | (eq 'lambda (car-safe (nth 1 code)))) | 1643 | (eq 'lambda (car-safe (nth 1 code)))) |
| 1592 | (cons (car form) | 1644 | (cons (car form) |
| 1593 | (cons name (cdr (nth 1 code)))) | 1645 | (cons name (cdr (nth 1 code)))) |
| 1646 | (byte-compile-flush-pending) | ||
| 1594 | (if (not (stringp (nth 3 form))) | 1647 | (if (not (stringp (nth 3 form))) |
| 1595 | ;; No doc string to make-docfile; insert form in normal code. | 1648 | ;; No doc string. Provide -1 as the "doc string index" |
| 1596 | (byte-compile-keep-pending | 1649 | ;; so that no element will be treated as a doc string. |
| 1597 | (list (if (byte-compile-version-cond byte-compile-compatibility) | 1650 | (byte-compile-output-docform |
| 1598 | 'fset 'defalias) | 1651 | (if (byte-compile-version-cond byte-compile-compatibility) |
| 1599 | (list 'quote name) | 1652 | "\n(fset '" "\n(defalias '") |
| 1600 | (cond ((not macrop) | 1653 | name |
| 1601 | code) | 1654 | (cond ((atom code) |
| 1602 | ((eq 'make-byte-code (car-safe code)) | 1655 | (if macrop '(" '(macro . #[" -1 "])") '(" #[" -1 "]"))) |
| 1603 | (list 'cons ''macro code)) | 1656 | ((eq (car code) 'quote) |
| 1604 | ((list 'quote (if macrop | 1657 | (setq code new-one) |
| 1605 | (cons 'macro new-one) | 1658 | (if macrop '(" '(macro " -1 ")") '(" '(" -1 ")"))) |
| 1606 | new-one)))))) | 1659 | ((if macrop '(" (cons 'macro (" -1 "))") '(" (" -1 ")")))) |
| 1660 | (append code nil) | ||
| 1661 | (and (atom code) byte-compile-dynamic | ||
| 1662 | 1) | ||
| 1663 | nil) | ||
| 1607 | ;; Output the form by hand, that's much simpler than having | 1664 | ;; Output the form by hand, that's much simpler than having |
| 1608 | ;; b-c-output-file-form analyze the defalias. | 1665 | ;; b-c-output-file-form analyze the defalias. |
| 1609 | (byte-compile-flush-pending) | ||
| 1610 | (princ (if (byte-compile-version-cond byte-compile-compatibility) | ||
| 1611 | "\n(fset '" "\n(defalias '") | ||
| 1612 | outbuffer) | ||
| 1613 | (prin1 name outbuffer) | ||
| 1614 | (byte-compile-output-docform | 1666 | (byte-compile-output-docform |
| 1667 | (if (byte-compile-version-cond byte-compile-compatibility) | ||
| 1668 | "\n(fset '" "\n(defalias '") | ||
| 1669 | name | ||
| 1615 | (cond ((atom code) | 1670 | (cond ((atom code) |
| 1616 | (if macrop '(" '(macro . #[" 4 "])") '(" #[" 4 "]"))) | 1671 | (if macrop '(" '(macro . #[" 4 "])") '(" #[" 4 "]"))) |
| 1617 | ((eq (car code) 'quote) | 1672 | ((eq (car code) 'quote) |
| 1618 | (setq code new-one) | 1673 | (setq code new-one) |
| 1619 | (if macrop '(" '(macro " 2 ")") '(" '(" 2 ")"))) | 1674 | (if macrop '(" '(macro " 2 ")") '(" '(" 2 ")"))) |
| 1620 | ((if macrop '(" (cons 'macro (" 5 "))") '(" (" 5 ")")))) | 1675 | ((if macrop '(" (cons 'macro (" 5 "))") '(" (" 5 ")")))) |
| 1621 | (append code nil)) | 1676 | (append code nil) |
| 1622 | (princ ")" outbuffer) | 1677 | (and (atom code) byte-compile-dynamic |
| 1623 | nil))))) | 1678 | 1) |
| 1679 | nil)) | ||
| 1680 | (princ ")" outbuffer) | ||
| 1681 | nil)))) | ||
| 1682 | |||
| 1683 | ;; Print Lisp object EXP in the output file, inside a comment, | ||
| 1684 | ;; and return the file position it will have. | ||
| 1685 | ;; If QUOTED is non-nil, print with quoting; otherwise, print without quoting. | ||
| 1686 | (defun byte-compile-output-as-comment (exp quoted) | ||
| 1687 | (let ((position (point))) | ||
| 1688 | (set-buffer | ||
| 1689 | (prog1 (current-buffer) | ||
| 1690 | (set-buffer outbuffer) | ||
| 1691 | |||
| 1692 | ;; Insert EXP, and make it a comment with #@LENGTH. | ||
| 1693 | (insert " ") | ||
| 1694 | (if quoted | ||
| 1695 | (prin1 exp outbuffer) | ||
| 1696 | (princ exp outbuffer)) | ||
| 1697 | (goto-char position) | ||
| 1698 | ;; Quote certain special characters as needed. | ||
| 1699 | ;; get_doc_string in doc.c does the unquoting. | ||
| 1700 | (while (search-forward "\^A" nil t) | ||
| 1701 | (replace-match "\^A\^A" t t)) | ||
| 1702 | (goto-char position) | ||
| 1703 | (while (search-forward "\000" nil t) | ||
| 1704 | (replace-match "\^A0" t t)) | ||
| 1705 | (goto-char position) | ||
| 1706 | (while (search-forward "\037" nil t) | ||
| 1707 | (replace-match "\^A_" t t)) | ||
| 1708 | (goto-char (point-max)) | ||
| 1709 | (insert "\037") | ||
| 1710 | (goto-char position) | ||
| 1711 | (insert "#@" (format "%d" (- (point-max) position))) | ||
| 1712 | |||
| 1713 | ;; Save the file position of the object. | ||
| 1714 | ;; Note we should add 1 to skip the space | ||
| 1715 | ;; that we inserted before the actual doc string, | ||
| 1716 | ;; and subtract 1 to convert from an 1-origin Emacs position | ||
| 1717 | ;; to a file position; they cancel. | ||
| 1718 | (setq position (point)) | ||
| 1719 | (goto-char (point-max)))) | ||
| 1720 | position)) | ||
| 1721 | |||
| 1624 | 1722 | ||
| 1625 | 1723 | ||
| 1626 | ;;;###autoload | 1724 | ;;;###autoload |