Пример #1
0
        public static void Test3_preCH_delta()
        {
            // basic
            var C1 = new TypedSingleCH <sC1>();
            var C2 = new TypedSingleCH <sC2>();
            var C3 = new TypedSingleCH <sC3>();

            var clSC = new CH_closedScope()
                       .decl("c1", C1)
                       .decl("c2", C2)
                       .decl("c3", C3);

            var D1 = new TypedSingleCH <sD1>();
            var D2 = new TypedSingleCH <sD2>();
            var D3 = new TypedSingleCH <sD3>();

            var pD1 = new adapter_preCH(D1);
            var pD2 = new adapter_preCH(D2);
            var pD3 = new adapter_preCH(D3);

            var pdeltaSC = new preCH_deltaScope(clSC)
                           .decl("c1", pD1)
                           .decl("delta_2", pD2);

            AssertEquivalent(pdeltaSC.instantiate().close(),
                             new []        { "delta_2", "c1", "c3", "c2" },
                             new TypedCH[] { D2, D1, C3, C2 });

            // todo : MOAR!
            Console.WriteLine("================= preDeltaScoping ok ============= ");
        }
Пример #2
0
        public static void Equivalent(CH_closedScope cls, preCH_deltaScope deltaSC)
        {
            int common_count = cls.refs().Count();
            var test         = cls.refs().Zip(deltaSC.refs(), (ref_L, ref_R) => ReferenceEquals(ref_L.CH, ref_R.pre_ch.CH));

            D.Assert(test.All(_ => _));                // all true
            D.Assert(test.Count() == common_count);    // re-evals ... stress testing is never bad
        }
Пример #3
0
 preCH_deltaScope(CH_closedScope origScope, LL <preCH> origLL, LL <preCH> own, LL <preCH> extnls)
 {
     D.Assert(origScope != null);
     this.origScope = origScope;
     origLL_head    = origLL;
     ownLL_head     = own;
     externals      = extnls;
 } // the readonlys need a detour over constructor
Пример #4
0
 public preCH_deltaScope(CH_closedScope clSC)
 {
     D.Assert(clSC != null);
     origScope = clSC;
     foreach (var nodeCH in clSC.LL_head.LIFO_shadowed().Reverse())
     {
         origLL_head = origLL_head.chain(nodeCH.name, new adapter_preCH(nodeCH.pay));
     }
 }
Пример #5
0
 public CH_deltaScope(CH_closedScope clsSc)
 {
     if (clsSc == null)
     {
         throw new ScopeException("origin scope can't be null");
     }
     orig_scope = clsSc;
     // own and externals stay empty
 }
Пример #6
0
 public CH_deltaScope(CH_closedScope clsSc, LL <TypedCH> ll, LL <TypedCH> externals)
 {
     if (clsSc == null)
     {
         throw new ScopeException("origin scope can't be null");
     }
     orig_scope      = clsSc;
     this.ownLL_head = ll;
     this.externals  = externals;
 }
Пример #7
0
        // to be able to write down expected result in a readable way
        public static void AssertEquivalent(CH_closedScope cls, string [] names, TypedCH [] CHs)
        {
            D.Assert(names.Length == CHs.Length);
            // cls.refs().NLSendRec("scope refs" , 1 , (_obj) => doing( (CH_Scope.Ref) _obj ) ); // git f****d this prototype
            var zipped_refs = names
                              .Zip(CHs, (n, ch) => new CH_Scope.Ref {
                name = n, CH = ch
            })
                              /*.NLSendRec("zpipped" , 1 , doing )*/;


            var test = cls.refs().Zip(zipped_refs,
                                      (r_left, r_right) =>
                                      (r_left.name == r_right.name) &&                  //.NLSend("name_equal")
                                      ReferenceEquals(r_left.CH, r_right.CH)            //.NLSend("ref_equal")
                                      ).NLSendRec();

            D.Assert(names.Length == test.Count());
            D.Assert(test.All(_ => _));
        }
