/// <summary> /// Execute this script. /// </summary> /// <param name="r">The current memory.</param> /// <param name="args">The arguments.</param> /// <returns>The resulting return.</returns> public object Execute(RAM r, object[] args) { if (args.Length != ArgCount) { throw new ArgumentException(); } r.PushNewLocalMemory(); var i = 0; foreach (var a in args) { var farg = r.GetValue(a); if (float.TryParse(farg.ToString(), out float f)) { r.SetLocal(_ArgNames[i++], f); } else { r.SetLocal(_ArgNames[i++], farg); } } var obj = BrackInterpreter.Execute(r, _Brack); r.RemoveLastLocalMemory(); return(obj); }
/// <summary> /// Check arguments to be valid for execution. /// </summary> /// <param name="r">The current memory.</param> /// <param name="args">The arguments.</param> /// <returns>The calculated arguments.</returns> protected object[] CheckArgs(RAM r, object[] args) { try { if (args.Length != ArgCount) { throw new ArgumentException(); } var ret = new object[ArgCount]; var i = 0; foreach (var a in args) { if (a is object[] && !(((object[])_Types)[i] is object[][])) { ret[i++] = r.GetValue(a); } else { ret[i++] = a; } } return(ret); } #pragma warning disable CS0168 // Variable is declared but never used catch (InvalidCastException e) #pragma warning restore CS0168 // Variable is declared but never used { throw new ArgumentException(); } }
/// <summary> /// Execute this BrackOperator. /// </summary> /// <param name="r">The current memory.</param> /// <param name="args">The arguments to pass in.</param> /// <returns>The return of this operation.</returns> public override object Execute(RAM r, object[] args) { try { var f = new T[args.Length]; int i = 0; foreach (var a in args) { if (a is object[]) { f[i++] = (T)r.GetValue(a); } else { f[i++] = (T)a; } } return(((BrackParamDelegate <T>)_BrackDelegate)(r, f)); } #pragma warning disable CS0168 // Variable is declared but never used catch (InvalidCastException e) #pragma warning restore CS0168 // Variable is declared but never used { throw new ArgumentException(); } }
/// <summary> /// Execute the given raw Brack statement. /// </summary> /// <param name="r">The current RAM.</param> /// <param name="brack">The raw Brack statement.</param> /// <returns>The returned result of this execution.</returns> public static object Execute(RAM r, object[] brack) { var obj = r.GetValue(brack); if (obj is Return || obj is bool || obj is FlowControl) { return(obj); } return(null); }
/// <summary> /// Overloaded Constructor /// </summary> /// <param name="r">The current memory.</param> /// <param name="brack">The brack statements.</param> /// <param name="argNames">The arguments.</param> public Script(RAM r, object[][] brack, object[] argNames) { _Brack = brack; _ArgNames = new string[argNames.Length]; int i = 0; foreach (var a in argNames) { _ArgNames[i++] = r.GetValue(a).ToString(); } }
/// <summary> /// Get the argument name of the given index. /// </summary> /// <param name="r">The current memory.</param> /// <param name="index">The index of the argument to get (nested Brack statements execute).</param> /// <returns>The name of the argument.</returns> public string GetArgName(RAM r, object index) { try { return(GetArgName(Convert.ToInt32(r.GetValue(index)))); } #pragma warning disable CS0168 // Variable is declared but never used catch (Exception e) #pragma warning restore CS0168 // Variable is declared but never used { throw new ArgumentException(); } }
/// <summary> /// Does a localvar exist with the given name? /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="varName">The name of the localvars to check for (nested brack operations execute).</param> /// <returns>If a localvars exists with the given name.</returns> public bool HasLocal(RAM r, object varName) { return(HasLocal(r.GetValue(varName).ToString())); }
/// <summary> /// Delete the localvar with the given name from memory (with garbage collection). /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="varName">The name of the localvar to delete (nested brack operations execute).</param> public void DeleteLocal(RAM r, object varName) { DeleteLocal(r.GetValue(varName).ToString()); }
/// <summary> /// Get the value of the localvar with the given name. /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="varName">The name of the localvar to get from (nested brack operations execute).</param> /// <returns>The value found in the localvar with the given name.</returns> public object GetLocal(RAM r, object varName) { return(GetLocal(r.GetValue(varName).ToString())); }
/// <summary> /// Set the localvar with the given name to have the given value, and declare a localvar with the given name if none exist already. /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="varName">The name of the localvar to check for (nested brack operations execute).</param> /// <param name="value">The value to store in the localvars.</param> /// <returns>If a localvar exists with the given name.</returns> public void SetLocal(RAM r, object varName, object value) { SetLocal(r.GetValue(varName).ToString(), value); }
/// <summary> /// Set the Script with the given name to have the given value, and declare a Script with the given name if none exist already. /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="scriptName">The name of the Script to check for (nested brack operations execute).</param> /// <param name="script">The Script to add.</param> /// <returns>If a Script exists with the given name.</returns> public void SetScript(RAM r, object scriptName, Script script) { SetScript(r.GetValue(scriptName).ToString(), script); }
/// <summary> /// Execute an Operator with the given name and arguments. /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="opName">The name of the Operator to execute.</param> /// <param name="args">The arguments to pass into the Operator (nested brack operations execute).</param> /// <returns>The resulting return of the Operator execution.</returns> public object ExecuteOperator(RAM r, object opName, object[] args) { return(ExecuteOperator(r, r.GetValue(opName).ToString().ToLower(), args)); }
static void Main(string[] args) { ///Flag for application threads Control ThreadFlagWrapper flag = new ThreadFlagWrapper(); flag.Flag = true; Clock clock = new Clock(flag); CCAction cc = new CCAction(flag, clock); CCInterconection interconection = new CCInterconection(flag, clock); MemoryBus mainBus = new MemoryBus(flag, clock); RAM ram = new RAM(flag, clock, mainBus); mainBus.RequestBus(Constants.CORE_ZERO_ID, "0000", Constants.CC_WRITE, 5); //TODO Agregar el main bus a los controladores de cache y a la RAM CacheController cacheControler0 = new CacheController(Constants.CORE_ZERO_ID, 0, cc, interconection, flag, clock, mainBus); CacheController cacheControler1 = new CacheController(Constants.CORE_ONE_ID, 1, cc, interconection, flag, clock, mainBus); CacheController cacheControler2 = new CacheController(Constants.CORE_TWO_ID, 2, cc, interconection, flag, clock, mainBus); CacheController cacheControler3 = new CacheController(Constants.CORE_THREE_ID, 3, cc, interconection, flag, clock, mainBus); Console.WriteLine("--------------------------------------"); Console.WriteLine("Prueba 1: Coherencia de Cache \n"); string Test1Addres = "0000"; int position = Convert.ToInt32(Test1Addres, 2) % 2; cacheControler0.SaveCacheValue(Test1Addres, 1); Console.WriteLine("Se escribe en cache del core 0: " + "Dirección = " + Test1Addres + " Valor = " + 1); cacheControler1.SaveCacheValue(Test1Addres, 2); Console.WriteLine("Se escribe en cache del core 1: " + "Dirección = " + Test1Addres + " Valor = " + 2); cacheControler2.SaveCacheValue(Test1Addres, 3); Console.WriteLine("Se escribe en cache del core 2: " + "Dirección = " + Test1Addres + " Valor = " + 3); cacheControler3.SaveCacheValue(Test1Addres, 4); Console.WriteLine("Se escribe en cache del core 3: " + "Dirección = " + Test1Addres + " Valor = " + 4); Console.WriteLine(); Console.WriteLine("Resultados"); Console.WriteLine("Cache Core 0: " + "Position = " + position + " Tag = " + cacheControler0.cache.memoryCache[position].Tag + " Value = " + cacheControler0.cache.memoryCache[position].Value + " State = " + cacheControler0.cache.memoryCache[position].State); Console.WriteLine("Cache Core 1: " + "Position = " + position + " Tag = " + cacheControler1.cache.memoryCache[position].Tag + " Value = " + cacheControler1.cache.memoryCache[position].Value + " State = " + cacheControler1.cache.memoryCache[position].State); Console.WriteLine("Cache Core 2: " + "Position = " + position + " Tag = " + cacheControler2.cache.memoryCache[position].Tag + " Value = " + cacheControler2.cache.memoryCache[position].Value + " State = " + cacheControler2.cache.memoryCache[position].State); Console.WriteLine("Cache Core 3: " + "Position = " + position + " Tag = " + cacheControler3.cache.memoryCache[position].Tag + " Value = " + cacheControler3.cache.memoryCache[position].Value + " State = " + cacheControler3.cache.memoryCache[position].State); Console.WriteLine("-------------------------------------- \n"); Console.WriteLine("Prueba 2: Coherencia de Cache - Correspondencia de Cache \n"); Test1Addres = "1000"; position = Convert.ToInt32(Test1Addres, 2) % 2; Console.WriteLine("Se escribe en cache del core 3: " + "Dirección = 0x" + Test1Addres + " Valor = " + 10); Console.WriteLine("Memoria RAM: " + "Dirección: 0x0000" + " Valor: " + ram.GetValue("0000")); cacheControler3.SaveCacheValue(Test1Addres, 10); Console.WriteLine(); Console.WriteLine("Resultados \n"); Console.WriteLine("Cache Core 3: " + "Position = " + position + " Tag = " + cacheControler3.cache.memoryCache[position].Tag + " Value = " + cacheControler3.cache.memoryCache[position].Value + " State = " + cacheControler3.cache.memoryCache[position].State); Console.WriteLine("Memoria RAM: " + "Dirección: 0x0000" + " Valor: " + ram.GetValue("0000")); Thread.Sleep(1000); Console.WriteLine("-------------------------------------- \n"); Console.WriteLine("Prueba 3: Red de Interconexión \n"); Test1Addres = "1000"; position = Convert.ToInt32(Test1Addres, 2) % 2; Console.WriteLine("CORE ZERO Se solciita la direcicón 0x" + Test1Addres); cacheControler0.GetCacheValue("1000"); Console.WriteLine("Resultados \n"); Console.WriteLine("Cache Core 0: " + "Position = " + position + " Tag = " + cacheControler0.cache.memoryCache[position].Tag + " Value = " + cacheControler0.cache.memoryCache[position].Value + " State = " + cacheControler0.cache.memoryCache[position].State); Console.WriteLine("Cache Core 3: " + "Position = " + position + " Tag = " + cacheControler3.cache.memoryCache[position].Tag + " Value = " + cacheControler3.cache.memoryCache[position].Value + " State = " + cacheControler3.cache.memoryCache[position].State); int a = 5; }
/// <summary> /// Execute a Script. /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="scriptName">The Script name.</param> /// <param name="args">The arguments.</param> /// <returns>The resulting return.</returns> public object ExecuteScript(RAM r, object scriptName, object[] args) { return(ExecuteScript(r, r.GetValue(scriptName), args)); }
/// <summary> /// Get the names of the arguments of the given Script from this GlobalMemory. /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="scriptName">The name of the Script (nested operators are executed).</param> /// <returns>The argument names</returns> public string[] GetScriptArguments(RAM r, object scriptName) { return(GetScriptArguments(r.GetValue(scriptName).ToString())); }
/// <summary> /// Delete the Script with the given name from memory (with garbage collection). /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="scriptName">The name of the Script to delete (nested brack operations execute).</param> public void DeleteScript(RAM r, object scriptName) { DeleteScript(r.GetValue(scriptName).ToString()); }
/// <summary> /// Get the Script with the given name. /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="scriptName">The name of the Script to get from (nested brack operations execute).</param> /// <returns>The Script found with the given name.</returns> public Script GetScript(RAM r, object scriptName) { return(GetScript(r.GetValue(scriptName).ToString())); }
/// <summary> /// Does an Operator exist with the given name? /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="opName">The name of the Operator to look for (nested brack operations execute).</param> /// <returns></returns> public bool HasOpName(RAM r, object opName) { return(HasOpName(r.GetValue(opName).ToString())); }
/// <summary> /// Does a Script exist with the given name? /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="scriptName">The name of the Script to check for (nested brack operations execute).</param> /// <returns>If a Script exists with the given name.</returns> public bool HasScript(RAM r, object scriptName) { return(HasScript(r.GetValue(scriptName).ToString())); }