diff options
Diffstat (limited to 'modules/language')
-rw-r--r-- | modules/language/python/compile.scm | 10 | ||||
-rw-r--r-- | modules/language/python/dict.scm | 14 | ||||
-rw-r--r-- | modules/language/python/list.scm | 12 | ||||
-rw-r--r-- | modules/language/python/module/python.scm | 2 | ||||
-rw-r--r-- | modules/language/python/number.scm | 2 | ||||
-rw-r--r-- | modules/language/python/set.scm | 9 | ||||
-rw-r--r-- | modules/language/python/string.scm | 4 | ||||
-rw-r--r-- | modules/language/python/tuple.scm | 4 |
8 files changed, 35 insertions, 22 deletions
diff --git a/modules/language/python/compile.scm b/modules/language/python/compile.scm index 3e16386..b7a52b2 100644 --- a/modules/language/python/compile.scm +++ b/modules/language/python/compile.scm @@ -1117,7 +1117,9 @@ (letrec ((,f (case-lambda ((,q) - (apply ,f ,q)) + (if (pair? ,q) + (apply ,f ,q) + (apply ,f (,(L 'to-list) ,q)))) (,vars ,@(map (lambda (l v) (make-set vs op l v)) l vars))))) @@ -1182,13 +1184,13 @@ (match op ((or "<" ">" "<=" ">=") (list (G (string->symbol op)) x y)) - ("!=" (list (G 'not) (list (G 'equal?) x y))) - ("==" (list (G 'equal?) x y)) + ("!=" (list (G 'not) (list (O 'equal?) x y))) + ("==" (list (O 'equal?) x y)) ("is" (list (G 'eq?) x y)) ("isnot" (list (G 'not) (list (G 'eq?) x y))) ("in" (list (L 'in) x y)) ("notin" (list (G 'not) (list (L 'in) x y))) - ("<>" (list (G 'not) (list (G 'equal?) x y))))) + ("<>" (list (G 'not) (list (O 'equal?) x y))))) (tr op (exp vs x) (exp vs y))))) (define (exp vs x) diff --git a/modules/language/python/dict.scm b/modules/language/python/dict.scm index f4d13a5..b9ab116 100644 --- a/modules/language/python/dict.scm +++ b/modules/language/python/dict.scm @@ -20,13 +20,19 @@ (define-syntax-rule (aif it p x y) (let ((it p)) (if it x y))) (define (h x n) (modulo (py-hash x) n)) +(define (py-assoc k l) + (if (pair? l) + (if (equal? (caar l) k) + (car l) + (py-assoc k (cdr l))) + #f)) (define (py-hash-ref . l) - (apply hashx-ref h assoc l)) + (apply hashx-ref h py-assoc l)) (define (py-hash-set! . l) - (apply hashx-set! h assoc l)) + (apply hashx-set! h py-assoc l)) (define (py-hash-remove! . l) - (apply hashx-remove! h assoc l)) + (apply hashx-remove! h py-assoc l)) (set! (@@ (language python def) hset!) py-hash-set!) @@ -430,7 +436,7 @@ (format port "{}") (format port "{~a: ~a~{, ~a: ~a~}}" (car li) (cadr li) (cddr li)))) -(define-method (equal? (o1 <py-hashtable>) (o2 <py-hashtable>)) +(define-method (py-equal? (o1 <py-hashtable>) (o2 <py-hashtable>)) (and (equal? (slot-ref o1 'n) (slot-ref o2 'n)) (equal? (slot-ref o1 'h) (slot-ref o2 'h)) diff --git a/modules/language/python/list.scm b/modules/language/python/list.scm index e9c301c..a35ceae 100644 --- a/modules/language/python/list.scm +++ b/modules/language/python/list.scm @@ -454,7 +454,10 @@ (next-method))) ;; equal? -(define-method (equal? (o1 <py-list>) (o2 <py-list>)) +(define-method (py-equal? (o1 <py-list>) (o2 <py-list>)) + (equal o1 o2)) + +(define (equal o1 o2) (let ((n1 (slot-ref o1 'n)) (n2 (slot-ref o2 'n)) (vec1 (slot-ref o1 'vec)) @@ -466,10 +469,6 @@ (and (equal? (vector-ref vec1 i) (vector-ref vec2 i)) (lp (+ i 1))) #t))))) - -(define-method (equal? (o1 <py-list>) o2) #f) -(define-method (equal? o1 (o2 <py-list>)) #f) - (define-class <py-seq-iter> () o i n d) (define-class <py-list-iter> (<py-list>) i d) @@ -833,10 +832,9 @@ (__init__ self) (for ((i : it)) () (pylist-append! self i)))))) __init__))) - + (define pylist list) - (define-method (py-class (o <py-list>) list)) (define (pylist-listing) diff --git a/modules/language/python/module/python.scm b/modules/language/python/module/python.scm index 418c325..492e013 100644 --- a/modules/language/python/module/python.scm +++ b/modules/language/python/module/python.scm @@ -221,7 +221,7 @@ (lambda z (lp2 (cdr l) (append (reverse z) r)))) (begin - (apply yield (reverse r)) + (yield (reverse r)) (lp)))))))))) diff --git a/modules/language/python/number.scm b/modules/language/python/number.scm index d0218d3..2d90554 100644 --- a/modules/language/python/number.scm +++ b/modules/language/python/number.scm @@ -67,7 +67,7 @@ (mk-biop1 b0 <= __lt__) (mk-biop1 b0 >= __gt__) (mk-biop2 b0 rexpt expt __pow__ __rpow__) -(b0 equal?) +(b0 py-equal?) (define-method (py-lshift (o1 <integer>) (o2 <integer>)) (ash o1 o2)) diff --git a/modules/language/python/set.scm b/modules/language/python/set.scm index d69b7c9..ef4abe7 100644 --- a/modules/language/python/set.scm +++ b/modules/language/python/set.scm @@ -198,7 +198,14 @@ (let* ((d (slot-ref self 'dict)) (t (slot-ref d 't))) (not (eq? miss (py-hash-ref t x miss)))))) - + + (define __eq__ + (lambda (self x) + (and + (is-a? x <p>) + (eq? (ref self '__class__ 1) (ref x '__class__ 2)) + (equal? (ref self 'd 1) (ref x 'd 2))))) + (define __iter__ (make-generator (self) (lambda (yield self) diff --git a/modules/language/python/string.scm b/modules/language/python/string.scm index d8f4da7..16d9d0b 100644 --- a/modules/language/python/string.scm +++ b/modules/language/python/string.scm @@ -513,9 +513,9 @@ (define-method (pyhash (o <py-string>)) (hash (slot-ref o 'str) pyhash-N)) -(define-method (equal? (o <py-string>) x) +(define-method (py-equal? (o <py-string>) x) (equal? (slot-ref o 'str) x)) -(define-method (equal? x (o <py-string>)) +(define-method (py-equal? x (o <py-string>)) (equal? (slot-ref o 'str) x)) (define-class <string-iter> (<py-string>) str i d) diff --git a/modules/language/python/tuple.scm b/modules/language/python/tuple.scm index 87a6ed0..5362cc9 100644 --- a/modules/language/python/tuple.scm +++ b/modules/language/python/tuple.scm @@ -9,8 +9,8 @@ (define-class <py-tuple> () l) (define-method (py-hash (o <py-tuple>)) (py-hash (slot-ref o 'l))) (define-method (py-class (o <py-tuple>) tuple)) -(define-method (equal? (o1 <py-tuple>) o2) (equal? (slot-ref o1 'l) o2)) -(define-method (equal? o1 (o2 <py-tuple>)) (equal? o1 (slot-ref o2 'l))) +(define-method (py-equal? (o1 <py-tuple>) o2) (equal? (slot-ref o1 'l) o2)) +(define-method (py-equal? o1 (o2 <py-tuple>)) (equal? o1 (slot-ref o2 'l))) (define-method (wrap-in (o <py-tuple>)) (wrap-in (slot-ref o 'l))) |