mirror of https://github.com/arendst/Tasmota.git
Berry yet another fix 2
This commit is contained in:
parent
a92f2cb941
commit
c152838e25
|
@ -554,7 +554,6 @@ extern const bcstring be_const_str_readline;
|
|||
extern const bcstring be_const_str_real;
|
||||
extern const bcstring be_const_str_reapply;
|
||||
extern const bcstring be_const_str_redirect;
|
||||
extern const bcstring be_const_str_reduce;
|
||||
extern const bcstring be_const_str_refr_size;
|
||||
extern const bcstring be_const_str_register_obj;
|
||||
extern const bcstring be_const_str_remove;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,25 +1,23 @@
|
|||
#include "be_constobj.h"
|
||||
|
||||
static be_define_const_map_slots(be_class_map_map) {
|
||||
{ be_const_key(setitem, -1), be_const_func(m_setitem) },
|
||||
{ be_const_key(remove, 8), be_const_func(m_remove) },
|
||||
{ be_const_key(insert, -1), be_const_func(m_insert) },
|
||||
{ be_const_key(tostring, 4), be_const_func(m_tostring) },
|
||||
{ be_const_key(has, -1), be_const_func(m_contains) },
|
||||
{ be_const_key(init, -1), be_const_func(m_init) },
|
||||
{ be_const_key(contains, 9), be_const_func(m_contains) },
|
||||
{ be_const_key(_X2Ep, 13), be_const_var(0) },
|
||||
{ be_const_key(reduce, -1), be_const_func(m_reduce) },
|
||||
{ be_const_key(size, -1), be_const_func(m_size) },
|
||||
{ be_const_key(find, -1), be_const_func(m_find) },
|
||||
{ be_const_key(tostring, -1), be_const_func(m_tostring) },
|
||||
{ be_const_key(insert, -1), be_const_func(m_insert) },
|
||||
{ be_const_key(init, -1), be_const_func(m_init) },
|
||||
{ be_const_key(contains, -1), be_const_func(m_contains) },
|
||||
{ be_const_key(keys, -1), be_const_func(m_keys) },
|
||||
{ be_const_key(item, -1), be_const_func(m_item) },
|
||||
{ be_const_key(iter, -1), be_const_func(m_iter) },
|
||||
{ be_const_key(_X2Ep, -1), be_const_var(0) },
|
||||
{ be_const_key(iter, 6), be_const_func(m_iter) },
|
||||
{ be_const_key(setitem, 2), be_const_func(m_setitem) },
|
||||
{ be_const_key(remove, -1), be_const_func(m_remove) },
|
||||
{ be_const_key(item, 11), be_const_func(m_item) },
|
||||
{ be_const_key(find, -1), be_const_func(m_find) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
be_class_map_map,
|
||||
14
|
||||
12
|
||||
);
|
||||
|
||||
BE_EXPORT_VARIABLE be_define_const_class(
|
||||
|
|
|
@ -201,15 +201,6 @@ const bntvmodule be_native_module(_module) = { \
|
|||
.members = _members \
|
||||
}
|
||||
|
||||
// #define be_local_instance(_name, _class_ptr, _members) \
|
||||
// static const binstance i_##_name = { \
|
||||
// be_const_header(BE_INSTANCE), \
|
||||
// .super = NULL, \
|
||||
// .sub = NULL, \
|
||||
// ._class = (bclass*) _class_ptr, \
|
||||
// .members = _members \
|
||||
// }
|
||||
|
||||
#define be_nested_map(_size, _slots) \
|
||||
& (const bmap) { \
|
||||
be_const_header(BE_MAP), \
|
||||
|
@ -233,13 +224,6 @@ const bntvmodule be_native_module(_module) = { \
|
|||
BE_STRING \
|
||||
}
|
||||
|
||||
#define be_nested_str_literal(_str) \
|
||||
{ \
|
||||
{ .s=(be_nested_const_str(_str, 0, sizeof(_str)-1 )) \
|
||||
}, \
|
||||
BE_STRING \
|
||||
}
|
||||
|
||||
#define be_str_literal(_str) \
|
||||
be_nested_const_str(_str, 0, sizeof(_str)-1 )
|
||||
|
||||
|
|
|
@ -561,5 +561,9 @@ void be_gc_collect(bvm *vm)
|
|||
reset_fixedlist(vm);
|
||||
/* step 5: calculate the next GC threshold */
|
||||
vm->gc.threshold = next_threshold(vm->gc);
|
||||
#if BE_USE_PERF_COUNTERS
|
||||
if (vm->obshook != NULL) (*vm->obshook)(vm, BE_OBS_GC_END, vm->gc.usage, vm->counter_gc_kept, vm->counter_gc_freed);
|
||||
#else
|
||||
if (vm->obshook != NULL) (*vm->obshook)(vm, BE_OBS_GC_END, vm->gc.usage);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -212,62 +212,6 @@ static int m_keys(bvm *vm)
|
|||
be_return(vm);
|
||||
}
|
||||
|
||||
/* apply a function/closure to each element of a map */
|
||||
/* `map.reduce(f:function [, initializer:any]) -> any` */
|
||||
/* Calls for each element `f(key, value, acc) -> any` */
|
||||
/* `acc` is initialized with `initilizer` if present or `nil` */
|
||||
/* the return value of the function becomes the next value passed in arg `acc` */
|
||||
static int m_reduce(bvm *vm)
|
||||
{
|
||||
int argc = be_top(vm);
|
||||
if (argc > 1 && be_isfunction(vm, 2)) {
|
||||
bbool has_initializer = (argc > 2);
|
||||
/* get map internal object */
|
||||
be_getmember(vm, 1, ".p");
|
||||
bvalue *v = be_indexof(vm, -1);
|
||||
bmap *map = cast(bmap*, var_toobj(v));
|
||||
/* get the number of slots if any */
|
||||
int slots_initial = be_map_size(map);
|
||||
/* place-holder for on-going value and return value */
|
||||
if (has_initializer) {
|
||||
be_pushvalue(vm, 3);
|
||||
} else {
|
||||
be_pushnil(vm); /* if no initializer use `nil` */
|
||||
}
|
||||
for (int i = 0; i < slots_initial; i++) {
|
||||
bmapnode * node = map->slots + i;
|
||||
if (!var_isnil(&node->key)) { /* is the key present in this slot? */
|
||||
be_pushvalue(vm, 2); /* push function */
|
||||
|
||||
bvalue kv; /* push key on stack */
|
||||
kv.type = node->key.type;
|
||||
kv.v = node->key.v;
|
||||
bvalue *reg = vm->top;
|
||||
var_setval(reg, &kv);
|
||||
be_incrtop(vm);
|
||||
|
||||
reg = vm->top; /* push value on stack */
|
||||
var_setval(reg, &node->value);
|
||||
be_incrtop(vm);
|
||||
|
||||
be_pushvalue(vm, -4);
|
||||
|
||||
be_call(vm, 3);
|
||||
be_pop(vm, 3); /* pop args, keep return value */
|
||||
be_remove(vm, -2); /* remove previous accumulator, keep return value from function */
|
||||
}
|
||||
/* check if the map has been resized during the call */
|
||||
if (be_map_size(map) != slots_initial) {
|
||||
be_raise(vm, "stop_iteration", "map resized within apply");
|
||||
break; /* abort */
|
||||
}
|
||||
}
|
||||
be_return(vm);
|
||||
}
|
||||
be_raise(vm, "value_error", "needs function as first argument");
|
||||
be_return_nil(vm);
|
||||
}
|
||||
|
||||
#if !BE_USE_PRECOMPILED_OBJECT
|
||||
void be_load_maplib(bvm *vm)
|
||||
{
|
||||
|
@ -280,12 +224,10 @@ void be_load_maplib(bvm *vm)
|
|||
{ "setitem", m_setitem },
|
||||
{ "find", m_find },
|
||||
{ "contains", m_contains },
|
||||
{ "has", m_contains }, /* deprecated */
|
||||
{ "size", m_size },
|
||||
{ "insert", m_insert },
|
||||
{ "iter", m_iter },
|
||||
{ "keys", m_keys },
|
||||
{ "reduce", m_reduce },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
be_regclass(vm, "map", members);
|
||||
|
@ -301,12 +243,10 @@ class be_class_map (scope: global, name: map) {
|
|||
setitem, func(m_setitem)
|
||||
find, func(m_find)
|
||||
contains, func(m_contains)
|
||||
has, func(m_contains)
|
||||
size, func(m_size)
|
||||
insert, func(m_insert)
|
||||
iter, func(m_iter)
|
||||
keys, func(m_keys)
|
||||
reduce, func(m_reduce)
|
||||
}
|
||||
@const_object_info_end */
|
||||
#include "../generate/be_fixed_be_class_map.h"
|
||||
|
|
|
@ -38,11 +38,11 @@ extern const bclass be_class_map;
|
|||
be_writestring(__lbuf); \
|
||||
} while (0)
|
||||
|
||||
/********************************************************************
|
||||
/********************************************************************\
|
||||
* Encode string to identifiers
|
||||
*
|
||||
* `_X` is used as an escape marker
|
||||
/********************************************************************/
|
||||
\********************************************************************/
|
||||
static unsigned toidentifier_length(const char *s)
|
||||
{
|
||||
unsigned len = 1;
|
||||
|
@ -115,7 +115,6 @@ static void m_solidify_map(bvm *vm, bmap * map, const char *class_name)
|
|||
be_raise(vm, "internal_error", error);
|
||||
}
|
||||
int key_next = node->key.next;
|
||||
size_t len = strlen(str(node->key.v.s));
|
||||
if (0xFFFFFF == key_next) {
|
||||
key_next = -1; /* more readable */
|
||||
}
|
||||
|
@ -192,10 +191,16 @@ static void m_solidify_bvalue(bvm *vm, bvalue * value, const char *classname, co
|
|||
}
|
||||
break;
|
||||
case BE_CLOSURE:
|
||||
{
|
||||
const char * func_name = str(((bclosure*) var_toobj(value))->proto->name);
|
||||
size_t id_len = toidentifier_length(func_name);
|
||||
char func_name_id[id_len];
|
||||
toidentifier(func_name_id, func_name);
|
||||
logfmt("be_const_%sclosure(%s%s%s_closure)",
|
||||
func_isstatic(value) ? "static_" : "",
|
||||
classname ? classname : "", classname ? "_" : "",
|
||||
str(((bclosure*) var_toobj(value))->proto->name));
|
||||
func_name_id);
|
||||
}
|
||||
break;
|
||||
case BE_CLASS:
|
||||
logfmt("be_const_class(be_class_%s)", str(((bclass*) var_toobj(value))->name));
|
||||
|
@ -365,9 +370,14 @@ static void m_solidify_closure(bvm *vm, bclosure *cl, const char * classname, in
|
|||
logfmt("** Solidified function: %s\n", func_name);
|
||||
logfmt("********************************************************************/\n");
|
||||
|
||||
{
|
||||
size_t id_len = toidentifier_length(func_name);
|
||||
char func_name_id[id_len];
|
||||
toidentifier(func_name_id, func_name);
|
||||
logfmt("be_local_closure(%s%s%s, /* name */\n",
|
||||
classname ? classname : "", classname ? "_" : "",
|
||||
func_name);
|
||||
func_name_id);
|
||||
}
|
||||
|
||||
m_solidify_proto(vm, pr, func_name, builtins, indent);
|
||||
logfmt("\n");
|
||||
|
|
Loading…
Reference in New Issue