emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stack size info


From: Thien-Thi Nguyen
Subject: Re: stack size info
Date: Sat, 24 Mar 2007 09:38:10 -0400

   From: A Soare <address@hidden>
   Date: Fri, 23 Mar 2007 16:08:46 +0100 (CET)

   I can not imagine an example in which this STACKSIZE is greater than
   the actual real size. Can somebody help me with an example, please?

following is an example (created in the *scratch* buffer, btw, so
you can try to recreate it for yourself, as well).  the annotations
(comments) on the right were added by hand.

there are two functions and three function calls.  the second and
third calls illustrate how one function might use a different amount
of stack depending on its operating environment (in this case, the
value of its arg OBJECT).  that amount is at most 4, which coincides
(purposefully) with the STACKSIZE element in the byte-code function
object for `maybe'.

to understand in more detail, you will need to understand how each
operation interacts with the stack (if at all).  for more info,
place the cursor after the following form and type `C-x C-e':

  (info "(elisp)Disassembly")

btw, the construct `(or (byte-compile FOO) (symbol-function FOO))'
is because `byte-compile' returns nil if FOO is already compiled.

thi

___________________________________________________

(defun no-op () t)
no-op

(disassemble (or (byte-compile 'no-op)
                 (symbol-function 'no-op))
             (current-buffer))
byte code:
  args: nil                             ; stack usage
0       constant  t                     ; 1
1       return                          ; 0

(defun maybe (object)
  (when object
    (let* ((a 42)
           (b 6))
      (when (= a (+ b (* b b)))
        object))))
maybe

(disassemble (or (byte-compile 'maybe)
                 (symbol-function 'maybe))
             (current-buffer))
byte code:                              ; OBJECT: nil
  args: (object)                        ; stack usage
0       varref    object                ; 1
1       goto-if-nil-else-pop 2          ; (branch taken)
4       constant  42
5       varbind   a
6       constant  6
7       varbind   b
8       varref    a
9       varref    b
10      dup
11      dup
12      mult
13      plus
14      eqlsign
15      goto-if-nil-else-pop 1
18      varref    object
19:1    unbind    2
20:2    return                          ; 0

(disassemble (or (byte-compile 'maybe)
                 (symbol-function 'maybe))
             (current-buffer))
byte code:                              ; OBJECT: 42
  args: (object)                        ; stack usage
0       varref    object                ; 1
1       goto-if-nil-else-pop 2          ; 0 (branch not taken)
4       constant  42                    ; 1
5       varbind   a                     ; 0
6       constant  6                     ; 1
7       varbind   b                     ; 0
8       varref    a                     ; 1
9       varref    b                     ; 2
10      dup                             ; 3
11      dup                             ; 4
12      mult                            ; 3
13      plus                            ; 2
14      eqlsign                         ; 1
15      goto-if-nil-else-pop 1          ; 0 (branch not taken)
18      varref    object                ; 1
19:1    unbind    2
20:2    return                          ; 0





reply via email to

[Prev in Thread] Current Thread [Next in Thread]