Exemple #1
0
        public void GenerateClass(class_definition Stmt, Context context)
        {
            //Create type
            TypeBuilder classBuilder = moduleBuilder.DefineType(Stmt.name);
            //Add interface implementations
            if (Stmt.interfaces != null)
            {
                GetILNames(Stmt.interfaces).ToList().ForEach((i) => classBuilder.AddInterfaceImplementation(i));
            }
            //Start genetation of class
            GenerateIL(Stmt.body, null, context, null, null, classBuilder);

            //Finish class, generate it
            classBuilder.CreateType();
        }
Exemple #2
0
        public void GenerateIL(stmt Stmt, ILGenerator generator, Context context, Dictionary<string,LocalBuilder> symbolTable, MethodBuilder Method = null, TypeBuilder Class = null)
        {
            ILGenerator ilGenerator;
            if (generator == null)
            {
                if (Method == null)
                {
                    ilGenerator = mainMethod.GetILGenerator();
                }
                else
                {
                    ilGenerator = Method.GetILGenerator();
                }
            }
            else
            {
                ilGenerator = generator;
            }

            if (Class != null)
            {
                if(Stmt is stmt_list)
                {
                    stmt_list list = Stmt as stmt_list; //Cast stmt
                    foreach (stmt s in list.list)
                    {
                        GenerateIL(s, null, context, null, null, Class);
                    }
                }
            }
            else
            {
                if (Stmt is stmt_list)
                {
                    stmt_list list = Stmt as stmt_list; //Cast stmt
                    foreach (stmt s in list.list)
                    {
                        GenerateIL(s, generator, context, symbolTable, Method, null);
                    }
                }
                else if (Stmt is declarevar)
                {
                    declarevar stmt = Stmt as declarevar;
                    mainSymbolTable[stmt.name] = ilGenerator.DeclareLocal(GetILType(stmt.type));

                    GenerateExpr(stmt.value, ilGenerator);
                    StoreLocal(stmt.name, ilGenerator);
                }
                else if (Stmt is setvar)
                {
                    setvar stmt = Stmt as setvar;
                    GenerateExpr(stmt.value, ilGenerator);
                    StoreLocal(stmt.name, ilGenerator);
                }
                else if (Stmt is function_call)
                {
                    function_call stmt = Stmt as function_call;
                    GenerateExpr(stmt.arg, ilGenerator);
                    //ilGenerator.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(string) }));
                    MethodInfo method = GetMethodInfo(stmt.name, Class, null, GetExprTypes(stmt.arg));
                    MethodInfo rmethod = Type.GetType("System.Console").GetMethod("WriteLine", new Type[] { typeof(string) });
                    if(method == rmethod)
                    {
                        Console.WriteLine("MATCH!");
                    }
                    ilGenerator.Emit(OpCodes.Call, method);
                }
                else if (Stmt is class_definition)
                {
                    class_definition stmt = Stmt as class_definition;
                    GenerateClass(stmt, context);
                }
            }
        }
Exemple #3
0
 public void GenerateMethod(function_definition Stmt, Context context, TypeBuilder Class)
 {
 }