internal static void Reachable(
      IMetadataHost host,
      ISlice<MethodReferenceAdaptor, FieldReferenceAdaptor, TypeReferenceAdaptor, IAssemblyReference> slice,
      HashSet<object> thingsToKeep,
      HashSet<uint> methodsWhoseBodiesShouldBeKept,
      out Dictionary<IMethodDefinition, uint> contractOffsets
      ) {

      Contract.Requires(host != null);
      Contract.Requires(slice != null);
      Contract.Requires(thingsToKeep != null);
      Contract.Requires(methodsWhoseBodiesShouldBeKept != null);

      var traverser = new MetadataTraverser();
      var me = new FindReachable(host, traverser, slice, thingsToKeep, methodsWhoseBodiesShouldBeKept);
      traverser.TraverseIntoMethodBodies = true;
      traverser.PreorderVisitor = me;

      var methodsToTraverse = slice.Methods;
      foreach (var m in methodsToTraverse) {
        var methodDefinition = m.reference.ResolvedMethod;
        traverser.Traverse(methodDefinition);
      }

      foreach (var c in slice.Chains) {
        VisitChain(c, traverser);
      }
      contractOffsets = me.contractOffsets;
      return;
    }
Example #2
0
        internal static void Reachable(
            IMetadataHost host,
            ISlice <MethodReferenceAdaptor, FieldReferenceAdaptor, TypeReferenceAdaptor, IAssemblyReference> slice,
            HashSet <object> thingsToKeep,
            HashSet <uint> methodsWhoseBodiesShouldBeKept,
            out Dictionary <IMethodDefinition, uint> contractOffsets
            )
        {
            Contract.Requires(host != null);
            Contract.Requires(slice != null);
            Contract.Requires(thingsToKeep != null);
            Contract.Requires(methodsWhoseBodiesShouldBeKept != null);

            var traverser = new MetadataTraverser();
            var me        = new FindReachable(host, traverser, slice, thingsToKeep, methodsWhoseBodiesShouldBeKept);

            traverser.TraverseIntoMethodBodies = true;
            traverser.PreorderVisitor          = me;

            var methodsToTraverse = slice.Methods;

            foreach (var m in methodsToTraverse)
            {
                var methodDefinition = m.reference.ResolvedMethod;
                traverser.Traverse(methodDefinition);
            }

            foreach (var c in slice.Chains)
            {
                VisitChain(c, traverser);
            }
            contractOffsets = me.contractOffsets;
            return;
        }
 protected override void UpdateView(IUnit unit, ISlice slice, float deltaTime)
 {
     if (slice is IProperty prop)
     {
         UpdateValue(prop);
     }
 }
Example #4
0
        T ICoreInstantiate.Instantiate <T>()
        {
            ISlice slice = (ISlice)System.Activator.CreateInstance(GetType());

            slice.FillFrom(this);
            return((T)slice);
        }
Example #5
0
 public override void FillFrom(ISlice other)
 {
     if (other is BaseProperty <T> prop)
     {
         m_Absorbs = new List <IDamage>(prop.m_Absorbs);
         m_Resists = new List <IDamage>(prop.m_Resists);
     }
 }
Example #6
0
 public override void FillFrom(ISlice other)
 {
     if (other is DamageFire @base)
     {
         m_ViewPrefab = @base.m_ViewPrefab;
         m_Damages    = new List <IDamage>(@base.m_Damages);
     }
 }
Example #7
0
 public void QueueSlice(ISlice slice)
 {
     if (slice == null)
     {
         return;
     }
     slice.TimeQueuedMs = _timeStamp;
     _sliceQueue.Add(slice);
 }
Example #8
0
 public override void FillFrom(ISlice other)
 {
     base.FillFrom(other);
     if (other is Health health)
     {
         m_Value         = health.m_Value;
         m_Regen         = health.m_Regen;
         m_RegenDuration = health.m_RegenDuration;
     }
 }
Example #9
0
 public override void FillFrom(ISlice other)
 {
     base.FillFrom(other);
     if (other is Shooting shooting)
     {
         m_TargetterPrefab = shooting.m_TargetterPrefab;
         m_SearchRate      = shooting.m_SearchRate;
         m_EffectRate      = shooting.m_EffectRate;
     }
 }
