Skip to content

Commit f0dd1e3

Browse files
committed
python language support
1 parent 70a9f9e commit f0dd1e3

File tree

26 files changed

+348
-1713
lines changed

26 files changed

+348
-1713
lines changed

ejs/evm_main.c bsp/common/evm_main.c

+43-6
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,20 @@
1313
****************************************************************************/
1414

1515
#include "evm_main.h"
16-
#include "ecma.h"
1716
#include "uol_output.h"
18-
#include <drivers/gpio.h>
17+
18+
#ifdef CONFIG_EVM_LANG_JS
19+
#include "ecma.h"
20+
#endif
21+
22+
#ifdef CONFIG_EVM_LANG_QML
23+
#include "ecma.h"
24+
#include "qml_lvgl_module.h"
25+
#endif
26+
27+
#ifdef CONFIG_EVM_LANG_PY
28+
#include "python_builtins.h"
29+
#endif
1930

2031
evm_t * nevm_runtime;
2132

@@ -95,16 +106,42 @@ int evm_main(void){
95106
evm_print("Failed to initialize evm\r\n");
96107
return err;
97108
}
109+
err = evm_module(env);
110+
if( err ) {
111+
evm_print("Failed to add evm module\r\n");
112+
return err;
113+
}
114+
#ifdef CONFIG_EVM_LANG_JS
98115
err = ecma_module(env);
99116
if( err ) {
100117
evm_print("Failed to add ecma module\r\n");
101118
}
102-
err = evm_module(env);
119+
err = evm_repl_run(env, 20, EVM_LANG_JS);
120+
return err;
121+
#endif
122+
123+
#ifdef CONFIG_EVM_LANG_QML
124+
err = qml_lvgl_module(env);
103125
if( err ) {
104-
evm_print("Failed to add evm module\r\n");
105-
return err;
126+
evm_print("Failed to add qml module\r\n");
106127
}
107128

108-
err = evm_repl_run(env, 20, EVM_LANG_JS);
129+
evm_boot(env, "main.qml");
130+
131+
evm_start(env);
132+
133+
while(1){
134+
lv_task_handler();
135+
k_msleep(10);
136+
}
137+
#endif
138+
139+
#ifdef CONFIG_EVM_LANG_PY
140+
python_builtins(env);
141+
if( err ) {
142+
evm_print("Failed to add python builtins module\r\n");
143+
}
144+
err = evm_repl_run(env, 20, EVM_LANG_PY);
109145
return err;
146+
#endif
110147
}
File renamed without changes.
File renamed without changes.

bsp/ejs/qemu_cortex_m3/ejs/CMakeLists.txt bsp/ejs/qemu_cortex_m3/CMakeLists.txt

+7-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if (EXISTS ${EVM_DEV})
1414
find_package(ejs)
1515
target_link_libraries(app PRIVATE eqml)
1616
else()
17-
set(LIBEJS ${EVM_BASE}/lib/arm-none-eabi-gcc/cortex-m3/libeqml.a)
17+
set(LIBEJS ${EVM_BASE}/lib/arm-none-eabi-gcc/cortex-m3/libejs.a)
1818
message(${LIBEJS})
1919
target_link_libraries(app PRIVATE ${LIBEJS})
2020
endif()
@@ -76,14 +76,14 @@ add_definitions("-DQMAKE_VERSION=\"1.0\"")
7676
remove_definitions("-DWall")
7777

7878
include_directories(app PRIVATE ${EVM_BASE}/include)
79-
include_directories(app PRIVATE ${EVM_BASE}/ejs)
79+
include_directories(app PRIVATE ${EVM_BASE}/bsp/common)
8080
include_directories(app PRIVATE ${EVM_BASE}/modules/ecma)
8181
include_directories(app PRIVATE src)
8282

8383
target_sources(app PRIVATE ${libevm_module_sources})
8484
target_sources(app PRIVATE src/main.c)
85-
target_sources(app PRIVATE ${EVM_BASE}/ejs/evm_main.c)
86-
target_sources(app PRIVATE ${EVM_BASE}/ejs/uol_output.c)
85+
target_sources(app PRIVATE ${EVM_BASE}/bsp/common/evm_main.c)
86+
target_sources(app PRIVATE ${EVM_BASE}/bsp/common/uol_output.c)
8787

