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)); }
public Instantiation(TaskMaster task_master, SourceReference src_ref, Context context, Frame container, params string[] names) : base(task_master) { this.src_ref = src_ref; this.context = context; this.container = container; this.names = names; }
public Frame(long id, SourceReference source_ref, Context context, Frame container) { this.SourceReference = source_ref; this.Context = context; this.Container = container; this.Id = TaskMaster.OrdinalName(id); }
/** * 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); } }
public CharacterCategory(TaskMaster task_master, SourceReference source_ref, Context context, Frame self, Frame container) : base(task_master) { this.source_reference = source_ref; this.context = context; this.container = self; }
public ParseInt(TaskMaster master, SourceReference source_ref, Context context, Frame self, Frame container) { this.master = master; this.source_reference = source_ref; this.context = context; }
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); }
public Computation ResolveUri(TaskMaster master, string uri, out LibraryFailure reason) { if (!uri.StartsWith("http:") && !uri.StartsWith("https:")) { reason = LibraryFailure.Missing; return(null); } reason = LibraryFailure.None; var src_ref = new NativeSourceReference(uri); try { var response = WebRequest.Create(uri).GetResponse(); var frame = new FixedFrame("http" + uri.GetHashCode(), src_ref); var data = new byte[response.ContentLength]; var stream = response.GetResponseStream(); for (var offset = 0; offset < data.Length; offset += stream.Read(data, offset, data.Length - offset)) { ; } frame.Add("data", data); frame.Add("content_type", response.ContentType); return(new Precomputation(frame)); } catch (Exception e) { return(new FailureComputation(master, src_ref, e.Message)); } }
public Computation ResolveUri(TaskMaster task_master, string uri, out LibraryFailure reason) { if (!uri.StartsWith("sql:")) { reason = LibraryFailure.Missing; return(null); } reason = LibraryFailure.None; try { var param = new Dictionary <string, string>(); int first_colon = 5; while (first_colon < uri.Length && uri[first_colon] != ':') { first_colon++; } if (first_colon >= uri.Length) { return(new FailureComputation(task_master, new ClrSourceReference(), "Bad provider in URI “" + uri + "”.")); } var provider = uri.Substring(4, first_colon - 4); int question_mark = first_colon; while (question_mark < uri.Length && uri[question_mark] != '?') { question_mark++; } var uri_fragment = uri.Substring(first_colon + 1, question_mark - first_colon - 1); if (question_mark < uri.Length - 1) { foreach (var param_str in uri.Substring(question_mark + 1).Split(new [] { '&' })) { if (param_str.Length == 0) { continue; } var parts = param_str.Split(new [] { '=' }, 2); if (parts.Length != 2) { return(new FailureComputation(task_master, new ClrSourceReference(), "Bad parameter “" + param_str + "”.")); } param[parts[0]] = parts[1]; } } string error; var connection = DbParser.Parse(provider, uri_fragment, param, out error); if (connection == null) { return(new FailureComputation(task_master, new ClrSourceReference(), error ?? "Bad URI.")); } connection.Open(); var connection_proxy = ReflectedFrame.Create(task_master, connection, connection_hooks); connection_proxy.Set("provider", new SimpleStringish(provider)); return(new Precomputation(connection_proxy)); } catch (Exception e) { return(new FailureComputation(task_master, new ClrSourceReference(e), e.Message)); } }
public Escape(TaskMaster task_master, SourceReference source_ref, Context context, Frame self, Frame container) : base(task_master) { this.source_ref = source_ref; this.context = context; this.self = self; }
public StringToCodepoints(TaskMaster task_master, SourceReference source_ref, Context context, Frame self, Frame container) : base(task_master) { this.source_reference = source_ref; this.context = context; this.container = self; }
public Frame(TaskMaster task_master, long id, SourceReference source_ref, Context context, Frame container) { this.task_master = task_master; SourceReference = source_ref; Context = Context.Prepend(this, context); Container = container ?? this; Id = TaskMaster.OrdinalName(id); }
protected override bool Run() { if (!state) { var input_lookup = new Lookup(master, source_ref, new [] { "args" }, context); input_lookup.Notify(HandleArgs); master.Slot(input_lookup); var transformation_lookup = new Lookup(master, source_ref, new [] { "transformations" }, context); transformation_lookup.Notify(HandleTransformations); master.Slot(transformation_lookup); state = true; if (Interlocked.Decrement(ref interlock) > 0) { return(false); } } var output_frame = new Frame(master, master.NextId(), source_ref, context, self); for (var index = 0; index < input.Length; index++) { var buffer = new StringBuilder(); for (var it = 0; it < input[index].Length; it += Char.IsSurrogatePair(input[index], it) ? 2 : 1) { var c = Char.ConvertToUtf32(input[index], it); var is_surrogate = Char.IsSurrogatePair(input[index], it); string replacement; if (single_substitutions.TryGetValue(c, out replacement)) { buffer.Append(replacement); } else { bool matched = false; foreach (var range in ranges.Values) { if (c >= range.start && c <= range.end) { var utf8 = new byte[4]; Encoding.UTF8.GetBytes(input[index], it, is_surrogate ? 2 : 1, utf8, 0); buffer.Append(String.Format(range.replacement, c, (int)input[index][it], is_surrogate ? (int)input[index][it + 1] : 0, (int)utf8[0], (int)utf8[1], (int)utf8[2], (int)utf8[3])); matched = true; break; } } if (!matched) { buffer.Append(Char.ConvertFromUtf32(c)); } } } output_frame[TaskMaster.OrdinalNameStr(index)] = new SimpleStringish(buffer.ToString()); } result = output_frame; return(true); }
public Lookup(TaskMaster master, SourceReference source_ref, Context context, string[] names) { this.master = master; this.SourceReference = source_ref; this.names = names; /* Create grid where the first entry is the frame under consideration. */ var values = new object[context.Length, names.Length + 1]; context.Fill((index, frame) => values[index, 0] = frame); }
public Computation ResolveUri(TaskMaster master, string uri, out LibraryFailure reason) { if (!uri.StartsWith("settings:")) { reason = LibraryFailure.Missing; return(null); } var setting = ConfigurationManager.AppSettings[HttpUtility.UrlDecode(uri.Substring(9))]; reason = LibraryFailure.None; return(new Precomputation(setting == null ? (object)Unit.NULL : (object)new SimpleStringish(setting))); }
public Computation ResolveUri(TaskMaster master, string uri, out LibraryFailure reason) { reason = LibraryFailure.Missing; if (!uri.StartsWith("current:")) { return(null); } if (information.ContainsKey(uri.Substring(8))) { reason = LibraryFailure.None; return(information[uri.Substring(8)]); } return(null); }
public Lookup(TaskMaster task_master, SourceReference source_ref, string[] names, Context context) : base(task_master) { SourceReference = source_ref; this.names = names; /* Create grid where the first entry is the frame under consideration. */ frames = new Frame[context.Length]; var index = 0; foreach (var frame in context.Fill()) { frames[index++] = frame; } }
public Computation ResolveUri(TaskMaster master, string uri, out LibraryFailure reason) { if (!uri.StartsWith("ftp:") && !uri.StartsWith("ftps:")) { reason = LibraryFailure.Missing; return(null); } reason = LibraryFailure.None; try { return(new Precomputation(new WebClient().DownloadData(uri))); } catch (Exception e) { return(new FailureComputation(master, new NativeSourceReference(uri), e.Message)); } }
public Computation ResolveUri(TaskMaster master, string uri, out LibraryFailure reason) { if (!uri.StartsWith("file:")) { reason = LibraryFailure.Missing; return(null); } reason = LibraryFailure.None; try { return(new Precomputation(File.ReadAllBytes(new Uri(uri).LocalPath))); } catch (Exception e) { return(new FailureComputation(master, new NativeSourceReference(uri), e.Message)); } }
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); }
public static Frame Through(TaskMaster task_master, long id, SourceReference source_ref, long start, long end, Context context, Frame container) { var result = new Frame(task_master, id, source_ref, context, container); if (end < start) { return(result); } for (long it = 0; it <= (end - start); it++) { result[TaskMaster.OrdinalNameStr(it + 1)] = start + it; } return(result); }
public Computation ResolveUri(TaskMaster task_master, string uri, out LibraryFailure reason) { var type = loader.ResolveUri(uri, out reason); if (reason != LibraryFailure.None || type == null) { return(null); } if (!typeof(Computation).IsAssignableFrom(type)) { throw new InvalidCastException(String.Format( "Class {0} for URI {1} from {2} is not a computation.", type, uri, UriName)); } return((Computation)Activator.CreateInstance(type, task_master)); }
public Computation ResolveUri(TaskMaster task_master, string uri, out LibraryFailure reason) { if (!uri.StartsWith("env:")) { reason = LibraryFailure.Missing; return(null); } var name = uri.Substring(4); if (!Regex.IsMatch(name, "[A-Z_][A-Z0-9_]*")) { reason = LibraryFailure.BadName; return(null); } reason = LibraryFailure.None; var content = Environment.GetEnvironmentVariable(name); return(new Precomputation(content == null ? (object)Unit.NULL : new SimpleStringish(content))); }
public Computation ResolveUri(TaskMaster master, string uri, out LibraryFailure reason) { if (!uri.StartsWith("res:")) { reason = LibraryFailure.Missing; return(null); } var tail = HttpUtility.UrlDecode(uri.Substring(4)).Replace('/', Path.DirectorySeparatorChar); try { foreach (var filename in Finder.FindAll(tail, "")) { reason = LibraryFailure.None; return(new Precomputation(File.ReadAllBytes(filename))); } reason = LibraryFailure.Missing; return(null); } catch (Exception e) { reason = LibraryFailure.None; return(new FailureComputation(master, new NativeSourceReference(uri), e.Message)); } }
public PrintResult(TaskMaster task_master, Computation source, string output_filename) { this.task_master = task_master; this.source = source; this.output_filename = output_filename; }
public ParseDouble(TaskMaster master, SourceReference source_ref, Context context, Frame self, Frame container) : base(master) { this.source_reference = source_ref; this.context = context; }
public Computation(TaskMaster task_master) { this.task_master = task_master; }
public MutableFrame(TaskMaster task_master, SourceReference source_ref, Context context, Frame container) : base(task_master, source_ref, context, container) { }
public void Set(long ordinal, object value) { Set(TaskMaster.OrdinalNameStr(ordinal), value); }
private ReflectedFrame(TaskMaster task_master, SourceReference source_ref, Object backing, IDictionary <string, object> attributes) : base(task_master, source_ref, null, null) { Backing = backing; this.attributes = attributes; }