unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Help with the disassembly of a very short function, please.
@ 2022-01-01 19:01 Alan Mackenzie
  2022-01-01 19:43 ` Andreas Schwab
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Mackenzie @ 2022-01-01 19:01 UTC (permalink / raw)
  To: emacs-devel

Hello, Emacs.

The following function comes from .../test/src/comp-tests.el, more or
less:

;; -*- lexical-binding: t -*-
(defun comp-test-55 (x)
  (unless (integerp x)
      x))

I byte compile it with C-x C-e then dump out its byte code with M-x
disassemble.  I get this:

byte code for comp-test-55:
  doc:   ...
    args: (arg1)
    0       dup
    1       integerp
    2       not
    3       goto-if-nil-else-pop 1
    6       dup
    7:1     return

..  In the case where x is not an integer, it seems that the dup at 6
will leave two many copies of x on the stack for the return.

In the case where x is an integer, it seems that the
goto-if-nil-else-pop will leave a nil on the stack over the original
x, returning the nil but leaving a superfluous copy of the integer x
on the stack.

So, either way, there is an unwanted copy of x left on the stack at the
end of the function.

I can't work this out.  What am I missing?

-- 
Alan Mackenzie (Nuremberg, Germany).



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

* Re: Help with the disassembly of a very short function, please.
  2022-01-01 19:01 Help with the disassembly of a very short function, please Alan Mackenzie
@ 2022-01-01 19:43 ` Andreas Schwab
  2022-01-01 22:07   ` Alan Mackenzie
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Schwab @ 2022-01-01 19:43 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: emacs-devel

The arguments are not consumed.  Each byte-code execution has a private
value stack, which is just discarded at the end, no matter what's left.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



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

* Re: Help with the disassembly of a very short function, please.
  2022-01-01 19:43 ` Andreas Schwab
@ 2022-01-01 22:07   ` Alan Mackenzie
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Mackenzie @ 2022-01-01 22:07 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: emacs-devel

Hello, Andreas.

On Sat, Jan 01, 2022 at 20:43:52 +0100, Andreas Schwab wrote:
> The arguments are not consumed.  Each byte-code execution has a private
> value stack, which is just discarded at the end, no matter what's left.

Thanks, I understand it now.

> -- 
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."

-- 
Alan Mackenzie (Nuremberg, Germany).



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

end of thread, other threads:[~2022-01-01 22:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-01 19:01 Help with the disassembly of a very short function, please Alan Mackenzie
2022-01-01 19:43 ` Andreas Schwab
2022-01-01 22:07   ` Alan Mackenzie

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).