mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
byteCodeFrame_print is ok
This commit is contained in:
parent
e73a8d2950
commit
eb35a8c536
@ -2133,6 +2133,9 @@ TEST(asmer, asmer_to_instructUnit) {
|
||||
byteCodeFrame_init(&bytecode_frame);
|
||||
byteCodeFrame_appendFromAsm(&bytecode_frame, asm_line);
|
||||
constPool_print(&(bytecode_frame.const_pool));
|
||||
instructArray_print(&(bytecode_frame.instruct_array));
|
||||
size_t byteCode_size = byteCodeFrame_getSize(&bytecode_frame);
|
||||
EXPECT_EQ(byteCode_size, 33);
|
||||
EXPECT_STREQ(constPool_getNext(&(bytecode_frame.const_pool)), (char*)"2");
|
||||
EXPECT_STREQ(constPool_getNext(&(bytecode_frame.const_pool)), (char*)"3");
|
||||
EXPECT_STREQ(constPool_getNext(&(bytecode_frame.const_pool)), (char*)"add");
|
||||
|
@ -1553,7 +1553,7 @@ ByteCodeFrame* byteCodeFrame_appendFromAsm(ByteCodeFrame* self, char* pikaAsm) {
|
||||
}
|
||||
|
||||
/* append instructUnit to instructArray */
|
||||
instructArray_append(&(self->Instruct_array), &ins_unit);
|
||||
instructArray_append(&(self->instruct_array), &ins_unit);
|
||||
|
||||
/* load const to const pool buff */
|
||||
char* data = line + 6;
|
||||
|
@ -914,12 +914,12 @@ exit:
|
||||
|
||||
void byteCodeFrame_init(ByteCodeFrame* self) {
|
||||
constPool_init(&(self->const_pool));
|
||||
instructArray_init(&(self->Instruct_array));
|
||||
instructArray_init(&(self->instruct_array));
|
||||
}
|
||||
|
||||
void byteCodeFrame_deinit(ByteCodeFrame* self) {
|
||||
constPool_deinit(&(self->const_pool));
|
||||
instructArray_deinit(&(self->Instruct_array));
|
||||
instructArray_deinit(&(self->instruct_array));
|
||||
}
|
||||
|
||||
void instructArray_init(InstructArray* ins_array) {
|
||||
@ -996,3 +996,7 @@ exit:
|
||||
self->content_offset_now = offset_befor;
|
||||
return;
|
||||
}
|
||||
|
||||
size_t byteCodeFrame_getSize(ByteCodeFrame* bf){
|
||||
return bf->const_pool.size + bf->instruct_array.size;
|
||||
}
|
||||
|
20
src/PikaVM.h
20
src/PikaVM.h
@ -55,7 +55,7 @@ typedef struct InstructArray_t {
|
||||
|
||||
typedef struct ByteCodeFrame_t {
|
||||
ConstPool const_pool;
|
||||
InstructArray Instruct_array;
|
||||
InstructArray instruct_array;
|
||||
} ByteCodeFrame;
|
||||
|
||||
VMParameters* pikaVM_run(PikaObj* self, char* pyLine);
|
||||
@ -72,16 +72,16 @@ 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 { \
|
||||
#define instructUnit_setInvokeDeepth(self, val) \
|
||||
do { \
|
||||
((self)->deepth) |= ((0x0F & (val)) << 4); \
|
||||
} while (0)
|
||||
|
||||
@ -92,13 +92,13 @@ VMParameters* pikaVM_runAsm(PikaObj* self, char* pikaAsm);
|
||||
} while (0)
|
||||
*/
|
||||
|
||||
#define instructUnit_setInstruct(self, val) \
|
||||
do { \
|
||||
#define instructUnit_setInstruct(self, val) \
|
||||
do { \
|
||||
((self)->isNewLine_instruct) |= (0x7F & (val)); \
|
||||
} while (0)
|
||||
|
||||
#define instructUnit_setIsNewLine(self, val) \
|
||||
do { \
|
||||
#define instructUnit_setIsNewLine(self, val) \
|
||||
do { \
|
||||
((self)->isNewLine_instruct) |= ((0x01 & (val)) << 7); \
|
||||
} while (0)
|
||||
|
||||
@ -130,6 +130,8 @@ void constPool_print(ConstPool* self);
|
||||
|
||||
void byteCodeFrame_init(ByteCodeFrame* bf);
|
||||
void byteCodeFrame_deinit(ByteCodeFrame* bf);
|
||||
size_t byteCodeFrame_getSize(ByteCodeFrame* bf);
|
||||
|
||||
void instructArray_init(InstructArray* ins_array);
|
||||
void instructArray_deinit(InstructArray* ins_array);
|
||||
void instructArray_append(InstructArray* ins_array, InstructUnit* ins_unit);
|
||||
|
Loading…
x
Reference in New Issue
Block a user