Compare commits

..

No commits in common. "e2dfad3fcebe041eae75cd3db1f6aa41f77971ab" and "f7141d59675a8ddacb22cdeca89712e9d229d944" have entirely different histories.

9 changed files with 30 additions and 29 deletions

View File

@ -37,6 +37,8 @@ Please see https://pocketpy.dev for details and try the following resources.
pkpy should work on any platform with a C11 compiler. pkpy should work on any platform with a C11 compiler.
These platforms are officially tested. These platforms are officially tested.
> C99 compilers may also work currently according to users' feedback.
+ Windows 64-bit + Windows 64-bit
+ Linux 64-bit / 32-bit + Linux 64-bit / 32-bit
+ macOS 64-bit + macOS 64-bit

View File

@ -16,11 +16,10 @@ if [ $? -ne 0 ]; then
fi fi
SRC=$(find src/ -name "*.c") SRC=$(find src/ -name "*.c")
SRC2=${1:-src2/main.c}
echo "> Compiling and linking source files... " echo "> Compiling and linking source files... "
clang -std=c11 -O2 -Wfatal-errors -Iinclude -DNDEBUG -o main $SRC $SRC2 -lm -ldl clang -std=c11 -O2 -Wfatal-errors -Iinclude -DNDEBUG -o main src2/main.c $SRC -lm -ldl
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Build completed. Type \"./main\" to enter REPL." echo "Build completed. Type \"./main\" to enter REPL."

View File

@ -12,8 +12,6 @@ if [ "$(uname)" == "Darwin" ]; then
SANITIZE_FLAGS="-fsanitize=address,undefined" SANITIZE_FLAGS="-fsanitize=address,undefined"
fi fi
SRC2=${1:-src2/main.c}
echo "Compiling C files..." echo "Compiling C files..."
clang $FLAGS $SANITIZE_FLAGS $SRC $SRC2 -o main clang $FLAGS $SANITIZE_FLAGS $SRC src2/main.c -o main

View File

@ -34,6 +34,8 @@ print(primes)
pkpy should work on any platform with a C11 compiler. pkpy should work on any platform with a C11 compiler.
These platforms are officially tested. These platforms are officially tested.
> C99 compilers may also work currently according to users' feedback.
+ Windows 64-bit + Windows 64-bit
+ Linux 64-bit / 32-bit + Linux 64-bit / 32-bit
+ macOS 64-bit + macOS 64-bit

View File

@ -7,6 +7,12 @@
#define PK_VERSION_PATCH 8 #define PK_VERSION_PATCH 8
/*************** feature settings ***************/ /*************** feature settings ***************/
// Reduce the startup memory usage for embedded systems
#ifndef PK_LOW_MEMORY_MODE // can be overridden by cmake
#define PK_LOW_MEMORY_MODE 0
#endif
// Whether to compile os-related modules or not // Whether to compile os-related modules or not
#ifndef PK_ENABLE_OS // can be overridden by cmake #ifndef PK_ENABLE_OS // can be overridden by cmake
#define PK_ENABLE_OS 1 #define PK_ENABLE_OS 1
@ -14,7 +20,11 @@
// GC min threshold // GC min threshold
#ifndef PK_GC_MIN_THRESHOLD // can be overridden by cmake #ifndef PK_GC_MIN_THRESHOLD // can be overridden by cmake
#define PK_GC_MIN_THRESHOLD 32768 #if PK_LOW_MEMORY_MODE
#define PK_GC_MIN_THRESHOLD 2048
#else
#define PK_GC_MIN_THRESHOLD 32768
#endif
#endif #endif
// Memory allocation functions // Memory allocation functions
@ -27,7 +37,11 @@
// This is the maximum size of the value stack in py_TValue units // This is the maximum size of the value stack in py_TValue units
// The actual size in bytes equals `sizeof(py_TValue) * PK_VM_STACK_SIZE` // The actual size in bytes equals `sizeof(py_TValue) * PK_VM_STACK_SIZE`
#ifndef PK_VM_STACK_SIZE // can be overridden by cmake #ifndef PK_VM_STACK_SIZE // can be overridden by cmake
#define PK_VM_STACK_SIZE 16384 #if PK_LOW_MEMORY_MODE
#define PK_VM_STACK_SIZE 2048
#else
#define PK_VM_STACK_SIZE 16384
#endif
#endif #endif
// This is the maximum number of local variables in a function // This is the maximum number of local variables in a function

View File

