Skip to content

Commit

Permalink
Bump berry to latest master
Browse files Browse the repository at this point in the history
Contains a few bugfixes
  • Loading branch information
alufers committed Apr 16, 2024
1 parent 42d1b3d commit da5ca97
Show file tree
Hide file tree
Showing 29 changed files with 911 additions and 431 deletions.
11 changes: 11 additions & 0 deletions src/core/external/berry/generate/be_const_strtab.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern const bcstring be_const_str__X2Elen;
extern const bcstring be_const_str__X2Ep;
extern const bcstring be_const_str__X2Esize;
extern const bcstring be_const_str__X3D_X3D;
extern const bcstring be_const_str___incr__;
extern const bcstring be_const_str___iterator__;
extern const bcstring be_const_str___lower__;
extern const bcstring be_const_str___upper__;
Expand All @@ -15,7 +16,10 @@ extern const bcstring be_const_str__change_buffer;
extern const bcstring be_const_str_abs;
extern const bcstring be_const_str_acos;
extern const bcstring be_const_str_add;
extern const bcstring be_const_str_addfloat;
extern const bcstring be_const_str_allocated;
extern const bcstring be_const_str_allocs;
extern const bcstring be_const_str_append;
extern const bcstring be_const_str_as;
extern const bcstring be_const_str_asin;
extern const bcstring be_const_str_assert;
Expand All @@ -29,6 +33,7 @@ extern const bcstring be_const_str_byte;
extern const bcstring be_const_str_bytes;
extern const bcstring be_const_str_call;
extern const bcstring be_const_str_calldepth;
extern const bcstring be_const_str_caller;
extern const bcstring be_const_str_ceil;
extern const bcstring be_const_str_char;
extern const bcstring be_const_str_chdir;
Expand Down Expand Up @@ -56,6 +61,7 @@ extern const bcstring be_const_str_dump;
extern const bcstring be_const_str_elif;
extern const bcstring be_const_str_else;
extern const bcstring be_const_str_end;
extern const bcstring be_const_str_endswith;
extern const bcstring be_const_str_escape;
extern const bcstring be_const_str_except;
extern const bcstring be_const_str_exists;
Expand All @@ -66,10 +72,12 @@ extern const bcstring be_const_str_find;
extern const bcstring be_const_str_floor;
extern const bcstring be_const_str_for;
extern const bcstring be_const_str_format;
extern const bcstring be_const_str_frees;
extern const bcstring be_const_str_fromb64;
extern const bcstring be_const_str_fromhex;
extern const bcstring be_const_str_fromptr;
extern const bcstring be_const_str_fromstring;
extern const bcstring be_const_str_gcdebug;
extern const bcstring be_const_str_get;
extern const bcstring be_const_str_getbits;
extern const bcstring be_const_str_getcwd;
Expand All @@ -80,6 +88,7 @@ extern const bcstring be_const_str_if;
extern const bcstring be_const_str_imax;
extern const bcstring be_const_str_imin;
extern const bcstring be_const_str_import;
extern const bcstring be_const_str_incr;
extern const bcstring be_const_str_init;
extern const bcstring be_const_str_input;
extern const bcstring be_const_str_insert;
Expand Down Expand Up @@ -123,6 +132,7 @@ extern const bcstring be_const_str_raise;
extern const bcstring be_const_str_rand;
extern const bcstring be_const_str_range;
extern const bcstring be_const_str_real;
extern const bcstring be_const_str_reallocs;
extern const bcstring be_const_str_remove;
extern const bcstring be_const_str_replace;
extern const bcstring be_const_str_resize;
Expand All @@ -145,6 +155,7 @@ extern const bcstring be_const_str_split;
extern const bcstring be_const_str_splitext;
extern const bcstring be_const_str_sqrt;
extern const bcstring be_const_str_srand;
extern const bcstring be_const_str_startswith;
extern const bcstring be_const_str_static;
extern const bcstring be_const_str_str;
extern const bcstring be_const_str_super;
Expand Down
400 changes: 208 additions & 192 deletions src/core/external/berry/generate/be_const_strtab_def.h

