Skip to content

Commit

Permalink
fixed #257: fix a decl in const.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kray-G committed Mar 30, 2021
1 parent e5f5941 commit da857d6
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions src/ast_gencode.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@

static const kx_block_t kx_empty_block = {0};
static const kx_function_t kx_empty_func = {0};
static void apply_getvals(kx_context_t *ctx, kx_object_t *node, kx_analyze_t *ana, int jmp, int nested);
static void apply_getvals(kx_context_t *ctx, kx_object_t *node, kx_analyze_t *ana, int decl, int jmp, int nested);
static void gencode_ast(kx_context_t *ctx, kx_object_t *node, kx_analyze_t *ana, int lvalue);

static int new_function(kx_analyze_t *ana, kx_object_t *node)
Expand Down Expand Up @@ -376,19 +376,19 @@ if (code_size(module, ana) > 0) { \
} \
/**/

static int apply_getval(kx_context_t *ctx, kx_object_t *node, kx_analyze_t *ana, int jmp, int index, int nested)
static int apply_getval(kx_context_t *ctx, kx_object_t *node, kx_analyze_t *ana, int decl, int jmp, int index, int nested)
{
kx_module_t *module = ana->module;
if (!node) {
return index;
}
if (node->type == KXST_EXPRLIST) {
index = apply_getval(ctx, node->lhs, ana, jmp, index, nested);
index = apply_getval(ctx, node->rhs, ana, jmp, index, nested);
index = apply_getval(ctx, node->lhs, ana, decl, jmp, index, nested);
index = apply_getval(ctx, node->rhs, ana, decl, jmp, index, nested);
return index;
}
if (node->type == KXOP_CAST) {
return apply_getval(ctx, node->lhs, ana, jmp, index, nested);
return apply_getval(ctx, node->lhs, ana, decl, jmp, index, nested);
}
if (node->type == KXOP_KEYVALUE) {
kx_yyerror_line("Cannot use a key-value pair in array item", node->file, node->line);
Expand Down Expand Up @@ -440,8 +440,8 @@ static int apply_getval(kx_context_t *ctx, kx_object_t *node, kx_analyze_t *ana,
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_DUP }));
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_TYPEOF, .value1 = { .i = KX_ARY_T } }));
KX_CHECK_PATTERN_JMP(jmpblk, nested+1);
int idx = apply_getval(ctx, node->lhs, ana, jmp, 0, nested + 1);
(void)apply_getval(ctx, node->rhs, ana, jmp, idx, nested + 1);
int idx = apply_getval(ctx, node->lhs, ana, decl, jmp, 0, nested + 1);
(void)apply_getval(ctx, node->rhs, ana, decl, jmp, idx, nested + 1);
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_POP }));
break;
case KXOP_MKOBJ:
Expand All @@ -450,7 +450,7 @@ static int apply_getval(kx_context_t *ctx, kx_object_t *node, kx_analyze_t *ana,
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_DUP }));
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_TYPEOF, .value1 = { .i = KX_OBJ_T } }));
KX_CHECK_PATTERN_JMP(jmpblk, nested+1);
apply_getvals(ctx, node->lhs, ana, jmp, nested + 1);
apply_getvals(ctx, node->lhs, ana, decl, jmp, nested + 1);
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_POP }));
break;
case KXOP_MKRANGE:
Expand All @@ -463,7 +463,7 @@ static int apply_getval(kx_context_t *ctx, kx_object_t *node, kx_analyze_t *ana,
default:
if (!(node->type == KXOP_VAR && node->var_type == KX_UND_T)) {
// KXDC_CONST means with a pin operator.
if (node->optional == KXDC_CONST) {
if (!decl && node->optional == KXDC_CONST) {
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_DUP }));
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_APPLYVI, .value1.i = index }));
gencode_ast_hook(ctx, node, ana, 0);
Expand All @@ -483,15 +483,15 @@ static int apply_getval(kx_context_t *ctx, kx_object_t *node, kx_analyze_t *ana,
return index + 1;
}