@ -4,7 +4,7 @@
typedef struct PyObject PyObject; typedef struct PyObject PyObject;
typedef struct VM VM; typedef struct VM VM;
extern _Thread_local VM* pk_current_vm; extern VM* pk_current_vm;
typedef struct py_TValue { typedef struct py_TValue {
py_Type type; py_Type type;

View File

@ -81,7 +81,7 @@ PyObject* ManagedHeap__gcnew(ManagedHeap* self, py_Type type, int slots, int uds
PyObject* obj; PyObject* obj;
// header + slots + udsize // header + slots + udsize
int size = sizeof(PyObject) + PK_OBJ_SLOTS_SIZE(slots) + udsize; int size = sizeof(PyObject) + PK_OBJ_SLOTS_SIZE(slots) + udsize;
if(size <= kPoolMaxBlockSize) { if(!PK_LOW_MEMORY_MODE && size <= kPoolMaxBlockSize) {
obj = MultiPool__alloc(&self->small_objects, size); obj = MultiPool__alloc(&self->small_objects, size);
assert(obj != NULL); assert(obj != NULL);
} else { } else {

View File

@ -909,10 +909,7 @@ static py_TValue* c11_chunked_array2d__new_chunk(c11_chunked_array2d* self, c11_
if(!py_isnone(&self->context_builder)) { if(!py_isnone(&self->context_builder)) {
py_newvec2i(&data[0], pos); py_newvec2i(&data[0], pos);
bool ok = py_call(&self->context_builder, 1, &data[0]); bool ok = py_call(&self->context_builder, 1, &data[0]);
if(!ok) { if(!ok) return NULL;
PK_FREE(data);
return NULL;
}
data[0] = *py_retval(); data[0] = *py_retval();
} else { } else {
data[0] = *py_None(); data[0] = *py_None();
@ -1106,7 +1103,6 @@ static bool chunked_array2d__len__(int argc, py_Ref argv) {
static bool chunked_array2d_clear(int argc, py_Ref argv) { static bool chunked_array2d_clear(int argc, py_Ref argv) {
PY_CHECK_ARGC(1); PY_CHECK_ARGC(1);
c11_chunked_array2d* self = py_touserdata(argv); c11_chunked_array2d* self = py_touserdata(argv);
c11__foreach(c11_chunked_array2d_chunks_KV, &self->chunks, p_kv) PK_FREE(p_kv->value);
c11_chunked_array2d_chunks__clear(&self->chunks); c11_chunked_array2d_chunks__clear(&self->chunks);
self->last_visited.value = NULL; self->last_visited.value = NULL;
py_newnone(py_retval()); py_newnone(py_retval());
@ -1170,16 +1166,9 @@ static bool chunked_array2d_remove_chunk(int argc, py_Ref argv) {
PY_CHECK_ARG_TYPE(1, tp_vec2i); PY_CHECK_ARG_TYPE(1, tp_vec2i);
c11_chunked_array2d* self = py_touserdata(argv); c11_chunked_array2d* self = py_touserdata(argv);
c11_vec2i pos = py_tovec2i(&argv[1]); c11_vec2i pos = py_tovec2i(&argv[1]);
py_TValue* data = c11_chunked_array2d_chunks__get(&self->chunks, pos, NULL); bool ok = c11_chunked_array2d_chunks__del(&self->chunks, pos);
if(data != NULL) { self->last_visited.value = NULL;
PK_FREE(data); py_newbool(py_retval(), ok);
bool ok = c11_chunked_array2d_chunks__del(&self->chunks, pos);
assert(ok);
self->last_visited.value = NULL;
py_newbool(py_retval(), ok);
} else {
py_newbool(py_retval(), false);
}
return true; return true;
} }

View File

@ -5,15 +5,14 @@
#include "pocketpy/common/utils.h" #include "pocketpy/common/utils.h"
#include "pocketpy/interpreter/vm.h" #include "pocketpy/interpreter/vm.h"
_Thread_local VM* pk_current_vm; VM* pk_current_vm;
static bool pk_initialized;
static VM pk_default_vm; static VM pk_default_vm;
static VM* pk_all_vm[16]; static VM* pk_all_vm[16];
static py_TValue _True, _False, _None, _NIL; static py_TValue _True, _False, _None, _NIL;
void py_initialize() { void py_initialize() {
if(pk_initialized) { if(pk_current_vm) {
// c11__abort("py_initialize() can only be called once!"); // c11__abort("py_initialize() can only be called once!");
return; return;
} }
@ -36,8 +35,6 @@ void py_initialize() {
py_newnone(&_None); py_newnone(&_None);
py_newnil(&_NIL); py_newnil(&_NIL);
VM__ctor(&pk_default_vm); VM__ctor(&pk_default_vm);
pk_initialized = true;
} }
py_GlobalRef py_True() { return &_True; } py_GlobalRef py_True() { return &_True; }