From 3f9d37a8587d7b2eefad38d82ed15629ee7fdc07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Mon, 5 May 2014 20:16:41 +0000 Subject: [PATCH] [INTERPRETER] * BUG: Correctly drop arguments when using the new '...' symbol syntax. [COMPILER] * BUG: Correctly drop arguments when using the new '...' symbol syntax. git-svn-id: svn://localhost/gambas/trunk@6252 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- main/gbc/gbc_trans_expr.c | 9 +++++++++ main/gbx/gbx_exec.c | 10 ++++++++++ main/gbx/gbx_exec.h | 1 + main/gbx/gbx_exec_loop.c | 11 +++++++++-- main/share/gb_code.h | 2 ++ main/share/gb_code_temp.h | 13 +++++++++++-- main/share/gb_pcode.h | 1 + 7 files changed, 43 insertions(+), 4 deletions(-) diff --git a/main/gbc/gbc_trans_expr.c b/main/gbc/gbc_trans_expr.c index b2a5ff121..657f689e1 100644 --- a/main/gbc/gbc_trans_expr.c +++ b/main/gbc/gbc_trans_expr.c @@ -39,6 +39,8 @@ //static bool _accept_statement = FALSE; +static bool _must_drop_vargs = FALSE; + static short get_nparam(PATTERN *tree, int count, int *pindex, uint64_t *byref) { PATTERN pattern; @@ -325,6 +327,12 @@ static void trans_call(short nparam, uint64_t byref) } CODE_call_byref(nparam, byref); + + if (_must_drop_vargs) + { + CODE_drop_vargs(); + _must_drop_vargs = FALSE; + } } static void trans_expr_from_tree(TRANS_TREE *tree, int count) @@ -426,6 +434,7 @@ static void trans_expr_from_tree(TRANS_TREE *tree, int count) } else if (PATTERN_is(pattern, RS_3PTS)) { + _must_drop_vargs = TRUE; CODE_push_vargs(); } else diff --git a/main/gbx/gbx_exec.c b/main/gbx/gbx_exec.c index b8462d21e..0d74d20cf 100644 --- a/main/gbx/gbx_exec.c +++ b/main/gbx/gbx_exec.c @@ -2031,3 +2031,13 @@ void EXEC_push_vargs(void) PUSH(); } } + +void EXEC_drop_vargs(void) +{ + int nargs = (FP && FP->vararg) ? BP - PP : 0; + + if (nargs == 0) + return; + + RELEASE_MANY(SP, nargs); +} diff --git a/main/gbx/gbx_exec.h b/main/gbx/gbx_exec.h index ae1c352ea..123fa4014 100644 --- a/main/gbx/gbx_exec.h +++ b/main/gbx/gbx_exec.h @@ -230,6 +230,7 @@ void RELEASE_many(VALUE *val, int n); void EXEC_push_complex(void); void EXEC_push_vargs(void); +void EXEC_drop_vargs(void); #define BORROW(_value) \ do { \ diff --git a/main/gbx/gbx_exec_loop.c b/main/gbx/gbx_exec_loop.c index 476877d3e..22113220a 100644 --- a/main/gbx/gbx_exec_loop.c +++ b/main/gbx/gbx_exec_loop.c @@ -786,7 +786,8 @@ _PUSH_MISC: { static const void *_jump[] = - { &&__PUSH_NULL, &&__PUSH_VOID, &&__PUSH_FALSE, &&__PUSH_TRUE, &&__PUSH_LAST, &&__PUSH_STRING, &&__PUSH_PINF, &&__PUSH_MINF, &&__PUSH_COMPLEX, &&__PUSH_VARGS }; + { &&__PUSH_NULL, &&__PUSH_VOID, &&__PUSH_FALSE, &&__PUSH_TRUE, &&__PUSH_LAST, &&__PUSH_STRING, &&__PUSH_PINF, &&__PUSH_MINF, &&__PUSH_COMPLEX, + &&__PUSH_VARGS, &&__PUSH_DROP_VARGS }; //, &&__POP_LAST }; goto *_jump[GET_UX()]; @@ -854,9 +855,15 @@ _PUSH_MISC: goto _NEXT; __PUSH_VARGS: + EXEC_push_vargs(); goto _NEXT; - + + __PUSH_DROP_VARGS: + + EXEC_drop_vargs(); + goto _NEXT; + /*__POP_LAST: VALUE_conv(&SP[-1], T_OBJECT); diff --git a/main/share/gb_code.h b/main/share/gb_code.h index fdc1180bb..f26aba8de 100644 --- a/main/share/gb_code.h +++ b/main/share/gb_code.h @@ -125,7 +125,9 @@ void CODE_push_void_string(); void CODE_push_boolean(bool value); void CODE_push_inf(bool neg); void CODE_push_complex(); + void CODE_push_vargs(); +void CODE_drop_vargs(); void CODE_dup(void); diff --git a/main/share/gb_code_temp.h b/main/share/gb_code_temp.h index 261e421a4..323a8c3f9 100644 --- a/main/share/gb_code_temp.h +++ b/main/share/gb_code_temp.h @@ -1358,8 +1358,6 @@ void CODE_push_vargs(void) { LAST_CODE; - use_stack(0); - #ifdef DEBUG printf("PUSH VARGS\n"); #endif @@ -1367,6 +1365,17 @@ void CODE_push_vargs(void) write_ZZxx(C_PUSH_MISC, CPM_VARGS); } +void CODE_drop_vargs(void) +{ + LAST_CODE; + + #ifdef DEBUG + printf("DROP VARGS\n"); + #endif + + write_ZZxx(C_PUSH_MISC, CPM_DROP_VARGS); +} + #ifdef CODE_DUMP void CODE_dump(PCODE *code, int count) diff --git a/main/share/gb_pcode.h b/main/share/gb_pcode.h index 38a25d64c..28d530884 100644 --- a/main/share/gb_pcode.h +++ b/main/share/gb_pcode.h @@ -78,6 +78,7 @@ #define CPM_MINF 7 #define CPM_COMPLEX 8 #define CPM_VARGS 9 +#define CPM_DROP_VARGS 10 #define C_TRY 0x1600 #define C_END_TRY 0x1700