mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-06 03:30:18 +00:00
Compare commits
No commits in common. "ce8d9600a4192d5393838903d22d14aef0374805" and "d717f9499fe7da97eb5d06e5f446812c2b0b09e7" have entirely different histories.
ce8d9600a4
...
d717f9499f
4
.gitignore
vendored
4
.gitignore
vendored
@ -26,7 +26,9 @@ APPS
|
|||||||
build
|
build
|
||||||
|
|
||||||
main
|
main
|
||||||
*.dSYM
|
pocketpy.dSYM
|
||||||
|
libpocketpy.dylib.dSYM/
|
||||||
|
main.dSYM/
|
||||||
|
|
||||||
docs/references.md
|
docs/references.md
|
||||||
|
|
||||||
|
|||||||
@ -69,7 +69,7 @@ else()
|
|||||||
target_link_libraries(main ${PROJECT_NAME})
|
target_link_libraries(main ${PROJECT_NAME})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# link math library
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
target_link_libraries(${PROJECT_NAME} m)
|
target_link_libraries(${PROJECT_NAME} m)
|
||||||
target_link_libraries(${PROJECT_NAME} dl)
|
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
2
build.sh
2
build.sh
@ -19,7 +19,7 @@ SRC=$(find src/ -name "*.c")
|
|||||||
|
|
||||||
echo "> Compiling and linking source files... "
|
echo "> Compiling and linking source files... "
|
||||||
|
|
||||||
clang -std=c11 -O2 -Wfatal-errors -Iinclude -DNDEBUG -o main src2/main.c $SRC -lm -ldl
|
clang -std=c11 -O2 -Wfatal-errors -Iinclude -DNDEBUG -o main src2/main.c $SRC -lm
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "Build completed. Type \"./main\" to enter REPL."
|
echo "Build completed. Type \"./main\" to enter REPL."
|
||||||
|
|||||||
@ -1,6 +0,0 @@
|
|||||||
set -e
|
|
||||||
|
|
||||||
FLAGS="-std=c11 -Iinclude -O0 -Wfatal-errors -g -DDEBUG -DPK_ENABLE_OS=1"
|
|
||||||
|
|
||||||
# link libpocketpy.dylib
|
|
||||||
clang $FLAGS -shared -fPIC src2/hello.c -o libhello.dylib -L. -lpocketpy
|
|
||||||
@ -4,7 +4,7 @@ python prebuild.py
|
|||||||
|
|
||||||
SRC=$(find src/ -name "*.c")
|
SRC=$(find src/ -name "*.c")
|
||||||
|
|
||||||
FLAGS="-std=c11 -lm -ldl -Iinclude -O0 -Wfatal-errors -g -DDEBUG -DPK_ENABLE_OS=1"
|
FLAGS="-std=c11 -lm -Iinclude -O0 -Wfatal-errors -g -DDEBUG -DPK_ENABLE_OS=1"
|
||||||
|
|
||||||
SANITIZE_FLAGS="-fsanitize=address,leak,undefined"
|
SANITIZE_FLAGS="-fsanitize=address,leak,undefined"
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ python prebuild.py
|
|||||||
|
|
||||||
SRC=$(find src/ -name "*.c")
|
SRC=$(find src/ -name "*.c")
|
||||||
|
|
||||||
gcc -pg -Og -std=c11 -Wfatal-errors -o main $SRC src2/main.c -Iinclude -lm -ldl -DNDEBUG -flto
|
gcc -pg -Og -std=c11 -Wfatal-errors -o main $SRC src2/main.c -Iinclude -lm -DNDEBUG -flto
|
||||||
./main benchmarks/fib.py
|
./main benchmarks/fib.py
|
||||||
gprof main gmon.out > gprof.txt
|
gprof main gmon.out > gprof.txt
|
||||||
rm gmon.out
|
rm gmon.out
|
||||||
|
|||||||
@ -4,7 +4,7 @@ python prebuild.py
|
|||||||
|
|
||||||
SRC=$(find src/ -name "*.c")
|
SRC=$(find src/ -name "*.c")
|
||||||
|
|
||||||
clang -std=c11 --coverage -O1 -Wfatal-errors -o main src2/main.c $SRC -Iinclude -DPK_ENABLE_OS=1 -DPK_ENABLE_PROFILER=1 -lm -ldl -DNDEBUG
|
clang -std=c11 --coverage -O1 -Wfatal-errors -o main src2/main.c $SRC -Iinclude -DPK_ENABLE_OS=1 -DPK_ENABLE_PROFILER=1 -lm -DNDEBUG
|
||||||
|
|
||||||
python scripts/run_tests.py
|
python scripts/run_tests.py
|
||||||
|
|
||||||
|
|||||||
@ -1,37 +0,0 @@
|
|||||||
#include "pocketpy/pocketpy.h"
|
|
||||||
|
|
||||||
#if PK_IS_DESKTOP_PLATFORM
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
void* LoadLibraryA(const char*);
|
|
||||||
void* GetProcAddress(void*, const char*);
|
|
||||||
#else
|
|
||||||
#include <dlfcn.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef bool (*py_module_initialize_t)() PY_RAISE PY_RETURN;
|
|
||||||
|
|
||||||
int load_module_from_dll_desktop_only(const char* path) PY_RAISE PY_RETURN {
|
|
||||||
const char* f_init_name = "py_module_initialize";
|
|
||||||
#ifdef _WIN32
|
|
||||||
void* dll = LoadLibraryA(path);
|
|
||||||
if(dll == NULL) return 0;
|
|
||||||
py_module_initialize_t f_init = (py_module_initialize_t)GetProcAddress(dll, f_init_name);
|
|
||||||
#else
|
|
||||||
void* dll = dlopen(path, RTLD_LAZY);
|
|
||||||
if(dll == NULL) return 0;
|
|
||||||
py_module_initialize_t f_init = (py_module_initialize_t)dlsym(dll, f_init_name);
|
|
||||||
#endif
|
|
||||||
if(f_init == NULL) return 0;
|
|
||||||
bool success = f_init();
|
|
||||||
if(!success) return -1;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
int load_module_from_dll_desktop_only(const char* path) PY_RAISE PY_RETURN {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -20,10 +20,6 @@ static VM pk_default_vm;
|
|||||||
static VM* pk_all_vm[16];
|
static VM* pk_all_vm[16];
|
||||||
|
|
||||||
void py_initialize() {
|
void py_initialize() {
|
||||||
if(pk_current_vm){
|
|
||||||
c11__abort("py_initialize() can only be called once!");
|
|
||||||
}
|
|
||||||
|
|
||||||
MemoryPools__initialize();
|
MemoryPools__initialize();
|
||||||
py_Name__initialize();
|
py_Name__initialize();
|
||||||
|
|
||||||
|
|||||||
@ -63,9 +63,9 @@ py_Ref py_newmodule(const char* path) {
|
|||||||
return py_getmodule(path);
|
return py_getmodule(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
int load_module_from_dll_desktop_only(const char* path) PY_RAISE PY_RETURN;
|
|
||||||
|
|
||||||
int py_import(const char* path_cstr) {
|
int py_import(const char* path_cstr) {
|
||||||
|
// printf("importing %s\n", path_cstr);
|
||||||
|
|
||||||
VM* vm = pk_current_vm;
|
VM* vm = pk_current_vm;
|
||||||
c11_sv path = {path_cstr, strlen(path_cstr)};
|
c11_sv path = {path_cstr, strlen(path_cstr)};
|
||||||
if(path.size == 0) return ValueError("empty module name");
|
if(path.size == 0) return ValueError("empty module name");
|
||||||
@ -142,8 +142,7 @@ int py_import(const char* path_cstr) {
|
|||||||
|
|
||||||
c11_string__delete(filename);
|
c11_string__delete(filename);
|
||||||
c11_string__delete(slashed_path);
|
c11_string__delete(slashed_path);
|
||||||
// not found
|
return 0;
|
||||||
return load_module_from_dll_desktop_only(path_cstr);
|
|
||||||
|
|
||||||
__SUCCESS:
|
__SUCCESS:
|
||||||
do {
|
do {
|
||||||
|
|||||||
15
src2/hello.c
15
src2/hello.c
@ -1,15 +0,0 @@
|
|||||||
#include "pocketpy.h"
|
|
||||||
|
|
||||||
static bool hello_add(int argc, py_Ref argv){
|
|
||||||
PY_CHECK_ARGC(2);
|
|
||||||
return py_binaryadd(py_arg(0), py_arg(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool py_module_initialize(){
|
|
||||||
py_GlobalRef mod = py_newmodule("hello");
|
|
||||||
|
|
||||||
py_bindfunc(mod, "add", hello_add);
|
|
||||||
|
|
||||||
py_assign(py_retval(), mod);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user