Mercurial > hg > xemacs-beta
comparison man/lispref/compile.texi @ 380:8626e4521993 r21-2-5
Import from CVS: tag r21-2-5
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:07:10 +0200 |
parents | 70ad99077275 |
children | 501cfd01ee6d |
comparison
equal
deleted
inserted
replaced
379:76b7d63099ad | 380:8626e4521993 |
---|---|
1 @c -*-texinfo-*- | 1 @c -*-texinfo-*- |
2 @c This is part of the XEmacs Lisp Reference Manual. | 2 @c This is part of the XEmacs Lisp Reference Manual. |
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. | 3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. |
4 @c See the file lispref.texi for copying conditions. | 4 @c See the file lispref.texi for copying conditions. |
5 @setfilename ../../info/compile.info | 5 @setfilename ../../info/compile.info |
6 @node Byte Compilation, Debugging, Loading, Top | 6 @node Byte Compilation, Debugging, Loading, Top |
7 @chapter Byte Compilation | 7 @chapter Byte Compilation |
8 @cindex byte-code | 8 @cindex byte-code |
22 | 22 |
23 In general, any version of Emacs can run byte-compiled code produced | 23 In general, any version of Emacs can run byte-compiled code produced |
24 by recent earlier versions of Emacs, but the reverse is not true. In | 24 by recent earlier versions of Emacs, but the reverse is not true. In |
25 particular, if you compile a program with XEmacs 20, the compiled code | 25 particular, if you compile a program with XEmacs 20, the compiled code |
26 may not run in earlier versions. | 26 may not run in earlier versions. |
27 | |
28 The first time a compiled-function object is executed, the byte-code | |
29 instructions are validated and the byte-code is further optimized. An | |
30 @code{invalid-byte-code} error is signaled if the byte-code is invalid, | |
31 for example if it contains invalid opcodes. This usually means a bug in | |
32 the byte compiler. | |
33 | |
27 @iftex | 34 @iftex |
28 @xref{Docs and Compilation}. | 35 @xref{Docs and Compilation}. |
29 @end iftex | 36 @end iftex |
30 | 37 |
31 @xref{Compilation Errors}, for how to investigate errors occurring in | 38 @xref{Compilation Errors}, for how to investigate errors occurring in |
51 @example | 58 @example |
52 @group | 59 @group |
53 (defun silly-loop (n) | 60 (defun silly-loop (n) |
54 "Return time before and after N iterations of a loop." | 61 "Return time before and after N iterations of a loop." |
55 (let ((t1 (current-time-string))) | 62 (let ((t1 (current-time-string))) |
56 (while (> (setq n (1- n)) | 63 (while (> (setq n (1- n)) |
57 0)) | 64 0)) |
58 (list t1 (current-time-string)))) | 65 (list t1 (current-time-string)))) |
59 @result{} silly-loop | 66 @result{} silly-loop |
60 @end group | 67 @end group |
61 | 68 |
62 @group | 69 @group |
63 (silly-loop 5000000) | 70 (silly-loop 5000000) |
64 @result{} ("Fri Nov 28 20:56:16 1997" | 71 @result{} ("Mon Sep 14 15:51:49 1998" |
65 "Fri Nov 28 20:56:39 1997") ; @r{23 seconds} | 72 "Mon Sep 14 15:52:07 1998") ; @r{18 seconds} |
66 @end group | 73 @end group |
67 | 74 |
68 @group | 75 @group |
69 (byte-compile 'silly-loop) | 76 (byte-compile 'silly-loop) |
70 @result{} #<compiled-function | 77 @result{} #<compiled-function |
71 (from "loadup.el") | |
72 (n) | 78 (n) |
73 "...(23)" | 79 "...(23)" |
74 [current-time-string t1 n 0] | 80 [current-time-string t1 n 0] |
75 2 | 81 2 |
76 "Return time before and after N iterations of a loop."> | 82 "Return time before and after N iterations of a loop."> |
77 @end group | 83 @end group |
78 | 84 |
79 @group | 85 @group |
80 (silly-loop 5000000) | 86 (silly-loop 5000000) |
81 @result{} ("Fri Nov 28 20:57:49 1997" | 87 @result{} ("Mon Sep 14 15:53:43 1998" |
82 "Fri Nov 28 20:57:55 1997") ; @r{6 seconds} | 88 "Mon Sep 14 15:53:49 1998") ; @r{6 seconds} |
83 @end group | 89 @end group |
84 @end example | 90 @end example |
85 | 91 |
86 In this example, the interpreted code required 23 seconds to run, | 92 In this example, the interpreted code required 18 seconds to run, |
87 whereas the byte-compiled code required 6 seconds. These results are | 93 whereas the byte-compiled code required 6 seconds. These results are |
88 representative, but actual results will vary greatly. | 94 representative, but actual results will vary greatly. |
89 | 95 |
90 @node Compilation Functions | 96 @node Compilation Functions |
91 @comment node-name, next, previous, up | 97 @comment node-name, next, previous, up |
107 for proper compilation. For more details, see @ref{Compiling Macros}. | 113 for proper compilation. For more details, see @ref{Compiling Macros}. |
108 | 114 |
109 Normally, compiling a file does not evaluate the file's contents or | 115 Normally, compiling a file does not evaluate the file's contents or |
110 load the file. But it does execute any @code{require} calls at top | 116 load the file. But it does execute any @code{require} calls at top |
111 level in the file. One way to ensure that necessary macro definitions | 117 level in the file. One way to ensure that necessary macro definitions |
112 are available during compilation is to require the file that defines | 118 are available during compilation is to @code{require} the file that defines |
113 them (@pxref{Named Features}). To avoid loading the macro definition files | 119 them (@pxref{Named Features}). To avoid loading the macro definition files |
114 when someone @emph{runs} the compiled program, write | 120 when someone @emph{runs} the compiled program, write |
115 @code{eval-when-compile} around the @code{require} calls (@pxref{Eval | 121 @code{eval-when-compile} around the @code{require} calls (@pxref{Eval |
116 During Compile}). | 122 During Compile}). |
117 | 123 |
139 @end group | 145 @end group |
140 | 146 |
141 @group | 147 @group |
142 (byte-compile 'factorial) | 148 (byte-compile 'factorial) |
143 @result{} #<compiled-function | 149 @result{} #<compiled-function |
144 (from "loadup.el") | |
145 (integer) | 150 (integer) |
146 "...(21)" | 151 "...(21)" |
147 [integer 1 factorial] | 152 [integer 1 factorial] |
148 3 | 153 3 |
149 "Compute factorial of INTEGER."> | 154 "Compute factorial of INTEGER."> |
200 @end group | 205 @end group |
201 | 206 |
202 @group | 207 @group |
203 % ls -l push* | 208 % ls -l push* |
204 -rw-r--r-- 1 lewis 791 Oct 5 20:31 push.el | 209 -rw-r--r-- 1 lewis 791 Oct 5 20:31 push.el |
205 -rw-rw-rw- 1 lewis 638 Oct 8 20:25 push.elc | 210 -rw-r--r-- 1 lewis 638 Oct 8 20:25 push.elc |
206 @end group | 211 @end group |
207 @end example | 212 @end example |
208 @end deffn | 213 @end deffn |
209 | 214 |
210 @c flag is not optional in FSF Emacs | 215 @c flag is not optional in FSF Emacs |
217 When a @samp{.el} file has no corresponding @samp{.elc} file, then | 222 When a @samp{.el} file has no corresponding @samp{.elc} file, then |
218 @var{flag} says what to do. If it is @code{nil}, these files are | 223 @var{flag} says what to do. If it is @code{nil}, these files are |
219 ignored. If it is non-@code{nil}, the user is asked whether to compile | 224 ignored. If it is non-@code{nil}, the user is asked whether to compile |
220 each such file. | 225 each such file. |
221 | 226 |
222 The returned value of this command is unpredictable. | 227 The return value of this command is unpredictable. |
223 @end deffn | 228 @end deffn |
224 | 229 |
225 @defun batch-byte-compile | 230 @defun batch-byte-compile |
226 This function runs @code{byte-compile-file} on files specified on the | 231 This function runs @code{byte-compile-file} on files specified on the |
227 command line. This function must be used only in a batch execution of | 232 command line. This function must be used only in a batch execution of |
247 will continue compiling even when an error occurs in a file. This is | 252 will continue compiling even when an error occurs in a file. This is |
248 normally @code{nil}, but is bound to @code{t} by | 253 normally @code{nil}, but is bound to @code{t} by |
249 @code{batch-byte-recompile-directory}. | 254 @code{batch-byte-recompile-directory}. |
250 @end defvar | 255 @end defvar |
251 | 256 |
252 @defun byte-code code-string data-vector max-stack | 257 @defun byte-code instructions constants stack-size |
253 @cindex byte-code interpreter | 258 @cindex byte-code interpreter |
254 This function actually interprets byte-code. A byte-compiled function | 259 This function actually interprets byte-code. |
255 is actually defined with a body that calls @code{byte-code}. Don't call | 260 Don't call this function yourself. Only the byte compiler knows how to |
256 this function yourself. Only the byte compiler knows how to generate | 261 generate valid calls to this function. |
257 valid calls to this function. | 262 |
258 | 263 In newer Emacs versions (19 and up), byte code is usually executed as |
259 In newer Emacs versions (19 and up), byte-code is usually executed as | |
260 part of a compiled-function object, and only rarely due to an explicit | 264 part of a compiled-function object, and only rarely due to an explicit |
261 call to @code{byte-code}. | 265 call to @code{byte-code}. A byte-compiled function was once actually |
266 defined with a body that calls @code{byte-code}, but in recent versions | |
267 of Emacs @code{byte-code} is only used to run isolated fragments of lisp | |
268 code without an associated argument list. | |
262 @end defun | 269 @end defun |
263 | 270 |
264 @node Docs and Compilation | 271 @node Docs and Compilation |
265 @section Documentation Strings and Compilation | 272 @section Documentation Strings and Compilation |
266 @cindex dynamic loading of documentation | 273 @cindex dynamic loading of documentation |
295 However, if you have built Emacs yourself and use it from the | 302 However, if you have built Emacs yourself and use it from the |
296 directory where you built it, you will experience this problem | 303 directory where you built it, you will experience this problem |
297 occasionally if you edit and recompile Lisp files. When it happens, you | 304 occasionally if you edit and recompile Lisp files. When it happens, you |
298 can cure the problem by reloading the file after recompiling it. | 305 can cure the problem by reloading the file after recompiling it. |
299 | 306 |
300 Byte-compiled files made with Emacs 19.29 will not load into older | 307 Versions of Emacs up to and including XEmacs 19.14 and FSF Emacs 19.28 |
301 versions because the older versions don't support this feature. You can | 308 do not support the dynamic docstrings feature, and so will not be able |
302 turn off this feature by setting @code{byte-compile-dynamic-docstrings} | 309 to load bytecode created by more recent Emacs versions. You can turn |
303 to @code{nil}. Once this is done, you can compile files that will load | 310 off the dynamic docstring feature by setting |
304 into older Emacs versions. You can do this globally, or for one source | 311 @code{byte-compile-dynamic-docstrings} to @code{nil}. Once this is |
305 file by specifying a file-local binding for the variable. Here's one | 312 done, you can compile files that will load into older Emacs versions. |
306 way to do that: | 313 You can do this globally, or for one source file by specifying a |
314 file-local binding for the variable. Here's one way to do that: | |
307 | 315 |
308 @example | 316 @example |
309 -*-byte-compile-dynamic-docstrings: nil;-*- | 317 -*-byte-compile-dynamic-docstrings: nil;-*- |
310 @end example | 318 @end example |
311 | 319 |
413 @section Compiled-Function Objects | 421 @section Compiled-Function Objects |
414 @cindex compiled function | 422 @cindex compiled function |
415 @cindex byte-code function | 423 @cindex byte-code function |
416 | 424 |
417 Byte-compiled functions have a special data type: they are | 425 Byte-compiled functions have a special data type: they are |
418 @dfn{compiled-function objects}. | 426 @dfn{compiled-function objects}. The evaluator handles this data type |
419 | 427 specially when it appears as a function to be called. |
420 A compiled-function object is a bit like a vector; however, the | 428 |
421 evaluator handles this data type specially when it appears as a function | 429 The printed representation for a compiled-function object normally |
422 to be called. The printed representation for a compiled-function | 430 begins with @samp{#<compiled-function} and ends with @samp{>}. However, |
423 object normally begins with @samp{#<compiled-function} and ends with | 431 if the variable @code{print-readably} is non-@code{nil}, the object is |
424 @samp{>}. However, if the variable @code{print-readably} is | 432 printed beginning with @samp{#[} and ending with @samp{]}. This |
425 non-@code{nil}, the object is printed beginning with @samp{#[} and | 433 representation can be read directly by the Lisp reader, and is used in |
426 ending with @samp{]}. This representation can be read directly | 434 byte-compiled files (those ending in @samp{.elc}). |
427 by the Lisp reader, and is used in byte-compiled files (those ending | |
428 in @samp{.elc}). | |
429 | 435 |
430 In Emacs version 18, there was no compiled-function object data type; | 436 In Emacs version 18, there was no compiled-function object data type; |
431 compiled functions used the function @code{byte-code} to run the byte | 437 compiled functions used the function @code{byte-code} to run the byte |
432 code. | 438 code. |
433 | 439 |
434 A compiled-function object has a number of different elements. | 440 A compiled-function object has a number of different attributes. |
435 They are: | 441 They are: |
436 | 442 |
437 @table @var | 443 @table @var |
438 @item arglist | 444 @item arglist |
439 The list of argument symbols. | 445 The list of argument symbols. |
443 | 449 |
444 @item constants | 450 @item constants |
445 The vector of Lisp objects referenced by the byte code. These include | 451 The vector of Lisp objects referenced by the byte code. These include |
446 symbols used as function names and variable names. | 452 symbols used as function names and variable names. |
447 | 453 |
448 @item stacksize | 454 @item stack-size |
449 The maximum stack size this function needs. | 455 The maximum stack size this function needs. |
450 | 456 |
451 @item doc-string | 457 @item doc-string |
452 The documentation string (if any); otherwise, @code{nil}. The value may | 458 The documentation string (if any); otherwise, @code{nil}. The value may |
453 be a number or a list, in case the documentation string is stored in a | 459 be a number or a list, in case the documentation string is stored in a |
468 Here's an example of a compiled-function object, in printed | 474 Here's an example of a compiled-function object, in printed |
469 representation. It is the definition of the command | 475 representation. It is the definition of the command |
470 @code{backward-sexp}. | 476 @code{backward-sexp}. |
471 | 477 |
472 @example | 478 @example |
473 #<compiled-function | 479 (symbol-function 'backward-sexp) |
474 (from "lisp.elc") | 480 @result{} #<compiled-function |
475 (&optional arg) | 481 (&optional arg) |
476 "...(15)" [arg 1 forward-sexp] 2 854740 "_p"> | 482 "...(15)" [arg 1 forward-sexp] 2 854740 "_p"> |
477 @end example | 483 @end example |
478 | 484 |
479 The primitive way to create a compiled-function object is with | 485 The primitive way to create a compiled-function object is with |
480 @code{make-byte-code}: | 486 @code{make-byte-code}: |
481 | 487 |
482 @defun make-byte-code &rest elements | 488 @defun make-byte-code arglist instructions constants stack-size &optional doc-string interactive |
483 This function constructs and returns a compiled-function object | 489 This function constructs and returns a compiled-function object |
484 with @var{elements} as its elements. | 490 with the specified attributes. |
485 | 491 |
486 @emph{Please note:} Unlike all other Emacs-lisp functions, calling this with | 492 @emph{Please note:} Unlike all other Emacs-lisp functions, calling this with |
487 five arguments is @emph{not} the same as calling it with six arguments, | 493 five arguments is @emph{not} the same as calling it with six arguments, |
488 the last of which is @code{nil}. If the @var{interactive} arg is | 494 the last of which is @code{nil}. If the @var{interactive} arg is |
489 specified as @code{nil}, then that means that this function was defined | 495 specified as @code{nil}, then that means that this function was defined |
569 @end deffn | 575 @end deffn |
570 | 576 |
571 Here are two examples of using the @code{disassemble} function. We | 577 Here are two examples of using the @code{disassemble} function. We |
572 have added explanatory comments to help you relate the byte-code to the | 578 have added explanatory comments to help you relate the byte-code to the |
573 Lisp source; these do not appear in the output of @code{disassemble}. | 579 Lisp source; these do not appear in the output of @code{disassemble}. |
574 These examples show unoptimized byte-code. Nowadays byte-code is | |
575 usually optimized, but we did not want to rewrite these examples, since | |
576 they still serve their purpose. | |
577 | 580 |
578 @example | 581 @example |
579 @group | 582 @group |
580 (defun factorial (integer) | 583 (defun factorial (integer) |
581 "Compute factorial of an integer." | 584 "Compute factorial of an integer." |
595 doc: Compute factorial of an integer. | 598 doc: Compute factorial of an integer. |
596 args: (integer) | 599 args: (integer) |
597 @end group | 600 @end group |
598 | 601 |
599 @group | 602 @group |
600 0 constant 1 ; @r{Push 1 onto stack.} | 603 0 varref integer ; @r{Get value of @code{integer}} |
601 | |
602 1 varref integer ; @r{Get value of @code{integer}} | |
603 ; @r{from the environment} | 604 ; @r{from the environment} |
604 ; @r{and push the value} | 605 ; @r{and push the value} |
605 ; @r{onto the stack.} | 606 ; @r{onto the stack.} |
607 | |
608 1 constant 1 ; @r{Push 1 onto stack.} | |
606 @end group | 609 @end group |
607 | 610 |
608 @group | 611 @group |
609 2 eqlsign ; @r{Pop top two values off stack,} | 612 2 eqlsign ; @r{Pop top two values off stack,} |
610 ; @r{compare them,} | 613 ; @r{compare them,} |
611 ; @r{and push result onto stack.} | 614 ; @r{and push result onto stack.} |
612 @end group | 615 @end group |
613 | 616 |
614 @group | 617 @group |
615 3 goto-if-nil 10 ; @r{Pop and test top of stack;} | 618 3 goto-if-nil 1 ; @r{Pop and test top of stack;} |
616 ; @r{if @code{nil}, go to 10,} | 619 ; @r{if @code{nil},} |
620 ; @r{go to label 1 (which is also byte 7),} | |
617 ; @r{else continue.} | 621 ; @r{else continue.} |
618 @end group | 622 @end group |
619 | 623 |
620 @group | 624 @group |
621 6 constant 1 ; @r{Push 1 onto top of stack.} | 625 5 constant 1 ; @r{Push 1 onto top of stack.} |
622 | 626 |
623 7 goto 17 ; @r{Go to 17 (in this case, 1 will be} | 627 6 return ; @r{Return the top element} |
624 ; @r{returned by the function).} | 628 ; @r{of the stack.} |
625 @end group | 629 @end group |
626 | 630 |
627 @group | 631 7:1 varref integer ; @r{Push value of @code{integer} onto stack.} |
628 10 constant * ; @r{Push symbol @code{*} onto stack.} | 632 |
629 | 633 @group |
630 11 varref integer ; @r{Push value of @code{integer} onto stack.} | 634 8 constant factorial ; @r{Push @code{factorial} onto stack.} |
631 @end group | 635 |
632 | 636 9 varref integer ; @r{Push value of @code{integer} onto stack.} |
633 @group | 637 |
634 12 constant factorial ; @r{Push @code{factorial} onto stack.} | 638 10 sub1 ; @r{Pop @code{integer}, decrement value,} |
635 | |
636 13 varref integer ; @r{Push value of @code{integer} onto stack.} | |
637 | |
638 14 sub1 ; @r{Pop @code{integer}, decrement value,} | |
639 ; @r{push new value onto stack.} | 639 ; @r{push new value onto stack.} |
640 @end group | 640 @end group |
641 | 641 |
642 @group | 642 @group |
643 ; @r{Stack now contains:} | 643 ; @r{Stack now contains:} |
644 ; @minus{} @r{decremented value of @code{integer}} | 644 ; @minus{} @r{decremented value of @code{integer}} |
645 ; @minus{} @r{@code{factorial}} | 645 ; @minus{} @r{@code{factorial}} |
646 ; @minus{} @r{value of @code{integer}} | 646 ; @minus{} @r{value of @code{integer}} |
647 ; @minus{} @r{@code{*}} | |
648 @end group | 647 @end group |
649 | 648 |
650 @group | 649 @group |
651 15 call 1 ; @r{Call function @code{factorial} using} | 650 15 call 1 ; @r{Call function @code{factorial} using} |
652 ; @r{the first (i.e., the top) element} | 651 ; @r{the first (i.e., the top) element} |
657 @group | 656 @group |
658 ; @r{Stack now contains:} | 657 ; @r{Stack now contains:} |
659 ; @minus{} @r{result of recursive} | 658 ; @minus{} @r{result of recursive} |
660 ; @r{call to @code{factorial}} | 659 ; @r{call to @code{factorial}} |
661 ; @minus{} @r{value of @code{integer}} | 660 ; @minus{} @r{value of @code{integer}} |
662 ; @minus{} @r{@code{*}} | 661 @end group |
663 @end group | 662 |
664 | 663 @group |
665 @group | 664 12 mult ; @r{Pop top two values off the stack,} |
666 16 call 2 ; @r{Using the first two} | 665 ; @r{multiply them,} |
667 ; @r{(i.e., the top two)} | |
668 ; @r{elements of the stack} | |
669 ; @r{as arguments,} | |
670 ; @r{call the function @code{*},} | |
671 ; @r{pushing the result onto the stack.} | 666 ; @r{pushing the result onto the stack.} |
672 @end group | 667 @end group |
673 | 668 |
674 @group | 669 @group |
675 17 return ; @r{Return the top element} | 670 13 return ; @r{Return the top element} |
676 ; @r{of the stack.} | 671 ; @r{of the stack.} |
677 @result{} nil | 672 @result{} nil |
678 @end group | 673 @end group |
679 @end example | 674 @end example |
680 | 675 |
683 @example | 678 @example |
684 @group | 679 @group |
685 (defun silly-loop (n) | 680 (defun silly-loop (n) |
686 "Return time before and after N iterations of a loop." | 681 "Return time before and after N iterations of a loop." |
687 (let ((t1 (current-time-string))) | 682 (let ((t1 (current-time-string))) |
688 (while (> (setq n (1- n)) | 683 (while (> (setq n (1- n)) |
689 0)) | 684 0)) |
690 (list t1 (current-time-string)))) | 685 (list t1 (current-time-string)))) |
691 @result{} silly-loop | 686 @result{} silly-loop |
692 @end group | 687 @end group |
693 | 688 |
712 2 varbind t1 ; @r{Pop stack and bind @code{t1}} | 707 2 varbind t1 ; @r{Pop stack and bind @code{t1}} |
713 ; @r{to popped value.} | 708 ; @r{to popped value.} |
714 @end group | 709 @end group |
715 | 710 |
716 @group | 711 @group |
717 3 varref n ; @r{Get value of @code{n} from} | 712 3:1 varref n ; @r{Get value of @code{n} from} |
718 ; @r{the environment and push} | 713 ; @r{the environment and push} |
719 ; @r{the value onto the stack.} | 714 ; @r{the value onto the stack.} |
720 @end group | 715 @end group |
721 | 716 |
722 @group | 717 @group |
726 @group | 721 @group |
727 5 dup ; @r{Duplicate the top of the stack;} | 722 5 dup ; @r{Duplicate the top of the stack;} |
728 ; @r{i.e., copy the top of} | 723 ; @r{i.e., copy the top of} |
729 ; @r{the stack and push the} | 724 ; @r{the stack and push the} |
730 ; @r{copy onto the stack.} | 725 ; @r{copy onto the stack.} |
731 @end group | 726 |
732 | |
733 @group | |
734 6 varset n ; @r{Pop the top of the stack,} | 727 6 varset n ; @r{Pop the top of the stack,} |
735 ; @r{and bind @code{n} to the value.} | 728 ; @r{and set @code{n} to the value.} |
736 | 729 |
737 ; @r{In effect, the sequence @code{dup varset}} | 730 ; @r{In effect, the sequence @code{dup varset}} |
738 ; @r{copies the top of the stack} | 731 ; @r{copies the top of the stack} |
739 ; @r{into the value of @code{n}} | 732 ; @r{into the value of @code{n}} |
740 ; @r{without popping it.} | 733 ; @r{without popping it.} |
741 @end group | 734 @end group |
742 | 735 |
743 @group | 736 @group |
744 7 constant 0 ; @r{Push 0 onto stack.} | 737 7 constant 0 ; @r{Push 0 onto stack.} |
745 @end group | 738 |
746 | |
747 @group | |
748 8 gtr ; @r{Pop top two values off stack,} | 739 8 gtr ; @r{Pop top two values off stack,} |
749 ; @r{test if @var{n} is greater than 0} | 740 ; @r{test if @var{n} is greater than 0} |
750 ; @r{and push result onto stack.} | 741 ; @r{and push result onto stack.} |
751 @end group | 742 @end group |
752 | 743 |
753 @group | 744 @group |
754 9 goto-if-nil-else-pop 17 ; @r{Goto 17 if @code{n} <= 0} | 745 9 goto-if-not-nil 1 ; @r{Goto label 1 (byte 3) if @code{n} <= 0} |
755 ; @r{(this exits the while loop).} | 746 ; @r{(this exits the while loop).} |
756 ; @r{else pop top of stack} | 747 ; @r{else pop top of stack} |
757 ; @r{and continue} | 748 ; @r{and continue} |
758 @end group | 749 @end group |
759 | 750 |
760 @group | 751 @group |
761 12 constant nil ; @r{Push @code{nil} onto stack} | 752 11 varref t1 ; @r{Push value of @code{t1} onto stack.} |
762 ; @r{(this is the body of the loop).} | 753 @end group |
763 @end group | 754 |
764 | 755 @group |
765 @group | 756 12 constant current-time-string ; @r{Push} |
766 13 discard ; @r{Discard result of the body} | |
767 ; @r{of the loop (a while loop} | |
768 ; @r{is always evaluated for} | |
769 ; @r{its side effects).} | |
770 @end group | |
771 | |
772 @group | |
773 14 goto 3 ; @r{Jump back to beginning} | |
774 ; @r{of while loop.} | |
775 @end group | |
776 | |
777 @group | |
778 17 discard ; @r{Discard result of while loop} | |
779 ; @r{by popping top of stack.} | |
780 ; @r{This result is the value @code{nil} that} | |
781 ; @r{was not popped by the goto at 9.} | |
782 @end group | |
783 | |
784 @group | |
785 18 varref t1 ; @r{Push value of @code{t1} onto stack.} | |
786 @end group | |
787 | |
788 @group | |
789 19 constant current-time-string ; @r{Push} | |
790 ; @r{@code{current-time-string}} | 757 ; @r{@code{current-time-string}} |
791 ; @r{onto top of stack.} | 758 ; @r{onto top of stack.} |
792 @end group | 759 @end group |
793 | 760 |
794 @group | 761 @group |
795 20 call 0 ; @r{Call @code{current-time-string} again.} | 762 13 call 0 ; @r{Call @code{current-time-string} again.} |
796 @end group | 763 |
797 | 764 14 unbind 1 ; @r{Unbind @code{t1} in local environment.} |
798 @group | 765 @end group |
799 21 list2 ; @r{Pop top two elements off stack,} | 766 |
767 @group | |
768 15 list2 ; @r{Pop top two elements off stack,} | |
800 ; @r{create a list of them,} | 769 ; @r{create a list of them,} |
801 ; @r{and push list onto stack.} | 770 ; @r{and push list onto stack.} |
802 @end group | 771 @end group |
803 | 772 |
804 @group | 773 @group |
805 22 unbind 1 ; @r{Unbind @code{t1} in local environment.} | 774 16 return ; @r{Return the top element of the stack.} |
806 | |
807 23 return ; @r{Return value of the top of stack.} | |
808 | 775 |
809 @result{} nil | 776 @result{} nil |
810 @end group | 777 @end group |
811 @end example | 778 @end example |
812 | 779 |