Skip to content

Commit 15941d4

Browse files
committed
turing now does a "precheck" for LOC commands, this allows IF to work.
1 parent 0976c40 commit 15941d4

File tree

7 files changed

+45
-13
lines changed

7 files changed

+45
-13
lines changed

LANGUAGE_DOC.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
- `INIT [x]` - Create the memory space with a size of `x`. Clears memory.
44
- `GOTO [x]` - Sets the read position of the program's memory to location `x`.
55
- `JUMP [x]` - Jump's to the execution point `x`.
6-
- `LOC [x]` - Set the line the command to the execution point number `x`. DO NOT use this is combination with other commands, it should be standalone. In addition, execution points must be declared first (so you can't jump to `LOC` points later in the program). **WARNING: You can only have 1,000 execution points in one program (but you can change where**
6+
- `LOC [x]` - Set the line the command to the execution point number `x`. DO NOT use this is combination with other commands, it should be standalone. **WARNING: You can only have 1,000 execution points in one program (but you can change where**
77
- Move commands: `LEFT` and `PREV` go backwards, while `RIGHT` and `PREV` go forwards (to be added)
88
- `WRITE [x] (y)` - Writes `x` to the current position. If `y` is specified, it will use `y` rather than the current position.
99
- `LOGIWRITE ([x]) (y)` - Similar to `WRITE`, but evaluates the expression in `x` first, and then sets the value.

src/main.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,18 @@ fn main() {
4040
let mut current_location: usize = 0;
4141
let mut current_line: usize = 0;
4242

43-
//BUG: `continue` statements do not let the add one to current_line statement run.
43+
// Itterate over lines
44+
for current_line in 0..lines.len() {
45+
let line = lines[current_line].clone();
46+
47+
if loc_regex.is_match(&line).unwrap() {
48+
let index_string = loc_regex.find(&line).unwrap().unwrap().as_str();
49+
let index = index_string.parse::<usize>().unwrap();
50+
51+
jump_list[index] = current_line;
52+
}
53+
}
54+
4455
// Loop through the lines
4556
loop {
4657
let line = lines[current_line].to_string();
@@ -127,17 +138,6 @@ fn main() {
127138
println!("{}", binary_vector_to_int(segment.to_vec()));
128139
}
129140
}
130-
// Location saving
131-
else if loc_regex.is_match(&line).unwrap() {
132-
let index_string = loc_regex.find(&line).unwrap().unwrap().as_str();
133-
let index = index_string.parse::<usize>().unwrap();
134-
135-
// println!(
136-
// "Attempting to add a jump coordiante to index number {}, at itteration {}",
137-
// index, l
138-
// );
139-
jump_list[index] = current_line;
140-
}
141141
// Jumping
142142
else if jump_regex.is_match(&line).unwrap() {
143143
let index_string = jump_regex.find(&line).unwrap().unwrap().as_str();
@@ -197,6 +197,10 @@ fn main() {
197197
memory_line[final_param] = value;
198198
}
199199
}
200+
201+
// Uncomment for debugging
202+
// println!("{}", line);
203+
200204
// Add one to the current line
201205
current_line = current_line + 1;
202206
}
File renamed without changes.

src/test/if.trng

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
INIT 8
2+
WRITE 1 0
3+
WRITE 1 2
4+
5+
WBOOL (2 AND 0) 1
6+
7+
IF 1 1
8+
BIT PRINT 7
9+
END
10+
11+
LOC 1
12+
BIT PRINT 2
13+
END
14+
File renamed without changes.

src/test/skip.trng

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
INIT 8
2+
3+
WRITE 1 1
4+
5+
JUMP 1
6+
7+
BIT PRINT 0
8+
END
9+
10+
LOC 1
11+
BIT PRINT 1
12+
END
13+
14+
// Printing of a `1` mean it worked, a `0` means the pre-loction check failed
File renamed without changes.

0 commit comments

Comments
 (0)