blueloveTH 2 years ago
parent
commit
cb6d302b2f

+ 0 - 0
docs/LuaC-API/call.md → docs/C-API/call.md


+ 0 - 0
docs/LuaC-API/error.md → docs/C-API/error.md


+ 1 - 1
docs/C-API/index.yml

@@ -1,3 +1,3 @@
-label: Legacy C-API
+label: C-API
 icon: code
 order: 1

+ 10 - 6
docs/LuaC-API/introduction.md → docs/C-API/introduction.md

@@ -4,13 +4,17 @@ icon: dot
 order: 10
 ---
 
-We take a lot of inspiration from the lua api for these bindings.
-The key difference being most methods return a bool, 
-true if it succeeded false if it did not.
+### What C-API is for
 
-!!!
-Special thanks for [@koltenpearson](https://github.com/koltenpearson) for bringing us the Lua Style API implementation.
-!!!
+The C-APIs are designed for these purposes:
+
+1. Your target platform does not support C++17. You compile pkpy into a static library and use its exported C-APIs.
+2. You want to write a native module that can be imported via `__import__` at runtime. By using C-APIs, the module is portable across different compilers without C++ ABI compatibility issues.
+
+Our C-APIs take a lot of inspiration from the lua C-APIs.
+Methods return a `bool` indicating if the operation succeeded or not.
+
+Special thanks for [@koltenpearson](https://github.com/koltenpearson)'s contribution.
 
 ## Basic Functions
 

+ 0 - 12
docs/C-API/repl.md

@@ -1,12 +0,0 @@
----
-title: REPL
-icon: dot
-order: 8
----
-#### `REPL* pkpy_new_repl(VM* vm)`
-
-Create a REPL, using the given virtual machine as the backend.
-
-#### `bool pkpy_repl_input(REPL* r, const char* line)`
-
-Input a source line to an interactive console. Return true if need more lines.

+ 0 - 0
docs/LuaC-API/stack.md → docs/C-API/stack.md


+ 0 - 0
docs/LuaC-API/types.md → docs/C-API/types.md


+ 0 - 0
docs/LuaC-API/variables.md → docs/C-API/variables.md


+ 0 - 40
docs/C-API/vm.md

@@ -1,40 +0,0 @@
----
-title: VM
-icon: dot
-order: 10
----
-
-#### `VM* pkpy_new_vm()`
-
-Create a virtual machine.
-
-#### `void pkpy_vm_add_module(VM* vm, const char* name, const char* source)`
-
-Add a source module into a virtual machine.
-
-#### `void pkpy_vm_exec(VM* vm, const char* source)`
-
-Run a given source on a virtual machine.
-
-#### `void pkpy_vm_exec_2(pkpy::VM* vm, const char* source, const char* filename, int mode, const char* module)`
-
-Advanced version of `pkpy_vm_exec`.
-
-#### `void pkpy_free(void* p)`
-
-Free a pointer via `free`.
-
-#### `void pkpy_delete_vm(VM* vm)`
-
-Delete a virtual machine.
-
-#### `void pkpy_delete_repl(REPL* repl)`
-
-Delete a REPL.
-
-#### `void pkpy_vm_compile(VM* vm, const char* source, const char* filename, int mode, bool* ok, char** res)`
-
-Compile a source into bytecode and serialize it into a string.
-
-+ `ok`: whether the compilation is successful.
-+ `res`: if `ok` is true, `res` is the bytecode string, otherwise it is the error message.

+ 0 - 3
docs/LuaC-API/index.yml

@@ -1,3 +0,0 @@
-label: Lua Style C-API
-icon: code
-order: 2

+ 1 - 1
docs/retype.yml

@@ -3,7 +3,7 @@ output: .retype
 url: https://pocketpy.dev
 branding:
   title: pocketpy
-  label: v1.0
+  label: v1.1
   logo: "./static/logo.png"
 favicon: "./static/logo.png"
 meta:

+ 13 - 3
include/pocketpy/export.h

@@ -14,31 +14,41 @@
 
     #define PK_EXPORT __declspec(dllexport)
     #define PK_SUPPORT_DYLIB    1
+    #define PK_SYS_PLATFORM     "win32"
 #elif __EMSCRIPTEN__
     #include <emscripten.h>
     #define PK_EXPORT EMSCRIPTEN_KEEPALIVE
     #define PK_SUPPORT_DYLIB    0
+    #define PK_SYS_PLATFORM     "emscripten"
 #elif __APPLE__
     #include <TargetConditionals.h>
     #include <dlfcn.h>
     #define PK_SUPPORT_DYLIB    2
     #if TARGET_IPHONE_SIMULATOR
-         // iOS, tvOS, or watchOS Simulator
-    #elif TARGET_OS_MACCATALYST
-         // Mac's Catalyst (ports iOS API into Mac, like UIKit).
+        // iOS, tvOS, or watchOS Simulator
+        #define PK_SYS_PLATFORM     "ios"
     #elif TARGET_OS_IPHONE
         // iOS, tvOS, or watchOS device
+        #define PK_SYS_PLATFORM     "ios"
     #elif TARGET_OS_MAC
         // Other kinds of Apple platforms
+        #define PK_SYS_PLATFORM     "darwin"
     #else
     #   error "Unknown Apple platform"
     #endif
     #define PK_EXPORT __attribute__((visibility("default")))
+#elif __ANDROID__
+    #include <dlfcn.h>
+    #define PK_SUPPORT_DYLIB    2
+    #define PK_EXPORT __attribute__((visibility("default")))
+    #define PK_SYS_PLATFORM     "android"
 #elif __linux__
     #include <dlfcn.h>
     #define PK_SUPPORT_DYLIB    2
     #define PK_EXPORT __attribute__((visibility("default")))
+    #define PK_SYS_PLATFORM     "linux"
 #else
     #define PK_EXPORT
     #define PK_SUPPORT_DYLIB    0
+    #define PK_SYS_PLATFORM     "unknown"
 #endif

+ 1 - 0
src/pocketpy.cpp

@@ -1271,6 +1271,7 @@ void add_module_sys(VM* vm){
     PyObject* mod = vm->new_module("sys");
     PyREPL::register_class(vm, mod);
     vm->setattr(mod, "version", VAR(PK_VERSION));
+    vm->setattr(mod, "platform", VAR(PK_SYS_PLATFORM));
 
     PyObject* stdout_ = vm->heap.gcnew<DummyInstance>(vm->tp_object, {});
     PyObject* stderr_ = vm->heap.gcnew<DummyInstance>(vm->tp_object, {});

+ 1 - 1
src/repl.cpp

@@ -3,7 +3,7 @@
 namespace pkpy {
     REPL::REPL(VM* vm) : vm(vm){
         vm->_stdout(vm, "pocketpy " PK_VERSION " (" __DATE__ ", " __TIME__ ") ");
-        vm->_stdout(vm, fmt("[", sizeof(void*)*8, " bit]" "\n"));
+        vm->_stdout(vm, fmt("[", sizeof(void*)*8, " bit] on ", PK_SYS_PLATFORM "\n"));
         vm->_stdout(vm, "https://github.com/blueloveTH/pocketpy" "\n");
         vm->_stdout(vm, "Type \"exit()\" to exit." "\n");
     }