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; }
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); }
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); } }
public virtual void Execute(Stack s) { }
public override void Execute(Stack s) { s.Push(_t, _value); }
public void reset() { Stack = new Stack(); Pc.Pc = -1; }
public Environment() { Stack = new Stack(); Pc.Pc = -1; }
public virtual CodeOp Parse(string args, Stack s) { return null; }
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)); }
public void reset() { _pc = 0; _s = new Stack(); }
Stack _s; // pile #endregion Fields #region Constructors // initialisation public Controleur() { _pc = 0; _s = new Stack(); _compilator = new Compilator(); }