This commit is contained in:
blueloveTH 2023-04-05 22:43:43 +08:00
parent baf7ad6b50
commit 818ee2981e
6 changed files with 15 additions and 17 deletions

View File

@ -27,7 +27,11 @@ def test_dir(path):
print(f' cpython: {_1 - _0:.6f}s (100%)') print(f' cpython: {_1 - _0:.6f}s (100%)')
print(f' pocketpy: {_2 - _1:.6f}s ({(_2 - _1) / (_1 - _0) * 100:.2f}%)') print(f' pocketpy: {_2 - _1:.6f}s ({(_2 - _1) / (_1 - _0) * 100:.2f}%)')
else: else:
if not test_file(filepath): exit(1) if not test_file(filepath):
print('-' * 50)
print("TEST FAILED! Press any key to continue...")
input()
if len(sys.argv) == 2: if len(sys.argv) == 2:
assert 'benchmark' in sys.argv[1] assert 'benchmark' in sys.argv[1]

View File

@ -149,11 +149,8 @@ __NEXT_STEP:;
frame->push(VAR(std::move(items))); frame->push(VAR(std::move(items)));
} DISPATCH(); } DISPATCH();
case OP_BUILD_STRING: { case OP_BUILD_STRING: {
// asStr() may run extra bytecode StrStream ss; // asStr() may run extra bytecode
// so we use top_n_reversed() in order to avoid accidental gc for(int i=byte.arg-1; i>=0; i--) ss << CAST(Str&, asStr(frame->top_n(i)));
Args items = frame->top_n_reversed(byte.arg);
StrStream ss;
for(int i=0; i<items.size(); i++) ss << CAST(Str, asStr(items[i]));
frame->pop_n(byte.arg); frame->pop_n(byte.arg);
frame->push(VAR(ss.str())); frame->push(VAR(ss.str()));
} DISPATCH(); } DISPATCH();

View File

@ -35,7 +35,7 @@
#define DEBUG_EXTRA_CHECK 1 #define DEBUG_EXTRA_CHECK 1
#define DEBUG_DIS_REPL 0 #define DEBUG_DIS_REPL 0
#define DEBUG_DIS_REPL_MIN 1 #define DEBUG_DIS_REPL_MIN 1
#define DEBUG_FULL_EXCEPTION 1 #define DEBUG_FULL_EXCEPTION 0
#if (defined(__ANDROID__) && __ANDROID_API__ <= 22) || defined(__EMSCRIPTEN__) #if (defined(__ANDROID__) && __ANDROID_API__ <= 22) || defined(__EMSCRIPTEN__)
#define PK_ENABLE_FILEIO 0 #define PK_ENABLE_FILEIO 0

View File

@ -952,7 +952,7 @@ public:
match_newlines(); // skip possible leading '\n' match_newlines(); // skip possible leading '\n'
if(mode()==EVAL_MODE) { if(mode()==EVAL_MODE) {
EXPR_TUPLE(); EXPR_TUPLE(false);
consume(TK("@eof")); consume(TK("@eof"));
ctx()->emit(OP_RETURN_VALUE, BC_NOARG, BC_KEEPLINE); ctx()->emit(OP_RETURN_VALUE, BC_NOARG, BC_KEEPLINE);
pop_context(); pop_context();

View File

@ -85,11 +85,12 @@ struct Frame {
return _data[_data.size()-2]; return _data[_data.size()-2];
} }
PyObject*& top_2(){ PyObject*& top_n(int n){
n += 1;
#if DEBUG_EXTRA_CHECK #if DEBUG_EXTRA_CHECK
if(_data.size() < 3) throw std::runtime_error("_data.size() < 3"); if(_data.size() < n) throw std::runtime_error("_data.size() < n");
#endif #endif
return _data[_data.size()-3]; return _data[_data.size()-n];
} }
template<typename T> template<typename T>
@ -142,12 +143,6 @@ struct Frame {
return v; return v;
} }
Args top_n_reversed(int n){
Args v(n);
for(int i=0; i<n; i++) v[i] = _data[_data.size()-1-i];
return v;
}
void pop_n(int n){ void pop_n(int n){
_data.resize(_data.size()-n); _data.resize(_data.size()-n);
} }

View File

@ -17,6 +17,8 @@ asds1321321321测试\测试'''
assert s == 'asdasd\nasds1321321321测试\\测试' assert s == 'asdasd\nasds1321321321测试\\测试'
assert f'123{2*2}56789' == '123456789'
s = f'''->->{s}<-<- s = f'''->->{s}<-<-
{123} {123}
''' '''