Exemplo n.º 1
0
        public void AddModule(Module module)
        {
            string ModuleName = RunTimeModules.Count.ToString();

            //Handle return types, displays and entry point
            foreach (Procedure proc in module.GetProcedures())
            {
                proc._ParentModule = ModuleName;

                if (proc._ReturnType == Types.Void)
                {
                    proc._ReturnType = Types.Pointer; //Any
                }
                if (module._HasDisplay)
                {
                    _DisplayRequired = true;
                }

                _Procedures.Add(proc.GetName(), proc);
                if (proc.HasEntrypoint)
                {
                    _EntryProcedure = proc.GetName();
                }

                proc.CalculateLabels();
            }

            //Handle adding references to internal functions
            foreach (string function in module.GetReferences())
            {
                Function.AddFunctionReference(function, module.GetReferenceFunc(function));
            }

            //Handle global variables for module
            RunTimeModules.Add(ModuleName, new RunTimeModule());

            //Handle shared memory between variables
            Dictionary <string, DataValue> SharedMemory = new Dictionary <string, DataValue>();

            foreach (String global in module.GetDataSetList())
            {
                //TODO: don't just compare names, also compare types for shared memory

                DataValue set;
                if (SharedMemory.ContainsKey(global))
                {
                    set = SharedMemory[global];
                }
                else
                {
                    set = module.GetDataSet(global).ToDataValue();
                    SharedMemory.Add(global, set);
                }

                RunTimeModules[ModuleName].GlobalVariables.Add(set.GetName(), set);

                if (set is Structure)
                {
                    if (!(set as Structure).isQualified())
                    {
                        foreach (string column in (set as Structure).GetSubfieldNames())
                        {
                            if (SharedMemory.ContainsKey(column))
                            {
                                (set as Structure).SetData(SharedMemory[column], column);
                            }
                            else
                            {
                                SharedMemory.Add(column, (set as Structure).GetData(column));
                            }
                        }
                    }
                }
            }
        }