8888
# ecma module config
8989
add_definitions("-DCONFIG_EVM_ECMA_OBJECT")
@@ -92,3 +92,6 @@ add_definitions("-DCONFIG_EVM_ECMA_REGEXP")
9292
add_definitions("-DCONFIG_EVM_ECMA_MATH")
9393
add_definitions("-DCONFIG_EVM_ECMA_NUMBER")
9494
add_definitions("-DCONFIG_EVM_ECMA_STRING")
95+
96+
# language config
97+
add_definitions("-DCONFIG_EVM_LANG_JS")
File renamed without changes.
File renamed without changes.

bsp/ejs/stm32/bearpi_stm32l431/CMakeLists.txt

+9-13
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,9 @@ project(ejs)
1414
set(EVM_BASE ${ZEPHYR_BASE}/../../../)
1515

1616

17-
if (EXISTS ${EVM_DEV})
18-
message(${EVM_DEV})
19-
set(CMAKE_MODULE_PATH ${EVM_DEV})
20-
find_package(ejs)
21-
target_link_libraries(app PRIVATE ejs)
22-
else()
23-
set(LIBEJS ${EVM_BASE}/lib/arm-none-eabi-gcc/cortex-m4/libejs.a)
24-
message(${LIBEJS})
25-
target_link_libraries(app PRIVATE ${LIBEJS})
26-
endif()
17+
set(LIBEJS ${EVM_BASE}/lib/arm-none-eabi-gcc/cortex-m4/libejs.a)
18+
message(${LIBEJS})
19+
target_link_libraries(app PRIVATE ${LIBEJS})
2720

2821
set(evm_ecma_sources
2922
${EVM_BASE}/modules/ecma/ecma.c
@@ -82,16 +75,16 @@ add_definitions("-DQMAKE_VERSION=\"1.0\"")
8275
remove_definitions("-DWall")
8376

8477
include_directories(app PRIVATE ${EVM_BASE}/include)
85-
include_directories(app PRIVATE ${EVM_BASE}/ejs)
78+
include_directories(app PRIVATE ${EVM_BASE}/bsp/common)
8679
include_directories(app PRIVATE ${EVM_BASE}/modules/ecma)
8780
include_directories(app PRIVATE ${EVM_BASE}/modules/evm)
8881
include_directories(app PRIVATE src)
8982

9083
target_sources(app PRIVATE ${libevm_module_sources})
9184
target_sources(app PRIVATE src/main.c)
92-
target_sources(app PRIVATE ${EVM_BASE}/ejs/evm_main.c)
9385
target_sources(app PRIVATE src/evm_board.c)
94-
target_sources(app PRIVATE ${EVM_BASE}/ejs/uol_output.c)
86+
target_sources(app PRIVATE ${EVM_BASE}/bsp/common/evm_main.c)
87+
target_sources(app PRIVATE ${EVM_BASE}/bsp/common/uol_output.c)
9588

9689
# evm module config
9790
add_definitions("-DCONFIG_EVM_GPIO")
@@ -109,3 +102,6 @@ add_definitions("-DCONFIG_EVM_WIFI")
109102
# ecma module config
110103
add_definitions("-DCONFIG_EVM_ECMA_OBJECT")
111104
add_definitions("-DCONFIG_EVM_ECMA_ARRAY")
105+
106+
# language config
107+
add_definitions("-DCONFIG_EVM_LANG_JS")

bsp/epy/qemu_cortex_m3/CMakeLists.txt

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.13.1)
4+
5+
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
6+
project(eqml)
7+
8+
set(EVM_BASE ${ZEPHYR_BASE}/../../../)
9+
10+
11+
set(LIBEPY ${EVM_BASE}/lib/arm-none-eabi-gcc/cortex-m3/libepy.a)
12+
message(${LIBEPY})
13+
target_link_libraries(app PRIVATE ${LIBEPY})
14+
15+
set(evm_python_builtins_sources
16+
${EVM_BASE}/modules/python_builtins/python_builtins.c
17+
)
18+
19+
set(evm_driver_sources
20+
${EVM_BASE}/drivers/zephyr/uol/adc_driver.c
21+
${EVM_BASE}/drivers/zephyr/uol/can_driver.c
22+
${EVM_BASE}/drivers/zephyr/uol/dac_driver.c
23+
${EVM_BASE}/drivers/zephyr/uol/flash_driver.c
24+
${EVM_BASE}/drivers/zephyr/uol/gpio_driver.c
25+
${EVM_BASE}/drivers/zephyr/uol/i2c_driver.c
26+
${EVM_BASE}/drivers/zephyr/uol/rtc_driver.c
27+
${EVM_BASE}/drivers/zephyr/uol/spi_driver.c
28+
${EVM_BASE}/drivers/zephyr/uol/timer_driver.c
29+
${EVM_BASE}/drivers/zephyr/uol/uart_driver.c
30+
${EVM_BASE}/drivers/zephyr/uol/watchdog_driver.c
31+
${EVM_BASE}/drivers/zephyr/uol/pwm_driver.c
32+
${EVM_BASE}/drivers/zephyr/uol/sys_driver.c
33+
)
34+
35+
set(evm_modules_sources
36+
${EVM_BASE}/modules/evm/evm_module.c
37+
${EVM_BASE}/modules/evm/evm_module_adc.c
38+
${EVM_BASE}/modules/evm/evm_module_can.c
39+
${EVM_BASE}/modules/evm/evm_module_dac.c
40+
${EVM_BASE}/modules/evm/evm_module_flash.c
41+
${EVM_BASE}/modules/evm/evm_module_i2c.c
42+
${EVM_BASE}/modules/evm/evm_module_lcd.c
43+
${EVM_BASE}/modules/evm/evm_module_led.c
44+
${EVM_BASE}/modules/evm/evm_module_pin.c
45+
${EVM_BASE}/modules/evm/evm_module_rtc.c
46+
${EVM_BASE}/modules/evm/evm_module_spi.c
47+
${EVM_BASE}/modules/evm/evm_module_switch.c
48+
${EVM_BASE}/modules/evm/evm_module_timer.c
49+
${EVM_BASE}/modules/evm/evm_module_uart.c
50+
${EVM_BASE}/modules/evm/evm_module_watchdog.c
51+
${EVM_BASE}/modules/evm/evm_module_led.c
52+
)
53+
54+
set(libevm_module_sources
55+
${evm_driver_sources}
56+
${evm_modules_sources}
57+
${evm_python_builtins_sources}
58+
)
59+
60+
include_directories(app PRIVATE ${EVM_BASE}/include)
61+
include_directories(app PRIVATE ${EVM_BASE}/bsp/common)
62+
include_directories(app PRIVATE ${EVM_BASE}/modules/python_builtins)
63+
include_directories(app PRIVATE src)
64+
65+
target_sources(app PRIVATE ${libevm_module_sources})
66+
target_sources(app PRIVATE src/main.c)
67+
target_sources(app PRIVATE ${EVM_BASE}/bsp/common/evm_main.c)
68+
target_sources(app PRIVATE ${EVM_BASE}/bsp/common/uol_output.c)
69+
70+
# language config
71+
add_definitions("-DCONFIG_EVM_LANG_PY")

