cmd_showbc.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. # cmdline: -v -v
  2. # test printing of all bytecodes
  3. def f():
  4. # constants
  5. a = None + False + True
  6. a = 0
  7. a = 1000
  8. a = -1000
  9. # constructing data
  10. a = 1
  11. b = (1, 2)
  12. c = [1, 2]
  13. d = {1, 2}
  14. e = {}
  15. f = {1:2}
  16. g = 'a'
  17. h = b'a'
  18. # unary/binary ops
  19. i = 1
  20. j = 2
  21. k = a + b
  22. l = -a
  23. m = not a
  24. m = a == b == c
  25. m = not (a == b and b == c)
  26. # attributes
  27. n = b.c
  28. b.c = n
  29. # subscript
  30. p = b[0]
  31. b[0] = p
  32. b[0] += p
  33. # slice
  34. a = b[::]
  35. # sequenc unpacking
  36. a, b = c
  37. a, *a = a
  38. # tuple swapping
  39. a, b = b, a
  40. a, b, c = c, b, a
  41. # del fast
  42. del a
  43. # globals
  44. global gl
  45. gl = a
  46. del gl
  47. # comprehensions
  48. a = (b for c in d if e)
  49. a = [b for c in d if e]
  50. a = {b:b for c in d if e}
  51. # function calls
  52. a()
  53. a(1)
  54. a(b=1)
  55. a(*b)
  56. # method calls
  57. a.b()
  58. a.b(1)
  59. a.b(c=1)
  60. a.b(*c)
  61. # jumps
  62. if a:
  63. x
  64. else:
  65. y
  66. while a:
  67. b
  68. while not a:
  69. b
  70. a = a or a
  71. # for loop
  72. for a in b:
  73. c
  74. # exceptions
  75. try:
  76. while a:
  77. break
  78. except:
  79. b
  80. finally:
  81. c
  82. while a:
  83. try:
  84. break
  85. except:
  86. pass
  87. # with
  88. with a:
  89. b
  90. # closed over variables
  91. x = 1
  92. def closure():
  93. a = x + 1
  94. x = 1
  95. del x
  96. # import
  97. import a
  98. from a import b
  99. from a import *
  100. # raise
  101. raise
  102. raise 1
  103. # return
  104. return
  105. return 1
  106. # function with lots of locals
  107. def f():
  108. l1 = l2 = l3 = l4 = l5 = l6 = l7 = l8 = l9 = l10 = 1
  109. m1 = m2 = m3 = m4 = m5 = m6 = m7 = m8 = m9 = m10 = 2
  110. l10 + m10
  111. # functions with default args
  112. def f(a=1):
  113. pass
  114. def f(b=2):
  115. return b + a
  116. # function which yields
  117. def f():
  118. yield
  119. yield 1
  120. yield from 1
  121. # class
  122. class Class:
  123. pass
  124. # delete name
  125. del Class
  126. # load super method
  127. def f(self):
  128. super().f()