added test code for bootstrapping
This commit is contained in:
@ -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" {
|
||||
|
Reference in New Issue
Block a user