typegraph/scripts/typing/copyType.gml

39 lines
873 B
Plaintext
Raw Normal View History

///copyType(id)
/**
* copyType :: Type -> Type
*
* Returns a deep copy of the given type instance.
*
* @param id the type to copy
*/
assert(false, "deprecated");
var orig = argument0;
var copy = new(orig.object_index);
for (var trait = ds_set_first(orig.traits); ds_set_exists(orig.traits, trait); trait = ds_set_next(orig.traits, trait)) {
var newTrait = new(trait.object_index);
newTrait.parameter = trait.parameter;
ds_set_add(copy.traits, newTrait);
addChild(copy, newTrait);
}
if (instanceof(orig, ParametricType))
setParameter(copy, orig.parameter);
if (instanceof(orig, UnaryType)) {
copy.first = copyType(orig.first);
addChild(copy, copy.first);
}
if (instanceof(orig, BinaryType)) {
copy.first = copyType(orig.first);
copy.second = copyType(orig.second);
addChild(copy, copy.first);
addChild(copy, copy.second);
}
return copy;