Skip to content
Draft
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
27 changes: 27 additions & 0 deletions interpreters/berry/0001-Fix-Berry-default-port-for-NuttX.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
diff --git a/default/berry.c b/default/berry.c
index d6ea5d1..bb95fc7 100644
--- a/default/berry.c
+++ b/default/berry.c
@@ -22 +22,3 @@
-#if defined(__linux)
+#if defined(__NuttX__)
+ #define OS_NAME "NuttX"
+#elif defined(__linux)
@@ -103 +105 @@
- const char *optarg;
+ const char *optvalue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ALL change is general, so it's better to upstream to Berry community.

@@ -148 +150 @@
- opt->optarg = argv[opt->idx++]; /* save the argument */
+ opt->optvalue = argv[opt->idx++]; /* save the argument */
@@ -151 +153 @@
- opt->optarg = NULL;
+ opt->optvalue = NULL;
@@ -272 +274 @@
- opt->modulepath = opt->optarg;
+ opt->modulepath = opt->optvalue;
@@ -277 +279 @@
- opt->src = opt->optarg;
+ opt->src = opt->optvalue;
@@ -281 +283 @@
- opt->dst = opt->optarg;
+ opt->dst = opt->optvalue;
145 changes: 145 additions & 0 deletions interpreters/berry/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# ##############################################################################
# apps/interpreters/berry/CMakeLists.txt
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################

if(CONFIG_INTERPRETERS_BERRY)
set(BERRY_COMMIT_ID 4db341475df9e9ad18e6741ef978b4c467690e09)
set(BERRY_DIR ${CMAKE_CURRENT_LIST_DIR}/berry)

