Skip to content

Commit f5cf77d

Browse files
committed
bug fix
1 parent f1fcc47 commit f5cf77d

File tree

7 files changed

+17
-14
lines changed

7 files changed

+17
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "minicode"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55

66
[dependencies]

src/interpreter/code_operations.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ pub fn calculate<'a>(
2121
let old_value = match target.get(key) {
2222
Some(s) => match s {
2323
Int(i) => i,
24-
Line(_s) => &0,
24+
Line(_s) => panic!("wrong type for calculate"),
2525
},
26-
None => &0,
26+
None => panic!("not value for calculate"),
2727
};
2828

2929
let new_value = match o_type {
@@ -51,9 +51,9 @@ pub fn condition(
5151
return i != target_value;
5252
}
5353
}
54-
Line(_s) => panic!("not value"),
54+
Line(_s) => panic!("condition - wrong type value"),
5555
},
56-
None => panic!("not value"),
56+
None => panic!("condition - not value"),
5757
};
5858
}
5959

@@ -65,6 +65,6 @@ pub fn print_value(key: &String, storage: &HashMap<&String, ValueType>) {
6565
Int(i) => println!("{}", i),
6666
Line(s) => println!("{}", s),
6767
},
68-
None => panic!("not value"),
68+
None => panic!("not value for print"),
6969
};
7070
}

src/interpreter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn exegete(operations: Vec<OpCode>) {
1616
Create(k, v) => code_operations::create(k, v, &mut addresses),
1717
Print(k) => code_operations::print_value(k, &addresses),
1818
Operation(k, o, v) => code_operations::calculate(k, o, v, &mut addresses),
19-
ErrorCode(e) => panic!("{}", e),
19+
ErrorCode(e) => println!("{} - line - {}", e, pointer + 1),
2020
Condition(k, v, b, p) => {
2121
let result = code_operations::condition(k, b, v, &addresses);
2222
if result {

src/parser/opcode_operations.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn calculation(data: Vec<&str>) -> OpCode {
1616

1717
match data[3].to_string().parse::<i64>() {
1818
Ok(parsed) => Operation(value_name, op, parsed),
19-
Err(_e) => ErrorCode("wrong operation".to_string()),
19+
Err(_e) => ErrorCode("wrong type for operation".to_string()),
2020
}
2121
}
2222

@@ -25,17 +25,17 @@ pub fn condition(data: Vec<&str>) -> OpCode {
2525
let true_or_false = match data[2] {
2626
"=" => true,
2727
"!" => false,
28-
_ => return ErrorCode("wrong operation".to_string()),
28+
_ => return ErrorCode("wrong condition".to_string()),
2929
};
3030

3131
let target_value = match data[3].parse::<i64>() {
3232
Ok(parsed) => parsed,
33-
Err(_) => return ErrorCode("wrong operation".to_string()),
33+
Err(_) => return ErrorCode("wrong target value for operation".to_string()),
3434
};
3535

3636
let target_pointer = match data[4].parse::<usize>() {
3737
Ok(parsed) => parsed,
38-
Err(_) => return ErrorCode("wrong operation".to_string()),
38+
Err(_) => return ErrorCode("wrong target pointer".to_string()),
3939
};
4040

4141
Condition(value_name, target_value, true_or_false, target_pointer)
@@ -45,7 +45,7 @@ pub fn user_var(data: Vec<&str>) -> OpCode {
4545
let mut input = String::new();
4646
let value_name = data[1].to_string();
4747
io::stdin().read_line(&mut input).expect("dont read");
48-
match input.parse::<i64>() {
48+
match input.trim().parse::<i64>() {
4949
Ok(parsed) => Create(value_name, Int(parsed)),
5050
Err(_e) => Create(value_name, Line(input)),
5151
}

src/parser/opcode_parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn get_opcode(line: &String) -> OpCode {
1919
} else if parts[0] == "?" {
2020
opcode_operations::condition(parts)
2121
} else {
22-
ErrorCode("no command".to_string())
22+
ErrorCode("Could not recognize the command".to_string())
2323
}
2424
}
2525

test/examples/arithmetic.mc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$> a
2+
= a + 10
3+
p a

0 commit comments

Comments
 (0)