コード例 #1
0
ファイル: llimpl.py プロジェクト: antoine1fr/pygirl
 def specialize_call(self, hop):
     ARGS = [r.lowleveltype for r in hop.args_r]
     RESULT = hop.r_result.lowleveltype
     if hop.rtyper.type_system.name == 'lltypesystem':
         FUNCTYPE = lltype.FuncType(ARGS, RESULT)
         funcptr = lltype.functionptr(FUNCTYPE, func.__name__,
                                      _callable=func, _debugexc=True)
         cfunc = hop.inputconst(lltype.Ptr(FUNCTYPE), funcptr)
     else:
         FUNCTYPE = ootype.StaticMethod(ARGS, RESULT)
         sm = ootype._static_meth(FUNCTYPE, _name=func.__name__, _callable=func)
         cfunc = hop.inputconst(FUNCTYPE, sm)
     args_v = hop.inputargs(*hop.args_r)
     return hop.genop('direct_call', [cfunc] + args_v, hop.r_result)
コード例 #2
0
 def specialize_call(self, hop):
     ARGS = [r.lowleveltype for r in hop.args_r]
     RESULT = hop.r_result.lowleveltype
     if hop.rtyper.type_system.name == 'lltypesystem':
         FUNCTYPE = lltype.FuncType(ARGS, RESULT)
         funcptr = lltype.functionptr(FUNCTYPE,
                                      func.__name__,
                                      _callable=func,
                                      _debugexc=True)
         cfunc = hop.inputconst(lltype.Ptr(FUNCTYPE), funcptr)
     else:
         FUNCTYPE = ootype.StaticMethod(ARGS, RESULT)
         sm = ootype._static_meth(FUNCTYPE,
                                  _name=func.__name__,
                                  _callable=func)
         cfunc = hop.inputconst(FUNCTYPE, sm)
     args_v = hop.inputargs(*hop.args_r)
     return hop.genop('direct_call', [cfunc] + args_v, hop.r_result)
コード例 #3
0
def _generalcast(T, value):
    if lltype.typeOf(value) == T:
        return value
    elif isinstance(T, lltype.Ptr):
        return lltype.cast_pointer(T, value)
    elif T == llmemory.Address:
        return llmemory.cast_ptr_to_adr(value)
    elif isinstance(T, ootype.StaticMethod):
        fn = value._obj
        return ootype._static_meth(T, graph=fn.graph, _callable=fn._callable)
    else:
        T1 = lltype.typeOf(value)
        if T1 is llmemory.Address:
            value = llmemory.cast_adr_to_int(value)
        elif isinstance(T1, lltype.Ptr):
            value = lltype.cast_ptr_to_int(value)
        else:
            value = value
        return lltype.cast_primitive(T, value)
コード例 #4
0
ファイル: llimpl.py プロジェクト: antoine1fr/pygirl
def _generalcast(T, value):
    if lltype.typeOf(value) == T:
        return value
    elif isinstance(T, lltype.Ptr):
        return lltype.cast_pointer(T, value)
    elif T == llmemory.Address:
        return llmemory.cast_ptr_to_adr(value)
    elif isinstance(T, ootype.StaticMethod):
        fn = value._obj
        return ootype._static_meth(T, graph=fn.graph, _callable=fn._callable)
    else:
        T1 = lltype.typeOf(value)
        if T1 is llmemory.Address:
            value = llmemory.cast_adr_to_int(value)
        elif isinstance(T1, lltype.Ptr):
            value = lltype.cast_ptr_to_int(value)
        else:
            value = value
        return lltype.cast_primitive(T, value)