Skip to content

Commit 76bd483

Browse files
committed
change
1 parent 10d6b0b commit 76bd483

32 files changed

+196
-225
lines changed

lib/rivet/src/ast/Decl.ri

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub enum Decl {
5454
name: string;
5555
mut underlying_type: Type;
5656
bases: []mut Type;
57-
variants: []EnumVariantDecl;
57+
variants: []mut EnumVariantDecl;
5858
is_tagged: bool;
5959
decls: []Decl;
6060
pos: token.Pos;
@@ -106,7 +106,7 @@ pub enum Decl {
106106
is_public: bool;
107107
is_extern: bool;
108108
abi: ABI;
109-
lefts: []ObjectData;
109+
lefts: []mut ObjectData;
110110
mut right: Expr;
111111
pos: token.Pos;
112112
mut sym: Sym;
@@ -125,7 +125,7 @@ pub enum Decl {
125125
is_operator: bool;
126126
abi: ABI;
127127
name: string;
128-
args: []Arg;
128+
args: []mut Arg;
129129
has_named_args: bool;
130130
mut ret_type: Type;
131131
stmts: []mut Stmt;

lib/rivet/src/ast/Expr.ri

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub enum Expr < traits.Stringable {
170170
},
171171
Call {
172172
mut left: Expr;
173-
mut args: []CallArg;
173+
mut args: []mut CallArg;
174174
mut spread_expr: Expr;
175175
has_spread_expr: bool;
176176
mut err_handler: CallErrorHandler;
@@ -224,7 +224,7 @@ pub enum Expr < traits.Stringable {
224224
},
225225
BuiltinCall {
226226
name: string;
227-
args: []CallArg;
227+
mut args: []mut CallArg;
228228
pos: token.Pos;
229229
mut builtin: Builtin := .Invalid;
230230
mut type: Type;
@@ -266,15 +266,15 @@ pub enum Expr < traits.Stringable {
266266
mut defer_stmts: []Stmt.Defer;
267267
},
268268
If {
269-
branches: []IfBranch;
269+
branches: []mut IfBranch;
270270
has_else: bool;
271271
pos: token.Pos;
272272
mut expected_type: Type;
273273
mut type: Type;
274274
},
275275
Match {
276276
mut expr: Expr;
277-
branches: []MatchBranch;
277+
branches: []mut MatchBranch;
278278
mut is_typematch: bool;
279279
has_else: bool;
280280
mut scope: Scope;
@@ -287,7 +287,7 @@ pub enum Expr < traits.Stringable {
287287
// - if x := optional_or_result_fn() { ... }
288288
// - while byte := reader.read() { ... }
289289
Guard {
290-
vars: []ObjectData;
290+
vars: []mut ObjectData;
291291
mut expr: Expr;
292292
has_cond: bool;
293293
mut cond: Expr;

lib/rivet/src/ast/Scope.ri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct Scope {
1212
pub mut parent: ?Scope;
1313
pub mut detached_from_parent: bool;
1414
pub mut childrens: []Scope;
15-
pub mut syms: []Sym;
15+
pub mut syms: []mut Sym;
1616
pub mut is_local: bool;
1717

1818
pub func add(mut self, sym: Sym) -> ! {

lib/rivet/src/ast/SourceFile.ri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ../token;
77
#[boxed]
88
pub struct SourceFile {
99
pub path: string;
10-
pub decls: []Decl;
10+
pub decls: []mut Decl;
1111
pub mut mod: Module;
1212
pub mut imported_symbols: ImportedSymbols;
1313
pub mut pos: token.Pos;

lib/rivet/src/ast/Stmt.ri

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub enum Stmt {
99
Comment(Comment),
1010
Expr(Expr),
1111
VarDecl {
12-
lefts: []ObjectData;
12+
lefts: []mut ObjectData;
1313
mut right: Expr;
1414
mut scope: Scope;
1515
pos: token.Pos;
@@ -27,7 +27,7 @@ pub enum Stmt {
2727
For {
2828
mut index: ObjectData;
2929
has_index: bool;
30-
values: []ObjectData;
30+
values: []mut ObjectData;
3131
mut iterable: Expr;
3232
mut stmt: Stmt;
3333
mut scope: Scope;
@@ -39,6 +39,7 @@ pub enum Stmt {
3939
Error,
4040
Success
4141
}
42+
4243
mut expr: Expr;
4344
mode: Mode;
4445
pos: token.Pos;

lib/rivet/src/ast/Type.ri

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ pub enum Type < traits.Stringable {
7676
is_method: bool;
7777
self_is_mut: bool;
7878
self_is_ptr: bool;
79-
args: []Arg;
79+
args: []mut Arg;
8080
mut ret_type: Type;
8181
pos: token.Pos;
8282
mut sym: TypeSym;
8383
mut has_sym: bool;
8484

8585
#[inline]
86-
func symbol(self) -> Func {
86+
func symbol(&self) -> Func {
8787
return if self.has_sym && self.sym.info is .Func(func_sym) {
8888
func_sym
8989
} else {
@@ -108,7 +108,7 @@ pub enum Type < traits.Stringable {
108108
};
109109
}
110110

111-
pub func unalias(self) -> ?Self {
111+
pub func unalias(mut self) -> ?Self {
112112
// NOTE: `.unalias()` returns an option, so we use the same type without
113113
// unaliasing instead.
114114
return match self {
@@ -131,8 +131,8 @@ pub enum Type < traits.Stringable {
131131
.Pointer(pointer_data) -> .Pointer(
132132
pointer_data.inner.unalias() ?? pointer_data.inner, ...self
133133
),
134-
.Func(func_data) -> {
135-
for arg in func_data.args {
134+
.Func(mut func_data) -> {
135+
for mut arg in func_data.args {
136136
arg.type = arg.type.unalias() ?? arg.type;
137137
}
138138
.Func(

lib/rivet/src/ast/TypeInfo.ri

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub enum TypeInfo < traits.Stringable {
4444
},
4545
Trait {
4646
mut bases: []mut TypeSym;
47-
mut implements: []TypeSym;
47+
mut implements: []mut TypeSym;
4848
mut has_objects: bool;
4949

5050
func index_of(&self, type_sym: TypeSym) -> ?uint {
@@ -72,7 +72,7 @@ pub enum TypeInfo < traits.Stringable {
7272
},
7373
Enum {
7474
underlying_type: Type;
75-
mut variants: []EnumVariant;
75+
mut variants: []mut EnumVariant;
7676
is_tagged: bool;
7777
mut traits: []mut TypeSym;
7878

lib/rivet/src/checker/builtin_call.ri

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extend Checker {
3636
err.emit();
3737
}
3838
} else {
39-
for i, arg in builtin_call.args {
39+
for i, mut arg in builtin_call.args {
4040
arg_info := b_func.args[i];
4141
arg.type = self.check_expr(arg.expr);
4242
if arg_info.is_mut {
@@ -124,7 +124,7 @@ extend Checker {
124124
), builtin_call.pos
125125
);
126126
}
127-
} else if from_ts := from_type.symbol() {
127+
} else if mut from_ts := from_type.symbol() {
128128
match from_ts.info {
129129
.Trait(mut trait_info) -> if to_ts := to_type.symbol() {
130130
if to_ts in trait_info.implements {

lib/rivet/src/checker/call_expr.ri

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extend Checker {
4747
}
4848
}
4949
},
50-
.Selector(selector) -> if selector.is_path {
50+
.Selector(mut selector) -> if selector.is_path {
5151
match selector.sym is {
5252
ast.TypeSym(mut s_type_sym) if s_type_sym.info is .Trait
5353
|| s_type_sym.info is .Struct || s_type_sym.info is .String
@@ -131,7 +131,7 @@ extend Checker {
131131
);
132132
}
133133
},
134-
.EnumLiteral(enum_lit) -> {
134+
.EnumLiteral(mut enum_lit) -> {
135135
enum_lit.is_instance = true;
136136
_ = self.check_expr(left);
137137
self.check_ctor_call(enum_lit.sym, call_expr);
@@ -222,7 +222,7 @@ extend Checker {
222222
} else if variant.has_type {
223223
old_expected_type := self.expected_type;
224224
self.expected_type = variant.type;
225-
arg0 := call_expr.args[0];
225+
mut arg0 := call_expr.args[0];
226226
self.check_types(
227227
self.check_expr(arg0.expr), variant.type
228228
) catch |err| {
@@ -462,7 +462,7 @@ extend Checker {
462462
}
463463

464464
old_expected_type := self.expected_type;
465-
for i, arg in call_expr.args {
465+
for i, mut arg in call_expr.args {
466466
arg_fn := if func_.is_variadic && i >= func_.args.len - 1 {
467467
func_.args[func_.args.len - 1]
468468
} else {

lib/rivet/src/checker/decls.ri

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ extend Checker {
6060
self.check_decls(extern_decl.decls);
6161
self.inside_extern = false;
6262
},
63-
.Var(var_decl) -> {
63+
.Var(mut var_decl) -> {
6464
self.inside_var_decl = true;
6565
self.check_var_decl(
6666
var_decl.lefts, var_decl.right, var_decl.scope, var_decl.pos
6767
);
6868
self.inside_var_decl = false;
6969
},
70-
.Const(const_decl) -> {
70+
.Const(mut const_decl) -> {
7171
self.check_name_case(.Upper, "constant", const_decl.name, const_decl.pos);
7272
if const_decl.has_type {
7373
old_expected_type := self.expected_type;
@@ -129,7 +129,7 @@ extend Checker {
129129
}
130130
self.check_decls(struct_decl.decls);
131131
},
132-
.Field(field_decl) -> {
132+
.Field(mut field_decl) -> {
133133
self.check_name_case(.Snake, "field", field_decl.name, field_decl.pos);
134134
if field_decl.has_def_expr {
135135
old_expected_type := self.expected_type;
@@ -213,7 +213,7 @@ extend Checker {
213213
if func_decl.is_method && func_decl.self_is_ptr && func_decl.self_type.is_boxed() {
214214
report.error("cannot take the address of a boxed value as receiver", func_decl.self_pos);
215215
}
216-
for arg in func_decl.args {
216+
for mut arg in func_decl.args {
217217
self.check_name_case(.Snake, "argument", arg.name, arg.pos);
218218
if arg.has_def_expr {
219219
if func_decl.abi != .Rivet {

lib/rivet/src/checker/exprs.ri

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@ extend Checker {
1414
self.scope_returns = true;
1515
.Never(branch.pos)
1616
},
17-
.Paren(paren) -> self.check_expr(paren.expr),
17+
.Paren(mut paren) -> self.check_expr(paren.expr),
1818
.NoneLiteral -> .None,
1919
.BoolLiteral -> self.table.bool_t,
20-
.CharLiteral(char_lit) -> {
20+
.CharLiteral(mut char_lit) -> {
2121
char_lit.type = if char_lit.is_byte {
2222
self.table.uint8_t
2323
} else {
2424
self.table.rune_t
2525
};
2626
char_lit.type
2727
},
28-
.IntegerLiteral(int_lit) -> {
28+
.IntegerLiteral(mut int_lit) -> {
2929
int_lit.type = self.table.comptime_int_t;
3030
int_lit.type
3131
},
32-
.FloatLiteral(float_lit) -> {
32+
.FloatLiteral(mut float_lit) -> {
3333
float_lit.type = self.table.comptime_float_t;
3434
float_lit.type
3535
},
36-
.StringLiteral(string_lit) -> {
36+
.StringLiteral(mut string_lit) -> {
3737
string_lit.type = if string_lit.is_bytestr {
3838
.Basic(self.table.universe.add_or_get_array(
3939
self.table.uint8_t, string_lit.value.len, false
@@ -45,12 +45,12 @@ extend Checker {
4545
};
4646
string_lit.type
4747
},
48-
.SelfLiteral(self_lit) -> {
48+
.SelfLiteral(mut self_lit) -> {
4949
self_lit.type = self_lit.obj.type;
5050
self_lit.type
5151
},
5252
.SelfTy -> .Void,
53-
.EnumLiteral(enum_lit) -> {
53+
.EnumLiteral(mut enum_lit) -> {
5454
enum_lit.type = .Void;
5555
if sym := self.expected_type.symbol(); sym.info is .Enum(enum_info) {
5656
if variant := enum_info.get_variant(enum_lit.value) {
@@ -86,7 +86,7 @@ extend Checker {
8686
enum_lit.type
8787
},
8888
.TupleLiteral(mut tuple_lit) -> self.check_tuple_literal(tuple_lit),
89-
.ArrayCtor(array_ctor) -> {
89+
.ArrayCtor(mut array_ctor) -> {
9090
if mut init_value := array_ctor.init_value {
9191
init_t := self.check_expr(init_value);
9292
if !self.check_compatible_types(init_t, array_ctor.elem_type) {
@@ -137,7 +137,7 @@ extend Checker {
137137
array_ctor.type
138138
},
139139
.ArrayLiteral(mut array_lit) -> self.check_array_literal(array_lit),
140-
.Ident(ident) -> {
140+
.Ident(mut ident) -> {
141141
ident.type = if ident.name == "_" {
142142
.Void
143143
} else if ident.is_comptime {
@@ -164,7 +164,7 @@ extend Checker {
164164
ident.type
165165
},
166166
.Selector(mut selector) -> self.check_selector(selector),
167-
.Indirect(indirect) -> {
167+
.Indirect(mut indirect) -> {
168168
indirect.left_type = self.check_expr(indirect.left);
169169
indirect.type = if indirect.left_type.is_pointer()
170170
|| (indirect.left_type is .Pointer(ptr) && !ptr.is_indexable)
@@ -187,7 +187,7 @@ extend Checker {
187187
};
188188
indirect.type
189189
},
190-
.OptionCheck(option_check) -> {
190+
.OptionCheck(mut option_check) -> {
191191
option_check.left_type = self.check_expr(option_check.left);
192192
option_check.type = if option_check.left_type is .Option(opt) {
193193
opt.inner
@@ -197,7 +197,7 @@ extend Checker {
197197
};
198198
option_check.type
199199
},
200-
.Range(range) -> {
200+
.Range(mut range) -> {
201201
range.type = if range.has_start {
202202
self.check_expr(range.start)
203203
} else {
@@ -216,7 +216,7 @@ extend Checker {
216216
.Index(mut index) -> self.check_index(index),
217217
.Call(mut call_expr) -> self.check_call(call_expr),
218218
.BuiltinCall(mut builtin_call) -> self.check_builtin_call(builtin_call),
219-
.Block(block) -> {
219+
.Block(mut block) -> {
220220
self.defer_stmts_start = self.defer_stmts.len;
221221
if block.is_unsafe {
222222
if self.inside_unsafe_block {
@@ -255,7 +255,7 @@ extend Checker {
255255
.Binary(mut binary) -> self.check_binary(binary),
256256
.If(mut if_expr) -> self.check_if(if_expr),
257257
.Match(mut match_expr) -> self.check_match(match_expr),
258-
.Guard(guard) -> {
258+
.Guard(mut guard) -> {
259259
old_inside_guard_expr := self.inside_guard_expr;
260260
self.inside_guard_expr = true;
261261
self.check_var_decl(guard.vars, guard.expr, guard.scope, guard.pos);
@@ -573,8 +573,8 @@ extend Checker {
573573
expected_pointer = true;
574574
indexable_pointer = opt_ptr.is_indexable;
575575
}
576-
right := unary.right.clean_paren();
577-
if right is .Index(index) {
576+
mut right := unary.right.clean_paren();
577+
if right is .Index(mut index) {
578578
if index.left_type is .Pointer && !expected_pointer {
579579
report.error("cannot take the address of a pointer indexing", unary.pos);
580580
}
@@ -743,6 +743,7 @@ extend Checker {
743743
binary.var_obj.sym.type = right_type;
744744
}
745745
if binary.var_obj.is_mut {
746+
self.check_expr_is_mut(binary.left);
746747
binary.var_obj.sym.is_hidden_ref = true;
747748
}
748749
}
@@ -824,7 +825,7 @@ extend Checker {
824825

825826
func check_if(mut self, mut if_expr: ast.Expr.If) -> ast.Type {
826827
if_expr.expected_type = self.expected_type;
827-
for i, branch in if_expr.branches {
828+
for i, mut branch in if_expr.branches {
828829
if !branch.is_else {
829830
bcond_t := self.check_expr(branch.cond);
830831
if branch.cond !is .Guard && bcond_t != self.table.bool_t {

0 commit comments

Comments
 (0)