Skip to content

Commit

Permalink
rclear
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Dec 7, 2023
1 parent 460a9e4 commit 6338888
Show file tree
Hide file tree
Showing 34 changed files with 470 additions and 470 deletions.
4 changes: 2 additions & 2 deletions lib/rivet/src/ast/CHeader.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
10 changes: 5 additions & 5 deletions lib/rivet/src/ast/Decl.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
Expand Down
122 changes: 61 additions & 61 deletions lib/rivet/src/ast/Expr.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -287,65 +287,65 @@ 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
};
}

#[inline]
pub func to_string(self) -> string {
return match self is {
.Empty -> "<empty-expression>",
.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
},
.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)
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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'(');
Expand Down Expand Up @@ -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'(');
Expand All @@ -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 ");
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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("(");
Expand Down
12 changes: 6 additions & 6 deletions lib/rivet/src/ast/Stmt.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
}
8 changes: 4 additions & 4 deletions lib/rivet/src/ast/Sym.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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"
};
}
Expand Down
30 changes: 15 additions & 15 deletions lib/rivet/src/ast/Table.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 }
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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()
};
}
Expand Down
Loading

0 comments on commit 6338888

Please sign in to comment.