private bool Xor(TSRPStack stack, bool flip = false) { if (stack.Top is StackBool && stack.FromTop(1) is StackBool) { StackBool a = (StackBool)stack.Pop(); StackBool b = (StackBool)stack.Pop(); var c = Xor(a, b) ^ flip; stack.Push(new StackBool(c)); return(true); } return(false); }
public override bool Execute(string command, TSRPStack stack) { if (command == "open_file") { if (stack.Top is StackString) { StackString s = (StackString)stack.Pop(); stack.Push(new StackFile(s.Value)); } } else if (command == "call_windows") { if (stack.Top is StackString) { StackString s = (StackString)stack.Pop(); System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = "cmd.exe"; startInfo.Arguments = "/C " + s.Value; process.StartInfo = startInfo; process.Start(); return(true); } } else if (command == "call_program") { if (stack.Top is StackString && stack.FromTop(1) is StackString) { StackString args = (StackString)stack.Pop(); StackString program_name = (StackString)stack.Pop(); System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.FileName = program_name.Value; startInfo.Arguments = args.Value; process.StartInfo = startInfo; process.Start(); return(true); } } return(false); }
public override bool Execute(string command, TSRPStack stack) { if (command == "function") { stack.Pop(); stack.Push(new StackFunction(value)); return(true); } else if (types.Contains(command)) { stack.Pop(); StackNumber a = StackNumber.Convert(command, value); stack.Push(a); return(true); } else if (command == "+") { if (stack.FromTop(1) is StackNumber) { stack.Pop(); var a = (StackNumber)stack.Pop(); stack.Push(new StackString(a.ToString() + value)); } else if (stack.FromTop(1) is StackString) { stack.Pop(); var a = (StackString)stack.Pop(); stack.Push(new StackString(a.value + value)); } else { return(false); } return(true); } else if (command == "array") { stack.Pop(); stack.Push(new StackArray(this)); return(true); } else if (command == "chararray" || command == "carray") { stack.Pop(); stack.Push(new StackArray(this, true)); return(true); } else if (command == "string") { return(true); } else if (command == "==") { if (stack.FromTop(1) is StackString) { stack.Pop(); var a = (StackString)stack.Pop(); stack.Push(a.value == value); return(true); } } else if (command == "!=") { if (stack.FromTop(1) is StackString) { stack.Pop(); var a = (StackString)stack.Pop(); stack.Push(a.value != value); return(true); } } else if (command == "contains") { if (stack.FromTop(1) is StackString) { stack.Pop(); var a = (StackString)stack.Pop(); stack.Push(a.value.Contains(value)); return(true); } } else if (command == "split") { if (stack.FromTop(1) is StackString) { stack.Pop(); var a = (StackString)stack.Pop(); var b = new TSRPStack(); var c = a.value.Split(new string[] { value }, StringSplitOptions.None); foreach (string d in c) { b.Push(d); } stack.Push(new StackArray(b)); return(true); } } else if (command == "trim") { stack.Pop(); stack.Push(value.Trim().Replace("\n", "").Replace("\r", "").Replace("\t", "")); return(true); } else if (command == "len" || command == "length") { stack.Pop(); stack.Push(value.Length); return(true); } return(false); }
public override bool Execute(string command, TSRPStack stack) { if (command.EndsWith("*") && (stack.Top == this || command.EndsWith("**"))) { int k = 1; if (command.EndsWith("**")) { k = 2; } bool j = Execute(command.Substring(0, command.Length - k), stack); int counter = 0; while (stack.Top != this) { counter++; elements.Push(stack.Pop()); } stack.Pop(); for (int i = 0; i < counter; i++) { stack.Push(elements.Pop()); } } else if (command == "size") { stack.Push(Count); return(true); } else if (command == "at") { if (stack.Top is StackNumber) { int n = ((StackNumber)stack.Pop()).ToInt(); if (n < Count) { stack.Push(((StackElement)elements.FromTop(Count - n - 1).Clone())); return(true); } else { return(false); } } return(false); } else if (command == "push" || command == "array_push") { if (stack.Count != 0) { elements.Push(stack.Pop()); } return(true); } else if (command == "array_pop") { if (elements.Count > 0) { stack.Push(elements.Pop()); return(true); } else { return(false); } } else if (command == "set") { if (stack.Top is StackNumber) { int n = ((StackNumber)stack.Pop()).ToInt(); StackElement el = stack.Pop(); var x = Elements; if (n < Count) { x[n] = el; elements.Elements = x; return(true); } else { return(false); } } return(false); } else if (command == "chars2str") { var x = Elements; StringBuilder b = new StringBuilder(); for (int i = 0; i < x.Length; i++) { StackNumber y = null; if (x[i] is StackNumber) { y = (StackNumber)x[i]; } else { continue; } b.Append((char)y.ToUnsignedShort()); } stack.Push(b.ToString()); return(true); } else if (command == "concatstr") { var x = Elements; StringBuilder b = new StringBuilder(); for (int i = 0; i < x.Length; i++) { StackString y = null; if (x[i] is StackString) { y = (StackString)x[i]; } else { continue; } b.Append(y.Value); } stack.Push(b.ToString()); return(true); } else if (command == "array_clear" || command == "empty") { elements.Clear(); return(true); } else if (command == "release") { stack.Pop(); var els = elements.Elements; //Array.Reverse(els); foreach (StackElement el in els) { stack.Push(el); } elements.Clear(); return(true); } else if (command == "clone") { stack.Push(new StackArray(this)); return(true); } else if (command == "reverse") { var x = elements.Elements; elements.Clear(); for (var i = x.Length - 1; i >= 0; i--) { elements.Push(x[i]); } return(true); } return(false); }