Exemple #1
0
        /// <summary>
        ///     Ctor which takes Executable name
        ///     as parameter
        /// </summary>
        /// <param name="name"></param>
        public ExeGenerator(TModule p, string name)
        {
            //
            // The Program to be compiled...
            //
            _p = p;
            //
            // Get The App Domain
            //
            //
            AppDomain    _app_domain = Thread.GetDomain();
            AssemblyName _asm_name   = new AssemblyName();

            //
            //  One can give a strong name , if we want
            //
            _asm_name.Name = "MyAssembly";
            //
            // Save the Exe Name
            //
            _name = name;
            //
            // Create an instance of Assembly Builder
            //
            //
            _asm_builder = AppDomain.CurrentDomain.DefineDynamicAssembly(
                _asm_name,
                AssemblyBuilderAccess.RunAndSave);
            //
            // Create a module builder , from AssemblyBuilder
            //
            _module_builder = _asm_builder.DefineDynamicModule("DynamicModule1", _name, false);
            //
            // Create a class by the name MainClass..
            // We compile the statements into a static method
            // of the type MainClass .. the entry point will
            // be called Main
            // ExeGenerator will be called from TModule.Compile method
            // We will add methods to the type MainClass as static method
            //
            _type_builder = _module_builder.DefineType("MainClass");
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cont"></param>
        /// <returns></returns>
        public override bool Compile(DNET_EXECUTABLE_GENERATION_CONTEXT cont)
        {
            if (m_proc == null)
            {
                // if it is  a recursive call..
                // resolve the address...
                m_proc = cont.GetProgram().Find(_procname);
            }

            string name = m_proc.Name;


            TModule       str = cont.GetProgram();
            MethodBuilder bld = str._get_entry_point(name);

            foreach (Exp ex in m_actuals)
            {
                ex.Compile(cont);
            }
            cont.CodeOutput.Emit(OpCodes.Call, bld);
            return(true);
        }
Exemple #3
0
 /// <summary>
 ///    Create an instance of Symbol Table
 /// </summary>
 public RUNTIME_CONTEXT(TModule Pgrm)
 {
     m_dt  = new SymbolTable();
     _prog = Pgrm;
 }
Exemple #4
0
        public DNET_EXECUTABLE_GENERATION_CONTEXT(TModule program,
                                                  Procedure proc,
                                                  TypeBuilder bld)
        {
            _proc    = proc;
            _bld     = bld;
            _program = program;

            System.Type[] s = new System.Type[_proc.FORMALS.Count];

            int i = 0;

            foreach (SYMBOL_INFO ts in _proc.FORMALS)
            {
                if (ts.Type == TYPE_INFO.TYPE_BOOL)
                {
                    s[i] = typeof(bool);
                }
                else if (ts.Type == TYPE_INFO.TYPE_NUMERIC)
                {
                    s[i] = typeof(double);
                }
                else
                {
                    s[i] = typeof(string);
                }
                i = i + 1;
            }

            if (_proc.FORMALS.Count == 0)
            {
                s = null;
            }

            System.Type ret_type = null;

            if (_proc.TYPE == TYPE_INFO.TYPE_BOOL)
            {
                ret_type = typeof(bool);
            }
            else if (_proc.TYPE == TYPE_INFO.TYPE_STRING)
            {
                ret_type = typeof(string);
            }
            else
            {
                ret_type = typeof(double);
            }

            if (_proc.m_name.Equals("MAIN"))
            {
                //--------- Deleberately set to null
                // This is to ignore return value of main
                ret_type  = null;
                _methinfo = _bld.DefineMethod(_proc.Name, MethodAttributes.Public | MethodAttributes.Static, ret_type, s);
            }
            else
            {
                _methinfo = _bld.DefineMethod(_proc.Name, MethodAttributes.Public | MethodAttributes.Static, ret_type, s);
            }
            ILout = _methinfo.GetILGenerator();
        }