Exemple #1
0
 public static object Clone(CloneInfo info, object arg)
 {
     if (arg is ValueNode)
         return ((ValueNode) arg).Clone(info);
     else
         return arg;
 }
Exemple #2
0
 public override object Clone(CloneInfo info)
 {
     object res = Utils.Eval(info.StackFrame, Expression);
     var list = res as IEnumerable;
     var splice = new Splice(list);
     return splice;
 }
Exemple #3
0
 public override object Clone(CloneInfo info)
 {
     if (info.BackQuote)
     {
         var clone = new SymbolNode();
         BaseClone(clone);
         clone.Name = Name;
         return clone;
     }
     else
     {
         if (info.LocalIdentifiers.Contains(Name) || !info.StackFrame.Scope.ContainsSymbol(Name))
         {
             var clone = new SymbolNode();
             BaseClone(clone);
             clone.Name = Name;
             return clone;
         }
         else
         {
             var clone = new SymbolSnapshotNode();
             BaseClone(clone);
             clone.staticSymbol = new Symbol();
             clone.StaticSymbol.Value = info.StackFrame.Scope.GetSymbol(Name).Value;
             clone.Name = Name;
             return clone;
         }
     }
 }
 public override object Clone(CloneInfo info)
 {
     var clone = new SymbolSnapshotNode();
     BaseClone(clone);
     clone.staticSymbol = new Symbol();
     clone.StaticSymbol.Value = StaticSymbol.Value;
     clone.Name = Name;
     return clone;
 }
        public override object Clone(CloneInfo info)
        {
            if (info.BackQuote)
            {
                var clone = new ConsNode();
                BaseClone(clone);
                clone.Args = new List<object>(10);
                foreach (object arg in Args)
                {
                    object cloneArg = Utils.Clone(info, arg);
                    if (cloneArg is Splice)
                    {
                        var splice = cloneArg as Splice;
                        foreach (object spliceArg in splice.List)
                        {
                            object cloneSpliceArg = Utils.Clone(info, spliceArg);
                            clone.Args.Add(cloneSpliceArg);
                        }
                    }
                    else
                    {
                        clone.Args.Add(cloneArg);
                    }
                }

                return clone;
            }
            else
            {
                var clone = new ConsNode();
                BaseClone(clone);
                clone.Args = new List<object>(10);
                foreach (object arg in Args)
                {
                    object cloneArg = Utils.Clone(info, arg);
                    clone.Args.Add(cloneArg);
                }

                return clone;
            }
        }
 public abstract object Clone(CloneInfo info);
