Ejemplo n.º 1
0
        public void EvalChart(RCRunner runner, RCClosure closure, RCSymbol right)
        {
            RCCube result = new RCCube(new RCArray <string> ("S"));

            DoChart <RCSymbolScalar> (result, RCSymbolScalar.Empty, 0, 0, right);
            runner.Yield(closure, result);
        }
Ejemplo n.º 2
0
            public void EvalTake(RCRunner runner, RCClosure closure, RCSymbol left, RCBlock right)
            {
                RCBot bot    = runner.GetBot(closure.Bot);
                Take  module = (Take)bot.GetModule(typeof(Take));

                module.DoTake(runner, closure, left, right);
            }
Ejemplo n.º 3
0
        public void EvalSwitch(RCRunner runner, RCClosure closure, RCSymbol left, RCBlock right)
        {
            Picker <RCSymbolScalar> picker = delegate(RCSymbolScalar val, out bool eval)
            {
                if (val.Length > 1)
                {
                    throw new Exception(
                              "switch only supports block lookups using tuples of count 1.  But this could change.");
                }
                RCBlock variable = right.GetName((string)val.Key);
                RCValue code;
                // This behavior is sketchy and should be reevaluated - this should be an
                // exception
                if (variable == null)
                {
                    code = RCBlock.Empty;
                    eval = true;
                }
                else
                {
                    code = variable.Value;
                    eval = !variable.Evaluator.Pass;
                }
                return(code);
            };

            DoSwitch <RCSymbolScalar> (runner, closure, left, right, picker);
        }
Ejemplo n.º 4
0
 protected virtual void WriteToFiles(RCRunner runner,
                                     RCClosure closure,
                                     RCSymbol symbol,
                                     RCBlock data)
 {
     for (int i = 0; i < data.Count; ++i)
     {
         FileStream stream = null;
         RCBlock    column = data.GetName(i);
         if (!_files.TryGetValue(column.Name, out stream))
         {
             string path = Path.Combine(_dir.Name, column.Name);
             stream = new FileStream(path,
                                     FileMode.CreateNew,
                                     FileAccess.Write);
             _files[column.Name] = stream;
         }
         RCArray <byte> array = new RCArray <byte> ();
         column.Value.ToByte(array);
         // throw new NotImplementedException ("This is where it's at baby, get er done.");
         // RCAsyncState state = new RCAsyncState (runner, closure, stream);
         // stream.BeginWrite (array, 0, array.Length, new AsyncCallback (EndWrite),
         // state);
     }
 }
Ejemplo n.º 5
0
        public void EvalGawk(RCRunner runner, RCClosure closure, RCSymbol symbol, RCLong right)
        {
            int limit = (int)right[0];

            lock (_readWriteLock)
            {
                Section  s          = GetSection(symbol);
                ReadSpec spec       = s._counter.GetReadSpec(symbol, limit, false, true);
                Satisfy  canSatisfy = s._counter.CanSatisfy(spec);
                RCCube   result     = s._blackboard.Read(spec, s._counter, true, s._blackboard.Count);

                if ((spec.SymbolUnlimited && result.Count > 0) ||
                    (!spec.SymbolUnlimited && result.Count >= symbol.Count * Math.Abs(spec.SymbolLimit)))
                {
                    if (canSatisfy != Satisfy.Yes)
                    {
                        throw new Exception();
                    }
                    runner.Yield(closure, result);
                }
                else
                {
                    if (canSatisfy != Satisfy.No)
                    {
                        throw new Exception();
                    }
                    s._dispatchWaiters.Enqueue(symbol, closure);
                }
            }
        }
Ejemplo n.º 6
0
            public void Enqueue(RCSymbol symbol, RCClosure closure)
            {
                if (_symbolsByFiber.ContainsKey(closure.Fiber))
                {
                    throw new Exception("Fiber " + closure.Fiber.ToString() +
                                        " is already waiting, something is wrong.");
                }
                RCArray <RCSymbolScalar> stripped = new RCArray <RCSymbolScalar> (symbol.Count);

                for (int i = 0; i < symbol.Count; ++i)
                {
                    if (symbol[i].Key.Equals("*"))
                    {
                        stripped.Write(symbol[i].Previous);
                    }
                    else
                    {
                        stripped.Write(symbol[i]);
                    }
                }
                _symbolsByFiber.Add(closure.Fiber,
                                    new HashSet <RCSymbolScalar> (stripped));
                for (int i = 0; i < stripped.Count; ++i)
                {
                    HashSet <long> fibers;
                    if (!_fibersBySymbol.TryGetValue(stripped[i], out fibers))
                    {
                        _fibersBySymbol[stripped[i]] = fibers = new HashSet <long> ();
                    }
                    fibers.Add(closure.Fiber);
                }
                _waitOrder.Enqueue(closure);
            }
