Browse Source

feat: infer struct type

structs
Garrit Franke 3 years ago
parent
commit
efe8e18160
  1. 1
      src/generator/c.rs
  2. 1
      src/generator/llvm.rs
  3. 1
      src/parser/infer.rs
  4. 1
      src/parser/node_type.rs

1
src/generator/c.rs

@ -51,6 +51,7 @@ pub(super) fn generate_type(t: Either<Variable, Option<Type>>) -> String {
Type::Str => "char *".into(),
Type::Any => "void *".into(),
Type::Bool => "bool".into(),
Type::Struct(_) => todo!(),
Type::Array(_) => match name {
Some(n) => format!(
"{T} {N}[]",

1
src/generator/llvm.rs

@ -31,6 +31,7 @@ impl<'ctx> LLVMGenerator<'ctx> {
Some(Type::Any) => todo!(),
Some(Type::Str) => todo!(),
Some(Type::Array(_)) => todo!(),
Some(Type::Struct(_)) => todo!(),
None => panic!("Function argument has no type"),
})
.collect();

1
src/parser/infer.rs

@ -32,6 +32,7 @@ fn infer_expression(expr: &Expression, table: &SymbolTable) -> Option<Type> {
Expression::Int(_) => Some(Type::Int),
Expression::Bool(_) => Some(Type::Bool),
Expression::Str(_) => Some(Type::Str),
Expression::StructInitialization(name, _) => Some(Type::Struct(name.to_string())),
Expression::FunctionCall(name, _) => infer_function_call(name, table),
Expression::Array(els) => infer_array(els, table),
_ => None,

1
src/parser/node_type.rs

@ -71,6 +71,7 @@ pub enum Type {
Str,
Bool,
Array(Box<Type>),
Struct(String),
}
impl TryFrom<String> for Type {

Loading…
Cancel
Save