Ejemplo n.º 1
0
 public Interpreter()
 {
     mTypeCtxt = new TypeCtxtGlobal();
     mTypeEnv = new TypeEnvGlobal();
     mValueCtxt = new ValueCtxtGlobal();
     mValueEnv = new ValueEnvGlobal();
 }
Ejemplo n.º 2
0
 public IKind Check(ITypeCtxt typeCtxt)
 {
     typeCtxt = typeCtxt.MakeChild();
     typeCtxt.Add(mTypeVarName, mKind);
     IKind kind = mTypeExpr.Check(typeCtxt);
     return new KArrow(mKind, kind);
 }
Ejemplo n.º 3
0
 public IKind Check(ITypeCtxt typeCtxt)
 {
     return new KArrow(
         new KArrow(mKind, KCType.Instance),
         KCType.Instance
     );
 }
Ejemplo n.º 4
0
 public IType Check(
     ITypeCtxt typeCtxt,
     ITypeEnv typeEnv,
     IValueCtxt valueCtxt
 )
 {
     return mValueConst.ToType();
 }
Ejemplo n.º 5
0
 public IKind Check(ITypeCtxt typeCtxt)
 {
     foreach (ITypeExpr typeExpr in mMethodTypeExprs.Values)
     {
         typeExpr.Check(typeCtxt);
     }
     return KCType.Instance;
 }
Ejemplo n.º 6
0
 public IType Check(
     ITypeCtxt typeCtxt,
     ITypeEnv typeEnv,
     IValueCtxt valueCtxt
 )
 {
     mTypeExpr.Check(typeCtxt);
     mTypeExpr.Eval(typeEnv);
     return TCUnit.Instance;
 }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
0
 public IType Check(
     ITypeCtxt typeCtxt,
     ITypeEnv typeEnv,
     IValueCtxt valueCtxt
 )
 {
     IType type = mValueExpr.Check(typeCtxt, typeEnv, valueCtxt);
     valueCtxt.Add(mValueVarName, type);
     return type;
 }
Ejemplo n.º 9
0
 public IKind Check(ITypeCtxt typeCtxt)
 {
     IKind result;
     if (!typeCtxt.TryGetValue(mTypeVarName, out result))
     {
         throw new InvalidOperationException(
             string.Format("unknown type variable: {0}", mTypeVarName)
         );
     }
     return result;
 }
Ejemplo n.º 10
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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 17
0
 public IKind Check(ITypeCtxt typeCtxt)
 {
     IKind kind1 = mTypeExpr1.Check(typeCtxt);
     IKind kind2 = mTypeExpr2.Check(typeCtxt);
     return CheckApp(kind1, kind2);
 }
Ejemplo n.º 18
0
 public IKind Check(ITypeCtxt typeCtxt)
 {
     IKind kind = mTypeExpr.Check(typeCtxt);
     typeCtxt.Add(mTypeVarName, kind);
     return kind;
 }
Ejemplo n.º 19
0
 public TypeCtxtLocal(ITypeCtxt parent)
 {
     mDictionary = new Dictionary<string, IKind>();
     mParent = parent;
 }