all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* stack size info
@ 2007-03-20 13:22 A Soare
  2007-03-20 16:14 ` ttn
  0 siblings, 1 reply; 9+ messages in thread
From: A Soare @ 2007-03-20 13:22 UTC (permalink / raw)
  To: Emacs   Dev  [emacs-devel]


16.7 Byte-Code Function Objects
===============================

STACKSIZE
     The maximum stack size this function needs.

------------------------------

(defun p (n)
  "sum"
  (if (> n 1) (+ n (p (1- n)))
    n))



(byte-compile 'p)
(symbol-function 'p)

#[(n)
  "..."
  [n 1 p]
  3            <=<= here is the stack size.
  "sum"]

But I believe that a recursive function has the stack greater, 3*n, not 3. For every recursion I believe that the stack size get greater with 3, so the stack is dependent of n. Is it true?

Is this a little error of explanation in INFO file?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: stack size info
  2007-03-20 13:22 A Soare
@ 2007-03-20 16:14 ` ttn
  0 siblings, 0 replies; 9+ messages in thread
From: ttn @ 2007-03-20 16:14 UTC (permalink / raw)
  To: alinsoar; +Cc: emacs-devel

   From: A Soare <alinsoar@voila.fr>
   Date: Tue, 20 Mar 2007 14:22:14 +0100 (CET)

   #[(n)
     "..."
     [n 1 p]
     3            <=<= here is the stack size.
     "sum"]

   But I believe that a recursive function has the stack greater, 3*n,
   not 3. For every recursion I believe that the stack size get greater
   with 3, so the stack is dependent of n. Is it true?

   Is this a little error of explanation in INFO file?

i think the intention of the documentation is that "this function" means
this "this function call".  to me it seems pretty clear, but that may be
due to recent coffee intake...  could you suggest a change to make the
explanation clearer for you?

thi

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: stack size info
@ 2007-03-22 15:19 A Soare
  2007-03-22 18:24 ` David Kastrup
  0 siblings, 1 reply; 9+ messages in thread
From: A Soare @ 2007-03-22 15:19 UTC (permalink / raw)
  To: ttn; +Cc: Emacs   Dev  [emacs-devel]



STACKSIZE
     The maximum stack size this function needs. In case of recursion,
     every recursive call grows function's stack size with this constant.

########

This is a litte better?

It is mecessary to use "maximum". It is not an exact quantity?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: stack size info
  2007-03-22 15:19 stack size info A Soare
@ 2007-03-22 18:24 ` David Kastrup
  2007-03-23 15:01   ` Thien-Thi Nguyen
  0 siblings, 1 reply; 9+ messages in thread
From: David Kastrup @ 2007-03-22 18:24 UTC (permalink / raw)
  To: alinsoar; +Cc: ttn, Emacs Dev [emacs-devel]

A Soare <alinsoar@voila.fr> writes:

> STACKSIZE
>      The maximum stack size this function needs. In case of recursion,
>      every recursive call grows function's stack size with this constant.
>
> ########
>
> This is a litte better?

I don't think so.  My guess is "The maximum stack size this function
needs for execution, disregarding further (including recursive)
function calls as those extend the stack on their own."

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: stack size info
  2007-03-22 18:24 ` David Kastrup
@ 2007-03-23 15:01   ` Thien-Thi Nguyen
  2007-03-23 16:00     ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Thien-Thi Nguyen @ 2007-03-23 15:01 UTC (permalink / raw)
  To: alinsoar, emacs-devel

   From: David Kastrup <dak@gnu.org>
   Date: Thu, 22 Mar 2007 19:24:10 +0100

   A Soare <alinsoar@voila.fr> writes:

   > STACKSIZE
   >      The maximum stack size this function needs. In case of recursion,
   >      every recursive call grows function's stack size with this constant.
   >
   > ########
   >
   > This is a litte better?

   I don't think so.  My guess is "The maximum stack size this function
   needs for execution, disregarding further (including recursive)
   function calls as those extend the stack on their own."

i'm inclined to leave the docs alone.  the node's entire context is a
single function and thus the STACKSIZE element of the byte-code function
object pertains to a single function call.

however, if pressed, i will suggest:
The maximum stack size this function might need when called.

"might" because it is possible that any particular call uses less than
that amount.  "when called" addresses recursion.

is that wording ok?

thi

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: stack size info
@ 2007-03-23 15:08 A Soare
  2007-03-24 13:38 ` Thien-Thi Nguyen
  0 siblings, 1 reply; 9+ messages in thread
