mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
up
This commit is contained in:
parent
baf7ad6b50
commit
818ee2981e
@ -27,7 +27,11 @@ def test_dir(path):
|
||||
print(f' cpython: {_1 - _0:.6f}s (100%)')
|
||||
print(f' pocketpy: {_2 - _1:.6f}s ({(_2 - _1) / (_1 - _0) * 100:.2f}%)')
|
||||
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:
|
||||
assert 'benchmark' in sys.argv[1]
|
||||
|
@ -149,11 +149,8 @@ __NEXT_STEP:;
|
||||
frame->push(VAR(std::move(items)));
|
||||
} DISPATCH();
|
||||
case OP_BUILD_STRING: {
|
||||
// asStr() may run extra bytecode
|
||||
// so we use top_n_reversed() in order to avoid accidental gc
|
||||
Args items = frame->top_n_reversed(byte.arg);
|
||||
StrStream ss;
|
||||
for(int i=0; i<items.size(); i++) ss << CAST(Str, asStr(items[i]));
|
||||
StrStream ss; // asStr() may run extra bytecode
|
||||
for(int i=byte.arg-1; i>=0; i--) ss << CAST(Str&, asStr(frame->top_n(i)));
|
||||
frame->pop_n(byte.arg);
|
||||
frame->push(VAR(ss.str()));
|
||||
} DISPATCH();
|
||||
|
@ -35,7 +35,7 @@
|
||||
#define DEBUG_EXTRA_CHECK 1
|
||||
#define DEBUG_DIS_REPL 0
|
||||
#define DEBUG_DIS_REPL_MIN 1
|
||||
#define DEBUG_FULL_EXCEPTION 1
|
||||
#define DEBUG_FULL_EXCEPTION 0
|
||||
|
||||
#if (defined(__ANDROID__) && __ANDROID_API__ <= 22) || defined(__EMSCRIPTEN__)
|
||||
#define PK_ENABLE_FILEIO 0
|
||||
|
@ -952,7 +952,7 @@ public:
|
||||
match_newlines(); // skip possible leading '\n'
|
||||
|
||||
if(mode()==EVAL_MODE) {
|
||||
EXPR_TUPLE();
|
||||
EXPR_TUPLE(false);
|
||||
consume(TK("@eof"));
|
||||
ctx()->emit(OP_RETURN_VALUE, BC_NOARG, BC_KEEPLINE);
|
||||
pop_context();
|
||||
|
13
src/frame.h
13
src/frame.h
@ -85,11 +85,12 @@ struct Frame {
|
||||
return _data[_data.size()-2];
|
||||
}
|
||||
|
||||
PyObject*& top_2(){
|
||||
PyObject*& top_n(int n){
|
||||
n += 1;
|
||||
#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
|
||||
return _data[_data.size()-3];
|
||||
return _data[_data.size()-n];
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@ -142,12 +143,6 @@ struct Frame {
|
||||
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){
|
||||
_data.resize(_data.size()-n);
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ asds1321321321测试\测试'''
|
||||
|
||||
assert s == 'asdasd\nasds1321321321测试\\测试'
|
||||
|
||||
assert f'123{2*2}56789' == '123456789'
|
||||
|
||||
s = f'''->->{s}<-<-
|
||||
{123}
|
||||
'''
|
||||
|
Loading…
x
Reference in New Issue
Block a user