From xemacs-m  Sat Jun  7 13:21:42 1997
Received: from jagor.srce.hr (hniksic@jagor.srce.hr [161.53.2.130])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id NAA03852
	for <xemacs-beta@xemacs.org>; Sat, 7 Jun 1997 13:21:41 -0500 (CDT)
Received: (from hniksic@localhost)
          by jagor.srce.hr (8.8.5/8.8.4)
	  id UAA22776; Sat, 7 Jun 1997 20:21:42 +0200 (MET DST)
To: XEmacs Developers <xemacs-beta@xemacs.org>
Subject: A byte-compiler bug?
X-Attribution: Hrv
X-Face: Mie8:rOV<\c/~z{s.X4A{!?vY7{drJ([U]0O=W/<W*SMo/Mv:58:*_y~ki>xDi&N7XG
        KV^$k0m3Oe/)'e%3=$PCR&3ITUXH,cK>]bci&<qQ>Ff%x_>1`T(+M2Gg/fgndU%k*ft
        [(7._6e0n-V%|%'[c|q:;}td$#INd+;?!-V=c8Pqf}3J
From: Hrvoje Niksic <hniksic@srce.hr>
Date: 07 Jun 1997 20:21:42 +0200
Message-ID: <kig206ep93d.fsf@jagor.srce.hr>
Lines: 78
X-Mailer: Gnus v5.4.52/XEmacs 20.3(beta4)

This example has me completely baffled.  Take this form:

(princ
 (let ((x (make-string 256 ?\0)))
   (dotimes (i 256)
     (debug)
     (aset x i (int-char i)))
   x)
 (current-buffer))

It creates a string of 256 chars, each index having the char-value of
its index position.

Try evaluating it, and you get the correct thing.  Now save it to a
file, byte-compile it and load the byte-compiled file, and you get an
error.

It seems that `dotimes' somehow misbehaves -- it sets i to ?\^@ when
byte-compiled (!).  Now, let's see.  The `dotimes' form expands to:

(let ((--dotimes-temp--44056 256)
      (i 0))
    (while (< i --dotimes-temp--44056)
      (debug)
      (aset x i (int-char i))
      (setq i (1+ i)))
    nil)

OK.  But, the whole  byte-compiled form disassembles to:

byte code:
  args: nil
0	constant  princ
1	constant  make-string
2	constant  256
3	constant  ?\^@
4	call	  2
5	varbind	  x
6	constant  256
7	constant  ?\^@                ; WTF???!!!    -hniksic
8	varbind	  i
9	varbind	  --dotimes-temp--44055
11	varref	  i
12:1	varref	  --dotimes-temp--44055
14	lss	  
15	goto-if-nil 2
17	constant  debug
18	call	  0
19	discard	  
20	varref	  x
21	varref	  i
22	constant  int-char
23	varref	  i
24	call	  1
25	aset	  
26	discard	  
27	varref	  i
28	add1	  
29	dup	  
30	varset	  i
31	goto	  1
33:2	unbind	  2
34	varref	  x
35	unbind	  1
36	current-buffer 
37	call	  2
38	return	  


To me it seems that the byte-compiler tries to do some wonders by
reusing the 256 ?\0 sequence.  Is the compiler really fully aware of
the difference between 0 and `?\0'?

-- 
Hrvoje Niksic <hniksic@srce.hr> | Student at FER Zagreb, Croatia
--------------------------------+--------------------------------
4.  Thou shalt not warlorde a sig if it bee the sig of Kibo, nor if
    it bee the sig of the Inner Circle.