bsp/epy/qemu_cortex_m3/prj.conf

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# nothing here
2+
CONFIG_NEWLIB_LIBC=y
3+
CONFIG_STDOUT_CONSOLE=y
4+
CONFIG_CONSOLE_SUBSYS=y
5+
CONFIG_CONSOLE_GETCHAR=y
6+
CONFIG_STDOUT_CONSOLE=y
7+
CONFIG_PRINTK=y
8+
CONFIG_MAIN_STACK_SIZE=4096
9+
# CONFIG_GPIO=y
10+
# CONFIG_FLASH=y
11+
# CONFIG_DISPLAY=y
12+
# CONFIG_SPI=y
13+
# CONFIG_ST7789V=y
14+
# CONFIG_LOG=y
15+
# CONFIG_SPI_LOG_LEVEL_ERR=y
16+
# CONFIG_ADC=y
17+
# CONFIG_ADC_STM32=y
18+
19+
# CONFIG_DAC=y
20+
# CONFIG_DAC_STM32=y
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/****************************************************************************
2+
**
3+
** Copyright (C) 2020 @scriptiot
4+
**
5+
** EVM是一款通用化设计的虚拟机引擎,拥有语法解析前端接口、编译器、虚拟机和虚拟机扩展接口框架。
6+
** 支持js、python、qml、lua等多种脚本语言,纯C开发,零依赖,内置REPL,支持主流 ROM > 40KB, RAM > 2KB的MCU;
7+
** 自带垃圾回收(GC)先进的内存管理,采用最复杂的压缩算法,无内存碎片(大部分解释器都存在内存碎片)
8+
** Version : 1.0
9+
10+
** Website : https://github.com/scriptiot/evm
11+
** https://gitee.com/scriptiot/evm
12+
** Licence: Apache-2.0
13+
****************************************************************************/
14+
15+
#ifndef EVM_BOARD_H
16+
#define EVM_BOARD_H
17+
18+
#define CONFIG_EVM_CALLBACK_SIZE 10
19+
20+
#endif

