Exemplo n.º 1
0
def inputconst(reqtype, value):
    """Return a Constant with the given value, of the requested type,
    which can be a Repr instance or a low-level type.
    """
    if isinstance(reqtype, Repr):
        value = reqtype.convert_const(value)
        lltype = reqtype.lowleveltype
    elif isinstance(reqtype, LowLevelType):
        lltype = reqtype
    else:
        raise TypeError(repr(reqtype))
    # Void Constants can hold any value;
    # non-Void Constants must hold a correctly ll-typed value
    if lltype is not Void:
        try:
            realtype = typeOf(value)
        except (AssertionError, AttributeError):
            realtype = '???'
        if not isCompatibleType(realtype, lltype):
            raise TyperError("inputconst(reqtype = %s, value = %s):\n"
                             "expected a %r,\n"
                             "     got a %r" % (reqtype, value,
                                                lltype, realtype))
    c = Constant(value)
    c.concretetype = lltype
    return c
Exemplo n.º 2
0
 def perform_call(self, f, ARGS, args):
     fobj = self.llinterpreter.typer.type_system.deref(f)
     has_callable = getattr(fobj, '_callable', None) is not None
     if hasattr(fobj, 'graph'):
         graph = fobj.graph
     else:
         assert has_callable, "don't know how to execute %r" % f
         return self.invoke_callable_with_pyexceptions(f, *args)
     args_v = graph.getargs()
     if len(ARGS) != len(args_v):
         raise TypeError("graph with %d args called with wrong func ptr type: %r" %(len(args_v), ARGS))
     for T, v in zip(ARGS, args_v):
         if not lltype.isCompatibleType(T, v.concretetype):
             raise TypeError("graph with %r args called with wrong func ptr type: %r" %
                             (tuple([v.concretetype for v in args_v]), ARGS))
     frame = self.newsubframe(graph, args)
     return frame.eval()