Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with Berry upstream #19119

Merged
merged 1 commit into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/libesp32/berry/src/be_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions lib/libesp32/berry/src/berry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
Expand Down
15 changes: 14 additions & 1 deletion lib/libesp32/berry/tests/class_static.be
Original file line number Diff line number Diff line change
Expand Up @@ -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)
22 changes: 22 additions & 0 deletions lib/libesp32/berry/tests/string.be
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
35 changes: 35 additions & 0 deletions lib/libesp32/berry/tests/walrus.be
Original file line number Diff line number Diff line change
@@ -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