예제 #1
0
 public Utility(IYololExecutor executor, IYololParser parser, Configuration config)
 {
     _executor    = executor;
     _parser      = parser;
     _yogi        = config.YogiPath;
     _debuggerUrl = config.OnlineDebuggerUrl;
 }
예제 #2
0
        private async Task RunYolol(string input, IYololExecutor executor, uint lines)
        {
            // Try to parse code as Yolol
            var result = await Parse(input);

            if (result == null)
            {
                return;
            }

            // Prep execution state
            var compileTimer = new Stopwatch();

            compileTimer.Start();
            var state = await executor.Prepare(result);

            compileTimer.Stop();

            // Run for N lines, 500ms or until `:done!=0`
            var exeTimer = new Stopwatch();

            exeTimer.Start();
            var saved = state.Serialize();
            var err   = await state.Run(lines, TimeSpan.FromMilliseconds(500));

            // Print out the final machine state
            var embed = state.ToEmbed(embed =>
            {
                embed.AddField("Setup", $"{compileTimer.ElapsedMilliseconds}ms", true);
                embed.AddField("Execute", $"{exeTimer.ElapsedMilliseconds}ms", true);

                if (err != null)
                {
                    embed.AddField("Error", $"{err}", false);
                }

                if (_debuggerUrl != null)
                {
                    var base64 = saved.Serialize();
                    embed.WithUrl($"{_debuggerUrl}?state={base64}");
                }
            });

            await ReplyAsync(embed : embed.Build());
        }
예제 #3
0
        private async Task RunYolol(string input, IYololExecutor executor)
        {
            // Try to parse code as Yolol
            var result = await Parse(input);

            if (result == null)
            {
                return;
            }

            // Prep execution state
            var compileTimer = new Stopwatch();

            compileTimer.Start();
            var state = executor.Prepare(result);

            compileTimer.Stop();

            // Run for 2000 lines, 500ms or until `:done!=0`
            var exeTimer = new Stopwatch();

            exeTimer.Start();
            var err = state.Run(2000, TimeSpan.FromMilliseconds(500));

            // Print out error if execution terminated for some reason
            if (err != null)
            {
                await ReplyAsync(err);

                return;
            }

            // Print out the final machine state
            var embed = state.ToEmbed(embed => {
                embed.AddField("Setup", $"{compileTimer.ElapsedMilliseconds}ms", true);
                embed.AddField("Execute", $"{exeTimer.ElapsedMilliseconds}ms", true);
            });

            await ReplyAsync(embed : embed.Build());
        }
예제 #4
0
 public Utility(IYololExecutor executor, IYololParser parser)
 {
     _executor = executor;
     _parser   = parser;
 }
예제 #5
0
 public BasicVerification(IYololExecutor executor)
 {
     _executor = executor;
 }
예제 #6
0
 public JupyterContext(IYololExecutor executor)
 {
     _executor = executor;
 }
예제 #7
0
 public Jupyter(IYololExecutor executor)
 {
     _executor = executor;
 }
예제 #8
0
 public BasicVerification(Configuration config, IYololExecutor executor)
 {
     _config   = config;
     _executor = executor;
 }
예제 #9
0
 public static async Task <IExecutionState> Prepare(this IYololExecutor executor, Yolol.Grammar.AST.Program program, string done = ":done")
 {
     return((await executor.Prepare(new[] { program }, done)).Single());
 }