示例#1
0
        /// <summary>Get the imported method.</summary>
        public MethodInfo Get(Module module, out int paramCount, out Type returnType)
        {
            if (Signature == null)
            {
                // Get the signature:
                Signature = module.FunctionSection.Types[(int)Type];
            }

            paramCount = Signature.ParameterCount;
            returnType = Signature.GetReturnType();

            // If we're importing a compiling JS function then we
            // can potentially generate an overload which specifically
            // matches our given signature.
            if (ImportedMethod == null)
            {
                ImportedMethod = MapImport(module) as MethodInfo;
            }

            return(ImportedMethod);
        }
        /// <summary>Compiles all the methods in this code section.</summary>
        public void Compile()
        {
            if (Bodies == null)
            {
                return;
            }

            for (int b = 0; b < Bodies.Length; b++)
            {
                // Get the body:
                FunctionBody body = Bodies[b];

                // Get the function signature:
                FuncType sig = body.Signature;

                // Create the builder:
                ILGenerator gen = sig.GetGenerator(Module);

                // Define the locals now:
                body.DefineLocals(gen);

                // Set body to the generator:
                gen.FunctionBody = body;

                // For each instruction in the input set, output it now:
                for (int i = 0; i < body.Root.Count; i++)
                {
                    // Get the instruction:
                    Instruction instruction = body.Root[i];

                    // Emit it:
                    instruction.Output(gen);
                }

                // Complete it:
                gen.Complete(sig.Name, sig.GetParameters(), sig.GetReturnType(), true);
            }
        }