Пример #1
0
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)
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
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)
Пример #5
0
        context.log_error("wtf")
        return Union.EMPTY
    t1 = args[0].types()[0]
    t2 = args[1].types()[0]
    if not isinstance(t1, InstanceType) or not t1.cls is TupleClass:
        context.log_error("wtf")
        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 = {}
Пример #6
0
        context.log_error("wtf")
        return Union.EMPTY
    t1 = args[0].types()[0]
    t2 = args[1].types()[0]
    if not isinstance(t1, InstanceType) or not t1.cls is TupleClass:
        context.log_error("wtf")
        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 = {}