Ejemplo n.º 7
0
        public void EvalPage(RCRunner runner, RCClosure closure, RCSymbol symbol, RCLong right)
        {
            int pageNumber = 0;

            if (right.Count > 0)
            {
                pageNumber = (int)right[0];
            }
            int pageSize = int.MaxValue;

            if (right.Count > 1)
            {
                pageSize = (int)right[1];
            }

            // Page lets you access the blackboard by page number and page size, rather than row
            // numbers.
            // Good for building tools for looking at blackboard contents.
            lock (_readWriteLock)
            {
                Section  s         = GetSection(symbol);
                int      skipFirst = pageNumber * pageSize;
                int      stopAfter = pageSize;
                ReadSpec spec      = new ReadSpec(s._counter, symbol, skipFirst, stopAfter, false);
                RCCube   result    = s._blackboard.Read(spec, s._counter, true, s._blackboard.Count);
                runner.Yield(closure, result);
            }
        }
Ejemplo n.º 8
0
        public void EvalPeek(RCRunner runner, RCClosure closure, RCSymbol left, RCLong right)
        {
            int limit = (int)right[0];

            lock (_readWriteLock)
            {
                Section  s          = GetSection(left);
                ReadSpec spec       = s._counter.GetReadSpec(left, limit, false, true);
                Satisfy  canSatisfy = s._counter.CanSatisfy(spec);
                RCCube   result     = s._blackboard.Read(spec, s._counter, true, s._blackboard.Count);

                if ((spec.SymbolUnlimited && result.Count > 0) ||
                    (!spec.SymbolUnlimited && result.Count >= left.Count * Math.Abs(spec.SymbolLimit)))
                {
                    // If dispatch would yield, return lines.
                    if (canSatisfy != Satisfy.Yes)
                    {
                        throw new Exception();
                    }
                    runner.Yield(closure, RCBoolean.True);
                }
                else
                {
                    if (canSatisfy != Satisfy.No)
                    {
                        throw new Exception();
                    }
                    runner.Yield(closure, RCBoolean.False);
                }
            }
        }
Ejemplo n.º 9
0
        public void EvalListen(RCRunner runner, RCClosure closure, RCSymbol right)
        {
            if (right.Count != 1)
            {
                throw new Exception("listen takes exactly one protocol,port");
            }
            string protocol = (string)right[0].Part(0);
            long   port     = (long)right[0].Part(1);
            RCBot  bot      = runner.GetBot(closure.Bot);
            long   handle   = bot.New();
            Server server;

            if (protocol.Equals("http"))
            {
                throw new NotImplementedException("http server not ready yet");
            }
            else if (protocol.Equals("tcp"))
            {
                server = new TcpServer(handle, port, new TcpProtocol());
            }
            else if (protocol.Equals("udp"))
            {
                throw new ArgumentException("No udp sockets yet");
            }
            else
            {
                throw new ArgumentException("Unknown protocol: " + protocol);
            }
            bot.Put(handle, server);
            server.Listen(runner, closure);
        }
Ejemplo n.º 10
0
        public void EvalPartsAfter(RCRunner runner, RCClosure closure, RCSymbol left, RCLong right)
        {
            RCArray <RCSymbolScalar> result = new RCArray <RCSymbolScalar> (left.Count);

            if (right.Count == 1)
            {
                for (int i = 0; i < left.Count; ++i)
                {
                    result.Write(left[i].PartsAfter(right[0]));
                }
            }
            else if (right.Count == left.Count)
            {
                for (int i = 0; i < left.Count; ++i)
                {
                    result.Write(left[i].PartsAfter(right[i]));
                }
            }
            else
            {
                throw new RCException(closure,
                                      RCErrors.Count,
                                      "partsBefore requires a single part index or an array having the same count as the left argument");
            }
            runner.Yield(closure, new RCSymbol(result));
        }
