mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-22 02:06:31 +00:00
Berry support for int keys in map in solidification
This commit is contained in:
parent
5a507a5c6e
commit
4629bb4436
@ -33,6 +33,12 @@ extern "C" {
|
|||||||
.next = (uint32_t)(_next) & 0xFFFFFF \
|
.next = (uint32_t)(_next) & 0xFFFFFF \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define be_const_key_int(_i, _next) { \
|
||||||
|
.v.i = _i, \
|
||||||
|
.type = BE_INT, \
|
||||||
|
.next = (uint32_t)(_next) & 0xFFFFFF \
|
||||||
|
}
|
||||||
|
|
||||||
#define be_const_func(_func) { \
|
#define be_const_func(_func) { \
|
||||||
.v.nf = (_func), \
|
.v.nf = (_func), \
|
||||||
.type = BE_NTVFUNC \
|
.type = BE_NTVFUNC \
|
||||||
@ -249,6 +255,12 @@ const bntvmodule be_native_module(_module) = { \
|
|||||||
uint32_t((_next)&0xFFFFFF) \
|
uint32_t((_next)&0xFFFFFF) \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define be_const_key_int(_i, _next) { \
|
||||||
|
bvaldata(i), \
|
||||||
|
BE_INT, \
|
||||||
|
uint32_t((_next)&0xFFFFFF) \
|
||||||
|
}
|
||||||
|
|
||||||
#define be_const_func(_func) { \
|
#define be_const_func(_func) { \
|
||||||
bvaldata(_func), \
|
bvaldata(_func), \
|
||||||
BE_NTVFUNC \
|
BE_NTVFUNC \
|
||||||
|
@ -109,15 +109,11 @@ static void m_solidify_map(bvm *vm, bmap * map, const char *class_name)
|
|||||||
if (node->key.type == BE_NIL) {
|
if (node->key.type == BE_NIL) {
|
||||||
continue; /* key not used */
|
continue; /* key not used */
|
||||||
}
|
}
|
||||||
if (node->key.type != BE_STRING) {
|
|
||||||
char error[64];
|
|
||||||
snprintf(error, sizeof(error), "Unsupported type in key: %i", node->key.type);
|
|
||||||
be_raise(vm, "internal_error", error);
|
|
||||||
}
|
|
||||||
int key_next = node->key.next;
|
int key_next = node->key.next;
|
||||||
if (0xFFFFFF == key_next) {
|
if (0xFFFFFF == key_next) {
|
||||||
key_next = -1; /* more readable */
|
key_next = -1; /* more readable */
|
||||||
}
|
}
|
||||||
|
if (node->key.type == BE_STRING) {
|
||||||
/* convert the string literal to identifier */
|
/* convert the string literal to identifier */
|
||||||
const char * key = str(node->key.v.s);
|
const char * key = str(node->key.v.s);
|
||||||
size_t id_len = toidentifier_length(key);
|
size_t id_len = toidentifier_length(key);
|
||||||
@ -125,6 +121,14 @@ static void m_solidify_map(bvm *vm, bmap * map, const char *class_name)
|
|||||||
toidentifier(id_buf, key);
|
toidentifier(id_buf, key);
|
||||||
logfmt(" { be_const_key(%s, %i), ", id_buf, key_next);
|
logfmt(" { be_const_key(%s, %i), ", id_buf, key_next);
|
||||||
m_solidify_bvalue(vm, &node->value, class_name, str(node->key.v.s));
|
m_solidify_bvalue(vm, &node->value, class_name, str(node->key.v.s));
|
||||||
|
} else if (node->key.type == BE_INT) {
|
||||||
|
logfmt(" { be_const_key_int(%i, %i), ", node->key.v.i, key_next);
|
||||||
|
m_solidify_bvalue(vm, &node->value, class_name, NULL);
|
||||||
|
} else {
|
||||||
|
char error[64];
|
||||||
|
snprintf(error, sizeof(error), "Unsupported type in key: %i", node->key.type);
|
||||||
|
be_raise(vm, "internal_error", error);
|
||||||
|
}
|
||||||
|
|
||||||
logfmt(" },\n");
|
logfmt(" },\n");
|
||||||
}
|
}
|
||||||
@ -358,7 +362,8 @@ static void m_solidify_closure(bvm *vm, bclosure *cl, const char * classname, in
|
|||||||
const char * func_name = str(pr->name);
|
const char * func_name = str(pr->name);
|
||||||
|
|
||||||
if (cl->nupvals > 0) {
|
if (cl->nupvals > 0) {
|
||||||
be_raise(vm, "internal_error", "Unsupported upvals in closure");
|
logfmt("--> Unsupported upvals in closure <---");
|
||||||
|
// be_raise(vm, "internal_error", "Unsupported upvals in closure");
|
||||||
}
|
}
|
||||||
|
|
||||||
int indent = 2;
|
int indent = 2;
|
||||||
|
@ -113,7 +113,7 @@ static void free_sstring(bvm *vm, bstring *str)
|
|||||||
static uint32_t str_hash(const char *str, size_t len)
|
static uint32_t str_hash(const char *str, size_t len)
|
||||||
{
|
{
|
||||||
uint32_t hash = 2166136261u;
|
uint32_t hash = 2166136261u;
|
||||||
be_assert(str || len);
|
be_assert(str || !len);
|
||||||
while (len--) {
|
while (len--) {
|
||||||
hash = (hash ^ (unsigned char)*str++) * 16777619u;
|
hash = (hash ^ (unsigned char)*str++) * 16777619u;
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,7 @@ extern "C" {
|
|||||||
int32_t top = be_top(vm); // Get the number of arguments
|
int32_t top = be_top(vm); // Get the number of arguments
|
||||||
if (top >= 2 && be_isstring(vm, 2)) { // 1 mandatory string argument
|
if (top >= 2 && be_isstring(vm, 2)) { // 1 mandatory string argument
|
||||||
const char * payload = be_tostring(vm, 2);
|
const char * payload = be_tostring(vm, 2);
|
||||||
|
be_pop(vm, top); // clear the stack before calling, because of re-entrant call to Berry in a Rule
|
||||||
bool handled = XdrvRulesProcess(0, payload);
|
bool handled = XdrvRulesProcess(0, payload);
|
||||||
be_pushbool(vm, handled);
|
be_pushbool(vm, handled);
|
||||||
be_return(vm); // Return
|
be_return(vm); // Return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user