Example #10
0
 public override void FillFrom(ISlice other)
 {
     base.FillFrom(other);
     if (other is Shield shield)
     {
         m_Value           = shield.m_Value;
         m_RegenRate       = shield.m_RegenRate;
         m_StaggerDuration = shield.m_StaggerDuration;
     }
 }
Example #11
0
 static internal void SetAll(ref _Recons st, ISlice <string> rec)
 {
     st.Dienq       = rec[0];
     st.Phuan       = rec[1];
     st.Karlgren    = rec[2];
     st.Hvang       = rec[3];
     st.Lyx         = rec[4];
     st.Zjew        = rec[5];
     st.PulleyBlank = rec[6];
 }
        protected override void UpdateView(IUnit unit, ISlice slice, float deltaTime)
        {
            //Poolable.TryGetPoolable<ICoreGameObjectInstantiate>(gameObject).GameObject;
            if (unit.Turret != null)
            {
                transform.localRotation = unit.Turret.GameObject.transform.localRotation;
            }
            var system = GetComponent <ParticleSystem>();

            system.Play(true);
        }
Example #13
0
        public void RotatingAndRotatingBackBringsBackToStartPoint()
        {
            ISlice _slice   = new Slice(_basicBlocks);
            ISlice newSlice = _slice.rotate(Direction.left).rotate(Direction.right);

            Assert.AreEqual(newSlice.get_block_in_position(0, 0).get_colour_in_axis(Axis.x), Colour.Blue);
            Assert.AreEqual(newSlice.get_block_in_position(0, 1).get_colour_in_axis(Axis.x), Colour.Red);
            Assert.AreEqual(newSlice.get_block_in_position(0, 2).get_colour_in_axis(Axis.x), Colour.White);
            Assert.AreEqual(newSlice.get_block_in_position(1, 0).get_colour_in_axis(Axis.x), Colour.Green);
            Assert.AreEqual(newSlice.get_block_in_position(1, 1).get_colour_in_axis(Axis.x), Colour.Orange);
        }
Example #14
0
 public override void FillFrom(ISlice other)
 {
     base.FillFrom(other);
     if (other is Moving)
     {
         var moving = (other as Moving);
         moveSpeed             = moving.moveSpeed;
         rotateSpeed           = moving.rotateSpeed;
         pointToPointThreshold = moving.pointToPointThreshold;
         m_Path = moving.m_Path;
     }
 }
