Example #1
0
 def lowlevelspecialize(funcdesc, args_s, key_for_args):
     args_s, key1, builder = flatten_star_args(funcdesc, args_s)
     key = []
     new_args_s = []
     for i, s_obj in enumerate(args_s):
         if i in key_for_args:
             key.append(key_for_args[i])
             new_args_s.append(s_obj)
         elif isinstance(s_obj, annmodel.SomePBC):
             assert s_obj.is_constant(
             ), "ambiguous low-level helper specialization"
             key.append(KeyComp(s_obj.const))
             new_args_s.append(s_obj)
         elif isinstance(s_obj, annmodel.SomeNone):
             key.append(KeyComp(None))
             new_args_s.append(s_obj)
         else:
             new_args_s.append(annmodel.not_const(s_obj))
             try:
                 key.append(annotation_to_lltype(s_obj))
             except ValueError:
                 # passing non-low-level types to a ll_* function is allowed
                 # for module/ll_*
                 key.append(s_obj.__class__)
     key = (tuple(key), )
     if key1 is not None:
         key += (key1, )
     flowgraph = funcdesc.cachedgraph(key, builder=builder)
     args_s[:] = new_args_s
     return flowgraph
Example #2
0
 def lowlevelspecialize(funcdesc, args_s, key_for_args):
     args_s, key1, builder = flatten_star_args(funcdesc, args_s)
     key = []
     new_args_s = []
     for i, s_obj in enumerate(args_s):
         if i in key_for_args:
             key.append(key_for_args[i])
             new_args_s.append(s_obj)
         elif isinstance(s_obj, annmodel.SomePBC):
             assert s_obj.is_constant(), "ambiguous low-level helper specialization"
             key.append(KeyComp(s_obj.const))
             new_args_s.append(s_obj)
         else:
             new_args_s.append(annmodel.not_const(s_obj))
             try:
                 key.append(annotation_to_lltype(s_obj))
             except ValueError:
                 # passing non-low-level types to a ll_* function is allowed
                 # for module/ll_*
                 key.append(s_obj.__class__)
     key = (tuple(key),)
     if key1 is not None:
         key += (key1,)
     flowgraph = funcdesc.cachedgraph(key, builder=builder)
     args_s[:] = new_args_s
     return flowgraph
Example #3
0
def test_annotation_to_lltype():
    s_i = SomeInteger()
    s_pos = SomeInteger(nonneg=True)
    s_1 = SomeInteger(nonneg=True)
    s_1.const = 1
    s_m1 = SomeInteger(nonneg=False)
    s_m1.const = -1
    s_u = SomeInteger(nonneg=True, unsigned=True)
    s_u1 = SomeInteger(nonneg=True, unsigned=True)
    s_u1.const = r_uint(1)
    assert annotation_to_lltype(s_i) == lltype.Signed
    assert annotation_to_lltype(s_pos) == lltype.Signed
    assert annotation_to_lltype(s_1) == lltype.Signed
    assert annotation_to_lltype(s_m1) == lltype.Signed
    assert annotation_to_lltype(s_u) == lltype.Unsigned
    assert annotation_to_lltype(s_u1) == lltype.Unsigned
    assert annotation_to_lltype(SomeBool()) == lltype.Bool
    assert annotation_to_lltype(SomeChar()) == lltype.Char
    PS = lltype.Ptr(lltype.GcStruct('s'))
    s_p = SomePtr(ll_ptrtype=PS)
    assert annotation_to_lltype(s_p) == PS
    si0 = SomeInstance(DummyClassDef(), True)
    with py.test.raises(ValueError):
        annotation_to_lltype(si0)
    s_singlefloat = SomeSingleFloat()
    s_singlefloat.const = r_singlefloat(0.0)
    assert annotation_to_lltype(s_singlefloat) == lltype.SingleFloat
Example #4
0
 def specialize__genconst(pol, funcdesc, args_s, i):
     # XXX this is specific to the JIT
     TYPE = annotation_to_lltype(args_s[i], 'genconst')
     args_s[i] = lltype_to_annotation(TYPE)
     alt_name = funcdesc.name + "__%s" % (TYPE._short_name(),)
     return funcdesc.cachedgraph(TYPE, alt_name=valid_identifier(alt_name))
Example #5
0
def test_annotation_to_lltype():
    s_i = SomeInteger()
    s_pos = SomeInteger(nonneg=True)
    s_1 = SomeInteger(nonneg=True)
    s_1.const = 1
    s_m1 = SomeInteger(nonneg=False)
    s_m1.const = -1
    s_u = SomeInteger(nonneg=True, unsigned=True)
    s_u1 = SomeInteger(nonneg=True, unsigned=True)
    s_u1.const = r_uint(1)
    assert annotation_to_lltype(s_i) == lltype.Signed
    assert annotation_to_lltype(s_pos) == lltype.Signed
    assert annotation_to_lltype(s_1) == lltype.Signed
    assert annotation_to_lltype(s_m1) == lltype.Signed
    assert annotation_to_lltype(s_u) == lltype.Unsigned
    assert annotation_to_lltype(s_u1) == lltype.Unsigned
    assert annotation_to_lltype(SomeBool()) == lltype.Bool
    assert annotation_to_lltype(SomeChar()) == lltype.Char
    PS = lltype.Ptr(lltype.GcStruct('s'))
    s_p = SomePtr(ll_ptrtype=PS)
    assert annotation_to_lltype(s_p) == PS
    si0 = SomeInstance(DummyClassDef(), True)
    with py.test.raises(ValueError):
        annotation_to_lltype(si0)
    s_singlefloat = SomeSingleFloat()
    s_singlefloat.const = r_singlefloat(0.0)
    assert annotation_to_lltype(s_singlefloat) == lltype.SingleFloat
Example #6
0
 def specialize__genconst(self, funcdesc, args_s, i):
     # XXX this is specific to the JIT
     TYPE = annotation_to_lltype(args_s[i], 'genconst')
     args_s[i] = lltype_to_annotation(TYPE)
     alt_name = funcdesc.name + "__%s" % (TYPE._short_name(), )
     return funcdesc.cachedgraph(TYPE, alt_name=valid_identifier(alt_name))
Example #7
0
def cast_primitive(T, s_v):
    assert T.is_constant()
    return ll_to_annotation(lltype.cast_primitive(T.const, annotation_to_lltype(s_v)._defl()))
Example #8
0
def typeOf(s_val):
    lltype = annotation_to_lltype(s_val, info="in typeOf(): ")
    return immutablevalue(lltype)