mirror of
https://github.com/arendst/Tasmota.git
synced 2025-04-25 07:17:16 +00:00
Merge pull request #15412 from s-hadinger/sync_berry
Sync with latest Berry PRs
This commit is contained in:
commit
02408df708
@ -1502,6 +1502,8 @@ void be_load_byteslib(bvm *vm)
|
|||||||
{ "geti", m_geti },
|
{ "geti", m_geti },
|
||||||
{ "set", m_set },
|
{ "set", m_set },
|
||||||
{ "seti", m_set }, // setters for signed and unsigned are identical
|
{ "seti", m_set }, // setters for signed and unsigned are identical
|
||||||
|
{ "getfloat", m_getfloat },
|
||||||
|
{ "setfloat", m_setfloat },
|
||||||
{ "item", m_item },
|
{ "item", m_item },
|
||||||
{ "setitem", m_setitem },
|
{ "setitem", m_setitem },
|
||||||
{ "size", m_size },
|
{ "size", m_size },
|
||||||
|
@ -44,7 +44,6 @@
|
|||||||
/* values for bproto.varg */
|
/* values for bproto.varg */
|
||||||
#define BE_VA_VARARG (1 << 0) /* function has variable number of arguments */
|
#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 BE_VA_METHOD (1 << 1) /* function is a method (this is only a hint) */
|
||||||
|
|
||||||
#define array_count(a) (sizeof(a) / sizeof((a)[0]))
|
#define array_count(a) (sizeof(a) / sizeof((a)[0]))
|
||||||
|
|
||||||
#define bcommon_header \
|
#define bcommon_header \
|
||||||
|
@ -55,7 +55,7 @@ static int global_native_class_find(bvm *vm, bstring *name)
|
|||||||
/* class name matches */
|
/* class name matches */
|
||||||
int idx = be_global_new(vm, name);
|
int idx = be_global_new(vm, name);
|
||||||
bvalue *v = be_global_var(vm, idx);
|
bvalue *v = be_global_var(vm, idx);
|
||||||
var_setclass(v, cl);
|
var_setclass(v, (void*) cl);
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,7 @@ struct bupval {
|
|||||||
} u;
|
} u;
|
||||||
int refcnt;
|
int refcnt;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct bvm {
|
struct bvm {
|
||||||
bglobaldesc gbldesc; /* global description */
|
bglobaldesc gbldesc; /* global description */
|
||||||
bvalue *stack; /* stack space */
|
bvalue *stack; /* stack space */
|
||||||
|
@ -184,40 +184,9 @@ assert(b[-10..-5] == bytes("66778899AABB"))
|
|||||||
assert(b[5..-10] == bytes("5566"))
|
assert(b[5..-10] == bytes("5566"))
|
||||||
assert(b[7..-12] == bytes())
|
assert(b[7..-12] == bytes())
|
||||||
|
|
||||||
#- floats little endian -#
|
#- float -#
|
||||||
b = bytes("00000000")
|
b = bytes("00000000")
|
||||||
b.setfloat(0, 0)
|
b.setfloat(0, 0.33)
|
||||||
assert(b == bytes("00000000"))
|
assert(b == bytes('C3F5A83E'))
|
||||||
b.setfloat(0, 1)
|
b = bytes("0000C03F")
|
||||||
assert(b == bytes("0000803F"))
|
assert(b.getfloat(0) == 1.5)
|
||||||
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)
|
|
||||||
|
@ -45,3 +45,16 @@ assert(c2.C1 == C)
|
|||||||
c3 = m.C2(m.C())
|
c3 = m.C2(m.C())
|
||||||
assert(type(c3.C1) == 'instance')
|
assert(type(c3.C1) == 'instance')
|
||||||
assert(classname(c3.C1) == 'C')
|
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')
|
8
lib/libesp32/berry/tests/int.be
Normal file
8
lib/libesp32/berry/tests/int.be
Normal 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)
|
@ -26,3 +26,8 @@ assert(introspect.get(a, 'a') == nil)
|
|||||||
|
|
||||||
introspect.set(a, 'a', 3)
|
introspect.set(a, 'a', 3)
|
||||||
assert(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')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user