예제 #1
0
        public static void Compile(string asm, string mdl, string nameSpace, Type target, string[] table, string[] labels, string[] files, Dictionary<string, string> header)
        {
            AssemblyName asmName = new AssemblyName(asm);
            AssemblyBuilder asmBldr = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.RunAndSave);
            ModuleBuilder mdlBldr = asmBldr.DefineDynamicModule(mdl, asmName.Name + ".dll");
            foreach (var f in files)
            {
                TypeBuilder typBldr = mdlBldr.DefineType(nameSpace + "." + Path.GetFileNameWithoutExtension(f), TypeAttributes.Public | TypeAttributes.Abstract);
                var scan = new Scanner(File.ReadAllText(f), header);
                var tree = new ExpressionTreeMaker(scan.Tokens.ToArray(), target, table);
                tree.Compile(GetMethodBuilder(typBldr, "main"));
                if (labels != null)
                {
                    foreach (var l in labels)
                    {
                        if (tree.LabelExist(l))
                        {
                            tree.CompileLabel(l, GetMethodBuilder(typBldr, l));
                        }
                    }
                }
                int gvn = tree.GlobalVarNumber;
                //System.Linq.Expressions.Expression<Func<int>> gb = () => (gvn);
                //gb.CompileToMethod(GetMethodBuilder(typBldr, "GlobalVarNumber"));
                typBldr.DefineField("GlobalVarNumber", typeof(int), FieldAttributes.Public | FieldAttributes.Static).SetConstant(tree.GlobalVarNumber);
                var type = typBldr.CreateType();
            }

            asmBldr.Save(asmName.Name + ".dll");
        }
예제 #2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="code">プリプロセス済みコード</param>
 /// <param name="name">ファイル名</param>
 protected void Load(string code, string name)
 {
     Scanner sc = null;
     try
     {
         sc = new Scanner(code, HeaderDictionary);
     }
     catch (Exception e)
     {
         throw new Exception(name + "でスキャナエラー:" + e.Message, e);
     }
     try
     {
         Tree = new ExpressionTreeMaker(sc.Tokens.ToArray(), TargetType, Table);
     }
     catch (Exception e)
     {
         throw new Exception(name + "で構文エラー:" + e.Message, e);
     }
     if (Labels != null)
     {
         foreach (var item in Labels)
         {
             Tree.GetLabelStatement(item);
         }
     }
 }