public override object this[object key] { get { return(base[key]); } set { Builtins.AssertionViolation("hashtable-set!", "hashtable is readonly", this); } }
protected static bool AssignParameters(CodeBlock cb, object arg, object types) { bool isrest = false; Cons cargs = arg as Cons; Cons ctypes = types as Cons; if (cargs != null) { while (cargs != null) { SymbolId an = (SymbolId)Builtins.First(cargs); if (ctypes == null) { Builtins.SyntaxError("AssignParameters", "missing parameter type", Builtins.UnGenSymInternal(an), Builtins.FALSE); } object type = Builtins.First(ctypes); Type clrtype = ClrGenerator.ExtractTypeInfo(Builtins.List(quote, type)); CreateParameter(an, cb, clrtype); Cons r = cargs.cdr as Cons; Cons rt = ctypes.cdr as Cons; // not sure I can even handle this... if (r == null && cargs.cdr != null) { SymbolId ta = (SymbolId)cargs.cdr; CreateParameter(ta, cb, typeof(object)); isrest = true; break; } else { cargs = r; ctypes = rt; } } if (ctypes != null) { Builtins.SyntaxError("AssignParameters", "extra parameter type(s)", ctypes, Builtins.FALSE); } } else if (arg != null) // empty { SymbolId an = (SymbolId)arg; isrest = true; CreateParameter(an, cb, typeof(object)); } // else both null, which is OK, no? return(isrest); }
public override Expression Generate(object args, CodeBlock cb) { var to = Builtins.First(args); Type t = ExtractTypeInfo(to); if (t == null) { ClrSyntaxError("clr-type-of", "type not found", to, Cons.FromList(namespaces.Keys)); } return(Ast.Constant(t)); }
public static Variable DownCall(Variable list) { List <object> lo = new List <object>(); VarDeque it = Builtins.start_iter(list); while (Kernel.IterHasFlat(it, true)) { lo.Add(DCArg(it.Shift())); } return(DCResult(RawDowncall(lo.ToArray()))); }
public override void EmitCreation(CodeGen cg) { if (Builtins.IsTrue(Builtins.IsSymbolBound(RtdSymbol))) { var rtd = Builtins.SymbolValue(RtdSymbol); var pcd = ParentRcd; var prt = Builtins.SymbolValue(Protocol); var cd = Records.MakeRecordConstructorDescriptor(rtd, pcd, prt); Builtins.SetSymbolValueFast(NameHint, cd); } }
// (clr-field-set! type field-name obj value) public override Expression Generate(object args, CodeBlock cb) { Type t = null; string type = null; bool inferred = false; object rtype = Builtins.First(args); ExtractTypeInfo(rtype, out t, out type, out inferred); string member = SymbolTable.IdToString((SymbolId)Builtins.Second(Builtins.Second(args))); BindingFlags bf = BindingFlags.Instance; Expression instance = GetAst(Builtins.Third(args), cb); if (instance is ConstantExpression && ((ConstantExpression)instance).Value == null) { bf = BindingFlags.Static; instance = null; if (inferred) { ClrSyntaxError("clr-field-set!", "type inference not possible on static member", member); } } else if (inferred) { if (instance is UnaryExpression && instance.Type == typeof(object)) { var ue = (UnaryExpression)instance; instance = ue.Operand; } t = instance.Type; } else { instance = ConvertToHelper(t, instance); } type = t.Name; FieldInfo fi = t.GetField(member, BindingFlags.Public | bf | BindingFlags.FlattenHierarchy); if (fi == null) { ClrSyntaxError("clr-field-set!", "field not found on type: " + type, args); } Expression value = GetAst(Builtins.Car(Builtins.LastPair(args)), cb); return(Ast.Comma(Ast.AssignField(instance, fi, value), Ast.ReadField(null, Unspecified))); }
public static Variable cb_downcall(Variable list) { List <object> lo = new List <object>(); VarDeque it = Builtins.start_iter(list); while (Kernel.IterHasFlat(it, true)) { lo.Add(Downcaller.DCArg(it.Shift())); } return(Downcaller.DCResult(list.Fetch().mo.setting, Downcaller.RawDowncall(lo.ToArray()))); }
private void CheckVariableAvailable(string name, string nameOf, bool prefix) { if (Units.ContainsKey(name)) { throw new ArgumentException(prefix ? $"The name with prefix `{name}` is already used by another unit." : $"The name `{name}` is already used by another unit.", nameOf); } if (Builtins.ContainsKey(name)) { throw new ArgumentException(prefix ? $"The name with prefix `{name}` is already used a builtin variable or function." : $"The name `{name}` is already used a builtin variable or function.", nameOf); } }
public override DecoderFallbackBuffer CreateFallbackBuffer() { if (error == null) { Builtins.IODecodingError(); } else { error.Call(); } return(null); }
public static Variable ucd_get_ranges(Variable tbl, Variable sm) { Property p = (Property)DataSet.GetTable( tbl.Fetch().mo.mro_raw_Str.Get(tbl)); int[] rranges = p.GetRanges(sm); Variable[] cranges = new Variable[rranges.Length]; for (int i = 0; i < rranges.Length; i++) { cranges[i] = Builtins.MakeInt(rranges[i]); } return(Builtins.MakeParcel(cranges)); }
private Dispatcher Create(SetOrGet gos) { MemberInfo[] candidates = _type.GetMember(_name, MemberTypes.Property | MemberTypes.Field, RuntimeServices.DefaultBindingFlags); if (candidates.Length == 0) { return(FindExtension(GetCandidateExtensions(gos))); } if (candidates.Length > 1) { throw new AmbiguousMatchException(Builtins.join(candidates, ", ")); } return(EmitDispatcherFor(candidates[0], gos)); }
// (clr-reference assname) public override Expression Generate(object args, CodeBlock cb) { Assembly ass = null; object name = Builtins.Second(Builtins.First(args)); string assname = null; if (name is SymbolId) { assname = SymbolTable.IdToString((SymbolId)name);//.Replace(".dll", ""); } else if (name is string) { assname = (string)name; } else { ClrSyntaxError("clr-reference", "reference is not a symbol or a string", name); } try { var aname = AssemblyName.GetAssemblyName(assname); ass = Assembly.Load(aname); } catch (FileNotFoundException) { try { ass = Assembly.Load(assname); } catch (FileNotFoundException) { // final fail, after AssemblyResolve } } if (ass == null) { // last chance #pragma warning disable 0618 ass = Assembly.LoadWithPartialName(assname); #pragma warning restore 0618 } if (ass == null) { ClrSyntaxError("clr-reference", "assembly not found", args); } return(Ast.ReadField(null, Unspecified)); }
static void AddReadOnlyAttr( Analyzer analyzer, FunType fun, string name, DataType type, BindingKind kind) { Node loc = Builtins.newDataModelUrl("the-standard-type-hierarchy"); Binding b = analyzer.CreateBinding(name, loc, type, kind); fun.Table.Update(name, b); b.IsSynthetic = true; b.IsStatic = true; }
private MemberInfo ResolveMember() { MemberInfo[] candidates = _type.GetMember(_name, MemberTypes.Property | MemberTypes.Field, RuntimeServices.DefaultBindingFlags); if (candidates.Length == 0) { throw MissingField(); } if (candidates.Length > 1) { throw new AmbiguousMatchException(Builtins.join(candidates, ", ")); } return(candidates[0]); }
static Expression InlineCall(CodeBlock parent, CodeBlockExpression cbe, params Expression[] pp) { // all var names are unique. CodeBlock cb = cbe.Block; List <Statement> assigns = new List <Statement>(); int i = 0; cb.Inlined = true; var parentvars = new List <Variable>(parent.Variables); foreach (Variable p in cb.Parameters) { SymbolId origname = p.Name; p.Name = (SymbolId)Builtins.GenSym(p.Name); p.Block = parent; p.Kind = Variable.VariableKind.Local; parent.AddVariable(p); assigns.Add(Ast.Write(p, pp[i])); if (p.Lift) { parent.HasEnvironment = true; } i++; } foreach (Variable l in cb.Variables) { if (l.DefaultValue == null && l.Kind != Variable.VariableKind.Global) { l.Name = (SymbolId)Builtins.GenSym(l.Name); } l.Block = parent; parent.AddVariable(l); if (l.Lift) { parent.HasEnvironment = true; } } assigns.Add(cb.Body); return(Ast.Void(Ast.Block(assigns))); }
static bool IsSimpleExpression(Expression e) { if (e is MethodCallExpression) { return(IsSimpleCall((MethodCallExpression)e)); } if (e is UnaryExpression) { UnaryExpression ue = (UnaryExpression)e; if (ue.NodeType == AstNodeType.Convert) { return(IsSimpleExpression(ue.Operand)); } return(false); } if (e is BinaryExpression) { return(IsSimpleExpression(((BinaryExpression)e).Left) && IsSimpleExpression(((BinaryExpression)e).Right)); } if (e is TypeBinaryExpression) { return(IsSimpleExpression(((TypeBinaryExpression)e).Expression)); } if (e is ConstantExpression) { ConstantExpression ce = (ConstantExpression)e; return(Builtins.IsTrue(ce.Value)); } if (e is ConditionalExpression) { ConditionalExpression ce = (ConditionalExpression)e; return(IsSimpleExpression(ce.Test) && IsSimpleExpression(ce.IfTrue) && IsSimpleExpression(ce.IfFalse)); } if (e is BoundExpression) { return(true); } else { return(false); } }
internal IronSchemeLanguageProvider(ScriptDomainManager x) : base(x) { ScriptDomainManager.Options.DynamicStackTraceSupport = false; Runtime.Closure.ConsFromArray = Runtime.Cons.FromArray; Runtime.Closure.ConsStarFromArray = delegate(object[] args) { return(Builtins.ToImproper(Cons.FromArray(args))); }; Runtime.Closure.Unspecified = Builtins.Unspecified; Runtime.Closure.ArrayFromCons = Builtins.ListToVector; Initialize(); // only register when done x.RegisterLanguageProvider("IronScheme", "IronScheme.Hosting.IronSchemeLanguageProvider", ".sps", ".ss", ".sls"); }
private bool BuildSetterAutoAssign(DAssignment node, Hints hints, CompilerContext ctx) { var acc = (DAccess)node.Target; Build(acc.Target, hints.Remove(Last).Append(Push), ctx); cw.GetMember(Builtins.Setter(acc.Name)); cw.FunPrep(1); EmitGetter(acc.Target, acc.Name, hints, ctx); Build(node.Value, hints.Append(Push), ctx); EmitBinaryOp(node.AutoAssign !.Value); cw.FunArgIx(0); cw.FunCall(1); PopIf(hints); return(true); }
public void ProcessRequest(HttpContext context) { if (lp == null) { lp = Helpers.Provider as IronSchemeLanguageProvider; se = lp.GetEngine(); RuntimeExtensions.Eval("(library-path (cons {0} (library-path)))", context.Server.MapPath("~/lib")); compiled.Clear(); } if (!File.Exists(context.Request.PhysicalPath)) { if (context.Request.AppRelativeCurrentExecutionFilePath == "~/process-routes.ss") { if (process_routes == null) { Callable eval = Builtins.SymbolValue(SymbolTable.StringToObject("eval-r6rs")) as Callable; StringReader r = new StringReader("(eval 'process-request (environment '(ironscheme web routing)))"); process_routes = eval.Call(Builtins.Read(r)) as Callable; } process_routes.Call(); } else { context.Response.StatusCode = 404; } return; } Compiled cc; lock (GLOBALLOCK) { if (!compiled.TryGetValue(context.Request.PhysicalPath, out cc) || cc.Time < File.GetLastWriteTime(context.Request.PhysicalPath) || cc.Closure == null) { Callable ccc = se.Evaluate(string.Format("(compile->closure \"{0}\")", context.Request.PhysicalPath.Replace('\\', '/'))) as Callable; cc = new Compiled(); cc.Time = DateTime.Now; cc.Closure = ccc; compiled[context.Request.PhysicalPath] = cc; } } cc.Closure.Call(); }
// (clr-using namespace) public override Expression Generate(object args, CodeBlock cb) { object name = Builtins.Second(Builtins.First(args)); string assname = null; if (name is SymbolId) { assname = SymbolTable.IdToString((SymbolId)name); namespaces[assname] = assname; } else { ClrSyntaxError("clr-using", "namespace is not a symbol", name); } return(Ast.ReadField(null, Unspecified)); }
public void Help(ScriptExpression expression = null) { var name = expression?.ToString(); if (name != null) { if (Descriptors.TryGetValue(name, out var descriptor)) { WriteHelpForDescriptor(descriptor); return; } throw new ArgumentException($"The builtin function `{name}` does not exist", nameof(expression)); } WriteHighlightLine($"# help [name]"); // Verify that all function/modules belong to a category var invalidRegistered = Descriptors.FirstOrDefault(x => x.Value.Category == null); if (invalidRegistered.Value != null) { throw new InvalidOperationException($"The function or module `{invalidRegistered.Key}` doesn't have a category. This is an invalid state of the program"); } var categoryToDescriptors = Descriptors.GroupBy(x => x.Value.Category).ToDictionary(x => x.Key, y => y.Select(x => x.Value).Distinct().ToList()); WriteHighlightLine($"#"); foreach (var categoryPair in categoryToDescriptors.OrderBy(x => x.Key)) { var list = categoryPair.Value; // Exclude from the list modules that have been already imported var names = list.SelectMany(x => x.Names).Where(funcName => Builtins.TryGetValue(funcName, out var funcObj) && (!(funcObj is KalkModuleWithFunctions module) || !module.IsImported) ).OrderBy(x => x).ToList(); if (names.Count > 0) { WriteHighlightLine($"# {categoryPair.Key}"); WriteHighlightAligned(" - ", string.Join(", ", names)); WriteHighlightLine(""); } } }
// (clr-is type arg) public override Expression Generate(object args, CodeBlock cb) { Type t; string type; bool inferred; object rtype = Builtins.First(args); ExtractTypeInfo(rtype, out t, out type, out inferred); if (t == null) { ClrSyntaxError("clr-is", "type not found", type); } return(Ast.TypeIs(GetAst(Builtins.Second(args), cb), t)); }
private static void Test() { const int items = 2000000; object[] array = (object[])new List(Builtins.range(items)).ToArray(typeof(object)); List collect = new List(); DateTime start = DateTime.Now; foreach (int i in Builtins.range(items)) { collect.Add(array[i]); } TimeSpan elapsed = DateTime.Now.Subtract(start); Console.WriteLine("{0} elapsed.", elapsed.TotalMilliseconds); }
private Dispatcher Create(SetOrGet gos) { #if !DNXCORE50 MemberInfo[] candidates = _type.GetMember(_name, MemberTypes.Property | MemberTypes.Field, RuntimeServices.DefaultBindingFlags); #else MemberInfo[] candidates = _type.GetMember(_name, RuntimeServices.DefaultBindingFlags); candidates = candidates.Where((v) => v.MemberType == MemberTypes.Property || v.MemberType == MemberTypes.Field).ToArray(); #endif if (candidates.Length == 0) { return(FindExtension(GetCandidateExtensions(gos))); } if (candidates.Length > 1) { throw new AmbiguousMatchException(Builtins.join(candidates, ", ")); } return(EmitDispatcherFor(candidates[0], gos)); }
public override object this[object i] { set { } get { object[] ia = (object[])i; Variable[] va = new Variable[ia.Length]; var cb = Downcaller.upcall_cb.Fetch(); for (int ix = 0; ix < ia.Length; ix++) { va[ix] = Downcaller.DCResult(cb.mo.setting, ia[ix]); } try { Variable vr = Builtins.InvokeSub(cb, va); return(Downcaller.DCArg(vr)); } catch (Exception ex) { return(new Exception(ex.ToString())); } } }
internal static object ReadExpressions(Stream code, CompilerContext cc) { if (parser == null) { parser = new Parser(); } Parser p = parser; Scanner sc = new Scanner(code, "GUESS"); p.scanner = sc; sc.SourceUnit = cc.SourceUnit; sc.Errors = cc.Errors; if (p.Parse()) { return(p.parsed); } return(Builtins.LexicalError("invalid syntax", code)); }
public static void Main(string[] args) { var fn = Builtins.CreateNamedFunction <Func <int, int> >( "Test", new[] { "argInt" }, @"return argInt + closureInt;", new { closureInt = 2 } ); if (fn == null) { Console.WriteLine("fn == null"); } else { Console.WriteLine(fn(1)); } }
public void ComplexXml() { this.PropertyBag.Add("Numbers", Builtins.range(10)); var expected = @" 0,1,2,3,4,5,6,7,8,9, html string <ol> <li>0</li> <li>1</li> <li>2</li> </ol>"; ProcessView_StripRailsExtension("Xml/Complex.rails"); AssertReplyEqualTo(expected); }
protected static bool AssignParameters(CodeBlock cb, object arg, object types) { bool isrest = false; Cons cargs = arg as Cons; Cons ctypes = types as Cons; if (cargs != null) { while (cargs != null) { SymbolId an = (SymbolId)Builtins.First(cargs); object type = Builtins.First(ctypes); Type clrtype = ClrGenerator.ExtractTypeInfo(Builtins.List(quote, type)); CreateParameter(an, cb, clrtype); Cons r = cargs.cdr as Cons; Cons rt = ctypes.cdr as Cons; if (r == null && cargs.cdr != null) { SymbolId ta = (SymbolId)cargs.cdr; CreateParameter(ta, cb, typeof(object)); isrest = true; break; } else { cargs = r; ctypes = rt; } } } else if (arg != null) // empty { SymbolId an = (SymbolId)arg; isrest = true; CreateParameter(an, cb, typeof(object)); } return(isrest); }
public override void Write(byte[] buffer, int offset, int count) { if (HasPosition) { long pos = Position; int written = Convert.ToInt32(write.Call(buffer, offset, count)); if (written != count && written != (Position - pos)) { Builtins.AssertionViolation("write!", "position does not match number of bytes written"); } } else { int written = Convert.ToInt32(write.Call(buffer, offset, count)); if (written != count) { Builtins.AssertionViolation("write!", "could not write all the bytes"); } } }