diff --git a/stix/lib/comp.c b/stix/lib/comp.c index ebd0464..98e067b 100644 --- a/stix/lib/comp.c +++ b/stix/lib/comp.c @@ -2451,10 +2451,11 @@ static int make_defined_class (stix_t* stix) stix->c->cls.indexed_type); self_spec = STIX_CLASS_SELFSPEC_MAKE(stix->c->cls.var_count[VAR_CLASS], stix->c->cls.var_count[VAR_CLASSINST]); +#if 0 printf ("MAKING ... "); print_ucs (&stix->c->cls.name); printf (" instvars %d classvars %d classinstvars %d\n", (int)stix->c->cls.var_count[VAR_INSTANCE], (int)stix->c->cls.var_count[VAR_CLASS], (int)stix->c->cls.var_count[VAR_CLASSINST]); - +#endif if (stix->c->cls.self_oop) { STIX_ASSERT (STIX_CLASSOF(stix, stix->c->cls.self_oop) == stix->_class); @@ -2466,11 +2467,12 @@ printf (" instvars %d classvars %d classinstvars %d\n", (int)stix->c->cls.var_co /* it conflicts with internal definition */ +#if 0 printf (" CONFLICTING CLASS DEFINITION %lu %lu %lu %lu\n", (unsigned long)spec, (unsigned long)self_spec, (unsigned long)STIX_OOP_TO_SMINT(stix->c->cls.self_oop->spec), (unsigned long)STIX_OOP_TO_SMINT(stix->c->cls.self_oop->selfspec) ); - +#endif set_syntax_error (stix, STIX_SYNERR_CLASSCONTRA, &stix->c->cls.name_loc, &stix->c->cls.name); return -1; } @@ -2510,7 +2512,10 @@ printf (" CONFLICTING CLASS DEFINITION %lu %lu %lu %lu\n", if (!tmp) return -1; stix->c->cls.self_oop->classinstvars = (stix_oop_char_t)tmp; -/* TODO: initialize more fields??? method_dictionary. */ + tmp = stix_instantiate(stix, stix->_method_dictionary, STIX_NULL, 0); + if (!tmp) return -1; + stix->c->cls.mthdic_oop = (stix_oop_set_t)tmp; +/* TODO: initialize more fields??? whatelse. */ if (just_made) { @@ -2596,6 +2601,8 @@ static int __compile_class_definition (stix_t* stix) if (stix->c->tok.type == STIX_IOTOK_LPAREN) { + int super_is_nil = 0; + printf ("DEFININING..\n"); { int i; @@ -2605,7 +2612,6 @@ printf ("%c", stix->c->cls.name.ptr[i]); } printf ("\n"); } - int super_is_nil = 0; /* superclass is specified. new class defintion. * for example, #class Class(Stix) @@ -2799,6 +2805,7 @@ static int compile_class_definition (stix_t* stix) stix->c->cls.self_oop = STIX_NULL; stix->c->cls.super_oop = STIX_NULL; + stix->c->cls.mthdic_oop = STIX_NULL; /* do main compilation work */ n = __compile_class_definition (stix); @@ -2806,6 +2813,7 @@ static int compile_class_definition (stix_t* stix) /* reset these oops not to confuse gc_compiler() */ stix->c->cls.self_oop = STIX_NULL; stix->c->cls.super_oop = STIX_NULL; + stix->c->cls.mthdic_oop = STIX_NULL; return n; } diff --git a/stix/lib/dic.c b/stix/lib/dic.c index be6cc95..ad41268 100644 --- a/stix/lib/dic.c +++ b/stix/lib/dic.c @@ -26,23 +26,25 @@ #include "stix-prv.h" -static stix_oop_oop_t expand_bucket (stix_t* stix, stix_oop_oop_t old_bucket) +static stix_oop_oop_t expand_bucket (stix_t* stix, stix_oop_oop_t oldbuc) { - stix_oop_oop_t new_bucket; + stix_oop_oop_t newbuc; stix_oow_t oldsz, newsz, index; stix_oop_association_t ass; stix_oop_char_t key; /* TODO: derive a better growth size */ - new_bucket = (stix_oop_oop_t)stix_instantiate (stix, stix->_array, STIX_NULL, STIX_OBJ_GET_SIZE(old_bucket) * 2); - if (!new_bucket) return STIX_NULL; + stix_pushtmp (stix, (stix_oop_t*)&oldbuc); + newbuc = (stix_oop_oop_t)stix_instantiate (stix, stix->_array, STIX_NULL, STIX_OBJ_GET_SIZE(oldbuc) * 2); + stix_poptmp (stix); + if (!newbuc) return STIX_NULL; - oldsz = STIX_OBJ_GET_SIZE(old_bucket); - newsz = STIX_OBJ_GET_SIZE(new_bucket); + oldsz = STIX_OBJ_GET_SIZE(oldbuc); + newsz = STIX_OBJ_GET_SIZE(newbuc); while (oldsz > 0) { - ass = (stix_oop_association_t)old_bucket->slot[--oldsz]; + ass = (stix_oop_association_t)oldbuc->slot[--oldsz]; if ((stix_oop_t)ass != stix->_nil) { STIX_ASSERT (STIX_CLASSOF(stix,ass) == stix->_association); @@ -50,17 +52,16 @@ static stix_oop_oop_t expand_bucket (stix_t* stix, stix_oop_oop_t old_bucket) key = (stix_oop_char_t)ass->key; STIX_ASSERT (STIX_CLASSOF(stix,key) == (stix_oop_t)stix->_symbol); - index = stix_hashchars (key->slot, STIX_OBJ_GET_SIZE(key)) % newsz; - while (new_bucket->slot[index] != stix->_nil) - index = (index + 1) % newsz; - new_bucket->slot[index] = (stix_oop_t)ass; + index = stix_hashchars(key->slot, STIX_OBJ_GET_SIZE(key)) % newsz; + while (newbuc->slot[index] != stix->_nil) index = (index + 1) % newsz; + newbuc->slot[index] = (stix_oop_t)ass; } } - return new_bucket; + return newbuc; } -static stix_oop_t find_or_insert (stix_t* stix, stix_oop_char_t key, stix_oop_t value) +static stix_oop_t find_or_insert (stix_t* stix, stix_oop_set_t dic, stix_oop_char_t key, stix_oop_t value) { stix_oow_t index, tally; stix_oop_association_t ass; @@ -69,14 +70,14 @@ static stix_oop_t find_or_insert (stix_t* stix, stix_oop_char_t key, stix_oop_t /* the system dictionary is not a generic dictionary. * it accepts only a symbol as a key. */ STIX_ASSERT (STIX_CLASSOF(stix,key) == stix->_symbol); - STIX_ASSERT (STIX_CLASSOF(stix,stix->sysdic->tally) == stix->_small_integer); - STIX_ASSERT (STIX_CLASSOF(stix,stix->sysdic->bucket) == stix->_array); + STIX_ASSERT (STIX_CLASSOF(stix,dic->tally) == stix->_small_integer); + STIX_ASSERT (STIX_CLASSOF(stix,dic->bucket) == stix->_array); - index = stix_hashchars(key->slot, STIX_OBJ_GET_SIZE(key)) % STIX_OBJ_GET_SIZE(stix->sysdic->bucket); + index = stix_hashchars(key->slot, STIX_OBJ_GET_SIZE(key)) % STIX_OBJ_GET_SIZE(dic->bucket); - while (stix->sysdic->bucket->slot[index] != stix->_nil) + while (dic->bucket->slot[index] != stix->_nil) { - ass = (stix_oop_association_t)stix->sysdic->bucket->slot[index]; + ass = (stix_oop_association_t)dic->bucket->slot[index]; STIX_ASSERT (STIX_CLASSOF(stix,ass) == stix->_association); STIX_ASSERT (STIX_CLASSOF(stix,ass->key) == stix->_symbol); @@ -87,7 +88,7 @@ static stix_oop_t find_or_insert (stix_t* stix, stix_oop_char_t key, stix_oop_t return (stix_oop_t)ass; } - index = (index + 1) % STIX_OBJ_GET_SIZE(stix->sysdic->bucket); + index = (index + 1) % STIX_OBJ_GET_SIZE(dic->bucket); } if (value == STIX_NULL) @@ -97,11 +98,12 @@ static stix_oop_t find_or_insert (stix_t* stix, stix_oop_char_t key, stix_oop_t return STIX_NULL; } + stix_pushtmp (stix, (stix_oop_t*)&dic); tmp_count++; stix_pushtmp (stix, (stix_oop_t*)&key); tmp_count++; stix_pushtmp (stix, &value); tmp_count++; - tally = STIX_OOP_TO_SMINT(stix->sysdic->tally); - if (tally + 1 >= STIX_OBJ_GET_SIZE(stix->sysdic->bucket)) + tally = STIX_OOP_TO_SMINT(dic->tally); + if (tally + 1 >= STIX_OBJ_GET_SIZE(dic->bucket)) { stix_oop_oop_t bucket; @@ -113,28 +115,28 @@ static stix_oop_t find_or_insert (stix_t* stix, stix_oop_char_t key, stix_oop_t * make sure that it has at least one free slot left * after having added a new symbol. this is to help * traversal end at a _nil slot if no entry is found. */ - bucket = expand_bucket (stix, stix->sysdic->bucket); + bucket = expand_bucket (stix, dic->bucket); if (!bucket) goto oops; - stix->sysdic->bucket = bucket; + dic->bucket = bucket; /* recalculate the index for the expanded bucket */ - index = stix_hashchars(key->slot, STIX_OBJ_GET_SIZE(key)) % STIX_OBJ_GET_SIZE(stix->sysdic->bucket); + index = stix_hashchars(key->slot, STIX_OBJ_GET_SIZE(key)) % STIX_OBJ_GET_SIZE(dic->bucket); - while (stix->sysdic->bucket->slot[index] != stix->_nil) - index = (index + 1) % STIX_OBJ_GET_SIZE(stix->sysdic->bucket); + while (dic->bucket->slot[index] != stix->_nil) + index = (index + 1) % STIX_OBJ_GET_SIZE(dic->bucket); } /* create a new assocation of a key and a value since * the key isn't found in the root dictionary */ ass = (stix_oop_association_t)stix_instantiate (stix, stix->_association, STIX_NULL, 0); if (!ass) goto oops; - + ass->key = (stix_oop_t)key; ass->value = value; - stix->sysdic->tally = STIX_OOP_FROM_SMINT(tally + 1); - stix->sysdic->bucket->slot[index] = (stix_oop_t)ass; + dic->tally = STIX_OOP_FROM_SMINT(tally + 1); + dic->bucket->slot[index] = (stix_oop_t)ass; stix_poptmps (stix, tmp_count); return (stix_oop_t)ass; @@ -144,19 +146,7 @@ oops: return STIX_NULL; } -stix_oop_t stix_putatsysdic (stix_t* stix, stix_oop_t key, stix_oop_t value) -{ - STIX_ASSERT (STIX_CLASSOF(stix,key) == stix->_symbol); - return find_or_insert (stix, (stix_oop_char_t)key, value); -} - -stix_oop_t stix_getatsysdic (stix_t* stix, stix_oop_t key) -{ - STIX_ASSERT (STIX_CLASSOF(stix,key) == stix->_symbol); - return find_or_insert (stix, (stix_oop_char_t)key, STIX_NULL); -} - -stix_oop_t stix_lookupsysdic (stix_t* stix, const stix_ucs_t* name) +static stix_oop_t lookup (stix_t* stix, stix_oop_set_t dic, const stix_ucs_t* name) { /* this is special version of stix_getatsysdic() that performs * lookup using a plain string specified */ @@ -164,14 +154,14 @@ stix_oop_t stix_lookupsysdic (stix_t* stix, const stix_ucs_t* name) stix_oow_t index; stix_oop_association_t ass; - STIX_ASSERT (STIX_CLASSOF(stix,stix->sysdic->tally) == stix->_small_integer); - STIX_ASSERT (STIX_CLASSOF(stix,stix->sysdic->bucket) == stix->_array); + STIX_ASSERT (STIX_CLASSOF(stix,dic->tally) == stix->_small_integer); + STIX_ASSERT (STIX_CLASSOF(stix,dic->bucket) == stix->_array); - index = stix_hashchars(name->ptr, name->len) % STIX_OBJ_GET_SIZE(stix->sysdic->bucket); + index = stix_hashchars(name->ptr, name->len) % STIX_OBJ_GET_SIZE(dic->bucket); - while (stix->sysdic->bucket->slot[index] != stix->_nil) + while (dic->bucket->slot[index] != stix->_nil) { - ass = (stix_oop_association_t)stix->sysdic->bucket->slot[index]; + ass = (stix_oop_association_t)dic->bucket->slot[index]; STIX_ASSERT (STIX_CLASSOF(stix,ass) == stix->_association); STIX_ASSERT (STIX_CLASSOF(stix,ass->key) == stix->_symbol); @@ -182,10 +172,63 @@ stix_oop_t stix_lookupsysdic (stix_t* stix, const stix_ucs_t* name) return (stix_oop_t)ass; } - index = (index + 1) % STIX_OBJ_GET_SIZE(stix->sysdic->bucket); + index = (index + 1) % STIX_OBJ_GET_SIZE(dic->bucket); } /* when value is STIX_NULL, perform no insertion */ stix->errnum = STIX_ENOENT; return STIX_NULL; } + +stix_oop_t stix_putatsysdic (stix_t* stix, stix_oop_t key, stix_oop_t value) +{ + STIX_ASSERT (STIX_CLASSOF(stix,key) == stix->_symbol); + return find_or_insert (stix, stix->sysdic, (stix_oop_char_t)key, value); +} + +stix_oop_t stix_getatsysdic (stix_t* stix, stix_oop_t key) +{ + STIX_ASSERT (STIX_CLASSOF(stix,key) == stix->_symbol); + return find_or_insert (stix, stix->sysdic, (stix_oop_char_t)key, STIX_NULL); +} + +stix_oop_t stix_lookupsysdic (stix_t* stix, const stix_ucs_t* name) +{ + return lookup (stix, stix->sysdic, name); +} + +stix_oop_t stix_putatdic (stix_t* stix, stix_oop_set_t dic, stix_oop_t key, stix_oop_t value) +{ + STIX_ASSERT (STIX_CLASSOF(stix,key) == stix->_symbol); + return find_or_insert (stix, stix->sysdic, (stix_oop_char_t)key, value); +} + +stix_oop_t stix_getatdic (stix_t* stix, stix_oop_set_t dic, stix_oop_t key) +{ + STIX_ASSERT (STIX_CLASSOF(stix,key) == stix->_symbol); + return find_or_insert (stix, dic, (stix_oop_char_t)key, STIX_NULL); +} + +stix_oop_t stix_lookupdic (stix_t* stix, stix_oop_set_t dic, const stix_ucs_t* name) +{ + return lookup (stix, dic, name); +} + +stix_oop_set_t stix_makedic (stix_t* stix, stix_oop_t cls, stix_oow_t size) +{ + stix_oop_set_t dic; + stix_oop_t tmp; + + dic = (stix_oop_set_t)stix_instantiate (stix, cls, STIX_NULL, 0); + if (!dic) return STIX_NULL; + + dic->tally = STIX_OOP_FROM_SMINT(0); + + stix_pushtmp (stix, (stix_oop_t*)&dic); + tmp = stix_instantiate (stix, stix->_array, STIX_NULL, size); + stix_poptmp (stix); + if (!tmp) return STIX_NULL; + + dic->bucket = (stix_oop_oop_t)tmp; + return dic; +} diff --git a/stix/lib/gc.c b/stix/lib/gc.c index e3b7a22..22fbf3e 100644 --- a/stix/lib/gc.c +++ b/stix/lib/gc.c @@ -209,6 +209,7 @@ printf ("STARTING GC curheap base %p ptr %p newheap base %p ptr %p\n", stix->_symbol = stix_moveoop (stix, stix->_symbol); stix->_symbol_set = stix_moveoop (stix, stix->_symbol_set); stix->_system_dictionary = stix_moveoop (stix, stix->_system_dictionary); + stix->_method_dictionary = stix_moveoop (stix, stix->_method_dictionary); stix->_association = stix_moveoop (stix, stix->_association); stix->_true_class = stix_moveoop (stix, stix->_true_class); stix->_false_class = stix_moveoop (stix, stix->_false_class); diff --git a/stix/lib/ignite.c b/stix/lib/ignite.c index 7c29209..4bd7aee 100644 --- a/stix/lib/ignite.c +++ b/stix/lib/ignite.c @@ -122,6 +122,7 @@ static int ignite_1 (stix_t* stix) stix->_symbol = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 1, STIX_OBJ_TYPE_CHAR)); stix->_symbol_set = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_SET_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP)); stix->_system_dictionary = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_SET_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP)); + stix->_method_dictionary = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_SET_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP)); stix->_association = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_ASSOCIATION_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP)); stix->_true_class = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); stix->_false_class = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); @@ -134,8 +135,8 @@ static int ignite_1 (stix_t* stix) if (!stix->_stix || !stix->_nil_object || !stix->_object || !stix->_array || !stix->_string || !stix->_symbol || - !stix->_symbol_set || !stix->_system_dictionary || !stix->_association || - !stix->_true_class || !stix->_false_class || + !stix->_symbol_set || !stix->_system_dictionary || !stix->_method_dictionary || + !stix->_association || !stix->_true_class || !stix->_false_class || !stix->_character || !stix->_small_integer) return -1; STIX_OBJ_SET_CLASS (stix->_nil, stix->_nil_object); return 0; @@ -143,7 +144,7 @@ static int ignite_1 (stix_t* stix) static int ignite_2 (stix_t* stix) { - stix_oop_oop_t arr; + stix_oop_t tmp; /* Create 'true' and 'false objects */ stix->_true = stix_instantiate (stix, stix->_true_class, STIX_NULL, 0); @@ -151,8 +152,9 @@ static int ignite_2 (stix_t* stix) if (!stix->_true || !stix->_false) return -1; /* Create the symbol table */ - stix->symtab = (stix_oop_set_t)stix_instantiate (stix, stix->_symbol_set, STIX_NULL, 0); - if (!stix->symtab) return -1; + tmp = stix_instantiate (stix, stix->_symbol_set, STIX_NULL, 0); + if (!tmp) return -1; + stix->symtab = (stix_oop_set_t)tmp; stix->symtab->tally = STIX_OOP_FROM_SMINT(0); /* It's important to assign the result of stix_instantiate() to a temporary @@ -160,18 +162,19 @@ static int ignite_2 (stix_t* stix) * The pointer 'stix->symtab; can change in stix_instantiate() and the * target address of assignment may get set before stix_instantiate() * is called. */ - arr = (stix_oop_oop_t)stix_instantiate (stix, stix->_array, STIX_NULL, stix->option.dfl_symtab_size); - if (!arr) return -1; - stix->symtab->bucket = arr; + tmp = stix_instantiate (stix, stix->_array, STIX_NULL, stix->option.dfl_symtab_size); + if (!tmp) return -1; + stix->symtab->bucket = (stix_oop_oop_t)tmp; /* Create the system dictionary */ - stix->sysdic = (stix_oop_set_t)stix_instantiate (stix, stix->_system_dictionary, STIX_NULL, 0); - if (!stix->sysdic) return -1; + tmp = stix_instantiate (stix, stix->_system_dictionary, STIX_NULL, 0); + if (!tmp) return -1; + stix->sysdic = (stix_oop_set_t)tmp; stix->sysdic->tally = STIX_OOP_FROM_SMINT(0); - arr = (stix_oop_oop_t)stix_instantiate (stix, stix->_array, STIX_NULL, stix->option.dfl_sysdic_size); - if (!arr) return -1; - stix->sysdic->bucket = arr; + tmp = stix_instantiate (stix, stix->_array, STIX_NULL, stix->option.dfl_sysdic_size); + if (!tmp) return -1; + stix->sysdic->bucket = (stix_oop_oop_t)tmp; /* Export the system dictionary via the first class variable of the Stix class */ ((stix_oop_class_t)stix->_stix)->classvar[0] = (stix_oop_t)stix->sysdic; @@ -197,6 +200,7 @@ static int ignite_3 (stix_t* stix) { 5, { 'A','r','r','a','y' } }, { 9, { 'S','y','m','b','o','l','S','e','t' } }, { 16, { 'S','y','s','t','e','m','D','i','c','t','i','o','n','a','r','y' } }, + { 16, { 'M','e','t','h','o','d','D','i','c','t','i','o','n','a','r','y' } }, { 11, { 'A','s','s','o','c','i','a','t','i','o','n' } }, { 4, { 'T','r','u','e' } }, { 5, { 'F','a','l','s','e' } }, diff --git a/stix/lib/main.c b/stix/lib/main.c index 36b1cfa..256fce7 100644 --- a/stix/lib/main.c +++ b/stix/lib/main.c @@ -255,11 +255,13 @@ int main (int argc, char* argv[]) (unsigned long int)STIX_MAX_CLASSINSTVARS); +#if !defined(macintosh) if (argc != 2) { fprintf (stderr, "Usage: %s filename\n", argv[0]); return -1; } +#endif { stix_oow_t x; @@ -280,9 +282,12 @@ int main (int argc, char* argv[]) } { - stix_oow_t symtab_size = 5000; - stix_setoption (stix, STIX_DFL_SYMTAB_SIZE, &symtab_size); - stix_setoption (stix, STIX_DFL_SYSDIC_SIZE, &symtab_size); + stix_oow_t tab_size; + + tab_size = 5000; + stix_setoption (stix, STIX_DFL_SYMTAB_SIZE, &tab_size); + tab_size = 5000; + stix_setoption (stix, STIX_DFL_SYSDIC_SIZE, &tab_size); } if (stix_ignite(stix) <= -1) @@ -316,7 +321,11 @@ printf ("%p\n", a); } xtn = stix_getxtn (stix); +#if !defined(macintosh) xtn->source_path = argv[1]; +#else + xtn->source_path = "test.st"; +#endif if (stix_compile (stix, input_handler) <= -1) { if (stix->errnum == STIX_ESYNTAX) diff --git a/stix/lib/obj.c b/stix/lib/obj.c index 4ae4141..e77ed00 100644 --- a/stix/lib/obj.c +++ b/stix/lib/obj.c @@ -121,7 +121,6 @@ stix_oop_t stix_alloccharobj (stix_t* stix, const stix_uch_t* ptr, stix_oow_t le stix_oop_t stix_allocbyteobj (stix_t* stix, const stix_byte_t* ptr, stix_oow_t len) { - return alloc_numeric_array (stix, ptr, len, STIX_OBJ_TYPE_BYTE, STIX_SIZEOF(stix_byte_t), 0); } diff --git a/stix/lib/stix-prv.h b/stix/lib/stix-prv.h index 822dcd8..8e649b1 100644 --- a/stix/lib/stix-prv.h +++ b/stix/lib/stix-prv.h @@ -515,6 +515,7 @@ struct stix_compiler_t stix_oop_class_t self_oop; stix_oop_t super_oop; /* this may be nil. so the type is stix_oop_t */ + stix_oop_set_t mthdic_oop; stix_ucs_t name; stix_size_t name_capa; @@ -655,26 +656,20 @@ stix_oop_t stix_allocoopobj ( stix_oop_t stix_alloccharobj ( stix_t* stix, - const stix_uch_t* ptr, + const stix_uch_t* ptr, stix_oow_t len ); -stix_oop_t stix_allocuint8obj ( - stix_t* stix, - const stix_uint8_t* ptr, - stix_oow_t len +stix_oop_t stix_allocbyteobj ( + stix_t* stix, + const stix_byte_t* ptr, + stix_oow_t len ); -stix_oop_t stix_allocuint16obj ( - stix_t* stix, - const stix_uint16_t* ptr, - stix_oow_t len -); - -stix_oop_t stix_allocuint32obj ( - stix_t* stix, - const stix_uint32_t* ptr, - stix_oow_t len +stix_oop_t stix_allocwordobj ( + stix_t* stix, + const stix_oow_t* ptr, + stix_oow_t len ); /* ========================================================================= */ @@ -717,6 +712,31 @@ stix_oop_t stix_lookupsysdic ( const stix_ucs_t* name ); +stix_oop_t stix_putatdic ( + stix_t* stix, + stix_oop_set_t dic, + stix_oop_t key, + stix_oop_t value +); + +stix_oop_t stix_getatdic ( + stix_t* stix, + stix_oop_set_t dic, + stix_oop_t key +); + +stix_oop_t stix_lookupdic ( + stix_t* stix, + stix_oop_set_t dic, + const stix_ucs_t* name +); + +stix_oop_set_t stix_makedic ( + stix_t* stix, + stix_oop_t cls, + stix_oow_t size +); + /* ========================================================================= */ /* utf8.c */ /* ========================================================================= */ diff --git a/stix/lib/stix.h b/stix/lib/stix.h index f6a59e7..3d791de 100644 --- a/stix/lib/stix.h +++ b/stix/lib/stix.h @@ -620,6 +620,7 @@ struct stix_t stix_oop_t _array; /* Array */ stix_oop_t _symbol_set; /* SymbolSet */ stix_oop_t _system_dictionary; /* SystemDictionary */ + stix_oop_t _method_dictionary; /* MethodDictionary */ stix_oop_t _association; /* Association */ stix_oop_t _true_class; /* True */ stix_oop_t _false_class; /* False */ @@ -630,7 +631,7 @@ struct stix_t stix_oop_set_t symtab; /* system-wide symbol table. instance of SymbolSet */ stix_oop_set_t sysdic; /* system dictionary. instance of SystemDictionary */ - stix_oop_t* tmp_stack[100]; /* stack for temporaries */ + stix_oop_t* tmp_stack[256]; /* stack for temporaries */ stix_oow_t tmp_count; #if defined(STIX_INCLUDE_COMPILER) diff --git a/stix/lib/sym.c b/stix/lib/sym.c index d5c3fc1..71eeb69 100644 --- a/stix/lib/sym.c +++ b/stix/lib/sym.c @@ -26,35 +26,36 @@ #include "stix-prv.h" -static stix_oop_oop_t expand_bucket (stix_t* stix, stix_oop_oop_t old_bucket) +static stix_oop_oop_t expand_bucket (stix_t* stix, stix_oop_oop_t oldbuc) { - stix_oop_oop_t new_bucket; + stix_oop_oop_t newbuc; stix_oow_t oldsz, newsz, index; stix_oop_char_t symbol; /* TODO: derive a better growth size */ - new_bucket = (stix_oop_oop_t)stix_instantiate (stix, stix->_array, STIX_NULL, STIX_OBJ_GET_SIZE(old_bucket) * 2); - if (!new_bucket) return STIX_NULL; + stix_pushtmp (stix, (stix_oop_t*)&oldbuc); + newbuc = (stix_oop_oop_t)stix_instantiate (stix, stix->_array, STIX_NULL, STIX_OBJ_GET_SIZE(oldbuc) * 2); + stix_poptmp (stix); + if (!newbuc) return STIX_NULL; - oldsz = STIX_OBJ_GET_SIZE(old_bucket); - newsz = STIX_OBJ_GET_SIZE(new_bucket); + oldsz = STIX_OBJ_GET_SIZE(oldbuc); + newsz = STIX_OBJ_GET_SIZE(newbuc); while (oldsz > 0) { - symbol = (stix_oop_char_t)old_bucket->slot[--oldsz]; + symbol = (stix_oop_char_t)oldbuc->slot[--oldsz]; if ((stix_oop_t)symbol != stix->_nil) { STIX_ASSERT (STIX_CLASSOF(stix,symbol) == stix->_symbol); /*STIX_ASSERT (sym->size > 0);*/ index = stix_hashchars(symbol->slot, STIX_OBJ_GET_SIZE(symbol)) % newsz; - while (new_bucket->slot[index] != stix->_nil) - index = (index + 1) % newsz; - new_bucket->slot[index] = (stix_oop_t)symbol; + while (newbuc->slot[index] != stix->_nil) index = (index + 1) % newsz; + newbuc->slot[index] = (stix_oop_t)symbol; } } - return new_bucket; + return newbuc; } static stix_oop_t find_or_make_symbol (stix_t* stix, const stix_uch_t* ptr, stix_oow_t len, int create) diff --git a/stix/lib/syntax.txt b/stix/lib/syntax.txt new file mode 100644 index 0000000..ebf4f1f --- /dev/null +++ b/stix/lib/syntax.txt @@ -0,0 +1,62 @@ + +literal := number-literal | string-literal | character-literal | symbol-literal + +string-literal := single-quote string-character* single-quote +string-character := normal-character | (single-quote single-quote) +single-quote := "'" +normal-character := character-except-single-quote + +character-literal := "$" character +character := normal-character | "'" + +symbol-literal := "#" symbol-body +symbol-body := identifier | keyword+ | binary-selector | string + +unary-selector := identifier +binary-selector := binary-selector-character+ +binary-selector-character := "+" | "/" | "\" | ... +selector-argument := identifier + +identifier := alpha-char (alpha-char | digit-char)* +keyword := identifier ":" + + + +class-definition := #class class-modifier? "{" class-body "}" +class-modifier := "(" (#byte | #character | #word | #pointer)? ")" +class-body := variable-definition* method-definition* + +variable-definition := (#dcl | #declare) variable-modifier? variable-list "." +variable-modifier := "(" (#class | #classinst)? ")" +variable-list := identifier* + +method-definition := (#mth | #method) method-modifier? method-actual-definition +method-modifier := "(" (#class | #instance) ")" +method-actual-definition := method-name "{" method-tempraries? method-primitive? method-statements* "}" + +method-name := unary-method-name | binary-method-name | keyword-method-name +unary-method-name := unary-selector +binary-method-name := binary-selector selector-argument +keyword-method-name := (keyword selector-argument)+ + +method-temporaries := "|" variable-list "|" +method-primitive := "<" "primitive:" integer ">" +method-statements := method-statement ("." | ("." method-statements))* +method-statement := method-return | method-expression +method-return := "^" method-expression + + +method-expression := assignment-expression | basic-expression +assignment-expression := identifier ":=" method-expression +basic-expression := expression-primary (message cascaded-message)? + +---------------------------------------------------------- + +#include '....'. + +#class Test(Object) +{ +} + +#main +