summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/language/python/compile.scm57
-rw-r--r--modules/language/python/str.scm3
2 files changed, 40 insertions, 20 deletions
diff --git a/modules/language/python/compile.scm b/modules/language/python/compile.scm
index ab9b8f6..50698c8 100644
--- a/modules/language/python/compile.scm
+++ b/modules/language/python/compile.scm
@@ -3,6 +3,7 @@
#:use-module (ice-9 control)
#:use-module (oop pf-objects)
#:use-module (oop goops)
+ #:use-module (rnrs bytevectors)
#:use-module (language python dict)
#:use-module (language python exceptions)
#:use-module (language python yield)
@@ -10,6 +11,7 @@
#:use-module (language python try)
#:use-module (language python list)
#:use-module (language python string)
+ #:use-module (language python str)
#:use-module (language python number)
#:use-module (language python def)
#:use-module (ice-9 pretty-print)
@@ -17,21 +19,22 @@
(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 (N x) `(@@ (language python number) ,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-inlinable (H x) `(@ (language python hash) ,x))
+(define-inlinable (C x) `(@@ (language python compile) ,x))
+(define-inlinable (N x) `(@@ (language python number) ,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 (STR x) `(@@ (language python str) ,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-inlinable (H x) `(@ (language python hash) ,x))
(define s/d 'set!)
@@ -597,11 +600,27 @@
'(values)))
(#:string
- ((#:string p x)
- (if (or (equal? p "r") (equal? p "R"))
- `((@ (language python str) str) ,x)
- x)))
+ ((_ l)
+ (string-join l "")))
+ (#:bytes
+ ((_ l)
+ (let* ((n (let lp ((l l) (s 0))
+ (if (pair? l)
+ (lp (cdr l) (+ s (length (car l))))
+ s)))
+ (b (make-bytevector n)))
+ (let lp ((l l) (i 0))
+ (if (pair? l)
+ (let lp2 ((u (car l)) (i i))
+ (if (pair? u)
+ (begin
+ (bytevector-u8-set! b i (car u))
+ (lp2 (cdr u) (+ i 1)))
+ (lp (cdr l) i)))))
+ `(,(STR 'str) ,b))))
+
+
(#:+
((_ . l)
(cons '+ (map (g vs exp) l))))
diff --git a/modules/language/python/str.scm b/modules/language/python/str.scm
index e4e821b..ef09def 100644
--- a/modules/language/python/str.scm
+++ b/modules/language/python/str.scm
@@ -71,7 +71,8 @@
(define-method (f (o <py-str>) . l) (apply f (slot-ref o 'str) l))))
(define-method (write (b <py-str>) . l)
- (apply write (b->string (slot-ref b 'str)) l))
+ (define port (if (pair? l) (car l) #t))
+ (format port "b~s" (b->string (slot-ref b 'str))))
(define dynlink (dynamic-link))