/// <summary>
        /// Creates the methods and optimized Scope's which get associated with each ScriptCode.
        /// </summary>
        private Scope CompileOptimizedScope()
        {
            DlrMainCallTarget     target;
            IAttributesCollection globals;

            if (UseLightweightScopes)
            {
                CompileWithArrayGlobals(out target, out globals);
            }
            else
            {
                CompileWithStaticGlobals(out target, out globals);
            }

            // Force creation of names used in other script codes into all optimized dictionaries
            Scope scope = new Scope(globals);

            ((IModuleDictionaryInitialization)globals).InitializeModuleDictionary(new CodeContext(scope, LanguageContext));

            // everything succeeded, commit the results
            _optimizedTarget = target;
            _optimizedScope  = scope;

            return(scope);
        }
        public OptimizedScriptCode(Scope optimizedScope, DlrMainCallTarget optimizedTarget, SourceUnit sourceUnit)
            : base(sourceUnit) {
            ContractUtils.RequiresNotNull(optimizedScope, "optimizedScope");

            _optimizedScope = optimizedScope;
            _optimizedTarget = optimizedTarget;
        }
        public LegacyScriptCode(LambdaExpression code, DlrMainCallTarget target, SourceUnit sourceUnit) : base(sourceUnit)
        {
            ContractUtils.RequiresNotNull(sourceUnit, "sourceUnit");

            _target = target;
            _code   = code;
        }
        private void CompileWithStaticGlobals(out DlrMainCallTarget target, out IAttributesCollection globals)
        {
            // Create typegen
            TypeGen typeGen = Snippets.Shared.DefineType(MakeDebugName(), typeof(CustomSymbolDictionary), false, SourceUnit.EmitDebugSymbols);

            typeGen.TypeBuilder.DefineDefaultConstructor(MethodAttributes.Public);

            // Create rewriter
            GlobalStaticFieldRewriter rewriter = new GlobalStaticFieldRewriter(typeGen);

            // Compile lambda
            LambdaExpression lambda = rewriter.RewriteLambda(Code, "Initialize");

            lambda.CompileToMethod(typeGen.TypeBuilder, CompilerHelpers.PublicStatic, SourceUnit.EmitDebugSymbols);

            // Create globals dictionary, finish type
            rewriter.EmitDictionary();
            Type type = typeGen.FinishType();

            globals = (IAttributesCollection)Activator.CreateInstance(type);

            // Create target
            target = (DlrMainCallTarget)Delegate.CreateDelegate(typeof(DlrMainCallTarget), type.GetMethod("Initialize"));

            // TODO: clean this up after clarifying dynamic site initialization logic
            InitializeFields(type);
        }
        public OptimizedScriptCode(Scope optimizedScope, DlrMainCallTarget optimizedTarget, SourceUnit sourceUnit)
            : base(null, optimizedTarget, sourceUnit)
        {
            ContractUtils.RequiresNotNull(optimizedScope, "optimizedScope");

            _optimizedScope  = optimizedScope;
            _optimizedTarget = optimizedTarget;
        }
Beispiel #6
0
        public LegacyScriptCode(LambdaExpression code, DlrMainCallTarget target, SourceUnit sourceUnit)
            : base(sourceUnit)
        {
            ContractUtils.RequiresNotNull(sourceUnit, "sourceUnit");

            _target = target;
            _code = code;
        }
        private void CompileWithArrayGlobals(out DlrMainCallTarget target, out IAttributesCollection globals)
        {
            GlobalArrayRewriter            rewriter = new GlobalArrayRewriter();
            Expression <DlrMainCallTarget> lambda   = rewriter.RewriteLambda(Code);

            // Compile target
            target = lambda.Compile(SourceUnit.EmitDebugSymbols);

            // Create globals
            globals = rewriter.CreateDictionary();
        }
Beispiel #8
0
        public ScriptCode(LambdaExpression code, DlrMainCallTarget target, SourceUnit sourceUnit) {
            if (code == null && target == null) {
                throw Error.MustHaveCodeOrTarget();
            }

            ContractUtils.RequiresNotNull(sourceUnit, "sourceUnit");

            _code = code;
            _sourceUnit = sourceUnit;
            _target = target;
        }
Beispiel #9
0
        public ScriptCode(LambdaExpression code, DlrMainCallTarget target, SourceUnit sourceUnit)
        {
            if (code == null && target == null)
            {
                throw Error.MustHaveCodeOrTarget();
            }

            ContractUtils.RequiresNotNull(sourceUnit, "sourceUnit");

            _code       = code;
            _sourceUnit = sourceUnit;
            _target     = target;
        }
        /// <summary>
        /// Creates the methods and optimized Scope's which get associated with each ScriptCode.
        /// </summary>
        private Scope CompileOptimizedScope() {
            DlrMainCallTarget target;
            IAttributesCollection globals;
            if (UseLightweightScopes) {
                CompileWithArrayGlobals(out target, out globals);
            } else {
                CompileWithStaticGlobals(out target, out globals);
            }

            // Force creation of names used in other script codes into all optimized dictionaries
            Scope scope = new Scope(globals);
            ((IModuleDictionaryInitialization)globals).InitializeModuleDictionary(new CodeContext(scope, LanguageContext));

            // everything succeeded, commit the results
            _optimizedTarget = target;
            _optimizedScope = scope;

            return scope;
        }
        private void CompileWithStaticGlobals(out DlrMainCallTarget target, out IAttributesCollection globals) {
            // Create typegen
            TypeGen typeGen = Snippets.Shared.DefineType(MakeDebugName(), typeof(CustomSymbolDictionary), false, SourceUnit.EmitDebugSymbols);
            typeGen.TypeBuilder.DefineDefaultConstructor(MethodAttributes.Public);

            // Create rewriter
            GlobalStaticFieldRewriter rewriter = new GlobalStaticFieldRewriter(typeGen);

            // Compile lambda
            LambdaExpression lambda = rewriter.RewriteLambda(Code, "Initialize");
            MethodBuilder mb = typeGen.TypeBuilder.DefineMethod(lambda.Name, CompilerHelpers.PublicStatic);
            lambda.CompileToMethod(mb, SourceUnit.EmitDebugSymbols);

            // Create globals dictionary, finish type
            rewriter.EmitDictionary();
            Type type = typeGen.FinishType();
            globals = (IAttributesCollection)Activator.CreateInstance(type);

            // Create target
            target = (DlrMainCallTarget)Delegate.CreateDelegate(typeof(DlrMainCallTarget), type.GetMethod("Initialize"));

            // TODO: clean this up after clarifying dynamic site initialization logic
            InitializeFields(type);
        }        
        private void CompileWithArrayGlobals(out DlrMainCallTarget target, out IAttributesCollection globals) {
            GlobalArrayRewriter rewriter = new GlobalArrayRewriter();
            Expression<DlrMainCallTarget> lambda = rewriter.RewriteLambda(Code);

            // Compile target
            target = lambda.Compile(SourceUnit.EmitDebugSymbols);

            // Create globals
            globals = rewriter.CreateDictionary();
        }
        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));
        }
Beispiel #14
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);
 }
Beispiel #15
0
 internal protected virtual ScriptCode LoadCompiledCode(DlrMainCallTarget method, string path)
 {
     return(ScriptCode.Load(method, this, path));
 }
Beispiel #16
0
 public OnDiskScriptCode(DlrMainCallTarget code, SourceUnit sourceUnit) :
     base(null, code, sourceUnit) {
     _code = code;
 }