def compile(pattern, *args, **kwargs):
id, p = repr(pattern) + repr(args), pattern<EOL>if id in _cache and not kwargs:<EOL><INDENT>return _cache[id]<EOL><DEDENT>if isinstance(pattern, basestring):<EOL><INDENT>p = Pattern.fromstring(pattern, *args, **kwargs)<EOL><DEDENT>if isinstance(pattern, regexp):<EOL><INDENT>p = Pattern([Constraint(words=[pattern], taxonomy=kwargs.get("<STR_LIT>", TAXONOMY))], *args, **kwargs)<EOL><DEDENT>if len(_cache) > _CACHE_SIZE:<EOL><INDENT>_cache.clear()<EOL><DEDENT>if isinstance(p, Pattern) and not kwargs:<EOL><INDENT>_cache[id] = p<EOL><DEDENT>if isinstance(p, Pattern):<EOL><INDENT>return p<EOL><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>" % pattern.__class__.__name__)<EOL><DEDENT>
Returns a Pattern from the given string or regular expression.
        Recently compiled patterns are kept in cache
        (if they do not use taxonomies, which are mutable dicts).