diff options
Diffstat (limited to 'modules/language/python/compile.scm')
-rw-r--r-- | modules/language/python/compile.scm | 72 |
1 files changed, 33 insertions, 39 deletions
diff --git a/modules/language/python/compile.scm b/modules/language/python/compile.scm index 8007449..fdc6309 100644 --- a/modules/language/python/compile.scm +++ b/modules/language/python/compile.scm @@ -11,12 +11,27 @@ #:use-module (language python list) #:use-module (language python string) #:use-module (language python def) - #:use-module (language python set) #:use-module (ice-9 pretty-print) #:export (comp)) (define-syntax-rule (aif it p x y) (let ((it p)) (if it x y))) +(define-inlinable (C x) `(@@ (language python compile) ,x)) +(define-inlinable (Y x) `(@@ (language python yield) ,x)) +(define-inlinable (T x) `(@@ (language python try) ,x)) +(define-inlinable (F x) `(@@ (language python for) ,x)) +(define-inlinable (E x) `(@@ (language python exceptions) ,x)) +(define-inlinable (L x) `(@@ (language python list) ,x)) +(define-inlinable (A x) `(@@ (language python array) ,x)) +(define-inlinable (S x) `(@@ (language python string) ,x)) +(define-inlinable (Se x) `(@@ (language python set) ,x)) +(define-inlinable (D x) `(@@ (language python def) ,x)) +(define-inlinable (Di x) `(@@ (language python dict) ,x)) +(define-inlinable (O x) `(@@ (oop pf-objects) ,x)) +(define-inlinable (G x) `(@ (guile) ,x)) + + + (define s/d 'set!) (define-syntax clear-warning-data @@ -78,34 +93,13 @@ (define (gen-sel vs e item) (match e + (#f item) ((#:cfor for-e in-e cont) - `(,(F 'for) ((,@(map (g vs exp) for-e) : ,(exp vs in))) - ,(if cont - (gen-sel vs cont item) - item))) + `(,(F 'for) ((,@(map (g vs exp) for-e) : ,(exp vs in-e))) () + ,(gen-sel vs cont item))) ((#:cif cif cont) `(if ,(exp vs cif) - ,(if cont - (gen-sel vs cont item) - item))))) - -(define (gen-sel vs e item) - (match e - ((#:cif . l) - (gen-cif vs e item - -(define-inlinable (C x) `(@@ (language python compile) ,x)) -(define-inlinable (Y x) `(@@ (language python yield) ,x)) -(define-inlinable (T x) `(@@ (language python try) ,x)) -(define-inlinable (F x) `(@@ (language python for) ,x)) -(define-inlinable (E x) `(@@ (language python exceptions) ,x)) -(define-inlinable (L x) `(@@ (language python list) ,x)) -(define-inlinable (A x) `(@@ (language python array) ,x)) -(define-inlinable (S x) `(@@ (language python string) ,x)) -(define-inlinable (D x) `(@@ (language python def) ,x)) -(define-inlinable (Di x) `(@@ (language python dict) ,x)) -(define-inlinable (O x) `(@@ (oop pf-objects) ,x)) -(define-inlinable (G x) `(@ (guile) ,x)) + ,(gen-sel vs cont item))))) (define (union as vs) (let lp ((as as) (vs vs)) @@ -396,7 +390,7 @@ (cdr addings))) (cons v addings))) (v (car v.add)) - (addings (cdr addings)) + (addings (cdr v.add)) (addings (get-addings vs addings))) (define q (lambda (x) `',x)) (if kind @@ -947,8 +941,8 @@ (#:list ((_ x (and e (#:cfor . _))) (let ((l (gensym "l"))) - `(let ((,l ,((L 'to-pylist) '()))) - ,(gen-sel vs e `(pylist-append ,l ,(exp vs x))) + `(let ((,l (,(L 'to-pylist) '()))) + ,(gen-sel vs e `(,(L 'pylist-append!) ,l ,(exp vs x))) ,l))) ((_ . l) @@ -965,7 +959,7 @@ `(cons ,(exp vs x) ,(lp l)))))))) (#:tuple ((_ x (and e (#:cfor . _))) - (let ((l (gensym "l"))) + (let ((l (gensym "l"))) `(let ((,l '())) ,(gen-sel vs e `(set! ,l (cons ,(exp vs x) ,l))) (reverse ,l)))) @@ -1042,7 +1036,7 @@ ((_ (#:e k . v) (and e (#:cfor . _))) (let ((dict (gensym "dict"))) `(let ((,dict (,(Di 'make-py-hashtable)))) - ,(gen-sel vs e `(pylist-set! ,dict ,(exp vs k) ,(exp vs v))) + ,(gen-sel vs e `(,(L 'pylist-set!) ,dict ,(exp vs k) ,(exp vs v))) ,dict))) ((_ (#:e k . v) ...) @@ -1051,21 +1045,21 @@ ,@(map (lambda (k v) `(,(L 'pylist-set!) ,dict ,(exp vs k) ,(exp vs v))) k v) - ,dict)))) + ,dict))) - ((_ k (and e (#:cfor . _))) + ((_ k (and e (#:cfor . _))) (let ((dict (gensym "dict"))) `(let ((,dict (,(Se 'set)))) - ,(gen-sel vs e `(,(O 'ref) ,dict 'add) ,(exp vs k)) + ,(gen-sel vs e `((,(O 'ref) ,dict 'add) ,(exp vs k))) ,dict))) - ((_ k ...) + ((_ k ...) (let ((set (gensym "dict"))) `(let ((,set (,(Se 'set)))) - ,@(map (lambda (k v) - `((,(O 'ref) 'add) ,set ,(exp vs k))) - k v) - ,dict)))) + ,@(map (lambda (k) + `((,(O 'ref) ,set 'add) ,(exp vs k))) + k) + ,set)))) (#:comp |