Esempio n. 1
0
 public MidVarRef(
     SourceRange range,
     MidVar var)
     : base(range, var.Type)
 {
     _var = var;
 }
Esempio n. 2
0
 public MidLetExp(
     SourceRange range,
     MidVar var,
     MidExp exp,
     MidExp body)
     : base(range, new MidDummyType())
 {
     _var = var;
     _exp = exp;
     _body = body;
 }
Esempio n. 3
0
 public MidForExp(
     SourceRange range,
     MidVar var,
     MidVal seq,
     MidExp body)
     : base(range, new MidVoidType())
 {
     _var  = var;
     _seq  = seq;
     _body = body;
 }
Esempio n. 4
0
 public MidLetExp(
     SourceRange range,
     MidVar var,
     MidExp exp,
     MidExp body)
     : base(range, new MidDummyType())
 {
     _var  = var;
     _exp  = exp;
     _body = body;
 }
Esempio n. 5
0
        public override MidVal CreateTemp(MidExp exp, MidType type)
        {
            if (_element != null)
            {
                var attrDecl = _element.CacheAttr(exp, type);
                return(_exps.AttributeRef(exp.Range, attrDecl));
            }
            else
            {
                MidVar var = new MidVar(_identifiers.unique("temp"), type);

                Func <MidExp, MidExp> wrapper = (body) => new MidLetExp(exp.Range, var, exp, body);

                _wrappers.Insert(0, wrapper);

                return(new MidVarRef(exp.Range, var));
            }
        }
Esempio n. 6
0
        private bool UsesVar(
            MidExp exp,
            MidVar var)
        {
            bool result    = false;
            var  transform = new MidTransform(
                (e) =>
            {
                if (e is MidVarRef && (e as MidVarRef).Var == var)
                {
                    result = true;
                }
                return(e);
            });

            transform.Transform(exp);

            return(result);
        }
Esempio n. 7
0
 private MidExp TryFoldPath(
     MidVar var,
     MidExp exp,
     MidPath path)
 {
     if (exp is MidFieldRef)
     {
         var midFieldRef = (MidFieldRef)exp;
         if (midFieldRef.Obj is MidVarRef)
         {
             var midVarRef = (MidVarRef)midFieldRef.Obj;
             if (midVarRef.Var == var)
             {
                 midFieldRef.Obj = path;
                 return(midFieldRef);
             }
         }
     }
     return(exp);
 }
Esempio n. 8
0
        private MidExp EmitExpImpl(
            ResForExp resFor,
            MidEmitEnv env)
        {
            // \todo: Set up the variable... :(
            var resVar = resFor.Var;
            var midVar = new MidVar(
                resVar.Name,
                EmitTypeExp(resVar.Type, env));

            var seq = EmitVal(resFor.Sequence, env);

            var bodyEnv = new MidLocalEmitEnv(env, _identifiers, null, _exps);

            bodyEnv.Insert(resVar, (SourceRange r) => new MidVarRef(r, midVar));
            var body = bodyEnv.Wrap(EmitVal(resFor.Body, bodyEnv));

            return(new MidForExp(
                       resFor.Range,
                       midVar,
                       seq,
                       body));
        }
Esempio n. 9
0
 public void Insert(MidVar var, MidVal val)
 {
     _vars[var] = val;
 }
Esempio n. 10
0
 public MidVarRef(
     SourceRange range,
     MidVar var)
     : base(range, var.Type)
 {
     _var = var;
 }
Esempio n. 11
0
 public void Insert( MidVar var, MidVal val )
 {
     _vars[var] = val;
 }
Esempio n. 12
0
        private bool UsesVar(
            MidExp exp,
            MidVar var)
        {
            bool result = false;
            var transform = new MidTransform(
                (e) =>
                {
                    if (e is MidVarRef && (e as MidVarRef).Var == var)
                        result = true;
                    return e;
                });

            transform.Transform(exp);

            return result;
        }
Esempio n. 13
0
 private MidExp TryFoldPath(
     MidVar var,
     MidExp exp,
     MidPath path)
 {
     if (exp is MidFieldRef)
     {
         var midFieldRef = (MidFieldRef)exp;
         if (midFieldRef.Obj is MidVarRef)
         {
             var midVarRef = (MidVarRef) midFieldRef.Obj;
             if (midVarRef.Var == var)
             {
                 midFieldRef.Obj = path;
                 return midFieldRef;
             }
         }
     }
     return exp;
 }