Merge pull request #15412 from s-hadinger/sync_berry

Sync with latest Berry PRs
This commit is contained in:
s-hadinger 2022-04-20 23:05:04 +02:00 committed by GitHub
commit 02408df708
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 35 additions and 38 deletions

View File

@ -1502,6 +1502,8 @@ void be_load_byteslib(bvm *vm)
{ "geti", m_geti },
{ "set", m_set },
{ "seti", m_set }, // setters for signed and unsigned are identical
{ "getfloat", m_getfloat },
{ "setfloat", m_setfloat },
{ "item", m_item },
{ "setitem", m_setitem },
{ "size", m_size },

View File

@ -44,7 +44,6 @@
/* values for bproto.varg */
#define BE_VA_VARARG (1 << 0) /* function has variable number of arguments */
#define BE_VA_METHOD (1 << 1) /* function is a method (this is only a hint) */
#define array_count(a) (sizeof(a) / sizeof((a)[0]))
#define bcommon_header \

View File

@ -55,7 +55,7 @@ static int global_native_class_find(bvm *vm, bstring *name)
/* class name matches */
int idx = be_global_new(vm, name);
bvalue *v = be_global_var(vm, idx);
var_setclass(v, cl);
var_setclass(v, (void*) cl);
return idx;
}
}

View File

@ -84,6 +84,7 @@ struct bupval {
} u;
int refcnt;
};
struct bvm {
bglobaldesc gbldesc; /* global description */
bvalue *stack; /* stack space */

View File

@ -184,40 +184,9 @@ assert(b[-10..-5] == bytes("66778899AABB"))
assert(b[5..-10] == bytes("5566"))
assert(b[7..-12] == bytes())
#- floats little endian -#
#- float -#
b = bytes("00000000")
b.setfloat(0, 0)
assert(b == bytes("00000000"))
b.setfloat(0, 1)
assert(b == bytes("0000803F"))
b.setfloat(0, -1)
assert(b == bytes("000080BF"))
b.setfloat(0, 3.5)
assert(b == bytes("00006040"))
import math
b.setfloat(0, math.nan)
assert(b == bytes("0000C07F"))
assert(bytes("00000000").getfloat(0) == 0)
assert(bytes("0000803F").getfloat(0) == 1)
assert(bytes("000080BF").getfloat(0) == -1)
assert(bytes("00006040").getfloat(0) == 3.5)
#- floats big endian -#
b = bytes("00000000")
b.setfloat(0, 0, true)
assert(b == bytes("00000000"))
b.setfloat(0, 1, true)
assert(b == bytes("3F800000"))
b.setfloat(0, -1, true)
assert(b == bytes("BF800000"))
b.setfloat(0, 3.5, true)
assert(b == bytes("40600000"))
import math
b.setfloat(0, math.nan, true)
assert(b == bytes("7FC00000"))
assert(bytes("00000000").getfloat(0, true) == 0)
assert(bytes("3F800000").getfloat(0, true) == 1)
assert(bytes("BF800000").getfloat(0, true) == -1)
assert(bytes("40600000").getfloat(0, true) == 3.5)
b.setfloat(0, 0.33)
assert(b == bytes('C3F5A83E'))
b = bytes("0000C03F")
assert(b.getfloat(0) == 1.5)

View File

@ -45,3 +45,16 @@ assert(c2.C1 == C)
c3 = m.C2(m.C())
assert(type(c3.C1) == 'instance')
assert(classname(c3.C1) == 'C')
#- an instance member can be a class and called directly -#
class Test_class
var c
def init()
self.c = map
end
end
c4 = Test_class()
assert(type(c4.c) == 'class')
c5 = c4.c()
assert(type(c5) == 'instance')
assert(classname(c5) == 'map')

View File

@ -0,0 +1,8 @@
#- toint() converts any instance to int -#
class Test_int
def toint()
return 42
end
end
t=Test_int()
assert(int(t) == 42)

View File

@ -26,3 +26,8 @@ assert(introspect.get(a, 'a') == nil)
introspect.set(a, 'a', 3)
assert(a.a == 3)
#- load module dynamically -#
import introspect
m = introspect.module("math") # load module `math`, assign to `m` and don't create a global variable
assert(type(m.pi) == 'real')