mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
instructArray print is ok
This commit is contained in:
parent
87c30b2cb3
commit
8d5ba40b14
@ -770,6 +770,7 @@ TEST(VM, nag_a) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(InstructUnit, base) {
|
TEST(InstructUnit, base) {
|
||||||
|
__platform_printf((char*)"BEGIN\r\n");
|
||||||
InstructUnit bu;
|
InstructUnit bu;
|
||||||
instructUnit_init(&bu);
|
instructUnit_init(&bu);
|
||||||
instructUnit_setBlockDeepth(&bu, 2);
|
instructUnit_setBlockDeepth(&bu, 2);
|
||||||
@ -785,6 +786,10 @@ TEST(InstructUnit, base) {
|
|||||||
EXPECT_EQ(instructUnit_getConstPoolIndex(&bu), 12);
|
EXPECT_EQ(instructUnit_getConstPoolIndex(&bu), 12);
|
||||||
|
|
||||||
instructUnit_print(&bu);
|
instructUnit_print(&bu);
|
||||||
|
EXPECT_STREQ(log_buff[2], (char*)"BEGIN\r\n");
|
||||||
|
EXPECT_STREQ(log_buff[1], (char*)"B2\r\n");
|
||||||
|
EXPECT_STREQ(log_buff[0], (char*)"3 OUT #12\r\n");
|
||||||
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TEST(InstructUnit, new_) {
|
// TEST(InstructUnit, new_) {
|
||||||
@ -833,6 +838,7 @@ TEST(ConstPool, get) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(InstructArray, set) {
|
TEST(InstructArray, set) {
|
||||||
|
__platform_printf((char*)"BEGIN\r\n");
|
||||||
InstructArray ia;
|
InstructArray ia;
|
||||||
InstructUnit bu;
|
InstructUnit bu;
|
||||||
instructUnit_init(&bu);
|
instructUnit_init(&bu);
|
||||||
@ -844,7 +850,10 @@ TEST(InstructArray, set) {
|
|||||||
|
|
||||||
instructArray_init(&ia);
|
instructArray_init(&ia);
|
||||||
instructArray_append(&ia, &bu);
|
instructArray_append(&ia, &bu);
|
||||||
|
instructArray_print(&ia);
|
||||||
instructArray_deinit(&ia);
|
instructArray_deinit(&ia);
|
||||||
|
EXPECT_STREQ(log_buff[2], (char*)"BEGIN\r\n");
|
||||||
|
EXPECT_STREQ(log_buff[1], (char*)"B2\r\n");
|
||||||
|
EXPECT_STREQ(log_buff[0], (char*)"3 OUT #12\r\n");
|
||||||
EXPECT_EQ(pikaMemNow(), 0);
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
}
|
}
|
||||||
|
23
src/PikaVM.c
23
src/PikaVM.c
@ -922,6 +922,8 @@ void ByteCodeFrame_deinit(ByteCodeFrame* bf) {
|
|||||||
|
|
||||||
void instructArray_init(InstructArray* ia) {
|
void instructArray_init(InstructArray* ia) {
|
||||||
ia->arg_buff = arg_setNull(NULL);
|
ia->arg_buff = arg_setNull(NULL);
|
||||||
|
ia->size = 0;
|
||||||
|
ia->content_offset_now = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void instructArray_deinit(InstructArray* ia) {
|
void instructArray_deinit(InstructArray* ia) {
|
||||||
@ -930,6 +932,7 @@ void instructArray_deinit(InstructArray* ia) {
|
|||||||
|
|
||||||
void instructArray_append(InstructArray* ia, InstructUnit* iu) {
|
void instructArray_append(InstructArray* ia, InstructUnit* iu) {
|
||||||
ia->arg_buff = arg_append(ia->arg_buff, iu, sizeof(InstructUnit));
|
ia->arg_buff = arg_append(ia->arg_buff, iu, sizeof(InstructUnit));
|
||||||
|
ia->size += sizeof(InstructUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void instructUnit_init(InstructUnit* iu) {
|
void instructUnit_init(InstructUnit* iu) {
|
||||||
@ -968,9 +971,25 @@ char* instructUnit_getInstructStr(InstructUnit* self) {
|
|||||||
|
|
||||||
void instructUnit_print(InstructUnit* self) {
|
void instructUnit_print(InstructUnit* self) {
|
||||||
if (instructUnit_getIsNewLine(self)) {
|
if (instructUnit_getIsNewLine(self)) {
|
||||||
__platform_printf("B%d\n", instructUnit_getBlockDeepth(self));
|
__platform_printf("B%d\r\n", instructUnit_getBlockDeepth(self));
|
||||||
}
|
}
|
||||||
__platform_printf("%d %s #%d\n ", instructUnit_getInvokeDeepth(self),
|
__platform_printf("%d %s #%d\r\n", instructUnit_getInvokeDeepth(self),
|
||||||
instructUnit_getInstructStr(self),
|
instructUnit_getInstructStr(self),
|
||||||
self->const_pool_index);
|
self->const_pool_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void instructArray_print(InstructArray* self) {
|
||||||
|
uint16_t offset_befor = self->content_offset_now;
|
||||||
|
self->content_offset_now = 0;
|
||||||
|
while (1) {
|
||||||
|
InstructUnit* iu = instructArray_getNow(self);
|
||||||
|
if (NULL == iu) {
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
instructUnit_print(iu);
|
||||||
|
instructArray_getNext(self);
|
||||||
|
}
|
||||||
|
exit:
|
||||||
|
self->content_offset_now = offset_befor;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
11
src/PikaVM.h
11
src/PikaVM.h
@ -72,17 +72,17 @@ VMParameters* pikaVM_runAsm(PikaObj* self, char* pikaAsm);
|
|||||||
|
|
||||||
#define instructUnit_setBlockDeepth(self, val) \
|
#define instructUnit_setBlockDeepth(self, val) \
|
||||||
do { \
|
do { \
|
||||||
((self)->deepth) |= (0x0F & val); \
|
((self)->deepth) |= (0x0F & (val)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define instructUnit_setConstPoolIndex(self, val) \
|
#define instructUnit_setConstPoolIndex(self, val) \
|
||||||
do { \
|
do { \
|
||||||
((self)->const_pool_index = val); \
|
((self)->const_pool_index = (val)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define instructUnit_setInvokeDeepth(self, val) \
|
#define instructUnit_setInvokeDeepth(self, val) \
|
||||||
do { \
|
do { \
|
||||||
((self)->deepth) |= ((0x0F & val) << 4); \
|
((self)->deepth) |= ((0x0F & (val)) << 4); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -94,12 +94,12 @@ VMParameters* pikaVM_runAsm(PikaObj* self, char* pikaAsm);
|
|||||||
|
|
||||||
#define instructUnit_setInstruct(self, val) \
|
#define instructUnit_setInstruct(self, val) \
|
||||||
do { \
|
do { \
|
||||||
((self)->isNewLine_instruct) |= (0x7F & val); \
|
((self)->isNewLine_instruct) |= (0x7F & (val)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define instructUnit_setIsNewLine(self, val) \
|
#define instructUnit_setIsNewLine(self, val) \
|
||||||
do { \
|
do { \
|
||||||
((self)->isNewLine_instruct) |= ((0x01 & val) << 7); \
|
((self)->isNewLine_instruct) |= ((0x01 & (val)) << 7); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
InstructUnit* New_instructUnit(uint8_t data_size);
|
InstructUnit* New_instructUnit(uint8_t data_size);
|
||||||
@ -135,5 +135,6 @@ void instructArray_deinit(InstructArray* ia);
|
|||||||
void instructArray_append(InstructArray* ia, InstructUnit* iu);
|
void instructArray_append(InstructArray* ia, InstructUnit* iu);
|
||||||
void instructUnit_init(InstructUnit* iu);
|
void instructUnit_init(InstructUnit* iu);
|
||||||
void instructUnit_print(InstructUnit* self);
|
void instructUnit_print(InstructUnit* self);
|
||||||
|
void instructArray_print(InstructArray* self);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user