mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 12:00:18 +00:00
up
This commit is contained in:
parent
07ffe75102
commit
3d610e4fdc
@ -1,4 +1,4 @@
|
|||||||
## 0.6.0+2
|
## 0.6.0+3
|
||||||
|
|
||||||
+ Break change
|
+ Break change
|
||||||
|
|
||||||
|
@ -26,7 +26,8 @@ class _Bindings
|
|||||||
|
|
||||||
static final pkpy_delete = _lib.lookupFunction<ffi.Void Function(ffi.Pointer p), void Function(ffi.Pointer p)>("pkpy_delete");
|
static final pkpy_delete = _lib.lookupFunction<ffi.Void Function(ffi.Pointer p), void Function(ffi.Pointer p)>("pkpy_delete");
|
||||||
static final pkpy_new_repl = _lib.lookupFunction<ffi.Pointer Function(ffi.Pointer vm), ffi.Pointer Function(ffi.Pointer vm)>("pkpy_new_repl");
|
static final pkpy_new_repl = _lib.lookupFunction<ffi.Pointer Function(ffi.Pointer vm), ffi.Pointer Function(ffi.Pointer vm)>("pkpy_new_repl");
|
||||||
static final pkpy_repl_input = _lib.lookupFunction<ffi.Int32 Function(ffi.Pointer r, ffi.Pointer<Utf8> line), int Function(ffi.Pointer r, ffi.Pointer<Utf8> line)>("pkpy_repl_input");
|
static final pkpy_repl_input = _lib.lookupFunction<ffi.Void Function(ffi.Pointer r, ffi.Pointer<Utf8> line), void Function(ffi.Pointer r, ffi.Pointer<Utf8> line)>("pkpy_repl_input");
|
||||||
|
static final pkpy_repl_last_input_result = _lib.lookupFunction<ffi.Int32 Function(ffi.Pointer r), int Function(ffi.Pointer r)>("pkpy_repl_last_input_result");
|
||||||
static final pkpy_new_tvm = _lib.lookupFunction<ffi.Pointer Function(ffi.Bool use_stdio), ffi.Pointer Function(bool use_stdio)>("pkpy_new_tvm");
|
static final pkpy_new_tvm = _lib.lookupFunction<ffi.Pointer Function(ffi.Bool use_stdio), ffi.Pointer Function(bool use_stdio)>("pkpy_new_tvm");
|
||||||
static final pkpy_tvm_exec_async = _lib.lookupFunction<ffi.Void Function(ffi.Pointer vm, ffi.Pointer<Utf8> source), void Function(ffi.Pointer vm, ffi.Pointer<Utf8> source)>("pkpy_tvm_exec_async");
|
static final pkpy_tvm_exec_async = _lib.lookupFunction<ffi.Void Function(ffi.Pointer vm, ffi.Pointer<Utf8> source), void Function(ffi.Pointer vm, ffi.Pointer<Utf8> source)>("pkpy_tvm_exec_async");
|
||||||
static final pkpy_tvm_get_state = _lib.lookupFunction<ffi.Int32 Function(ffi.Pointer vm), int Function(ffi.Pointer vm)>("pkpy_tvm_get_state");
|
static final pkpy_tvm_get_state = _lib.lookupFunction<ffi.Int32 Function(ffi.Pointer vm), int Function(ffi.Pointer vm)>("pkpy_tvm_get_state");
|
||||||
@ -162,10 +163,16 @@ class REPL {
|
|||||||
_Bindings.pkpy_delete(pointer);
|
_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).
|
/// Input a source line to an interactive console.
|
||||||
int input(String line)
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,8 @@ class _Bindings
|
|||||||
{
|
{
|
||||||
static final pkpy_delete = (dynamic p) => ccall("pkpy_delete", null, ["number"], [p]);
|
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_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_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_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]);
|
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);
|
_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).
|
/// Input a source line to an interactive console.
|
||||||
int input(String line)
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: pocketpy
|
name: pocketpy
|
||||||
description: A lightweight Python interpreter for game engines.
|
description: A lightweight Python interpreter for game engines.
|
||||||
version: 0.6.0+2
|
version: 0.6.0+3
|
||||||
homepage: https://pocketpy.dev
|
homepage: https://pocketpy.dev
|
||||||
repository: https://github.com/blueloveth/pocketpy
|
repository: https://github.com/blueloveth/pocketpy
|
||||||
|
|
||||||
|
@ -6147,7 +6147,7 @@ __LISTCOMP:
|
|||||||
|
|
||||||
enum InputResult {
|
enum InputResult {
|
||||||
NEED_MORE_LINES = 0,
|
NEED_MORE_LINES = 0,
|
||||||
EXEC_DONE = 1,
|
EXEC_STARTED = 1,
|
||||||
EXEC_SKIPPED = 2,
|
EXEC_SKIPPED = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -6156,12 +6156,7 @@ protected:
|
|||||||
int need_more_lines = 0;
|
int need_more_lines = 0;
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
VM* vm;
|
VM* vm;
|
||||||
bool exited = false;
|
InputResult lastResult = EXEC_SKIPPED;
|
||||||
|
|
||||||
void _exit(){
|
|
||||||
exited = true;
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
public:
|
public:
|
||||||
REPL(VM* vm) : vm(vm){
|
REPL(VM* vm) : vm(vm){
|
||||||
(*vm->_stdout) << ("pocketpy " PK_VERSION " (" __DATE__ ", " __TIME__ ")\n");
|
(*vm->_stdout) << ("pocketpy " PK_VERSION " (" __DATE__ ", " __TIME__ ")\n");
|
||||||
@ -6169,12 +6164,11 @@ public:
|
|||||||
(*vm->_stdout) << ("Type \"exit()\" to exit." "\n");
|
(*vm->_stdout) << ("Type \"exit()\" to exit." "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_need_more_lines() const {
|
InputResult last_input_result() const {
|
||||||
return need_more_lines;
|
return lastResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
InputResult input(std::string line){
|
void input(std::string line){
|
||||||
if(exited) return EXEC_SKIPPED;
|
|
||||||
if(need_more_lines){
|
if(need_more_lines){
|
||||||
buffer += line;
|
buffer += line;
|
||||||
buffer += '\n';
|
buffer += '\n';
|
||||||
@ -6188,11 +6182,15 @@ public:
|
|||||||
buffer.clear();
|
buffer.clear();
|
||||||
}else{
|
}else{
|
||||||
__NOT_ENOUGH_LINES:
|
__NOT_ENOUGH_LINES:
|
||||||
return NEED_MORE_LINES;
|
lastResult = NEED_MORE_LINES;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if(line == "exit()") _exit();
|
if(line == "exit()") exit(0);
|
||||||
if(line.empty()) return EXEC_SKIPPED;
|
if(line.empty()) {
|
||||||
|
lastResult = EXEC_SKIPPED;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
@ -6202,12 +6200,16 @@ __NOT_ENOUGH_LINES:
|
|||||||
buffer += line;
|
buffer += line;
|
||||||
buffer += '\n';
|
buffer += '\n';
|
||||||
need_more_lines = ne.isClassDef ? 3 : 2;
|
need_more_lines = ne.isClassDef ? 3 : 2;
|
||||||
return NEED_MORE_LINES;
|
if (need_more_lines) {
|
||||||
|
lastResult = NEED_MORE_LINES;
|
||||||
|
}
|
||||||
|
return;
|
||||||
}catch(...){
|
}catch(...){
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastResult = EXEC_STARTED;
|
||||||
vm->execAsync(line, "<stdin>", SINGLE_MODE);
|
vm->execAsync(line, "<stdin>", SINGLE_MODE);
|
||||||
return EXEC_DONE;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -7106,12 +7108,14 @@ extern "C" {
|
|||||||
|
|
||||||
__EXPORT
|
__EXPORT
|
||||||
/// Input a source line to an interactive console.
|
/// Input a source line to an interactive console.
|
||||||
///
|
void pkpy_repl_input(REPL* r, const char* line){
|
||||||
/// Return `0` if need more lines,
|
r->input(line);
|
||||||
/// `1` if execution happened,
|
}
|
||||||
/// `2` if execution skipped (compile error or empty input).
|
|
||||||
int pkpy_repl_input(REPL* r, const char* line){
|
__EXPORT
|
||||||
return r->input(line);
|
/// Check if the REPL needs more lines.
|
||||||
|
int pkpy_repl_last_input_result(REPL* r){
|
||||||
|
return (int)(r->last_input_result());
|
||||||
}
|
}
|
||||||
|
|
||||||
__EXPORT
|
__EXPORT
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 9766382dcb2bdeace0d209b9bf2813cf62c88fb7
|
Subproject commit ac067d7f1f84cb757db20ffb3c929d880053c6c1
|
@ -56,13 +56,15 @@ int main(int argc, char** argv){
|
|||||||
ThreadedVM* vm = pkpy_new_tvm(true);
|
ThreadedVM* vm = pkpy_new_tvm(true);
|
||||||
#endif
|
#endif
|
||||||
REPL repl(vm);
|
REPL repl(vm);
|
||||||
|
int result = -1;
|
||||||
while(true){
|
while(true){
|
||||||
(*vm->_stdout) << (repl.is_need_more_lines() ? "... " : ">>> ");
|
(*vm->_stdout) << (result==0 ? "... " : ">>> ");
|
||||||
std::string line;
|
std::string line;
|
||||||
std::getline(std::cin, 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
|
#ifdef PK_DEBUG_THREADED
|
||||||
if(result == (int)EXEC_DONE){
|
if(result == (int)EXEC_STARTED){
|
||||||
_tvm_dispatch(vm);
|
_tvm_dispatch(vm);
|
||||||
pkpy_tvm_reset_state(vm);
|
pkpy_tvm_reset_state(vm);
|
||||||
}
|
}
|
||||||
|
@ -900,12 +900,14 @@ extern "C" {
|
|||||||
|
|
||||||
__EXPORT
|
__EXPORT
|
||||||
/// Input a source line to an interactive console.
|
/// Input a source line to an interactive console.
|
||||||
///
|
void pkpy_repl_input(REPL* r, const char* line){
|
||||||
/// Return `0` if need more lines,
|
r->input(line);
|
||||||
/// `1` if execution happened,
|
}
|
||||||
/// `2` if execution skipped (compile error or empty input).
|
|
||||||
int pkpy_repl_input(REPL* r, const char* line){
|
__EXPORT
|
||||||
return r->input(line);
|
/// Check if the REPL needs more lines.
|
||||||
|
int pkpy_repl_last_input_result(REPL* r){
|
||||||
|
return (int)(r->last_input_result());
|
||||||
}
|
}
|
||||||
|
|
||||||
__EXPORT
|
__EXPORT
|
||||||
|
34
src/repl.h
34
src/repl.h
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
enum InputResult {
|
enum InputResult {
|
||||||
NEED_MORE_LINES = 0,
|
NEED_MORE_LINES = 0,
|
||||||
EXEC_DONE = 1,
|
EXEC_STARTED = 1,
|
||||||
EXEC_SKIPPED = 2,
|
EXEC_SKIPPED = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -14,12 +14,7 @@ protected:
|
|||||||
int need_more_lines = 0;
|
int need_more_lines = 0;
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
VM* vm;
|
VM* vm;
|
||||||
bool exited = false;
|
InputResult lastResult = EXEC_SKIPPED;
|
||||||
|
|
||||||
void _exit(){
|
|
||||||
exited = true;
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
public:
|
public:
|
||||||
REPL(VM* vm) : vm(vm){
|
REPL(VM* vm) : vm(vm){
|
||||||
(*vm->_stdout) << ("pocketpy " PK_VERSION " (" __DATE__ ", " __TIME__ ")\n");
|
(*vm->_stdout) << ("pocketpy " PK_VERSION " (" __DATE__ ", " __TIME__ ")\n");
|
||||||
@ -27,12 +22,11 @@ public:
|
|||||||
(*vm->_stdout) << ("Type \"exit()\" to exit." "\n");
|
(*vm->_stdout) << ("Type \"exit()\" to exit." "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_need_more_lines() const {
|
InputResult last_input_result() const {
|
||||||
return need_more_lines;
|
return lastResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
InputResult input(std::string line){
|
void input(std::string line){
|
||||||
if(exited) return EXEC_SKIPPED;
|
|
||||||
if(need_more_lines){
|
if(need_more_lines){
|
||||||
buffer += line;
|
buffer += line;
|
||||||
buffer += '\n';
|
buffer += '\n';
|
||||||
@ -46,11 +40,15 @@ public:
|
|||||||
buffer.clear();
|
buffer.clear();
|
||||||
}else{
|
}else{
|
||||||
__NOT_ENOUGH_LINES:
|
__NOT_ENOUGH_LINES:
|
||||||
return NEED_MORE_LINES;
|
lastResult = NEED_MORE_LINES;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if(line == "exit()") _exit();
|
if(line == "exit()") exit(0);
|
||||||
if(line.empty()) return EXEC_SKIPPED;
|
if(line.empty()) {
|
||||||
|
lastResult = EXEC_SKIPPED;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
@ -60,11 +58,15 @@ __NOT_ENOUGH_LINES:
|
|||||||
buffer += line;
|
buffer += line;
|
||||||
buffer += '\n';
|
buffer += '\n';
|
||||||
need_more_lines = ne.isClassDef ? 3 : 2;
|
need_more_lines = ne.isClassDef ? 3 : 2;
|
||||||
return NEED_MORE_LINES;
|
if (need_more_lines) {
|
||||||
|
lastResult = NEED_MORE_LINES;
|
||||||
|
}
|
||||||
|
return;
|
||||||
}catch(...){
|
}catch(...){
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastResult = EXEC_STARTED;
|
||||||
vm->execAsync(line, "<stdin>", SINGLE_MODE);
|
vm->execAsync(line, "<stdin>", SINGLE_MODE);
|
||||||
return EXEC_DONE;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user