-
Notifications
You must be signed in to change notification settings - Fork 0
/
loo.v
68 lines (59 loc) · 1.33 KB
/
loo.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
struct Position {
data string
mut:
position int
}
fn (mut position Position) increment(increment_by int) int {
position.position += increment_by
return position.position
}
fn (position Position) current_character() string {
if position.position == position.data.len {
return ';'
} else {
return position.data[position.position].str()
}
}
fn create_byte_array(data string) []byte {
mut byte_array := []byte{}
for index := 0; index < data.len; index++ {
byte_array << data[index]
}
return byte_array
}
fn execute(data string) {
data_array := data.split('')
mut ascii := 0
for current_character in data_array {
if current_character == '+' {
ascii += 1
} else if current_character == '-' {
ascii -= 1
} else if current_character == ';' {
break
} else if current_character == '#' {
print(byte(ascii).ascii_str())
}
}
}
// Capturing the filename from the command
// line arguments and throwing an error if
// the filename is not mentioned
// Return the file content if it exists
fn source(arguments []string) string {
if arguments.len == 0 {
eprintln("No filename mentioned")
}
filename := arguments[0]
data := os.read_file(filename) or {
panic("Error reading $filename")
return ''
}
return data
}
fn main() {
arguments := os.args[1..]
source_code := source(arguments)
execute(source_code)
}