Exemplo n.º 1
0
        public string RealExecute(FungeContext fungeContext)
        {
            var n = fungeContext.GetTopStackTopValues(1)[0];

            if (n < 0)
            {
                return("UB in \"(\" : top stack value negative");
            }

            var values = fungeContext.GetTopStackTopValues(n).ToArray();

            var accum = values.Aggregate(0, (current, value) => current * 256 + value);

            var fps = fungeContext.SupportedFingerPrints;
            var fp  = fps.Find(f => f.FingerPrintHash == accum);

            if (fp == null)
            {
                fungeContext.CurrentThreadDeltaVector = fungeContext.CurrentThreadDeltaVector.Reflect();
                return(null);
            }

            foreach (var(key, f) in fp.KeyBinding)
            {
                _fpc.Find(c => c.Name == key)?.ApplyAlias(f);
            }

            fungeContext.PushToTopStack(accum);
            fungeContext.PushToTopStack(1);
            return(null);
        }
Exemplo n.º 2
0
        protected override string RealExecute(FungeContext fungeContext)
        {
            var values = fungeContext.GetTopStackTopValues(1);

            fungeContext.PushToTopStack(values[0]);
            fungeContext.PushToTopStack(values[0]);
            return(null);
        }
Exemplo n.º 3
0
        public string RealExecute(FungeContext fungeContext)
        {
            var values = fungeContext.GetTopStackTopValues(2);

            fungeContext.PushToTopStack(values[0]);
            fungeContext.PushToTopStack(values[1]);
            return(null);
        }
Exemplo n.º 4
0
        private static string AFunc(FungeContext context)
        {
            var complexes = context.GetTopStackTopValues(4);

            context.PushToTopStack(complexes[0] + complexes[2]);
            context.PushToTopStack(complexes[1] + complexes[3]);
            return(null);
        }
Exemplo n.º 5
0
        public string RealExecute(FungeContext fungeContext)
        {
            var name    = fungeContext.PopString();
            var process = Process.Start(name);

            if (process == null)
            {
                fungeContext.PushToTopStack(-1);
                return($" Can't start {name}");
            }
            process.WaitForExit();
            fungeContext.PushToTopStack(process.ExitCode);
            return(null);
        }
Exemplo n.º 6
0
        public string RealExecute(FungeContext fungeContext)
        {
            //todo wtf
            try
            {
                fungeContext.PushToTopStack(int.Parse(Name.ToString(), System.Globalization.NumberStyles.HexNumber));
            }
            catch
            {
                fungeContext.PushToTopStack(Name);
            }

            return(null);
        }
Exemplo n.º 7
0
        protected override string RealExecute(FungeContext fungeContext)
        {
            var values = fungeContext.GetTopStackTopValues(2);

            try
            {
                fungeContext.PushToTopStack(_func(values[1], values[0]));
            }
            catch (DivideByZeroException)
            {
                fungeContext.PushToTopStack(0);
                return("Divided by zero!");
            }

            return(null);
        }
Exemplo n.º 8
0
        protected override string RealExecute(FungeContext fungeContext)
        {
            fungeContext.MoveOnce();
            var fetched = fungeContext.GetCurrentCommandName();

            fungeContext.PushToTopStack(fetched);
            return(null);
        }
Exemplo n.º 9
0
        public string RealExecute(FungeContext fungeContext)
        {
            fungeContext.MoveCurrentThread();
            var fetched = fungeContext.GetCellValue(fungeContext.CurrentThread.CurrentPosition);

            fungeContext.PushToTopStack(fetched);
            return(null);
        }
