Exemple #1
0
            public override void Invoke(SpoolSpace Memory)
            {
                Cell x = this._Parameters[0].Evaluate(Memory);

                if (x.Affinity == CellAffinity.ARRAY)
                {
                    x.ARRAY.Sort();
                }
                else if (x.Affinity == CellAffinity.TREF)
                {
                    Table t = this._Host.OpenTable(x.valueTREF);
                    Key   k = new Key();
                    if (this._Parameters.Count >= 2)
                    {
                        Cell y = this._Parameters[1].Evaluate(Memory);
                        if (y.IsNumeric)
                        {
                            k.Add(y.valueINT);
                        }
                        else if (y.IsArray)
                        {
                            foreach (Cell z in y.valueARRAY)
                            {
                                k.Add(z.valueINT);
                            }
                        }
                        else
                        {
                            k = Key.Build(t.Columns.Count);
                        }
                    }
                    Spectre.Tables.TableUtil.Sort(t, k);
                }
            }
Exemple #2
0
            public override void BeginInvoke(SpoolSpace Memory)
            {
                // Do the checks, need an aggregate and we must be part of a loop
                if (!this._Parameters.ContainsAggregate || !this._Parameters.ContainsNonAggregate)
                {
                    throw new Exception("Dictionary aggregates must contain at least one aggregate and one non-aggregate");
                }

                //if (this._Parent == null || !this._Parent.IsBreakable)
                //    throw new Exception("Aggregates can only appear in loop statements");

                // We don't need to invoke the base method

                // Build the keys
                Key k = new Key(), v = new Key();
                int idx = 0;

                foreach (Expression x in this._Parameters)
                {
                    if (x.IsAggregate)
                    {
                        v.Add(idx);
                    }
                    else
                    {
                        k.Add(idx);
                    }
                    idx++;
                }

                // Set up the staging table //
                this._StorageTree = new DictionaryTable(this._Host, Host.RandomPath(), this._Parameters.Columns, k, Page.DEFAULT_SIZE);
            }
Exemple #3
0
            public override void Invoke(SpoolSpace Memory)
            {
                // Get the table source //
                if (this._Parameters[0].TypeOf() != CellAffinity.TREF)
                {
                    throw new Exception("Table loops require a tabular expression");
                }

                this.AddSpools(Memory);

                // Get the table
                Table t = this._Parameters[0].Select(Memory);

                // Loop
                using (RecordReader rr = t.OpenReader())
                {
                    while (rr.CanAdvance)
                    {
                        Memory[this._SpoolName].Set(rr.ReadNext());

                        if (this._Filter.Evaluate(Memory).valueBOOL)
                        {
                            this.InvokeChildren(Memory);
                        }
                    }
                }

                this.RemoveSpools(Memory);
            }
Exemple #4
0
        /// <summary>
        /// Creates a host
        /// </summary>
        public Host()
        {
            // Check the directory
            Host.CheckDir();

            // Timer
            this._Timer = Stopwatch.StartNew();

            // Communicator
            this._IO = new CommandLineCommunicator();

            // Random number generator
            this._RNG = new CellRandom();

            // Tables
            this._Cache = new TableStore(this);

            // Spools
            this._Store = new SpoolSpace();
            this._Store.Add(GLOBAL, new Spool.HeapSpindle(GLOBAL));

            // Libraries
            this._Libraries = new Heap <Library>();
            this._Libraries.Allocate("BASE", new BaseLibrary(this));

            // Engine
            this._Engine = new ScriptProcessor(this);

            // Possibly create a log writer //
            if (DEBUG_STATE == 1)
            {
                this._DebugWriter = new StreamWriter(DebugLogPath);
            }
        }
Exemple #5
0
            public override Cell Evaluate(SpoolSpace Memory)
            {
                this.CheckParameters();
                Cell x = this._Children[0].Evaluate(Memory);

                return(new Cell(CellSerializer.DiskSize(x)));
            }
Exemple #6
0
            public override void Invoke(SpoolSpace Memory)
            {
                Record value = this._Parameters.ToRecord(Memory);

                value = this.CheckValue(value);
                this._Writer.Insert(value);
            }
Exemple #7
0
            public override void Invoke(SpoolSpace Memory)
            {
                Table  Destination = this._Parameters[0].Select(Memory);
                string Source      = this._Parameters[1].Evaluate(Memory).valueCSTRING;

                char[] Delims = this._Parameters[2].Evaluate(Memory).valueCSTRING.ToCharArray();
                char   Escape = (this._Parameters.Count >= 4 ? this._Parameters[3].Evaluate(Memory).valueCSTRING.First() : char.MaxValue);
                int    Skips  = (this._Parameters.Count == 5 ? this._Parameters[4].Evaluate(Memory).valueINT : 0);

                using (StreamReader Reader = new StreamReader(Source))
                {
                    int i = 0;
                    while (i < Skips && !Reader.EndOfStream)
                    {
                        i++;
                        Reader.ReadLine();
                    }

                    using (RecordWriter Writer = Destination.OpenWriter())
                    {
                        while (!Reader.EndOfStream)
                        {
                            Record r = Util.StringUtil.ToRecord(Reader.ReadLine(), Destination.Columns, Delims, Escape);
                            Writer.Insert(r);
                        }
                    }
                }
            }