Large diffs are not rendered by default.

66 changes: 34 additions & 32 deletions src/core/external/berry/generate/be_fixed_be_class_bytes.h
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
#include "be_constobj.h"

static be_define_const_map_slots(be_class_bytes_map) {
{ be_const_key(resize, 27), be_const_func(m_resize) },
{ be_const_key(_X3D_X3D, -1), be_const_func(m_equal) },
{ be_const_key(setfloat, -1), be_const_func(m_setfloat) },
{ be_const_key(clear, -1), be_const_func(m_clear) },
{ be_const_key(fromb64, -1), be_const_func(m_fromb64) },
{ be_const_key(_change_buffer, 32), be_const_func(m_change_buffer) },
{ be_const_key(_X21_X3D, -1), be_const_func(m_nequal) },
{ be_const_key(_X2Ep, 31), be_const_var(0) },
{ be_const_key(_X2B, 4), be_const_func(m_merge) },
{ be_const_key(_X2Esize, 6), be_const_var(1) },
{ be_const_key(size, -1), be_const_func(m_size) },
{ be_const_key(_X2Elen, 21), be_const_var(0) },
{ be_const_key(fromstring, 26), be_const_func(m_fromstring) },
{ be_const_key(resize, 35), be_const_func(m_resize) },
{ be_const_key(set, -1), be_const_func(m_set) },
{ be_const_key(getbits, -1), be_const_closure(getbits_closure) },
{ be_const_key(add, 29), be_const_func(m_add) },
{ be_const_key(init, -1), be_const_func(m_init) },
{ be_const_key(ismapped, -1), be_const_func(m_is_mapped) },
{ be_const_key(_X3D_X3D, 16), be_const_func(m_equal) },
{ be_const_key(_change_buffer, 17), be_const_func(m_change_buffer) },
{ be_const_key(getfloat, -1), be_const_func(m_getfloat) },
{ be_const_key(tohex, 0), be_const_func(m_tohex) },
{ be_const_key(size, 23), be_const_func(m_size) },
{ be_const_key(tostring, 10), be_const_func(m_tostring) },
{ be_const_key(fromhex, -1), be_const_func(m_fromhex) },
{ be_const_key(seti, -1), be_const_func(m_set) },
{ be_const_key(_buffer, -1), be_const_func(m_buffer) },
{ be_const_key(fromb64, -1), be_const_func(m_fromb64) },
{ be_const_key(geti, -1), be_const_func(m_geti) },
{ be_const_key(_X2B, 38), be_const_func(m_merge) },
{ be_const_key(get, 36), be_const_func(m_getu) },
{ be_const_key(add, 19), be_const_func(m_add) },
{ be_const_key(setbytes, -1), be_const_func(m_setbytes) },
{ be_const_key(tobool, -1), be_const_func(m_tobool) },
{ be_const_key(addfloat, 14), be_const_func(m_addfloat) },
{ be_const_key(_X2Esize, 31), be_const_var(1) },
{ be_const_key(tob64, -1), be_const_func(m_tob64) },
{ be_const_key(_X2Elen, -1), be_const_var(2) },
{ be_const_key(_X2E_X2E, 5), be_const_func(m_connect) },
{ be_const_key(_buffer, -1), be_const_func(m_buffer) },
{ be_const_key(deinit, 12), be_const_func(m_deinit) },
{ be_const_key(set, -1), be_const_func(m_set) },
{ be_const_key(_X2E_X2E, -1), be_const_func(m_connect) },
{ be_const_key(reverse, 3), be_const_func(m_reverse) },
{ be_const_key(setitem, -1), be_const_func(m_setitem) },
{ be_const_key(asstring, -1), be_const_func(m_asstring) },
{ be_const_key(ismapped, -1), be_const_func(m_is_mapped) },
{ be_const_key(copy, 17), be_const_func(m_copy) },
{ be_const_key(fromhex, 11), be_const_func(m_fromhex) },
{ be_const_key(setitem, 2), be_const_func(m_setitem) },
{ be_const_key(item, 30), be_const_func(m_item) },
{ be_const_key(tostring, -1), be_const_func(m_tostring) },
{ be_const_key(init, -1), be_const_func(m_init) },
{ be_const_key(reverse, 13), be_const_func(m_reverse) },
{ be_const_key(tohex, -1), be_const_func(m_tohex) },
{ be_const_key(tobool, -1), be_const_func(m_tobool) },
{ be_const_key(deinit, 33), be_const_func(m_deinit) },
{ be_const_key(copy, -1), be_const_func(m_copy) },
{ be_const_key(setbits, -1), be_const_closure(setbits_closure) },
{ be_const_key(seti, 34), be_const_func(m_set) },
{ be_const_key(setbytes, -1), be_const_func(m_setbytes) },
{ be_const_key(get, -1), be_const_func(m_getu) },
{ be_const_key(fromstring, -1), be_const_func(m_fromstring) },
{ be_const_key(getfloat, -1), be_const_func(m_getfloat) },
{ be_const_key(_X21_X3D, -1), be_const_func(m_nequal) },
{ be_const_key(item, -1), be_const_func(m_item) },
{ be_const_key(clear, -1), be_const_func(m_clear) },
{ be_const_key(_X2Ep, -1), be_const_var(2) },
{ be_const_key(append, -1), be_const_func(m_connect) },
};

