diff --git a/stix/lib/Stix.st b/stix/lib/Stix.st index 8e5a7a4..1fd355f 100644 --- a/stix/lib/Stix.st +++ b/stix/lib/Stix.st @@ -1,4 +1,4 @@ -#class Stix(nil) +#class Apex(nil) { #dcl(#class) sysdic. @@ -72,17 +72,17 @@ } } -#class Object(Stix) +#class Object(Apex) { } -#class NilObject(Stix) +#class UndefinedObject(Apex) { } -#class(#pointer) Class(Stix) +#class(#pointer) Class(Apex) { #dcl spec selfspec superclass subclasses name instvars classvars classinstvars instmthdic classmthdic. } @@ -245,12 +245,16 @@ { } +#class PoolDictionary(Set) +{ +} + #class MethodDictionary(Dictionary) { } -#class(#pointer) Context(Stix) +#class(#pointer) Context(Apex) { } diff --git a/stix/lib/comp.c b/stix/lib/comp.c index ac56ad6..64f0bf9 100644 --- a/stix/lib/comp.c +++ b/stix/lib/comp.c @@ -38,6 +38,7 @@ #define INSTANCE_METHOD_DICTIONARY_SIZE 256 /* TODO: choose the right size */ #define CLASS_METHOD_DICTIONARY_SIZE 128 /* TODO: choose the right size */ #define NAMESPACE_SIZE 128 /* TODO: choose the right size */ +#define POOL_DICTIONARY_SIZE_ALIGN 128 enum class_mod_t { @@ -93,6 +94,7 @@ static struct voca_t { 3, { 'm','t','h' } }, { 3, { 'n','i','l' } }, { 7, { 'p','o','i','n','t','e','r' } }, + { 7, { 'p','o','o','l','d','i','c' } }, { 10, { 'p','r','i','m','i','t','i','v','e',':' } }, { 4, { 's','e','l','f' } }, { 5, { 's','u','p','e','r' } }, @@ -123,6 +125,7 @@ enum voca_id_t VOCA_MTH, VOCA_NIL, VOCA_POINTER, + VOCA_POOLDIC, VOCA_PRIMITIVE_COLON, VOCA_SELF, VOCA_SUPER, @@ -1431,9 +1434,11 @@ retry: break; } +/* printf ("TOKEN: ["); print_ucs (&stix->c->tok.name); printf ("]\n"); +*/ return 0; } @@ -1866,7 +1871,9 @@ static stix_ssize_t find_class_level_variable (stix_t* stix, stix_oop_class_t se { STIX_ASSERT (STIX_CLASSOF(stix, self) == stix->_class); - /* NOTE the loop here assumes the right order of + /* [NOTE] + * the loop here assumes that the class has the following + * fields in the order shown below: * instvars * classvars * classinstvars @@ -1882,6 +1889,11 @@ static stix_ssize_t find_class_level_variable (stix_t* stix, stix_oop_class_t se if (pos >= 0) { super = self->superclass; + + /* 'self' may be STIX_NULL if STIX_NULL has been given for it. + * the caller must take good care when interpreting the meaning of + * this field */ + var->cls = self; goto done; } } @@ -1890,7 +1902,8 @@ static stix_ssize_t find_class_level_variable (stix_t* stix, stix_oop_class_t se } else { - /* the class definition is not available yet */ + /* the class definition is not available yet. + * find the variable in the compiler's own list */ for (index = VAR_INSTANCE; index <= VAR_CLASSINST; index++) { pos = find_word_in_string(&stix->c->cls.vars[index], name); @@ -1898,6 +1911,7 @@ static stix_ssize_t find_class_level_variable (stix_t* stix, stix_oop_class_t se if (pos >= 0) { super = stix->c->cls.super_oop; + var->cls = self; goto done; } } @@ -1908,7 +1922,9 @@ static stix_ssize_t find_class_level_variable (stix_t* stix, stix_oop_class_t se { STIX_ASSERT (STIX_CLASSOF(stix, super) == stix->_class); - /* NOTE the loop here assumes the right order of + /* [NOTE] + * the loop here assumes that the class has the following + * fields in the order shown below: * instvars * classvars * classinstvars @@ -1923,6 +1939,13 @@ static stix_ssize_t find_class_level_variable (stix_t* stix, stix_oop_class_t se pos = find_word_in_string(&hs, name); if (pos >= 0) { + /* class variables reside in the class where the definition is found. + * that means a class variable is found in the definition of + * a superclass, the superclass is the placeholder of the + * class variable. on the other hand, instance variables and + * class instance variables live in the current class being + * compiled as they are inherited. */ + var->cls = (index == VAR_CLASS)? (stix_oop_class_t)super: self; super = ((stix_oop_class_t)super)->superclass; goto done; } @@ -1935,15 +1958,12 @@ static stix_ssize_t find_class_level_variable (stix_t* stix, stix_oop_class_t se return -1; done: - /* 'self' may be STIX_NULL if STIX_NULL has been given for it. - * the caller must take good care when interpreting the meaning of - * this field */ - var->cls = self; - if (super != stix->_nil) { stix_oow_t spec; + /* the class being compiled has a superclass */ + STIX_ASSERT (STIX_CLASSOF(stix, super) == stix->_class); switch (index) { @@ -1957,12 +1977,13 @@ done: break; case VAR_CLASS: - /* no adjustment is needed. - * a class object is composed of three parts. - * fixed-part | classinst-variables | class-variabes - * the position returned here doesn't consider - * class instance variables that can be potentially - * placed before the class variables. */ + /* [NOTE] + * no adjustment is needed. + * a class object is composed of three parts. + * fixed-part | classinst-variables | class-variabes + * the position returned here doesn't consider + * class instance variables that can be potentially + * placed before the class variables. */ break; case VAR_CLASSINST: @@ -2143,7 +2164,7 @@ oops: return STIX_NULL; } -static int preprocess_dotted_class_name (stix_t* stix, int dont_add_ns, const stix_ucs_t* fqn, const stix_ioloc_t* fqn_loc, stix_ucs_t* name, stix_oop_set_t* ns_oop) +static int preprocess_dotted_name (stix_t* stix, int dont_add_ns, const stix_ucs_t* fqn, const stix_ioloc_t* fqn_loc, stix_ucs_t* name, stix_oop_set_t* ns_oop) { const stix_uch_t* ptr, * dot; stix_size_t len; @@ -2170,7 +2191,7 @@ static int preprocess_dotted_class_name (stix_t* stix, int dont_add_ns, const st if (ass) { if (STIX_CLASSOF(stix, ass->value) == stix->_namespace || - (seg.ptr == stix->c->cls.name.ptr && ass->value == (stix_oop_t)stix->sysdic)) + (seg.ptr == fqn->ptr && ass->value == (stix_oop_t)stix->sysdic)) { /* ok */ dic = (stix_oop_set_t)ass->value; @@ -2482,7 +2503,7 @@ static int get_variable_info (stix_t* stix, const stix_ucs_t* name, const stix_i /*TODO: handle self.XXX ---------- */ /* TOOD: handle pool dictionary ---- */ - if (preprocess_dotted_class_name (stix, 1, name, name_loc, &last, &ns_oop) <= -1) return -1; + if (preprocess_dotted_name (stix, 1, name, name_loc, &last, &ns_oop) <= -1) return -1; ass = stix_lookupdic (stix, ns_oop, &last); if (ass) @@ -2522,13 +2543,12 @@ static int get_variable_info (stix_t* stix, const stix_ucs_t* name, const stix_i break; case VAR_CLASS: -/* TODO: change code here ... */ /* a class variable can be access by both instance methods and class methods */ STIX_ASSERT (var->cls != STIX_NULL); STIX_ASSERT (STIX_CLASSOF(stix, var->cls) == stix->_class); -/* TOOD: index must be incremented witht eh number of classinstancevariables counts from var.cls - * verify if the below increment is correct*/ + /* increment the position by the number of class instance variables + * as the class variables are placed after the class instance variables */ var->pos += STIX_CLASS_NAMED_INSTVARS + STIX_CLASS_SELFSPEC_CLASSINSTVAR(STIX_OOP_TO_SMINT(var->cls->selfspec)); break; @@ -2557,7 +2577,10 @@ static int get_variable_info (stix_t* stix, const stix_ucs_t* name, const stix_i else { stix_oop_association_t ass; - ass = stix_lookupsysdic (stix, name); + /*ass = stix_lookupsysdic (stix, name);*/ + ass = stix_lookupdic (stix, stix->c->cls.ns_oop, name); + if (!ass && stix->c->cls.ns_oop != stix->sysdic) + ass = stix_lookupdic (stix, stix->sysdic, name); if (ass) { var->type = VAR_GLOBAL; @@ -2867,12 +2890,11 @@ static int add_to_arlit_buffer (stix_t* stix, stix_oop_t item) stix->c->mth.arlit = tmp; } -/* TODO: overflow check of stix->c->mth.arlit_count */ +/* TODO: overflow check of stix->c->mth.arlit_count itself */ stix->c->mth.arlit[stix->c->mth.arlit_count++] = item; return 0; } - static int __compile_byte_array_literal (stix_t* stix, stix_oop_t* xlit) { stix_ooi_t tmp; @@ -3671,7 +3693,6 @@ printf ("\t%s_into_instvar %d\n", (pop? "pop":"store"), (int)var.pos); break; case VAR_CLASS: -/* TODO is this correct? */ if (add_literal (stix, (stix_oop_t)var.cls, &index) <= -1 || emit_double_param_instruction (stix, (pop? BCODE_POP_INTO_OBJVAR_0: BCODE_STORE_INTO_OBJVAR_0), var.pos, index) <= -1) goto oops; printf ("\t%s_into_objvar %d %d\n", (pop? "pop":"store"), (int)var.pos, (int)index); @@ -3975,7 +3996,7 @@ need to write code to collect string. stix_poptmps (stix, tmp_count); tmp_count = 0; - if (!stix_putatdic (stix, stix->c->cls.mthdic_oop[stix->c->mth.type], name, (stix_oop_t)mth)) goto oops; + if (!stix_putatdic(stix, stix->c->cls.mthdic_oop[stix->c->mth.type], name, (stix_oop_t)mth)) goto oops; return 0; oops: @@ -4237,7 +4258,7 @@ static int __compile_class_definition (stix_t* stix, int extend) stix->c->cls.fqn_loc = stix->c->tok.loc; if (stix->c->tok.type == STIX_IOTOK_IDENT_DOTTED) { - if (preprocess_dotted_class_name(stix, extend, &stix->c->cls.fqn, &stix->c->cls.fqn_loc, &stix->c->cls.name, &stix->c->cls.ns_oop) <= -1) return -1; + if (preprocess_dotted_name(stix, extend, &stix->c->cls.fqn, &stix->c->cls.fqn_loc, &stix->c->cls.name, &stix->c->cls.ns_oop) <= -1) return -1; } else { @@ -4308,7 +4329,7 @@ printf ("\n"); if (stix->c->tok.type == STIX_IOTOK_IDENT_DOTTED) { - if (preprocess_dotted_class_name(stix, 1, &stix->c->cls.superfqn, &stix->c->cls.superfqn_loc, &stix->c->cls.supername, &stix->c->cls.superns_oop) <= -1) return -1; + if (preprocess_dotted_name(stix, 1, &stix->c->cls.superfqn, &stix->c->cls.superfqn_loc, &stix->c->cls.supername, &stix->c->cls.superns_oop) <= -1) return -1; } else { @@ -4507,6 +4528,182 @@ static int compile_class_definition (stix_t* stix, int extend) return n; } +static int __compile_pooldic_definition (stix_t* stix) +{ + stix_oop_t lit; + stix_ooi_t tally; + stix_size_t i; + + if (stix->c->tok.type != STIX_IOTOK_IDENT && + stix->c->tok.type != STIX_IOTOK_IDENT_DOTTED) + { + set_syntax_error (stix, STIX_SYNERR_IDENT, &stix->c->tok.loc, &stix->c->tok.name); + return -1; + } + + /* [NOTE] + * reuse stix->c->cls.fqn and related fields are reused + * to store the pool dictionary name */ + if (set_class_fqn(stix, &stix->c->tok.name) <= -1) return -1; + stix->c->cls.fqn_loc = stix->c->tok.loc; + + if (stix->c->tok.type == STIX_IOTOK_IDENT_DOTTED) + { + if (preprocess_dotted_name(stix, 0, &stix->c->cls.fqn, &stix->c->cls.fqn_loc, &stix->c->cls.name, &stix->c->cls.ns_oop) <= -1) return -1; + } + else + { + stix->c->cls.ns_oop = stix->sysdic; + } + + if (stix_lookupdic (stix, stix->c->cls.ns_oop, &stix->c->cls.name)) + { + /* a conflicting entry has been found */ + set_syntax_error (stix, STIX_SYNERR_POOLDICDUP, &stix->c->tok.loc, &stix->c->tok.name); + return -1; + } + + GET_TOKEN (stix); + if (stix->c->tok.type != STIX_IOTOK_LBRACE) + { + set_syntax_error (stix, STIX_SYNERR_LBRACE, &stix->c->tok.loc, &stix->c->tok.name); + return -1; + } + + GET_TOKEN (stix); + + while (stix->c->tok.type == STIX_IOTOK_SYMLIT) + { + lit = stix_makesymbol (stix, stix->c->tok.name.ptr, stix->c->tok.name.len); + if (!lit || add_to_arlit_buffer (stix, lit) <= -1) return -1; + + GET_TOKEN (stix); + + if (stix->c->tok.type != STIX_IOTOK_ASSIGN) + { + set_syntax_error (stix, STIX_SYNERR_ASSIGN, &stix->c->tok.loc, &stix->c->tok.name); + return -1; + } + + GET_TOKEN (stix); + + switch (stix->c->tok.type) + { + case STIX_IOTOK_NIL: + lit = stix->_nil; + goto simple_literal; + + case STIX_IOTOK_TRUE: + lit = stix->_true; + goto simple_literal; + + case STIX_IOTOK_FALSE: + lit = stix->_false; + goto simple_literal; + + + case STIX_IOTOK_CHARLIT: + STIX_ASSERT (stix->c->tok.name.len == 1); + lit = STIX_OOP_FROM_CHAR(stix->c->tok.name.ptr[0]); + goto simple_literal; + + case STIX_IOTOK_STRLIT: + lit = stix_instantiate (stix, stix->_string, stix->c->tok.name.ptr, stix->c->tok.name.len); + if (!lit) return -1; + goto simple_literal; + + case STIX_IOTOK_SYMLIT: + lit = stix_makesymbol (stix, stix->c->tok.name.ptr, stix->c->tok.name.len); + if (!lit) return -1; + goto simple_literal; + + case STIX_IOTOK_NUMLIT: + case STIX_IOTOK_RADNUMLIT: + goto simple_literal; + +#if 0 + case STIX_IOTOK_BPAREN: /* byte array */ + case STIX_IOTOK_APAREN: /* array */ + break; +TODO: +#endif + + default: + set_syntax_error (stix, STIX_SYNERR_LITERAL, &stix->c->tok.loc, &stix->c->tok.name); + return -1; + + simple_literal: + if (add_to_arlit_buffer(stix, lit) <= -1) return -1; + GET_TOKEN (stix); + break; + } + + /*if (stix->c->tok.type == STIX_IOTOK_RBRACE) goto done; + else*/ if (stix->c->tok.type != STIX_IOTOK_PERIOD) + { + set_syntax_error (stix, STIX_SYNERR_PERIOD, &stix->c->tok.loc, &stix->c->tok.name); + return -1; + } + + GET_TOKEN (stix); + } + + + if (stix->c->tok.type != STIX_IOTOK_RBRACE) + { + set_syntax_error (stix, STIX_SYNERR_RBRACE, &stix->c->tok.loc, &stix->c->tok.name); + return -1; + } + +/*done:*/ + GET_TOKEN (stix); + + tally = stix->c->mth.arlit_count / 2; +/*TODO: tally and arlit_count range check */ + /*if (!STIX_OOI_IN_SMINT_RANGE(tally)) ERROR??*/ + + stix->c->cls.mthdic_oop[0] = stix_makedic (stix, stix->_pool_dictionary, STIX_ALIGN(tally + 10, POOL_DICTIONARY_SIZE_ALIGN)); + if (!stix->c->cls.mthdic_oop[0]) return -1; + + for (i = 0; i < stix->c->mth.arlit_count; i += 2) + { + /* TODO: handle duplicate keys? */ + if (!stix_putatdic(stix, stix->c->cls.mthdic_oop[0], stix->c->mth.arlit[i], stix->c->mth.arlit[i + 1])) return -1; + } + + /* eveything seems ok. register the pool dictionary to the main + * system dictionary or to the name space it belongs to */ + lit = stix_makesymbol (stix, stix->c->cls.name.ptr, stix->c->cls.name.len); + if (!lit || !stix_putatdic (stix, stix->c->cls.ns_oop, lit, (stix_oop_t)stix->c->cls.mthdic_oop[0])) return -1; + return 0; +} + +static int compile_pooldic_definition (stix_t* stix) +{ + int n; + + /* reset the structure to hold information about a pool dictionary to be compiled. + * i'll be reusing some fields reserved for compling a class */ + stix->c->cls.name.len = 0; + STIX_MEMSET (&stix->c->cls.fqn_loc, 0, STIX_SIZEOF(stix->c->cls.fqn_loc)); + stix->c->cls.mthdic_oop[0] = STIX_NULL; + stix->c->cls.ns_oop = STIX_NULL; + stix->c->mth.literal_count = 0; + stix->c->mth.balit_count = 0; + stix->c->mth.arlit_count = 0; + + n = __compile_pooldic_definition (stix); + + /* reset these oops plus literal pointers not to confuse gc_compiler() */ + stix->c->cls.mthdic_oop[0] = STIX_NULL; + stix->c->cls.ns_oop = STIX_NULL; + stix->c->mth.literal_count = 0; + stix->c->mth.balit_count = 0; + stix->c->mth.arlit_count = 0; + return n; +} + + static int compile_stream (stix_t* stix) { GET_CHAR (stix); @@ -4537,6 +4734,12 @@ static int compile_stream (stix_t* stix) GET_TOKEN (stix); if (compile_class_definition(stix, 1) <= -1) return -1; } + else if (is_token_symbol(stix, VOCA_POOLDIC)) + { + /* #pooldic SharedPoolDic { #abc := 20. #defg := 'ayz' } */ + GET_TOKEN (stix); + if (compile_pooldic_definition(stix) <= -1) return -1; + } #if 0 else if (is_token_symbol(stix, VOCA_MAIN)) { diff --git a/stix/lib/gc.c b/stix/lib/gc.c index 36ba9b5..ee14e14 100644 --- a/stix/lib/gc.c +++ b/stix/lib/gc.c @@ -268,9 +268,9 @@ void stix_gc (stix_t* stix) stix->_true = stix_moveoop (stix, stix->_true); stix->_false = stix_moveoop (stix, stix->_false); - stix->_stix = stix_moveoop (stix, stix->_stix); + stix->_apex = stix_moveoop (stix, stix->_apex); stix->_class = stix_moveoop (stix, stix->_class); - stix->_nil_object = stix_moveoop (stix, stix->_nil_object); + stix->_undefined_object = stix_moveoop (stix, stix->_undefined_object); stix->_object = stix_moveoop (stix, stix->_object); stix->_array = stix_moveoop (stix, stix->_array); stix->_byte_array = stix_moveoop (stix, stix->_byte_array); @@ -279,6 +279,7 @@ void stix_gc (stix_t* stix) stix->_symbol_set = stix_moveoop (stix, stix->_symbol_set); stix->_system_dictionary = stix_moveoop (stix, stix->_system_dictionary); stix->_namespace = stix_moveoop (stix, stix->_namespace); + stix->_pool_dictionary = stix_moveoop (stix, stix->_pool_dictionary); stix->_method_dictionary = stix_moveoop (stix, stix->_method_dictionary); stix->_method = stix_moveoop (stix, stix->_method); stix->_association = stix_moveoop (stix, stix->_association); diff --git a/stix/lib/ignite.c b/stix/lib/ignite.c index 9861b1f..553f7a5 100644 --- a/stix/lib/ignite.c +++ b/stix/lib/ignite.c @@ -104,9 +104,9 @@ static int ignite_1 (stix_t* stix) STIX_OBJ_SET_CLASS (stix->_class, stix->_class); /* -------------------------------------------------------------- - * Stix - proto-object with 1 class variable. - * NilObject - class for the nil object. - * Object - top of all ordinary objects. + * Apex - proto-object with 1 class variable. + * UndefinedObject - class for the nil object. + * Object - top of all ordinary objects. * String * Symbol * Array @@ -115,8 +115,8 @@ static int ignite_1 (stix_t* stix) * Character * SmallIntger * -------------------------------------------------------------- */ - stix->_stix = alloc_kernel_class (stix, 1, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); - stix->_nil_object = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); + stix->_apex = alloc_kernel_class (stix, 1, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); + stix->_undefined_object = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); stix->_object = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); stix->_string = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 1, STIX_OBJ_TYPE_CHAR)); @@ -127,11 +127,12 @@ static int ignite_1 (stix_t* stix) stix->_system_dictionary = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_SET_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP)); stix->_namespace = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_SET_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP)); + stix->_pool_dictionary = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_SET_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP)); stix->_method_dictionary = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_SET_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP)); stix->_method = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_METHOD_NAMED_INSTVARS, 1, STIX_OBJ_TYPE_OOP)); stix->_association = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_ASSOCIATION_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP)); - stix->_method_context = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_CONTEXT_NAMED_INSTVARS, 1, STIX_OBJ_TYPE_OOP)); + stix->_method_context = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_CONTEXT_NAMED_INSTVARS, 1, STIX_OBJ_TYPE_OOP)); stix->_block_context = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_CONTEXT_NAMED_INSTVARS, 1, STIX_OBJ_TYPE_OOP)); stix->_true_class = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); stix->_false_class = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); @@ -141,19 +142,20 @@ static int ignite_1 (stix_t* stix) stix->_character = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); stix->_small_integer = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); - if (!stix->_stix || !stix->_nil_object || + if (!stix->_apex || !stix->_undefined_object || !stix->_object || !stix->_string || !stix->_symbol || !stix->_array || !stix->_byte_array || !stix->_symbol_set || !stix->_system_dictionary || - !stix->_namespace || !stix->_method_dictionary || - !stix->_method || !stix->_association || !stix->_method_context || + !stix->_namespace || !stix->_pool_dictionary || + !stix->_method_dictionary || !stix->_method || !stix->_association || - !stix->_block_context || !stix->_true_class || - !stix->_false_class || !stix->_character || !stix->_small_integer) return -1; - - STIX_OBJ_SET_CLASS (stix->_nil, stix->_nil_object); + !stix->_method_context || !stix->_block_context || + !stix->_true_class || !stix->_false_class || + !stix->_character || !stix->_small_integer) return -1; + + STIX_OBJ_SET_CLASS (stix->_nil, stix->_undefined_object); return 0; } @@ -187,7 +189,7 @@ static int ignite_2 (stix_t* stix) stix->sysdic = (stix_oop_set_t)tmp; /* Export the system dictionary via the first class variable of the Stix class */ - ((stix_oop_class_t)stix->_stix)->slot[0] = (stix_oop_t)stix->sysdic; + ((stix_oop_class_t)stix->_apex)->slot[0] = (stix_oop_t)stix->sysdic; return 0; } @@ -201,8 +203,8 @@ static int ignite_3 (stix_t* stix) stix_oow_t len; stix_uch_t str[16]; } symnames[] = { - { 4, { 'S','t','i','x' } }, - { 9, { 'N','i','l','O','b','j','e','c','t' } }, + { 4, { 'A','p','e','x' } }, + { 15, { 'U','n','d','e','f','i','n','e','d','O','b','j','e','c','t' } }, { 5, { 'C','l','a','s','s' } }, { 6, { 'O','b','j','e','c','t' } }, { 6, { 'S','t','r','i','n','g' } }, @@ -214,11 +216,12 @@ static int ignite_3 (stix_t* stix) { 16, { 'S','y','s','t','e','m','D','i','c','t','i','o','n','a','r','y' } }, { 9, { 'N','a','m','e','s','p','a','c','e' } }, + { 14, { 'P','o','o','l','D','i','c','t','i','o','n','a','r','y' } }, { 16, { 'M','e','t','h','o','d','D','i','c','t','i','o','n','a','r','y' } }, { 14, { 'C','o','m','p','i','l','e','d','M','e','t','h','o','d' } }, { 11, { 'A','s','s','o','c','i','a','t','i','o','n' } }, - { 13, { 'M','e','t','h','o','d','C','o','n','t','e','x','t' } }, + { 13, { 'M','e','t','h','o','d','C','o','n','t','e','x','t' } }, { 12, { 'B','l','o','c','k','C','o','n','t','e','x','t' } }, { 4, { 'T','r','u','e' } }, { 5, { 'F','a','l','s','e' } }, @@ -226,16 +229,17 @@ static int ignite_3 (stix_t* stix) { 12, { 'S','m','a','l','l','I','n','t','e','g','e','r' } } }; - static stix_uch_t stix_str[] = { 'S','t','a','x' }; + static stix_uch_t str_stix[] = { 'S','t','i','x' }; stix_oow_t i; stix_oop_t sym; stix_oop_t* stix_ptr; - stix_ptr = &stix->_stix; - /* The loop here repies on the proper order of fields in stix_t. - * Be sure to keep in sync the order of items in symnames and - * the releated fields of stix_t */ + stix_ptr = &stix->_apex; + /* [NOTE] + * The loop here repies on the proper order of fields in stix_t. + * Be sure to keep in sync the order of items in symnames and + * the releated fields of stix_t */ for (i = 0; i < STIX_COUNTOF(symnames); i++) { sym = stix_makesymbol (stix, symnames[i].str, symnames[i].len); @@ -245,7 +249,7 @@ static int ignite_3 (stix_t* stix) stix_ptr++; } - sym = stix_makesymbol (stix, stix_str, 4); + sym = stix_makesymbol (stix, str_stix, 4); if (!sym) return -1; if (!stix_putatsysdic(stix, sym, (stix_oop_t)stix->sysdic)) return -1; diff --git a/stix/lib/main.c b/stix/lib/main.c index 5d3c0a1..78221f6 100644 --- a/stix/lib/main.c +++ b/stix/lib/main.c @@ -189,6 +189,7 @@ static char* syntax_error_msg[] = ". expected", "| expected", "> expected", + ":= expected", "identifier expected", "integer expected", "primitive: expected", @@ -215,7 +216,9 @@ static char* syntax_error_msg[] = "too large block", "wrong primitive number", "#include error", - "wrong namespace name" + "wrong namespace name", + "duplicate pool dictionary name", + "literal expected" }; stix_uch_t str_stix[] = { 'S', 't', 'i', 'x' }; diff --git a/stix/lib/stix-prv.h b/stix/lib/stix-prv.h index 5288c87..a3df929 100644 --- a/stix/lib/stix-prv.h +++ b/stix/lib/stix-prv.h @@ -303,6 +303,7 @@ enum stix_synerrnum_t STIX_SYNERR_PERIOD, /* . expected */ STIX_SYNERR_VBAR, /* | expected */ STIX_SYNERR_GT, /* > expected */ + STIX_SYNERR_ASSIGN, /* := expected */ STIX_SYNERR_IDENT, /* identifier expected */ STIX_SYNERR_INTEGER, /* integer expected */ STIX_SYNERR_PRIMITIVE, /* primitive: expected */ @@ -329,7 +330,9 @@ enum stix_synerrnum_t STIX_SYNERR_BLKFLOOD, /* too large block */ STIX_SYNERR_PRIMNO, /* wrong primitive number */ STIX_SYNERR_INCLUDE, /* #include error */ - STIX_SYNERR_NAMESPACE /* wrong namespace name */ + STIX_SYNERR_NAMESPACE, /* wrong namespace name */ + STIX_SYNERR_POOLDICDUP, /* duplicate pool dictionary */ + STIX_SYNERR_LITERAL /* literal expected */ }; typedef enum stix_synerrnum_t stix_synerrnum_t; diff --git a/stix/lib/stix.h b/stix/lib/stix.h index e9afc46..190b2e3 100644 --- a/stix/lib/stix.h +++ b/stix/lib/stix.h @@ -762,8 +762,8 @@ struct stix_t /* == NEVER CHANGE THE ORDER OF FIELDS BELOW == */ /* stix_ignite() assumes this order. make sure to update symnames in ignite_3() */ - stix_oop_t _stix; /* Stix */ - stix_oop_t _nil_object; /* NilObject */ + stix_oop_t _apex; /* Apex */ + stix_oop_t _undefined_object; /* UndefinedObject */ stix_oop_t _class; /* Class */ stix_oop_t _object; /* Object */ stix_oop_t _string; /* String */ @@ -775,15 +775,17 @@ struct stix_t stix_oop_t _system_dictionary; /* SystemDictionary */ stix_oop_t _namespace; /* Namespace */ + stix_oop_t _pool_dictionary; /* PoolDictionary */ stix_oop_t _method_dictionary; /* MethodDictionary */ stix_oop_t _method; /* CompiledMethod */ stix_oop_t _association; /* Association */ - stix_oop_t _method_context; /* MethodContext */ + stix_oop_t _method_context; /* MethodContext */ stix_oop_t _block_context; /* BlockContext */ stix_oop_t _true_class; /* True */ stix_oop_t _false_class; /* False */ stix_oop_t _character; /* Character */ + stix_oop_t _small_integer; /* SmallInteger */ /* == NEVER CHANGE THE ORDER OF FIELDS ABOVE == */ diff --git a/stix/lib/test-005.st b/stix/lib/test-005.st index 80da876..36611c9 100644 --- a/stix/lib/test-005.st +++ b/stix/lib/test-005.st @@ -9,7 +9,7 @@ ## use #extend to extend a class ## using #class for both feels confusing. -#extend Stix +#extend Apex { }