clean stack when match new line

This commit is contained in:
lyon1998 2022-03-29 22:32:20 +08:00
parent 8116f4f48b
commit 60514571b6
4 changed files with 19 additions and 4 deletions

View File

@ -35,7 +35,8 @@
#include "dataStrs.h"
Arg* arg_setMetaObj(char* objName, char* className, NewFun objPtr) {
Args buffs = {0}; Arg* argNew = New_arg(NULL);
Args buffs = {0};
Arg* argNew = New_arg(NULL);
/* m means mate-object */
argNew = arg_setPtr(argNew, objName, ARG_TYPE_MATE_OBJECT, (void*)objPtr);
strsDeinit(&buffs);
@ -69,7 +70,7 @@ static void print_no_end(PikaObj* self, Args* args) {
__platform_printf("%s", res);
}
void print(PikaObj* self, Args* args) {
void baseobj_print(PikaObj* self, Args* args) {
obj_setErrorCode(self, 0);
char* res = args_print(args, "val");
if (NULL == res) {
@ -88,7 +89,7 @@ void print(PikaObj* self, Args* args) {
PikaObj* New_BaseObj(Args* args) {
PikaObj* self = New_TinyObj(args);
class_defineMethod(self, "print(val:any)", print);
class_defineMethod(self, "print(val:any)", baseobj_print);
class_defineMethod(self, "printNoEnd(val:any)", print_no_end);
return self;
}

View File

@ -41,6 +41,6 @@ int32_t obj_newObj(PikaObj* self,
char* className,
NewFun newFunPtr);
Arg* arg_setMetaObj(char* objName, char* className, NewFun objPtr);
void baseobj_print(PikaObj* self, Args* args);
#endif

View File

@ -1138,6 +1138,19 @@ VMParameters* pikaVM_runByteCodeWithState(PikaObj* self,
break;
}
InstructUnit* this_ins_unit = VMState_getInstructNow(&vs);
if (instructUnit_getIsNewLine(this_ins_unit)) {
for (int8_t i = 0; i < stack_getTop(vs.stack); i++) {
// Args print_args = {0};
// Arg* print_arg = stack_popArg(vs.stack);
// arg_setName(print_arg, "val");
// args_setArg(&print_args, print_arg);
// if (ARG_TYPE_NONE != arg_getType(print_arg)) {
// baseobj_print(self, &print_args);
// }
// args_deinit_stack(&print_args);
arg_deinit(stack_popArg(vs.stack));
}
}
vs.pc = pikaVM_runInstructUnit(self, &vs, this_ins_unit);
if (0 != vs.error_code) {
InstructUnit* head_ins_unit = this_ins_unit;

View File

@ -312,3 +312,4 @@ void arg_deinit(Arg* self) {
}
arg_freeContent(self);
}