From 337e7c93299e5a73dc0ada909ea93d2fe0ad8800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Sun, 18 May 2014 13:18:32 +0000 Subject: [PATCH] [COMPILER] * OPT: Write in the bytecode file if a function uses the IsMissing() native routine. [INTERPRETER] * OPT: Don't use a stack slot for missing arguments if the IsMissing() function is not used. git-svn-id: svn://localhost/gambas/trunk@6274 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- main/gbc/gbc_class.h | 3 ++- main/gbc/gbc_output.c | 9 ++++++++- main/gbc/gbc_trans_expr.c | 1 + main/gbx/gbx_class.h | 14 +++++++++++++- main/gbx/gbx_class_load.c | 11 +++++++++-- main/gbx/gbx_class_load.h | 2 +- main/gbx/gbx_exec.c | 2 +- 7 files changed, 35 insertions(+), 7 deletions(-) diff --git a/main/gbc/gbc_class.h b/main/gbc/gbc_class.h index bb86ac9ad..b952942b7 100644 --- a/main/gbc/gbc_class.h +++ b/main/gbc/gbc_class.h @@ -92,7 +92,8 @@ typedef char npmin; // Minimum number of arguments unsigned vararg : 1; // If this function accepts extra arguments unsigned fast : 1; // If this function is jit compiled - unsigned _reserved : 14; + unsigned use_is_missing : 1; // If this function uses IsMissing() + unsigned _reserved : 13; short nlocal; // Local variable count short nctrl; // Control structure variable count diff --git a/main/gbc/gbc_output.c b/main/gbc/gbc_output.c index 007bde7f9..a1baede64 100644 --- a/main/gbc/gbc_output.c +++ b/main/gbc/gbc_output.c @@ -800,6 +800,7 @@ static void output_method(void) { int i, n; FUNCTION *func; + uchar flag; /*SYMBOL *sym;*/ n = ARRAY_count(Class->function); @@ -814,7 +815,13 @@ static void output_method(void) write_byte(func->nparam); write_byte(func->npmin); write_byte(func->vararg); - write_byte(func->fast || Class->all_fast); + + flag = func->fast || Class->all_fast; + if (func->use_is_missing) + flag += 2; + + write_byte(flag); + write_short(func->nlocal); write_short(func->nctrl); write_short(func->stack); diff --git a/main/gbc/gbc_trans_expr.c b/main/gbc/gbc_trans_expr.c index 7a44eccee..20596f927 100644 --- a/main/gbc/gbc_trans_expr.c +++ b/main/gbc/gbc_trans_expr.c @@ -271,6 +271,7 @@ static void trans_subr(int subr, short nparam) } else if (subr == SUBR_IsMissing) { + JOB->func->use_is_missing = TRUE; if (CODE_check_ismissing()) THROW("IsMissing() requires a function argument"); } diff --git a/main/gbx/gbx_class.h b/main/gbx/gbx_class.h index e7a862a94..ba8ca77c7 100644 --- a/main/gbx/gbx_class.h +++ b/main/gbx/gbx_class.h @@ -101,7 +101,8 @@ typedef char vararg; unsigned fast : 1; unsigned optional : 1; - unsigned _reserved : 6; + unsigned use_is_missing : 1; + unsigned _reserved : 5; short n_local; short n_ctrl; short stack_usage; @@ -114,6 +115,17 @@ typedef PACKED FUNCTION; +typedef + struct { + TYPE type; + char n_param; + char npmin; + char vararg; + unsigned char flag; + } + PACKED + FUNCTION_FLAG; + typedef struct { TYPE type; diff --git a/main/gbx/gbx_class_load.c b/main/gbx/gbx_class_load.c index 02f8b2f9d..693080a57 100644 --- a/main/gbx/gbx_class_load.c +++ b/main/gbx/gbx_class_load.c @@ -496,6 +496,7 @@ static void load_and_relocate(CLASS *class, int len_data, CLASS_DESC **pstart, i char *name; int len; bool have_jit_functions = FALSE; + uchar flag; ALLOC_ZERO(&class->load, sizeof(CLASS_LOAD)); @@ -576,6 +577,13 @@ static void load_and_relocate(CLASS *class, int len_data, CLASS_DESC **pstart, i { func = &class->load->func[i]; func->code = (ushort *)get_section("code", §ion, NULL, _s); + + flag = ((FUNCTION_FLAG *)func)->flag; + + func->fast = (flag & 1) != 0; + func->optional = (func->npmin < func->n_param); + func->use_is_missing = (flag & 2) != 0; + if (func->fast) { func->fast = JIT_load(); @@ -583,8 +591,7 @@ static void load_and_relocate(CLASS *class, int len_data, CLASS_DESC **pstart, i have_jit_functions = TRUE; } - func->optional = (func->npmin < func->n_param); - if (func->optional) + if (func->use_is_missing) { func->stack_usage++; func->n_ctrl++; diff --git a/main/gbx/gbx_class_load.h b/main/gbx/gbx_class_load.h index 2a6cacdb9..032f9e093 100644 --- a/main/gbx/gbx_class_load.h +++ b/main/gbx/gbx_class_load.h @@ -109,7 +109,7 @@ typedef char n_param; char npmin; char vararg; - char _reserved; + char flag; short n_local; short n_ctrl; short stack_usage; diff --git a/main/gbx/gbx_exec.c b/main/gbx/gbx_exec.c index e5f551184..1c03657de 100644 --- a/main/gbx/gbx_exec.c +++ b/main/gbx/gbx_exec.c @@ -542,7 +542,7 @@ void EXEC_enter(void) } // Optional argument map - if (optional) + if (optional && func->use_is_missing) { SP--; SP->type = T_LONG;