Exemplo n.º 1
0
 public MidVarRef(
     SourceRange range,
     MidVar var)
     : base(range, var.Type)
 {
     _var = var;
 }
Exemplo n.º 2
0
 public MidLetExp(
     SourceRange range,
     MidVar var,
     MidExp exp,
     MidExp body)
     : base(range, new MidDummyType())
 {
     _var = var;
     _exp = exp;
     _body = body;
 }
Exemplo n.º 3
0
 public MidForExp(
     SourceRange range,
     MidVar var,
     MidVal seq,
     MidExp body)
     : base(range, new MidVoidType())
 {
     _var  = var;
     _seq  = seq;
     _body = body;
 }
Exemplo n.º 4
0
 public MidLetExp(
     SourceRange range,
     MidVar var,
     MidExp exp,
     MidExp body)
     : base(range, new MidDummyType())
 {
     _var  = var;
     _exp  = exp;
     _body = body;
 }
Exemplo 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));
            }
        }
Exemplo 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);
        }
Exemplo 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);
 }
Exemplo 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));
        }
Exemplo n.º 9
0
 public void Insert(MidVar var, MidVal val)
 {
     _vars[var] = val;
 }
Exemplo n.º 10
0
 public MidVarRef(
     SourceRange range,
     MidVar var)
     : base(range, var.Type)
 {
     _var = var;
 }
Exemplo n.º 11
0
 public void Insert( MidVar var, MidVal val )
 {
     _vars[var] = val;
 }
Exemplo 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;
        }
Exemplo 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;
 }