Exemple #8
0
            public override void Invoke(SpoolSpace Memory)
            {
                this.CheckParameters(2, 4);

                Table  Source = this._Parameters[0].Select(Memory);
                string Path   = this._Parameters[1].Evaluate(Memory);
                string Delim  = this._Parameters.Count >= 3 ? this._Parameters[2].Evaluate(Memory).valueCSTRING : "\t";
                string TextQ  = this._Parameters.Count == 4 ? this._Parameters[3].Evaluate(Memory).valueCSTRING : "";

                using (RecordReader reader = Source.OpenReader())
                {
                    using (StreamWriter writer = new StreamWriter(Path))
                    {
                        string x = Source.Columns.ToNameString(Delim);
                        writer.WriteLine(x);

                        while (reader.CanAdvance)
                        {
                            Record r   = reader.ReadNext();
                            string rec = Util.StringUtil.ToString(r, Delim, TextQ);
                            writer.WriteLine(rec);
                        }
                    }
                }
            }
Exemple #9
0
 public virtual void EndInvokeChildren(SpoolSpace Memory)
 {
     foreach (Statement s in this._Children)
     {
         s.EndInvoke(Memory);
     }
 }
Exemple #10
0
 public void BurnBoundTables(SpoolSpace Memory)
 {
     foreach (string t in this._BoundTables)
     {
         Memory.Drop(t);
     }
 }
Exemple #11
0
        public void Execute(string Script)
        {
            // Create a token stream and do lexal analysis //
            AntlrInputStream TextStream = new AntlrInputStream(Script);
            S_ScriptLexer    lex        = new S_ScriptLexer(TextStream);

            // Parse the script //
            CommonTokenStream RyeTokenStream = new CommonTokenStream(lex);
            S_ScriptParser    par            = new S_ScriptParser(RyeTokenStream);

            // Create an executer object //
            StatementVisitor processor = new StatementVisitor(this.Host);

            // Create a spool space //
            SpoolSpace mem = this._Host.Spools;

            // Load the call stack and/or parse the errors
            foreach (S_ScriptParser.StatementContext ctx in par.compileUnit().statement())
            {
                Statement stmt = processor.Render(ctx);
                stmt.BeginInvoke(mem);
                stmt.Invoke(mem);
                stmt.EndInvoke(mem);
            }
        }
Exemple #12
0
            public override Cell Evaluate(SpoolSpace Memory)
            {
                this.CheckParameters();
                Cell x = this._Children[0].Evaluate(Memory);

                return(CellFunctions.Sign(x));
            }
Exemple #13
0
            public override Cell Evaluate(SpoolSpace Memory)
            {
                this.CheckParameters();

                double pr = this._Children.Count == 1 ? this._Children[0].Evaluate(Memory).valueDOUBLE : 0.5;

                return(this._Source.NextBool(pr));
            }
Exemple #14
0
 public override void BeginInvoke(SpoolSpace Memory)
 {
     if (this._Parameters.ContainsAggregate || this._Parameters.Count == 0)
     {
         throw new Exception("Generic table inserts cannot contain aggregate functions and must contain at least one expression");
     }
     base.BeginInvoke(Memory);
 }
Exemple #15
0
            public override Cell Evaluate(SpoolSpace Memory)
            {
                this.CheckParameters();
                string Path = this._Children[0].Evaluate(Memory).valueCSTRING;
                string Name = this._Children[1].Evaluate(Memory).valueCSTRING;

                return(TableHeader.DeriveV1Path(Path, Name));
            }
Exemple #16
0
 public void BindTables(SpoolSpace Memory)
 {
     foreach (Expression x in this._Parameters.AllTables)
     {
         Memory.Add(x.NameOf(), new Spool.RecordSpindle(x.NameOf(), x.Columns));
         this._BoundTables.Add(x.NameOf());
     }
 }
Exemple #17
0
            public override Cell Evaluate(SpoolSpace Memory)
            {
                this.CheckParameters();
                Cell x = this._Children[0].Evaluate(Memory);
                Cell y = this._Children[1].Evaluate(Memory);

                return(CellFunctions.Round(x, y.valueINT));
            }
