public ControlledRun(bool passive) { menu.CQ.PassiveMode = passive; menu.Add(new Menu_Print(this)); menu.Add(new Menu_Lib(this)); menu.Add(new Menu_Def(this)); menu.Add(new Menu_Create(this)); menu.Add(new Menu_Step(this)); menu.Add(new Menu_Run(this)); menu.Add(new Menu_Break(this)); menu.Add(new Menu_Stopwatch()); //menu.Add ("log-break", s => Log.AddBreakpoint (s)); menu.Add(new MI_Echo()); menu.Add(new MI_Pause()); var store = new FileRecordStore(); menu.Add(new MI_Record(store) { Selector = "{", EndRecordCommand = "}", }); menu.Add(new MI_Replay(menu, store) { Selector = "!", }); var mi_if = menu.Add(new MI_If()); mi_if.Conditions.Add("hist-has", Condition_HistHas); _Def = DefinitionLibrary.Load("BusyBeaver2"); }
public string ToString(TmDefinition def) { var sb = new StringBuilder(); Func <byte, string> convertSingle = b => def == null?b.ToString() : def.Gamma[b]; var headPos = StartFacingRight ? 0 : _WriteUnpacked.Length - 1; var unpacked = _ReadUnpacked.Select(convertSingle).ToArray(); sb.Append(TapeUtil.WriteHeadCell( StartFacingRight, unpacked, headPos, Source.ToString())); sb.Append(" => "); if (Next != null) { headPos += Direction; unpacked = _WriteUnpacked.Select(convertSingle).ToArray(); sb.Append(TapeUtil.WriteHeadCell( EndFacingRight ?? true, unpacked, headPos, Next.ToString())); } else { sb.Append("[INFTY]"); } sb.Append(" (" + Shifts + "s)"); return(sb.ToString()); }
public History(TmDefinition def) { if (def == null) { throw new ArgumentNullException(); } Def = def; }
public MmRun( TmDefinition def, PackedExponentTape tape, MacroLibrary ml, State initialState = null, History <PackedExponentTape> history = null) : base(def, tape, initialState, history) { ML = ml; }
public SimpleTmRun( TmDefinition def, ISimpleTape tape, ISimpleTape secondary = null, State initialState = null, History <ISimpleTape> history = null) : base(def, tape, initialState, history) { if (secondary != null) { _LoopCheck = new SimpleTmRun(def, secondary, null, initialState); _LoopCheck.Options.AllowCreateMissingTransitionBranches = true; // Implies that this machine will follow the path taken by the primary machine. } }
public TmRunBase( TmDefinition def, TTape tape, State initialState = null, History <TTape> hist = null) { if (def == null) { throw new ArgumentNullException(); } if (tape == null) { throw new ArgumentNullException(); } _Definition = def; Tape = tape; Q = initialState ?? _Definition.Q0; History = hist; Result = new TmRunResult(this); }
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)); } }