Пример #8
0
        // not quite sure yet
        // this is for TURX .... probably most sensible to swap the inheritance arrow between TU > TURX
        // Concrete TUs already use something like this, but by convention only rather then interface - this might actually be the better solution
        //public virtual preCH preCH_out => VBoxTUs.Last().preCH_out;

        // translation phases
        public preCH_deltaScope scope(CH_closedScope c)
        {
            return(scope(new preCH_deltaScope(c)));
        }
Пример #9
0
        public static void Test2_basic_scoping()
        {
            var closA = new TypedSingleCH <int>();
            var closB = new TypedMultiCH <string>();  // types and kinds don't matter

            var closedSC = new CH_closedScope()
                           .decl("cA", closA)
                           .decl("cB", closB);

            var D1 = new TypedSingleCH <int>();
            var D2 = new TypedMultiCH <string>();  // types and kinds don't matter

            TypedCH dummy1;
            TypedCH dummy2;

            var deltaCH = new CH_deltaScope(closedSC)
                          .decl("new name", D1)
                          .addRef("cA", out dummy1)
                          .addRef("new name", out dummy2);

            D.Assert(object.ReferenceEquals(dummy1, closA));
            D.Assert(object.ReferenceEquals(dummy2, D1));

            D.Assert(
                deltaCH.external_refs().Select(_ref => _ref.name).
                SequenceEqual(new [] { "cA" })                        // ref for "new name" is not external
                );

            // ----------------------------

            var deltaCH2 = new CH_deltaScope(closedSC)
                           .decl("cA", D1)
                           .decl("cA", D1)
                           .decl("cA", D1)
                           .decl("cB", D1) // shadow both, multiple "cA"s are compressed to one in LIFO_shadowed
                           .decl("cA", D2) // shadow cA again with a different target
                           .addRef("cA", out dummy1);

            var expected_names = new []        { "cA", "cB" };   // in reverse of insertion order
            var expected_chs   = new TypedCH[] { D2, D1 };       // for cA , cB resp.

            D.Assert(deltaCH2.refs().Select(r => r.name).SequenceEqual(expected_names));
            D.Assert(deltaCH2.refs().Select(r => r.CH).SequenceEqual(expected_chs));

            // -------------------------------------


            var closFunky = new TypedSingleCH <object>();


            var origSC = new CH_closedScope()
                         .decl("cA", closFunky) // never see this guy
                         .decl("cA", closA)
                         .decl("cB", closB);

            var     sh1       = new TypedMultiCH <float>();
            TypedCH sh_dummy1 = null;
            TypedCH sh_dummy2 = null;

            var shadowDelta1 = new CH_deltaScope(origSC)
                               .decl("sh1", sh1)
                               .addRef("cA", out sh_dummy1) // external ref
                               .decl("cA", sh1)
                               .addRef("cA", out sh_dummy2) // now cA is both an external and internal ref
            ;

            // cB is not touched , thus :
            // refs in order : [  "cA" -> sh_dummy2 == sh1 | "sh1" -> sh1 | "cB" -> closB ]
            //                 ["cA" -> closA == sh_dummy1] is preserved in external_refs

            D.Assert(ReferenceEquals(sh_dummy1, closA));
            D.Assert(ReferenceEquals(sh_dummy2, sh1));

            expected_names = new []        { "cA", "sh1", "cB" };
            expected_chs   = new TypedCH[] { sh1, sh1, closB };

            D.Assert(shadowDelta1.refs().Select(r => r.name).SequenceEqual(expected_names));
            D.Assert(shadowDelta1.refs().Select(r => r.CH).SequenceEqual(expected_chs));

            D.Assert(shadowDelta1.external_refs().Select(r => r.name).SequenceEqual(new        [] { "cA" }));
            D.Assert(shadowDelta1.external_refs().Select(r => r.CH).SequenceEqual(new TypedCH[] { closA }));

            // heheh :) two chaining deltaScopes need no extra testing   new DeltaScope ( fromDeltaScope ) is identical to its original in all fields - there is no point to this

            Console.WriteLine("================= basicScoping ok ============= ");
        }