Artifact
d396e153611dd480bad2d1a1c6389f7bfda34771:
Attachment "Bytecode safety and exception ranges..txt" to
ticket [3098302fff]
added by
kennykb
2010-10-30 00:51:16.
0000: 53 75 62 6a 65 63 74 3a 0a 42 79 74 65 63 6f 64 Subject:.Bytecod
0010: 65 20 73 61 66 65 74 79 20 61 6e 64 20 65 78 63 e safety and exc
0020: 65 70 74 69 6f 6e 20 72 61 6e 67 65 73 2e 0a 46 eption ranges..F
0030: 72 6f 6d 3a 0a 4b 65 76 69 6e 20 4b 65 6e 6e 79 rom:.Kevin Kenny
0040: 20 3c 6b 6b 65 6e 6e 79 32 2d 74 55 77 4f 31 38 <kkenny2-tUwO18
0050: 75 44 37 43 42 57 6b 30 48 74 69 6b 33 4a 2f 77 uD7CBWk0Htik3J/w
0060: 40 70 75 62 6c 69 63 2e 67 6d 61 6e 65 2e 6f 72 @public.gmane.or
0070: 67 3e 0a 44 61 74 65 3a 0a 46 72 69 2c 20 32 39 g>.Date:.Fri, 29
0080: 20 4f 63 74 20 32 30 31 30 20 31 32 3a 31 35 3a Oct 2010 12:15:
0090: 31 32 20 2d 30 34 30 30 0a 54 6f 3a 0a 54 63 6c 12 -0400.To:.Tcl
00a0: 20 43 6f 72 65 20 4c 69 73 74 20 3c 74 63 6c 2d Core List <tcl-
00b0: 63 6f 72 65 2d 35 4e 57 47 4f 66 72 51 6d 6e 65 core-5NWGOfrQmne
00c0: 52 76 2b 4c 56 39 4d 58 35 75 69 70 78 6c 77 61 Rv+LV9MX5uipxlwa
00d0: 4f 56 51 35 66 40 70 75 62 6c 69 63 2e 67 6d 61 [email protected]
00e0: 6e 65 2e 6f 72 67 3e 0a 43 43 3a 0a 4f 7a 67 75 ne.org>.CC:.Ozgu
00f0: 72 20 44 6f 67 61 6e 20 55 67 75 72 6c 75 20 3c r Dogan Ugurlu <
0100: 64 6f 67 65 65 6e 2d 52 65 35 4a 51 45 65 51 71 dogeen-Re5JQEeQq
0110: 65 38 41 76 78 74 69 75 4d 77 78 33 77 40 70 75 e8AvxtiuMwx3w@pu
0120: 62 6c 69 63 2e 67 6d 61 6e 65 2e 6f 72 67 3e 0a blic.gmane.org>.
0130: 4e 65 77 73 67 72 6f 75 70 73 3a 0a 67 6d 61 6e Newsgroups:.gman
0140: 65 2e 63 6f 6d 70 2e 6c 61 6e 67 2e 74 63 6c 2e e.comp.lang.tcl.
0150: 63 6f 72 65 0a 0a 41 73 20 6d 6f 73 74 20 6f 66 core..As most of
0160: 20 79 6f 75 20 61 72 65 20 61 77 61 72 65 2c 20 you are aware,
0170: 49 27 76 65 20 62 65 65 6e 20 77 6f 72 6b 69 6e I've been workin
0180: 67 20 6f 6e 20 62 79 74 65 63 6f 64 65 20 73 61 g on bytecode sa
0190: 66 65 74 79 20 61 6e 61 6c 79 73 69 73 0a 66 6f fety analysis.fo
01a0: 72 20 54 41 4c 2e 20 49 20 73 74 61 72 74 65 64 r TAL. I started
01b0: 20 74 68 61 74 20 70 72 6f 6a 65 63 74 20 73 69 that project si
01c0: 6d 70 6c 79 20 62 65 63 61 75 73 65 20 69 74 20 mply because it
01d0: 63 61 6d 65 20 61 73 20 61 20 73 69 64 65 20 65 came as a side e
01e0: 66 66 65 63 74 0a 6f 66 20 74 68 65 20 66 61 63 ffect.of the fac
01f0: 74 20 74 68 61 74 20 61 20 42 79 74 65 63 6f 64 t that a Bytecod
0200: 65 20 6f 62 6a 65 63 74 20 68 61 73 20 74 6f 20 e object has to
0210: 61 73 73 65 72 74 20 74 68 65 20 73 74 61 63 6b assert the stack
0220: 20 64 65 70 74 68 20 61 6e 64 0a 65 78 63 65 70 depth and.excep
0230: 74 69 6f 6e 20 72 61 6e 67 65 20 64 65 70 74 68 tion range depth
0240: 20 74 68 61 74 20 6d 69 67 68 74 20 61 70 70 65 that might appe
0250: 61 72 20 69 6e 73 69 64 65 20 69 74 2c 20 62 75 ar inside it, bu
0260: 74 20 69 74 20 6e 6f 77 20 73 65 65 6d 73 20 74 t it now seems t
0270: 68 61 74 0a 74 68 65 20 67 72 65 61 74 65 73 74 hat.the greatest
0280: 20 76 61 6c 75 65 20 6f 66 20 74 68 65 20 70 72 value of the pr
0290: 6f 6a 65 63 74 20 63 6f 6d 65 73 20 66 72 6f 6d oject comes from
02a0: 20 74 68 65 20 66 61 63 74 20 74 68 61 74 20 74 the fact that t
02b0: 68 65 20 61 74 74 65 6d 70 74 73 0a 61 74 20 73 he attempts.at s
02c0: 61 66 65 74 79 20 61 6e 61 6c 79 73 69 73 20 61 afety analysis a
02d0: 72 65 20 65 78 70 6f 73 69 6e 67 20 62 79 74 65 re exposing byte
02e0: 63 6f 64 65 20 63 6f 6d 70 69 6c 61 74 69 6f 6e code compilation
02f0: 20 62 75 67 73 2e 0a 0a 54 68 65 20 6c 61 74 65 bugs...The late
0300: 73 74 20 6e 61 73 74 79 20 62 75 67 20 69 73 20 st nasty bug is
0310: 6e 75 6d 62 65 72 20 33 30 39 38 33 30 32 2e 20 number 3098302.
0320: 20 54 68 65 20 6f 66 66 65 6e 64 69 6e 67 20 63 The offending c
0330: 6f 64 65 20 69 73 20 66 61 69 72 6c 79 0a 73 69 ode is fairly.si
0340: 6d 70 6c 65 3a 0a 0a 70 72 6f 63 20 66 61 69 6c mple:..proc fail
0350: 74 72 61 63 65 20 7b 6e 31 20 6e 32 20 6f 70 7d trace {n1 n2 op}
0360: 20 7b 0a 20 20 20 20 20 72 65 74 75 72 6e 20 2d {. return -
0370: 63 6f 64 65 20 65 72 72 6f 72 20 22 74 72 61 63 code error "trac
0380: 65 20 6f 6e 20 24 6e 31 20 66 61 69 6c 73 20 62 e on $n1 fails b
0390: 79 20 72 65 71 75 65 73 74 22 0a 7d 0a 74 72 61 y request".}.tra
03a0: 63 65 20 61 64 64 20 76 61 72 69 61 62 6c 65 20 ce add variable
03b0: 72 65 73 75 6c 74 31 20 77 72 69 74 65 20 66 61 result1 write fa
03c0: 69 6c 74 72 61 63 65 0a 0a 70 72 6f 63 20 78 20 iltrace..proc x
03d0: 7b 7d 20 7b 0a 20 20 20 20 20 76 61 72 69 61 62 {} {. variab
03e0: 6c 65 20 72 65 73 75 6c 74 31 0a 20 20 20 20 20 le result1.
03f0: 66 6f 72 20 7b 73 65 74 20 69 20 30 7d 20 7b 24 for {set i 0} {$
0400: 69 20 3c 20 31 30 30 7d 20 7b 69 6e 63 72 20 69 i < 100} {incr i
0410: 7d 20 7b 0a 09 73 65 74 20 73 74 61 74 75 73 32 } {..set status2
0420: 20 5b 63 61 74 63 68 20 7b 0a 09 20 20 20 20 73 [catch {.. s
0430: 65 74 20 73 74 61 74 75 73 31 20 5b 63 61 74 63 et status1 [catc
0440: 68 20 7b 0a 09 09 72 65 74 75 72 6e 20 2d 63 6f h {...return -co
0450: 64 65 20 65 72 72 6f 72 20 2d 6c 65 76 65 6c 20 de error -level
0460: 30 20 22 6f 72 69 67 69 6e 61 6c 20 66 61 69 6c 0 "original fail
0470: 75 72 65 22 0a 09 20 20 20 20 7d 20 72 65 73 75 ure".. } resu
0480: 6c 74 31 20 6f 70 74 69 6f 6e 73 31 5d 0a 09 7d lt1 options1]..}
0490: 20 72 65 73 75 6c 74 32 20 6f 70 74 69 6f 6e 73 result2 options
04a0: 32 5d 0a 09 6c 61 70 70 65 6e 64 20 72 65 74 76 2]..lappend retv
04b0: 61 6c 20 24 73 74 61 74 75 73 32 20 24 72 65 73 al $status2 $res
04c0: 75 6c 74 32 20 24 6f 70 74 69 6f 6e 73 32 0a 20 ult2 $options2.
04d0: 20 20 20 20 7d 0a 7d 0a 0a 70 75 74 73 20 5b 78 }.}..puts [x
04e0: 5d 0a 0a 54 6f 20 73 65 65 20 77 68 61 74 27 73 ]..To see what's
04f0: 20 67 6f 69 6e 67 20 6f 6e 20 68 65 72 65 2c 20 going on here,
0500: 69 74 20 68 65 6c 70 73 20 74 6f 20 6c 6f 6f 6b it helps to look
0510: 20 61 74 20 74 68 65 20 67 65 6e 65 72 61 74 65 at the generate
0520: 64 0a 62 79 74 65 63 6f 64 65 20 66 6f 72 20 74 d.bytecode for t
0530: 68 65 20 6e 65 73 74 65 64 20 5b 63 61 74 63 68 he nested [catch
0540: 5d 65 73 2e 20 20 28 54 68 65 20 5b 66 6f 72 5d ]es. (The [for]
0550: 20 6c 6f 6f 70 20 69 73 20 69 6d 6d 61 74 65 72 loop is immater
0560: 69 61 6c 3b 20 69 74 27 73 0a 74 68 65 72 65 20 ial; it's.there
0570: 6f 6e 6c 79 20 62 65 63 61 75 73 65 20 74 68 65 only because the
0580: 20 6f 66 66 65 6e 64 69 6e 67 20 63 6f 64 65 20 offending code
0590: 64 6f 65 73 6e 27 74 20 6f 66 66 65 6e 64 20 62 doesn't offend b
05a0: 61 64 6c 79 20 65 6e 6f 75 67 68 20 74 6f 0a 63 adly enough to.c
05b0: 61 75 73 65 20 61 20 54 63 6c 5f 50 61 6e 69 63 ause a Tcl_Panic
05c0: 20 6f 6e 20 74 68 65 20 66 69 72 73 74 20 72 6f on the first ro
05d0: 75 6e 64 2e 29 20 49 20 69 6e 63 6c 75 64 65 20 und.) I include
05e0: 69 74 73 20 64 69 73 61 73 73 65 6d 62 6c 79 0a its disassembly.
05f0: 62 65 6c 6f 77 2e 0a 0a 54 68 65 20 6b 65 79 20 below...The key
0600: 73 65 71 75 65 6e 63 65 20 6f 66 20 65 76 65 6e sequence of even
0610: 74 73 20 69 73 3a 0a 0a 57 65 20 65 6e 74 65 72 ts is:..We enter
0620: 20 74 68 65 20 6f 75 74 65 72 20 5b 63 61 74 63 the outer [catc
0630: 68 5d 20 61 74 20 70 63 20 32 39 2c 20 61 6e 64 h] at pc 29, and
0640: 20 70 75 73 68 20 61 6e 20 65 78 63 65 70 74 69 push an excepti
0650: 6f 6e 20 63 6f 6e 74 65 78 74 0a 61 74 20 70 63 on context.at pc
0660: 20 33 38 2e 0a 0a 49 6d 6d 65 64 69 61 74 65 6c 38...Immediatel
0670: 79 2c 20 77 65 20 65 6e 74 65 72 20 74 68 65 20 y, we enter the
0680: 69 6e 6e 65 72 20 63 61 74 63 68 20 61 74 20 70 inner catch at p
0690: 63 20 34 33 20 61 6e 64 20 70 75 73 68 20 61 6e c 43 and push an
06a0: 6f 74 68 65 72 0a 65 78 63 65 70 74 69 6f 6e 20 other.exception
06b0: 63 6f 6e 74 65 78 74 20 61 74 20 70 63 20 35 32 context at pc 52
06c0: 2e 0a 0a 54 68 65 20 63 6f 64 65 62 75 72 73 74 ...The codeburst
06d0: 20 66 72 6f 6d 20 35 37 2d 37 30 20 74 68 72 6f from 57-70 thro
06e0: 77 73 20 61 6e 20 65 78 63 65 70 74 69 6f 6e 20 ws an exception
06f0: 77 69 74 68 20 74 68 65 20 27 72 65 74 75 72 6e with the 'return
0700: 49 6d 6d 20 31 20 30 27 0a 61 74 20 70 63 20 37 Imm 1 0'.at pc 7
0710: 30 2e 20 20 54 68 65 20 69 6e 6e 65 72 6d 6f 73 0. The innermos
0720: 74 20 65 78 63 65 70 74 69 6f 6e 20 72 61 6e 67 t exception rang
0730: 65 20 61 74 20 70 63 20 37 30 20 69 73 20 72 61 e at pc 70 is ra
0740: 6e 67 65 20 33 2c 20 61 6e 64 0a 65 78 65 63 75 nge 3, and.execu
0750: 74 69 6f 6e 20 70 72 6f 63 65 65 64 73 20 74 6f tion proceeds to
0760: 20 70 63 20 39 36 2e 0a 0a 39 36 2d 39 37 20 70 pc 96...96-97 p
0770: 75 73 68 20 72 65 74 75 72 6e 4f 70 74 73 20 61 ush returnOpts a
0780: 6e 64 20 72 65 73 75 6c 74 20 74 6f 20 74 68 65 nd result to the
0790: 20 73 74 61 63 6b 2e 20 20 39 38 20 74 72 69 65 stack. 98 trie
07a0: 73 20 74 6f 20 73 74 6f 72 65 20 74 68 65 0a 72 s to store the.r
07b0: 65 73 75 6c 74 20 69 6e 20 27 72 65 73 75 6c 74 esult in 'result
07c0: 31 27 2c 20 61 6e 64 20 74 68 65 20 72 65 73 75 1', and the resu
07d0: 6c 74 20 69 73 20 61 20 66 61 69 6c 65 64 20 74 lt is a failed t
07e0: 72 61 63 65 20 61 6e 64 20 61 20 6e 65 77 0a 65 race and a new.e
07f0: 78 63 65 70 74 69 6f 6e 2e 20 54 68 65 20 69 6e xception. The in
0800: 6e 65 72 6d 6f 73 74 20 65 78 63 65 70 74 69 6f nermost exceptio
0810: 6e 20 72 61 6e 67 65 20 61 74 20 70 63 20 39 38 n range at pc 98
0820: 20 69 73 20 72 61 6e 67 65 20 32 2c 20 61 6e 64 is range 2, and
0830: 0a 65 78 65 63 75 74 69 6f 6e 20 70 72 6f 63 65 .execution proce
0840: 65 64 73 20 74 6f 20 70 63 20 31 32 35 2e 0a 0a eds to pc 125...
0850: 54 68 65 20 63 6f 64 65 20 62 75 72 73 74 20 66 The code burst f
0860: 72 6f 6d 20 31 32 35 20 74 6f 20 31 33 33 20 70 rom 125 to 133 p
0870: 72 6f 63 65 65 64 73 20 6e 6f 72 6d 61 6c 6c 79 roceeds normally
0880: 2c 20 73 63 61 76 65 6e 67 69 6e 67 20 72 65 73 , scavenging res
0890: 75 6c 74 2c 0a 72 65 74 75 72 6e 20 6f 70 74 69 ult,.return opti
08a0: 6f 6e 73 20 61 6e 64 20 72 65 74 75 72 6e 20 63 ons and return c
08b0: 6f 64 65 2e 20 41 74 20 31 33 34 2c 20 77 65 20 ode. At 134, we
08c0: 70 6f 70 20 61 6e 20 65 78 63 65 70 74 69 6f 6e pop an exception
08d0: 20 63 6f 6e 74 65 78 74 2c 0a 77 68 69 63 68 20 context,.which
08e0: 69 73 20 74 68 65 20 6f 6e 65 20 74 68 61 74 20 is the one that
08f0: 77 61 73 20 70 75 73 68 65 64 20 61 74 20 35 32 was pushed at 52
0900: 2e 0a 0a 41 6e 64 20 77 65 27 76 65 20 6c 65 66 ...And we've lef
0910: 74 20 74 68 65 20 6f 75 74 65 72 20 5b 63 61 74 t the outer [cat
0920: 63 68 5d 2c 20 77 69 74 68 20 61 6e 20 65 78 63 ch], with an exc
0930: 65 70 74 69 6f 6e 20 63 6f 6e 74 65 78 74 20 73 eption context s
0940: 74 69 6c 6c 0a 6f 6e 20 74 68 65 20 73 74 61 63 till.on the stac
0950: 6b 20 28 61 6e 64 20 74 68 65 20 73 74 61 63 6b k (and the stack
0960: 20 70 6f 69 6e 74 65 72 20 69 6e 20 74 68 65 20 pointer in the
0970: 77 72 6f 6e 67 20 70 6c 61 63 65 2c 20 73 69 6e wrong place, sin
0980: 63 65 20 77 65 0a 72 65 73 74 6f 72 65 64 20 69 ce we.restored i
0990: 74 20 66 72 6f 6d 20 74 68 65 20 77 72 6f 6e 67 t from the wrong
09a0: 20 63 6f 6e 74 65 78 74 29 2e 20 20 43 72 61 73 context). Cras
09b0: 68 2e 0a 0a 4f 4b 2c 20 6e 6f 77 2c 20 77 68 61 h...OK, now, wha
09c0: 74 20 74 6f 20 64 6f 20 61 62 6f 75 74 20 74 68 t to do about th
09d0: 69 73 3f 0a 0a 41 72 67 75 61 62 6c 79 2c 20 74 is?..Arguably, t
09e0: 68 65 20 62 79 74 65 63 6f 64 65 20 63 6f 6d 70 he bytecode comp
09f0: 69 6c 65 72 20 66 6f 72 20 5b 63 61 74 63 68 5d iler for [catch]
0a00: 20 69 73 20 66 61 69 6c 69 6e 67 20 74 6f 20 66 is failing to f
0a10: 6f 6c 6c 6f 77 0a 74 68 65 20 72 75 6c 65 73 20 ollow.the rules
0a20: 62 79 20 68 61 76 69 6e 67 20 69 6e 73 74 72 75 by having instru
0a30: 63 74 69 6f 6e 73 20 62 65 74 77 65 65 6e 20 62 ctions between b
0a40: 65 67 69 6e 43 61 74 63 68 20 61 6e 64 20 65 6e eginCatch and en
0a50: 64 43 61 74 63 68 0a 74 68 61 74 20 61 72 65 20 dCatch.that are
0a60: 6f 75 74 73 69 64 65 20 74 68 65 20 65 78 63 65 outside the exce
0a70: 70 74 69 6f 6e 20 72 61 6e 67 65 2e 20 4e 61 75 ption range. Nau
0a80: 67 68 74 79 20 5b 63 61 74 63 68 5d 2c 20 6e 6f ghty [catch], no
0a90: 20 63 6f 6f 6b 69 65 21 0a 0a 42 75 74 20 74 68 cookie!..But th
0aa0: 61 74 27 73 20 74 6f 6f 20 73 69 6d 70 6c 69 73 at's too simplis
0ab0: 74 69 63 20 61 20 73 74 6f 72 79 2e 20 20 41 73 tic a story. As
0ac0: 73 75 6d 65 20 74 68 61 74 20 77 65 20 77 65 72 sume that we wer
0ad0: 65 20 74 6f 20 65 78 74 65 6e 64 0a 74 68 65 20 e to extend.the
0ae0: 65 78 63 65 70 74 69 6f 6e 20 72 61 6e 67 65 20 exception range
0af0: 74 6f 20 65 6e 63 6f 6d 70 61 73 73 20 74 68 65 to encompass the
0b00: 20 63 6f 64 65 20 66 72 6f 6d 20 39 36 2d 31 30 code from 96-10
0b10: 34 2e 20 57 68 61 74 20 77 6f 75 6c 64 0a 68 61 4. What would.ha
0b20: 70 70 65 6e 20 74 68 65 6e 3f 20 54 68 65 20 66 ppen then? The f
0b30: 61 69 6c 65 64 20 27 73 74 6f 72 65 53 63 61 6c ailed 'storeScal
0b40: 61 72 27 20 69 6e 74 6f 20 27 72 65 73 75 6c 74 ar' into 'result
0b50: 31 27 20 77 6f 75 6c 64 20 62 65 0a 74 61 6b 65 1' would be.take
0b60: 20 65 78 65 63 75 74 69 6f 6e 20 62 61 63 6b 20 execution back
0b70: 74 6f 20 39 36 20 2d 20 77 69 74 68 20 73 65 76 to 96 - with sev
0b80: 65 72 61 6c 20 61 64 64 69 74 69 6f 6e 61 6c 20 eral additional
0b90: 65 6c 65 6d 65 6e 74 73 20 6f 6e 0a 74 68 65 20 elements on.the
0ba0: 6f 70 65 72 61 6e 64 20 73 74 61 63 6b 2e 20 54 operand stack. T
0bb0: 68 65 20 63 6f 64 65 20 73 74 61 72 74 69 6e 67 he code starting
0bc0: 20 61 74 20 39 36 20 77 6f 75 6c 64 20 61 67 61 at 96 would aga
0bd0: 69 6e 20 74 72 79 20 74 6f 0a 73 74 6f 72 65 20 in try to.store
0be0: 74 6f 20 27 72 65 73 75 6c 74 31 27 2c 20 65 6e to 'result1', en
0bf0: 63 6f 75 6e 74 65 72 69 6e 67 20 74 68 65 20 73 countering the s
0c00: 61 6d 65 20 65 72 72 6f 72 2c 20 61 6e 64 20 67 ame error, and g
0c10: 6f 69 6e 67 20 62 61 63 6b 20 74 6f 0a 39 36 20 oing back to.96
0c20: 61 67 61 69 6e 20 69 6e 20 61 6e 20 69 6e 66 69 again in an infi
0c30: 6e 69 74 65 20 6c 6f 6f 70 20 63 6f 6e 73 75 6d nite loop consum
0c40: 69 6e 67 20 6f 70 65 72 61 6e 64 20 73 74 61 63 ing operand stac
0c50: 6b 20 73 70 61 63 65 2e 20 41 6e 6f 74 68 65 72 k space. Another
0c60: 0a 63 72 61 73 68 2e 0a 0a 50 75 74 74 69 6e 67 .crash...Putting
0c70: 20 74 68 65 20 65 6e 74 69 72 65 20 63 6f 64 65 the entire code
0c80: 20 62 75 72 73 74 20 61 66 74 65 72 20 74 68 65 burst after the
0c90: 20 27 65 6e 64 43 61 74 63 68 27 20 69 73 20 6e 'endCatch' is n
0ca0: 6f 20 62 65 74 74 65 72 2e 0a 54 68 65 20 70 72 o better..The pr
0cb0: 6f 62 6c 65 6d 20 68 65 72 65 20 69 73 20 74 68 oblem here is th
0cc0: 61 74 20 27 65 6e 64 43 61 74 63 68 27 20 28 6e at 'endCatch' (n
0cd0: 65 63 65 73 73 61 72 69 6c 79 29 20 72 65 73 65 ecessarily) rese
0ce0: 74 73 20 74 68 65 20 69 6e 74 65 72 70 72 65 74 ts the interpret
0cf0: 65 72 0a 72 65 73 75 6c 74 2c 20 73 6f 20 27 70 er.result, so 'p
0d00: 75 73 68 52 65 73 75 6c 74 27 2c 20 27 70 75 73 ushResult', 'pus
0d10: 68 52 65 74 75 72 6e 43 6f 64 65 27 20 61 6e 64 hReturnCode' and
0d20: 20 27 70 75 73 68 52 65 74 75 72 6e 4f 70 74 69 'pushReturnOpti
0d30: 6f 6e 73 27 0a 77 69 6c 6c 20 61 6c 6c 20 73 69 ons'.will all si
0d40: 6d 70 6c 79 20 66 69 6e 64 20 61 6e 20 65 6d 70 mply find an emp
0d50: 74 79 20 72 65 73 75 6c 74 20 61 6e 64 20 61 20 ty result and a
0d60: 54 43 4c 5f 4f 4b 20 72 65 74 75 72 6e 20 63 6f TCL_OK return co
0d70: 64 65 2e 0a 0a 53 6f 20 77 65 20 6e 65 65 64 20 de...So we need
0d80: 74 6f 20 68 61 76 65 20 74 68 65 20 27 70 75 73 to have the 'pus
0d90: 68 52 65 73 75 6c 74 27 2c 20 27 70 75 73 68 52 hResult', 'pushR
0da0: 65 74 75 72 6e 43 6f 64 65 27 20 61 6e 64 0a 27 eturnCode' and.'
0db0: 70 75 73 68 52 65 74 75 72 6e 4f 70 74 69 6f 6e pushReturnOption
0dc0: 73 27 20 62 65 66 6f 72 65 20 74 68 65 20 27 65 s' before the 'e
0dd0: 6e 64 43 61 74 63 68 27 20 62 75 74 20 74 68 65 ndCatch' but the
0de0: 20 27 73 74 6f 72 65 53 63 61 6c 61 72 27 0a 69 'storeScalar'.i
0df0: 6e 73 74 72 75 63 74 69 6f 6e 73 20 61 66 74 65 nstructions afte
0e00: 72 20 69 74 2e 20 28 49 74 20 6c 6f 6f 6b 73 20 r it. (It looks
0e10: 70 6f 73 73 69 62 6c 65 20 74 6f 20 72 65 6f 72 possible to reor
0e20: 64 65 72 20 74 68 65 20 63 6f 64 65 0a 74 6f 20 der the code.to
0e30: 6d 61 6b 65 20 69 74 20 68 61 70 70 65 6e 2e 29 make it happen.)
0e40: 20 53 69 6e 63 65 20 27 70 75 73 68 52 65 73 75 Since 'pushResu
0e50: 6c 74 27 2c 20 27 70 75 73 68 52 65 74 75 72 6e lt', 'pushReturn
0e60: 43 6f 64 65 27 20 61 6e 64 0a 27 70 75 73 68 52 Code' and.'pushR
0e70: 65 74 75 72 6e 4f 70 74 69 6f 6e 73 27 20 63 61 eturnOptions' ca
0e80: 6e 6e 6f 74 20 74 68 72 6f 77 2c 20 69 74 20 69 nnot throw, it i
0e90: 73 20 69 6d 6d 61 74 65 72 69 61 6c 20 77 68 65 s immaterial whe
0ea0: 74 68 65 72 20 74 68 65 79 0a 61 72 65 20 69 6e ther they.are in
0eb0: 73 69 64 65 20 6f 72 20 6f 75 74 73 69 64 65 20 side or outside
0ec0: 74 68 65 20 65 78 63 65 70 74 69 6f 6e 20 72 61 the exception ra
0ed0: 6e 67 65 2e 0a 0a 4e 6f 77 2c 20 68 6f 77 20 64 nge...Now, how d
0ee0: 6f 20 77 65 20 66 6f 72 6d 75 6c 61 74 65 20 74 o we formulate t
0ef0: 68 69 73 20 69 6e 74 6f 20 61 20 67 65 6e 65 72 his into a gener
0f00: 61 6c 20 73 61 66 65 74 79 20 72 75 6c 65 3f 20 al safety rule?
0f10: 49 27 64 0a 70 72 6f 70 6f 73 65 20 70 65 72 68 I'd.propose perh
0f20: 61 70 73 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e aps the followin
0f30: 67 3a 0a 0a 28 61 29 20 43 6f 64 65 20 72 65 61 g:..(a) Code rea
0f40: 63 68 61 62 6c 65 20 66 72 6f 6d 20 27 62 65 67 chable from 'beg
0f50: 69 6e 43 61 74 63 68 27 20 74 68 61 74 20 64 6f inCatch' that do
0f60: 65 73 20 6e 6f 74 20 70 61 73 73 20 74 68 72 6f es not pass thro
0f70: 75 67 68 0a 20 20 20 20 20 61 20 6d 61 74 63 68 ugh. a match
0f80: 69 6e 67 20 27 65 6e 64 43 61 74 63 68 27 20 6d ing 'endCatch' m
0f90: 61 79 20 62 65 20 69 6e 73 69 64 65 20 6f 72 20 ay be inside or
0fa0: 6f 75 74 73 69 64 65 20 74 68 65 20 65 78 63 65 outside the exce
0fb0: 70 74 69 6f 6e 0a 20 20 20 20 20 72 61 6e 67 65 ption. range
0fc0: 2e 0a 28 62 29 20 43 6f 64 65 20 6f 75 74 73 69 ..(b) Code outsi
0fd0: 64 65 20 74 68 65 20 65 78 63 65 70 74 69 6f 6e de the exception
0fe0: 20 72 61 6e 67 65 2c 20 74 68 61 74 20 69 73 20 range, that is
0ff0: 72 65 61 63 68 61 62 6c 65 20 66 72 6f 6d 0a 20 reachable from.
1000: 20 20 20 20 27 62 65 67 69 6e 43 61 74 63 68 27 'beginCatch'
1010: 2c 20 61 6e 64 20 6e 6f 74 20 72 65 61 63 68 61 , and not reacha
1020: 62 6c 65 20 66 72 6f 6d 20 74 68 65 20 65 78 63 ble from the exc
1030: 65 70 74 69 6f 6e 20 72 61 6e 67 65 2c 0a 20 20 eption range,.
1040: 20 20 20 69 73 20 27 62 65 66 6f 72 65 27 20 74 is 'before' t
1050: 68 65 20 63 61 74 63 68 2e 20 53 75 63 68 20 63 he catch. Such c
1060: 6f 64 65 20 6d 61 79 20 75 73 65 20 6f 6e 6c 79 ode may use only
1070: 20 27 6e 6f 6e 74 68 72 6f 77 69 6e 67 27 0a 20 'nonthrowing'.
1080: 20 20 20 20 69 6e 73 74 72 75 63 74 69 6f 6e 73 instructions
1090: 2e 0a 28 63 29 20 43 6f 64 65 20 6f 75 74 73 69 ..(c) Code outsi
10a0: 64 65 20 74 68 65 20 65 78 63 65 70 74 69 6f 6e de the exception
10b0: 20 72 61 6e 67 65 20 74 68 61 74 20 69 73 20 72 range that is r
10c0: 65 61 63 68 61 62 6c 65 20 66 72 6f 6d 20 69 6e eachable from in
10d0: 73 69 64 65 0a 20 20 20 20 20 74 68 65 20 65 78 side. the ex
10e0: 63 65 70 74 69 6f 6e 20 72 61 6e 67 65 20 69 73 ception range is
10f0: 20 27 61 66 74 65 72 27 20 74 68 65 20 63 61 74 'after' the cat
1100: 63 68 20 61 6e 64 20 6d 61 79 20 75 73 65 20 6f ch and may use o
1110: 6e 6c 79 0a 20 20 20 20 20 27 6e 6f 6e 74 68 72 nly. 'nonthr
1120: 6f 77 69 6e 67 27 20 69 6e 73 74 72 75 63 74 69 owing' instructi
1130: 6f 6e 73 2e 0a 28 64 29 20 54 68 65 20 70 63 20 ons..(d) The pc
1140: 74 68 61 74 20 69 73 20 74 68 65 20 65 78 63 65 that is the exce
1150: 70 74 69 6f 6e 20 72 61 6e 67 65 27 73 20 74 61 ption range's ta
1160: 72 67 65 74 2c 20 61 6e 64 20 61 6c 6c 20 63 6f rget, and all co
1170: 64 65 0a 20 20 20 20 20 72 65 61 63 68 61 62 6c de. reachabl
1180: 65 20 66 72 6f 6d 20 74 68 65 72 65 2c 20 69 73 e from there, is
1190: 20 61 6c 73 6f 20 27 61 66 74 65 72 27 20 74 68 also 'after' th
11a0: 65 20 63 61 74 63 68 2e 0a 28 65 29 20 49 74 20 e catch..(e) It
11b0: 69 73 20 70 65 72 6d 69 73 73 69 62 6c 65 20 66 is permissible f
11c0: 6f 72 20 63 6f 6e 74 72 6f 6c 20 74 6f 20 62 61 or control to ba
11d0: 73 73 20 66 72 6f 6d 20 27 62 65 66 6f 72 65 27 ss from 'before'
11e0: 20 74 6f 20 27 77 69 74 68 69 6e 27 0a 20 20 20 to 'within'.
11f0: 20 20 61 6e 64 20 66 72 6f 6d 20 27 77 69 74 68 and from 'with
1200: 69 6e 27 20 74 6f 20 27 61 66 74 65 72 27 2c 20 in' to 'after',
1210: 62 75 74 20 6e 6f 74 20 69 6e 20 74 68 65 20 72 but not in the r
1220: 65 76 65 72 73 65 20 64 69 72 65 63 74 69 6f 6e everse direction
1230: 2e 0a 0a 54 68 65 20 27 6e 6f 6e 74 68 72 6f 77 ...The 'nonthrow
1240: 69 6e 67 27 20 69 6e 73 74 72 75 63 74 69 6f 6e ing' instruction
1250: 73 20 63 6f 6d 70 72 69 73 65 3a 20 70 75 73 68 s comprise: push
1260: 2c 20 70 6f 70 2c 20 64 75 70 2c 20 6f 76 65 72 , pop, dup, over
1270: 2c 0a 72 65 76 65 72 73 65 2c 20 6a 75 6d 70 31 ,.reverse, jump1
1280: 2c 20 6a 75 6d 70 34 2c 20 6a 75 6d 70 54 61 62 , jump4, jumpTab
1290: 6c 65 2c 20 72 65 74 75 72 6e 43 6f 64 65 42 72 le, returnCodeBr
12a0: 61 6e 63 68 2c 20 61 6e 64 0a 6f 66 20 63 6f 75 anch, and.of cou
12b0: 72 73 65 20 27 65 6e 64 43 61 74 63 68 27 20 28 rse 'endCatch' (
12c0: 77 68 69 63 68 20 72 65 73 74 6f 72 65 73 20 74 which restores t
12d0: 68 65 20 65 78 63 65 70 74 69 6f 6e 20 63 6f 6e he exception con
12e0: 74 65 78 74 29 2e 0a 0a 4d 79 20 74 77 6f 20 71 text)...My two q
12f0: 75 65 73 74 69 6f 6e 73 20 66 6f 72 20 74 68 65 uestions for the
1300: 20 74 65 61 6d 20 61 72 65 3a 0a 0a 28 31 29 20 team are:..(1)
1310: 49 73 20 74 68 69 73 20 61 20 72 65 61 73 6f 6e Is this a reason
1320: 61 62 6c 65 20 73 74 61 74 65 20 6f 66 20 63 6f able state of co
1330: 6e 73 74 72 61 69 6e 74 73 20 66 6f 72 20 74 68 nstraints for th
1340: 65 20 63 6f 6d 70 69 6c 65 72 73 0a 20 20 20 20 e compilers.
1350: 20 74 6f 20 6c 69 76 65 20 77 69 74 68 3f 0a 28 to live with?.(
1360: 32 29 20 49 73 20 74 68 69 73 20 73 65 74 20 6f 2) Is this set o
1370: 66 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 74 68 f constraints th
1380: 65 20 72 69 67 68 74 20 6f 6e 65 20 74 6f 20 65 e right one to e
1390: 6e 73 75 72 65 20 74 68 61 74 0a 20 20 20 20 20 nsure that.
13a0: 77 65 20 64 6f 6e 27 74 20 73 6d 61 73 68 20 74 we don't smash t
13b0: 68 65 20 65 78 63 65 70 74 69 6f 6e 20 73 74 61 he exception sta
13c0: 63 6b 3f 0a 0a 49 20 61 6d 20 70 75 72 70 6f 73 ck?..I am purpos
13d0: 65 6c 79 20 69 67 6e 6f 72 69 6e 67 20 27 6c 6f ely ignoring 'lo
13e0: 6f 70 27 20 65 78 63 65 70 74 69 6f 6e 20 72 61 op' exception ra
13f0: 6e 67 65 73 20 66 6f 72 20 74 68 65 20 6d 6f 6d nges for the mom
1400: 65 6e 74 2e 0a 54 68 6f 73 65 20 68 61 76 65 20 ent..Those have
1410: 74 68 65 69 72 20 6f 77 6e 20 62 75 67 73 20 28 their own bugs (
1420: 6e 6f 74 61 62 6c 79 20 32 38 33 35 33 31 33 29 notably 2835313)
1430: 2c 20 62 75 74 20 49 27 6d 20 63 68 61 73 69 6e , but I'm chasin
1440: 67 20 6f 6e 65 0a 73 65 74 20 6f 66 20 69 73 73 g one.set of iss
1450: 75 65 73 20 61 74 20 61 20 74 69 6d 65 2e 0a 0a ues at a time...
1460: 2d 2d 20 37 33 20 64 65 20 6b 65 39 74 76 2f 32 -- 73 de ke9tv/2
1470: 2c 20 4b 65 76 69 6e 20 0a , Kevin .