all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* On byte compilation
@ 2023-09-17 18:32 Petteri Hintsanen
  2023-09-18 19:07 ` tpeplt
  0 siblings, 1 reply; 3+ messages in thread
From: Petteri Hintsanen @ 2023-09-17 18:32 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

I'm converting some old code to use new bindat-type introduced in
Emacs 28.1.  I'd like to keep the legacy forms for backwards
compatibility with older emacsen.  But there is a problem with byte
compilation.

Toy example:

  (defconst foo-bindat-spec
    (eval-when-compile
      (if (fboundp 'bindat-type)
          (bindat-type  ;; new form
            (id uint 32))
        '((id u32))))  ;; legacy form
    "Bindat spec for foo.")

What I try to accomplish here is to assign to foo-bindat-spec either the
result of (bindat-type ...) or list '((id u32)), depending on whether
bindat-type macro is available or not.  However, Emacs' 27.2 byte
compiler complains:

  foo.el:5:14:Warning: reference to free variable ‘uint’

even though (fboundp 'bindat-type) evaluates to nil with that Emacs
version.  The resulting elc seems to be ok (?) despite the warning:

  #@22 Bindat spec for foo.
  (defconst foo-bindat-spec '((id u32)) (#$ . 408))

If I relocate eval-when-compile like this

  (defconst foo-bindat-spec
    (if (eval-when-compile (fboundp 'bindat-type))
        (bindat-type  ;; new form
          (id uint 32))
      '((id u32)))  ;; legacy form
    "Bindat spec for foo.")

then the byte compiler does not complain.  Could someone please explain
why?

Thanks,
Petteri




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

* Re: On byte compilation
  2023-09-17 18:32 On byte compilation Petteri Hintsanen
@ 2023-09-18 19:07 ` tpeplt
  2023-09-19 22:47   ` tpeplt
  0 siblings, 1 reply; 3+ messages in thread
From: tpeplt @ 2023-09-18 19:07 UTC (permalink / raw)
  To: Petteri Hintsanen; +Cc: help-gnu-emacs

Petteri Hintsanen <petterih@iki.fi> writes:

> Hello,
>
> I'm converting some old code to use new bindat-type introduced in
> Emacs 28.1.  I'd like to keep the legacy forms for backwards
> compatibility with older emacsen.  But there is a problem with byte
> compilation.
>
> Toy example:
>
>   (defconst foo-bindat-spec
>     (eval-when-compile
>       (if (fboundp 'bindat-type)
>           (bindat-type  ;; new form
>             (id uint 32))
>         '((id u32))))  ;; legacy form
>     "Bindat spec for foo.")
>
> What I try to accomplish here is to assign to foo-bindat-spec either the
> result of (bindat-type ...) or list '((id u32)), depending on whether
> bindat-type macro is available or not.  However, Emacs' 27.2 byte
> compiler complains:
>
>   foo.el:5:14:Warning: reference to free variable ‘uint’
>

Emacs 28.2 reports this, also.  Did you mean 28.2 instead of 27.2?

‘uint’ is a symbol rather than a variable, according to the
documentation in the elisp info manual: (elisp)"Bindat Types".  So, it
is good that the compiler is warning you.  You would get the same
warning if you used:
  (id uintr 32) or (id str 32) or (id strz 32) or (id vec 32),...

The identifier ‘uint’ needs to be quoted: (id 'uint 32) or
alternatively, (id (quote uint) 32), if that is clearer to you.

(type-of uint) => error, void variable
(type-of 'uint) => symbol

Also, if you have not read it or haven’t read it recently, here is the
node in the elisp manual for Eval During Compile:
   (elisp) Eval During Compile

--



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

* Re: On byte compilation
  2023-09-18 19:07 ` tpeplt
@ 2023-09-19 22:47   ` tpeplt
  0 siblings, 0 replies; 3+ messages in thread
From: tpeplt @ 2023-09-19 22:47 UTC (permalink / raw)
  To: Petteri Hintsanen; +Cc: help-gnu-emacs

tpeplt <tpeplt@gmail.com> writes:

> Petteri Hintsanen <petterih@iki.fi> writes:
>
>> Hello,
>>
>> I'm converting some old code to use new bindat-type introduced in
>> Emacs 28.1.  I'd like to keep the legacy forms for backwards
>> compatibility with older emacsen.  But there is a problem with byte
>> compilation.
>>
>> Toy example:
>>
>>   (defconst foo-bindat-spec
>>     (eval-when-compile
>>       (if (fboundp 'bindat-type)
>>           (bindat-type  ;; new form
>>             (id uint 32))
>>         '((id u32))))  ;; legacy form
>>     "Bindat spec for foo.")
>>
>> What I try to accomplish here is to assign to foo-bindat-spec either the
>> result of (bindat-type ...) or list '((id u32)), depending on whether
>> bindat-type macro is available or not.  However, Emacs' 27.2 byte
>> compiler complains:
>>
>>   foo.el:5:14:Warning: reference to free variable ‘uint’
>>
>
> Emacs 28.2 reports this, also.  Did you mean 28.2 instead of 27.2?
>
> ‘uint’ is a symbol rather than a variable, according to the
> documentation in the elisp info manual: (elisp)"Bindat Types".  So, it
> is good that the compiler is warning you.  You would get the same
> warning if you used:
>   (id uintr 32) or (id str 32) or (id strz 32) or (id vec 32),...
>
> The identifier ‘uint’ needs to be quoted: (id 'uint 32) or
> alternatively, (id (quote uint) 32), if that is clearer to you.
>
> (type-of uint) => error, void variable
> (type-of 'uint) => symbol
>
> Also, if you have not read it or haven’t read it recently, here is the
> node in the elisp manual for Eval During Compile:
>    (elisp) Eval During Compile
>
> --

I was mistaken.  According to the parent node of (elisp)Bindat Types,
that is, node (elisp) Byte Packing:

   "To use the functions referred to in this section, load the ‘bindat’
    library."

So, if we take your example, and first evaluate the expression:

   (require 'bindat)

Then your example evaluates and compiles (and lints) without any
warnings or errors.

--



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

end of thread, other threads:[~2023-09-19 22:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-17 18:32 On byte compilation Petteri Hintsanen
2023-09-18 19:07 ` tpeplt
2023-09-19 22:47   ` tpeplt

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.