mirror of
https://github.com/pocketpy/pocketpy
synced 2026-05-18 08:03:38 +00:00
Compare commits
2 Commits
86b4fc623c
...
62c12981df
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62c12981df | ||
|
|
8277895502 |
@ -120,15 +120,16 @@ void FuncDecl__add_arg(FuncDecl* self, py_Name name);
|
|||||||
void FuncDecl__add_kwarg(FuncDecl* self, py_Name name, const py_TValue* value);
|
void FuncDecl__add_kwarg(FuncDecl* self, py_Name name, const py_TValue* value);
|
||||||
void FuncDecl__add_starred_arg(FuncDecl* self, py_Name name);
|
void FuncDecl__add_starred_arg(FuncDecl* self, py_Name name);
|
||||||
void FuncDecl__add_starred_kwarg(FuncDecl* self, py_Name name);
|
void FuncDecl__add_starred_kwarg(FuncDecl* self, py_Name name);
|
||||||
|
void FuncDecl__gc_mark(const FuncDecl* self);
|
||||||
|
|
||||||
// runtime function
|
// runtime function
|
||||||
typedef struct Function {
|
typedef struct Function {
|
||||||
FuncDecl_ decl;
|
FuncDecl_ decl;
|
||||||
py_TValue module; // weak ref
|
py_TValue module; // weak ref
|
||||||
PyObject* clazz; // weak ref
|
PyObject* clazz; // weak ref
|
||||||
NameDict* closure; // strong ref
|
NameDict* closure; // strong ref
|
||||||
py_CFunction cfunc; // wrapped C function
|
py_CFunction cfunc; // wrapped C function
|
||||||
} Function;
|
} Function;
|
||||||
|
|
||||||
void Function__ctor(Function* self, FuncDecl_ decl, py_TValue* module);
|
void Function__ctor(Function* self, FuncDecl_ decl, py_TValue* module);
|
||||||
void Function__dtor(Function* self);
|
void Function__dtor(Function* self);
|
||||||
|
|||||||
@ -602,9 +602,23 @@ static void mark_object(PyObject* obj) {
|
|||||||
if(ti->gc_mark) ti->gc_mark(PyObject__userdata(obj));
|
if(ti->gc_mark) ti->gc_mark(PyObject__userdata(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FuncDecl__gc_mark(const FuncDecl* self) {
|
||||||
|
CodeObject__gc_mark(&self->code);
|
||||||
|
for(int j = 0; j < self->kwargs.length; j++) {
|
||||||
|
FuncDeclKwArg* kw = c11__at(FuncDeclKwArg, &self->kwargs, j);
|
||||||
|
pk__mark_value(&kw->value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CodeObject__gc_mark(const CodeObject* self) {
|
void CodeObject__gc_mark(const CodeObject* self) {
|
||||||
c11__foreach(py_TValue, &self->consts, i) { pk__mark_value(i); }
|
for(int i = 0; i < self->consts.length; i++) {
|
||||||
c11__foreach(FuncDecl_, &self->func_decls, i) { CodeObject__gc_mark(&(*i)->code); }
|
py_TValue* p = c11__at(py_TValue, &self->consts, i);
|
||||||
|
pk__mark_value(p);
|
||||||
|
}
|
||||||
|
for(int i = 0; i < self->func_decls.length; i++) {
|
||||||
|
FuncDecl_ decl = c11__getitem(FuncDecl_, &self->func_decls, i);
|
||||||
|
FuncDecl__gc_mark(decl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManagedHeap__mark(ManagedHeap* self) {
|
void ManagedHeap__mark(ManagedHeap* self) {
|
||||||
|
|||||||
@ -278,6 +278,7 @@ static bool builtins_round(int argc, py_Ref argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool builtins_print(int argc, py_Ref argv) {
|
static bool builtins_print(int argc, py_Ref argv) {
|
||||||
|
// print(*args, sep=' ', end='\n')
|
||||||
py_TValue* args;
|
py_TValue* args;
|
||||||
int length = pk_arrayview(argv, &args);
|
int length = pk_arrayview(argv, &args);
|
||||||
assert(length != -1);
|
assert(length != -1);
|
||||||
@ -684,7 +685,7 @@ py_TValue pk_builtins__register() {
|
|||||||
static void function__gc_mark(void* ud) {
|
static void function__gc_mark(void* ud) {
|
||||||
Function* func = ud;
|
Function* func = ud;
|
||||||
if(func->closure) pk__mark_namedict(func->closure);
|
if(func->closure) pk__mark_namedict(func->closure);
|
||||||
CodeObject__gc_mark(&func->decl->code);
|
FuncDecl__gc_mark(func->decl);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool function__doc__(int argc, py_Ref argv) {
|
static bool function__doc__(int argc, py_Ref argv) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user