From 3d610e4fdcdb1881fba46fd480f9cb3a8e5dfcdd Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Fri, 30 Dec 2022 21:03:17 +0800 Subject: [PATCH] up --- plugins/flutter/CHANGELOG.md | 2 +- plugins/flutter/lib/no_web.dart | 15 ++++++++--- plugins/flutter/lib/web.dart | 15 ++++++++--- plugins/flutter/pubspec.yaml | 2 +- plugins/flutter/src/pocketpy.h | 48 ++++++++++++++++++--------------- plugins/godot/godot-cpp | 2 +- src/main.cpp | 8 +++--- src/pocketpy.h | 14 +++++----- src/repl.h | 34 ++++++++++++----------- 9 files changed, 82 insertions(+), 58 deletions(-) diff --git a/plugins/flutter/CHANGELOG.md b/plugins/flutter/CHANGELOG.md index b0732c47..89e92b84 100644 --- a/plugins/flutter/CHANGELOG.md +++ b/plugins/flutter/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.6.0+2 +## 0.6.0+3 + Break change diff --git a/plugins/flutter/lib/no_web.dart b/plugins/flutter/lib/no_web.dart index c16391d6..ac2dedde 100644 --- a/plugins/flutter/lib/no_web.dart +++ b/plugins/flutter/lib/no_web.dart @@ -26,7 +26,8 @@ class _Bindings static final pkpy_delete = _lib.lookupFunction("pkpy_delete"); static final pkpy_new_repl = _lib.lookupFunction("pkpy_new_repl"); - static final pkpy_repl_input = _lib.lookupFunction line), int Function(ffi.Pointer r, ffi.Pointer line)>("pkpy_repl_input"); + static final pkpy_repl_input = _lib.lookupFunction line), void Function(ffi.Pointer r, ffi.Pointer line)>("pkpy_repl_input"); + static final pkpy_repl_last_input_result = _lib.lookupFunction("pkpy_repl_last_input_result"); static final pkpy_new_tvm = _lib.lookupFunction("pkpy_new_tvm"); static final pkpy_tvm_exec_async = _lib.lookupFunction source), void Function(ffi.Pointer vm, ffi.Pointer source)>("pkpy_tvm_exec_async"); static final pkpy_tvm_get_state = _lib.lookupFunction("pkpy_tvm_get_state"); @@ -162,10 +163,16 @@ class REPL { _Bindings.pkpy_delete(pointer); } - /// Input a source line to an interactive console. Return `0` if need more lines, `1` if execution happened, `2` if execution skipped (compile error or empty input). - int input(String line) + /// Input a source line to an interactive console. + void input(String line) { - var ret = _Bindings.pkpy_repl_input(pointer, _Str(line).p); + _Bindings.pkpy_repl_input(pointer, _Str(line).p); + } + + /// Check if the REPL needs more lines. + int last_input_result() + { + var ret = _Bindings.pkpy_repl_last_input_result(pointer); return ret; } diff --git a/plugins/flutter/lib/web.dart b/plugins/flutter/lib/web.dart index fa1b8523..5cc14c64 100644 --- a/plugins/flutter/lib/web.dart +++ b/plugins/flutter/lib/web.dart @@ -10,7 +10,8 @@ class _Bindings { static final pkpy_delete = (dynamic p) => ccall("pkpy_delete", null, ["number"], [p]); static final pkpy_new_repl = (dynamic vm) => ccall("pkpy_new_repl", "number", ["number"], [vm]); - static final pkpy_repl_input = (dynamic r, String line) => ccall("pkpy_repl_input", "number", ["number", "string"], [r, line]); + static final pkpy_repl_input = (dynamic r, String line) => ccall("pkpy_repl_input", null, ["number", "string"], [r, line]); + static final pkpy_repl_last_input_result = (dynamic r) => ccall("pkpy_repl_last_input_result", "number", ["number"], [r]); static final pkpy_new_tvm = (bool use_stdio) => ccall("pkpy_new_tvm", "number", ["boolean"], [use_stdio]); static final pkpy_tvm_exec_async = (dynamic vm, String source) => ccall("pkpy_tvm_exec_async", null, ["number", "string"], [vm, source]); static final pkpy_tvm_get_state = (dynamic vm) => ccall("pkpy_tvm_get_state", "number", ["number"], [vm]); @@ -126,10 +127,16 @@ class REPL { _Bindings.pkpy_delete(pointer); } - /// Input a source line to an interactive console. Return `0` if need more lines, `1` if execution happened, `2` if execution skipped (compile error or empty input). - int input(String line) + /// Input a source line to an interactive console. + void input(String line) { - var ret = _Bindings.pkpy_repl_input(pointer, line); + _Bindings.pkpy_repl_input(pointer, line); + } + + /// Check if the REPL needs more lines. + int last_input_result() + { + var ret = _Bindings.pkpy_repl_last_input_result(pointer); return ret; } diff --git a/plugins/flutter/pubspec.yaml b/plugins/flutter/pubspec.yaml index c5b8145b..4f92291d 100644 --- a/plugins/flutter/pubspec.yaml +++ b/plugins/flutter/pubspec.yaml @@ -1,6 +1,6 @@ name: pocketpy description: A lightweight Python interpreter for game engines. -version: 0.6.0+2 +version: 0.6.0+3 homepage: https://pocketpy.dev repository: https://github.com/blueloveth/pocketpy diff --git a/plugins/flutter/src/pocketpy.h b/plugins/flutter/src/pocketpy.h index fbef8666..1a8cd44e 100644 --- a/plugins/flutter/src/pocketpy.h +++ b/plugins/flutter/src/pocketpy.h @@ -6147,7 +6147,7 @@ __LISTCOMP: enum InputResult { NEED_MORE_LINES = 0, - EXEC_DONE = 1, + EXEC_STARTED = 1, EXEC_SKIPPED = 2, }; @@ -6156,12 +6156,7 @@ protected: int need_more_lines = 0; std::string buffer; VM* vm; - bool exited = false; - - void _exit(){ - exited = true; - exit(0); - } + InputResult lastResult = EXEC_SKIPPED; public: REPL(VM* vm) : vm(vm){ (*vm->_stdout) << ("pocketpy " PK_VERSION " (" __DATE__ ", " __TIME__ ")\n"); @@ -6169,12 +6164,11 @@ public: (*vm->_stdout) << ("Type \"exit()\" to exit." "\n"); } - bool is_need_more_lines() const { - return need_more_lines; + InputResult last_input_result() const { + return lastResult; } - InputResult input(std::string line){ - if(exited) return EXEC_SKIPPED; + void input(std::string line){ if(need_more_lines){ buffer += line; buffer += '\n'; @@ -6188,11 +6182,15 @@ public: buffer.clear(); }else{ __NOT_ENOUGH_LINES: - return NEED_MORE_LINES; + lastResult = NEED_MORE_LINES; + return; } }else{ - if(line == "exit()") _exit(); - if(line.empty()) return EXEC_SKIPPED; + if(line == "exit()") exit(0); + if(line.empty()) { + lastResult = EXEC_SKIPPED; + return; + } } try{ @@ -6202,12 +6200,16 @@ __NOT_ENOUGH_LINES: buffer += line; buffer += '\n'; need_more_lines = ne.isClassDef ? 3 : 2; - return NEED_MORE_LINES; + if (need_more_lines) { + lastResult = NEED_MORE_LINES; + } + return; }catch(...){ // do nothing } + + lastResult = EXEC_STARTED; vm->execAsync(line, "", SINGLE_MODE); - return EXEC_DONE; } }; @@ -7106,12 +7108,14 @@ extern "C" { __EXPORT /// Input a source line to an interactive console. - /// - /// Return `0` if need more lines, - /// `1` if execution happened, - /// `2` if execution skipped (compile error or empty input). - int pkpy_repl_input(REPL* r, const char* line){ - return r->input(line); + void pkpy_repl_input(REPL* r, const char* line){ + r->input(line); + } + + __EXPORT + /// Check if the REPL needs more lines. + int pkpy_repl_last_input_result(REPL* r){ + return (int)(r->last_input_result()); } __EXPORT diff --git a/plugins/godot/godot-cpp b/plugins/godot/godot-cpp index 9766382d..ac067d7f 160000 --- a/plugins/godot/godot-cpp +++ b/plugins/godot/godot-cpp @@ -1 +1 @@ -Subproject commit 9766382dcb2bdeace0d209b9bf2813cf62c88fb7 +Subproject commit ac067d7f1f84cb757db20ffb3c929d880053c6c1 diff --git a/src/main.cpp b/src/main.cpp index 00ede797..cde1830c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,13 +56,15 @@ int main(int argc, char** argv){ ThreadedVM* vm = pkpy_new_tvm(true); #endif REPL repl(vm); + int result = -1; while(true){ - (*vm->_stdout) << (repl.is_need_more_lines() ? "... " : ">>> "); + (*vm->_stdout) << (result==0 ? "... " : ">>> "); std::string line; std::getline(std::cin, line); - int result = pkpy_repl_input(&repl, line.c_str()); + pkpy_repl_input(&repl, line.c_str()); + result = pkpy_repl_last_input_result(&repl); #ifdef PK_DEBUG_THREADED - if(result == (int)EXEC_DONE){ + if(result == (int)EXEC_STARTED){ _tvm_dispatch(vm); pkpy_tvm_reset_state(vm); } diff --git a/src/pocketpy.h b/src/pocketpy.h index caac1e98..66a63ee1 100644 --- a/src/pocketpy.h +++ b/src/pocketpy.h @@ -900,12 +900,14 @@ extern "C" { __EXPORT /// Input a source line to an interactive console. - /// - /// Return `0` if need more lines, - /// `1` if execution happened, - /// `2` if execution skipped (compile error or empty input). - int pkpy_repl_input(REPL* r, const char* line){ - return r->input(line); + void pkpy_repl_input(REPL* r, const char* line){ + r->input(line); + } + + __EXPORT + /// Check if the REPL needs more lines. + int pkpy_repl_last_input_result(REPL* r){ + return (int)(r->last_input_result()); } __EXPORT diff --git a/src/repl.h b/src/repl.h index 92c1972a..84cb7fd9 100644 --- a/src/repl.h +++ b/src/repl.h @@ -5,7 +5,7 @@ enum InputResult { NEED_MORE_LINES = 0, - EXEC_DONE = 1, + EXEC_STARTED = 1, EXEC_SKIPPED = 2, }; @@ -14,12 +14,7 @@ protected: int need_more_lines = 0; std::string buffer; VM* vm; - bool exited = false; - - void _exit(){ - exited = true; - exit(0); - } + InputResult lastResult = EXEC_SKIPPED; public: REPL(VM* vm) : vm(vm){ (*vm->_stdout) << ("pocketpy " PK_VERSION " (" __DATE__ ", " __TIME__ ")\n"); @@ -27,12 +22,11 @@ public: (*vm->_stdout) << ("Type \"exit()\" to exit." "\n"); } - bool is_need_more_lines() const { - return need_more_lines; + InputResult last_input_result() const { + return lastResult; } - InputResult input(std::string line){ - if(exited) return EXEC_SKIPPED; + void input(std::string line){ if(need_more_lines){ buffer += line; buffer += '\n'; @@ -46,11 +40,15 @@ public: buffer.clear(); }else{ __NOT_ENOUGH_LINES: - return NEED_MORE_LINES; + lastResult = NEED_MORE_LINES; + return; } }else{ - if(line == "exit()") _exit(); - if(line.empty()) return EXEC_SKIPPED; + if(line == "exit()") exit(0); + if(line.empty()) { + lastResult = EXEC_SKIPPED; + return; + } } try{ @@ -60,11 +58,15 @@ __NOT_ENOUGH_LINES: buffer += line; buffer += '\n'; need_more_lines = ne.isClassDef ? 3 : 2; - return NEED_MORE_LINES; + if (need_more_lines) { + lastResult = NEED_MORE_LINES; + } + return; }catch(...){ // do nothing } + + lastResult = EXEC_STARTED; vm->execAsync(line, "", SINGLE_MODE); - return EXEC_DONE; } }; \ No newline at end of file