typegraph/scripts/blocks/createTypeInstance.gml

37 lines
808 B
Plaintext
Raw Permalink Normal View History

///createTypeInstance(con)
/**
* createTypeInstance :: TypeConLink -> TypeConInstance
*
* Creates a visual type instance for a type.
*
* @param con the type for which to make a type instance
* @returns a type instance
*/
var con = argument0;
assertInstanceof(con, TypeConLink);
var inst;
if (instanceof(con, TypeCon1Link)) {
inst = new(con.type.instance);
inst.parameter = con.type;
var traits = con.type.traits;
for (var trait = ds_set_first(traits); ds_set_exists(traits, trait); trait = ds_set_next(traits, trait)) {
var traitInst = new(TraitInstance);
traitInst.parameter = trait;
addChild(inst, traitInst);
}
}
else {
inst = new(TypeConInstance);
for (var i = 0; i < ds_list_size(con.to); i++)
addChild(inst, createTypeInstance(con.to[|i]));
}
return inst;