Esempio n. 1
0
        protected override bool Run()
        {
            if (input == null)
            {
                Computation input_lookup = new Lookup(master, source_reference, new [] { "arg" }, context);
                input_lookup.Notify(input_result => {
                    if (input_result is Stringish)
                    {
                        input = input_result.ToString();
                        if (Interlocked.Decrement(ref interlock) == 0)
                        {
                            master.Slot(this);
                        }
                    }
                    else
                    {
                        master.ReportOtherError(source_reference, "Input argument must be a string.");
                    }
                });
                master.Slot(input_lookup);

                if (Interlocked.Decrement(ref interlock) > 0)
                {
                    return(false);
                }
            }
            var frame = new Frame(master, master.NextId(), source_reference, context, container);

            for (int it = 0; it < input.Length; it++)
            {
                frame[TaskMaster.OrdinalNameStr(it + 1)] = (long)Char.ConvertToUtf32(input, it);
            }
            result = frame;
            return(true);
        }
Esempio n. 2
0
        protected override bool Run()
        {
            var computation = (Computation)Activator.CreateInstance(test_target, task_master);

            computation.Notify(HandleFrameResult);
            task_master.Slot(computation);
            return(false);
        }
Esempio n. 3
0
        protected override bool Run()
        {
            if (input == null)
            {
                var input_lookup = new Lookup(master, source_reference,
                                              new String[] { "arg" }, context);
                input_lookup.Notify(input_result => {
                    if (input_result is Stringish)
                    {
                        input = input_result.ToString();
                        if (Interlocked.Decrement(ref interlock) == 0)
                        {
                            master.Slot(this);
                        }
                    }
                    else
                    {
                        master.ReportOtherError(source_reference,
                                                "Input argument must be a string.");
                    }
                });
                master.Slot(input_lookup);

                var radix_lookup = new Lookup(master, source_reference,
                                              new String[] { "radix" }, context);
                radix_lookup.Notify(radix_result => {
                    if (radix_result is Int64)
                    {
                        radix = (int)(long)radix_result;
                        if (Interlocked.Decrement(ref interlock) == 0)
                        {
                            master.Slot(this);
                        }
                    }
                    else
                    {
                        master.ReportOtherError(source_reference,
                                                "Input argument must be a string.");
                    }
                });
                master.Slot(radix_lookup);

                if (Interlocked.Decrement(ref interlock) > 0)
                {
                    return(false);
                }
            }

            try {
                result = Convert.ToInt64(input, radix);
                return(true);
            } catch (Exception e) {
                master.ReportOtherError(source_reference, e.Message);
                return(false);
            }
        }
Esempio n. 4
0
        protected override bool Run()
        {
            if (mappings.Count == 0)
            {
                interlock = categories.Count + 2;
                Computation input_lookup = new Lookup(master, source_reference, new [] { "arg" }, context);
                input_lookup.Notify(input_result => {
                    if (input_result is Stringish)
                    {
                        input = input_result.ToString();
                        if (Interlocked.Decrement(ref interlock) == 0)
                        {
                            master.Slot(this);
                        }
                    }
                    else
                    {
                        master.ReportOtherError(source_reference, "Input argument must be a string.");
                    }
                });
                master.Slot(input_lookup);

                foreach (var entry in categories)
                {
                    var lookup = new Lookup(master, source_reference, new [] { entry.Value }, context);
                    lookup.Notify(cat_result => {
                        mappings[entry.Key] = cat_result;
                        if (Interlocked.Decrement(ref interlock) == 0)
                        {
                            master.Slot(this);
                        }
                    });
                    master.Slot(lookup);
                }

                if (Interlocked.Decrement(ref interlock) > 0)
                {
                    return(false);
                }
            }
            var frame = new Frame(master, master.NextId(), source_reference, context, container);

            for (int it = 0; it < input.Length; it++)
            {
                frame[TaskMaster.OrdinalNameStr(it + 1)] = mappings[Char.GetUnicodeCategory(input[it])];
            }
            result = frame;
            return(true);
        }
        private void HandleFrameResult(object result)
        {
            var frame = result as Frame;

            if (frame != null)
            {
                var lookup = new Lookup(task_master, new SourceReference("printer", "<native>", 0, 0, 0, 0, null), new[] { "value" }, frame.Context);
                lookup.Notify(HandleFinalResult);
                task_master.Slot(lookup);
            }
            else
            {
                Console.Error.WriteLine("File did not contain a frame. That should be impossible.");
            }
        }
Esempio n. 6
0
 /**
  * Trigger any unfinished computations contained in this frame to be executed.
  *
  * When a frame is being filled, unfinished computations may be added. They
  * cannot be started immediately, since the frame may still have members to
  * be added and those changes will be visible to the lookup environments of
  * those computations. Only when a frame is “returned” can the computations
  * be started. This should be called before returning to trigger computation.
  */
 public void Slot(TaskMaster master)
 {
     foreach (var computation in unslotted)
     {
         master.Slot(computation);
     }
 }
Esempio n. 7
0
        /**
         * Trigger any unfinished computations contained in this frame to be executed.
         *
         * When a frame is being filled, unfinished computations may be added. They
         * cannot be started immediately, since the frame may still have members to
         * be added and those changes will be visible to the lookup environments of
         * those computations. Only when a frame is “returned” can the computations
         * be started. This should be called before returning to trigger computation.
         */

        public void Slot()
        {
            foreach (var computation in unslotted)
            {
                task_master.Slot(computation);
            }
            unslotted.Clear();
        }
Esempio n. 8
0
 private void SlotHelper()
 {
     if (virgin && task_master != null)
     {
         virgin = false;
         task_master.Slot(this);
     }
 }
Esempio n. 9
0
 /**
  * This is the callback used by GetOrSubscribe. It will be called when a value is available.
  *
  * If that was not immediately, then delayed will be true, so we slot outselves for further evaluation.
  */
 private void ConsumeResult(object result)
 {
     values[frame, name++] = result;
     got_value             = true;
     if (delayed)
     {
         master.Slot(this);
     }
 }
Esempio n. 10
0
 private void HandleArgs(object result)
 {
     if (result is Frame)
     {
         var input = (Frame)result;
         Interlocked.Add(ref interlock, (int)input.Count);
         this.input = new string[input.Count];
         var index = 0;
         foreach (var name in input.GetAttributeNames())
         {
             var target_index = index++;
             input.GetOrSubscribe(name, arg => {
                 if (arg is Stringish)
                 {
                     this.input[target_index] = arg.ToString();
                     if (Interlocked.Decrement(ref interlock) == 0)
                     {
                         master.Slot(this);
                     }
                 }
                 else
                 {
                     master.ReportOtherError(source_ref, String.Format("Expected “args” to contain strings. Got {0} instead.", arg.GetType()));
                 }
             });
         }
         if (Interlocked.Decrement(ref interlock) == 0)
         {
             master.Slot(this);
         }
     }
     else
     {
         master.ReportOtherError(source_ref, String.Format("Expected “args” to be a frame. Got {0} instead.", Stringish.HideImplementation(result.GetType())));
     }
 }