public ivKittenObject Kitten_SendMessage(ivKittenObject obj, ivKittenMessage msg) { ivKittenClass cls = obj.isa; ivKittenMethod selectedMethod = null; //search methods up the inheritance tree while (true) { foreach (ivKittenMethod method in cls.methodList) { if (method.methodName == msg.msg) { selectedMethod = method; } goto end; } if (cls.superclass != cls) { cls = cls.superclass; } else { goto end; } } end: //can respond to message if (selectedMethod == null) { Kitten_ReportError($"Object Unable to Respond to message: {msg.ToString()}"); return(null); } //args count matches if (msg.args.Count != selectedMethod.argCount) { Kitten_ReportError("Argument count mismatch"); return(null); } //case 1: built-in functions if (selectedMethod is ivKittenBuiltinMethod) { selectedMethod.self = obj; return((selectedMethod as ivKittenBuiltinMethod).impl(msg.args)); } //case 2: image functions else { #warning implementation incomplete for image functions return(null); } return(null); }
public List <ivKittenClass> init() { List <ivKittenClass> standardImage = new List <ivKittenClass>(); //kObject_metaclass (no implementation yet) kObject_meta_cls = new ivKittenClass() { classname = "meta_kObject" }; //kObject ivKittenClass kObject_cls = new ivKittenClass(); kObject_cls.classname = "kObject"; kObject_cls.isa = kObject_meta_cls; kObject_cls.superclass = kObject_cls; //superclass of Object is itself //KObject_metaclass finish-up kObject_meta_cls.superclass = kObject_cls; kObject_meta_cls.isa = kObject_meta_cls; //kString_metaclass (no implementation yet) ivKittenClass kString_meta_cls = new ivKittenClass() { classname = "meta_kString", isa = kObject_meta_cls, superclass = kObject_meta_cls }; //kString ivKittenClass kString_cls = new ivKittenClass() { classname = "kString", isa = kObject_meta_cls, superclass = kObject_cls }; /*kObject member methods*/ //kObject_toString var kObject_toString_method = new ivKittenBuiltinMethod() { methodName = "toString", argCount = 0 }; kObject_toString_method.impl = n => { return(new ivKittenString("this is returned by sending toString to Object")); }; return(standardImage); }