static be_define_const_map(
be_class_bytes_map,
37
39
);

BE_EXPORT_VARIABLE be_define_const_class(
Expand Down
18 changes: 10 additions & 8 deletions src/core/external/berry/generate/be_fixed_be_class_range.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
#include "be_constobj.h"

static be_define_const_map_slots(be_class_range_map) {
{ be_const_key(__lower__, 8), be_const_var(0) },
{ be_const_key(__incr__, -1), be_const_var(1) },
{ be_const_key(setrange, -1), be_const_func(m_setrange) },
{ be_const_key(iter, -1), be_const_func(m_iter) },
{ be_const_key(__upper__, -1), be_const_var(2) },
{ be_const_key(init, -1), be_const_func(m_init) },
{ be_const_key(tostring, 4), be_const_func(m_tostring) },
{ be_const_key(incr, -1), be_const_func(m_incr) },
{ be_const_key(upper, 6), be_const_func(m_upper) },
{ be_const_key(lower, -1), be_const_func(m_lower) },
{ be_const_key(init, 4), be_const_func(m_init) },
{ be_const_key(__upper__, -1), be_const_var(0) },
{ be_const_key(tostring, -1), be_const_func(m_tostring) },
{ be_const_key(__lower__, -1), be_const_var(1) },
{ be_const_key(upper, 1), be_const_func(m_upper) },
{ be_const_key(iter, -1), be_const_func(m_iter) },
};

static be_define_const_map(
be_class_range_map,
8
10
);

BE_EXPORT_VARIABLE be_define_const_class(
be_class_range,
2,
3,
NULL,
range
);
17 changes: 11 additions & 6 deletions src/core/external/berry/generate/be_fixed_debug.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
#include "be_constobj.h"

static be_define_const_map_slots(m_libdebug_map) {
{ be_const_key(attrdump, 3), be_const_func(m_attrdump) },
{ be_const_key(upvname, -1), be_const_func(m_upvname) },
{ be_const_key(gcdebug, -1), be_const_func(m_gcdebug) },
{ be_const_key(codedump, -1), be_const_func(m_codedump) },
{ be_const_key(counters, -1), be_const_func(m_counters) },
{ be_const_key(top, -1), be_const_func(m_top) },
{ be_const_key(varname, 7), be_const_func(m_varname) },
{ be_const_key(calldepth, -1), be_const_func(m_calldepth) },
{ be_const_key(allocs, -1), be_const_func(m_allocs) },
{ be_const_key(traceback, -1), be_const_func(m_traceback) },
{ be_const_key(calldepth, 8), be_const_func(m_calldepth) },
{ be_const_key(attrdump, 7), be_const_func(m_attrdump) },
{ be_const_key(top, -1), be_const_func(m_top) },
{ be_const_key(frees, -1), be_const_func(m_frees) },
{ be_const_key(varname, -1), be_const_func(m_varname) },
{ be_const_key(reallocs, 1), be_const_func(m_reallocs) },
{ be_const_key(counters, 9), be_const_func(m_counters) },
{ be_const_key(caller, -1), be_const_func(m_caller) },
};

static be_define_const_map(
m_libdebug_map,
8
13
);

static be_define_const_module(
Expand Down
19 changes: 10 additions & 9 deletions src/core/external/berry/generate/be_fixed_introspect.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#include "be_constobj.h"

static be_define_const_map_slots(m_libintrospect_map) {
{ be_const_key(module, 1), be_const_func(m_getmodule) },
{ be_const_key(toptr, -1), be_const_func(m_toptr) },
{ be_const_key(ismethod, -1), be_const_func(m_ismethod) },
{ be_const_key(setmodule, -1), be_const_func(m_setmodule) },
{ be_const_key(get, -1), be_const_func(m_findmember) },
{ be_const_key(fromptr, 3), be_const_func(m_fromptr) },
{ be_const_key(name, 4), be_const_func(m_name) },
{ be_const_key(members, -1), be_const_func(m_attrlist) },
{ be_const_key(ismethod, 8), be_const_func(m_ismethod) },
{ be_const_key(set, -1), be_const_func(m_setmember) },
{ be_const_key(name, 8), be_const_func(m_name) },
{ be_const_key(toptr, -1), be_const_func(m_toptr) },
{ be_const_key(members, 3), be_const_func(m_attrlist) },
{ be_const_key(get, 6), be_const_func(m_findmember) },
{ be_const_key(module, -1), be_const_func(m_getmodule) },
{ be_const_key(set, 1), be_const_func(m_setmember) },
{ be_const_key(contains, -1), be_const_func(m_contains) },
{ be_const_key(fromptr, -1), be_const_func(m_fromptr) },
};

static be_define_const_map(
m_libintrospect_map,
9
10
);

static be_define_const_module(
Expand Down
24 changes: 13 additions & 11 deletions src/core/external/berry/generate/be_fixed_string.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
#include "be_constobj.h"

static be_define_const_map_slots(m_libstring_map) {
{ be_const_key(count, 4), be_const_func(str_count) },
{ be_const_key(byte, 6), be_const_func(str_byte) },
{ be_const_key(format, 8), be_const_func(be_str_format) },
{ be_const_key(format, 12), be_const_func(be_str_format) },
{ be_const_key(byte, 3), be_const_func(str_byte) },
{ be_const_key(find, -1), be_const_func(str_find) },
{ be_const_key(char, 13), be_const_func(str_char) },
{ be_const_key(startswith, -1), be_const_func(str_startswith) },
{ be_const_key(split, -1), be_const_func(str_split) },
{ be_const_key(count, -1), be_const_func(str_count) },
{ be_const_key(tr, 5), be_const_func(str_tr) },
{ be_const_key(toupper, -1), be_const_func(str_toupper) },
{ be_const_key(char, -1), be_const_func(str_char) },
{ be_const_key(tr, -1), be_const_func(str_tr) },
{ be_const_key(replace, 1), be_const_func(str_replace) },
{ be_const_key(hex, 11), be_const_func(str_i2hex) },
{ be_const_key(tolower, 5), be_const_func(str_tolower) },
{ be_const_key(find, -1), be_const_func(str_find) },
{ be_const_key(escape, -1), be_const_func(str_escape) },
{ be_const_key(replace, -1), be_const_func(str_replace) },
{ be_const_key(escape, 2), be_const_func(str_escape) },
{ be_const_key(tolower, 1), be_const_func(str_tolower) },
{ be_const_key(hex, -1), be_const_func(str_i2hex) },
{ be_const_key(endswith, -1), be_const_func(str_endswith) },
};

static be_define_const_map(
m_libstring_map,
12
14
);

static be_define_const_module(
Expand Down
18 changes: 13 additions & 5 deletions src/core/external/berry/src/be_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,10 @@ BERRY_API bbool be_setmember(bvm *vm, int index, const char *k)
bstring *key = be_newstr(vm, k);
bmodule *mod = var_toobj(o);
return be_module_setmember(vm, mod, key, v);
} else if (var_isclass(o)) {
bstring *key = be_newstr(vm, k);
bclass *cl = var_toobj(o);
return be_class_setmember(vm, cl, key, v);
}
return bfalse;
}
Expand All @@ -661,6 +665,7 @@ BERRY_API bbool be_copy(bvm *vm, int index)
}

/* `onlyins` limits the search to instance, and discards module. Makes sure getmethod does not return anything for module. */
/* may return BE_NONE */
static int ins_member(bvm *vm, int index, const char *k, bbool onlyins)
{
int type = BE_NIL;
Expand All @@ -677,12 +682,12 @@ static int ins_member(bvm *vm, int index, const char *k, bbool onlyins)
bmodule *module = var_toobj(o);
type = be_module_attr(vm, module, be_newstr(vm, k), top);
}
return type == BE_NONE ? BE_NIL : type;
return type;
}

