//TODO: args processing public static Object Closure(Cons symbols, LSharp.Environment environment) { string v = string.Empty; Symbol s = symbols.First() as Symbol; if (s != null) { string name = s.Name; string cname = MakeCompat(name); Closure c = Runtime.Eval(s, environment) as Closure; if (c == null) { return NewLine; } v += string.Format(@" [LSharp.Symbol(""{0}"")] public static object {1}(LSharp.Cons args, LSharp.Environment environment) {{ object retval = null; ", name, cname); currsymbols.Add(s, c); //after eval environment.AssignLocal(s, cname); Cons argnames = c.GetArgumentNames(); Cons body = c.GetBody(); if (argnames != null) { int i = 0; int al = argnames.Length(); foreach (Symbol arg in argnames) { environment.AssignLocal(arg, MakeCompat(arg.Name)); v += string.Format("object {0} = args.Car();\n", environment.GetValue(arg)); if (++i < al) { v += "args = (LSharp.Cons)args.Cdr();\n"; } } } // BODY if (body != null) { foreach (object con in body) { v += Generate(con, environment); } } // RETURN v += @" return retval; } "; } return v; }
public static string GenerateAssignLocal(Symbol s, object value, LSharp.Environment environment) { if (environment.Contains(s)) { string ns = MakeUnique(s.Name); environment.AssignLocal(s, ns); if (value is string) { return string.Format(@"{1} object {0} = retval;", ns, value) + NewLine; } else { return string.Format(@"{2} {0} = {1};", ns, value, value.GetType()) + NewLine; } } else { environment.AssignLocal(s, s.Name); if (value is string) { return string.Format(@"{1} object {0} = retval;", s.Name, value) + NewLine; } else { return string.Format(@"{2} {0} = {1};", s.Name, value, value.GetType()) + NewLine; } } }