diff --git a/stix/lib/debug.c b/stix/lib/debug.c index cb96163..a012163 100644 --- a/stix/lib/debug.c +++ b/stix/lib/debug.c @@ -26,165 +26,46 @@ #include "stix-prv.h" -void dump_symbol_table (stix_t* stix) +void stix_dumpsymtab (stix_t* stix) { - stix_oow_t i, j; + stix_oow_t i; stix_oop_char_t symbol; - printf ("--------------------------------------------\n"); - printf ("Stix Symbol Table %lu\n", (unsigned long int)STIX_OBJ_GET_SIZE(stix->symtab->bucket)); - printf ("--------------------------------------------\n"); + STIX_DEBUG0 (stix, "--------------------------------------------\n"); + STIX_DEBUG1 (stix, "Stix Symbol Table %zu\n", STIX_OBJ_GET_SIZE(stix->symtab->bucket)); + STIX_DEBUG0 (stix, "--------------------------------------------\n"); for (i = 0; i < STIX_OBJ_GET_SIZE(stix->symtab->bucket); i++) { symbol = (stix_oop_char_t)stix->symtab->bucket->slot[i]; if ((stix_oop_t)symbol != stix->_nil) { - printf (" %lu [", (unsigned long int)i); - for (j = 0; j < STIX_OBJ_GET_SIZE(symbol); j++) - { - printf ("%c", symbol->slot[j]); - } - printf ("]\n"); + STIX_DEBUG2 (stix, " %07zu %O\n", i, symbol); } } - printf ("--------------------------------------------\n"); + + STIX_DEBUG0 (stix, "--------------------------------------------\n"); } -void dump_dictionary (stix_t* stix, stix_oop_set_t dic, const char* title) +void stix_dumpdic (stix_t* stix, stix_oop_set_t dic, const stix_bch_t* title) { stix_oow_t i, j; stix_oop_association_t ass; - printf ("--------------------------------------------\n"); - printf ("%s %lu\n", title, (unsigned long int)STIX_OBJ_GET_SIZE(dic->bucket)); - printf ("--------------------------------------------\n"); + STIX_DEBUG0 (stix, "--------------------------------------------\n"); + STIX_DEBUG2 (stix, "%s %zu\n", title, STIX_OBJ_GET_SIZE(dic->bucket)); + STIX_DEBUG0 (stix, "--------------------------------------------\n"); for (i = 0; i < STIX_OBJ_GET_SIZE(dic->bucket); i++) { ass = (stix_oop_association_t)dic->bucket->slot[i]; if ((stix_oop_t)ass != stix->_nil) { - printf (" %lu [", (unsigned long int)i); - for (j = 0; j < STIX_OBJ_GET_SIZE(ass->key); j++) - { - printf ("%c", ((stix_oop_char_t)ass->key)->slot[j]); - } - printf ("]\n"); + STIX_DEBUG2 (stix, " %07zu %O\n", i, ass->key); } } - printf ("--------------------------------------------\n"); -} - -void print_oocs (const stix_oocs_t* name) -{ - stix_oow_t i; - for (i = 0; i < name->len; i++) printf ("%c", name->ptr[i]); + STIX_DEBUG0 (stix, "--------------------------------------------\n"); } -void print_object (stix_t* stix, unsigned int mask, stix_oop_t oop) -{ - if (oop == stix->_nil) - { - stix_logbfmt (stix, mask, "nil"); - } - else if (oop == stix->_true) - { - stix_logbfmt (stix, mask, "true"); - } - else if (oop == stix->_false) - { - stix_logbfmt (stix, mask, "false"); - } - else if (STIX_OOP_IS_SMOOI(oop)) - { - stix_logbfmt (stix, mask, "%zd", STIX_OOP_TO_SMOOI(oop)); - } - else if (STIX_OOP_IS_CHAR(oop)) - { - stix_logbfmt (stix, mask, "$%.1C", STIX_OOP_TO_CHAR(oop)); - } - else - { - stix_oop_class_t c; - stix_oow_t i; - STIX_ASSERT (STIX_OOP_IS_POINTER(oop)); - c = (stix_oop_class_t)STIX_OBJ_GET_CLASS(oop); /*STIX_CLASSOF(stix, oop);*/ - - if ((stix_oop_t)c == stix->_large_negative_integer) - { - stix_oow_t i; - stix_logbfmt (stix, mask, "-16r"); - for (i = STIX_OBJ_GET_SIZE(oop); i > 0;) - { - stix_logbfmt (stix, mask, "%0*lX", (int)(STIX_SIZEOF(stix_liw_t) * 2), (unsigned long)((stix_oop_liword_t)oop)->slot[--i]); - } - } - else if ((stix_oop_t)c == stix->_large_positive_integer) - { - stix_oow_t i; - stix_logbfmt (stix, mask, "16r"); - for (i = STIX_OBJ_GET_SIZE(oop); i > 0;) - { - stix_logbfmt (stix, mask, "%0*lX", (int)(STIX_SIZEOF(stix_liw_t) * 2), (unsigned long)((stix_oop_liword_t)oop)->slot[--i]); - } - } - else if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_CHAR) - { - if ((stix_oop_t)c == stix->_symbol) stix_logbfmt (stix, mask, "#"); - else if ((stix_oop_t)c == stix->_string) stix_logbfmt (stix, mask, "'"); - - stix_logbfmt (stix, mask, "%.*S", STIX_OBJ_GET_SIZE(oop), ((stix_oop_char_t)oop)->slot); - if ((stix_oop_t)c == stix->_string) stix_logbfmt (stix, mask, "'"); - } - else if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_BYTE) - { - stix_logbfmt (stix, mask, "#["); - for (i = 0; i < STIX_OBJ_GET_SIZE(oop); i++) - { - stix_logbfmt (stix, mask, " %d", ((stix_oop_byte_t)oop)->slot[i]); - } - stix_logbfmt (stix, mask, "]"); - } - - else if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_HALFWORD) - { - stix_logbfmt (stix, mask, "#[["); /* TODO: fix this symbol/notation */ - for (i = 0; i < STIX_OBJ_GET_SIZE(oop); i++) - { - stix_logbfmt (stix, mask, " %zX", (stix_oow_t)((stix_oop_halfword_t)oop)->slot[i]); - } - stix_logbfmt (stix, mask, "]]"); - } - else if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_WORD) - { - stix_logbfmt (stix, mask, "#[[["); /* TODO: fix this symbol/notation */ - for (i = 0; i < STIX_OBJ_GET_SIZE(oop); i++) - { - stix_logbfmt (stix, mask, " %zX", ((stix_oop_word_t)oop)->slot[i]); - } - stix_logbfmt (stix, mask, "]]]"); - } - else if ((stix_oop_t)c == stix->_array) - { - stix_logbfmt (stix, mask, "#("); - for (i = 0; i < STIX_OBJ_GET_SIZE(oop); i++) - { - stix_logbfmt (stix, mask, " "); - print_object (stix, mask, ((stix_oop_oop_t)oop)->slot[i]); - } - stix_logbfmt (stix, mask, ")"); - } - else if ((stix_oop_t)c == stix->_class) - { - /* print the class name */ - stix_logbfmt (stix, mask, "%.*S", STIX_OBJ_GET_SIZE(((stix_oop_class_t)oop)->name), ((stix_oop_class_t)oop)->name->slot); - } - else - { - stix_logbfmt (stix, mask, "instance of %.*S(%p)", STIX_OBJ_GET_SIZE(c->name), ((stix_oop_char_t)c->name)->slot, oop); - } - } -} diff --git a/stix/lib/exec.c b/stix/lib/exec.c index 50ff2e0..86f739f 100644 --- a/stix/lib/exec.c +++ b/stix/lib/exec.c @@ -1079,7 +1079,7 @@ static stix_oop_method_t find_method (stix_t* stix, stix_oop_t receiver, const s STIX_ASSERT ((stix_oop_t)mthdic != stix->_nil); STIX_ASSERT (STIX_CLASSOF(stix, mthdic) == stix->_method_dictionary); -/*dump_dictionary (stix, mthdic, "Method dictionary");*/ +/*stix_dumpdic (stix, mthdic, "Method dictionary");*/ ass = (stix_oop_association_t)stix_lookupdic (stix, mthdic, message); if (ass) { diff --git a/stix/lib/gc.c b/stix/lib/gc.c index 2c26643..0b76bfe 100644 --- a/stix/lib/gc.c +++ b/stix/lib/gc.c @@ -399,7 +399,7 @@ void stix_gc (stix_t* stix) { stix_oow_t index; stix_oop_oop_t buc; - STIX_LOG0 (stix, STIX_LOG_GC | STIX_LOG_DEBUG, "=== SURVIVING SYMBOLS IN GC ===\n"); + STIX_LOG0 (stix, STIX_LOG_GC | STIX_LOG_DEBUG, "--------- SURVIVING SYMBOLS IN GC ----------\n"); buc = (stix_oop_oop_t) stix->symtab->bucket; for (index = 0; index < STIX_OBJ_GET_SIZE(buc); index++) { @@ -408,7 +408,7 @@ void stix_gc (stix_t* stix) STIX_LOG1 (stix, STIX_LOG_GC | STIX_LOG_DEBUG, "\t%O\n", buc->slot[index]); } } - STIX_LOG0 (stix, STIX_LOG_GC | STIX_LOG_DEBUG, "===============================\n"); + STIX_LOG0 (stix, STIX_LOG_GC | STIX_LOG_DEBUG, "--------------------------------------------\n"); } */ diff --git a/stix/lib/logfmt.c b/stix/lib/logfmt.c index 89b7d7f..00cb5c2 100644 --- a/stix/lib/logfmt.c +++ b/stix/lib/logfmt.c @@ -277,6 +277,114 @@ static int put_oocs (stix_t* stix, unsigned int mask, const stix_ooch_t* ptr, st /* ------------------------------------------------------------------------- */ +static void print_object (stix_t* stix, unsigned int mask, stix_oop_t oop) +{ + if (oop == stix->_nil) + { + stix_logbfmt (stix, mask, "nil"); + } + else if (oop == stix->_true) + { + stix_logbfmt (stix, mask, "true"); + } + else if (oop == stix->_false) + { + stix_logbfmt (stix, mask, "false"); + } + else if (STIX_OOP_IS_SMOOI(oop)) + { + stix_logbfmt (stix, mask, "%zd", STIX_OOP_TO_SMOOI(oop)); + } + else if (STIX_OOP_IS_CHAR(oop)) + { + stix_logbfmt (stix, mask, "$%.1C", STIX_OOP_TO_CHAR(oop)); + } + else + { + stix_oop_class_t c; + stix_oow_t i; + + STIX_ASSERT (STIX_OOP_IS_POINTER(oop)); + c = (stix_oop_class_t)STIX_OBJ_GET_CLASS(oop); /*STIX_CLASSOF(stix, oop);*/ + + if ((stix_oop_t)c == stix->_large_negative_integer) + { + stix_oow_t i; + stix_logbfmt (stix, mask, "-16r"); + for (i = STIX_OBJ_GET_SIZE(oop); i > 0;) + { + stix_logbfmt (stix, mask, "%0*lX", (int)(STIX_SIZEOF(stix_liw_t) * 2), (unsigned long)((stix_oop_liword_t)oop)->slot[--i]); + } + } + else if ((stix_oop_t)c == stix->_large_positive_integer) + { + stix_oow_t i; + stix_logbfmt (stix, mask, "16r"); + for (i = STIX_OBJ_GET_SIZE(oop); i > 0;) + { + stix_logbfmt (stix, mask, "%0*lX", (int)(STIX_SIZEOF(stix_liw_t) * 2), (unsigned long)((stix_oop_liword_t)oop)->slot[--i]); + } + } + else if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_CHAR) + { + if ((stix_oop_t)c == stix->_symbol) stix_logbfmt (stix, mask, "#"); + else if ((stix_oop_t)c == stix->_string) stix_logbfmt (stix, mask, "'"); + + stix_logbfmt (stix, mask, "%.*S", STIX_OBJ_GET_SIZE(oop), ((stix_oop_char_t)oop)->slot); + if ((stix_oop_t)c == stix->_string) stix_logbfmt (stix, mask, "'"); + } + else if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_BYTE) + { + stix_logbfmt (stix, mask, "#["); + for (i = 0; i < STIX_OBJ_GET_SIZE(oop); i++) + { + stix_logbfmt (stix, mask, " %d", ((stix_oop_byte_t)oop)->slot[i]); + } + stix_logbfmt (stix, mask, "]"); + } + + else if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_HALFWORD) + { + stix_logbfmt (stix, mask, "#[["); /* TODO: fix this symbol/notation */ + for (i = 0; i < STIX_OBJ_GET_SIZE(oop); i++) + { + stix_logbfmt (stix, mask, " %zX", (stix_oow_t)((stix_oop_halfword_t)oop)->slot[i]); + } + stix_logbfmt (stix, mask, "]]"); + } + else if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_WORD) + { + stix_logbfmt (stix, mask, "#[[["); /* TODO: fix this symbol/notation */ + for (i = 0; i < STIX_OBJ_GET_SIZE(oop); i++) + { + stix_logbfmt (stix, mask, " %zX", ((stix_oop_word_t)oop)->slot[i]); + } + stix_logbfmt (stix, mask, "]]]"); + } + else if ((stix_oop_t)c == stix->_array) + { + stix_logbfmt (stix, mask, "#("); + for (i = 0; i < STIX_OBJ_GET_SIZE(oop); i++) + { + stix_logbfmt (stix, mask, " "); + print_object (stix, mask, ((stix_oop_oop_t)oop)->slot[i]); + } + stix_logbfmt (stix, mask, ")"); + } + else if ((stix_oop_t)c == stix->_class) + { + /* print the class name */ + stix_logbfmt (stix, mask, "%.*S", STIX_OBJ_GET_SIZE(((stix_oop_class_t)oop)->name), ((stix_oop_class_t)oop)->name->slot); + } + else + { + stix_logbfmt (stix, mask, "instance of %.*S(%p)", STIX_OBJ_GET_SIZE(c->name), ((stix_oop_char_t)c->name)->slot, oop); + } + } +} + +/* ------------------------------------------------------------------------- */ + #undef fmtchar_t #undef logfmtv #define fmtchar_t stix_bch_t diff --git a/stix/lib/main.c b/stix/lib/main.c index bd9e48c..42f40ad 100644 --- a/stix/lib/main.c +++ b/stix/lib/main.c @@ -336,7 +336,7 @@ static void log_write (stix_t* stix, unsigned int mask, const stix_ooch_t* msg, # error NOT IMPLEMENTED #else - stix_bch_t buf[10]; + stix_bch_t buf[256]; stix_oow_t ucslen, bcslen, msgidx; int n; @@ -529,12 +529,12 @@ static void cancel_tick (void) itv.it_interval.tv_sec = 0; itv.it_interval.tv_usec = 0; - itv.it_value.tv_sec = 0; + itv.it_value.tv_sec = 0; /* make setitimer() one-shot only */ itv.it_value.tv_usec = 0; setitimer (ITIMER_VIRTUAL, &itv, STIX_NULL); - sigemptyset (&act.sa_mask); - act.sa_handler = SIG_DFL; + sigemptyset (&act.sa_mask); + act.sa_handler = SIG_IGN; /* ignore the signal potentially fired by the one-shot arrange above */ act.sa_flags = 0; sigaction (SIGVTALRM, &act, STIX_NULL); @@ -554,19 +554,6 @@ int main (int argc, char* argv[]) stix_vmprim_t vmprim; int i, xret; - printf ("Stix 1.0.0 - max named %lu max indexed %lu max class %lu max classinst %lu oowmax %lu, ooimax %ld ooimin %ld smooimax %ld smooimax %ld\n", - (unsigned long int)STIX_MAX_NAMED_INSTVARS, - (unsigned long int)STIX_MAX_INDEXED_INSTVARS(STIX_MAX_NAMED_INSTVARS), - (unsigned long int)STIX_MAX_CLASSVARS, - (unsigned long int)STIX_MAX_CLASSINSTVARS, - (unsigned long int)STIX_TYPE_MAX(stix_oow_t), - (long int)STIX_TYPE_MAX(stix_ooi_t), - (long int)STIX_TYPE_MIN(stix_ooi_t), - (long)STIX_SMOOI_MAX, (long)STIX_SMOOI_MIN); - - printf ("STIX_SMOOI_MIN + STIX_SMOOI_MIN => %ld\n", (long)(STIX_SMOOI_MIN + STIX_SMOOI_MIN)); - printf ("STIX_SMOOI_MIN - STIX_SMOOI_MAX => %ld\n", (long)(STIX_SMOOI_MIN - STIX_SMOOI_MAX)); - #if !defined(macintosh) if (argc < 2) { @@ -704,6 +691,9 @@ int main (int argc, char* argv[]) cancel_tick (); g_stix = STIX_NULL; +stix_dumpsymtab(stix); +stix_dumpdic(stix, stix->sysdic, "System dictionary"); + stix_close (stix); #if defined(USE_LTDL) diff --git a/stix/lib/stix-prv.h b/stix/lib/stix-prv.h index 3ac46e3..f3f02da 100644 --- a/stix/lib/stix-prv.h +++ b/stix/lib/stix-prv.h @@ -46,7 +46,7 @@ /* this is for gc debugging */ /* #define STIX_DEBUG_GC */ -#define SIIX_DEBUG_COMPILER +#define STIX_DEBUG_COMPILER /*#define STIX_DEBUG_VM_PROCESSOR*/ /*#define STIX_DEBUG_VM_EXEC*/ /*#define STIX_DEBUG_VM_METHOD_LOOKUP*/ @@ -1325,11 +1325,8 @@ int stix_getprimno ( /* ========================================================================= */ /* debug.c */ /* ========================================================================= */ -void dump_symbol_table (stix_t* stix); -void dump_dictionary (stix_t* stix, stix_oop_set_t dic, const char* title); -void print_oocs (const stix_oocs_t* name); -void print_object (stix_t* stix, unsigned int mask, stix_oop_t oop); - +void stix_dumpsymtab (stix_t* stix); +void stix_dumpdic (stix_t* stix, stix_oop_set_t dic, const stix_bch_t* title); #if defined(__cplusplus)