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; } } }
public static string GenerateAssign(Symbol s, object value, LSharp.Environment environment) { if (environment.Contains(s)) { object sn = environment.GetValue(s); return string.Format(@"{1} {0} = retval;", sn, value) + NewLine; } else { environment.Assign(s, s.Name); return string.Format(@"{1} object {0} = retval;", s.Name, value) + NewLine; } }
public static string GenerateList(Cons rest, LSharp.Environment environment, string margs) { string v = string.Format(@"System.Collections.ArrayList {0} = new System.Collections.ArrayList({1}); ", margs, rest.Length()); // load args foreach (object argo in rest) { if (argo is Symbol) { Symbol sarg = (Symbol)argo; if (environment.Contains(sarg)) { v += string.Format(@"{1}.Add({0}); ", environment.GetValue(sarg), margs); } else { v += Generate(argo, environment); v += margs + @".Add(retval); "; } } else if (argo is Cons) { v += Generate(argo, environment); v += margs + @".Add(retval); "; } else { // load primitive v += string.Format(@"{1}.Add({0}); ", Printer.WriteToString(argo), margs); } } return v; }
public static string GenerateFuncCall(string type, string method, Cons rest, LSharp.Environment environment) { string v = string.Empty; string typemeth = method; if (type != null) { typemeth = type + "." + method; } if (rest == null) { return v + "retval = " + typemeth + string.Format(@"(null, environment); "); } else { if (rest.Length() == 1) { object argo = rest.First(); string argn = "retval"; if (argo is Symbol) { Symbol sarg = (Symbol)argo; if (environment.Contains(sarg)) { argn = environment.GetValue(sarg) as string; } else { v += Generate(argo, environment); } } else if (argo is Cons) { v += Generate(argo, environment); } else { // load primitive argn = Printer.WriteToString(argo); } return v + "retval = " + typemeth + string.Format(@"(new LSharp.Cons({0}), environment); ", argn); } else { string margs = GetArgs(); v += GenerateList(rest, environment, margs); return v + "retval = " + typemeth + string.Format(@"(LSharp.Cons.FromList({0}), environment); ", margs); } } }
public static string Generate(object obj, LSharp.Environment environment) { if (obj is Cons) { return GenerateCons(obj as Cons, environment); } string s = "// " + Printer.WriteToString(obj) + NewLine; if (obj is Symbol) { if (environment.Contains(obj as Symbol)) { string symn = environment.GetValue(obj as Symbol) as string; return s + "retval = " + symn + ";" + NewLine; } else { return s + "retval = " + obj + ";" + NewLine; } } else { return s + "retval = " + Printer.WriteToString(obj) + ";" + NewLine; } }