Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public string RealExecute(FungeContext fungeContext)
        {
            var filename = fungeContext.PopString();
            var flag     = fungeContext.GetTopStackTopValues(1)[0];
            var va       = new DeltaVector(fungeContext.GetTopStackTopValues(fungeContext.Dimension).Reverse().ToArray()) + fungeContext.CurrentThread.StorageOffset;
            var vb       = fungeContext.GetTopStackTopValues(fungeContext.Dimension).Reverse().ToArray();

            try
            {
                using var fw = new StreamWriter(File.OpenWrite(filename));


                for (var y = va.Y; y < vb[1] + va.Y; y++)
                {
                    var line = new List <char>();
                    for (var x = va.X; x < va.X + vb[0]; x++)
                    {
                        var c = fungeContext.GetCellValue(new DeltaVector(x, y, 0));
                        line.Add((char)c);
                    }

                    var resString = new string(line.ToArray());
                    if ((flag & 1) == 1)
                    {
                        resString = resString.Trim();
                    }

                    fw.WriteLine(resString);
                }
            }
            catch
            {
                fungeContext.CurrentThreadDeltaVector = fungeContext.CurrentThreadDeltaVector.Reflect();
            }

            return(null);
        }
Ejemplo n.º 3
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);
        }