public static async Task MessageCreated(DiscordClient client, MessageCreateEventArgs ctx) { if (ctx.Author.IsBot) { return; } string message = ctx.Message.Content; if (!message.StartsWith("$")) { return; } message = message.Substring(1); bool dumpMemory = false; bool dumpFull = false; if (message.Contains('-')) { dumpMemory = message.Contains("--dumpMemory"); dumpFull = message.Contains("--dumpMemoryFull"); message = message.Substring(0, message.IndexOf('-')); message = message.Substring(0, message.Length - 1); } ProgramEnvironment environment = new ProgramEnvironment(message, ctx.Channel); if (await environment.Compile(dumpMemory, dumpFull)) { await environment.Run(dumpMemory, dumpFull); } }
public void GetCoinbase() { Address coinbase = new Address(); ProgramEnvironment environment = ProgramEnvironment.Builder().Coinbase(coinbase).Build(); var compiler = new BytecodeCompiler(); compiler.Coinbase(); Machine machine = new Machine(environment); machine.Execute(compiler.ToBytes()); var stack = machine.Stack; Assert.IsNotNull(stack); Assert.AreEqual(1, stack.Size); Assert.AreEqual(new DataWord(coinbase.Bytes), stack.Pop()); }
private static (int Accumulator, bool didTerminate) Run(ProgramEnvironment environment, IReadOnlyList <Action <ProgramEnvironment> > program) { var visitedMemoryLocations = new HashSet <int>(); while (true) { var previousAcc = environment.Accumulator; program[environment.InstructionPointer](environment); if (environment.InstructionPointer == program.Count - 1) { return(environment.Accumulator, true); } if (visitedMemoryLocations.Contains(environment.InstructionPointer)) { return(previousAcc, false); } visitedMemoryLocations.Add(environment.InstructionPointer); } }
/// <summary> /// The entry point of the program, where the program control starts and ends. /// </summary> /// <param name="args">The command-line arguments.</param> /// <returns>The exit code that is given to the operating system after the program ends.</returns> public static int Main(string[] args) { bool show_help = false; ProgramEnvironment env = new ProgramEnvironment(); var p = new OptionSet() { { "t|task=", "The task to be executed (validate-model,validate-data,match,generate-data,generate-heuristics,assume).", env.SetTask }, { "v|verbosity=", "The level of verbosity (error,warning,assumption,remark).", env.SetVerbosity }, { "h|help", "Show this help message and exit.", x => show_help = x != null } }; List <string> files = new List <string> (); try { files = p.Parse(args); Interaction.VerbosityLevel = env.Verbosity; } catch (OptionException e) { Console.Error.Write("zincoxide: "); Console.Error.WriteLine(e.Message); Console.Error.WriteLine("Try 'zincoxide --help' for more information."); return((int)ProgramResult.StaticError); } catch (ZincOxideException e) { Interaction.Error(e.Message); return((int)ProgramResult.StaticError); } if (show_help) { Console.Error.WriteLine("Usage: zincoxide [Options]+ files"); Console.Error.WriteLine(); Console.Error.WriteLine("Options: "); p.WriteOptionDescriptions(Console.Error); } else { DirectoryInfo dirInfo = new DirectoryInfo("."); foreach (string name in files) { FileInfo[] fInfo = dirInfo.GetFiles(name); foreach (FileInfo info in fInfo) { try { using (FileStream file = new FileStream(info.FullName, FileMode.Open)) { MiniZincLexer scnr = new MiniZincLexer(file); MiniZincParser pars = new MiniZincParser(scnr); Interaction.ActiveFile = info.Name; Console.Error.WriteLine("File: " + info.Name); #if PARSE pars.Parse(); #else foreach (Token tok in scnr.Tokenize()) { Console.Error.Write(tok); Console.Error.Write(' '); } #endif if (pars.Result != null) { Console.Error.WriteLine("echo: "); pars.Result.Write(Console.Out); } else { Interaction.Warning("File \"{0}\" is not a valid MiniZinc file."); } } } catch (IOException) { Interaction.Warning("File \"{0}\" not found.", info.Name); } } } } return((int)ProgramResult.Succes); }