Merge pull request #15913 from s-hadinger/berry_sync_upstream_220207

Berry sync with upstream
This commit is contained in:
s-hadinger 2022-07-02 16:37:32 +02:00 committed by GitHub
commit 553bc6706b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 45 additions and 45 deletions

58
lib/libesp32/berry/Makefile Normal file → Executable file
View File

@ -1,26 +1,25 @@
CFLAGS = -Wall -Wextra -std=c99 -pedantic-errors -O2 CFLAGS = -Wall -Wextra -std=c99 -pedantic-errors -O2
LIBS = -lm DEBUG_FLAGS = -O0 -g -DBE_DEBUG
TARGET = berry TEST_FLAGS = $(DEBUG_FLAGS) --coverage -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined
CC ?= gcc LIBS = -lm
MKDIR = mkdir TARGET = berry
LFLAGS = CC = gcc
MKDIR = mkdir
LFLAGS =
INCPATH = src default INCPATH = src default
SRCPATH = src default SRCPATH = src default
GENERATE = generate GENERATE = generate
CONFIG = default/berry_conf.h CONFIG = default/berry_conf.h
COC = tools/coc/coc COC = tools/coc/coc
PY = python3 CONST_TAB = $(GENERATE)/be_const_strtab.h
PYCOC = tools/coc/coc
CONST_TAB = $(GENERATE)/be_const_strtab.h
MAKE_COC = $(MAKE) -C tools/coc
ifeq ($(OS), Windows_NT) # Windows ifeq ($(OS), Windows_NT) # Windows
CFLAGS += -Wno-format # for "%I64d" warning CFLAGS += -Wno-format # for "%I64d" warning
LFLAGS += -Wl,--out-implib,berry.lib # export symbols lib for dll linked LFLAGS += -Wl,--out-implib,berry.lib # export symbols lib for dll linked
TARGET := $(TARGET).exe TARGET := $(TARGET).exe
COC := $(COC).exe PYTHON ?= python # only for windows and need python3
PY := $(PY).exe COC := $(PYTHON) $(COC)
else else
CFLAGS += -DUSE_READLINE_LIB CFLAGS += -DUSE_READLINE_LIB
LIBS += -lreadline -ldl LIBS += -lreadline -ldl
@ -33,16 +32,10 @@ endif
ifneq ($(V), 1) ifneq ($(V), 1)
Q=@ Q=@
MSG=@echo MSG=@echo
MAKE_COC += -s Q=$(Q)
else else
MSG=@true MSG=@true
endif endif
ifeq ($(TEST), 1)
CFLAGS += -fprofile-arcs -ftest-coverage
LFLAGS += -fprofile-arcs -ftest-coverage
endif
SRCS = $(foreach dir, $(SRCPATH), $(wildcard $(dir)/*.c)) SRCS = $(foreach dir, $(SRCPATH), $(wildcard $(dir)/*.c))
OBJS = $(patsubst %.c, %.o, $(SRCS)) OBJS = $(patsubst %.c, %.o, $(SRCS))
DEPS = $(patsubst %.c, %.d, $(SRCS)) DEPS = $(patsubst %.c, %.d, $(SRCS))
@ -52,11 +45,11 @@ INCFLAGS = $(foreach dir, $(INCPATH), -I"$(dir)")
all: $(TARGET) all: $(TARGET)
debug: CFLAGS += -O0 -g -DBE_DEBUG debug: CFLAGS += $(DEBUG_FLAGS)
debug: all debug: all
test: CFLAGS += --coverage test: CFLAGS += $(TEST_FLAGS)
test: LFLAGS += --coverage test: LFLAGS += $(TEST_FLAGS)
test: all test: all
$(MSG) [Run Testcases...] $(MSG) [Run Testcases...]
$(Q) ./testall.be $(Q) ./testall.be
@ -76,30 +69,25 @@ sinclude $(DEPS)
$(OBJS): $(CONST_TAB) $(OBJS): $(CONST_TAB)
$(CONST_TAB): $(COC) $(GENERATE) $(SRCS) $(CONFIG) $(CONST_TAB): $(GENERATE) $(SRCS) $(CONFIG)
$(MSG) [Prebuild] generate resources $(MSG) [Prebuild] generate resources
$(Q) $(COC) -i $(SRCPATH) -c $(CONFIG) -o $(GENERATE) $(Q) $(COC) -o $(GENERATE) $(SRCPATH) -c $(CONFIG)
$(GENERATE): $(GENERATE):
$(Q) $(MKDIR) $(GENERATE) $(Q) $(MKDIR) $(GENERATE)
$(COC):
$(MSG) [Make] coc
$(Q) $(MAKE_COC)
install: install:
cp $(TARGET) /usr/local/bin cp $(TARGET) /usr/local/bin
uninstall: uninstall:
$(RM) /usr/local/bin/$(TARGET) $(RM) /usr/local/bin/$(TARGET)
prebuild: $(COC) $(GENERATE) prebuild: $(GENERATE)
$(MSG) [Prebuild] generate resources $(MSG) [Prebuild] generate resources
$(Q) $(PY) $(PYCOC) -o $(GENERATE) $(SRCPATH) -c $(CONFIG) $(Q) $(COC) -o $(GENERATE) $(SRCPATH) -c $(CONFIG)
$(MSG) done $(MSG) done
clean: clean:
$(MSG) [Clean...] $(MSG) [Clean...]
$(Q) $(RM) $(OBJS) $(DEPS) $(GENERATE)/* berry.lib $(Q) $(RM) $(OBJS) $(DEPS) $(GENERATE)/* berry.lib
$(Q) $(MAKE_COC) clean
$(MSG) done $(MSG) done

View File

@ -23,11 +23,9 @@ Berry has the following advantages:
## Documents ## Documents
LaTeX documents repository: [https://github.com/Skiars/berry_doc](https://github.com/Skiars/berry_doc) Reference Manual: [Wiki](https://github.com/berry-lang/berry/wiki/Reference)
Short Manual: [berry_short_manual.pdf](https://github.com/Skiars/berry_doc/releases/download/latest/berry_short_manual.pdf). Short Manual (slightly outdated): [berry_short_manual.pdf](https://github.com/Skiars/berry_doc/releases/download/latest/berry_short_manual.pdf).
Reference Manual: [berry_rm_en_us.pdf](https://github.com/Skiars/berry_doc/releases/download/latest/berry_rm_en_us.pdf), [berry_rm_zh_cn.pdf](https://github.com/Skiars/berry_doc/releases/download/latest/berry_rm_zh_cn.pdf).
Berry's EBNF grammar definition: [tools/grammar/berry.ebnf](./tools/grammar/berry.ebnf) Berry's EBNF grammar definition: [tools/grammar/berry.ebnf](./tools/grammar/berry.ebnf)
@ -111,9 +109,9 @@ Berry's EBNF grammar definition: [tools/grammar/berry.ebnf](./tools/grammar/berr
make install make install
``` ```
## Editor pulgins ## Editor plugins
[Visual Studio Code](https://code.visualstudio.com/) pulgin are in this directory: [./tools/pulgins/vscode](./tools/pulgins/vscode). [Visual Studio Code](https://code.visualstudio.com/) plugin are in this directory: [./tools/plugins/vscode](./tools/plugins/vscode).
## Examples ## Examples

View File

@ -1216,7 +1216,7 @@ static int m_fromhex(bvm *vm)
from = be_toint(vm, 3); from = be_toint(vm, 3);
} }
const char *s = be_tostring(vm, 2); const char *s = be_tostring(vm, 2);
size_t s_len = strlen(s); int32_t s_len = strlen(s);
if (from < 0) { from = 0; } if (from < 0) { from = 0; }
if (from > s_len) { from = s_len; } if (from > s_len) { from = s_len; }
int32_t bin_len = (s_len - from) / 2; int32_t bin_len = (s_len - from) / 2;

View File

@ -12,6 +12,7 @@
#include "be_exec.h" #include "be_exec.h"
#include "be_map.h" #include "be_map.h"
#include "be_vm.h" #include "be_vm.h"
#include "be_strlib.h"
#define SHORT_STR_LEN 32 #define SHORT_STR_LEN 32
#define EOS '\0' /* end of source */ #define EOS '\0' /* end of source */

View File

@ -190,3 +190,15 @@ b.setfloat(0, 0.33)
assert(b == bytes('C3F5A83E')) assert(b == bytes('C3F5A83E'))
b = bytes("0000C03F") b = bytes("0000C03F")
assert(b.getfloat(0) == 1.5) assert(b.getfloat(0) == 1.5)
#- fromhex -#
b = bytes("112233")
b.fromhex("FFFEAABBCC")
assert(b == bytes("FFFEAABBCC"))
b.fromhex("")
assert(b == bytes())
#- tohex -#
b = bytes("FFFEAABBCC")
assert(b.tohex() == "FFFEAABBCC")
assert(bytes().tohex() == "")

View File

@ -64,4 +64,5 @@ assert(b1 == b2)
b2.set(0,0xAABB,2) b2.set(0,0xAABB,2)
assert(b2 == bytes("BBAA33445566")) assert(b2 == bytes("BBAA33445566"))
assert(b1 == bytes("BBAA33445566")) assert(b1 == bytes("BBAA33445566"))
assert(b1 == b2) assert(b1 == b2)
assert(b1.ismapped() == false)

View File

@ -8,11 +8,11 @@ def assert_attribute_error(f)
end end
class A class A
static a static var a
def init() self.b = 2 end def init() self.b = 2 end
def f() end def f() end
var b var b
static c, s, r static var c, s, r
end end
assert(A.a == nil) assert(A.a == nil)