Version 1 of tcl::unsupported::disassemble

Updated 2007-11-16 14:27:17 by dkf

The tcl::unsupported::disassemble command disassembles bytecode generted from procs, lambdas and general scripts.

tcl::unsupported::disassemble proc|lambda|script thingToDisassemble

Only present from Tcl 8.5. Does not disassemble things created by tbcload. Not present in safe interpreters. This command was developed during the Fourteenth Annual Tcl/Tk Conference (2007).

Example Output

% proc foo {x} {
   for {set y 0} {$y < $x} {incr y} {
      puts $x,$y
   }
}
% tcl::unsupported::disassemble proc foo
ByteCode 0x0x9a2ec58, refCt 1, epoch 1, interp 0x0x9a377d8 (epoch 1)
  Source "\n   for {set y 0} {$y < $x} {incr y} {\n      puts $x,$y"
  Cmds 4, src 61, inst 43, litObjs 4, aux 0, stkDepth 4, code/src 0.00
  Proc 0x0x9a48f70, refCt 1, args 1, compiled locals 2
      slot 0, scalar, arg, "x"
      slot 1, scalar, "y"
  Exception ranges 2, depth 1:
      0: level 0, loop, pc 7-18, continue 20, break 40
      1: level 0, loop, pc 20-31, continue -1, break 40
  Commands 4:
      1: pc 0-41, src 4-59         2: pc 0-3, src 9-15
      3: pc 7-18, src 45-54        4: pc 20-31, src 29-34
  Command 1: "for {set y 0} {$y < $x} {incr y} {\n      puts $x,$y\n   "
  Command 2: "set y 0"
    (0) push1 0         # "0"
    (2) storeScalar1 %v1        # var "y"
    (4) pop
    (5) jump1 +28       # pc 33
  Command 3: "puts $x,$y"
    (7) push1 1         # "puts"
    (9) loadScalar1 %v0         # var "x"
    (11) push1 2        # ","
    (13) loadScalar1 %v1        # var "y"
    (15) concat1 3
    (17) invokeStk1 2
    (19) pop
  Command 4: "incr y"
    (20) startCommand +12 1     # next cmd at pc 32
    (29) incrScalar1Imm %v1 +1  # var "y"
    (32) pop
    (33) loadScalar1 %v1        # var "y"
    (35) loadScalar1 %v0        # var "x"
    (37) lt
    (38) jumpTrue1 -31  # pc 7
    (40) push1 3        # ""
    (42) done