示例#1
0
        protected override void GenerateConvertStackFrame_HL()
        {
            var cases       = new List <MatchCaseExpr>();
            var methodNames = pgp.symbolsHigh.MethodNames;

            foreach (var methodName in methodNames)
            {
                var smst = pgp.symbolsHigh.GetMethodSymbolTable(methodName);
                var ps   = new List <Expression>();
                var bvs  = new List <BoundVar>();
                foreach (var v in smst.AllVariablesInOrder)
                {
                    var ty = (v is AddressableArmadaVariable) ? AH.ReferToType("Armada_Pointer") : v.ty;
                    var e  = AH.MakeNameSegment(v.FieldName, ty);
                    if (methodName != strategy.MethodName || v.name != strategy.VariableName)
                    {
                        ps.Add(e);
                    }
                    var bv = AH.MakeBoundVar(v.FieldName, v.GetFlattenedType(pgp.symbolsHigh));
                    bvs.Add(bv);
                }
                var case_body = AH.MakeApplyN($"L.Armada_StackFrame_{methodName}", ps, "L.Armada_StackFrame");
                cases.Add(AH.MakeMatchCaseExpr($"Armada_StackFrame_{methodName}", bvs, case_body));
            }

            var source  = AH.MakeNameSegment("frame", "H.Armada_StackFrame");
            var body    = AH.MakeMatchExpr(source, cases, "L.Armada_StackFrame");
            var formals = new List <Formal> {
                AH.MakeFormal("frame", "H.Armada_StackFrame")
            };
            var fn = AH.MakeFunction("ConvertStackFrame_HL", formals, body);

            pgp.AddDefaultClassDecl(fn, "convert");
        }
示例#2
0
        protected override void GenerateConvertStackFrame_LH()
        {
            var cases       = new List <MatchCaseExpr>();
            var methodNames = pgp.symbolsLow.MethodNames;

            foreach (var methodName in methodNames)
            {
                var smst        = pgp.symbolsLow.GetMethodSymbolTable(methodName);
                var ps          = new List <Expression>();
                var bvs         = new List <BoundVar>();
                var lowVarNames = new List <string>(smst.AllVariableNamesInOrder);
                foreach (var varName in lowVarNames)
                {
                    var v  = smst.LookupVariable(varName);
                    var ty = (v is AddressableArmadaVariable) ? AH.ReferToType("Armada_Pointer") : v.ty;
                    var e  = AH.MakeNameSegment(v.FieldName, ty);
                    ps.Add(e);
                    var bv = AH.MakeBoundVar(v.FieldName, v.GetFlattenedType(pgp.symbolsLow));
                    bvs.Add(bv);
                }

                smst = pgp.symbolsHigh.GetMethodSymbolTable(methodName);
                var highVars = new List <ArmadaVariable>(smst.AllVariablesInOrder);

                if (highVars.Count() != lowVarNames.Count())
                {
                    for (var i = 0; i < highVars.Count(); ++i)
                    {
                        if (!lowVarNames.Contains(highVars[i].name))
                        {
                            var v  = highVars[i];
                            var ty = (v is AddressableArmadaVariable) ? AH.ReferToType("Armada_Pointer") : v.ty;
                            ps.Insert(i, AH.MakeNameSegment(strategy.InitializationExpression, ty));
                        }
                    }
                }

                var case_body = AH.MakeApplyN($"H.Armada_StackFrame_{methodName}", ps, "H.Armada_StackFrame");
                cases.Add(AH.MakeMatchCaseExpr($"Armada_StackFrame_{methodName}", bvs, case_body));
            }

            var source  = AH.MakeNameSegment("frame", "L.Armada_StackFrame");
            var body    = AH.MakeMatchExpr(source, cases, "H.Armada_StackFrame");
            var formals = new List <Formal> {
                AH.MakeFormal("frame", "L.Armada_StackFrame")
            };
            var fn = AH.MakeFunction("ConvertStackFrame_LH", formals, body);

            pgp.AddDefaultClassDecl(fn, "convert");
        }
示例#3
0
        protected override void GenerateConvertTraceEntry_LH()
        {
            var cases = new List <MatchCaseExpr>();

            foreach (var nextRoutine in pgp.symbolsLow.NextRoutines)
            {
                cases.Add(GetTraceEntryCaseForNextRoutine_LH(nextRoutine));
            }

            ExpressionBuilder bodyBuilder = new ExpressionBuilder(pgp.prog);

            var ls    = AH.MakeNameSegment("ls", "L.Armada_TraceEntry");
            var entry = AH.MakeNameSegment("entry", "L.Armada_TraceEntry");
            var tid   = AH.MakeExprDotName(entry, "tid", "L.Armada_ThreadHandle");

            var locv    = AH.MakeApply2("L.Armada_GetThreadLocalView", ls, tid, "L.Armada_SharedMemory");
            var threads = AH.MakeExprDotName(ls, "threads", "map<Armada_ThreadHandle, Armada_Thread>");
            var t       = AH.MakeSeqSelectExpr(threads, tid, "L.Armada_Thread");

            // var t = AH.ParseExpression(pgp.prog, "", "ls.threads[tid]");

            locv = bodyBuilder.AddVariableDeclaration("locv", locv);
            t    = bodyBuilder.AddVariableDeclaration("t", t);

            var source = AH.MakeNameSegment("entry", "L.Armada_TraceEntry");
            var body   = AH.MakeMatchExpr(source, cases, "H.Armada_TraceEntry");

            bodyBuilder.SetBody(body);

            var formals = new List <Formal> {
                AH.MakeFormal("ls", "LState"), AH.MakeFormal("entry", "L.Armada_TraceEntry")
            };
            var validTraceEntryPredicate = AH.MakeApply2("L.Armada_ValidStep", ls, entry, new BoolType());

            var fn = AH.MakeFunctionWithReq("ConvertTraceEntry_LH", formals, validTraceEntryPredicate, bodyBuilder.Extract());

            pgp.AddDefaultClassDecl(fn, "convert");
        }