예제 #1
0
        // Defines [methodValue] as a method on [classObj].
        private static Obj BindMethod(bool isStatic, int symbol, ObjClass classObj, Obj methodContainer)
        {
            ObjFn methodFn = methodContainer as ObjFn ?? ((ObjClosure)methodContainer).Function;

            // Methods are always bound against the class, and not the metaclass, even
            // for static methods, because static methods don't have instance fields
            // anyway.
            Compiler.BindMethodCode(classObj, methodFn);

            Method method = new Method { MType = MethodType.Block, Obj = methodContainer };

            if (isStatic)
                classObj = classObj.ClassObj;

            classObj.BindMethod(symbol, method);
            return null;
        }
예제 #2
0
 public void BindMethod(int symbol, Method method)
 {
     if (symbol >= Methods.Length)
     {
         ResizeMethods(symbol);
     }
     Methods[symbol] = method;
 }
예제 #3
0
        /* Anotehr Dirty Hack */
        public void Primitive(ObjClass objClass, string s, Primitive func)
        {
            if (!MethodNames.Contains(s))
            {
                MethodNames.Add(s);
            }
            int symbol = MethodNames.IndexOf(s);

            Method m = new Method { Primitive = func, MType = MethodType.Primitive };
            objClass.BindMethod(symbol, m);
        }
예제 #4
0
 private void ResizeMethods(int symbol)
 {
     int i = Methods.Length;
     while (i <= symbol)
         i *= 2;
     Method[] m = new Method[i];
     Methods.CopyTo(m,0);
     Methods = m;
 }