forked from M-Labs/nac3
formatting
This commit is contained in:
parent
44f4b7cfc7
commit
f691fbb4dc
@ -121,7 +121,7 @@ impl<'a> InferenceContext<'a> {
|
||||
/// get the type of an identifier
|
||||
/// may return error if the identifier is not defined, and cannot be resolved with the
|
||||
/// resolution function.
|
||||
pub fn resolve(&mut self, name: & str) -> Result<Type, String> {
|
||||
pub fn resolve(&mut self, name: &str) -> Result<Type, String> {
|
||||
if let Some((t, x)) = self.sym_table.get(name) {
|
||||
if *x {
|
||||
Ok(t.clone())
|
||||
@ -194,10 +194,7 @@ impl TypeEnum {
|
||||
match self {
|
||||
TypeEnum::ParametricType(id, params) => TypeEnum::ParametricType(
|
||||
*id,
|
||||
params
|
||||
.iter()
|
||||
.map(|v| v.as_ref().inv_subst(map))
|
||||
.collect(),
|
||||
params.iter().map(|v| v.as_ref().inv_subst(map)).collect(),
|
||||
),
|
||||
_ => self.clone(),
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
mod top_level_context;
|
||||
mod inference_context;
|
||||
pub use top_level_context::TopLevelContext;
|
||||
mod top_level_context;
|
||||
pub use inference_context::InferenceContext;
|
||||
|
||||
pub use top_level_context::TopLevelContext;
|
||||
|
@ -532,15 +532,9 @@ mod test {
|
||||
parents: vec![],
|
||||
});
|
||||
let foo_def = ctx.get_class_def_mut(foo);
|
||||
foo_def
|
||||
.base
|
||||
.fields
|
||||
.insert("a", int32.clone());
|
||||
foo_def.base.fields.insert("a", int32.clone());
|
||||
foo_def.base.fields.insert("b", ClassType(foo).into());
|
||||
foo_def
|
||||
.base
|
||||
.fields
|
||||
.insert("c", int32.clone());
|
||||
foo_def.base.fields.insert("c", int32.clone());
|
||||
|
||||
let bar = ctx.add_class(ClassDef {
|
||||
base: TypeDef {
|
||||
@ -551,15 +545,9 @@ mod test {
|
||||
parents: vec![],
|
||||
});
|
||||
let bar_def = ctx.get_class_def_mut(bar);
|
||||
bar_def
|
||||
.base
|
||||
.fields
|
||||
.insert("a", int32);
|
||||
bar_def.base.fields.insert("a", int32);
|
||||
bar_def.base.fields.insert("b", ClassType(bar).into());
|
||||
bar_def
|
||||
.base
|
||||
.fields
|
||||
.insert("c", float);
|
||||
bar_def.base.fields.insert("c", float);
|
||||
|
||||
let v0 = ctx.add_variable(VarDef {
|
||||
name: "v0",
|
||||
@ -574,7 +562,8 @@ mod test {
|
||||
let mut ctx = get_inference_context(ctx);
|
||||
ctx.assign("foo", Rc::new(ClassType(foo))).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("v1", ctx.get_variable(v1)).unwrap();
|
||||
ctx.assign("bot", Rc::new(BotType)).unwrap();
|
||||
@ -790,7 +779,8 @@ mod test {
|
||||
let mut ctx = get_inference_context(ctx);
|
||||
ctx.assign("foo", Rc::new(ClassType(foo))).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("v1", ctx.get_variable(v1)).unwrap();
|
||||
ctx.assign("v2", ctx.get_variable(v2)).unwrap();
|
||||
|
@ -19,10 +19,13 @@ fn impl_math(def: &mut TypeDef, ty: &Type) {
|
||||
def.methods.insert("__add__", fun.clone());
|
||||
def.methods.insert("__sub__", fun.clone());
|
||||
def.methods.insert("__mul__", fun.clone());
|
||||
def.methods.insert("__neg__", FnDef {
|
||||
args: vec![],
|
||||
result
|
||||
});
|
||||
def.methods.insert(
|
||||
"__neg__",
|
||||
FnDef {
|
||||
args: vec![],
|
||||
result,
|
||||
},
|
||||
);
|
||||
def.methods.insert(
|
||||
"__truediv__",
|
||||
FnDef {
|
||||
|
Loading…
Reference in New Issue
Block a user