Guest User

Untitled

a guest
Jun 19th, 2017
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.25 KB | None | 0 0
  1. (defun normal-return (v) (1+ v))
  2. (disassemble 'normal-return)
  3. ;; =>
  4. ;; 0       dup
  5. ;; 1       add1
  6. ;; 2       return
  7.  
  8. (defun block-return (v)
  9.   (cl-block 'top
  10.     (cl-return-from 'top v)))
  11. (disassemble 'block-return)
  12. ;; =>
  13. ;; 0       constant  --cl-block-\(quote\ top\)--
  14. ;; 1       pushcatch 1
  15. ;; 4       constant  throw
  16. ;; 5       constant  --cl-block-\(quote\ top\)--
  17. ;; 6       stack-ref 2
  18. ;; 7       call      2
  19. ;; 8       pophandler
  20. ;; 9:1     return
  21. (defun other-cl-return (v) (cl-return v))
  22. ;; =>
  23. ;; ... same bytecode as in `block-return'.
  24.  
  25. (defun ret-in-while (v)
  26.   (dotimes (i 10)
  27.     (when (= v 20)
  28.       (cl-return "return-1")))
  29.   "return-2")
  30. (disassemble 'ret-in-while)
  31. ;; =>
  32. ;; 0       constant  10
  33. ;; 1       constant  0
  34. ;; 2:1     dup
  35. ;; 3       stack-ref 2
  36. ;; 4       lss
  37. ;; 5       goto-if-nil 3
  38. ;; 8       dup
  39. ;; 9       stack-ref 3
  40. ;; 10      constant  20
  41. ;; 11      eqlsign
  42. ;; 12      goto-if-nil 2
  43. ;; 15      constant  throw
  44. ;; 16      constant  --cl-block-nil--
  45. ;; 17      constant  "return-1"
  46. ;; 18      call      2
  47. ;; 19      discard
  48. ;; 20:2    discard
  49. ;; 21      dup
  50. ;; 22      add1
  51. ;; 23      stack-set 1
  52. ;; 25      goto      1
  53. ;; 28:3    discardN  2
  54. ;; 30      constant  "return-2"
  55. ;; 31      return
Advertisement
Add Comment
Please, Sign In to add comment