mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
some fix
This commit is contained in:
parent
fb0ec57f38
commit
7e35fa2d56
@ -4,8 +4,9 @@ python prebuild.py
|
||||
|
||||
SRC=$(find src/ -name "*.c")
|
||||
|
||||
FLAGS="-std=c11 -lm -Iinclude -O0 -Wfatal-errors -g -DDEBUG -DPK_ENABLE_OS=1" # -fsanitize=address,leak,undefined"
|
||||
FLAGS="-std=c11 -lm -Iinclude -O0 -Wfatal-errors -g -DDEBUG -DPK_ENABLE_OS=1"
|
||||
SANITIZE_FLAGS="-fsanitize=address,leak,undefined"
|
||||
|
||||
echo "Compiling C files..."
|
||||
clang $FLAGS $SRC src2/main.c -o main
|
||||
clang $FLAGS $SANITIZE_FLAGS $SRC src2/main.c -o main
|
||||
|
||||
|
@ -9,7 +9,7 @@ extern "C" {
|
||||
|
||||
typedef uint16_t StrName;
|
||||
|
||||
#define py_name(name) pk_StrName__map(#name)
|
||||
#define py_name(name) pk_StrName__map(name)
|
||||
|
||||
uint16_t pk_StrName__map(const char*);
|
||||
uint16_t pk_StrName__map2(c11_string);
|
||||
|
@ -124,6 +124,7 @@ void py_import(const char* name, py_Ref out);
|
||||
py_Error* py_getlasterror();
|
||||
void py_Error__print(py_Error*);
|
||||
|
||||
/************* Operators *************/
|
||||
int py_eq(const py_Ref, const py_Ref);
|
||||
int py_le(const py_Ref, const py_Ref);
|
||||
int py_hash(const py_Ref, int64_t* out);
|
||||
|
@ -74,14 +74,16 @@ void METHOD(delete)(NAME* self) {
|
||||
void METHOD(set)(NAME* self, K key, V value) {
|
||||
int index;
|
||||
c11__lower_bound(KV, self->data, self->count, key, partial_less, &index);
|
||||
if(index != self->count){
|
||||
KV* it = c11__at(KV, self, index);
|
||||
if(index != self->count && equal(it->key, key)) {
|
||||
if(equal(it->key, key)){
|
||||
it->value = value;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
KV kv = {key, value};
|
||||
c11_vector__insert(KV, self, index, kv);
|
||||
}
|
||||
}
|
||||
|
||||
V* METHOD(try_get)(const NAME* self, K key) {
|
||||
// use `bsearch` which is faster than `lower_bound`
|
||||
@ -113,11 +115,13 @@ bool METHOD(contains)(const NAME* self, K key) {
|
||||
bool METHOD(del)(NAME* self, K key) {
|
||||
int index;
|
||||
c11__lower_bound(KV, self->data, self->count, key, partial_less, &index);
|
||||
if(index != self->count){
|
||||
KV* it = c11__at(KV, self, index);
|
||||
if(index != self->count && equal(it->key, key)) {
|
||||
if(equal(it->key, key)){
|
||||
c11_vector__erase(KV, self, index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -115,5 +115,13 @@ PyObject* PyObject__new(py_Type type, int slots, int size){
|
||||
self->type = type;
|
||||
self->gc_marked = false;
|
||||
self->slots = slots;
|
||||
|
||||
// initialize slots or dict
|
||||
void* p = (char*)self + 8;
|
||||
if(slots >= 0){
|
||||
memset(p, 0, slots*sizeof(PyVar));
|
||||
}else{
|
||||
pk_NameDict__ctor(p);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
14
src/interpreter/py_ops.c
Normal file
14
src/interpreter/py_ops.c
Normal file
@ -0,0 +1,14 @@
|
||||
#include "pocketpy/interpreter/vm.h"
|
||||
#include "pocketpy/pocketpy.h"
|
||||
|
||||
int py_eq(const py_Ref lhs, const py_Ref rhs){
|
||||
return 0;
|
||||
}
|
||||
|
||||
int py_le(const py_Ref lhs, const py_Ref rhs){
|
||||
return 0;
|
||||
}
|
||||
|
||||
int py_hash(const py_Ref self, int64_t* out){
|
||||
return 0;
|
||||
}
|
@ -176,7 +176,7 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self){
|
||||
py_Type pk_VM__new_type(pk_VM* self, const char* name, py_Type base, const PyVar* module, bool subclass_enabled){
|
||||
py_Type type = self->types.count;
|
||||
pk_TypeInfo* ti = c11_vector__emplace(&self->types);
|
||||
PyObject* typeobj = pk_ManagedHeap__gcnew(&self->heap, tp_type, 0, sizeof(py_Type));
|
||||
PyObject* typeobj = pk_ManagedHeap__gcnew(&self->heap, tp_type, -1, sizeof(py_Type));
|
||||
py_Type* value = PyObject__value(typeobj);
|
||||
*value = type;
|
||||
pk_TypeInfo__ctor(ti, py_name(name), base, typeobj, module, subclass_enabled);
|
||||
|
@ -24,7 +24,7 @@ void py_newbool(py_Ref self, bool val) {
|
||||
void py_newstr(py_Ref self, const char* data) {
|
||||
pk_ManagedHeap* heap = &pk_current_vm->heap;
|
||||
PyObject* obj = pk_ManagedHeap__gcnew(heap, tp_str, 0, sizeof(py_Str));
|
||||
py_Str__ctor((py_Str*)PyObject__value(obj), data);
|
||||
py_Str__ctor(PyObject__value(obj), data);
|
||||
self->type = tp_str;
|
||||
self->is_ptr = true;
|
||||
self->_obj = obj;
|
||||
|
Loading…
x
Reference in New Issue
Block a user