diff --git a/main/gbx/gbx_exec.c b/main/gbx/gbx_exec.c index 754c253cc..a9f5ee1aa 100644 --- a/main/gbx/gbx_exec.c +++ b/main/gbx/gbx_exec.c @@ -322,67 +322,82 @@ static bool exec_enter_can_quick(void) return TRUE; } -static void set_class_default(CLASS *class, VALUE *value, CTYPE ctype) +static void init_local_var(CLASS *class, FUNCTION *func) { - static const void *jump[] = { - &&__VOID, &&__BOOLEAN, &&__BYTE, &&__SHORT, &&__INTEGER, &&__LONG, &&__SINGLE, &&__FLOAT, - &&__DATE, &&__STRING, &&__STRING, &&__POINTER, &&__VARIANT, &&__FUNCTION, &&__CLASS, &&__NULL, - &&__OBJECT - }; + static const void *jump[] = { + &&__VOID, &&__BOOLEAN, &&__BYTE, &&__SHORT, &&__INTEGER, &&__LONG, &&__SINGLE, &&__FLOAT, + &&__DATE, &&__STRING, &&__STRING, &&__POINTER, &&__VARIANT, &&__FUNCTION, &&__CLASS, &&__NULL, + &&__OBJECT + }; + + CLASS_LOCAL *local; + int n; + CTYPE ctype; + VALUE *value; + + local = func->local; + value = SP; + + for (n = func->n_local; n; n--, value++, local++) + { + ctype = local->type; + + value->type = ctype.id; + goto *jump[ctype.id]; - value->type = ctype.id; - goto *jump[ctype.id]; + __BOOLEAN: + __BYTE: + __SHORT: + __INTEGER: -__BOOLEAN: -__BYTE: -__SHORT: -__INTEGER: + value->_integer.value = 0; + continue; - value->_integer.value = 0; - return; + __LONG: -__LONG: + value->_long.value = 0; + continue; - value->_long.value = 0; - return; + __SINGLE: + __FLOAT: + value->_float.value = 0; + continue; -__SINGLE: -__FLOAT: - value->_float.value = 0; - return; + __STRING: + value->_string.addr = NULL; + value->_string.start = 0; + value->_string.len = 0; + continue; -__STRING: - value->_string.addr = NULL; - value->_string.start = 0; - value->_string.len = 0; - return; + __VARIANT: + value->_variant.vtype = T_NULL; + continue; -__VARIANT: - value->_variant.vtype = T_NULL; - return; + __POINTER: + value->_pointer.value = NULL; + continue; -__POINTER: - value->_pointer.value = NULL; - return; + __DATE: + value->_date.date = 0; + value->_date.time = 0; + continue; -__DATE: - value->_date.date = 0; - value->_date.time = 0; - return; + __VOID: + continue; -__VOID: - return; + __OBJECT: + if (ctype.value >= 0) + value->type = (TYPE)class->load->class_ref[ctype.value]; + value->_object.object = NULL; + continue; -__OBJECT: - if (ctype.value >= 0) - value->type = (TYPE)class->load->class_ref[ctype.value]; - value->_object.object = NULL; - return; - -__FUNCTION: -__CLASS: -__NULL: - ERROR_panic("VALUE_default: Unknown default type"); + __FUNCTION: + __CLASS: + __NULL: + ERROR_panic("VALUE_default: Unknown default type"); + } + + SP = value; } // EXEC.nparam must be set to the amount of stack that must be freed if an exception is raised during EXEC_enter() @@ -497,13 +512,7 @@ void EXEC_enter(void) /* local variables initialization */ if (LIKELY(func->n_local > 0)) - { - for (i = 0; i < func->n_local; i++) - { - set_class_default(class, SP, func->local[i].type); - SP++; - } - } + init_local_var(class, func); /* control variables initialization */ @@ -585,13 +594,7 @@ void EXEC_enter_quick(void) /* local variables initialization */ if (LIKELY(func->n_local != 0)) - { - for (i = 0; i < func->n_local; i++) - { - set_class_default(class, SP, func->local[i].type); - SP++; - } - } + init_local_var(class, func); /* control variables initialization */ diff --git a/main/gbx/gbx_stack.h b/main/gbx/gbx_stack.h index c0072441a..7b1e67358 100644 --- a/main/gbx/gbx_stack.h +++ b/main/gbx/gbx_stack.h @@ -76,7 +76,7 @@ void STACK_grow(void); #define STACK_get_current() ((STACK_frame_count > 0) ? STACK_frame : NULL) -#define STACK_copy(_dst, _src) \ +/*#define STACK_copy(_dst, _src) \ (_dst)->next = (_src)->next; \ (_dst)->bp = (_src)->bp; \ (_dst)->pp = (_src)->pp; \ @@ -88,7 +88,9 @@ void STACK_grow(void); (_dst)->ec = (_src)->ec; \ (_dst)->et = (_src)->et; \ (_dst)->tc = (_src)->tc; \ - (_dst)->tp = (_src)->tp; + (_dst)->tp = (_src)->tp;*/ + +#define STACK_copy(_dst, _src) *(_dst) = *(_src) #define STACK_RELOCATE(_ptr) if (_ptr) _ptr = (void *)((char *)_ptr + STACK_relocate) diff --git a/main/gbx/gbx_subr_math.c b/main/gbx/gbx_subr_math.c index 2943a0a84..c2982e627 100644 --- a/main/gbx/gbx_subr_math.c +++ b/main/gbx/gbx_subr_math.c @@ -604,14 +604,14 @@ void SUBR_add_(ushort code) TYPE type; VALUE *P1, *P2; void *jump_end; - short op; + int op; P1 = SP - 2; P2 = P1 + 1; jump_end = &&__END; type = code & 0x0F; - op = (code - C_ADD) >> 8; + op = (code >> 8) - (C_ADD >> 8); goto *jump[type]; __BOOLEAN: diff --git a/main/gbx/gbx_subr_test.c b/main/gbx/gbx_subr_test.c index 7abc36003..3d40a5178 100644 --- a/main/gbx/gbx_subr_test.c +++ b/main/gbx/gbx_subr_test.c @@ -680,13 +680,10 @@ void SUBR_compi(ushort code) static void *test[] = { &&__GT, &&__LE, &&__LT, &&__GE }; char NO_WARNING(result); - char op; VALUE *P1; VALUE *P2; TYPE type; - op = (code - C_GT) >> 8; - P1 = SP - 2; P2 = P1 + 1; @@ -801,7 +798,7 @@ __END: P1->type = T_BOOLEAN; SP--; - goto *test[(int)op]; + goto *test[(code >> 8) - (C_GT >> 8)]; __GT: P1->_boolean.value = result > 0 ? -1 : 0; diff --git a/main/share/gb_code_temp.h b/main/share/gb_code_temp.h index fa2eb7817..8fc51355b 100644 --- a/main/share/gb_code_temp.h +++ b/main/share/gb_code_temp.h @@ -1216,11 +1216,11 @@ void CODE_drop(void) } } - THROW("Internal compiler error: Bad stack drop!"); + //THROW("Internal compiler error: Bad stack drop!"); - /*LAST_CODE; + LAST_CODE; - write_ZZxx(C_DROP, 1);*/ + write_ZZxx(C_DROP, 1); } diff --git a/main/share/gb_hash_temp.h b/main/share/gb_hash_temp.h index dab2bf447..e0ff7592b 100644 --- a/main/share/gb_hash_temp.h +++ b/main/share/gb_hash_temp.h @@ -49,6 +49,8 @@ static const int primes[] = 1215497, 1823231, 2734867, 4102283, 6153409, 9230113, 13845163 }; +//static const uint seed[] = { 0x9A177BA5, 0x9A177BA4, 0x9A177BA7, 0x9A177BA6, 0x9A177BA1, 0x9A177BA0, 0x9A177BA3, 0x9A177BA2, 0x9A177BAD }; + static const int nprimes = sizeof (primes) / sizeof (primes[0]); static int spaced_primes_closest(int num) @@ -63,87 +65,72 @@ static int spaced_primes_closest(int num) } +// Fast hashing functions. Sometimes Microsoft Research produces useful things. + static uint key_hash_binary(const char *key, int len) { - static const void *jump[4] = { &&__LEN_0, &&__LEN_1, &&__LEN_2, &&__LEN_3 }; - uint hash = 0; - - //for (i = 0; i < len; i++) - // hash = (hash << 4) + (hash ^ key[i]); - - while (len >= 4) - { - len -= 4; - hash = (hash << 4) + (hash ^ key[len]); - hash = (hash << 4) + (hash ^ key[len + 1]); - hash = (hash << 4) + (hash ^ key[len + 2]); - hash = (hash << 4) + (hash ^ key[len + 3]); - } + static const void *jump[] = { &&__LEN_0, &&__LEN_1, &&__LEN_2, &&__LEN_3, &&__LEN_4, &&__LEN_5, &&__LEN_6, &&__LEN_7, &&__LEN_8 }; + uint hash = 0x9A177BA5 ^ len; + if (len > 8) + len = 8; + goto *jump[len]; +__LEN_8: + hash = hash * 101 + key[7]; +__LEN_7: + hash = hash * 101 + key[6]; +__LEN_6: + hash = hash * 101 + key[5]; +__LEN_5: + hash = hash * 101 + key[4]; +__LEN_4: + hash = hash * 101 + key[3]; __LEN_3: - hash = (hash << 4) + (hash ^ key[2]); + hash = hash * 101 + key[2]; __LEN_2: - hash = (hash << 4) + (hash ^ key[1]); + hash = hash * 101 + key[1]; __LEN_1: - hash = (hash << 4) + (hash ^ key[0]); + hash = hash * 101 + key[0]; __LEN_0: - - /*while (len) - { - len--; - hash = (hash << 4) + (hash ^ key[len]); - }*/ - - return hash; -} + return hash; +} static uint key_hash_text(const char *key, int len) { - static const void *jump[4] = { &&__LEN_0, &&__LEN_1, &&__LEN_2, &&__LEN_3 }; - uint hash = 0; - - while (len >= 4) - { - len--; - hash = (hash << 4) + (hash ^ (key[len] & ~0x20)); - len--; - hash = (hash << 4) + (hash ^ (key[len] & ~0x20)); - len--; - hash = (hash << 4) + (hash ^ (key[len] & ~0x20)); - len--; - hash = (hash << 4) + (hash ^ (key[len] & ~0x20)); - } + static const void *jump[] = { &&__LEN_0, &&__LEN_1, &&__LEN_2, &&__LEN_3, &&__LEN_4, &&__LEN_5, &&__LEN_6, &&__LEN_7, &&__LEN_8 }; + uint hash = 0x9A177BA5 ^ len; + if (len > 8) + len = 8; + goto *jump[len]; +__LEN_8: + hash = hash * 101 + (key[7] & ~0x20); +__LEN_7: + hash = hash * 101 + (key[6] & ~0x20); +__LEN_6: + hash = hash * 101 + (key[5] & ~0x20); +__LEN_5: + hash = hash * 101 + (key[4] & ~0x20); +__LEN_4: + hash = hash * 101 + (key[3] & ~0x20); __LEN_3: - hash = (hash << 4) + (hash ^ (key[2] & ~0x20)); + hash = hash * 101 + (key[2] & ~0x20); __LEN_2: - hash = (hash << 4) + (hash ^ (key[1] & ~0x20)); + hash = hash * 101 + (key[1] & ~0x20); __LEN_1: - hash = (hash << 4) + (hash ^ (key[0] & ~0x20)); + hash = hash * 101 + (key[0] & ~0x20); __LEN_0: - - /*while (len) - { - len--; - hash = (hash << 4) + (hash ^ (key[len] & ~0x20)); - }*/ return hash; } -static HASH_FUNC get_hash_func(HASH_TABLE *hash) -{ - if (hash->mode == HF_IGNORE_CASE) - return key_hash_text; - else - return key_hash_binary; -} +#define get_hash_func(_hash) ((_hash)->mode ? key_hash_text : key_hash_binary) void HASH_TABLE_create(HASH_TABLE **hash, size_t s_value, HASH_FLAG mode) @@ -188,44 +175,13 @@ int HASH_TABLE_size(HASH_TABLE *hash_table) return hash_table->nnodes; } -#if 0 -static bool compare_key_ignore_case(const char *key_comp, int len_comp, const char *key, int len) -{ - if (len != len_comp) - return FALSE; - - while (len) - { - len--; - if (toupper(key_comp[len]) != toupper(key[len])) - return FALSE; - } - - return TRUE; -} - -static bool compare_key(const char *key_comp, int len_comp, const char *key, int len) -{ - if (len != len_comp) - return FALSE; - - while (len) - { - len--; - if (key_comp[len] != key[len]) - return FALSE; - } - - return TRUE; -} -#endif static HASH_NODE **hash_table_lookup_node(HASH_TABLE *hash_table, const char *key, int len) { HASH_NODE **node; HASH_KEY *node_key; - if (hash_table->mode == HF_IGNORE_CASE) + if (hash_table->mode) { node = &hash_table->nodes[key_hash_text(key, len) % hash_table->size]; diff --git a/main/share/gb_table_temp.h b/main/share/gb_table_temp.h index 6668b9c97..fe0e1617a 100644 --- a/main/share/gb_table_temp.h +++ b/main/share/gb_table_temp.h @@ -151,6 +151,13 @@ static bool search(void *symbol, ushort *sort, int n_symbol, size_t size, int fl for(;;) { + /*result = (*s1 - *s2) & ~0x20; + + if (LIKELY(result < 0)) + goto __T_LOWER; + else if (LIKELY(result > 0)) + goto __T_GREATER;*/ + result = tolower(*s1) - tolower(*s2); if (LIKELY(result < 0))