mirror of https://github.com/arendst/Tasmota.git
Berry improve solidification of bytes (#21751)
This commit is contained in:
parent
a3048a0b25
commit
b56e3c43a8
|
@ -29,21 +29,36 @@ extern "C" {
|
|||
.marked = GC_CONST
|
||||
|
||||
#define be_define_const_bytes(_name, ...) \
|
||||
const uint8_t be_const_bin_##_name[] = { __VA_ARGS__ }
|
||||
|
||||
#define be_const_bytes_instance(_bytes) { \
|
||||
.v.c = ( \
|
||||
& (const binstance_arg3) { \
|
||||
const binstance_arg3 be_const_instance_##_name = { \
|
||||
be_const_header(BE_INSTANCE), \
|
||||
.super = NULL, \
|
||||
.sub = NULL, \
|
||||
._class = (bclass*) &be_class_bytes, \
|
||||
.members = { \
|
||||
be_const_comptr(&be_const_bin_##_bytes), \
|
||||
be_const_int(sizeof(#_bytes) / 2), \
|
||||
{.v.c = (const void*) & (const uint8_t[]) { __VA_ARGS__ }, \
|
||||
.type = BE_COMPTR }, \
|
||||
be_const_int(sizeof(#_name) / 2), \
|
||||
be_const_int(BYTES_SIZE_SOLIDIFIED) \
|
||||
} \
|
||||
}), \
|
||||
}
|
||||
|
||||
/* special version to define a default empty bytes */
|
||||
#define be_define_const_bytes_empty() \
|
||||
const binstance_arg3 be_const_instance_ = { \
|
||||
be_const_header(BE_INSTANCE), \
|
||||
.super = NULL, \
|
||||
.sub = NULL, \
|
||||
._class = (bclass*) &be_class_bytes, \
|
||||
.members = { \
|
||||
{.v.c = (const void*) & (const uint8_t[]) { 0x00 }, \
|
||||
.type = BE_COMPTR }, \
|
||||
be_const_int(0), \
|
||||
be_const_int(BYTES_SIZE_SOLIDIFIED) \
|
||||
} \
|
||||
}
|
||||
|
||||
#define be_const_bytes_instance(_bytes) { \
|
||||
.v.c = &be_const_instance_##_bytes, \
|
||||
.type = BE_INSTANCE \
|
||||
}
|
||||
|
||||
|
@ -339,8 +354,8 @@ const bntvmodule_t be_native_module(_module) = { \
|
|||
|
||||
#else
|
||||
|
||||
#define be_define_const_bytes(_name, ...) \
|
||||
const uint8_t be_const_bin_##_name[] = { __VA_ARGS__ }
|
||||
// #define be_define_const_bytes(_name, ...) \
|
||||
// const uint8_t be_const_bin_##_name[] = { __VA_ARGS__ }
|
||||
|
||||
#define be_define_const_str_weak(_name, _s, _len) \
|
||||
const bcstring be_const_str_##_name = { \
|
||||
|
|
|
@ -132,7 +132,7 @@ static const bclass *m_solidify_get_parentclass(const bproto *pr)
|
|||
|
||||
static void m_solidify_bvalue(bvm *vm, bbool str_literal, const bvalue * value, const char *prefixname, const char *key, void* fout);
|
||||
|
||||
static void m_solidify_map(bvm *vm, bbool str_literal, const bmap * map, const char *prefixname, void* fout)
|
||||
static void m_solidify_map(bvm *vm, bbool str_literal, bmap * map, const char *prefixname, void* fout)
|
||||
{
|
||||
// compact first
|
||||
be_map_compact(vm, map);
|
||||
|
@ -288,14 +288,6 @@ static void m_solidify_bvalue(bvm *vm, bbool str_literal, const bvalue * value,
|
|||
{
|
||||
binstance * ins = (binstance *) var_toobj(value);
|
||||
bclass * cl = ins->_class;
|
||||
if (ins->super || ins->sub) {
|
||||
be_raise(vm, "internal_error", "instance must not have a super/sub class");
|
||||
} else if ((cl != &be_class_map && cl != &be_class_list) || 1) { // TODO
|
||||
const char * cl_ptr = "";
|
||||
if (cl == &be_class_map) { cl_ptr = "map"; }
|
||||
else if (cl == &be_class_list) { cl_ptr = "list"; }
|
||||
else if (cl == &be_class_bytes) { cl_ptr = "bytes"; }
|
||||
else { be_raise(vm, "internal_error", "unsupported class"); }
|
||||
|
||||
if (cl == &be_class_bytes) {
|
||||
const void * bufptr = var_toobj(&ins->members[0]);
|
||||
|
@ -306,7 +298,14 @@ static void m_solidify_bvalue(bvm *vm, bbool str_literal, const bvalue * value,
|
|||
be_bytes_tohex(hex_out, hex_len, bufptr, len);
|
||||
logfmt("be_const_bytes_instance(%s)", hex_out);
|
||||
be_pop(vm, 1);
|
||||
} else if (ins->super || ins->sub) {
|
||||
be_raise(vm, "internal_error", "instance must not have a super/sub class");
|
||||
} else {
|
||||
const char * cl_ptr = "";
|
||||
if (cl == &be_class_map) { cl_ptr = "map"; }
|
||||
else if (cl == &be_class_list) { cl_ptr = "list"; }
|
||||
else { be_raise(vm, "internal_error", "unsupported class"); }
|
||||
|
||||
logfmt("be_const_simple_instance(be_nested_simple_instance(&be_class_%s, {\n", cl_ptr);
|
||||
if (cl == &be_class_map) {
|
||||
logfmt(" be_const_map( * ");
|
||||
|
@ -317,7 +316,6 @@ static void m_solidify_bvalue(bvm *vm, bbool str_literal, const bvalue * value,
|
|||
logfmt(" ) } ))");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BE_MAP:
|
||||
m_solidify_map(vm, str_literal, (bmap *) var_toobj(value), prefixname, fout);
|
||||
|
@ -354,7 +352,7 @@ static void m_solidify_proto_inner_class(bvm *vm, bbool str_literal, const bprot
|
|||
}
|
||||
}
|
||||
|
||||
static void m_solidify_proto(bvm *vm, bbool str_literal, const bproto *pr, const char * func_name, const char *prefixname, int indent, void* fout)
|
||||
static void m_solidify_proto(bvm *vm, bbool str_literal, const bproto *pr, const char * func_name, int indent, void* fout)
|
||||
{
|
||||
/* get parent class name if any */
|
||||
const bclass *parentclass = m_solidify_get_parentclass(pr);
|
||||
|
@ -386,7 +384,7 @@ static void m_solidify_proto(bvm *vm, bbool str_literal, const bproto *pr, const
|
|||
size_t sub_len = strlen(func_name) + 10;
|
||||
char sub_name[sub_len];
|
||||
snprintf(sub_name, sizeof(sub_name), "%s_%"PRId32, func_name, i);
|
||||
m_solidify_proto(vm, str_literal, pr->ptab[i], sub_name, NULL, indent+2, fout);
|
||||
m_solidify_proto(vm, str_literal, pr->ptab[i], sub_name, indent+2, fout);
|
||||
logfmt(",\n");
|
||||
}
|
||||
if (parentclass_name) {
|
||||
|
@ -500,7 +498,7 @@ static void m_solidify_closure(bvm *vm, bbool str_literal, const bclosure *clo,
|
|||
func_name_id);
|
||||
}
|
||||
|
||||
m_solidify_proto(vm, str_literal, pr, func_name, prefixname, indent, fout);
|
||||
m_solidify_proto(vm, str_literal, pr, func_name, indent, fout);
|
||||
logfmt("\n");
|
||||
|
||||
// closure
|
||||
|
@ -564,12 +562,12 @@ static void m_solidify_subclass(bvm *vm, bbool str_literal, const bclass *cla, v
|
|||
logfmt(");\n");
|
||||
}
|
||||
|
||||
static void m_solidify_class(bvm *vm, bbool str_literal, const bclass *cl, void* fout)
|
||||
static void m_solidify_class(bvm *vm, bbool str_literal, bclass *cl, void* fout)
|
||||
{
|
||||
m_solidify_subclass(vm, str_literal, cl, fout);
|
||||
}
|
||||
|
||||
static void m_solidify_module(bvm *vm, bbool str_literal, const bmodule *ml, void* fout)
|
||||
static void m_solidify_module(bvm *vm, bbool str_literal, bmodule *ml, void* fout)
|
||||
{
|
||||
const char * modulename = be_module_name(ml);
|
||||
if (!modulename) { modulename = ""; }
|
||||
|
|
|
@ -23,7 +23,7 @@ class bytes_build:
|
|||
def build_bytes_def(self):
|
||||
ostr = ""
|
||||
ostr += "/* binary arrays */\n"
|
||||
ostr += "be_define_const_bytes(,);\n"
|
||||
ostr += "be_define_const_bytes_empty();\n"
|
||||
for k in self.map:
|
||||
ostr += "be_define_const_bytes("
|
||||
ostr += k + ", " + ", ".join( [ "0x" + k[i:i+2] for i in range(0, len(k), 2)] )
|
||||
|
@ -34,8 +34,8 @@ class bytes_build:
|
|||
def build_bytes_ext(self):
|
||||
ostr = ""
|
||||
ostr += "/* extern binary arrays */\n"
|
||||
ostr += "extern const uint8_t be_const_bin_[];\n"
|
||||
ostr += "extern const binstance_arg3 be_const_instance_;\n"
|
||||
for k in self.map:
|
||||
ostr += "extern const uint8_t be_const_bin_" + k + "[];\n"
|
||||
ostr += "extern const binstance_arg3 be_const_instance_" + k + ";\n"
|
||||
|
||||
return ostr
|
Loading…
Reference in New Issue