Exemplo n.º 1
0
        void RunEnd(IOStream iostream, RuntimeMachine runtime, HASMSource source)
        {
            if (InvokeRequired)
            {
                Invoke(new RunEndDelegate(RunEnd), iostream, runtime, source);
            }
            else
            {
                if (runtime == null || source == null)
                {
                    toolStripLabel1.Text = "Run aborted";
                    Output = null;
                }
                else
                {
                    Output = iostream.ReadAll();
                    int size = 0;                    //source.ParseResult.Sum(p => p.FixedSize);
                    toolStripLabel1.Text =
                        $"Parsed in: {Formatter.ToPrettyFormat(source.ParseTime)}" +
                        $" | Byte code size: {size} {(HASMBase.IsSTD ? "byte" : "fbn")}{(size == 1 ? "" : "s")}" +
                        $" | Run in: {Formatter.ToPrettyFormat(runtime.TimeOfRunning)} or {runtime.Ticks} step{(runtime.Ticks == 1 ? "" : "s")}" +
                        $" | Result is: {Output.Count} {(HASMBase.IsSTD ? "byte" : "fbn")}{(Output.Count == 1 ? "" : "s")}";
                }


                OutputToTextBox();
                loadingCircle1.Visible        = false;
                stopToolStripMenuItem.Enabled = false;
                tabControl1.Enabled           = true;

                (tabControl1.SelectedTab as TextEditor)?.TextBox.Focus();
            }
        }
Exemplo n.º 2
0
 public void RuntimeMachineJump(Integer position, RuntimeMachine runtimeMachine)
 {
     throw new System.NotImplementedException();
     //TODO
     //var localIndex = position;
     //var globalIndex = runtimeMachine.GetGlobalInstructionIndexByLocalOne(localIndex);
     //runtimeMachine.ProgramCounter = globalIndex - (Integer)1;
 }
Exemplo n.º 3
0
        public RuntimeMachine CreateRuntimeMachine(HASMSource source, List <IOStream> streams = null)
        {
            var rm = new RuntimeMachine(this, source);

            MemZone.Clear();
            //MemZone.Flash = source.ParseResult;

            if (streams != null)
            {
                foreach (var stream in streams)
                {
                    stream.Init(rm);
                }
            }

            return(rm);
        }
Exemplo n.º 4
0
        /// <summary>
        /// This function executes the scalar variable, works together with GetVariable. It will also parse the inherited
        /// codebase.
        /// </summary>
        /// <param name="Variable"></param>
        /// <param name="reflector">Reflector divides which is the conditinoal statement and the boolean output</param>
        /// <param name="divider">Boolean divider</param>
        /// <param name="vetero">Which variable beside the reflector divider should be present in fallback</param>
        /// <value>Returns an 2 field String array where {InitialVariableName,Output}</value>
        /// <returns></returns>
        public String[] ExecuteScalarVariable(String Variable, char reflector, char divider, bool vetero)
        {
            // An variable in this instruction {boolVar} : return1 | return 2
            if (Variable.Contains(reflector) && Variable.Contains(divider))
            {
                // Get the codebase
                String Codebase = Variable.Split(reflector)[0];

                // Run the codebase
                object d = RuntimeMachine.RunCode(Codebase)[0];

                // If it are an boolean decide it, otherwise return the left/right variable as fallback decided by the vetero varialbe
                if (d.GetType() == typeof(bool))
                {
                    // Get the two case output
                    String[] c = Variable.Split(reflector)[1].Split(divider);

                    // Return the decition
                    String output = (bool)d ? c[0] : c[1];
                    return(new String[] { Codebase, output });
                }
                else
                {
                    String[] c = Variable.Split(reflector)[1].Split(divider);

                    // Return the case fallback
                    String output = vetero ? c[0] : c[1];
                    return(new String[] { Codebase, output });
                }
            }

            /**
             * Otherwise return the value of the variable asserted by the current state of the execution instance
             * */

            // Output data
            object _output = RuntimeMachine.RunCode("return " + Variable + ";");

            if (_output.GetType() == typeof(String))
            {
                return(new String[] { Variable, (String)_output });
            }

            return(new String[] { Variable, Variable });
        }