Example #1
0
        public PackedExponentTape(
            PackedExponentTape src,
            bool cutOffLeft  = false,
            bool cutOffRight = false)
        {
            if (src == null)
            {
                throw new ArgumentNullException();
            }

            Macro            = new MacroPacker(src.Macro);
            _PositionInMacro = src._PositionInMacro;
            FacingRight      = src.FacingRight;
            Shifts           = src.Shifts;

            if (!cutOffLeft)
            {
                _L = new LinkedList2 <Cell> (src._L.Select(c => c.Clone()));
            }
            if (!cutOffRight)
            {
                _R = new LinkedList2 <Cell> (src._R.Select(c => c.Clone()));
            }

            CheckConsistency();
        }
Example #2
0
		public void DecodeTest ()
		{
			var target = new PackedExponentTape (8, _DefaultGamma, null);
			var data = new byte[] { 1, 1, 1, 0, 0, 0, 0, 1 }; // = 128 + 64 + 32 + 1 = 225
			var actual = target.Macro.Decode (225);
			CollectionAssert.AreEqual (data, actual);
		}
Example #3
0
		public void EncodeTest ()
		{
			var target = new PackedExponentTape (8, _DefaultGamma, null);
			var data = new byte[] { 1, 1, 1, 0, 0, 0, 0, 1 }; // = 128 + 64 + 32 + 1 = 225
			var actual = target.Macro.Encode (data);
			Assert.AreEqual (225, actual);
		}
Example #4
0
 public bool Equals(
     PackedExponentTape t,
     ExponentComparison ec,
     bool ignoreTheirSuperfluousLeft,
     bool ignoreTheirSuperfluousRight)
 {
     if (t == null)
     {
         return(false);
     }
     return(true &&
            LeftSideEqualWith(t, ec, ignoreTheirSuperfluousLeft) &&
            RightSideEqualWith(t, ec, ignoreTheirSuperfluousRight));
 }
Example #5
0
        public bool RightSideEqualWith(PackedExponentTape t, ExponentComparison ec, bool ignoreTheirSuperfluous)
        {
            if (t == null)
            {
                throw new ArgumentNullException();
            }

            if (_PositionInMacro != t._PositionInMacro)
            {
                return(false);
            }
            if (FacingRight != t.FacingRight)
            {
                return(false);
            }
            return(ContentEqualWith(ec, _R.First, t._R.First, ignoreTheirSuperfluous));
        }
Example #6
0
		public PackedExponentTape (
			PackedExponentTape src,
			bool cutOffLeft = false,
			bool cutOffRight = false)
		{
			if (src == null)
				throw new ArgumentNullException ();

			Macro = new MacroPacker (src.Macro);
			_PositionInMacro = src._PositionInMacro;
			FacingRight = src.FacingRight;
			Shifts = src.Shifts;

			if (!cutOffLeft) {
				_L = new LinkedList2<Cell> (src._L.Select (c => c.Clone ()));
			}
			if (!cutOffRight) {
				_R = new LinkedList2<Cell> (src._R.Select (c => c.Clone ()));
			}

			CheckConsistency ();
		}
Example #7
0
 public Cell(PackedExponentTape parent, byte b, ulong exponent)
 {
     Parent   = parent;
     Data     = b;
     Exponent = exponent;
 }
Example #8
0
			public override void Execute (string s)
			{
				var options = s.Split (null)
					.Select (o => o.ToLowerInvariant ())
					.Where (o => !string.IsNullOrWhiteSpace (o))
					.ToArray ();

				var hist = options.Contains ("nohist")
					? null
					: new History<PackedExponentTape> (CR._Def);
				var macro = (uint) (CR._Def.SuggestedMacroSize ?? 1);
				var tape = new PackedExponentTape (macro, CR._Def.Gamma, null);
				CR.MM = new MmRun (CR._Def, tape, new MacroLibrary (), null, hist);

				var silent = options.Contains ("silent");

				TmPrintOptions.PrintTapeSteps = !silent;
				TmPrintOptions.PrintTransitionLevel = silent
					? PrintTransitionLevel.None
					: PrintTransitionLevel.All;

				var useFastMacro = !options.Contains ("nofastmacro");
				CR.MM.Options.UseMacros = true; // must be true unless tape is not exponential
				CR.MM.Options.UseMacroForwarding = useFastMacro;

				CR.MM.AfterStep += new DetectTapeTooSmall ().Detect;
				CR.MM.Result.Changed += () => {
					Console.WriteLine ("Result of " + CR._Def.ShortDefinitionString + ": " + CR.MM.Result);
				};

				using (var block = Log.BeginLocal ()) {
					Log.Write ("Selected machine: ");
					Log.BackgroundColor = ConsoleColor.Yellow;
					Log.ForegroundColor = ConsoleColor.Black;
					Log.Write (CR._Def.ShortDefinitionString);
					Log.ResetColor ();
					if (options.Any ()) {
						Log.Write ("; Options: ");
						Log.Write (s);
					}
					Log.WriteLine ();
				}

				CR.RaiseMmCreated ();
			}
Example #9
0
		public bool RightSideEqualWith (PackedExponentTape t, ExponentComparison ec, bool ignoreTheirSuperfluous)
		{
			if (t == null)
				throw new ArgumentNullException ();

			if (_PositionInMacro != t._PositionInMacro) {
				return false;
			}
			if (FacingRight != t.FacingRight) {
				return false;
			}
			return ContentEqualWith (ec, _R.First, t._R.First, ignoreTheirSuperfluous);
		}
Example #10
0
		public bool Equals (
			PackedExponentTape t,
			ExponentComparison ec,
			bool ignoreTheirSuperfluousLeft,
			bool ignoreTheirSuperfluousRight)
		{
			if (t == null) {
				return false;
			}
			return true
				&& LeftSideEqualWith (t, ec, ignoreTheirSuperfluousLeft)
				&& RightSideEqualWith (t, ec, ignoreTheirSuperfluousRight);
		}