reorganized the compiler code by moving the method data into the cunit_class

This commit is contained in:
hyunghwan.chung 2018-10-05 16:25:17 +00:00
parent e6fca77adf
commit 079f2d3f4a
4 changed files with 506 additions and 595 deletions

View File

@ -168,6 +168,21 @@ difficulty: how to ensure that the class implements the defined interface?
method shoutWith: number {} method shoutWith: number {}
} }
<<swift>>
protocol StringConvertible {
func toString() -> String
}
extension String: StringConvertible {
func toString() -> String {
return self
}
}
<<end swift>>
4) other methods??? 4) other methods???
Let me think about it.. Let me think about it..

File diff suppressed because it is too large Load Diff

View File

@ -473,8 +473,7 @@ enum moo_cunit_type_t
{ {
MOO_CUNIT_BLANK = 0, MOO_CUNIT_BLANK = 0,
MOO_CUNIT_CLASS, MOO_CUNIT_CLASS,
MOO_CUNIT_POOLDIC, MOO_CUNIT_POOLDIC
MOO_CUNIT_METHOD
}; };
typedef enum moo_cunit_type_t moo_cunit_type_t; typedef enum moo_cunit_type_t moo_cunit_type_t;
@ -505,66 +504,9 @@ struct moo_cunit_pooldic_t
moo_oow_t end; moo_oow_t end;
}; };
typedef struct moo_pooldic_import_data_t moo_pooldic_import_data_t;
typedef struct moo_cunit_class_t moo_cunit_class_t; struct moo_pooldic_import_data_t
struct moo_cunit_class_t
{ {
MOO_CUNIT_HEADER;
int flags;
int indexed_type;
/* fixed instance size specified for a non-pointer class. class(#byte(N)), etc */
moo_oow_t non_pointer_instsize;
moo_oop_class_t self_oop;
moo_oop_t super_oop; /* this may be nil. so the type is moo_oop_t */
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_nsdic_t superns_oop;
moo_oocs_t superfqn;
moo_oocs_t supername;
moo_oow_t superfqn_capa;
moo_ioloc_t superfqn_loc;
moo_oocs_t modname; /* module name after 'from' */
moo_oow_t modname_capa;
moo_ioloc_t modname_loc;
/* instance variable, class variable, class instance variable, constant
* var[0] - named instance variables
* var[1] - class instance variables
* var[2] - class variables
*/
struct
{
moo_oocs_t str; /* long string containing all variables declared delimited by a space */
moo_oow_t str_capa;
moo_oow_t count; /* the number of variables declared in this class only */
moo_oow_t total_count; /* the number of variables declared in this class and superclasses */
moo_initv_t* initv;
moo_oow_t initv_capa;
/* initv_count holds the index to the last variable with a
* default initial value defined in this class only plus one.
* inheritance is handled by the compiler separately using
* the reference to the superclass. so it doesn't include
* the variables defined in the superclass chain.
* for a definition: class ... { var a, b := 0, c },
* initv_count is set to 2 while count is 3. totoal_count
* will be 3 too if there is no variabled defined in the
* superclass chain. */
moo_oow_t initv_count;
} var[3];
/* buffer to hold pooldic import declaration */
struct
{
moo_oocs_t dcl; moo_oocs_t dcl;
moo_oow_t dcl_capa; moo_oow_t dcl_capa;
moo_oow_t dcl_count; moo_oow_t dcl_count;
@ -572,15 +514,11 @@ struct moo_cunit_class_t
/* used to hold imported pool dictionarie objects */ /* used to hold imported pool dictionarie objects */
moo_oop_dic_t* oops; moo_oop_dic_t* oops;
moo_oow_t oops_capa; moo_oow_t oops_capa;
} pooldic_imp;
}; };
typedef struct moo_method_data_t moo_method_data_t;
typedef struct moo_cunit_method_t moo_cunit_method_t; struct moo_method_data_t
struct moo_cunit_method_t
{ {
MOO_CUNIT_HEADER;
int active; int active;
moo_method_type_t type; moo_method_type_t type;
@ -638,6 +576,66 @@ struct moo_cunit_method_t
moo_oow_t code_capa; moo_oow_t code_capa;
}; };
typedef struct moo_cunit_class_t moo_cunit_class_t;
struct moo_cunit_class_t
{
MOO_CUNIT_HEADER;
int flags;
int indexed_type;
/* fixed instance size specified for a non-pointer class. class(#byte(N)), etc */
moo_oow_t non_pointer_instsize;
moo_oop_class_t self_oop;
moo_oop_t super_oop; /* this may be nil. so the type is moo_oop_t */
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_nsdic_t superns_oop;
moo_oocs_t superfqn;
moo_oocs_t supername;
moo_oow_t superfqn_capa;
moo_ioloc_t superfqn_loc;
moo_oocs_t modname; /* module name after 'from' */
moo_oow_t modname_capa;
moo_ioloc_t modname_loc;
/* instance variable, class variable, class instance variable, constant
* var[0] - named instance variables
* var[1] - class instance variables
* var[2] - class variables
*/
struct
{
moo_oocs_t str; /* long string containing all variables declared delimited by a space */
moo_oow_t str_capa;
moo_oow_t count; /* the number of variables declared in this class only */
moo_oow_t total_count; /* the number of variables declared in this class and superclasses */
moo_initv_t* initv;
moo_oow_t initv_capa;
/* initv_count holds the index to the last variable with a
* default initial value defined in this class only plus one.
* inheritance is handled by the compiler separately using
* the reference to the superclass. so it doesn't include
* the variables defined in the superclass chain.
* for a definition: class ... { var a, b := 0, c },
* initv_count is set to 2 while count is 3. totoal_count
* will be 3 too if there is no variabled defined in the
* superclass chain. */
moo_oow_t initv_count;
} var[3];
moo_pooldic_import_data_t pdimp;
moo_method_data_t mth;
};
struct moo_compiler_t struct moo_compiler_t
{ {
int pragma_flags; int pragma_flags;
@ -683,16 +681,10 @@ struct moo_compiler_t
moo_cunit_t* cunit; moo_cunit_t* cunit;
/* inner-most class unit. it may be same as 'cunit' or something up /* inner-most class unit. it may be same as 'cunit' or something up
* the 'cunit->cunit_parent' chain */ * the 'cunit->cunit_parent' chain. i keep these to avoid repeated
* typecasting and assignment to another variable */
moo_cunit_class_t* cclass; moo_cunit_class_t* cclass;
moo_cunit_pooldic_t* cpooldic; moo_cunit_pooldic_t* cpooldic;
/* information about a class being compiled */
//moo_cunit_class_t cls;
/* pooldic declaration */
/*moo_cunit_pooldic_t pooldic;*/
/* information about a method being comipled */
moo_cunit_method_t mth;
}; };
#endif #endif

View File

@ -533,6 +533,19 @@ struct moo_nsdic_t
moo_oop_t nsup; /* a class if it belongs to the class. another nsdic if it doesn't */ moo_oop_t nsup; /* a class if it belongs to the class. another nsdic if it doesn't */
}; };
struct moo_interface_t
{
MOO_OBJ_HEADER;
moo_oop_char_t name;
/* [0] - instance methods, MethodDictionary
* [1] - class methods, MethodDictionary */
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 */
};
struct moo_class_t struct moo_class_t
{ {
MOO_OBJ_HEADER; MOO_OBJ_HEADER;