예제 #1
0
파일: pycompile.py 프로젝트: DawidvC/Logix
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
예제 #2
0
파일: pycompile.py 프로젝트: manbaum/Logix
def compileOperator(op):
    getOpFunc = ast.Getattr(compileGetOp(op), 'func')
    return compileFunctionCall(getOpFunc, opargs(op), opfields(op), None, None)