static void apply_getvals(kx_context_t *ctx, kx_object_t *node, kx_analyze_t *ana, int jmp, int nested)
static void apply_getvals(kx_context_t *ctx, kx_object_t *node, kx_analyze_t *ana, int decl, int jmp, int nested)
{
kx_module_t *module = ana->module;
if (!node) {
return;
}
if (node->type == KXST_EXPRLIST) {
apply_getvals(ctx, node->lhs, ana, jmp, nested);
apply_getvals(ctx, node->rhs, ana, jmp, nested);
apply_getvals(ctx, node->lhs, ana, decl, jmp, nested);
apply_getvals(ctx, node->rhs, ana, decl, jmp, nested);
return;
}

Expand Down Expand Up @@ -544,8 +544,8 @@ static void apply_getvals(kx_context_t *ctx, kx_object_t *node, kx_analyze_t *an
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_DUP }));
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_TYPEOF, .value1 = { .i = KX_ARY_T } }));
KX_CHECK_PATTERN_JMP(jmpblk, nested+1);
int idx = apply_getval(ctx, value->lhs, ana, jmp, 0, nested + 1);
(void)apply_getval(ctx, value->rhs, ana, jmp, idx, nested + 1);
int idx = apply_getval(ctx, value->lhs, ana, decl, jmp, 0, nested + 1);
(void)apply_getval(ctx, value->rhs, ana, decl, jmp, idx, nested + 1);
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_POP }));
break;
}
Expand All @@ -555,7 +555,7 @@ static void apply_getvals(kx_context_t *ctx, kx_object_t *node, kx_analyze_t *an
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_DUP }));
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_TYPEOF, .value1 = { .i = KX_OBJ_T } }));
KX_CHECK_PATTERN_JMP(jmpblk, nested+1);
apply_getvals(ctx, value->lhs, ana, jmp, nested + 1);
apply_getvals(ctx, value->lhs, ana, decl, jmp, nested + 1);
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_POP }));
break;
case KXOP_MKRANGE:
Expand All @@ -567,7 +567,7 @@ static void apply_getvals(kx_context_t *ctx, kx_object_t *node, kx_analyze_t *an
break;
default:
// KXDC_CONST means with a pin operator.
if (value->optional == KXDC_CONST) {
if (!decl && value->optional == KXDC_CONST) {
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_DUP }));
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_APPLYVS, .value1.s = key }));
gencode_ast_hook(ctx, value, ana, 0);
Expand Down Expand Up @@ -1336,9 +1336,9 @@ LOOP_HEAD:;
}
}
if (node->lhs->type == KXOP_MKARY) {
apply_getval(ctx, node->lhs->lhs, ana, -1, 0, 0);
apply_getval(ctx, node->lhs->lhs, ana, 1, -1, 0, 0);
} else if (node->lhs->type == KXOP_MKOBJ) {
apply_getvals(ctx, node->lhs->lhs, ana, -1, 0);
apply_getvals(ctx, node->lhs->lhs, ana, 1, -1, 0);
} else {
gencode_ast_hook(ctx, node->lhs, ana, 1);
if ((code_size(module, ana) > 0) && last_op(ana) == KX_PUSHLV) {
Expand Down Expand Up @@ -1414,9 +1414,9 @@ LOOP_HEAD:;
}
}
if (node->lhs->type == KXOP_MKARY) {
apply_getval(ctx, node->lhs->lhs, ana, -1, 0, 0);
apply_getval(ctx, node->lhs->lhs, ana, 0, -1, 0, 0);
} else if (node->lhs->type == KXOP_MKOBJ) {
apply_getvals(ctx, node->lhs->lhs, ana, -1, 0);
apply_getvals(ctx, node->lhs->lhs, ana, 0, -1, 0);
} else {
gencode_ast_hook(ctx, node->lhs, ana, 1);
if ((code_size(module, ana) > 0) && last_op(ana) == KX_PUSHLV) {
Expand Down Expand Up @@ -1757,15 +1757,15 @@ LOOP_HEAD:;
get_block(module, chklen_block)->tf[0] = ana->block;
}
if (last || exblk < 0) {
apply_getval(ctx, cond->lhs, ana, next, 0, 1);
apply_getval(ctx, cond->lhs, ana, 0, next, 0, 1);
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE_OF(cond, ana), .op = KX_POP }));
get_block(module, curblk)->tf[1] = next;
if (chklen_block > 0) {
get_block(module, chklen_block)->tf[1] = next;
}
} else {
int nc = new_block_hook(ana);
apply_getval(ctx, cond->lhs, ana, nc, 0, 1);
apply_getval(ctx, cond->lhs, ana, 0, nc, 0, 1);
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE_OF(cond, ana), .op = KX_POP }));
get_block(module, ana->block)->tf[0] = exblk;
get_block(module, curblk)->tf[1] = nc;
Expand All @@ -1784,12 +1784,12 @@ LOOP_HEAD:;
get_block(module, curblk)->tf[0] = ana->block;

if (last || exblk < 0) {
apply_getvals(ctx, cond->lhs, ana, next, 1);
apply_getvals(ctx, cond->lhs, ana, 0, next, 1);
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE_OF(cond, ana), .op = KX_POP }));
get_block(module, curblk)->tf[1] = next;
} else {
int nc = new_block_hook(ana);
apply_getvals(ctx, cond->lhs, ana, nc, 1);
apply_getvals(ctx, cond->lhs, ana, 0, nc, 1);
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE_OF(cond, ana), .op = KX_POP }));
get_block(module, ana->block)->tf[0] = exblk;
get_block(module, curblk)->tf[1] = nc;
Expand Down

0 comments on commit da857d6

Please sign in to comment.