示例#1
0
        internal void build_closure(EmitContext ec, string full_name, string encodedSource)
        {
            ILGenerator ig   = ec.ig;
            string      name = func_obj.name;

            Type t = ec.mod_builder.GetType(CodeGenerator.GetTypeName(Location.SourceName));

            ig.Emit(OpCodes.Ldtoken, t);

            if (name != String.Empty)
            {
                ig.Emit(OpCodes.Ldstr, name);
            }
            else
            {
                ig.Emit(OpCodes.Ldstr, SemanticAnalyser.CurrentAnonymousMethod);
            }

            ig.Emit(OpCodes.Ldstr, full_name);

            func_obj.parameters.Emit(ec);
            build_local_fields(ig);

            ig.Emit(OpCodes.Ldc_I4_0);              // FIXME: this hard coded for now.
            ig.Emit(OpCodes.Ldc_I4_0);              // FIXME: this hard coded for now.
            ig.Emit(OpCodes.Ldstr, Decompiler.Decompile(encodedSource, 0, 0).Trim());
            CodeGenerator.load_engine(InFunction, ig);
            ig.Emit(OpCodes.Call, typeof(FunctionExpression).GetMethod("JScriptFunctionExpression"));
            ig.Emit(OpCodes.Stloc, local_func);
            ig.Emit(OpCodes.Ldloc, local_func);
            ig.Emit(OpCodes.Newobj, typeof(Closure).GetConstructor(new Type [] { typeof(FunctionObject) }));
            if (name != String.Empty)
            {
                ig.Emit(OpCodes.Dup);
                if (parent == null || parent.GetType() == typeof(ScriptBlock))
                {
                    ig.Emit(OpCodes.Stsfld, field);
                }
                else if (parent != null &&
                         (parent.GetType() == typeof(FunctionDeclaration) ||
                          parent.GetType() == typeof(FunctionExpression)))
                {
                    ig.Emit(OpCodes.Stloc, local_script_func);
                }
            }
            else
            {
                if (parent != null &&
                    (parent.GetType() == typeof(FunctionDeclaration) ||
                     parent.GetType() == typeof(FunctionExpression)))
                {
                    ig.Emit(OpCodes.Dup);
                    ig.Emit(OpCodes.Stloc, local_script_func);
                }
            }
        }
        internal void build_closure(EmitContext ec, string full_name, string encodedSource)
        {
            ILGenerator ig   = ec.ig;
            string      name = func_obj.name;
            Type        t    = ec.mod_builder.GetType(CodeGenerator.GetTypeName(Location.SourceName));

            ig.Emit(OpCodes.Ldtoken, t);
            ig.Emit(OpCodes.Ldstr, name);
            ig.Emit(OpCodes.Ldstr, full_name);

            func_obj.parameters.Emit(ec);
            build_local_fields(ig);

            //
            // If we have en eval method call, we have to
            // save the loca vars in the stack
            //
            if (SemanticAnalyser.MethodContainsEval(name) ||
                SemanticAnalyser.MethodVarsUsedNested(name))
            {
                ig.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                ig.Emit(OpCodes.Ldc_I4_0);
            }

            ig.Emit(OpCodes.Ldc_I4_0);            // FIXME: this hard coded for now.
            ig.Emit(OpCodes.Ldstr, Decompiler.Decompile(encodedSource, 0, 0).Trim());
            ig.Emit(OpCodes.Ldnull);              // FIXME: this hard coded for now.

            CodeGenerator.load_engine(InFunction, ig);

            ig.Emit(OpCodes.Call, typeof(FunctionDeclaration).GetMethod("JScriptFunctionDeclaration"));

            if (parent == null || parent.GetType() == typeof(ScriptBlock))
            {
                ig.Emit(OpCodes.Stsfld, t.GetField(name));
            }
            else
            {
                ig.Emit(OpCodes.Stloc, local_func);
            }
        }