Ejemplo n.º 1
0
Archivo: Through.cs Proyecto: baban/lp
 protected override object DoEvaluate(ScriptThread thread)
 {
     thread.CurrentNode = this;
     Object.LpObject result = (Object.LpObject)Node.Evaluate(thread);
     thread.CurrentNode = Parent;
     return(result);
 }
Ejemplo n.º 2
0
 protected override object DoEvaluate(ScriptThread thread)
 {
     thread.CurrentNode = this;
     Object.LpObject result = Object.LpSymbol.initialize(node.Token.Text);
     thread.CurrentNode = Parent;
     return(result);
 }
Ejemplo n.º 3
0
        public Object.LpObject[] putVariables(Object.LpObject[] args, Object.LpObject block)
        {
            if (args == null)
            {
                return new Object.LpObject[] { }
            }
            ;
            if (args.Count() == arity())
            {
                return(args);
            }

            int argsSize = Math.Abs(arity());

            Object.LpObject[] dstArgs = new Object.LpObject[argsSize];
            if (arity() < 0)
            {
                Array.Copy(args, dstArgs, argsSize - 1);
                dstArgs[argsSize - 1] = Object.LpArray.initialize(args.Skip(argsSize - 1).Take(args.Count() - (argsSize - 1)).ToArray());
            }
            else
            {
                Array.Copy(args, dstArgs, argsSize);
            }

            return(dstArgs);
        }
Ejemplo n.º 4
0
 protected override object DoEvaluate(ScriptThread thread)
 {
     thread.CurrentNode = this;
     Object.LpObject[] result = new Object.LpObject[] { (Object.LpObject)Key.Evaluate(thread), (Object.LpObject)Value.Evaluate(thread) };
     thread.CurrentNode = Parent;
     return(result);
 }
Ejemplo n.º 5
0
Archivo: String.cs Proyecto: baban/lp
 protected override object DoEvaluate(ScriptThread thread)
 {
     thread.CurrentNode = this;
     Object.LpObject result = Object.LpString.initialize((string)Node.Evaluate(thread));
     thread.CurrentNode = Parent;
     return(result);
 }
Ejemplo n.º 6
0
Archivo: IfStmt.cs Proyecto: baban/lp
        protected override object DoEvaluate(ScriptThread thread)
        {
            thread.CurrentNode = this;
            var check = (Object.LpObject)Expr.Evaluate(thread);

            Object.LpObject result = null;
            if ((bool)check.boolValue)
            {
                result = (Object.LpObject)Stmts.Evaluate(thread);
            }
            else if (ElsIfStmts != null)
            {
                result = (Object.LpObject)ElsIfStmts.Evaluate(thread);
            }
            if (result == null)
            {
                if (ElseStmt != null)
                {
                    result = (Object.LpObject)ElseStmt.Evaluate(thread);
                }
                else
                {
                    result = Object.LpNl.initialize();
                }
            }

            thread.CurrentNode = Parent;

            return(result);
        }
Ejemplo n.º 7
0
        private void setBaseVariables(Object.LpObject self, Object.LpObject[] args)
        {
            int?equalCnt = searchEqualArg();

            if (equalCnt != null)
            {
                // have equal '='
                for (int i = Math.Abs(arity()); i < arguments.Count(); i++)
                {
                    if (-1 != arguments[i].IndexOf("="))
                    {
                        //var node = null;  //LpParser.createNode(arguments[i]);
                        //node.DoEvaluate();
                    }
                }
                for (int i = 0; i < Math.Abs(arity()); i++)
                {
                    self.variables[arguments[i]] = args[i];
                }
            }
            else
            {
                // have not equal '='
                for (int i = 0; i < arguments.Count(); i++)
                {
                    self.variables[arguments[i]] = args[i];
                }
            }
        }
Ejemplo n.º 8
0
Archivo: Funcall.cs Proyecto: baban/lp
        object EvaluateInStmts(Object.LpObject function, ScriptThread thread)
        {
            var newScopeInfo = new ScopeInfo(thread.CurrentNode, false);

            var args = (Object.LpObject[])Args.Evaluate(thread);

            thread.PushClosureScope(newScopeInfo, thread.CurrentScope, args);

            var scope = thread.CurrentScope;

            var dic = scope.AsDictionary();

            dic["methods"]   = new Dictionary <string, object>();
            dic["variables"] = new Dictionary <string, object>();
            var methods   = (Dictionary <string, object>)dic["methods"];
            var variables = (Dictionary <string, object>)dic["variables"];

            /*
             * var parameters = scope.Parameters;
             *
             * for(int i=0; i < args.Length ; i++)
             * {
             *  var v = args[i];
             *  variables[i.ToString()] = v;
             * }
             */
            var result = function.statements.Evaluate(thread);

            thread.PopScope();

            return(result);
        }
