ceval.cpp 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085
  1. #include "pocketpy/ceval.h"
  2. namespace pkpy{
  3. #define PREDICT_INT_OP(op) \
  4. if(is_int(_0) && is_int(_1)){ \
  5. TOP() = VAR(_0.as<i64>() op _1.as<i64>()); \
  6. DISPATCH() \
  7. }
  8. #define PREDICT_INT_DIV_OP(op) \
  9. if(is_int(_0) && is_int(_1)){ \
  10. i64 divisor = _1.as<i64>(); \
  11. if(divisor == 0) ZeroDivisionError(); \
  12. TOP() = VAR(_0.as<i64>() op divisor); \
  13. DISPATCH() \
  14. }
  15. #define BINARY_F_COMPARE(func, op, rfunc) \
  16. PyVar ret; \
  17. const PyTypeInfo* _ti = _tp_info(_0); \
  18. if(_ti->m##func){ \
  19. ret = _ti->m##func(this, _0, _1); \
  20. }else{ \
  21. PyVar self; \
  22. PyVar _2 = get_unbound_method(_0, func, &self, false); \
  23. if(_2 != nullptr) ret = call_method(self, _2, _1); \
  24. else ret = NotImplemented; \
  25. } \
  26. if(is_not_implemented(ret)){ \
  27. PyVar self; \
  28. PyVar _2 = get_unbound_method(_1, rfunc, &self, false); \
  29. if(_2 != nullptr) ret = call_method(self, _2, _0); \
  30. else BinaryOptError(op, _0, _1); \
  31. if(is_not_implemented(ret)) BinaryOptError(op, _0, _1); \
  32. }
  33. void VM::__op_unpack_sequence(uint16_t arg){
  34. PyVar _0 = POPX();
  35. if(is_type(_0, VM::tp_tuple)){
  36. // fast path for tuple
  37. Tuple& tuple = PK_OBJ_GET(Tuple, _0);
  38. if(tuple.size() == arg){
  39. for(PyVar obj: tuple) PUSH(obj);
  40. }else{
  41. ValueError(_S("expected ", (int)arg, " values to unpack, got ", (int)tuple.size()));
  42. }
  43. }else{
  44. auto _lock = heap.gc_scope_lock(); // lock the gc via RAII!!
  45. _0 = py_iter(_0);
  46. const PyTypeInfo* ti = _tp_info(_0);
  47. for(int i=0; i<arg; i++){
  48. PyVar _1 = _py_next(ti, _0);
  49. if(_1 == StopIteration) ValueError("not enough values to unpack");
  50. PUSH(_1);
  51. }
  52. if(_py_next(ti, _0) != StopIteration) ValueError("too many values to unpack");
  53. }
  54. }
  55. bool VM::py_lt(PyVar _0, PyVar _1){
  56. BINARY_F_COMPARE(__lt__, "<", __gt__);
  57. return ret == True;
  58. }
  59. bool VM::py_le(PyVar _0, PyVar _1){
  60. BINARY_F_COMPARE(__le__, "<=", __ge__);
  61. return ret == True;
  62. }
  63. bool VM::py_gt(PyVar _0, PyVar _1){
  64. BINARY_F_COMPARE(__gt__, ">", __lt__);
  65. return ret == True;
  66. }
  67. bool VM::py_ge(PyVar _0, PyVar _1){
  68. BINARY_F_COMPARE(__ge__, ">=", __le__);
  69. return ret == True;
  70. }
  71. #undef BINARY_F_COMPARE
  72. #if PK_ENABLE_PROFILER
  73. #define CEVAL_STEP_CALLBACK() \
  74. if(_ceval_on_step) _ceval_on_step(this, frame, byte); \
  75. if(_profiler) _profiler->_step(callstack.size(), frame); \
  76. if(!_next_breakpoint.empty()) { _next_breakpoint._step(this); }
  77. #else
  78. #define CEVAL_STEP_CALLBACK() \
  79. if(_ceval_on_step && _ceval_on_step){ \
  80. if(_ceval_on_step) \
  81. if(_ceval_on_step) _ceval_on_step(this, frame, byte); \
  82. }
  83. #endif
  84. #define DISPATCH() { frame->_ip++; goto __NEXT_STEP; }
  85. #define DISPATCH_JUMP(__offset) { frame->_ip+=__offset; goto __NEXT_STEP; }
  86. #define DISPATCH_JUMP_ABSOLUTE(__target) { frame->_ip=&frame->co->codes[__target]; goto __NEXT_STEP; }
  87. PyVar VM::__run_top_frame(){
  88. Frame* frame = &callstack.top();
  89. const Frame* base_frame = frame;
  90. InternalException __internal_exception;
  91. while(true){
  92. try{
  93. /**********************************************************************/
  94. {
  95. __NEXT_FRAME:
  96. Bytecode byte;
  97. if(__internal_exception.type == InternalExceptionType::Null){
  98. // None
  99. frame->_ip++;
  100. }else if(__internal_exception.type == InternalExceptionType::Handled){
  101. // HandledException + continue
  102. frame->_ip = &frame->co->codes[__internal_exception.arg];
  103. __internal_exception = {};
  104. }else{
  105. // UnhandledException + continue (need_raise = true)
  106. // ToBeRaisedException + continue (need_raise = true)
  107. __internal_exception = {};
  108. __raise_exc(); // no return
  109. }
  110. __NEXT_STEP:
  111. byte = *frame->_ip;
  112. CEVAL_STEP_CALLBACK()
  113. #if PK_DEBUG_CEVAL_STEP
  114. __log_s_data();
  115. #endif
  116. switch ((Opcode)byte.op)
  117. {
  118. case OP_NO_OP: DISPATCH()
  119. /*****************************************/
  120. case OP_POP_TOP: POP(); DISPATCH()
  121. case OP_DUP_TOP: PUSH(TOP()); DISPATCH()
  122. case OP_DUP_TOP_TWO:
  123. // [a, b]
  124. PUSH(SECOND()); // [a, b, a]
  125. PUSH(SECOND()); // [a, b, a, b]
  126. DISPATCH()
  127. case OP_ROT_TWO: std::swap(TOP(), SECOND()); DISPATCH()
  128. case OP_ROT_THREE:{
  129. // [a, b, c] -> [c, a, b]
  130. PyVar _0 = TOP();
  131. TOP() = SECOND();
  132. SECOND() = THIRD();
  133. THIRD() = _0;
  134. } DISPATCH()
  135. case OP_PRINT_EXPR:
  136. if(TOP() != None) stdout_write(py_repr(TOP()) + "\n");
  137. POP();
  138. DISPATCH()
  139. /*****************************************/
  140. case OP_LOAD_CONST:
  141. PUSH(frame->co->consts[byte.arg]);
  142. DISPATCH()
  143. case OP_LOAD_NONE: PUSH(None); DISPATCH()
  144. case OP_LOAD_TRUE: PUSH(True); DISPATCH()
  145. case OP_LOAD_FALSE: PUSH(False); DISPATCH()
  146. /*****************************************/
  147. case OP_LOAD_SMALL_INT:
  148. s_data.emplace(tp_int, (i64)(int16_t)byte.arg);
  149. DISPATCH()
  150. /*****************************************/
  151. case OP_LOAD_ELLIPSIS: PUSH(Ellipsis); DISPATCH()
  152. case OP_LOAD_FUNCTION: {
  153. const FuncDecl_& decl = frame->co->func_decls[byte.arg];
  154. PyVar obj;
  155. if(decl->nested){
  156. NameDict_ captured = frame->_locals.to_namedict();
  157. obj = VAR(Function(decl, frame->_module, nullptr, captured));
  158. captured->set(decl->code->name, obj);
  159. }else{
  160. obj = VAR(Function(decl, frame->_module, nullptr, nullptr));
  161. }
  162. PUSH(obj);
  163. } DISPATCH()
  164. case OP_LOAD_NULL: PUSH(PY_NULL); DISPATCH()
  165. /*****************************************/
  166. case OP_LOAD_FAST: {
  167. PyVar _0 = frame->_locals[byte.arg];
  168. if(_0 == PY_NULL) vm->UnboundLocalError(frame->co->varnames[byte.arg]);
  169. PUSH(_0);
  170. } DISPATCH()
  171. case OP_LOAD_NAME: {
  172. StrName _name(byte.arg);
  173. PyVar* slot = frame->_locals.try_get_name(_name);
  174. if(slot != nullptr) {
  175. if(*slot == PY_NULL) vm->UnboundLocalError(_name);
  176. PUSH(*slot);
  177. DISPATCH()
  178. }
  179. PyVar* _0 = frame->f_closure_try_get(_name);
  180. if(_0 != nullptr) { PUSH(*_0); DISPATCH() }
  181. _0 = frame->f_globals().try_get_2_likely_found(_name);
  182. if(_0 != nullptr) { PUSH(*_0); DISPATCH() }
  183. _0 = vm->builtins->attr().try_get_2_likely_found(_name);
  184. if(_0 != nullptr) { PUSH(*_0); DISPATCH() }
  185. vm->NameError(_name);
  186. } DISPATCH()
  187. case OP_LOAD_NONLOCAL: {
  188. StrName _name(byte.arg);
  189. PyVar* _0 = frame->f_closure_try_get(_name);
  190. if(_0 != nullptr) { PUSH(*_0); DISPATCH() }
  191. _0 = frame->f_globals().try_get_2_likely_found(_name);
  192. if(_0 != nullptr) { PUSH(*_0); DISPATCH() }
  193. _0 = vm->builtins->attr().try_get_2_likely_found(_name);
  194. if(_0 != nullptr) { PUSH(*_0); DISPATCH() }
  195. vm->NameError(_name);
  196. } DISPATCH()
  197. case OP_LOAD_GLOBAL:{
  198. StrName _name(byte.arg);
  199. PyVar _0 = frame->f_globals().try_get_likely_found(_name);
  200. if(_0 != nullptr) { PUSH(_0); DISPATCH() }
  201. _0 = vm->builtins->attr().try_get_likely_found(_name);
  202. if(_0 != nullptr) { PUSH(_0); DISPATCH() }
  203. vm->NameError(_name);
  204. } DISPATCH()
  205. case OP_LOAD_ATTR:{
  206. TOP() = getattr(TOP(), StrName(byte.arg));
  207. } DISPATCH()
  208. case OP_LOAD_CLASS_GLOBAL:{
  209. PK_ASSERT(__curr_class != nullptr);
  210. StrName _name(byte.arg);
  211. PyVar _0 = getattr(__curr_class, _name, false);
  212. if(_0 != nullptr) { PUSH(_0); DISPATCH() }
  213. // load global if attribute not found
  214. _0 = frame->f_globals().try_get_likely_found(_name);
  215. if(_0 != nullptr) { PUSH(_0); DISPATCH() }
  216. _0 = vm->builtins->attr().try_get_likely_found(_name);
  217. if(_0 != nullptr) { PUSH(_0); DISPATCH() }
  218. vm->NameError(_name);
  219. } DISPATCH()
  220. case OP_LOAD_METHOD:{
  221. PyVar _0;
  222. TOP() = get_unbound_method(TOP(), StrName(byte.arg), &_0, true, true);
  223. PUSH(_0);
  224. }DISPATCH()
  225. case OP_LOAD_SUBSCR:{
  226. PyVar _1 = POPX(); // b
  227. PyVar _0 = TOP(); // a
  228. auto _ti = _tp_info(_0);
  229. if(_ti->m__getitem__){
  230. TOP() = _ti->m__getitem__(this, _0, _1);
  231. }else{
  232. TOP() = call_method(_0, __getitem__, _1);
  233. }
  234. } DISPATCH()
  235. case OP_LOAD_SUBSCR_FAST:{
  236. PyVar _1 = frame->_locals[byte.arg];
  237. if(_1 == PY_NULL) vm->UnboundLocalError(frame->co->varnames[byte.arg]);
  238. PyVar _0 = TOP(); // a
  239. auto _ti = _tp_info(_0);
  240. if(_ti->m__getitem__){
  241. TOP() = _ti->m__getitem__(this, _0, _1);
  242. }else{
  243. TOP() = call_method(_0, __getitem__, _1);
  244. }
  245. } DISPATCH()
  246. case OP_LOAD_SUBSCR_SMALL_INT:{
  247. PyVar _1 = VAR((int16_t)byte.arg);
  248. PyVar _0 = TOP(); // a
  249. auto _ti = _tp_info(_0);
  250. if(_ti->m__getitem__){
  251. TOP() = _ti->m__getitem__(this, _0, _1);
  252. }else{
  253. TOP() = call_method(_0, __getitem__, _1);
  254. }
  255. } DISPATCH()
  256. case OP_STORE_FAST:
  257. frame->_locals[byte.arg] = POPX();
  258. DISPATCH()
  259. case OP_STORE_NAME:{
  260. StrName _name(byte.arg);
  261. PyVar _0 = POPX();
  262. if(frame->_callable != nullptr){
  263. PyVar* slot = frame->_locals.try_get_name(_name);
  264. if(slot != nullptr){
  265. *slot = _0; // store in locals if possible
  266. }else{
  267. Function& func = frame->_callable->as<Function>();
  268. if(func.decl == __dynamic_func_decl){
  269. PK_DEBUG_ASSERT(func._closure != nullptr);
  270. func._closure->set(_name, _0);
  271. }else{
  272. vm->NameError(_name);
  273. }
  274. }
  275. }else{
  276. frame->f_globals().set(_name, _0);
  277. }
  278. } DISPATCH()
  279. case OP_STORE_GLOBAL:
  280. frame->f_globals().set(StrName(byte.arg), POPX());
  281. DISPATCH()
  282. case OP_STORE_ATTR: {
  283. PyVar _0 = TOP(); // a
  284. PyVar _1 = SECOND(); // val
  285. setattr(_0, StrName(byte.arg), _1);
  286. STACK_SHRINK(2);
  287. } DISPATCH()
  288. case OP_STORE_SUBSCR:{
  289. PyVar _2 = POPX(); // b
  290. PyVar _1 = POPX(); // a
  291. PyVar _0 = POPX(); // val
  292. auto _ti = _tp_info(_1);
  293. if(_ti->m__setitem__){
  294. _ti->m__setitem__(this, _1, _2, _0);
  295. }else{
  296. call_method(_1, __setitem__, _2, _0);
  297. }
  298. }DISPATCH()
  299. case OP_STORE_SUBSCR_FAST:{
  300. PyVar _2 = frame->_locals[byte.arg]; // b
  301. if(_2 == PY_NULL) vm->UnboundLocalError(frame->co->varnames[byte.arg]);
  302. PyVar _1 = POPX(); // a
  303. PyVar _0 = POPX(); // val
  304. auto _ti = _tp_info(_1);
  305. if(_ti->m__setitem__){
  306. _ti->m__setitem__(this, _1, _2, _0);
  307. }else{
  308. call_method(_1, __setitem__, _2, _0);
  309. }
  310. }DISPATCH()
  311. case OP_DELETE_FAST:{
  312. PyVar _0 = frame->_locals[byte.arg];
  313. if(_0 == PY_NULL) vm->UnboundLocalError(frame->co->varnames[byte.arg]);
  314. frame->_locals[byte.arg].set_null();
  315. }DISPATCH()
  316. case OP_DELETE_NAME:{
  317. StrName _name(byte.arg);
  318. if(frame->_callable != nullptr){
  319. PyVar* slot = frame->_locals.try_get_name(_name);
  320. if(slot != nullptr){
  321. slot->set_null();
  322. }else{
  323. Function& func = frame->_callable->as<Function>();
  324. if(func.decl == __dynamic_func_decl){
  325. PK_DEBUG_ASSERT(func._closure != nullptr);
  326. bool ok = func._closure->del(_name);
  327. if(!ok) vm->NameError(_name);
  328. }else{
  329. vm->NameError(_name);
  330. }
  331. }
  332. }else{
  333. if(!frame->f_globals().del(_name)) vm->NameError(_name);
  334. }
  335. } DISPATCH()
  336. case OP_DELETE_GLOBAL:{
  337. StrName _name(byte.arg);
  338. if(!frame->f_globals().del(_name)) vm->NameError(_name);
  339. }DISPATCH()
  340. case OP_DELETE_ATTR:{
  341. PyVar _0 = POPX();
  342. delattr(_0, StrName(byte.arg));
  343. } DISPATCH()
  344. case OP_DELETE_SUBSCR:{
  345. PyVar _1 = POPX();
  346. PyVar _0 = POPX();
  347. auto _ti = _tp_info(_0);
  348. if(_ti->m__delitem__){
  349. _ti->m__delitem__(this, _0, _1);
  350. }else{
  351. call_method(_0, __delitem__, _1);
  352. }
  353. }DISPATCH()
  354. /*****************************************/
  355. case OP_BUILD_LONG: {
  356. PyVar _0 = builtins->attr().try_get_likely_found(pk_id_long);
  357. if(_0 == nullptr) AttributeError(builtins, pk_id_long);
  358. TOP() = call(_0, TOP());
  359. } DISPATCH()
  360. case OP_BUILD_IMAG: {
  361. PyVar _0 = builtins->attr().try_get_likely_found(pk_id_complex);
  362. if(_0 == nullptr) AttributeError(builtins, pk_id_long);
  363. TOP() = call(_0, VAR(0), TOP());
  364. } DISPATCH()
  365. case OP_BUILD_BYTES: {
  366. const Str& s = CAST(Str&, TOP());
  367. unsigned char* p = (unsigned char*)malloc(s.size);
  368. memcpy(p, s.data, s.size);
  369. TOP() = VAR(Bytes(p, s.size));
  370. } DISPATCH()
  371. case OP_BUILD_TUPLE:{
  372. PyVar _0 = VAR(STACK_VIEW(byte.arg).to_tuple());
  373. STACK_SHRINK(byte.arg);
  374. PUSH(_0);
  375. } DISPATCH()
  376. case OP_BUILD_LIST:{
  377. PyVar _0 = VAR(STACK_VIEW(byte.arg).to_list());
  378. STACK_SHRINK(byte.arg);
  379. PUSH(_0);
  380. } DISPATCH()
  381. case OP_BUILD_DICT:{
  382. if(byte.arg == 0){
  383. PUSH(VAR(Dict()));
  384. DISPATCH()
  385. }
  386. PyVar _0 = VAR(STACK_VIEW(byte.arg).to_list());
  387. _0 = call(_t(tp_dict), _0);
  388. STACK_SHRINK(byte.arg);
  389. PUSH(_0);
  390. } DISPATCH()
  391. case OP_BUILD_SET:{
  392. PyVar _0 = VAR(STACK_VIEW(byte.arg).to_list());
  393. _0 = call(builtins->attr(pk_id_set), _0);
  394. STACK_SHRINK(byte.arg);
  395. PUSH(_0);
  396. } DISPATCH()
  397. case OP_BUILD_SLICE:{
  398. PyVar _2 = POPX(); // step
  399. PyVar _1 = POPX(); // stop
  400. PyVar _0 = POPX(); // start
  401. PUSH(VAR(Slice(_0, _1, _2)));
  402. } DISPATCH()
  403. case OP_BUILD_STRING: {
  404. SStream ss;
  405. ArgsView view = STACK_VIEW(byte.arg);
  406. for(PyVar obj : view) ss << py_str(obj);
  407. STACK_SHRINK(byte.arg);
  408. PUSH(VAR(ss.str()));
  409. } DISPATCH()
  410. /*****************************************/
  411. case OP_BUILD_TUPLE_UNPACK: {
  412. List list;
  413. __unpack_as_list(STACK_VIEW(byte.arg), list);
  414. STACK_SHRINK(byte.arg);
  415. PyVar _0 = VAR(list.to_tuple());
  416. PUSH(_0);
  417. } DISPATCH()
  418. case OP_BUILD_LIST_UNPACK: {
  419. List list;
  420. __unpack_as_list(STACK_VIEW(byte.arg), list);
  421. STACK_SHRINK(byte.arg);
  422. PyVar _0 = VAR(std::move(list));
  423. PUSH(_0);
  424. } DISPATCH()
  425. case OP_BUILD_DICT_UNPACK: {
  426. Dict dict;
  427. __unpack_as_dict(STACK_VIEW(byte.arg), dict);
  428. STACK_SHRINK(byte.arg);
  429. PyVar _0 = VAR(std::move(dict));
  430. PUSH(_0);
  431. } DISPATCH()
  432. case OP_BUILD_SET_UNPACK: {
  433. List list;
  434. __unpack_as_list(STACK_VIEW(byte.arg), list);
  435. STACK_SHRINK(byte.arg);
  436. PyVar _0 = VAR(std::move(list));
  437. _0 = call(builtins->attr(pk_id_set), _0);
  438. PUSH(_0);
  439. } DISPATCH()
  440. /*****************************************/
  441. #define BINARY_OP_SPECIAL(func) \
  442. _ti = _tp_info(_0); \
  443. if(_ti->m##func){ \
  444. TOP() = _ti->m##func(this, _0, _1); \
  445. }else{ \
  446. PyVar self; \
  447. PyVar _2 = get_unbound_method(_0, func, &self, false); \
  448. if(_2 != nullptr) TOP() = call_method(self, _2, _1); \
  449. else TOP() = NotImplemented; \
  450. }
  451. #define BINARY_OP_RSPECIAL(op, func) \
  452. if(is_not_implemented(TOP())){ \
  453. PyVar self; \
  454. PyVar _2 = get_unbound_method(_1, func, &self, false); \
  455. if(_2 != nullptr) TOP() = call_method(self, _2, _0); \
  456. else BinaryOptError(op, _0, _1); \
  457. if(is_not_implemented(TOP())) BinaryOptError(op, _0, _1); \
  458. }
  459. case OP_BINARY_TRUEDIV:{
  460. PyVar _1 = POPX();
  461. PyVar _0 = TOP();
  462. const PyTypeInfo* _ti;
  463. BINARY_OP_SPECIAL(__truediv__);
  464. if(is_not_implemented(TOP())) BinaryOptError("/", _0, _1);
  465. } DISPATCH()
  466. case OP_BINARY_POW:{
  467. PyVar _1 = POPX();
  468. PyVar _0 = TOP();
  469. const PyTypeInfo* _ti;
  470. BINARY_OP_SPECIAL(__pow__);
  471. if(is_not_implemented(TOP())) BinaryOptError("**", _0, _1);
  472. } DISPATCH()
  473. case OP_BINARY_ADD:{
  474. PyVar _1 = POPX();
  475. PyVar _0 = TOP();
  476. PREDICT_INT_OP(+)
  477. const PyTypeInfo* _ti;
  478. BINARY_OP_SPECIAL(__add__);
  479. BINARY_OP_RSPECIAL("+", __radd__);
  480. } DISPATCH()
  481. case OP_BINARY_SUB:{
  482. PyVar _1 = POPX();
  483. PyVar _0 = TOP();
  484. PREDICT_INT_OP(-)
  485. const PyTypeInfo* _ti;
  486. BINARY_OP_SPECIAL(__sub__);
  487. BINARY_OP_RSPECIAL("-", __rsub__);
  488. } DISPATCH()
  489. case OP_BINARY_MUL:{
  490. PyVar _1 = POPX();
  491. PyVar _0 = TOP();
  492. PREDICT_INT_OP(*)
  493. const PyTypeInfo* _ti;
  494. BINARY_OP_SPECIAL(__mul__);
  495. BINARY_OP_RSPECIAL("*", __rmul__);
  496. } DISPATCH()
  497. case OP_BINARY_FLOORDIV:{
  498. PyVar _1 = POPX();
  499. PyVar _0 = TOP();
  500. PREDICT_INT_DIV_OP(/)
  501. const PyTypeInfo* _ti;
  502. BINARY_OP_SPECIAL(__floordiv__);
  503. if(is_not_implemented(TOP())) BinaryOptError("//", _0, _1);
  504. } DISPATCH()
  505. case OP_BINARY_MOD:{
  506. PyVar _1 = POPX();
  507. PyVar _0 = TOP();
  508. PREDICT_INT_DIV_OP(%)
  509. const PyTypeInfo* _ti;
  510. BINARY_OP_SPECIAL(__mod__);
  511. if(is_not_implemented(TOP())) BinaryOptError("%", _0, _1);
  512. } DISPATCH()
  513. case OP_COMPARE_LT:{
  514. PyVar _1 = POPX();
  515. PyVar _0 = TOP();
  516. PREDICT_INT_OP(<)
  517. TOP() = VAR(py_lt(_0, _1));
  518. } DISPATCH()
  519. case OP_COMPARE_LE:{
  520. PyVar _1 = POPX();
  521. PyVar _0 = TOP();
  522. PREDICT_INT_OP(<=)
  523. TOP() = VAR(py_le(_0, _1));
  524. } DISPATCH()
  525. case OP_COMPARE_EQ:{
  526. PyVar _1 = POPX();
  527. PyVar _0 = TOP();
  528. TOP() = VAR(py_eq(_0, _1));
  529. } DISPATCH()
  530. case OP_COMPARE_NE:{
  531. PyVar _1 = POPX();
  532. PyVar _0 = TOP();
  533. TOP() = VAR(py_ne(_0, _1));
  534. } DISPATCH()
  535. case OP_COMPARE_GT:{
  536. PyVar _1 = POPX();
  537. PyVar _0 = TOP();
  538. PREDICT_INT_OP(>)
  539. TOP() = VAR(py_gt(_0, _1));
  540. } DISPATCH()
  541. case OP_COMPARE_GE:{
  542. PyVar _1 = POPX();
  543. PyVar _0 = TOP();
  544. PREDICT_INT_OP(>=)
  545. TOP() = VAR(py_ge(_0, _1));
  546. } DISPATCH()
  547. case OP_BITWISE_LSHIFT:{
  548. PyVar _1 = POPX();
  549. PyVar _0 = TOP();
  550. PREDICT_INT_OP(<<)
  551. const PyTypeInfo* _ti;
  552. BINARY_OP_SPECIAL(__lshift__);
  553. if(is_not_implemented(TOP())) BinaryOptError("<<", _0, _1);
  554. } DISPATCH()
  555. case OP_BITWISE_RSHIFT:{
  556. PyVar _1 = POPX();
  557. PyVar _0 = TOP();
  558. PREDICT_INT_OP(>>)
  559. const PyTypeInfo* _ti;
  560. BINARY_OP_SPECIAL(__rshift__);
  561. if(is_not_implemented(TOP())) BinaryOptError(">>", _0, _1);
  562. } DISPATCH()
  563. case OP_BITWISE_AND:{
  564. PyVar _1 = POPX();
  565. PyVar _0 = TOP();
  566. PREDICT_INT_OP(&)
  567. const PyTypeInfo* _ti;
  568. BINARY_OP_SPECIAL(__and__);
  569. if(is_not_implemented(TOP())) BinaryOptError("&", _0, _1);
  570. } DISPATCH()
  571. case OP_BITWISE_OR:{
  572. PyVar _1 = POPX();
  573. PyVar _0 = TOP();
  574. PREDICT_INT_OP(|)
  575. const PyTypeInfo* _ti;
  576. BINARY_OP_SPECIAL(__or__);
  577. if(is_not_implemented(TOP())) BinaryOptError("|", _0, _1);
  578. } DISPATCH()
  579. case OP_BITWISE_XOR:{
  580. PyVar _1 = POPX();
  581. PyVar _0 = TOP();
  582. PREDICT_INT_OP(^)
  583. const PyTypeInfo* _ti;
  584. BINARY_OP_SPECIAL(__xor__);
  585. if(is_not_implemented(TOP())) BinaryOptError("^", _0, _1);
  586. } DISPATCH()
  587. case OP_BINARY_MATMUL:{
  588. PyVar _1 = POPX();
  589. PyVar _0 = TOP();
  590. const PyTypeInfo* _ti;
  591. BINARY_OP_SPECIAL(__matmul__);
  592. if(is_not_implemented(TOP())) BinaryOptError("@", _0, _1);
  593. } DISPATCH()
  594. #undef BINARY_OP_SPECIAL
  595. #undef BINARY_OP_RSPECIAL
  596. #undef PREDICT_INT_OP
  597. case OP_IS_OP:{
  598. PyVar _1 = POPX(); // rhs
  599. PyVar _0 = TOP(); // lhs
  600. TOP() = _0 == _1 ? True : False;
  601. } DISPATCH()
  602. case OP_IS_NOT_OP:{
  603. PyVar _1 = POPX(); // rhs
  604. PyVar _0 = TOP(); // lhs
  605. TOP() = _0 != _1 ? True : False;
  606. } DISPATCH()
  607. case OP_CONTAINS_OP:{
  608. // a in b -> b __contains__ a
  609. auto _ti = _tp_info(TOP());
  610. PyVar _0;
  611. if(_ti->m__contains__){
  612. _0 = _ti->m__contains__(this, TOP(), SECOND());
  613. }else{
  614. _0 = call_method(TOP(), __contains__, SECOND());
  615. }
  616. POP();
  617. TOP() = VAR(static_cast<bool>((int)CAST(bool, _0) ^ byte.arg));
  618. } DISPATCH()
  619. /*****************************************/
  620. case OP_JUMP_FORWARD:
  621. DISPATCH_JUMP((int16_t)byte.arg)
  622. case OP_POP_JUMP_IF_FALSE:
  623. if(!py_bool(POPX())) DISPATCH_JUMP((int16_t)byte.arg)
  624. DISPATCH()
  625. case OP_POP_JUMP_IF_TRUE:
  626. if(py_bool(POPX())) DISPATCH_JUMP((int16_t)byte.arg)
  627. DISPATCH()
  628. case OP_JUMP_IF_TRUE_OR_POP:
  629. if(py_bool(TOP())){
  630. DISPATCH_JUMP((int16_t)byte.arg)
  631. }else{
  632. POP();
  633. DISPATCH()
  634. }
  635. case OP_JUMP_IF_FALSE_OR_POP:
  636. if(!py_bool(TOP())){
  637. DISPATCH_JUMP((int16_t)byte.arg)
  638. }else{
  639. POP();
  640. DISPATCH()
  641. }
  642. case OP_SHORTCUT_IF_FALSE_OR_POP:
  643. if(!py_bool(TOP())){ // [b, False]
  644. STACK_SHRINK(2); // []
  645. PUSH(vm->False); // [False]
  646. DISPATCH_JUMP((int16_t)byte.arg)
  647. } else{
  648. POP(); // [b]
  649. DISPATCH()
  650. }
  651. case OP_LOOP_CONTINUE:
  652. // just an alias of OP_JUMP_FORWARD
  653. DISPATCH_JUMP((int16_t)byte.arg)
  654. case OP_LOOP_BREAK: {
  655. frame->prepare_jump_break(&s_data, frame->ip()+byte.arg);
  656. DISPATCH_JUMP((int16_t)byte.arg)
  657. }
  658. case OP_JUMP_ABSOLUTE_TOP:
  659. DISPATCH_JUMP_ABSOLUTE(_CAST(int, POPX()))
  660. case OP_GOTO: {
  661. StrName _name(byte.arg);
  662. int target = frame->co->labels.try_get_likely_found(_name);
  663. if(target < 0) RuntimeError(_S("label ", _name.escape(), " not found"));
  664. frame->prepare_jump_break(&s_data, target);
  665. DISPATCH_JUMP_ABSOLUTE(target)
  666. }
  667. /*****************************************/
  668. case OP_FSTRING_EVAL:{
  669. PyVar _0 = frame->co->consts[byte.arg];
  670. std::string_view string = CAST(Str&, _0).sv();
  671. auto it = __cached_codes.find(string);
  672. CodeObject_ code;
  673. if(it == __cached_codes.end()){
  674. code = vm->compile(string, "<eval>", EVAL_MODE, true);
  675. __cached_codes[string] = code;
  676. }else{
  677. code = it->second;
  678. }
  679. _0 = vm->_exec(code.get(), frame->_module, frame->_callable, frame->_locals);
  680. PUSH(_0);
  681. } DISPATCH()
  682. case OP_REPR:
  683. TOP() = VAR(py_repr(TOP()));
  684. DISPATCH()
  685. case OP_CALL:{
  686. if(heap._should_auto_collect()) heap._auto_collect();
  687. PyVar _0 = vectorcall(
  688. byte.arg & 0xFF, // ARGC
  689. (byte.arg>>8) & 0xFF, // KWARGC
  690. true
  691. );
  692. if(_0 == PY_OP_CALL){
  693. frame = &callstack.top();
  694. goto __NEXT_FRAME;
  695. }
  696. PUSH(_0);
  697. } DISPATCH()
  698. case OP_CALL_TP:{
  699. if(heap._should_auto_collect()) heap._auto_collect();
  700. PyVar _0;
  701. PyVar _1;
  702. PyVar _2;
  703. // [callable, <self>, args: tuple, kwargs: dict | NULL]
  704. if(byte.arg){
  705. _2 = POPX();
  706. _1 = POPX();
  707. for(PyVar obj: _CAST(Tuple&, _1)) PUSH(obj);
  708. _CAST(Dict&, _2).apply([this](PyVar k, PyVar v){
  709. PUSH(VAR(StrName(CAST(Str&, k)).index));
  710. PUSH(v);
  711. });
  712. _0 = vectorcall(
  713. _CAST(Tuple&, _1).size(), // ARGC
  714. _CAST(Dict&, _2).size(), // KWARGC
  715. true
  716. );
  717. }else{
  718. // no **kwargs
  719. _1 = POPX();
  720. for(PyVar obj: _CAST(Tuple&, _1)) PUSH(obj);
  721. _0 = vectorcall(
  722. _CAST(Tuple&, _1).size(), // ARGC
  723. 0, // KWARGC
  724. true
  725. );
  726. }
  727. if(_0 == PY_OP_CALL){
  728. frame = &callstack.top();
  729. goto __NEXT_FRAME;
  730. }
  731. PUSH(_0);
  732. } DISPATCH()
  733. case OP_RETURN_VALUE:{
  734. PyVar _0 = byte.arg == BC_NOARG ? POPX() : None;
  735. __pop_frame();
  736. if(frame == base_frame){ // [ frameBase<- ]
  737. return _0;
  738. }else{
  739. frame = &callstack.top();
  740. PUSH(_0);
  741. goto __NEXT_FRAME;
  742. }
  743. } DISPATCH()
  744. case OP_YIELD_VALUE: return PY_OP_YIELD;
  745. /*****************************************/
  746. case OP_LIST_APPEND:{
  747. PyVar _0 = POPX();
  748. PK_OBJ_GET(List, SECOND()).push_back(_0);
  749. } DISPATCH()
  750. case OP_DICT_ADD: {
  751. PyVar _0 = POPX();
  752. const Tuple& t = PK_OBJ_GET(Tuple, _0);
  753. PK_OBJ_GET(Dict, SECOND()).set(this, t[0], t[1]);
  754. } DISPATCH()
  755. case OP_SET_ADD:{
  756. PyVar _0 = POPX();
  757. call_method(SECOND(), pk_id_add, _0);
  758. } DISPATCH()
  759. /*****************************************/
  760. case OP_UNARY_NEGATIVE:
  761. TOP() = py_negate(TOP());
  762. DISPATCH()
  763. case OP_UNARY_NOT:{
  764. PyVar _0 = TOP();
  765. if(_0==True) TOP()=False;
  766. else if(_0==False) TOP()=True;
  767. else TOP() = VAR(!py_bool(_0));
  768. } DISPATCH()
  769. case OP_UNARY_STAR:
  770. TOP() = VAR(StarWrapper(byte.arg, TOP()));
  771. DISPATCH()
  772. case OP_UNARY_INVERT:{
  773. PyVar _0;
  774. auto _ti = _tp_info(TOP());
  775. if(_ti->m__invert__) _0 = _ti->m__invert__(this, TOP());
  776. else _0 = call_method(TOP(), __invert__);
  777. TOP() = _0;
  778. } DISPATCH()
  779. /*****************************************/
  780. case OP_GET_ITER:
  781. TOP() = py_iter(TOP());
  782. DISPATCH()
  783. case OP_GET_ITER_NEW: {
  784. // This opcode always creates a temporary iterator object
  785. const PyTypeInfo* _ti = _tp_info(TOP());
  786. if(_ti->op__iter__){
  787. PyVar _0 = POPX();
  788. _ti->op__iter__(this, _0);
  789. }else{
  790. TOP() = py_iter(TOP());
  791. }
  792. DISPATCH()
  793. }
  794. case OP_FOR_ITER:{
  795. PyVar _0 = py_next(TOP());
  796. if(_0 == StopIteration){
  797. int target = frame->prepare_loop_break(&s_data);
  798. DISPATCH_JUMP_ABSOLUTE(target)
  799. } else{
  800. PUSH(_0);
  801. DISPATCH()
  802. }
  803. }
  804. case OP_FOR_ITER_STORE_FAST:{
  805. PyVar _0 = py_next(TOP());
  806. if(_0 == StopIteration){
  807. int target = frame->prepare_loop_break(&s_data);
  808. DISPATCH_JUMP_ABSOLUTE(target)
  809. }else{
  810. frame->_locals[byte.arg] = _0;
  811. DISPATCH()
  812. }
  813. }
  814. case OP_FOR_ITER_STORE_GLOBAL:{
  815. PyVar _0 = py_next(TOP());
  816. if(_0 == StopIteration){
  817. int target = frame->prepare_loop_break(&s_data);
  818. DISPATCH_JUMP_ABSOLUTE(target)
  819. }else{
  820. frame->f_globals().set(StrName(byte.arg), _0);
  821. DISPATCH()
  822. }
  823. }
  824. case OP_FOR_ITER_YIELD_VALUE:{
  825. PyVar _0 = py_next(TOP());
  826. if(_0 == StopIteration){
  827. int target = frame->prepare_loop_break(&s_data);
  828. DISPATCH_JUMP_ABSOLUTE(target)
  829. }else{
  830. PUSH(_0);
  831. return PY_OP_YIELD;
  832. }
  833. }
  834. case OP_FOR_ITER_UNPACK:{
  835. PyVar _0 = TOP();
  836. const PyTypeInfo* _ti = _tp_info(_0);
  837. if(_ti->op__next__){
  838. unsigned n = _ti->op__next__(this, _0);
  839. if(n == 0){
  840. // StopIteration
  841. int target = frame->prepare_loop_break(&s_data);
  842. DISPATCH_JUMP_ABSOLUTE(target)
  843. }else if(n == 1){
  844. // UNPACK_SEQUENCE
  845. __op_unpack_sequence(byte.arg);
  846. }else{
  847. if(n != byte.arg){
  848. ValueError(_S("expected ", (int)byte.arg, " values to unpack, got ", (int)n));
  849. }
  850. }
  851. }else{
  852. // FOR_ITER
  853. _0 = call_method(_0, __next__);
  854. if(_0 != StopIteration){
  855. PUSH(_0);
  856. // UNPACK_SEQUENCE
  857. __op_unpack_sequence(byte.arg);
  858. }else{
  859. int target = frame->prepare_loop_break(&s_data);
  860. DISPATCH_JUMP_ABSOLUTE(target)
  861. }
  862. }
  863. } DISPATCH()
  864. /*****************************************/
  865. case OP_IMPORT_PATH:{
  866. PyVar _0 = frame->co->consts[byte.arg];
  867. PUSH(py_import(CAST(Str&, _0)));
  868. } DISPATCH()
  869. case OP_POP_IMPORT_STAR: {
  870. PyVar _0 = POPX(); // pop the module
  871. PyVar _1 = _0->attr().try_get(__all__);
  872. StrName _name;
  873. if(_1 != nullptr){
  874. for(PyVar key: CAST(List&, _1)){
  875. _name = StrName::get(CAST(Str&, key).sv());
  876. PyVar value = _0->attr().try_get_likely_found(_name);
  877. if(value == nullptr){
  878. ImportError(_S("cannot import name ", _name.escape()));
  879. }else{
  880. frame->f_globals().set(_name, value);
  881. }
  882. }
  883. }else{
  884. for(auto& [name, value]: _0->attr().items()){
  885. std::string_view s = name.sv();
  886. if(s.empty() || s[0] == '_') continue;
  887. frame->f_globals().set(name, value);
  888. }
  889. }
  890. } DISPATCH()
  891. /*****************************************/
  892. case OP_UNPACK_SEQUENCE:{
  893. __op_unpack_sequence(byte.arg);
  894. } DISPATCH()
  895. case OP_UNPACK_EX: {
  896. auto _lock = heap.gc_scope_lock(); // lock the gc via RAII!!
  897. PyVar _0 = py_iter(POPX());
  898. const PyTypeInfo* _ti = _tp_info(_0);
  899. PyVar _1;
  900. for(int i=0; i<byte.arg; i++){
  901. _1 = _py_next(_ti, _0);
  902. if(_1 == StopIteration) ValueError("not enough values to unpack");
  903. PUSH(_1);
  904. }
  905. List extras;
  906. while(true){
  907. _1 = _py_next(_ti, _0);
  908. if(_1 == StopIteration) break;
  909. extras.push_back(_1);
  910. }
  911. PUSH(VAR(std::move(extras)));
  912. } DISPATCH()
  913. /*****************************************/
  914. case OP_BEGIN_CLASS:{
  915. StrName _name(byte.arg);
  916. PyVar _0 = POPX(); // super
  917. if(_0 == None) _0 = _t(tp_object);
  918. check_type(_0, tp_type);
  919. __curr_class = new_type_object(frame->_module, _name, PK_OBJ_GET(Type, _0), true);
  920. } DISPATCH()
  921. case OP_END_CLASS: {
  922. PK_ASSERT(__curr_class != nullptr);
  923. StrName _name(byte.arg);
  924. frame->_module->attr().set(_name, __curr_class);
  925. // call on_end_subclass
  926. PyTypeInfo* ti = &_all_types[__curr_class->as<Type>()];
  927. if(ti->base != tp_object){
  928. PyTypeInfo* base_ti = &_all_types[ti->base];
  929. if(base_ti->on_end_subclass) base_ti->on_end_subclass(this, ti);
  930. }
  931. __curr_class = nullptr;
  932. } DISPATCH()
  933. case OP_STORE_CLASS_ATTR:{
  934. PK_ASSERT(__curr_class != nullptr);
  935. StrName _name(byte.arg);
  936. PyVar _0 = POPX();
  937. if(is_type(_0, tp_function)){
  938. PK_OBJ_GET(Function, _0)._class = __curr_class;
  939. }
  940. __curr_class->attr().set(_name, _0);
  941. } DISPATCH()
  942. case OP_BEGIN_CLASS_DECORATION:{
  943. PUSH(__curr_class);
  944. } DISPATCH()
  945. case OP_END_CLASS_DECORATION:{
  946. __curr_class = POPX().get();
  947. } DISPATCH()
  948. case OP_ADD_CLASS_ANNOTATION: {
  949. PK_ASSERT(__curr_class != nullptr);
  950. StrName _name(byte.arg);
  951. Type type = __curr_class->as<Type>();
  952. _all_types[type].annotated_fields.push_back(_name);
  953. } DISPATCH()
  954. /*****************************************/
  955. case OP_WITH_ENTER:
  956. PUSH(call_method(TOP(), __enter__));
  957. DISPATCH()
  958. case OP_WITH_EXIT:
  959. call_method(TOP(), __exit__);
  960. POP();
  961. DISPATCH()
  962. /*****************************************/
  963. case OP_TRY_ENTER: {
  964. frame->set_unwind_target(s_data._sp);
  965. DISPATCH()
  966. }
  967. case OP_EXCEPTION_MATCH: {
  968. PyVar assumed_type = POPX();
  969. check_type(assumed_type, tp_type);
  970. PyVar e_obj = TOP();
  971. bool ok = isinstance(e_obj, PK_OBJ_GET(Type, assumed_type));
  972. PUSH(VAR(ok));
  973. } DISPATCH()
  974. case OP_RAISE: {
  975. if(is_type(TOP(), tp_type)){
  976. TOP() = call(TOP());
  977. }
  978. if(!isinstance(TOP(), tp_exception)){
  979. TypeError("exceptions must derive from Exception");
  980. }
  981. _error(POPX());
  982. } DISPATCH()
  983. case OP_RAISE_ASSERT:
  984. if(byte.arg){
  985. Str msg = py_str(TOP());
  986. POP();
  987. AssertionError(msg);
  988. }else{
  989. AssertionError();
  990. }
  991. DISPATCH()
  992. case OP_RE_RAISE: __raise_exc(true); DISPATCH()
  993. case OP_POP_EXCEPTION: __last_exception = POPX().get(); DISPATCH()
  994. /*****************************************/
  995. case OP_FORMAT_STRING: {
  996. PyVar _0 = POPX();
  997. const Str& spec = CAST(Str&, frame->co->consts[byte.arg]);
  998. PUSH(__format_object(_0, spec));
  999. } DISPATCH()
  1000. /*****************************************/
  1001. case OP_INC_FAST:{
  1002. PyVar* p = &frame->_locals[byte.arg];
  1003. if(*p == PY_NULL) vm->NameError(frame->co->varnames[byte.arg]);
  1004. *p = VAR(CAST(i64, *p) + 1);
  1005. } DISPATCH()
  1006. case OP_DEC_FAST:{
  1007. PyVar* p = &frame->_locals[byte.arg];
  1008. if(*p == PY_NULL) vm->NameError(frame->co->varnames[byte.arg]);
  1009. *p = VAR(CAST(i64, *p) - 1);
  1010. } DISPATCH()
  1011. case OP_INC_GLOBAL:{
  1012. StrName _name(byte.arg);
  1013. PyVar* p = frame->f_globals().try_get_2_likely_found(_name);
  1014. if(p == nullptr) vm->NameError(_name);
  1015. *p = VAR(CAST(i64, *p) + 1);
  1016. } DISPATCH()
  1017. case OP_DEC_GLOBAL:{
  1018. StrName _name(byte.arg);
  1019. PyVar* p = frame->f_globals().try_get_2_likely_found(_name);
  1020. if(p == nullptr) vm->NameError(_name);
  1021. *p = VAR(CAST(i64, *p) - 1);
  1022. } DISPATCH()
  1023. /*****************************************/
  1024. default: PK_UNREACHABLE();
  1025. }
  1026. }
  1027. /**********************************************************************/
  1028. PK_UNREACHABLE();
  1029. }catch(InternalException internal){
  1030. __internal_exception = internal;
  1031. if(internal.type == InternalExceptionType::Unhandled){
  1032. __last_exception = POPX().get();
  1033. Exception& _e = __last_exception->as<Exception>();
  1034. bool is_base_frame_to_be_popped = frame == base_frame;
  1035. __pop_frame();
  1036. if(callstack.empty()){
  1037. // propagate to the top level
  1038. throw TopLevelException(this, &_e);
  1039. }
  1040. frame = &callstack.top();
  1041. PUSH(__last_exception);
  1042. if(is_base_frame_to_be_popped){
  1043. throw InternalException(InternalExceptionType::ToBeRaised);
  1044. }
  1045. }
  1046. }
  1047. }
  1048. }
  1049. #undef TOP
  1050. #undef SECOND
  1051. #undef THIRD
  1052. #undef STACK_SHRINK
  1053. #undef PUSH
  1054. #undef POP
  1055. #undef POPX
  1056. #undef STACK_VIEW
  1057. #undef DISPATCH
  1058. #undef DISPATCH_JUMP
  1059. #undef CEVAL_STEP_CALLBACK
  1060. } // namespace pkpy