Berry sync with upstream

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

View File

@ -23,11 +23,9 @@ Berry has the following advantages:
## 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).
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).
Short Manual (slightly outdated): [berry_short_manual.pdf](https://github.com/Skiars/berry_doc/releases/download/latest/berry_short_manual.pdf).
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
```
## 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

View File

@ -1216,7 +1216,7 @@ static int m_fromhex(bvm *vm)
from = be_toint(vm, 3);
}
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 > s_len) { from = s_len; }
int32_t bin_len = (s_len - from) / 2;

View File

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

View File

@ -190,3 +190,15 @@ b.setfloat(0, 0.33)
assert(b == bytes('C3F5A83E'))
b = bytes("0000C03F")
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)
assert(b2 == 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
class A
static a
static var a
def init() self.b = 2 end
def f() end
var b
static c, s, r
static var c, s, r
end
assert(A.a == nil)