From: A Soare @ 2007-03-23 15:08 UTC (permalink / raw)
  To: ttn; +Cc: Emacs   Dev  [emacs-devel]

>    From: David Kastrup <dak@gnu.org>
>    Date: Thu, 22 Mar 2007 19:24:10 +0100
> 
>    A Soare <alinsoar@voila.fr> writes:
> 
>    > STACKSIZE
>    >      The maximum stack size this function needs. In case of recursion,
>    >      every recursive call grows function's stack size with this constant.
>    >
>    > ########
>    >
>    > This is a litte better?
> 
>    I don't think so.  My guess is "The maximum stack size this function
>    needs for execution, disregarding further (including recursive)
>    function calls as those extend the stack on their own."
> 
> i'm inclined to leave the docs alone.  the node's entire context is a
> single function and thus the STACKSIZE element of the byte-code function
> object pertains to a single function call.

I think this problem is not at all important, but at a first glance one can imagine something wrong.


> 
> however, if pressed, i will suggest:
> The maximum stack size this function might need when called.
> 
> "might" because it is possible that any particular call uses less than
> that amount.  "when called" addresses recursion.
> 

As you wish.



One more important question is "The maximum stack size" or just simply "the stack size". 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?

Thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: stack size info
  2007-03-23 15:01   ` Thien-Thi Nguyen
@ 2007-03-23 16:00     ` Stefan Monnier
  0 siblings, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2007-03-23 16:00 UTC (permalink / raw)
  To: ttn; +Cc: alinsoar, emacs-devel

>    I don't think so.  My guess is "The maximum stack size this function
>    needs for execution, disregarding further (including recursive)
>    function calls as those extend the stack on their own."

> i'm inclined to leave the docs alone.  the node's entire context is a
> single function and thus the STACKSIZE element of the byte-code function
> object pertains to a single function call.

> however, if pressed, i will suggest:
> The maximum stack size this function might need when called.

> "might" because it is possible that any particular call uses less than
> that amount.  "when called" addresses recursion.

Maybe it could be called a "stack frame".
And I'd use the word "upper bound" rather than maximum.
Also I'd use the word "use" rather than "need".


        Stefan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: stack size info
  2007-03-23 15:08 A Soare
@ 2007-03-24 13:38 ` Thien-Thi Nguyen
  0 siblings, 0 replies; 9+ messages in thread
From: Thien-Thi Nguyen @ 2007-03-24 13:38 UTC (permalink / raw)
  To: alinsoar; +Cc: emacs-devel

   From: A Soare <alinsoar@voila.fr>
   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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: stack size info
@ 2007-03-26 10:42 A Soare
  0 siblings, 0 replies; 9+ messages in thread
From: A Soare @ 2007-03-26 10:42 UTC (permalink / raw)
  To: ttn; +Cc: Emacs   Dev  [emacs-devel]


>    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
> 
> 
> 




Thank you very much.


Alin Soare.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-03-26 10:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-22 15:19 stack size info A Soare
2007-03-22 18:24 ` David Kastrup
2007-03-23 15:01   ` Thien-Thi Nguyen
2007-03-23 16:00     ` Stefan Monnier
  -- strict thread matches above, loose matches on Subject: below --
2007-03-26 10:42 A Soare
2007-03-23 15:08 A Soare
2007-03-24 13:38 ` Thien-Thi Nguyen
2007-03-20 13:22 A Soare
2007-03-20 16:14 ` ttn

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.