Skip to content

Commit b46a36c

Browse files
committed
feat: added shifting operators parsing
1 parent 14963c8 commit b46a36c

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

compiler/ast/src/operators.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,24 @@ pub fn parse_math_operator(tokens: &Vec<LexerToken>, ind: &mut usize) -> Diagnos
88
let op = match tokens[*ind].tok_type {
99
LexerTokenType::Plus => MathOperatorType::Add,
1010
LexerTokenType::Minus => MathOperatorType::Subtract,
11-
LexerTokenType::Asterisk => MathOperatorType::Multiply,
12-
LexerTokenType::Divide => MathOperatorType::Divide,
11+
LexerTokenType::Asterisk => {
12+
if tokens[*ind + 1].tok_type == LexerTokenType::Asterisk {
13+
*ind += 1;
14+
15+
MathOperatorType::ShiftLeft
16+
} else {
17+
MathOperatorType::Multiply
18+
}
19+
}
20+
LexerTokenType::Divide => {
21+
if tokens[*ind + 1].tok_type == LexerTokenType::Divide {
22+
*ind += 1;
23+
24+
MathOperatorType::ShiftRight
25+
} else {
26+
MathOperatorType::Divide
27+
}
28+
}
1329

1430
_ => return Err(make_unexpected_simple_error(&tokens[*ind], &tokens[*ind].tok_type).into())
1531
};

compiler/astoir_mir_lowering/src/math.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn lower_hir_math_operation_int(left: BaseMIRValue, right: BaseMIRValue, ope
5353
MathOperatorType::Add => build_int_add(&mut ctx.mir_ctx, left, right, signed)?,
5454
MathOperatorType::Subtract => build_int_sub(&mut ctx.mir_ctx, left, right, signed)?,
5555
MathOperatorType::Multiply => build_int_mul(&mut ctx.mir_ctx, left, right, signed)?,
56-
MathOperatorType::Divide => build_int_div(&mut ctx.mir_ctx, left, right, signed)?
56+
MathOperatorType::Divide => build_int_div(&mut ctx.mir_ctx, left, right, signed)?,
5757
};
5858

5959
return Ok(res.into());

compiler/compiler_utils/src/operators.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ pub enum MathOperatorType {
66
Add,
77
Subtract,
88
Multiply,
9-
Divide
9+
Divide,
10+
ShiftLeft,
11+
ShiftRight
1012
}
1113

1214
/// Represents an actual math operator

0 commit comments

Comments
 (0)