Skip to content

Commit

Permalink
Use "-> None" when function returns nothing (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli authored Dec 9, 2023
1 parent 91e38b9 commit b709670
Show file tree
Hide file tree
Showing 157 changed files with 343 additions and 313 deletions.
7 changes: 4 additions & 3 deletions doc/syntax-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,17 @@ Jou has a few different kinds of tokens:
- `continue`
- `True`
- `False`
- `None`
- `NULL`
- `self`
- `void`
- `noreturn`
- `and`
- `or`
- `not`
- `self`
- `as`
- `sizeof`
- `assert`
- `void`
- `noreturn`
- `bool`
- `byte`
- `short`
Expand Down
2 changes: 1 addition & 1 deletion examples/aoc2023/day02/part2.jou
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Game:
green: int
blue: int

def update(self, text: byte*) -> void:
def update(self, text: byte*) -> None:
n: int
color: byte[10]
assert sscanf(text, "%d %9s", &n, color) == 2
Expand Down
2 changes: 1 addition & 1 deletion examples/aoc2023/day03/part2.jou
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def read_file(filename: byte*) -> byte*:
return result


def find_whole_number(input: byte*, a_digit: byte*, start: byte**, end: byte**) -> void:
def find_whole_number(input: byte*, a_digit: byte*, start: byte**, end: byte**) -> None:
*start = a_digit
while *start > input and is_ascii_digit((*start)[-1]):
--*start
Expand Down
4 changes: 2 additions & 2 deletions examples/aoc2023/day05/part1.jou
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Map:
triples: long[3][50]
ntriples: int

def add_triple(self, s: byte*) -> void:
def add_triple(self, s: byte*) -> None:
a: long
b: long
c: long
Expand All @@ -34,7 +34,7 @@ class Input:
maps: Map[10]
nmaps: int

def add_seeds(self, line: byte*) -> void:
def add_seeds(self, line: byte*) -> None:
assert self->n_seed_numbers == 0
assert starts_with(line, "seeds: ")

Expand Down
10 changes: 5 additions & 5 deletions examples/aoc2023/day05/part2.jou
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class List:
def end(self) -> long*:
return &self->ptr[self->len]

def append(self, n: long) -> void:
def append(self, n: long) -> None:
if self->alloc == self->len:
if self->alloc == 0:
self->alloc = 4
Expand All @@ -24,11 +24,11 @@ class List:

self->ptr[self->len++] = n

def extend(self, other: List) -> void:
def extend(self, other: List) -> None:
for v = other.ptr; v < other.end(); v++:
self->append(*v)

def remove_dupes(self) -> void:
def remove_dupes(self) -> None:
for i = self->len-1; i >= 0; i--:
# delete i'th number if it occurs after index i
for k = i+1; k < self->len; k++:
Expand All @@ -41,7 +41,7 @@ class Map:
triples: long[3][50]
ntriples: int

def add_triple(self, s: byte*) -> void:
def add_triple(self, s: byte*) -> None:
a: long
b: long
c: long
Expand Down Expand Up @@ -109,7 +109,7 @@ class Input:
maps: Map[10]
nmaps: int

def add_seeds(self, line: byte*) -> void:
def add_seeds(self, line: byte*) -> None:
assert self->n_seed_ranges == 0
assert starts_with(line, "seeds: ")
line = &line[6]
Expand Down
2 changes: 1 addition & 1 deletion examples/aoc2023/day06/part2.jou
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "stdlib/io.jou"
import "stdlib/math.jou"


def remove_all_whitespace(s: byte*) -> void:
def remove_all_whitespace(s: byte*) -> None:
while *s != '\0':
if is_ascii_whitespace(*s):
memmove(s, &s[1], strlen(s))
Expand Down
4 changes: 2 additions & 2 deletions examples/aoc2023/day07/part1.jou
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ class Hand:
return 0


def swap(h1: Hand*, h2: Hand*) -> void:
def swap(h1: Hand*, h2: Hand*) -> None:
temp = *h1
*h1 = *h2
*h2 = temp


def sort(hands: Hand*, nhands: int) -> void:
def sort(hands: Hand*, nhands: int) -> None:
# bubble sort go brrr
for sorted_part_len = 1; sorted_part_len < nhands; sorted_part_len++:
i = sorted_part_len
Expand Down
4 changes: 2 additions & 2 deletions examples/aoc2023/day07/part2.jou
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ class Hand:
return 0


def swap(h1: Hand*, h2: Hand*) -> void:
def swap(h1: Hand*, h2: Hand*) -> None:
temp = *h1
*h1 = *h2
*h2 = temp


def sort(hands: Hand*, nhands: int) -> void:
def sort(hands: Hand*, nhands: int) -> None:
# bubble sort go brrr
for sorted_part_len = 1; sorted_part_len < nhands; sorted_part_len++:
i = sorted_part_len
Expand Down
2 changes: 1 addition & 1 deletion examples/aoc2023/day08/part1.jou
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Input:
nodes: Node[1000]
nnodes: int

def add_node(self, node: Node) -> void:
def add_node(self, node: Node) -> None:
assert self->nnodes < sizeof(self->nodes)/sizeof(self->nodes[0])
self->nodes[self->nnodes++] = node

Expand Down
16 changes: 8 additions & 8 deletions examples/aoc2023/day08/part2.jou
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Input:
nodes: Node[1000]
nnodes: int

def add_node(self, node: Node) -> void:
def add_node(self, node: Node) -> None:
assert self->nnodes < sizeof(self->nodes)/sizeof(self->nodes[0])
self->nodes[self->nnodes++] = node

Expand All @@ -27,7 +27,7 @@ class Input:
return &self->nodes[i]
assert False

def find_node_pointers(self) -> void:
def find_node_pointers(self) -> None:
for i = 0; i < self->nnodes; i++:
self->nodes[i].left_node = self->find_node(self->nodes[i].left)
self->nodes[i].right_node = self->find_node(self->nodes[i].right)
Expand All @@ -45,7 +45,7 @@ class List:
assert self->len != 0
return self->end()[-1]

def append(self, n: long) -> void:
def append(self, n: long) -> None:
if self->alloc == self->len:
if self->alloc == 0:
self->alloc = 4
Expand All @@ -57,12 +57,12 @@ class List:

self->ptr[self->len++] = n

def extend(self, other: List) -> void:
def extend(self, other: List) -> None:
for v = other.ptr; v < other.end(); v++:
self->append(*v)


def swap(a: long*, b: long*) -> void:
def swap(a: long*, b: long*) -> None:
temp = *a
*a = *b
*b = temp
Expand Down Expand Up @@ -99,11 +99,11 @@ class ZCounts:
first_cycle: List
cycle_offset: long # 10 in the example, each cycle starts 10 bigger than previous

def free(self) -> void:
def free(self) -> None:
free(self->non_repeating.ptr)
free(self->first_cycle.ptr)

def print(self) -> void:
def print(self) -> None:
printf(" ")
for p = self->non_repeating.ptr; p < self->non_repeating.end(); p++:
printf("%d ", *p)
Expand All @@ -115,7 +115,7 @@ class ZCounts:
printf("%d ", *p + k*self->cycle_offset)
printf("| ...\n")

def simplify_cycles(self) -> void:
def simplify_cycles(self) -> None:
# If the first cycle repeats the same thing twice, reduce it to half of its length.
# If the first cycle repeats the same thing 3 times, reduce it to 1/3 length.
# And so on.
Expand Down
Loading

0 comments on commit b709670

Please sign in to comment.