diff --git a/test/test_try.py b/test/test_try.py deleted file mode 100644 index 11c6b81..0000000 --- a/test/test_try.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- - -import ast -from astpretty import pprint -from yapypy.extended_python.parser import parse -from yapypy.extended_python.symbol_analyzer import ASTTagger, SymTable, to_tagged_ast, Tag -from yapypy.extended_python.py_compile import py_compile - -code = r""" -try: - raise -except TypeError as e: - a = 3 -except NameError as e: - a = 4 -except RuntimeError as e: - a = 5 -""" -res: Tag = to_tagged_ast(parse(code).result) -co = py_compile(res) -import dis -dis.dis(co) -print( dis.code_info(co) ) -exec(co) -print( a ) \ No newline at end of file diff --git a/yapypy/extended_python/emit_impl/exception_handling.py b/yapypy/extended_python/emit_impl/exception_handling.py index 9ee9a4f..51a457f 100644 --- a/yapypy/extended_python/emit_impl/exception_handling.py +++ b/yapypy/extended_python/emit_impl/exception_handling.py @@ -76,72 +76,3 @@ def py_emit(node: ast.Assert, ctx: Context): ctx.bc.append(Instr("RAISE_VARARGS", 1, lineno=node.lineno)) # awalys 1 ctx.bc.append(label) - - -@py_emit.case(ast.Try) -def py_emit(node: ast.Try, ctx: Context): - """ - title: try - test: - >>> try: - >>> a = b - >>> except: - >>> a = 2 - """ - lineno = node.lineno - bodys = node.body - handlers = node.handlers - orelse = node.orelse # wait - finalbody = node.finalbody # wait - setup_forward = Label() - try_forward = Label() - except_forward = Label() - ctx.bc.append(Instr("SETUP_EXCEPT", setup_forward)) - for body in bodys: - py_emit(body, ctx) - ctx.bc.append( Instr("POP_BLOCK") ) - ctx.bc.append( Instr("JUMP_FORWARD", try_forward)) - ctx.bc.append( setup_forward ) - labels = [Label() for n in range(len(handlers) - 1)] - print( labels ) - for (idx,handler) in enumerate(handlers): - h_lineno = handler.lineno - typ = handler.type - name = handler.name - h_bodys = handler.body - if typ: - if idx > 0: - dur_top = labels.pop() - ctx.bc.append( dur_top ) - ctx.bc.append( Instr("DUP_TOP") ) - py_emit(typ, ctx) - ctx.bc.append( Instr("COMPARE_OP",Compare.EXC_MATCH) ) - if labels: - ctx.bc.append( Instr("POP_JUMP_IF_FALSE",labels[-1] ) ) - else: - ctx.bc.append( Instr("POP_JUMP_IF_FALSE",except_forward) ) - ctx.bc.append ( Instr("POP_TOP") ) - if name: - name_forward = Label() - ctx.store_name( name ) - ctx.bc.append ( Instr("POP_TOP") ) - ctx.bc.append ( Instr("SETUP_FINALLY", name_forward) ) - else: - ctx.bc.append ( Instr("POP_TOP") ) - ctx.bc.append ( Instr("POP_TOP") ) - for hbody in h_bodys: - py_emit(hbody, ctx) - #ctx.bc.append( Instr("POP_EXCEPT") ) - if name: - ctx.bc.append( Instr("POP_BLOCK") ) - ctx.bc.append( Instr("LOAD_CONST",None) ) - ctx.bc.append( name_forward ) - ctx.bc.append( Instr("LOAD_CONST",None) ) - ctx.store_name( name ) - ctx.del_name( name ) - ctx.bc.append( Instr("POP_EXCEPT") ) - ctx.bc.append( Instr("JUMP_FORWARD", except_forward) ) - ctx.bc.append( try_forward ) - ctx.bc.append( Instr("END_FINALLY") ) - ctx.bc.append( except_forward ) - # process else \ No newline at end of file diff --git a/yapypy/extended_python/emit_impl/simple_expr.py b/yapypy/extended_python/emit_impl/simple_expr.py index be2af42..c5e0b45 100644 --- a/yapypy/extended_python/emit_impl/simple_expr.py +++ b/yapypy/extended_python/emit_impl/simple_expr.py @@ -14,24 +14,15 @@ def py_emit(node: ast.Set, ctx: Context): >>> test: - >>> assert {1,2} == {1,2} - >>> assert {1,*{2,3},*{3,4}} == {1,2,3,4} - >>> assert {1, *{2, 3, 4}, 6, *{6, 7}, 8} == {1, 2, 3, 4, 6, 7, 8} + >>> {1,2,3,4} + >>> {233,'233'} """ elts = node.elts - starreds = [ ] n = 0 for elt in elts: - if isinstance(elt,ast.Starred): - starreds += [elt] - else: - py_emit(elt, ctx) - n += 1 + py_emit(elt, ctx) + n += 1 ctx.bc.append(BUILD_SET(n, lineno=node.lineno)) - for starred in starreds: - py_emit(starred.value, ctx) - ctx.bc.append(Instr("BUILD_SET_UNPACK",len(starreds) + 1 - ,lineno=node.lineno)) @py_emit.case(ast.Str)