added test code for bootstrapping
This commit is contained in:
parent
682cfc1949
commit
121f0145fa
@ -1,28 +1,68 @@
|
||||
#include <qse/stx/stx.h>
|
||||
/*#include <qse/stx/stx.h>*/
|
||||
#include "../../lib/stx/stx.h"
|
||||
#include <qse/cmn/main.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
|
||||
#if 0
|
||||
#include <qse/stx/bootstrp.h>
|
||||
#include <qse/stx/object.h>
|
||||
#include <qse/stx/symbol.h>
|
||||
#include <qse/stx/context.h>
|
||||
#include <qse/stx/class.h>
|
||||
#include <qse/stx/dict.h>
|
||||
#endif
|
||||
void print_class_name (qse_stx_t* stx, qse_word_t class, int tabs);
|
||||
void print_metaclass_name (qse_stx_t* stx, qse_word_t class, int tabs);
|
||||
|
||||
#if 0
|
||||
void print_symbol_names (qse_stx_t* stx, qse_word_t sym, void* unused)
|
||||
|
||||
void print_system_symbol_table (qse_stx_t* stx)
|
||||
{
|
||||
qse_printf (QSE_T("%lu [%s]\n"), (unsigned long)sym, QSE_STX_DATA(stx,sym));
|
||||
qse_word_t ref = stx->ref.symtab;
|
||||
qse_word_t capa, i;
|
||||
|
||||
capa = QSE_STX_OBJSIZE(stx,ref) - 1;
|
||||
qse_printf (QSE_T("TALLY = %d\n"), QSE_STX_REFTOINT(stx,QSE_STX_WORDAT(stx,ref,QSE_STX_SYSTEMSYMBOLTABLE_TALLY)));
|
||||
for (i = 1; i <= capa; i++)
|
||||
{
|
||||
qse_word_t symref = QSE_STX_WORDAT(stx,ref,i);
|
||||
if (symref != stx->ref.nil)
|
||||
{
|
||||
qse_printf (QSE_T("%lu [%s]\n"), (unsigned long)symref, QSE_STX_CHARPTR(stx,symref));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void print_symbol_names_2 (qse_stx_t* stx, qse_word_t idx, void* unused)
|
||||
void print_system_dictionary (qse_stx_t* stx)
|
||||
{
|
||||
qse_word_t key = QSE_STX_WORD_AT(stx,idx,QSE_STX_ASSOCIATION_KEY);
|
||||
qse_word_t value = QSE_STX_WORD_AT(stx,idx,QSE_STX_ASSOCIATION_VALUE);
|
||||
qse_printf (QSE_T("%lu [%s] %lu\n"),
|
||||
(unsigned long)key, QSE_STX_DATA(stx,key), (unsigned long)value);
|
||||
qse_word_t ref = stx->ref.sysdic;
|
||||
qse_word_t capa, i;
|
||||
|
||||
capa = QSE_STX_OBJSIZE(stx,ref) - 1;
|
||||
qse_printf (QSE_T("TALLY = %d\n"), QSE_STX_REFTOINT(stx,QSE_STX_WORDAT(stx,ref,QSE_STX_SYSTEMSYMBOLTABLE_TALLY)));
|
||||
for (i = 1; i <= capa; i++)
|
||||
{
|
||||
qse_word_t assref = QSE_STX_WORDAT(stx,ref,i);
|
||||
if (assref != stx->ref.nil)
|
||||
{
|
||||
qse_word_t keyref = QSE_STX_WORDAT(stx,assref,QSE_STX_ASSOCIATION_KEY);
|
||||
qse_word_t valref = QSE_STX_WORDAT(stx,assref,QSE_STX_ASSOCIATION_VALUE);
|
||||
qse_char_t value[128] = QSE_T("");
|
||||
|
||||
qse_word_t vcref = QSE_STX_OBJCLASS(stx,valref);
|
||||
|
||||
if (QSE_STX_OBJCLASS(stx,vcref) == stx->ref.class_metaclass)
|
||||
{
|
||||
qse_word_t nameref = QSE_STX_WORDAT(stx,valref,QSE_STX_CLASS_NAME);
|
||||
qse_sprintf (value, QSE_COUNTOF(value),
|
||||
QSE_T("<<%s>>"), QSE_STX_CHARPTR(stx,nameref));
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_word_t nameref = QSE_STX_WORDAT(stx,vcref,QSE_STX_CLASS_NAME);
|
||||
qse_sprintf (value, QSE_COUNTOF(value),
|
||||
QSE_T("instance of <<%s>>"), QSE_STX_CHARPTR(stx,nameref));
|
||||
}
|
||||
|
||||
/* i dind't use other object types for a key... so keys must be symbols */
|
||||
QSE_ASSERT (QSE_STX_OBJCLASS(stx,keyref) == stx->ref.class_symbol);
|
||||
|
||||
qse_printf (QSE_T("%lu [%s] => %s\n"),
|
||||
(unsigned long)keyref, QSE_STX_CHARPTR(stx,keyref), value
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void print_superclasses (qse_stx_t* stx, const qse_char_t* name)
|
||||
@ -30,14 +70,13 @@ void print_superclasses (qse_stx_t* stx, const qse_char_t* name)
|
||||
qse_word_t n;
|
||||
qse_stx_class_t* obj;
|
||||
|
||||
n = qse_stx_lookup_class (stx, name);
|
||||
n = qse_stx_findclass (stx, name);
|
||||
qse_printf (QSE_T("Class hierarchy for the class '%s'\n"), name);
|
||||
|
||||
while (n != stx->nil) {
|
||||
obj = (qse_stx_class_t*)QSE_STX_WORD_OBJECT(stx,n);
|
||||
qse_printf (QSE_T("%lu, %s\n"),
|
||||
(unsigned long)obj->name,
|
||||
QSE_STX_DATA(stx, obj->name));
|
||||
while (n != stx->ref.nil)
|
||||
{
|
||||
obj = (qse_stx_class_t*)PTRBYREF(stx,n);
|
||||
qse_printf (QSE_T("%lu, %s\n"), (unsigned long)obj->name, CHARPTR(stx, obj->name));
|
||||
n = obj->superclass;
|
||||
}
|
||||
}
|
||||
@ -48,27 +87,39 @@ void print_metaclass_superclasses (qse_stx_t* stx, const qse_char_t* name)
|
||||
qse_stx_metaclass_t* obj;
|
||||
qse_stx_class_t* xobj;
|
||||
|
||||
n = qse_stx_lookup_class (stx, name);
|
||||
n = QSE_STX_CLASS(stx,n);
|
||||
n = qse_stx_findclass (stx, name);
|
||||
|
||||
n = QSE_STX_OBJCLASS(stx,n);
|
||||
qse_printf (QSE_T("Class hierarchy for the metaclass '%s class'\n"), name);
|
||||
|
||||
while (n != stx->nil) {
|
||||
while (n != stx->ref.nil)
|
||||
{
|
||||
/*if (n == stx->class_class) break; */
|
||||
if (QSE_STX_CLASS(stx,n) != stx->class_metaclass) break;
|
||||
if (QSE_STX_OBJCLASS(stx,n) != stx->ref.class_metaclass)
|
||||
{
|
||||
/* probably reached the superclass of
|
||||
* 'Object class' which is 'Class' * */
|
||||
break;
|
||||
}
|
||||
|
||||
obj = (qse_stx_metaclass_t*)QSE_STX_WORD_OBJECT(stx,n);
|
||||
obj = (qse_stx_metaclass_t*)QSE_STX_PTRBYREF(stx,n);
|
||||
x = obj->instance_class;
|
||||
xobj = (qse_stx_class_t*)QSE_STX_WORD_OBJECT(stx,x);
|
||||
|
||||
xobj = (qse_stx_class_t*)QSE_STX_PTRBYREF(stx,x);
|
||||
qse_printf (QSE_T("%lu, %s class\n"),
|
||||
(unsigned long)xobj->name,
|
||||
QSE_STX_DATA(stx, xobj->name));
|
||||
CHARPTR(stx, xobj->name));
|
||||
|
||||
|
||||
n = obj->superclass;
|
||||
}
|
||||
while (n != stx->nil) {
|
||||
xobj = (qse_stx_class_t*)QSE_STX_WORD_OBJECT(stx,n);
|
||||
|
||||
while (n != stx->ref.nil)
|
||||
{
|
||||
xobj = (qse_stx_class_t*)QSE_STX_PTRBYREF(stx,n);
|
||||
qse_printf (QSE_T("%lu, %s\n"),
|
||||
(unsigned long)xobj->name,
|
||||
QSE_STX_DATA(stx, xobj->name));
|
||||
CHARPTR(stx, xobj->name));
|
||||
n = xobj->superclass;
|
||||
}
|
||||
}
|
||||
@ -76,12 +127,12 @@ void print_metaclass_superclasses (qse_stx_t* stx, const qse_char_t* name)
|
||||
void print_class_name (qse_stx_t* stx, qse_word_t class, int tabs)
|
||||
{
|
||||
qse_stx_class_t* xobj;
|
||||
xobj = (qse_stx_class_t*)QSE_STX_WORD_OBJECT(stx,class);
|
||||
xobj = (qse_stx_class_t*)QSE_STX_PTRBYREF(stx,class);
|
||||
|
||||
while (tabs-- > 0) qse_printf (QSE_T(" "));
|
||||
|
||||
qse_printf (QSE_T("%s [%lu]\n"),
|
||||
QSE_STX_DATA(stx, xobj->name),
|
||||
CHARPTR(stx, xobj->name),
|
||||
(unsigned long)class);
|
||||
}
|
||||
|
||||
@ -90,13 +141,13 @@ void print_metaclass_name (qse_stx_t* stx, qse_word_t class, int tabs)
|
||||
qse_stx_metaclass_t* obj;
|
||||
qse_stx_class_t* xobj;
|
||||
|
||||
obj = (qse_stx_metaclass_t*)QSE_STX_WORD_OBJECT(stx,class);
|
||||
xobj = (qse_stx_class_t*)QSE_STX_WORD_OBJECT(stx,obj->instance_class);
|
||||
obj = (qse_stx_metaclass_t*)QSE_STX_PTRBYREF(stx,class);
|
||||
xobj = (qse_stx_class_t*)QSE_STX_PTRBYREF(stx,obj->instance_class);
|
||||
|
||||
while (tabs-- > 0) qse_printf (QSE_T(" "));
|
||||
|
||||
qse_printf (QSE_T("%s class [%lu]\n"),
|
||||
QSE_STX_DATA(stx, xobj->name),
|
||||
CHARPTR(stx, xobj->name),
|
||||
(unsigned long)class);
|
||||
}
|
||||
|
||||
@ -104,19 +155,23 @@ void print_subclass_names (qse_stx_t* stx, qse_word_t class, int tabs)
|
||||
{
|
||||
qse_stx_class_t* obj;
|
||||
|
||||
obj = (qse_stx_class_t*)QSE_STX_WORD_OBJECT(stx,class);
|
||||
if (obj->header.class == stx->class_metaclass) {
|
||||
if (QSE_STX_OBJCLASS(stx,class) == stx->ref.class_metaclass)
|
||||
{
|
||||
print_metaclass_name (stx, class, tabs);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
print_class_name (stx, class, tabs);
|
||||
}
|
||||
|
||||
if (obj->subclasses != stx->nil) {
|
||||
qse_word_t count = QSE_STX_SIZE(stx, obj->subclasses);
|
||||
while (count-- > 0) {
|
||||
obj = (qse_stx_class_t*)QSE_STX_PTRBYREF(stx,class);
|
||||
if (obj->subclasses != stx->ref.nil)
|
||||
{
|
||||
qse_word_t count = QSE_STX_OBJSIZE(stx, obj->subclasses);
|
||||
while (count-- > 0)
|
||||
{
|
||||
print_subclass_names (stx,
|
||||
QSE_STX_WORD_AT(stx,obj->subclasses,count), tabs + 1);
|
||||
QSE_STX_WORDAT(stx,obj->subclasses,count), tabs + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -124,73 +179,71 @@ void print_subclass_names (qse_stx_t* stx, qse_word_t class, int tabs)
|
||||
void print_subclasses (qse_stx_t* stx, const qse_char_t* name)
|
||||
{
|
||||
qse_word_t class;
|
||||
class = qse_stx_lookup_class (stx, name);
|
||||
class = qse_stx_findclass (stx, name);
|
||||
qse_printf (QSE_T("== NORMAL == \n"));
|
||||
print_subclass_names (stx, class, 0);
|
||||
qse_printf (QSE_T("== META == \n"));
|
||||
print_subclass_names (stx, QSE_STX_CLASS(stx,class), 0);
|
||||
print_subclass_names (stx, QSE_STX_OBJCLASS(stx,class), 0);
|
||||
}
|
||||
|
||||
static int stx_main (int argc, qse_char_t* argv[])
|
||||
{
|
||||
qse_stx_t stx;
|
||||
qse_stx_t* stx;
|
||||
//qse_word_t i;
|
||||
|
||||
#ifndef _DOS
|
||||
if (qse_setlocale () == -1) {
|
||||
printf ("cannot set locale\n");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
if (argc != 2) { /* TODO: argument processing */
|
||||
qse_printf (QSE_T("Usage: %s [-f imageFile] MainClass\n"), argv[0]);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (qse_stx_open (&stx, 10000) == QSE_NULL) {
|
||||
stx = qse_stx_open (QSE_NULL, 0, 10000);
|
||||
if (stx == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("cannot open stx\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qse_stx_bootstrap(&stx) == -1) {
|
||||
qse_stx_close (&stx);
|
||||
if (qse_stx_boot(stx) <= -1)
|
||||
{
|
||||
qse_stx_close (stx);
|
||||
qse_printf (QSE_T("cannot bootstrap\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("stx.nil %lu\n"), (unsigned long)stx.nil);
|
||||
qse_printf (QSE_T("stx.true %lu\n"), (unsigned long)stx.true);
|
||||
qse_printf (QSE_T("stx.false %lu\n"), (unsigned long)stx.false);
|
||||
qse_printf (QSE_T("stx.nil %lu %lu\n"), (unsigned long)stx->ref.nil, (unsigned long)QSE_STX_REFTOIDX(stx,stx->ref.nil));
|
||||
qse_printf (QSE_T("stx.true %lu %lu\n"), (unsigned long)stx->ref.true, (unsigned long)QSE_STX_REFTOIDX(stx,stx->ref.true));
|
||||
qse_printf (QSE_T("stx.false %lu %lu\n"), (unsigned long)stx->ref.false, (unsigned long)QSE_STX_REFTOIDX(stx,stx->ref.false));
|
||||
qse_printf (QSE_T("-------------\n"));
|
||||
|
||||
|
||||
qse_printf (QSE_T(">> SYMBOL_TABLE (%u/%u symbols/slots) <<\n"),
|
||||
(unsigned int)stx.symtab.size, (unsigned int)stx.symtab.capacity);
|
||||
qse_stx_traverse_symbol_table (&stx, print_symbol_names, QSE_NULL);
|
||||
qse_printf (QSE_T(">> SYSTEM_SYMBOL_TABLE\n"));
|
||||
print_system_symbol_table (stx);
|
||||
qse_printf (QSE_T("-------------\n"));
|
||||
|
||||
qse_stx_dict_traverse (&stx, stx.smalltalk, print_symbol_names_2, QSE_NULL);
|
||||
qse_printf (QSE_T(">> SYSTEM_DICTIONARY\n"));
|
||||
print_system_dictionary (stx);
|
||||
qse_printf (QSE_T("-------------\n"));
|
||||
|
||||
print_superclasses (&stx, QSE_T("Array"));
|
||||
print_superclasses (stx, QSE_T("Array"));
|
||||
qse_printf (QSE_T("-------------\n"));
|
||||
print_metaclass_superclasses (&stx, QSE_T("Array"));
|
||||
print_metaclass_superclasses (stx, QSE_T("Array"));
|
||||
qse_printf (QSE_T("-------------\n"));
|
||||
print_superclasses (&stx, QSE_T("False"));
|
||||
print_superclasses (stx, QSE_T("False"));
|
||||
qse_printf (QSE_T("-------------\n"));
|
||||
print_metaclass_superclasses (&stx, QSE_T("False"));
|
||||
print_metaclass_superclasses (stx, QSE_T("False"));
|
||||
qse_printf (QSE_T("-------------\n"));
|
||||
print_superclasses (&stx, QSE_T("Metaclass"));
|
||||
print_superclasses (stx, QSE_T("Metaclass"));
|
||||
qse_printf (QSE_T("-------------\n"));
|
||||
print_metaclass_superclasses (&stx, QSE_T("Metaclass"));
|
||||
print_metaclass_superclasses (stx, QSE_T("Metaclass"));
|
||||
qse_printf (QSE_T("-------------\n"));
|
||||
print_superclasses (&stx, QSE_T("Class"));
|
||||
print_superclasses (stx, QSE_T("Class"));
|
||||
qse_printf (QSE_T("-------------\n"));
|
||||
print_metaclass_superclasses (&stx, QSE_T("Class"));
|
||||
print_metaclass_superclasses (stx, QSE_T("Class"));
|
||||
qse_printf (QSE_T("-------------\n"));
|
||||
|
||||
print_subclasses (&stx, QSE_T("Object"));
|
||||
print_subclasses (stx, QSE_T("Object"));
|
||||
qse_printf (QSE_T("-------------\n"));
|
||||
|
||||
#if 0
|
||||
@ -199,52 +252,36 @@ static int stx_main (int argc, qse_char_t* argv[])
|
||||
qse_word_t main_class;
|
||||
qse_word_t method, context;
|
||||
|
||||
method_name = qse_stx_new_symbol (&stx,QSE_T("main"));
|
||||
method_name = qse_stx_new_symbol (stx,QSE_T("main"));
|
||||
|
||||
main_class = qse_stx_lookup_class (&stx,argv[1]);
|
||||
main_class = qse_stx_findclass (stx,argv[1]);
|
||||
if (main_class == stx.nil) {
|
||||
qse_printf (QSE_T("non-existent class: %s\n"), argv[1]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
method = qse_stx_alloc_byte_object (&stx,100);
|
||||
QSE_STX_CLASS(&stx,method) = stx.class_method;
|
||||
method = qse_stx_alloc_byte_object (stx,100);
|
||||
QSE_STX_CLASS(stx,method) = stx.class_method;
|
||||
*/
|
||||
method = qse_stx_instantiate (&stx, QSE_T("Method"));
|
||||
method = qse_stx_instantiate (stx, QSE_T("Method"));
|
||||
|
||||
QSE_STX_BYTEAT(&stx,method,0) = PUSH_OBJECT;
|
||||
QSE_STX_BYTEAT(&stx,method,1) = main_class;
|
||||
QSE_STX_BYTEAT(&stx,method,2) = SEND_UNARY_MESSAGE;
|
||||
QSE_STX_BYTEAT(&stx,method,3) = method_name;
|
||||
QSE_STX_BYTEAT(&stx,method,4) = HALT;
|
||||
QSE_STX_BYTEAT(stx,method,0) = PUSH_OBJECT;
|
||||
QSE_STX_BYTEAT(stx,method,1) = main_class;
|
||||
QSE_STX_BYTEAT(stx,method,2) = SEND_UNARY_MESSAGE;
|
||||
QSE_STX_BYTEAT(stx,method,3) = method_name;
|
||||
QSE_STX_BYTEAT(stx,method,4) = HALT;
|
||||
|
||||
/*
|
||||
context = qse_stx_new_context (&stx, method, stx.nil, stx.nil);
|
||||
context = qse_stx_new_context (stx, method, stx.nil, stx.nil);
|
||||
*/
|
||||
context = qse_stx_instantiate (&stx, QSE_T("Context"));
|
||||
qse_stx_run_context (&stx, context);
|
||||
context = qse_stx_instantiate (stx, QSE_T("Context"));
|
||||
qse_stx_runcontext (stx, context);
|
||||
}
|
||||
#endif
|
||||
|
||||
qse_stx_close (&stx);
|
||||
qse_printf (QSE_T("== End of program ==\n"));
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int stx_main (int argc, qse_char_t* argv[])
|
||||
{
|
||||
qse_stx_t* stx;
|
||||
|
||||
stx = qse_stx_open (QSE_NULL, 0, 1000);
|
||||
if (stx == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("Cannot open stx\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_stx_close (stx);
|
||||
qse_printf (QSE_T("== End of program ==\n"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -477,7 +477,6 @@ static int sketch_nil (qse_stx_t* stx)
|
||||
ptr->h._class = stx->ref.nil; /* the class is yet to be set */
|
||||
ptr->h._backref = ref;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -517,7 +516,7 @@ static int sketch_key_objects (qse_stx_t* stx)
|
||||
/* TODO: initial symbol table size */
|
||||
ALLOC_WORDOBJ_TO (stx, stx->ref.symtab, 1, SYMTAB_INIT_CAPA);
|
||||
/* Set tally to 0. */
|
||||
WORDAT(stx,stx->ref.symtab,QSE_STX_SYMTAB_TALLY) = INTTOREF(stx,0);
|
||||
WORDAT(stx,stx->ref.symtab,QSE_STX_SYSTEMSYMBOLTABLE_TALLY) = INTTOREF(stx,0);
|
||||
|
||||
/* Create a global system dictionary partially initialized.
|
||||
* Especially, the class of the system dictionary is not set yet.
|
||||
@ -871,10 +870,16 @@ static void filein_kernel_source (qse_stx_t* stx)
|
||||
|
||||
int qse_stx_boot (qse_stx_t* stx)
|
||||
{
|
||||
/* create nil, true, false references */
|
||||
/* you must not call this function more than once... */
|
||||
QSE_ASSERTX (
|
||||
stx->ref.nil == 0 &&
|
||||
stx->ref.true == 0 &&
|
||||
stx->ref.false == 0,
|
||||
"You must not call qse_stx_boot() more than once"
|
||||
);
|
||||
|
||||
if (sketch_nil (stx) <= -1) return -1;
|
||||
|
||||
/* continue intializing other key objects */
|
||||
if (sketch_key_objects (stx) <= -1) return -1;
|
||||
|
||||
if (make_key_classes (stx) <= -1) return -1;
|
||||
@ -892,3 +897,9 @@ int qse_stx_boot (qse_stx_t* stx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* for debugging for the time begin ... */
|
||||
qse_word_t qse_stx_findclass (qse_stx_t* stx, const qse_char_t* name)
|
||||
{
|
||||
return find_class (stx, name);
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ int qse_stx_boot (
|
||||
qse_stx_t* stx
|
||||
);
|
||||
|
||||
|
||||
qse_word_t qse_stx_findclass (qse_stx_t* stx, const qse_char_t* name);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -8,6 +8,29 @@
|
||||
#include <qse/stx/dict.h>
|
||||
#include <qse/stx/misc.h>
|
||||
|
||||
qse_char_t* qse_stx_strword (
|
||||
const qse_char_t* str, const qse_char_t* word, qse_word_t* word_index)
|
||||
{
|
||||
qse_char_t* p = (qse_char_t*)str;
|
||||
qse_char_t* tok;
|
||||
qse_size_t len;
|
||||
qse_word_t index = 0;
|
||||
|
||||
while (p != QSE_NULL)
|
||||
{
|
||||
p = qse_strtok (p, QSE_T(""), &tok, &len);
|
||||
if (qse_strxcmp (tok, len, word) == 0)
|
||||
{
|
||||
*word_index = index;
|
||||
return tok;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
*word_index = index;
|
||||
return QSE_NULL;
|
||||
}
|
||||
qse_word_t qse_stx_newclass (qse_stx_t* stx, const qse_char_t* name)
|
||||
{
|
||||
qse_word_t meta, class;
|
||||
|
@ -5,6 +5,30 @@
|
||||
#include "stx.h"
|
||||
|
||||
#if 0
|
||||
qse_char_t* qse_stx_strword (
|
||||
const qse_char_t* str, const qse_char_t* word, qse_word_t* word_index)
|
||||
{
|
||||
qse_char_t* p = (qse_char_t*)str;
|
||||
qse_char_t* tok;
|
||||
qse_size_t len;
|
||||
qse_word_t index = 0;
|
||||
|
||||
while (p != QSE_NULL)
|
||||
{
|
||||
p = qse_strtok (p, QSE_T(""), &tok, &len);
|
||||
if (qse_strxcmp (tok, len, word) == 0)
|
||||
{
|
||||
*word_index = index;
|
||||
return tok;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
*word_index = index;
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
int qse_stx_get_instance_variable_index (
|
||||
qse_stx_t* stx, qse_word_t class_index,
|
||||
const qse_char_t* name, qse_word_t* index)
|
||||
@ -139,7 +163,6 @@ qse_word_t qse_stx_instantiate (
|
||||
QSE_ASSERT (OBJCLASS(stx,classref) != stx->ref.class_metaclass);
|
||||
|
||||
classptr = (qse_stx_class_t*)PTRBYREF(stx,classref);
|
||||
qse_printf (QSE_T("instantiating ... %s\n"), ((qse_stx_charobj_t*)PTRBYREF(stx,classptr->name))->fld);
|
||||
QSE_ASSERT (REFISINT(stx,classptr->spec));
|
||||
|
||||
spec = REFTOINT(stx,classptr->spec);
|
||||
|
@ -33,7 +33,8 @@ qse_word_t qse_stx_hashstr (qse_stx_t* stx, const qse_char_t* str)
|
||||
return h;
|
||||
}
|
||||
|
||||
qse_word_t qse_stx_hashstrx (qse_stx_t* stx, const qse_char_t* str, qse_word_t len)
|
||||
qse_word_t qse_stx_hashstrx (
|
||||
qse_stx_t* stx, const qse_char_t* str, qse_word_t len)
|
||||
{
|
||||
return qse_stx_hashbytes (stx, str, len * QSE_SIZEOF(*str));
|
||||
}
|
||||
@ -54,8 +55,8 @@ qse_word_t qse_stx_hashobj (qse_stx_t* stx, qse_word_t ref)
|
||||
case BYTEOBJ:
|
||||
hv = qse_stx_hashbytes (
|
||||
stx,
|
||||
&BYTEAT(stx,ref,0),
|
||||
OBJSIZE(stx,ref)
|
||||
BYTEPTR(stx,ref),
|
||||
BYTELEN(stx,ref)
|
||||
);
|
||||
break;
|
||||
|
||||
@ -78,7 +79,7 @@ qse_word_t qse_stx_hashobj (qse_stx_t* stx, qse_word_t ref)
|
||||
|
||||
default:
|
||||
QSE_ASSERT (
|
||||
!"This should never happen"
|
||||
!"This must never happen"
|
||||
);
|
||||
break;
|
||||
}
|
||||
@ -86,29 +87,3 @@ qse_word_t qse_stx_hashobj (qse_stx_t* stx, qse_word_t ref)
|
||||
|
||||
return hv;
|
||||
}
|
||||
|
||||
#if 0
|
||||
qse_char_t* qse_stx_strword (
|
||||
const qse_char_t* str, const qse_char_t* word, qse_word_t* word_index)
|
||||
{
|
||||
qse_char_t* p = (qse_char_t*)str;
|
||||
qse_char_t* tok;
|
||||
qse_size_t len;
|
||||
qse_word_t index = 0;
|
||||
|
||||
while (p != QSE_NULL)
|
||||
{
|
||||
p = qse_strtok (p, QSE_T(""), &tok, &len);
|
||||
if (qse_strxcmp (tok, len, word) == 0)
|
||||
{
|
||||
*word_index = index;
|
||||
return tok;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
*word_index = index;
|
||||
return QSE_NULL;
|
||||
}
|
||||
#endif
|
||||
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include "stx.h"
|
||||
#include <qse/cmn/str.h>
|
||||
|
||||
qse_word_t qse_stx_hashbyte (qse_stx_t* stx, const void* data, qse_word_t len)
|
||||
{
|
||||
qse_word_t h = 0;
|
||||
qse_byte_t* bp, * be;
|
||||
|
||||
bp = (qse_byte_t*)data; be = bp + len;
|
||||
while (bp < be) h = h * 31 + *bp++;
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
qse_word_t qse_stx_hashstr (qse_stx_t* stx, const qse_char_t* str)
|
||||
{
|
||||
qse_word_t h = 0;
|
||||
qse_byte_t* bp, * be;
|
||||
const qse_char_t* p = str;
|
||||
|
||||
while (*p != QSE_T('\0'))
|
||||
{
|
||||
bp = (qse_byte_t*)p;
|
||||
be = bp + QSE_SIZEOF(qse_char_t);
|
||||
while (bp < be) h = h * 31 + *bp++;
|
||||
p++;
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
qse_word_t qse_stx_hashstrx (qse_stx_t* stx, const qse_char_t* str, qse_word_t len)
|
||||
{
|
||||
return qse_stx_hashbytes (stx, str, len * QSE_SIZEOF(*str));
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
qse_char_t* qse_stx_strword (
|
||||
const qse_char_t* str, const qse_char_t* word, qse_word_t* word_index)
|
||||
{
|
||||
qse_char_t* p = (qse_char_t*)str;
|
||||
qse_char_t* tok;
|
||||
qse_size_t len;
|
||||
qse_word_t index = 0;
|
||||
|
||||
while (p != QSE_NULL)
|
||||
{
|
||||
p = qse_strtok (p, QSE_T(""), &tok, &len);
|
||||
if (qse_strxcmp (tok, len, word) == 0)
|
||||
{
|
||||
*word_index = index;
|
||||
return tok;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
*word_index = index;
|
||||
return QSE_NULL;
|
||||
}
|
||||
#endif
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef _QSE_LIB_STX_MISC_H_
|
||||
#define _QSE_LIB_STX_MISC_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
qse_word_t qse_stx_hashbytes (
|
||||
qse_stx_t* stx,
|
||||
const void* data,
|
||||
qse_word_t len
|
||||
);
|
||||
|
||||
qse_word_t qse_stx_hashstr (
|
||||
qse_stx_t* stx,
|
||||
const qse_char_t* str
|
||||
);
|
||||
|
||||
qse_word_t qse_stx_hashstrx (
|
||||
qse_stx_t* stx,
|
||||
const qse_char_t* str,
|
||||
qse_word_t len
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -40,13 +40,13 @@ qse_word_t qse_stx_allocwordobj (
|
||||
while (total_nflds > nflds)
|
||||
{
|
||||
total_nflds--;
|
||||
ptr->fld[total_nflds] = variable_data[total_nflds - nflds];
|
||||
ptr->slot[total_nflds] = variable_data[total_nflds - nflds];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (total_nflds > nflds)
|
||||
ptr->fld[--total_nflds] = stx->ref.nil;
|
||||
ptr->slot[--total_nflds] = stx->ref.nil;
|
||||
}
|
||||
|
||||
if (data)
|
||||
@ -54,13 +54,13 @@ qse_word_t qse_stx_allocwordobj (
|
||||
while (total_nflds > 0)
|
||||
{
|
||||
total_nflds--;
|
||||
ptr->fld[total_nflds] = data[total_nflds];
|
||||
ptr->slot[total_nflds] = data[total_nflds];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (total_nflds > 0)
|
||||
ptr->fld[--total_nflds] = stx->ref.nil;
|
||||
ptr->slot[--total_nflds] = stx->ref.nil;
|
||||
}
|
||||
|
||||
return ref;
|
||||
@ -92,7 +92,7 @@ qse_word_t qse_stx_allocbyteobj (
|
||||
while (variable_nflds > 0)
|
||||
{
|
||||
variable_nflds--;
|
||||
ptr->fld[variable_nflds] = variable_data[variable_nflds];
|
||||
ptr->slot[variable_nflds] = variable_data[variable_nflds];
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,11 +142,11 @@ qse_word_t qse_stx_alloccharobj (
|
||||
while (variable_nflds > 0)
|
||||
{
|
||||
variable_nflds--;
|
||||
ptr->fld[variable_nflds] = variable_data[variable_nflds];
|
||||
ptr->slot[variable_nflds] = variable_data[variable_nflds];
|
||||
}
|
||||
}
|
||||
|
||||
QSE_ASSERT (ptr->fld[ptr->h._size] == QSE_T('\0'));
|
||||
QSE_ASSERT (ptr->slot[ptr->h._size] == QSE_T('\0'));
|
||||
return ref;
|
||||
}
|
||||
|
||||
|
@ -15,58 +15,6 @@ qse_stx_t* qse_stx_init (qse_stx_t* stx, qse_mmgr_t* mmgr, qse_size_t memcapa)
|
||||
/* initialize object memory subsystem */
|
||||
if (qse_stx_initmem (stx, memcapa) <= -1) return QSE_NULL;
|
||||
|
||||
/* perform initial bootstrapping */
|
||||
/* TODO: if image file is available, load it.... */
|
||||
if (qse_stx_boot (stx) <= -1)
|
||||
{
|
||||
qse_stx_finimem (stx);
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (qse_stx_initsymtab (stx, 128) <= -1)
|
||||
{
|
||||
qse_stx_finimem (stx);
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
stx->symtab.size = 0;
|
||||
stx->symtab.capacity = 128; /* TODO: symbol table size */
|
||||
stx->symtab.datum = (qse_word_t*)qse_malloc (
|
||||
qse_sizeof(qse_word_t) * stx->symtab.capacity);
|
||||
if (stx->symtab.datum == QSE_NULL)
|
||||
{
|
||||
qse_stx_memory_close (&stx->memory);
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
stx->ref.nil = QSE_STX_NIL;
|
||||
stx->ref.true = QSE_STX_TRUE;
|
||||
stx->ref.false = QSE_STX_FALSE;
|
||||
|
||||
stx->smalltalk = QSE_STX_NIL;
|
||||
|
||||
stx->class_symbol = QSE_STX_NIL;
|
||||
stx->class_metaclass = QSE_STX_NIL;
|
||||
stx->class_association = QSE_STX_NIL;
|
||||
|
||||
stx->class_object = QSE_STX_NIL;
|
||||
stx->class_class = QSE_STX_NIL;
|
||||
stx->class_array = QSE_STX_NIL;
|
||||
stx->class_bytearray = QSE_STX_NIL;
|
||||
stx->class_string = QSE_STX_NIL;
|
||||
stx->class_character = QSE_STX_NIL;
|
||||
stx->class_context = QSE_STX_NIL;
|
||||
stx->class_system_dictionary = QSE_STX_NIL;
|
||||
stx->class_method = QSE_STX_NIL;
|
||||
stx->class_smallinteger = QSE_STX_NIL;
|
||||
|
||||
for (i = 0; i < stx->symtab.capacity; i++)
|
||||
{
|
||||
stx->symtab.datum[i] = stx->nil;
|
||||
}
|
||||
#endif
|
||||
|
||||
return stx;
|
||||
}
|
||||
|
||||
|
@ -71,19 +71,19 @@ struct qse_stx_object_t
|
||||
struct qse_stx_wordobj_t
|
||||
{
|
||||
qse_stx_objhdr_t h;
|
||||
qse_word_t fld[1];
|
||||
qse_word_t slot[1];
|
||||
};
|
||||
|
||||
struct qse_stx_byteobj_t
|
||||
{
|
||||
qse_stx_objhdr_t h;
|
||||
qse_byte_t fld[1];
|
||||
qse_byte_t slot[1];
|
||||
};
|
||||
|
||||
struct qse_stx_charobj_t
|
||||
{
|
||||
qse_stx_objhdr_t h;
|
||||
qse_char_t fld[1];
|
||||
qse_char_t slot[1];
|
||||
};
|
||||
|
||||
struct qse_stx_t
|
||||
@ -175,12 +175,21 @@ struct qse_stx_t
|
||||
#define QSE_STX_OBJSIZE(stx,ref) (QSE_STX_PTRBYREF(stx,ref)->h._size)
|
||||
#define QSE_STX_OBJCLASS(stx,ref) (QSE_STX_PTRBYREF(stx,ref)->h._class)
|
||||
|
||||
#define QSE_STX_WORDAT(stx,ref,pos) \
|
||||
(((qse_stx_wordobj_t*)QSE_STX_PTRBYREF(stx,ref))->fld[pos])
|
||||
#define QSE_STX_BYTEAT(stx,ref,pos) \
|
||||
(((qse_stx_byteobj_t*)QSE_STX_PTRBYREF(stx,ref))->fld[pos])
|
||||
#define QSE_STX_CHARAT(stx,ref,pos) \
|
||||
(((qse_stx_charobj_t*)QSE_STX_PTRBYREF(stx,ref))->fld[pos])
|
||||
/* pointer to the body of the object past the header */
|
||||
#define QSE_STX_WORDPTR(stx,ref) \
|
||||
(((qse_stx_wordobj_t*)QSE_STX_PTRBYREF(stx,ref))->slot)
|
||||
#define QSE_STX_BYTEPTR(stx,ref) \
|
||||
(((qse_stx_byteobj_t*)QSE_STX_PTRBYREF(stx,ref))->slot)
|
||||
#define QSE_STX_CHARPTR(stx,ref) \
|
||||
(((qse_stx_charobj_t*)QSE_STX_PTRBYREF(stx,ref))->slot)
|
||||
|
||||
#define QSE_STX_WORDLEN(stx,ref) OBJSIZE(stx,ref)
|
||||
#define QSE_STX_BYTELEN(stx,ref) OBJSIZE(stx,ref)
|
||||
#define QSE_STX_CHARLEN(stx,ref) OBJSIZE(stx,ref)
|
||||
|
||||
#define QSE_STX_WORDAT(stx,ref,pos) (QSE_STX_WORDPTR(stx,ref)[pos])
|
||||
#define QSE_STX_BYTEAT(stx,ref,pos) (QSE_STX_BYTEPTR(stx,ref)[pos])
|
||||
#define QSE_STX_CHARAT(stx,ref,pos) (QSE_STX_CHARPTR(stx,ref)[pos])
|
||||
|
||||
/* REDEFINITION DROPPING PREFIX FOR INTERNAL USE */
|
||||
#define REFISINT(stx,x) QSE_STX_REFISINT(stx,x)
|
||||
@ -198,6 +207,13 @@ struct qse_stx_t
|
||||
#define OBJCLASS(stx,ref) QSE_STX_OBJCLASS(stx,ref)
|
||||
#define OBJSIZE(stx,ref) QSE_STX_OBJSIZE(stx,ref)
|
||||
|
||||
|
||||
#define BYTEPTR(stx,ref) QSE_STX_BYTEPTR(stx,ref)
|
||||
#define CHARPTR(stx,ref) QSE_STX_CHARPTR(stx,ref)
|
||||
#define WORDPTR(stx,ref) QSE_STX_WORDPTR(stx,ref)
|
||||
#define BYTELEN(stx,ref) QSE_STX_BYTELEN(stx,ref)
|
||||
#define CHARLEN(stx,ref) QSE_STX_CHARLEN(stx,ref)
|
||||
#define WORDLEN(stx,ref) QSE_STX_WORDLEN(stx,ref)
|
||||
#define BYTEAT(stx,ref,pos) QSE_STX_BYTEAT(stx,ref,pos)
|
||||
#define CHARAT(stx,ref,pos) QSE_STX_CHARAT(stx,ref,pos)
|
||||
#define WORDAT(stx,ref,pos) QSE_STX_WORDAT(stx,ref,pos)
|
||||
@ -211,7 +227,6 @@ struct qse_stx_t
|
||||
#define SYSDIC_INIT_CAPA 256
|
||||
|
||||
#define ISNIL(stx,obj) ((obj) == (stx)->ref.nil)
|
||||
#define NIL(stx) ((stx)->ref.nil)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -7,8 +7,8 @@
|
||||
|
||||
/* The SystemSymbolTable is a variable word class.
|
||||
* The info below is for the fixed part only */
|
||||
#define QSE_STX_SYMTAB_SIZE 1
|
||||
#define QSE_STX_SYMTAB_TALLY 0
|
||||
#define QSE_STX_SYSTEMSYMBOLTABLE_SIZE 1
|
||||
#define QSE_STX_SYSTEMSYMBOLTABLE_TALLY 0
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
Loading…
Reference in New Issue
Block a user