File: support.py

package info (click to toggle)
pypy 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 107,216 kB
  • sloc: python: 1,201,787; ansic: 62,419; asm: 5,169; cpp: 3,017; sh: 2,534; makefile: 545; xml: 243; lisp: 45; awk: 4
file content (55 lines) | stat: -rw-r--r-- 2,214 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from rpython.rtyper.llinterp import LLInterpreter
from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.rtyper.extregistry import ExtRegistryEntry

def maybe_on_top_of_llinterp(rtyper, fnptr):
    # Run a generated graph on top of the llinterp for testing.
    # When translated, this just returns the fnptr.
    def process_args(args):
        real_args = []
        ARGS = lltype.typeOf(funcobj).ARGS
        i = 0
        for ARG in ARGS:
            if ARG is lltype.Void:
                real_args.append(None)
            else:
                if ARG is lltype.Float:
                    real_args.append(args[i])
                elif isinstance(ARG, lltype.Primitive):
                    real_args.append(lltype.cast_primitive(ARG, args[i]))
                elif isinstance(ARG, lltype.Ptr):
                    if ARG.TO._gckind == 'gc':
                        real_args.append(lltype.cast_opaque_ptr(ARG, args[i]))
                    else:
                        real_args.append(rffi.cast(ARG, args[i]))
                else:
                    raise Exception("Unexpected arg: %s" % ARG)
                i += 1
        return real_args

    funcobj = fnptr._obj
    if hasattr(funcobj, 'graph'):
        # cache the llinterp; otherwise the remember_malloc/remember_free
        # done on the LLInterpreter don't match
        try:
            llinterp = rtyper._on_top_of_llinterp_llinterp
        except AttributeError:
            llinterp = LLInterpreter(rtyper)  #, exc_data_ptr=exc_data_ptr)
            rtyper._on_top_of_llinterp_llinterp = llinterp
        def on_top_of_llinterp(*args):
            real_args = process_args(args)
            return llinterp.eval_graph(funcobj.graph, real_args)
    else:
        assert hasattr(funcobj, '_callable')
        def on_top_of_llinterp(*args):
            args = process_args(args)
            return funcobj._callable(*args)
    return on_top_of_llinterp

class Entry(ExtRegistryEntry):
    _about_ = maybe_on_top_of_llinterp
    def compute_result_annotation(self, s_rtyper, s_fnptr):
        return s_fnptr
    def specialize_call(self, hop):
        hop.exception_cannot_occur()
        return hop.inputarg(hop.args_r[1], arg=1)