feat(gs/achilles): Implement extern decls, for glibc functions

Implement extern decls, which codegen to LLVM as forward-declared
functions, and use these as a hook into calling glibc functions.

We can print to the terminal now! The integration tests can test this
now.

Change-Id: I70af4546b417b888ad9fbb18798db240f77f4e71
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2614
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
This commit is contained in:
Griffin Smith 2021-03-19 20:46:19 -04:00 committed by glittershark
parent fec6595d21
commit 2c838ab845
9 changed files with 147 additions and 28 deletions

View file

@ -219,12 +219,19 @@ pub enum Decl<'a, T> {
body: Box<Expr<'a, T>>,
type_: T,
},
Extern {
name: Ident<'a>,
arg_types: Vec<T>,
ret_type: T,
},
}
impl<'a, T> Decl<'a, T> {
pub fn type_(&self) -> &T {
pub fn type_(&self) -> Option<&T> {
match self {
Decl::Fun { type_, .. } => type_,
Decl::Fun { type_, .. } => Some(type_),
Decl::Extern { .. } => None,
}
}
@ -247,6 +254,15 @@ impl<'a, T> Decl<'a, T> {
body: Box::new(body.traverse_type(f.clone())?),
type_: f(type_)?,
}),
Decl::Extern {
name,
arg_types,
ret_type,
} => Ok(Decl::Extern {
name,
arg_types: arg_types.into_iter().map(f.clone()).try_collect()?,
ret_type: f(ret_type)?,
}),
}
}
}

View file

@ -265,8 +265,18 @@ impl<'a> Fun<'a> {
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum Decl<'a> {
Fun { name: Ident<'a>, body: Fun<'a> },
Ascription { name: Ident<'a>, type_: Type<'a> },
Fun {
name: Ident<'a>,
body: Fun<'a>,
},
Ascription {
name: Ident<'a>,
type_: Type<'a>,
},
Extern {
name: Ident<'a>,
type_: FunctionType<'a>,
},
}
////