示例#1
0
        // if isAnonymous is true, parameters is actually envVars
        public FunInfo(bool isAnonymous, FuncTerm parameters, AST <FuncTerm> returnType, FuncTerm locals, Node body)
        {
            this.isAnonymous = isAnonymous;
            this.returnType  = returnType;
            this.body        = body;

            this.parameterNames      = new List <string>();
            this.isRefParameter      = new List <bool>();
            this.localNameToInfo     = new Dictionary <string, LocalVariableInfo>();
            this.localNames          = new List <string>();
            this.numFairChoices      = 0;
            this.typeInfo            = new Dictionary <AST <Node>, FuncTerm>();
            this.maxNumLocals        = 0;
            this.invokeSchedulerFuns = new HashSet <Node>();
            this.invokePluginFuns    = new HashSet <Node>();
            this.printArgs           = new HashSet <string>();

            int paramIndex = 0;

            while (parameters != null)
            {
                var ft = (FuncTerm)PTranslation.GetArgByIndex(parameters, 0);
                using (var enumerator = ft.Args.GetEnumerator())
                {
                    enumerator.MoveNext();
                    var isRef = ((Id)enumerator.Current).Name == "REF";
                    enumerator.MoveNext();
                    var varName = ((Cnst)enumerator.Current).GetStringValue();
                    enumerator.MoveNext();
                    var varType = (FuncTerm)enumerator.Current;
                    localNameToInfo[varName] = new LocalVariableInfo(varType, paramIndex);
                    parameterNames.Add(varName);
                    isRefParameter.Add(isRef);
                }
                parameters = PTranslation.GetArgByIndex(parameters, 1) as FuncTerm;
                paramIndex++;
            }

            int localIndex = paramIndex;

            while (locals != null)
            {
                var ft = (FuncTerm)PToZing.GetArgByIndex(locals, 0);
                using (var enumerator = ft.Args.GetEnumerator())
                {
                    // skip over the qualifier
                    enumerator.MoveNext();
                    enumerator.MoveNext();
                    var varName = ((Cnst)enumerator.Current).GetStringValue();
                    enumerator.MoveNext();
                    var varType = (FuncTerm)enumerator.Current;
                    localNameToInfo[varName] = new LocalVariableInfo(varType, localIndex);
                    localNames.Add(varName);
                }
                locals = PToZing.GetArgByIndex(locals, 1) as FuncTerm;
                localIndex++;
            }
        }
示例#2
0
 public TypeTranslationContext(PToZing pToZing)
 {
     this.pToZing            = pToZing;
     fieldCount              = 0;
     typeCount               = 0;
     fieldNameInitialization = new List <AST <Node> >();
     typeInitialization      = new List <AST <Node> >();
     fieldNameToZingExpr     = new Dictionary <string, AST <FuncTerm> >();
     pTypeToZingExpr         = new Dictionary <AST <Node>, AST <Node> >();
 }
 public ZingFoldContext(PToZing comp, string machineName, string entityName, FunInfo entityInfo)
 {
     this.pToZing          = comp;
     this.machineName      = machineName;
     this.entityName       = entityName;
     this.entityInfo       = entityInfo;
     this.sideEffectsStack = new Stack <List <AST <Node> > >();
     PushSideEffectStack();
     this.locals   = new List <Tuple <AST <Node>, string> >();
     this.labels   = new Dictionary <string, int>();
     this.lhsStack = new Stack <bool>();
 }
            public AST <Node> EmitZingSideEffects(AST <Node> stmt)
            {
                Debug.Assert(sideEffectsStack.Count > 0);
                var sideEffects = sideEffectsStack.Pop();

                if (sideEffects.Count > 0)
                {
                    sideEffects.Add(stmt);
                    return(PToZing.MkZingSeq(sideEffects));
                }
                else
                {
                    return(stmt);
                }
            }
            public AST <Node> EmitLabelPrelude()
            {
                var prelude = new List <AST <Node> >();
                var tmpVar  = GetTmpVar(Factory.Instance.MkCnst("StackFrame"), "retTo");

                prelude.Add(PToZing.MkZingAssign(tmpVar, PToZing.MkZingCall(MkZingDot("entryCtxt", "PopReturnTo"))));
                prelude.Add(PToZing.MkZingAssign(MkZingIdentifier("locals"), MkZingDot(tmpVar, "locals")));
                prelude.Add(PToZing.MkZingIfThen(PToZing.MkZingEq(MkZingDot(tmpVar, "pc"), Factory.Instance.MkCnst(0)), MkZingGoto("start")));

                foreach (var l in labels.Keys)
                {
                    prelude.Add(PToZing.MkZingIfThen(PToZing.MkZingEq(MkZingDot(tmpVar, "pc"), Factory.Instance.MkCnst(labels[l])), MkZingGoto(l)));
                }

                prelude.Add(MkZingAssert(ZingData.Cnst_False, "Internal error"));

                return(PToZing.MkZingSeq(prelude));
            }
 public IEnumerable <AST <Node> > EmitLocals()
 {
     return(locals.Select(loc => PToZing.MkZingVarDecl(loc.Item2, loc.Item1)));
 }