Esempio n. 1
0
 public override void Do(RamMachineCommand command, IRamMachine ram)
 {
     RamMachineHelper.DoWithDeepLv(command.Argument, (ramEl, val) =>
     {
         ramEl.Set(0, func(ramEl.Get(0), val));
     }, ram);
 }
Esempio n. 2
0
 public override void Do(RamMachineCommand command, IRamMachine ram)
 {
     if (func(ram.Get(0)))
     {
         ram.Jump(command.Argument);
     }
 }
Esempio n. 3
0
            public override void Do(RamMachineCommand command, IRamMachine ram)
            {
                var splited = RamMachineHelper.SplitToPreArgument(command.Argument);
                int val     = int.Parse(splited.argument);

                switch (splited.pre)
                {
                case null: ram.Set(val, ram.Get(0)); break;

                case '*': ram.Set((int)ram.Get((int)val), ram.Get(0)); break;
                }
            }
        public static void Invoke(RamMachineCommand command, IRamMachine ram)
        {
            if (ram is null)
            {
                throw new ArgumentNullException(nameof(ram));
            }

            try
            {
                if (command.Type.EndsWith(":"))
                {
                    labelCommand.Do(command, ram);
                }
                else
                {
                    commands[command.Type].Do(command, ram);
                }
            }

            catch (Exception exception) when(!(exception is RamMachineRuntimeException))
            {
                throw new RamMachineRuntimeException(command.Line, $"Unexpected exception had occured during runtime ({command})", exception);
            }
        }
Esempio n. 5
0
 public abstract void Do(RamMachineCommand command, IRamMachine ram);
Esempio n. 6
0
 public override void Do(RamMachineCommand command, IRamMachine ram)
 {
     RamMachineHelper.DoWithDeepLv(command.Argument, (ramEl, val) => ramEl.Write(val), ram);
 }
Esempio n. 7
0
 public override void Do(RamMachineCommand command, IRamMachine ram)
 {
     ram.PushLabel(command.Type.Substring(0, command.Type.Length - 1));
 }
Esempio n. 8
0
 public override void Do(RamMachineCommand command, IRamMachine ram)
 {
     ram.Jump(command.Argument);
 }
Esempio n. 9
0
 public override void Do(RamMachineCommand command, IRamMachine ram)
 {
     ram.Halt();
 }