Exemple #7
0
        public static void Configure(RuntimeStack stack)
        {
            //known types
            stack.StackFrame.Scope.SetSymbolValue("Form", typeof (Form));
            stack.StackFrame.Scope.SetSymbolValue("Button", typeof (Button));
            stack.StackFrame.Scope.SetSymbolValue("int", typeof (int));
            stack.StackFrame.Scope.SetSymbolValue("big", typeof (BigInteger));
            stack.StackFrame.Scope.SetSymbolValue("long", typeof (long));
            stack.StackFrame.Scope.SetSymbolValue("bool", typeof (bool));
            stack.StackFrame.Scope.SetSymbolValue("string", typeof (string));
            stack.StackFrame.Scope.SetSymbolValue("char", typeof (char));
            stack.StackFrame.Scope.SetSymbolValue("double", typeof (double));
            stack.StackFrame.Scope.SetSymbolValue("float", typeof (float));
            stack.StackFrame.Scope.SetSymbolValue("date-time", typeof (DateTime));
            stack.StackFrame.Scope.SetSymbolValue("Console", typeof (Console));

            //atoms
            stack.StackFrame.Scope.SetSymbolValue("null", null);
            stack.StackFrame.Scope.SetSymbolValue("true", true);
            stack.StackFrame.Scope.SetSymbolValue("false", false);

            //functions
            stack.StackFrame.Scope.SetSymbolValue("progn", Functions.Progn);
            stack.StackFrame.Scope.SetSymbolValue("concat", Functions.Concat);
            stack.StackFrame.Scope.SetSymbolValue("format", Functions.Format);

            stack.StackFrame.Scope.SetSymbolValue("+", Functions.Add);
            stack.StackFrame.Scope.SetSymbolValue("-", Functions.Sub);
            stack.StackFrame.Scope.SetSymbolValue("*", Functions.Mul);
            stack.StackFrame.Scope.SetSymbolValue("/", Functions.Div);
            stack.StackFrame.Scope.SetSymbolValue("||", Functions.LogicalOr);
            stack.StackFrame.Scope.SetSymbolValue("==", Functions.Equal);
            stack.StackFrame.Scope.SetSymbolValue("!=", Functions.NotEqual);
            stack.StackFrame.Scope.SetSymbolValue("is", Functions.Is);
            stack.StackFrame.Scope.SetSymbolValue(">", Functions.GreaterThan);
            stack.StackFrame.Scope.SetSymbolValue("<", Functions.LessThan);
            stack.StackFrame.Scope.SetSymbolValue(">=", Functions.GreaterOrEqualTo);
            stack.StackFrame.Scope.SetSymbolValue("<=", Functions.LessOrEqualTo);

            stack.StackFrame.Scope.SetSymbolValue("break-debugger", Functions.BreakDebugger);
            stack.StackFrame.Scope.SetSymbolValue("if", Functions.If);
            stack.StackFrame.Scope.SetSymbolValue("#", Functions.EvalFormula);
            stack.StackFrame.Scope.SetSymbolValue("arr", Functions.Arr);
            stack.StackFrame.Scope.SetSymbolValue("list", Functions.List);
            stack.StackFrame.Scope.SetSymbolValue("hash", Functions.Hash);
            stack.StackFrame.Scope.SetSymbolValue("while", Functions.While);
            stack.StackFrame.Scope.SetSymbolValue("foreach", Functions.ForEach);
            stack.StackFrame.Scope.SetSymbolValue("defun", Functions.Defun);
            stack.StackFrame.Scope.SetSymbolValue("defmacro", Functions.Defmacro);
            stack.StackFrame.Scope.SetSymbolValue("lambda", Functions.Lambda);
            stack.StackFrame.Scope.SetSymbolValue("force", Functions.EnsureNotLazy);
            stack.StackFrame.Scope.SetSymbolValue("delay", Functions.Delay);
            stack.StackFrame.Scope.SetSymbolValue("tail", Functions.Tail);
            stack.StackFrame.Scope.SetSymbolValue("setf", Functions.Setf);
            stack.StackFrame.Scope.SetSymbolValue("let", Functions.Let);
            stack.StackFrame.Scope.SetSymbolValue("new-thread", Functions.NewThread);
            stack.StackFrame.Scope.SetSymbolValue("eval-string", Functions.EvalString);
            stack.StackFrame.Scope.SetSymbolValue("eval", Functions.EvalList);
            stack.StackFrame.Scope.SetSymbolValue("include", Functions.Include);
            stack.StackFrame.Scope.SetSymbolValue("reverse", Functions.Reverse);
            stack.StackFrame.Scope.SetSymbolValue("car", Functions.Car);
            stack.StackFrame.Scope.SetSymbolValue("cdr", Functions.Cdr);
            stack.StackFrame.Scope.SetSymbolValue("empty?", Functions.IsEmpty);
            stack.StackFrame.Scope.SetSymbolValue("cast", Functions.Cast);


            stack.StackFrame.Scope.SetSymbolValue("print", call =>
                                                           {
                                                               call.EvalArgs().ToList().ForEach(
                                                                   arg =>
                                                                   stack.Engine.OnPrint(arg == null
                                                                                            ? ""
                                                                                            : arg.ToString()));
                                                               return null;
                                                           });

            stack.StackFrame.Scope.SetSymbolValue("quote", call =>
                                                           {
                                                               var info = new CloneInfo();
                                                               info.StackFrame = call.StackFrame;
                                                               info.LocalIdentifiers = new List<string>();
                                                               info.BackQuote = true;

                                                               object expression = call.Args[1];
                                                               object clone = Utils.Clone(info, expression);
                                                               return clone;
                                                           });

            stack.StackFrame.Scope.SetSymbolValue("operator-prio", call =>
                                                                   {
                                                                       var func =
                                                                           Utils.Eval(call.StackFrame, call.Args[1]) as
                                                                           LispFunc;
                                                                       var prio =
                                                                           (int)
                                                                           Utils.Eval(call.StackFrame, call.Args[2]);

                                                                       if (prio == 0)
                                                                       {
                                                                           //remove
                                                                           stack.OperatorPriority.Remove(func);
                                                                       }
                                                                       else
                                                                       {
                                                                           stack.OperatorPriority[func] = prio;
                                                                       }

                                                                       return null;
                                                                   });


            stack.StackFrame.Scope.SetSymbolValue("input", call =>
                                                           {
                                                               var var = call.Args[1] as SymbolNode;
                                                               string res = Console.ReadLine();
                                                               var.GetSymbol(call.StackFrame).Value = res;
                                                               return null;
                                                           });

            stack.StackFrame.Scope.SetSymbolValue("new", call =>
                                                         {
                                                             var typeId = call.Args[1] as SymbolNode;
                                                             var type = typeId.GetSymbol(call.StackFrame).Value as Type;
                                                             object res = Activator.CreateInstance(type);

                                                             return res;
                                                         });

            stack.StackFrame.Scope.SetSymbolValue("call-by-name", call =>
                                                                  {
                                                                      string methodName =
                                                                          Utils.Eval(call.StackFrame, call.Args[2]).
                                                                              ToString();
                                                                      return stack.HandleCall(call, methodName);
                                                                  });

            stack.StackFrame.Scope.SetSymbolValue("application-run", call =>
                                                                     {
                                                                         Application.Run();
                                                                         return null;
                                                                     });
        }
 public override object Clone(CloneInfo info)
 {
     object res = (Utils.Eval(info.StackFrame, Expression));
     return res;
 }
Exemple #9
0
 public override object Clone(CloneInfo info)
 {
     return null;
 }