Ejemplo n.º 9
0
Archivo: Bool.cs Proyecto: baban/lp
        protected override object DoEvaluate(ScriptThread thread)
        {
            thread.CurrentNode = this;
            var boolValue = Node.Term.ToString() == "true" ? true : false;

            Object.LpObject result = Object.LpBool.initialize(boolValue);
            thread.CurrentNode = Parent;
            return(result);
        }
Ejemplo n.º 10
0
        protected override object DoEvaluate(ScriptThread thread)
        {
            thread.CurrentNode = this;

            var val  = (Object.LpObject)Expr.Evaluate(thread);
            var arg  = (Object.LpObject)Arg.Evaluate(thread);
            var args = new Object.LpObject[] { arg };

            // var result = val.funcall("[]", args);

            thread.CurrentNode = Parent;

            //return result;
            return(Object.LpNl.initialize());
        }
Ejemplo n.º 11
0
        protected override object DoEvaluate(ScriptThread thread)
        {
            thread.CurrentNode = this;
            var check = (Object.LpObject)Expr.Evaluate(thread);

            Object.LpObject result = null;
            if ((bool)check.boolValue)
            {
                result = (Object.LpObject)Stmts.Evaluate(thread);
            }

            thread.CurrentNode = Parent;

            return(result);
        }
Ejemplo n.º 12
0
 protected override object DoEvaluate(ScriptThread thread)
 {
     thread.CurrentNode = this;
     Object.LpObject result = null;
     if (ChildNodes.Count() > 0)
     {
         result           = Object.LpBlock.initialize(Body);
         result.arguments = null;
     }
     else
     {
         result = Object.LpBlock.initialize();
     }
     thread.CurrentNode = Parent;
     return(result);
 }
Ejemplo n.º 13
0
        protected override object DoEvaluate(ScriptThread thread)
        {
            thread.CurrentNode = this;

            Object.LpObject result = null;
            if(Stmts != null) {
                result = (Object.LpObject)Stmts.Evaluate(thread);
            } else
            {
                result = Object.LpNl.initialize();
            }

            thread.CurrentNode = Parent;

            return result;
        }
Ejemplo n.º 14
0
 private Object.LpObject cond(ScriptThread thread, Object.LpObject baseValue, AstNode[][] childNodes)
 {
     Object.LpObject result = null;
     foreach (var node in childNodes)
     {
         var pair  = node;
         var expr  = pair[0];
         var stmts = pair[1];
         var check = (Object.LpObject)(expr.Evaluate(thread));
         if ((bool)check.funcall("==", new Object.LpObject[] { baseValue }).boolValue)
         {
             result = (Object.LpObject)(stmts.Evaluate(thread));
             break;
         }
     }
     return(result);
 }
Ejemplo n.º 15
0
Archivo: Stmts.cs Proyecto: baban/lp
 protected override object DoEvaluate(ScriptThread thread)
 {
     try {
         Object.LpObject result = Object.LpNl.initialize();
         thread.CurrentNode = this;
         ChildNodes.ForEach((node) => result = (Object.LpObject)node.Evaluate(thread));
         thread.CurrentNode = Parent;
         return(result);
     }
     catch (System.Exception e)
     {
         var traces   = thread.GetStackTrace();
         var location = thread.CurrentNode.Location;
         System.Console.WriteLine(e.Message);
         System.Console.WriteLine(location);
         return(null);
     }
 }
Ejemplo n.º 16
0
        protected override object DoEvaluate(ScriptThread thread)
        {
            Object.LpObject result = null;
            thread.CurrentNode = this;

            foreach (var node in ChildNodes)
            {
                result = (Object.LpObject)node.Evaluate(thread);
                if (result != null)
                {
                    return(result);
                }
            }

            thread.CurrentNode = Parent;

            return(result);
        }
Ejemplo n.º 17
0
        protected override object DoEvaluate(ScriptThread thread)
        {
            thread.CurrentNode = this;
            string Varname = node.Token.Text;

            var scope = thread.CurrentScope;
            var dic   = Util.Scope.searchContext(scope, "variables", Varname);

            thread.CurrentNode = Parent;

            if (dic == null)
            {
                throw new Error.NameError();
            }

            Object.LpObject value = (Object.LpObject)dic[Varname];
            return(value);
        }
Ejemplo n.º 18
0
        public Object.LpObject setVariables(Object.LpObject self, Object.LpObject[] args, Object.LpObject block)
        {
            if (!check(args))
            {
                throw new Error.LpArgumentError();
            }

            setBaseVariables(self, args);

            // have asterisk '*'
            if (arrayArg != null)
            {
                self.variables[arrayArg] = Object.LpArray.initialize(args.Skip(arguments.Count()).ToArray());
            }

            if (blockArg != null)
            {
                self.variables[blockArg] = block;
            }

            return(self);
        }