From ac97532a7a7c308183b47147db1100957217c150 Mon Sep 17 00:00:00 2001 From: pikastech Date: Wed, 10 Aug 2022 12:07:32 +0800 Subject: [PATCH] support `exec()` builtin --- package/PikaStdLib/PikaStdLib.pyi | 3 +++ package/PikaStdLib/PikaStdLib_SysObj.c | 9 +++++++++ port/linux/package/pikascript/PikaStdLib.pyi | 3 +++ .../pikascript-lib/PikaStdLib/PikaStdLib_SysObj.c | 9 +++++++++ src/pika_config_valid.h | 12 ++++++++++++ 5 files changed, 36 insertions(+) diff --git a/package/PikaStdLib/PikaStdLib.pyi b/package/PikaStdLib/PikaStdLib.pyi index 58a7fa684..957857be4 100644 --- a/package/PikaStdLib/PikaStdLib.pyi +++ b/package/PikaStdLib/PikaStdLib.pyi @@ -79,6 +79,9 @@ class SysObj: @staticmethod def dir(obj: object) -> list: ... + @staticmethod + def exec(code: str): ... + class RangeObj: def __next__(self) -> any: ... diff --git a/package/PikaStdLib/PikaStdLib_SysObj.c b/package/PikaStdLib/PikaStdLib_SysObj.c index 0864a4506..31c849a85 100644 --- a/package/PikaStdLib/PikaStdLib_SysObj.c +++ b/package/PikaStdLib/PikaStdLib_SysObj.c @@ -499,3 +499,12 @@ PikaObj* PikaStdLib_SysObj_dir(PikaObj* self, PikaObj* obj) { args_deinit(context); return list; } + +void PikaStdLib_SysObj_exec(PikaObj* self, char* code) { +#if PIKA_EXEC_ENABLE + obj_run(self, code); +#else + obj_setErrorCode(self, 1); + __platform_printf("[Error] PIKA_EXEC_ENABLE is not enabled.\r\n"); +#endif +} diff --git a/port/linux/package/pikascript/PikaStdLib.pyi b/port/linux/package/pikascript/PikaStdLib.pyi index 58a7fa684..957857be4 100644 --- a/port/linux/package/pikascript/PikaStdLib.pyi +++ b/port/linux/package/pikascript/PikaStdLib.pyi @@ -79,6 +79,9 @@ class SysObj: @staticmethod def dir(obj: object) -> list: ... + @staticmethod + def exec(code: str): ... + class RangeObj: def __next__(self) -> any: ... diff --git a/port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdLib_SysObj.c b/port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdLib_SysObj.c index 0864a4506..31c849a85 100644 --- a/port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdLib_SysObj.c +++ b/port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdLib_SysObj.c @@ -499,3 +499,12 @@ PikaObj* PikaStdLib_SysObj_dir(PikaObj* self, PikaObj* obj) { args_deinit(context); return list; } + +void PikaStdLib_SysObj_exec(PikaObj* self, char* code) { +#if PIKA_EXEC_ENABLE + obj_run(self, code); +#else + obj_setErrorCode(self, 1); + __platform_printf("[Error] PIKA_EXEC_ENABLE is not enabled.\r\n"); +#endif +} diff --git a/src/pika_config_valid.h b/src/pika_config_valid.h index c379905d0..c7536e06d 100644 --- a/src/pika_config_valid.h +++ b/src/pika_config_valid.h @@ -106,6 +106,10 @@ #define PIKA_FILEIO_ENABLE 0 #endif + #ifndef PIKA_EXEC_ENABLE + #define PIKA_EXEC_ENABLE 0 + #endif + #elif PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL #ifndef PIKA_SYNTAX_SLICE_ENABLE #define PIKA_SYNTAX_SLICE_ENABLE 1 @@ -139,6 +143,10 @@ #define PIKA_FILEIO_ENABLE 1 #endif + #ifndef PIKA_EXEC_ENABLE + #define PIKA_EXEC_ENABLE 1 + #endif + #endif /* default configuration */ @@ -262,6 +270,10 @@ #define PIKA_INSTRUCT_HOOK_PERIOD 50 #endif + #ifndef PIKA_EXEC_ENABLE + #define PIKA_EXEC_ENABLE 1 + #endif + /* configuration validation */ #endif