Example #1
0
        private void Setter(string destination, string to_move)
        {
            var dest = DestinationSelecter.IsCommand(destination);

            if (dest == SelfLanguageDestination.Ram)
            {
                var dst   = destination.Split(':');
                var name  = dst.ElementAtOrDefault(1);
                var value = dst.ElementAtOrDefault(2);
                var type  = dst.ElementAtOrDefault(3);
                HandleToRam(string.Concat(name, ":", to_move, ":", type));
            }
            else if (dest == SelfLanguageDestination.Stack)
            {
                CommandStackCarry.Push(Convert.ToInt32(to_move));
            }
            else if (dest == SelfLanguageDestination.StackMultiChar)
            {
                to_move.ToList().ForEach((s) => CommandStackCarry.Push(Convert.ToInt32(s)));
            }
            else if (dest == SelfLanguageDestination.Number)
            {
                LoadInMemory(to_move, Convert.ToInt32(destination));
            }
            else if (dest == SelfLanguageDestination.None)
            {
                throw new InvalidMoveException(string.Format("The destination {0} is not well formed", destination));
            }
            else
            {
                throw new NotImplementedException(); //HTF
            }
        }
Example #2
0
        private string Getter(string source)
        {
            var dest = DestinationSelecter.IsCommand(source);

            if (dest == SelfLanguageDestination.Ram)   //is a Ram source
            {
                return(HandleFromRam(source));
            }
            else if (dest == SelfLanguageDestination.Here)     //TODO
            {
                return(source.Replace("^", ""));
            }
            else if (dest == SelfLanguageDestination.Stack)     //Could be buggy cause of a R containing a -? keep the order this way
            {
                return(Convert.ToString(CommandStackCarry.Pop()));
            }
            else if (dest == SelfLanguageDestination.Number)
            {
                return(HandleFromMemory(Convert.ToInt32(source)));
            }
            else if (dest == SelfLanguageDestination.Compare)
            {
                return(Convert.ToString(Compare(source)));
            }
            else if (dest == SelfLanguageDestination.None)
            {
                throw new InvalidGetterException(string.Format("The get operation with the > {0} < source is not valid", source));
            }
            else
            {
                throw new NotImplementedException(); //HTF
            }
        }
Example #3
0
        /// <summary>
        /// Moves pointer to a new point, like the assembly jmp
        /// </summary>
        private void JumpCommand(int pointer)
        {
            var v = GetLitteral(pointer + 2);

            if (v.Contains(';'))
            {
                var where = Convert.ToInt32(v.Split(';').ElementAt(0));
                var condition = v.Split(';').ElementAt(1);
                if (!DestinationSelecter.IsConditionalJump(condition))
                {
                    throw new InvalidJumpException(string.Format("The condition > {0} < is not well formed", condition));
                }
                var expect   = condition.First();
                var compare  = condition.Skip(1).Select(s => Convert.ToString(s)).Aggregate((a, b) => a + b);
                var returned = Getter(compare);
                if (DestinationSelecter.JumpIntToBool(Convert.ToInt32(returned), Convert.ToString(expect)))
                {
                    _pointer = where - 1;
                }
            }
            else
            {
                _pointer = Convert.ToInt32(v) - 1;
            }
        }