Compare commits

...

2 Commits

Author SHA1 Message Date
8afb2c2572 Fix bug in Logic Operator conversion 2025-07-09 19:00:03 +03:00
974647b401 Fix FullToken positions 2025-07-09 18:54:51 +03:00
4 changed files with 10 additions and 7 deletions

View File

@ -359,12 +359,12 @@ impl CmpPredicate {
use LLVMIntPredicate::*;
match (self, signed) {
(LT, true) => LLVMIntSLT,
(GT, true) => LLVMIntSGT,
(LE, true) => LLVMIntSLE,
(GT, true) => LLVMIntSGT,
(GE, true) => LLVMIntSGE,
(LT, false) => LLVMIntULT,
(GT, false) => LLVMIntUGT,
(LE, false) => LLVMIntULE,
(GT, false) => LLVMIntUGT,
(GE, false) => LLVMIntUGE,
(EQ, _) => LLVMIntEQ,
(NE, _) => LLVMIntNE,

View File

@ -1,12 +1,12 @@
// Main
fn main() -> bool {
return 1 == fibonacci(3);
return 2 == fibonacci(3);
}
// Fibonacci
fn fibonacci(value: u16) -> u16 {
if value < 3 {
if value <= 2 {
return 1;
}
return 5 + fibonacci(value - 2);
return fibonacci(value - 1) + fibonacci(value - 2);
}

View File

@ -291,7 +291,7 @@ impl mir::LogicOperator {
match self {
mir::LogicOperator::LT => CmpPredicate::LT,
mir::LogicOperator::GT => CmpPredicate::GT,
mir::LogicOperator::LE => CmpPredicate::LT,
mir::LogicOperator::LE => CmpPredicate::LE,
mir::LogicOperator::GE => CmpPredicate::GE,
mir::LogicOperator::EQ => CmpPredicate::EQ,
mir::LogicOperator::NE => CmpPredicate::NE,

View File

@ -134,6 +134,9 @@ pub fn tokenize<T: Into<String>>(to_tokenize: T) -> Result<Vec<FullToken>, Error
let mut tokens = Vec::new();
while let Some(character) = &cursor.next() {
// Save "current" token first character position
let position = (cursor.position.0 - 1, cursor.position.1);
let variant = match character {
// Whitespace
w if w.is_whitespace() => continue,
@ -204,7 +207,7 @@ pub fn tokenize<T: Into<String>>(to_tokenize: T) -> Result<Vec<FullToken>, Error
tokens.push(FullToken {
token: variant,
position: cursor.position,
position,
});
}