コード例 #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");
        }