mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-02-05 17:28:23 +08:00
cut VM for nano mode
This commit is contained in:
parent
26702ad030
commit
c70947aa6e
@ -15,9 +15,6 @@ class MemChecker:
|
|||||||
|
|
||||||
|
|
||||||
class SysObj:
|
class SysObj:
|
||||||
@staticmethod
|
|
||||||
def type(arg: any) -> any: ...
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def int(arg: any) -> int: ...
|
def int(arg: any) -> int: ...
|
||||||
|
|
||||||
@ -42,6 +39,10 @@ class SysObj:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def __getitem__(obj: any, key: any) -> any: ...
|
def __getitem__(obj: any, key: any) -> any: ...
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||||
|
def type(arg: any) -> any: ...
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
|
@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
|
||||||
def __slice__(obj: any, start: any, end: any, step: int) -> any: ...
|
def __slice__(obj: any, start: any, end: any, step: int) -> any: ...
|
||||||
|
3
port/linux/.vscode/settings.json
vendored
3
port/linux/.vscode/settings.json
vendored
@ -25,6 +25,7 @@
|
|||||||
"pikacv_filter.h": "c",
|
"pikacv_filter.h": "c",
|
||||||
"pika_config.h": "c",
|
"pika_config.h": "c",
|
||||||
"gtesttask.h": "c",
|
"gtesttask.h": "c",
|
||||||
"mnist_valid_q.h": "c"
|
"mnist_valid_q.h": "c",
|
||||||
|
"pikaplatform.h": "c"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,9 +15,6 @@ class MemChecker:
|
|||||||
|
|
||||||
|
|
||||||
class SysObj:
|
class SysObj:
|
||||||
@staticmethod
|
|
||||||
def type(arg: any) -> any: ...
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def int(arg: any) -> int: ...
|
def int(arg: any) -> int: ...
|
||||||
|
|
||||||
@ -42,6 +39,10 @@ class SysObj:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def __getitem__(obj: any, key: any) -> any: ...
|
def __getitem__(obj: any, key: any) -> any: ...
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||||
|
def type(arg: any) -> any: ...
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
|
@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
|
||||||
def __slice__(obj: any, start: any, end: any, step: int) -> any: ...
|
def __slice__(obj: any, start: any, end: any, step: int) -> any: ...
|
||||||
|
@ -1445,6 +1445,7 @@ TEST(vm, none) {
|
|||||||
EXPECT_EQ(pikaMemNow(), 0);
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !PIKA_NANO_ENABLE
|
||||||
TEST(vm, super_) {
|
TEST(vm, super_) {
|
||||||
/* init */
|
/* init */
|
||||||
pikaMemInfo.heapUsedMax = 0;
|
pikaMemInfo.heapUsedMax = 0;
|
||||||
@ -1500,6 +1501,7 @@ TEST(vm, super_val) {
|
|||||||
obj_deinit(pikaMain);
|
obj_deinit(pikaMain);
|
||||||
EXPECT_EQ(pikaMemNow(), 0);
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !PIKA_NANO_ENABLE
|
#if !PIKA_NANO_ENABLE
|
||||||
TEST(vm, multi_return) {
|
TEST(vm, multi_return) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "test_common.h"
|
#include "test_common.h"
|
||||||
|
|
||||||
|
#if !PIKA_NANO_ENABLE
|
||||||
TEST(class, class_par) {
|
TEST(class, class_par) {
|
||||||
/* init */
|
/* init */
|
||||||
pikaMemInfo.heapUsedMax = 0;
|
pikaMemInfo.heapUsedMax = 0;
|
||||||
@ -50,6 +51,7 @@ TEST(class, static_method) {
|
|||||||
obj_deinit(self);
|
obj_deinit(self);
|
||||||
EXPECT_EQ(pikaMemNow(), 0);
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
TEST(class, dir_) {
|
TEST(class, dir_) {
|
||||||
/* init */
|
/* init */
|
||||||
|
@ -188,6 +188,7 @@ TEST(string, replace_chain) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !PIKA_NANO_ENABLE
|
||||||
TEST(string, split_chain) {
|
TEST(string, split_chain) {
|
||||||
/* init */
|
/* init */
|
||||||
pikaMemInfo.heapUsedMax = 0;
|
pikaMemInfo.heapUsedMax = 0;
|
||||||
@ -205,6 +206,7 @@ TEST(string, split_chain) {
|
|||||||
obj_deinit(pikaMain);
|
obj_deinit(pikaMain);
|
||||||
EXPECT_EQ(pikaMemNow(), 0);
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
TEST(string, str_chain) {
|
TEST(string, str_chain) {
|
||||||
/* init */
|
/* init */
|
||||||
|
@ -474,6 +474,7 @@ static PikaObj* __obj_getObjDirect(PikaObj* self,
|
|||||||
if (argType_isObject(type)) {
|
if (argType_isObject(type)) {
|
||||||
return args_getPtr(self->list, name);
|
return args_getPtr(self->list, name);
|
||||||
}
|
}
|
||||||
|
#if !PIKA_NANO_ENABLE
|
||||||
/* found class */
|
/* found class */
|
||||||
if (type == ARG_TYPE_METHOD_NATIVE_CONSTRUCTOR ||
|
if (type == ARG_TYPE_METHOD_NATIVE_CONSTRUCTOR ||
|
||||||
type == ARG_TYPE_METHOD_CONSTRUCTOR) {
|
type == ARG_TYPE_METHOD_CONSTRUCTOR) {
|
||||||
@ -489,6 +490,7 @@ static PikaObj* __obj_getObjDirect(PikaObj* self,
|
|||||||
arg_deinit(cls_obj_arg);
|
arg_deinit(cls_obj_arg);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return _arg_to_obj(args_getArg(self->list, name), pIsTemp);
|
return _arg_to_obj(args_getArg(self->list, name), pIsTemp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
src/PikaVM.c
22
src/PikaVM.c
@ -81,10 +81,12 @@ static char* VMState_getConstWithInstructUnit(VMState* vm,
|
|||||||
instructUnit_getConstPoolIndex(ins_unit));
|
instructUnit_getConstPoolIndex(ins_unit));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !PIKA_NANO_ENABLE
|
||||||
static char* VMState_getConstWithOffset(VMState* vm, int32_t offset) {
|
static char* VMState_getConstWithOffset(VMState* vm, int32_t offset) {
|
||||||
return VMState_getConstWithInstructUnit(
|
return VMState_getConstWithInstructUnit(
|
||||||
vm, VMState_getInstructUnitWithOffset(vm, offset));
|
vm, VMState_getInstructUnitWithOffset(vm, offset));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int VMState_getInvokeDeepthNow(VMState* vm) {
|
static int VMState_getInvokeDeepthNow(VMState* vm) {
|
||||||
/* support run byteCode */
|
/* support run byteCode */
|
||||||
@ -183,6 +185,7 @@ static int32_t VMState_getAddrOffsetOfBreak(VMState* vm) {
|
|||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !PIKA_NANO_ENABLE
|
||||||
static int32_t VMState_getAddrOffsetOfRaise(VMState* vm) {
|
static int32_t VMState_getAddrOffsetOfRaise(VMState* vm) {
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
InstructUnit* ins_unit_now = VMState_getInstructNow(vm);
|
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) {
|
static int32_t VMState_getAddrOffsetOfContinue(VMState* vm) {
|
||||||
int32_t offset = VMState_getAddrOffsetOfJmpBack(vm);
|
int32_t offset = VMState_getAddrOffsetOfJmpBack(vm);
|
||||||
@ -905,6 +909,7 @@ static Arg* VM_instruction_handler_RET(PikaObj* self,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !PIKA_NANO_ENABLE
|
||||||
static char* _find_super_class_name(VMState* vm) {
|
static char* _find_super_class_name(VMState* vm) {
|
||||||
/* find super class */
|
/* find super class */
|
||||||
int offset = 0;
|
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) {
|
static char* _find_self_name(VMState* vm) {
|
||||||
/* find super class */
|
/* find super class */
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
@ -958,6 +965,7 @@ static char* _find_self_name(VMState* vm) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static Arg* VM_instruction_handler_RUN(PikaObj* self,
|
static Arg* VM_instruction_handler_RUN(PikaObj* self,
|
||||||
VMState* vm,
|
VMState* vm,
|
||||||
@ -1001,12 +1009,14 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self,
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !PIKA_NANO_ENABLE
|
||||||
/* support for super() */
|
/* support for super() */
|
||||||
if (strEqu(run_path, "super")) {
|
if (strEqu(run_path, "super")) {
|
||||||
run_path = _find_super_class_name(vm);
|
run_path = _find_super_class_name(vm);
|
||||||
vm->in_super = 1;
|
vm->in_super = 1;
|
||||||
skip_init = 1;
|
skip_init = 1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* return tiny obj */
|
/* return tiny obj */
|
||||||
if (strEqu(run_path, "TinyObj")) {
|
if (strEqu(run_path, "TinyObj")) {
|
||||||
@ -1014,10 +1024,12 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self,
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !PIKA_NANO_ENABLE
|
||||||
if (!skip_init && vm->in_super) {
|
if (!skip_init && vm->in_super) {
|
||||||
vm->in_super = PIKA_FALSE;
|
vm->in_super = PIKA_FALSE;
|
||||||
obj_this = obj_getPtr(vm->locals, _find_self_name(vm));
|
obj_this = obj_getPtr(vm->locals, _find_self_name(vm));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* get method host obj from reg */
|
/* get method host obj from reg */
|
||||||
if (NULL == method_host && _checkLReg(run_path)) {
|
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];
|
method_host = vm->lreg[reg_index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !PIKA_NANO_ENABLE
|
||||||
/* get method host obj from stack */
|
/* get method host obj from stack */
|
||||||
if (NULL == method_host && run_path[0] == '.') {
|
if (NULL == method_host && run_path[0] == '.') {
|
||||||
/* get method host obj from stack */
|
/* 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]);
|
stack_pushArg(&(vm->stack), stack_tmp[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* get method host obj from self */
|
/* get method host obj from self */
|
||||||
if (NULL == method_host) {
|
if (NULL == method_host) {
|
||||||
@ -1964,6 +1978,9 @@ static Arg* VM_instruction_handler_RIS(PikaObj* self,
|
|||||||
VMState* vm,
|
VMState* vm,
|
||||||
char* data,
|
char* data,
|
||||||
Arg* arg_ret_reg) {
|
Arg* arg_ret_reg) {
|
||||||
|
#if PIKA_NANO_ENABLE
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
Arg* err_arg = stack_popArg_alloc(&(vm->stack));
|
Arg* err_arg = stack_popArg_alloc(&(vm->stack));
|
||||||
PIKA_RES err = (PIKA_RES)arg_getInt(err_arg);
|
PIKA_RES err = (PIKA_RES)arg_getInt(err_arg);
|
||||||
VMState_setErrorCode(vm, err);
|
VMState_setErrorCode(vm, err);
|
||||||
@ -1975,6 +1992,9 @@ static Arg* VM_instruction_handler_ASS(PikaObj* self,
|
|||||||
VMState* vm,
|
VMState* vm,
|
||||||
char* data,
|
char* data,
|
||||||
Arg* arg_ret_reg) {
|
Arg* arg_ret_reg) {
|
||||||
|
#if PIKA_NANO_ENABLE
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
arg_newReg(reg1, PIKA_ARG_BUFF_SIZE);
|
arg_newReg(reg1, PIKA_ARG_BUFF_SIZE);
|
||||||
arg_newReg(reg2, PIKA_ARG_BUFF_SIZE);
|
arg_newReg(reg2, PIKA_ARG_BUFF_SIZE);
|
||||||
Arg* arg1 = NULL;
|
Arg* arg1 = NULL;
|
||||||
@ -2173,6 +2193,7 @@ nextLine:
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
/* raise */
|
/* raise */
|
||||||
|
#if !PIKA_NANO_ENABLE
|
||||||
if (VM_JMP_RAISE == vm->jmp) {
|
if (VM_JMP_RAISE == vm->jmp) {
|
||||||
int offset = VMState_getAddrOffsetOfRaise(vm);
|
int offset = VMState_getAddrOffsetOfRaise(vm);
|
||||||
if (0 == offset) {
|
if (0 == offset) {
|
||||||
@ -2184,6 +2205,7 @@ nextLine:
|
|||||||
pc_next = vm->pc + offset;
|
pc_next = vm->pc + offset;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/* static jmp */
|
/* static jmp */
|
||||||
if (vm->jmp != 0) {
|
if (vm->jmp != 0) {
|
||||||
pc_next = vm->pc + VMState_getAddrOffsetFromJmp(vm);
|
pc_next = vm->pc + VMState_getAddrOffsetFromJmp(vm);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user