Exemple #1
0
        public void Break(bool silent = false)
        {
            if (!silent && !allowControlCBreak)
            {
                return;
            }

            // grab the full stack and tuck it away for future reference
            ValList stack = M1API.StackList(interpreter.vm);

            // also find the first non-null entry, to display right away
            SourceLoc loc = null;

            if (interpreter.vm != null)
            {
                foreach (var stackLoc in interpreter.vm.GetStack())
                {
                    loc = stackLoc;
                    if (loc != null)
                    {
                        break;
                    }
                }
            }
            interpreter.Stop();
            console.AbortInput();
            console.keyBuffer.Clear();
            if (!silent)
            {
                string msg = "BREAK";
                if (loc != null)
                {
                    msg += " at ";
                    if (loc.context != null)
                    {
                        msg += loc.context + " ";
                    }
                    msg += "line " + loc.lineNum;
                }
                textDisplay.Print(msg + "\n");
                //Debug.Log("printed: " + msg);
            }
            ValMap globals = interpreter.vm.globalContext.variables;

            interpreter.Reset();
            interpreter.REPL("");               // (forces creation of a VM)
            interpreter.vm.globalContext.variables = globals;
            globals.SetElem(M1API._stackAtBreak, stack);
            AddGlobals();
            //Debug.Log("Rebuilt VM and restored " + globals.Count + " globals");
        }
Exemple #2
0
        public void Init(Bot botContext = null)
        {
            this.bot = botContext;
            M1API.Init(this);

            var display = console.display;

            display.backColor = new Color(0.31f, 0.11f, 0.86f);
            display.Clear();

            var colors = new Color[] { Color.Red, Color.Yellow, Color.Green, Color.Purple };

            display.SetCursor(19, 3);
            for (int i = 0; i < 4; i++)
            {
                display.textColor = colors[i]; display.Print("*");
            }
            display.textColor = Color.Azure; display.Print(" Farmtronics " + (botContext == null ? "Home" : "Bot") + " Computer ");
            for (int i = 0; i < 4; i++)
            {
                display.textColor = colors[3 - i]; display.Print("*");
            }
            display.textColor = Color.White;
            display.NextLine();

            if (interpreter.vm == null)
            {
                interpreter.REPL("", 0);                        // (forces creation of a VM)
                AddGlobals();
            }

            {
                var d = new RealFileDisk();
                d.readOnly = true;
                d.Open(Path.Combine(ModEntry.helper.DirectoryPath, "assets", "sysdisk"));
                sysDisk = d;
                FileUtils.disks["sys"] = sysDisk;
            }
            if (!string.IsNullOrEmpty(Constants.CurrentSavePath))
            {
                var d = new RealFileDisk();
                d.readOnly = false;
                d.Open(Path.Combine(Constants.CurrentSavePath, "usrdisk"));
                FileUtils.disks["usr"] = d;
            }

            // Prepare the env map
            env = new ValMap();
            if (FileUtils.disks.ContainsKey("usr") && FileUtils.disks["usr"] != null)
            {
                env["curdir"] = new ValString("/usr/");
            }
            else
            {
                env["curdir"] = new ValString("/sys/demo");
            }
            env["home"]       = new ValString("/usr/");
            env["prompt"]     = new ValString("]");
            env["morePrompt"] = new ValString("...]");

            // NOTE: importPaths is also in the reset function in startup.ms.
            // If you change this in either place, change it in both!
            var importPaths = new List <string> {
                ".", "/usr/lib", "/sys/lib"
            };

            env["importPaths"] = importPaths.ToValue();

            RunStartupScripts();
        }