Exemple #18
0
            public override Cell Evaluate(SpoolSpace Memory)
            {
                this.CheckParameters();
                Cell x = this._Children[0].Evaluate(Memory);
                Cell y = this._Children[1].Evaluate(Memory);
                Cell z = this._Children[2].Evaluate(Memory);

                return(CellFunctions.ModPow(x, y, z));
            }
Exemple #19
0
            public override Cell Evaluate(SpoolSpace Memory)
            {
                this.CheckParameters();
                Cell         c = this._Children[0].Evaluate(Memory);
                Cell         d = this._Children[1].Evaluate(Memory);
                CellAffinity a = (CellAffinity)d.BYTE;

                return(CellConverter.Cast(c, a));
            }
Exemple #20
0
            public override Cell Evaluate(SpoolSpace Memory)
            {
                this.CheckParameters();
                Cell a     = this._Children[0].Evaluate(Memory);
                Cell b     = this._Children[1].Evaluate(Memory);
                int  Start = (this._Children.Count == 2 ? 0 : this._Children[2].Evaluate(Memory).valueINT);

                return(CellFunctions.Position(a, b, Start));
            }
Exemple #21
0
            protected void AddSpools(SpoolSpace Memory)
            {
                string lname = this._Parameters[0].NameOf();

                Memory.Add(lname, new Spool.RecordSpindle(lname, this._Parameters[0].Columns));
                string rname = this._Parameters[1].NameOf();

                Memory.Add(rname, new Spool.RecordSpindle(rname, this._Parameters[1].Columns));
            }
Exemple #22
0
            public override void Invoke(SpoolSpace Memory)
            {
                Statement x = this._Parent;

                while (x != null)
                {
                    x.Raise(RaiseAlert.Exit);
                    x = x._Parent;
                }
            }
Exemple #23
0
            public override Cell Evaluate(SpoolSpace Memory)
            {
                this.CheckParameters();
                Cell Length  = this._Children[0].Evaluate(Memory);
                Cell Default = (this._Children.Count >= 2 ? this._Children[1].Evaluate(Memory) : CellValues.NullBOOL);

                CellArray x = CellArray.Vector(Length.valueINT, Default);

                return(new Cell(x));
            }
Exemple #24
0
            public override Cell Evaluate(SpoolSpace Memory)
            {
                this.CheckParameters();

                CellArray x = this._Children[0].Evaluate(Memory);
                CellArray y = this._Children[1].Evaluate(Memory);
                CellArray z = CellArray.Multiply(x, y);

                return(new Cell(z));
            }
Exemple #25
0
 public virtual void InvokeChildren(SpoolSpace Memory)
 {
     foreach (Statement s in this._Children)
     {
         s.Invoke(Memory);
         if (this.RaiseElement == RaiseAlert.Break || this.RaiseElement == RaiseAlert.Return || this.RaiseElement == RaiseAlert.Exit)
         {
             break;
         }
     }
 }
Exemple #26
0
            public override Cell Evaluate(SpoolSpace Memory)
            {
                this.CheckParameters();
                if (this._Children[0] is Expression.ArrayLiteral)
                {
                    return(new Cell((this._Children[0] as Expression.ArrayLiteral).Children.Count));
                }
                Cell x = this._Children[0].Evaluate(Memory);

                return(new Cell(x.Length));
            }
Exemple #27
0
            public override Cell Evaluate(SpoolSpace Memory)
            {
                this.CheckParameters();
                Cell x = this._Children[0].Evaluate(Memory);

                if (x.Affinity != CellAffinity.TREF)
                {
                    return(CellValues.NullLONG);
                }
                return(this._Host.TableStore.RequestTable(x.valueTREF).RecordCount);
            }
Exemple #28
0
            public override Cell Evaluate(SpoolSpace Memory)
            {
                this.CheckParameters();
                Cell RowCount    = this._Children[0].Evaluate(Memory);
                Cell ColumnCount = this._Children[1].Evaluate(Memory);
                Cell Default     = (this._Children.Count >= 3 ? this._Children[2].Evaluate(Memory) : CellValues.NullBOOL);

                CellArray x = CellArray.Matrix(RowCount.valueINT, ColumnCount.valueINT, Default);

                return(new Cell(x));
            }
        public override void Invoke(SpoolSpace Memory)
        {
            // Bind First
            this.Bind(Memory);

            // Invoke all
            this.InvokeChildren(Memory);

            Memory.Drop(this._Name);

            this.BurnBoundTables(Memory);
        }
Exemple #30
0
            public override void Invoke(SpoolSpace Memory)
            {
                Expression x = this._Parameters[0];

                while (x.Evaluate(Memory).valueBOOL)
                {
                    this.InvokeChildren(Memory);
                    if (this.RaiseElement == RaiseAlert.Break || this.RaiseElement == RaiseAlert.Return || this.RaiseElement == RaiseAlert.Exit)
                    {
                        break;
                    }
                }
            }