diff options
author | Stefan Israelsson Tampe <stefan.itampe@gmail.com> | 2017-10-15 21:24:44 +0200 |
---|---|---|
committer | Stefan Israelsson Tampe <stefan.itampe@gmail.com> | 2017-10-15 21:24:44 +0200 |
commit | a7346773d6b517fc09e5b776fb685daffc228528 (patch) | |
tree | 6cf641f121e2b9f9cb1e8beaa1d7657cc11a4b68 /modules/language/python/compile.scm | |
parent | 7852343a565da36a09340306a57cae9d3239337a (diff) |
bytevecor improvements
Diffstat (limited to 'modules/language/python/compile.scm')
-rw-r--r-- | modules/language/python/compile.scm | 57 |
1 files changed, 38 insertions, 19 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)))) |