public bool ReadRecord(out PopCommand record) { record = default; unsafe { fixed(byte *pByte = this.buffer) { // This pointer points to the current read point in the // instruction stream. byte *pCur = pByte; // This points to the first byte past the end of the // instruction stream (i.e. when to stop) byte *pEndOfInstructions = pByte + this.currentReadOffset; if ((pCur >= pEndOfInstructions)) //reach end { return(false); } RecordHeader *pCurRecord = (RecordHeader *)pCur; if (pCurRecord->Type != RecordType.Pop) { return(false); } //pop command consumes no space this.currentReadOffset += pCurRecord->Size; return(true); } } }
public void Pop(PopCommand command) { _file.WriteLine($"// Pop {command.Arg1} {command.Arg2}"); var segment = command.Arg1 switch { "local" => "LCL", "argument" => "ARG", "this" => "THIS", "that" => "THAT", _ => "" }; if (!string.IsNullOrEmpty(segment)) { this.PopToARegister(); _file.WriteLine("D=M"); _file.WriteLine($"@{segment}"); _file.WriteLine($"A=M"); for (int i = 0; i < command.Arg2; i++) { _file.WriteLine($"A=A+1"); } _file.WriteLine($"M=D"); return; } var baseAddress = command.Arg1 switch { "temp" => "5", "pointer" => "3", _ => "" }; if (!string.IsNullOrEmpty(baseAddress)) { this.PopToARegister(); _file.WriteLine($"D=M"); _file.WriteLine($"@{baseAddress}"); for (int i = 0; i < command.Arg2; i++) { _file.WriteLine($"A=A+1"); } _file.WriteLine($"M=D"); return; } if (command.Arg1 == "static") { this.PopToARegister(); _file.WriteLine($"D=M"); _file.WriteLine($"@{_name}.{command.Arg2}"); _file.WriteLine($"M=D"); return; } Debugger.WriteLine($"\"{command.Arg1}\""); }
public void Run_Passes_InputOperationIsCorrect() { // Arrange CommandContext context = new CommandContext(); context.PushStack(new MutableKeyValuePair <string, object>("var2", 5)); var stackSizeExpected = 0; var pop = new PopCommand(context); // Act pop.Run(); // Assert Assert.Equal(stackSizeExpected, context.Stack.Count); }
public LoginPageModel(IAppStoreContainer storeContainer, AuthenticationActionCreator authenticationActionCreator) { var store = storeContainer.Store; store.Subscribe(s => { IsLoggingIn = s.AuthenticationState.IsLoggingIn; if (s.AuthenticationState.Exception != null) { CoreMethods.DisplayAlert("An error occured", s.AuthenticationState.Exception.Message, "OK"); return; } if (!string.IsNullOrEmpty(s.AuthenticationState.SessionId)) { PopCommand.Execute(null); } }); PopCommand = new Command(() => { CoreMethods.PopPageModel(true, true); }); LoginCommand = new Command(() => { if (string.IsNullOrEmpty(Username) || string.IsNullOrEmpty(Password)) { CoreMethods.DisplayAlert("An error occured", "All fields are required", "OK"); return; } store.Dispatch(authenticationActionCreator.LoginAction(new Model.Credentials { Password = Password, Username = Username })); }); }