forked from M-Labs/nac3
formatting
This commit is contained in:
parent
8c7ccb626b
commit
1db8378f60
|
@ -62,12 +62,14 @@ fn get_llvm_type<'ctx>(
|
|||
use TypeEnum::*;
|
||||
// we assume the type cache should already contain primitive types,
|
||||
// and they should be passed by value instead of passing as pointer.
|
||||
type_cache.get(&unifier.get_representative(ty)).cloned().unwrap_or_else(|| match &*unifier.get_ty(ty) {
|
||||
type_cache.get(&unifier.get_representative(ty)).cloned().unwrap_or_else(|| {
|
||||
match &*unifier.get_ty(ty) {
|
||||
TObj { obj_id, fields, .. } => {
|
||||
// a struct with fields in the order of declaration
|
||||
let defs = top_level.definitions.read();
|
||||
let definition = defs.get(obj_id.0).unwrap();
|
||||
let ty = if let TopLevelDef::Class { fields: fields_list, .. } = &*definition.read() {
|
||||
let ty = if let TopLevelDef::Class { fields: fields_list, .. } = &*definition.read()
|
||||
{
|
||||
let fields = fields.borrow();
|
||||
let fields = fields_list
|
||||
.iter()
|
||||
|
@ -96,10 +98,17 @@ fn get_llvm_type<'ctx>(
|
|||
}
|
||||
TVirtual { .. } => unimplemented!(),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn gen_func<'ctx>(context: &'ctx Context, builder: Builder<'ctx>, module: Module<'ctx>, task: CodeGenTask, top_level_ctx: Arc<TopLevelContext>) -> Module<'ctx> {
|
||||
pub fn gen_func<'ctx>(
|
||||
context: &'ctx Context,
|
||||
builder: Builder<'ctx>,
|
||||
module: Module<'ctx>,
|
||||
task: CodeGenTask,
|
||||
top_level_ctx: Arc<TopLevelContext>,
|
||||
) -> Module<'ctx> {
|
||||
// unwrap_or(0) is for unit tests without using rayon
|
||||
let (mut unifier, primitives) = {
|
||||
let unifiers = top_level_ctx.unifiers.read();
|
||||
|
|
|
@ -95,15 +95,20 @@ pub fn parse_type_annotation<T>(
|
|||
Subscript { value, slice, .. } => {
|
||||
if let Name { id, .. } = &value.node {
|
||||
if id == "virtual" {
|
||||
let ty = parse_type_annotation(resolver, top_level, unifier, primitives, slice)?;
|
||||
let ty =
|
||||
parse_type_annotation(resolver, top_level, unifier, primitives, slice)?;
|
||||
Ok(unifier.add_ty(TypeEnum::TVirtual { ty }))
|
||||
} else {
|
||||
let types = if let Tuple { elts, .. } = &slice.node {
|
||||
elts.iter()
|
||||
.map(|v| parse_type_annotation(resolver, top_level, unifier, primitives, v))
|
||||
.map(|v| {
|
||||
parse_type_annotation(resolver, top_level, unifier, primitives, v)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?
|
||||
} else {
|
||||
vec![parse_type_annotation(resolver, top_level, unifier, primitives, slice)?]
|
||||
vec![parse_type_annotation(
|
||||
resolver, top_level, unifier, primitives, slice,
|
||||
)?]
|
||||
};
|
||||
|
||||
let obj_id = resolver
|
||||
|
|
|
@ -696,7 +696,11 @@ impl Unifier {
|
|||
let fields = self
|
||||
.subst_map(&fields.borrow(), mapping)
|
||||
.unwrap_or_else(|| fields.borrow().clone());
|
||||
Some(self.add_ty(TypeEnum::TObj { obj_id, params: params.into(), fields: fields.into() }))
|
||||
Some(self.add_ty(TypeEnum::TObj {
|
||||
obj_id,
|
||||
params: params.into(),
|
||||
fields: fields.into(),
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue