Example #1
0
        internal override IEnumerable <Instruction> Compile()
        {
            List <InternalLambdaDescription> constructorOverloads = new List <InternalLambdaDescription>();

            if (ParameterFields != null)
            {
                constructorOverloads.Add(new InternalLambdaDescription
                {
                    argTypes     = ParameterFields.Select(param => param.Type.GetIndicatedType()).ToArray(),
                    returnType   = Type,
                    closureSize  = Type.numSlots,
                    stackSize    = ConstructorStackSize,
                    instructions = CompileConstructor(null).ToArray()
                });
            }

            foreach (FunctionDefinition constructor in Constructors)
            {
                constructorOverloads.Add(new InternalLambdaDescription
                {
                    argTypes     = constructor.Parameters.Select(param => param.Type.GetIndicatedType()).ToArray(),
                    returnType   = Type,
                    closureSize  = Type.numSlots,
                    stackSize    = ConstructorStackSize,
                    instructions = CompileConstructor(constructor).ToArray()
                });
            }

            List <Instruction> instructions = new List <Instruction>();

            instructions.AddRange(
                new Instruction[]
            {
                new BuildInternalLambdasInstruction(constructorOverloads.ToArray()),
                new AssignConstructorLambdaInstruction(Type),
                new LoadConstantInstruction(Type),
                Compiler.CompileVariableAssign(DeclaredVariable)
            }
                );

            for (int i = 0; i < StaticOverloads.Count; i++)
            {
                OverloadGroup overload = StaticOverloads[i];
                instructions.AddRange(overload.Compile());
                instructions.Add(Compiler.CompileVariableLookup(overload.variable));
                instructions.Add(new SetStaticOverloadInstruction(Type, i));
            }
            return(instructions);
        }