Exemple #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();
        }
Exemple #2
0
        public PackedExponentTape(
            uint macroSize,
            Dictionary <byte, string> gamma,
            IEnumerable <byte> unpackedInit)
        {
            if (macroSize <= 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            if (gamma == null)
            {
                throw new ArgumentNullException();
            }
            Macro = new MacroPacker(macroSize, gamma);

            if (unpackedInit != null)
            {
                foreach (var b in unpackedInit.Reverse())
                {
                    WritePacked(b, false, 0, false);
                }
                _R.RemoveLast();
            }

            FacingRight = true;
            Shifts      = 0;

            CheckConsistency();
        }
Exemple #3
0
		public PackedExponentTape (
			uint macroSize,
			Dictionary<byte, string> gamma,
			IEnumerable<byte> unpackedInit)
		{
			if (macroSize <= 0)
				throw new ArgumentOutOfRangeException ();
			if (gamma == null)
				throw new ArgumentNullException ();
			Macro = new MacroPacker (macroSize, gamma);

			if (unpackedInit != null) {
				foreach (var b in unpackedInit.Reverse ()) {
					WritePacked (b, false, 0, false);
				}
				_R.RemoveLast ();
			}

			FacingRight = true;
			Shifts = 0;

			CheckConsistency ();
		}
Exemple #4
0
		public MacroPacker (MacroPacker clone)
		{
			MacroSize = clone.MacroSize;
			_Gamma = new Dictionary<byte, string> (clone._Gamma);
			_NonzerosInWord = new Dictionary<byte, uint> (clone._NonzerosInWord);
		}
Exemple #5
0
		public static MacroTransition CreateSingleMacroTransition (
			TmDefinition def,
			State q,
			byte readPacked,
			bool facingRight,
			MacroPacker packerInfo)
		{
			if (def == null)
				throw new ArgumentNullException ();
			if (q == null)
				throw new ArgumentNullException ();
			if (packerInfo == null)
				throw new ArgumentNullException ();

			var readUnpacked = packerInfo.Decode (readPacked);
			var left = facingRight ? new byte[0] : readUnpacked.SubArray (0, readUnpacked.Length - 1);
			var right = facingRight ? readUnpacked : readUnpacked.SubArray (readUnpacked.Length - 1, 1);
			var tape = new LimitedBasicTape (left, right, def.Gamma);
			short dir;

			var tm = new SimpleTmRun (def, tape, new LimitedBasicTape (tape, def.Gamma), q);
			tm.AfterStep += new DetectTapeTooSmall ().Detect;
			tm.Options.AllowCreateMissingTransitionBranches = false;

			try {
				TmPrintOptions.Push ();
				TmPrintOptions.PrintTapeSteps = false;
				TmPrintOptions.PrintTransitionLevel = PrintTransitionLevel.None;

				var prevPos = (short) tape.Position;
				tm.Run ();
				dir = (short) (tape.Position - prevPos);
			}
			catch (TransitionNotDefinedException) {
				// Intentional throw. Let the caller handle this.
				throw;
			}
			finally {
				TmPrintOptions.Pop ();
			}

			Debug.Assert (tm.Result.Halted.HasValue != tape.ExitsOnLeftSide.HasValue);

			if (tm.Result.Halted == false) {
				return new MacroTransition (q, readPacked, facingRight, null, readPacked, 0, tm.Shifts, readUnpacked, readUnpacked);
			}
			else {
				var writeUnpacked = tape.Tape;
				var writePacked = packerInfo.Encode (writeUnpacked);
				return new MacroTransition (q, readPacked, facingRight, tm.Q, writePacked, dir, tm.Shifts, readUnpacked, writeUnpacked);
			}
		}
Exemple #6
0
 public MacroPacker(MacroPacker clone)
 {
     MacroSize       = clone.MacroSize;
     _Gamma          = new Dictionary <byte, string> (clone._Gamma);
     _NonzerosInWord = new Dictionary <byte, uint> (clone._NonzerosInWord);
 }
Exemple #7
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 ();
		}