// Defines [methodValue] as a method on [classObj]. private static Value BindMethod(MethodType methodType, int symbol, ObjClass classObj, Value methodContainer) { ObjFn methodFn = methodContainer.Obj as ObjFn ?? ((ObjClosure)methodContainer.Obj).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.Obj }; if (methodType == MethodType.Static) classObj = classObj.ClassObj; //classObj.Methods[symbol] = method; classObj.BindMethod(symbol, method); return new Value (ValueType.Null); }
public void Primitive(ObjClass objClass, string s, Primitive func) { if (!MethodNames.Contains(s)) { MethodNames.Add(s); } int symbol = MethodNames.IndexOf(s); objClass.BindMethod(symbol, new Method { Primitive = func, MType = MethodType.Primitive }); }
// Defines [methodValue] as a method on [classObj]. private static bool BindMethod(bool isStatic, int symbol, ObjClass classObj, Obj methodContainer) { // If we are binding a foreign method, just return, as this will be handled later if (methodContainer is ObjString) return true; ObjFn methodFn = methodContainer as ObjFn ?? ((ObjClosure)methodContainer).Function; Method method = new Method { MType = MethodType.Block, Obj = methodContainer }; if (isStatic) classObj = classObj.ClassObj; // 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); classObj.BindMethod(symbol, method); return true; }
public void Call(ObjClass objClass, string s) { if (!MethodNames.Contains(s)) { MethodNames.Add(s); } int symbol = MethodNames.IndexOf(s); objClass.BindMethod(symbol, new Method { MType = MethodType.Call }); }