mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
rename
This commit is contained in:
parent
7ad0ed1e2e
commit
f129b1913d
@ -3,7 +3,7 @@ with open("src/opcodes.h", "rt", encoding='utf-8') as f:
|
|||||||
|
|
||||||
pipeline = [
|
pipeline = [
|
||||||
["hash_table8.hpp", "__stl__.h", "memory.h", "str.h", "safestl.h", "builtins.h", "error.h"],
|
["hash_table8.hpp", "__stl__.h", "memory.h", "str.h", "safestl.h", "builtins.h", "error.h"],
|
||||||
["obj.h", "iter.h", "parser.h", "pointer.h", "codeobject.h"],
|
["obj.h", "iter.h", "parser.h", "ref.h", "codeobject.h"],
|
||||||
["vm.h", "compiler.h", "repl.h"],
|
["vm.h", "compiler.h", "repl.h"],
|
||||||
["pocketpy.h"]
|
["pocketpy.h"]
|
||||||
]
|
]
|
||||||
@ -51,7 +51,7 @@ r'''/*
|
|||||||
f.write(final_text)
|
f.write(final_text)
|
||||||
|
|
||||||
shutil.copy("src/main.cpp", "amalgamated/main.cpp")
|
shutil.copy("src/main.cpp", "amalgamated/main.cpp")
|
||||||
os.system("g++ -o pocketpy amalgamated/main.cpp --std=c++17 -pthread")
|
os.system("g++ -o pocketpy amalgamated/main.cpp --std=c++17")
|
||||||
os.system("rm pocketpy")
|
os.system("rm pocketpy")
|
||||||
|
|
||||||
os.system("cp amalgamated/pocketpy.h plugins/flutter/src/pocketpy.h")
|
os.system("cp amalgamated/pocketpy.h plugins/flutter/src/pocketpy.h")
|
||||||
|
@ -1828,11 +1828,9 @@ private:
|
|||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
#include <emscripten.h>
|
#include <emscripten.h>
|
||||||
#else
|
|
||||||
#include <thread>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define PK_VERSION "0.6.2"
|
#define PK_VERSION "0.8.0"
|
||||||
|
|
||||||
//#define PKPY_NO_INDEX_CHECK
|
//#define PKPY_NO_INDEX_CHECK
|
||||||
|
|
||||||
@ -3114,9 +3112,7 @@ constexpr _TokenType TK(const char* const token) {
|
|||||||
for(int k=0; k<__TOKENS_LEN; k++){
|
for(int k=0; k<__TOKENS_LEN; k++){
|
||||||
const char* i = __TOKENS[k];
|
const char* i = __TOKENS[k];
|
||||||
const char* j = token;
|
const char* j = token;
|
||||||
while(*i && *j && *i == *j){
|
while(*i && *j && *i == *j) { i++; j++;}
|
||||||
i++; j++;
|
|
||||||
}
|
|
||||||
if(*i == *j) return k;
|
if(*i == *j) return k;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -3187,9 +3183,7 @@ struct Parser {
|
|||||||
std::queue<Token> nexts;
|
std::queue<Token> nexts;
|
||||||
std::stack<int> indents;
|
std::stack<int> indents;
|
||||||
|
|
||||||
int brackets_level_0 = 0;
|
int brackets_level = 0;
|
||||||
int brackets_level_1 = 0;
|
|
||||||
int brackets_level_2 = 0;
|
|
||||||
|
|
||||||
Token next_token(){
|
Token next_token(){
|
||||||
if(nexts.empty()){
|
if(nexts.empty()){
|
||||||
@ -3229,7 +3223,7 @@ struct Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool eat_indentation(){
|
bool eat_indentation(){
|
||||||
if(brackets_level_0 > 0 || brackets_level_1 > 0 || brackets_level_2 > 0) return true;
|
if(brackets_level > 0) return true;
|
||||||
int spaces = eat_spaces();
|
int spaces = eat_spaces();
|
||||||
if(peekchar() == '#') skip_line_comment();
|
if(peekchar() == '#') skip_line_comment();
|
||||||
if(peekchar() == '\0' || peekchar() == '\n') return true;
|
if(peekchar() == '\0' || peekchar() == '\n') return true;
|
||||||
@ -3358,16 +3352,10 @@ struct Parser {
|
|||||||
|
|
||||||
// Initialize the next token as the type.
|
// Initialize the next token as the type.
|
||||||
void set_next_token(_TokenType type, PyVar value=nullptr) {
|
void set_next_token(_TokenType type, PyVar value=nullptr) {
|
||||||
|
|
||||||
switch(type){
|
switch(type){
|
||||||
case TK("("): brackets_level_0++; break;
|
case TK("{"): case TK("["): case TK("("): brackets_level++; break;
|
||||||
case TK(")"): brackets_level_0--; break;
|
case TK(")"): case TK("]"): case TK("}"): brackets_level--; break;
|
||||||
case TK("["): brackets_level_1++; break;
|
|
||||||
case TK("]"): brackets_level_1--; break;
|
|
||||||
case TK("{"): brackets_level_2++; break;
|
|
||||||
case TK("}"): brackets_level_2--; break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nexts.push( Token{
|
nexts.push( Token{
|
||||||
type,
|
type,
|
||||||
token_start,
|
token_start,
|
||||||
@ -3877,7 +3865,6 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
class VM {
|
class VM {
|
||||||
std::atomic<bool> _stop_flag = false;
|
|
||||||
std::vector<PyVar> _small_integers; // [-5, 256]
|
std::vector<PyVar> _small_integers; // [-5, 256]
|
||||||
PyVarDict _modules; // loaded modules
|
PyVarDict _modules; // loaded modules
|
||||||
emhash8::HashMap<_Str, _Str> _lazy_modules; // lazy loaded modules
|
emhash8::HashMap<_Str, _Str> _lazy_modules; // lazy loaded modules
|
||||||
@ -3885,21 +3872,11 @@ protected:
|
|||||||
std::deque< std::unique_ptr<Frame> > callstack;
|
std::deque< std::unique_ptr<Frame> > callstack;
|
||||||
PyVar __py2py_call_signal;
|
PyVar __py2py_call_signal;
|
||||||
|
|
||||||
inline void test_stop_flag(){
|
|
||||||
if(_stop_flag){
|
|
||||||
_stop_flag = false;
|
|
||||||
_error("KeyboardInterrupt", "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PyVar run_frame(Frame* frame){
|
PyVar run_frame(Frame* frame){
|
||||||
while(frame->has_next_bytecode()){
|
while(frame->has_next_bytecode()){
|
||||||
const Bytecode& byte = frame->next_bytecode();
|
const Bytecode& byte = frame->next_bytecode();
|
||||||
//printf("[%d] %s (%d)\n", frame->stack_size(), OP_NAMES[byte.op], byte.arg);
|
//printf("[%d] %s (%d)\n", frame->stack_size(), OP_NAMES[byte.op], byte.arg);
|
||||||
//printf("%s\n", frame->code->src->getLine(byte.line).c_str());
|
//printf("%s\n", frame->code->src->getLine(byte.line).c_str());
|
||||||
|
|
||||||
test_stop_flag();
|
|
||||||
|
|
||||||
switch (byte.op)
|
switch (byte.op)
|
||||||
{
|
{
|
||||||
case OP_NO_OP: break; // do nothing
|
case OP_NO_OP: break; // do nothing
|
||||||
@ -4236,22 +4213,6 @@ public:
|
|||||||
for(i64 i=-5; i<=256; i++) _small_integers.push_back(new_object(_tp_int, i));
|
for(i64 i=-5; i<=256; i++) _small_integers.push_back(new_object(_tp_int, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
void keyboardInterrupt(){
|
|
||||||
_stop_flag = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void sleepForSecs(f64 sec){
|
|
||||||
i64 ms = (i64)(sec * 1000);
|
|
||||||
for(i64 i=0; i<ms; i+=20){
|
|
||||||
test_stop_flag();
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
emscripten_sleep(20);
|
|
||||||
#else
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PyVar asStr(const PyVar& obj){
|
PyVar asStr(const PyVar& obj){
|
||||||
PyVarOrNull str_fn = getattr(obj, __str__, false);
|
PyVarOrNull str_fn = getattr(obj, __str__, false);
|
||||||
if(str_fn != nullptr) return call(str_fn);
|
if(str_fn != nullptr) return call(str_fn);
|
||||||
@ -4422,10 +4383,6 @@ public:
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void execAsync(_Str source, _Str filename, CompileMode mode) {
|
|
||||||
exec(source, filename, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
Frame* __pushNewFrame(const _Code& code, PyVar _module, PyVarDict&& locals){
|
Frame* __pushNewFrame(const _Code& code, PyVar _module, PyVarDict&& locals){
|
||||||
if(code == nullptr) UNREACHABLE();
|
if(code == nullptr) UNREACHABLE();
|
||||||
if(callstack.size() > maxRecursionDepth){
|
if(callstack.size() > maxRecursionDepth){
|
||||||
@ -4593,7 +4550,8 @@ public:
|
|||||||
}else if(obj->is_type(_tp_float)){
|
}else if(obj->is_type(_tp_float)){
|
||||||
return PyFloat_AS_C(obj);
|
return PyFloat_AS_C(obj);
|
||||||
}
|
}
|
||||||
UNREACHABLE();
|
typeError("expected int or float");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyVar num_negated(const PyVar& obj){
|
PyVar num_negated(const PyVar& obj){
|
||||||
@ -4781,9 +4739,7 @@ public:
|
|||||||
i64 x = 1000003;
|
i64 x = 1000003;
|
||||||
for (const auto& item : PyTuple_AS_C(obj)) {
|
for (const auto& item : PyTuple_AS_C(obj)) {
|
||||||
i64 y = hash(item);
|
i64 y = hash(item);
|
||||||
// this is recommended by Github Copilot
|
x = x ^ (y + 0x9e3779b9 + (x << 6) + (x >> 2)); // recommended by Github Copilot
|
||||||
// i am not sure whether it is a good idea
|
|
||||||
x = x ^ (y + 0x9e3779b9 + (x << 6) + (x >> 2));
|
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
@ -4879,10 +4835,10 @@ void NameRef::del(VM* vm, Frame* frame) const{
|
|||||||
} break;
|
} break;
|
||||||
case NAME_GLOBAL:
|
case NAME_GLOBAL:
|
||||||
{
|
{
|
||||||
if(frame->f_locals.count(pair->first) > 0){
|
if(frame->f_locals.contains(pair->first)){
|
||||||
frame->f_locals.erase(pair->first);
|
frame->f_locals.erase(pair->first);
|
||||||
}else{
|
}else{
|
||||||
if(frame->f_globals().count(pair->first) > 0){
|
if(frame->f_globals().contains(pair->first)){
|
||||||
frame->f_globals().erase(pair->first);
|
frame->f_globals().erase(pair->first);
|
||||||
}else{
|
}else{
|
||||||
vm->nameError(pair->first);
|
vm->nameError(pair->first);
|
||||||
@ -4957,124 +4913,6 @@ PyVar StringIterator::next(){
|
|||||||
return vm->PyStr(str.u8_getitem(index++));
|
return vm->PyStr(str.u8_getitem(index++));
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ThreadState {
|
|
||||||
THREAD_READY,
|
|
||||||
THREAD_RUNNING,
|
|
||||||
THREAD_SUSPENDED,
|
|
||||||
THREAD_FINISHED
|
|
||||||
};
|
|
||||||
|
|
||||||
class ThreadedVM : public VM {
|
|
||||||
std::atomic<ThreadState> _state = THREAD_READY;
|
|
||||||
_Str _sharedStr = "";
|
|
||||||
|
|
||||||
#ifndef __EMSCRIPTEN__
|
|
||||||
std::thread* _thread = nullptr;
|
|
||||||
void __deleteThread(){
|
|
||||||
if(_thread != nullptr){
|
|
||||||
terminate();
|
|
||||||
_thread->join();
|
|
||||||
delete _thread;
|
|
||||||
_thread = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
void __deleteThread(){
|
|
||||||
terminate();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
|
||||||
ThreadedVM(bool use_stdio) : VM(use_stdio) {
|
|
||||||
bindBuiltinFunc("__string_channel_call", [](VM* vm, const pkpy::ArgList& args){
|
|
||||||
vm->check_args_size(args, 1);
|
|
||||||
_Str data = vm->PyStr_AS_C(args[0]);
|
|
||||||
|
|
||||||
ThreadedVM* tvm = (ThreadedVM*)vm;
|
|
||||||
tvm->_sharedStr = data;
|
|
||||||
tvm->suspend();
|
|
||||||
return tvm->PyStr(tvm->readJsonRpcRequest());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void terminate(){
|
|
||||||
if(_state == THREAD_RUNNING || _state == THREAD_SUSPENDED){
|
|
||||||
keyboardInterrupt();
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
// no way to terminate safely
|
|
||||||
#else
|
|
||||||
while(_state != THREAD_FINISHED);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void suspend(){
|
|
||||||
if(_state != THREAD_RUNNING) UNREACHABLE();
|
|
||||||
_state = THREAD_SUSPENDED;
|
|
||||||
while(_state == THREAD_SUSPENDED){
|
|
||||||
test_stop_flag();
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
emscripten_sleep(20);
|
|
||||||
#else
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_Str readJsonRpcRequest(){
|
|
||||||
_Str copy = _sharedStr;
|
|
||||||
_sharedStr = "";
|
|
||||||
return copy;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***** For outer use *****/
|
|
||||||
|
|
||||||
ThreadState getState(){
|
|
||||||
return _state;
|
|
||||||
}
|
|
||||||
|
|
||||||
void writeJsonrpcResponse(const char* value){
|
|
||||||
if(_state != THREAD_SUSPENDED) UNREACHABLE();
|
|
||||||
_sharedStr = _Str(value);
|
|
||||||
_state = THREAD_RUNNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
void execAsync(_Str source, _Str filename, CompileMode mode) override {
|
|
||||||
if(_state != THREAD_READY) UNREACHABLE();
|
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
this->_state = THREAD_RUNNING;
|
|
||||||
VM::exec(source, filename, mode);
|
|
||||||
this->_state = THREAD_FINISHED;
|
|
||||||
#else
|
|
||||||
__deleteThread();
|
|
||||||
_thread = new std::thread([=](){
|
|
||||||
this->_state = THREAD_RUNNING;
|
|
||||||
VM::exec(source, filename, mode);
|
|
||||||
this->_state = THREAD_FINISHED;
|
|
||||||
});
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
PyVarOrNull exec(_Str source, _Str filename, CompileMode mode, PyVar _module=nullptr) override {
|
|
||||||
if(_state == THREAD_READY) return VM::exec(source, filename, mode, _module);
|
|
||||||
auto callstackBackup = std::move(callstack);
|
|
||||||
callstack.clear();
|
|
||||||
PyVarOrNull ret = VM::exec(source, filename, mode, _module);
|
|
||||||
callstack = std::move(callstackBackup);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void resetState(){
|
|
||||||
if(this->_state != THREAD_FINISHED) return;
|
|
||||||
this->_state = THREAD_READY;
|
|
||||||
}
|
|
||||||
|
|
||||||
~ThreadedVM(){
|
|
||||||
__deleteThread();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class Compiler;
|
class Compiler;
|
||||||
|
|
||||||
@ -6178,7 +6016,6 @@ protected:
|
|||||||
int need_more_lines = 0;
|
int need_more_lines = 0;
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
VM* vm;
|
VM* vm;
|
||||||
InputResult lastResult = EXEC_SKIPPED;
|
|
||||||
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");
|
||||||
@ -6186,11 +6023,7 @@ public:
|
|||||||
(*vm->_stdout) << ("Type \"exit()\" to exit." "\n");
|
(*vm->_stdout) << ("Type \"exit()\" to exit." "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
InputResult last_input_result() const {
|
InputResult input(std::string line){
|
||||||
return lastResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
void input(std::string line){
|
|
||||||
if(need_more_lines){
|
if(need_more_lines){
|
||||||
buffer += line;
|
buffer += line;
|
||||||
buffer += '\n';
|
buffer += '\n';
|
||||||
@ -6204,15 +6037,10 @@ public:
|
|||||||
buffer.clear();
|
buffer.clear();
|
||||||
}else{
|
}else{
|
||||||
__NOT_ENOUGH_LINES:
|
__NOT_ENOUGH_LINES:
|
||||||
lastResult = NEED_MORE_LINES;
|
return NEED_MORE_LINES;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if(line == "exit()") exit(0);
|
if(line.empty()) return EXEC_SKIPPED;
|
||||||
if(line.empty()) {
|
|
||||||
lastResult = EXEC_SKIPPED;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
@ -6222,16 +6050,12 @@ __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;
|
||||||
if (need_more_lines) {
|
if (need_more_lines) return NEED_MORE_LINES;
|
||||||
lastResult = NEED_MORE_LINES;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}catch(...){
|
}catch(...){
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
vm->exec(line, "<stdin>", SINGLE_MODE);
|
||||||
lastResult = EXEC_STARTED;
|
return EXEC_STARTED;
|
||||||
vm->execAsync(line, "<stdin>", SINGLE_MODE);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -6840,16 +6664,6 @@ void __addModuleTime(VM* vm){
|
|||||||
auto now = std::chrono::high_resolution_clock::now();
|
auto now = std::chrono::high_resolution_clock::now();
|
||||||
return vm->PyFloat(std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count() / 1000000.0);
|
return vm->PyFloat(std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count() / 1000000.0);
|
||||||
});
|
});
|
||||||
|
|
||||||
vm->bindFunc(mod, "sleep", [](VM* vm, const pkpy::ArgList& args) {
|
|
||||||
vm->check_args_size(args, 1);
|
|
||||||
if(!vm->is_int_or_float(args[0])){
|
|
||||||
vm->typeError("time.sleep() argument must be int or float");
|
|
||||||
}
|
|
||||||
double sec = vm->num_to_float(args[0]);
|
|
||||||
vm->sleepForSecs(sec);
|
|
||||||
return vm->None;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void __addModuleSys(VM* vm){
|
void __addModuleSys(VM* vm){
|
||||||
@ -7063,7 +6877,7 @@ public:
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
__EXPORT
|
__EXPORT
|
||||||
/// Delete a pointer allocated by `pkpy_xxx_xxx`.
|
/// Delete a pointer allocated by `pkpy_xxx_xxx`.
|
||||||
/// It can be `VM*`, `REPL*`, `ThreadedVM*`, `char*`, etc.
|
/// It can be `VM*`, `REPL*`, `char*`, etc.
|
||||||
///
|
///
|
||||||
/// !!!
|
/// !!!
|
||||||
/// If the pointer is not allocated by `pkpy_xxx_xxx`, the behavior is undefined.
|
/// If the pointer is not allocated by `pkpy_xxx_xxx`, the behavior is undefined.
|
||||||
@ -7126,14 +6940,8 @@ 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){
|
int pkpy_repl_input(REPL* r, const char* line){
|
||||||
r->input(line);
|
return 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
|
__EXPORT
|
||||||
@ -7166,14 +6974,6 @@ extern "C" {
|
|||||||
return vm;
|
return vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
__EXPORT
|
|
||||||
/// Create a virtual machine that supports asynchronous execution.
|
|
||||||
ThreadedVM* pkpy_new_tvm(bool use_stdio){
|
|
||||||
ThreadedVM* vm = pkpy_allocate(ThreadedVM, use_stdio);
|
|
||||||
__vm_init(vm);
|
|
||||||
return vm;
|
|
||||||
}
|
|
||||||
|
|
||||||
__EXPORT
|
__EXPORT
|
||||||
/// Read the standard output and standard error as string of a virtual machine.
|
/// Read the standard output and standard error as string of a virtual machine.
|
||||||
/// The `vm->use_stdio` should be `false`.
|
/// The `vm->use_stdio` should be `false`.
|
||||||
@ -7194,50 +6994,6 @@ extern "C" {
|
|||||||
s_err->str("");
|
s_err->str("");
|
||||||
return strdup(ss.str().c_str());
|
return strdup(ss.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
__EXPORT
|
|
||||||
/// Get the current state of a threaded virtual machine.
|
|
||||||
///
|
|
||||||
/// Return `0` for `THREAD_READY`,
|
|
||||||
/// `1` for `THREAD_RUNNING`,
|
|
||||||
/// `2` for `THREAD_SUSPENDED`,
|
|
||||||
/// `3` for `THREAD_FINISHED`.
|
|
||||||
int pkpy_tvm_get_state(ThreadedVM* vm){
|
|
||||||
return vm->getState();
|
|
||||||
}
|
|
||||||
|
|
||||||
__EXPORT
|
|
||||||
/// Set the state of a threaded virtual machine to `THREAD_READY`.
|
|
||||||
/// The current state should be `THREAD_FINISHED`.
|
|
||||||
void pkpy_tvm_reset_state(ThreadedVM* vm){
|
|
||||||
vm->resetState();
|
|
||||||
}
|
|
||||||
|
|
||||||
__EXPORT
|
|
||||||
/// Read the current JSONRPC request from shared string buffer.
|
|
||||||
char* pkpy_tvm_read_jsonrpc_request(ThreadedVM* vm){
|
|
||||||
_Str s = vm->readJsonRpcRequest();
|
|
||||||
return strdup(s.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
__EXPORT
|
|
||||||
/// Write a JSONRPC response to shared string buffer.
|
|
||||||
void pkpy_tvm_write_jsonrpc_response(ThreadedVM* vm, const char* value){
|
|
||||||
vm->writeJsonrpcResponse(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
__EXPORT
|
|
||||||
/// Emit a KeyboardInterrupt signal to stop a running threaded virtual machine.
|
|
||||||
void pkpy_tvm_terminate(ThreadedVM* vm){
|
|
||||||
vm->terminate();
|
|
||||||
}
|
|
||||||
|
|
||||||
__EXPORT
|
|
||||||
/// Run a given source on a threaded virtual machine.
|
|
||||||
/// The excution will be started in a new thread.
|
|
||||||
void pkpy_tvm_exec_async(VM* vm, const char* source){
|
|
||||||
vm->execAsync(source, "main.py", EXEC_MODE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // POCKETPY_H
|
#endif // POCKETPY_H
|
@ -36,6 +36,6 @@
|
|||||||
#include <emscripten.h>
|
#include <emscripten.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define PK_VERSION "0.6.2"
|
#define PK_VERSION "0.8.0"
|
||||||
|
|
||||||
//#define PKPY_NO_INDEX_CHECK
|
//#define PKPY_NO_INDEX_CHECK
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "obj.h"
|
#include "obj.h"
|
||||||
#include "pointer.h"
|
#include "ref.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
|
||||||
enum Opcode {
|
enum Opcode {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user