BERRY_API bbool be_getmember(bvm *vm, int index, const char *k)
{
return ins_member(vm, index, k, bfalse) != BE_NIL;
return ins_member(vm, index, k, bfalse) != BE_NONE;
}

BERRY_API bbool be_getmethod(bvm *vm, int index, const char *k)
Expand Down Expand Up @@ -727,10 +732,13 @@ BERRY_API bbool be_getindex(bvm *vm, int index)
static bvalue* list_setindex(blist *list, bvalue *key)
{
int idx = var_toidx(key);
if (idx < be_list_count(list)) {
return be_list_at(list, idx);
if (idx < 0) {
idx = list->count + idx;
}
return NULL;
if (idx < 0 || idx >= list->count) {
return NULL;
}
return be_list_at(list, idx);
}

BERRY_API bbool be_setindex(bvm *vm, int index)
Expand Down
35 changes: 20 additions & 15 deletions src/core/external/berry/src/be_bytecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,29 +596,34 @@ void load_global_info(bvm *vm, void *fp)
be_global_release_space(vm);
}

bclosure* be_bytecode_load_from_fs(bvm *vm, void *fp)
{
int version = load_head(fp);
if (version == BYTECODE_VERSION) {
bclosure *cl = be_newclosure(vm, 0);
var_setclosure(vm->top, cl);
be_stackpush(vm);
load_global_info(vm, fp);
load_proto(vm, fp, &cl->proto, -1, version);
be_stackpop(vm, 2); /* pop the closure and list */
be_fclose(fp);
return cl;
}
bytecode_error(vm, be_pushfstring(vm,
"invalid bytecode version."));
return NULL;
}

