public dynamic ExecuteMethod(StructModule cls, string func, dynamic[] pars) { foreach (var f in cls.Methods) { if (f.FuncName == func) { if (pars != null) { if (f.Pars.Pars.Count != pars.Length) { continue; } } else { if (f.Pars != null) { if (f.Pars.Pars.Count != 0) { continue; } } } int ii = 0; var ns = new CodeScope("func_pars"); if (pars != null) { foreach (var p in pars) { var rp = f.Pars.Pars[ii]; ns.RegisterVar(rp); rp.Value = p; ii++; } } PushScope(SystemScope); PushScope(cls.InstanceScope); PushScope(ns); return(f.Code.Exec()); PopScope(); PopScope(); PopScope(); return(null); } } return(null); }
public StructModule ParseModule(ref int i) { Log("Begun parsing module", i); Console.WriteLine("Parsing Module:" + Peek(i + 1).Text); var name = Peek(i + 1).Text; i = i + 2; var mod = new StructModule(); mod.ModuleName = name; for (i = i; i < toks.Len; i++) { var mtok = toks.Tokes[i]; switch (mtok.Token) { case Token.End: return(mod); break; case Token.Func: var func = ParseFunc(ref i); if (func.Static) { mod.StaticFuncs.Add(func); } else { mod.Methods.Add(func); } break; case Token.Var: i++; while (true) { var t = Get(i); if (t.Text == ",") { i++; continue; } if (t.Text == ";") { break; } var nv = new Var(); nv.Name = t.Text; nv.Value = 0; mod.Vars.Add(nv); i++; if (Get(i).Text == "=") { i++; nv.Init = ParseExp(ref i); } } break; } } return(null); }