mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30: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_dis();
|
||||||
void pk__add_module_random();
|
void pk__add_module_random();
|
||||||
void pk__add_module_json();
|
void pk__add_module_json();
|
||||||
|
void pk__add_module_gc();
|
@ -80,9 +80,9 @@ bool py_exec(const char* source,
|
|||||||
/// After the execution, the result will be set to `py_retval()`.
|
/// After the execution, the result will be set to `py_retval()`.
|
||||||
/// The stack size will be reduced by 2.
|
/// The stack size will be reduced by 2.
|
||||||
bool py_execdyn(const char* source,
|
bool py_execdyn(const char* source,
|
||||||
const char* filename,
|
const char* filename,
|
||||||
enum py_CompileMode mode,
|
enum py_CompileMode mode,
|
||||||
py_Ref module) PY_RAISE;
|
py_Ref module) PY_RAISE;
|
||||||
|
|
||||||
/************* Values Creation *************/
|
/************* Values Creation *************/
|
||||||
|
|
||||||
|
@ -198,6 +198,7 @@ void VM__ctor(VM* self) {
|
|||||||
pk__add_module_dis();
|
pk__add_module_dis();
|
||||||
pk__add_module_random();
|
pk__add_module_random();
|
||||||
pk__add_module_json();
|
pk__add_module_json();
|
||||||
|
pk__add_module_gc();
|
||||||
|
|
||||||
// add python builtins
|
// add python builtins
|
||||||
do {
|
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) {
|
static bool builtins_globals(int argc, py_Ref argv) {
|
||||||
|
PY_CHECK_ARGC(0);
|
||||||
Frame* frame = pk_current_vm->top_frame;
|
Frame* frame = pk_current_vm->top_frame;
|
||||||
if(frame->is_dynamic) {
|
if(frame->is_dynamic) {
|
||||||
py_assign(py_retval(), &frame->p0[0]);
|
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) {
|
static bool builtins_locals(int argc, py_Ref argv) {
|
||||||
|
PY_CHECK_ARGC(0);
|
||||||
Frame* frame = pk_current_vm->top_frame;
|
Frame* frame = pk_current_vm->top_frame;
|
||||||
if(frame->is_dynamic) {
|
if(frame->is_dynamic) {
|
||||||
py_assign(py_retval(), &frame->p0[1]);
|
py_assign(py_retval(), &frame->p0[1]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user