# This is a hack that works because the Mython expression language # is identical to Python's. # XXX Consider splitting the myeval() and myexec() (contrary to # the original Mython paper). if isinstance(code, str): ret_val = eval(code, env) else: assert isinstance(code, _ast.AST) env = env.copy() code_obj, env = mybackend(code, env) ret_val = eval(code_obj, env) return ret_val, env # ______________________________________________________________________ myescape = _ASTUtils.mk_escaper(_ast) # ______________________________________________________________________ def mython (name, code, env0): """mython(name, code, env0) Quotation function for Mython.""" stmt_lst = [] ast, env1 = myparse(code, env0) esc_ast = myescape(ast) if name is not None: env1[name] = ast # XXX Add line and position information to the constructed syntax. stmt_lst = [_ast.Assign([_ast.Name(name, _ast.Store())], esc_ast)] else: stmt_lst = [_ast.Expr(esc_ast)]