Ejemplo n.º 1
0
        private void ResetAndLoadButton_Click(object sender, EventArgs e)
        {
            try
            {
                _vm       = new StackVirtualMachine(LogToOutput);
                _vm.State = SVMSStates.Idle;
                var assembler = new SVMAssembler();
                var program   = assembler.Assemble(CodeInput.Text);

                _vm.Load(program);

                _vmBackgroundThread         = new BackgroundWorker();
                _vmBackgroundThread.DoWork += (o, args) =>
                {
                    _vm.Start();
                };
                _vmBackgroundThread.RunWorkerAsync();

                LogToOutput("Loaded. VM Running in idle state");
            }
            catch (Exception ex)
            {
                if (ex.GetType() == typeof(AssemblerSyntaxErrorException))
                {
                    LogToOutput(ex.Message);
                }
                else
                {
                    LogToOutput(ex.ToString());
                }
            }
        }
Ejemplo n.º 2
0
        private void Run(string input)
        {
            byte[] buffer;
            using (var fs = new FileStream(input, FileMode.Open, FileAccess.Read))
            {
                buffer = new byte[fs.Length];
                fs.Seek(0, SeekOrigin.Begin);
                fs.Read(buffer, 0, input.Length);
            }

            var vm = new StackVirtualMachine(_errorCallback);

            vm.Load(buffer);
            vm.Start();
        }
        public void DebugErrorCallback()
        {
            string debugMsg = null;

            var vm = new StackVirtualMachine((string msg) =>
            {
                debugMsg = msg;
            });

            LoadVM(new object[]
            {
                0x12345678u
            }, vm);

            try
            {
                vm.Start();
            }
            finally
            {
                Assert.IsNotNull(debugMsg);
            }
        }
Ejemplo n.º 4
0
 protected StackVirtualMachine LoadVM(object[] instructions, StackVirtualMachine vm = null)
 {
     vm = vm ?? new StackVirtualMachine();
     vm.Load(instructions.Select(o => Convert.ToUInt32(o)).ToArray());
     return(vm);
 }