started working on parser
This commit is contained in:
parent
121f0145fa
commit
2008bdeef1
@ -8,6 +8,6 @@ AM_CPPFLAGS = \
|
||||
|
||||
lib_LTLIBRARIES = libqsestx.la
|
||||
|
||||
libqsestx_la_SOURCES = stx.c err.c hash.c mem.c obj.c sym.c dic.c cls.c boot.c
|
||||
libqsestx_la_SOURCES = stx.c err.c hash.c mem.c obj.c sym.c dic.c cls.c boot.c par.c
|
||||
libqsestx_la_LDFLAGS = -L../cmn -L$(libdir) -version-info 1:0:0 -no-undefined
|
||||
libqsestx_la_LIBADD = -lqsecmn
|
||||
|
@ -72,7 +72,7 @@ am__installdirs = "$(DESTDIR)$(libdir)"
|
||||
LTLIBRARIES = $(lib_LTLIBRARIES)
|
||||
libqsestx_la_DEPENDENCIES =
|
||||
am_libqsestx_la_OBJECTS = stx.lo err.lo hash.lo mem.lo obj.lo sym.lo \
|
||||
dic.lo cls.lo boot.lo
|
||||
dic.lo cls.lo boot.lo par.lo
|
||||
libqsestx_la_OBJECTS = $(am_libqsestx_la_OBJECTS)
|
||||
libqsestx_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
@ -239,7 +239,7 @@ AM_CPPFLAGS = \
|
||||
-I$(includedir)
|
||||
|
||||
lib_LTLIBRARIES = libqsestx.la
|
||||
libqsestx_la_SOURCES = stx.c err.c hash.c mem.c obj.c sym.c dic.c cls.c boot.c
|
||||
libqsestx_la_SOURCES = stx.c err.c hash.c mem.c obj.c sym.c dic.c cls.c boot.c par.c
|
||||
libqsestx_la_LDFLAGS = -L../cmn -L$(libdir) -version-info 1:0:0 -no-undefined
|
||||
libqsestx_la_LIBADD = -lqsecmn
|
||||
all: all-am
|
||||
@ -323,6 +323,7 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hash.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mem.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/obj.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/par.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stx.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sym.Plo@am__quote@
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: symbol.h 118 2008-03-03 11:21:33Z baconevi $
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef _QSE_LIB_STX_BOOT_H_
|
||||
@ -13,8 +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
|
||||
|
@ -1,680 +0,0 @@
|
||||
/*
|
||||
* $Id: bootstrp.c 118 2008-03-03 11:21:33Z baconevi $
|
||||
*/
|
||||
|
||||
#include <qse/stx/bootstrp.h>
|
||||
#include <qse/stx/symbol.h>
|
||||
#include <qse/stx/class.h>
|
||||
#include <qse/stx/object.h>
|
||||
#include <qse/stx/dict.h>
|
||||
#include <qse/stx/misc.h>
|
||||
|
||||
static void __create_bootstrapping_objects (qse_stx_t* stx);
|
||||
static void __create_builtin_classes (qse_stx_t* stx);
|
||||
static qse_word_t __make_classvar_dict (
|
||||
qse_stx_t* stx, qse_word_t class, const qse_char_t* names);
|
||||
static void __filein_kernel (qse_stx_t* stx);
|
||||
|
||||
static qse_word_t __count_names (const qse_char_t* str);
|
||||
static void __set_names (
|
||||
qse_stx_t* stx, qse_word_t* array, const qse_char_t* str);
|
||||
|
||||
static qse_word_t __count_subclasses (const qse_char_t* str);
|
||||
static void __set_subclasses (
|
||||
qse_stx_t* stx, qse_word_t* array, const qse_char_t* str);
|
||||
static void __set_metaclass_subclasses (
|
||||
qse_stx_t* stx, qse_word_t* array, const qse_char_t* str);
|
||||
|
||||
struct class_info_t
|
||||
{
|
||||
const qse_char_t* name;
|
||||
const qse_char_t* superclass;
|
||||
const qse_char_t* instance_variables;
|
||||
const qse_char_t* class_variables;
|
||||
const qse_char_t* pool_dictionaries;
|
||||
const int indexable;
|
||||
};
|
||||
|
||||
typedef struct class_info_t class_info_t;
|
||||
|
||||
static class_info_t class_info[] =
|
||||
{
|
||||
{
|
||||
QSE_T("Object"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("UndefinedObject"),
|
||||
QSE_T("Object"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("Behavior"),
|
||||
QSE_T("Object"),
|
||||
QSE_T("spec methods superclass"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("Class"),
|
||||
QSE_T("Behavior"),
|
||||
QSE_T("name variables classVariables poolDictionaries"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("Metaclass"),
|
||||
QSE_T("Behavior"),
|
||||
QSE_T("instanceClass"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("Block"),
|
||||
QSE_T("Object"),
|
||||
QSE_T("context argCount argLoc bytePointer"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("Boolean"),
|
||||
QSE_T("Object"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("True"),
|
||||
QSE_T("Boolean"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("False"),
|
||||
QSE_T("Boolean"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("Context"),
|
||||
QSE_T("Object"),
|
||||
QSE_T("stack stackTop receiver pc method"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("Method"),
|
||||
QSE_T("Object"),
|
||||
QSE_T("text selector bytecodes tmpCount argCount"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_WORD_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("Magnitude"),
|
||||
QSE_T("Object"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("Association"),
|
||||
QSE_T("Magnitude"),
|
||||
QSE_T("key value"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("Character"),
|
||||
QSE_T("Magnitude"),
|
||||
QSE_T("value"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("Number"),
|
||||
QSE_T("Magnitude"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("Integer"),
|
||||
QSE_T("Number"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("SmallInteger"),
|
||||
QSE_T("Integer"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("LargeInteger"),
|
||||
QSE_T("Integer"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_BYTE_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("Collection"),
|
||||
QSE_T("Magnitude"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("IndexedCollection"),
|
||||
QSE_T("Collection"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("Array"),
|
||||
QSE_T("IndexedCollection"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_WORD_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("ByteArray"),
|
||||
QSE_T("IndexedCollection"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_BYTE_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("Dictionary"),
|
||||
QSE_T("IndexedCollection"),
|
||||
QSE_T("tally"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_WORD_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("SystemDictionary"),
|
||||
QSE_T("Dictionary"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_WORD_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("PoolDictionary"),
|
||||
QSE_T("Dictionary"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_WORD_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("String"),
|
||||
QSE_T("IndexedCollection"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_CHAR_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("Symbol"),
|
||||
QSE_T("String"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_CHAR_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_T("Link"),
|
||||
QSE_T("Object"),
|
||||
QSE_T("link"),
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
},
|
||||
{
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_NULL,
|
||||
QSE_STX_SPEC_NOT_INDEXABLE
|
||||
}
|
||||
};
|
||||
|
||||
qse_word_t INLINE __new_string (qse_stx_t* stx, const qse_char_t* str)
|
||||
{
|
||||
qse_word_t x;
|
||||
|
||||
qse_assert (stx->class_string != stx->nil);
|
||||
x = qse_stx_alloc_char_object (stx, str);
|
||||
QSE_STX_CLASS(stx,x) = stx->class_string;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
int qse_stx_bootstrap (qse_stx_t* stx)
|
||||
{
|
||||
qse_word_t symbol_Smalltalk;
|
||||
qse_word_t object_meta;
|
||||
|
||||
__create_bootstrapping_objects (stx);
|
||||
|
||||
/* object, class, and array are precreated for easier instantiation
|
||||
* of builtin classes */
|
||||
stx->class_object = qse_stx_new_class (stx, QSE_T("Object"));
|
||||
stx->class_class = qse_stx_new_class (stx, QSE_T("Class"));
|
||||
stx->class_array = qse_stx_new_class (stx, QSE_T("Array"));
|
||||
stx->class_bytearray = qse_stx_new_class (stx, QSE_T("ByteArray"));
|
||||
stx->class_string = qse_stx_new_class (stx, QSE_T("String"));
|
||||
stx->class_character = qse_stx_new_class (stx, QSE_T("Character"));
|
||||
stx->class_context = qse_stx_new_class (stx, QSE_T("Context"));
|
||||
stx->class_system_dictionary =
|
||||
qse_stx_new_class (stx, QSE_T("SystemDictionary"));
|
||||
stx->class_method =
|
||||
qse_stx_new_class (stx, QSE_T("Method"));
|
||||
stx->class_smallinteger =
|
||||
qse_stx_new_class (stx, QSE_T("SmallInteger"));
|
||||
|
||||
__create_builtin_classes (stx);
|
||||
|
||||
/* (Object class) setSuperclass: Class */
|
||||
object_meta = QSE_STX_CLASS(stx,stx->class_object);
|
||||
QSE_STX_WORD_AT(stx,object_meta,QSE_STX_METACLASS_SUPERCLASS) = stx->class_class;
|
||||
/* instance class for Object is set here as it is not
|
||||
* set in __create_builtin_classes */
|
||||
QSE_STX_WORD_AT(stx,object_meta,QSE_STX_METACLASS_INSTANCE_CLASS) = stx->class_object;
|
||||
|
||||
/* for some fun here */
|
||||
{
|
||||
qse_word_t array;
|
||||
array = qse_stx_new_array (stx, 1);
|
||||
QSE_STX_WORD_AT(stx,array,0) = object_meta;
|
||||
QSE_STX_WORD_AT(stx,stx->class_class,QSE_STX_CLASS_SUBCLASSES) = array;
|
||||
}
|
||||
|
||||
/* more initialization */
|
||||
QSE_STX_CLASS(stx,stx->smalltalk) = stx->class_system_dictionary;
|
||||
|
||||
symbol_Smalltalk = qse_stx_new_symbol (stx, QSE_T("Smalltalk"));
|
||||
qse_stx_dict_put (stx, stx->smalltalk, symbol_Smalltalk, stx->smalltalk);
|
||||
|
||||
/* create #nil, #true, #false */
|
||||
qse_stx_new_symbol (stx, QSE_T("nil"));
|
||||
qse_stx_new_symbol (stx, QSE_T("true"));
|
||||
qse_stx_new_symbol (stx, QSE_T("false"));
|
||||
|
||||
/* nil setClass: UndefinedObject */
|
||||
QSE_STX_CLASS(stx,stx->nil) =
|
||||
qse_stx_lookup_class(stx, QSE_T("UndefinedObject"));
|
||||
/* true setClass: True */
|
||||
QSE_STX_CLASS(stx,stx->true) =
|
||||
qse_stx_lookup_class (stx, QSE_T("True"));
|
||||
/* fales setClass: False */
|
||||
QSE_STX_CLASS(stx,stx->false) =
|
||||
qse_stx_lookup_class (stx, QSE_T("False"));
|
||||
|
||||
__filein_kernel (stx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __create_bootstrapping_objects (qse_stx_t* stx)
|
||||
{
|
||||
qse_word_t class_SymbolMeta;
|
||||
qse_word_t class_MetaclassMeta;
|
||||
qse_word_t class_AssociationMeta;
|
||||
qse_word_t symbol_Symbol;
|
||||
qse_word_t symbol_Metaclass;
|
||||
qse_word_t symbol_Association;
|
||||
|
||||
/* allocate three keyword objects */
|
||||
stx->ref.nil = qse_stx_alloc_word_object (stx, QSE_NULL, 0, QSE_NULL, 0);
|
||||
stx->ref.true = qse_stx_alloc_word_object (stx, QSE_NULL, 0, QSE_NULL, 0);
|
||||
stx->ref.false = qse_stx_alloc_word_object (stx, QSE_NULL, 0, QSE_NULL, 0);
|
||||
|
||||
QSE_ASSERT (stx->ref.nil == QSE_STX_NIL);
|
||||
QSE_ASSERT (stx->ref.true == QSE_STX_TRUE);
|
||||
QSE_ASSERT (stx->ref.false == QSE_STX_FALSE);
|
||||
|
||||
stx->symtab = qse_stx_alloc_word_object (
|
||||
stx, QSE_NULL, 1, QSE_NULL, 256);
|
||||
QSE_STX_WORDAT(stx,stx->symtab,QSE_STX_SYMSET_TALLY) = QSE_STX_INTTOREF(0);
|
||||
|
||||
/* system dictionary */
|
||||
/* TODO: dictionary size */
|
||||
stx->smalltalk = qse_stx_alloc_word_object (
|
||||
stx, QSE_NULL, 1, QSE_NULL, 256);
|
||||
/* set tally */
|
||||
QSE_STX_WORD_AT(stx,stx->smalltalk,0) = QSE_STX_TO_SMALLINT(0);
|
||||
|
||||
/* Symbol */
|
||||
stx->class_symbol = qse_stx_alloc_word_object(
|
||||
stx, QSE_NULL, QSE_STX_CLASS_SIZE, QSE_NULL, 0);
|
||||
/* Metaclass */
|
||||
stx->class_metaclass = qse_stx_alloc_word_object(
|
||||
stx, QSE_NULL, QSE_STX_CLASS_SIZE, QSE_NULL, 0);
|
||||
/* Association */
|
||||
stx->class_association = qse_stx_alloc_word_object(
|
||||
stx, QSE_NULL, QSE_STX_CLASS_SIZE, QSE_NULL, 0);
|
||||
|
||||
/* Metaclass is a class so it has the same structure
|
||||
* as a normal class. "Metaclass class" is an instance of
|
||||
* Metaclass. */
|
||||
|
||||
/* Symbol class */
|
||||
class_SymbolMeta = qse_stx_alloc_word_object(
|
||||
stx, QSE_NULL, QSE_STX_METACLASS_SIZE, QSE_NULL, 0);
|
||||
/* Metaclass class */
|
||||
class_MetaclassMeta = qse_stx_alloc_word_object(
|
||||
stx, QSE_NULL, QSE_STX_METACLASS_SIZE, QSE_NULL, 0);
|
||||
/* Association class */
|
||||
class_AssociationMeta = qse_stx_alloc_word_object(
|
||||
stx, QSE_NULL, QSE_STX_METACLASS_SIZE, QSE_NULL, 0);
|
||||
|
||||
/* (Symbol class) setClass: Metaclass */
|
||||
QSE_STX_CLASS(stx,class_SymbolMeta) = stx->class_metaclass;
|
||||
/* (Metaclass class) setClass: Metaclass */
|
||||
QSE_STX_CLASS(stx,class_MetaclassMeta) = stx->class_metaclass;
|
||||
/* (Association class) setClass: Metaclass */
|
||||
QSE_STX_CLASS(stx,class_AssociationMeta) = stx->class_metaclass;
|
||||
|
||||
/* Symbol setClass: (Symbol class) */
|
||||
QSE_STX_CLASS(stx,stx->class_symbol) = class_SymbolMeta;
|
||||
/* Metaclass setClass: (Metaclass class) */
|
||||
QSE_STX_CLASS(stx,stx->class_metaclass) = class_MetaclassMeta;
|
||||
/* Association setClass: (Association class) */
|
||||
QSE_STX_CLASS(stx,stx->class_association) = class_AssociationMeta;
|
||||
|
||||
/* (Symbol class) setSpec: CLASS_SIZE */
|
||||
QSE_STX_WORD_AT(stx,class_SymbolMeta,QSE_STX_CLASS_SPEC) =
|
||||
QSE_STX_TO_SMALLINT((QSE_STX_CLASS_SIZE << QSE_STX_SPEC_INDEXABLE_BITS) | QSE_STX_SPEC_NOT_INDEXABLE);
|
||||
/* (Metaclass class) setSpec: CLASS_SIZE */
|
||||
QSE_STX_WORD_AT(stx,class_MetaclassMeta,QSE_STX_CLASS_SPEC) =
|
||||
QSE_STX_TO_SMALLINT((QSE_STX_CLASS_SIZE << QSE_STX_SPEC_INDEXABLE_BITS) | QSE_STX_SPEC_NOT_INDEXABLE);
|
||||
/* (Association class) setSpec: CLASS_SIZE */
|
||||
QSE_STX_WORD_AT(stx,class_AssociationMeta,QSE_STX_CLASS_SPEC) =
|
||||
QSE_STX_TO_SMALLINT((QSE_STX_CLASS_SIZE << QSE_STX_SPEC_INDEXABLE_BITS) | QSE_STX_SPEC_NOT_INDEXABLE);
|
||||
|
||||
/* specs for class_metaclass, class_association,
|
||||
* class_symbol are set later in __create_builtin_classes */
|
||||
|
||||
/* #Symbol */
|
||||
symbol_Symbol = qse_stx_new_symbol (stx, QSE_T("Symbol"));
|
||||
/* #Metaclass */
|
||||
symbol_Metaclass = qse_stx_new_symbol (stx, QSE_T("Metaclass"));
|
||||
/* #Association */
|
||||
symbol_Association = qse_stx_new_symbol (stx, QSE_T("Association"));
|
||||
|
||||
/* Symbol setName: #Symbol */
|
||||
QSE_STX_WORD_AT(stx,stx->class_symbol,QSE_STX_CLASS_NAME) = symbol_Symbol;
|
||||
/* Metaclass setName: #Metaclass */
|
||||
QSE_STX_WORD_AT(stx,stx->class_metaclass,QSE_STX_CLASS_NAME) = symbol_Metaclass;
|
||||
/* Association setName: #Association */
|
||||
QSE_STX_WORD_AT(stx,stx->class_association,QSE_STX_CLASS_NAME) = symbol_Association;
|
||||
|
||||
/* register class names into the system dictionary */
|
||||
qse_stx_dict_put (stx,
|
||||
stx->smalltalk, symbol_Symbol, stx->class_symbol);
|
||||
qse_stx_dict_put (stx,
|
||||
stx->smalltalk, symbol_Metaclass, stx->class_metaclass);
|
||||
qse_stx_dict_put (stx,
|
||||
stx->smalltalk, symbol_Association, stx->class_association);
|
||||
}
|
||||
|
||||
static void __create_builtin_classes (qse_stx_t* stx)
|
||||
{
|
||||
class_info_t* p;
|
||||
qse_word_t class, superclass, array;
|
||||
qse_stx_class_t* class_obj, * superclass_obj;
|
||||
qse_word_t metaclass;
|
||||
qse_stx_metaclass_t* metaclass_obj;
|
||||
qse_word_t n, nfields;
|
||||
|
||||
qse_assert (stx->class_array != stx->nil);
|
||||
|
||||
for (p = class_info; p->name != QSE_NULL; p++) {
|
||||
class = qse_stx_lookup_class(stx, p->name);
|
||||
if (class == stx->nil) {
|
||||
class = qse_stx_new_class (stx, p->name);
|
||||
}
|
||||
|
||||
qse_assert (class != stx->nil);
|
||||
class_obj = (qse_stx_class_t*)QSE_STX_OBJPTR(stx, class);
|
||||
class_obj->superclass = (p->superclass == QSE_NULL)?
|
||||
stx->nil: qse_stx_lookup_class(stx,p->superclass);
|
||||
|
||||
nfields = 0;
|
||||
if (p->superclass != QSE_NULL) {
|
||||
qse_word_t meta;
|
||||
qse_stx_metaclass_t* meta_obj;
|
||||
|
||||
superclass = qse_stx_lookup_class(stx,p->superclass);
|
||||
qse_assert (superclass != stx->nil);
|
||||
|
||||
meta = class_obj->header.class;
|
||||
meta_obj = (qse_stx_metaclass_t*)QSE_STX_OBJPTR(stx,meta);
|
||||
meta_obj->superclass = QSE_STX_CLASS(stx,superclass);
|
||||
meta_obj->instance_class = class;
|
||||
|
||||
while (superclass != stx->nil) {
|
||||
superclass_obj = (qse_stx_class_t*)
|
||||
QSE_STX_OBJPTR(stx,superclass);
|
||||
nfields +=
|
||||
QSE_STX_FROMSMALLINT(superclass_obj->spec) >>
|
||||
QSE_STX_SPEC_INDEXABLE_BITS;
|
||||
superclass = superclass_obj->superclass;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (p->instance_variables != QSE_NULL) {
|
||||
nfields += __count_names (p->instance_variables);
|
||||
class_obj->variables =
|
||||
__new_string (stx, p->instance_variables);
|
||||
}
|
||||
|
||||
qse_assert (nfields <= 0 || (nfields > 0 &&
|
||||
(p->indexable == QSE_STX_SPEC_NOT_INDEXABLE ||
|
||||
p->indexable == QSE_STX_SPEC_WORD_INDEXABLE)));
|
||||
|
||||
class_obj->spec = QSE_STX_TO_SMALLINT(
|
||||
(nfields << QSE_STX_SPEC_INDEXABLE_BITS) | p->indexable);
|
||||
}
|
||||
|
||||
for (p = class_info; p->name != QSE_NULL; p++) {
|
||||
class = qse_stx_lookup_class(stx, p->name);
|
||||
qse_assert (class != stx->nil);
|
||||
|
||||
class_obj = (qse_stx_class_t*)QSE_STX_OBJPTR(stx, class);
|
||||
|
||||
if (p->class_variables != QSE_NULL) {
|
||||
class_obj->class_variables =
|
||||
__make_classvar_dict(stx, class, p->class_variables);
|
||||
}
|
||||
|
||||
/*
|
||||
TODO:
|
||||
if (p->pool_dictionaries != QSE_NULL) {
|
||||
class_obj->pool_dictionaries =
|
||||
__make_pool_dictionary(stx, class, p->pool_dictionaries);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/* fill subclasses */
|
||||
for (p = class_info; p->name != QSE_NULL; p++) {
|
||||
n = __count_subclasses (p->name);
|
||||
array = qse_stx_new_array (stx, n);
|
||||
__set_subclasses (stx, QSE_STX_DATA(stx,array), p->name);
|
||||
|
||||
class = qse_stx_lookup_class(stx, p->name);
|
||||
qse_assert (class != stx->nil);
|
||||
class_obj = (qse_stx_class_t*)QSE_STX_OBJPTR(stx, class);
|
||||
class_obj->subclasses = array;
|
||||
}
|
||||
|
||||
/* fill subclasses for metaclasses */
|
||||
for (p = class_info; p->name != QSE_NULL; p++) {
|
||||
n = __count_subclasses (p->name);
|
||||
array = qse_stx_new_array (stx, n);
|
||||
__set_metaclass_subclasses (stx, QSE_STX_DATA(stx,array), p->name);
|
||||
|
||||
class = qse_stx_lookup_class(stx, p->name);
|
||||
qse_assert (class != stx->nil);
|
||||
metaclass = QSE_STX_CLASS(stx,class);
|
||||
metaclass_obj = (qse_stx_metaclass_t*)QSE_STX_OBJPTR(stx, metaclass);
|
||||
metaclass_obj->subclasses = array;
|
||||
}
|
||||
}
|
||||
|
||||
static qse_word_t __count_names (const qse_char_t* str)
|
||||
{
|
||||
qse_word_t n = 0;
|
||||
const qse_char_t* p = str;
|
||||
|
||||
do {
|
||||
while (*p == QSE_T(' ') ||
|
||||
*p == QSE_T('\t')) p++;
|
||||
if (*p == QSE_T('\0')) break;
|
||||
|
||||
n++;
|
||||
while (*p != QSE_T(' ') &&
|
||||
*p != QSE_T('\t') &&
|
||||
*p != QSE_T('\0')) p++;
|
||||
} while (1);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static void __set_names (
|
||||
qse_stx_t* stx, qse_word_t* array, const qse_char_t* str)
|
||||
{
|
||||
qse_word_t n = 0;
|
||||
const qse_char_t* p = str;
|
||||
const qse_char_t* name;
|
||||
|
||||
do {
|
||||
while (*p == QSE_T(' ') ||
|
||||
*p == QSE_T('\t')) p++;
|
||||
if (*p == QSE_T('\0')) break;
|
||||
|
||||
name = p;
|
||||
while (*p != QSE_T(' ') &&
|
||||
*p != QSE_T('\t') &&
|
||||
*p != QSE_T('\0')) p++;
|
||||
|
||||
array[n++] = qse_stx_new_symbolx (stx, name, p - name);
|
||||
} while (1);
|
||||
}
|
||||
|
||||
static qse_word_t __count_subclasses (const qse_char_t* str)
|
||||
{
|
||||
class_info_t* p;
|
||||
qse_word_t n = 0;
|
||||
|
||||
for (p = class_info; p->name != QSE_NULL; p++) {
|
||||
if (p->superclass == QSE_NULL) continue;
|
||||
if (qse_strcmp (str, p->superclass) == 0) n++;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static void __set_subclasses (
|
||||
qse_stx_t* stx, qse_word_t* array, const qse_char_t* str)
|
||||
{
|
||||
class_info_t* p;
|
||||
qse_word_t n = 0, class;
|
||||
|
||||
for (p = class_info; p->name != QSE_NULL; p++) {
|
||||
if (p->superclass == QSE_NULL) continue;
|
||||
if (qse_strcmp (str, p->superclass) != 0) continue;
|
||||
class = qse_stx_lookup_class (stx, p->name);
|
||||
qse_assert (class != stx->nil);
|
||||
array[n++] = class;
|
||||
}
|
||||
}
|
||||
|
||||
static void __set_metaclass_subclasses (
|
||||
qse_stx_t* stx, qse_word_t* array, const qse_char_t* str)
|
||||
{
|
||||
class_info_t* p;
|
||||
qse_word_t n = 0, class;
|
||||
|
||||
for (p = class_info; p->name != QSE_NULL; p++) {
|
||||
if (p->superclass == QSE_NULL) continue;
|
||||
if (qse_strcmp (str, p->superclass) != 0) continue;
|
||||
class = qse_stx_lookup_class (stx, p->name);
|
||||
qse_assert (class != stx->nil);
|
||||
array[n++] = QSE_STX_CLASS(stx,class);
|
||||
}
|
||||
}
|
||||
|
||||
static qse_word_t __make_classvar_dict (
|
||||
qse_stx_t* stx, qse_word_t class, const qse_char_t* names)
|
||||
{
|
||||
qse_word_t dict, symbol;
|
||||
const qse_char_t* p = names;
|
||||
const qse_char_t* name;
|
||||
|
||||
dict = qse_stx_instantiate (
|
||||
stx, stx->class_system_dictionary,
|
||||
QSE_NULL, QSE_NULL, __count_names(names));
|
||||
|
||||
do {
|
||||
while (*p == QSE_T(' ') ||
|
||||
*p == QSE_T('\t')) p++;
|
||||
if (*p == QSE_T('\0')) break;
|
||||
|
||||
name = p;
|
||||
while (*p != QSE_T(' ') &&
|
||||
*p != QSE_T('\t') &&
|
||||
*p != QSE_T('\0')) p++;
|
||||
|
||||
symbol = qse_stx_new_symbolx (stx, name, p - name);
|
||||
qse_stx_dict_put (stx, dict, symbol, stx->nil);
|
||||
} while (1);
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
static void __filein_kernel (qse_stx_t* stx)
|
||||
{
|
||||
class_info_t* p;
|
||||
|
||||
for (p = class_info; p->name != QSE_NULL; p++) {
|
||||
/* TODO: */
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
/*
|
||||
* $Id: bootstrp.h 118 2008-03-03 11:21:33Z baconevi $
|
||||
*/
|
||||
|
||||
#ifndef _QSE_STX_BOOTSTRP_H_
|
||||
#define _QSE_STX_BOOTSTRP_H_
|
||||
|
||||
#include <qse/stx/stx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
qse_word_t qse_stx_new_array (qse_stx_t* stx, qse_word_t size);
|
||||
int qse_stx_bootstrap (qse_stx_t* stx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,146 +0,0 @@
|
||||
/*
|
||||
* $Id: name.c 118 2008-03-03 11:21:33Z baconevi $
|
||||
*/
|
||||
|
||||
#include <qse/stx/name.h>
|
||||
#include <qse/stx/misc.h>
|
||||
|
||||
qse_stx_name_t* qse_stx_name_open (
|
||||
qse_stx_name_t* name, qse_word_t capacity)
|
||||
{
|
||||
if (capacity == 0)
|
||||
capacity = qse_countof(name->static_buffer) - 1;
|
||||
|
||||
if (name == QSE_NULL) {
|
||||
name = (qse_stx_name_t*)
|
||||
qse_malloc (qse_sizeof(qse_stx_name_t));
|
||||
if (name == QSE_NULL) return QSE_NULL;
|
||||
name->__dynamic = qse_true;
|
||||
}
|
||||
else name->__dynamic = qse_false;
|
||||
|
||||
if (capacity < qse_countof(name->static_buffer)) {
|
||||
name->buffer = name->static_buffer;
|
||||
}
|
||||
else {
|
||||
name->buffer = (qse_char_t*)
|
||||
qse_malloc ((capacity + 1) * qse_sizeof(qse_char_t));
|
||||
if (name->buffer == QSE_NULL) {
|
||||
if (name->__dynamic) qse_free (name);
|
||||
return QSE_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
name->size = 0;
|
||||
name->capacity = capacity;
|
||||
name->buffer[0] = QSE_T('\0');
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
void qse_stx_name_close (qse_stx_name_t* name)
|
||||
{
|
||||
if (name->capacity >= qse_countof(name->static_buffer)) {
|
||||
qse_assert (name->buffer != name->static_buffer);
|
||||
qse_free (name->buffer);
|
||||
}
|
||||
if (name->__dynamic) qse_free (name);
|
||||
}
|
||||
|
||||
int qse_stx_name_addc (qse_stx_name_t* name, qse_cint_t c)
|
||||
{
|
||||
if (name->size >= name->capacity) {
|
||||
/* double the capacity. */
|
||||
qse_size_t new_capacity = name->capacity * 2;
|
||||
|
||||
if (new_capacity >= qse_countof(name->static_buffer)) {
|
||||
qse_char_t* space;
|
||||
|
||||
if (name->capacity < qse_countof(name->static_buffer)) {
|
||||
space = (qse_char_t*)qse_malloc (
|
||||
(new_capacity + 1) * qse_sizeof(qse_char_t));
|
||||
if (space == QSE_NULL) return -1;
|
||||
|
||||
/* don't need to copy up to the terminating null */
|
||||
qse_memcpy (space, name->buffer,
|
||||
name->capacity * qse_sizeof(qse_char_t));
|
||||
}
|
||||
else {
|
||||
space = (qse_char_t*)qse_realloc (name->buffer,
|
||||
(new_capacity + 1) * qse_sizeof(qse_char_t));
|
||||
if (space == QSE_NULL) return -1;
|
||||
}
|
||||
|
||||
name->buffer = space;
|
||||
}
|
||||
|
||||
name->capacity = new_capacity;
|
||||
}
|
||||
|
||||
name->buffer[name->size++] = c;
|
||||
name->buffer[name->size] = QSE_T('\0');
|
||||
return 0;
|
||||
}
|
||||
|
||||
int qse_stx_name_adds (qse_stx_name_t* name, const qse_char_t* s)
|
||||
{
|
||||
while (*s != QSE_T('\0')) {
|
||||
if (qse_stx_name_addc(name, *s) == -1) return -1;
|
||||
s++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void qse_stx_name_clear (qse_stx_name_t* name)
|
||||
{
|
||||
name->size = 0;
|
||||
name->buffer[0] = QSE_T('\0');
|
||||
}
|
||||
|
||||
qse_char_t* qse_stx_name_yield (qse_stx_name_t* name, qse_word_t capacity)
|
||||
{
|
||||
qse_char_t* old_buffer, * new_buffer;
|
||||
|
||||
if (capacity == 0)
|
||||
capacity = qse_countof(name->static_buffer) - 1;
|
||||
|
||||
if (name->capacity < qse_countof(name->static_buffer)) {
|
||||
old_buffer = (qse_char_t*)
|
||||
qse_malloc((name->capacity + 1) * qse_sizeof(qse_char_t));
|
||||
if (old_buffer == QSE_NULL) return QSE_NULL;
|
||||
qse_memcpy (old_buffer, name->buffer,
|
||||
(name->capacity + 1) * qse_sizeof(qse_char_t));
|
||||
}
|
||||
else old_buffer = name->buffer;
|
||||
|
||||
if (capacity < qse_countof(name->static_buffer)) {
|
||||
new_buffer = name->static_buffer;
|
||||
}
|
||||
else {
|
||||
new_buffer = (qse_char_t*)
|
||||
qse_malloc((capacity + 1) * qse_sizeof(qse_char_t));
|
||||
if (new_buffer == QSE_NULL) return QSE_NULL;
|
||||
}
|
||||
|
||||
name->buffer = new_buffer;
|
||||
name->size = 0;
|
||||
name->capacity = capacity;
|
||||
name->buffer[0] = QSE_T('\0');
|
||||
|
||||
return old_buffer;
|
||||
}
|
||||
|
||||
int qse_stx_name_compare (qse_stx_name_t* name, const qse_char_t* str)
|
||||
{
|
||||
qse_char_t* p = name->buffer;
|
||||
qse_word_t index = 0;
|
||||
|
||||
while (index < name->size) {
|
||||
if (*p > *str) return 1;
|
||||
if (*p < *str) return -1;
|
||||
index++; p++; str++;
|
||||
}
|
||||
|
||||
return (*str == QSE_T('\0'))? 0: -1;
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* $Id: name.h 118 2008-03-03 11:21:33Z baconevi $
|
||||
*/
|
||||
|
||||
#ifndef _QSE_STX_NAME_H_
|
||||
#define _QSE_STX_NAME_H_
|
||||
|
||||
#include <qse/stx/stx.h>
|
||||
|
||||
struct qse_stx_name_t
|
||||
{
|
||||
qse_word_t capacity;
|
||||
qse_word_t size;
|
||||
qse_char_t* buffer;
|
||||
qse_char_t static_buffer[128];
|
||||
qse_bool_t __dynamic;
|
||||
};
|
||||
|
||||
typedef struct qse_stx_name_t qse_stx_name_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
qse_stx_name_t* qse_stx_name_open (
|
||||
qse_stx_name_t* name, qse_word_t capacity);
|
||||
void qse_stx_name_close (qse_stx_name_t* name);
|
||||
|
||||
int qse_stx_name_addc (qse_stx_name_t* name, qse_cint_t c);
|
||||
int qse_stx_name_adds (qse_stx_name_t* name, const qse_char_t* s);
|
||||
void qse_stx_name_clear (qse_stx_name_t* name);
|
||||
qse_char_t* qse_stx_name_yield (qse_stx_name_t* name, qse_word_t capacity);
|
||||
int qse_stx_name_compare (qse_stx_name_t* name, const qse_char_t* str);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
1616
qse/lib/stx/par.c
Normal file
1616
qse/lib/stx/par.c
Normal file
File diff suppressed because it is too large
Load Diff
107
qse/lib/stx/par.h
Normal file
107
qse/lib/stx/par.h
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* $Id: parser.h 118 2008-03-03 11:21:33Z baconevi $
|
||||
*/
|
||||
|
||||
#ifndef _QSE_STX_PARSER_H_
|
||||
#define _QSE_STX_PARSER_H_
|
||||
|
||||
#include <qse/stx/stx.h>
|
||||
#include <qse/stx/name.h>
|
||||
#include <qse/stx/token.h>
|
||||
#include <qse/bas/arr.h>
|
||||
|
||||
enum
|
||||
{
|
||||
QSE_STX_PARSER_ERROR_NONE,
|
||||
|
||||
/* system errors */
|
||||
QSE_STX_PARSER_ERROR_INPUT_FUNC,
|
||||
QSE_STX_PARSER_ERROR_INPUT,
|
||||
QSE_STX_PARSER_ERROR_MEMORY,
|
||||
|
||||
/* lexical errors */
|
||||
QSE_STX_PARSER_ERROR_CHAR,
|
||||
QSE_STX_PARSER_ERROR_CHARLIT,
|
||||
QSE_STX_PARSER_ERROR_STRLIT,
|
||||
QSE_STX_PARSER_ERROR_LITERAL,
|
||||
|
||||
/* syntatic error */
|
||||
QSE_STX_PARSER_ERROR_MESSAGE_SELECTOR,
|
||||
QSE_STX_PARSER_ERROR_ARGUMENT_NAME,
|
||||
QSE_STX_PARSER_ERROR_TOO_MANY_ARGUMENTS,
|
||||
|
||||
QSE_STX_PARSER_ERROR_PRIMITIVE_KEYWORD,
|
||||
QSE_STX_PARSER_ERROR_PRIMITIVE_NUMBER,
|
||||
QSE_STX_PARSER_ERROR_PRIMITIVE_NUMBER_RANGE,
|
||||
QSE_STX_PARSER_ERROR_PRIMITIVE_NOT_CLOSED,
|
||||
|
||||
QSE_STX_PARSER_ERROR_TEMPORARIES_NOT_CLOSED,
|
||||
QSE_STX_PARSER_ERROR_TOO_MANY_TEMPORARIES,
|
||||
QSE_STX_PARSER_ERROR_PSEUDO_VARIABLE,
|
||||
QSE_STX_PARSER_ERROR_PRIMARY,
|
||||
|
||||
QSE_STX_PARSER_ERROR_NO_PERIOD,
|
||||
QSE_STX_PARSER_ERROR_NO_RPAREN,
|
||||
QSE_STX_PARSER_ERROR_BLOCK_ARGUMENT_NAME,
|
||||
QSE_STX_PARSER_ERROR_BLOCK_ARGUMENT_LIST,
|
||||
QSE_STX_PARSER_ERROR_BLOCK_NOT_CLOSED,
|
||||
|
||||
QSE_STX_PARSER_ERROR_UNDECLARED_NAME,
|
||||
QSE_STX_PARSER_ERROR_TOO_MANY_LITERALS
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
/* input_func cmd */
|
||||
QSE_STX_PARSER_INPUT_OPEN,
|
||||
QSE_STX_PARSER_INPUT_CLOSE,
|
||||
QSE_STX_PARSER_INPUT_CONSUME,
|
||||
QSE_STX_PARSER_INPUT_REWIND
|
||||
};
|
||||
|
||||
typedef struct qse_stx_parser_t qse_stx_parser_t;
|
||||
|
||||
struct qse_stx_parser_t
|
||||
{
|
||||
qse_stx_t* stx;
|
||||
int error_code;
|
||||
|
||||
qse_word_t method_class;
|
||||
qse_stx_name_t method_name;
|
||||
|
||||
qse_char_t* temporaries[256]; /* TODO: different size? or dynamic? */
|
||||
qse_word_t argument_count;
|
||||
qse_word_t temporary_count;
|
||||
|
||||
qse_word_t literals[256]; /* TODO: make it a dynamic array */
|
||||
qse_word_t literal_count;
|
||||
|
||||
qse_arr_t bytecode;
|
||||
|
||||
qse_stx_token_t token;
|
||||
qse_cint_t curc;
|
||||
qse_cint_t ungotc[5];
|
||||
qse_size_t ungotc_count;
|
||||
|
||||
void* input_owner;
|
||||
int (*input_func) (int cmd, void* owner, void* arg);
|
||||
|
||||
qse_bool_t __dynamic;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
qse_stx_parser_t* qse_stx_parser_open (qse_stx_parser_t* parser, qse_stx_t* stx);
|
||||
void qse_stx_parser_close (qse_stx_parser_t* parser);
|
||||
|
||||
const qse_char_t* qse_stx_parser_error_string (qse_stx_parser_t* parser);
|
||||
int qse_stx_parser_parse_method (
|
||||
qse_stx_parser_t* parser, qse_word_t method_class, void* input);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -131,6 +131,7 @@ struct qse_stx_t
|
||||
qse_word_t class_systemdictionary;
|
||||
qse_word_t class_method;
|
||||
qse_word_t class_smallinteger;
|
||||
qse_word_t class_parser;
|
||||
} ref;
|
||||
|
||||
qse_bool_t __wantabort; /* TODO: make it a function pointer */
|
||||
|
Loading…
Reference in New Issue
Block a user