Re-factoring MotoType

David Hakim <dhakim-Gkm/TONP9n1Wk0Htik3J/[email protected]> Mon, 10 Feb 2003 18:51:12 -0500
Newsgroups gmane.comp.lang.moto.devel
Message-ID <[email protected]>
	I've embarked on fairly major re-factoring to MotoType and type 
related functions. I need to do this for work I'll be beginning shortly 
on Higher Order Functions. This re-factor will likely be helpful for 
the work that will begin soon on inheritance as well. The key idea 
behind the re-factoring is that of 'dynamically defined types'. These 
are a bit more dynamic than just being able to define new classes in 
your moto pages. Rather it is a way of telling the type system that if

X is an allowed type than X() is an allowed type (in this case the new 
type is a 'function that returns type X and takes no arguments)

The dynamic typing rules for higher order functions will amount to:

if X is a type than X() is a type
if X and Y are types than X(Y) is a type
if X is a type and Z is a comma delimited list of types than X(Z) is a 
type

There is already an example of this sort of dynamic typing done in the 
code base for arrays:

if X is a type than X[] is a type

But the implementation is all wrong. We currently store the dimension 
and subtype with the MotoVals and MotoVars as opposed to recognizing 
these constructions as true MotoTypes. I am fixing this now.

The new definition for MotoType that I have in mind looks like :

typedef struct motoType {
    TypeKind kind;
    char *name; // The canonical, human readable type name e.g. "int", 
"int[]", "int(String)"
    struct motoType *atype;	// The ancestor type used for derived types 
such as Arrays or HOF types
    					// 	If this is an HOF type than the atype is the return type
    					// 	If this is an Array type than the atype is the type of 
Object the array stores
    int dim;	// The dimension (used for Array types)
    int argc;	 // The number of type arguments for this type (used for 
HOFs)
    struct motoType *argt; // The argument types (used for HOFs)
    char isExternallyDefined;
} MotoType;

When someone tries to getType() on a dynamically defineable moto type 
if it is not already in the type system it will be added.

-Dave