diff --git a/ChangeLog.md b/ChangeLog.md index 84e80406..3266920f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -22,6 +22,7 @@ * #272: Supported a binary mode in HTTP. * #273: Supported `read`/`write` in `File`. * #290: Supported `chmod` in `File`. + * #308: Improvement of the stack usage. * Small improvements and enhancements as follows without managing by issues. * Supported SemanticVersion class with `using SemanticVersion;`. * Supported putting a comma at the end of an argument's list for both declaration and calling. diff --git a/ChangeLog_v1.0.x.md b/ChangeLog_v1.0.x.md index fe90be67..703b1b4c 100644 --- a/ChangeLog_v1.0.x.md +++ b/ChangeLog_v1.0.x.md @@ -2,6 +2,10 @@ ## V1.0.3 (Current Development Version) +* Improvements + * #308: Improvement of the stack usage. + * Some feedbacks from V1.1.0. + * Supported putting a comma at the end of an argument's list for both declaration and calling. * Bug Fixed * #302: Fixed a prblem of the string optimization. * #305: Fixed a prblem of no POPC in try. diff --git a/include/kxastobject.h b/include/kxastobject.h index 8a7f5cbc..24b9173c 100644 --- a/include/kxastobject.h +++ b/include/kxastobject.h @@ -61,6 +61,7 @@ extern kx_object_t *kx_gen_texpr_object(kx_object_t *lhs, kx_object_t *rhs, kx_o extern kx_object_t *kx_gen_stmt_object(int type, kx_object_t *lhs, kx_object_t *rhs, kx_object_t *ex); extern kx_object_t *kx_gen_stmt_object_line(int type, kx_object_t *lhs, kx_object_t *rhs, kx_object_t *ex, int line); extern kx_object_t *kx_gen_modifier(kx_object_t *modifier, kx_object_t *stmt); +extern kx_object_t *kx_gen_try_stmt_object(kx_object_t *lhs, kx_object_t *rhs, kx_object_t *ex); extern kx_object_t *kx_gen_case_stmt_object(int optional, kx_object_t *lhs); extern kx_object_t *kx_gen_break_object(int type, const char *name); extern kx_object_t *kx_gen_label_object(int type, const char *name, kx_object_t *lhs); diff --git a/src/ast_object.c b/src/ast_object.c index f6433da4..cca1f407 100644 --- a/src/ast_object.c +++ b/src/ast_object.c @@ -628,6 +628,11 @@ kx_object_t *kx_gen_modifier(kx_object_t *modifier, kx_object_t *stmt) return stmt; } +kx_object_t *kx_gen_try_stmt_object(kx_object_t *lhs, kx_object_t *rhs, kx_object_t *ex) +{ + return kx_gen_stmt_object(KXST_TRY, lhs, rhs, ex ? ex : kx_gen_block_object(NULL)); +} + kx_object_t *kx_gen_case_stmt_object(int optional, kx_object_t *lhs) { return kx_gen_obj(KXST_CASE, optional, lhs, NULL, NULL); diff --git a/src/kinx.y b/src/kinx.y index 5d726fb2..57ff3399 100644 --- a/src/kinx.y +++ b/src/kinx.y @@ -337,7 +337,7 @@ ForInVariable ; TryCatchStatement - : TRY BlockStatement CatchStatement_Opt FinallyStatement_Opt { $$ = kx_gen_stmt_object(KXST_TRY, $2, $3, $4); } + : TRY BlockStatement CatchStatement_Opt FinallyStatement_Opt { $$ = kx_gen_try_stmt_object($2, $3, $4); } ; CatchStatement_Opt @@ -351,8 +351,8 @@ CatchVariable ; FinallyStatement_Opt - : { $$ = kx_gen_block_object(NULL); } - | FINALLY BlockStatement { $$ = ($2 == NULL) ? kx_gen_block_object(NULL) : $2; } + : { $$ = NULL; } + | FINALLY BlockStatement { $$ = $2; } ; BreakStatement diff --git a/src/parser.c b/src/parser.c index 1572dc8f..b9d2593d 100644 --- a/src/parser.c +++ b/src/parser.c @@ -2139,7 +2139,7 @@ int yyparse(YYPARSE_ARG) { yyval.obj = kx_gen_forin_object(YYASP(4-8).obj, YYASP(6-8).obj, YYASP(8-8).obj, 1); } break; case 78: #line 340 "src/kinx.y" -{ yyval.obj = kx_gen_stmt_object(KXST_TRY, YYASP(2-4).obj, YYASP(3-4).obj, YYASP(4-4).obj); } break; +{ yyval.obj = kx_gen_try_stmt_object(YYASP(2-4).obj, YYASP(3-4).obj, YYASP(4-4).obj); } break; case 79: #line 344 "src/kinx.y" { yyval.obj = NULL; } break; @@ -2154,10 +2154,10 @@ int yyparse(YYPARSE_ARG) { yyval.obj = kx_gen_var_object_line_pos(YYASP(2-3).strinfo.name, KX_UNKNOWN_T, YYASP(2-3).strinfo.line, YYASP(2-3).strinfo.pos1, YYASP(2-3).strinfo.pos2); } break; case 83: #line 354 "src/kinx.y" -{ yyval.obj = kx_gen_block_object(NULL); } break; +{ yyval.obj = NULL; } break; case 84: #line 355 "src/kinx.y" -{ yyval.obj = (YYASP(2-2).obj == NULL) ? kx_gen_block_object(NULL) : YYASP(2-2).obj; } break; +{ yyval.obj = YYASP(2-2).obj; } break; case 85: #line 359 "src/kinx.y" { yyval.obj = kx_gen_modifier(YYASP(2-3).obj, kx_gen_break_object(KXST_BREAK, NULL)); } break;