diff --git a/examples/brainfuck.zr b/examples/brainfuck.zr index 70f0035..26f0027 100644 --- a/examples/brainfuck.zr +++ b/examples/brainfuck.zr @@ -12,38 +12,38 @@ func main[] : i64 op := src[i] if op == '>' - p = p + 1 + p += 1 else if op == '<' - p = p - 1 + p -= 1 else if op == '+' - memory[p] = memory[p] + 1 + memory[p] += 1 else if op == '-' - memory[p] = memory[p] - 1 + memory[p] -= 1 else if op == '.' io.print_char(memory[p]) else if op == ',' memory[p] = io.read_char() else if op == '[' if !memory[p] - i = i + 1 + i += 1 opened := 0 while i < src_len && !(src[i] == ']' && !opened) if src[i] == '[' - opened = opened + 1 + opened += 1 else if src[i] == ']' - opened = opened - 1 - i = i + 1 + opened -= 1 + i += 1 else if op == ']' if memory[p] - i = i - 1 + i -= 1 closed := 0 while i >= 0 && !(src[i] == '[' && !closed) if src[i] == ']' - closed = closed + 1 + closed += 1 else if src[i] == '[' - closed = closed - 1 - i = i - 1 + closed -= 1 + i -= 1 - i = i + 1 + i += 1 mem.free(memory) diff --git a/examples/chip8.zr b/examples/chip8.zr index 32f1e5a..6f0f433 100644 --- a/examples/chip8.zr +++ b/examples/chip8.zr @@ -60,7 +60,7 @@ func chip8_disassemble[c: CHIP8, ins_count: i64] : void high := c->memory[c->pc] as i64 low := c->memory[c->pc + 1] as i64 - c->pc = c->pc + 2 + c->pc += 2 ins := (high << 8) | low nnn := ins & 0x0fff @@ -156,7 +156,7 @@ func chip8_disassemble[c: CHIP8, ins_count: i64] : void func chip8_step[c: CHIP8] : void high := c->memory[c->pc] as i64 low := c->memory[c->pc + 1] as i64 - c->pc = c->pc + 2 + c->pc += 2 ins := (high << 8) | low nnn := ins & 0x0fff @@ -175,22 +175,22 @@ func chip8_step[c: CHIP8] : void else if op == 0x1 c->pc = nnn else if op == 0x2 - c->sp = c->sp + 1 + c->sp += 1 array.set(c->stack, c->sp, c->pc) c->pc = nnn else if op == 0x3 if c->reg[x] == kk - c->pc = c->pc + 2 + c->pc += 2 else if op == 0x4 if c->reg[x] != kk - c->pc = c->pc + 2 + c->pc += 2 else if op == 0x5 if c->reg[x] == c->reg[y] - c->pc = c->pc + 2 + c->pc += 2 else if op == 0x6 c->reg[x] = kk else if op == 0x7 - c->reg[x] = c->reg[x] + kk + c->reg[x] += kk else if op == 0x8 if n == 0x0 c->reg[x] = c->reg[y] @@ -218,7 +218,7 @@ func chip8_step[c: CHIP8] : void c->reg[x] = c->reg[x] << 1 else if op == 0x9 if c->reg[x] != c->reg[y] - c->pc = c->pc + 2 + c->pc += 2 else if op == 0xa c->I = nnn else if op == 0xb @@ -240,10 +240,10 @@ func chip8_step[c: CHIP8] : void else if op == 0xe if kk == 0x9e if IsKeyDown(array.nth(c->keyboard_map, c->reg[x] as i64)) - c->pc = c->pc + 2 + c->pc += 2 else if kk == 0xa1 if !IsKeyDown(array.nth(c->keyboard_map, c->reg[x] as i64)) - c->pc = c->pc + 2 + c->pc += 2 else if op == 0xf if kk == 0x07 c->reg[x] = c->delay_timer @@ -259,7 +259,7 @@ func chip8_step[c: CHIP8] : void else if kk == 0x18 c->sound_timer = c->reg[x] else if kk == 0x1E - c->I = c->I + c->reg[x] + c->I += c->reg[x] else if kk == 0x29 c->I = c->reg[x] as i64 * 5 else if kk == 0x33 diff --git a/examples/curl.zr b/examples/curl.zr index 63eb8aa..221d74b 100644 --- a/examples/curl.zr +++ b/examples/curl.zr @@ -19,7 +19,7 @@ func main[argc: i64, argv: ptr] : i64 while i < url_len if url[i] == '/' break - i = i + 1 + i += 1 host := str.substr(url, host_start, i - host_start) path := "/" @@ -59,7 +59,7 @@ func main[argc: i64, argv: ptr] : i64 found = true end_index = i + 4 break - i = i + 1 + i += 1 header_size = current_size if end_index < header_size diff --git a/examples/fib.zr b/examples/fib.zr index 8977a97..b0ec677 100644 --- a/examples/fib.zr +++ b/examples/fib.zr @@ -5,5 +5,5 @@ func main[] : i64 while a < 100000 io.println_i64(a) temp := b - b = a + b + b += a a = temp diff --git a/examples/puzzles/aoc2024_01.zr b/examples/puzzles/aoc2024_01.zr index 0fc3966..514750b 100644 --- a/examples/puzzles/aoc2024_01.zr +++ b/examples/puzzles/aoc2024_01.zr @@ -2,7 +2,7 @@ func part1[l1: Array, l2: Array] : void out := 0 for i in 0..l1->size - out = out + math.abs(array.nth(l1, i) - array.nth(l2, i)) + out += math.abs(array.nth(l1, i) - array.nth(l2, i)) io.println_i64(out) @@ -10,7 +10,7 @@ func part2[l1: Array, l2: Array] : void out := 0 for i in 0..l1->size - out = out + array.nth(l1, i) * alg.count(l2, array.nth(l1, i)) + out += array.nth(l1, i) * alg.count(l2, array.nth(l1, i)) io.println_i64(out) diff --git a/examples/puzzles/aoc2024_02.zr b/examples/puzzles/aoc2024_02.zr index c1b96d7..a8b2347 100644 --- a/examples/puzzles/aoc2024_02.zr +++ b/examples/puzzles/aoc2024_02.zr @@ -18,7 +18,7 @@ func part1[data: Array] : void for i in 0..data->size if check(array.nth(data, i)) - out = out + 1 + out += 1 io.println_i64(out) @@ -27,14 +27,14 @@ func part2[data: Array] : void for i in 0..data->size if check(array.nth(data, i)) - out = out + 1 + out += 1 else arr : Array = array.nth(data, i) for j in 0..arr->size sliced := array.concat(array.slice(arr, 0, j), array.slice(arr, j + 1, arr->size - (j + 1))) if check(sliced) - out = out + 1 + out += 1 break io.println_i64(out) diff --git a/examples/puzzles/aoc2024_04.zr b/examples/puzzles/aoc2024_04.zr index 536256f..c7d80e8 100644 --- a/examples/puzzles/aoc2024_04.zr +++ b/examples/puzzles/aoc2024_04.zr @@ -19,21 +19,21 @@ func part1[lines: Array] : void for x in 0..lines->size for y in 0..str.len(array.nth(lines, x)) if check(lines, x, y, 0, 1) - out = out + 1 + out += 1 if check(lines, x, y, 0, -1) - out = out + 1 + out += 1 if check(lines, x, y, 1, 0) - out = out + 1 + out += 1 if check(lines, x, y, -1, 0) - out = out + 1 + out += 1 if check(lines, x, y, 1, 1) - out = out + 1 + out += 1 if check(lines, x, y, -1, -1) - out = out + 1 + out += 1 if check(lines, x, y, 1, -1) - out = out + 1 + out += 1 if check(lines, x, y, -1, 1) - out = out + 1 + out += 1 io.println_i64(out) @@ -51,7 +51,7 @@ func part2[lines: Array] : void s[4] = 0 if str.equal(s, "MSSM") || str.equal(s, "SMMS") || str.equal(s, "MMSS") || str.equal(s, "SSMM") - out = out + 1 + out += 1 io.println_i64(out) diff --git a/examples/puzzles/aoc2024_05.zr b/examples/puzzles/aoc2024_05.zr index cf02440..bc8b246 100644 --- a/examples/puzzles/aoc2024_05.zr +++ b/examples/puzzles/aoc2024_05.zr @@ -31,7 +31,7 @@ func part1[updates: Array, rules_left: Array, rules_right: Array] : void for i in 0..updates->size update : Array = array.nth(updates, i) if check(update, rules_left, rules_right) - out = out + array.nth(update, update->size / 2) + out += array.nth(update, update->size / 2) io.println_i64(out) @@ -42,7 +42,7 @@ func part2[updates: Array, rules_left: Array, rules_right: Array] : void update : Array = array.nth(updates, i) if !check(update, rules_left, rules_right) sort_by_rules(update, rules_left, rules_right) - out = out + array.nth(update, update->size / 2) + out += array.nth(update, update->size / 2) io.println_i64(out) diff --git a/examples/puzzles/aoc2024_07.zr b/examples/puzzles/aoc2024_07.zr index 91f8b71..52a65d1 100644 --- a/examples/puzzles/aoc2024_07.zr +++ b/examples/puzzles/aoc2024_07.zr @@ -16,7 +16,7 @@ func solve[ops: Array, e: Array] : i64 op : str = array.nth(ops, array.nth(indices, i)) if str.equal(op, "add") - res = res + array.nth(e_1, i + 1) + res += array.nth(e_1, i + 1) else if str.equal(op, "mul") res = res * array.nth(e_1, i + 1) else if str.equal(op, "concat") @@ -33,7 +33,7 @@ func solve[ops: Array, e: Array] : i64 done = false break array.set(indices, i, 0) - i = i - 1 + i -= 1 if done return 0 @@ -42,7 +42,7 @@ func part1[equations: Array] : void out := 0 for i in 0..equations->size - out = out + solve(["add", "mul"], array.nth(equations, i)) + out += solve(["add", "mul"], array.nth(equations, i)) io.println_i64(out) @@ -50,7 +50,7 @@ func part2[equations: Array] : void out := 0 for i in 0..equations->size - out = out + solve(["add", "mul", "concat"], array.nth(equations, i)) + out += solve(["add", "mul", "concat"], array.nth(equations, i)) io.println_i64(out) diff --git a/examples/puzzles/aoc2025_01.zr b/examples/puzzles/aoc2025_01.zr index 28ad2b8..5483946 100644 --- a/examples/puzzles/aoc2025_01.zr +++ b/examples/puzzles/aoc2025_01.zr @@ -8,16 +8,16 @@ func part1[lines: Array] : void n := str.substr(line, 1, str.len(line) - 1) |> str.parse_i64() if dir == 'L' - dial = dial - n + dial -= n while dial < 0 - dial = 100 + dial + dial += 100 else - dial = dial + n + dial += n while dial >= 100 - dial = dial - 100 + dial -= 100 if dial == 0 - password = password + 1 + password += 1 io.println_i64(password) @@ -32,17 +32,17 @@ func part2[lines: Array] : void if dir == 'L' for i in 0..n - dial = dial - 1 + dial -= 1 if dial == 0 - password = password + 1 + password += 1 if dial == -1 dial = 99 else for i in 0..n - dial = dial + 1 + dial += 1 if dial == 100 dial = 0 - password = password + 1 + password += 1 io.println_i64(password) diff --git a/examples/puzzles/aoc2025_02.zr b/examples/puzzles/aoc2025_02.zr index 8c57e08..72d5252 100644 --- a/examples/puzzles/aoc2025_02.zr +++ b/examples/puzzles/aoc2025_02.zr @@ -18,7 +18,7 @@ func part1[ranges: Array] : void for n in (start)..end+1 if part1_is_invalid_id(str.from_i64(n)) - sum = sum + n + sum += n io.println_i64(sum) @@ -49,7 +49,7 @@ func part2[ranges: Array] : void for n in (start)..end+1 if part2_is_invalid_id(str.from_i64(n)) - sum = sum + n + sum += n io.println_i64(sum) diff --git a/examples/puzzles/aoc2025_03.zr b/examples/puzzles/aoc2025_03.zr index 5c4d2b2..3f0e491 100644 --- a/examples/puzzles/aoc2025_03.zr +++ b/examples/puzzles/aoc2025_03.zr @@ -15,7 +15,7 @@ func part1[lines: Array] : void if n > largest largest = n - sum = sum + largest + sum += largest io.println_i64(sum) // had to cheat this one @@ -41,7 +41,7 @@ func part2[lines: Array] : void for i in 0..lines->size line : str = array.nth(lines, i) - sum = sum + part2_rec(line, 0, 12) + sum += part2_rec(line, 0, 12) io.println_i64(sum) func main[] : i64 diff --git a/examples/puzzles/euler_00.zr b/examples/puzzles/euler_00.zr index a0e5ae1..b5786e9 100644 --- a/examples/puzzles/euler_00.zr +++ b/examples/puzzles/euler_00.zr @@ -3,6 +3,6 @@ func main[] : i64 for i in 0..266000 if i % 2 != 0 - sum = sum + i * i + sum += i * i io.println_i64(sum) diff --git a/examples/puzzles/euler_01.zr b/examples/puzzles/euler_01.zr index a62eb2e..f0636d2 100644 --- a/examples/puzzles/euler_01.zr +++ b/examples/puzzles/euler_01.zr @@ -3,6 +3,6 @@ func main[] : i64 for i in 0..1000 if i % 5 == 0 || i % 3 == 0 - sum = sum + i + sum += i io.println_i64(sum) diff --git a/examples/puzzles/euler_02.zr b/examples/puzzles/euler_02.zr index 26cb747..3e7a325 100644 --- a/examples/puzzles/euler_02.zr +++ b/examples/puzzles/euler_02.zr @@ -5,9 +5,9 @@ func main[] : i64 while a < 4000000 if a % 2 == 0 - sum = sum + a + sum += a temp := b - b = a + b + b += a a = temp io.println_i64(sum) diff --git a/examples/puzzles/euler_03.zr b/examples/puzzles/euler_03.zr index d1dff74..e235491 100644 --- a/examples/puzzles/euler_03.zr +++ b/examples/puzzles/euler_03.zr @@ -6,6 +6,6 @@ func main[] : i64 if n % f == 0 n = n / f else - f = f + 1 + f += 1 io.println_i64(n) diff --git a/examples/puzzles/euler_06.zr b/examples/puzzles/euler_06.zr index 5ea6421..dcb5768 100644 --- a/examples/puzzles/euler_06.zr +++ b/examples/puzzles/euler_06.zr @@ -1,11 +1,11 @@ func main[] : i64 sum_of_squares := 0 for i in 1..101 - sum_of_squares = sum_of_squares + i * i + sum_of_squares += i * i square_of_sum := 0 for i in 1..101 - square_of_sum = square_of_sum + i + square_of_sum += i square_of_sum = square_of_sum * square_of_sum io.println_i64(square_of_sum - sum_of_squares) diff --git a/examples/puzzles/euler_07.zr b/examples/puzzles/euler_07.zr index 92422ef..e42fba7 100644 --- a/examples/puzzles/euler_07.zr +++ b/examples/puzzles/euler_07.zr @@ -4,8 +4,8 @@ func main[] : i64 i := 1 while true if math.is_prime(i) - found = found + 1 + found += 1 if found == 10001 io.println_i64(i) break - i = i + 1 + i += 1 diff --git a/examples/puzzles/euler_08.zr b/examples/puzzles/euler_08.zr index 308514b..08466f8 100644 --- a/examples/puzzles/euler_08.zr +++ b/examples/puzzles/euler_08.zr @@ -8,7 +8,7 @@ func main[] : i64 j := 0 while j < 13 s = s * (n[i + j] - '0') - j = j + 1 + j += 1 if s > out out = s io.println_i64(out) diff --git a/examples/puzzles/euler_10.zr b/examples/puzzles/euler_10.zr index 16e9f97..7057e28 100644 --- a/examples/puzzles/euler_10.zr +++ b/examples/puzzles/euler_10.zr @@ -3,5 +3,5 @@ func main[] : i64 for i in 0..2000000 if math.is_prime(i) - sum = sum + i + sum += i io.println_i64(sum) diff --git a/examples/puzzles/euler_12.zr b/examples/puzzles/euler_12.zr index 01d73ec..9e550d4 100644 --- a/examples/puzzles/euler_12.zr +++ b/examples/puzzles/euler_12.zr @@ -4,18 +4,18 @@ func num_divisors[n: i64] : i64 out := 0 for i in 1..end+1 if n % i == 0 - out = out + 2 + out += 2 if end * end == n - out = out - 1 + out -= 1 return out func main[] : i64 n := 0 i := 1 while true - n = n + i + n += i if num_divisors(n) > 500 io.println_i64(n) break - i = i + 1 + i += 1 diff --git a/examples/puzzles/euler_14.zr b/examples/puzzles/euler_14.zr index b9e0094..9d3454e 100644 --- a/examples/puzzles/euler_14.zr +++ b/examples/puzzles/euler_14.zr @@ -7,7 +7,7 @@ func collatz_seq[n: i64]: i64 i := 1 while n != 1 n = collatz_num(n) - i = i + 1 + i += 1 return i func main[] : i64 diff --git a/examples/puzzles/euler_16.zr b/examples/puzzles/euler_16.zr index 30024f0..1ba8408 100644 --- a/examples/puzzles/euler_16.zr +++ b/examples/puzzles/euler_16.zr @@ -14,6 +14,6 @@ func main[] : i64 sum := 0 for i in 0..n->size - sum = sum + array.nth(n, i) + sum += array.nth(n, i) io.println_i64(sum) diff --git a/examples/puzzles/euler_17.zr b/examples/puzzles/euler_17.zr index a9bd855..2546d5f 100644 --- a/examples/puzzles/euler_17.zr +++ b/examples/puzzles/euler_17.zr @@ -6,21 +6,21 @@ func main[] : i64 sum := 0 for i in 1..10 - sum = sum + array.nth(s1, i) + sum += array.nth(s1, i) for i in 0..10 - sum = sum + array.nth(s2, i) + sum += array.nth(s2, i) for i in 20..100 - sum = sum + array.nth(s3, i / 10) + array.nth(s1, i % 10) + sum += array.nth(s3, i / 10) + array.nth(s1, i % 10) for i in 1..10 - sum = sum + array.nth(s1, i) + 7 + sum += array.nth(s1, i) + 7 for j in 1..10 - sum = sum + array.nth(s1, i) + 7 + 3 + array.nth(s1, j) + sum += array.nth(s1, i) + 7 + 3 + array.nth(s1, j) for j in 0..10 - sum = sum + array.nth(s1, i) + 7 + 3 + array.nth(s2, j) + sum += array.nth(s1, i) + 7 + 3 + array.nth(s2, j) for j in 20..100 - sum = sum + array.nth(s1, i) + 7 + 3 + array.nth(s3, j / 10) + array.nth(s1, j % 10) + sum += array.nth(s1, i) + 7 + 3 + array.nth(s3, j / 10) + array.nth(s1, j % 10) - sum = sum + array.nth(s1, 1) + 8 + sum += array.nth(s1, 1) + 8 io.println_i64(sum) diff --git a/examples/puzzles/euler_19.zr b/examples/puzzles/euler_19.zr index e2c0c4e..fef3eda 100644 --- a/examples/puzzles/euler_19.zr +++ b/examples/puzzles/euler_19.zr @@ -16,7 +16,7 @@ func main[] : i64 for year in 1901..2001 for mon in 1..13 if wday == 5 - sun = sun + 1 + sun += 1 wday = (wday + days(year, mon)) % 7 io.println_i64(sun) diff --git a/examples/puzzles/euler_20.zr b/examples/puzzles/euler_20.zr index 10ca23a..19ff04a 100644 --- a/examples/puzzles/euler_20.zr +++ b/examples/puzzles/euler_20.zr @@ -16,6 +16,6 @@ func main[] : i64 sum := 0 for i in 0..n->size - sum = sum + array.nth(n, i) + sum += array.nth(n, i) io.println_i64(sum) diff --git a/examples/puzzles/euler_21.zr b/examples/puzzles/euler_21.zr index 837b5ef..1bb3b97 100644 --- a/examples/puzzles/euler_21.zr +++ b/examples/puzzles/euler_21.zr @@ -16,6 +16,6 @@ func main[] : i64 for i in 2..10000 d := divisors_sum(i) if i < d && i == divisors_sum(d) - sum = sum + i + d + sum += i + d io.println_i64(sum) diff --git a/examples/raylib.zr b/examples/raylib.zr index 640dcfd..04c974b 100644 --- a/examples/raylib.zr +++ b/examples/raylib.zr @@ -26,13 +26,13 @@ func main[] : i64 while !WindowShouldClose() if IsKeyDown(KEY_W) & 255 - y = y - 10 + y -= 10 if IsKeyDown(KEY_S) & 255 - y = y + 10 + y += 10 if IsKeyDown(KEY_A) & 255 - x = x - 10 + x -= 10 if IsKeyDown(KEY_D) & 255 - x = x + 10 + x += 10 BeginDrawing() ClearBackground(WHITE) diff --git a/src/parser.rs b/src/parser.rs index ed6125e..3f28b93 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -355,6 +355,35 @@ impl Parser { op, value, }) + } else if self.match_token(&[TokenType::PlusEqual, TokenType::MinusEqual]) { + let op = self.previous().clone(); + let right = self.expression()?; + let binary_token = Token { + token_type: match op.token_type { + TokenType::PlusEqual => TokenType::Plus, + TokenType::MinusEqual => TokenType::Minus, + _ => unreachable!(), + }, + lexeme: match op.token_type { + TokenType::PlusEqual => String::from("+"), + TokenType::MinusEqual => String::from("-"), + _ => unreachable!(), + }, + loc: op.loc.clone(), + }; + Ok(Stmt::Assign { + left: expr.clone(), + op: Token { + token_type: TokenType::Equal, + lexeme: String::from("="), + loc: op.loc, + }, + value: Expr::new(ExprKind::Binary { + left: Box::new(expr), + op: binary_token, + right: Box::new(right), + }), + }) } else { Ok(Stmt::Expression(expr)) } diff --git a/src/std/net.zr b/src/std/net.zr index 6ccb903..6647784 100644 --- a/src/std/net.zr +++ b/src/std/net.zr @@ -138,11 +138,11 @@ func net.encode_dns_name[domain: str] : Blob if i == domain_len || domain[i] == '.' part_len := i - part_start buf->data[out_pos] = part_len & 0xff - out_pos = out_pos + 1 + out_pos += 1 mem.copy(domain as ptr + part_start, buf->data + out_pos, part_len) - out_pos = out_pos + part_len + out_pos += part_len part_start = i + 1 - i = i + 1 + i += 1 buf->data[out_pos] = 0 return buf @@ -188,11 +188,11 @@ func net.resolve[domain: str] : i64, bool pos := 12 // skip header (12 bytes) while pkt->data[pos] != 0 - pos = pos + pkt->data[pos] + 1 // skip question + pos += pkt->data[pos] + 1 // skip question - pos = pos + 5 // skip null byte, type(2), class(2) + pos += 5 // skip null byte, type(2), class(2) - pos = pos + 12 // skip name(2), type(2), class(2), ttl(4), rdlength(2) + pos += 12 // skip name(2), type(2), class(2), ttl(4), rdlength(2) out := net.pack_addr(pkt->data[pos] as i64, pkt->data[pos+1] as i64, pkt->data[pos+2] as i64, pkt->data[pos+3] as i64) net.UDPPacket.free(pkt) diff --git a/src/std/std.zr b/src/std/std.zr index eecfc64..8ff5d3a 100644 --- a/src/std/std.zr +++ b/src/std/std.zr @@ -90,7 +90,7 @@ func mem.free[x: any] : void if next as ptr && next->free expected_next := (blk as ptr + MEM_BLOCK_SIZE + blk->size) as mem.Block if expected_next as ptr == next as ptr - blk->size = blk->size + MEM_BLOCK_SIZE + next->size + blk->size += MEM_BLOCK_SIZE + next->size blk->next = next->next if next->next as ptr next->next->prev = blk @@ -101,7 +101,7 @@ func mem.free[x: any] : void if prev as ptr && prev->free expected_blk := (prev as ptr + MEM_BLOCK_SIZE + prev->size) as mem.Block if expected_blk as ptr == blk as ptr - prev->size = prev->size + MEM_BLOCK_SIZE + blk->size + prev->size += MEM_BLOCK_SIZE + blk->size prev->next = blk->next if blk->next as ptr blk->next->prev = prev @@ -168,28 +168,28 @@ func mem.zero[x: ptr, size: i64] : void i := 0 while i + 8 <= size mem.write64(x + i, 0) - i = i + 8 + i += 8 while i < size x[i] = 0 as u8 - i = i + 1 + i += 1 func mem.copy[src: ptr, dst: ptr, n: i64] : void if dst > src && dst < src + n i := n while i - 8 >= 0 - i = i - 8 + i -= 8 mem.write64(dst + i, mem.read64(src + i)) while i > 0 - i = i - 1 + i -= 1 dst[i] = src[i] else i := 0 while i + 8 <= n mem.write64(dst + i, mem.read64(src + i)) - i = i + 8 + i += 8 while i < n dst[i] = src[i] - i = i + 1 + i += 1 func mem.read8[x: ptr] : u8 return x[0] @@ -246,20 +246,20 @@ func io.printf[..] : void while s[0] if s[0] == '%' - s = s + 1 + s += 1 if s[0] == 'd' io.print_i64(_var_arg(i) as i64) - i = i + 1 + i += 1 else if s[0] == 'x' io.print_i64_hex(_var_arg(i) as i64) - i = i + 1 + i += 1 else if s[0] == 's' io.print(_var_arg(i) as str) - i = i + 1 + i += 1 else if s[0] == 'c' io.print_char(_var_arg(i) as u8) - i = i + 1 + i += 1 else if s[0] == '%' io.print_char('%') else if s[0] == 0 @@ -268,7 +268,7 @@ func io.printf[..] : void panic("io.printf: unrecognized format") else io.print_char(s[0]) - s = s + 1 + s += 1 func io.snprintf[..] : i64 buf := _var_arg(0) as ptr @@ -281,7 +281,7 @@ func io.snprintf[..] : i64 while s[0] if s[0] == '%' - s = s + 1 + s += 1 if s[0] == 'd' tmp := _stackalloc(21) @@ -289,32 +289,32 @@ func io.snprintf[..] : i64 tmp_len := str.len(tmp as str) remaining := size - n - 1 mem.copy(tmp, buf + n, math.min(tmp_len, remaining)) - n = n + tmp_len - i = i + 1 + n += tmp_len + i += 1 else if s[0] == 'x' tmp := _stackalloc(17) str.hex_from_i64_buf(tmp, _var_arg(i) as i64) tmp_len := str.len(tmp as str) remaining := size - n - 1 mem.copy(tmp, buf + n, math.min(tmp_len, remaining)) - n = n + tmp_len - i = i + 1 + n += tmp_len + i += 1 else if s[0] == 's' tmp_str := _var_arg(i) as str tmp_len := str.len(tmp_str) remaining := size - n - 1 mem.copy(tmp_str as ptr, buf + n, math.min(tmp_len, remaining)) - n = n + tmp_len - i = i + 1 + n += tmp_len + i += 1 else if s[0] == 'c' if n < size - 1 buf[n] = _var_arg(i) as u8 - n = n + 1 - i = i + 1 + n += 1 + i += 1 else if s[0] == '%' if n < size - 1 buf[n] = '%' - n = n + 1 + n += 1 else if s[0] == 0 break else @@ -322,8 +322,8 @@ func io.snprintf[..] : i64 else if n < size - 1 buf[n] = s[0] - n = n + 1 - s = s + 1 + n += 1 + s += 1 if n < size buf[n] = 0 @@ -449,7 +449,7 @@ func io.write_binary_file[path: str, content: ptr, size: i64] : bool func str.len[s: str] : i64 i := 0 while s[i] - i = i + 1 + i += 1 return i func str.make_copy[s: str] : str @@ -463,7 +463,7 @@ func str.equal[a: str, b: str] : bool while a[i] != 0 && b[i] != 0 if a[i] != b[i] return false - i = i + 1 + i += 1 return a[i] == b[i] func str.is_whitespace[x: u8] : bool @@ -543,10 +543,10 @@ func str.trim[s: str] : str end := len - 1 while start <= end && str.is_whitespace(s[start]) - start = start + 1 + start += 1 while end >= start && str.is_whitespace(s[end]) - end = end - 1 + end -= 1 return str.substr(s, start, end - start + 1) @@ -575,9 +575,9 @@ func str.split[haystack: str, needle: str]: Array if match array.push(result, str.substr(haystack, start, i - start)) start = i + needle_len - i = i + needle_len + i += needle_len continue - i = i + 1 + i += 1 array.push(result, str.substr(haystack, start, haystack_len - start)) return result @@ -609,16 +609,16 @@ func str.from_i64_buf[buf: ptr, n: i64] : void tmp := _stackalloc(21) end := 20 tmp[end] = 0 - end = end - 1 + end -= 1 for i in 0..19 if n == 0 break tmp[end] = '0' + (n % 10) n = n / 10 - end = end - 1 + end -= 1 if neg tmp[end] = '-' - end = end - 1 + end -= 1 len := 19 - end for i in 0..len buf[i] = tmp[end + 1 + i] @@ -646,7 +646,7 @@ func str.hex_from_i64_buf[buf: ptr, n: i64] : void break tmp[len] = hex_chars[n & 15] n = (n >> 4) & mask - len = len + 1 + len += 1 for j in 0..len buf[j] = tmp[len - 1 - j] @@ -666,7 +666,7 @@ func str.parse_i64[s: str] : i64 sign := 1 if i < len && s[i] == '-' sign = -1 - i = i + 1 + i += 1 num := 0 while i < len @@ -674,7 +674,7 @@ func str.parse_i64[s: str] : i64 if d < '0' || d > '9' break num = num * 10 + (d - '0') - i = i + 1 + i += 1 return num * sign func str.hex_encode[s: str, s_len: i64] : str @@ -731,13 +731,13 @@ func str.Builder._grow[b: str.Builder, needed: i64] : void func str.Builder.append_char[b: str.Builder, c: u8] : void str.Builder._grow(b, 1) b->data[b->size] = c - b->size = b->size + 1 + b->size += 1 func str.Builder.append[b: str.Builder, s: str] : void len := str.len(s) str.Builder._grow(b, len) mem.copy(s as ptr, b->data + b->size, len) - b->size = b->size + len + b->size += len func str.Builder.build[b: str.Builder] : str s := mem.alloc(b->size + 1) as str @@ -820,7 +820,7 @@ func math.is_prime[n: i64]: bool while i * i <= n if n % i == 0 || n % (i + 2) == 0 return false - i = i + 6 + i += 6 return true struct Array @@ -856,7 +856,7 @@ func array.push[xs: Array, x: any] : void xs->capacity = new_capacity mem.write64(xs->data + xs->size * 8, x) - xs->size = xs->size + 1 + xs->size += 1 func array.free[xs: Array] : void if xs->data != 0 @@ -986,7 +986,7 @@ func alg._partition[arr: Array, low: i64, high: i64] : i64 i := low - 1 for j in (low)..high if array.nth(arr, j) as i64 <= pivot - i = i + 1 + i += 1 temp : i64 = array.nth(arr ,i) array.set(arr, i, array.nth(arr, j)) array.set(arr, j, temp) @@ -999,7 +999,7 @@ func alg.count[arr: Array, item: any] : i64 count := 0 for i in 0..arr->size if array.nth(arr, i) == item - count = count + 1 + count += 1 return count func alg.map[arr: Array, fn: fnptr] : Array @@ -1044,7 +1044,7 @@ func os.urandom_buf[buf: ptr, n: i64] : void ret := _builtin_syscall(SYS_getrandom, buf + pos, n - pos, 0) if ret <= 0 panic("os.urandom_buf: syscall failed") - pos = pos + ret + pos += ret func os.urandom[n: i64]: ptr buf := mem.alloc(n) @@ -1119,7 +1119,7 @@ func os.list_directory[path: str] : Array, bool skip = true if !skip array.push(files, str.make_copy(name as str)) - pos = pos + len + pos += len _builtin_syscall(SYS_close, fd) return files, true diff --git a/src/tokenizer.rs b/src/tokenizer.rs index bd08ef2..a7804f9 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -8,7 +8,9 @@ pub enum TokenType { RightBracket, Comma, Plus, + PlusEqual, Minus, + MinusEqual, Star, Slash, Mod, @@ -154,7 +156,13 @@ impl Tokenizer { ')' => self.add_token(TokenType::RightParen)?, '[' => self.add_token(TokenType::LeftBracket)?, ']' => self.add_token(TokenType::RightBracket)?, - '+' => self.add_token(TokenType::Plus)?, + '+' => { + if self.match_char('=') { + self.add_token(TokenType::PlusEqual)? + } else { + self.add_token(TokenType::Plus)? + } + } '*' => self.add_token(TokenType::Star)?, ',' => self.add_token(TokenType::Comma)?, '%' => self.add_token(TokenType::Mod)?, @@ -162,7 +170,9 @@ impl Tokenizer { ':' => self.add_token(TokenType::Colon)?, '~' => self.add_token(TokenType::Tilde)?, '-' => { - if self.match_char('>') { + if self.match_char('=') { + self.add_token(TokenType::MinusEqual)? + } else if self.match_char('>') { self.add_token(TokenType::Arrow)? } else { self.add_token(TokenType::Minus)?