instructArray print is ok

This commit is contained in:
lyon1998 2022-03-13 12:01:25 +08:00
parent 87c30b2cb3
commit 8d5ba40b14
3 changed files with 37 additions and 8 deletions

View File

@ -770,6 +770,7 @@ TEST(VM, nag_a) {
}
TEST(InstructUnit, base) {
__platform_printf((char*)"BEGIN\r\n");
InstructUnit bu;
instructUnit_init(&bu);
instructUnit_setBlockDeepth(&bu, 2);
@ -785,6 +786,10 @@ TEST(InstructUnit, base) {
EXPECT_EQ(instructUnit_getConstPoolIndex(&bu), 12);
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_) {
@ -833,6 +838,7 @@ TEST(ConstPool, get) {
}
TEST(InstructArray, set) {
__platform_printf((char*)"BEGIN\r\n");
InstructArray ia;
InstructUnit bu;
instructUnit_init(&bu);
@ -844,7 +850,10 @@ TEST(InstructArray, set) {
instructArray_init(&ia);
instructArray_append(&ia, &bu);
instructArray_print(&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);
}

View File

@ -922,6 +922,8 @@ void ByteCodeFrame_deinit(ByteCodeFrame* bf) {
void instructArray_init(InstructArray* ia) {
ia->arg_buff = arg_setNull(NULL);
ia->size = 0;
ia->content_offset_now = 0;
}
void instructArray_deinit(InstructArray* ia) {
@ -930,6 +932,7 @@ void instructArray_deinit(InstructArray* ia) {
void instructArray_append(InstructArray* ia, InstructUnit* iu) {
ia->arg_buff = arg_append(ia->arg_buff, iu, sizeof(InstructUnit));
ia->size += sizeof(InstructUnit);
}
void instructUnit_init(InstructUnit* iu) {
@ -968,9 +971,25 @@ char* instructUnit_getInstructStr(InstructUnit* self) {
void instructUnit_print(InstructUnit* 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),
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;
}

View File

@ -72,17 +72,17 @@ VMParameters* pikaVM_runAsm(PikaObj* self, char* pikaAsm);
#define instructUnit_setBlockDeepth(self, val) \
do { \
((self)->deepth) |= (0x0F & val); \
((self)->deepth) |= (0x0F & (val)); \
} while (0)
#define instructUnit_setConstPoolIndex(self, val) \
do { \
((self)->const_pool_index = val); \
((self)->const_pool_index = (val)); \
} while (0)
#define instructUnit_setInvokeDeepth(self, val) \
do { \
((self)->deepth) |= ((0x0F & val) << 4); \
((self)->deepth) |= ((0x0F & (val)) << 4); \
} while (0)
/*
@ -94,12 +94,12 @@ VMParameters* pikaVM_runAsm(PikaObj* self, char* pikaAsm);
#define instructUnit_setInstruct(self, val) \
do { \
((self)->isNewLine_instruct) |= (0x7F & val); \
((self)->isNewLine_instruct) |= (0x7F & (val)); \
} while (0)
#define instructUnit_setIsNewLine(self, val) \
do { \
((self)->isNewLine_instruct) |= ((0x01 & val) << 7); \
((self)->isNewLine_instruct) |= ((0x01 & (val)) << 7); \
} while (0)
InstructUnit* New_instructUnit(uint8_t data_size);
@ -135,5 +135,6 @@ void instructArray_deinit(InstructArray* ia);
void instructArray_append(InstructArray* ia, InstructUnit* iu);
void instructUnit_init(InstructUnit* iu);
void instructUnit_print(InstructUnit* self);
void instructArray_print(InstructArray* self);
#endif