Example #15
0
 public override bool Equals(object?obj)
 {
     return(obj switch
     {
         NilType _ => true,
         ISlice slice => slice == Default,
         IArray array => array == Default,
         IChannel channel => channel == Default,
         @string gostr => gostr == Default,
         string str => str == Default,
         _ => obj is null
     });
Example #16
0
 public void ConnectWith <TAxon>(ISlice <T> nextSlice) where TAxon : IAxon <T>, new()
 {
     foreach (var fromNeuron in Neurons)
     {
         foreach (var toNeuron in nextSlice.Neurons)
         {
             var axon = new TAxon
             {
                 InputNeuron = fromNeuron
             };
             toNeuron.InputAxons.Add(axon);
         }
     }
 }
Example #17
0
        public Task Run(ISlice slice)
        {
            if (!Idle)
            {
                return(null);
            }
            _slice = slice;
            _cancelSource.CancelAfter(ConfigManager.Properties.BackgroundThreadTimeout);
            var token = _cancelSource.Token;
            //TODO : Fix cancelation
            var task = Task.Run(() => Start(token));//, token);

            Idle = false;
            return(task);
        }
Example #18
0
        private bool MakeSureSliceHasAtLeastMethodSourceLocation(ISlice <MethodReferenceAdaptor, FieldReferenceAdaptor, TypeReferenceAdaptor, IAssemblyReference> slice, ISourceLocationProvider sourceLocationProvider)
        {
            Contract.Requires(slice != null);
            Contract.Requires(sourceLocationProvider != null);

            foreach (var m in slice.Methods)
            {
                var methodDefinition = m.reference.ResolvedMethod;
                if (sourceLocationProvider.GetPrimarySourceLocationsFor(methodDefinition.Locations).Any())
                {
                    return(true);
                }
            }
            return(false);
        }
Example #19
0
        protected override void UpdateView(IUnit unit, ISlice slice, float deltaTime)
        {
            if (unit.Turret != null)
            {
                transform.localRotation = unit.Turret.GameObject.transform.localRotation;
            }

            var system = GetComponent <ParticleSystem>();

            system.Play(true);

            StartCoroutine(WaitStop());
            IEnumerator WaitStop()
            {
                yield return(new WaitForSeconds(5));

                system.Stop();
            }
        }
Example #20
0
    private void GenerateSlice()
    {
        CurrentSlice.Clear();
        foreach (Transform child in _startCircle.transform)
        {
            Destroy(child.gameObject);
        }

        float usefulWeight = 0f;

        float randomResult          = Random.Range(0, weigths.Sum(w => w));
        int   amountOfSlicesToSpawn = 0;

        for (int i = 0; i < weigths.Count; i++)
        {
            if (randomResult <= weigths[i] + usefulWeight)
            {
                amountOfSlicesToSpawn = i + 1;
                break;
            }
            usefulWeight += weigths[i];
        }

        if (amountOfSlicesToSpawn == 0)
        {
            Debug.Log("Generator generated nothing");
            amountOfSlicesToSpawn = 1;
        }

        int startingPosition = Random.Range(0, 6);

        for (int i = 0; i < amountOfSlicesToSpawn; i++)
        {
            GameObject newSlice       = Instantiate(_slicePrefab, _startCircle.transform);
            ISlice     sliceComponent = newSlice.GetComponent <ISlice>();
            sliceComponent.Init(startingPosition + i > 5 ? (Position)(startingPosition + i - 6) : (Position)(startingPosition + i));
            CurrentSlice.Add(sliceComponent);
        }
        if (IsGameOver())
        {
            EventsManager.Broadcast(EventsType.GameOver);
        }
    }
Example #21
0
        private FindReachable(
            IMetadataHost host,
            MetadataTraverser myTraverser, ISlice <MethodReferenceAdaptor, FieldReferenceAdaptor, TypeReferenceAdaptor, IAssemblyReference> slice,
            HashSet <object> thingsToKeep,
            HashSet <uint> methodsWhoseBodiesShouldBeKept
            )
        {
            Contract.Requires(host != null);
            Contract.Requires(myTraverser != null);
            Contract.Requires(slice != null);
            Contract.Requires(thingsToKeep != null);
            Contract.Requires(methodsWhoseBodiesShouldBeKept != null);

            this.host         = host;
            this.traverser    = myTraverser;
            this.unitIdentity = slice.ContainingAssembly.UnitIdentity;
            this.slice        = slice;
            this.thingsToKeep = thingsToKeep;
            this.methodsWhoseBodiesShouldBeKept = methodsWhoseBodiesShouldBeKept;
            this.contractOffsets = new Dictionary <IMethodDefinition, uint>();
        }
    private FindReachable(
      IMetadataHost host,
      MetadataTraverser myTraverser, ISlice<MethodReferenceAdaptor, FieldReferenceAdaptor, TypeReferenceAdaptor, IAssemblyReference> slice,
      HashSet<object> thingsToKeep,
      HashSet<uint> methodsWhoseBodiesShouldBeKept
      ) {
      Contract.Requires(host != null);
      Contract.Requires(myTraverser != null);
      Contract.Requires(slice != null);
      Contract.Requires(thingsToKeep != null);
      Contract.Requires(methodsWhoseBodiesShouldBeKept != null);

      this.host = host;
      this.traverser = myTraverser;
      this.unitIdentity = slice.ContainingAssembly.UnitIdentity;
      this.slice = slice;
      this.thingsToKeep = thingsToKeep;
      this.methodsWhoseBodiesShouldBeKept = methodsWhoseBodiesShouldBeKept;
      this.contractOffsets = new Dictionary<IMethodDefinition, uint>();

    }
Example #23
0
 void ISliceVisualizer.UpdateView(IUnit unit, ISlice slice, float deltaTime)
 {
     UpdateView(unit, slice, deltaTime);
 }
 public static void DoSomethingCoolWithTheSliceSlide(ISlice slice)
 {
     slice.Slide.LookitMeIAmLearningDesignPatterns();
 }
Example #25
0
    public static Assembly PruneAssembly(HostEnvironment host, ISlice<MethodReferenceAdaptor, FieldReferenceAdaptor, TypeReferenceAdaptor, IAssemblyReference> slice) {
      Contract.Requires(host != null);
      Contract.Requires(slice != null);

      var newAssemblyName = slice.Name;
      var originalAssembly = slice.ContainingAssembly.ResolvedAssembly;
      Contract.Assume(!(originalAssembly is Dummy));
      var methodDefsToKeep = new HashSet<uint>();
      foreach (var m in slice.Methods) {
        methodDefsToKeep.Add(m.reference.InternedKey);
      }


      var copier = new MetadataDeepCopier(host);
      var thingsToKeep = new HashSet<object>();
      var methodHashAttributes = new Dictionary<IMethodDefinition, MethodHashAttribute>();
      var me = new Prune(host, copier, thingsToKeep, methodDefsToKeep, methodHashAttributes);

      // 1. everything that is specified in the slice should definitely be kept.
      foreach (var c in slice.Chains) {
        me.VisitChain(c);
      }

      // 2. everything reachable from the initial set of things to keep should be kept
      Dictionary<IMethodDefinition, uint> contractOffsets;
      FindReachable.Reachable(host, slice, thingsToKeep, methodDefsToKeep, out contractOffsets);
      me.contractOffsets = contractOffsets;

      // 3. copy the original assembly --- entirely!
      var a_prime = copier.Copy(originalAssembly);
      var nameTable = host.NameTable;
      a_prime.ModuleName = nameTable.GetNameFor(newAssemblyName + ".dll");
      a_prime.Name = nameTable.GetNameFor(newAssemblyName);

      var mutableRoot = (RootUnitNamespace)(a_prime.UnitNamespaceRoot);
      var methodHashAttributeType = DefineMethodHashAttributeType(host, mutableRoot);
      me.methodHashAttributeCtor = new Microsoft.Cci.MethodReference(
          host,
          methodHashAttributeType,
          CallingConvention.HasThis,
          host.PlatformType.SystemVoid,
          host.NameTable.Ctor,
          0,
          me.systemString,
          me.systemInt);

      // 4. delete all unwanted things from the mutable copy
      me.RewriteChildren(a_prime);

      var remainingTypes = new List<INamedTypeDefinition>(a_prime.AllTypes.Count); // will only shrink
      remainingTypes.Add(a_prime.AllTypes[0]); // <Module> class is always kept
      for (int i = 1, n = a_prime.AllTypes.Count; i < n; i++) {
        var t = a_prime.AllTypes[i];
        Contract.Assume(t!= null);
        Contract.Assume(copier.OriginalFor.ContainsKey(t));
        var orig = copier.OriginalFor[t];
        if (thingsToKeep.Contains(orig))
          remainingTypes.Add(t);
      }
      a_prime.AllTypes = remainingTypes;
      // do this afterwards so it doesn't get visited.
      mutableRoot.Members.Add(methodHashAttributeType);
      a_prime.AllTypes.Add(methodHashAttributeType);

      return a_prime;
    }
Example #26
0
        internal void AddIndex(ISlice slice)
        {
            npy_intp step;
            bool     negativeStep;
            npy_intp start;
            npy_intp stop;
            bool     hasStop;

            // Find the step
            if (slice.Step == null)
            {
                step         = (npy_intp)1;
                negativeStep = false;
            }
            else
            {
                step         = ConvertSliceValue(slice.Step);
                negativeStep = (step < 0);
            }

            // Find the start
            if (slice.Start == null)
            {
                start = (npy_intp)(negativeStep ? -1 : 0);
            }
            else
            {
                start = ConvertSliceValue(slice.Start);
            }


            // Find the stop
            if (slice.Stop == null)
            {
                hasStop = false;
                stop    = 0;
            }
            else
            {
                hasStop = true;
                stop    = ConvertSliceValue(slice.Stop);
            }

            // Write the type
            int offset = num_indexes * sizeof(npy_intp);

            if (!hasStop)
            {
                indexes[num_indexes].type = NpyIndexType.NPY_INDEX_SLICE_NOSTOP;

                NpyIndexSliceNoStop IndexSliceNoStop = new NpyIndexSliceNoStop()
                {
                    start = start,
                    step  = step,
                };

                indexes[num_indexes].slice_nostop = IndexSliceNoStop;
            }
            else
            {
                indexes[num_indexes].type = NpyIndexType.NPY_INDEX_SLICE;

                NpyIndexSlice IndexSlice = new NpyIndexSlice()
                {
                    start = start,
                    stop  = stop,
                    step  = step,
                };

                indexes[num_indexes].slice = IndexSlice;
            }

            ++num_indexes;
        }
Example #27
0
 public ICube replace_slice(SliceIdentifier identifier, ISlice slice)
 {
     throw new NotImplementedException();
 }
Example #28
0
 public static string CreateFilter(ISlice filter)
 {
     var visitor = new RenderFilterVisitor();
     filter.Accept(visitor);
     return visitor.Html;
 }
Example #29
0
 static public AdaptorSlice <T, U> Cast <T, U> (this ISlice <T> slice, Func <T, U> adaptor)
 {
     return(new AdaptorSlice <T, U>(slice, adaptor));
 }
Example #30
0
 public AdaptorSlice(ISlice <T> slice, Func <T, U> adaptor)
 {
     _slice   = slice;
     _adaptor = adaptor;
 }
Example #31
0
 protected override void FillFrom(ISlice other)
 {
 }
Example #32
0
 public abstract void FillFrom(ISlice other);
Example #33
0
        public static Assembly PruneAssembly(HostEnvironment host, ISlice <MethodReferenceAdaptor, FieldReferenceAdaptor, TypeReferenceAdaptor, IAssemblyReference> slice)
        {
            Contract.Requires(host != null);
            Contract.Requires(slice != null);

            var newAssemblyName  = slice.Name;
            var originalAssembly = slice.ContainingAssembly.ResolvedAssembly;

            Contract.Assume(!(originalAssembly is Dummy));
            var methodDefsToKeep = new HashSet <uint>();

            foreach (var m in slice.Methods)
            {
                methodDefsToKeep.Add(m.reference.InternedKey);
            }


            var copier               = new MetadataDeepCopier(host);
            var thingsToKeep         = new HashSet <object>();
            var methodHashAttributes = new Dictionary <IMethodDefinition, MethodHashAttribute>();
            var me = new Prune(host, copier, thingsToKeep, methodDefsToKeep, methodHashAttributes);

            // 1. everything that is specified in the slice should definitely be kept.
            foreach (var c in slice.Chains)
            {
                me.VisitChain(c);
            }

            // 2. everything reachable from the initial set of things to keep should be kept
            Dictionary <IMethodDefinition, uint> contractOffsets;

            FindReachable.Reachable(host, slice, thingsToKeep, methodDefsToKeep, out contractOffsets);
            me.contractOffsets = contractOffsets;

            // 3. copy the original assembly --- entirely!
            var a_prime   = copier.Copy(originalAssembly);
            var nameTable = host.NameTable;

            a_prime.ModuleName = nameTable.GetNameFor(newAssemblyName + ".dll");
            a_prime.Name       = nameTable.GetNameFor(newAssemblyName);

            var mutableRoot             = (RootUnitNamespace)(a_prime.UnitNamespaceRoot);
            var methodHashAttributeType = DefineMethodHashAttributeType(host, mutableRoot);

            me.methodHashAttributeCtor = new Microsoft.Cci.MethodReference(
                host,
                methodHashAttributeType,
                CallingConvention.HasThis,
                host.PlatformType.SystemVoid,
                host.NameTable.Ctor,
                0,
                me.systemString,
                me.systemInt);

            // 4. delete all unwanted things from the mutable copy
            me.RewriteChildren(a_prime);

            var remainingTypes = new List <INamedTypeDefinition>(a_prime.AllTypes.Count); // will only shrink

            remainingTypes.Add(a_prime.AllTypes[0]);                                      // <Module> class is always kept
            for (int i = 1, n = a_prime.AllTypes.Count; i < n; i++)
            {
                var t = a_prime.AllTypes[i];
                Contract.Assume(t != null);
                Contract.Assume(copier.OriginalFor.ContainsKey(t));
                var orig = copier.OriginalFor[t];
                if (thingsToKeep.Contains(orig))
                {
                    remainingTypes.Add(t);
                }
            }
            a_prime.AllTypes = remainingTypes;
            // do this afterwards so it doesn't get visited.
            mutableRoot.Members.Add(methodHashAttributeType);
            a_prime.AllTypes.Add(methodHashAttributeType);

            return(a_prime);
        }
Example #34
0
 protected abstract void UpdateView(IUnit unit, ISlice slice, float deltaTime);
Example #35
0
        public bool WriteSliceToFile(ISlice <MethodReferenceAdaptor, FieldReferenceAdaptor, TypeReferenceAdaptor, IAssemblyReference> slice, string directory, out string dll)
        {
#if TRACE_PERFORMANCE
            var stopWatch = new Stopwatch();
            stopWatch.Start();
#endif

            var newAssembly = Prune.PruneAssembly(host, slice);

#if TRACE_PERFORMANCE
            Console.WriteLine("Time to prune the assembly: {0}", stopWatch.Elapsed);
#endif

            var errors = ValidateAssembly(host, newAssembly);
            if (/*errors != null && */ 0 < errors.Count)
            {
#if !DEBUG_SLICE
                dll = null;
                return(false);
#endif
            }

            //Get a PDB reader if there is a PDB file.
            PdbReader /*?*/ pdbReader = null;
            string          pdbFile   = slice.ContainingAssembly.ResolvedAssembly.DebugInformationLocation;
            if (string.IsNullOrEmpty(pdbFile) || !File.Exists(pdbFile))
            {
                pdbFile = Path.ChangeExtension(slice.ContainingAssembly.ResolvedAssembly.Location, "pdb");
            }
            if (File.Exists(pdbFile))
            {
                using (var pdbStream = File.OpenRead(pdbFile)) {
                    pdbReader = new PdbReader(pdbStream, host);
                }
            }
            using (pdbReader) {
                ISourceLocationProvider sourceLocationProvider = pdbReader;
                ILocalScopeProvider     localScopeProvider     = pdbReader;

                Contract.Assume(sourceLocationProvider != null, "why??");
                if (!MakeSureSliceHasAtLeastMethodSourceLocation(slice, sourceLocationProvider))
                {
                    dll = null;
                    return(false);
                }

                dll = Path.Combine(directory, slice.Name + ".dll");

#if TRACE_PERFORMANCE
                stopWatch.Reset();
#endif

                using (var peStream = File.Create(dll)) {
                    if (pdbReader == null)
                    {
                        PeWriter.WritePeToStream(newAssembly, host, peStream);
                    }
                    else
                    {
                        using (var pdbWriter = new PdbWriter(dll.Replace(".dll", ".pdb"), pdbReader, emitTokenSourceInfo: true)) {
                            PeWriter.WritePeToStream(newAssembly, host, peStream, sourceLocationProvider, localScopeProvider, pdbWriter);
                        }
                    }
                }

#if TRACE_PERFORMANCE
                Console.WriteLine("Time spent to write on the disk: {0}", stopWatch.Elapsed);
#endif
            }

#if !DEBUG_SLICE
            if (errors != null && 0 < errors.Count)
            {
                using (var tw = new StreamWriter(File.Create(Path.Combine(directory, slice.Name + ".errors.txt"))))
                {
                    // something is performed asynchronously and may not be terminated here, that is wrong!
                    lock (errors)
                    {
                        foreach (var err in errors)
                        {
                            tw.WriteLine(err.Location);
                            foreach (var e in err.Errors)
                            {
                                tw.WriteLine("{0} {1} {2}", e.IsWarning ? "WARNING" : "ERROR ", e.Code, e.Message);
                            }
                            tw.WriteLine();
                        }
                    }
                }

                return(false);
            }
#endif

            // Can this be checked before writing it out?
            if (newAssembly.AssemblyReferences.Any(ar => ar.AssemblyIdentity.Equals(slice.ContainingAssembly.AssemblyIdentity)))
            {
            }

            return(true);
        }