From 5274a844fb6e075ad31f280c5654d005810bdff7 Mon Sep 17 00:00:00 2001 From: Alexander Satretdinov Date: Mon, 16 Nov 2026 20:23:51 +0200 Subject: [PATCH] remove ++ and --: x += 1 is the one increment; object() takes an argument, {} is the empty object; compound index assignment keeps constants out of registers --- docs/src/language/loops.md | 2 +- docs/src/language/variables.md | 5 +- docs/src/stdlib/builtins.md | 2 +- examples/blog/md/block.rn | 21 ++++--- examples/calc.rn | 2 +- examples/chess.rn | 12 ++-- examples/kv/store.rn | 14 ++--- examples/log-report.rn | 8 +-- examples/query/aggregate.rn | 6 +- examples/query/main.rn | 14 +++-- examples/query/parser.rn | 6 +- examples/query/table.rn | 4 +- examples/shop.rn | 2 +- examples/todo.rn | 2 +- pkg/ast/expression.go | 24 ------- pkg/ast/token.go | 6 -- pkg/format/format.go | 12 +--- pkg/rune/arith.go | 18 +++--- pkg/rune/bench_test.go | 6 +- pkg/rune/bytecode.go | 2 +- pkg/rune/compile_access.go | 69 +++------------------ pkg/rune/compile_expr.go | 8 +-- pkg/rune/compile_stmt.go | 15 +---- pkg/rune/moves.go | 3 - pkg/rune/parse_expr.go | 36 +---------- pkg/rune/resolver.go | 17 ----- pkg/rune/scanner.go | 4 -- pkg/rune/vm_slow.go | 2 +- pkg/stdlib/collections.go | 4 +- test/const/assign.rn | 2 +- test/const/assign.stderr | 2 +- test/default/basic.rn | 2 +- test/defer/return.rn | 2 +- test/destructure/array.rn | 2 +- test/destructure/defaults.rn | 2 +- test/for_in/bare_body.rn | 2 +- test/for_in/pattern.rn | 2 +- test/impl/_geo/shapes.rn | 2 +- test/impl/bound_mut.rn | 2 +- test/impl/mut_self.rn | 5 +- test/impl/mut_self_changed.rn | 2 +- test/impl/mut_self_error.rn | 2 +- test/impl/mut_self_immutable.rn | 2 +- test/impl/mut_self_in_place.rn | 2 +- test/impl/mut_self_local.rn | 2 +- test/impl/mut_self_temporary.rn | 2 +- test/impl/mut_self_transfer.rn | 2 +- test/impl/set_fields.rn | 2 +- test/impl/temp_struct_field.rn | 2 +- test/import/mutation.rn | 2 +- test/import/mutation.stderr | 4 +- test/increment/closure.rn | 13 ---- test/increment/index.rn | 12 ---- test/increment/invalid_prefix_target.rn | 1 - test/increment/invalid_prefix_target.stderr | 5 -- test/increment/invalid_target.rn | 2 - test/increment/invalid_target.stderr | 6 -- test/increment/missing_property.rn | 2 - test/increment/missing_property.stderr | 6 -- test/increment/type_error.rn | 2 - test/increment/type_error.stderr | 6 -- test/increment/undefined.rn | 1 - test/increment/undefined.stderr | 5 -- test/increment/variable.rn | 21 ------- test/int/arith.rn | 4 +- test/int/errors.rn | 2 +- test/interpolation/evaluation_order.rn | 2 +- test/match/statement.rn | 2 +- test/mutability/contents.rn | 2 +- test/mutability/contents.stderr | 2 +- test/mutability/for_in_mut.rn | 2 +- test/mutability/increment.rn | 3 - test/mutability/increment.stderr | 17 ----- test/mutability/mutable.rn | 2 +- test/mutability/mutable_contents.rn | 2 +- test/mutability/mutable_parameter.rn | 2 +- test/namespace/set_member.rn | 2 +- test/namespace/set_member.stderr | 4 +- test/optional/assign.rn | 2 +- test/optional/assign.stderr | 8 +-- test/slice/errors.rn | 2 +- test/slice/errors.stderr | 10 +-- test/stdlib/arrays_search.rn | 2 +- test/stdlib/conversions.rn | 1 - test/struct/increment_field.rn | 10 --- test/struct/increment_field.stderr | 6 -- test/value/arrays.rn | 2 +- test/value/containers.rn | 2 +- test/value/inout.rn | 2 +- test/value/moves.rn | 2 +- test/value/places.rn | 4 +- test/vm/loop_closures.rn | 2 +- test/vm/nested_loops.rn | 2 +- test/vm/registers.rn | 5 -- test/vm/shared_cell.rn | 2 +- testdata/disasm/closures.golden | 2 +- testdata/disasm/data.golden | 2 +- testdata/disasm/data.rn | 2 +- testdata/disasm/loops.golden | 2 +- testdata/disasm/methods.rn | 2 +- testdata/fmt/layout.golden | 2 +- testdata/fmt/layout.rn | 2 +- 102 files changed, 153 insertions(+), 430 deletions(-) delete mode 100644 test/increment/closure.rn delete mode 100644 test/increment/index.rn delete mode 100644 test/increment/invalid_prefix_target.rn delete mode 100644 test/increment/invalid_prefix_target.stderr delete mode 100644 test/increment/invalid_target.rn delete mode 100644 test/increment/invalid_target.stderr delete mode 100644 test/increment/missing_property.rn delete mode 100644 test/increment/missing_property.stderr delete mode 100644 test/increment/type_error.rn delete mode 100644 test/increment/type_error.stderr delete mode 100644 test/increment/undefined.rn delete mode 100644 test/increment/undefined.stderr delete mode 100644 test/increment/variable.rn delete mode 100644 test/mutability/increment.rn delete mode 100644 test/mutability/increment.stderr delete mode 100644 test/struct/increment_field.rn delete mode 100644 test/struct/increment_field.stderr diff --git a/docs/src/language/loops.md b/docs/src/language/loops.md index c66b7362..220f2232 100644 --- a/docs/src/language/loops.md +++ b/docs/src/language/loops.md @@ -235,7 +235,7 @@ let mut n = 27; let mut steps = 0; while n != 1 { n = if n % 2 == 0 { math.idiv(n, 2) } else { 3 * n + 1 }; - steps++; + steps += 1; } print(steps); // 111 ``` diff --git a/docs/src/language/variables.md b/docs/src/language/variables.md index 252cabef..16503ffd 100644 --- a/docs/src/language/variables.md +++ b/docs/src/language/variables.md @@ -10,11 +10,10 @@ let name = "ann"; let mut visits = 0; visits += 1; -visits++; -print("{name} visited {visits} times"); // ann visited 2 times +print("{name} visited {visits} times"); // ann visited 1 times ``` -Changing a `let` variable, with `=`, `+=`, `++` or any other assignment, is +Changing a `let` variable, with `=`, `+=` or any other assignment, is caught at compile time, before the program runs: ```rune diff --git a/docs/src/stdlib/builtins.md b/docs/src/stdlib/builtins.md index 7f865c44..f429c82c 100644 --- a/docs/src/stdlib/builtins.md +++ b/docs/src/stdlib/builtins.md @@ -135,7 +135,7 @@ int(1e300); // ValueError: int() cannot convert 1e+300 to an integer. ## object -`object()` makes an empty object. `object(src)` makes one from a map or an +`object(src)` makes an object from a map or an array of `[key, value]` pairs; the keys must be strings. To copy an object or a struct into a new object, use [spread](../language/spread-and-rest.md): `{ ...src }`. diff --git a/examples/blog/md/block.rn b/examples/blog/md/block.rn index 60c75514..f18a443d 100644 --- a/examples/blog/md/block.rn +++ b/examples/blog/md/block.rn @@ -26,20 +26,21 @@ export fun render(src) { let line = lines[i]; if line.trim() == "" { - i++; + i += 1; continue; } if line.startsWith("```") { let lang = line[3..].trim(); let mut code = []; - i++; + i += 1; while i < lines.len() && !lines[i].startsWith("```") { - code.push(lines[i++]); + code.push(lines[i]); + i += 1; } - i++; + i += 1; let cls = if lang == "" { "" } else { " class=\"lang-{lang}\"" }; doc.html.push("
{inline.escape(code.join("\n"))}
"); continue; @@ -53,13 +54,13 @@ export fun render(src) { let id = slug(text); doc.headings.push(Heading { level, text, id }); doc.html.push("""{inline.render(text)}"""); - i++; + i += 1; continue; } if regex.test(r"^(-{3,}|\*{3,})$", line.trim()) { doc.html.push("
"); - i++; + i += 1; continue; } @@ -67,7 +68,8 @@ export fun render(src) { let mut quote = []; while i < lines.len() && lines[i].startsWith(">") { - quote.push(lines[i++][1..].trim()); + quote.push(lines[i][1..].trim()); + i += 1; } doc.html.push("

{inline.render(quote.join(" "))}

"); @@ -88,7 +90,7 @@ export fun render(src) { } items.push("
  • {inline.render(it.text)}
  • "); - i++; + i += 1; } doc.html.push("<{tag}>{items.join("")}"); @@ -98,7 +100,8 @@ export fun render(src) { let mut para = []; while i < lines.len() && !startsBlock(lines[i]) { - para.push(lines[i++].trim()); + para.push(lines[i].trim()); + i += 1; } doc.html.push("

    {inline.render(para.join(" "))}

    "); diff --git a/examples/calc.rn b/examples/calc.rn index 47afd039..98ad42a8 100644 --- a/examples/calc.rn +++ b/examples/calc.rn @@ -67,7 +67,7 @@ impl Parser { fun next(mut self) { let t = self.tokens[self.i]; - self.i++; + self.i += 1; return t; } diff --git a/examples/chess.rn b/examples/chess.rn index f1505bdd..c4e576c8 100644 --- a/examples/chess.rn +++ b/examples/chess.rn @@ -220,7 +220,7 @@ impl Position { kings[color(if p > 0 { 1 } else { -1 })] = sq(file, rank); } - file++; + file += 1; } if file != 8 { @@ -256,7 +256,7 @@ impl Position { let p = self.board[sq(f, r)]; if p == EMPTY { - gap++; + gap += 1; continue; } @@ -696,7 +696,7 @@ impl Search { return self.quiesce(alpha, beta, ply); } - self.nodes++; + self.nodes += 1; let entry = self.tt?.[self.pos.hash]; @@ -724,7 +724,7 @@ impl Search { continue; } - legal++; + legal += 1; let score = -self.negamax(remaining - 1, -beta, -a, ply + 1); self.pos.unmake(); @@ -764,7 +764,7 @@ impl Search { } fun quiesce(mut self, alpha, beta, ply) { - self.nodes++; + self.nodes += 1; let stand = self.pos.score * self.pos.side; if stand >= beta { @@ -1036,7 +1036,7 @@ fun options(args) { } out.rest.push(arg); - i++; + i += 1; } return out; diff --git a/examples/kv/store.rn b/examples/kv/store.rn index c24ede89..77c7f149 100644 --- a/examples/kv/store.rn +++ b/examples/kv/store.rn @@ -126,7 +126,7 @@ impl Store { self.replay(id, i == ids.len() - 1, rec); } - rec.segments++; + rec.segments += 1; } // A compacted segment, the one with a hint, is never appended to @@ -180,7 +180,7 @@ impl Store { } self.apply(r.key, codec.Loc { seg: id, start: r.start, recLen: r.recLen, size: r.size }, r.kind); - rec.records++; + rec.records += 1; at += r.recLen; } } @@ -191,7 +191,7 @@ impl Store { while at < data.len() { let h = codec.decodeHint(data, at, id) ?? throw KvError { message: "{fs.base(self.segs[id].hint)}: bad entry at byte {at}" }; self.apply(h.key, h.loc, codec.PUT); - rec.hinted++; + rec.hinted += 1; at = h.next; } } @@ -217,13 +217,13 @@ impl Store { self.out.flush(); } - self.writes++; + self.writes += 1; self.apply(key, loc, kind); } fun rotate(mut self) { self.out.close(); - self.active++; + self.active += 1; self.openActive(); } @@ -282,7 +282,7 @@ impl Store { let mut keydir = map(); for chunk in chunks(self.keydir.entries(), self.maxSegment) { - self.active++; + self.active += 1; let mut log = bytes.buffer(); let mut hints = bytes.buffer(); @@ -309,7 +309,7 @@ impl Store { self.segs = segs; self.keydir = keydir; - self.active++; + self.active += 1; self.openActive(); return { before, after: self.info() }; } diff --git a/examples/log-report.rn b/examples/log-report.rn index 089c16b6..b2176ee9 100644 --- a/examples/log-report.rn +++ b/examples/log-report.rn @@ -49,11 +49,11 @@ impl Stats { fun new() { Stats {} } fun add(mut self, { status, bytes, latency }) { - self.count++; + self.count += 1; self.bytes += bytes; if status >= 500 { - self.errors++; + self.errors += 1; } self.latencies.push(latency); @@ -83,7 +83,7 @@ impl Report { fun new() { Report {} } fun add(mut self, e) { - self.total++; + self.total += 1; let key = "{e.method} {e.path}"; @@ -100,7 +100,7 @@ impl Report { self.clients[e.ip] = { hits: 0, paths: set() }; } - self.clients[e.ip].hits++; + self.clients[e.ip].hits += 1; self.clients[e.ip].paths.add(e.path); self.slowest.push(e); diff --git a/examples/query/aggregate.rn b/examples/query/aggregate.rn index 6a174af0..ee1cf39d 100644 --- a/examples/query/aggregate.rn +++ b/examples/query/aggregate.rn @@ -69,7 +69,7 @@ fun accumulate(mut acc, aggs, r) { let a = aggs[i]; if a.arg == nil { - acc[i]++; + acc[i] += 1; continue; } @@ -85,11 +85,11 @@ fun accumulate(mut acc, aggs, r) { } match a.fn { - Agg.Count => acc[i]++, + Agg.Count => acc[i] += 1, Agg.Sum => acc[i] = (acc[i] ?? 0) + v, Agg.Avg => { acc[i][0] += v; - acc[i][1]++; + acc[i][1] += 1; }, Agg.Min => { if acc[i] == nil || expr.compare(v, acc[i]) < 0 { acc[i] = v; diff --git a/examples/query/main.rn b/examples/query/main.rn index aa7a0427..447f5449 100644 --- a/examples/query/main.rn +++ b/examples/query/main.rn @@ -84,12 +84,18 @@ fun main(args) { while i < args.len() { match args[i] { - "-d" => dir = args?.[++i] ?? return usage(), - "-f" => format = args?.[++i] ?? return usage(), + "-d" => { + i += 1; + dir = args?.[i] ?? return usage(); + }, + "-f" => { + i += 1; + format = args?.[i] ?? return usage(); + }, a => rest.push(a), } - i++; + i += 1; } if format !in output.FORMATS { @@ -104,7 +110,7 @@ fun main(args) { while line != nil { if line.trim() != "" && !tryRun(line, catalog, format) { - failed++; + failed += 1; } line = io.readLine(); diff --git a/examples/query/parser.rn b/examples/query/parser.rn index ccce577f..b725cfd2 100644 --- a/examples/query/parser.rn +++ b/examples/query/parser.rn @@ -56,7 +56,7 @@ impl Parser { let t = self.tokens[self.i]; if t.kind != Kind.Eof { - self.i++; + self.i += 1; } return t; @@ -264,7 +264,7 @@ impl Parser { return ast.Like { expr, pattern: self.expr(5), not }; } - self.i--; + self.i -= 1; self.fail("expected IN, BETWEEN or LIKE after NOT"); } @@ -284,7 +284,7 @@ impl Parser { Token { kind: Kind.Id, text, word, pos } if word !in RESERVED => self.reference(text, word, pos), _ => { if t.kind != Kind.Eof { - self.i--; + self.i -= 1; } self.fail("expected an expression"); diff --git a/examples/query/table.rn b/examples/query/table.rn index 17de3b5f..d60e9c57 100644 --- a/examples/query/table.rn +++ b/examples/query/table.rn @@ -100,7 +100,7 @@ fun splitCsv(line) { if c == "\"" { if chars?.[i + 1] == "\"" { cell.push("\""); - i++; + i += 1; } else { quoted = false; } @@ -116,7 +116,7 @@ fun splitCsv(line) { cell.push(c); } - i++; + i += 1; } cells.push(cell.join("")); diff --git a/examples/shop.rn b/examples/shop.rn index fb57ce20..df3aee94 100644 --- a/examples/shop.rn +++ b/examples/shop.rn @@ -24,7 +24,7 @@ impl Client { let r = self.send("POST", "/auth/refresh", { refreshToken: self.refreshToken }); self.token = r.accessToken; self.refreshToken = r.refreshToken; - self.refreshes++; + self.refreshes += 1; } fun expire(mut self) { diff --git a/examples/todo.rn b/examples/todo.rn index eb50ba2d..60c68ac2 100644 --- a/examples/todo.rn +++ b/examples/todo.rn @@ -101,7 +101,7 @@ impl Store { fun add(mut self, task) { self.tasks.push(Task({ ...task, id: self.nextId })); - self.nextId++; + self.nextId += 1; return self.nextId - 1; } diff --git a/pkg/ast/expression.go b/pkg/ast/expression.go index 54519d57..6828e446 100644 --- a/pkg/ast/expression.go +++ b/pkg/ast/expression.go @@ -19,7 +19,6 @@ type ExprVisitor interface { VisitSetIndexExpr(setIndexExpr *SetIndexExpr) (value.Value, error) VisitObjectExpr(objectExpr *ObjectExpr) (value.Value, error) VisitFunctionExpr(functionExpr *FunctionExpr) (value.Value, error) - VisitUpdateExpr(updateExpr *UpdateExpr) (value.Value, error) VisitRangeExpr(rangeExpr *RangeExpr) (value.Value, error) VisitSliceExpr(sliceExpr *SliceExpr) (value.Value, error) VisitStructExpr(structExpr *StructExpr) (value.Value, error) @@ -213,29 +212,6 @@ func NewSetIndexExpr(target *IndexExpr, value Expr, op *Token) Expr { return &SetIndexExpr{Array: target.Array, Index: target.Index, Value: value, Token: target.Token, Op: op, Property: target.Property} } -// UpdateExpr is ++x, x++, --x or x--. Target is a *VarExpr or *IndexExpr. -type UpdateExpr struct { - Target Expr - Operator Token - Prefix bool -} - -func NewUpdateExpr(target Expr, operator Token, prefix bool) Expr { - return &UpdateExpr{Target: target, Operator: operator, Prefix: prefix} -} - -func (n *UpdateExpr) Accept(v ExprVisitor) (value.Value, error) { - return v.VisitUpdateExpr(n) -} - -func (n *UpdateExpr) String() string { - if n.Prefix { - return fmt.Sprintf("(%s %v)", n.Operator.Lexeme, n.Target) - } - - return fmt.Sprintf("(%v %s)", n.Target, n.Operator.Lexeme) -} - // FunctionExpr is an arrow function: (a, b) => ... Its Decl has // an empty name and is never declared in any scope. type FunctionExpr struct { diff --git a/pkg/ast/token.go b/pkg/ast/token.go index e04d85d6..63e1e34b 100644 --- a/pkg/ast/token.go +++ b/pkg/ast/token.go @@ -110,8 +110,6 @@ const ( STAR_EQUAL SLASH_EQUAL PERCENT_EQUAL - PLUS_PLUS - MINUS_MINUS AMP CARET TILDE @@ -321,10 +319,6 @@ func (tokenType TokenType) String() string { return "SLASH_EQUAL" case PERCENT_EQUAL: return "PERCENT_EQUAL" - case PLUS_PLUS: - return "PLUS_PLUS" - case MINUS_MINUS: - return "MINUS_MINUS" case AMP: return "AMP" case CARET: diff --git a/pkg/format/format.go b/pkg/format/format.go index 07f1f090..967b4cd1 100644 --- a/pkg/format/format.go +++ b/pkg/format/format.go @@ -30,12 +30,11 @@ const ( other role = iota operand prefix - postfix // path is a part of an import, after the keyword. path ) -func (a *atom) ended() bool { return a.role == operand || a.role == postfix } +func (a *atom) ended() bool { return a.role == operand } // gap is what precedes an atom: comments, and the newlines before each. type gap struct { @@ -215,11 +214,6 @@ func classify(a *atom, ended bool) role { case ast.NUMBER, ast.STRING, ast.BYTES, ast.TRUE, ast.FALSE, ast.NIL, ast.RIGHT_PAREN, ast.RIGHT_BRACKET, ast.RIGHT_BRACE: return operand - case ast.PLUS_PLUS, ast.MINUS_MINUS: - if ended && a.before.breaks == 0 { - return postfix - } - return prefix case ast.MINUS: if ended { return other @@ -370,9 +364,7 @@ func (p *printer) spaceBefore(a *atom) bool { case a.role == path: return pt == ast.IMPORT || isWord(a, "as") || isWord(prev, "as") case prev.role == prefix: - return pt == ast.MINUS && (t == ast.MINUS || t == ast.MINUS_MINUS) - case a.role == postfix: - return false + return pt == ast.MINUS && t == ast.MINUS case t == ast.COMMA, t == ast.SEMICOLON, t == ast.RIGHT_PAREN, t == ast.RIGHT_BRACKET: return false case t == ast.RIGHT_BRACE: diff --git a/pkg/rune/arith.go b/pkg/rune/arith.go index cffb3195..d05f6fbc 100644 --- a/pkg/rune/arith.go +++ b/pkg/rune/arith.go @@ -29,6 +29,16 @@ func binaryIns(op ast.TokenType, a, b, c int32) ins { return ins{op: arithOp(arithOps[op], false), a: a, b: b, c: c} } +// arithConstIns is the instruction applying op to register b and the +// constant v, which is K[c]. +func arithConstIns(op value.Arith, a, b, c int32, v value.Value) ins { + if v.IsInt() && v.Int() == 1 && (op == value.OpAdd || op == value.OpSub) { + return ins{op: opIncr, x: uint8(op), a: a, b: b} + } + + return ins{op: arithOp(op, true), a: a, b: b, c: c} +} + // binaryOp applies a binary operator; operator also locates errors. func binaryOp(operator *ast.Token, l, r value.Value) (value.Value, error) { op := operator.TokenType @@ -135,14 +145,6 @@ func negate(tok *ast.Token, v value.Value) (value.Value, error) { return value.NilValue, errors.NewRuntimeError(errors.TypeError, *tok, "Operand must be a number.") } -func increment(tok *ast.Token, v value.Value, delta int64) (value.Value, error) { - if v.IsNumber() { - return arith(tok, value.OpAdd, v, value.NewInt(delta)) - } - - return value.NilValue, errors.NewRuntimeError(errors.TypeError, *tok, "Operand must be a number.") -} - func bitNot(tok *ast.Token, v value.Value) (value.Value, error) { if n, ok := value.ToInt(v); ok { return value.NewInt(^n), nil diff --git a/pkg/rune/bench_test.go b/pkg/rune/bench_test.go index aa1cc9e9..27d246d6 100644 --- a/pkg/rune/bench_test.go +++ b/pkg/rune/bench_test.go @@ -18,7 +18,7 @@ var benchSources = map[string]string{ "push": `let mut a = []; for i in 0..2000 { a.push(i); } let mut s = 0; for x in a { s += x; }`, "map": `let mut a = []; for i in 0..2000 { a.push(i); } for k in 0..20 { a.map(x => x * 2).filter(x => x % 3 == 0); }`, - "update": `let mut s = 0; let mut i = 0; while i < 100000 { i++; s++; } let mut a = [0]; let mut j = 0; while j < 20000 { ++j; a[0]++; }`, + "update": `let mut s = 0; let mut i = 0; while i < 100000 { i += 1; s += 1; } let mut a = [0]; let mut j = 0; while j < 20000 { j += 1; a[0] += 1; }`, "locals": `fun run() { let mut s = 0; for i in 0..100000 { s = s + i % 7; } return s; } run();`, "strings": `let mut s = ""; for i in 0..1000 { s = s + "ab"; } let mut n = 0; for c in s { if c == "a" { n += 1; } }`, "objects": `let mut o = {x: 0, y: 0}; for i in 0..20000 { o.x = o.x + 1; o["y"] += o.x; }`, @@ -28,7 +28,7 @@ var benchSources = map[string]string{ "sfields": `struct P { x, y, z } let p = P { x: 1, y: 2, z: 3 }; let mut s = 0; for i in 0..50000 { s += p.x + p.y + p.z; }`, "methods": `struct P { x } impl P { fun get(self, k) { return self.x + k; } } let p = P { x: 1 }; let mut s = 0; for i in 0..50000 { s += p.get(i); }`, "funcs": `struct P { x } fun get(p, k) { return p.x + k; } let p = P { x: 1 }; let mut s = 0; for i in 0..50000 { s += get(p, i); }`, - "mutself": `struct C { n } impl C { fun incr(mut self) { self.n++; } } let mut c = C { n: 0 }; for i in 0..20000 { c.incr(); }`, + "mutself": `struct C { n } impl C { fun incr(mut self) { self.n += 1; } } let mut c = C { n: 0 }; for i in 0..20000 { c.incr(); }`, "objcall": `let o = {a: 1, b: 2}; let mut s = 0; for i in 0..20000 { s += o.len(); }`, "print": `for i in 0..20000 { print(i); }`, "format": `let mut n = 0; for i in 0..20000 { n += "%-8s|%5.2f|%03d".format("ab", 3.14159, i).len(); }`, @@ -150,7 +150,7 @@ func TestContainerMovesDoNotCopy(t *testing.T) { func TestPathWritesInPlace(t *testing.T) { src := `let mut g = []; for i in 0..100 { g.push([0].repeat(100)); } let mut o = { g }; - for k in 0..%d { for i in 0..100 { g[i][k %% 100] = k; g[i][0] += 1; g[i][1]++; o.g[i][0] = k; } g[0].push(k); g[0].pop(); }` + for k in 0..%d { for i in 0..100 { g[i][k %% 100] = k; g[i][0] += 1; g[i][1] += 1; o.g[i][0] = k; } g[0].push(k); g[0].pop(); }` if one, many := allocated(t, src, 1), allocated(t, src, 101); many > one+50<<10 { t.Fatalf("path writes copy: %d bytes for 1 pass, %d for 101", one, many) diff --git a/pkg/rune/bytecode.go b/pkg/rune/bytecode.go index 5c6d37d9..34f4ea02 100644 --- a/pkg/rune/bytecode.go +++ b/pkg/rune/bytecode.go @@ -49,7 +49,7 @@ const ( opIs // R[A] = R[B] is R[C], negated with Y opNeg // R[A] = -R[B] opNot // R[A] = !R[B] - opIncr // R[A] = R[B] + 1, or - 1 if X + opIncr // R[A] = R[B] + 1, or - 1 if X is value.OpSub opBitwise // R[A] = R[B] R[C], X a value.Bit opBitNot // R[A] = ^R[B] diff --git a/pkg/rune/compile_access.go b/pkg/rune/compile_access.go index d8a1bfba..675abfcf 100644 --- a/pkg/rune/compile_access.go +++ b/pkg/rune/compile_access.go @@ -129,8 +129,15 @@ func (fs *funcState) setIndex(n *ast.SetIndexExpr) int32 { old := fs.alloc() pl.load(old) - v := fs.exprAny(n.Value) - fs.emit(binaryIns(n.Op.TokenType, old, old, v), n.Op) + arith, isArith := arithOps[n.Op.TokenType] + rc, rConst := literalOf(n.Value) + + if k, ok := fs.operandConst(rc, rConst && isArith, maxC); ok { + fs.emit(arithConstIns(arith, old, old, k, rc), n.Op) + } else { + fs.emit(binaryIns(n.Op.TokenType, old, old, fs.exprAny(n.Value)), n.Op) + } + pl.store(old, quiet(n)) return old @@ -153,64 +160,6 @@ func (fs *funcState) simple(e ast.Expr) bool { return false } -func (fs *funcState) update(n *ast.UpdateExpr, dst int32) { - op := &n.Operator - incr := ins{op: opIncr, x: uint8(boolNum(op.TokenType == ast.MINUS_MINUS))} - - if t, ok := n.Target.(*ast.VarExpr); ok { - kind, r := fs.lookup(t.Local) - - if kind == varLocal { - fs.checkDefined(t.Local, r, &t.Name) - - if !n.Prefix { - fs.move(dst, r) - } - - incr.a, incr.b = r, r - fs.emit(incr, op) - - if n.Prefix { - fs.move(dst, r) - } - - return - } - - old := fs.alloc() - fs.varExpr(t, old) - - v := old - if !n.Prefix { - v = fs.alloc() - } - - incr.a, incr.b = v, old - fs.emit(incr, op) - fs.store(kind, r, v, false, &t.Name) - fs.move(dst, old) - - return - } - - target := n.Target.(*ast.IndexExpr) - pl := fs.place(target.Array, target.Index, target.Property, &target.Token) - pl.check() - - old := fs.alloc() - pl.load(old) - - v := old - if !n.Prefix { - v = fs.alloc() - } - - incr.a, incr.b = v, old - fs.emit(incr, op) - pl.store(v, reads(target)) - fs.move(dst, old) -} - // quiet reports whether the write n shares nothing between loading the // path it writes and writing: its indices and value only read, and the // value is no part of the variable written. diff --git a/pkg/rune/compile_expr.go b/pkg/rune/compile_expr.go index ce926044..0d3ac80f 100644 --- a/pkg/rune/compile_expr.go +++ b/pkg/rune/compile_expr.go @@ -259,7 +259,7 @@ func fresh(e ast.Expr) bool { return isConst(n) || n.Moves && n.Local.Param == 0 case *ast.LiteralExpr, *ast.ArrayExpr, *ast.ObjectExpr, *ast.StructExpr, *ast.CallExpr, *ast.BinaryExpr, *ast.UnaryExpr, *ast.InterpolationExpr, *ast.RangeExpr, *ast.FunctionExpr, - *ast.SliceExpr, *ast.IsExpr, *ast.UpdateExpr: + *ast.SliceExpr, *ast.IsExpr: return true case *ast.LogicalExpr: return fresh(n.Left) && fresh(n.Right) @@ -385,8 +385,6 @@ func (fs *funcState) expr(e ast.Expr, dst int32) { fs.slice(n, dst) case *ast.SetIndexExpr: fs.move(dst, fs.setIndex(n)) - case *ast.UpdateExpr: - fs.update(n, dst) case *ast.RangeExpr: base := fs.rangeParts(n) fs.emit(ins{op: opRange, a: dst, b: base, x: uint8(boolNum(n.Inclusive))}, &n.Operator) @@ -554,8 +552,6 @@ func writesEarly(e ast.Expr) bool { switch n := unwrap(e).(type) { case *ast.LogicalExpr, *ast.AssignExpr, *ast.SetIndexExpr, *ast.ThrowExpr, *ast.TryExpr: return true - case *ast.UpdateExpr: - return !n.Prefix case *ast.IfExpr, *ast.MatchExpr: return slices.ContainsFunc(values(n), writesEarly) } @@ -669,7 +665,7 @@ func (fs *funcState) binary(n *ast.BinaryExpr, dst int32) { l := fs.operand(left) if isArith { - fs.emit(ins{op: arithOp(arith, true), a: dst, b: l, c: k}, op) + fs.emit(arithConstIns(arith, dst, l, k, rc), op) } else { fs.emit(ins{op: opCmpK, x: kcmp, a: dst, b: l, c: k}, op) } diff --git a/pkg/rune/compile_stmt.go b/pkg/rune/compile_stmt.go index 6be37f8f..5b7a2e20 100644 --- a/pkg/rune/compile_stmt.go +++ b/pkg/rune/compile_stmt.go @@ -128,7 +128,7 @@ func (fs *funcState) scoped(body func()) { func (fs *funcState) stmt(stmt ast.Stmt) { switch s := stmt.(type) { case *ast.ExprStmt: - fs.exprStmt(s.Expr) + fs.exprAny(s.Expr) case *ast.VarStmt: fs.varStmt(s) case *ast.PatternStmt: @@ -194,19 +194,6 @@ func (fs *funcState) returnStmt(s *ast.ReturnStmt) { fs.emit(ret, nil) } -// exprStmt drops the value, so x++ needs no copy of the old x. -func (fs *funcState) exprStmt(e ast.Expr) { - if u, ok := e.(*ast.UpdateExpr); ok { - prefix := *u - prefix.Prefix = true - fs.update(&prefix, noReg) - - return - } - - fs.exprAny(e) -} - // leaveLoop leaves the trys and defers a break or continue jumps out of. func (fs *funcState) leaveLoop() *loop { l := fs.loops[len(fs.loops)-1] diff --git a/pkg/rune/moves.go b/pkg/rune/moves.go index 7feea7b6..6460c1ed 100644 --- a/pkg/rune/moves.go +++ b/pkg/rune/moves.go @@ -305,9 +305,6 @@ func (lv *liveness) expr(e ast.Expr, live liveSet) { lv.expr(n.Value, live) lv.expr(n.Index, live) lv.expr(n.Array, live) - case *ast.UpdateExpr: - lv.holds(n.Target, live) - lv.expr(n.Target, live) case *ast.ArrayExpr: lv.exprs(n.Items, live) case *ast.InterpolationExpr: diff --git a/pkg/rune/parse_expr.go b/pkg/rune/parse_expr.go index c1a841ab..25c26b6e 100644 --- a/pkg/rune/parse_expr.go +++ b/pkg/rune/parse_expr.go @@ -307,18 +307,7 @@ func (s *Parser) unary() (ast.Expr, error) { return ast.NewUnaryExpr(right, operator), nil } - if s.match(ast.PLUS_PLUS, ast.MINUS_MINUS) { - operator := s.previous() - target, err := s.unary() - - if err != nil { - return nil, err - } - - return update(target, operator, true) - } - - return s.postfix() + return s.call() } // tryExpr parses `try value catch [name [is T | U]] => value ...`; "try" @@ -385,29 +374,6 @@ func (s *Parser) jumpExpr() (*ast.JumpExpr, error) { return &ast.JumpExpr{Stmt: ast.NewReturnStmt(v, keyword)}, nil } -func (s *Parser) postfix() (ast.Expr, error) { - expr, err := s.call() - - if err != nil { - return nil, err - } - - if s.match(ast.PLUS_PLUS, ast.MINUS_MINUS) { - return update(expr, s.previous(), false) - } - - return expr, nil -} - -func update(target ast.Expr, operator ast.Token, prefix bool) (ast.Expr, error) { - switch target.(type) { - case *ast.VarExpr, *ast.IndexExpr: - return ast.NewUpdateExpr(target, operator, prefix), nil - } - - return nil, errors.NewSyntaxError(operator, "Invalid increment target.") -} - // allowStructs sets which "Name {" start a struct literal and returns a // func restoring the previous setting. func (s *Parser) allowStructs(mode structMode) (restore func()) { diff --git a/pkg/rune/resolver.go b/pkg/rune/resolver.go index 51e08ac3..17bd7530 100644 --- a/pkg/rune/resolver.go +++ b/pkg/rune/resolver.go @@ -657,23 +657,6 @@ func (p *Resolver) VisitSliceExpr(expr *ast.SliceExpr) (value.Value, error) { return value.NilValue, nil } -func (p *Resolver) VisitUpdateExpr(expr *ast.UpdateExpr) (value.Value, error) { - p.resolveExpr(expr.Target) - - switch t := expr.Target.(type) { - case *ast.VarExpr: - p.requireMutable(t.Name, "assign to") - case *ast.IndexExpr: - if q := p.qualifier(t.Array); q != "" { - p.memberAssign(q, t.Array, t.Token) - } else { - p.requireMutableRoot(t.Array) - } - } - - return value.NilValue, nil -} - func (p *Resolver) VisitObjectExpr(expr *ast.ObjectExpr) (value.Value, error) { for _, pair := range expr.Pairs { p.resolveExpr(pair.Value) diff --git a/pkg/rune/scanner.go b/pkg/rune/scanner.go index eda05449..95c40c9f 100644 --- a/pkg/rune/scanner.go +++ b/pkg/rune/scanner.go @@ -157,8 +157,6 @@ func (s *Scanner) scanToken() { } case '-': switch { - case s.match('-'): - s.addToken(ast.MINUS_MINUS) case s.match('='): s.addToken(ast.MINUS_EQUAL) default: @@ -166,8 +164,6 @@ func (s *Scanner) scanToken() { } case '+': switch { - case s.match('+'): - s.addToken(ast.PLUS_PLUS) case s.match('='): s.addToken(ast.PLUS_EQUAL) default: diff --git a/pkg/rune/vm_slow.go b/pkg/rune/vm_slow.go index fa7c828a..484b6027 100644 --- a/pkg/rune/vm_slow.go +++ b/pkg/rune/vm_slow.go @@ -49,7 +49,7 @@ func (p *Interpreter) slow(in Instr) error { return err case opIncr: - v, err := increment(tok, regs[in.b()], int64(1-2*int(in.x()))) + v, err := arith(tok, value.Arith(in.x()), regs[in.b()], value.NewInt(1)) if err == nil { regs[in.a()] = v } diff --git a/pkg/stdlib/collections.go b/pkg/stdlib/collections.go index 4b81168b..44f035e5 100644 --- a/pkg/stdlib/collections.go +++ b/pkg/stdlib/collections.go @@ -106,8 +106,8 @@ var collectionNatives = []*Native{ return c.result(value.NewMap(m)) }}, - {"object", 0, 1, func(c *call) value.Value { - if c.has(0) && c.args[0].Kind() != value.Map && c.args[0].Kind() != value.Array { + {"object", 1, 1, func(c *call) value.Value { + if c.args[0].Kind() != value.Map && c.args[0].Kind() != value.Array { return c.typeError(0, "a map or an array of pairs") } diff --git a/test/const/assign.rn b/test/const/assign.rn index a51d5629..4857b719 100644 --- a/test/const/assign.rn +++ b/test/const/assign.rn @@ -1,3 +1,3 @@ const A = 1; A = 2; // Error at 'A': Cannot assign to constant 'A'. -A++; // Error at 'A': Cannot assign to constant 'A'. +A += 1; // Error at 'A': Cannot assign to constant 'A'. diff --git a/test/const/assign.stderr b/test/const/assign.stderr index 1f64be26..f2926a83 100644 --- a/test/const/assign.stderr +++ b/test/const/assign.stderr @@ -9,5 +9,5 @@ error: Cannot assign to constant 'A'. --> assign.rn:3:1 | 2 | A = 2; // Error at 'A': Cannot assign to constant 'A'. -3 | A++; // Error at 'A': Cannot assign to constant 'A'. +3 | A += 1; // Error at 'A': Cannot assign to constant 'A'. | ^ diff --git a/test/default/basic.rn b/test/default/basic.rn index 53caac3f..2b61c975 100644 --- a/test/default/basic.rn +++ b/test/default/basic.rn @@ -8,7 +8,7 @@ print(greet("ann", "yo", "?")); // expect: yo ann? print(greet("ann", nil)); // expect: nil ann. let mut evals = 0; -fun next() { evals++; return evals; } +fun next() { evals += 1; return evals; } fun f(a = next()) { return a; } print(f()); // expect: 1 print(f()); // expect: 2 diff --git a/test/defer/return.rn b/test/defer/return.rn index 9c9dd672..bd2f22fc 100644 --- a/test/defer/return.rn +++ b/test/defer/return.rn @@ -27,7 +27,7 @@ struct Counter { n = 0 } impl Counter { fun bump(mut self) { defer self.n += 10; - self.n++; + self.n += 1; return self.n; } } diff --git a/test/destructure/array.rn b/test/destructure/array.rn index a62e8287..9430a444 100644 --- a/test/destructure/array.rn +++ b/test/destructure/array.rn @@ -29,7 +29,7 @@ print(capture([7])()); // expect: 7 fun counter() { let [mut n] = [0]; - return () => ++n; + return () => n += 1; } let next = counter(); next(); diff --git a/test/destructure/defaults.rn b/test/destructure/defaults.rn index 3f9bcf66..9e7a6c2a 100644 --- a/test/destructure/defaults.rn +++ b/test/destructure/defaults.rn @@ -21,7 +21,7 @@ let [q, r = 5, ...more] = [1, 2, 3, 4]; print([q, r, more]); // expect: [1, 2, [3, 4]] let mut calls = 0; -let { v = calls++ } = { v: 1 }; +let { v = (calls += 1) } = { v: 1 }; print(calls); // expect: 0 let g = k => { diff --git a/test/for_in/bare_body.rn b/test/for_in/bare_body.rn index f23c9d30..789026ca 100644 --- a/test/for_in/bare_body.rn +++ b/test/for_in/bare_body.rn @@ -15,7 +15,7 @@ for x in [1, 2] { for y in [3, 4] { print(x * y); } } // expect: 8 let mut i = 0; -while i < 3 { i++; } +while i < 3 { i += 1; } print(i); // expect: 3 if true { print("yes"); } else { print("no"); } // expect: yes diff --git a/test/for_in/pattern.rn b/test/for_in/pattern.rn index 1315cfa2..0dbe4387 100644 --- a/test/for_in/pattern.rn +++ b/test/for_in/pattern.rn @@ -11,7 +11,7 @@ for i, [a, _, ...rest] in [[9, 8, 7, 6]] { print("{i} {a} {rest}"); } // expect: let mut fs = []; for { hits: mut h } in [{ hits: 1 }, { hits: 2 }] { - h++; + h += 1; fs.push(() => h); } print(fs.map(f => f())); // expect: [2, 3] diff --git a/test/impl/_geo/shapes.rn b/test/impl/_geo/shapes.rn index 1b9835c8..aa72307d 100644 --- a/test/impl/_geo/shapes.rn +++ b/test/impl/_geo/shapes.rn @@ -3,7 +3,7 @@ export struct Point { x, y = 0 } impl Point { fun origin() { return Point { x: 0 }; } fun len(self) { return self.x + self.y; } - fun shift(mut self) { self.x++; } + fun shift(mut self) { self.x += 1; } } impl string { diff --git a/test/impl/bound_mut.rn b/test/impl/bound_mut.rn index 41175f36..847018a4 100644 --- a/test/impl/bound_mut.rn +++ b/test/impl/bound_mut.rn @@ -1,7 +1,7 @@ struct Counter { n = 0 } impl Counter { - fun incr(mut self) { self.n++; } + fun incr(mut self) { self.n += 1; } } let mut c = Counter {}; diff --git a/test/impl/mut_self.rn b/test/impl/mut_self.rn index 19630b23..604e14a5 100644 --- a/test/impl/mut_self.rn +++ b/test/impl/mut_self.rn @@ -1,7 +1,7 @@ struct Counter { n = 0 } impl Counter { - fun incr(mut self) { self.n++; } + fun incr(mut self) { self.n += 1; } fun add(mut self, k) { self.n += k; return self.n; @@ -37,6 +37,7 @@ print(g.n); // expect: 2 let mut i = 0; let mut xs = [Counter {}, Counter {}]; -xs[i++].incr(); +xs[i].incr(); +i += 1; print(i); // expect: 1 print(xs); // expect: [Counter {n: 1}, Counter {n: 0}] diff --git a/test/impl/mut_self_changed.rn b/test/impl/mut_self_changed.rn index 00db54f4..3834e77e 100644 --- a/test/impl/mut_self_changed.rn +++ b/test/impl/mut_self_changed.rn @@ -4,7 +4,7 @@ struct P { i = 0 } impl P { fun list(mut self, f) { let a = f(); self.i += 10; return a; } - fun item(mut self) { self.i++; return self.i; } + fun item(mut self) { self.i += 1; return self.i; } fun nested(mut self) { return self.list(() => self.item()); } fun apart(mut self) { let add = () => self.item(); diff --git a/test/impl/mut_self_error.rn b/test/impl/mut_self_error.rn index 1507726d..8ffc386c 100644 --- a/test/impl/mut_self_error.rn +++ b/test/impl/mut_self_error.rn @@ -2,7 +2,7 @@ struct Counter { n = 0 } impl Counter { fun incr(mut self) { - self.n++; + self.n += 1; throw ValueError { message: "no" }; } } diff --git a/test/impl/mut_self_immutable.rn b/test/impl/mut_self_immutable.rn index f4c24ff8..11d1e1b0 100644 --- a/test/impl/mut_self_immutable.rn +++ b/test/impl/mut_self_immutable.rn @@ -1,7 +1,7 @@ struct Counter { n = 0 } impl Counter { - fun incr(mut self) { self.n++; } + fun incr(mut self) { self.n += 1; } } let c = Counter {}; diff --git a/test/impl/mut_self_in_place.rn b/test/impl/mut_self_in_place.rn index a2f470a0..a12bfd29 100644 --- a/test/impl/mut_self_in_place.rn +++ b/test/impl/mut_self_in_place.rn @@ -5,7 +5,7 @@ struct P { x = 0, y = 0, log = [] } let mut kept = []; impl P { - fun bump(mut self) { self.x++; self.y += 2; } + fun bump(mut self) { self.x += 1; self.y += 2; } fun twice(mut self) { self.bump(); self.bump(); self.x *= 10; } fun keep(mut self) { self.x = 1; kept.push(self); self.x = 2; } fun alias(mut self) { let before = self; self.x = 5; return before.x; } diff --git a/test/impl/mut_self_local.rn b/test/impl/mut_self_local.rn index 1fd5699b..4653819c 100644 --- a/test/impl/mut_self_local.rn +++ b/test/impl/mut_self_local.rn @@ -3,7 +3,7 @@ struct P { x = 0, y = 0 } impl P { - fun bump(mut self) { self.x++; } + fun bump(mut self) { self.x += 1; } fun get(self) { return self.x; } fun setX(mut self, v) { self.x = v; } fun setY(mut self, v) { self.y = v; } diff --git a/test/impl/mut_self_temporary.rn b/test/impl/mut_self_temporary.rn index 2c6dcf84..e0a5eb0e 100644 --- a/test/impl/mut_self_temporary.rn +++ b/test/impl/mut_self_temporary.rn @@ -1,7 +1,7 @@ struct Counter { n = 0 } impl Counter { - fun incr(mut self) { self.n++; } + fun incr(mut self) { self.n += 1; } fun get(mut self) { return self.n; } } diff --git a/test/impl/mut_self_transfer.rn b/test/impl/mut_self_transfer.rn index a728e8e7..61c3f7ec 100644 --- a/test/impl/mut_self_transfer.rn +++ b/test/impl/mut_self_transfer.rn @@ -1,7 +1,7 @@ struct C { n = 0, tag = "c" } impl C { - fun incr(mut self) { self.n++; } + fun incr(mut self) { self.n += 1; } fun add(mut self, k = 1) { self.n += k; return k; } fun twice(mut self) { self.incr(); self.incr(); } fun get(self) { return self.n; } diff --git a/test/impl/set_fields.rn b/test/impl/set_fields.rn index 650306e0..ad689bb7 100644 --- a/test/impl/set_fields.rn +++ b/test/impl/set_fields.rn @@ -5,7 +5,7 @@ impl Point { self.x += dx; self.y = self.y + dy; self["x"] *= 2; - self.y++; + self.y += 1; } } diff --git a/test/impl/temp_struct_field.rn b/test/impl/temp_struct_field.rn index 8e623b24..73cc1642 100644 --- a/test/impl/temp_struct_field.rn +++ b/test/impl/temp_struct_field.rn @@ -1,7 +1,7 @@ struct C { n = 0 } impl C { fun get(self) { return self.n; } - fun incr(mut self) { self.n++; } + fun incr(mut self) { self.n += 1; } } struct R { c } fun mk() { return R { c: C { n: 7 } }; } diff --git a/test/import/mutation.rn b/test/import/mutation.rn index a14c8c04..a6d3adca 100644 --- a/test/import/mutation.rn +++ b/test/import/mutation.rn @@ -2,6 +2,6 @@ import _lib.math; math.pi = 4; // Error at 'pi': Cannot assign to a member of module 'math'. math.calls += 1; // Error at 'calls': Cannot assign to a member of module 'math'. -math.calls++; // Error at 'calls': Cannot assign to a member of module 'math'. +math.calls += 1; // Error at 'calls': Cannot assign to a member of module 'math'. math.items[0] = 1; // Error at 'items': Cannot mutate immutable variable 'math.items'. math = 1; // Error at 'math': Cannot assign to immutable variable 'math'. diff --git a/test/import/mutation.stderr b/test/import/mutation.stderr index f034666f..8aa9a04f 100644 --- a/test/import/mutation.stderr +++ b/test/import/mutation.stderr @@ -15,13 +15,13 @@ error: Cannot assign to a member of module 'math'. --> mutation.rn:5:6 | 4 | math.calls += 1; // Error at 'calls': Cannot assign to a member of module 'math'. -5 | math.calls++; // Error at 'calls': Cannot assign to a member of module 'math'. +5 | math.calls += 1; // Error at 'calls': Cannot assign to a member of module 'math'. | ^^^^^ error: Cannot mutate immutable variable 'math.items'. --> mutation.rn:6:6 | -5 | math.calls++; // Error at 'calls': Cannot assign to a member of module 'math'. +5 | math.calls += 1; // Error at 'calls': Cannot assign to a member of module 'math'. 6 | math.items[0] = 1; // Error at 'items': Cannot mutate immutable variable 'math.items'. | ^^^^^ diff --git a/test/increment/closure.rn b/test/increment/closure.rn deleted file mode 100644 index a6318eb8..00000000 --- a/test/increment/closure.rn +++ /dev/null @@ -1,13 +0,0 @@ -let mut n = 0; -fun outer() { - let mut x = 10; - fun inner() { - fun deepest() { return x++; } - return deepest(); - } - inner(); - n++; - return x; -} -print(outer()); // expect: 11 -print(n); // expect: 1 diff --git a/test/increment/index.rn b/test/increment/index.rn deleted file mode 100644 index a6be08cc..00000000 --- a/test/increment/index.rn +++ /dev/null @@ -1,12 +0,0 @@ -let mut calls = 0; -fun idx() { calls++; return 1; } - -let mut arr = [1, 2, 3]; -print(arr[idx()]++); // expect: 2 -print(++arr[idx()]); // expect: 4 -print(arr); // expect: [1, 4, 3] -print(calls); // expect: 2 - -let mut o = {"n": 1}; -print(o.n--); // expect: 1 -print(--o["n"]); // expect: -1 diff --git a/test/increment/invalid_prefix_target.rn b/test/increment/invalid_prefix_target.rn deleted file mode 100644 index 19ebc65a..00000000 --- a/test/increment/invalid_prefix_target.rn +++ /dev/null @@ -1 +0,0 @@ ---1; // [line: 1] Error at '--': Invalid increment target. diff --git a/test/increment/invalid_prefix_target.stderr b/test/increment/invalid_prefix_target.stderr deleted file mode 100644 index ceb5b001..00000000 --- a/test/increment/invalid_prefix_target.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: Invalid increment target. - --> invalid_prefix_target.rn:1:1 - | -1 | --1; // [line: 1] Error at '--': Invalid increment target. - | ^^ diff --git a/test/increment/invalid_target.rn b/test/increment/invalid_target.rn deleted file mode 100644 index dad15317..00000000 --- a/test/increment/invalid_target.rn +++ /dev/null @@ -1,2 +0,0 @@ -let a = 1; -(a)++; // [line: 2] Error at '++': Invalid increment target. diff --git a/test/increment/invalid_target.stderr b/test/increment/invalid_target.stderr deleted file mode 100644 index 14d7a7f8..00000000 --- a/test/increment/invalid_target.stderr +++ /dev/null @@ -1,6 +0,0 @@ -error: Invalid increment target. - --> invalid_target.rn:2:4 - | -1 | let a = 1; -2 | (a)++; // [line: 2] Error at '++': Invalid increment target. - | ^^ diff --git a/test/increment/missing_property.rn b/test/increment/missing_property.rn deleted file mode 100644 index 3065f081..00000000 --- a/test/increment/missing_property.rn +++ /dev/null @@ -1,2 +0,0 @@ -let mut o = {}; -o.n++; // expect runtime error: [line: 2] KeyError: Undefined property 'n'. diff --git a/test/increment/missing_property.stderr b/test/increment/missing_property.stderr deleted file mode 100644 index 14ac25ec..00000000 --- a/test/increment/missing_property.stderr +++ /dev/null @@ -1,6 +0,0 @@ -KeyError: Undefined property 'n'. - --> missing_property.rn:2:3 - | -1 | let mut o = {}; -2 | o.n++; // expect runtime error: [line: 2] KeyError: Undefined property 'n'. - | ^ diff --git a/test/increment/type_error.rn b/test/increment/type_error.rn deleted file mode 100644 index c251af27..00000000 --- a/test/increment/type_error.rn +++ /dev/null @@ -1,2 +0,0 @@ -let mut s = "x"; -s++; // expect runtime error: [line: 2] TypeError: Operand must be a number. diff --git a/test/increment/type_error.stderr b/test/increment/type_error.stderr deleted file mode 100644 index 338a08a8..00000000 --- a/test/increment/type_error.stderr +++ /dev/null @@ -1,6 +0,0 @@ -TypeError: Operand must be a number. - --> type_error.rn:2:2 - | -1 | let mut s = "x"; -2 | s++; // expect runtime error: [line: 2] TypeError: Operand must be a number. - | ^^ diff --git a/test/increment/undefined.rn b/test/increment/undefined.rn deleted file mode 100644 index fbb0e4fd..00000000 --- a/test/increment/undefined.rn +++ /dev/null @@ -1 +0,0 @@ -nope++; // expect runtime error: [line: 1] NameError: Undefined variable 'nope'. diff --git a/test/increment/undefined.stderr b/test/increment/undefined.stderr deleted file mode 100644 index 0c0d87a5..00000000 --- a/test/increment/undefined.stderr +++ /dev/null @@ -1,5 +0,0 @@ -NameError: Undefined variable 'nope'. - --> undefined.rn:1:1 - | -1 | nope++; // expect runtime error: [line: 1] NameError: Undefined variable 'nope'. - | ^^^^ diff --git a/test/increment/variable.rn b/test/increment/variable.rn deleted file mode 100644 index 5cacb6c6..00000000 --- a/test/increment/variable.rn +++ /dev/null @@ -1,21 +0,0 @@ -let mut a = 1; -print(a++); // expect: 1 -print(a); // expect: 2 -print(++a); // expect: 3 -print(a--); // expect: 3 -print(--a); // expect: 1 -print(a); // expect: 1 - -{ - let mut local = 5; - local++; - ++local; - print(local); // expect: 7 - fun f() { local--; return local; } - print(f()); // expect: 6 -} - -let mut b = 2; -print(a++ + ++b); // expect: 4 -print(-a--); // expect: -2 -print(a); // expect: 1 diff --git a/test/int/arith.rn b/test/int/arith.rn index 2f37811e..be827b9a 100644 --- a/test/int/arith.rn +++ b/test/int/arith.rn @@ -24,13 +24,13 @@ print(1 is number); // expect: true print(1.5 is number); // expect: true let mut i = 0; -i++; +i += 1; i += 2; print(i); // expect: 3 print(math.isInt(i)); // expect: true let mut f = 0.5; -f++; +f += 1; print(f); // expect: 1.5 let xs = [10, 20, 30]; diff --git a/test/int/errors.rn b/test/int/errors.rn index e4389650..58fd809c 100644 --- a/test/int/errors.rn +++ b/test/int/errors.rn @@ -20,5 +20,5 @@ fails(() => math.abs(math.MIN_INT)); // expect: ValueError: math.abs() integer o fails(() => int(math.INF)); // expect: ValueError: int() cannot convert inf to an integer. let mut m = math.MAX_INT; -fails(() => { m++; }); // expect: ValueError: Integer overflow. +fails(() => { m += 1; }); // expect: ValueError: Integer overflow. print(1 / 0); // expect: inf diff --git a/test/interpolation/evaluation_order.rn b/test/interpolation/evaluation_order.rn index 2cbba7c5..4eb676f2 100644 --- a/test/interpolation/evaluation_order.rn +++ b/test/interpolation/evaluation_order.rn @@ -1,4 +1,4 @@ let mut i = 0; -print("{i++} {i++} {i}"); // expect: 0 1 2 +print("{i += 1} {i += 1} {i}"); // expect: 1 2 2 let mut s = "a"; print("{s} {s = "b"} {s}"); // expect: a b b diff --git a/test/match/statement.rn b/test/match/statement.rn index 61a8c2db..26698408 100644 --- a/test/match/statement.rn +++ b/test/match/statement.rn @@ -7,7 +7,7 @@ print(log); // expect: ["pushed"] let mut i = 0; while true { - i++; + i += 1; match i { 1 => { continue; }, 4 => { break; }, diff --git a/test/mutability/contents.rn b/test/mutability/contents.rn index 7a8849c3..a4ab650f 100644 --- a/test/mutability/contents.rn +++ b/test/mutability/contents.rn @@ -2,7 +2,7 @@ let arr = [[1]]; arr[0] = 2; // [line: 2] Error at 'arr': Cannot mutate immutable variable 'arr'. arr[0][0] = 2; // [line: 3] Error at 'arr': Cannot mutate immutable variable 'arr'. arr[0] += 1; // [line: 4] Error at 'arr': Cannot mutate immutable variable 'arr'. -arr[0]++; // [line: 5] Error at 'arr': Cannot mutate immutable variable 'arr'. +arr[0] += 1; // [line: 5] Error at 'arr': Cannot mutate immutable variable 'arr'. let obj = {x: 1}; obj.x = 2; // [line: 7] Error at 'obj': Cannot mutate immutable variable 'obj'. obj["x"] = 2; // [line: 8] Error at 'obj': Cannot mutate immutable variable 'obj'. diff --git a/test/mutability/contents.stderr b/test/mutability/contents.stderr index 93ace025..76d5468b 100644 --- a/test/mutability/contents.stderr +++ b/test/mutability/contents.stderr @@ -29,7 +29,7 @@ error: Cannot mutate immutable variable 'arr'. --> contents.rn:5:1 | 4 | arr[0] += 1; // [line: 4] Error at 'arr': Cannot mutate immutable variable 'arr'. -5 | arr[0]++; // [line: 5] Error at 'arr': Cannot mutate immutable variable 'arr'. +5 | arr[0] += 1; // [line: 5] Error at 'arr': Cannot mutate immutable variable 'arr'. | ^^^ | = hint: declare it as 'mut arr' on line 1 diff --git a/test/mutability/for_in_mut.rn b/test/mutability/for_in_mut.rn index 61c356d2..13006a25 100644 --- a/test/mutability/for_in_mut.rn +++ b/test/mutability/for_in_mut.rn @@ -10,7 +10,7 @@ for i, mut x in nums { print(nums); // expect: [50, 60] let mut o = {a: 1}; for k, mut v in o { - v++; + v += 1; print(v); // expect: 2 } print(o); // expect: {a: 2} diff --git a/test/mutability/increment.rn b/test/mutability/increment.rn deleted file mode 100644 index 3a8f83da..00000000 --- a/test/mutability/increment.rn +++ /dev/null @@ -1,3 +0,0 @@ -let a = 1; -a++; // [line: 2] Error at 'a': Cannot assign to immutable variable 'a'. ---a; // [line: 3] Error at 'a': Cannot assign to immutable variable 'a'. diff --git a/test/mutability/increment.stderr b/test/mutability/increment.stderr deleted file mode 100644 index 6eb2144b..00000000 --- a/test/mutability/increment.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error: Cannot assign to immutable variable 'a'. - --> increment.rn:2:1 - | -1 | let a = 1; -2 | a++; // [line: 2] Error at 'a': Cannot assign to immutable variable 'a'. - | ^ - | - = hint: declare it as 'mut a' on line 1 - -error: Cannot assign to immutable variable 'a'. - --> increment.rn:3:3 - | -2 | a++; // [line: 2] Error at 'a': Cannot assign to immutable variable 'a'. -3 | --a; // [line: 3] Error at 'a': Cannot assign to immutable variable 'a'. - | ^ - | - = hint: declare it as 'mut a' on line 1 diff --git a/test/mutability/mutable.rn b/test/mutability/mutable.rn index fc6bee1b..3d57e14d 100644 --- a/test/mutability/mutable.rn +++ b/test/mutability/mutable.rn @@ -2,5 +2,5 @@ let mut a; print(a); // expect: nil a = 1; a += 1; -a++; +a += 1; print(a); // expect: 3 diff --git a/test/mutability/mutable_contents.rn b/test/mutability/mutable_contents.rn index 14ee3b2c..0b52a8dc 100644 --- a/test/mutability/mutable_contents.rn +++ b/test/mutability/mutable_contents.rn @@ -1,6 +1,6 @@ let mut arr = [[1], 2]; arr[0][0] = 3; -arr[1]++; +arr[1] += 1; arr.push(4); arr.sort((a, b) => { return 0; }); print(arr); // expect: [[3], 3, 4] diff --git a/test/mutability/mutable_parameter.rn b/test/mutability/mutable_parameter.rn index 9ff2d546..6b498007 100644 --- a/test/mutability/mutable_parameter.rn +++ b/test/mutability/mutable_parameter.rn @@ -7,7 +7,7 @@ fun fill(mut arr, n) { let mut a = [0]; print(fill(a, 7)); // expect: nil print(a); // expect: nil -let f = (mut x) => { x++; return x; }; +let f = (mut x) => { x += 1; return x; }; let mut n = 1; print(f(n)); // expect: 2 print(n); // expect: 2 diff --git a/test/namespace/set_member.rn b/test/namespace/set_member.rn index fa173d3f..75c8e883 100644 --- a/test/namespace/set_member.rn +++ b/test/namespace/set_member.rn @@ -1,3 +1,3 @@ math.PI = 3; // Error at 'PI': Cannot assign to a member of namespace 'math'. -math.PI++; // Error at 'PI': Cannot assign to a member of namespace 'math'. +math.PI += 1; // Error at 'PI': Cannot assign to a member of namespace 'math'. module.dir = "x"; // Error at 'dir': Cannot assign to a member of namespace 'module'. diff --git a/test/namespace/set_member.stderr b/test/namespace/set_member.stderr index d774304f..4a759abf 100644 --- a/test/namespace/set_member.stderr +++ b/test/namespace/set_member.stderr @@ -8,12 +8,12 @@ error: Cannot assign to a member of namespace 'math'. --> set_member.rn:2:6 | 1 | math.PI = 3; // Error at 'PI': Cannot assign to a member of namespace 'math'. -2 | math.PI++; // Error at 'PI': Cannot assign to a member of namespace 'math'. +2 | math.PI += 1; // Error at 'PI': Cannot assign to a member of namespace 'math'. | ^^ error: Cannot assign to a member of namespace 'module'. --> set_member.rn:3:8 | -2 | math.PI++; // Error at 'PI': Cannot assign to a member of namespace 'math'. +2 | math.PI += 1; // Error at 'PI': Cannot assign to a member of namespace 'math'. 3 | module.dir = "x"; // Error at 'dir': Cannot assign to a member of namespace 'module'. | ^^^ diff --git a/test/optional/assign.rn b/test/optional/assign.rn index 49bb23c0..a9083f12 100644 --- a/test/optional/assign.rn +++ b/test/optional/assign.rn @@ -1,3 +1,3 @@ let mut o = { a: nil }; o?.a = 1; // Error at '=': Invalid assignment target. -o?.a++; // Error at '++': Invalid increment target. +o?.a += 1; // Error at '+=': Invalid assignment target. diff --git a/test/optional/assign.stderr b/test/optional/assign.stderr index 255a4a41..5d5f444b 100644 --- a/test/optional/assign.stderr +++ b/test/optional/assign.stderr @@ -5,9 +5,9 @@ error: Invalid assignment target. 2 | o?.a = 1; // Error at '=': Invalid assignment target. | ^ -error: Invalid increment target. - --> assign.rn:3:5 +error: Invalid assignment target. + --> assign.rn:3:6 | 2 | o?.a = 1; // Error at '=': Invalid assignment target. -3 | o?.a++; // Error at '++': Invalid increment target. - | ^^ +3 | o?.a += 1; // Error at '+=': Invalid assignment target. + | ^^ diff --git a/test/slice/errors.rn b/test/slice/errors.rn index 3031feb4..2aeeb1a9 100644 --- a/test/slice/errors.rn +++ b/test/slice/errors.rn @@ -1,4 +1,4 @@ let mut xs = [1, 2]; xs[0..1] = [3]; // Error at '=': Invalid assignment target. -xs[0..]++; // Error at '++': Invalid increment target. +xs[0..] += 1; // Error at '+=': Invalid assignment target. print(xs[0..2 step 1]); // Error at '..': A slice takes no step. diff --git a/test/slice/errors.stderr b/test/slice/errors.stderr index 7769448e..a4377ad6 100644 --- a/test/slice/errors.stderr +++ b/test/slice/errors.stderr @@ -5,16 +5,16 @@ error: Invalid assignment target. 2 | xs[0..1] = [3]; // Error at '=': Invalid assignment target. | ^ -error: Invalid increment target. - --> errors.rn:3:8 +error: Invalid assignment target. + --> errors.rn:3:9 | 2 | xs[0..1] = [3]; // Error at '=': Invalid assignment target. -3 | xs[0..]++; // Error at '++': Invalid increment target. - | ^^ +3 | xs[0..] += 1; // Error at '+=': Invalid assignment target. + | ^^ error: A slice takes no step. --> errors.rn:4:11 | -3 | xs[0..]++; // Error at '++': Invalid increment target. +3 | xs[0..] += 1; // Error at '+=': Invalid assignment target. 4 | print(xs[0..2 step 1]); // Error at '..': A slice takes no step. | ^^ diff --git a/test/stdlib/arrays_search.rn b/test/stdlib/arrays_search.rn index 55f8629c..753e862d 100644 --- a/test/stdlib/arrays_search.rn +++ b/test/stdlib/arrays_search.rn @@ -10,7 +10,7 @@ print(xs.findIndex(x => x > 4)); // expect: 1 print(xs.findIndex(x => x > 9)); // expect: nil let mut calls = 0; -xs.some(x => { calls++; return x == 8; }); +xs.some(x => { calls += 1; return x == 8; }); print(calls); // expect: 2 try { diff --git a/test/stdlib/conversions.rn b/test/stdlib/conversions.rn index 1231db7b..01d0f73e 100644 --- a/test/stdlib/conversions.rn +++ b/test/stdlib/conversions.rn @@ -51,7 +51,6 @@ print(number(" -0b101 ")); // expect: -5 print(number("1_000.5")); // expect: 1000.5 struct User { name, role = "guest" } -print(object()); // expect: {} print(object(map([["b", 1], ["a", 2]]))); // expect: {b: 1, a: 2} print(object([["x", 1], ["y", [2]]])); // expect: {x: 1, y: [2]} try { object({ a: 1 }); } catch e is TypeError { print(e.message); } // expect: object() expects a map or an array of pairs as argument 1, got object. diff --git a/test/struct/increment_field.rn b/test/struct/increment_field.rn deleted file mode 100644 index 5d0ec03e..00000000 --- a/test/struct/increment_field.rn +++ /dev/null @@ -1,10 +0,0 @@ -struct Point { x, y } - -impl Point { - fun step(mut self) { self.x++; self.y--; return self.x++; } -} - -let mut p = Point { x: 1, y: 2 }; -print(p.step()); // expect: 2 -print(p); // expect: Point {x: 3, y: 1} -p.x++; // expect runtime error: [line: 10] TypeError: Cannot set field 'x' of Point outside its mut self methods. diff --git a/test/struct/increment_field.stderr b/test/struct/increment_field.stderr deleted file mode 100644 index 6b3ac8cb..00000000 --- a/test/struct/increment_field.stderr +++ /dev/null @@ -1,6 +0,0 @@ -TypeError: Cannot set field 'x' of Point outside its mut self methods. - --> increment_field.rn:10:3 - | - 9 | print(p); // expect: Point {x: 3, y: 1} -10 | p.x++; // expect runtime error: [line: 10] TypeError: Cannot set field 'x' of Point outside its mut self methods. - | ^ diff --git a/test/value/arrays.rn b/test/value/arrays.rn index 5e661017..9861a4a1 100644 --- a/test/value/arrays.rn +++ b/test/value/arrays.rn @@ -93,7 +93,7 @@ print([s1, s2, s3, s4, s5]); // expect: [[1, 2, 3], [2, 1, 3], [3, 1], [1, 2], [ let mut n1 = [1, 2]; let n2 = n1; n1[0] += 10; -n1[1]++; +n1[1] += 1; print(n2); // expect: [1, 2] print(n1); // expect: [11, 3] diff --git a/test/value/containers.rn b/test/value/containers.rn index b9704a40..2a04ee9a 100644 --- a/test/value/containers.rn +++ b/test/value/containers.rn @@ -102,7 +102,7 @@ print(byId); // expect: map {1: {name: "bob", seen: set {5}, n: 2}} let mut cfg = { a: { b: { c: 1 } } }; let ca = cfg.a; let cb = cfg.a.b; -cfg.a.b.c++; +cfg.a.b.c += 1; cfg.a.b.d = 0; print(ca); // expect: {b: {c: 1}} print(cb); // expect: {c: 1} diff --git a/test/value/inout.rn b/test/value/inout.rn index 0b24d5e1..4201a520 100644 --- a/test/value/inout.rn +++ b/test/value/inout.rn @@ -122,7 +122,7 @@ print(own); // expect: ["b", "c"] // An owned struct goes back after its mut self calls. struct Counter { n = 0 } -impl Counter { fun incr(mut self) { self.n++; } } +impl Counter { fun incr(mut self) { self.n += 1; } } fun twice(mut c) { c.incr(); c.incr(); } let mut c = Counter {}; let c0 = c; diff --git a/test/value/moves.rn b/test/value/moves.rn index 087be518..04f7422a 100644 --- a/test/value/moves.rn +++ b/test/value/moves.rn @@ -20,7 +20,7 @@ let mut n = 0; while n < 2 { let mut c = w; c[0] = 9; - n++; + n += 1; } print(w); // expect: [0] diff --git a/test/value/places.rn b/test/value/places.rn index d29ec7c5..0864c585 100644 --- a/test/value/places.rn +++ b/test/value/places.rn @@ -13,7 +13,7 @@ print(grid); // expect: [[9, 0], [0, 9]] // Compound operators and increments. let g3 = grid; grid[0][1] += 5; -grid[1][0]++; +grid[1][0] += 1; print(g3); // expect: [[9, 0], [0, 9]] print(grid); // expect: [[9, 5], [1, 9]] @@ -84,7 +84,7 @@ inner(); let mut g = [[0, 0]]; let row = g[0]; - g[0][1]++; + g[0][1] += 1; g[0][0] += 3; print(row); // expect: [0, 0] print(g); // expect: [[3, 1]] diff --git a/test/vm/loop_closures.rn b/test/vm/loop_closures.rn index 56fd4ca3..01a475ab 100644 --- a/test/vm/loop_closures.rn +++ b/test/vm/loop_closures.rn @@ -12,7 +12,7 @@ let mut k = 0; while k < 3 { let c = k; gs.push(() => { return c; }); - k++; + k += 1; } for g in gs { print(g()); } // expect: 0 // expect: 1 diff --git a/test/vm/nested_loops.rn b/test/vm/nested_loops.rn index 54e4bbfa..30b53f33 100644 --- a/test/vm/nested_loops.rn +++ b/test/vm/nested_loops.rn @@ -2,7 +2,7 @@ let mut out = ""; for i in ["0", "1", "2"] { let mut j = 0; while true { - j++; + j += 1; if j > 2 { break; } if j == 1 { continue; } for c in "ab" { diff --git a/test/vm/registers.rn b/test/vm/registers.rn index bb6e3600..e3fcaddc 100644 --- a/test/vm/registers.rn +++ b/test/vm/registers.rn @@ -13,9 +13,6 @@ fun f(v) { return v + 1; } let mut a = [y, w]; a = [a[1], a[0]]; print(a); // expect: [4, 5] - let mut i = 5; - i = i++ + i; - print(i); // expect: 11 let mut o = {v: 1}; o.v += o.v * 10; print(o.v); // expect: 11 @@ -23,5 +20,3 @@ fun f(v) { return v + 1; } s = s + s + s; print(s); // expect: aaa } -x = x++; -print(x); // expect: 1 diff --git a/test/vm/shared_cell.rn b/test/vm/shared_cell.rn index 7a3d436d..7f322296 100644 --- a/test/vm/shared_cell.rn +++ b/test/vm/shared_cell.rn @@ -1,6 +1,6 @@ fun make() { let mut n = 0; - fun inc() { n++; return n; } + fun inc() { n += 1; return n; } fun get() { return n; } return [inc, get]; } diff --git a/testdata/disasm/closures.golden b/testdata/disasm/closures.golden index 8d4ef143..62fb3e1e 100644 --- a/testdata/disasm/closures.golden +++ b/testdata/disasm/closures.golden @@ -33,7 +33,7 @@ counter: arity 0, 2 registers, 0 upvalues inc: arity 0, 2 registers, 1 upvalues 0 GETUPVAL 1 0 0 - 1 ADDK 0 1 0 + 1 INCR 0 1 0 2 SETUPVAL 0 0 0 3 GETUPVAL 0 0 0 4 RETURN 0 0 0 x=1 y=false diff --git a/testdata/disasm/data.golden b/testdata/disasm/data.golden index 6b5e4fe3..6dca0861 100644 --- a/testdata/disasm/data.golden +++ b/testdata/disasm/data.golden @@ -5,7 +5,7 @@ error: Cannot mutate immutable variable 'a'. --> data.rn:5:1 | 4 | let a = [1, 2, 3]; -5 | a[1]++; +5 | a[1] += 1; | ^ | = hint: declare it as 'mut a' on line 4 diff --git a/testdata/disasm/data.rn b/testdata/disasm/data.rn index 86e27990..1d0aca88 100644 --- a/testdata/disasm/data.rn +++ b/testdata/disasm/data.rn @@ -2,6 +2,6 @@ let mut o = {x: 1, y: [1, 2]}; o.x = o.x + 1; o["y"][0] += 5; let a = [1, 2, 3]; -a[1]++; +a[1] += 1; print(a.len() + o.x * 2 - 1 / 3); print("a" + "b" == "ab"); diff --git a/testdata/disasm/loops.golden b/testdata/disasm/loops.golden index ddd3c8ee..cfe06da8 100644 --- a/testdata/disasm/loops.golden +++ b/testdata/disasm/loops.golden @@ -5,7 +5,7 @@ exit: 0 1 LOADK 2 0 1 2 LOADK 1 0 2 3 JMP 0 0 5 - 4 ADDK 1 1 3 + 4 INCR 1 1 0 5 JMPCMPK 1 4 4 x=0 y=true 6 LOADK 3 0 2 7 LOADK 4 0 5 diff --git a/testdata/disasm/methods.rn b/testdata/disasm/methods.rn index eafa5d5d..ede6ac76 100644 --- a/testdata/disasm/methods.rn +++ b/testdata/disasm/methods.rn @@ -2,7 +2,7 @@ struct C { n } impl C { fun get(self) { return self.n; } - fun incr(mut self) { self.n++; } + fun incr(mut self) { self.n += 1; } } let mut c = C { n: 0 }; diff --git a/testdata/fmt/layout.golden b/testdata/fmt/layout.golden index 970b20e5..9adc1e57 100644 --- a/testdata/fmt/layout.golden +++ b/testdata/fmt/layout.golden @@ -10,7 +10,7 @@ export fun add(a, b = 1, ...rest) { fun main() { let x = -1; let y = - -x; - let z = x++ + ++y; + let z = x + y; let o = { a: 1, "b": 2, [k]: 3, ...rest }; let e = {}; let s = "hi {o.a + f("in {x}")} there"; diff --git a/testdata/fmt/layout.rn b/testdata/fmt/layout.rn index 5a5eb6db..8c8023a5 100644 --- a/testdata/fmt/layout.rn +++ b/testdata/fmt/layout.rn @@ -6,7 +6,7 @@ return a+b ; fun main(){ let x=-1;let y = - -x; - let z=x++ + ++y; + let z=x+y; let o={a:1,"b":2,[k]:3,...rest}; let e = {}; let s = "hi {o.a + f("in {x}")} there";