if(NOT EXISTS ${BERRY_DIR})
set(BERRY_URL_BASE https://github.com/Skiars/berry/archive/)

FetchContent_Declare(
berry_fetch
URL ${BERRY_URL_BASE}/${BERRY_COMMIT_ID}.zip SOURCE_DIR
${CMAKE_CURRENT_LIST_DIR}/berry BINARY_DIR
${CMAKE_BINARY_DIR}/apps/interpreters/berry/berry
PATCH_COMMAND
patch -l -p1 -d ${CMAKE_CURRENT_LIST_DIR}/berry -i
${CMAKE_CURRENT_LIST_DIR}/0001-Fix-Berry-default-port-for-NuttX.patch
DOWNLOAD_NO_PROGRESS true
TIMEOUT 30)

FetchContent_GetProperties(berry_fetch)

if(NOT berry_fetch_POPULATED)
FetchContent_Populate(berry_fetch)
endif()
endif()

find_package(Python3 COMPONENTS Interpreter REQUIRED)

set(BERRY_CONFIG_DIR ${CMAKE_CURRENT_LIST_DIR}/include)
set(BERRY_CONFIG ${BERRY_CONFIG_DIR}/berry_conf.h)
set(BERRY_GENERATE ${BERRY_DIR}/generate)
set(BERRY_GEN_STAMP ${BERRY_GENERATE}/.generated)
set(BERRY_FLAGS -Wno-unused-but-set-variable)
set(BERRY_INCDIR ${BERRY_CONFIG_DIR} ${BERRY_DIR}/src ${BERRY_DIR}/default)

set(BERRY_CSRCS
${BERRY_DIR}/src/be_api.c
${BERRY_DIR}/src/be_baselib.c
${BERRY_DIR}/src/be_bytecode.c
${BERRY_DIR}/src/be_byteslib.c
${BERRY_DIR}/src/be_class.c
${BERRY_DIR}/src/be_code.c
${BERRY_DIR}/src/be_debug.c
${BERRY_DIR}/src/be_debuglib.c
${BERRY_DIR}/src/be_exec.c
${BERRY_DIR}/src/be_filelib.c
${BERRY_DIR}/src/be_func.c
${BERRY_DIR}/src/be_gc.c
${BERRY_DIR}/src/be_gclib.c
${BERRY_DIR}/src/be_globallib.c
${BERRY_DIR}/src/be_introspectlib.c
${BERRY_DIR}/src/be_jsonlib.c
${BERRY_DIR}/src/be_lexer.c
${BERRY_DIR}/src/be_libs.c
${BERRY_DIR}/src/be_list.c
${BERRY_DIR}/src/be_listlib.c
${BERRY_DIR}/src/be_map.c
${BERRY_DIR}/src/be_maplib.c
${BERRY_DIR}/src/be_mathlib.c
${BERRY_DIR}/src/be_mem.c
${BERRY_DIR}/src/be_module.c
${BERRY_DIR}/src/be_object.c
${BERRY_DIR}/src/be_oslib.c
${BERRY_DIR}/src/be_parser.c
${BERRY_DIR}/src/be_rangelib.c
${BERRY_DIR}/src/be_repl.c
${BERRY_DIR}/src/be_solidifylib.c
${BERRY_DIR}/src/be_strictlib.c
${BERRY_DIR}/src/be_string.c
${BERRY_DIR}/src/be_strlib.c
${BERRY_DIR}/src/be_syslib.c
${BERRY_DIR}/src/be_timelib.c
${BERRY_DIR}/src/be_undefinedlib.c
${BERRY_DIR}/src/be_var.c
${BERRY_DIR}/src/be_vector.c
${BERRY_DIR}/src/be_vm.c
${BERRY_DIR}/default/be_modtab.c
${BERRY_DIR}/default/be_port.c)

add_custom_command(
OUTPUT ${BERRY_GEN_STAMP}
COMMAND ${CMAKE_COMMAND} -E make_directory ${BERRY_GENERATE}
COMMAND
${Python3_EXECUTABLE} ${BERRY_DIR}/tools/coc/coc -o ${BERRY_GENERATE}
${BERRY_DIR}/src ${BERRY_DIR}/default -c ${BERRY_CONFIG}
COMMAND ${CMAKE_COMMAND} -E touch ${BERRY_GEN_STAMP}
DEPENDS ${BERRY_CSRCS} ${BERRY_CONFIG}
WORKING_DIRECTORY ${BERRY_DIR}
COMMENT "Generating Berry constant objects")

add_custom_target(berry_coc DEPENDS ${BERRY_GEN_STAMP})

nuttx_add_library(libberry)
target_sources(libberry PRIVATE ${BERRY_CSRCS})
target_include_directories(libberry PRIVATE ${BERRY_INCDIR})
target_compile_options(libberry PRIVATE ${BERRY_FLAGS})
add_dependencies(libberry berry_coc)
nuttx_export_header(TARGET libberry INCLUDE_DIRECTORIES ${BERRY_DIR}/src)

set_property(
TARGET nuttx
APPEND
PROPERTY NUTTX_INCLUDE_DIRECTORIES ${BERRY_DIR}/src)

nuttx_add_application(
MODULE
${CONFIG_INTERPRETERS_BERRY}
NAME
${CONFIG_INTERPRETERS_BERRY_PROGNAME}
STACKSIZE
${CONFIG_INTERPRETERS_BERRY_STACKSIZE}
PRIORITY
${CONFIG_INTERPRETERS_BERRY_PRIORITY}
SRCS
${BERRY_DIR}/default/berry.c
INCLUDE_DIRECTORIES
${BERRY_INCDIR}
COMPILE_FLAGS
${BERRY_FLAGS}
DEPENDS
libberry
berry_coc)

endif()
43 changes: 43 additions & 0 deletions interpreters/berry/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#

config INTERPRETERS_BERRY
tristate "Berry scripting language"
default n
depends on ARCH_SETJMP_H
depends on LIBC_FLOATINGPOINT
depends on SYSTEM_SYSTEM
---help---
Enable the Berry embedded scripting language as an NSH built-in
command. Berry provides a small ANSI C99 compiler, register-based
virtual machine, garbage collector, file I/O, bytecode loading and
saving, and built-in modules.

The default NuttX configuration keeps Berry shared-library loading
disabled so boards do not need CONFIG_LIBC_DLFCN. The math module
is enabled, so select a NuttX math library or provide one from the
toolchain.

if INTERPRETERS_BERRY

config INTERPRETERS_BERRY_PROGNAME
string "Berry program name"
default "berry"
---help---
The command name used to start the Berry interpreter.

config INTERPRETERS_BERRY_PRIORITY
int "Berry interpreter priority"
default 100
---help---
Task priority of the Berry interpreter main task.

config INTERPRETERS_BERRY_STACKSIZE
int "Berry interpreter stack size"
default 12288
---help---
Size of the stack allocated for the Berry interpreter main task.

endif # INTERPRETERS_BERRY
25 changes: 25 additions & 0 deletions interpreters/berry/Make.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
############################################################################
# apps/interpreters/berry/Make.defs
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

ifneq ($(CONFIG_INTERPRETERS_BERRY),)
CONFIGURED_APPS += $(APPDIR)/interpreters/berry
endif
97 changes: 97 additions & 0 deletions interpreters/berry/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
############################################################################
# apps/interpreters/berry/Makefile
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

include $(APPDIR)/Make.defs

BERRY_COMMIT_ID = 4db341475df9e9ad18e6741ef978b4c467690e09
BERRY_UNPACK = berry
BERRY_ARCHIVE = berry-$(BERRY_COMMIT_ID).zip
BERRY_URL_BASE = https://github.com/Skiars/berry/archive/
BERRY_URL = $(BERRY_URL_BASE)/$(BERRY_COMMIT_ID).zip
BERRY_CONFIG = include$(DELIM)berry_conf.h
BERRY_COC = $(BERRY_UNPACK)$(DELIM)tools$(DELIM)coc$(DELIM)coc
BERRY_GENERATE = $(BERRY_UNPACK)$(DELIM)generate
BERRY_GEN_STAMP = $(BERRY_GENERATE)$(DELIM).generated

BERRY_SRCS = be_api.c be_baselib.c be_bytecode.c be_byteslib.c
BERRY_SRCS += be_class.c be_code.c be_debug.c be_debuglib.c be_exec.c
BERRY_SRCS += be_filelib.c be_func.c be_gc.c be_gclib.c be_globallib.c
BERRY_SRCS += be_introspectlib.c be_jsonlib.c be_lexer.c be_libs.c
BERRY_SRCS += be_list.c be_listlib.c be_map.c be_maplib.c be_mathlib.c
BERRY_SRCS += be_mem.c be_module.c be_object.c be_oslib.c be_parser.c
BERRY_SRCS += be_rangelib.c be_repl.c be_solidifylib.c be_strictlib.c
BERRY_SRCS += be_string.c be_strlib.c be_syslib.c be_timelib.c
BERRY_SRCS += be_undefinedlib.c be_var.c be_vector.c be_vm.c

CSRCS = $(BERRY_SRCS)
CSRCS += be_modtab.c be_port.c

MAINSRC = berry.c

VPATH += $(BERRY_UNPACK)$(DELIM)src
VPATH += $(BERRY_UNPACK)$(DELIM)default
DEPPATH += --dep-path $(BERRY_UNPACK)$(DELIM)src
DEPPATH += --dep-path $(BERRY_UNPACK)$(DELIM)default

CFLAGS += ${INCDIR_PREFIX}$(APPDIR)$(DELIM)interpreters$(DELIM)berry$(DELIM)include
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)$(DELIM)interpreters$(DELIM)berry$(DELIM)$(BERRY_UNPACK)$(DELIM)src
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)$(DELIM)interpreters$(DELIM)berry$(DELIM)$(BERRY_UNPACK)$(DELIM)default
CFLAGS += -Wno-unused-but-set-variable

