diff options
Diffstat (limited to 'modules/language')
-rw-r--r-- | modules/language/python/compile.scm | 50 | ||||
-rw-r--r-- | modules/language/python/list.scm | 18 |
2 files changed, 54 insertions, 14 deletions
diff --git a/modules/language/python/compile.scm b/modules/language/python/compile.scm index 9076e61..07a8e29 100644 --- a/modules/language/python/compile.scm +++ b/modules/language/python/compile.scm @@ -8,6 +8,7 @@ #:use-module (language python for) #:use-module (language python try) #:use-module (language python list) + #:use-module (language python string) #:use-module (ice-9 pretty-print) #:export (comp)) @@ -55,6 +56,7 @@ (define-inlinable (F x) `(@@ (language python for) ,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 (O x) `(@@ (oop pf-objects) ,x)) (define-inlinable (G x) `(@ (guile) ,x)) @@ -177,8 +179,27 @@ ((remove) (L 'pylist-remove!)) ((reverse) (L 'pylist-reverse!)) ((sort) (L 'pylist-sort!)) + + ;; String + ((format) (S 'py-format)) (else #f))) +(define (get-kwarg vs arg) + (let lp ((arg arg) (l '()) (kw '())) + (match arg + (((#:= a b) . arg) + (lp arg + l + (cons* + (exp vs b) + (symbol->keyword + (exp vs a)) + kw))) + ((x . arg) + (lp arg (cons (exp vs x) l) kw)) + (() + (values (reverse l) (reverse kw)))))) + (define (get-addings vs x) (match x (() '()) @@ -204,12 +225,14 @@ is-fkn? `(#:identifier ',tag)))) - ((#:arglist args apply #f) - (if apply - `(#:apply ,@(map (g vs exp) args) - ,`(,(L 'to-list) ,(exp vs apply))) - `(#:call ,@(map (g vs exp) args)))) - + ((#:arglist args apply #f) + (call-with-values (lambda () (get-kwarg vs args)) + (lambda (args kwarg) + (if apply + `(#:apply ,@args ,@kwarg + ,`(,(L 'to-list) ,(exp vs apply))) + `(#:call ,@args ,@kwarg))))) + ((#:subscripts (n #f #f)) `(#:vecref ,(exp vs n))) @@ -337,12 +360,15 @@ trailer))) ((#:arglist args apply #f) - (if apply - (lp `(apply ,e - ,@(map (g vs exp) args) - ,`(,(L 'to-list) ,(exp vs apply))) - trailer) - (lp `(,e ,@(map (g vs exp) args)) trailer))) + (call-with-values (lambda () (get-kwarg vs args)) + (lambda (args kwarg) + (if apply + (lp `(apply ,e + ,@args + ,@kwarg + ,`(,(L 'to-list) ,(exp vs apply))) + trailer) + (lp `(,e ,@args ,@kwarg) trailer))))) ((#:subscripts (n #f #f)) `(,(L 'pylist-ref) ,e ,(exp vs n))) diff --git a/modules/language/python/list.scm b/modules/language/python/list.scm index f31fcba..3b7fbd5 100644 --- a/modules/language/python/list.scm +++ b/modules/language/python/list.scm @@ -65,6 +65,9 @@ (define-method (to-pylist (l <vector>)) (to-pylist (vector->list l))) +(define-method (to-pylist (o <string>)) + (to-pylist (string->list o))) + (define-method (to-pylist l) (if (null? l) (let ((o (make <py-list>))) @@ -125,8 +128,19 @@ '())))) (to-pylist l))) -(define-method (pylist-slice o n1 n2 n3) - (pylist-slice (to-pylist o) n1 n2 n3)) +(define-method (pylist-slice (o <string>) n1 n2 n3) + (list->string + (to-list + (pylist-slice (to-pylist o) n1 n2 n3)))) + +(define-method (pylist-slice (o <pair>) n1 n2 n3) + (to-list + (pylist-slice (to-pylist o) n1 n2 n3))) + +(define-method (pylist-slice (o <vector>) n1 n2 n3) + (list->vector + (to-list + (pylist-slice (to-pylist o) n1 n2 n3)))) ;;SUBSET (define-method (pylist-subset! (o <py-list>) n1 n2 n3 val) |