Beispiel #1
0
 public Method CompileInstanceMethod(string text, IBehavior cls)
 {
     ModelParser parser = new ModelParser(text);
     var methodmodel = parser.ParseMethod();
     Method method = new Method(cls, methodmodel.Selector, text);
     BytecodeCompiler compiler = new BytecodeCompiler(method);
     compiler.CompileMethod(methodmodel);
     return method;
 }
        internal static IClass CompileClass(string clsname, string[] varnames, string[] methods, string[] clsmethods)
        {
            Machine machine = new Machine();
            IClass cls = machine.CreateClass(clsname);

            if (varnames != null)
            {
                foreach (string varname in varnames)
                {
                    cls.DefineInstanceVariable(varname);
                }
            }

            if (methods != null)
            {
                foreach (string method in methods)
                {
                    ModelParser parser = new ModelParser(method);
                    MethodModel model = parser.ParseMethod();
                    Method newmethod = new Method(cls, model.Selector, method);
                    BytecodeCompiler compiler = new BytecodeCompiler(newmethod);
                    compiler.CompileMethod(model);
                    cls.DefineInstanceMethod(newmethod);
                }
            }

            if (clsmethods != null)
            {
                foreach (string method in clsmethods)
                {
                    ModelParser parser = new ModelParser(method);
                    MethodModel model = parser.ParseMethod();
                    Method newmethod = new Method(cls, model.Selector, method);
                    BytecodeCompiler compiler = new BytecodeCompiler(newmethod);
                    compiler.CompileMethod(model);
                    cls.DefineClassMethod(newmethod);
                }
            }

            return cls;
        }