OUT for keyword pars is ok

This commit is contained in:
pikastech 2022-08-28 22:12:07 +08:00
parent d56aec5f7f
commit abe576d9e5
3 changed files with 44 additions and 8 deletions

View File

@ -4000,3 +4000,23 @@ TEST(parser, issues_I5OJQB) {
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(parser, keyword1) {
pikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines = "test(a=1, b ='test')";
__platform_printf("%s\n", lines);
char* pikaAsm = Parser_linesToAsm(buffs, lines);
__platform_printf("%s", pikaAsm);
EXPECT_STREQ(pikaAsm,
"B0\n"
"1 NUM 1\n"
"1 OUT a\n"
"1 STR test\n"
"1 OUT b\n"
"0 RUN test\n"
"B0\n");
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}

View File

@ -69,6 +69,12 @@ static int VMState_getBlockDeepthNow(VMState* vm) {
return instructUnit_getBlockDeepth(ins_unit);
}
static int VMState_getInvokeDeepthNow(VMState* vm) {
/* support run byteCode */
InstructUnit* ins_unit = VMState_getInstructNow(vm);
return instructUnit_getInvokeDeepth(ins_unit);
}
static char* VMState_getConstWithInstructUnit(VMState* vm,
InstructUnit* ins_unit) {
return constPool_getByOffset(&(vm->bytecode_frame->const_pool),
@ -1085,10 +1091,18 @@ static Arg* VM_instruction_handler_OUT(PikaObj* self,
char* data,
Arg* arg_ret_reg) {
arg_newReg(outArg_reg, PIKA_ARG_BUFF_SIZE);
Arg* outArg = stack_popArg(&vm->stack, &outArg_reg);
// Arg* outArg = stack_popArg_alloc(&vm->stack);
ArgType outArg_type = arg_getType(outArg);
if (VMState_getInvokeDeepthNow(vm) > 0) {
/* in block, is a keyword arg */
arg_setIsKeyword(outArg, PIKA_TRUE);
arg_setName(outArg, data);
return arg_copy_noalloc(outArg, arg_ret_reg);
}
if (_checkLReg(data)) {
uint8_t index = _getLRegIndex(data);
if (argType_isObject(outArg_type)) {
@ -1196,8 +1210,7 @@ static Arg* VM_instruction_handler_JEZ(PikaObj* self,
VMState* vm,
char* data,
Arg* arg_ret_reg) {
int thisBlockDeepth;
thisBlockDeepth = VMState_getBlockDeepthNow(vm);
int thisBlockDeepth = VMState_getBlockDeepthNow(vm);
int jmp_expect = fast_atoi(data);
arg_newReg(pika_assertArg_reg, PIKA_ARG_BUFF_SIZE);
Arg* pika_assertArg = stack_popArg(&(vm->stack), &pika_assertArg_reg);
@ -1235,6 +1248,9 @@ static uint8_t VMState_getInputArgNum(VMState* vm) {
break;
}
if (invode_deepth == invoke_deepth_this + 1) {
if (instructUnit_getInstruct(ins_unit_now) == OUT) {
continue;
}
num++;
}
if (instructUnit_getIsNewLine(ins_unit_now)) {

View File

@ -61,12 +61,12 @@ typedef union {
uint8_t* buffer;
} _arg_union;
struct Arg {
_arg_union _;
uint32_t size;
uint8_t type;
PIKA_BOOL serialized;
Hash name_hash;
uint8_t content[];
_arg_union _; // 32/64 bit
uint32_t size; // 32 bit
uint8_t type; // 8 bit
uint32_t flag; //
Hash name_hash; // 32bit
uint8_t content[]; // n bit
};
Arg* arg_getNext(Arg* self);