예제 #1
0
        public List<CodeOpRoot> compile(string[] instructions, Stack s)
        {
            for (int i = 0; i < instructions.Length; i++ )
            {
                // retire les espace et . en trop
                string instruction = instructions[i];
                instruction.Replace(' ', '.');
                while (instruction.Contains(".."))
                {
                    instruction.Replace("..", ".");
                }

                if (instruction != "")
                {
                    // on recupére le nom de la méthode et les arguments
                    string operation = instruction.Split('.', ' ')[0];
                    if (_lib.LibIsCodeOpRootExiste(operation)) _operations.Add(_lib.LibFindOpCodeRoot(operation));
                    else
                    {
                        throw new Exception("Compilation error : line " + (i + 1).ToString() + ", instruction : \"" + operation + "\" can't be found in library");
                    }
                }
                else
                {
                    _operations.Add(null);
                }
            }
            return _operations;
        }
예제 #2
0
        public override CodeOp Parse(string args, Stack s)
        {
            Type t;

            t = s.CurrentStack[s.Count - 1].Type;

            if (t != s.CurrentStack[s.Count - 2].Type)
            {
                throw new InvalidOperationException("can't add two values using different type");
            }

            return new AddCodeOp(t);
        }
예제 #3
0
 public override void Execute(Stack s)
 {
     if (_t == typeof(Int64))
     {
         Int64 i1 = Convert.ToInt64(s.Pop().Value);
         Int64 i2 = Convert.ToInt64(s.Pop().Value);
         s.Push(_t, i1 + i2);
     }
     else if (_t == typeof(Int32))
     {
         Int32 i1 = Convert.ToInt32(s.Pop().Value);
         Int32 i2 = Convert.ToInt32(s.Pop().Value);
         s.Push(_t, i1 + i2);
     }
     else if (_t == typeof(Int16))
     {
         Int16 i1 = Convert.ToInt16(s.Pop().Value);
         Int16 i2 = Convert.ToInt16(s.Pop().Value);
         s.Push(_t, i1 + i2);
     }
 }
예제 #4
0
 public virtual void Execute(Stack s)
 {
 }
예제 #5
0
 public override void Execute(Stack s)
 {
     s.Push(_t, _value);
 }
예제 #6
0
 public void reset()
 {
     Stack = new Stack();
     Pc.Pc = -1;
 }
예제 #7
0
 public Environment()
 {
     Stack = new Stack();
     Pc.Pc = -1;
 }
예제 #8
0
 public virtual CodeOp Parse(string args, Stack s)
 {
     return null;
 }
예제 #9
0
        public override CodeOp Parse(string args, Stack s)
        {
            string[] instruction = args.Split('.');
            Type t;
            object Value;

            if (instruction[1].Equals("i8"))
            {
                t = typeof(Int64);
                Value = Convert.ToInt64(instruction[2]);
            }
            else if (instruction[1].Equals("i4"))
            {
                t = typeof(Int32);
                Value = Convert.ToInt32(instruction[2]);
            }
            else if (instruction[1].Equals("i2"))
            {
                t = typeof(Int16);
                Value = Convert.ToInt16(instruction[2]);
            }
            else
            {
                throw new Exception("lcd operation can't have first argument : " + instruction[1]);
            }

            return (new LdcCodeOp(t, Value));
        }
예제 #10
0
 public void reset()
 {
     _pc = 0;
     _s = new Stack();
 }
예제 #11
0
        Stack _s; // pile

        #endregion Fields

        #region Constructors

        // initialisation
        public Controleur()
        {
            _pc = 0;
            _s = new Stack();
            _compilator = new Compilator();
        }