internal bool TryLoadLanguage(ScriptDomainManager manager, string str, bool isExtension, out LanguageContext language)
        {
            Assert.NotNull(manager, str);

            var dict = (isExtension) ? _languageExtensions : _languageNames;

            LanguageConfiguration config;

            if (dict.TryGetValue(str, out config))
            {
                language = LoadLanguageContext(manager, config);
                return(true);
            }

            language = null;
            return(false);
        }
예제 #2
0
 public DynamicOperations(LanguageContext lc)
 {
     ContractUtils.RequiresNotNull(lc, nameof(lc));
     _lc = lc;
 }
        internal bool TryLoadLanguage(ScriptDomainManager manager, AssemblyQualifiedTypeName providerName, out LanguageContext language)
        {
            Assert.NotNull(manager);
            LanguageConfiguration config;

            if (_languageConfigurations.TryGetValue(providerName, out config))
            {
                language = LoadLanguageContext(manager, config);
                return(true);
            }

            language = null;
            return(false);
        }
예제 #4
0
 public bool TryGetLanguage(string languageName, out LanguageContext language)
 {
     ContractUtils.RequiresNotNull(languageName, nameof(languageName));
     return(Configuration.TryLoadLanguage(this, languageName, false, out language));
 }
예제 #5
0
 public bool TryGetLanguageByFileExtension(string fileExtension, out LanguageContext language)
 {
     ContractUtils.RequiresNotEmpty(fileExtension, nameof(fileExtension));
     return(Configuration.TryLoadLanguage(this, DlrConfiguration.NormalizeExtension(fileExtension), true, out language));
 }
예제 #6
0
 internal DefaultCallAction(LanguageContext context, string name, bool ignoreCase, CallInfo callInfo)
     : base(name, ignoreCase, callInfo)
 {
     _context = context;
 }
예제 #7
0
 internal DelegateInfo GenerateDelegateStub(LanguageContext context)
 {
     return(new DelegateInfo(context, _returnType, _parameters));
 }
예제 #8
0
        /// <summary>
        /// Determines if this context or any outer scope contains the defined name that
        /// is available from the provided LanguageContext.
        /// </summary>
        public bool ContainsName(LanguageContext context, SymbolId name)
        {
            object tmp;

            return(TryLookupName(context, name, out tmp));
        }