Ejemplo n.º 11
0
 public void EvalTrace(RCRunner runner, RCClosure closure, RCSymbol right)
 {
     try
     {
         // This read is different from all others in that it has force on and fill off.
         // force causes duplicate values to be written.
         // fill causes prior values to be filled into the results.
         // This read gives you exactly what exists in the blackboard.
         RCLong  args    = new RCLong(0, 0);
         Section section = GetSection(right);
         Read(runner,
              closure,
              right,
              new ReadSpec(section._counter,
                           right,
                           args,
                           0,
                           false,
                           true,
                           false,
                           true));
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 12
0
        public void EvalRename(RCRunner runner, RCClosure closure, RCSymbol left, RCBlock right)
        {
            if (left.Count != right.Count && left.Count != 1)
            {
                throw new Exception("left and right arguments must have the same length");
            }

            RCBlock result = RCBlock.Empty;

            if (left.Count == 1)
            {
                for (int i = 0; i < right.Count; ++i)
                {
                    RCBlock name  = right.GetName(i);
                    string  field = left[0].Part(0).ToString();
                    result = new RCBlock(result, field, name.Evaluator, name.Value);
                }
            }
            else
            {
                for (int i = 0; i < left.Count; ++i)
                {
                    RCBlock name  = right.GetName(i);
                    string  field = left[i].Part(0).ToString();
                    result = new RCBlock(result, field, name.Evaluator, name.Value);
                }
            }
            runner.Yield(closure, result);
        }
Ejemplo n.º 13
0
        public void EvalForce(RCRunner runner, RCClosure closure, RCSymbol left, RCBlock right)
        {
            long    line     = Write(runner, left, right, true);
            RCBlock logBlock = new RCBlock(right, "S", ":", left);

            RCSystem.Log.Record(closure, "board", 0, "write", logBlock);
            runner.Yield(closure, new RCLong(line));
        }
Ejemplo n.º 14
0
        public void EvalRmdir(RCRunner runner, RCClosure closure, RCSymbol right)
        {
            // All of this stuff HASTA HASTA HASTA be ASYNC!
            string path = PathSymbolToLocalString(right[0]);

            Directory.Delete(path);
            runner.Yield(closure, right);
        }
Ejemplo n.º 15
0
 public void EvalDelete(RCRunner runner, RCClosure closure, RCSymbol right)
 {
     for (int i = 0; i < right.Count; ++i)
     {
         File.Delete(PathSymbolToLocalString(right[i]));
     }
     runner.Yield(closure, right);
 }
Ejemplo n.º 16
0
        public void EvalList(RCRunner runner, RCClosure closure, RCSymbol left, RCSymbol right)
        {
            HashSet <RCSymbolScalar> options = new HashSet <RCSymbolScalar> (left);
            string target = (string)right[0].Part(0);

            if (target == "" || target == "work")
            {
                BeginListFilesCube(runner,
                                   closure,
                                   new ListArgs(right[0],
                                                options.Contains(all),
                                                options.Contains(deep)));
            }
            else if (target == "home")
            {
                BeginListFilesCube(runner,
                                   closure,
                                   new ListArgs(right[0],
                                                options.Contains(all),
                                                options.Contains(deep)));
            }
            else if (target == "root")
            {
                BeginListFilesCube(runner,
                                   closure,
                                   new ListArgs(right[0],
                                                options.Contains(all),
                                                options.Contains(deep)));
            }
            else if (target == "fibers")
            {
                ListFibers(runner, closure);
            }
            else if (target == "vars")
            {
                ListVars(runner, closure);
            }
            else if (target == "urls")
            {
                ListUrls(runner, closure);
            }
            else if (target == "request")
            {
                ListRequest(runner, closure);
            }
            else if (target == "sockets")
            {
                ListSockets(runner, closure);
            }
            else if (target == "exec")
            {
                ListExec(runner, closure);
            }
            else
            {
                throw new Exception("Unknown target for list: " + target);
            }
        }
Ejemplo n.º 17
0
 public void Deletem(RCRunner runner, RCClosure closure, RCSymbol key)
 {
     lock (_lock)
     {
         Dictionary <RCSymbolScalar, RCValue> store = GetSection(key);
         store.Remove(key[0]);
     }
     runner.Yield(closure, new RCSymbol(key[0]));
 }
Ejemplo n.º 18
0
 public void Putm(RCRunner runner, RCClosure closure, RCSymbol key, object val)
 {
     lock (_lock)
     {
         Dictionary <RCSymbolScalar, RCValue> store = GetSection(key);
         store[key[0]] = (RCValue)val;
     }
     runner.Yield(closure, key);
 }
Ejemplo n.º 19
0
        public void EvalSelect(RCRunner runner, RCClosure closure, RCSymbol left, RCCube right)
        {
            RCLong      args    = new RCLong(0, 0);
            ReadCounter counter = new ReadCounter(right);
            ReadSpec    spec    = new ReadSpec(counter, left, args, 0, false, false, true, false);
            RCCube      result  = right.Read(spec, counter, true, right.Count);

            runner.Yield(closure, result);
        }
Ejemplo n.º 20
0
 public void EvalInfo(RCRunner runner, RCClosure closure, RCSymbol right)
 {
     if (right.Count > 1)
     {
         throw new Exception(
                   "info can only provide one value at a time. info #help gives a list of valid values.");
     }
     Info(runner, closure, right[0].Part(0).ToString());
 }
Ejemplo n.º 21
0
 public void EvalCd(RCRunner runner, RCClosure closure, RCSymbol right)
 {
     if (right.Count > 1)
     {
         throw new Exception("cd can only change into one directory");
     }
     Environment.CurrentDirectory = Command.PathSymbolToLocalString(right[0]);
     runner.Yield(closure, right);
 }
Ejemplo n.º 22
0
        public void EvalLoad(RCRunner runner, RCClosure closure, RCSymbol right)
        {
            // Need check for windows drive letter
            string path = PathSymbolToLocalString(right[0]);
            string code = File.ReadAllText(path, Encoding.UTF8);

            code = code.Replace("\r", "");
            runner.Yield(closure, new RCString(code));
        }
Ejemplo n.º 23
0
        public void EvalSymbolMonadicPlus(RCRunner runner, RCClosure closure, RCSymbol right)
        {
            RCSymbolScalar result = RCSymbolScalar.Empty;

            for (int i = 0; i < right.Count; ++i)
            {
                result = ScalarMath.Plus(result, right[i]);
            }
            runner.Yield(closure, new RCSymbol(result));
        }
Ejemplo n.º 24
0
        public void EvalFile(RCRunner runner, RCClosure closure, RCSymbol right)
        {
            RCArray <bool> result = new RCArray <bool> (right.Count);

            for (int i = 0; i < right.Count; ++i)
            {
                result.Write(File.Exists(PathSymbolToLocalString(right[i])));
            }
            runner.Yield(closure, new RCBoolean(result));
        }
Ejemplo n.º 25
0
        public void EvalPath(RCRunner runner, RCClosure closure, RCSymbol right)
        {
            RCArray <string> result = new RCArray <string> (right.Count);

            for (int i = 0; i < right.Count; ++i)
            {
                result.Write(PathSymbolToLocalString(right[i]));
            }
            runner.Yield(closure, new RCString(result));
        }
Ejemplo n.º 26
0
 public void Read(RCRunner runner, RCClosure closure, RCSymbol symbol, ReadSpec spec)
 {
     lock (_readWriteLock)
     {
         // Make abstract symbols concrete
         Section section    = GetSection(symbol);
         Satisfy canSatisfy = section._counter.CanSatisfy(spec);
         RCCube  result     = section._blackboard.Read(spec,
                                                       section._counter,
                                                       true,
                                                       section._blackboard.Count);
         if (spec.SymbolUnlimited)
         {
             if (result.Count > 0)
             {
                 // Notice the canSatisfy constraints here are less strict.
                 // If the start point is greater than zero then we have to
                 // do the full read and then just see if there were enough
                 // rows to satisfy the constraints.
                 if (canSatisfy == Satisfy.No)
                 {
                     throw new Exception();
                 }
                 runner.Yield(closure, result);
             }
             else
             {
                 if (canSatisfy == Satisfy.Yes)
                 {
                     throw new Exception();
                 }
                 section._readWaiters.Enqueue(symbol, closure);
             }
         }
         else
         {
             if (result.Count >= symbol.Count * Math.Abs(spec.SymbolLimit))
             {
                 if (canSatisfy == Satisfy.No)
                 {
                     throw new Exception();
                 }
                 runner.Yield(closure, result);
             }
             else
             {
                 if (canSatisfy == Satisfy.Yes)
                 {
                     throw new Exception();
                 }
                 section._readWaiters.Enqueue(symbol, closure);
             }
         }
     }
 }
Ejemplo n.º 27
0
 public void Clear(RCRunner runner, RCClosure closure, RCSymbol key)
 {
     lock (_lock)
     {
         for (int i = 0; i < key.Count; ++i)
         {
             _sections.Remove(key[i].Part(0));
         }
     }
     runner.Yield(closure, key);
 }
Ejemplo n.º 28
0
 public void List(RCRunner runner, RCClosure closure, RCSymbol key)
 {
     RCSymbolScalar[] array;
     lock (_lock)
     {
         Dictionary <RCSymbolScalar, RCValue> store = GetSection(key);
         array = new RCSymbolScalar[store.Keys.Count];
         store.Keys.CopyTo(array, 0);
     }
     runner.Yield(closure, new RCSymbol(array));
 }
Ejemplo n.º 29
0
        public static SortDirection ToDir(RCSymbol left)
        {
            if (left.Count != 1)
            {
                throw new Exception("left argument must be exactly one of #asc #desc #absasc #absdesc");
            }
            SortDirection result = (SortDirection)Enum.Parse(typeof(SortDirection),
                                                             (string)left[0].Part(0));

            return(result);
        }
Ejemplo n.º 30
0
 public void ShowSpecialFolders(RCRunner runner, RCClosure closure, RCSymbol right)
 {
     foreach (Environment.SpecialFolder folder in Enum.GetValues(typeof(
                                                                     Environment.SpecialFolder)))
     {
         Console.WriteLine(string.Format("{0}\t\t\t{1}",
                                         folder.ToString(),
                                         Environment.GetFolderPath(folder)));
     }
     runner.Yield(closure, right);
 }