From c70947aa6e9f74f8c22b9b1c929febb2351ec3c7 Mon Sep 17 00:00:00 2001 From: pikastech Date: Sat, 10 Sep 2022 23:16:59 +0800 Subject: [PATCH] cut VM for nano mode --- package/PikaStdLib/PikaStdLib.pyi | 7 ++++--- port/linux/.vscode/settings.json | 3 ++- port/linux/package/pikascript/PikaStdLib.pyi | 7 ++++--- port/linux/test/VM-test.cpp | 2 ++ port/linux/test/class-test.cpp | 2 ++ port/linux/test/string-test.cpp | 2 ++ src/PikaObj.c | 2 ++ src/PikaVM.c | 22 ++++++++++++++++++++ 8 files changed, 40 insertions(+), 7 deletions(-) diff --git a/package/PikaStdLib/PikaStdLib.pyi b/package/PikaStdLib/PikaStdLib.pyi index f42516641..ff86aea40 100644 --- a/package/PikaStdLib/PikaStdLib.pyi +++ b/package/PikaStdLib/PikaStdLib.pyi @@ -15,9 +15,6 @@ class MemChecker: class SysObj: - @staticmethod - def type(arg: any) -> any: ... - @staticmethod def int(arg: any) -> int: ... @@ -42,6 +39,10 @@ class SysObj: @staticmethod def __getitem__(obj: any, key: any) -> any: ... + @staticmethod + @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") + def type(arg: any) -> any: ... + @staticmethod @PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE") def __slice__(obj: any, start: any, end: any, step: int) -> any: ... diff --git a/port/linux/.vscode/settings.json b/port/linux/.vscode/settings.json index 75eaeccb1..7187157ed 100644 --- a/port/linux/.vscode/settings.json +++ b/port/linux/.vscode/settings.json @@ -25,6 +25,7 @@ "pikacv_filter.h": "c", "pika_config.h": "c", "gtesttask.h": "c", - "mnist_valid_q.h": "c" + "mnist_valid_q.h": "c", + "pikaplatform.h": "c" } } \ No newline at end of file diff --git a/port/linux/package/pikascript/PikaStdLib.pyi b/port/linux/package/pikascript/PikaStdLib.pyi index f42516641..ff86aea40 100644 --- a/port/linux/package/pikascript/PikaStdLib.pyi +++ b/port/linux/package/pikascript/PikaStdLib.pyi @@ -15,9 +15,6 @@ class MemChecker: class SysObj: - @staticmethod - def type(arg: any) -> any: ... - @staticmethod def int(arg: any) -> int: ... @@ -42,6 +39,10 @@ class SysObj: @staticmethod def __getitem__(obj: any, key: any) -> any: ... + @staticmethod + @PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE") + def type(arg: any) -> any: ... + @staticmethod @PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE") def __slice__(obj: any, start: any, end: any, step: int) -> any: ... diff --git a/port/linux/test/VM-test.cpp b/port/linux/test/VM-test.cpp index dae54c5f7..e953a6599 100644 --- a/port/linux/test/VM-test.cpp +++ b/port/linux/test/VM-test.cpp @@ -1445,6 +1445,7 @@ TEST(vm, none) { EXPECT_EQ(pikaMemNow(), 0); } +#if !PIKA_NANO_ENABLE TEST(vm, super_) { /* init */ pikaMemInfo.heapUsedMax = 0; @@ -1500,6 +1501,7 @@ TEST(vm, super_val) { obj_deinit(pikaMain); EXPECT_EQ(pikaMemNow(), 0); } +#endif #if !PIKA_NANO_ENABLE TEST(vm, multi_return) { diff --git a/port/linux/test/class-test.cpp b/port/linux/test/class-test.cpp index 6bca737b1..941292aae 100644 --- a/port/linux/test/class-test.cpp +++ b/port/linux/test/class-test.cpp @@ -1,5 +1,6 @@ #include "test_common.h" +#if !PIKA_NANO_ENABLE TEST(class, class_par) { /* init */ pikaMemInfo.heapUsedMax = 0; @@ -50,6 +51,7 @@ TEST(class, static_method) { obj_deinit(self); EXPECT_EQ(pikaMemNow(), 0); } +#endif TEST(class, dir_) { /* init */ diff --git a/port/linux/test/string-test.cpp b/port/linux/test/string-test.cpp index 0ae427514..f5940c7e1 100644 --- a/port/linux/test/string-test.cpp +++ b/port/linux/test/string-test.cpp @@ -188,6 +188,7 @@ TEST(string, replace_chain) { } #endif +#if !PIKA_NANO_ENABLE TEST(string, split_chain) { /* init */ pikaMemInfo.heapUsedMax = 0; @@ -205,6 +206,7 @@ TEST(string, split_chain) { obj_deinit(pikaMain); EXPECT_EQ(pikaMemNow(), 0); } +#endif TEST(string, str_chain) { /* init */ diff --git a/src/PikaObj.c b/src/PikaObj.c index cb0fe3cac..6b5b790b6 100644 --- a/src/PikaObj.c +++ b/src/PikaObj.c @@ -474,6 +474,7 @@ static PikaObj* __obj_getObjDirect(PikaObj* self, if (argType_isObject(type)) { return args_getPtr(self->list, name); } + #if !PIKA_NANO_ENABLE /* found class */ if (type == ARG_TYPE_METHOD_NATIVE_CONSTRUCTOR || type == ARG_TYPE_METHOD_CONSTRUCTOR) { @@ -489,6 +490,7 @@ static PikaObj* __obj_getObjDirect(PikaObj* self, arg_deinit(cls_obj_arg); return res; } + #endif return _arg_to_obj(args_getArg(self->list, name), pIsTemp); } diff --git a/src/PikaVM.c b/src/PikaVM.c index 3110c30c6..9ec845aa1 100644 --- a/src/PikaVM.c +++ b/src/PikaVM.c @@ -81,10 +81,12 @@ static char* VMState_getConstWithInstructUnit(VMState* vm, instructUnit_getConstPoolIndex(ins_unit)); } +#if !PIKA_NANO_ENABLE static char* VMState_getConstWithOffset(VMState* vm, int32_t offset) { return VMState_getConstWithInstructUnit( vm, VMState_getInstructUnitWithOffset(vm, offset)); } +#endif static int VMState_getInvokeDeepthNow(VMState* vm) { /* support run byteCode */ @@ -183,6 +185,7 @@ static int32_t VMState_getAddrOffsetOfBreak(VMState* vm) { return offset; } +#if !PIKA_NANO_ENABLE static int32_t VMState_getAddrOffsetOfRaise(VMState* vm) { int offset = 0; InstructUnit* ins_unit_now = VMState_getInstructNow(vm); @@ -202,6 +205,7 @@ static int32_t VMState_getAddrOffsetOfRaise(VMState* vm) { } } } +#endif static int32_t VMState_getAddrOffsetOfContinue(VMState* vm) { int32_t offset = VMState_getAddrOffsetOfJmpBack(vm); @@ -905,6 +909,7 @@ static Arg* VM_instruction_handler_RET(PikaObj* self, return NULL; } +#if !PIKA_NANO_ENABLE static char* _find_super_class_name(VMState* vm) { /* find super class */ int offset = 0; @@ -931,7 +936,9 @@ static char* _find_super_class_name(VMState* vm) { } } } +#endif +#if !PIKA_NANO_ENABLE static char* _find_self_name(VMState* vm) { /* find super class */ int offset = 0; @@ -958,6 +965,7 @@ static char* _find_self_name(VMState* vm) { } } } +#endif static Arg* VM_instruction_handler_RUN(PikaObj* self, VMState* vm, @@ -1001,12 +1009,14 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, goto exit; } + #if !PIKA_NANO_ENABLE /* support for super() */ if (strEqu(run_path, "super")) { run_path = _find_super_class_name(vm); vm->in_super = 1; skip_init = 1; } + #endif /* return tiny obj */ if (strEqu(run_path, "TinyObj")) { @@ -1014,10 +1024,12 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, goto exit; } + #if !PIKA_NANO_ENABLE if (!skip_init && vm->in_super) { vm->in_super = PIKA_FALSE; obj_this = obj_getPtr(vm->locals, _find_self_name(vm)); } + #endif /* get method host obj from reg */ if (NULL == method_host && _checkLReg(run_path)) { @@ -1025,6 +1037,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, method_host = vm->lreg[reg_index]; } + #if !PIKA_NANO_ENABLE /* get method host obj from stack */ if (NULL == method_host && run_path[0] == '.') { /* get method host obj from stack */ @@ -1050,6 +1063,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, stack_pushArg(&(vm->stack), stack_tmp[i]); } } + #endif /* get method host obj from self */ if (NULL == method_host) { @@ -1964,6 +1978,9 @@ static Arg* VM_instruction_handler_RIS(PikaObj* self, VMState* vm, char* data, Arg* arg_ret_reg) { + #if PIKA_NANO_ENABLE + return NULL; + #endif Arg* err_arg = stack_popArg_alloc(&(vm->stack)); PIKA_RES err = (PIKA_RES)arg_getInt(err_arg); VMState_setErrorCode(vm, err); @@ -1975,6 +1992,9 @@ static Arg* VM_instruction_handler_ASS(PikaObj* self, VMState* vm, char* data, Arg* arg_ret_reg) { + #if PIKA_NANO_ENABLE + return NULL; + #endif arg_newReg(reg1, PIKA_ARG_BUFF_SIZE); arg_newReg(reg2, PIKA_ARG_BUFF_SIZE); Arg* arg1 = NULL; @@ -2173,6 +2193,7 @@ nextLine: goto exit; } /* raise */ + #if !PIKA_NANO_ENABLE if (VM_JMP_RAISE == vm->jmp) { int offset = VMState_getAddrOffsetOfRaise(vm); if (0 == offset) { @@ -2184,6 +2205,7 @@ nextLine: pc_next = vm->pc + offset; goto exit; } + #endif /* static jmp */ if (vm->jmp != 0) { pc_next = vm->pc + VMState_getAddrOffsetFromJmp(vm);