Skip to content

Commit

Permalink
basics of extern
Browse files Browse the repository at this point in the history
  • Loading branch information
JCBurnside committed Mar 2, 2024
1 parent 24a77dc commit 2ee532a
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 10 deletions.
2 changes: 1 addition & 1 deletion compiler/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub struct ArgDeclaration {
pub ty: Option<ResolvedType>,
}

#[derive(PartialEq,Debug)]
#[derive(PartialEq,Debug, Clone)]
pub struct Abi {
pub loc : crate::Location,
pub identifier : String,
Expand Down
28 changes: 23 additions & 5 deletions compiler/src/inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl Context {
.map(|stmnt| self.assign_ids_stmnt(stmnt))
.collect(),
),
untyped_ast::ValueType::External => todo!(),
untyped_ast::ValueType::External => ast::ValueType::External,
};
ast::ValueDeclaration {
loc,
Expand All @@ -156,6 +156,7 @@ impl Context {
ty: decl_ty,
value,
generics: generictypes,
abi,
id,
}
}
Expand Down Expand Up @@ -482,7 +483,8 @@ impl Context {
.reduce(|ty, arg| ty.fn_ty(&arg));
value.ty = fun.unwrap().fn_ty(&ty.unwrap()); //not sure if this the correct way to handle this.
}
}
},
ast::ValueType::External => (),
}

}
Expand Down Expand Up @@ -889,6 +891,7 @@ impl Context {
ty: v_ty,
value,
generics,
abi:_,
id: _,
} = decl;
v_ty.replace_unkown_with(id, ty.clone());
Expand All @@ -908,6 +911,7 @@ impl Context {
}
}
}
ast::ValueType::External=>(),
}
}

Expand Down Expand Up @@ -938,6 +942,7 @@ impl Context {
self.apply_substution_statement(sub, stmnt);
}
},
ast::ValueType::External=>()
}
}

Expand Down Expand Up @@ -1392,6 +1397,7 @@ mod tests {
2
)),
generics: None,
abi:None,
id: 0
}
)]
Expand Down Expand Up @@ -1446,6 +1452,7 @@ mod tests {
}
)),
generics: None,
abi:None,
id: 0
}
)]
Expand Down Expand Up @@ -1538,6 +1545,7 @@ let foo a = match a where
}
)),
generics: None,
abi: None,
id: 0,
}
)]
Expand Down Expand Up @@ -1579,6 +1587,7 @@ let foo a = match a where
}
)),
generics: None,
abi: None,
id: 0
}
)]
Expand Down Expand Up @@ -1653,6 +1662,7 @@ for<T> let foo x y : T -> T -> () = ()
((1,4),"T".to_string())
]
}),
abi: None,
id: 0
}
)]
Expand Down Expand Up @@ -1756,6 +1766,7 @@ let complex x =
id: 2
}),
generics: None,
abi: None,
id: 0
}),
super::ast::Declaration::Value(super::ast::ValueDeclaration {
Expand Down Expand Up @@ -1875,6 +1886,7 @@ let complex x =
)
]),
generics: None,
abi: None,
id: 7
}),
// super::ast::ValueDeclaration {
Expand Down Expand Up @@ -1954,6 +1966,7 @@ let unit_unit _ : () -> () = ()
},
value: super::ast::ValueType::Expr(super::ast::Expr::ValueRead("x".to_string(), (5,33), 7)),
generics: None,
abi: None,
id: 5
}),
int_int,
Expand All @@ -1979,6 +1992,7 @@ let unit_unit _ : () -> () = ()
},
value: super::ast::ValueType::Expr(super::ast::Expr::UnitLiteral),
generics: None,
abi: None,
id: 0
}),
int_unit,
Expand All @@ -2004,6 +2018,7 @@ let unit_unit _ : () -> () = ()
},
value: super::ast::ValueType::Expr(super::ast::Expr::NumericLiteral { value: "0".to_string(), id: 4, ty: types::INT16 }),
generics: None,
abi: None,
id: 2
}),
unit_int,
Expand All @@ -2029,6 +2044,7 @@ let unit_unit _ : () -> () = ()
},
value: super::ast::ValueType::Expr(super::ast::Expr::UnitLiteral),
generics: None,
abi: None,
id: 8
}),
unit_unit,
Expand Down Expand Up @@ -2081,7 +2097,6 @@ let if_expr a b : bool -> int32 -> int32 = if a then b else 0
}.boxed(),
loc:(1, 23)
},
id:0,
value: super::ast::ValueType::Expr(super::ast::Expr::If(super::ast::IfExpr {
cond: super::ast::Expr::ValueRead("a".to_string(), (1,46), 4).boxed(),
true_branch: (
Expand All @@ -2097,7 +2112,9 @@ let if_expr a b : bool -> int32 -> int32 = if a then b else 0
id: 3,
result: types::INT32
})),
generics:None
generics:None,
abi: None,
id:0,
}),
if_expr,
)
Expand Down Expand Up @@ -2141,7 +2158,6 @@ let returns a : bool -> int32 =
returns: types::INT32.boxed(),
loc: (1,21)
},
generics:None,
value:super::ast::ValueType::Function(vec![
super::ast::Statement::IfStatement(super::ast::IfBranching{
cond: super::ast::Expr::ValueRead("a".to_string(), (2,7), 2).boxed(),
Expand All @@ -2160,6 +2176,8 @@ let returns a : bool -> int32 =
(4,4)
)
]),
generics:None,
abi: None,
id:0
}),
returns,
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/inference/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub(crate) struct ValueDeclaration {
pub(crate) ty: ResolvedType,
pub(crate) value: ValueType,
pub(crate) generics: Option<GenericsDecl>,
pub(crate) abi : Option<crate::ast::Abi>,
pub(crate) id: usize,
}

Expand All @@ -61,6 +62,7 @@ pub struct ArgDeclaration {
pub(crate) enum ValueType {
Expr(Expr),
Function(Vec<Statement>),
External,
}

#[derive(PartialEq, Debug)]
Expand Down
Loading

0 comments on commit 2ee532a

Please sign in to comment.