style fix

pull/14/head
pca006132 2020-12-21 09:55:38 +08:00 committed by pca006132
parent 40c106ab6a
commit b296e67ad1
1 changed files with 16 additions and 16 deletions

View File

@ -62,8 +62,8 @@ def get_bin_ops(op):
return f'__{type(op).__name__.lower()}__'
def parse_constant(ctx: Context,
sym_table: dict[str, Type],
node):
sym_table: dict[str, Type],
node):
v = node.value
if isinstance(v, int):
return ctx.types['int32']
@ -92,22 +92,22 @@ def parse_list(ctx: Context,
return ListType(types[0])
def parse_tuple(ctx: Context,
sym_table: dict[str, Type],
node):
sym_table: dict[str, Type],
node):
types = [parse_expr(ctx, sym_table, e) for e in node.elts]
return TupleType(types)
def parse_attribute(ctx: Context,
sym_table: dict[str, Type],
node):
sym_table: dict[str, Type],
node):
obj = parse_expr(node.value)
if node.attr in obj.fields:
return obj.fields[node.attr]
raise CustomError(f'unknown field {node.attr} in {obj}')
def parse_bool_ops(ctx: Context,
sym_table: dict[str, Type],
node):
sym_table: dict[str, Type],
node):
assert len(node.values) == 2
left = parse_expr(ctx, sym_table, node.values[0])
right = parse_expr(ctx, sym_table, node.values[1])
@ -117,16 +117,16 @@ def parse_bool_ops(ctx: Context,
return b
def parse_bin_ops(ctx: Context,
sym_table: dict[str, Type],
node):
sym_table: dict[str, Type],
node):
left = parse_expr(ctx, sym_table, node.left)
right = parse_expr(ctx, sym_table, node.right)
op = get_bin_ops(node.op)
return resolve_call(left, op, [right], {}, ctx)
def parse_unary_ops(ctx: Context,
sym_table: dict[str, Type],
node):
sym_table: dict[str, Type],
node):
t = parse_expr(node.operand)
if isinstance(node.op, ast.Not):
b = ctx.types['bool']
@ -136,8 +136,8 @@ def parse_unary_ops(ctx: Context,
return resolve_call(t, get_unary_op(node.op), [], {}, ctx)
def parse_compare(ctx: Context,
sym_table: dict[str, Type],
node):
sym_table: dict[str, Type],
node):
items = [parse_expr(ctx, sym_table, v) for v in node.comparators]
items.insert(0, parse_expr(ctx, sym_table, node.left))
boolean = ctx.types['bool']
@ -165,8 +165,8 @@ def parse_call(ctx: Context,
return resolve_call(obj, f, args, {}, ctx)
def parse_subscript(ctx: Context,
sym_table: dict[str, Type],
node):
sym_table: dict[str, Type],
node):
value = parse_expr(ctx, sym_table, node.value)
if not isinstance(value, ListType):
raise CustomError(f'cannot take index of {value}')