diff options
Diffstat (limited to 'modules/oop')
-rw-r--r-- | modules/oop/pf-objects.scm | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/modules/oop/pf-objects.scm b/modules/oop/pf-objects.scm index 0e2f1d9..47dea90 100644 --- a/modules/oop/pf-objects.scm +++ b/modules/oop/pf-objects.scm @@ -18,7 +18,7 @@ *class* *self* pyobject? pytype? type object pylist-set! pylist-ref tr resolve-method-g rawref rawset py-dict - ref-class + ref-class fastref fastset )) #| @@ -35,6 +35,7 @@ The datastructure is functional but the objects mutate. So one need to explicitly tell it to not update etc. |# + (define-syntax-rule (aif it p x y) (let ((it p)) (if it x y))) ;; this is mutated by the dict class @@ -144,6 +145,20 @@ explicitly tell it to not update etc. (name-object <pyf>) (name-object <property>) +(define (fastref o k . e) + (define r (if (pair? e) (car e) #f)) + (let ((h (slot-ref o 'h))) + (if (hash-table? h) + (hash-ref (slot-ref o 'h) k r) + (aif it (vhash-assoc k (slot-ref o 'h)) (cdr it) r)))) + +(define (fastset o k v) + (let ((h (slot-ref o 'h))) + (if (hash-table? h) + (hash-set! (slot-ref o 'h) k v) + (slot-set! o 'h + (vhash-cons k v (slot-ref o 'h)))))) + (define-method (pylist-set! (o <p>) key val) (aif it (ref o '__setitem__) (it key val) @@ -247,7 +262,7 @@ explicitly tell it to not update etc. (if (pytype? cls) (lambda x (apply f obj x)) f) - (if (pyclass? cls) + (if (pyclass? cls) (lambda x (apply f obj x)) f))))) @@ -730,7 +745,7 @@ explicitly tell it to not update etc. #f))) (define-syntax-rule (mox o x) - (if (procedure? x) + (if (and (procedure? x) (not (is-a? x <p>))) (aif it (procedure-property- x '__get__) (it x o (fluid-ref *location*)) x))) |