Add binary and hex number parsing
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -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())
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user