public void Insert0x60AccordingToTimeStamp(CommandBlock x60) { //we have to insert this 0x60 block type in its proper place int timeStamp = x60.CurrentTimeStamp; int interval = timeStamp / 60; int seconds = timeStamp % 60; int index = IndexOfNth0x5dBlock(interval) + 1; int indexNext = IndexOfNth0x5dBlock(interval + 1); CommandBlock cb; for (int ii = index; ii < indexNext; ii++) { cb = GetAt(ii); if (cb.Type == BlockType.PlayWaveFile) { if (cb.CurrentTimeStamp > timeStamp) { Insert(ii, x60); return; } } } Insert(indexNext, x60); }
public static ILanguageExpressionAtomic ExpressionToAtomicExpression(this CommandBlock commandBlock, ILanguageExpression oldExpr) { //If the given expression is atomic cast it into a scalar atomic expression var atomicExpression = oldExpr as ILanguageExpressionAtomic; return (atomicExpression ?? NonAtomicExpressionToValueAccess(commandBlock, oldExpr)); }
public static LanguageValueAccess NonOrthogonalToOrthogonalMultivector(this CommandBlock commandBlock, GMacFrame derivedFrame, ILanguageExpressionAtomic expr) { //var derived_frame = ((GMacFrameMultivector)expr.ExpressionType).ParentFrame; var newRhsExpr = derivedFrame.DerivedToBaseTransform.CreateTransformExpression(expr); return(NonAtomicExpressionToValueAccess(commandBlock, newRhsExpr)); }
public static ScopeCommandBlockChild Create(CommandBlock parentBlock, string scopeName) { var scope = new ScopeCommandBlockChild(parentBlock, scopeName); RegisterChildScope(scope.ParentScope, scope); return(scope); }
/// <summary> /// Visit a command block to precess its high-level commands into low-level commands /// </summary> /// <param name="command">The command block to be processed</param> /// <returns>Null</returns> public override ILanguageValue Visit(CommandBlock command) { foreach (var childCommand in command.CommandsNoDeclare.OfType <CommandAssign>()) { Visit(childCommand); } return(null); }
public static BasicUnary OrthogonalToNonOrthogonalMultivectorTransform(this CommandBlock commandBlock, GMacFrame derivedFrame, ILanguageExpressionAtomic expr) { //var derived_frame = ((GMacFrameMultivector)expr.ExpressionType).ParentFrame; var newRhsExpr = derivedFrame.BaseToDerivedTransform.CreateTransformExpression(expr); return(newRhsExpr); //return NonAtomicExpressionToValueAccess(command_block, new_rhs_expr); }
public void UnFocusAllSliders() { //MessageBox.Show("Unfocusing all sliders", this.Name); // Console.Beep(); for (int ii = 0; ii < this.CountOf0x5dBlocks(); ii++) { CommandBlock cb = this.GetNth0x5dBlock(ii); cb.UnFocus(); } }
public void Visit(CommandBlock command) { PushRecord(command.ChildScope, true); foreach (var subCommand in command.Commands) { subCommand.AcceptVisitor(this); } PopRecord(); }
/// <summary> /// </summary> /// <param name="commandBlock"> /// The response. /// </param> protected virtual void Send(CommandBlock commandBlock) { if (commandBlock == null) { return; } // Trace.WriteLineIf("Send from " + Name + " " + commandBlock.Cmd1); Send(commandBlock.ToBytes()); }
/// <summary> /// Optimize the compiled body of the given macro /// </summary> /// <param name="baseMacro"></param> /// <returns></returns> public static CommandBlock OptimizeMacro(GMacMacro baseMacro) { var optimizer = new HlOptimizer(baseMacro) { _optimizedBlock = CommandBlock.Create(baseMacro) }; optimizer.Optimize(); return(optimizer._optimizedBlock); }
public void PropagateForwardInclineFromNth0x5dBlock(int nth) { double incline = GetNth0x5dBlock(nth).CurrentIncline; for (int ii = nth + 1; ii < CountOf0x5dBlocks() - 1; ii++) { CommandBlock x5d = GetNth0x5dBlock(ii); x5d.CurrentIncline = incline; x5d.InclineSlider.Value = incline; x5d.Invalidate(); } }
static Command CreateCommandBlock(ParsingInfo info) { CommandBlock block = new CommandBlock(); var commands = info.MultipleChildren("Commands"); foreach (var cmd in commands) { block.commands.Add(CreateCommand(cmd)); //Console.WriteLine("created command " + block.commands[block.commands.Count - 1]); } return(block); }
public void AdjustByte8In0x5dBlocks() //byte #8 refers to the number of 0x60 blocks //immediately preceeding each 0x5d block { for (int ii = 0; ii < CountOf0x5dBlocks(); ii++) { CommandBlock x5d = GetNth0x5dBlock(ii); int idx = IndexOfNth0x5dBlock(ii); int num0x60s = CountOf0x60sBelowThisIndex(idx); int byte8 = 0xf7 - 9 * num0x60s; x5d.SetByte(7, (byte)byte8); x5d.Invalidate(); } }
public void PropagateForwardSpeedFromNth0x5dBlock(int nth) { double speed = GetNth0x5dBlock(nth).CurrentSpeed; for (int ii = nth + 1; ii < CountOf0x5dBlocks() - 1; ii++) { CommandBlock x5d = GetNth0x5dBlock(ii); x5d.CurrentSpeed = speed; x5d.CurrentSpeedMetric = speed * 1.609344; x5d.SpeedSlider.Value = speed; x5d.Invalidate(); } }
public int IndexOf(CommandBlock cb) { int idx = -1; for (int ii = 0; ii < blocks.Count; ii++) { if (blocks[ii].Equals(cb)) { return(ii); } } return(idx); }
/// <summary> /// Execute a command block /// </summary> /// <param name="command"></param> /// <returns></returns> public override ILanguageValue Visit(CommandBlock command) { PushRecord(command.ChildScope, true); foreach (var subCommand in command.Commands) { subCommand.AcceptVisitor(this); } PopRecord(); return(null); }
private static void ExecuteBlock(CommandBlock block) { Memory.IncreaseScope(); foreach (var cmd in block.commands) { Execute(cmd); if (onLoop > 0 && breakSet) { break; } } Memory.DecreaseScope(); }
public TreeNode Visit(CommandBlock command) { var node = new TreeNode("<BLOCK>") { Tag = command }; foreach (var item in command.Commands) { node.Nodes.Add(item.AcceptVisitor(this)); } return(node); }
public List <double> GetMets() { List <double> mets = new List <double>(CountOf0x5dBlocks() - 1); for (int ii = 0; ii < CountOf0x5dBlocks() - 2; ii++) { CommandBlock x5d = GetNth0x5dBlock(ii); double speed = x5d.CurrentSpeed; double incline = x5d.CurrentIncline; mets.Add(calculateMets(speed, incline)); } return(mets); }
/// <summary> /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnDataReceived(object sender, SerialDataReceivedEventArgs e) { var serialPort = sender as SerialPort; if (null == serialPort) { throw new ArgumentNullException(nameof(sender)); } // Sometimes the serialport reports data, even if the port was closed. if (!serialPort.IsOpen) { return; } // Only deal with the arival of chars, ignore all other events if (e.EventType == SerialData.Chars) { var count = serialPort.BytesToRead; var buffer = new byte[count]; var bytesRead = serialPort.Read(buffer, 0, count); Debug.Assert(bytesRead == count, "Bytes read not count"); // Add the read bytes to the end of the buffer InputBuffer.AddRange(buffer); try { var commandBlock = new CommandBlock(); while (null != commandBlock) { if (CommandBlock.TryParse(InputBuffer, out commandBlock)) { InputBuffer.Clear(); Serial.DiscardInBuffer(); Serial.DiscardOutBuffer(); var response = ProcessRequest(commandBlock); Send(response); } } } catch (ArgumentException) { } } }
public void AdjustShowInitialInclineBlock() { CommandBlock b = this.GetNthBlockType(BlockType.ShowInitialIncline, 0); if (b != null) { double initialIncline = this.GetInclineInSteepestBlock(); b.CurrentIncline = initialIncline; b.Invalidate(); } else { MessageBox.Show("Logical program error: NthBlockType.AdjustShowInitalInclineBlock = null", Name); } }
public void Visit(CommandBlock command) { Log.AppendAtNewLine("begin"); Log.IncreaseIndentation(); foreach (var item in command.Commands) { item.AcceptVisitor(this); } Log.DecreaseIndentation(); Log.AppendLineAtNewLine("end"); }
public void AdjustShowInitialSpeedBlock() { CommandBlock b = this.GetNthBlockType(BlockType.ShowInitialSpeed, 0); if (b != null) { double initialSpeed = this.GetSpeedInFastestBlock(); b.CurrentSpeed = initialSpeed; b.CurrentSpeedMetric = initialSpeed * 1.609344; b.Invalidate(); } else { MessageBox.Show("Logical program error: NthBlockType.AdjustShowInitalSpeedBlock = null", Name); } }
public void Insert(int index, CommandBlock b) { try { blocks.Insert(index, b); } catch (ArgumentOutOfRangeException aoore) { if (aoore != null) { MessageBox.Show("program error BinaryFit.Insert(idx,block) -- idx out of bounds", "program logical error"); } blocks.Add(b); } AdjustCommandCountBlock(); }
public override void VisitCommandBlock(CommandBlock node) { base.VisitCommandBlock(node); if (node.Statements.Count > 0 && node.Statements[0].Separator != null && _position > node.Statements[0].End) { var command = node.Statements[0].Element.GetFirstDescendant <Command>(); if (command != null) { var commandResults = new VariableSymbol("$command_results", _binder.GetResultTypeOrError(command)); _binder._localScope.AddSymbol(commandResults); } } }
private static LanguageValueAccess NonAtomicExpressionToValueAccess(this CommandBlock commandBlock, ILanguageExpression oldExpr) { if (oldExpr is ILanguageExpressionAtomic) { throw new InvalidOperationException("This should never happen!"); } var localVar = commandBlock.DefineLocalVariable(oldExpr.ExpressionType).DataStore; //Create a local variable to hold value and return the local variable as a direct value access object var lhsValueAccess = LanguageValueAccess.Create(localVar); commandBlock.AddCommand_Assign(lhsValueAccess, oldExpr); return(lhsValueAccess); }
//public override void ResetOnAcquire() //{ // base.ResetOnAcquire(); // _generatedBlock = null; //} protected override void Translate() { //Create the command block _generatedBlock = CommandBlock.Create(Context.ActiveParentScope); Context.PushState(_generatedBlock.ChildCommandBlockScope); //Begin translation of the composite expression commands var nodeBlockExpressionCommandsList = RootParseNode.ChildNodes[0]; foreach (var subnode in nodeBlockExpressionCommandsList.ChildNodes) { GMacCommandGenerator.Translate(Context, subnode); } Context.PopState(); }
public void AdjustCommandCountBlock() { CommandBlock commandCountBlock = this.blocks[0]; if (commandCountBlock.Type != BlockType.CommandCount) { return; } else { short count = (short)(this.blocks.Count - 1); //we don't count the commandCountBlock //since it's not technically a command block byte highByte = (byte)((count & 0xff00) >> 8); byte lowByte = (byte)(count & 0x00ff); commandCountBlock.SetByte(0, highByte); commandCountBlock.SetByte(1, lowByte); } }
public void CommandBlockTest() { object[][] datas = { new object[] { "say \"fa q\" \\", "setblock ~0 ~2 ~0 chain_command_block 0 replace {Command:\"say \\\"fa q\\\" \\\\\",auto:1b}", false, (byte)0, ccb }, new object[] { "cond:say hi", "setblock ~0 ~2 ~0 chain_command_block 8 replace {Command:say hi,auto:1b}", true, (byte)0, ccb }, new object[] { "data:5 icb:say test", "setblock ~0 ~2 ~0 command_block 5 replace {Command:say test}", false, (byte)5, icb }, new object[] { "data:5 cond:rcb:say hi", "setblock ~0 ~2 ~0 repeating_command_block 13 replace {Command:say hi,auto:1b}", true, (byte)5, rcb } }; foreach (object[] data in datas) { var cb = new CommandBlock((string)data[0], 0, 2, 0, 0, 0); Assert.AreEqual(cb.isCond, (bool)data[2]); Assert.AreEqual(cb.damage, (byte)data[3]); Assert.AreEqual(cb.cbType, (CommandBlock.type)data[4]); Assert.AreEqual(cb.ToString(), (string)data[1]); } }
public void ReplaceBlockType(BlockType t, CommandBlock b) { //replace first found pre-existing block type t with new command block b //this is used to update the information contained in the header //blocks which said values were unknown at the time the header //blocks were first generated or said values have changed since then for (int ii = 0; ii < this.Count; ii++) { if (blocks[ii].Type == t) { //we have our boy, so break out of this loop afterwards RemoveAt(ii); Insert(ii, b); break; } } }