PROGNAME = $(CONFIG_INTERPRETERS_BERRY_PROGNAME)
PRIORITY = $(CONFIG_INTERPRETERS_BERRY_PRIORITY)
STACKSIZE = $(CONFIG_INTERPRETERS_BERRY_STACKSIZE)
MODULE = $(CONFIG_INTERPRETERS_BERRY)

$(BERRY_ARCHIVE):
$(Q) echo "Downloading $(BERRY_ARCHIVE)"
$(Q) curl -L $(BERRY_URL) -o $(BERRY_ARCHIVE)

$(BERRY_UNPACK): $(BERRY_ARCHIVE)
$(Q) echo "Unpacking $(BERRY_ARCHIVE) to $(BERRY_UNPACK)"
$(Q) unzip -q -o $(BERRY_ARCHIVE)
$(call DELDIR, $(BERRY_UNPACK))
$(Q) mv berry-$(BERRY_COMMIT_ID) $(BERRY_UNPACK)
$(Q) patch -l -d $(BERRY_UNPACK) -p1 < 0001-Fix-Berry-default-port-for-NuttX.patch

$(BERRY_GEN_STAMP): $(BERRY_UNPACK) $(BERRY_CONFIG)
$(Q) echo "Generating Berry constant objects"
$(Q) mkdir -p $(BERRY_GENERATE)
$(Q) python3 $(BERRY_COC) -o $(BERRY_GENERATE) \
$(BERRY_UNPACK)$(DELIM)src \
$(BERRY_UNPACK)$(DELIM)default \
-c $(BERRY_CONFIG)
$(Q) touch $(BERRY_GEN_STAMP)

ifeq ($(wildcard $(BERRY_UNPACK)/.git),)
context:: $(BERRY_GEN_STAMP)
endif

depend:: $(BERRY_GEN_STAMP)

distclean::
ifeq ($(wildcard $(BERRY_UNPACK)/.git),)
$(call DELDIR, $(BERRY_UNPACK))
$(call DELFILE, $(BERRY_ARCHIVE))
endif

include $(APPDIR)/Application.mk
Loading
Loading