blueloveTH 2023-04-24 17:18:43 +08:00
parent 657e9b4313
commit dd27071b22
5 changed files with 15 additions and 10 deletions

View File

@ -43,10 +43,10 @@
#define DEBUG_NO_AUTO_GC 0
#define DEBUG_GC_STATS 0
#if (defined(__ANDROID__) && __ANDROID_API__ <= 22) || defined(__EMSCRIPTEN__)
#define PK_ENABLE_FILEIO 0
#if (defined(__ANDROID__) && __ANDROID_API__ <= 22)
#define PK_ENABLE_OS 0
#else
#define PK_ENABLE_FILEIO 1
#define PK_ENABLE_OS 1
#endif
// This is the maximum number of arguments in a function declaration

View File

@ -4,7 +4,7 @@
#include "cffi.h"
#include "common.h"
#if PK_ENABLE_FILEIO
#if PK_ENABLE_OS
#include <fstream>
#include <filesystem>

View File

@ -6,7 +6,7 @@
#ifndef __EMSCRIPTEN__
int main(int argc, char** argv){
pkpy::VM* vm = pkpy_new_vm(true);
pkpy::VM* vm = pkpy_new_vm(true, true);
vm->bind_builtin_func<0>("input", [](pkpy::VM* vm, pkpy::ArgsView args){
return VAR(pkpy::getline());
});

View File

@ -828,12 +828,15 @@ inline void VM::post_init(){
add_module_math(this);
add_module_re(this);
add_module_dis(this);
add_module_io(this);
add_module_os(this);
add_module_c(this);
add_module_gc(this);
add_module_random(this);
if(enable_os){
add_module_io(this);
add_module_os(this);
}
for(const char* name: {"this", "functools", "collections", "heapq", "bisect"}){
_lazy_modules[name] = kPythonLibs[name];
}
@ -970,8 +973,8 @@ extern "C" {
__EXPORT
/// Create a virtual machine.
pkpy::VM* pkpy_new_vm(bool use_stdio){
return PKPY_ALLOCATE(pkpy::VM, use_stdio);
pkpy::VM* pkpy_new_vm(bool use_stdio, bool enable_os){
return PKPY_ALLOCATE(pkpy::VM, use_stdio, enable_os);
}
__EXPORT

View File

@ -104,7 +104,9 @@ public:
Type tp_slice, tp_range, tp_module;
Type tp_super, tp_exception, tp_bytes;
VM(bool use_stdio) : heap(this){
const bool enable_os;
VM(bool use_stdio, bool enable_os) : heap(this), enable_os(enable_os) {
this->vm = this;
this->_stdout = use_stdio ? &std::cout : &_stdout_buffer;
this->_stderr = use_stdio ? &std::cerr : &_stderr_buffer;