decompile_py_mid.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. from evaluator import *
  2. DESCRIPTION = "Test if the model can disassemble Python bytecode and create a function that returns a list of prime numbers and their negations."
  3. TAGS = ['code', 'python']
  4. question = """
  5. Disassemble the following python into a function called foo:
  6. 5 0 BUILD_LIST 0
  7. 2 STORE_FAST 1 (primes)
  8. 6 4 LOAD_GLOBAL 0 (range)
  9. 6 LOAD_CONST 1 (2)
  10. 8 LOAD_FAST 0 (max_number)
  11. 10 LOAD_CONST 2 (1)
  12. 12 BINARY_ADD
  13. 14 CALL_FUNCTION 2
  14. 16 GET_ITER
  15. >> 18 FOR_ITER 94 (to 114)
  16. 20 STORE_FAST 2 (possible_prime)
  17. 7 22 LOAD_CONST 3 (True)
  18. 24 STORE_FAST 3 (is_prime)
  19. 9 26 LOAD_GLOBAL 0 (range)
  20. 28 LOAD_CONST 1 (2)
  21. 30 LOAD_GLOBAL 1 (int)
  22. 32 LOAD_FAST 2 (possible_prime)
  23. 34 LOAD_CONST 4 (0.5)
  24. 36 BINARY_POWER
  25. 38 CALL_FUNCTION 1
  26. 40 LOAD_CONST 2 (1)
  27. 42 BINARY_ADD
  28. 44 CALL_FUNCTION 2
  29. 46 GET_ITER
  30. >> 48 FOR_ITER 24 (to 74)
  31. 50 STORE_FAST 4 (num)
  32. 10 52 LOAD_FAST 2 (possible_prime)
  33. 54 LOAD_FAST 4 (num)
  34. 56 BINARY_MODULO
  35. 58 LOAD_CONST 5 (0)
  36. 60 COMPARE_OP 2 (==)
  37. 62 POP_JUMP_IF_FALSE 48
  38. 11 64 LOAD_CONST 6 (False)
  39. 66 STORE_FAST 3 (is_prime)
  40. 12 68 POP_TOP
  41. 70 JUMP_ABSOLUTE 74
  42. 72 JUMP_ABSOLUTE 48
  43. 13 >> 74 LOAD_FAST 3 (is_prime)
  44. 76 POP_JUMP_IF_FALSE 18
  45. 14 78 LOAD_FAST 1 (primes)
  46. 80 LOAD_METHOD 2 (append)
  47. 82 LOAD_FAST 2 (possible_prime)
  48. 84 CALL_METHOD 1
  49. 86 POP_TOP
  50. 16 88 LOAD_FAST 2 (possible_prime)
  51. 90 LOAD_CONST 1 (2)
  52. 92 BINARY_MODULO
  53. 94 LOAD_CONST 5 (0)
  54. 96 COMPARE_OP 3 (!=)
  55. 98 POP_JUMP_IF_FALSE 18
  56. 17 100 LOAD_FAST 1 (primes)
  57. 102 LOAD_METHOD 2 (append)
  58. 104 LOAD_FAST 2 (possible_prime)
  59. 106 UNARY_NEGATIVE
  60. 108 CALL_METHOD 1
  61. 110 POP_TOP
  62. 112 JUMP_ABSOLUTE 18
  63. 18 >> 114 LOAD_FAST 1 (primes)
  64. 116 RETURN_VALUE
  65. """
  66. test_case, answer = make_python_test([("foo(20)", "[2, 3, -3, 5, -5, 7, -7, 11, -11, 13, -13, 17, -17, 19, -19]")])
  67. TestDisasPrimes = question >> LLMRun() >> ExtractCode(keep_main=False) >> PythonRun(test_case) >> SubstringEvaluator(answer)
  68. if __name__ == "__main__":
  69. print(run_test(TestDisasPrimes))