mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
...
This commit is contained in:
parent
3e99f46273
commit
d8f2808462
@ -6,3 +6,4 @@ void pk__add_module_math();
|
||||
void pk__add_module_dis();
|
||||
void pk__add_module_random();
|
||||
void pk__add_module_json();
|
||||
void pk__add_module_gc();
|
@ -198,6 +198,7 @@ void VM__ctor(VM* self) {
|
||||
pk__add_module_dis();
|
||||
pk__add_module_random();
|
||||
pk__add_module_json();
|
||||
pk__add_module_gc();
|
||||
|
||||
// add python builtins
|
||||
do {
|
||||
|
19
src/modules/gc.c
Normal file
19
src/modules/gc.c
Normal file
@ -0,0 +1,19 @@
|
||||
#include "pocketpy/pocketpy.h"
|
||||
|
||||
#include "pocketpy/common/utils.h"
|
||||
#include "pocketpy/objects/object.h"
|
||||
#include "pocketpy/common/sstream.h"
|
||||
#include "pocketpy/interpreter/vm.h"
|
||||
|
||||
static bool gc_collect(int argc, py_Ref argv){
|
||||
ManagedHeap* heap = &pk_current_vm->heap;
|
||||
int res = ManagedHeap__collect(heap);
|
||||
py_newint(py_retval(), res);
|
||||
return true;
|
||||
}
|
||||
|
||||
void pk__add_module_gc() {
|
||||
py_Ref mod = py_newmodule("gc");
|
||||
|
||||
py_bindfunc(mod, "collect", gc_collect);
|
||||
}
|
@ -387,6 +387,7 @@ static bool builtins_ord(int argc, py_Ref argv) {
|
||||
}
|
||||
|
||||
static bool builtins_globals(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(0);
|
||||
Frame* frame = pk_current_vm->top_frame;
|
||||
if(frame->is_dynamic) {
|
||||
py_assign(py_retval(), &frame->p0[0]);
|
||||
@ -397,6 +398,7 @@ static bool builtins_globals(int argc, py_Ref argv) {
|
||||
}
|
||||
|
||||
static bool builtins_locals(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(0);
|
||||
Frame* frame = pk_current_vm->top_frame;
|
||||
if(frame->is_dynamic) {
|
||||
py_assign(py_retval(), &frame->p0[1]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user