def _map_rtn(args, keywords, starargs, context, dryrun, orig_args): assert not keywords assert not starargs f = args[0] elts = [] for a in args[1:]: elts.append(get_iter_type(a, context)) r = context.get_cached(_map_rtn) if not r: r = InstanceType(ListClass, [Union.EMPTY]) context.set_cached(_map_rtn, r) u = f.call(elts, {}, None, context, dryrun, orig_args) r.update(0, u) return Union(r)
def _filter_rtn(args, keywords, starargs, context, dryrun, orig_args): assert not keywords assert not starargs assert len(args) == 2 f = args[0] r = context.get_cached(_filter_rtn) if not r: r = InstanceType(ListClass, [Union.EMPTY]) context.set_cached(_filter_rtn, r) rtn = [] for t in args[1].types(): elt_type = get_iter_type(Union(t), context) if f != Union(NONE): f.call([elt_type], {}, None, context, dryrun, orig_args) if t is STR: rtn.append(Union(STR)) else: r.update(0, elt_type) rtn.append(Union(r)) return Union.make_union(*rtn)
return Union.EMPTY if not isinstance(t2, InstanceType) or not t1.cls is TupleClass: context.log_error("wtf") return Union.EMPTY t = context.get_cached("__add__") n1 = len(t1.unions) n2 = len(t2.unions) if t is None: t = InstanceType(TupleClass, [Union.EMPTY for i in xrange(n1 + n2)]) context.set_cached("__add__", t) if len(t.unions) != n1 + n2: print >>sys.stderr, "WTF" return Union.EMPTY for i in xrange(n1): t.update(i, t1.unions[i]) for i in xrange(n2): t.update(n1 + i, t2.unions[i]) return Union(t) TupleClass.setattr("__add__", Union(SpecialFunction(tuple_add))) TupleClass.setattr("__lt__", Union(TOP)) # TODO not the right definition BUILTINS = {} BUILTINS['__name__'] = BUILTINS['__file__'] = Union(STR) BUILTINS['object'] = Union(ObjectClass) BUILTINS['type'] = Union(TypeClass) BUILTINS['list'] = Union(ListClass)
return Union.EMPTY if not isinstance(t2, InstanceType) or not t1.cls is TupleClass: context.log_error("wtf") return Union.EMPTY t = context.get_cached("__add__") n1 = len(t1.unions) n2 = len(t2.unions) if t is None: t = InstanceType(TupleClass, [Union.EMPTY for i in xrange(n1 + n2)]) context.set_cached("__add__", t) if len(t.unions) != n1 + n2: print >> sys.stderr, "WTF" return Union.EMPTY for i in xrange(n1): t.update(i, t1.unions[i]) for i in xrange(n2): t.update(n1 + i, t2.unions[i]) return Union(t) TupleClass.setattr("__add__", Union(SpecialFunction(tuple_add))) TupleClass.setattr("__lt__", Union(TOP)) # TODO not the right definition BUILTINS = {} BUILTINS['__name__'] = BUILTINS['__file__'] = Union(STR) BUILTINS['object'] = Union(ObjectClass) BUILTINS['type'] = Union(TypeClass) BUILTINS['list'] = Union(ListClass)