Beispiel #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();
        }
Beispiel #2
0
 public XNClass(class_definition Class,XAssembly assembly)
     : base(Class.name,assembly)
 {
     this.name = Class.name;
     this.inheritance = Class.interfaces.Select(s => assembly.GetClass(s)).ToList();
 }
Beispiel #3
0
        private stmt ParseWord()
        {
            if (Current == TokenType.word)
            {
                if (!IsNextEOT && Next == TokenType.symbol)
                {
                    if (Next == '=')
                    {
                        setvar stmt = new setvar();
                        stmt.name = Current;
                        Step(); Step();
                        stmt.value = ParseExpr();
                        return stmt;
                    }
                    else
                    {
                        return null;
                    }
                }
                else if (Current == "var")
                {
                    declarevar stmt = new declarevar();
                    Step(); //Step over "var"
                    stmt.name = Current;
                    Step(); //Step over name
                    if (Current == "as")
                    {
                        Step(); //Step over "as"
                        stmt.type = Current;
                        Step(); //Step over type
                    }
                    else
                    {
                        stmt.type = "object";
                    }

                    if (Current == '=')
                    {
                        Step(); //Step over =
                        stmt.value = ParseExpr();
                    }
                    return stmt;
                }
                else if (Current == "def")
                {
                    function_definition stmt = new function_definition();
                    Step(); //Step over def
                    stmt.name = Current;
                    Step(); //Step over fname
                    Step(); //Step over (
                    stmt.args = ParseArgs();
                    Step(); //Step over )
                    if (Current == "as")
                    {
                        Step(); //Step over "as"
                        stmt.type = Current;
                        Step(); //Step over type
                    }
                    else
                    {
                        stmt.type = "object";
                    }
                    stmt.body = ParseStmt();
                    return stmt;
                }
                else if (Current == "return")
                {
                    return_value ret = new return_value();
                    Step(); //Step over return
                    ret.returnvalue = ParseExpr();
                    return ret;
                }
                else if (Current == "class")
                {
                    class_definition cls = new class_definition();
                    Step(); //Step over "class"
                    cls.name = Current;
                    Step(); //Step over name
                    if(Current == ':')
                    {
                        Step(); //Step over :
                        cls.interfaces = ParseClassImplemetations();
                        Step(); //Step over class implementations
                    }
                    cls.body = ParseStmt();
                    return cls;
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return null;
            }
        }