/* This...is called to 'fix' how many generics are available in the current class. As a 'neat' side-effect, it also sets how many generics that 'decl_class' has. */ void lily_update_symtab_generics(lily_symtab *symtab, int count) { /* The symtab special cases all types holding generic information so that they're unique, together, and in numerical order. */ lily_type *type_iter = symtab->generic_class->all_subtypes; int i = 1; while (count) { type_iter->flags &= ~TYPE_HIDDEN_GENERIC; count--; if (type_iter->next == NULL && count) { lily_type *new_type = make_new_type(symtab->generic_class); new_type->flags = TYPE_IS_UNRESOLVED; new_type->generic_pos = i; /* It's much easier if generics are linked so that the higher number ones come further on. (A => B => C) instead of having the newest one be at the front. In fact, a couple of other modules poke the generics directly and rely on this ordering. */ type_iter->next = new_type; } i++; type_iter = type_iter->next; } while (type_iter) { type_iter->flags |= TYPE_HIDDEN_GENERIC; type_iter = type_iter->next; } }
/* This creates a new class based off of a given seed. The name is copied over from the seed given. If the given class does not take generics, this will also set the default type of the newly-made class. */ lily_class *lily_new_class_by_seed(lily_symtab *symtab, const void *seed) { lily_class_seed *class_seed = (lily_class_seed *)seed; lily_class *new_class = lily_new_class(symtab, class_seed->name); lily_type *type; /* If a class doesn't take generics (or isn't the generic class), then give it a default type. */ if (class_seed->generic_count != 0) type = NULL; else { /* A basic class? Make a quick default type for it. */ type = make_new_type(new_class); new_class->type = type; new_class->all_subtypes = type; } new_class->type = type; new_class->is_builtin = 1; new_class->generic_count = class_seed->generic_count; new_class->flags = 0; new_class->is_refcounted = class_seed->is_refcounted; new_class->import = symtab->active_import; new_class->dynaload_table = class_seed->dynaload_table; return new_class; }