Пример #1
0
 public Interpreter()
 {
     mTypeCtxt = new TypeCtxtGlobal();
     mTypeEnv = new TypeEnvGlobal();
     mValueCtxt = new ValueCtxtGlobal();
     mValueEnv = new ValueEnvGlobal();
 }
Пример #2
0
 public IType Eval(ITypeEnv typeEnv)
 {
     Unique unique = new Unique();
     typeEnv = typeEnv.MakeChild();
     typeEnv.Add(mTypeVarName, new TVar(unique));
     IType type = mTypeExpr.Eval(typeEnv);
     return new TAbs(unique, type);
 }
Пример #3
0
 public IType Check(
     ITypeCtxt typeCtxt,
     ITypeEnv typeEnv,
     IValueCtxt valueCtxt
 )
 {
     return mValueConst.ToType();
 }
Пример #4
0
 public IType Eval(ITypeEnv typeEnv)
 {
     var methodTypes = new Dictionary<string, IType>();
     foreach (KeyValuePair<string, ITypeExpr> kvp in mMethodTypeExprs)
     {
         methodTypes.Add(kvp.Key, kvp.Value.Eval(typeEnv));
     }
     return new TObj(methodTypes);
 }
Пример #5
0
 public IType Check(
     ITypeCtxt typeCtxt,
     ITypeEnv typeEnv,
     IValueCtxt valueCtxt
 )
 {
     IType type1 = mValueExpr1.Check(typeCtxt, typeEnv, valueCtxt);
     IType type2 = mValueExpr2.Check(typeCtxt, typeEnv, valueCtxt);
     return CheckApp(type1, type2);
 }
Пример #6
0
 public IType Check(
     ITypeCtxt typeCtxt,
     ITypeEnv typeEnv,
     IValueCtxt valueCtxt
 )
 {
     IType type = mValueExpr.Check(typeCtxt, typeEnv, valueCtxt);
     valueCtxt.Add(mValueVarName, type);
     return type;
 }
Пример #7
0
 public IType Check(
     ITypeCtxt typeCtxt,
     ITypeEnv typeEnv,
     IValueCtxt valueCtxt
 )
 {
     mTypeExpr.Check(typeCtxt);
     mTypeExpr.Eval(typeEnv);
     return TCUnit.Instance;
 }
Пример #8
0
 public IType Eval(ITypeEnv typeEnv)
 {
     IType result;
     if (!typeEnv.TryGetValue(mTypeVarName, out result))
     {
         throw new InvalidOperationException(
             string.Format("unbound type variable: {0}", mTypeVarName)
         );
     }
     return result;
 }
Пример #9
0
 public IType Check(
     ITypeCtxt typeCtxt,
     ITypeEnv typeEnv,
     IValueCtxt valueCtxt
 )
 {
     IType type1 = mValueExpr.Check(typeCtxt, typeEnv, valueCtxt);
     IKind kind = mTypeExpr.Check(typeCtxt);
     IType type2 = mTypeExpr.Eval(typeEnv);
     return CheckApp(type1, kind, type2);
 }
Пример #10
0
 public IType Eval(ITypeEnv typeEnv)
 {
     IType type1 = mTypeExpr1.Eval(typeEnv);
     IType type2 = mTypeExpr2.Eval(typeEnv);
     if (type1 is ITypeFunc)
     {
         return ((ITypeFunc)type1).Apply(type2);
     }
     else
     {
         return new TApp(type1, type2);
     }
 }
Пример #11
0
 public IType Check(
     ITypeCtxt typeCtxt,
     ITypeEnv typeEnv,
     IValueCtxt valueCtxt
 )
 {
     Unique unique = new Unique();
     typeCtxt = typeCtxt.MakeChild();
     typeEnv = typeEnv.MakeChild();
     typeCtxt.Add(mTypeVarName, mKind);
     typeEnv.Add(mTypeVarName, new TVar(unique));
     IType type = mValueExpr.Check(typeCtxt, typeEnv, valueCtxt);
     return MakePolymorphicType(unique, mKind, type);
 }
Пример #12
0
 public IType Check(
     ITypeCtxt typeCtxt,
     ITypeEnv typeEnv,
     IValueCtxt valueCtxt
 )
 {
     var methodTypes = new Dictionary<string, IType>();
     foreach (KeyValuePair<string, IValueExpr> kvp in mMethodValueExprs)
     {
         methodTypes.Add(
             kvp.Key, kvp.Value.Check(typeCtxt, typeEnv, valueCtxt)
         );
     }
     return new TObj(methodTypes);
 }
Пример #13
0
 public IType Check(
     ITypeCtxt typeCtxt,
     ITypeEnv typeEnv,
     IValueCtxt valueCtxt
 )
 {
     IType result;
     if (!valueCtxt.TryGetValue(mValueVarName, out result))
     {
         throw new InvalidOperationException(
             string.Format("unknown variable: {0}", mValueVarName)
         );
     }
     return result;
 }
Пример #14
0
 public IType Check(
     ITypeCtxt typeCtxt,
     ITypeEnv typeEnv,
     IValueCtxt valueCtxt
 )
 {
     IType type = mValueExpr.Check(typeCtxt, typeEnv, valueCtxt);
     if (!(type is TObj))
     {
         throw new InvalidOperationException(
             string.Format(
                 "{0} doesn't have an object type", mValueExpr.Show()
             )
         );
     }
     return ((TObj)type).GetMethodType(mMethodName);
 }
Пример #15
0
 public IType Check(
     ITypeCtxt typeCtxt,
     ITypeEnv typeEnv,
     IValueCtxt valueCtxt
 )
 {
     IKind kind = mTypeExpr.Check(typeCtxt);
     if (!(kind is IKindConst))
     {
         throw new InvalidOperationException(
             string.Format(
                 "{0} doesn't have a base kind", mTypeExpr.Show()
             )
         );
     }
     IType type1 = mTypeExpr.Eval(typeEnv);
     valueCtxt = valueCtxt.MakeChild();
     valueCtxt.Add(mValueVarName, type1);
     IType type2 = mValueExpr.Check(typeCtxt, typeEnv, valueCtxt);
     return MakeFunctionType(type1, type2);
 }
Пример #16
0
 public IType Check(
     ITypeCtxt typeCtxt,
     ITypeEnv typeEnv,
     IValueCtxt valueCtxt
 )
 {
     mTypeExpr.Check(typeCtxt);
     IType rolledType = mTypeExpr.Eval(typeEnv);
     IType unrolledType = VEFold.Unroll(rolledType);
     IType valueExprType = mValueExpr.Check(
         typeCtxt, typeEnv, valueCtxt
     );
     if (!valueExprType.Equals(rolledType))
     {
         throw new InvalidOperationException(
             string.Format(
                 "{0} cannot be unfolded with the type {1}",
                 mValueExpr.Show(),
                 mTypeExpr.Show()
             )
         );
     }
     return unrolledType;
 }
Пример #17
0
 public IType Eval(ITypeEnv typeEnv)
 {
     return new TCPoly(mKind);
 }
Пример #18
0
 public IType Eval(ITypeEnv typeEnv)
 {
     IType type = mTypeExpr.Eval(typeEnv);
     typeEnv.Add(mTypeVarName, type);
     return type;
 }
Пример #19
0
 public TypeEnvLocal(ITypeEnv parent)
 {
     mDictionary = new Dictionary<string, IType>();
     mParent = parent;
 }