Ejemplo n.º 1
0
        public static ReflectedFrame Create <T>(TaskMaster task_master, T backing,
                                                IDictionary <string, Func <T, object> > accessors)
        {
            var attributes = accessors.ToDictionary(pair => pair.Key, pair => {
                object result = pair.Value(backing);
                if (result == null)
                {
                    result = Unit.NULL;
                }
                else if (result is Boolean || result is Double ||
                         result is Int64 || result is Frame ||
                         result is Stringish ||
                         result is Template || result is Unit)
                {
                }
                else if (result is string)
                {
                    result = new SimpleStringish((String)result);
                }
                else
                {
                    throw new InvalidCastException("Value for " + pair.Key
                                                   + " is non-Flabbergast type "
                                                   + result.GetType() + ".");
                }
                return(result);
            });

            return(new ReflectedFrame(task_master, new ClrSourceReference(),
                                      backing, attributes));
        }
Ejemplo n.º 2
0
        protected override bool Run()
        {
            if (input == null)
            {
                Computation input_lookup = new Lookup(task_master, source_reference, new [] { "arg" }, context);
                input_lookup.Notify(input_result => {
                    if (input_result is byte[])
                    {
                        input = (byte[])input_result;
                        if (Interlocked.Decrement(ref interlock) == 0)
                        {
                            task_master.Slot(this);
                        }
                    }
                    else
                    {
                        task_master.ReportOtherError(source_reference, "Input argument must be a Bin.");
                    }
                });

                Computation encoding_lookup = new Lookup(task_master, source_reference, new [] { "encoding" }, context);
                encoding_lookup.Notify(encoding_result => {
                    if (encoding_result is long)
                    {
                        var index = (long)encoding_result;
                        if (index >= 0 && index < encodings.Length)
                        {
                            encoding = encodings[index];
                            if (Interlocked.Decrement(ref interlock) == 0)
                            {
                                task_master.Slot(this);
                                return;
                            }
                        }
                    }
                    task_master.ReportOtherError(source_reference, "Invalid encoding.");
                });

                if (Interlocked.Decrement(ref interlock) > 0)
                {
                    return(false);
                }
            }
            try {
                result = new SimpleStringish(encoding.GetString(input));
                return(true);
            } catch (DecoderFallbackException e) {
                task_master.ReportOtherError(source_reference, String.Format("Cannot decode byte {0}.", e.Index));
                return(false);
            }
        }
Ejemplo n.º 3
0
 public void Add(string name, string val)
 {
     attributes[name] = new SimpleStringish(val);
 }