public static bool IsStrongBox(object target) { Type t = CompilerHelpers.GetType(target); return(IsStrongBox(t)); }
public Expression MakeExpression(ActionBinder binder, StandardRule rule, Expression[] parameters) { MethodBinderContext context = new MethodBinderContext(binder, rule); Expression check = Ast.True(); if (_binder.IsBinaryOperator) { // TODO: only if we have a narrowing level // need to emit check to see if args are convertible... for (int i = 0; i < _argBuilders.Count; i++) { Expression checkedExpr = _argBuilders[i].CheckExpression(context, parameters); if (checkedExpr != null) { check = Ast.AndAlso(check, checkedExpr); } } } Expression[] args = new Expression[_argBuilders.Count]; for (int i = 0; i < _argBuilders.Count; i++) { args[i] = _argBuilders[i].ToExpression(context, parameters); } MethodInfo mi = Method as MethodInfo; Expression ret, call; if (!Method.IsPublic || !Method.DeclaringType.IsVisible) { if (mi != null) { mi = CompilerHelpers.GetCallableMethod(mi); } } if (Method.IsPublic && Method.DeclaringType.IsVisible) { // public method if (mi != null) { Expression instance = mi.IsStatic ? null : _instanceBuilder.ToExpression(context, parameters); call = Ast.SimpleCallHelper(instance, mi, args); } else { call = Ast.SimpleNewHelper((ConstructorInfo)Method, args); } } else { // Private binding, invoke via reflection if (mi != null) { Expression instance = mi.IsStatic ? null : _instanceBuilder.ToExpression(context, parameters); call = Ast.Call( Ast.RuntimeConstant(mi), typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }), Ast.ConvertHelper(instance, typeof(object)), Ast.NewArrayHelper(typeof(object[]), args) ); } else { call = Ast.Call( Ast.RuntimeConstant((ConstructorInfo)Method), typeof(ConstructorInfo).GetMethod("Invoke", new Type[] { typeof(object[]) }), Ast.NewArrayHelper(typeof(object[]), args) ); } } ret = _returnBuilder.ToExpression(context, _argBuilders, parameters, call); List <Expression> updates = null; for (int i = 0; i < _argBuilders.Count; i++) { Expression next = _argBuilders[i].UpdateFromReturn(context, parameters); if (next != null) { if (updates == null) { updates = new List <Expression>(); } updates.Add(next); } } if (updates != null) { updates.Insert(0, ret); ret = Ast.Comma(0, updates.ToArray()); } if (!check.IsConstant(true)) { ret = Ast.Condition( check, Ast.ConvertHelper(ret, typeof(object)), GetNotImplemented() ); } return(ret); }
protected override CodeGen CreateCodeGen(ScriptCode scriptCode) { return(CompilerHelpers.CreateDynamicCodeGenerator(scriptCode.CompilerContext)); }
public object CreateTupleInstance() { return(Tuple.MakeTuple(TupleType, CompilerHelpers.MakeRepeatedArray <object>(null, _slots.Count))); }