mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 19:40:18 +00:00
...
This commit is contained in:
parent
3514114f2d
commit
c9f93f126c
@ -1,34 +1,44 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
inline const char* kPlatformStrings[] = {
|
||||||
|
"win32", // 0
|
||||||
|
"emscripten", // 1
|
||||||
|
"ios", // 2
|
||||||
|
"darwin", // 3
|
||||||
|
"android", // 4
|
||||||
|
"linux", // 5
|
||||||
|
"unknown" // 6
|
||||||
|
};
|
||||||
|
|
||||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||||
//define something for Windows (32-bit and 64-bit, this part is common)
|
//define something for Windows (32-bit and 64-bit, this part is common)
|
||||||
#define PK_EXPORT __declspec(dllexport)
|
#define PK_EXPORT __declspec(dllexport)
|
||||||
#define PK_SYS_PLATFORM "win32"
|
#define PK_SYS_PLATFORM 0
|
||||||
#elif __EMSCRIPTEN__
|
#elif __EMSCRIPTEN__
|
||||||
#include <emscripten.h>
|
#include <emscripten.h>
|
||||||
#define PK_EXPORT EMSCRIPTEN_KEEPALIVE
|
#define PK_EXPORT EMSCRIPTEN_KEEPALIVE
|
||||||
#define PK_SYS_PLATFORM "emscripten"
|
#define PK_SYS_PLATFORM 1
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
#include <TargetConditionals.h>
|
#include <TargetConditionals.h>
|
||||||
#if TARGET_IPHONE_SIMULATOR
|
#if TARGET_IPHONE_SIMULATOR
|
||||||
// iOS, tvOS, or watchOS Simulator
|
// iOS, tvOS, or watchOS Simulator
|
||||||
#define PK_SYS_PLATFORM "ios"
|
#define PK_SYS_PLATFORM 2
|
||||||
#elif TARGET_OS_IPHONE
|
#elif TARGET_OS_IPHONE
|
||||||
// iOS, tvOS, or watchOS device
|
// iOS, tvOS, or watchOS device
|
||||||
#define PK_SYS_PLATFORM "ios"
|
#define PK_SYS_PLATFORM 2
|
||||||
#elif TARGET_OS_MAC
|
#elif TARGET_OS_MAC
|
||||||
#define PK_SYS_PLATFORM "darwin"
|
#define PK_SYS_PLATFORM 3
|
||||||
#else
|
#else
|
||||||
# error "Unknown Apple platform"
|
# error "Unknown Apple platform"
|
||||||
#endif
|
#endif
|
||||||
#define PK_EXPORT __attribute__((visibility("default")))
|
#define PK_EXPORT __attribute__((visibility("default")))
|
||||||
#elif __ANDROID__
|
#elif __ANDROID__
|
||||||
#define PK_EXPORT __attribute__((visibility("default")))
|
#define PK_EXPORT __attribute__((visibility("default")))
|
||||||
#define PK_SYS_PLATFORM "android"
|
#define PK_SYS_PLATFORM 4
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
#define PK_EXPORT __attribute__((visibility("default")))
|
#define PK_EXPORT __attribute__((visibility("default")))
|
||||||
#define PK_SYS_PLATFORM "linux"
|
#define PK_SYS_PLATFORM 5
|
||||||
#else
|
#else
|
||||||
#define PK_EXPORT
|
#define PK_EXPORT
|
||||||
#define PK_SYS_PLATFORM "unknown"
|
#define PK_SYS_PLATFORM 6
|
||||||
#endif
|
#endif
|
@ -136,12 +136,14 @@ void add_module_os(VM* vm){
|
|||||||
return vm->None;
|
return vm->None;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
#if PK_SYS_PLATFORM != 2
|
||||||
// system
|
// system
|
||||||
vm->bind_func<1>(mod, "system", [](VM* vm, ArgsView args){
|
vm->bind_func<1>(mod, "system", [](VM* vm, ArgsView args){
|
||||||
std::string cmd = CAST(Str&, args[0]).str();
|
std::string cmd = CAST(Str&, args[0]).str();
|
||||||
int ret = system(cmd.c_str());
|
int ret = system(cmd.c_str());
|
||||||
return VAR(ret);
|
return VAR(ret);
|
||||||
});
|
});
|
||||||
|
#endif
|
||||||
|
|
||||||
vm->bind_func<1>(mod, "listdir", [](VM* vm, ArgsView args){
|
vm->bind_func<1>(mod, "listdir", [](VM* vm, ArgsView args){
|
||||||
std::filesystem::path path(CAST(Str&, args[0]).sv());
|
std::filesystem::path path(CAST(Str&, args[0]).sv());
|
||||||
|
@ -1431,7 +1431,7 @@ void add_module_time(VM* vm){
|
|||||||
void add_module_sys(VM* vm){
|
void add_module_sys(VM* vm){
|
||||||
PyObject* mod = vm->new_module("sys");
|
PyObject* mod = vm->new_module("sys");
|
||||||
vm->setattr(mod, "version", VAR(PK_VERSION));
|
vm->setattr(mod, "version", VAR(PK_VERSION));
|
||||||
vm->setattr(mod, "platform", VAR(PK_SYS_PLATFORM));
|
vm->setattr(mod, "platform", VAR(kPlatformStrings[PK_SYS_PLATFORM]));
|
||||||
|
|
||||||
PyObject* stdout_ = vm->heap.gcnew<DummyInstance>(vm->tp_object);
|
PyObject* stdout_ = vm->heap.gcnew<DummyInstance>(vm->tp_object);
|
||||||
PyObject* stderr_ = vm->heap.gcnew<DummyInstance>(vm->tp_object);
|
PyObject* stderr_ = vm->heap.gcnew<DummyInstance>(vm->tp_object);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
namespace pkpy {
|
namespace pkpy {
|
||||||
REPL::REPL(VM* vm) : vm(vm){
|
REPL::REPL(VM* vm) : vm(vm){
|
||||||
vm->stdout_write("pocketpy " PK_VERSION " (" __DATE__ ", " __TIME__ ") ");
|
vm->stdout_write("pocketpy " PK_VERSION " (" __DATE__ ", " __TIME__ ") ");
|
||||||
vm->stdout_write(fmt("[", sizeof(void*)*8, " bit] on ", PK_SYS_PLATFORM "\n"));
|
vm->stdout_write(fmt("[", sizeof(void*)*8, " bit] on ", kPlatformStrings[PK_SYS_PLATFORM], "\n"));
|
||||||
vm->stdout_write("https://github.com/blueloveTH/pocketpy" "\n");
|
vm->stdout_write("https://github.com/blueloveTH/pocketpy" "\n");
|
||||||
vm->stdout_write("Type \"exit()\" to exit." "\n");
|
vm->stdout_write("Type \"exit()\" to exit." "\n");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user