Posted to tcl by mjanssen at Mon Jul 20 09:42:48 GMT 2020view raw

  1. proc run {program} {
  2. set pc 0
  3. while 1 {
  4. set cmd [lindex $program $pc]
  5. switch -exact $cmd {
  6. 0 {incr pc}
  7. 99 {break}
  8. }
  9. }
  10.  
  11. }
  12.  
  13. proc 0 {args} {
  14. return 1
  15. }
  16.  
  17. proc 99 {args} {
  18. return -code break
  19. }
  20.  
  21. proc run2 {program} {
  22. set pc 0
  23. while 1 {
  24. incr pc [{*}[lrange $program $pc end]]
  25. }
  26.  
  27. }
  28.  
  29.  
  30. set program [lrepeat 10000 0] ; set a 2
  31. lappend program 99 ; set a 2
  32.  
  33. time {run $program}
  34. time {run2 $program}