From c9f93f126ca39f705da93c7b5a324459aa084b92 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 9 Dec 2023 18:26:53 +0800 Subject: [PATCH] ... --- include/pocketpy/export.h | 26 ++++++++++++++++++-------- src/io.cpp | 2 ++ src/pocketpy.cpp | 2 +- src/repl.cpp | 2 +- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/pocketpy/export.h b/include/pocketpy/export.h index 85acde3e..7142b4fa 100644 --- a/include/pocketpy/export.h +++ b/include/pocketpy/export.h @@ -1,34 +1,44 @@ #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__) //define something for Windows (32-bit and 64-bit, this part is common) #define PK_EXPORT __declspec(dllexport) - #define PK_SYS_PLATFORM "win32" + #define PK_SYS_PLATFORM 0 #elif __EMSCRIPTEN__ #include #define PK_EXPORT EMSCRIPTEN_KEEPALIVE - #define PK_SYS_PLATFORM "emscripten" + #define PK_SYS_PLATFORM 1 #elif __APPLE__ #include #if TARGET_IPHONE_SIMULATOR // iOS, tvOS, or watchOS Simulator - #define PK_SYS_PLATFORM "ios" + #define PK_SYS_PLATFORM 2 #elif TARGET_OS_IPHONE // iOS, tvOS, or watchOS device - #define PK_SYS_PLATFORM "ios" + #define PK_SYS_PLATFORM 2 #elif TARGET_OS_MAC - #define PK_SYS_PLATFORM "darwin" + #define PK_SYS_PLATFORM 3 #else # error "Unknown Apple platform" #endif #define PK_EXPORT __attribute__((visibility("default"))) #elif __ANDROID__ #define PK_EXPORT __attribute__((visibility("default"))) - #define PK_SYS_PLATFORM "android" + #define PK_SYS_PLATFORM 4 #elif __linux__ #define PK_EXPORT __attribute__((visibility("default"))) - #define PK_SYS_PLATFORM "linux" + #define PK_SYS_PLATFORM 5 #else #define PK_EXPORT - #define PK_SYS_PLATFORM "unknown" + #define PK_SYS_PLATFORM 6 #endif \ No newline at end of file diff --git a/src/io.cpp b/src/io.cpp index b9dd3146..b5cb9432 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -136,12 +136,14 @@ void add_module_os(VM* vm){ return vm->None; }); +#if PK_SYS_PLATFORM != 2 // system vm->bind_func<1>(mod, "system", [](VM* vm, ArgsView args){ std::string cmd = CAST(Str&, args[0]).str(); int ret = system(cmd.c_str()); return VAR(ret); }); +#endif vm->bind_func<1>(mod, "listdir", [](VM* vm, ArgsView args){ std::filesystem::path path(CAST(Str&, args[0]).sv()); diff --git a/src/pocketpy.cpp b/src/pocketpy.cpp index 6014503e..8a702fa1 100644 --- a/src/pocketpy.cpp +++ b/src/pocketpy.cpp @@ -1431,7 +1431,7 @@ void add_module_time(VM* vm){ void add_module_sys(VM* vm){ PyObject* mod = vm->new_module("sys"); 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(vm->tp_object); PyObject* stderr_ = vm->heap.gcnew(vm->tp_object); diff --git a/src/repl.cpp b/src/repl.cpp index 3ff64cbe..5cb140b9 100644 --- a/src/repl.cpp +++ b/src/repl.cpp @@ -3,7 +3,7 @@ namespace pkpy { REPL::REPL(VM* vm) : vm(vm){ 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("Type \"exit()\" to exit." "\n"); }