Berry introspect toptr (#13172)

* Berry introspect, add `toptr` and `fromptr`

* Remove warning
This commit is contained in:
s-hadinger 2021-09-19 15:35:51 +02:00 committed by GitHub
parent f7613ee0c8
commit 5e2686407d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1787 additions and 1741 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,16 @@
#include "be_constobj.h"
static be_define_const_map_slots(m_libintrospect_map) {
{ be_const_key(members, -1), be_const_func(m_attrlist) },
{ be_const_key(set, -1), be_const_func(m_setmember) },
{ be_const_key(get, -1), be_const_func(m_findmember) },
{ be_const_key(toptr, 3), be_const_func(m_toptr) },
{ be_const_key(set, -1), be_const_func(m_setmember) },
{ be_const_key(fromptr, -1), be_const_func(m_fromptr) },
{ be_const_key(members, 1), be_const_func(m_attrlist) },
};
static be_define_const_map(
m_libintrospect_map,
3
5
);
static be_define_const_module(

View File

@ -13,6 +13,8 @@
#include "be_debug.h"
#include "be_map.h"
#include "be_vm.h"
#include "be_exec.h"
#include "be_gc.h"
#include <string.h>
#if BE_USE_INTROSPECT_MODULE
@ -76,6 +78,40 @@ static int m_setmember(bvm *vm)
be_return_nil(vm);
}
static int m_toptr(bvm *vm)
{
int top = be_top(vm);
if (top >= 1) {
bvalue *v = be_indexof(vm, 1);
if (var_basetype(v) >= BE_GCOBJECT) {
be_pushint(vm, (int) var_toobj(v));
be_return(vm);
} else {
be_raise(vm, "value_error", "unsupported for this type");
}
}
be_return_nil(vm);
}
static int m_fromptr(bvm *vm)
{
int top = be_top(vm);
if (top >= 1) {
int v = be_toint(vm, 1);
if (v) {
bgcobject * ptr = (bgcobject*) v;
if (var_basetype(ptr) >= BE_GCOBJECT) {
bvalue *top = be_incrtop(vm);
var_setobj(top, ptr->type, ptr);
} else {
be_raise(vm, "value_error", "unsupported for this type");
}
}
be_return(vm);
}
be_return_nil(vm);
}
#if !BE_USE_PRECOMPILED_OBJECT
be_native_module_attr_table(introspect) {
be_native_module_function("members", m_attrlist),
@ -92,6 +128,9 @@ module introspect (scope: global, depend: BE_USE_INTROSPECT_MODULE) {
get, func(m_findmember)
set, func(m_setmember)
toptr, func(m_toptr)
fromptr, func(m_fromptr)
}
@const_object_info_end */
#include "../generate/be_fixed_introspect.h"