style fix

This commit is contained in:
pca006132 2020-12-21 09:55:38 +08:00 committed by pca006132
parent 40c106ab6a
commit b296e67ad1

View File

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