mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
befor add native_method
This commit is contained in:
parent
8d84cb6423
commit
c2a459a0ab
@ -1259,3 +1259,25 @@ TEST(pikaMain, for_if_continue_byte_code) {
|
|||||||
/* mem check */
|
/* mem check */
|
||||||
EXPECT_EQ(pikaMemNow(), 0);
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TEST(pikaMain, print_in_def_byte_code) {
|
||||||
|
// /* init */
|
||||||
|
// pikaMemInfo.heapUsedMax = 0;
|
||||||
|
// PikaObj* pikaMain = newRootObj((char*)"pikaMain", New_PikaMain);
|
||||||
|
// /* run */
|
||||||
|
// __platform_printf((char*)"BEGIN\r\n");
|
||||||
|
// pikaVM_run_enableByteCode(pikaMain, (char*)
|
||||||
|
// "def test_print():\n"
|
||||||
|
// " print('test')\n"
|
||||||
|
// "test_print()\n"
|
||||||
|
// );
|
||||||
|
// /* collect */
|
||||||
|
// /* assert */
|
||||||
|
// /* should only print once, so the second log (log_buff[1]) shuold be '\0' */
|
||||||
|
// EXPECT_STREQ(log_buff[0], "test\r\n");
|
||||||
|
// EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
||||||
|
// /* deinit */
|
||||||
|
// obj_deinit(pikaMain);
|
||||||
|
// /* mem check */
|
||||||
|
// EXPECT_EQ(pikaMemNow(), 0);
|
||||||
|
// }
|
||||||
|
44
src/PikaVM.c
44
src/PikaVM.c
@ -698,18 +698,42 @@ static Arg* VM_instruction_handler_DEF(PikaObj* self, VMState* vs, char* data) {
|
|||||||
is_in_class = 1;
|
is_in_class = 1;
|
||||||
}
|
}
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
while (1) {
|
if (vs->ASM_start == NULL) {
|
||||||
if ((methodPtr[0] == 'B') &&
|
/* byteCode */
|
||||||
(methodPtr[1] - '0' == thisBlockDeepth + 1)) {
|
while (1) {
|
||||||
if (is_in_class) {
|
InstructUnit* ins_unit_now =
|
||||||
class_defineObjectMethod(hostObj, data, (Method)methodPtr);
|
instructArray_getByOffset(vs->ins_array, vs->pc_i + offset);
|
||||||
} else {
|
if (!instructUnit_getIsNewLine(ins_unit_now)) {
|
||||||
class_defineMethod(hostObj, data, (Method)methodPtr);
|
offset += instructUnit_getSize();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
if (instructUnit_getBlockDeepth(ins_unit_now) ==
|
||||||
|
thisBlockDeepth + 1) {
|
||||||
|
if (is_in_class) {
|
||||||
|
class_defineObjectMethod(hostObj, data,
|
||||||
|
(Method)ins_unit_now);
|
||||||
|
} else {
|
||||||
|
class_defineMethod(hostObj, data, (Method)ins_unit_now);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
offset += instructUnit_getSize();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* Asm */
|
||||||
|
while (1) {
|
||||||
|
if ((methodPtr[0] == 'B') &&
|
||||||
|
(methodPtr[1] - '0' == thisBlockDeepth + 1)) {
|
||||||
|
if (is_in_class) {
|
||||||
|
class_defineObjectMethod(hostObj, data, (Method)methodPtr);
|
||||||
|
} else {
|
||||||
|
class_defineMethod(hostObj, data, (Method)methodPtr);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
offset += __gotoNextLine(methodPtr);
|
||||||
|
methodPtr = vs->pc + offset;
|
||||||
}
|
}
|
||||||
offset += __gotoNextLine(methodPtr);
|
|
||||||
methodPtr = vs->pc + offset;
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user