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
|
/// get the type of an identifier
|
||||||
/// may return error if the identifier is not defined, and cannot be resolved with the
|
/// may return error if the identifier is not defined, and cannot be resolved with the
|
||||||
/// resolution function.
|
/// 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 let Some((t, x)) = self.sym_table.get(name) {
|
||||||
if *x {
|
if *x {
|
||||||
Ok(t.clone())
|
Ok(t.clone())
|
||||||
@ -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(),
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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();
|
||||||
|
@ -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(
|
||||||
args: vec![],
|
"__neg__",
|
||||||
result
|
FnDef {
|
||||||
});
|
args: vec![],
|
||||||
|
result,
|
||||||
|
},
|
||||||
|
);
|
||||||
def.methods.insert(
|
def.methods.insert(
|
||||||
"__truediv__",
|
"__truediv__",
|
||||||
FnDef {
|
FnDef {
|
||||||
|
Loading…
Reference in New Issue
Block a user