public override Value Execute(Args args, Environment environment, SourcePos pos) { var inparg = args.Get("input"); var callback = args.Get("callback").AsFunc(); Environment env = environment.NewEnv(); if (inparg is ValueInput) { ValueInput input = inparg.AsInput(); return(new ValueInt(input.Process(line => { Args args_ = new Args(callback.GetArgNames()[0], new ValueString(line), pos); return callback.Execute(args_, env, pos); }))); } if (inparg is ValueList) { var list = inparg.AsList().GetValue(); foreach (var element in list) { Args args_ = new Args(callback.GetArgNames()[0], element.AsString(), pos); callback.Execute(args_, env, pos); } ; return(new ValueInt(list.Count)); } throw new ControlErrorException(new ValueString("ERROR"), "Cannot process lines from " + inparg, pos); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { var a = args.Get("a"); var b = args.Get("b"); return(ValueBoolean.From(a.CompareTo(b) < 0)); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { var a = args.GetInt("a").GetValue(); var b = args.GetInt("b").GetValue(); return(new ValueInt((a & b) & 4294967295L)); }
public NodeDeref(Node expression, Node index, Node defaultValue, SourcePos pos) { this.expression = expression; this.index = index; this.defaultValue = defaultValue; this.pos = pos; }
public NodeDef(string identifier, Node expression, string info, SourcePos pos) { this.identifier = identifier; this.expression = expression; this.info = info; this.pos = pos; }
public override Value Execute(Args args, Environment environment, SourcePos pos) { var arg = args.Get("obj"); if (arg.IsString()) { return(new ValueInt(arg.AsString().GetValue().Length)); } if (arg.IsList()) { return(new ValueInt(arg.AsList().GetValue().Count)); } if (arg.IsSet()) { return(new ValueInt(arg.AsSet().GetValue().Count)); } if (arg.IsMap()) { return(new ValueInt(arg.AsMap().GetValue().Count)); } if (arg.IsObject()) { return(new ValueInt(arg.AsObject().value.Count)); } throw new ControlErrorException(new ValueString("ERROR"), "Cannot determine length of " + arg, pos); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { var filename = args.GetString("filename").GetValue(); var encoding = args.GetString("encoding", "UTF-8").GetValue(); return(new ValueInput(new StreamReader(filename, encoding == "UTF-8" ? Encoding.UTF8 : Encoding.GetEncoding(encoding)))); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { var dir = args.GetString("dir").GetValue(); var recursive = false; if (args.HasArg("recursive")) { recursive = args.GetBoolean("recursive").GetValue(); } var include_path = recursive; if (args.HasArg("include_path")) { include_path = args.GetBoolean("include_path").GetValue(); } var include_dirs = false; if (args.HasArg("include_dirs")) { include_dirs = args.GetBoolean("include_dirs").GetValue(); } var result = new ValueList(); CollectFiles(dir, recursive, include_path, include_dirs, result); return(result); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { var env = environment.NewEnv(); var lst = args.GetAsList("lst"); var cmp = args.HasArg("cmp") ? args.GetFunc("cmp") : environment.Get("compare", pos).AsFunc(); var key = args.HasArg("key") ? args.GetFunc("key") : environment.Get("identity", pos).AsFunc(); var result = new List <Value>(); result.AddRange(lst.GetValue()); for (var i = 1; i < result.Count; i++) { var v = key.Execute(new Args(key.GetArgNames()[0], result[i], pos), env, pos); for (var j = i - 1; j >= 0; j--) { var v2 = key.Execute(new Args(key.GetArgNames()[0], result[j], pos), env, pos); var cmpargs = new Args(cmp.GetArgNames()[0], cmp.GetArgNames()[1], v, v2, pos); var comparison = (int)cmp.Execute(cmpargs, env, pos).AsInt().GetValue(); if (comparison < 0) { var temp = result[j + 1]; result[j + 1] = result[j]; result[j] = temp; } else { break; } } } return(new ValueList(result)); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { var seed = (int)args.GetInt("n").GetValue(); FuncRandom.random = new Random(seed); return(new ValueInt(seed)); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { var a = args.Get("a"); var b = args.Get("b"); return(new ValueInt(a.CompareTo(b))); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { var result = new ValueList(); if (!args.HasArg("module")) { foreach (var symbol in environment.GetSymbols()) { result.AddItem(new ValueString(symbol)); } } else { var moduleArg = args.Get("module"); Dictionary <string, Value> module; if (moduleArg.IsString()) { module = environment.Get(moduleArg.AsString().GetValue(), pos).AsObject().value; } else { module = args.Get("module").AsObject().value; } foreach (var symbol in module.Keys) { result.AddItem(new ValueString(symbol)); } } return(result); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { var lst = args.Get("lst"); if (!lst.IsList()) { throw new ControlErrorException(new ValueString("ERROR"), "Cannot insert into object of type " + lst.Type(), pos); } var index = (int)args.GetInt("index").GetValue(); if (index < 0) { index = lst.AsList().GetValue().Count + index + 1; } var value = args.Get("value"); var list = lst.AsList().GetValue(); if (index < 0 || index > list.Count) { return(lst); } if (index == list.Count) { list.Add(value); } else { list.Insert(index, value); } return(lst); }
public NodeDerefAssign(Node expression, Node index, Node value, SourcePos pos) { this.expression = expression; this.index = index; this.value = value; this.pos = pos; }
public override Value Execute(Args args, Environment environment, SourcePos pos) { var filename = args.GetString("filename").GetValue(); if (File.Exists(filename)) { var result = new ValueObject(); var info = new FileInfo(filename); result.AddItem("size", new ValueInt(info.Length)); result.AddItem("is_dir", ValueBoolean.FALSE); result.AddItem("modified", new ValueDate(info.LastWriteTime)); result.AddItem("created", new ValueDate(info.CreationTime)); return(result); } if (Directory.Exists(filename)) { var result = new ValueObject(); var info = new DirectoryInfo(filename); result.AddItem("is_dir", ValueBoolean.TRUE); result.AddItem("modified", new ValueDate(info.LastWriteTime)); result.AddItem("created", new ValueDate(info.CreationTime)); return(result); } return(ValueNull.NULL); }
public NodeDefDestructuring(List <string> identifiers, Node expression, string info, SourcePos pos) { this.identifiers.AddRange(identifiers); this.expression = expression; this.info = info; this.pos = pos; }
public NodeListComprehension(Node valueExpr, string identifier, Node listExpr, SourcePos pos) { this.valueExpr = valueExpr; this.identifier = identifier; this.listExpr = listExpr; this.pos = pos; }
public NodeDerefSlice(Node expression, Node start, Node end, SourcePos pos) { this.expression = expression; this.start = start; this.end = end; this.pos = pos; }
public override Value Execute(Args args, Environment environment, SourcePos pos) { var lst = args.Get("lst"); var element = args.Get("element"); try { if (lst.IsList()) { lst.AsList().GetValue().Add(element); return(lst); } if (lst.IsSet()) { lst.AsSet().GetValue().Add(element); return(lst); } } catch { // handled below } throw new ControlErrorException(new ValueString("ERROR"), "Cannot append to " + lst, pos); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { var a = args.GetInt("a").GetValue(); var n = (int)args.GetInt("n").GetValue() % 32; return(new ValueInt((a >> n) & 4294967295L)); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { var a = args.Get("a"); var b = args.Get("b"); if (a.IsNull() || b.IsNull()) { return(ValueNull.NULL); } if (a.IsList() && b.IsList()) { var lista = a.AsList().GetValue(); var listb = b.AsList().GetValue(); var result = new ValueMap(); for (var i = 0; i < Math.Min(lista.Count, listb.Count); i++) { result.AddItem(lista[i], listb[i]); } return(result); } throw new ControlErrorException(new ValueString("ERROR"), "Cannot zip_map " + a + " and " + b, pos); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("str")) { return(ValueNull.NULL); } var value = args.GetString("str").GetValue(); var start = (int)args.GetInt("startidx").GetValue(); if (start < 0) { start = value.Length + start; } if (start > value.Length) { return(new ValueString("")); } var end = (int)args.GetInt("endidx", value.Length).GetValue(); if (end < 0) { end = value.Length + end; } if (end > value.Length) { end = value.Length; } return(new ValueString(value.Substring(start, end - start))); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { var a = args.Get("a"); var b = args.Get("b"); return(ValueBoolean.From(!a.IsEquals(b))); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("lst")) { return(ValueNull.NULL); } var value = args.GetList("lst").GetValue(); var start = (int)args.GetInt("startidx").GetValue(); if (start < 0) { start = value.Count + start; } if (start > value.Count) { return(new ValueList()); } var end = (int)args.GetInt("endidx", value.Count).GetValue(); if (end < 0) { end = value.Count + end; } if (end > value.Count) { end = value.Count; } var result = new ValueList(); for (var i = start; i < end; i++) { result.AddItem(value[i]); } return(result); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { var m = args.GetMap("m"); m.GetValue()[args.Get("key")] = args.Get("value"); return(m); }
public NodeRequire(Node modulespec, string name, bool unqualified, Dictionary <string, string> symbols, SourcePos pos) { this.modulespec = modulespec; this.name = name; this.unqualified = unqualified; this.symbols = symbols; this.pos = pos; }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("x")) { return(ValueNull.NULL); } return(new ValueDecimal((decimal)Math.Sqrt((double)args.GetNumerical("x").GetValue()))); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("n")) { return(ValueNull.NULL); } return(new ValueString(char.ConvertFromUtf32((int)args.GetInt("n").GetValue()).ToString())); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("ch")) { return(ValueNull.NULL); } return(new ValueInt(char.ConvertToUtf32(args.GetString("ch").GetValue(), 0))); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("str")) { return(ValueBoolean.FALSE); } return(ValueBoolean.From(args.GetString("str").GetValue().Contains(args.GetString("part").GetValue()))); }