Example #1
0
def topy(obj):
    """The main compiler function - convert a source object to an ast node"""

    # {{{ ln = line number from metadata (also set global \lineno)
    ln = getmeta(obj, 'lineno')
    if ln:
        global lineno
        lineno = ln
    # }}}

    customcompile = getattr(obj, 'pycompile', None)
    if customcompile:
        node = customcompile(*opargs(obj), **opfields(obj))

    elif isinstance(type(obj), OperatorType):
        node = compileOperator(obj)
    else:
        typ = type(obj).__name__
        method = (getattr(objtopy, typ, None) or
                  getattr(objtopy, "_" + typ, None))
        compilefunc = method and method.im_func

        if compilefunc:
            node = compilefunc(obj)
        else:
            raise CompileError("Cannot compile %s (of type %s)" % (obj, typ))

    if ln:
        node.lineno = ln

    return node
Example #2
0
def compileOperator(op):
    getOpFunc = ast.Getattr(compileGetOp(op), 'func')
    return compileFunctionCall(getOpFunc, opargs(op), opfields(op), None, None)