added nsup field to the class object to chain back to the upper namespace in the hierarchy.
changed bootstrapping code and compiler code to weave top-level namespace hierarchy more consistantly, mostly related to the System class and its intrinsic namespace dictionary linked via the nsdic field
This commit is contained in:
parent
8324f64dea
commit
1bdaba968d
@ -6,26 +6,15 @@ class(#pointer,#limited) Class(Apex)
|
||||
{
|
||||
var spec, selfspec, superclass, subclasses, name, modname.
|
||||
var instvars, classinstvars, classvars, pooldics.
|
||||
var instmthdic, classmthdic, nsdic, cdic.
|
||||
var instmthdic, classmthdic, nsup, nsdic, cdic.
|
||||
var trsize, initv, initv_ci.
|
||||
|
||||
method(#class) initialize
|
||||
{
|
||||
^self.
|
||||
}
|
||||
method(#class) initialize { ^self }
|
||||
|
||||
(* most of the following methods can actually become class methods of Apex.
|
||||
* if the instance varibles can be made accessible from the Apex class. *)
|
||||
|
||||
method name
|
||||
{
|
||||
^self.name
|
||||
}
|
||||
|
||||
method superclass
|
||||
{
|
||||
^self.superclass
|
||||
}
|
||||
method name { ^self.name }
|
||||
method superclass { ^self.superclass }
|
||||
|
||||
method specNumInstVars
|
||||
{
|
||||
@ -45,8 +34,6 @@ class(#pointer,#limited) Class(Apex)
|
||||
^false
|
||||
}*)
|
||||
|
||||
method nsdic
|
||||
{
|
||||
^self.nsdic
|
||||
}
|
||||
method nsup { ^self.nsup }
|
||||
method nsdic { ^self.nsdic }
|
||||
}
|
||||
|
@ -513,8 +513,23 @@ class Dictionary(Set)
|
||||
}
|
||||
}
|
||||
|
||||
class SystemDictionary(Set)
|
||||
(* Namespace is marked with #limited. If a compiler is writeen in moo itself, it must
|
||||
* call a primitive to instantiate a new namespace rather than sending the new message
|
||||
* to Namespace *)
|
||||
class(#limited) Namespace(Set)
|
||||
{
|
||||
var name, nsup.
|
||||
|
||||
method name { ^self.name }
|
||||
## method name: name { self.name := name }
|
||||
|
||||
(* nsup points to either the class associated with this namespace or directly
|
||||
* the upper namespace placed above this namespace. when it points to a class,
|
||||
* you should inspect the nsup field of the class to reach the actual upper
|
||||
* namespace *)
|
||||
method nsup { ^self.nsup }
|
||||
## method nsup: nsup { self.nsup := nsup }
|
||||
|
||||
method at: key
|
||||
{
|
||||
if (key class ~= Symbol) { InvalidArgumentException signal: 'key is not a symbol' }.
|
||||
@ -528,17 +543,12 @@ class SystemDictionary(Set)
|
||||
}
|
||||
}
|
||||
|
||||
class Namespace(Set)
|
||||
{
|
||||
}
|
||||
|
||||
class PoolDictionary(Set)
|
||||
{
|
||||
}
|
||||
|
||||
class MethodDictionary(Dictionary)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
extend Apex
|
||||
|
@ -94,6 +94,7 @@ class MyObject(Object)
|
||||
'unusable variable in compiled code'
|
||||
'inaccessible variable'
|
||||
'ambiguous variable'
|
||||
'inaccessible self'
|
||||
'wrong expression primary'
|
||||
'too many temporaries'
|
||||
'too many arguments'
|
||||
|
697
moo/lib/comp.c
697
moo/lib/comp.c
File diff suppressed because it is too large
Load Diff
@ -47,7 +47,7 @@ void moo_dumpsymtab (moo_t* moo)
|
||||
MOO_DEBUG0 (moo, "--------------------------------------------\n");
|
||||
}
|
||||
|
||||
void moo_dumpdic (moo_t* moo, moo_oop_set_t dic, const moo_bch_t* title)
|
||||
void moo_dumpdic (moo_t* moo, moo_oop_dic_t dic, const moo_bch_t* title)
|
||||
{
|
||||
moo_oow_t i;
|
||||
moo_oop_association_t ass;
|
||||
|
@ -85,7 +85,7 @@ static moo_oop_oop_t expand_bucket (moo_t* moo, moo_oop_oop_t oldbuc)
|
||||
return newbuc;
|
||||
}
|
||||
|
||||
static moo_oop_association_t find_or_upsert (moo_t* moo, moo_oop_set_t dic, moo_oop_char_t key, moo_oop_t value)
|
||||
static moo_oop_association_t find_or_upsert (moo_t* moo, moo_oop_dic_t dic, moo_oop_char_t key, moo_oop_t value)
|
||||
{
|
||||
moo_ooi_t tally;
|
||||
moo_oow_t hv, index;
|
||||
@ -196,7 +196,7 @@ oops:
|
||||
return MOO_NULL;
|
||||
}
|
||||
|
||||
static moo_oop_association_t lookup (moo_t* moo, moo_oop_set_t dic, const moo_oocs_t* name)
|
||||
static moo_oop_association_t lookup (moo_t* moo, moo_oop_dic_t dic, const moo_oocs_t* name)
|
||||
{
|
||||
/* this is special version of moo_getatsysdic() that performs
|
||||
* lookup using a plain string specified */
|
||||
@ -234,40 +234,40 @@ static moo_oop_association_t lookup (moo_t* moo, moo_oop_set_t dic, const moo_oo
|
||||
moo_oop_association_t moo_putatsysdic (moo_t* moo, moo_oop_t key, moo_oop_t value)
|
||||
{
|
||||
MOO_ASSERT (moo, MOO_CLASSOF(moo,key) == moo->_symbol);
|
||||
return find_or_upsert (moo, moo->sysdic, (moo_oop_char_t)key, value);
|
||||
return find_or_upsert (moo, (moo_oop_dic_t)moo->sysdic, (moo_oop_char_t)key, value);
|
||||
}
|
||||
|
||||
moo_oop_association_t moo_getatsysdic (moo_t* moo, moo_oop_t key)
|
||||
{
|
||||
MOO_ASSERT (moo, MOO_CLASSOF(moo,key) == moo->_symbol);
|
||||
return find_or_upsert (moo, moo->sysdic, (moo_oop_char_t)key, MOO_NULL);
|
||||
return find_or_upsert (moo, (moo_oop_dic_t)moo->sysdic, (moo_oop_char_t)key, MOO_NULL);
|
||||
}
|
||||
|
||||
moo_oop_association_t moo_lookupsysdic (moo_t* moo, const moo_oocs_t* name)
|
||||
{
|
||||
return lookup (moo, moo->sysdic, name);
|
||||
return lookup (moo, (moo_oop_dic_t)moo->sysdic, name);
|
||||
}
|
||||
|
||||
moo_oop_association_t moo_putatdic (moo_t* moo, moo_oop_set_t dic, moo_oop_t key, moo_oop_t value)
|
||||
moo_oop_association_t moo_putatdic (moo_t* moo, moo_oop_dic_t dic, moo_oop_t key, moo_oop_t value)
|
||||
{
|
||||
/*MOO_ASSERT (moo, MOO_CLASSOF(moo,key) == moo->_symbol);*/
|
||||
MOO_ASSERT (moo, MOO_OBJ_IS_CHAR_POINTER(key));
|
||||
return find_or_upsert (moo, dic, (moo_oop_char_t)key, value);
|
||||
}
|
||||
|
||||
moo_oop_association_t moo_getatdic (moo_t* moo, moo_oop_set_t dic, moo_oop_t key)
|
||||
moo_oop_association_t moo_getatdic (moo_t* moo, moo_oop_dic_t dic, moo_oop_t key)
|
||||
{
|
||||
/*MOO_ASSERT (moo, MOO_CLASSOF(moo,key) == moo->_symbol); */
|
||||
MOO_ASSERT (moo, MOO_OBJ_IS_CHAR_POINTER(key));
|
||||
return find_or_upsert (moo, dic, (moo_oop_char_t)key, MOO_NULL);
|
||||
}
|
||||
|
||||
moo_oop_association_t moo_lookupdic (moo_t* moo, moo_oop_set_t dic, const moo_oocs_t* name)
|
||||
moo_oop_association_t moo_lookupdic (moo_t* moo, moo_oop_dic_t dic, const moo_oocs_t* name)
|
||||
{
|
||||
return lookup (moo, dic, name);
|
||||
}
|
||||
|
||||
int moo_deletedic (moo_t* moo, moo_oop_set_t dic, const moo_oocs_t* name)
|
||||
int moo_deletedic (moo_t* moo, moo_oop_dic_t dic, const moo_oocs_t* name)
|
||||
{
|
||||
moo_ooi_t tally;
|
||||
moo_oow_t hv, index, bs, i, x, y, z;
|
||||
@ -334,18 +334,17 @@ found:
|
||||
return 0;
|
||||
}
|
||||
|
||||
moo_oop_set_t moo_makedic (moo_t* moo, moo_oop_class_t _class, moo_oow_t size)
|
||||
moo_oop_dic_t moo_makedic (moo_t* moo, moo_oop_class_t _class, moo_oow_t size)
|
||||
{
|
||||
moo_oop_set_t dic;
|
||||
moo_oop_dic_t dic;
|
||||
moo_oop_t tmp;
|
||||
|
||||
MOO_ASSERT (moo, MOO_CLASSOF(moo,_class) == moo->_class);
|
||||
MOO_ASSERT (moo, MOO_CLASS_SPEC_NAMED_INSTVARS(MOO_OOP_TO_SMOOI(_class->spec)) >= MOO_DIC_NAMED_INSTVARS);
|
||||
|
||||
dic = (moo_oop_set_t)moo_instantiate (moo, _class, MOO_NULL, 0);
|
||||
dic = (moo_oop_dic_t)moo_instantiate (moo, _class, MOO_NULL, 0);
|
||||
if (!dic) return MOO_NULL;
|
||||
|
||||
MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(dic) == MOO_SET_NAMED_INSTVARS);
|
||||
|
||||
moo_pushtmp (moo, (moo_oop_t*)&dic);
|
||||
tmp = moo_instantiate (moo, moo->_array, MOO_NULL, size);
|
||||
moo_poptmp (moo);
|
||||
@ -354,8 +353,16 @@ moo_oop_set_t moo_makedic (moo_t* moo, moo_oop_class_t _class, moo_oow_t size)
|
||||
dic->tally = MOO_SMOOI_TO_OOP(0);
|
||||
dic->bucket = (moo_oop_oop_t)tmp;
|
||||
|
||||
MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(dic) == MOO_SET_NAMED_INSTVARS);
|
||||
MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(dic) == MOO_CLASS_SPEC_NAMED_INSTVARS(MOO_OOP_TO_SMOOI(_class->spec)));
|
||||
MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(dic->bucket) == size);
|
||||
|
||||
return dic;
|
||||
}
|
||||
|
||||
moo_oop_nsdic_t moo_makensdic (moo_t* moo, moo_oop_class_t _class, moo_oow_t size)
|
||||
{
|
||||
MOO_ASSERT (moo, MOO_CLASSOF(moo,_class) == moo->_class);
|
||||
MOO_ASSERT (moo, MOO_CLASS_SPEC_NAMED_INSTVARS(MOO_OOP_TO_SMOOI(_class->spec)) >= MOO_NSDIC_NAMED_INSTVARS);
|
||||
|
||||
return (moo_oop_nsdic_t)moo_makedic (moo, _class, size);
|
||||
}
|
||||
|
@ -120,25 +120,26 @@ static moo_ooch_t synerrstr_46[] = {'u','n','d','e','c','l','a','r','e','d',' ',
|
||||
static moo_ooch_t synerrstr_47[] = {'u','n','u','s','a','b','l','e',' ','v','a','r','i','a','b','l','e',' ','i','n',' ','c','o','m','p','i','l','e','d',' ','c','o','d','e','\0'};
|
||||
static moo_ooch_t synerrstr_48[] = {'i','n','a','c','c','e','s','s','i','b','l','e',' ','v','a','r','i','a','b','l','e','\0'};
|
||||
static moo_ooch_t synerrstr_49[] = {'a','m','b','i','g','u','o','u','s',' ','v','a','r','i','a','b','l','e','\0'};
|
||||
static moo_ooch_t synerrstr_50[] = {'w','r','o','n','g',' ','e','x','p','r','e','s','s','i','o','n',' ','p','r','i','m','a','r','y','\0'};
|
||||
static moo_ooch_t synerrstr_51[] = {'t','o','o',' ','m','a','n','y',' ','t','e','m','p','o','r','a','r','i','e','s','\0'};
|
||||
static moo_ooch_t synerrstr_52[] = {'t','o','o',' ','m','a','n','y',' ','a','r','g','u','m','e','n','t','s','\0'};
|
||||
static moo_ooch_t synerrstr_53[] = {'t','o','o',' ','m','a','n','y',' ','b','l','o','c','k',' ','t','e','m','p','o','r','a','r','i','e','s','\0'};
|
||||
static moo_ooch_t synerrstr_54[] = {'t','o','o',' ','m','a','n','y',' ','b','l','o','c','k',' ','a','r','g','u','m','e','n','t','s','\0'};
|
||||
static moo_ooch_t synerrstr_55[] = {'t','o','o',' ','l','a','r','g','e',' ','b','l','o','c','k','\0'};
|
||||
static moo_ooch_t synerrstr_56[] = {'t','o','o',' ','l','a','r','g','e',' ','a','r','r','a','y',' ','e','x','p','r','e','s','s','i','o','n','\0'};
|
||||
static moo_ooch_t synerrstr_57[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','n','u','m','b','e','r','\0'};
|
||||
static moo_ooch_t synerrstr_58[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','i','d','e','n','t','i','f','i','e','r','\0'};
|
||||
static moo_ooch_t synerrstr_59[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','a','r','g','u','m','e','n','t',' ','d','e','f','i','n','i','t','i','o','n','\0'};
|
||||
static moo_ooch_t synerrstr_60[] = {'w','r','o','n','g',' ','m','o','d','u','l','e',' ','n','a','m','e','\0'};
|
||||
static moo_ooch_t synerrstr_61[] = {'#','i','n','c','l','u','d','e',' ','e','r','r','o','r','\0'};
|
||||
static moo_ooch_t synerrstr_62[] = {'w','r','o','n','g',' ','n','a','m','e','s','p','a','c','e',' ','n','a','m','e','\0'};
|
||||
static moo_ooch_t synerrstr_63[] = {'w','r','o','n','g',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'};
|
||||
static moo_ooch_t synerrstr_64[] = {'d','u','p','l','i','c','a','t','e',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'};
|
||||
static moo_ooch_t synerrstr_65[] = {'l','i','t','e','r','a','l',' ','e','x','p','e','c','t','e','d','\0'};
|
||||
static moo_ooch_t synerrstr_66[] = {'b','r','e','a','k',' ','o','r',' ','c','o','n','t','i','n','u','e',' ','n','o','t',' ','w','i','t','h','i','n',' ','a',' ','l','o','o','p','\0'};
|
||||
static moo_ooch_t synerrstr_67[] = {'b','r','e','a','k',' ','o','r',' ','c','o','n','t','i','n','u','e',' ','w','i','t','h','i','n',' ','a',' ','b','l','o','c','k','\0'};
|
||||
static moo_ooch_t synerrstr_68[] = {'w','h','i','l','e',' ','e','x','p','e','c','t','e','d','\0'};
|
||||
static moo_ooch_t synerrstr_50[] = {'i','n','a','c','c','e','s','s','i','b','l','e',' ','s','e','l','f','\0'};
|
||||
static moo_ooch_t synerrstr_51[] = {'w','r','o','n','g',' ','e','x','p','r','e','s','s','i','o','n',' ','p','r','i','m','a','r','y','\0'};
|
||||
static moo_ooch_t synerrstr_52[] = {'t','o','o',' ','m','a','n','y',' ','t','e','m','p','o','r','a','r','i','e','s','\0'};
|
||||
static moo_ooch_t synerrstr_53[] = {'t','o','o',' ','m','a','n','y',' ','a','r','g','u','m','e','n','t','s','\0'};
|
||||
static moo_ooch_t synerrstr_54[] = {'t','o','o',' ','m','a','n','y',' ','b','l','o','c','k',' ','t','e','m','p','o','r','a','r','i','e','s','\0'};
|
||||
static moo_ooch_t synerrstr_55[] = {'t','o','o',' ','m','a','n','y',' ','b','l','o','c','k',' ','a','r','g','u','m','e','n','t','s','\0'};
|
||||
static moo_ooch_t synerrstr_56[] = {'t','o','o',' ','l','a','r','g','e',' ','b','l','o','c','k','\0'};
|
||||
static moo_ooch_t synerrstr_57[] = {'t','o','o',' ','l','a','r','g','e',' ','a','r','r','a','y',' ','e','x','p','r','e','s','s','i','o','n','\0'};
|
||||
static moo_ooch_t synerrstr_58[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','n','u','m','b','e','r','\0'};
|
||||
static moo_ooch_t synerrstr_59[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','i','d','e','n','t','i','f','i','e','r','\0'};
|
||||
static moo_ooch_t synerrstr_60[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','a','r','g','u','m','e','n','t',' ','d','e','f','i','n','i','t','i','o','n','\0'};
|
||||
static moo_ooch_t synerrstr_61[] = {'w','r','o','n','g',' ','m','o','d','u','l','e',' ','n','a','m','e','\0'};
|
||||
static moo_ooch_t synerrstr_62[] = {'#','i','n','c','l','u','d','e',' ','e','r','r','o','r','\0'};
|
||||
static moo_ooch_t synerrstr_63[] = {'w','r','o','n','g',' ','n','a','m','e','s','p','a','c','e',' ','n','a','m','e','\0'};
|
||||
static moo_ooch_t synerrstr_64[] = {'w','r','o','n','g',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'};
|
||||
static moo_ooch_t synerrstr_65[] = {'d','u','p','l','i','c','a','t','e',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'};
|
||||
static moo_ooch_t synerrstr_66[] = {'l','i','t','e','r','a','l',' ','e','x','p','e','c','t','e','d','\0'};
|
||||
static moo_ooch_t synerrstr_67[] = {'b','r','e','a','k',' ','o','r',' ','c','o','n','t','i','n','u','e',' ','n','o','t',' ','w','i','t','h','i','n',' ','a',' ','l','o','o','p','\0'};
|
||||
static moo_ooch_t synerrstr_68[] = {'b','r','e','a','k',' ','o','r',' ','c','o','n','t','i','n','u','e',' ','w','i','t','h','i','n',' ','a',' ','b','l','o','c','k','\0'};
|
||||
static moo_ooch_t synerrstr_69[] = {'w','h','i','l','e',' ','e','x','p','e','c','t','e','d','\0'};
|
||||
static moo_ooch_t* synerrstr[] =
|
||||
{
|
||||
synerrstr_0, synerrstr_1, synerrstr_2, synerrstr_3, synerrstr_4, synerrstr_5, synerrstr_6, synerrstr_7,
|
||||
@ -149,7 +150,7 @@ static moo_ooch_t* synerrstr[] =
|
||||
synerrstr_40, synerrstr_41, synerrstr_42, synerrstr_43, synerrstr_44, synerrstr_45, synerrstr_46, synerrstr_47,
|
||||
synerrstr_48, synerrstr_49, synerrstr_50, synerrstr_51, synerrstr_52, synerrstr_53, synerrstr_54, synerrstr_55,
|
||||
synerrstr_56, synerrstr_57, synerrstr_58, synerrstr_59, synerrstr_60, synerrstr_61, synerrstr_62, synerrstr_63,
|
||||
synerrstr_64, synerrstr_65, synerrstr_66, synerrstr_67, synerrstr_68
|
||||
synerrstr_64, synerrstr_65, synerrstr_66, synerrstr_67, synerrstr_68, synerrstr_69
|
||||
};
|
||||
#endif
|
||||
/* END: GENERATED WITH generr.moo */
|
||||
|
@ -1042,7 +1042,7 @@ static moo_oop_method_t find_method (moo_t* moo, moo_oop_t receiver, const moo_o
|
||||
moo_oop_class_t cls;
|
||||
moo_oop_association_t ass;
|
||||
moo_oop_t c;
|
||||
moo_oop_set_t mthdic;
|
||||
moo_oop_dic_t mthdic;
|
||||
int dic_no;
|
||||
/* TODO: implement method lookup cache */
|
||||
|
||||
@ -5094,7 +5094,7 @@ int moo_execute (moo_t* moo)
|
||||
t1 = MOO_STACK_GETTOP(moo);
|
||||
MOO_STACK_POP (moo);
|
||||
t2 = MOO_STACK_GETTOP(moo);
|
||||
moo_putatdic (moo, (moo_oop_set_t)t2, ((moo_oop_association_t)t1)->key, ((moo_oop_association_t)t1)->value);
|
||||
moo_putatdic (moo, (moo_oop_dic_t)t2, ((moo_oop_association_t)t1)->key, ((moo_oop_association_t)t1)->value);
|
||||
*/
|
||||
if (send_message (moo, moo->dicputassocsym, 0, 1) <= -1) goto oops;
|
||||
break;
|
||||
|
46
moo/lib/gc.c
46
moo/lib/gc.c
@ -92,8 +92,6 @@ static kernel_class_info_t kernel_classes[] =
|
||||
{ 9, { 'B','y','t','e','A','r','r','a','y' }, MOO_OFFSETOF(moo_t, _byte_array) },
|
||||
{ 9, { 'S','y','m','b','o','l','S','e','t' }, MOO_OFFSETOF(moo_t, _symbol_set) },
|
||||
{ 10, { 'D','i','c','t','i','o','n','a','r','y' }, MOO_OFFSETOF(moo_t, _dictionary) },
|
||||
{ 16, { 'S','y','s','t','e','m','D','i','c','t','i','o','n','a','r','y' }, MOO_OFFSETOF(moo_t, _system_dictionary) },
|
||||
|
||||
{ 9, { 'N','a','m','e','s','p','a','c','e' }, MOO_OFFSETOF(moo_t, _namespace) },
|
||||
{ 14, { 'P','o','o','l','D','i','c','t','i','o','n','a','r','y' }, MOO_OFFSETOF(moo_t, _pool_dictionary) },
|
||||
{ 16, { 'M','e','t','h','o','d','D','i','c','t','i','o','n','a','r','y' }, MOO_OFFSETOF(moo_t, _method_dictionary) },
|
||||
@ -182,13 +180,11 @@ static int ignite_1 (moo_t* moo)
|
||||
|
||||
moo->_array = alloc_kernel_class (moo, 0, 0, MOO_CLASS_SPEC_MAKE(0, MOO_CLASS_SPEC_FLAG_INDEXED, MOO_OBJ_TYPE_OOP));
|
||||
moo->_byte_array = alloc_kernel_class (moo, 0, 0, MOO_CLASS_SPEC_MAKE(0, MOO_CLASS_SPEC_FLAG_INDEXED, MOO_OBJ_TYPE_BYTE));
|
||||
moo->_symbol_set = alloc_kernel_class (moo, 0, 0, MOO_CLASS_SPEC_MAKE(MOO_SET_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP));
|
||||
moo->_dictionary = alloc_kernel_class (moo, 0, 0, MOO_CLASS_SPEC_MAKE(MOO_SET_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP));
|
||||
moo->_system_dictionary = alloc_kernel_class (moo, 0, 0, MOO_CLASS_SPEC_MAKE(MOO_SET_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP));
|
||||
|
||||
moo->_namespace = alloc_kernel_class (moo, 0, 0, MOO_CLASS_SPEC_MAKE(MOO_SET_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP));
|
||||
moo->_pool_dictionary = alloc_kernel_class (moo, 0, 0, MOO_CLASS_SPEC_MAKE(MOO_SET_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP));
|
||||
moo->_method_dictionary = alloc_kernel_class (moo, 0, 0, MOO_CLASS_SPEC_MAKE(MOO_SET_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP));
|
||||
moo->_symbol_set = alloc_kernel_class (moo, 0, 0, MOO_CLASS_SPEC_MAKE(MOO_DIC_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP));
|
||||
moo->_dictionary = alloc_kernel_class (moo, 0, 0, MOO_CLASS_SPEC_MAKE(MOO_DIC_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP));
|
||||
moo->_namespace = alloc_kernel_class (moo, MOO_CLASS_SELFSPEC_FLAG_LIMITED, 0, MOO_CLASS_SPEC_MAKE(MOO_NSDIC_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP));
|
||||
moo->_pool_dictionary = alloc_kernel_class (moo, 0, 0, MOO_CLASS_SPEC_MAKE(MOO_DIC_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP));
|
||||
moo->_method_dictionary = alloc_kernel_class (moo, 0, 0, MOO_CLASS_SPEC_MAKE(MOO_DIC_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP));
|
||||
moo->_method = alloc_kernel_class (moo, 0, 0, MOO_CLASS_SPEC_MAKE(MOO_METHOD_NAMED_INSTVARS, MOO_CLASS_SPEC_FLAG_INDEXED, MOO_OBJ_TYPE_OOP));
|
||||
moo->_association = alloc_kernel_class (moo, 0, 0, MOO_CLASS_SPEC_MAKE(MOO_ASSOCIATION_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP));
|
||||
|
||||
@ -222,8 +218,7 @@ static int ignite_1 (moo_t* moo)
|
||||
!moo->_object || !moo->_string ||
|
||||
|
||||
!moo->_symbol || !moo->_array ||
|
||||
!moo->_byte_array || !moo->_symbol_set ||
|
||||
!moo->_dictionary || !moo->_system_dictionary ||
|
||||
!moo->_byte_array || !moo->_symbol_set || !moo->_dictionary ||
|
||||
|
||||
!moo->_namespace || !moo->_pool_dictionary ||
|
||||
!moo->_method_dictionary || !moo->_method || !moo->_association ||
|
||||
@ -252,7 +247,7 @@ static int ignite_2 (moo_t* moo)
|
||||
/* Create the symbol table */
|
||||
tmp = moo_instantiate (moo, moo->_symbol_set, MOO_NULL, 0);
|
||||
if (!tmp) return -1;
|
||||
moo->symtab = (moo_oop_set_t)tmp;
|
||||
moo->symtab = (moo_oop_dic_t)tmp;
|
||||
|
||||
moo->symtab->tally = MOO_SMOOI_TO_OOP(0);
|
||||
/* It's important to assign the result of moo_instantiate() to a temporary
|
||||
@ -265,9 +260,9 @@ static int ignite_2 (moo_t* moo)
|
||||
moo->symtab->bucket = (moo_oop_oop_t)tmp;
|
||||
|
||||
/* Create the system dictionary */
|
||||
tmp = (moo_oop_t)moo_makedic (moo, moo->_system_dictionary, moo->option.dfl_sysdic_size);
|
||||
tmp = (moo_oop_t)moo_makensdic (moo, moo->_namespace, moo->option.dfl_sysdic_size);
|
||||
if (!tmp) return -1;
|
||||
moo->sysdic = (moo_oop_set_t)tmp;
|
||||
moo->sysdic = (moo_oop_nsdic_t)tmp;
|
||||
|
||||
/* Create a nil process used to simplify nil check in GC.
|
||||
* only accessible by VM. not exported via the global dictionary. */
|
||||
@ -283,9 +278,6 @@ static int ignite_2 (moo_t* moo)
|
||||
moo->processor->tally = MOO_SMOOI_TO_OOP(0);
|
||||
moo->processor->active = moo->nil_process;
|
||||
|
||||
/* Attach the system dictionary to the nsdic field of the System class */
|
||||
moo->_system->nsdic = moo->sysdic;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -297,7 +289,8 @@ static int ignite_3 (moo_t* moo)
|
||||
static moo_ooch_t str_dicputassoc[] = { 'p', 'u', 't', '_', 'a', 's', 's', 'o', 'c', ':' };
|
||||
|
||||
moo_oow_t i;
|
||||
moo_oop_t sym, cls;
|
||||
moo_oop_t sym;
|
||||
moo_oop_class_t cls;
|
||||
moo_oop_t* moo_ptr;
|
||||
|
||||
for (i = 0; i < MOO_COUNTOF(kernel_classes); i++)
|
||||
@ -305,12 +298,21 @@ static int ignite_3 (moo_t* moo)
|
||||
sym = moo_makesymbol (moo, kernel_classes[i].name, kernel_classes[i].len);
|
||||
if (!sym) return -1;
|
||||
|
||||
cls = *(moo_oop_t*)((moo_uint8_t*)moo + kernel_classes[i].offset);
|
||||
cls = *(moo_oop_class_t*)((moo_uint8_t*)moo + kernel_classes[i].offset);
|
||||
cls->name = (moo_oop_char_t)sym;
|
||||
cls->nsup = moo->sysdic;
|
||||
|
||||
if (!moo_putatsysdic(moo, sym, cls)) return -1;
|
||||
if (!moo_putatsysdic(moo, sym, (moo_oop_t)cls)) return -1;
|
||||
moo_ptr++;
|
||||
}
|
||||
|
||||
/* Attach the system dictionary to the nsdic field of the System class */
|
||||
moo->_system->nsdic = moo->sysdic;
|
||||
/* Set the name field of the system dictionary */
|
||||
moo->sysdic->name = moo->_system->name;
|
||||
/* Set the owning class field of the system dictionary, it's circular here */
|
||||
moo->sysdic->nsup = (moo_oop_t)moo->_system;
|
||||
|
||||
/* Make the process scheduler avaialble as the global name 'Processor' */
|
||||
sym = moo_makesymbol (moo, str_processor, MOO_COUNTOF(str_processor));
|
||||
if (!sym) return -1;
|
||||
@ -632,7 +634,7 @@ void moo_gc (moo_t* moo)
|
||||
*(moo_oop_t*)((moo_uint8_t*)moo + kernel_classes[i].offset) = tmp;
|
||||
}
|
||||
|
||||
moo->sysdic = (moo_oop_set_t)moo_moveoop (moo, (moo_oop_t)moo->sysdic);
|
||||
moo->sysdic = (moo_oop_nsdic_t)moo_moveoop (moo, (moo_oop_t)moo->sysdic);
|
||||
moo->processor = (moo_oop_process_scheduler_t)moo_moveoop (moo, (moo_oop_t)moo->processor);
|
||||
moo->nil_process = (moo_oop_process_t)moo_moveoop (moo, (moo_oop_t)moo->nil_process);
|
||||
moo->dicnewsym = (moo_oop_char_t)moo_moveoop (moo, (moo_oop_t)moo->dicnewsym);
|
||||
@ -683,7 +685,7 @@ void moo_gc (moo_t* moo)
|
||||
compact_symbol_table (moo, old_nil);
|
||||
|
||||
/* move the symbol table itself */
|
||||
moo->symtab = (moo_oop_set_t)moo_moveoop (moo, (moo_oop_t)moo->symtab);
|
||||
moo->symtab = (moo_oop_dic_t)moo_moveoop (moo, (moo_oop_t)moo->symtab);
|
||||
|
||||
/* scan the new heap again from the end position of
|
||||
* the previous scan to move referenced objects by
|
||||
|
@ -423,8 +423,8 @@ struct moo_pooldic_t
|
||||
moo_oow_t fqn_capa;
|
||||
moo_ioloc_t fqn_loc;
|
||||
|
||||
moo_oop_set_t pd_oop;
|
||||
moo_oop_set_t ns_oop;
|
||||
moo_oop_dic_t pd_oop;
|
||||
moo_oop_nsdic_t ns_oop;
|
||||
};
|
||||
|
||||
typedef struct moo_oopbuf_t moo_oopbuf_t;
|
||||
@ -468,10 +468,8 @@ struct moo_compiler_t
|
||||
/* the last token read */
|
||||
moo_iotok_t tok;
|
||||
moo_iolink_t* io_names;
|
||||
#if 0
|
||||
int in_array;
|
||||
#endif
|
||||
|
||||
/* syntax error information */
|
||||
moo_synerr_t synerr;
|
||||
|
||||
/* temporary space used when dealing with an illegal character */
|
||||
@ -492,14 +490,16 @@ struct moo_compiler_t
|
||||
|
||||
moo_oop_class_t self_oop;
|
||||
moo_oop_t super_oop; /* this may be nil. so the type is moo_oop_t */
|
||||
moo_oop_set_t pooldic_oop; /* used when compiling a pooldic definition */
|
||||
moo_oop_set_t ns_oop;
|
||||
#if 0
|
||||
moo_oop_dic_t pooldic_oop; /* used when compiling a pooldic definition */
|
||||
#endif
|
||||
moo_oop_nsdic_t ns_oop;
|
||||
moo_oocs_t fqn;
|
||||
moo_oocs_t name;
|
||||
moo_oow_t fqn_capa;
|
||||
moo_ioloc_t fqn_loc;
|
||||
|
||||
moo_oop_set_t superns_oop;
|
||||
moo_oop_nsdic_t superns_oop;
|
||||
moo_oocs_t superfqn;
|
||||
moo_oocs_t supername;
|
||||
moo_oow_t superfqn_capa;
|
||||
@ -542,21 +542,23 @@ struct moo_compiler_t
|
||||
moo_oow_t dcl_count;
|
||||
|
||||
/* used to hold imported pool dictionarie objects */
|
||||
moo_oop_set_t* oops;
|
||||
moo_oop_dic_t* oops;
|
||||
moo_oow_t oops_capa;
|
||||
} pooldic_imp;
|
||||
|
||||
|
||||
/* pooldic declaration inside class */
|
||||
moo_pooldic_t pooldic;
|
||||
} cls;
|
||||
|
||||
/* pooldic declaration */
|
||||
moo_pooldic_t pooldic;
|
||||
|
||||
/* information about a method being comipled */
|
||||
struct
|
||||
{
|
||||
int active;
|
||||
|
||||
moo_method_type_t type;
|
||||
int primitive; /* true if method(#primitive) */
|
||||
int lenient;
|
||||
int lenient; /* true if method(#lenient) */
|
||||
|
||||
/* method source text */
|
||||
moo_oocs_t text;
|
||||
@ -591,7 +593,6 @@ struct moo_compiler_t
|
||||
/* literals */
|
||||
moo_oopbuf_t literals;
|
||||
|
||||
|
||||
/* 0 for no primitive, 1 for a normal primitive, 2 for a named primitive */
|
||||
int pftype;
|
||||
/* primitive function number */
|
||||
@ -1080,30 +1081,36 @@ moo_oop_association_t moo_lookupsysdic (
|
||||
|
||||
moo_oop_association_t moo_putatdic (
|
||||
moo_t* moo,
|
||||
moo_oop_set_t dic,
|
||||
moo_oop_dic_t dic,
|
||||
moo_oop_t key,
|
||||
moo_oop_t value
|
||||
);
|
||||
|
||||
moo_oop_association_t moo_getatdic (
|
||||
moo_t* moo,
|
||||
moo_oop_set_t dic,
|
||||
moo_oop_dic_t dic,
|
||||
moo_oop_t key
|
||||
);
|
||||
|
||||
moo_oop_association_t moo_lookupdic (
|
||||
moo_t* moo,
|
||||
moo_oop_set_t dic,
|
||||
moo_oop_dic_t dic,
|
||||
const moo_oocs_t* name
|
||||
);
|
||||
|
||||
int moo_deletedic (
|
||||
moo_t* moo,
|
||||
moo_oop_set_t dic,
|
||||
moo_oop_dic_t dic,
|
||||
const moo_oocs_t* name
|
||||
);
|
||||
|
||||
moo_oop_set_t moo_makedic (
|
||||
moo_oop_dic_t moo_makedic (
|
||||
moo_t* moo,
|
||||
moo_oop_class_t _class,
|
||||
moo_oow_t size
|
||||
);
|
||||
|
||||
moo_oop_nsdic_t moo_makensdic (
|
||||
moo_t* moo,
|
||||
moo_oop_class_t _class,
|
||||
moo_oow_t size
|
||||
@ -1290,7 +1297,7 @@ moo_pfbase_t* moo_querymod (
|
||||
/* debug.c */
|
||||
/* ========================================================================= */
|
||||
void moo_dumpsymtab (moo_t* moo);
|
||||
void moo_dumpdic (moo_t* moo, moo_oop_set_t dic, const moo_bch_t* title);
|
||||
void moo_dumpdic (moo_t* moo, moo_oop_dic_t dic, const moo_bch_t* title);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
@ -925,7 +925,7 @@ void* moo_getobjtrailer (moo_t* moo, moo_oop_t obj, moo_oow_t* size)
|
||||
return MOO_OBJ_GET_TRAILER_BYTE(obj);
|
||||
}
|
||||
|
||||
moo_oop_t moo_findclass (moo_t* moo, moo_oop_set_t nsdic, const moo_ooch_t* name)
|
||||
moo_oop_t moo_findclass (moo_t* moo, moo_oop_nsdic_t nsdic, const moo_ooch_t* name)
|
||||
{
|
||||
moo_oop_association_t ass;
|
||||
moo_oocs_t n;
|
||||
@ -933,7 +933,7 @@ moo_oop_t moo_findclass (moo_t* moo, moo_oop_set_t nsdic, const moo_ooch_t* name
|
||||
n.ptr = (moo_ooch_t*)name;
|
||||
n.len = moo_countoocstr(name);
|
||||
|
||||
ass = moo_lookupdic (moo, nsdic, &n);
|
||||
ass = moo_lookupdic (moo, (moo_oop_dic_t)nsdic, &n);
|
||||
if (!ass || MOO_CLASSOF(moo,ass->value) != moo->_class)
|
||||
{
|
||||
moo_seterrnum (moo, MOO_ENOENT);
|
||||
|
@ -478,19 +478,37 @@ struct moo_trailer_t
|
||||
#define MOO_OBJ_GET_TRAILER_BYTE(oop) ((moo_oob_t*)&((moo_oop_oop_t)oop)->slot[MOO_OBJ_GET_SIZE(oop) + 1])
|
||||
#define MOO_OBJ_GET_TRAILER_SIZE(oop) ((moo_oow_t)((moo_oop_oop_t)oop)->slot[MOO_OBJ_GET_SIZE(oop)])
|
||||
|
||||
#define MOO_SET_NAMED_INSTVARS 2
|
||||
typedef struct moo_set_t moo_set_t;
|
||||
typedef struct moo_set_t* moo_oop_set_t;
|
||||
struct moo_set_t
|
||||
#define MOO_DIC_NAMED_INSTVARS 2
|
||||
typedef struct moo_dic_t moo_dic_t;
|
||||
typedef struct moo_dic_t* moo_oop_dic_t;
|
||||
struct moo_dic_t
|
||||
{
|
||||
MOO_OBJ_HEADER;
|
||||
moo_oop_t tally; /* SmallInteger */
|
||||
moo_oop_oop_t bucket; /* Array */
|
||||
};
|
||||
|
||||
#define MOO_CLASS_NAMED_INSTVARS 17
|
||||
/* [NOTE] the beginning of the moo_nsdic_t structure
|
||||
* must be identical to the moo_dic_t streucture */
|
||||
#define MOO_NSDIC_NAMED_INSTVARS 4
|
||||
typedef struct moo_nsdic_t moo_nsdic_t;
|
||||
typedef struct moo_nsdic_t* moo_oop_nsdic_t;
|
||||
|
||||
#define MOO_CLASS_NAMED_INSTVARS 18
|
||||
typedef struct moo_class_t moo_class_t;
|
||||
typedef struct moo_class_t* moo_oop_class_t;
|
||||
|
||||
struct moo_nsdic_t
|
||||
{
|
||||
MOO_OBJ_HEADER;
|
||||
moo_oop_t tally;
|
||||
moo_oop_t bucket;
|
||||
/* same as moo_dic_t so far */
|
||||
|
||||
moo_oop_char_t name; /* a symbol. if it belongs to a class, it will be the same as the name of the class */
|
||||
moo_oop_t nsup; /* a class if it belongs to the class. another nsdic if it doesn't */
|
||||
};
|
||||
|
||||
struct moo_class_t
|
||||
{
|
||||
MOO_OBJ_HEADER;
|
||||
@ -514,10 +532,13 @@ struct moo_class_t
|
||||
|
||||
/* [0] - instance methods, MethodDictionary
|
||||
* [1] - class methods, MethodDictionary */
|
||||
moo_oop_set_t mthdic[2];
|
||||
moo_oop_dic_t mthdic[2];
|
||||
|
||||
moo_oop_nsdic_t nsup; /* pointer to the upper namespace */
|
||||
moo_oop_nsdic_t nsdic; /* dictionary used for namespacing - may be nil when there are no subitems underneath */
|
||||
|
||||
moo_oop_dic_t cdic; /* constant dictionary */
|
||||
|
||||
moo_oop_set_t nsdic; /* dictionary used for namespacing */
|
||||
moo_oop_set_t cdic; /* constant dictionary */
|
||||
moo_oop_t trsize; /* trailer size for new instances */
|
||||
|
||||
/* [0] - initial values for instance variables of new instances
|
||||
@ -1041,7 +1062,6 @@ struct moo_t
|
||||
moo_oop_class_t _byte_array; /* ByteArray */
|
||||
moo_oop_class_t _symbol_set; /* SymbolSet */
|
||||
moo_oop_class_t _dictionary;
|
||||
moo_oop_class_t _system_dictionary; /* SystemDictionary */
|
||||
|
||||
moo_oop_class_t _namespace; /* Namespace */
|
||||
moo_oop_class_t _pool_dictionary; /* PoolDictionary */
|
||||
@ -1078,8 +1098,8 @@ struct moo_t
|
||||
* are 3 */
|
||||
moo_oop_class_t* tagged_classes[16];
|
||||
|
||||
moo_oop_set_t symtab; /* system-wide symbol table. instance of SymbolSet */
|
||||
moo_oop_set_t sysdic; /* system dictionary. instance of SystemDictionary */
|
||||
moo_oop_dic_t symtab; /* system-wide symbol table. instance of SymbolSet */
|
||||
moo_oop_nsdic_t sysdic; /* system dictionary. instance of Namespace */
|
||||
moo_oop_process_scheduler_t processor; /* instance of ProcessScheduler */
|
||||
moo_oop_process_t nil_process; /* instance of Process */
|
||||
moo_oop_char_t dicnewsym; /* symbol new: for dictionary */
|
||||
@ -1319,6 +1339,7 @@ enum moo_synerrnum_t
|
||||
MOO_SYNERR_VARUNUSE, /* unsuable variable in compiled code */
|
||||
MOO_SYNERR_VARINACC, /* inaccessible variable - e.g. accessing an instance variable from a class method is not allowed. */
|
||||
MOO_SYNERR_VARAMBIG, /* ambiguious variable - e.g. the variable is found in multiple pool dictionaries imported */
|
||||
MOO_SYNERR_SELFINACC, /* inaccessible self */
|
||||
MOO_SYNERR_PRIMARYINVAL, /* wrong expression primary */
|
||||
MOO_SYNERR_TMPRFLOOD, /* too many temporaries */
|
||||
MOO_SYNERR_ARGFLOOD, /* too many arguments */
|
||||
@ -1591,7 +1612,7 @@ MOO_EXPORT int moo_inttoooi (
|
||||
|
||||
MOO_EXPORT moo_oop_t moo_findclass (
|
||||
moo_t* moo,
|
||||
moo_oop_set_t nsdic,
|
||||
moo_oop_nsdic_t nsdic,
|
||||
const moo_ooch_t* name
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user