Exemplo n.º 1
0
 public int CreateVariable(uint addr, uint size, bool isCode)
 {
     Variable var = new Variable()
     {
         Data = addr,
         Size = size,
         IsCode = isCode
     };
     int i;
     for (i = 0; i < Vars.Count; i++)
     {
         if (Vars[i].Data == 0)
         {
             Vars[i] = var;
             return i;
         }
     }
     Vars.Add(var);
     Console.Error.WriteLine("${0} = 0x{1:X}", i, addr);
     return i;
 }
Exemplo n.º 2
0
        public static Variable ToVariable(this string self, Device vita)
        {
            Variable v = Variable.Null;
            string[] parts = self.Split(new char[] { '+', '-' }, 2);
            long offset = 0;
            if (parts.Length > 1)
            {
                offset = parts[1].ToInteger();
                if (self.Contains("-"))
                {
                    offset = -offset;
                }
                self = parts[0];
            }
            if (!string.IsNullOrEmpty(self))
            {
                switch (self[0])
                {
                    case '$':
                        {
                            int idx;
                            if (Int32.TryParse(self.Substring(1), out idx) && vita.Vars.Count > idx)
                            {
                                v = vita.Vars[idx];
                                v.Data = (uint)(v.Data + offset);
                                v.Size = (uint)(v.Size - offset);
                            }
                            break;
                        }
                    case '%':
                        {
                            v = new Variable();
                            v.Size = 0;
                            v.IsCode = false;
                            if (self.Length > 1 && self[1] == '#')
                            {
                                v.Data = vita.LastReturn;
                            }
                            else if (vita.Locals.ContainsKey(self.Substring(1)))
                            {
                                v.Data = vita.Locals[self.Substring(1)];
                            }
                            else
                            {
                                Console.Error.WriteLine("Invalid variable {0}", self.Substring(1));
                            }
                            v.Data = (uint)(v.Data + offset);
                            break;
                        }
                    default:
                        {
                            v = new Variable();
                            v.Data = self.ToInteger();
                            v.Size = 0;
                            break;
                        }

                }
            }
            #if DEBUG
            Console.Error.WriteLine("Parsed '{0}' to '0x{1:X}' with size {2}", self, v.Data, v.Size);
            #endif
            return v;
        }
Exemplo n.º 3
0
 public int DeleteVariable(Variable var)
 {
     for (int i = 0; i < Vars.Count; i++)
     {
         if (Vars[i].Data == var.Data)
         {
             Vars[i] = Variable.Null;
     #if DEBUG
             Console.Error.WriteLine("Deleted variable ${0}", i);
     #endif
         }
     }
     return 0;
 }