Beispiel #1
0
    def gendirectcall(self, ll_function, *args_v):
        rtyper = self.rtyper
        args_s = []
        newargs_v = []
        for v in args_v:
            if v.concretetype is Void:
                s_value = rtyper.binding(v, default=annmodel.s_None)
                if not s_value.is_constant():
                    raise TyperError("non-constant variable of type Void")
                if not isinstance(s_value, annmodel.SomePBC):
                    raise TyperError("non-PBC Void argument: %r", (s_value,))
                args_s.append(s_value)
            else:
                args_s.append(annmodel.lltype_to_annotation(v.concretetype))
            newargs_v.append(v)
        
        self.rtyper.call_all_setups()  # compute ForwardReferences now

        # hack for bound methods
        if hasattr(ll_function, 'im_func'):
            bk = rtyper.annotator.bookkeeper
            args_s.insert(0, bk.immutablevalue(ll_function.im_self))
            newargs_v.insert(0, inputconst(Void, ll_function.im_self))
            ll_function = ll_function.im_func

        graph = annotate_lowlevel_helper(rtyper.annotator, ll_function, args_s,
                                         rtyper.lowlevel_ann_policy)
        self.record_extra_call(graph)

        # build the 'direct_call' operation
        f = self.rtyper.getcallable(graph)
        c = inputconst(typeOf(f), f)
        fobj = self.rtyper.type_system_deref(f)
        return self.genop('direct_call', [c]+newargs_v,
                          resulttype = typeOf(fobj).RESULT)
Beispiel #2
0
    def gendirectcall(self, ll_function, *args_v):
        rtyper = self.rtyper
        args_s = []
        newargs_v = []
        for v in args_v:
            if v.concretetype is Void:
                s_value = rtyper.binding(v, default=annmodel.s_None)
                if not s_value.is_constant():
                    raise TyperError("non-constant variable of type Void")
                if not isinstance(s_value, annmodel.SomePBC):
                    raise TyperError("non-PBC Void argument: %r", (s_value, ))
                args_s.append(s_value)
            else:
                args_s.append(annmodel.lltype_to_annotation(v.concretetype))
            newargs_v.append(v)

        self.rtyper.call_all_setups()  # compute ForwardReferences now

        # hack for bound methods
        if hasattr(ll_function, 'im_func'):
            bk = rtyper.annotator.bookkeeper
            args_s.insert(0, bk.immutablevalue(ll_function.im_self))
            newargs_v.insert(0, inputconst(Void, ll_function.im_self))
            ll_function = ll_function.im_func

        graph = annotate_lowlevel_helper(rtyper.annotator, ll_function, args_s,
                                         rtyper.lowlevel_ann_policy)
        self.record_extra_call(graph)

        # build the 'direct_call' operation
        f = self.rtyper.getcallable(graph)
        c = inputconst(typeOf(f), f)
        fobj = self.rtyper.type_system_deref(f)
        return self.genop('direct_call', [c] + newargs_v,
                          resulttype=typeOf(fobj).RESULT)
Beispiel #3
0
def ll_rtype(llfn, argtypes=[]):
    a = RPythonAnnotator()
    graph = annotate_lowlevel_helper(a, llfn, argtypes)
    s = a.binding(graph.getreturnvar())
    t = a.translator
    typer = RPythonTyper(a)
    typer.specialize()
    #t.view()
    t.checkgraphs()
    return s, t
Beispiel #4
0
def ll_rtype(llfn, argtypes=[]):
    a = RPythonAnnotator()
    graph = annotate_lowlevel_helper(a, llfn, argtypes)
    s = a.binding(graph.getreturnvar())
    t = a.translator
    typer = RPythonTyper(a)
    typer.specialize()
    #t.view()
    t.checkgraphs()
    return s, t
Beispiel #5
0
 def annotate_helper(self, ll_function, argtypes):
     """Annotate the given low-level helper function and return its graph
     """
     args_s = []
     for s in argtypes:
         # assume 's' is a low-level type, unless it is already an annotation
         if not isinstance(s, annmodel.SomeObject):
             s = annmodel.lltype_to_annotation(s)
         args_s.append(s)
     # hack for bound methods
     if hasattr(ll_function, 'im_func'):
         bk = self.annotator.bookkeeper
         args_s.insert(0, bk.immutablevalue(ll_function.im_self))
         ll_function = ll_function.im_func
     helper_graph = annotate_lowlevel_helper(self.annotator,
                                             ll_function, args_s,
                                             policy=self.lowlevel_ann_policy)
     return helper_graph
Beispiel #6
0
 def annotate_helper(self, ll_function, argtypes):
     """Annotate the given low-level helper function and return its graph
     """
     args_s = []
     for s in argtypes:
         # assume 's' is a low-level type, unless it is already an annotation
         if not isinstance(s, annmodel.SomeObject):
             s = annmodel.lltype_to_annotation(s)
         args_s.append(s)
     # hack for bound methods
     if hasattr(ll_function, 'im_func'):
         bk = self.annotator.bookkeeper
         args_s.insert(0, bk.immutablevalue(ll_function.im_self))
         ll_function = ll_function.im_func
     helper_graph = annotate_lowlevel_helper(
         self.annotator,
         ll_function,
         args_s,
         policy=self.lowlevel_ann_policy)
     return helper_graph
Beispiel #7
0
 def annotate(self, ll_function, argtypes):
     self.a = self.RPythonAnnotator()
     graph = annotate_lowlevel_helper(self.a, ll_function, argtypes)
     if option.view:
         self.a.translator.view()
     return self.a.binding(graph.getreturnvar())
Beispiel #8
0
 def annotate(self, ll_function, argtypes):
     self.a = self.RPythonAnnotator()
     graph = annotate_lowlevel_helper(self.a, ll_function, argtypes)
     if option.view:
         self.a.translator.view()
     return self.a.binding(graph.getreturnvar())