formatting

This commit is contained in:
pca006132 2021-01-04 14:47:43 +08:00
parent 44f4b7cfc7
commit f691fbb4dc
4 changed files with 19 additions and 30 deletions

View File

@ -194,10 +194,7 @@ impl TypeEnum {
match self { match self {
TypeEnum::ParametricType(id, params) => TypeEnum::ParametricType( TypeEnum::ParametricType(id, params) => TypeEnum::ParametricType(
*id, *id,
params params.iter().map(|v| v.as_ref().inv_subst(map)).collect(),
.iter()
.map(|v| v.as_ref().inv_subst(map))
.collect(),
), ),
_ => self.clone(), _ => self.clone(),
} }

View File

@ -1,5 +1,4 @@
mod top_level_context;
mod inference_context; mod inference_context;
pub use top_level_context::TopLevelContext; mod top_level_context;
pub use inference_context::InferenceContext; pub use inference_context::InferenceContext;
pub use top_level_context::TopLevelContext;

View File

@ -532,15 +532,9 @@ mod test {
parents: vec![], parents: vec![],
}); });
let foo_def = ctx.get_class_def_mut(foo); let foo_def = ctx.get_class_def_mut(foo);
foo_def foo_def.base.fields.insert("a", int32.clone());
.base
.fields
.insert("a", int32.clone());
foo_def.base.fields.insert("b", ClassType(foo).into()); foo_def.base.fields.insert("b", ClassType(foo).into());
foo_def foo_def.base.fields.insert("c", int32.clone());
.base
.fields
.insert("c", int32.clone());
let bar = ctx.add_class(ClassDef { let bar = ctx.add_class(ClassDef {
base: TypeDef { base: TypeDef {
@ -551,15 +545,9 @@ mod test {
parents: vec![], parents: vec![],
}); });
let bar_def = ctx.get_class_def_mut(bar); let bar_def = ctx.get_class_def_mut(bar);
bar_def bar_def.base.fields.insert("a", int32);
.base
.fields
.insert("a", int32);
bar_def.base.fields.insert("b", ClassType(bar).into()); bar_def.base.fields.insert("b", ClassType(bar).into());
bar_def bar_def.base.fields.insert("c", float);
.base
.fields
.insert("c", float);
let v0 = ctx.add_variable(VarDef { let v0 = ctx.add_variable(VarDef {
name: "v0", name: "v0",
@ -574,7 +562,8 @@ mod test {
let mut ctx = get_inference_context(ctx); let mut ctx = get_inference_context(ctx);
ctx.assign("foo", Rc::new(ClassType(foo))).unwrap(); ctx.assign("foo", Rc::new(ClassType(foo))).unwrap();
ctx.assign("bar", Rc::new(ClassType(bar))).unwrap(); ctx.assign("bar", Rc::new(ClassType(bar))).unwrap();
ctx.assign("foobar", Rc::new(VirtualClassType(foo))).unwrap(); ctx.assign("foobar", Rc::new(VirtualClassType(foo)))
.unwrap();
ctx.assign("v0", ctx.get_variable(v0)).unwrap(); ctx.assign("v0", ctx.get_variable(v0)).unwrap();
ctx.assign("v1", ctx.get_variable(v1)).unwrap(); ctx.assign("v1", ctx.get_variable(v1)).unwrap();
ctx.assign("bot", Rc::new(BotType)).unwrap(); ctx.assign("bot", Rc::new(BotType)).unwrap();
@ -790,7 +779,8 @@ mod test {
let mut ctx = get_inference_context(ctx); let mut ctx = get_inference_context(ctx);
ctx.assign("foo", Rc::new(ClassType(foo))).unwrap(); ctx.assign("foo", Rc::new(ClassType(foo))).unwrap();
ctx.assign("bar", Rc::new(ClassType(bar))).unwrap(); ctx.assign("bar", Rc::new(ClassType(bar))).unwrap();
ctx.assign("foobar", Rc::new(VirtualClassType(foo))).unwrap(); ctx.assign("foobar", Rc::new(VirtualClassType(foo)))
.unwrap();
ctx.assign("v0", ctx.get_variable(v0)).unwrap(); ctx.assign("v0", ctx.get_variable(v0)).unwrap();
ctx.assign("v1", ctx.get_variable(v1)).unwrap(); ctx.assign("v1", ctx.get_variable(v1)).unwrap();
ctx.assign("v2", ctx.get_variable(v2)).unwrap(); ctx.assign("v2", ctx.get_variable(v2)).unwrap();

View File

@ -19,10 +19,13 @@ fn impl_math(def: &mut TypeDef, ty: &Type) {
def.methods.insert("__add__", fun.clone()); def.methods.insert("__add__", fun.clone());
def.methods.insert("__sub__", fun.clone()); def.methods.insert("__sub__", fun.clone());
def.methods.insert("__mul__", fun.clone()); def.methods.insert("__mul__", fun.clone());
def.methods.insert("__neg__", FnDef { def.methods.insert(
"__neg__",
FnDef {
args: vec![], args: vec![],
result result,
}); },
);
def.methods.insert( def.methods.insert(
"__truediv__", "__truediv__",
FnDef { FnDef {