Compare commits
No commits in common. "9df1593de958cc5a729a28a46b7afc3b6f4d721c" and "c4f78471cda366bebf2d6f700dd07e5e78dd5d9a" have entirely different histories.
9df1593de9
...
c4f78471cd
@ -40,7 +40,7 @@ pub enum TypeKind {
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Literal {
|
pub enum Literal {
|
||||||
Integer(u128),
|
Integer(u64),
|
||||||
Decimal(f64),
|
Decimal(f64),
|
||||||
Bool(bool),
|
Bool(bool),
|
||||||
String(String),
|
String(String),
|
||||||
|
@ -23,10 +23,7 @@ impl Parse for Type {
|
|||||||
return Err(stream.expected_err("array length (number)")?);
|
return Err(stream.expected_err("array length (number)")?);
|
||||||
};
|
};
|
||||||
stream.expect(Token::BracketClose)?;
|
stream.expect(Token::BracketClose)?;
|
||||||
TypeKind::Array(
|
TypeKind::Array(Box::new(inner.0), length)
|
||||||
Box::new(inner.0),
|
|
||||||
length.parse().expect("Array length not parseable as u64!"),
|
|
||||||
)
|
|
||||||
} else if let Some(Token::Et) = stream.peek() {
|
} else if let Some(Token::Et) = stream.peek() {
|
||||||
stream.expect(Token::Et)?;
|
stream.expect(Token::Et)?;
|
||||||
let mutable = if let Some(Token::MutKeyword) = stream.peek() {
|
let mutable = if let Some(Token::MutKeyword) = stream.peek() {
|
||||||
@ -160,19 +157,15 @@ impl Parse for PrimaryExpression {
|
|||||||
let Some(Token::DecimalValue(fractional)) = stream.next() else {
|
let Some(Token::DecimalValue(fractional)) = stream.next() else {
|
||||||
return Err(stream.expected_err("fractional part")?);
|
return Err(stream.expected_err("fractional part")?);
|
||||||
};
|
};
|
||||||
|
let log = (fractional as f64).log10().ceil() as u32;
|
||||||
|
let value = (*v as f64) + (fractional as f64) / (10u64.pow(log) as f64);
|
||||||
Expression(
|
Expression(
|
||||||
Kind::Literal(Literal::Decimal(
|
Kind::Literal(Literal::Decimal(value)),
|
||||||
format!("{}.{}", v, fractional)
|
|
||||||
.parse()
|
|
||||||
.expect("Decimal is not parseable as f64!"),
|
|
||||||
)),
|
|
||||||
stream.get_range().unwrap(),
|
stream.get_range().unwrap(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Expression(
|
Expression(
|
||||||
Kind::Literal(Literal::Integer(
|
Kind::Literal(Literal::Integer(*v)),
|
||||||
v.parse().expect("Integer is not parseable as u128!"),
|
|
||||||
)),
|
|
||||||
stream.get_range().unwrap(),
|
stream.get_range().unwrap(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ pub enum Token {
|
|||||||
/// Values
|
/// Values
|
||||||
Identifier(String),
|
Identifier(String),
|
||||||
/// Number with at most one decimal point
|
/// Number with at most one decimal point
|
||||||
DecimalValue(String),
|
DecimalValue(u64),
|
||||||
/// Some character literal that was surrounded by 'single-quotes'.
|
/// Some character literal that was surrounded by 'single-quotes'.
|
||||||
CharLit(String),
|
CharLit(String),
|
||||||
/// Some string literal that was surrounded by "double-quotes".
|
/// Some string literal that was surrounded by "double-quotes".
|
||||||
@ -318,7 +318,7 @@ pub fn tokenize<T: Into<String>>(to_tokenize: T) -> Result<Vec<FullToken>, Error
|
|||||||
value += &c.to_string();
|
value += &c.to_string();
|
||||||
cursor.next();
|
cursor.next();
|
||||||
}
|
}
|
||||||
Token::DecimalValue(value)
|
Token::DecimalValue(value.parse().expect("Decimal not parseable to u64"))
|
||||||
}
|
}
|
||||||
'-' if cursor.first() == Some('>') => {
|
'-' if cursor.first() == Some('>') => {
|
||||||
cursor.next(); // Eat `>`
|
cursor.next(); // Eat `>`
|
||||||
|
@ -107,16 +107,6 @@ impl TypeKind {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn binop_hint(&self, op: &BinaryOperator) -> Option<TypeKind> {
|
|
||||||
match op {
|
|
||||||
BinaryOperator::Add | BinaryOperator::Minus | BinaryOperator::Mult => {
|
|
||||||
Some(self.clone())
|
|
||||||
}
|
|
||||||
BinaryOperator::And => None,
|
|
||||||
BinaryOperator::Cmp(_) => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn signed(&self) -> bool {
|
pub fn signed(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
TypeKind::Bool => false,
|
TypeKind::Bool => false,
|
||||||
@ -163,7 +153,7 @@ impl TypeKind {
|
|||||||
TypeKind::U128 => 128,
|
TypeKind::U128 => 128,
|
||||||
TypeKind::Void => 0,
|
TypeKind::Void => 0,
|
||||||
TypeKind::Char => 8,
|
TypeKind::Char => 8,
|
||||||
TypeKind::Array(type_kind, len) => type_kind.size_of() * (*len as u64),
|
TypeKind::Array(type_kind, len) => type_kind.size_of() * len,
|
||||||
TypeKind::CustomType(..) => 32,
|
TypeKind::CustomType(..) => 32,
|
||||||
TypeKind::CodegenPtr(_) => 64,
|
TypeKind::CodegenPtr(_) => 64,
|
||||||
TypeKind::Vague(_) => panic!("Tried to sizeof a vague type!"),
|
TypeKind::Vague(_) => panic!("Tried to sizeof a vague type!"),
|
||||||
|
@ -171,7 +171,7 @@ pub enum Literal {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||||
pub enum VagueLiteral {
|
pub enum VagueLiteral {
|
||||||
Number(u128),
|
Number(u64),
|
||||||
Decimal(f64),
|
Decimal(f64),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,11 +408,7 @@ impl Expression {
|
|||||||
ExprKind::BinOp(op, lhs, rhs) => {
|
ExprKind::BinOp(op, lhs, rhs) => {
|
||||||
// TODO make sure lhs and rhs can actually do this binary
|
// TODO make sure lhs and rhs can actually do this binary
|
||||||
// operation once relevant
|
// operation once relevant
|
||||||
let lhs_res = lhs.typecheck(
|
let lhs_res = lhs.typecheck(state, &typerefs, hint_t);
|
||||||
state,
|
|
||||||
&typerefs,
|
|
||||||
hint_t.and_then(|t| t.binop_hint(op)).as_ref(),
|
|
||||||
);
|
|
||||||
let lhs_type = state.or_else(lhs_res, TypeKind::Vague(Vague::Unknown), lhs.1);
|
let lhs_type = state.or_else(lhs_res, TypeKind::Vague(Vague::Unknown), lhs.1);
|
||||||
let rhs_res = rhs.typecheck(state, &typerefs, Some(&lhs_type));
|
let rhs_res = rhs.typecheck(state, &typerefs, Some(&lhs_type));
|
||||||
let rhs_type = state.or_else(rhs_res, TypeKind::Vague(Vague::Unknown), rhs.1);
|
let rhs_type = state.or_else(rhs_res, TypeKind::Vague(Vague::Unknown), rhs.1);
|
||||||
|
@ -5,5 +5,5 @@ pub fn OneHalf(var1: f32) -> f32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() -> bool {
|
pub fn main() -> bool {
|
||||||
return 7.5 > 5.001;
|
return 7.5 > 5.5;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user