mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
...
This commit is contained in:
parent
0f5ce54c66
commit
c4c7b9ef25
@ -89,3 +89,7 @@ if(PK_USE_CJSON)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE cjson)
|
||||
endif()
|
||||
|
||||
# link math library
|
||||
if(UNIX)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE m)
|
||||
endif()
|
2
build.sh
2
build.sh
@ -22,7 +22,7 @@ SRC=$(find src/ -name "*.c")
|
||||
|
||||
echo "> Compiling and linking source files... "
|
||||
|
||||
FLAGS="-std=c11 -O1 -Wfatal-errors -Iinclude"
|
||||
FLAGS="-std=c11 -O1 -Wfatal-errors -Iinclude -DNDEBUG"
|
||||
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
LIB_EXTENSION=".dylib"
|
||||
|
@ -18,17 +18,17 @@ assert config in ['Debug', 'Release', 'RelWithDebInfo']
|
||||
|
||||
os.chdir("build")
|
||||
|
||||
code = os.system(f"cmake .. -DPK_USE_CJSON=ON -DPK_ENABLE_OS=ON -DCMAKE_BUILD_TYPE={config}")
|
||||
code = os.system(f"cmake .. -DPK_ENABLE_OS=ON -DCMAKE_BUILD_TYPE={config}")
|
||||
assert code == 0
|
||||
code = os.system(f"cmake --build . --config {config}")
|
||||
assert code == 0
|
||||
|
||||
if sys.platform == "win32":
|
||||
shutil.copy(f"{config}/main.exe", "../main.exe")
|
||||
shutil.copy(f"{config}/pocketpy.dll", "../pocketpy.dll")
|
||||
# shutil.copy(f"{config}/pocketpy.dll", "../pocketpy.dll")
|
||||
elif sys.platform == "darwin":
|
||||
shutil.copy("main", "../main")
|
||||
shutil.copy("libpocketpy.dylib", "../libpocketpy.dylib")
|
||||
# shutil.copy("libpocketpy.dylib", "../libpocketpy.dylib")
|
||||
else:
|
||||
shutil.copy("main", "../main")
|
||||
shutil.copy("libpocketpy.so", "../libpocketpy.so")
|
||||
# shutil.copy("libpocketpy.so", "../libpocketpy.so")
|
||||
|
@ -460,7 +460,7 @@ bool py_call(py_Ref f, int argc, py_Ref argv) PY_RAISE;
|
||||
/// This function does extra checks to help you debug `py_CFunction`.
|
||||
bool py_callcfunc(py_CFunction f, int argc, py_Ref argv) PY_RAISE;
|
||||
#else
|
||||
#define py_callcfunc(f, argc, argv) f(argc, argv)
|
||||
#define py_callcfunc(f, argc, argv) (f((argc), (argv)))
|
||||
#endif
|
||||
|
||||
/// Python equivalent to `str(val)`.
|
||||
|
@ -17,7 +17,7 @@ void py_Name__initialize() {
|
||||
}
|
||||
c11_vector__ctor(&_r_interned, sizeof(c11_sv));
|
||||
|
||||
#define MAGIC_METHOD(x) assert(x == py_name(#x));
|
||||
#define MAGIC_METHOD(x) if(x != py_name(#x)) abort();
|
||||
#include "pocketpy/xmacros/magics.h"
|
||||
#undef MAGIC_METHOD
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ static char* pk_default_import_file(const char* path) {
|
||||
long size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
char* buffer = malloc(size + 1);
|
||||
fread(buffer, 1, size, f);
|
||||
size = fread(buffer, 1, size, f);
|
||||
buffer[size] = 0;
|
||||
fclose(f);
|
||||
return buffer;
|
||||
|
@ -91,18 +91,22 @@ bool py_call(py_Ref f, int argc, py_Ref argv) {
|
||||
}
|
||||
}
|
||||
|
||||
#if PK_DEBUG
|
||||
bool py_callcfunc(py_CFunction f, int argc, py_Ref argv) {
|
||||
py_StackRef p0 = py_peek(0);
|
||||
py_newnil(py_retval());
|
||||
bool ok = f(argc, argv);
|
||||
if(!ok) return false;
|
||||
if(py_peek(0) != p0)
|
||||
if(py_peek(0) != p0) {
|
||||
c11__abort("py_CFunction corrupts the stack! Did you forget to call `py_pop()`?");
|
||||
if(py_isnil(py_retval()))
|
||||
}
|
||||
if(py_isnil(py_retval())) {
|
||||
c11__abort(
|
||||
"py_CFunction returns nothing! Did you forget to call `py_newnone(py_retval())`?");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool py_vectorcall(uint16_t argc, uint16_t kwargc) {
|
||||
return VM__vectorcall(pk_current_vm, argc, kwargc, false) != RES_ERROR;
|
||||
|
@ -21,15 +21,14 @@ void py_setglobal(py_Name name, py_Ref val) { py_setdict(&pk_current_vm->main, n
|
||||
|
||||
py_Ref py_newmodule(const char* path) {
|
||||
ManagedHeap* heap = &pk_current_vm->heap;
|
||||
PyObject* obj = ManagedHeap__new(heap, tp_module, -1, 0);
|
||||
|
||||
py_Ref r0 = py_pushtmp();
|
||||
py_Ref r1 = py_pushtmp();
|
||||
|
||||
*r0 = (py_TValue){
|
||||
.type = obj->type,
|
||||
.type = tp_module,
|
||||
.is_ptr = true,
|
||||
._obj = obj,
|
||||
._obj = ManagedHeap__new(heap, tp_module, -1, 0),
|
||||
};
|
||||
|
||||
int last_dot = c11_sv__rindex((c11_sv){path, strlen(path)}, '.');
|
||||
|
@ -21,6 +21,9 @@ py_Ref py_getdict(py_Ref self, py_Name name) {
|
||||
|
||||
void py_setdict(py_Ref self, py_Name name, py_Ref val) {
|
||||
assert(self && self->is_ptr);
|
||||
// if(py_isidentical(self, &pk_current_vm->main)){
|
||||
// printf("Setting main: %s\n", py_name2str(name));
|
||||
// }
|
||||
if(!py_ismagicname(name) || self->type != tp_type) {
|
||||
NameDict__set(PyObject__dict(self->_obj), name, *val);
|
||||
} else {
|
||||
|
@ -41,7 +41,11 @@ int main(int argc, char** argv) {
|
||||
|
||||
if(argc == 1) {
|
||||
printf("pocketpy " PK_VERSION " (" __DATE__ ", " __TIME__ ") ");
|
||||
printf("[%d bit] on %s\n", (int)(sizeof(void*) * 8), PY_SYS_PLATFORM_STRING);
|
||||
printf("[%d bit] on %s", (int)(sizeof(void*) * 8), PY_SYS_PLATFORM_STRING);
|
||||
#if PK_DEBUG
|
||||
printf(" (DEBUG)");
|
||||
#endif
|
||||
printf("\n");
|
||||
printf("https://github.com/pocketpy/pocketpy\n");
|
||||
printf("Type \"exit()\" to exit.\n");
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
from cmath import isclose, sqrt
|
||||
|
||||
res = sqrt(1+2j)
|
||||
assert isclose(res, 1.272019649514069+0.7861513777574233j)
|
||||
|
||||
a = 1+2j
|
||||
{a: 1}
|
Loading…
x
Reference in New Issue
Block a user