support exec() builtin

This commit is contained in:
pikastech 2022-08-10 12:07:32 +08:00
parent e0eee73209
commit ac97532a7a
5 changed files with 36 additions and 0 deletions

View File

@ -79,6 +79,9 @@ class SysObj:
@staticmethod
def dir(obj: object) -> list: ...
@staticmethod
def exec(code: str): ...
class RangeObj:
def __next__(self) -> any: ...

View File

@ -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
}

View File

@ -79,6 +79,9 @@ class SysObj:
@staticmethod
def dir(obj: object) -> list: ...
@staticmethod
def exec(code: str): ...
class RangeObj:
def __next__(self) -> any: ...

View File

@ -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
}

View File

@ -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