From bcbef695ce0a40fff12b1960552d1367f2164d2a Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sat, 4 Dec 2021 13:46:43 +0100 Subject: [PATCH 1/2] Berry sync with upstream --- lib/libesp32/Berry/src/be_class.c | 2 +- lib/libesp32/Berry/src/be_class.h | 2 +- lib/libesp32/Berry/src/be_jsonlib.c | 2 +- lib/libesp32/Berry/src/be_strlib.c | 1 - lib/libesp32/Berry/src/be_vm.c | 14 +++++++------- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/libesp32/Berry/src/be_class.c b/lib/libesp32/Berry/src/be_class.c index a960d4b24..c2042fd39 100644 --- a/lib/libesp32/Berry/src/be_class.c +++ b/lib/libesp32/Berry/src/be_class.c @@ -220,7 +220,7 @@ static binstance* newobject(bvm *vm, bclass *c) /* Instanciate new instance from stack with argc parameters */ /* Pushes the constructor on the stack to be executed if a construtor is found */ /* Returns true if a constructor is found */ -bbool be_class_newobj(bvm *vm, bclass *c, int32_t pos, int argc, int mode) +bbool be_class_newobj(bvm *vm, bclass *c, int pos, int argc, int mode) { bvalue init; binstance *obj = newobject(vm, c); /* create empty object hierarchy from class hierarchy */ diff --git a/lib/libesp32/Berry/src/be_class.h b/lib/libesp32/Berry/src/be_class.h index 59abbab30..405ea6d38 100644 --- a/lib/libesp32/Berry/src/be_class.h +++ b/lib/libesp32/Berry/src/be_class.h @@ -58,7 +58,7 @@ void be_prim_method_bind(bvm *vm, bclass *c, bstring *name, bntvfunc f); void be_closure_method_bind(bvm *vm, bclass *c, bstring *name, bclosure *cl); int be_class_closure_count(bclass *c); void be_class_upvalue_init(bvm *vm, bclass *c); -bbool be_class_newobj(bvm *vm, bclass *c, int32_t pos, int argc, int mode); +bbool be_class_newobj(bvm *vm, bclass *c, int pos, int argc, int mode); int be_instance_member_simple(bvm *vm, binstance *obj, bstring *name, bvalue *dst); int be_instance_member(bvm *vm, binstance *obj, bstring *name, bvalue *dst); int be_class_member(bvm *vm, bclass *obj, bstring *name, bvalue *dst); diff --git a/lib/libesp32/Berry/src/be_jsonlib.c b/lib/libesp32/Berry/src/be_jsonlib.c index 2ee2a4daa..1d7049ea1 100644 --- a/lib/libesp32/Berry/src/be_jsonlib.c +++ b/lib/libesp32/Berry/src/be_jsonlib.c @@ -54,7 +54,7 @@ static int is_object(bvm *vm, const char *class, int idx) } be_remove(vm, -2); } - const char *name = be_classname(vm, idx); + const char *name = be_classname(vm, -1); bbool ret = !strcmp(name, class); be_pop(vm, 1); return ret; diff --git a/lib/libesp32/Berry/src/be_strlib.c b/lib/libesp32/Berry/src/be_strlib.c index e82ec3cf2..53f35607b 100644 --- a/lib/libesp32/Berry/src/be_strlib.c +++ b/lib/libesp32/Berry/src/be_strlib.c @@ -330,7 +330,6 @@ static bstring* string_range(bvm *vm, bstring *str, binstance *range) { bint lower, upper; bint size = str_len(str); /* size of source string */ - // bint size = be_data_size(vm, -1); /* get source list size */ /* get index range */ bvalue temp; be_instance_member(vm, range, be_newstr(vm, "__lower__"), &temp); diff --git a/lib/libesp32/Berry/src/be_vm.c b/lib/libesp32/Berry/src/be_vm.c index dd60e34b7..67519ee39 100644 --- a/lib/libesp32/Berry/src/be_vm.c +++ b/lib/libesp32/Berry/src/be_vm.c @@ -142,7 +142,7 @@ _vm->cf->status = PRIM_FUNC; \ } -static void prep_closure(bvm *vm, int32_t pos, int argc, int mode); +static void prep_closure(bvm *vm, int pos, int argc, int mode); static void attribute_error(bvm *vm, const char *t, bvalue *b, bvalue *c) { @@ -1186,7 +1186,7 @@ newframe: /* a new call frame */ } } -static void prep_closure(bvm *vm, int32_t pos, int argc, int mode) +static void prep_closure(bvm *vm, int pos, int argc, int mode) { bvalue *v, *end; bproto *proto = var2cl(vm->reg + pos)->proto; @@ -1211,7 +1211,7 @@ static void prep_closure(bvm *vm, int32_t pos, int argc, int mode) } } -static void do_closure(bvm *vm, int32_t pos, int argc) +static void do_closure(bvm *vm, int pos, int argc) { // bvalue *v, *end; // bproto *proto = var2cl(reg)->proto; @@ -1225,7 +1225,7 @@ static void do_closure(bvm *vm, int32_t pos, int argc) vm_exec(vm); } -static void do_ntvclos(bvm *vm, int32_t pos, int argc) +static void do_ntvclos(bvm *vm, int pos, int argc) { bntvclos *f = var_toobj(vm->reg + pos); push_native(vm, vm->reg + pos, argc, 0); @@ -1233,7 +1233,7 @@ static void do_ntvclos(bvm *vm, int32_t pos, int argc) ret_native(vm); } -static void do_ntvfunc(bvm *vm, int32_t pos, int argc) +static void do_ntvfunc(bvm *vm, int pos, int argc) { bntvfunc f = var_tontvfunc(vm->reg + pos); push_native(vm, vm->reg + pos, argc, 0); @@ -1241,7 +1241,7 @@ static void do_ntvfunc(bvm *vm, int32_t pos, int argc) ret_native(vm); } -static void do_class(bvm *vm, int32_t pos, int argc) +static void do_class(bvm *vm, int pos, int argc) { if (be_class_newobj(vm, var_toobj(vm->reg + pos), pos, ++argc, 0)) { be_incrtop(vm); @@ -1254,7 +1254,7 @@ void be_dofunc(bvm *vm, bvalue *v, int argc) { be_assert(vm->reg <= v && v < vm->stacktop); be_assert(vm->stack <= vm->reg && vm->reg < vm->stacktop); - int32_t pos = v - vm->reg; + int pos = v - vm->reg; switch (var_type(v)) { case BE_CLASS: do_class(vm, pos, argc); break; case BE_CLOSURE: do_closure(vm, pos, argc); break; From 888cbb999d50fba71d3f81d058cd6cc83c1caba8 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sat, 4 Dec 2021 13:49:06 +0100 Subject: [PATCH 2/2] Rename be_map_release to be_map_compact --- lib/libesp32/Berry/src/be_api.c | 2 +- lib/libesp32/Berry/src/be_class.c | 2 +- lib/libesp32/Berry/src/be_map.c | 2 +- lib/libesp32/Berry/src/be_map.h | 2 +- lib/libesp32/Berry/src/be_module.c | 2 +- lib/libesp32/Berry/src/be_solidifylib.c | 2 +- lib/libesp32/Berry/src/be_var.c | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/libesp32/Berry/src/be_api.c b/lib/libesp32/Berry/src/be_api.c index d883c08d7..79d5c48ff 100644 --- a/lib/libesp32/Berry/src/be_api.c +++ b/lib/libesp32/Berry/src/be_api.c @@ -51,7 +51,7 @@ static void class_init(bvm *vm, bclass *c, const bnfuncinfo *lib) ++slib; } } - be_map_release(vm, c->members); /* clear space */ + be_map_compact(vm, c->members); /* clear space */ } } diff --git a/lib/libesp32/Berry/src/be_class.c b/lib/libesp32/Berry/src/be_class.c index c2042fd39..0f4efb3d5 100644 --- a/lib/libesp32/Berry/src/be_class.c +++ b/lib/libesp32/Berry/src/be_class.c @@ -40,7 +40,7 @@ bclass* be_newclass(bvm *vm, bstring *name, bclass *super) void be_class_compress(bvm *vm, bclass *c) { if (!gc_isconst(c) && c->members) { - be_map_release(vm, c->members); /* clear space */ + be_map_compact(vm, c->members); /* clear space */ } } diff --git a/lib/libesp32/Berry/src/be_map.c b/lib/libesp32/Berry/src/be_map.c index 004406f46..37f9efc62 100644 --- a/lib/libesp32/Berry/src/be_map.c +++ b/lib/libesp32/Berry/src/be_map.c @@ -343,7 +343,7 @@ bmapnode* be_map_val2node(bvalue *value) return (bmapnode *)((size_t)value - sizeof(bmapkey)); } -void be_map_release(bvm *vm, bmap *map) +void be_map_compact(bvm *vm, bmap *map) { (void)vm; if (!gc_isconst(map)) { diff --git a/lib/libesp32/Berry/src/be_map.h b/lib/libesp32/Berry/src/be_map.h index d632f0d0b..7ae76962c 100644 --- a/lib/libesp32/Berry/src/be_map.h +++ b/lib/libesp32/Berry/src/be_map.h @@ -56,6 +56,6 @@ bvalue* be_map_insertstr(bvm *vm, bmap *map, bstring *key, bvalue *value); void be_map_removestr(bvm *vm, bmap *map, bstring *key); bmapnode* be_map_next(bmap *map, bmapiter *iter); bmapnode* be_map_val2node(bvalue *value); -void be_map_release(bvm *vm, bmap *map); +void be_map_compact(bvm *vm, bmap *map); #endif diff --git a/lib/libesp32/Berry/src/be_module.c b/lib/libesp32/Berry/src/be_module.c index c661528a1..0256809af 100644 --- a/lib/libesp32/Berry/src/be_module.c +++ b/lib/libesp32/Berry/src/be_module.c @@ -99,7 +99,7 @@ static bmodule* new_module(bvm *vm, const bntvmodule *nm) obj->table = NULL; /* gc protection */ obj->table = be_map_new(vm); insert_attrs(vm, obj->table, nm); - be_map_release(vm, obj->table); /* clear space */ + be_map_compact(vm, obj->table); /* clear space */ be_stackpop(vm, 1); } return obj; diff --git a/lib/libesp32/Berry/src/be_solidifylib.c b/lib/libesp32/Berry/src/be_solidifylib.c index d8291b365..2b82b44fd 100644 --- a/lib/libesp32/Berry/src/be_solidifylib.c +++ b/lib/libesp32/Berry/src/be_solidifylib.c @@ -42,7 +42,7 @@ static void m_solidify_bvalue(bvm *vm, bvalue * value, const char *classname, co static void m_solidify_map(bvm *vm, bmap * map, const char *class_name) { // compact first - be_map_release(vm, map); + be_map_compact(vm, map); logfmt(" be_nested_map(%i,\n", map->count); diff --git a/lib/libesp32/Berry/src/be_var.c b/lib/libesp32/Berry/src/be_var.c index ebc70ecea..4fee144cd 100644 --- a/lib/libesp32/Berry/src/be_var.c +++ b/lib/libesp32/Berry/src/be_var.c @@ -87,7 +87,7 @@ bvalue* be_global_var(bvm *vm, int index) void be_global_release_space(bvm *vm) { - be_map_release(vm, global(vm).vtab); + be_map_compact(vm, global(vm).vtab); be_vector_release(vm, &global(vm).vlist); } @@ -130,7 +130,7 @@ int be_builtin_new(bvm *vm, bstring *name) void be_bulitin_release_space(bvm *vm) { - be_map_release(vm, builtin(vm).vtab); + be_map_compact(vm, builtin(vm).vtab); be_vector_release(vm, &builtin(vm).vlist); } #else