mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +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 */
|
||||
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);
|
||||
// }
|
||||
|
24
src/PikaVM.c
24
src/PikaVM.c
@ -698,6 +698,29 @@ static Arg* VM_instruction_handler_DEF(PikaObj* self, VMState* vs, char* data) {
|
||||
is_in_class = 1;
|
||||
}
|
||||
int offset = 0;
|
||||
if (vs->ASM_start == NULL) {
|
||||
/* byteCode */
|
||||
while (1) {
|
||||
InstructUnit* ins_unit_now =
|
||||
instructArray_getByOffset(vs->ins_array, vs->pc_i + offset);
|
||||
if (!instructUnit_getIsNewLine(ins_unit_now)) {
|
||||
offset += instructUnit_getSize();
|
||||
continue;
|
||||
}
|
||||
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)) {
|
||||
@ -711,6 +734,7 @@ static Arg* VM_instruction_handler_DEF(PikaObj* self, VMState* vs, char* data) {
|
||||
offset += __gotoNextLine(methodPtr);
|
||||
methodPtr = vs->pc + offset;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user