Skip to content

Commit 1639f4c

Browse files
committed
chore: format code
1 parent f44d647 commit 1639f4c

File tree

4 files changed

+105
-44
lines changed

4 files changed

+105
-44
lines changed

rivetc/src/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,9 @@ def type_symbol_size(self, sy):
397397
max_alignment = self.pointer_size
398398
for variant in sy.info.variants:
399399
if variant.has_typ:
400-
variant_size, alignment = self.type_size(variant.typ)
400+
variant_size, alignment = self.type_size(
401+
variant.typ
402+
)
401403
if alignment > max_alignment:
402404
max_alignment = alignment
403405
total_size = utils.round_up(

rivetc/src/codegen/__init__.py

Lines changed: 95 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,9 @@ def gen_decl(self, decl):
350350
fn_dec_ret_type_str = str(fn_decl.ret_typ)
351351
if fn_dec_ret_type_str == "void" or fn_dec_ret_type_str == "_R6Result_R4void":
352352
self.gen_defer_stmts(scope = decl.scope)
353-
if fn_dec_ret_type_str == "_R6Result_R4void" and len(fn_decl.instrs) == 0:
353+
if fn_dec_ret_type_str == "_R6Result_R4void" and len(
354+
fn_decl.instrs
355+
) == 0:
354356
self.cur_func.add_ret(self.result_void(decl.ret_typ))
355357
elif fn_dec_ret_type_str != "void" and not (
356358
len(fn_decl.instrs) > 0
@@ -641,12 +643,19 @@ def gen_expr_with_cast(self, expected_typ_, expr, custom_tmp = None):
641643
tmp = self.cur_func.local_name()
642644
tmp_t = expected_typ
643645
variant_idx = expr_sym.info.get_variant_by_type(expected_typ_).value
644-
self.cur_func.add_call("_R4core16tagged_enum_castF", [
645-
ir.Selector(ir.UINT_T, res_expr, ir.Name("_idx_")),
646-
variant_idx
647-
])
648-
obj_f = ir.Selector(ir.Type(cg_utils.mangle_symbol(expr_sym)+"6_Union"), res_expr, ir.Name("obj"))
649-
value = ir.Selector(self.ir_type(expr.typ), obj_f, ir.Name(f"v{variant_idx}"))
646+
self.cur_func.add_call(
647+
"_R4core16tagged_enum_castF", [
648+
ir.Selector(ir.UINT_T, res_expr, ir.Name("_idx_")),
649+
variant_idx
650+
]
651+
)
652+
obj_f = ir.Selector(
653+
ir.Type(cg_utils.mangle_symbol(expr_sym) + "6_Union"), res_expr,
654+
ir.Name("obj")
655+
)
656+
value = ir.Selector(
657+
self.ir_type(expr.typ), obj_f, ir.Name(f"v{variant_idx}")
658+
)
650659
self.cur_func.inline_alloca(tmp_t, tmp, value)
651660
res_expr = ir.Ident(tmp_t, tmp)
652661

@@ -805,13 +814,23 @@ def gen_expr(self, expr, custom_tmp = None):
805814
elif typ_sym.kind == TypeKind.Enum and typ_sym.info.is_tagged:
806815
tmp = self.cur_func.local_name()
807816
tmp_t = ir_typ
808-
variant_idx = typ_sym.info.get_variant_by_type(expr.typ).value
809-
self.cur_func.add_call("_R4core16tagged_enum_castF", [
810-
ir.Selector(ir.UINT_T, res, ir.Name("_idx_")),
811-
variant_idx
812-
])
813-
obj_f = ir.Selector(ir.Type(cg_utils.mangle_symbol(typ_sym)+"6_Union"), res, ir.Name("obj"))
814-
value = ir.Selector(self.ir_type(expr.typ), obj_f, ir.Name(f"v{variant_idx}"))
817+
variant_idx = typ_sym.info.get_variant_by_type(
818+
expr.typ
819+
).value
820+
self.cur_func.add_call(
821+
"_R4core16tagged_enum_castF", [
822+
ir.Selector(ir.UINT_T, res, ir.Name("_idx_")),
823+
variant_idx
824+
]
825+
)
826+
obj_f = ir.Selector(
827+
ir.Type(cg_utils.mangle_symbol(typ_sym) + "6_Union"),
828+
res, ir.Name("obj")
829+
)
830+
value = ir.Selector(
831+
self.ir_type(expr.typ), obj_f,
832+
ir.Name(f"v{variant_idx}")
833+
)
815834
self.cur_func.inline_alloca(tmp_t, tmp, value)
816835
return ir.Ident(tmp_t, tmp)
817836
tmp = self.cur_func.local_name()
@@ -980,7 +999,11 @@ def gen_expr(self, expr, custom_tmp = None):
980999
)
9811000
elif typ_sym.kind == TypeKind.Enum:
9821001
if expr.is_enum_variant:
983-
tmp = self.stacked_instance(ir.Type(cg_utils.mangle_symbol(expr.enum_variant_sym)))
1002+
tmp = self.stacked_instance(
1003+
ir.Type(
1004+
cg_utils.mangle_symbol(expr.enum_variant_sym)
1005+
)
1006+
)
9841007
initted_fields = []
9851008
type_fields = expr.enum_variant_sym.full_fields()
9861009
for i, f in enumerate(expr.args):
@@ -1347,7 +1370,9 @@ def gen_expr(self, expr, custom_tmp = None):
13471370
)
13481371
self.cur_func.add_ret_void()
13491372
else:
1350-
tmp2 = self.stacked_instance(self.ir_type(self.cur_func_ret_typ))
1373+
tmp2 = self.stacked_instance(
1374+
self.ir_type(self.cur_func_ret_typ)
1375+
)
13511376
self.cur_func.store(
13521377
ir.Selector(ir.BOOL_T, tmp2, ir.Name("is_err")),
13531378
ir.IntLit(ir.BOOL_T, "1")
@@ -1551,7 +1576,9 @@ def gen_expr(self, expr, custom_tmp = None):
15511576
typ_sym = expr.typ.symbol()
15521577
if len(expr.elems) == 0:
15531578
if expr.is_dyn:
1554-
return self.stacked_instance(self.ir_type(expr.typ), self.empty_dyn_array(typ_sym))
1579+
return self.stacked_instance(
1580+
self.ir_type(expr.typ), self.empty_dyn_array(typ_sym)
1581+
)
15551582
return self.default_value(expr.typ)
15561583
elem_typ = typ_sym.info.elem_typ
15571584
size, _ = self.comp.type_size(elem_typ)
@@ -1750,7 +1777,9 @@ def gen_expr(self, expr, custom_tmp = None):
17501777
return tmp
17511778
elif expr.op in (Kind.LogicalAnd, Kind.LogicalOr):
17521779
left = self.gen_expr_with_cast(expr_left_typ, expr.left)
1753-
tmp = self.stacked_instance(self.ir_type(self.comp.bool_t), left)
1780+
tmp = self.stacked_instance(
1781+
self.ir_type(self.comp.bool_t), left
1782+
)
17541783
left_l = self.cur_func.local_name()
17551784
exit_l = self.cur_func.local_name()
17561785
if expr.op == Kind.LogicalAnd:
@@ -1827,22 +1856,25 @@ def gen_expr(self, expr, custom_tmp = None):
18271856
union_type = ir.Type(union_name)
18281857
obj_val = ir.Selector(union_type, left, ir.Name("obj"))
18291858
val = ir.Selector(
1830-
ir.Type(self.ir_type(expr.typ)), obj_val, ir.Name(f"v{expr.right.variant_info.value}")
1859+
ir.Type(self.ir_type(expr.typ)), obj_val,
1860+
ir.Name(f"v{expr.right.variant_info.value}")
18311861
)
1832-
if expr.var.is_mut and not isinstance(var_t, ir.Pointer):
1862+
if expr.var.is_mut and not isinstance(
1863+
var_t, ir.Pointer
1864+
):
18331865
val = ir.Inst(ir.InstKind.GetPtr, [val], var_t2)
18341866
var_t = var_t.ptr()
18351867
else:
18361868
val = ir.Inst(
18371869
ir.InstKind.Cast, [
1838-
ir.Selector(ir.VOID_PTR_T, left, ir.Name("obj")),
1839-
var_t2
1870+
ir.Selector(
1871+
ir.VOID_PTR_T, left, ir.Name("obj")
1872+
), var_t2
18401873
]
18411874
)
1842-
if not (
1843-
(isinstance(var_t2, ir.Pointer) and var_t2.is_managed)
1844-
or expr.var.is_mut
1845-
):
1875+
if not ((
1876+
isinstance(var_t2, ir.Pointer) and var_t2.is_managed
1877+
) or expr.var.is_mut):
18461878
val = ir.Inst(ir.InstKind.LoadPtr, [val], var_t2)
18471879
unique_name = self.cur_func.unique_name(expr.var.name)
18481880
expr.scope.update_ir_name(expr.var.name, unique_name)
@@ -2186,13 +2218,16 @@ def gen_expr(self, expr, custom_tmp = None):
21862218
e_expr_typ_sym = expr.expr.typ.symbol()
21872219
if e_expr_typ_sym.kind == TypeKind.Enum:
21882220
obj_f = ir.Selector(
2189-
e_expr_typ_sym.name + "6_Union", match_expr, ir.Name("obj")
2221+
e_expr_typ_sym.name + "6_Union", match_expr,
2222+
ir.Name("obj")
21902223
)
21912224
val = ir.Selector(
2192-
self.ir_type(p.variant_info.typ),
2193-
obj_f, ir.Name(f"v{p.variant_info.value}")
2225+
self.ir_type(p.variant_info.typ), obj_f,
2226+
ir.Name(f"v{p.variant_info.value}")
21942227
)
2195-
if b.var_is_mut and not isinstance(var_t, ir.Pointer):
2228+
if b.var_is_mut and not isinstance(
2229+
var_t, ir.Pointer
2230+
):
21962231
val = ir.Inst(ir.InstKind.GetPtr, [val])
21972232
else:
21982233
val = ir.Inst(
@@ -2323,7 +2358,9 @@ def gen_expr(self, expr, custom_tmp = None):
23232358
expr_ = self.gen_expr_with_cast(ret_typ, expr.expr)
23242359
if is_array and self.comp.prefs.target_backend == prefs.Backend.C:
23252360
size, _ = self.comp.type_size(ret_typ)
2326-
tmp = self.stacked_instance(ir.Type(self.cur_func.arr_ret_struct))
2361+
tmp = self.stacked_instance(
2362+
ir.Type(self.cur_func.arr_ret_struct)
2363+
)
23272364
self.cur_func.add_call(
23282365
"_R4core8mem_copyF", [
23292366
ir.Selector(
@@ -2665,7 +2702,7 @@ def gen_string_literal(self, lit, size = None):
26652702
self.generated_string_literals[lit_hash] = tmp.name
26662703
return tmp
26672704

2668-
def stacked_instance(self, typ, init_value=None):
2705+
def stacked_instance(self, typ, init_value = None):
26692706
tmp = ir.Ident(typ, self.cur_func.local_name())
26702707
if init_value:
26712708
self.cur_func.alloca(tmp, init_value)
@@ -2766,10 +2803,15 @@ def tagged_enum_value(
27662803
):
27672804
arg0 = self.gen_expr_with_cast(variant_info.typ, value)
27682805
size, _ = self.comp.type_size(variant_info.typ)
2769-
obj_f = ir.Selector(ir.Type(f"{cg_utils.mangle_symbol(enum_sym)}6_Union"), tmp, ir.Name("obj"))
2806+
obj_f = ir.Selector(
2807+
ir.Type(f"{cg_utils.mangle_symbol(enum_sym)}6_Union"), tmp,
2808+
ir.Name("obj")
2809+
)
27702810
self.cur_func.store(
2771-
ir.Selector(self.ir_type(variant_info.typ), obj_f, ir.Name(f"v{variant_info.value}")),
2772-
arg0
2811+
ir.Selector(
2812+
self.ir_type(variant_info.typ), obj_f,
2813+
ir.Name(f"v{variant_info.value}")
2814+
), arg0
27732815
)
27742816
return tmp
27752817

@@ -2789,9 +2831,15 @@ def tagged_enum_variant_with_fields_value(
27892831
ir.Selector(ir.UINT_T, tmp, ir.Name("_idx_")),
27902832
ir.IntLit(ir.UINT_T, variant_info.value)
27912833
)
2792-
obj_f = ir.Selector(ir.Type(f"{cg_utils.mangle_symbol(enum_sym)}6_Union"), tmp, ir.Name("obj"))
2834+
obj_f = ir.Selector(
2835+
ir.Type(f"{cg_utils.mangle_symbol(enum_sym)}6_Union"), tmp,
2836+
ir.Name("obj")
2837+
)
27932838
self.cur_func.store(
2794-
ir.Selector(self.ir_type(variant_info.typ), obj_f, ir.Name(f"v{variant_info.value}")), value
2839+
ir.Selector(
2840+
self.ir_type(variant_info.typ), obj_f,
2841+
ir.Name(f"v{variant_info.value}")
2842+
), value
27952843
)
27962844
return tmp
27972845

@@ -2981,7 +3029,9 @@ def gen_types(self):
29813029
fields = []
29823030
for v in ts.info.variants:
29833031
if v.has_typ:
2984-
fields.append(ir.Field(f"v{v.value}", self.ir_type(v.typ)))
3032+
fields.append(
3033+
ir.Field(f"v{v.value}", self.ir_type(v.typ))
3034+
)
29853035
union_name = mangled_name + "6_Union"
29863036
self.out_rir.types.append(ir.Union(union_name, fields))
29873037
struct_fields = []
@@ -2991,7 +3041,9 @@ def gen_types(self):
29913041
ir.Field("_idx_", ir.UINT_T),
29923042
ir.Field("obj", ir.Type(union_name))
29933043
]
2994-
self.out_rir.types.append(ir.Struct(False, mangled_name, struct_fields))
3044+
self.out_rir.types.append(
3045+
ir.Struct(False, mangled_name, struct_fields)
3046+
)
29953047
elif ts.kind == TypeKind.Trait:
29963048
ts_name = cg_utils.mangle_symbol(ts)
29973049
fields = [
@@ -3133,7 +3185,8 @@ def sort_type_symbols(self, tss):
31333185
for variant in ts.info.variants:
31343186
if variant.has_typ:
31353187
variant_sym = variant.typ.symbol()
3136-
if variant_sym.is_boxed() or isinstance(variant.typ, type.Option):
3188+
if variant_sym.is_boxed(
3189+
) or isinstance(variant.typ, type.Option):
31373190
continue
31383191
dep = cg_utils.mangle_symbol(variant_sym)
31393192
if dep not in typ_names or dep in field_deps:
@@ -3156,7 +3209,8 @@ def sort_type_symbols(self, tss):
31563209
elif ts.kind == TypeKind.Struct:
31573210
for base in ts.info.bases:
31583211
dep = cg_utils.mangle_symbol(base)
3159-
if dep not in typ_names or dep in field_deps or base.is_boxed():
3212+
if dep not in typ_names or dep in field_deps or base.is_boxed(
3213+
):
31603214
continue
31613215
field_deps.append(dep)
31623216
for f in ts.fields:

rivetc/src/parser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ def parse_decl(self):
212212
glob = True
213213
else:
214214
report.error("invalid syntax for unqualified import", pos)
215-
report.note("expected a single name, a list of names or `*`")
215+
report.note(
216+
"expected a single name, a list of names or `*`"
217+
)
216218
if len(import_list) == 0 and self.accept(Kind.KwAs):
217219
alias = self.parse_name()
218220
self.expect(Kind.Semicolon)

rivetc/src/register.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ def walk_decls(self, decls):
134134
report.error(e.args[0], decl.pos)
135135
elif isinstance(decl, ast.EnumDecl):
136136
try:
137-
info = sym.EnumInfo(decl.underlying_typ, decl.is_tagged, decl.attributes.has("boxed"))
137+
info = sym.EnumInfo(
138+
decl.underlying_typ, decl.is_tagged,
139+
decl.attributes.has("boxed")
140+
)
138141
decl.sym = self.sym.add_and_return(
139142
sym.Type(decl.is_public, decl.name, TypeKind.Enum)
140143
)

0 commit comments

Comments
 (0)