diff --git a/lib/libesp32/berry/src/be_constobj.h b/lib/libesp32/berry/src/be_constobj.h index 86a871563..7fccc8f4f 100644 --- a/lib/libesp32/berry/src/be_constobj.h +++ b/lib/libesp32/berry/src/be_constobj.h @@ -354,9 +354,6 @@ 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_str_weak(_name, _s, _len) \ const bcstring be_const_str_##_name = { \ NULL, \ diff --git a/lib/libesp32/berry/src/be_filelib.c b/lib/libesp32/berry/src/be_filelib.c index dcf661fde..135de8ef7 100644 --- a/lib/libesp32/berry/src/be_filelib.c +++ b/lib/libesp32/berry/src/be_filelib.c @@ -234,7 +234,9 @@ int be_nfunc_open(bvm *vm) { "flush", i_flush }, { "close", i_close }, { "deinit", i_close }, +#if BE_USE_BYTECODE_SAVER { "savecode", i_savecode }, +#endif { NULL, NULL } }; fname = argc >= 1 && be_isstring(vm, 1) ? be_tostring(vm, 1) : NULL; diff --git a/lib/libesp32/berry/src/be_mem.c b/lib/libesp32/berry/src/be_mem.c index 9d20ca055..00a65272c 100644 --- a/lib/libesp32/berry/src/be_mem.c +++ b/lib/libesp32/berry/src/be_mem.c @@ -40,10 +40,15 @@ #elif defined(_MSC_VER) #define popcount(v) __popcnt(v) +// Find a free slot in the space bitmask +// Find the least significant 1-bit in x and return its 1-based index. static int ffs(unsigned x) { unsigned long i; - return _BitScanForward(&i, x) ? i : 0; + // NOTE: _BitScanForward is 0-based, see: + // https://learn.microsoft.com/en-us/cpp/intrinsics/bitscanforward-bitscanforward64?view=msvc-170 + // _BitScanForward(&index, 12) populates index with 2 + return _BitScanForward(&i, x) ? i + 1 : 0; } #else /* https://github.com/hcs0/Hackers-Delight/blob/master/pop.c.txt - count number of 1-bits */ diff --git a/lib/libesp32/berry/src/be_parser.c b/lib/libesp32/berry/src/be_parser.c index 4fc03b793..371c53792 100644 --- a/lib/libesp32/berry/src/be_parser.c +++ b/lib/libesp32/berry/src/be_parser.c @@ -324,8 +324,8 @@ static void end_func(bparser *parser) proto->codesize = finfo->pc; proto->ktab = be_vector_release(vm, &finfo->kvec); proto->nconst = be_vector_count(&finfo->kvec); - proto->nproto = be_vector_count(&finfo->pvec); proto->ptab = be_vector_release(vm, &finfo->pvec); + proto->nproto = be_vector_count(&finfo->pvec); #if BE_USE_MEM_ALIGNED proto->code = be_move_to_aligned(vm, proto->code, proto->codesize * sizeof(binstruction)); /* move `code` to 4-bytes aligned memory region */ proto->ktab = be_move_to_aligned(vm, proto->ktab, proto->nconst * sizeof(bvalue)); /* move `ktab` to 4-bytes aligned memory region */