Sync with Berry upstream (#19119)

This commit is contained in:
s-hadinger 2023-07-15 18:11:04 +02:00 committed by GitHub
parent ada754c582
commit af27d65a8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 75 additions and 1 deletions

View File

@ -1038,7 +1038,9 @@ BERRY_API int be_pcall(bvm *vm, int argc)
return be_protectedcall(vm, f, argc);
}
#ifdef __GNUC__
__attribute__((noreturn))
#endif
BERRY_API void be_raise(bvm *vm, const char *except, const char *msg)
{
be_pushstring(vm, except);

View File

@ -2065,7 +2065,9 @@ BERRY_API void be_exit(bvm *vm, int status);
* @param except
* @param msg
*/
#ifdef __GNUC__
__attribute__((noreturn))
#endif
BERRY_API void be_raise(bvm *vm, const char *except, const char *msg);
/**

View File

@ -140,5 +140,18 @@ assert(classname(a) == 'A')
assert(classname(b) == 'B')
assert(A.B.f() == 1)
assert(b.g() == 2)
assert(super(b) == nil)
assert(super(A.B) == nil)
#- `_class` initializer can now be used in initializer code -#
class A
static var a = 1
static var b = _class
static var c = [_class.a, _class.b]
static def f(x)
return _class
end
end
assert(A.a == 1)
assert(A.b == A)
assert(A.c == [1, A])
assert(A.f(1) == A)

View File

@ -147,3 +147,25 @@ assert(string.format("%s", nil) == 'nil')
assert(string.format("%s", true) == 'true')
assert(string.format("%s", false) == 'false')
# format is now synonym to string.format
assert(format == string.format)
assert(format("%.1f", 3) == '3.0')
# f-strings
assert(f"" == '')
assert(f'' == '')
assert(f"abc\n\r\t" == 'abc\n\r\t')
assert(f'{{a}}' == '{a}')
assert(f'\\\\' == '\\\\')
assert(f"A = {1+1}" == 'A = 2')
assert(f"A = {1+1:s}" == 'A = 2')
assert(f"A = {1+1:i}" == 'A = 2')
assert(f"A = {1+1:04i}" == 'A = 0002')
assert(f"P = {3.1415:.2f}" == 'P = 3.14')
var a = 'foobar{0}'
assert(f"S = {a}" == 'S = foobar{0}')
assert(f"S = {a:i}" == 'S = 0')
assert(f"{a=}" == 'a=foobar{0}')

View File

@ -0,0 +1,35 @@
# test for the walrus operator
var a = 1
assert((a := a + 1) == 2)
assert((a := a + 1) == 3)
def f()
var defer = 10
var ret = []
for i:0..100
if (defer := defer - 1) == 0
ret.push(i)
defer = 10
end
end
return ret
end
assert(f() == [9, 19, 29, 39, 49, 59, 69, 79, 89, 99])
# test for expressions with no side effects
def assert_attribute_error(c)
try
compile(c)()
assert(false, 'unexpected execution flow')
except 'syntax_error' as e, m
end
end
# below the expressions `a` or `a b` have no side effect and do not generate any code, this is an error when in strict mode
import strict
var a, b
assert_attribute_error("var a,b def f() a b end")
assert_attribute_error("var a,b def f() a end")
# while the following does have side effect
def f() a := b end