bclosure* be_bytecode_load(bvm *vm, const char *filename)
{
void *fp = be_fopen(filename, "rb");
if (fp == NULL) {
bytecode_error(vm, be_pushfstring(vm,
"can not open file '%s'.", filename));
} else {
int version = load_head(fp);
if (version == BYTECODE_VERSION) {
bclosure *cl = be_newclosure(vm, 0);
var_setclosure(vm->top, cl);
be_stackpush(vm);
load_global_info(vm, fp);
load_proto(vm, fp, &cl->proto, -1, version);
be_stackpop(vm, 2); /* pop the closure and list */
be_fclose(fp);
return cl;
}
bytecode_error(vm, be_pushfstring(vm,
"invalid bytecode version '%s'.", filename));
return be_bytecode_load_from_fs(vm, fp);
}
bytecode_error(vm, be_pushfstring(vm,
"invalid bytecode file '%s'.", filename));
return NULL;
}

#endif /* BE_USE_BYTECODE_LOADER */
1 change: 1 addition & 0 deletions src/core/external/berry/src/be_bytecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

void be_bytecode_save(bvm *vm, const char *filename, bproto *proto);
bclosure* be_bytecode_load(bvm *vm, const char *filename);
bclosure* be_bytecode_load_from_fs(bvm *vm, void *fp);
bbool be_bytecode_check(const char *path);

#endif
Loading

0 comments on commit da5ca97

Please sign in to comment.