Example #1
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);
            }
        }
Example #2
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);
        }
Example #3
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);
        }
Example #4
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())));
     }
 }
Example #5
0
 protected override bool Run()
 {
     task_master.ReportOtherError(source_reference, message);
     return(false);
 }