Wrapped all global name lookups in typecheck.c into lookup_global_maybe_typecheck.
Freed memory of resolved_funcexpr in some places.
Implemented typechecking of template instatiated defs.