Exemplo n.º 10
0
        public string RealExecute(FungeContext fungeContext)
        {
            //todo
            var value  = fungeContext.GetTopStackTopValues(1)[0];
            var values = Enumerable.Repeat(GetFlagsInfo(fungeContext.Settings), 1)
                         .Append(sizeof(int))
                         .Append(FungeContext.HandPrint.Aggregate(0, (cur, c) => cur * 5 + c))
                         .Append(FungeContext.NumericVersion)
                         .Append(1) //use system();
                         .Append(Path.DirectorySeparatorChar)
                         .Append(fungeContext.Dimension)
                         .Append(fungeContext.CurrentThread.Id)
                         .Append(0) //teamId not supported
                         .Concat(fungeContext.CurrentThread.CurrentPosition.Coords(fungeContext.Dimension).Reverse())
                         .Concat(fungeContext.CurrentThreadDeltaVector.Coords(fungeContext.Dimension).Reverse())
                         .Concat(fungeContext.CurrentThread.StorageOffset.Coords(fungeContext.Dimension).Reverse())
                         .Concat(fungeContext.GetLeastPoint().Coords(fungeContext.Dimension).Reverse())
                         .Concat(fungeContext.GetGreatestPoint().Coords(fungeContext.Dimension).Reverse())
                         .Append((DateTime.Now.Year - 1900) * 256 * 256 + DateTime.Now.Month * 256 + DateTime.Now.Day)
                         .Append(DateTime.Now.Hour * 256 * 256 + DateTime.Now.Minute * 256 + DateTime.Now.Second)
                         .Append(fungeContext.CurrentThread.Stacks.Count)
                         .Concat(fungeContext.CurrentThread.Stacks.Select(s => s.Count).Reverse()).ToArray();

            if (value > 0)
            {
                if (value > values.Length)
                {
                    fungeContext.PushToTopStack(values[value - values.Length - 1]);
                }
                else
                {
                    fungeContext.PushToTopStack(values[value - 1]);
                }
            }
            else
            {
                foreach (var i in values.Reverse())
                {
                    fungeContext.PushToTopStack(i);
                }
            }


            return(null);
        }
Exemplo n.º 11
0
 protected override string RealExecute(FungeContext fungeContext)
 {
     if (!int.TryParse(_reader.ReadLine(), out var value))
     {
         return("Can't parse Integer from user input!");
     }
     fungeContext.PushToTopStack(value);
     return(null);
 }
Exemplo n.º 12
0
        public string RealExecute(FungeContext fungeContext)
        {
            var coords = fungeContext.GetTopStackTopValues(fungeContext.Dimension);
            var value  = fungeContext.GetCellValue(new DeltaVector(coords.Reverse().ToArray()) +
                                                   fungeContext.CurrentThread.StorageOffset);

            fungeContext.PushToTopStack(value);
            return(null);
        }
Exemplo n.º 13
0
 protected override string RealExecute(FungeContext fungeContext)
 {
     fungeContext.PushToTopStack(int.Parse(Name.ToString(), System.Globalization.NumberStyles.HexNumber));
     return(null);
 }
Exemplo n.º 14
0
 protected override string RealExecute(FungeContext fungeContext)
 {
     fungeContext.PushToTopStack(_reader.Read());
     return(null);
 }
Exemplo n.º 15
0
        public string RealExecute(FungeContext fungeContext)
        {
            var filename = fungeContext.PopString();
            var flag     = fungeContext.GetTopStackTopValues(1)[0];
            var vec      = new DeltaVector(fungeContext.GetTopStackTopValues(fungeContext.Dimension).Reverse().ToArray());

            if (!File.Exists(filename))
            {
                fungeContext.CurrentThreadDeltaVector = fungeContext.CurrentThreadDeltaVector.Reflect();
                return(null);
            }

            var y    = 0;
            int maxX = 0;

            if ((flag & 1) == 1)
            {
                using var fs     = File.OpenRead(filename);
                using var reader = new BinaryReader(fs);
                var target = vec + fungeContext.CurrentThread.StorageOffset;
                while (reader.BaseStream.Position != reader.BaseStream.Length)
                {
                    var c = reader.Read();
                    fungeContext.ModifyCell(target, c);
                    target.X += 1;
                }

                maxX = (int)(reader.BaseStream.Length + fungeContext.CurrentThread.StorageOffset.X);
            }
            else
            {
                foreach (var line in File.ReadLines(filename))
                {
                    for (var x = 0; x < line.Length; x++)
                    {
                        if (line[x] == ' ' || line[x] == '\f')
                        {
                            continue;
                        }
                        fungeContext.ModifyCell(
                            new DeltaVector(x, y, 0) + vec + fungeContext.CurrentThread.StorageOffset, line[x]);
                    }

                    if (line.Length > maxX)
                    {
                        maxX = line.Length;
                    }

                    y++;
                }
            }


            fungeContext.PushToTopStack(maxX);
            fungeContext.PushToTopStack(y);
            foreach (var c in vec.Coords(fungeContext.Dimension))
            {
                fungeContext.PushToTopStack(c);
            }

            return(null);
        }
Exemplo n.º 16
0
 public string RealExecute(FungeContext fungeContext)
 {
     fungeContext.PushToTopStack(_reader.Read());
     return(null);
 }