From 6338888a04e764400dfcbc68157fcc8bb023f5f7 Mon Sep 17 00:00:00 2001 From: Jose Mendoza <56417208+StunxFS@users.noreply.github.com> Date: Thu, 7 Dec 2023 18:28:19 +0000 Subject: [PATCH] rclear --- lib/rivet/src/ast/CHeader.ri | 4 +- lib/rivet/src/ast/Decl.ri | 10 +- lib/rivet/src/ast/Expr.ri | 122 +++++++++++----------- lib/rivet/src/ast/Stmt.ri | 12 +-- lib/rivet/src/ast/Sym.ri | 8 +- lib/rivet/src/ast/Table.ri | 30 +++--- lib/rivet/src/ast/Type.ri | 100 +++++++++--------- lib/rivet/src/ast/TypeInfo.ri | 16 +-- lib/rivet/src/ast/TypeSym.ri | 20 ++-- lib/rivet/src/checker/builtin_call.ri | 16 +-- lib/rivet/src/checker/call_expr.ri | 42 ++++---- lib/rivet/src/checker/check_trait_impl.ri | 2 +- lib/rivet/src/checker/decls.ri | 36 +++---- lib/rivet/src/checker/exprs.ri | 112 ++++++++++---------- lib/rivet/src/checker/match_expr.ri | 6 +- lib/rivet/src/checker/mod.ri | 68 ++++++------ lib/rivet/src/checker/stmts.ri | 10 +- lib/rivet/src/checker/types.ri | 26 ++--- lib/rivet/src/codegen/mod.ri | 4 +- lib/rivet/src/codegen/types.ri | 2 +- lib/rivet/src/lib.ri | 4 +- lib/rivet/src/parser/exprs.ri | 4 +- lib/rivet/src/resolver/Register.ri | 24 ++--- lib/rivet/src/resolver/decls.ri | 42 ++++---- lib/rivet/src/resolver/exprs.ri | 74 ++++++------- lib/rivet/src/resolver/mod.ri | 16 +-- lib/rivet/src/resolver/stmts.ri | 12 +-- lib/rivet/src/resolver/types.ri | 32 +++--- rivetc/src/checker.py | 34 +++--- rivetc/src/register.py | 16 +-- rivetc/src/resolver.py | 18 ++-- tests/valid/src/enums.ri | 12 +-- tests/valid/src/match_expr.ri | 2 +- tests/valid/src/results.ri | 4 +- 34 files changed, 470 insertions(+), 470 deletions(-) diff --git a/lib/rivet/src/ast/CHeader.ri b/lib/rivet/src/ast/CHeader.ri index 123088feb..987012af5 100644 --- a/lib/rivet/src/ast/CHeader.ri +++ b/lib/rivet/src/ast/CHeader.ri @@ -103,8 +103,8 @@ enum CImportValue { #[inline] pub func to_bool(self) -> bool { - return (self is .Int as int and int == 1) - or (self is .Uint as uint and uint == 1); + return (self is .Int(int) and int == 1) + or (self is .Uint(uint) and uint == 1); } } diff --git a/lib/rivet/src/ast/Decl.ri b/lib/rivet/src/ast/Decl.ri index 0205fdade..c48514210 100644 --- a/lib/rivet/src/ast/Decl.ri +++ b/lib/rivet/src/ast/Decl.ri @@ -152,11 +152,11 @@ pub enum Decl { pub func decls(self) -> ?[]Self { return match self is { - .Extern as extern_decl -> extern_decl.decls, - .Trait as trait_decl -> trait_decl.decls, - .Enum as enum_decl -> enum_decl.decls, - .Struct as struct_decl -> struct_decl.decls, - .Extend as extend_decl -> extend_decl.decls, + .Extern(extern_decl) -> extern_decl.decls, + .Trait(trait_decl) -> trait_decl.decls, + .Enum(enum_decl) -> enum_decl.decls, + .Struct(struct_decl) -> struct_decl.decls, + .Extend(extend_decl) -> extend_decl.decls, else -> none }; } diff --git a/lib/rivet/src/ast/Expr.ri b/lib/rivet/src/ast/Expr.ri index 035eb65d4..89e7119c9 100644 --- a/lib/rivet/src/ast/Expr.ri +++ b/lib/rivet/src/ast/Expr.ri @@ -278,7 +278,7 @@ pub enum Expr < traits.Stringable { pub func clean_paren(self) -> Self { mut res := self; - while res is .Paren as paren { + while res is .Paren(paren) { res = paren.expr; } return res; @@ -287,38 +287,38 @@ pub enum Expr < traits.Stringable { #[inline] pub func position(self) -> token.Pos { return match self is { - .Empty as empty_pos -> empty_pos, - .Paren as paren -> paren.pos, - .Type as type -> type.position(), - .Assign as assign -> assign.pos, - .Ident as ident -> ident.pos, - .SelfTy as self_ty -> self_ty.pos, - .SelfLiteral as self_lit -> self_lit.pos, - .NoneLiteral as none_lit -> none_lit.pos, - .BoolLiteral as bool_lit -> bool_lit.pos, - .CharLiteral as char_lit -> char_lit.pos, - .IntegerLiteral as int_lit -> int_lit.pos, - .FloatLiteral as float_lit -> float_lit.pos, - .StringLiteral as string_lit -> string_lit.pos, - .EnumLiteral as enum_lit -> enum_lit.pos, - .TupleLiteral as tuple_lit -> tuple_lit.pos, - .DynArrayLiteral as dyn_array_lit -> dyn_array_lit.pos, - .Index as index -> index.pos, - .Selector as selector -> selector.pos, - .Indirect as indirect -> indirect.pos, - .OptionCheck as option_check -> option_check.pos, - .Branch as branch -> branch.pos, - .Range as range -> range.pos, - .Call as call -> call.pos, - .BuiltinCall as builtin_call -> builtin_call.pos, - .Unary as unary -> unary.pos, - .Binary as binary -> binary.pos, - .Return as return_expr -> return_expr.pos, - .Throw as throw_expr -> throw_expr.pos, - .Block as block -> block.pos, - .If as if_expr -> if_expr.pos, - .Match as match_expr -> match_expr.pos, - .Guard as guard -> guard.pos + .Empty(empty_pos) -> empty_pos, + .Paren(paren) -> paren.pos, + .Type(type) -> type.position(), + .Assign(assign) -> assign.pos, + .Ident(ident) -> ident.pos, + .SelfTy(self_ty) -> self_ty.pos, + .SelfLiteral(self_lit) -> self_lit.pos, + .NoneLiteral(none_lit) -> none_lit.pos, + .BoolLiteral(bool_lit) -> bool_lit.pos, + .CharLiteral(char_lit) -> char_lit.pos, + .IntegerLiteral(int_lit) -> int_lit.pos, + .FloatLiteral(float_lit) -> float_lit.pos, + .StringLiteral(string_lit) -> string_lit.pos, + .EnumLiteral(enum_lit) -> enum_lit.pos, + .TupleLiteral(tuple_lit) -> tuple_lit.pos, + .DynArrayLiteral(dyn_array_lit) -> dyn_array_lit.pos, + .Index(index) -> index.pos, + .Selector(selector) -> selector.pos, + .Indirect(indirect) -> indirect.pos, + .OptionCheck(option_check) -> option_check.pos, + .Branch(branch) -> branch.pos, + .Range(range) -> range.pos, + .Call(call) -> call.pos, + .BuiltinCall(builtin_call) -> builtin_call.pos, + .Unary(unary) -> unary.pos, + .Binary(binary) -> binary.pos, + .Return(return_expr) -> return_expr.pos, + .Throw(throw_expr) -> throw_expr.pos, + .Block(block) -> block.pos, + .If(if_expr) -> if_expr.pos, + .Match(match_expr) -> match_expr.pos, + .Guard(guard) -> guard.pos }; } @@ -326,10 +326,10 @@ pub enum Expr < traits.Stringable { pub func to_string(self) -> string { return match self is { .Empty -> "", - .Paren as paren -> "({})".fmt(paren.expr), - .Type as type -> type.to_string(), - .Assign as assign -> "{} {} {}".fmt(assign.left, assign.op, assign.right), - .Ident as ident -> if ident.is_comptime { + .Paren(paren) -> "({})".fmt(paren.expr), + .Type(type) -> type.to_string(), + .Assign(assign) -> "{} {} {}".fmt(assign.left, assign.op, assign.right), + .Ident(ident) -> if ident.is_comptime { "@".concat(ident.name) } else { ident.name @@ -337,15 +337,15 @@ pub enum Expr < traits.Stringable { .SelfTy -> "Self", .SelfLiteral -> "self", .NoneLiteral -> "none", - .BoolLiteral as bool_lit -> bool_lit.value.to_string(), - .CharLiteral as char_lit -> if char_lit.is_byte { + .BoolLiteral(bool_lit) -> bool_lit.value.to_string(), + .CharLiteral(char_lit) -> if char_lit.is_byte { "b'{}'".fmt(char_lit.value) } else { "'{}'".fmt(char_lit.value) }, - .IntegerLiteral as int_lit -> int_lit.value, - .FloatLiteral as float_lit -> float_lit.value, - .StringLiteral as string_lit -> if string_lit.is_bytestr { + .IntegerLiteral(int_lit) -> int_lit.value, + .FloatLiteral(float_lit) -> float_lit.value, + .StringLiteral(string_lit) -> if string_lit.is_bytestr { "b\"{}\"".fmt(string_lit.value) } else if string_lit.is_raw { "r\"{}\"".fmt(string_lit.value) @@ -354,8 +354,8 @@ pub enum Expr < traits.Stringable { } else { "\"{}\"".fmt(string_lit.value) }, - .EnumLiteral as enum_lit -> ".".concat(enum_lit.value), - .TupleLiteral as tuple_lit -> { + .EnumLiteral(enum_lit) -> ".".concat(enum_lit.value), + .TupleLiteral(tuple_lit) -> { mut sb := strings.Builder.from_string("("); for i, value in tuple_lit.values { sb.write_string(value.to_string()); @@ -366,7 +366,7 @@ pub enum Expr < traits.Stringable { sb.write_byte(b')'); sb.to_string() }, - .DynArrayLiteral as dyn_array_lit -> { + .DynArrayLiteral(dyn_array_lit) -> { mut sb := strings.Builder.from_string("["); for i, value in dyn_array_lit.values { sb.write_string(value.to_string()); @@ -380,11 +380,11 @@ pub enum Expr < traits.Stringable { } sb.to_string() }, - .Selector as selector -> "{}.{}".fmt(selector.left, selector.field_name), - .Indirect as indirect -> "{}.*".fmt(indirect.left), - .OptionCheck as option_check -> "{}?".fmt(option_check.left), - .Branch as branch_expr -> branch_expr.op.to_string(), - .Range as range -> { + .Selector(selector) -> "{}.{}".fmt(selector.left, selector.field_name), + .Indirect(indirect) -> "{}.*".fmt(indirect.left), + .OptionCheck(option_check) -> "{}?".fmt(option_check.left), + .Branch(branch_expr) -> branch_expr.op.to_string(), + .Range(range) -> { mut sb := strings.Builder.new(); if range.has_start { sb.write_string(range.start.to_string()); @@ -399,8 +399,8 @@ pub enum Expr < traits.Stringable { } sb.to_string() }, - .Index as index -> "{}[{}]".fmt(index.left, index.index), - .Call as call -> { + .Index(index) -> "{}[{}]".fmt(index.left, index.index), + .Call(call) -> { mut sb := strings.Builder.new(); sb.write_string(call.left.to_string()); sb.write_byte(b'('); @@ -433,7 +433,7 @@ pub enum Expr < traits.Stringable { } sb.to_string() }, - .BuiltinCall as builtin_call -> { + .BuiltinCall(builtin_call) -> { mut sb := strings.Builder.from_string("@"); sb.write_string(builtin_call.name); sb.write_byte(b'('); @@ -446,15 +446,15 @@ pub enum Expr < traits.Stringable { sb.write_byte(b')'); sb.to_string() }, - .Unary as unary -> "{}{}".fmt(unary.op, unary.right), - .Binary as binary -> "{} {} {}".fmt(binary.left, binary.op, binary.right), - .Return as return_expr -> if return_expr.has_expr { + .Unary(unary) -> "{}{}".fmt(unary.op, unary.right), + .Binary(binary) -> "{} {} {}".fmt(binary.left, binary.op, binary.right), + .Return(return_expr) -> if return_expr.has_expr { "return {}".fmt(return_expr.expr) } else { "return" }, - .Throw as throw_expr -> "throw {}".fmt(throw_expr.expr), - .Block as block -> { + .Throw(throw_expr) -> "throw {}".fmt(throw_expr.expr), + .Block(block) -> { mut sb := strings.Builder.new(); if block.is_unsafe { sb.write_string("unsafe "); @@ -468,7 +468,7 @@ pub enum Expr < traits.Stringable { sb.write_string(" }"); sb.to_string() }, - .If as if_expr -> { + .If(if_expr) -> { mut sb := strings.Builder.new(); for branch in if_expr.branches { if branch.is_else { @@ -484,7 +484,7 @@ pub enum Expr < traits.Stringable { } sb.to_string() }, - .Match as match_expr -> { + .Match(match_expr) -> { mut sb := strings.Builder.new(); sb.write_fmt("match {} ", match_expr.expr); if match_expr.is_typematch { @@ -519,7 +519,7 @@ pub enum Expr < traits.Stringable { sb.write_string("} "); sb.to_string() }, - .Guard as guard -> { + .Guard(guard) -> { mut sb := strings.Builder.new(); if guard.vars.len > 0 { sb.write_string("("); diff --git a/lib/rivet/src/ast/Stmt.ri b/lib/rivet/src/ast/Stmt.ri index 117f6e80e..9b4690097 100644 --- a/lib/rivet/src/ast/Stmt.ri +++ b/lib/rivet/src/ast/Stmt.ri @@ -45,12 +45,12 @@ pub enum Stmt { pub func position(self) -> token.Pos { return match self is { - .Empty as empty_pos -> empty_pos, - .Expr as expr -> expr.position(), - .VarDecl as var_decl -> var_decl.pos, - .While as while_stmt -> while_stmt.pos, - .For as for_stmt -> for_stmt.pos, - .Defer as defer_stmt -> defer_stmt.pos + .Empty(empty_pos) -> empty_pos, + .Expr(expr) -> expr.position(), + .VarDecl(var_decl) -> var_decl.pos, + .While(while_stmt) -> while_stmt.pos, + .For(for_stmt) -> for_stmt.pos, + .Defer(defer_stmt) -> defer_stmt.pos }; } } diff --git a/lib/rivet/src/ast/Sym.ri b/lib/rivet/src/ast/Sym.ri index 430c80d18..3ecf23ea0 100644 --- a/lib/rivet/src/ast/Sym.ri +++ b/lib/rivet/src/ast/Sym.ri @@ -96,23 +96,23 @@ pub trait Sym { func type_of(self) -> string { return match self is { - SymRef as sym_ref -> if sym_ref.ref_resolved { + SymRef(sym_ref) -> if sym_ref.ref_resolved { sym_ref.ref.type_of() } else { "alias" }, Module -> "module", Const -> "constant", - Var as obj -> match obj.level { + Var(obj) -> match obj.level { .Receiver, .Argument -> "argument", else -> "variable" }, - TypeSym as type_sym -> if type_sym.info.is_compound() { + TypeSym(type_sym) -> if type_sym.info.is_compound() { type_sym.info.to_string() } else { "type" }, - Func as func_info -> func_info.kind(), + Func(func_info) -> func_info.kind(), else -> "unknown symbol kind" }; } diff --git a/lib/rivet/src/ast/Table.ri b/lib/rivet/src/ast/Table.ri index fd7b8df59..6d84da43b 100644 --- a/lib/rivet/src/ast/Table.ri +++ b/lib/rivet/src/ast/Table.ri @@ -196,8 +196,8 @@ pub struct Table { pub func find_builtin(self, name: string) -> ?Builtin { for builtin in self.builtins { is_equal := match builtin is { - .Const as b_var -> b_var.name == name, - .Func as b_func -> b_func.name == name, + .Const(b_var) -> b_var.name == name, + .Func(b_func) -> b_func.name == name, else -> false }; if is_equal { @@ -268,9 +268,9 @@ pub struct Table { pub func int_bits(self, type: Type) -> uint { type_sym := type.symbol()?; - return if type_sym.info is .SizedInt as int_info { + return if type_sym.info is .SizedInt(int_info) { int_info.size - } else if type_sym.info is .SizedUint as uint_info { + } else if type_sym.info is .SizedUint(uint_info) { uint_info.size } else if type_sym.info is .Int or type_sym.info is .Uint { if self.prefs.target_is_64bit { 64 } else { 32 } @@ -282,7 +282,7 @@ pub struct Table { pub func float_bits(self, type: Type) -> uint { _ = self; type_sym := type.symbol()?; - return if type_sym.info is .Float as float_info { + return if type_sym.info is .Float(float_info) { float_info.size } else { 75 @@ -313,44 +313,44 @@ pub struct Table { } else { match type_sym.info is { .Func -> (self.pointer_size, self.pointer_size), - .Alias as alias_info -> self.type_size(alias_info.parent), + .Alias(alias_info) -> self.type_size(alias_info.parent), .Bool -> (1, 1), .Uint, .Int -> (self.pointer_size, self.pointer_size), - .SizedInt as int -> match int.size { + .SizedInt(int) -> match int.size { 8 -> (1, 1), 16 -> (2, 2), 32 -> (4, 4), 64 -> (8, 8), else -> (0, 0) }, - .SizedUint as uint -> match uint.size { + .SizedUint(uint) -> match uint.size { 8 -> (1, 1), 16 -> (2, 2), 32 -> (4, 4), 64 -> (8, 8), else -> (0, 0) }, - .Float as float -> match float.size { + .Float(float) -> match float.size { 32 -> (4, 4), 64 -> (8, 8), else -> (0, 0) }, .Rune -> (4, 4), .ComptimeFloat, .ComptimeInt -> (8, 8), - .Enum as enum_info -> if enum_info.is_boxed { + .Enum(enum_info) -> if enum_info.is_boxed { ((type_sym.fields.len + 2) * self.pointer_size, self.pointer_size) } else { self.type_size(enum_info.underlying_type) }, .DynArray -> self.type_symbol_size(self.dyn_array_sym, is_raw), - .Array as array_info -> { + .Array(array_info) -> { (elem_size, elem_align) := self.type_size(array_info.elem_type); (array_info.size * elem_size, elem_align) }, .Struct, .Tuple -> { mut total_size: uint := 0; mut max_alignment: uint := 0; - types := if type_sym.info is .Tuple as tuple_lit { + types := if type_sym.info is .Tuple(tuple_lit) { tuple_lit.types } else { mut tmp := @dyn_array(Type); @@ -368,7 +368,7 @@ pub struct Table { } (utils.round_up(total_size, max_alignment), max_alignment) }, - .Trait as trait_info -> { + .Trait(trait_info) -> { (size, align) = ((type_sym.fields.len + 2) * self.pointer_size, self.pointer_size); for mut btype in trait_info.bases { (bsize, _balign) := self.type_symbol_size(btype, is_raw); @@ -546,8 +546,8 @@ pub enum Builtin { pub func type(self) -> Type { return match self is { - .Const as b_const -> b_const.type, - .Func as b_func -> b_func.type, + .Const(b_const) -> b_const.type, + .Func(b_func) -> b_func.type, else -> .Void() }; } diff --git a/lib/rivet/src/ast/Type.ri b/lib/rivet/src/ast/Type.ri index 7780bb2db..2267e621a 100644 --- a/lib/rivet/src/ast/Type.ri +++ b/lib/rivet/src/ast/Type.ri @@ -84,7 +84,7 @@ pub enum Type < traits.Stringable { #[inline] func symbol(self) -> Func { - return if self.has_sym and self.sym.info is .Func as func_sym { + return if self.has_sym and self.sym.info is .Func(func_sym) { func_sym } else { Func( @@ -102,7 +102,7 @@ pub enum Type < traits.Stringable { #[inline] pub func ptr_or_ref_inner(self) -> Self { return match self is { - .Pointer as ptr -> ptr.inner, + .Pointer(ptr) -> ptr.inner, .Rawptr -> self, else -> .Void() }; @@ -113,25 +113,25 @@ pub enum Type < traits.Stringable { // unaliasing instead. return match self is { .Rawptr -> self, - .Result as result -> .Result(result.inner.unalias() ?? result.inner), - .Option as option -> .Option(option.inner.unalias() ?? option.inner), - .Tuple as tuple_data -> { + .Result(result) -> .Result(result.inner.unalias() ?? result.inner), + .Option(option) -> .Option(option.inner.unalias() ?? option.inner), + .Tuple(tuple_data) -> { unaliased_types := @dyn_array(mut Type, tuple_data.inners.len); for i, tuple_type in tuple_data.inners { unaliased_types[i] = tuple_type.unalias() ?? tuple_type; } .Tuple(unaliased_types, tuple_data.sym) }, - .DynArray as dyn_array_data -> .DynArray( + .DynArray(dyn_array_data) -> .DynArray( dyn_array_data.inner.unalias() ?? dyn_array_data.inner, dyn_array_data.is_mut ), - .Array as array_data -> .Array( + .Array(array_data) -> .Array( array_data.inner.unalias() ?? array_data.inner, ...self ), - .Pointer as pointer_data -> .Pointer( + .Pointer(pointer_data) -> .Pointer( pointer_data.inner.unalias() ?? pointer_data.inner, ...self ), - .Func as func_data -> { + .Func(func_data) -> { for arg in func_data.args { arg.type = arg.type.unalias() ?? arg.type; } @@ -140,7 +140,7 @@ pub enum Type < traits.Stringable { ...self ) }, - .Basic as basic if !basic.is_unresolved -> if basic.sym.info is .Alias as alias_info { + .Basic(basic) if !basic.is_unresolved -> if basic.sym.info is .Alias(alias_info) { alias_info.parent.unalias() ?? alias_info.parent } else { .Basic(basic.sym) @@ -161,15 +161,15 @@ pub enum Type < traits.Stringable { pub func symbol(self) -> ?TypeSym { // NOTE: `.Void`, `.None`, `.Never` and `.Rawptr` has no `TypeSym` value. return match self is { - .Result as result -> result.inner.symbol(), - .Option as option -> option.inner.symbol(), - .Tuple as tuple_data -> tuple_data.sym, - .Variadic as variadic_data -> variadic_data.sym, - .DynArray as dyn_array_data -> dyn_array_data.sym, - .Array as array_data -> array_data.sym, - .Pointer as pointer_data -> pointer_data.inner.symbol(), - .Func as func_data -> func_data.sym, - .Basic as basic if !basic.is_unresolved -> basic.sym, + .Result(result) -> result.inner.symbol(), + .Option(option) -> option.inner.symbol(), + .Tuple(tuple_data) -> tuple_data.sym, + .Variadic(variadic_data) -> variadic_data.sym, + .DynArray(dyn_array_data) -> dyn_array_data.sym, + .Array(array_data) -> array_data.sym, + .Pointer(pointer_data) -> pointer_data.inner.symbol(), + .Func(func_data) -> func_data.sym, + .Basic(basic) if !basic.is_unresolved -> basic.sym, else -> none }; } @@ -196,7 +196,7 @@ pub enum Type < traits.Stringable { pub func is_void(self) -> bool { return match self is { .Void, .Never -> true, - .Result as result -> result.inner.is_void(), + .Result(result) -> result.inner.is_void(), else -> false }; } @@ -209,7 +209,7 @@ pub enum Type < traits.Stringable { #[inline] pub func is_mut_pointer(self) -> bool { return match self is { - .Pointer as ptr -> ptr.is_mut, + .Pointer(ptr) -> ptr.is_mut, .Rawptr -> true, else -> false }; @@ -231,17 +231,17 @@ pub enum Type < traits.Stringable { pub func position(self) -> token.Pos { return match self is { .Void, .None -> token.noPos, - .Never as never_pos -> never_pos, - .Option as opt_t -> opt_t.pos, - .Result as res_t -> res_t.pos, - .Tuple as tuple_t -> tuple_t.pos, - .Variadic as variadic_t -> variadic_t.pos, - .DynArray as dyn_array_t -> dyn_array_t.pos, - .Array as arr_t -> arr_t.pos, - .Pointer as ptr_t -> ptr_t.pos, - .Rawptr as rawptr_t -> rawptr_t.pos, - .Func as func_t -> func_t.pos, - .Basic as basic_t -> if basic_t.is_unresolved { + .Never(never_pos) -> never_pos, + .Option(opt_t) -> opt_t.pos, + .Result(res_t) -> res_t.pos, + .Tuple(tuple_t) -> tuple_t.pos, + .Variadic(variadic_t) -> variadic_t.pos, + .DynArray(dyn_array_t) -> dyn_array_t.pos, + .Array(arr_t) -> arr_t.pos, + .Pointer(ptr_t) -> ptr_t.pos, + .Rawptr(rawptr_t) -> rawptr_t.pos, + .Func(func_t) -> func_t.pos, + .Basic(basic_t) -> if basic_t.is_unresolved { basic_t.expr.position() } else { basic_t.pos @@ -255,19 +255,19 @@ pub enum Type < traits.Stringable { .None if rhs is .None -> true, .Void if rhs is .Void -> true, .Never if rhs is .Never -> true, - .Result as result_lhs if rhs is .Result as result_rhs -> + .Result(result_lhs) if rhs is .Result(result_rhs) -> result_lhs.inner == result_rhs.inner, - .Option as option_lhs if rhs is .Option as option_rhs -> + .Option(option_lhs) if rhs is .Option(option_rhs) -> option_lhs.inner == option_rhs.inner, - .Tuple as tuple_lhs if rhs is .Tuple as tuple_rhs -> tuple_lhs == tuple_rhs, - .Variadic as variadic_lhs if rhs is .Variadic as variadic_rhs -> + .Tuple(tuple_lhs) if rhs is .Tuple(tuple_rhs) -> tuple_lhs == tuple_rhs, + .Variadic(variadic_lhs) if rhs is .Variadic(variadic_rhs) -> variadic_lhs.inner == variadic_rhs.inner, - .DynArray as dyn_array_lhs if rhs is .DynArray as dyn_array_rhs -> + .DynArray(dyn_array_lhs) if rhs is .DynArray(dyn_array_rhs) -> dyn_array_lhs.inner == dyn_array_rhs.inner and dyn_array_lhs.is_mut == dyn_array_rhs.is_mut, - .Array as array_lhs if rhs is .Array as array_rhs -> + .Array(array_lhs) if rhs is .Array(array_rhs) -> array_lhs.inner == array_rhs.inner and array_lhs.size_value == array_rhs.size_value and array_lhs.is_mut == array_rhs.is_mut, - .Pointer as ptr_lhs if rhs is .Pointer as ptr_rhs -> if ptr_lhs.is_mut + .Pointer(ptr_lhs) if rhs is .Pointer(ptr_rhs) -> if ptr_lhs.is_mut and !ptr_rhs.is_mut { false } else if ptr_lhs.is_indexable and !ptr_rhs.is_indexable { @@ -276,7 +276,7 @@ pub enum Type < traits.Stringable { ptr_lhs.inner == ptr_rhs.inner }, .Rawptr if rhs is .Rawptr -> true, - .Func as func_lhs if rhs is .Func as func_rhs -> match { + .Func(func_lhs) if rhs is .Func(func_rhs) -> match { func_lhs.is_method != func_rhs.is_method, func_lhs.self_is_mut != func_rhs.self_is_mut, func_lhs.self_is_ptr != func_rhs.self_is_ptr, @@ -297,7 +297,7 @@ pub enum Type < traits.Stringable { final_res } }, - .Basic as basic_lhs if rhs is .Basic as basic_rhs -> + .Basic(basic_lhs) if rhs is .Basic(basic_rhs) -> !(basic_lhs.is_unresolved and basic_rhs.is_unresolved) and basic_lhs.sym == basic_rhs.sym, else -> false @@ -321,9 +321,9 @@ pub enum Type < traits.Stringable { .None -> "", .Void -> "", .Never -> "never", - .Result as result -> "!".concat(result.inner.to_string_(qualstr)), - .Option as option -> "?".concat(option.inner.to_string_(qualstr)), - .Tuple as tuple_data -> { + .Result(result) -> "!".concat(result.inner.to_string_(qualstr)), + .Option(option) -> "?".concat(option.inner.to_string_(qualstr)), + .Tuple(tuple_data) -> { mut sb := Builder.new(100); sb.write_byte(b'('); for i, inner in tuple_data.inners { @@ -335,20 +335,20 @@ pub enum Type < traits.Stringable { sb.write_byte(b')'); sb.to_string() }, - .Variadic as variadic_data -> "...".concat(variadic_data.inner.to_string_(qualstr)), - .DynArray as dyn_array_data -> if dyn_array_data.is_mut { + .Variadic(variadic_data) -> "...".concat(variadic_data.inner.to_string_(qualstr)), + .DynArray(dyn_array_data) -> if dyn_array_data.is_mut { "[]mut" } else { "[]" }.concat(dyn_array_data.inner.to_string_(qualstr)), - .Array as array_data -> "[".concat( + .Array(array_data) -> "[".concat( array_data.size.to_string(), "]", if array_data.is_mut { "mut " } else { "" }, array_data.inner.to_string_(qualstr) ), - .Pointer as pointer_data -> { + .Pointer(pointer_data) -> { if pointer_data.is_mut { if pointer_data.is_indexable { "[&]mut " @@ -364,7 +364,7 @@ pub enum Type < traits.Stringable { }.concat(pointer_data.inner.to_string_(qualstr)) }, .Rawptr -> "rawptr", - .Func as func_data -> { + .Func(func_data) -> { mut sb := Builder.new(150); sb.write_string("func("); if func_data.is_method { @@ -391,7 +391,7 @@ pub enum Type < traits.Stringable { } sb.to_string() }, - .Basic as basic -> if basic.is_unresolved { + .Basic(basic) -> if basic.is_unresolved { basic.expr.to_string() } else if qualstr { basic.sym.qualname() diff --git a/lib/rivet/src/ast/TypeInfo.ri b/lib/rivet/src/ast/TypeInfo.ri index 28d63fbed..9cbc1d282 100644 --- a/lib/rivet/src/ast/TypeInfo.ri +++ b/lib/rivet/src/ast/TypeInfo.ri @@ -133,8 +133,8 @@ pub enum TypeInfo < traits.Stringable { #[inline] pub func elem_type(self) -> ?Type { return match self is { - .Array as arr -> arr.elem_type, - .DynArray as vec -> vec.elem_type, + .Array(arr) -> arr.elem_type, + .DynArray(vec) -> vec.elem_type, else -> none }; } @@ -142,8 +142,8 @@ pub enum TypeInfo < traits.Stringable { #[inline] pub func is_mut_arr_or_vec(self) -> bool { return match self is { - .Array as arr -> arr.is_mut, - .DynArray as vec -> vec.is_mut, + .Array(arr) -> arr.is_mut, + .DynArray(vec) -> vec.is_mut, else -> false }; } @@ -169,12 +169,12 @@ pub enum TypeInfo < traits.Stringable { .Bool -> "bool", .Rune -> "rune", .Int -> "int", - .SizedInt as int_info -> "int{}".fmt(int_info.size), + .SizedInt(int_info) -> "int{}".fmt(int_info.size), .Uint -> "uint", - .SizedUint as uint_info -> "uint{}".fmt(uint_info.size), + .SizedUint(uint_info) -> "uint{}".fmt(uint_info.size), .ComptimeInt -> "comptime_int", .ComptimeFloat -> "comptime_float", - .Float as float_info -> "float{}".fmt(float_info.size), + .Float(float_info) -> "float{}".fmt(float_info.size), .String -> "string", .Func -> "func", .Alias -> "alias", @@ -182,7 +182,7 @@ pub enum TypeInfo < traits.Stringable { .DynArray -> "dynamic array", .Tuple -> "tuple", .Trait -> "trait", - .Struct as struct_info -> if struct_info.is_enum_variant { + .Struct(struct_info) -> if struct_info.is_enum_variant { "enum variant" } else { "struct" diff --git a/lib/rivet/src/ast/TypeSym.ri b/lib/rivet/src/ast/TypeSym.ri index 46b96fd90..94711d798 100644 --- a/lib/rivet/src/ast/TypeSym.ri +++ b/lib/rivet/src/ast/TypeSym.ri @@ -28,13 +28,13 @@ pub struct TypeSym < Sym { return f; } } - if self.info is .Trait as trait_info { + if self.info is .Trait(trait_info) { for b in trait_info.bases { if f := b.lookup_field(name) { return f; } } - } else if self.info is .Struct as struct_info { + } else if self.info is .Struct(struct_info) { for t in struct_info.traits { if f := t.lookup_field(name) { return f; @@ -64,13 +64,13 @@ pub struct TypeSym < Sym { } pub func find_in_base(self, name: string) -> ?Sym { - if self.info is .Trait as trait_info { + if self.info is .Trait(trait_info) { for b in trait_info.bases { if s := b.scope.find(name) { return s; } } - } else if self.info is .Struct as struct_info { + } else if self.info is .Struct(struct_info) { for t in struct_info.traits { if s := t.scope.find(name) { return s; @@ -81,7 +81,7 @@ pub struct TypeSym < Sym { return s; } } - } else if self.info is .Enum as enum_info { + } else if self.info is .Enum(enum_info) { for t in enum_info.traits { if s := t.scope.find(name) { return s; @@ -132,13 +132,13 @@ pub struct TypeSym < Sym { return self.full_fields_; } mut fields := @dyn_array(Field); - if self.info is .Trait as trait_info { + if self.info is .Trait(trait_info) { for mut b in trait_info.bases { for bf in b.full_fields() { fields.push(bf); } } - } else if self.info is .Struct as struct_info { + } else if self.info is .Struct(struct_info) { for mut t in struct_info.traits { for tf in t.full_fields() { fields.push(tf); @@ -159,7 +159,7 @@ pub struct TypeSym < Sym { #[inline] pub func implement_trait(self, trait_sym: TypeSym) -> bool { - return if trait_sym.info is .Trait as trait_info { + return if trait_sym.info is .Trait(trait_info) { self in trait_info.implements } else { false @@ -184,9 +184,9 @@ pub struct TypeSym < Sym { #[inline] pub func is_boxed(self) -> bool { - return if self.info is .Enum as enum_info { + return if self.info is .Enum(enum_info) { enum_info.is_boxed - } else if self.info is .Struct as struct_info { + } else if self.info is .Struct(struct_info) { struct_info.is_boxed } else { self.info is .Trait or self.info is .String or self.info is .DynArray diff --git a/lib/rivet/src/checker/builtin_call.ri b/lib/rivet/src/checker/builtin_call.ri index d0e1148d7..dfa6ecdb0 100644 --- a/lib/rivet/src/checker/builtin_call.ri +++ b/lib/rivet/src/checker/builtin_call.ri @@ -7,7 +7,7 @@ import ../report; extend Checker { func check_builtin_call(mut self, mut builtin_call: ast.Expr.BuiltinCall) -> ast.Type { - builtin_call.type = if builtin_call.builtin is .Func as b_func { + builtin_call.type = if builtin_call.builtin is .Func(b_func) { if b_func.is_unsafe and !self.inside_unsafe() { report.warn( "builtin function `{}` should be called inside `unsafe` block".fmt( @@ -57,7 +57,7 @@ extend Checker { mut return_type := b_func.type; for check in b_func.checks { match check is { - .ArgumentTypeEqualToArgumentType as at -> { + .ArgumentTypeEqualToArgumentType(at) -> { arg1 := builtin_call.args[at.arg1_idx]; arg2 := builtin_call.args[at.arg2_idx]; if arg2.type != arg1.type { @@ -72,7 +72,7 @@ extend Checker { err2.emit(); } }, - .ArgumentTypeShouldBe as ats -> { + .ArgumentTypeShouldBe(ats) -> { arg := builtin_call.args[ats.arg_idx]; match ats.type { .Enum -> if ts := arg.type.symbol(); ts.info !is .Enum { @@ -90,13 +90,13 @@ extend Checker { else -> {} } }, - .ReturnTypeEqualToArgumentType as arg_idx -> + .ReturnTypeEqualToArgumentType(arg_idx) -> return_type = builtin_call.args[arg_idx].type } } match b_func.name { "as" -> self.check_builtin_as(builtin_call), - "dyn_array" if builtin_call.args[0].expr is .Type as dyn_array_t -> + "dyn_array" if builtin_call.args[0].expr is .Type(dyn_array_t) -> return_type = .Basic(self.table.universe.add_or_get_dyn_array( dyn_array_t, builtin_call.dyn_array_is_mut )), @@ -130,13 +130,13 @@ extend Checker { } } else if from_ts := from_type.symbol() { match from_ts.info is { - .Trait as mut trait_info -> if to_ts := to_type.symbol() { + .Trait(mut trait_info) -> if to_ts := to_type.symbol() { if to_ts in trait_info.implements { trait_info.mark_has_objects(); return; } }, - .Enum as enum_info -> { + .Enum(enum_info) -> { if enum_info.is_boxed and enum_info.get_variant_by_type(to_type) is none { report.error( "cannot cast type `{}` to `{}`".fmt(from_type, to_type), @@ -164,7 +164,7 @@ extend Checker { } } match to_ts.info is { - .Enum as enum_info2 if !enum_info2.is_boxed -> { + .Enum(enum_info2) if !enum_info2.is_boxed -> { if self.table.is_int(to_type) and !self.inside_unsafe() { report.warn( "casting numbers to enums should be done inside `unsafe` blocks", diff --git a/lib/rivet/src/checker/call_expr.ri b/lib/rivet/src/checker/call_expr.ri index 98e96547d..1c568d847 100644 --- a/lib/rivet/src/checker/call_expr.ri +++ b/lib/rivet/src/checker/call_expr.ri @@ -11,8 +11,8 @@ extend Checker { call_expr.type = .Void(); mut left := call_expr.left; - inside_parens := if left is .Paren as paren - and paren.expr is .Selector as paren_selector and !paren_selector.is_path { + inside_parens := if left is .Paren(paren) + and paren.expr is .Selector(paren_selector) and !paren_selector.is_path { left = paren.expr; true } else { @@ -20,12 +20,12 @@ extend Checker { }; match left is { - .SelfTy as self_ty -> self.check_ctor_call(self_ty.sym, call_expr), - .Ident as ident if (ident.is_sym or ident.is_obj) -> match ident.sym is { - ast.TypeSym as mut type_sym if type_sym.info is .Trait + .SelfTy(self_ty) -> self.check_ctor_call(self_ty.sym, call_expr), + .Ident(ident) if (ident.is_sym or ident.is_obj) -> match ident.sym is { + ast.TypeSym(mut type_sym) if type_sym.info is .Trait or type_sym.info is .Struct or type_sym.info is .String or type_sym.info is .Enum -> self.check_ctor_call(type_sym, call_expr), - ast.Func as func_ -> { + ast.Func(func_) -> { call_expr.func_ = func_; if func_.is_main { report.error("cannot call to `main` function", ident.pos); @@ -35,7 +35,7 @@ extend Checker { }, else -> { ident_type := self.check_expr(left); - if ident_type is .Func as i_func { + if ident_type is .Func(i_func) { call_expr.is_closure = true; self.check_func_call(i_func.symbol(), call_expr); } else { @@ -47,20 +47,20 @@ extend Checker { } } }, - .Selector as selector -> if selector.is_path { + .Selector(selector) -> if selector.is_path { match selector.sym is { - ast.TypeSym as mut s_type_sym if s_type_sym.info is .Trait + ast.TypeSym(mut s_type_sym) if s_type_sym.info is .Trait or s_type_sym.info is .Struct or s_type_sym.info is .String or s_type_sym.info is .Enum -> self.check_ctor_call( s_type_sym, call_expr ), - ast.Func as s_func_ -> { + ast.Func(s_func_) -> { call_expr.func_ = s_func_; self.check_func_call(s_func_, call_expr); }, else -> { selector_type := self.check_expr(left); - if selector_type is .Func as s_func { + if selector_type is .Func(s_func) { call_expr.is_closure = true; self.check_func_call(s_func.symbol(), call_expr); } else { @@ -91,7 +91,7 @@ extend Checker { self.check_func_call(method, call_expr); } } else if field := left_sym.lookup_field(selector.field_name) { - if field.type is .Func as f_func { + if field.type is .Func(f_func) { if inside_parens { call_expr.is_closure = true; selector.field_type = field.type; @@ -131,7 +131,7 @@ extend Checker { ); } }, - .EnumLiteral as enum_lit -> { + .EnumLiteral(enum_lit) -> { enum_lit.is_instance = true; _ = self.check_expr(left); self.check_ctor_call(enum_lit.sym, call_expr); @@ -141,7 +141,7 @@ extend Checker { // result checking if call_expr.has_err_handler() { - if call_expr.type is .Result as result_t { + if call_expr.type is .Result(result_t) { if call_expr.err_handler.is_propagate { if !(self.cur_fn.is_main or self.inside_test or self.inside_var_decl or self.cur_fn.ret_type is .Result) { @@ -195,7 +195,7 @@ extend Checker { func check_ctor_call(mut self, mut type_sym: ast.TypeSym, mut call_expr: ast.Expr.Call) { call_expr.is_constructor = true; - call_expr.type = if type_sym.info is .Struct as struct_info and struct_info.is_enum_variant { + call_expr.type = if type_sym.info is .Struct(struct_info) and struct_info.is_enum_variant { call_expr.is_enum_variant = true; call_expr.enum_variant_sym = type_sym; .Basic(struct_info.parent) @@ -203,8 +203,8 @@ extend Checker { .Basic(type_sym, pos: call_expr.pos) }; match type_sym.info is { - .Enum as enum_info -> { - variant := if call_expr.left is .Selector as selector { + .Enum(enum_info) -> { + variant := if call_expr.left is .Selector(selector) { @as(ast.TypeInfo.Enum, @as(ast.TypeSym, selector.left_sym).info) .get_variant(selector.field_name)? } else { @@ -236,7 +236,7 @@ extend Checker { } } else if variant.has_type and !( variant.has_fields or ( - call_expr.left is .EnumLiteral as enum_lit and enum_lit.from_is_cmp + call_expr.left is .EnumLiteral(enum_lit) and enum_lit.from_is_cmp ) ) { report.error("`{}` expects a value".fmt(call_expr.left), call_expr.pos); @@ -249,7 +249,7 @@ extend Checker { ); } }, - .Trait as mut trait_info -> { + .Trait(mut trait_info) -> { if call_expr.has_spread_expr { report.error( "cannot use spread expression with trait constructor", call_expr.pos @@ -356,7 +356,7 @@ extend Checker { field.name, type_sym.name ), call_expr.pos ), - .Enum as enum_info2 if enum_info2.is_boxed and !was_initted -> + .Enum(enum_info2) if enum_info2.is_boxed and !was_initted -> report.warn( "field `{}` of type `{}` must be initialized".fmt( field.name, type_sym.name @@ -469,7 +469,7 @@ extend Checker { func_.args[i] }; - self.expected_type = if arg_fn.type is .Variadic as variadic { + self.expected_type = if arg_fn.type is .Variadic(variadic) { variadic.inner } else { arg_fn.type diff --git a/lib/rivet/src/checker/check_trait_impl.ri b/lib/rivet/src/checker/check_trait_impl.ri index 7343e2ed8..42a846719 100644 --- a/lib/rivet/src/checker/check_trait_impl.ri +++ b/lib/rivet/src/checker/check_trait_impl.ri @@ -10,7 +10,7 @@ extend Checker { func check_trait_impl(mut self, impltor: ast.TypeSym, trait_sym: ast.TypeSym, pos: token.Pos) { mut impl_does_not_implemented := @dyn_array(string); for sym in trait_sym.scope.syms { - if sym is ast.Func as trait_func { + if sym is ast.Func(trait_func) { if impl := impltor.find_func(trait_func.name); !trait_func.has_body { mut errors := @dyn_array(string); if !impl.is_public { diff --git a/lib/rivet/src/checker/decls.ri b/lib/rivet/src/checker/decls.ri index e580935b3..808fca24b 100644 --- a/lib/rivet/src/checker/decls.ri +++ b/lib/rivet/src/checker/decls.ri @@ -30,7 +30,7 @@ extend Checker { old_sym := self.sym; defer self.sym = old_sym; match decl is { - .Import as import_decl -> if import_decl.import_list.is_empty() and !import_decl.glob { + .Import(import_decl) -> if import_decl.import_list.is_empty() and !import_decl.glob { if import_decl.has_custom_alias { self.check_name_case( .Snake, "import alias", import_decl.alias_name, import_decl.pos @@ -46,8 +46,8 @@ extend Checker { ); } }, - .Alias as alias_decl -> { - alias_sym := if alias_decl.sym is ast.SymRef as sym_ref { sym_ref.ref } else { alias_decl.sym }; + .Alias(alias_decl) -> { + alias_sym := if alias_decl.sym is ast.SymRef(sym_ref) { sym_ref.ref } else { alias_decl.sym }; self.check_name_case(match { alias_decl.is_typealias or alias_sym is ast.TypeSym -> .Pascal, alias_sym is ast.Const -> .Upper, @@ -55,19 +55,19 @@ extend Checker { }, "alias", alias_decl.name, alias_decl.pos ); }, - .Extern as extern_decl -> { + .Extern(extern_decl) -> { self.inside_extern = true; self.check_decls(extern_decl.decls); self.inside_extern = false; }, - .Var as var_decl -> { + .Var(var_decl) -> { self.inside_var_decl = true; self.check_var_decl( var_decl.lefts, var_decl.right, var_decl.scope, var_decl.pos ); self.inside_var_decl = false; }, - .Const as const_decl -> { + .Const(const_decl) -> { self.check_name_case(.Upper, "constant", const_decl.name, const_decl.pos); if const_decl.has_type { old_expected_type := self.expected_type; @@ -95,11 +95,11 @@ extend Checker { } } }, - .Trait as trait_decl -> { + .Trait(trait_decl) -> { self.check_name_case(.Pascal, "trait", trait_decl.name, trait_decl.pos); self.check_decls(trait_decl.decls); }, - .Enum as enum_decl -> { + .Enum(enum_decl) -> { self.check_name_case(.Pascal, "enum", enum_decl.name, enum_decl.pos); for base in enum_decl.bases { if sym := base.symbol() { @@ -116,7 +116,7 @@ extend Checker { } self.check_decls(enum_decl.decls); }, - .Struct as struct_decl -> { + .Struct(struct_decl) -> { self.check_name_case(.Pascal, "struct", struct_decl.name, struct_decl.pos); for base in struct_decl.bases { if sym := base.symbol() { @@ -129,7 +129,7 @@ extend Checker { } self.check_decls(struct_decl.decls); }, - .Field as field_decl -> { + .Field(field_decl) -> { self.check_name_case(.Snake, "field", field_decl.name, field_decl.pos); if field_decl.has_def_expr { old_expected_type := self.expected_type; @@ -141,7 +141,7 @@ extend Checker { }; } }, - .Extend as extend_decl -> { + .Extend(extend_decl) -> { type_sym := extend_decl.type.symbol()?; for base in extend_decl.bases { if sym := base.symbol() { @@ -152,8 +152,8 @@ extend Checker { } self.check_decls(extend_decl.decls); }, - .Func as mut func_decl -> self.check_func(func_decl), - .Test as test_decl -> { + .Func(mut func_decl) -> self.check_func(func_decl), + .Test(test_decl) -> { old_cur_fn := self.cur_fn; self.cur_fn = ast.Func(ret_type: .Void()); self.inside_test = true; @@ -245,13 +245,13 @@ extend Checker { if func_decl.ret_type is .Never and !self.inside_extern { if func_decl.stmts.len > 0 { match func_decl.stmts[func_decl.stmts.len - 1] is { - .While as while_stmt if while_stmt.is_inf - and while_stmt.stmt is .Expr as expr and expr is .Block as block -> { + .While(while_stmt) if while_stmt.is_inf + and while_stmt.stmt is .Expr(expr) and expr is .Block(block) -> { if !block.stmts.is_empty() { report.error("infinite loop should be empty", while_stmt.pos); } }, - .Expr as expr2 if expr2 is .Call as call_expr -> { + .Expr(expr2) if expr2 is .Call(call_expr) -> { if call_expr.type !is .Never { report.error( "`{}` is not a `never` function".fmt( @@ -260,9 +260,9 @@ extend Checker { ); } }, - .Expr as expr3 if expr3 is .Block as block1 and block1.stmts.len > 0 -> { + .Expr(expr3) if expr3 is .Block(block1) and block1.stmts.len > 0 -> { last_stmt := block1.stmts[block1.stmts.len - 1]; - if last_stmt is .Expr as last_expr and last_expr is .Call as call { + if last_stmt is .Expr(last_expr) and last_expr is .Call(call) { if call.type !is .Never { report.error( "`{}` is not a `never` function".fmt( diff --git a/lib/rivet/src/checker/exprs.ri b/lib/rivet/src/checker/exprs.ri index 7b5441ae6..b7fcdb86d 100644 --- a/lib/rivet/src/checker/exprs.ri +++ b/lib/rivet/src/checker/exprs.ri @@ -9,15 +9,15 @@ extend Checker { func check_expr(mut self, mut expr: ast.Expr) -> ast.Type { return match expr is { .Empty -> .Void(), - .Type as type -> type, - .Branch as branch -> { + .Type(type) -> type, + .Branch(branch) -> { self.scope_returns = true; .Never(branch.pos) }, - .Paren as paren -> self.check_expr(paren.expr), + .Paren(paren) -> self.check_expr(paren.expr), .NoneLiteral -> .None(), .BoolLiteral -> self.table.bool_t, - .CharLiteral as char_lit -> { + .CharLiteral(char_lit) -> { char_lit.type = if char_lit.is_byte { self.table.uint8_t } else { @@ -25,15 +25,15 @@ extend Checker { }; char_lit.type }, - .IntegerLiteral as int_lit -> { + .IntegerLiteral(int_lit) -> { int_lit.type = self.table.comptime_int_t; int_lit.type }, - .FloatLiteral as float_lit -> { + .FloatLiteral(float_lit) -> { float_lit.type = self.table.comptime_float_t; float_lit.type }, - .StringLiteral as string_lit -> { + .StringLiteral(string_lit) -> { string_lit.type = if string_lit.is_bytestr { .Basic(self.table.universe.add_or_get_array( self.table.uint8_t, string_lit.value.len, false @@ -45,14 +45,14 @@ extend Checker { }; string_lit.type }, - .SelfLiteral as self_lit -> { + .SelfLiteral(self_lit) -> { self_lit.type = self_lit.obj.type; self_lit.type }, .SelfTy -> .Void(), - .EnumLiteral as enum_lit -> { + .EnumLiteral(enum_lit) -> { enum_lit.type = .Void(); - if sym := self.expected_type.symbol(); sym.info is .Enum as enum_info { + if sym := self.expected_type.symbol(); sym.info is .Enum(enum_info) { if variant := enum_info.get_variant(enum_lit.value) { enum_lit.sym = sym; enum_lit.variant = variant; @@ -80,18 +80,18 @@ extend Checker { } enum_lit.type }, - .TupleLiteral as mut tuple_lit -> self.check_tuple_literal(tuple_lit), - .DynArrayLiteral as mut dyn_array_lit -> self.check_dyn_array_literal(dyn_array_lit), - .Ident as ident -> { + .TupleLiteral(mut tuple_lit) -> self.check_tuple_literal(tuple_lit), + .DynArrayLiteral(mut dyn_array_lit) -> self.check_dyn_array_literal(dyn_array_lit), + .Ident(ident) -> { ident.type = if ident.name == "_" { .Void() } else if ident.is_comptime { ident.builtin.type() } else if ident.is_sym or ident.is_obj { match ident.sym is { - ast.Const as const_sym -> const_sym.type, - ast.Var as var_sym -> var_sym.type, - ast.Func as func_sym -> { + ast.Const(const_sym) -> const_sym.type, + ast.Var(var_sym) -> var_sym.type, + ast.Func(func_sym) -> { if func_sym.abi != .Rivet { mut err := report.error_builder( "cannot use an extern function as a value", ident.pos @@ -108,11 +108,11 @@ extend Checker { }; ident.type }, - .Selector as mut selector -> self.check_selector(selector), - .Indirect as indirect -> { + .Selector(mut selector) -> self.check_selector(selector), + .Indirect(indirect) -> { indirect.left_type = self.check_expr(indirect.left); indirect.type = if indirect.left_type.is_pointer() - or (indirect.left_type is .Pointer as ptr and !ptr.is_indexable) + or (indirect.left_type is .Pointer(ptr) and !ptr.is_indexable) or indirect.left_type is .Rawptr { indirect.is_mut = indirect.left_type.is_pointer(); indirect.left_type.ptr_or_ref_inner() @@ -124,7 +124,7 @@ extend Checker { err.add_help( "consider casting this to another pointer type, e.g. `*uint8`" ); - } else if indirect.left_type is .Pointer as ptr2 and ptr2.is_indexable { + } else if indirect.left_type is .Pointer(ptr2) and ptr2.is_indexable { err.add_help("use index access to element 0 instead"); } err.emit(); @@ -132,9 +132,9 @@ extend Checker { }; indirect.type }, - .OptionCheck as option_check -> { + .OptionCheck(option_check) -> { option_check.left_type = self.check_expr(option_check.left); - option_check.type = if option_check.left_type is .Option as opt { + option_check.type = if option_check.left_type is .Option(opt) { opt.inner } else { report.error("cannot check a non-option value", option_check.left.position()); @@ -142,7 +142,7 @@ extend Checker { }; option_check.type }, - .Range as range -> { + .Range(range) -> { range.type = if range.has_start { self.check_expr(range.start) } else { @@ -158,10 +158,10 @@ extend Checker { } range.type }, - .Index as mut index -> self.check_index(index), - .Call as mut call_expr -> self.check_call(call_expr), - .BuiltinCall as mut builtin_call -> self.check_builtin_call(builtin_call), - .Block as block -> { + .Index(mut index) -> self.check_index(index), + .Call(mut call_expr) -> self.check_call(call_expr), + .BuiltinCall(mut builtin_call) -> self.check_builtin_call(builtin_call), + .Block(block) -> { self.defer_stmts_start = self.defer_stmts.len; if block.is_unsafe { if self.inside_unsafe_block { @@ -196,11 +196,11 @@ extend Checker { self.defer_stmts = self.defer_stmts[..self.defer_stmts_start]; block.type }, - .Unary as mut unary -> self.check_unary(unary), - .Binary as mut binary -> self.check_binary(binary), - .If as mut if_expr -> self.check_if(if_expr), - .Match as mut match_expr -> self.check_match(match_expr), - .Guard as guard -> { + .Unary(mut unary) -> self.check_unary(unary), + .Binary(mut binary) -> self.check_binary(binary), + .If(mut if_expr) -> self.check_if(if_expr), + .Match(mut match_expr) -> self.check_match(match_expr), + .Guard(guard) -> { old_inside_guard_expr := self.inside_guard_expr; self.inside_guard_expr = true; self.check_var_decl(guard.vars, guard.expr, guard.scope, guard.pos); @@ -213,9 +213,9 @@ extend Checker { self.inside_guard_expr = old_inside_guard_expr; .Void() }, - .Return as mut return_expr -> self.check_return(return_expr), - .Throw as mut throw_expr -> self.check_throw(throw_expr), - .Assign as mut assign -> self.check_assign(assign) + .Return(mut return_expr) -> self.check_return(return_expr), + .Throw(mut throw_expr) -> self.check_throw(throw_expr), + .Assign(mut assign) -> self.check_assign(assign) }; } @@ -223,7 +223,7 @@ extend Checker { old_expected_type := self.expected_type; mut has_expected_types := false; mut expected_types := @dyn_array(ast.Type); - if expected_type_sym := self.expected_type.symbol(); expected_type_sym.info is .Tuple as tuple_info { + if expected_type_sym := self.expected_type.symbol(); expected_type_sym.info is .Tuple(tuple_info) { has_expected_types = tuple_lit.values.len == tuple_info.types.len; expected_types = tuple_info.types; } @@ -260,7 +260,7 @@ extend Checker { has_expected_type = true; value_type = value_sym.info.elem_type()?; self.expected_type = value_type; - if value_sym.info is .Array as array_info { + if value_sym.info is .Array(array_info) { size = array_info.size; } is_mut = value_sym.info.is_mut_arr_or_vec(); @@ -310,11 +310,11 @@ extend Checker { func check_selector(mut self, mut selector: ast.Expr.Selector) -> ast.Type { selector.type = if selector.is_path { - if selector.left_sym is ast.TypeSym as type_sym { + if selector.left_sym is ast.TypeSym(type_sym) { .Basic(type_sym, pos: selector.pos) } else { match selector.sym is { - ast.Func as func_sym -> { + ast.Func(func_sym) -> { if func_sym.is_method { report.error( "cannot take value of method `{}`".fmt( @@ -324,9 +324,9 @@ extend Checker { } func_sym.type(self.table.universe) }, - ast.TypeSym as type_sym_ -> .Basic(type_sym_, pos: selector.pos), - ast.Const as const_sym -> const_sym.type, - ast.Var as var_sym -> var_sym.type, + ast.TypeSym(type_sym_) -> .Basic(type_sym_, pos: selector.pos), + ast.Const(const_sym) -> const_sym.type, + ast.Var(var_sym) -> var_sym.type, else -> { mut err := report.error_builder( "unexpected bug for selector expression", selector.pos @@ -345,7 +345,7 @@ extend Checker { selector.field_is_mut = field.is_mut; field.type } else if sym := left_sym.scope.find(selector.field_name) { - if sym is ast.Func as func_sym { + if sym is ast.Func(func_sym) { if func_sym.is_method { mut err := report.error_builder( "cannot take value of method `{}`".fmt(selector.field_name), @@ -437,7 +437,7 @@ extend Checker { ); err.add_note("only pointers, arrays, dynamic arrays and string supports indexing"); err.emit(); - } else if index.left_type is .Pointer as pointer { + } else if index.left_type is .Pointer(pointer) { if !self.inside_unsafe() { report.error( "pointer indexing is only allowed inside `unsafe` blocks", @@ -495,16 +495,16 @@ extend Checker { mut indexable_pointer := false; if self.expected_type is .Rawptr { expected_pointer = true; - } else if self.expected_type is .Pointer as ptr { + } else if self.expected_type is .Pointer(ptr) { expected_pointer = true; indexable_pointer = ptr.is_indexable; - } else if self.expected_type is .Option as opt - and opt.inner is .Pointer as opt_ptr { + } else if self.expected_type is .Option(opt) + and opt.inner is .Pointer(opt_ptr) { expected_pointer = true; indexable_pointer = opt_ptr.is_indexable; } right := unary.right.clean_paren(); - if right is .Index as index { + if right is .Index(index) { if index.left_type is .Pointer and !expected_pointer { report.error("cannot take the address of a pointer indexing", unary.pos); } @@ -586,7 +586,7 @@ extend Checker { return_type = promoted_type; }, .OrElse -> { - if left_type is .Option as opt { + if left_type is .Option(opt) { if !self.check_compatible_types(right_type, opt.inner) and right_type !is .Never { mut err := report.error_builder( @@ -615,7 +615,7 @@ extend Checker { elem_type := right_sym.info.elem_type()?; op_method := if binary.op == .KwIn { "==" } else { "!=" }; if !(left_sym.info.is_primitive() - or !(left_sym.info is .Enum as enum_info + or !(left_sym.info is .Enum(enum_info) and enum_info.is_boxed)) and !left_sym.has_method(op_method) { mut err := report.error_builder( @@ -655,7 +655,7 @@ extend Checker { self.check_name_case( .Snake, "variable", binary.var_obj.name, binary.var_obj.pos ); - if left_sym.info is .Enum as enum_info and enum_info.is_boxed { + if left_sym.info is .Enum(enum_info) and enum_info.is_boxed { variant := @as(ast.Expr.EnumLiteral, binary.right).variant; if variant.has_type { binary.var_obj.type = variant.type; @@ -675,7 +675,7 @@ extend Checker { binary.var_obj.sym.is_hidden_ref = true; } } - if left_sym.info is .Enum as enum_info { + if left_sym.info is .Enum(enum_info) { if enum_info.is_boxed and binary.op !in [.KwIs, .KwNotIs] { report.error( "boxed enum types only support `is` and `!is`", binary.pos @@ -700,7 +700,7 @@ extend Checker { "non-boolean expression in right operand for `{}`".fmt(binary.op), binary.left.position() ); - } else if binary.left is .Binary as bin_left { + } else if binary.left is .Binary(bin_left) { if bin_left.op != binary.op and bin_left.op in [.KwAnd, .KwOr] { // use `(a and b) or c` instead of `a and b or c` mut err := report.error_builder( @@ -803,7 +803,7 @@ extend Checker { ); } else { old_expected_type := self.expected_type; - self.expected_type = if self.cur_fn.ret_type is .Result as res_t { + self.expected_type = if self.cur_fn.ret_type is .Result(res_t) { res_t.inner } else { self.cur_fn.ret_type @@ -823,7 +823,7 @@ extend Checker { } } else if !( self.cur_fn.ret_type is .Void - or (self.cur_fn.ret_type is .Result as res_t and res_t.inner is .Void) + or (self.cur_fn.ret_type is .Result(res_t) and res_t.inner is .Void) ) { mut err := report.error_builder( "expected `{}` value in return argument".fmt(self.cur_fn.ret_type), @@ -882,7 +882,7 @@ extend Checker { self.expected_type = left_type; right_type := self.check_expr(assign.right); self.expected_type = old_expected_type; - if assign.left is .Ident as ident and ident.name == "_" { + if assign.left is .Ident(ident) and ident.name == "_" { return .Void(); } self.check_types(right_type, left_type) catch |err| { diff --git a/lib/rivet/src/checker/match_expr.ri b/lib/rivet/src/checker/match_expr.ri index 0efa628b6..683b693b8 100644 --- a/lib/rivet/src/checker/match_expr.ri +++ b/lib/rivet/src/checker/match_expr.ri @@ -36,7 +36,7 @@ extend Checker { } ast.TypeSym() }; - if match_expr.expr is .Guard as guard_expr { + if match_expr.expr is .Guard(guard_expr) { if guard_expr.vars.len == 1 { expr_type = guard_expr.vars[0].type; expr_sym = expr_type.symbol()?; @@ -56,7 +56,7 @@ extend Checker { ); err.add_note("expected enum or trait type, found `{}`", expr_type); err.emit(); - } else if expr_sym.info is .Enum as enum_info { + } else if expr_sym.info is .Enum(enum_info) { if enum_info.is_boxed and !match_expr.is_typematch { mut err := report.error_builder( "cannot use `match` with a non-boxed enum type", match_expr.pos @@ -174,7 +174,7 @@ extend Checker { unhandled.push("`{}`".fmt(v)); } } - } else if expr_sym.info is .Enum as enum_info2 { + } else if expr_sym.info is .Enum(enum_info2) { for variant in enum_info2.variants { e := ".".concat(variant.name); if !branch_exprs.contains(e) { diff --git a/lib/rivet/src/checker/mod.ri b/lib/rivet/src/checker/mod.ri index a32065f9a..4af05b078 100644 --- a/lib/rivet/src/checker/mod.ri +++ b/lib/rivet/src/checker/mod.ri @@ -59,9 +59,9 @@ pub struct Checker { } // check global mutable variables for sym in self.table.universe.scope.syms { - if sym is ast.Module as module { + if sym is ast.Module(module) { for mod_sym in module.scope.syms { - if mod_sym is ast.Var as mod_var { + if mod_sym is ast.Var(mod_var) { if !mod_var.is_public and mod_var.is_mut and !mod_var.is_changed { report.warn( "variable `{}` does not need to be mutable".fmt(mod_var.name), @@ -107,9 +107,9 @@ pub struct Checker { } mut right_type := self.check_expr(right); if self.inside_guard_expr { - right_type = if right_type is .Result as result_t { + right_type = if right_type is .Result(result_t) { result_t.inner - } else if right_type is .Option as option_t { + } else if right_type is .Option(option_t) { option_t.inner } else { report.error("expected result or option value", right.position()); @@ -134,9 +134,9 @@ pub struct Checker { } else { mut right_type := self.check_expr(right); if self.inside_guard_expr { - right_type = if right_type is .Result as result_t { + right_type = if right_type is .Result(result_t) { result_t.inner - } else if right_type is .Option as option_t { + } else if right_type is .Option(option_t) { option_t.inner } else { report.error("expected result or option value", right.position()); @@ -144,7 +144,7 @@ pub struct Checker { }; } right_sym := right_type.symbol()?; - if right_sym.info is .Tuple as tuple_info { + if right_sym.info is .Tuple(tuple_info) { if tuple_info.types.len == lefts.len { for i, vd in lefts { if vd.name == "_" and vd.is_mut { @@ -200,7 +200,7 @@ pub struct Checker { func check_scope_vars(self, scope: ast.Scope) { if !self.inside_extern { for sym in scope.syms { - if sym is ast.Var as var_info { + if sym is ast.Var(var_info) { if !var_info.is_used and !var_info.name.starts_with("_") { mut warn_b := report.warn_builder( if var_info.level == .Receiver { @@ -254,8 +254,8 @@ pub struct Checker { from_selector: bool := false ) { match expr is { - .Paren as paren -> self.check_expr_is_mut(paren.expr), - .SelfLiteral as self_lit -> if self_lit.obj.is_mut { + .Paren(paren) -> self.check_expr_is_mut(paren.expr), + .SelfLiteral(self_lit) -> if self_lit.obj.is_mut { self_lit.obj.is_changed = true; } else { mut err := report.error_builder( @@ -264,7 +264,7 @@ pub struct Checker { err.add_help("consider making `self` as mutable: `mut self`"); err.emit(); }, - .Ident as ident -> if ident.is_comptime { + .Ident(ident) -> if ident.is_comptime { report.error( "cannot use constant `@{}` as mutable value".fmt(ident.name), ident.pos @@ -274,13 +274,13 @@ pub struct Checker { } else if ident.found and (ident.is_sym or ident.is_obj) { self.check_sym_is_mut(ident.sym, ident.pos, from_selector); }, - .Selector as selector -> if selector.is_path { + .Selector(selector) -> if selector.is_path { self.check_sym_is_mut(selector.sym, selector.pos, true); } else { match selector.left is { - .Ident as ident2 if ident2.found -> if ident2.is_sym { + .Ident(ident2) if ident2.found -> if ident2.is_sym { self.check_sym_is_mut(ident2.sym, ident2.pos, true) - } else if ident2.sym is ast.Var as i_var and i_var.level == .Argument { + } else if ident2.sym is ast.Var(i_var) and i_var.level == .Argument { if i_var.is_mut { i_var.is_changed = true; } else { @@ -305,32 +305,32 @@ pub struct Checker { ); } }, - .Indirect as indirect -> if !indirect.is_mut { + .Indirect(indirect) -> if !indirect.is_mut { report.error("cannot use a immutable pointer as mutable value", selector.pos); }, - .OptionCheck as option_check -> self.check_expr_is_mut(option_check.left), + .OptionCheck(option_check) -> self.check_expr_is_mut(option_check.left), .NoneLiteral -> report.error("`none` cannot be modified", expr.position()), .StringLiteral -> report.error( "string literals cannot be modified", expr.position() ), - .TupleLiteral as tuple_lit -> if from_assign { + .TupleLiteral(tuple_lit) -> if from_assign { for value in tuple_lit.values { self.check_expr_is_mut(value); } } else { report.error("tuple literals cannot be modified", tuple_lit.pos); }, - .EnumLiteral as enum_lit if !enum_lit.is_instance -> report.error( + .EnumLiteral(enum_lit) if !enum_lit.is_instance -> report.error( "enum literals cannot be modified", enum_lit.pos ), - .BuiltinCall as builtin_call -> { + .BuiltinCall(builtin_call) -> { for arg in builtin_call.args { self.check_expr_is_mut(arg.expr); } }, - .Block as block if block.is_expr -> self.check_expr_is_mut(block.expr), - .Index as index -> { - if index.left_type is .Pointer as ptr { + .Block(block) if block.is_expr -> self.check_expr_is_mut(block.expr), + .Index(index) -> { + if index.left_type is .Pointer(ptr) { if !ptr.is_mut { report.error( "cannot modify elements of an immutable pointer", index.pos @@ -346,17 +346,17 @@ pub struct Checker { ); } }, - .Unary as unary -> self.check_expr_is_mut(unary.right), - .Binary as binary -> { + .Unary(unary) -> self.check_expr_is_mut(unary.right), + .Binary(binary) -> { self.check_expr_is_mut(binary.left); self.check_expr_is_mut(binary.right); }, - .If as if_expr -> { + .If(if_expr) -> { for branch in if_expr.branches { self.check_expr_is_mut(branch.expr); } }, - .Match as match_expr -> { + .Match(match_expr) -> { for branch in match_expr.branches { self.check_expr_is_mut(branch.expr); } @@ -371,7 +371,7 @@ pub struct Checker { ast.Const -> report.error( "cannot use constant `{}` as mutable value".fmt(sym.name), pos ), - ast.Var as var_info if !(from_selector and var_info.level == .Local) -> { + ast.Var(var_info) if !(from_selector and var_info.level == .Local) -> { if var_info.is_mut { var_info.is_changed = true; } else { @@ -402,8 +402,8 @@ pub struct Checker { func check_expr_evaluated_but_not_used(self, expr_type: ast.Type, pos: token.Pos) { _ = self; - if !((expr_type is .Result as res and !res.inner.is_void()) - or (expr_type is .Option as opt and !opt.inner.is_void()) + if !((expr_type is .Result(res) and !res.inner.is_void()) + or (expr_type is .Option(opt) and !opt.inner.is_void()) or expr_type.is_void()) { report.warn("expression evaluated but not used", pos); } @@ -411,7 +411,7 @@ pub struct Checker { func has_return(self, stmts: []ast.Stmt, allow_throw: bool := false) -> bool { for stmt in stmts { - if stmt is .Expr as expr and self.expr_has_return(expr, allow_throw) { + if stmt is .Expr(expr) and self.expr_has_return(expr, allow_throw) { return true; } } @@ -420,7 +420,7 @@ pub struct Checker { func expr_has_return(self, expr: ast.Expr, allow_throw: bool := false) -> bool { return match expr is { - .Match as match_expr -> { + .Match(match_expr) -> { for i, branch in match_expr.branches { if match_expr.is_exhaustive and i == match_expr.branches.len { if self.expr_has_return(branch.expr, allow_throw) { @@ -432,7 +432,7 @@ pub struct Checker { } false }, - .If as if_expr -> { + .If(if_expr) -> { for branch in if_expr.branches { if branch.is_else and self.expr_has_return(branch.expr, allow_throw) { return true; @@ -440,8 +440,8 @@ pub struct Checker { } false }, - .Call as call_expr -> call_expr.type is .Never, - .Block as block -> self.has_return(block.stmts, allow_throw), + .Call(call_expr) -> call_expr.type is .Never, + .Block(block) -> self.has_return(block.stmts, allow_throw), .Return -> true, .Throw if allow_throw -> true, else -> false diff --git a/lib/rivet/src/checker/stmts.ri b/lib/rivet/src/checker/stmts.ri index 05d8cdeaf..54cb402e1 100644 --- a/lib/rivet/src/checker/stmts.ri +++ b/lib/rivet/src/checker/stmts.ri @@ -23,11 +23,11 @@ extend Checker { func check_stmt(mut self, mut stmt: ast.Stmt) { match stmt is { - .VarDecl as var_decl -> self.check_var_decl( + .VarDecl(var_decl) -> self.check_var_decl( var_decl.lefts, var_decl.right, var_decl.scope, var_decl.pos ), - .For as mut for_stmt -> self.check_for(for_stmt), - .While as while_stmt -> { + .For(mut for_stmt) -> self.check_for(for_stmt), + .While(while_stmt) -> { if !while_stmt.is_inf and self.check_expr( while_stmt.cond ) != self.table.bool_t { @@ -46,7 +46,7 @@ extend Checker { self.check_stmt(while_stmt.else_stmt); } }, - .Defer as defer_stmt -> { + .Defer(defer_stmt) -> { if self.cur_fn.ret_type is .Never { report.error("`never` functions cannot use `defer` statements", defer_stmt.pos); } @@ -57,7 +57,7 @@ extend Checker { self.defer_stmts.push(defer_stmt); self.inside_defer = false; }, - .Expr as mut expr -> self.check_expr_evaluated_but_not_used( + .Expr(mut expr) -> self.check_expr_evaluated_but_not_used( self.check_expr(expr), expr.position() ), else -> {} diff --git a/lib/rivet/src/checker/types.ri b/lib/rivet/src/checker/types.ri index 10be358f9..9696107a7 100644 --- a/lib/rivet/src/checker/types.ri +++ b/lib/rivet/src/checker/types.ri @@ -20,7 +20,7 @@ extend Checker { self, got: ast.Type, expected: ast.Type, pos: token.Pos, arg_name: string, func_kind: string, func_name: string ) { - if expected_sym := expected.symbol(); expected_sym.info is .Trait as mut trait_info + if expected_sym := expected.symbol(); expected_sym.info is .Trait(mut trait_info) and expected != got { got_t := self.table.comptime_number_to_type(got); if got_t.symbol()? in trait_info.implements { @@ -84,20 +84,20 @@ extend Checker { return true; } - if expected is .Result as result { + if expected is .Result(result) { return self.check_compatible_types(got, result.inner); } - if got is .Option as option and expected is .Pointer { + if got is .Option(option) and expected is .Pointer { return check_pointer(expected, option.inner); } else if got is .Option and expected !is .Option { return false; - } else if expected is .Option as option_ and got is .Option as option2 { + } else if expected is .Option(option_) and got is .Option(option2) { if option_.inner is .Pointer and option2.inner is .Pointer { return check_pointer(option_.inner, option2.inner); } return option_.inner == option2.inner; - } else if expected is .Option as option_2 and got !is .Option { + } else if expected is .Option(option_2) and got !is .Option { if got is .None { return true; } @@ -119,11 +119,11 @@ extend Checker { if expected is .Variadic { vec_info := @as(ast.TypeInfo.DynArray, expected_sym.info); - if got is .Variadic as variadic { + if got is .Variadic(variadic) { return vec_info.elem_type == variadic.inner; } elem_sym := vec_info.elem_type.symbol()?; - if got_sym.info is .Trait as trait_info and elem_sym in trait_info.bases { + if got_sym.info is .Trait(trait_info) and elem_sym in trait_info.bases { return true; } return self.check_compatible_types(got, vec_info.elem_type); @@ -131,7 +131,7 @@ extend Checker { if expected is .Func and got is .Func { return expected == got; - } else if expected is .DynArray as dyn_array_info and got is .DynArray as dyn_array_info2 { + } else if expected is .DynArray(dyn_array_info) and got is .DynArray(dyn_array_info2) { return dyn_array_info.inner == dyn_array_info2.inner; } @@ -149,27 +149,27 @@ extend Checker { } match expected_sym.info is { - .Trait as mut trait_info -> { + .Trait(mut trait_info) -> { got_sym2 := self.table.comptime_number_to_type(got).symbol()?; if got_sym2 in trait_info.implements { trait_info.mark_has_objects(); return true; } }, - .Array as array_info if got_sym.info is .Array as array_info2 -> { + .Array(array_info) if got_sym.info is .Array(array_info2) -> { if array_info.is_mut and !array_info2.is_mut { return false; } return array_info.elem_type == array_info2.elem_type and array_info.size == array_info2.size; }, - .DynArray as dyn_array_lhs if got_sym.info is .DynArray as dyn_array_rhs -> { + .DynArray(dyn_array_lhs) if got_sym.info is .DynArray(dyn_array_rhs) -> { if dyn_array_lhs.is_mut and !dyn_array_rhs.is_mut { return false; } return dyn_array_lhs.elem_type == dyn_array_rhs.elem_type; }, - .Tuple as tuple_lhs if got_sym.info is .Tuple as tuple_rhs -> { + .Tuple(tuple_lhs) if got_sym.info is .Tuple(tuple_rhs) -> { if tuple_lhs.types.len != tuple_rhs.types.len { return false; } @@ -257,7 +257,7 @@ func check_pointer(expected: ast.Type, got: ast.Type) -> bool { if expected is .Rawptr { // rawptr == &T, is valid return got is .Rawptr or got is .Pointer; - } else if expected is .Pointer as ptr and got is .Pointer as ptr2 { + } else if expected is .Pointer(ptr) and got is .Pointer(ptr2) { if ptr.is_mut and !ptr2.is_mut { return false; } diff --git a/lib/rivet/src/codegen/mod.ri b/lib/rivet/src/codegen/mod.ri index 1268ab1c4..b123fae43 100644 --- a/lib/rivet/src/codegen/mod.ri +++ b/lib/rivet/src/codegen/mod.ri @@ -103,7 +103,7 @@ pub struct Codegen { match type is { .Pointer(ptr) -> { mut inner := ptr.inner; - while (inner is .Pointer as inner_ptr) : inner = inner_ptr.inner { + while (inner is .Pointer(inner_ptr)) : inner = inner_ptr.inner { sb.write_string("ptr_"); if inner_ptr.is_mut { sb.write_string("mut_"); @@ -173,7 +173,7 @@ pub struct Codegen { } }, ast.TypeSym(type) -> match type.info is { - .Tuple as tuple_info -> { + .Tuple(tuple_info) -> { mut sb2 := strings.Builder.new(); sb2.write_string("Tuple_"); for i, ttype in tuple_info.types { diff --git a/lib/rivet/src/codegen/types.ri b/lib/rivet/src/codegen/types.ri index 4253bedba..7ff400eef 100644 --- a/lib/rivet/src/codegen/types.ri +++ b/lib/rivet/src/codegen/types.ri @@ -149,7 +149,7 @@ extend Codegen { ), .DynArray -> self.dyn_array_t, .Rawptr -> .Rawptr(self.table.pointer_size), - .Pointer as ptr_t -> .Pointer( + .Pointer(ptr_t) -> .Pointer( self.type_to_mir(ptr_t.inner), size: self.table.pointer_size ), else -> { diff --git a/lib/rivet/src/lib.ri b/lib/rivet/src/lib.ri index cbaebdbdc..c41c67885 100644 --- a/lib/rivet/src/lib.ri +++ b/lib/rivet/src/lib.ri @@ -123,7 +123,7 @@ pub struct Compiler { func import_modules(mut self) -> ! { for sf in self.table.source_files { for d in sf.decls { - if d is .Import as import_decl { + if d is .Import(import_decl) { if self.table.universe.scope.exists(import_decl.info.full_name) { continue; } @@ -307,7 +307,7 @@ pub struct Compiler { deps.push("core"); } for d in pf.decls { - if d is .Import as import_decl { + if d is .Import(import_decl) { if !import_decl.info.found { continue; // module not found } diff --git a/lib/rivet/src/parser/exprs.ri b/lib/rivet/src/parser/exprs.ri index 681340295..b0fef4a94 100644 --- a/lib/rivet/src/parser/exprs.ri +++ b/lib/rivet/src/parser/exprs.ri @@ -93,7 +93,7 @@ extend Parser { .Type(self.parse_type()) }; if self.accept(.Lparen) { - val := Expr.Binary( + val := ast.Expr.Binary( left: left, right: right, op: op, @@ -662,7 +662,7 @@ extend Parser { mut expr := ast.Expr.Empty(self.tok.pos); while !self.accept(.Rbrace) { stmt := self.parse_stmt(); - if stmt is .Expr as stmt_expr and self.prev_tok.kind != .Semicolon + if stmt is .Expr(stmt_expr) and self.prev_tok.kind != .Semicolon and self.tok.kind == .Rbrace { expr = stmt_expr; has_expr = true; diff --git a/lib/rivet/src/resolver/Register.ri b/lib/rivet/src/resolver/Register.ri index 2f442c70e..5f76f2052 100644 --- a/lib/rivet/src/resolver/Register.ri +++ b/lib/rivet/src/resolver/Register.ri @@ -39,12 +39,12 @@ pub struct Register { old_sym := self.sym; self.sym.scope.owner = self.sym; match decl is { - .Import as import_decl -> self.import_decl(import_decl), - .Extern as extern_decl -> { + .Import(import_decl) -> self.import_decl(import_decl), + .Extern(extern_decl) -> { self.abi = extern_decl.abi; self.walk_decls(extern_decl.decls); }, - .Alias as alias_decl -> alias_decl.sym = self.add_sym( + .Alias(alias_decl) -> alias_decl.sym = self.add_sym( if alias_decl.is_typealias { ast.TypeSym( parent: self.sym, @@ -62,7 +62,7 @@ pub struct Register { ) }, alias_decl.pos ), - .Trait as trait_decl -> { + .Trait(trait_decl) -> { trait_decl.sym = self.add_sym( ast.TypeSym( parent: self.sym, @@ -78,7 +78,7 @@ pub struct Register { self.sym = trait_decl.sym; self.walk_decls(trait_decl.decls); }, - .Struct as struct_decl -> { + .Struct(struct_decl) -> { struct_decl.sym = if self.is_core_mod and struct_decl.name == "string" { @as(ast.Type.Basic, self.table.string_t).sym } else { @@ -98,7 +98,7 @@ pub struct Register { self.sym = struct_decl.sym; self.walk_decls(struct_decl.decls); }, - .Enum as enum_decl -> { + .Enum(enum_decl) -> { info := ast.TypeInfo.Enum( underlying_type: enum_decl.underlying_type, is_boxed: enum_decl.is_boxed @@ -152,7 +152,7 @@ pub struct Register { self.sym = enum_decl.sym; self.walk_decls(enum_decl.decls); }, - .Field as field_decl -> { + .Field(field_decl) -> { type_sym := @as(ast.TypeSym, self.sym); if type_sym.has_field(field_decl.name) { report.error( @@ -172,7 +172,7 @@ pub struct Register { is_required: field_decl.attributes.has("required") )); }, - .Const as const_decl -> const_decl.sym = self.add_sym(ast.Const( + .Const(const_decl) -> const_decl.sym = self.add_sym(ast.Const( parent: self.sym, is_public: const_decl.is_public, abi: self.abi, @@ -180,7 +180,7 @@ pub struct Register { expr: const_decl.expr, type: const_decl.type ), const_decl.pos), - .Var as var_decl -> { + .Var(var_decl) -> { for left in var_decl.lefts { left.sym = ast.Var( parent: self.sym, @@ -197,9 +197,9 @@ pub struct Register { }; } }, - .Extend as extend_decl -> if extend_decl.type is .Basic as basic_type { + .Extend(extend_decl) -> if extend_decl.type is .Basic(basic_type) { if basic_type.is_unresolved { - if basic_type.expr is .Ident as ident { + if basic_type.expr is .Ident(ident) { self.sym = if type_sym := self.sym.scope.find(ident.name) { type_sym } else { @@ -237,7 +237,7 @@ pub struct Register { extend_decl.pos ); }, - .Func as func_decl -> func_decl.sym = self.add_sym(ast.Func( + .Func(func_decl) -> func_decl.sym = self.add_sym(ast.Func( parent: self.sym, abi: func_decl.abi, is_public: func_decl.is_public, diff --git a/lib/rivet/src/resolver/decls.ri b/lib/rivet/src/resolver/decls.ri index 80b7ffe04..e07187529 100644 --- a/lib/rivet/src/resolver/decls.ri +++ b/lib/rivet/src/resolver/decls.ri @@ -12,26 +12,26 @@ extend Resolver { old_self_sym := self.self_sym; old_self_sym_is_set := self.self_sym_is_set; match decl is { - .Empty as empty_pos -> report.error("BUG: empty declaration found", empty_pos), + .Empty(empty_pos) -> report.error("BUG: empty declaration found", empty_pos), .Import -> {}, - .Extern as extern_decl -> self.resolve_decls(extern_decl.decls), - .Alias as alias_decl -> if alias_decl.is_typealias { + .Extern(extern_decl) -> self.resolve_decls(extern_decl.decls), + .Alias(alias_decl) -> if alias_decl.is_typealias { _ = self.resolve_type(alias_decl.parent_type); } else { sym_ref := @as(ast.SymRef, alias_decl.sym); self.resolve_expr(sym_ref.ref_expr); - if sym_ref.ref_expr is .Ident as ident and ident.found and ident.is_sym { + if sym_ref.ref_expr is .Ident(ident) and ident.found and ident.is_sym { sym_ref.ref = ident.sym; sym_ref.ref_resolved = true; - } else if sym_ref.ref_expr is .Selector as selector and selector.found { + } else if sym_ref.ref_expr is .Selector(selector) and selector.found { sym_ref.ref = selector.sym; sym_ref.ref_resolved = true; } }, - .Const as const_decl -> if self.resolve_type(const_decl.type) { + .Const(const_decl) -> if self.resolve_type(const_decl.type) { self.resolve_expr(const_decl.expr); }, - .Var as var_decl -> { + .Var(var_decl) -> { for left in var_decl.lefts { self.check_variable_shadowing(left.name, left.pos); _ = self.resolve_type(left.type); @@ -40,17 +40,17 @@ extend Resolver { self.resolve_expr(var_decl.right); } }, - .Trait as trait_decl -> { + .Trait(trait_decl) -> { self.self_sym = @as(ast.TypeSym, trait_decl.sym); self.self_sym_is_set = true; trait_info := @as(ast.TypeInfo.Trait, self.self_sym.info); for mut base in trait_decl.bases { if self.resolve_type(base) { base_sym := base.symbol()?; - if base_sym.info is .Trait as mut base_trait_info { + if base_sym.info is .Trait(mut base_trait_info) { trait_info.bases.push(base_sym); for impl in base_trait_info.implements { - if impl.info is .Struct as struct_info { + if impl.info is .Struct(struct_info) { if !struct_info.contains_trait(base_sym) { base_trait_info.implement(impl); struct_info.traits.push(base_sym); @@ -71,7 +71,7 @@ extend Resolver { } self.resolve_decls(trait_decl.decls); }, - .Enum as enum_decl -> { + .Enum(enum_decl) -> { if enum_decl.is_boxed or self.resolve_type(enum_decl.underlying_type) { self.self_sym = @as(ast.TypeSym, enum_decl.sym); self.self_sym_is_set = true; @@ -84,7 +84,7 @@ extend Resolver { for mut base in enum_decl.bases { if self.resolve_type(base) { base_sym := base.symbol()?; - if base_sym.info is .Trait as mut trait_info { + if base_sym.info is .Trait(mut trait_info) { enum_info.traits.push(base_sym); trait_info.implement(self.self_sym); } else { @@ -111,17 +111,17 @@ extend Resolver { } self.resolve_decls(enum_decl.decls); }, - .Struct as struct_decl -> { + .Struct(struct_decl) -> { self.self_sym = @as(ast.TypeSym, struct_decl.sym); self.self_sym_is_set = true; for mut base in struct_decl.bases { if self.resolve_type(base) { struct_info := @as(ast.TypeInfo.Struct, self.self_sym.info); base_sym := base.symbol()?; - if base_sym.info is .Trait as mut trait_info { + if base_sym.info is .Trait(mut trait_info) { struct_info.traits.push(base_sym); trait_info.implement(self.self_sym); - } else if base_sym.info is .Struct as struct_info2 { + } else if base_sym.info is .Struct(struct_info2) { struct_info.bases.push(base_sym); for b_trait in struct_info2.traits { @as(ast.TypeInfo.Trait, b_trait.info).implement( @@ -139,15 +139,15 @@ extend Resolver { } self.resolve_decls(struct_decl.decls); }, - .Extend as extend_decl -> if self.resolve_type(extend_decl.type) { + .Extend(extend_decl) -> if self.resolve_type(extend_decl.type) { self.self_sym = extend_decl.type.symbol()?; self.self_sym_is_set = true; for mut base in extend_decl.bases { if self.resolve_type(base) { base_sym := base.symbol()?; - if base_sym.info is .Trait as mut trait_info { + if base_sym.info is .Trait(mut trait_info) { trait_info.implement(self.self_sym); - } else if self.self_sym.info is .Struct as struct_info + } else if self.self_sym.info is .Struct(struct_info) and base_sym.info is .Struct { struct_info.bases.push(base_sym); } else { @@ -161,11 +161,11 @@ extend Resolver { } self.resolve_decls(extend_decl.decls); }, - .Field as field_decl -> if self.resolve_type(field_decl.type) + .Field(field_decl) -> if self.resolve_type(field_decl.type) and field_decl.has_def_expr { self.resolve_expr(field_decl.def_expr); }, - .Func as func_decl -> { + .Func(func_decl) -> { if func_decl.is_method { mut self_type := ast.Type.Basic(self.self_sym); if func_decl.self_is_ptr { @@ -212,7 +212,7 @@ extend Resolver { self.resolve_stmt(stmt); } }, - .Test as test_decl -> { + .Test(test_decl) -> { for mut stmt in test_decl.stmts { self.resolve_stmt(stmt); } diff --git a/lib/rivet/src/resolver/exprs.ri b/lib/rivet/src/resolver/exprs.ri index ce4ecb2ca..c30506c9b 100644 --- a/lib/rivet/src/resolver/exprs.ri +++ b/lib/rivet/src/resolver/exprs.ri @@ -9,20 +9,20 @@ import ../report; extend Resolver { func resolve_expr(mut self, mut expr: ast.Expr) { match expr is { - .Empty as empty_pos -> report.error("BUG: empty expression found", empty_pos), - .Paren as paren -> self.resolve_expr(paren.expr), - .Type as mut type -> _ = self.resolve_type(type), - .Ident as mut ident -> self.resolve_ident(ident), - .Selector as mut selector -> self.resolve_selector(selector), - .Indirect as indirect -> self.resolve_expr(indirect.left), - .OptionCheck as option_check -> self.resolve_expr(option_check.left), - .SelfTy as self_ty -> if self.self_sym_is_set { + .Empty(empty_pos) -> report.error("BUG: empty expression found", empty_pos), + .Paren(paren) -> self.resolve_expr(paren.expr), + .Type(mut type) -> _ = self.resolve_type(type), + .Ident(mut ident) -> self.resolve_ident(ident), + .Selector(mut selector) -> self.resolve_selector(selector), + .Indirect(indirect) -> self.resolve_expr(indirect.left), + .OptionCheck(option_check) -> self.resolve_expr(option_check.left), + .SelfTy(self_ty) -> if self.self_sym_is_set { self_ty.sym = self.self_sym; self_ty.found = true; } else { report.error("cannot resolve `Self` expression", self_ty.pos); }, - .SelfLiteral as self_lit -> if self.self_sym_is_set { + .SelfLiteral(self_lit) -> if self.self_sym_is_set { self_lit.sym = self.self_sym; self_lit.found = true; self_lit.obj = @as(ast.Var, self_lit.scope.lookup("self")?); @@ -30,17 +30,17 @@ extend Resolver { } else { report.error("cannot resolve `self` expression", self_ty.pos); }, - .TupleLiteral as tuple_lit -> { + .TupleLiteral(tuple_lit) -> { for mut value in tuple_lit.values { self.resolve_expr(value); } }, - .DynArrayLiteral as dyn_array_lit -> { + .DynArrayLiteral(dyn_array_lit) -> { for mut value in dyn_array_lit.values { self.resolve_expr(value); } }, - .BuiltinCall as builtin_call -> { + .BuiltinCall(builtin_call) -> { if builtin := self.table.find_builtin(builtin_call.name) { if builtin is .Func { builtin_call.builtin = builtin; @@ -60,7 +60,7 @@ extend Resolver { ); } }, - .Call as call -> { + .Call(call) -> { self.resolve_expr(call.left); for arg in call.args { self.resolve_expr(arg.expr); @@ -86,8 +86,8 @@ extend Resolver { self.resolve_expr(call.err_handler.expr); } }, - .Unary as unary -> self.resolve_expr(unary.right), - .Binary as binary -> { + .Unary(unary) -> self.resolve_expr(unary.right), + .Binary(binary) -> { self.resolve_expr(binary.left); self.resolve_expr(binary.right); if binary.has_var_obj { @@ -104,7 +104,7 @@ extend Resolver { ); } }, - .Range as range -> { + .Range(range) -> { if range.has_start { self.resolve_expr(range.start); } @@ -112,11 +112,11 @@ extend Resolver { self.resolve_expr(range.end); } }, - .Index as index -> { + .Index(index) -> { self.resolve_expr(index.left); self.resolve_expr(index.index); }, - .Block as block -> { + .Block(block) -> { for mut stmt in block.stmts { self.resolve_stmt(stmt); } @@ -124,11 +124,11 @@ extend Resolver { self.resolve_expr(block.expr); } }, - .Return as return_expr -> if return_expr.has_expr { + .Return(return_expr) -> if return_expr.has_expr { self.resolve_expr(return_expr.expr); }, - .Throw as throw_expr -> self.resolve_expr(throw_expr.expr), - .Guard as guard -> { + .Throw(throw_expr) -> self.resolve_expr(throw_expr.expr), + .Guard(guard) -> { for var_ in guard.vars { self.check_variable_shadowing(var_.name, var_.pos); var_.sym = ast.Var( @@ -147,7 +147,7 @@ extend Resolver { self.resolve_expr(guard.cond); } }, - .If as if_expr -> { + .If(if_expr) -> { for branch in if_expr.branches { if !branch.is_else { self.resolve_expr(branch.cond); @@ -155,7 +155,7 @@ extend Resolver { self.resolve_expr(branch.expr); } }, - .Match as match_expr -> { + .Match(match_expr) -> { self.resolve_expr(match_expr.expr); for branch in match_expr.branches { if !branch.is_else { @@ -181,7 +181,7 @@ extend Resolver { self.resolve_expr(branch.expr); } }, - .Assign as assign_expr -> { + .Assign(assign_expr) -> { self.resolve_expr(assign_expr.left); self.resolve_expr(assign_expr.right); }, @@ -213,7 +213,7 @@ extend Resolver { ident.sym = obj; @as(ast.Var, obj).is_used = true; } else if imported := self.source_file.imported_symbols.find(ident.name) { - if !(imported.sym is ast.TypeSym as type_sym and type_sym.info is .Placeholder) { + if !(imported.sym is ast.TypeSym(type_sym) and type_sym.info is .Placeholder) { imported.is_used = true; ident.found = true; ident.is_sym = true; @@ -224,7 +224,7 @@ extend Resolver { ident.is_sym = true; ident.sym = sym; } else if sym := self.sym.scope.find(ident.name) { - if !(sym is ast.TypeSym as type_sym and type_sym.info is .Placeholder) { + if !(sym is ast.TypeSym(type_sym) and type_sym.info is .Placeholder) { ident.found = true; ident.is_sym = true; ident.sym = sym; @@ -243,7 +243,7 @@ extend Resolver { ident.sym = sym; } else if self.self_sym_is_set { if sym := self.self_sym.scope.find(ident.name) { - if !(sym is ast.TypeSym as type_sym and type_sym.info is .Placeholder) { + if !(sym is ast.TypeSym(type_sym) and type_sym.info is .Placeholder) { if sym is ast.Func { mut err := report.error_builder( "cannot find `{}` in this scope".fmt(ident.name), ident.pos @@ -260,7 +260,7 @@ extend Resolver { } if ident.found { - if ident.is_sym and ident.sym is ast.SymRef as mut sym_ref { + if ident.is_sym and ident.sym is ast.SymRef(mut sym_ref) { ident.sym = self.clean_symbol_reference(sym_ref); } self.check_symbol_abi(ident.sym, ident.pos); @@ -272,18 +272,18 @@ extend Resolver { func resolve_selector(mut self, mut selector: ast.Expr.Selector) { self.resolve_expr(selector.left); match selector.left is { - .SelfTy as self_ty if self_ty.found -> { + .SelfTy(self_ty) if self_ty.found -> { selector.is_path = true; selector.left_sym = self_ty.sym; }, - .Ident as ident if ident.found and ident.is_sym -> { + .Ident(ident) if ident.found and ident.is_sym -> { if ident.sym is ast.Var or ident.sym is ast.Const { return; } selector.is_path = true; selector.left_sym = ident.sym; }, - .Selector as selector2 if selector2.found and selector2.is_path -> { + .Selector(selector2) if selector2.found and selector2.is_path -> { if selector2.sym is ast.Var or selector2.sym is ast.Const { return; } @@ -305,17 +305,17 @@ extend Resolver { func find_symbol(mut self, sym: ast.Sym, name: string, pos: token.Pos) -> ?ast.Sym { mut sym_ := sym; - if sym is ast.SymRef as mut sym_ref { + if sym is ast.SymRef(mut sym_ref) { sym_ = self.clean_symbol_reference(sym_ref); } if s := sym_.scope.find(name) { self.check_vis(s, pos); - return if s is ast.SymRef as mut sym_ref2 { + return if s is ast.SymRef(mut sym_ref2) { self.clean_symbol_reference(sym_ref2) } else { s }; - } else if sym_ is ast.TypeSym as type_sym and type_sym.info is .Enum as enum_info { + } else if sym_ is ast.TypeSym(type_sym) and type_sym.info is .Enum(enum_info) { if enum_info.has_variant(name) { return sym_; } @@ -341,15 +341,15 @@ extend Resolver { func clean_symbol_reference(mut self, mut sym_ref: ast.SymRef) -> ast.Sym { if !sym_ref.ref_resolved { self.resolve_expr(sym_ref.ref_expr); - if sym_ref.ref_expr is .Ident as ident and ident.found and ident.is_sym { + if sym_ref.ref_expr is .Ident(ident) and ident.found and ident.is_sym { sym_ref.ref = ident.sym; sym_ref.ref_resolved = true; - } else if sym_ref.ref_expr is .Selector as selector and selector.found and + } else if sym_ref.ref_expr is .Selector(selector) and selector.found and selector.is_path { sym_ref.ref = selector.sym; sym_ref.ref_resolved = true; } - if sym_ref.ref is ast.SymRef as mut sym_ref2 { + if sym_ref.ref is ast.SymRef(mut sym_ref2) { sym_ref.ref = self.clean_symbol_reference(sym_ref2); } } diff --git a/lib/rivet/src/resolver/mod.ri b/lib/rivet/src/resolver/mod.ri index b9cb6e18b..51c93d9e0 100644 --- a/lib/rivet/src/resolver/mod.ri +++ b/lib/rivet/src/resolver/mod.ri @@ -68,9 +68,9 @@ pub struct Resolver { func eval_size(mut self, mut expr: ast.Expr) -> ?int { return match expr is { - .Paren as paren -> self.eval_size(paren.expr), - .IntegerLiteral as int_lit -> int_lit.value.to_int() catch return none, - .Ident as mut ident -> { + .Paren(paren) -> self.eval_size(paren.expr), + .IntegerLiteral(int_lit) -> int_lit.value.to_int() catch return none, + .Ident(mut ident) -> { self.resolve_ident(ident); if ident.found { self.eval_sym(ident.sym, ident.pos) @@ -78,7 +78,7 @@ pub struct Resolver { none } }, - .Selector as mut selector -> { + .Selector(mut selector) -> { self.resolve_selector(selector); if selector.found { self.eval_sym(selector.sym, selector.pos) @@ -86,7 +86,7 @@ pub struct Resolver { none } }, - .Binary as binary -> if left := self.eval_size(binary.left) { + .Binary(binary) -> if left := self.eval_size(binary.left) { if right := self.eval_size(binary.right) { match binary.op { .Plus -> left + right, @@ -107,8 +107,8 @@ pub struct Resolver { } else { none }, - .BuiltinCall as builtin_call if builtin_call.name in ["size_of", "align_of"] -> { - if builtin_call.args[0].expr is .Type as mut type and self.resolve_type(type) { + .BuiltinCall(builtin_call) if builtin_call.name in ["size_of", "align_of"] -> { + if builtin_call.args[0].expr is .Type(mut type) and self.resolve_type(type) { (size, align) := self.table.type_size(type); if builtin_call.name == "size_of" { @as(int, size) @@ -124,7 +124,7 @@ pub struct Resolver { } func eval_sym(mut self, sym: ast.Sym, pos: token.Pos) -> ?int { - if sym is ast.Const as const_ { + if sym is ast.Const(const_) { if !const_.has_evaled_size { const_.evaled_size = self.eval_size(const_.expr)?; } diff --git a/lib/rivet/src/resolver/stmts.ri b/lib/rivet/src/resolver/stmts.ri index 57d0b0fef..64ca1bc97 100644 --- a/lib/rivet/src/resolver/stmts.ri +++ b/lib/rivet/src/resolver/stmts.ri @@ -8,9 +8,9 @@ import ../report; extend Resolver { func resolve_stmt(mut self, mut stmt: ast.Stmt) { match stmt is { - .Empty as empty_pos -> report.error("BUG: empty statement found", empty_pos), - .Expr as mut expr -> self.resolve_expr(expr), - .VarDecl as var_stmt -> { + .Empty(empty_pos) -> report.error("BUG: empty statement found", empty_pos), + .Expr(mut expr) -> self.resolve_expr(expr), + .VarDecl(var_stmt) -> { for left in var_stmt.lefts { self.check_variable_shadowing(left.name, left.pos); _ = self.resolve_type(left.type); @@ -27,7 +27,7 @@ extend Resolver { } self.resolve_expr(var_stmt.right); }, - .While as while_stmt -> { + .While(while_stmt) -> { if !while_stmt.is_inf { self.resolve_expr(while_stmt.cond); } @@ -39,7 +39,7 @@ extend Resolver { self.resolve_stmt(while_stmt.else_stmt); } }, - .For as for_stmt -> { + .For(for_stmt) -> { if for_stmt.has_index { self.check_variable_shadowing(for_stmt.index.name, for_stmt.index.pos); for_stmt.index.sym = ast.Var( @@ -69,7 +69,7 @@ extend Resolver { self.resolve_expr(for_stmt.iterable); self.resolve_stmt(for_stmt.stmt); }, - .Defer as defer_stmt -> self.resolve_expr(defer_stmt.expr) + .Defer(defer_stmt) -> self.resolve_expr(defer_stmt.expr) } } } diff --git a/lib/rivet/src/resolver/types.ri b/lib/rivet/src/resolver/types.ri index 562fe0b99..208754fe1 100644 --- a/lib/rivet/src/resolver/types.ri +++ b/lib/rivet/src/resolver/types.ri @@ -9,11 +9,11 @@ extend Resolver { func resolve_type(mut self, mut type: ast.Type) -> bool { return match type is { .Void, .Never, .Rawptr -> true, - .Option as opt -> self.resolve_type(opt.inner), - .Result as res -> self.resolve_type(res.inner), - .Variadic as variadic -> if self.resolve_type(variadic.inner) { + .Option(opt) -> self.resolve_type(opt.inner), + .Result(res) -> self.resolve_type(res.inner), + .Variadic(variadic) -> if self.resolve_type(variadic.inner) { elem_sym := variadic.inner.symbol()?; - if elem_sym.info is .Trait as trait_info { + if elem_sym.info is .Trait(trait_info) { trait_info.has_objects = true; } variadic.sym = self.table.universe.add_or_get_dyn_array(variadic.inner, false); @@ -21,13 +21,13 @@ extend Resolver { } else { false }, - .DynArray as vec -> if self.resolve_type(vec.inner) { + .DynArray(vec) -> if self.resolve_type(vec.inner) { vec.sym = self.table.universe.add_or_get_dyn_array(vec.inner, vec.is_mut); true } else { false }, - .Array as arr -> if self.resolve_type(arr.inner) { + .Array(arr) -> if self.resolve_type(arr.inner) { if arr_size := self.eval_size(arr.size) { if arr_size <= 0 { mut err := report.error_builder( @@ -52,8 +52,8 @@ extend Resolver { } else { false }, - .Pointer as ptr -> self.resolve_type(ptr.inner), - .Tuple as tuple -> { + .Pointer(ptr) -> self.resolve_type(ptr.inner), + .Tuple(tuple) -> { mut resolved := false; for mut inner in tuple.inners { resolved = self.resolve_type(inner); @@ -63,7 +63,7 @@ extend Resolver { } resolved }, - .Func as func_t -> { + .Func(func_t) -> { mut res1 := false; for arg in func_t.args { res1 = self.resolve_type(arg.type); @@ -73,7 +73,7 @@ extend Resolver { func_t.has_sym = true; res1 }, - .Basic as basic -> if basic.is_unresolved { + .Basic(basic) -> if basic.is_unresolved { match basic.expr is { .SelfTy -> if self.self_sym_is_set { basic.is_unresolved = false; @@ -82,13 +82,13 @@ extend Resolver { } else { false }, - .Ident as mut ident -> { + .Ident(mut ident) -> { self.resolve_ident(ident); if ident.found { - if ident.sym is ast.TypeSym as type_sym { + if ident.sym is ast.TypeSym(type_sym) { basic.is_unresolved = false; basic.sym = type_sym; - if type_sym.info is .Alias as alias_info { + if type_sym.info is .Alias(alias_info) { if self.resolve_type(alias_info.parent) { type.unalias_in_place(); } @@ -102,10 +102,10 @@ extend Resolver { } ident.found }, - .Selector as mut selector -> { + .Selector(mut selector) -> { self.resolve_selector(selector); if selector.found { - if selector.sym is ast.TypeSym as type_sym { + if selector.sym is ast.TypeSym(type_sym) { if type_sym.info is .Placeholder { report.error( "cannot find type `{}` in {} `{}`".fmt( @@ -118,7 +118,7 @@ extend Resolver { } else { basic.is_unresolved = false; basic.sym = type_sym; - if type_sym.info is .Alias as alias_info { + if type_sym.info is .Alias(alias_info) { if self.resolve_type(alias_info.parent) { type.unalias_in_place(); } diff --git a/rivetc/src/checker.py b/rivetc/src/checker.py index c29219581..1a2ab46ed 100644 --- a/rivetc/src/checker.py +++ b/rivetc/src/checker.py @@ -81,7 +81,7 @@ def check_decl(self, decl): self.expected_type = old_expected_type try: self.check_compatible_types(field_typ, decl.typ) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], decl.pos) else: decl.typ = self.check_expr(decl.expr) @@ -95,7 +95,7 @@ def check_decl(self, decl): self.expected_type = old_expected_type try: self.check_compatible_types(left0.typ, expr_t) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], decl.pos) else: left0.typ = self.check_expr(decl.right) @@ -149,7 +149,7 @@ def check_decl(self, decl): self.expected_type = old_expected_type try: self.check_compatible_types(field_typ, decl.typ) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], decl.pos) elif isinstance(decl, ast.ExtendDecl): self_sym = decl.typ.symbol() @@ -180,7 +180,7 @@ def check_decl(self, decl): self.expected_type = old_expected_type try: self.check_types(def_expr_t, arg.typ) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], arg.pos) if isinstance(decl.ret_typ, type.Ptr) and decl.abi != sym.ABI.Rivet: report.error( @@ -221,7 +221,7 @@ def check_stmt(self, stmt): if stmt.lefts[0].has_typ: try: self.check_types(right_typ, self.expected_type) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], stmt.pos) else: right_typ = self.comp.comptime_number_to_type(right_typ) @@ -320,7 +320,7 @@ def check_expr(self, expr): return expr.typ try: self.check_types(right_t, left_t) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], expr.right.pos) return expr.typ elif isinstance(expr, ast.EnumLiteral): @@ -453,7 +453,7 @@ def check_expr(self, expr): else: try: self.check_types(typ, elem_typ) - except utils.CompilerError as err: + except utils.CompilerError(err): report.error(err.args[0], e.pos) if expr.is_arr: report.note(f"in element {i + 1} of array literal") @@ -682,7 +682,7 @@ def check_expr(self, expr): report.help( f"the type should define the operator `{op_m}`" ) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], expr.pos) return expr.typ elif expr.op in (Kind.KwIs, Kind.KwNotIs): @@ -1019,7 +1019,7 @@ def check_expr(self, expr): arg1_t = self.check_expr(expr.args[1]) try: self.check_types(arg1_t, self.comp.uint_t) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], expr.args[1].pos) report.note( "in second argument of builtin function `dyn_array`" @@ -1254,7 +1254,7 @@ def check_expr(self, expr): self.expected_type = old_expected_type try: self.check_types(expr_typ, self.cur_fn.ret_typ) - except utils.CompilerError as e: + except utils.CompilerError(e): expr_typ_sym = expr_typ.symbol() report.error(e.args[0], expr.expr.pos) report.note( @@ -1355,7 +1355,7 @@ def check_expr(self, expr): self.expected_type = old_expected_typ try: self.check_types(branch_t, expr.expected_typ) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], b.expr.pos) b.typ = branch_t return expr.expected_typ @@ -1390,7 +1390,7 @@ def check_expr(self, expr): pat_t = self.comp.comptime_number_to_type(pat_t) try: self.check_types(pat_t, expr_typ) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], p.pos) if b.has_var: if b.var_is_mut: @@ -1443,7 +1443,7 @@ def check_expr(self, expr): self.expected_type = old_expected_type try: self.check_types(branch_t, expr.expected_typ) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], b.expr.pos) b.typ = branch_t return expr.expected_typ @@ -1488,7 +1488,7 @@ def check_ctor(self, info, expr): self.check_types( self.check_expr(expr.args[0].expr), v.typ ) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], expr.args[0].expr.pos) self.expected_type = old_expected_type else: @@ -1558,7 +1558,7 @@ def check_ctor(self, info, expr): self.expected_type = old_expected_type try: self.check_types(arg_t, field_typ) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], arg.pos) if expr.has_spread_expr: @@ -1680,7 +1680,7 @@ def check_call(self, info, expr): dyn_array_t.sym = last_arg_typ.sym try: self.check_types(spread_expr_t, dyn_array_t) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], expr.spread_expr.pos) return expr.typ @@ -1703,7 +1703,7 @@ def check_argument_type( else: try: self.check_types(got, expected) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], pos) report.note(pos_msg) diff --git a/rivetc/src/register.py b/rivetc/src/register.py index 1d8b87897..f596a26f2 100644 --- a/rivetc/src/register.py +++ b/rivetc/src/register.py @@ -36,7 +36,7 @@ def walk_decls(self, decls): decl.is_public, decl.alias, decl.mod_sym ) ) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], decl.pos) else: self.source_file.imported_symbols[decl.alias @@ -79,7 +79,7 @@ def walk_decls(self, decls): v_sym.pos = decl.pos self.source_file.sym.add(v_sym) v.sym = v_sym - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], v.pos) elif isinstance(decl, ast.AliasDecl): try: @@ -96,7 +96,7 @@ def walk_decls(self, decls): decl.is_public, decl.name, decl.parent ) self.sym.add(decl.sym) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], decl.pos) elif isinstance(decl, ast.TraitDecl): try: @@ -110,7 +110,7 @@ def walk_decls(self, decls): self.comp.throwable_sym = decl.sym self.sym = decl.sym self.walk_decls(decl.decls) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], decl.pos) elif isinstance(decl, ast.StructDecl): try: @@ -130,7 +130,7 @@ def walk_decls(self, decls): self.comp.dyn_array_sym = decl.sym self.sym = decl.sym self.walk_decls(decl.decls) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], decl.pos) elif isinstance(decl, ast.EnumDecl): try: @@ -171,7 +171,7 @@ def walk_decls(self, decls): decl.sym.info = info self.sym = decl.sym self.walk_decls(decl.decls) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], decl.pos) elif isinstance(decl, ast.FieldDecl): if self.sym.has_field(decl.name): @@ -223,7 +223,7 @@ def walk_decls(self, decls): ) ) decl.sym.is_main = decl.is_main - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], decl.name_pos) self.abi = old_abi self.sym = old_sym @@ -231,7 +231,7 @@ def walk_decls(self, decls): def add_sym(self, sy, pos): try: self.sym.add(sy) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], pos) def check_vis(self, sym_, pos): diff --git a/rivetc/src/resolver.py b/rivetc/src/resolver.py index f37517693..2af8baaa8 100644 --- a/rivetc/src/resolver.py +++ b/rivetc/src/resolver.py @@ -134,7 +134,7 @@ def resolve_decls(self, decls): sym.ObjLevel.Rec, decl.name_pos ) ) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], decl.name_pos) decl.self_typ = self_typ decl.sym.self_typ = self_typ @@ -147,7 +147,7 @@ def resolve_decls(self, decls): arg.pos ) ) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], arg.pos) if arg.has_def_expr: self.resolve_expr(arg.def_expr) @@ -171,7 +171,7 @@ def resolve_stmt(self, stmt): v.is_mut, v.name, v.typ, sym.ObjLevel.Local, v.pos ) ) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], v.pos) self.resolve_expr(stmt.right) elif isinstance(stmt, ast.WhileStmt): @@ -190,7 +190,7 @@ def resolve_stmt(self, stmt): self.comp.void_t, sym.ObjLevel.Local, stmt.index.pos ) ) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], stmt.index.pos) try: stmt.scope.add( @@ -199,7 +199,7 @@ def resolve_stmt(self, stmt): sym.ObjLevel.Local, stmt.value.pos ) ) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], stmt.value.pos) self.resolve_expr(stmt.iterable) self.resolve_stmt(stmt.stmt) @@ -244,7 +244,7 @@ def resolve_expr(self, expr): v.is_mut, v.name, self.comp.void_t, False, v.pos ) ) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], v.pos) self.resolve_expr(expr.expr) if expr.has_cond: @@ -262,7 +262,7 @@ def resolve_expr(self, expr): sym.ObjLevel.Local, expr.var.pos ) ) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], expr.var.pos) elif isinstance(expr, ast.ParExpr): self.resolve_expr(expr.expr) @@ -286,7 +286,7 @@ def resolve_expr(self, expr): expr.err_handler.varname_pos ) ) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], expr.err_handler.varname_pos) self.resolve_expr(expr.err_handler.expr) elif isinstance(expr, ast.BuiltinCallExpr): @@ -328,7 +328,7 @@ def resolve_expr(self, expr): sym.ObjLevel.Local, b.var_pos ) ) - except utils.CompilerError as e: + except utils.CompilerError(e): report.error(e.args[0], b.var_pos) if b.has_cond: self.resolve_expr(b.cond) diff --git a/tests/valid/src/enums.ri b/tests/valid/src/enums.ri index f06f98c90..2a8c56993 100644 --- a/tests/valid/src/enums.ri +++ b/tests/valid/src/enums.ri @@ -48,15 +48,15 @@ test "enums: boxed enum" { if e is .Abc { @assert(@as(int32, e) == 6); } - if e is .Abc as e_int32 { + if e is .Abc(e_int32) { @assert(e_int32 == 6); } match e is { - .Abc as e_abc -> @assert(e_abc == 6), + .Abc(e_abc) -> @assert(e_abc == 6), else -> @assert(false) } match e is { - .Abc as mut e_abc2 -> { + .Abc(mut e_abc2) -> { e_abc2 += 2; @assert(e_abc2 == 8); }, @@ -81,12 +81,12 @@ enum OS { test "enums: boxed enum with fields" { mut user_os := OS.Windows(version: 2023_10_04); - if user_os is .Windows as windows { + if user_os is .Windows(windows) { @assert(windows.version == 2023_10_04); } user_os = .Linux(kernel_version: 5_16_0, distro_name: "CentOS"); - if user_os is .Linux as linux { + if user_os is .Linux(linux) { @assert(linux.kernel_version == 5_16_0); @assert(linux.distro_name == "CentOS"); linux.kernel_version = 5_12_0; @@ -107,5 +107,5 @@ struct EnumStruct { test "boxed enums with `default_value` attribute" { es := EnumStruct(); - @assert(es.dv is .Abc as int and int == 5); + @assert(es.dv is .Abc(int) and int == 5); } diff --git a/tests/valid/src/match_expr.ri b/tests/valid/src/match_expr.ri index 946a3d2a1..e1a5671b4 100644 --- a/tests/valid/src/match_expr.ri +++ b/tests/valid/src/match_expr.ri @@ -40,7 +40,7 @@ test "`match` branch variable" { ss := MatchSon(name: "Rivet"); sb := MatchBase.MatchSon(ss); @assert(match sb is { - .MatchSon as sb_ss -> sb_ss.name == "Rivet", + .MatchSon(sb_ss) -> sb_ss.name == "Rivet", else -> false }); } diff --git a/tests/valid/src/results.ri b/tests/valid/src/results.ri index 120f8f6be..c6ac7541c 100644 --- a/tests/valid/src/results.ri +++ b/tests/valid/src/results.ri @@ -45,8 +45,8 @@ enum IOError < Throwable { pub func to_string(self) -> string { return match self is { - .FileNotFound as path -> "file not found: {}".fmt(path), - .InvalidFileSize as ifsz -> "invalid file size for {} (size: {})".fmt( + .FileNotFound(path) -> "file not found: {}".fmt(path), + .InvalidFileSize(ifsz) -> "invalid file size for {} (size: {})".fmt( ifsz.path, ifsz.size ) };