public bool Run(GcMachine m, string[] param) { if (m.GetLocalIDByName(param[1]) == -1) { System.Console.WriteLine("Local varible " + param[1] + "do not exist."); } else { Varible v = m.GetLocalByID(m.GetLocalIDByName(param[1])); string st = "Local varible " + param[1] + ":"; if (v.type == VarType.TYPE_NUMBER) { st += v.num.ToString(); } else if (v.type == VarType.TYPE_STRING) { st = st + "\"" + m.GetString(v.pointer).Replace("\n", "").Replace("\r", "") + "\""; } else { st += "(function)"; } System.Console.WriteLine(st); } return(false); }
public bool Run(GcMachine m, string[] param) { List <StackInfo> L = m.GetCallStack(); foreach (StackInfo s in L) { string st = s.funcName + " (Line" + s.line + "): ("; foreach (Varible v in s.parmList) { if (v.type == VarType.TYPE_NUMBER) { st += v.num.ToString(); } else if (v.type == VarType.TYPE_STRING) { st = st + "\"" + m.GetString(v.pointer).Replace("\n", "").Replace("\r", "") + "\""; } else { st += "(function)"; } st = st + ","; } st += ")"; System.Console.WriteLine(st); } return(false); }
public bool Run(GcMachine m, string[] param) { if (!m.IsGlobalExists(param[1])) { System.Console.WriteLine("Varible " + param[1] + "has not been initialized yet."); } else { Varible v = m.GetGlobal(param[1]); string st = "Varible " + param[1] + ":"; if (v.type == VarType.TYPE_NUMBER) { st += v.num.ToString(); } else if (v.type == VarType.TYPE_STRING) { st = st + "\"" + m.GetString(v.pointer).Replace("\n", "").Replace("\r", "") + "\""; } else { st += "(function)"; } System.Console.WriteLine(st); } return(false); }
public Varible invoke(GcMachine m, int numParams) //Note that the interface has changed { Varible v; for (int i = 1; i <= numParams; ++i) //param have ID from 1 to numParams(possibly 0) { v = m.GetLocalByID(i); //How to access each param, do not specify ID less than 1 or greater than numParams if (v.type == VarType.TYPE_NUMBER) { System.Console.Write(v.num.ToString()); //How to access number } else if (v.type == VarType.TYPE_STRING) { System.Console.Write(m.GetString(v.pointer)); //For string ,you must use getString method to convert a string-pointer to actual string } else { throw new RuntimeException("Type mismatch"); //You can throw any runtime exception too. } } System.Console.Write("\n"); return(new Varible(0.0)); //You can return any number here. }