From ccb232329b72f0e454370b947dea04e02da7148e Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Mon, 11 May 2015 16:08:09 +0000 Subject: [PATCH] added code to register primitive objects into the system dictionary --- stix/lib/dic.c | 16 ++++--- stix/lib/gc.c | 2 + stix/lib/ignite.c | 107 +++++++++++++++++++--------------------------- stix/lib/stix.h | 4 ++ stix/lib/sym.c | 3 +- 5 files changed, 62 insertions(+), 70 deletions(-) diff --git a/stix/lib/dic.c b/stix/lib/dic.c index 2587f3e..fc02c1f 100644 --- a/stix/lib/dic.c +++ b/stix/lib/dic.c @@ -74,6 +74,13 @@ static stix_oop_t find_or_insert (stix_t* stix, stix_oop_char_t key, stix_oop_t index = stix_hashchars(key->slot, STIX_OBJ_GET_SIZE(key)) % STIX_OBJ_GET_SIZE(stix->sysdic->bucket); +{ +int i; +printf ("FINDING IN SYSDIC ["); +for (i = 0; i < STIX_OBJ_GET_SIZE(key); i++) printf ("%c", key->slot[i]); +printf ("]\n"); +} + while (stix->sysdic->bucket->slot[index] != stix->_nil) { ass = (stix_oop_association_t)stix->sysdic->bucket->slot[index]; @@ -130,11 +137,10 @@ static stix_oop_t find_or_insert (stix_t* stix, stix_oop_char_t key, stix_oop_t /* 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) - { - ass->key = (stix_oop_t)key; - ass->value = value; - } + 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; diff --git a/stix/lib/gc.c b/stix/lib/gc.c index b06c968..ccef631 100644 --- a/stix/lib/gc.c +++ b/stix/lib/gc.c @@ -208,6 +208,8 @@ printf ("STARTING GC curheap base %p ptr %p newheap base %p ptr %p\n", stix->_symbol_set = move_one (stix, stix->_symbol_set); stix->_system_dictionary = move_one (stix, stix->_system_dictionary); stix->_association = move_one (stix, stix->_association); + stix->_true_class = move_one (stix, stix->_true_class); + stix->_false_class = move_one (stix, stix->_false_class); stix->_character = move_one (stix, stix->_character); stix->_small_integer = move_one (stix, stix->_small_integer); diff --git a/stix/lib/ignite.c b/stix/lib/ignite.c index 617abd1..2cbf3da 100644 --- a/stix/lib/ignite.c +++ b/stix/lib/ignite.c @@ -26,41 +26,6 @@ #include "stix-prv.h" - -#if 0 -stix_oop_t stix_addclass (stix_t* stix, name, spec, ...) -{ -/* convert name to the internal encoding... */ - -/* returned value must be also registered in the system dictionary. - * so it doesn't get GCed. */ - return -1; -} - -int stix_delclass (stix_t* stix, stix_oop_t _class) -{ - stix_oop_class_t c = (stix_oop_class_t)_class; - - if (c->name) - { - /* delete c->name from system dictionary. it'll get GCed if it's not referenced */ - } - - return -1; -} - -stix_oop_t stix_findclass (stix_t* stix, const char* name) -{ - /* find a class object by name */ - return STIX_NULL; -} - -int stix_addmethod (stix_t* stix, stix_oop_t _class, const char* name, const bytecode) -{ - -} -#endif - /* * Stix ..................... * ^ ^ ^ : ....... @@ -155,6 +120,8 @@ static int ignite_1 (stix_t* stix) 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->_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)); /* TOOD: what is a proper spec for Character and SmallInteger? * If the fixed part is 0, its instance must be an object of 0 payload fields. @@ -165,8 +132,8 @@ static int ignite_1 (stix_t* stix) if (!stix->_stix || !stix->_nil_object || !stix->_object || !stix->_array || !stix->_symbol || !stix->_symbol_set || !stix->_system_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; } @@ -175,6 +142,11 @@ static int ignite_2 (stix_t* stix) { stix_oop_oop_t arr; + /* Create 'true' and 'false objects */ + stix->_true = stix_instantiate (stix, stix->_true_class, STIX_NULL, 0); + stix->_false = stix_instantiate (stix, stix->_false_class, STIX_NULL, 0); + 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; @@ -204,31 +176,47 @@ static int ignite_2 (stix_t* stix) return 0; } -#if 0 +static int ignite_3 (stix_t* stix) +{ + /* Register kernel classes manually created so far to the system dictionary */ -/* - stix_oop_class_t c; + static struct symbol_name_t + { + stix_oow_t len; + stix_char_t str[16]; + } symnames[] = { + { 4, { 'S','t','i','x' } }, + { 6, { 'O','b','j','e','c','t' } }, + { 5, { 'C','l','a','s','s' } }, + { 6, { 'S','y','m','b','o','l' } }, + { 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' } }, + { 11, { 'A','s','s','o','c','i','a','t','i','o','n' } }, + { 4, { 'T','r','u','e' } }, + { 5, { 'F','a','l','s','e' } }, + { 9, { 'C','h','a','r','a','c','t','e','r' } }, + { 12, { 'S','m','a','l','l','I','n','t','e','g','e','r' } } + }; - c = (stix_oop_class_t)stix->_stix; - c->classvar[0] = stix->_nil; -*/ - /* Set subclasses */ + stix_oow_t i; + stix_oop_t sym; + stix_oop_t* stix_ptr; - /* - Set Names. - stix->_stix_object->name = new_symbol ("ProtoObject"); - stix->_nil_object->name = new_symbol ("NilObject"); - stix->_class->name = new_symbol ("Class"); - */ + stix_ptr = &stix->_stix; + for (i = 0; i < STIX_COUNTOF(symnames); i++) + { + sym = stix_makesymbol (stix, symnames[i].str, symnames[i].len); + //sym = stix_makesymbol (stix, symnames[0].str, symnames[0].len); + if (!sym) return -1; - /* - _class->instvars = make_string or make_array('spec instmthds classmthds superclass name instvars'); - */ + if (!stix_putatsysdic (stix, sym, *stix_ptr)) return -1; - /*register 'Stix', 'NilObject' and 'Class' into the system dictionary.*/ - -#endif + stix_ptr++; + } + return 0; +} int stix_ignite (stix_t* stix) { @@ -240,14 +228,7 @@ int stix_ignite (stix_t* stix) stix->_nil->_flags = STIX_OBJ_MAKE_FLAGS (STIX_OBJ_TYPE_OOP, STIX_SIZEOF(stix_oop_t), 0, 1, 0); stix->_nil->_size = 0; - if (ignite_1(stix) <= -1 || ignite_2(stix) <= -1) return -1; - -/*stix_addclass (stix, "True", spec, "Boolean");*/ - /*stix->_true = stix_instantiate (stix, stix->_true_class, STIX_NULL, 0); - stix->_false = stix_instantiate (stix, stix->_false_class STIX_NULL, 0); - - if (!stix->_true || !stix->_false) return -1;*/ - + if (ignite_1(stix) <= -1 || ignite_2(stix) <= -1 || ignite_3(stix)) return -1; return 0; } diff --git a/stix/lib/stix.h b/stix/lib/stix.h index 6c81c7d..d5cfaac 100644 --- a/stix/lib/stix.h +++ b/stix/lib/stix.h @@ -730,6 +730,7 @@ struct stix_t stix_oop_t _true; stix_oop_t _false; + /* == NEVER CHANGE THE ORDER OF FIELDS BELOW == */ stix_oop_t _stix; /* Stix */ stix_oop_t _nil_object; /* NilObject */ stix_oop_t _class; /* Class */ @@ -739,8 +740,11 @@ struct stix_t stix_oop_t _symbol_set; /* SymbolSet */ stix_oop_t _system_dictionary; /* SystemDictionary */ stix_oop_t _association; /* Association */ + stix_oop_t _true_class; /* True */ + stix_oop_t _false_class; /* False */ stix_oop_t _character; /* Character */ stix_oop_t _small_integer; /* SmallInteger */ + /* == NEVER CHANGE THE ORDER OF FIELDS ABOVE == */ stix_oop_set_t symtab; /* system-wide symbol table. instance of SymbolSet */ stix_oop_set_t sysdic; /* system dictionary. instance of SystemDictionary */ diff --git a/stix/lib/sym.c b/stix/lib/sym.c index a7b1e37..2387170 100644 --- a/stix/lib/sym.c +++ b/stix/lib/sym.c @@ -103,7 +103,7 @@ static stix_oop_t find_or_make_symbol (stix_t* stix, const stix_char_t* ptr, sti stix_oop_oop_t bucket; /* TODO: make the growth policy configurable instead of growing - it just before it gets full. The polcy can be grow it + it just before it gets full. The polcy can be grow it if it's 70% full */ /* Enlarge the symbol table before it gets full to @@ -142,4 +142,3 @@ stix_oop_t stix_findsymbol (stix_t* stix, const stix_char_t* ptr, stix_oow_t len { return find_or_make_symbol (stix, ptr, len, 0); } -