mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
fix CI err
This commit is contained in:
parent
7f5edaf090
commit
ecfb8cb62f
3
port/linux/.vscode/launch.json
vendored
3
port/linux/.vscode/launch.json
vendored
@ -11,7 +11,8 @@
|
||||
"program": "${workspaceFolder}/build/test/pikascript_test",
|
||||
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
|
||||
"args": [
|
||||
"--gtest_filter=pikaui.*"
|
||||
// "--gtest_filter=pikaui.*"
|
||||
"--gtest_filter=InstructUnit.base"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
|
@ -6,6 +6,6 @@
|
||||
#define PIKA_INSTRUCT_HOOK_ENABLE 1
|
||||
#define PIKA_INSTRUCT_HOOK_PERIOD 1
|
||||
#define PIKA_SHELL_FILTER_ENABLE 1
|
||||
#define PIKA_GC_MARK_SWEEP_ENABLE 1
|
||||
// #define PIKA_GC_MARK_SWEEP_ENABLE 1
|
||||
#define PIKA_GC_MARK_SWEEP_THRESHOLD 1
|
||||
#define PIKA_KERNAL_DEBUG_ENABLE 1
|
@ -703,7 +703,7 @@ int pikaMaker_getDependencies(PikaMaker* self, char* module_name) {
|
||||
if (NULL == ins_unit) {
|
||||
goto exit;
|
||||
}
|
||||
if (instructUnit_getInstruct(ins_unit) == IMP) {
|
||||
if (instructUnit_getInstructIndex(ins_unit) == IMP) {
|
||||
char* imp_module_name =
|
||||
constPool_getByOffset(const_pool, ins_unit->const_pool_index);
|
||||
char* imp_module_path =
|
||||
|
166
src/PikaVM.c
166
src/PikaVM.c
@ -295,7 +295,7 @@ static void VMState_setErrorCode(VMState* vm, int8_t error_code) {
|
||||
}
|
||||
|
||||
static enum InstructIndex VMstate_getInstructWithOffset(VMState* vm,
|
||||
int32_t offset) {
|
||||
int32_t offset) {
|
||||
return instructUnit_getInstructIndex(
|
||||
VMState_getInstructUnitWithOffset(vm, offset));
|
||||
}
|
||||
@ -335,7 +335,8 @@ static int32_t VMState_getAddrOffsetOfJmpBack(VMState* vm) {
|
||||
if ((0 == invokeDeepth) && (JEZ == ins) && data[0] == '2') {
|
||||
InstructUnit* insUnitLast = VMState_getInstructUnitWithOffset(
|
||||
vm, offset - instructUnit_getSize());
|
||||
enum InstructIndex insLast = instructUnit_getInstructIndex(insUnitLast);
|
||||
enum InstructIndex insLast =
|
||||
instructUnit_getInstructIndex(insUnitLast);
|
||||
/* skip try stmt */
|
||||
if (GER == insLast) {
|
||||
continue;
|
||||
@ -3011,60 +3012,54 @@ static Arg* VM_instruction_handler_IMP(PikaObj* self,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if PIKA_INSTRUCT_EXTENSION_ENABLE
|
||||
const VMInstructionSet VM_default_instruction_set = {
|
||||
#define __INS_OPCODE
|
||||
.instructions = (const VMInstruction []) {
|
||||
#include "__instruction_table.h"
|
||||
},
|
||||
#define __INS_OPCODE
|
||||
.instructions =
|
||||
(const VMInstruction[]){
|
||||
#include "__instruction_table.h"
|
||||
},
|
||||
.count = __INSTRUCTION_CNT,
|
||||
.op_idx_start = NON,
|
||||
.op_idx_end = NON + __INSTRUCTION_CNT - 1,
|
||||
};
|
||||
|
||||
|
||||
#ifndef PIKA_INSTRUCT_SIGNATURE_DICT
|
||||
# define PIKA_INSTRUCT_SIGNATURE_DICT 0
|
||||
#define PIKA_INSTRUCT_SIGNATURE_DICT 0
|
||||
#endif
|
||||
|
||||
typedef struct VMInstructionSetItem VMInstructionSetItem;
|
||||
struct VMInstructionSetItem {
|
||||
VMInstructionSetItem *next;
|
||||
const VMInstructionSet *ins_set;
|
||||
VMInstructionSetItem* next;
|
||||
const VMInstructionSet* ins_set;
|
||||
};
|
||||
|
||||
static struct {
|
||||
const VMInstructionSetItem default_ins_set;
|
||||
VMInstructionSetItem *list;
|
||||
VMInstructionSetItem *recent;
|
||||
const VMInstructionSetItem default_ins_set;
|
||||
VMInstructionSetItem* list;
|
||||
VMInstructionSetItem* recent;
|
||||
#if PIKA_INSTRUCT_SIGNATURE_DICT_COUNT > 0
|
||||
const uint16_t signature_dict[PIKA_INSTRUCT_SIGNATURE_DICT_COUNT];
|
||||
#endif
|
||||
} VM = {
|
||||
.default_ins_set = {
|
||||
.ins_set = &VM_default_instruction_set,
|
||||
.next = NULL,
|
||||
},
|
||||
.list = (VMInstructionSetItem *)&VM.default_ins_set,
|
||||
.recent = (VMInstructionSetItem *)&VM.default_ins_set,
|
||||
.default_ins_set =
|
||||
{
|
||||
.ins_set = &VM_default_instruction_set,
|
||||
.next = NULL,
|
||||
},
|
||||
.list = (VMInstructionSetItem*)&VM.default_ins_set,
|
||||
.recent = (VMInstructionSetItem*)&VM.default_ins_set,
|
||||
#if PIKA_INSTRUCT_SIGNATURE_DICT_COUNT > 0
|
||||
.signature_dict = {
|
||||
PIKA_INSTRUCT_SIGNATURE_DICT
|
||||
},
|
||||
.signature_dict = {PIKA_INSTRUCT_SIGNATURE_DICT},
|
||||
#endif
|
||||
};
|
||||
|
||||
PIKA_BOOL pikaVM_registerInstructionSet(VMInstructionSet *ins_set)
|
||||
{
|
||||
PIKA_BOOL pikaVM_registerInstructionSet(VMInstructionSet* ins_set) {
|
||||
pika_assert(NULL != ins_set);
|
||||
|
||||
#if PIKA_INSTRUCT_SIGNATURE_DICT_COUNT > 0
|
||||
uint16_t signature = ins_set->signature;
|
||||
|
||||
|
||||
PIKA_BOOL ins_set_valid = PIKA_FALSE;
|
||||
for (int n = 0; n < sizeof(VM.signature_dict) / sizeof(uint16_t); n++) {
|
||||
if (VM.signature_dict[n] == signature) {
|
||||
@ -3078,74 +3073,76 @@ PIKA_BOOL pikaVM_registerInstructionSet(VMInstructionSet *ins_set)
|
||||
#endif
|
||||
|
||||
/* check whether the target instruction set exists or not */
|
||||
VMInstructionSetItem *list_item = VM.list;
|
||||
VMInstructionSetItem* list_item = VM.list;
|
||||
do {
|
||||
if (list_item->ins_set->signature == signature) {
|
||||
return PIKA_TRUE; /* already exist */
|
||||
return PIKA_TRUE; /* already exist */
|
||||
}
|
||||
|
||||
list_item = list_item->next;
|
||||
} while(NULL != list_item->next);
|
||||
} while (NULL != list_item->next);
|
||||
|
||||
|
||||
VMInstructionSetItem *item = pika_platform_malloc(sizeof(VMInstructionSetItem));
|
||||
VMInstructionSetItem* item =
|
||||
pika_platform_malloc(sizeof(VMInstructionSetItem));
|
||||
if (NULL == item) {
|
||||
return PIKA_FALSE;
|
||||
}
|
||||
item->ins_set = ins_set;
|
||||
item->next = NULL;
|
||||
|
||||
|
||||
/* add item to the tail of VM.list */
|
||||
list_item->next = item;
|
||||
|
||||
return PIKA_TRUE;
|
||||
}
|
||||
|
||||
static
|
||||
const VMInstruction *instructUnit_getInstruct(enum InstructIndex ins_idx) {
|
||||
VMInstructionSetItem *item = VM.recent;
|
||||
static const VMInstruction* instructUnit_getInstruct(
|
||||
enum InstructIndex ins_idx) {
|
||||
VMInstructionSetItem* item = VM.recent;
|
||||
|
||||
if ( (ins_idx >= item->ins_set->op_idx_start)
|
||||
&& (ins_idx <= item->ins_set->op_idx_end)) {
|
||||
return &(item->ins_set->instructions[ins_idx - item->ins_set->op_idx_start]);
|
||||
if ((ins_idx >= item->ins_set->op_idx_start) &&
|
||||
(ins_idx <= item->ins_set->op_idx_end)) {
|
||||
return &(
|
||||
item->ins_set->instructions[ins_idx - item->ins_set->op_idx_start]);
|
||||
}
|
||||
|
||||
|
||||
/* search list */
|
||||
item = VM.list;
|
||||
do {
|
||||
if ( (ins_idx >= item->ins_set->op_idx_start)
|
||||
&& (ins_idx <= item->ins_set->op_idx_end)) {
|
||||
if ((ins_idx >= item->ins_set->op_idx_start) &&
|
||||
(ins_idx <= item->ins_set->op_idx_end)) {
|
||||
VM.recent = item;
|
||||
return &(item->ins_set->instructions[ins_idx - item->ins_set->op_idx_start]);
|
||||
return &(item->ins_set
|
||||
->instructions[ins_idx - item->ins_set->op_idx_start]);
|
||||
}
|
||||
item = item->next;
|
||||
} while(NULL != item->next);
|
||||
} while (NULL != item->next);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static enum InstructIndex __find_ins_idx_in_ins_set(char* ins_str, const VMInstructionSet *set)
|
||||
{
|
||||
const VMInstruction *ins = set->instructions;
|
||||
static enum InstructIndex __find_ins_idx_in_ins_set(
|
||||
char* ins_str,
|
||||
const VMInstructionSet* set) {
|
||||
const VMInstruction* ins = set->instructions;
|
||||
uint_fast16_t count = set->count;
|
||||
|
||||
|
||||
do {
|
||||
if (0 == strncmp(ins_str, ins->op_str, ins->op_str_len)) {
|
||||
return ins->op_idx;
|
||||
}
|
||||
ins++;
|
||||
} while(--count);
|
||||
} while (--count);
|
||||
return __INSTRUCTION_UNKNOWN;
|
||||
}
|
||||
|
||||
enum InstructIndex pikaVM_getInstructFromAsm(char* ins_str) {
|
||||
|
||||
enum InstructIndex ins_idx = __find_ins_idx_in_ins_set(ins_str, VM.recent->ins_set);
|
||||
|
||||
enum InstructIndex ins_idx =
|
||||
__find_ins_idx_in_ins_set(ins_str, VM.recent->ins_set);
|
||||
|
||||
if (__INSTRUCTION_UNKNOWN == ins_idx) {
|
||||
VMInstructionSetItem *item = VM.list;
|
||||
|
||||
VMInstructionSetItem* item = VM.list;
|
||||
|
||||
do {
|
||||
ins_idx = __find_ins_idx_in_ins_set(ins_str, item->ins_set);
|
||||
if (__INSTRUCTION_UNKNOWN != ins_idx) {
|
||||
@ -3153,17 +3150,17 @@ enum InstructIndex pikaVM_getInstructFromAsm(char* ins_str) {
|
||||
return ins_idx;
|
||||
}
|
||||
item = item->next;
|
||||
} while(NULL != item->next);
|
||||
|
||||
} while (NULL != item->next);
|
||||
|
||||
return NON;
|
||||
}
|
||||
|
||||
|
||||
return ins_idx;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
PIKA_BOOL pikaVM_registerInstructionSet(VMInstructionSet *ins_set) {
|
||||
PIKA_BOOL pikaVM_registerInstructionSet(VMInstructionSet* ins_set) {
|
||||
return PIKA_FALSE;
|
||||
}
|
||||
|
||||
@ -3192,18 +3189,17 @@ static int pikaVM_runInstructUnit(PikaObj* self,
|
||||
pika_assert(NULL != vm->run_state);
|
||||
|
||||
#if PIKA_INSTRUCT_EXTENSION_ENABLE
|
||||
const VMInstruction * ins = instructUnit_getInstruct(instruct);
|
||||
const VMInstruction* ins = instructUnit_getInstruct(instruct);
|
||||
if (NULL == ins) {
|
||||
/* todo: unsupported instruction */
|
||||
pika_assert(NULL != ins);
|
||||
}
|
||||
pika_assert(NULL != ins->handler);
|
||||
|
||||
|
||||
return_arg = ins->handler(self, vm, data, &ret_reg);
|
||||
#else
|
||||
return_arg = VM_instruct_handler_table[instruct](self, vm, data, &ret_reg);
|
||||
#endif
|
||||
|
||||
|
||||
if (vm->error_code != PIKA_RES_OK ||
|
||||
VMSignal_getCtrl() == VM_SIGNAL_CTRL_EXIT) {
|
||||
@ -3680,42 +3676,36 @@ InstructUnit* instructArray_getNext(InstructArray* self) {
|
||||
|
||||
#if PIKA_INSTRUCT_EXTENSION_ENABLE
|
||||
|
||||
static const char * __find_ins_str_in_ins_set(enum InstructIndex op_idx, const VMInstructionSet *set)
|
||||
{
|
||||
const VMInstruction *ins = set->instructions;
|
||||
static const char* __find_ins_str_in_ins_set(enum InstructIndex op_idx,
|
||||
const VMInstructionSet* set) {
|
||||
const VMInstruction* ins = set->instructions;
|
||||
uint_fast16_t count = set->count;
|
||||
|
||||
|
||||
do {
|
||||
if (ins->op_idx == op_idx) {
|
||||
return ins->op_str;
|
||||
}
|
||||
ins++;
|
||||
} while(--count);
|
||||
} while (--count);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static char* instructUnit_getInstructStr(InstructUnit* self) {
|
||||
|
||||
enum InstructIndex op_idx = instructUnit_getInstructIndex(self);
|
||||
|
||||
const char *ins_str = __find_ins_str_in_ins_set(op_idx, VM.recent->ins_set);
|
||||
|
||||
if (NULL == ins_str) {
|
||||
VMInstructionSetItem *item = VM.list;
|
||||
|
||||
do {
|
||||
ins_str = __find_ins_str_in_ins_set(op_idx, item->ins_set);
|
||||
if (NULL != ins_str) {
|
||||
VM.recent = item;
|
||||
return (char *)ins_str;
|
||||
}
|
||||
item = item->next;
|
||||
} while(NULL != item->next);
|
||||
|
||||
return "NON";
|
||||
|
||||
const char* ins_str = __find_ins_str_in_ins_set(op_idx, VM.recent->ins_set);
|
||||
if (NULL != ins_str) {
|
||||
return (char*)ins_str;
|
||||
}
|
||||
|
||||
VMInstructionSetItem* item = VM.list;
|
||||
do {
|
||||
ins_str = __find_ins_str_in_ins_set(op_idx, item->ins_set);
|
||||
if (NULL != ins_str) {
|
||||
VM.recent = item;
|
||||
return (char*)ins_str;
|
||||
}
|
||||
item = item->next;
|
||||
} while (NULL != item->next);
|
||||
return "NON";
|
||||
}
|
||||
#else
|
||||
|
29
src/PikaVM.h
29
src/PikaVM.h
@ -40,7 +40,7 @@ enum InstructIndex {
|
||||
#include "__instruction_table.h"
|
||||
__INSTRUCTION_CNT,
|
||||
__INSTRUCTION_INDEX_MAX = 0xFFFF,
|
||||
__INSTRUCTION_UNKNOWN = 0xFFFF,
|
||||
__INSTRUCTION_UNKNOWN = 0xFFFF,
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
@ -164,25 +164,21 @@ typedef Arg* (*VM_instruct_handler)(PikaObj* self,
|
||||
typedef struct VMInstruction VMInstruction;
|
||||
struct VMInstruction {
|
||||
VM_instruct_handler handler;
|
||||
const char *op_str;
|
||||
uint16_t op_idx;
|
||||
uint16_t op_str_len : 4;
|
||||
uint16_t : 12;
|
||||
const char* op_str;
|
||||
uint16_t op_idx;
|
||||
uint16_t op_str_len : 4;
|
||||
uint16_t : 12;
|
||||
};
|
||||
|
||||
|
||||
typedef struct VMInstructionSet VMInstructionSet;
|
||||
struct VMInstructionSet {
|
||||
const VMInstruction *instructions;
|
||||
uint16_t count;
|
||||
uint16_t signature;
|
||||
uint16_t op_idx_start;
|
||||
uint16_t op_idx_end;
|
||||
const VMInstruction* instructions;
|
||||
uint16_t count;
|
||||
uint16_t signature;
|
||||
uint16_t op_idx_start;
|
||||
uint16_t op_idx_end;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
VMParameters* pikaVM_run(PikaObj* self, char* pyLine);
|
||||
VMParameters* pikaVM_runAsm(PikaObj* self, char* pikaAsm);
|
||||
VMParameters* pikaVM_runByteCodeFrame(PikaObj* self,
|
||||
@ -196,7 +192,8 @@ static inline int instructUnit_getInvokeDeepth(InstructUnit* self) {
|
||||
return self->deepth >> 4;
|
||||
}
|
||||
|
||||
static inline enum InstructIndex instructUnit_getInstructIndex(InstructUnit* self) {
|
||||
static inline enum InstructIndex instructUnit_getInstructIndex(
|
||||
InstructUnit* self) {
|
||||
return (enum InstructIndex)(self->isNewLine_instruct & 0x7F);
|
||||
}
|
||||
|
||||
@ -315,7 +312,7 @@ void instructArray_printAsArray(InstructArray* self);
|
||||
void byteCodeFrame_loadByteCode(ByteCodeFrame* self, uint8_t* bytes);
|
||||
void byteCodeFrame_printAsArray(ByteCodeFrame* self);
|
||||
void byteCodeFrame_init(ByteCodeFrame* self);
|
||||
PIKA_BOOL pikaVM_registerInstructionSet(VMInstructionSet *ins_set);
|
||||
PIKA_BOOL pikaVM_registerInstructionSet(VMInstructionSet* ins_set);
|
||||
VMParameters* pikaVM_runByteCode(PikaObj* self, const uint8_t* bytecode);
|
||||
VMParameters* pikaVM_runByteCodeInconstant(PikaObj* self, uint8_t* bytecode);
|
||||
InstructUnit* instructArray_getNow(InstructArray* self);
|
||||
|
@ -657,13 +657,13 @@ TEST(InstructUnit, base) {
|
||||
instructUnit_setBlockDeepth(&ins_unit, 2);
|
||||
instructUnit_setIsNewLine(&ins_unit, 1);
|
||||
instructUnit_setInvokeDeepth(&ins_unit, 3);
|
||||
instructUnit_setInstruct(&ins_unit, (Instruct)4);
|
||||
instructUnit_setInstruct(&ins_unit, (InstructIndex)4);
|
||||
instructUnit_setConstPoolIndex(&ins_unit, 12);
|
||||
|
||||
EXPECT_EQ(instructUnit_getBlockDeepth(&ins_unit), 2);
|
||||
EXPECT_EQ(instructUnit_getIsNewLine(&ins_unit), 1);
|
||||
EXPECT_EQ(instructUnit_getInvokeDeepth(&ins_unit), 3);
|
||||
EXPECT_EQ(instructUnit_getInstruct(&ins_unit), 4);
|
||||
EXPECT_EQ(instructUnit_getInstructIndex(&ins_unit), 4);
|
||||
EXPECT_EQ(instructUnit_getConstPoolIndex(&ins_unit), 12);
|
||||
|
||||
instructUnit_print(&ins_unit);
|
||||
@ -714,7 +714,7 @@ TEST(InstructArray, set) {
|
||||
instructUnit_setBlockDeepth(&ins_unit, 2);
|
||||
instructUnit_setIsNewLine(&ins_unit, 1);
|
||||
instructUnit_setInvokeDeepth(&ins_unit, 3);
|
||||
instructUnit_setInstruct(&ins_unit, (Instruct)4);
|
||||
instructUnit_setInstruct(&ins_unit, (InstructIndex)4);
|
||||
instructUnit_setConstPoolIndex(&ins_unit, 12);
|
||||
|
||||
InstructArray ins_array;
|
||||
|
Loading…
x
Reference in New Issue
Block a user