예제 #9
0
        internal static Delegate CreateDelegateForDynamicObject(LanguageContext context, object dynamicObject, Type delegateType, MethodInfo invoke)
        {
            PerfTrack.NoteEvent(PerfTrack.Categories.DelegateCreate, delegateType.ToString());

            Type returnType = invoke.ReturnType;

            ParameterInfo[] parameterInfos = invoke.GetParameters();

            var parameters = new List <ParameterExpression>();

            for (int i = 0; i < parameterInfos.Length; i++)
            {
                parameters.Add(Expression.Parameter(parameterInfos[i].ParameterType, "p" + i));
            }

            InvokeBinder  invokeBinder  = context.CreateInvokeBinder(new CallInfo(parameterInfos.Length));
            ConvertBinder convertBinder = (returnType != typeof(void)) ? context.CreateConvertBinder(returnType, explicitCast: true) : null;

            CallSite invokeSite     = CallSite.Create(DynamicSiteHelpers.MakeCallSiteDelegate(MakeSiteSignature(parameterInfos)), invokeBinder);
            Type     invokeSiteType = invokeSite.GetType();

            Type     convertSiteType;
            CallSite convertSite;

            if (convertBinder != null)
            {
                convertSite     = CallSite.Create(DynamicSiteHelpers.MakeCallSiteDelegate(typeof(object), returnType), convertBinder);
                convertSiteType = convertSite.GetType();
            }
            else
            {
                convertSiteType = null;
                convertSite     = null;
            }

            var locals = new List <ParameterExpression>();

            ParameterExpression invokeSiteVar  = Expression.Parameter(invokeSiteType, "site");
            ParameterExpression convertSiteVar = null;

            var args = new List <Expression>();

            args.Add(invokeSiteVar);
            args.Add(Expression.Constant(dynamicObject));

            int strongBoxVarsStart = locals.Count;

            for (int i = 0; i < parameterInfos.Length; i++)
            {
                if (parameterInfos[i].ParameterType.IsByRef)
                {
                    var argType = parameterInfos[i].ParameterType;

                    Type elementType  = argType.GetElementType();
                    Type concreteType = typeof(StrongBox <>).MakeGenericType(elementType);

                    var strongBox = Expression.Parameter(concreteType, "box" + i);
                    locals.Add(strongBox);

                    args.Add(
                        Expression.Assign(
                            strongBox,
                            Expression.New(
                                concreteType.GetConstructor(new Type[] { elementType }),
                                parameters[i]
                                )
                            )
                        );
                }
                else
                {
                    args.Add(parameters[i]);
                }
            }

            int strongBoxVarsEnd = locals.Count;

            Expression invocation = Expression.Invoke(
                Expression.Field(
                    Expression.Assign(
                        invokeSiteVar,
                        Expression.Convert(Expression.Constant(invokeSite), invokeSiteType)
                        ),
                    invokeSiteType.GetDeclaredField("Target")
                    ),
                args
                );

            if (convertBinder != null)
            {
                convertSiteVar = Expression.Parameter(convertSiteType, "convertSite");

                invocation = Expression.Invoke(
                    Expression.Field(
                        Expression.Assign(
                            convertSiteVar,
                            Expression.Convert(Expression.Constant(convertSite), convertSiteType)
                            ),
                        convertSiteType.GetDeclaredField("Target")
                        ),
                    convertSiteVar,
                    invocation
                    );
            }

            locals.Add(invokeSiteVar);
            if (convertSiteVar != null)
            {
                locals.Add(convertSiteVar);
            }

            Expression body;

            // copy back from StrongBox.Value
            if (strongBoxVarsEnd > strongBoxVarsStart)
            {
                var block = new Expression[1 + strongBoxVarsEnd - strongBoxVarsStart + 1];

                var resultVar = Expression.Parameter(invocation.Type, "result");
                locals.Add(resultVar);

                int b = 0;
                int l = strongBoxVarsStart;

                // values of strong boxes are initialized in invocation expression:
                block[b++] = Expression.Assign(resultVar, invocation);

                for (int i = 0; i < parameterInfos.Length; i++)
                {
                    if (parameterInfos[i].ParameterType.IsByRef)
                    {
                        var local = locals[l++];
                        block[b++] = Expression.Assign(
                            parameters[i],
                            Expression.Field(local, local.Type.GetDeclaredField("Value"))
                            );
                    }
                }

                block[b++] = resultVar;

                Debug.Assert(l == strongBoxVarsEnd);
                Debug.Assert(b == block.Length);

                body = Expression.Block(locals, block);
            }
            else
            {
                body = Expression.Block(locals, invocation);
            }

            var lambda = Expression.Lambda(delegateType, body, "_Scripting_", parameters);

            return(lambda.Compile());
        }
        public DynamicDelegateCreator(LanguageContext languageContext)
        {
            ContractUtils.RequiresNotNull(languageContext, "languageContext");

            _languageContext = languageContext;
        }
예제 #11
0
        public static ScriptCode Load(DlrMainCallTarget method, LanguageContext language, string path)
        {
            SourceUnit su = new SourceUnit(language, NullTextContentProvider.Null, path, SourceCodeKind.File);

            return(new LegacyScriptCode(null, method, su));
        }
예제 #12
0
 // emitted by GlobalRewriter
 // TODO: Python and JScript should do this
 public static CodeContext CreateTopLevelCodeContext(Scope scope, LanguageContext context)
 {
     context.EnsureScopeExtension(scope.ModuleScope);
     return(new CodeContext(scope, context));
 }
예제 #13
0
 public CodeContext(Scope scope, LanguageContext languageContext)
     : this(scope, languageContext, null)
 {
 }
예제 #14
0
 public static T CreateDelegate <T>(LanguageContext context, object callable)
 {
     return((T)(object)GetDelegate(context, callable, typeof(T)));
 }