bsp/epy/qemu_cortex_m3/src/main.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/****************************************************************************
2+
**
3+
** Copyright (C) 2020 @scriptiot
4+
**
5+
** EVM是一款通用化设计的虚拟机引擎,拥有语法解析前端接口、编译器、虚拟机和虚拟机扩展接口框架。
6+
** 支持js、python、qml、lua等多种脚本语言,纯C开发,零依赖,内置REPL,支持主流 ROM > 40KB, RAM > 2KB的MCU;
7+
** 自带垃圾回收(GC)先进的内存管理,采用最复杂的压缩算法,无内存碎片(大部分解释器都存在内存碎片)
8+
** Version : 1.0
9+
10+
** Website : https://github.com/scriptiot/evm
11+
** https://gitee.com/scriptiot/evm
12+
** Licence: Apache-2.0
13+
****************************************************************************/
14+
15+
#include "evm_main.h"
16+
17+
void main(void)
18+
{
19+
evm_main();
20+
}

bsp/eqml/stm32/stm32f103-fire-arbitrary/CMakeLists.txt

+9-13
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,9 @@ set(EVM_BASE ${ZEPHYR_BASE}/../../../)
1313

1414
set(STM32_HAL_BASE ${EVM_BASE}/components/zephyr-rtos/modules/hal/stm32/stm32cube/)
1515

16-
if (EXISTS ${EVM_DEV})
17-
message(${EVM_DEV})
18-
set(CMAKE_MODULE_PATH ${EVM_DEV})
19-
find_package(eqml)
20-
target_link_libraries(app PRIVATE eqml)
21-
else()
22-
set(LIBEQML ${EVM_BASE}/lib/arm-none-eabi-gcc/cortex-m3/libeqml.a)
23-
message(${LIBEQML})
24-
target_link_libraries(app PRIVATE ${LIBEQML})
25-
endif()
16+
set(LIBEQML ${EVM_BASE}/lib/arm-none-eabi-gcc/cortex-m3/libeqml.a)
17+
message(${LIBEQML})
18+
target_link_libraries(app PRIVATE ${LIBEQML})
2619

2720
set(evm_ecma_sources
2821
${EVM_BASE}/modules/ecma/ecma.c
@@ -89,7 +82,7 @@ set(libevm_module_sources
8982
)
9083

9184
include_directories(app PRIVATE ${EVM_BASE}/include)
92-
include_directories(app PRIVATE ${EVM_BASE}/eqml)
85+
include_directories(app PRIVATE ${EVM_BASE}/bsp/common)
9386
include_directories(app PRIVATE ${EVM_BASE}/modules/ecma)
9487
include_directories(app PRIVATE ${EVM_BASE}/modules/evm)
9588
include_directories(app PRIVATE ${EVM_BASE}/modules/qml)
@@ -100,13 +93,16 @@ include_directories(app PRIVATE src)
10093

10194
target_sources(app PRIVATE ${libevm_module_sources})
10295
target_sources(app PRIVATE src/main.c)
103-
target_sources(app PRIVATE ${EVM_BASE}/eqml/evm_main.c)
96+
target_sources(app PRIVATE ${EVM_BASE}/bsp/common/evm_main.c)
10497
target_sources(app PRIVATE src/evm_board.c)
105-
target_sources(app PRIVATE ${EVM_BASE}/eqml/uol_output.c)
98+
target_sources(app PRIVATE ${EVM_BASE}/bsp/common/uol_output.c)
10699

107100
# evm module config
108101
add_definitions("-DCONFIG_EVM_TIMER")
109102

110103
# ecma module config
111104
add_definitions("-DCONFIG_EVM_ECMA_OBJECT")
112105
add_definitions("-DCONFIG_EVM_ECMA_ARRAY")
106+
107+
# language config
108+
add_definitions("-DCONFIG_EVM_LANG_QML")

0 commit comments

Comments
 (0)