diff options
Diffstat (limited to 'mop/__init__.py')
-rw-r--r-- | mop/__init__.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/mop/__init__.py b/mop/__init__.py index b2bf41c..dffa4f8 100644 --- a/mop/__init__.py +++ b/mop/__init__.py @@ -121,6 +121,7 @@ def bootstrap(): # Phase 4: manually assemble enough scaffolding to allow object construction + # temporary, we'll have a better version later def gen_reader(name): return lambda self: self.slots[name] @@ -220,6 +221,18 @@ def bootstrap(): # Phase 6: now we can populate the rest of the mop + def get_value(self, instance): + return instance.slots[self.get_name()] + Attribute.add_method(Method.new( + name="get_value", body=get_value + )) + + # here's the better implementation + # note that we can't replace the implementation of the methods implemented + # by the previous gen_reader because that would end up recursive + def gen_reader(name): + return lambda self: self.metaclass.get_all_attributes()[name].get_value(self) + Method.add_method(Method.new( name="get_name", body=gen_reader("name") )) @@ -227,12 +240,6 @@ def bootstrap(): name="get_body", body=gen_reader("body") )) - def get_value(self, instance): - return instance.slots[self.get_name()] - Attribute.add_method(Method.new( - name="get_value", body=get_value - )) - Class.add_attribute(Attribute.new(name="name")) Class.add_attribute(Attribute.new(name="superclass")) Class.add_attribute(Attribute.new(name="attributes", default=lambda: {})) |