Ejemplo n.º 1
0
def get_compile():
    source_code = request.query.program

    # empty
    if not source_code.strip():
        return json.dumps({
            'status': 'success',
            'ast_svg': '',
            'bytecode_str': ''
        })

    try:
        obj = CodeAst(source_code)
        node = obj.get_ast()

        g = PGGraphvizCreator(node)
        ast_svg = g.graph.create_svg()

        codeobject = compile(node, '<string>', 'exec')
        c = byteplay.Code.from_code(codeobject)
        bytecode_str = str(c.code)

        ast_json = obj.to_renderable_json()

        return json.dumps({
            'status': 'success',
            'ast_svg': ast_svg,
            'ast_json': ast_json,
            'bytecode_str': bytecode_str
        })
    except SyntaxError:
        return json.dumps({'status': 'error', 'data': 'SyntaxError'})
Ejemplo n.º 2
0
def get_compile():
    source_code = request.query.program

    # empty
    if not source_code.strip():
        return json.dumps({'status': 'success',
                           'ast_svg': '',
                           'bytecode_str': ''})

    try:
        obj = CodeAst(source_code)
        node = obj.get_ast()

        g = PGGraphvizCreator(node)
        ast_svg = g.graph.create_svg()

        codeobject = compile(node, '<string>', 'exec')
        c = byteplay.Code.from_code(codeobject)
        bytecode_str = str(c.code)

        ast_json = obj.to_renderable_json()

        return json.dumps({'status': 'success',
                           'ast_svg': ast_svg,
                           'ast_json': ast_json,
                           'bytecode_str': bytecode_str})
    except SyntaxError:
        return json.dumps({'status': 'error', 'data': 'SyntaxError'})
Ejemplo n.º 3
0
import sys
from ast_extents import CodeAst

if __name__ == "__main__":
    code_str = open(sys.argv[1]).read()

    obj = CodeAst(code_str)

    print obj.to_renderable_json(compact=False, debug=True)