Add binary and hex number parsing

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2024-09-26 10:03:54 -07:00
parent cd9617d2fd
commit 1dd058ae18
4 changed files with 120 additions and 5 deletions

View File

@@ -889,6 +889,10 @@ impl ExprVisitor for Compiler {
TokenKind::Number => {
let obj = if expr.token.text.contains('.') {
FloatInst::create(expr.token.text.parse().unwrap())
} else if expr.token.text.starts_with("0x") || expr.token.text.starts_with("0X") {
IntInst::create(i64::from_str_radix(&expr.token.text[2..], 16).unwrap())
} else if expr.token.text.starts_with("0b") || expr.token.text.starts_with("0B") {
IntInst::create(i64::from_str_radix(&expr.token.text[2..], 2).unwrap())
} else {
IntInst::create(expr.token.text.parse().unwrap())
};