From 01be71f0efc26491de196227c19ddc87aea168b3 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Thu, 9 Feb 2023 20:13:57 +0800 Subject: [PATCH] rename --- src/builtins.h | 7 +++---- src/codeobject.h | 11 +++-------- src/vm.h | 2 +- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/builtins.h b/src/builtins.h index 50224595..014c9dd0 100644 --- a/src/builtins.h +++ b/src/builtins.h @@ -49,14 +49,13 @@ def reversed(iterable): return [a[i] for i in range(len(a)-1, -1, -1)] def sorted(iterable, key=None, reverse=False): - if key is None: - key = lambda x: x - a = [key(i) for i in iterable] b = list(iterable) + a = (key is None) ? b : [key(i) for i in iterable] for i in range(len(a)): for j in range(i+1, len(a)): if (a[i] > a[j]) ^ reverse: - a[i], a[j] = a[j], a[i] + if a is not b: + a[i], a[j] = a[j], a[i] b[i], b[j] = b[j], b[i] return b diff --git a/src/codeobject.h b/src/codeobject.h index 3cd7a94a..305d6cd2 100644 --- a/src/codeobject.h +++ b/src/codeobject.h @@ -85,7 +85,7 @@ struct CodeObject { return consts.size() - 1; } - void optimize_level_1(){ + void optimize(){ for(int i=0; i= OP_BINARY_OP && codes[i].op <= OP_CONTAINS_OP){ for(int j=0; j<2; j++){ @@ -116,10 +116,6 @@ struct CodeObject { } } - void optimize(int level=1){ - optimize_level_1(); - } - /************************************************/ int _curr_block_i = 0; bool _is_curr_block_loop() const { @@ -150,6 +146,7 @@ struct Frame { PyVar _module; pkpy::shared_ptr _locals; const i64 id; + std::stack>> s_try_block; inline PyVarDict& f_locals() noexcept { return *_locals; } inline PyVarDict& f_globals() noexcept { return _module->attribs; } @@ -190,7 +187,7 @@ struct Frame { return v; } - inline void __pop(){ + inline void _pop(){ if(_data.empty()) throw std::runtime_error("_data.empty() is true"); _data.pop_back(); } @@ -226,8 +223,6 @@ struct Frame { inline void jump_abs(int i){ _next_ip = i; } inline void jump_rel(int i){ _next_ip += i; } - std::stack>> s_try_block; - inline void on_try_block_enter(){ s_try_block.push(std::make_pair(co->codes[_ip].block, _data)); } diff --git a/src/vm.h b/src/vm.h index 103413a9..0784bb55 100644 --- a/src/vm.h +++ b/src/vm.h @@ -129,7 +129,7 @@ class VM { if(expr == None) break; *_stdout << PyStr_AS_C(asRepr(expr)) << '\n'; } break; - case OP_POP_TOP: frame->__pop(); break; + case OP_POP_TOP: frame->_pop(); break; case OP_BINARY_OP: { pkpy::Args args(2);