savbe state in debugging

parent 4c6aef43
......@@ -3,7 +3,7 @@
#:use-module (language python exceptions)
#:use-module (language python persist)
#:use-module (oop pf-objects)
#:export (bool))
#:export (bool boolean))
(define-syntax-rule (aif it p x y) (let ((it p)) (if it x y)))
......@@ -35,3 +35,17 @@
(- (if a 1 0) b))
(define-method (- b (a <boolean>))
(- b (if a 1 0)))
(define-python-class boolean ()
(define __new__
(lambda (cls x . l)
(if (pair? l)
(let ((self ((rawref object '__new__) cls)))
(set self '__bool__ (bool x))
self)
(bool x)))))
(set boolean '__name__ 'bool)
(define-method (scheme? (o <boolean>)) boolean)
......@@ -1572,3 +1572,7 @@
(set! (@@ (oop dict) b-decode) py-decode)
(define b-enc #f)
(define-method (scheme? (o <bytevector>)) bytes)
(define-method (scheme? (o <py-bytes>)) bytes)
(define-method (scheme? (o <py-bytearray>)) bytearray)
......@@ -26,7 +26,7 @@
#:use-module ((language python format2) #:select (fnm))
#:use-module ((language python with) #:select ())
#:use-module (ice-9 pretty-print)
#:export (python-comp exit-fluid exit-prompt pks do-pr))
#:export (python-comp exit-fluid exit-prompt pks do-pr o_a))
(define-syntax-rule (aif it p . x) (let ((it p)) (if it . x)))
......@@ -2367,6 +2367,7 @@ empty list."
(guile-3.0 (set! elsel '(else =>)))
((or guile-2.0 guile-2.2) (set! elsel '())))
(define (o_a x) (object-address x))
(define (python-comp in x)
(define (strit x)
......@@ -2418,7 +2419,7 @@ empty list."
fluid-ref ,@elsel define-values
syntax-rules let-syntax abort-to-prompt))
#:use-module (language python module python)
#:use-module ((language python compile) #:select (pks))
#:use-module ((language python compile) #:select (pks o_a))
#:use-module (language python exceptions)
#:use-module ((oop goops) #:select (<complex> <real> <fraction> <integer> <number>)))
(,(G 'define) __doc__ #f)
......
......@@ -138,7 +138,14 @@
(slot-ref o 'hash))
(define-method (len (o <hashtable>))
(hash-fold (lambda (k v s) (+ s 1)) 0 o))
(pk '============)
(hash-fold (lambda l
(pk '>>>>>>> l)
(apply (lambda ll
(pk '>>> ll)
(+ (caddr ll) 1))
l))
0 o))
(define-method (len (o <py-hashtable>))
(slot-ref o 'n))
......@@ -238,14 +245,14 @@
(define-method (bool (o <hashtable>))
(for ((k v : o)) ()
(break o)
#:final #f))
(let/ec ret
(hash-for-each (lambda x (ret #t)) o)
#f))
(define-method (bool (o <py-hashtable>))
(if (= (len o) 0)
#f
o))
(let/ec ret
(hash-for-each (lambda x (ret #t)) (slot-ref o 't))
#f))
(define-py (py-copy copy o)
(<hashtable>
......@@ -460,9 +467,11 @@
(define update
(lam (o (* L) (** K))
(pk 'update-py o L)
(match L
((L)
(for ((k v : L)) ()
(pk k)
(pylist-set! o k v)))
(_ #f))
(for ((k v : K)) ()
......@@ -573,6 +582,7 @@
(define <dict> `(,<py-hashtable> . _))
(define <dict1> `(,<py-hashtable>))
(define <in> `(,<top> ,<py-hashtable>))
(define (resolve a b) (object-method (resolve-method-g a b)))
(define dict-set! (resolve pylist-set! <dict>))
......@@ -582,7 +592,8 @@
(define dict-clear! (resolve py-clear <dict>))
(define dict-get (resolve py-get <dict>))
(define dict-len (resolve len <dict>))
(define dict-bool (resolve bool <dict>))
(define dict-bool (resolve bool <dict1>))
(define dict-update (resolve py-update <dict>))
(define dict-in (resolve in <in> ))
(define dict-items (resolve py-items <dict>))
......@@ -597,6 +608,7 @@
(define get dict-get)
(define __len__ dict-len)
(define __bool__ dict-bool)
(define update dict-update)
(define items dict-items)
(define __iter__ (lambda (self)
(wrap-in (slot-ref self 't))))
......@@ -605,6 +617,9 @@
(define __format___ (lambda x #f))
(define __setattr__ (@@ (oop pf-objects) __setattr__))
(define __getattribute__ (@@ (oop pf-objects) __getattribute__))
(define __repr__
(lambda (self)
(format #f "~a~a" (ref self '__name__) (slot-ref self 't))))
(define __init__
(letrec ((__init__
(case-lambda
......@@ -618,17 +633,13 @@
(catch #t
(lambda ()
(for ((k v : x)) ()
(pk 'key k v)
(pylist-set! self k v))
(pk 'fini))
(pylist-set! self k v)))
(lambda y
(pk y)
(for ((k : x)) ()
(if (pair? k)
(pylist-set! self (car k) (cdr k))
(raise TypeError
"wrong type of argument to dict" k))))))
(if (pair? k)
(pylist-set! self (car k) (cdr k))
(raise TypeError
"wrong type of argument to dict" k))))))
((self . l)
(__init__
self
......
......@@ -48,9 +48,16 @@
(lambda () (next-method))
(lambda x (hash x N))))
(aif it (ref-class x '__hash__ #f)
(it)
(next)))
(aif it (ref x '__hash__ #f)
(catch #t
(lambda () (it))
(lambda x
(catch #t
(lambda ()
(it x))
(lambda x
(next)))))
(next)))
(set object '__hash__
(object-method
......
......@@ -107,11 +107,13 @@
s))))
(define-method (to-list x)
(if (bool x)
(for ((i : x)) ((r '()))
(cons i r)
#:final (reverse r))
'()))
(if (pair? x)
x
(if (bool x)
(for ((i : x)) ((r '()))
(cons i r)
#:final (reverse r))
'())))
(define-method (to-list (x <p>))
(aif it (ref x '__tolist__)
......@@ -1057,3 +1059,5 @@
(define py-list list)
(set! (@@ (oop dict) to-list) to-list)
(define-method (scheme? (o <py-list>)) py-list)
......@@ -40,7 +40,7 @@
IndexError KeyError AttributeError
sendException next
GeneratorExit sendClose RuntimeError
SyntaxError bool compile
SyntaxError compile
len dir next dict None property range
tuple bytes bytearray locals globals
exec type object __import__ frozenset
......@@ -51,7 +51,7 @@
#:export (print repr complex float int str
set all any bin callable reversed
chr classmethod staticmethod objectmethod
divmod enumerate delattr
divmod enumerate delattr bool
getattr hasattr setattr delattr hex isinstance issubclass
iter sum id input oct ord pow super
sorted zip vars slice))
......@@ -122,8 +122,11 @@
(define* (getattr a b #:optional (k miss))
(let ((r (ref a (if (string? b) (string->symbol b) b) miss)))
(if (eq? r miss)
(if (eq? k miss)
(raise AttributeError "object/class ~a is missing attribute ~a" a b)
(if (eq? k miss)
(if (equal? b "__module__")
"<builtin>"
(raise AttributeError
"object/class ~a is missing attribute ~a" a b))
k)
r)))
......@@ -527,3 +530,4 @@
(lambda (x) (isinstance x (@@ (language python module) Module))))
(define (delattr o key) (rawdel o key))
(define bool boolean)
......@@ -59,7 +59,7 @@
(cons name l)
l)
#:final (reverse l))))))
(pk 'abc_o_a (object-address cls))
(for ((base : bases)) ()
(for ((name : (ref base '__abstractmethods__ (py-set '())))) ()
(let ((value (getattr cls name None)))
......
......@@ -20,7 +20,7 @@
#:use-module (language python exceptions)
#:use-module (language python module keyword)
#:use-module ((language python module python)
#:select ((map . pymap) isinstance reversed classmethod iter
#:select ((map . pymap) str isinstance reversed classmethod iter
any repr property super sorted
enumerate (map . py-map)))
......@@ -615,15 +615,14 @@
(set! field_names
(for ((fs : field_names)) ((r '()))
(if (string? fs)
(append (string-split fs #\space)
(if (isinstance fs str)
(append (string-split (scm-str fs) #\space)
r)
(cons fs r))
#:final
r))
(set! field_names (py-list (map scm-str field_names)))
(set! typename (scm-str typename))
(if rename
......@@ -648,6 +647,7 @@
(format #f "keyword: ~a" name)))))
(set! seen (py-set))
(for ((name : field_names)) ()
(if (and (py-startswith name "_") (not rename))
(raise ValueError
......@@ -660,7 +660,7 @@
(py-add! seen name))
(set! field_names (map string->symbol (to-list field_names)))
(make-p-class (string->symbol typename) '(())
(lambda (dict)
(pylist-set! dict '_fields (map symbol->string field_names))
......
......@@ -71,6 +71,7 @@
(setattr wrapper attr None))))
(for ((attr : updated)) ()
(pk 'attr attr)
(py-update (getattr wrapper attr) (getattr wrapped attr (dict))))
(set wrapper '__wrapped__ wrapped)
......@@ -232,11 +233,12 @@
(aif it (ref func 'func)
(begin
(set! args (+ (ref func 'args) args))
(let ((tmpkw (py-copy (ref func 'keywords))))
(let ((tmpkw (py-copy (aif it (ref func 'keywords #f)
it
(dict)))))
(py-update tmpkw keywords)
(set! keywords tmpkw)
(set func it))))
(set self 'func func )
(set self 'args args )
(set self 'keywords keywords)
......@@ -244,11 +246,13 @@
(define __call__
(lam (self (* args) (** keywords))
(let ((newkeywords (py-copy (ref self 'keywords))))
(py-update newkeywords 'keywords)
(py-apply (ref self 'func) (* (ref self 'args)) (* args)
(** newkeywords)))))
(let ((newkeywords (py-copy (aif it (ref self 'keywords #f)
it
(dict)))))
(py-update newkeywords keywords)
(py-apply (ref self 'func) (* (ref self 'args)) (* args)
(** newkeywords)))))
(define __repr__
(lambda (self)
......@@ -277,7 +281,9 @@
(begin
(set self 'func (ref func 'func))
(set self 'args (+ (ref func 'args) args))
(let ((kws (py-copy (ref func 'keywords))))
(let ((kws (py-copy (aif it (ref func 'keywords)
it
(dict)))))
(py-update kws keywords)
(set self 'keywords kws)))
(begin
......@@ -303,10 +309,12 @@
(define _make_unbound_method
(lambda (self)
(def (_method self (* args) (** keywords))
(let ((call_keywords (py-copy (ref self 'keywords)))
(call_args (+ (list self) (ref self 'args) args)))
(py-update call_keywords keywords)
(py-apply (ref self 'func) (* call_args) (** call_keywords))))
(let ((call_keywords (py-copy (aif it (ref self 'keywords #f)
it
(dict '()))))
(call_args (+ (list self) (ref self 'args) args)))
(py-update call_keywords keywords)
(py-apply (ref self 'func) (* call_args) (** call_keywords))))
(set _method '__isabstractmethod__ (ref self '__isabstractmethod__))
(set _method '_partialmethod self)
......@@ -454,7 +462,7 @@
(let/ec return
(let* ((key (make_key args kwds typed)))
(with ((lock))
(let ((link (cache_get cache key 'None)))
(let ((link (cache_get cache key None)))
(when (not (eq? link None))
(let ((link_prev (list-ref link 0))
(link_next (list-ref link 1))
......@@ -473,7 +481,7 @@
(let ((result (py-apply user_function (* args) (** kwds))))
(with ((lock))
(cond
((in key cache) (values))
((in key cache) (pk 0.1) (values))
(full
(let ((oldroot root))
(list-set! oldroot KEY key)
......@@ -491,7 +499,7 @@
(list-set! last NEXT link)
(list-set! root PREV link)
(pylist-set! cache key link)
(set! full (>= (cache_len) maxsize)))))
(set! full (>= (cache_len cache) maxsize)))))
(set! misses (+ misses 1)))
result))))))))
......
This diff is collapsed.
......@@ -702,5 +702,12 @@
(define-method (py-bin o)
(+ "0b" (number->string (py-index o) 2)))
(define-method (scheme? (o <integer> )) py-int)
(define-method (scheme? (o <py-int> )) py-int)
(define-method (scheme? (o <complex> )) py-complex)
(define-method (scheme? (o <py-complex>)) py-complex)
(define-method (scheme? (o <real> )) py-float)
(define-method (scheme? (o <py-float> )) py-float)
(set! (@@ (oop dict) int) int)
......@@ -72,11 +72,19 @@
(procedure-name f)))
((equal? tag '__dict__)
(dict (let lp ((l (procedure-properties- f)))
(if (pair? l)
(cons (list (car l) (cdr l))
(lp (cdr l)))
'()))))
(dict
(append
(list
(list '__class__ (ref-f f '__class__))
(list '__name__ (ref-f f '__name__))
(list '__code__ (ref-f f '__code__))
(list '__doc__ (ref-f f '__doc__))
(list '__qualname__ (ref-f f '__qualname__)))
(let lp ((l (procedure-properties- f)))
(if (pair? l)
(cons (list (car l) (cdr l))
(lp (cdr l)))
'())))))
((equal? tag '__annotations__)
(procedure-property- f '__annotations__))
......
......@@ -278,14 +278,34 @@
(define __xor__
(lambda (self op)
(symmetric_difference self op)))
(define __lt__
(lambda (self other)
(for ((k : self)) ()
(if (in k other)
(values)
(break #f))
#:final #t)))
(define __le__
(lambda (self other)
(and (not (__eq__ self other))
(__le__ self other))))
(define __ge__
(lambda (self other)
(not (__lt__ other self))))
(define __gt__
(lambda (self other)
(not (__le__ other self))))
(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)))))
(__lt__ self x)
(__lt__ x self))))
(define __iter__
(lambda (self)
((make-generator ()
......
......@@ -34,7 +34,7 @@
(define (scm-str x)
(if (string? x)
x
(slot-ref (pystring x) 'str)))
(string x)))
(define (scm-sym x)
(if (symbol? x)
......@@ -752,3 +752,5 @@
l))
(define-method (scheme? (o <string>)) string)
(define-method (scheme? (o <py-string>)) string)
......@@ -3,6 +3,7 @@
#:use-module (oop pf-objects)
#:use-module (language python hash)
#:use-module (language python for)
#:use-module (language python yield)
#:use-module (language python bool)
#:use-module (language python persist)
#:export (tuple <py-tuple> defpair))
......@@ -35,6 +36,14 @@
(cons x l)
#:final
(reverse l))))))
(define __iter__
(lambda (self)
((make-generator ()
(lambda (yield)
(for ((k : (slot-ref self 'l))) ()
(yield k)
(values)))))))
(define __repr__
(lambda (self) (format #f "~a" (slot-ref self 'l)))))
......@@ -47,3 +56,7 @@
(define-method (f (o <py-tuple>) . l)
(let ((o (slot-ref o 'l)))
(apply f o l)))))
(define-method (scheme? (o <pair>)) tuple)
(define-method (scheme? (o <py-tuple>)) tuple)
......@@ -72,7 +72,7 @@
(define (mkw kw) (error "not implemented"))
(define to-list #f)
(define to-list (lambda (x) x))
(define (int x) x)
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment