Beispiel #1
0
        public static FLProgram Initialize(this SerializableFLProgram program, FLInstructionSet instructionSet)
        {
            Dictionary <string, FLBuffer>           buffers           = new Dictionary <string, FLBuffer>();
            Dictionary <string, FLFunction>         functions         = new Dictionary <string, FLFunction>();
            Dictionary <string, ExternalFlFunction> externalFunctions = new Dictionary <string, ExternalFlFunction>();


            for (int i = 0; i < program.ExternalFunctions.Count; i++)
            {
                ExternalFlFunction extFunc = new ExternalFlFunction(program.ExternalFunctions[i].Name,
                                                                    program.ExternalFunctions[i].ExternalProgram, instructionSet);
                externalFunctions.Add(program.ExternalFunctions[i].Name, extFunc);
            }

            for (int i = 0; i < program.DefinedBuffers.Count; i++)
            {
                FLBuffer extFunc = program.DefinedBuffers[i].GetBuffer();
                extFunc.SetKey(program.DefinedBuffers[i].Name);
                buffers.Add(extFunc.DefinedBufferName, extFunc);
            }


            for (int i = 0; i < program.Functions.Count; i++)
            {
                functions.Add(program.Functions[i].Name, new FLFunction(program.Functions[i].Name));
            }

            FLProgram p = new FLProgram(externalFunctions, buffers, functions);

            for (int i = 0; i < program.Functions.Count; i++)
            {
                functions[program.Functions[i].Name].Initialize(program.Functions[i], p, instructionSet);
            }

            //TODO Resolve Functions first. then in a second step resolve the references of the arguments.
            //When a function is defined below it beeing used the program is crashing because
            //it resolves the argument before the function that the argument is pointing to is parsed(e.g. not null)
            //Create possibility to create the function objects in another loop than creating the arguments.
            //For functions
            //add the function objects with name to the dict
            //for functions
            //initialize function
            p.SetRoot();
            return(p);
        }
        public static FLProgram Initialize(
            this SerializableFLProgram program, CLAPI instance,
            FLInstructionSet instructionSet)
        {
            foreach (EmbeddedKernelData embeddedKernelData in program.KernelData)
            {
                if (instructionSet.Database.KernelNames.Contains(embeddedKernelData.Kernel))
                {
                    continue;
                }

                instructionSet.Database.AddProgram(
                    instance,
                    embeddedKernelData.Source,
                    "./",
                    false,
                    out CLProgramBuildResult res
                    );
                if (!res)
                {
                    throw res.GetAggregateException();
                }
            }

            Dictionary <string, FLBuffer>  buffers           = new Dictionary <string, FLBuffer>();
            Dictionary <string, IFunction> functions         = new Dictionary <string, IFunction>();
            Dictionary <string, IFunction> externalFunctions = new Dictionary <string, IFunction>();


            for (int i = 0; i < program.ExternalFunctions.Count; i++)
            {
                ExternalFlFunction extFunc = new ExternalFlFunction(
                    program.ExternalFunctions[i].Name,
                    program.ExternalFunctions[i].ExternalProgram,
                    instructionSet,
                    program.ExternalFunctions[i].Modifiers
                    );

                externalFunctions.Add(program.ExternalFunctions[i].Name, extFunc);
            }

            for (int i = 0; i < program.DefinedBuffers.Count; i++)
            {
                FLBuffer extFunc = program.DefinedBuffers[i].GetBuffer();
                extFunc.SetKey(program.DefinedBuffers[i].Name);
                buffers.Add(extFunc.DefinedBufferName, extFunc);
            }


            for (int i = 0; i < program.Functions.Count; i++)
            {
                functions.Add(
                    program.Functions[i].Name,
                    new FLFunction(program.Functions[i].Name, program.Functions[i].Modifiers)
                    );
            }

            FLProgram p = new FLProgram(instance, externalFunctions, buffers, functions);

            p.SetRoot();
            for (int i = 0; i < program.Functions.Count; i++)
            {
                (functions[program.Functions[i].Name] as FLFunction).Initialize(
                    program.Functions[i],
                    p,
                    instructionSet
                    );
            }

            //TODO Resolve Functions first. then in a second step resolve the references of the arguments.
            //When a function is defined below it beeing used the program is crashing because
            //it resolves the argument before the function that the argument is pointing to is parsed(e.g. not null)
            //Create possibility to create the function objects in another loop than creating the arguments.
            //For functions
            //add the function objects with name to the dict
            //for functions
            //initialize function
            p.SetRoot();


            return(p);
        }