1 (define-module (language python compile
)
2 #:use-module
(ice-9 match
)
3 #:use-module
(ice-9 control
)
4 #:use-module
(oop pf-objects
)
5 #:use-module
(oop goops
)
6 #:use-module
(rnrs bytevectors
)
7 #:use-module
(language python dict
)
8 #:use-module
(language python exceptions
)
9 #:use-module
(language python yield
)
10 #:use-module
(language python for
)
11 #:use-module
(language python try
)
12 #:use-module
(language python list
)
13 #:use-module
(language python string
)
14 #:use-module
(language python bytes
)
15 #:use-module
(language python number
)
16 #:use-module
(language python def
)
17 #:use-module
(language python module
)
18 #:use-module
(language python dir
)
19 #:use-module
(language python procedure
)
20 #:use-module
(language python bool
)
21 #:use-module
((language python with
) #:select
())
22 #:use-module
(ice-9 pretty-print
)
25 (define-syntax-rule (aif it p x y
) (let ((it p
)) (if it x y
)))
27 (define-inlinable (C x
) `(@@ (language python compile
) ,x
))
28 (define-inlinable (N x
) `(@@ (language python number
) ,x
))
29 (define-inlinable (Y x
) `(@@ (language python yield
) ,x
))
30 (define-inlinable (T x
) `(@@ (language python try
) ,x
))
31 (define-inlinable (F x
) `(@@ (language python for
) ,x
))
32 (define-inlinable (E x
) `(@@ (language python exceptions
) ,x
))
33 (define-inlinable (L x
) `(@@ (language python list
) ,x
))
34 (define-inlinable (S x
) `(@@ (language python string
) ,x
))
35 (define-inlinable (B x
) `(@@ (language python bytes
) ,x
))
36 (define-inlinable (Se x
) `(@@ (language python set
) ,x
))
37 (define-inlinable (D x
) `(@@ (language python def
) ,x
))
38 (define-inlinable (Di x
) `(@@ (language python dict
) ,x
))
39 (define-inlinable (O x
) `(@@ (oop pf-objects
) ,x
))
40 (define-inlinable (G x
) `(@ (guile) ,x
))
41 (define-inlinable (H x
) `(@ (language python hash
) ,x
))
42 (define-inlinable (W x
) `(@ (language python with
) ,x
))
44 (define-syntax-rule (use a ...
)
46 (lambda () (use-modules a ...
))
47 (lambda x
(raise (ImportError '(a ...
))))))
51 (define (pre) (warn "Patching guile will lead to way better experience use 'python.patch' on guile-2.2 e.g. (use-modules (language python guilemod))"))
53 (define-syntax clear-warning-data
57 (fluid-set! (@@ (system base message
) %dont-warn-list
) '()))
64 (fluid-set! (@@ (system base message
) %dont-warn-list
)
66 (fluid-ref (@@ (system base message
) %dont-warn-list
)))))
69 (define *prefixes
* (make-fluid '()))
70 (define (add-prefix id
)
73 (if (fluid-ref (@@ (system base compile
) %in-compile
))
74 (fluid-set! *prefixes
* (cons id
(fluid-ref *prefixes
*)))
76 (when (not (module-defined?
(current-module) '__prefixes__
))
77 (module-define! (current-module)
78 '__prefixes__
(make-fluid '())))
80 (let ((p (module-ref (current-module) '__prefixes__
)))
81 (fluid-set! p
(cons id
(fluid-ref p
)))))))
84 (define (is-prefix? id
)
87 (if (fluid-ref (@@ (system base compile
) %in-compile
))
88 (member id
(fluid-ref *prefixes
*))
89 (if (not (module-defined?
(current-module) '__prefixes__
))
91 (let ((p (module-ref (current-module) '__prefixes__
)))
92 (member id
(fluid-ref p
))))))
97 ((_ (f) . l
) (f . l
))))
99 (define (fold f init l
)
101 (fold f
(f (car l
) init
) (cdr l
))
105 (define port
(open-file "/home/stis/src/python-on-guile/log.txt" "a"))
106 (with-output-to-port port
108 (pretty-print (syntax->datum x
))))
113 (define port
(open-file "/home/stis/src/python-on-guile/compile.log" "a"))
114 (with-output-to-port port
115 (lambda () (pretty-print (syntax->datum x
)) x
))
120 (pretty-print (syntax->datum x
))
123 (define (gen-sel vs e item
)
126 ((#:cfor for-e in-e cont
)
127 (let lp
((for-e for-e
))
129 (((#:power
#f
(#:tuple . l
) . _
))
132 `(,(F 'for
) ((,@(map (g vs exp
) for-e
) : ,(exp vs in-e
))) ()
133 ,(gen-sel vs cont item
))))))
136 ,(gen-sel vs cont item
)))))
138 (define (union as vs
)
139 (let lp
((as as
) (vs vs
))
144 (lp as
(cons x vs
))))
149 (let lp
((as as
) (rs '()))
154 (lp as
(cons x rs
))))
158 (define (get-globals code
)
159 (let lp
((vs (glob code
'())) (rs (scope code
'())))
171 (let lp
((l l
) (vs vs
))
173 (((#:identifier v . _
) . l
)
174 (let ((s (string->symbol v
)))
177 (lp l
(cons s vs
)))))
181 (glob y
(glob x vs
)))
187 (union (list (exp '() f
)) vs
))
192 ((#:with
(l ...
) code
)
193 (scope code
(union vs
197 (cons (exp '() b
) (lp l
)))
202 (union (list (exp '() f
)) vs
))
207 ((#:import
(#:name
((ids ...
) . as
)) ...
)
208 (let lp
((ids ids
) (as as
) (vs vs
))
210 (lp (cdr ids
) (cdr as
)
213 (union vs
(list (exp '() (if as as
(car ids
)))))))
216 ((#:expr-stmt l
(#:assign u
))
217 (union (fold (lambda (x s
)
219 ((#:test
(#:power v2 v1
() . _
) . _
)
222 (union (list (exp '() v1
))
225 (union (list (exp '() v1
)) s
)))
231 ((#:expr-stmt l
(#:assign k . u
))
233 (union (fold (lambda (x s
)
235 ((#:test
(#:power v2 v1
() . _
) . _
)
238 (union (list (exp '() v1
))
241 (union (list (exp '() v1
)) s
)))
246 (scope `(#:expr-stmt
,k
(#:asignvs .
,u
)) vs
)))
249 (scope y
(scope x vs
)))
254 ((#:def
(#:identifier f
) . _
)
255 (union (list (string->symbol f
)) vs
))
262 ((#:import
(#:name
((ids ...
) . as
)) ...
)
263 (let lp
((ids ids
) (as as
) (vs vs
))
265 (lp (cdr ids
) (cdr as
)
268 (union vs
(list (exp '() (if as as
(car ids
)))))))
271 (defs y
(defs x vs
)))
274 (define (gen-yield f
)
281 (lambda (x) (e vs x
)))
283 (define return
(make-fluid 'error-return
))
285 (define-syntax-rule (<< x y
) (ash x y
))
286 (define-syntax-rule (>> x y
) (ash x
(- y
)))
288 (define-syntax-rule (mkfast ((a) v
) ...
)
289 (let ((h (make-hash-table)))
295 (aif it
(assoc x
`((__class__ .
,(O 'py-class
))))
302 ((__init__) (O 'py-init
))
303 ((__getattr__) (O 'getattr
))
304 ((__setattr__) (O 'setattr
))
305 ((__delattr__) (O 'delattr
))
307 ((__eq__) (O 'equal?
))
308 ((__repr__) (O 'repr
))
311 ((__iter__) (F 'wrap-in
))
312 ((__next__) (F 'next
))
313 ((__send__) (Y 'send
))
314 ((__exception__) (Y 'sendException
))
315 ((__close__) (Y 'sendClose
))
318 ((__index__) (N 'py-index
))
322 ((__radd__ ) (N 'r
+))
323 ((__rmul__ ) (N 'r
*))
324 ((__rsub__ ) (N 'r-
))
330 ((__abs__ ) (N 'py-abs
))
331 ((__pow__ ) (N 'expt
))
332 ((__rpow__ ) (N 'rexpt
))
333 ((__truediv__) (N 'py-
/))
334 ((__rtruediv__) (N 'py-r
/))
335 ((__and__) (N 'py-logand
))
336 ((__or__) (N 'py-logior
))
337 ((__xor__) (N 'py-logxor
))
338 ((__rand__) (N 'py-rlogand
))
339 ((__ror__) (N 'py-rlogior
))
340 ((__rxor__) (N 'py-rlogxor
))
341 ((__divmod__) (N 'py-divmod
))
342 ((__rdivmod__) (N 'py-rdivmod
))
343 ((__invert__) (N 'py-lognot
))
344 ((__int__) (N 'mk-int
))
345 ((__float__) (N 'mk-float
))
346 ((__lshift__) (N 'py-lshift
))
347 ((__rshift__) (N 'py-rshift
))
348 ((__rlshift__) (N 'py-rlshift
))
349 ((__rrshift__) (N 'py-rrshift
))
350 ((as_integer_ratio) (N 'py-as-integer-ratio
))
351 ((conjugate) (N 'py-conjugate
))
352 ((denominator) (N 'py-denominator
))
353 ((numerator) (N 'py-numerator
))
354 ((fromhex) (N 'py-fromhex
))
356 ((imag) (N 'py-imag
))
357 ((is_integer) (N 'py-is-integer
))
358 ((real) (N 'py-real
))
359 ((__mod__) (N 'py-mod
))
360 ((__rmod__) (N 'py-rmod
))
361 ((__floordiv__) (N 'py-floordiv
))
362 ((__rfloordiv__)(N 'py-rfloordiv
))
366 ((append) (L 'pylist-append
!))
367 ((count) (L 'pylist-count
))
368 ((extend) (L 'pylist-extend
!))
369 ((index) (L 'pylist-index
))
370 ((pop) (L 'pylist-pop
!))
371 ((insert) (L 'pylist-insert
!))
372 ((remove) (L 'pylist-remove
!))
373 ((reverse) (L 'pylist-reverse
!))
374 ((sort) (L 'pylist-sort
!))
376 ((__contains__) (L 'in
))
377 ((__delitem__) (L 'pylist-delete
!))
378 ((__delslice__) (L 'pylist-delslice
))
379 ((__setitem__) (L 'pylist-set
!))
382 ((format) (S 'py-strformat
))
383 ((format_map) (S 'py-format-map
))
384 ((capitalize) (S 'py-capitalize
))
385 ((center) (S 'py-center
))
386 ((endswith) (S 'py-endswith
))
387 ((expandtabs) (S 'py-expandtabs
))
388 ((find) (S 'py-find
))
389 ((rfind) (S 'py-rfind
))
390 ((isalnum) (S 'py-isalnum
))
391 ((isalpha) (S 'py-isalpha
))
392 ((isdigit) (S 'py-isdigit
))
393 ((islower) (S 'py-islower
))
394 ((isspace) (S 'py-isspace
))
395 ((isupper) (S 'py-isupper
))
396 ((istitle) (S 'py-istitle
))
397 ((isidentifier) (S 'py-identifier
))
398 ((join) (S 'py-join
))
399 ((ljust) (S 'py-join
))
400 ((rljust) (S 'py-rljust
))
401 ((lower) (S 'py-lower
))
402 ((upper) (S 'py-upper
))
403 ((lstrip) (S 'py-lstrip
))
404 ((rstrip) (S 'py-rstrip
))
405 ((partition) (S 'py-partition
))
406 ((replace) (S 'py-replace
))
407 ((strip) (S 'py-strip
))
408 ((title) (S 'py-title
))
409 ((rpartition) (S 'py-rpartition
))
410 ((rindex) (S 'py-rindex
))
411 ((split) (S 'py-split
))
412 ((rsplit) (S 'py-rsplit
))
413 ((splitlines) (S 'py-splitlines
))
414 ((startswith) (S 'py-startswith
))
415 ((swapcase) (S 'py-swapcase
))
416 ((translate) (S 'py-translate
))
417 ((zfill) (S 'py-zfill
))
420 ((copy) (Di 'py-copy
))
421 ((fromkeys) (Di 'py-fromkeys
))
423 ((has_key) (Di 'py-has_key
))
424 ((items) (Di 'py-items
))
425 ((iteritems) (Di 'py-iteritems
))
426 ((iterkeys) (Di 'py-iterkeys
))
427 ((itervalues) (Di 'py-itervalues
))
428 ((keys) (Di 'py-keys
))
429 ((values) (Di 'py-values
))
430 ((popitem) (Di 'py-popitem
))
431 ((setdefault) (Di 'py-setdefault
))
432 ((update) (Di 'py-update
))
433 ((clear) (Di 'py-clear
))
434 ((__hash__) (H 'py-hash
))))
437 (define (fastfkn x
) (hash-ref fasthash x
))
439 (define (get-kwarg vs arg
)
442 (((#:comp .
(and x
(_ (#:cfor . _
) . _
))) . arg2
)
443 (cons `(* ,(exp vs
`(#:tuple
,@x
))) (lp arg2
)))
445 (cons `(* ,(exp vs a
)) (lp arg
)))
447 (cons `(** ,(exp vs a
)) (lp arg
)))
449 (cons `(= ,(exp vs a
) ,(exp vs b
)) (lp arg
)))
451 (cons (exp vs x
) (lp arg
)))
461 (define (get-args_ vs arg
)
465 (cons (exp vs
(getarg x
))
473 (define (get-args= vs arg
)
477 (cons (list '= (exp vs
(getarg x
)) (exp vs v
))
486 (define (get-args* vs arg
)
490 (cons (list '* (exp vs
(getarg x
)))
499 (define (get-args** vs arg
)
503 (cons (list '** (exp vs
(getarg x
)))
512 (define (kw->li dict
)
513 (for ((k v
: dict
)) ((l '()))
514 (cons* v
(symbol->keyword
(string->symbol k
)) l
)
518 (define (arglist->pkw . l
)
519 (let lp
((l l
) (r '()))
524 (lp (cdr l
) (cons x r
))))
525 (cons (reverse l
) '()))))
527 (define (get-addings vs x
)
531 (let ((is-fkn?
(match l
533 (((#:arglist . _
) . _
)
541 (let* ((tag (exp vs x
))
544 (is-fkn?
(aif it
(and is-fkn? fast
)
545 `(#:call-obj
(lambda (e)
552 `(#:fastfkn-ref
,fast
',tag
)
553 (aif it
(fast-ref tag
)
554 `(#:fast-id
,it
',tag
)
555 `(#:identifier
',tag
))))))
558 `(#:apply
,@(get-kwarg vs args
)))
560 ((#:subscripts
(n #f
#f
))
561 `(#:vecref
,(exp vs n
)))
563 ((#:subscripts
(n1 n2 n3
))
564 (let ((w (lambda (x) (if (eq? x None
) (E 'None
) x
))))
566 ,(w (exp vs n1
)) ,(w (exp vs n2
)) ,(w (exp vs n3
)))))
568 ((#:subscripts
(n #f
#f
) ...
)
569 `(#:array-ref
,@ (map (lambda (n)
573 ((#:subscripts
(n1 n2 n3
) ...
)
574 (let ((w (lambda (x) (if (eq? x None
) (E 'None
) x
))))
576 ,@(map (lambda (x y z
)
577 `(,(exp vs x
) ,(exp vs y
) ,(exp vs z
)))
580 (_ (error "unhandled addings")))
581 (get-addings vs l
))))))
583 (define-syntax-rule (setwrap u
)
584 (call-with-values (lambda () u
)
589 (define (make-set vs op x u
)
603 ("//=" 'floor-quotient
)))
607 ((#:test
(#:power kind v addings . _
) . _
)
608 (let* ((v (exp vs v
))
609 (v.add
(if (is-prefix? v
)
610 (let ((w (symbol->string
(exp vs
(car addings
)))))
611 (cons (string-append (symbol->string v
) "." w
)
615 (addings (cdr v.add
))
616 (addings (get-addings vs addings
))
621 (let ((w (symbol->string
(exp vs
(car add
)))))
622 (cons (string-append (symbol->string v
) "." w
)
624 (cons (exp vs v
) add
)))))
627 (pa (get-addings vs pa
)))
628 (define q
(lambda (x) `',x
))
633 `(,s
/d
,v
(,(C 'setwrap
) (,(tr-op op
) ,v
,u
)))
634 `(,s
/d
,v
(,(C 'setwrap
) ,u
)))
636 `(,s
/d
,(exp vs kind
)
637 (,(C 'fset-x
) ,v
,addings
639 (,(tr-op op
) (,(C 'ref-x
) ,v
,@addings
) ,u
))))
641 `(,s
/d
,(exp vs kind
)
642 (,(C 'fset-x
) ,v
,addings
643 (,(C 'setwrap
) ,u
)))))
645 (let ((pre (if (equal? p v
)
646 (let lp
((pa pa
) (ad addings
) (r '()))
647 (if (and (pair? pa
) (pair? ad
))
648 (let ((px (car pa
)) (ax (car ad
)))
650 (lp (cdr pa
) (cdr ad
) (cons px r
))
658 `(,s
/d
,v
(,(C 'setwrap
) (,(tr-op op
) ,v
,u
)))
659 `(,s
/d
,v
(,(C 'setwrap
) ,u
)))
661 `(,(C 'set-x
) ,v
,pre
,p
,pa
,addings
663 (,(tr-op op
) (,(C 'ref-x
) ,v
,@addings
) ,u
)))
665 `(,(C 'set-x
) ,v
,pre
,p
,pa
,addings
666 (,(C 'setwrap
) ,u
))))))
670 `(,s
/d
,v
(,(C 'setwrap
)
671 (,(tr-op op
) (,(C 'ref-x
) ,v
,@addings
) ,u
)))
672 `(,s
/d
,v
(,(C 'setwrap
)
679 `(,(tr-op op
) (,(C 'ref-x
) ,v
,@addings
) ,u
)
682 (define is-class?
(make-fluid #f
))
683 (define (gen-yargs vs x
)
684 (match (pr 'yarg x
) ((#:list args
)
685 (map (g vs exp
) args
))))
687 (define inhibit-finally
#f
)
688 (define decorations
(make-fluid '()))
689 (define tagis
(make-hash-table))
690 (define-syntax-rule (gen-table x vs
(tag code ...
) ...
)
698 (define (tr-comp op x y
)
700 ((or "<" ">" "<=" ">=")
701 (list (G (string->symbol op
)) x y
))
702 ("!=" (list (G 'not
) (list (O 'equal?
) x y
)))
703 ("==" (list (O 'equal?
) x y
))
704 ("is" (list (G 'eq?
) x y
))
705 ("isnot" (list (G 'not
) (list (G 'eq?
) x y
)))
706 ("in" (list (L 'in
) x y
))
707 ("notin" (list (G 'not
) (list (L 'in
) x y
)))
708 ("<>" (list (G 'not
) (list (O 'equal?
) x y
)))))
718 ((_ #f vf trailer .
**)
719 (let* ((vf (exp vs vf
))
720 (vf.tr
(if (is-prefix? vf
)
726 (symbol->string
(exp vs
(car trailer
)))))
730 (trailer (cdr vf.tr
)))
733 `(expt ,x
,(exp vs
**))
736 (let ((trailer (get-addings vs trailer
)))
737 `(,(C 'ref-x
) ,vf
,@trailer
))))))
740 ((#:identifier x . _
)
745 (fluid-set! decorations
(map (g vs exp
) l
))
754 (let* ((b (make-bytevector (length l
))))
755 (let lp
((l l
) (i 0))
758 (bytevector-u8-set! b i
(car l
))
759 (lp (cdr l
) (+ i
1)))
760 `(,(B 'bytes
) ,b
))))))
765 (cons '+ (map (g vs exp
) l
))))
769 (cons '-
(map (g vs exp
) l
))))
773 (cons '* (map (g vs exp
) l
))))
777 (cons (N 'py-
/) (map (g vs exp
) l
))))
781 (cons (N 'py-mod
) (map (g vs exp
) l
))))
785 (cons (N 'py-floordiv
) (map (g vs exp
) l
))))
789 (cons (N 'py-lshift
) (map (g vs exp
) l
))))
793 (cons (N 'py-rshift
) (map (g vs exp
) l
))))
797 (list (N 'py-lognot
) (exp vs x
))))
801 (list '-
(exp vs x
))))
805 (list '+ (exp vs x
))))
809 (cons (N 'py-logand
) (map (g vs exp
) l
))))
813 (cons (N 'py-logxor
) (map (g vs exp
) l
))))
817 (cons (N 'py-logior
) (map (g vs exp
) l
))))
821 (list 'not
(list (C 'boolit
) (exp vs x
)))))
825 (cons 'or
(map (lambda (x) (list (C 'boolit
) (exp vs x
))) x
))))
829 (cons 'and
(map (lambda (x) (list (C 'boolit
) (exp vs x
))) x
))))
836 (list 'if
(list (C 'boolit
) (exp vs e2
)) (exp vs e1
) (C 'None
)))
839 (list 'if
(list (C 'boolit
) (exp vs e2
)) (exp vs e1
) (exp vs e3
))))
842 ;;We don't delete variables
843 ((_ (#:power
#f base
() .
#f
))
846 ((_ (#:power
#f base
(l ... fin
) .
#f
))
847 (let ((add (get-addings vs l
))
848 (fin (get-addings vs
(list fin
)))
850 `(,(C 'del-x
) (,(C 'ref-x
) ,f
,@add
) ,@fin
))))
854 (let* ((l (map (lambda (x)
856 ((a b
) (list (exp vs b
) (gensym "as") (exp vs a
)))
857 ((b) (list (exp vs b
)))))
859 (vs (union vs
(let lp
((l l
))
862 (((a b c
) . l
) (cons a
(lp l
)))
867 ((a b c
) (list 'set
! a b
))
868 ((a) (list (G 'values
)))))
875 `(,(W 'with
) ,(map g l
)
881 ((_ test a
((tests . as
) ...
) . else
)
883 (,(list (C 'boolit
) (exp vs test
)) ,(exp vs a
))
884 ,@(map (lambda (p a
) (list (list (C 'boolit
) (exp vs p
))
885 (exp vs a
))) tests as
)
886 ,@(if else
`((else ,(exp vs else
))) '()))))
889 ((_ . l
) (cons 'begin
(map (g vs exp
) l
))))
892 ((_ class parents code
)
893 (with-fluids ((is-class?
#t
))
895 (let* ((decor (let ((r (fluid-ref decorations
)))
896 (fluid-set! decorations
'())
898 (class (exp vs class
))
899 (vs (union (list class
) vs
))
903 (parents (match parents
907 (get-addings vs
(list parents
))))))
909 (,(C 'class-decor
) ,decor
910 (,(C 'with-class
) ,class
914 `(,(C 'ref-x
) ,(C 'arglist-
>pkw
) ,@parents
)
915 `(,(G 'cons
) '() '()))
916 ,(map (lambda (x) `(define ,x
#f
)) ls
)
917 ,(exp vs code
))))))))))
922 ((_ (#:string _ s
)) (with-input-from-string s read
)))
925 ((_ (#:from
(() . nm
) .
#f
))
926 `(,(C 'use
) (language python module
,@(map (lambda (nm) (exp vs nm
))
928 ((_ (#:from
(() . nm
) l
))
929 `(,(C 'use
) ((language python module
,@(map (lambda (nm) (exp vs nm
))
931 #:select
,(map (lambda (x)
936 (cons (exp vs a
) (exp vs b
)))))
940 ((_ (#:name
((ids ...
) . as
)) ...
)
944 (let ((path (map (g vs exp
) ids
)))
949 ((#:test
(#:power
#f
,as
())))
952 ((@ (language python module
) import
)
953 ((@ (language python module
) Module
)
954 ',(reverse (append '(language python module
) path
))
960 ((#:test
(#:power
#f
,(car ids
) ())))
963 ((@ (language python module
) import
)
964 ((@ (language python module
) Module
)
965 ',(append '(language python module
) path
))
966 ,(exp vs
(car ids
)))))))))))
974 (((#:power
#f
(#:tuple . l
) . _
))
977 (((#:power
#f
(#:identifier x . _
) () .
#f
))
979 (((#:test power . _
))
982 (#:identifier
"range" . _
)
983 ((#:arglist arglist . _
))
987 (let ((v (gensym "v"))
988 (x (string->symbol x
))
990 `(let ((,v
,(exp vs arg
)))
997 (let ((v1 (gensym "va"))
1000 `(let ((,v1
,(exp vs arg1
))
1001 (,v2
,(exp vs arg2
)))
1006 (,lp
(+ ,x
1))))))))
1008 (let ((v1 (gensym "va"))
1012 `(let ((,v1
,(exp vs arg1
))
1013 (,st
,(exp vs arg2
))
1014 (,v2
,(exp vs arg3
)))
1027 (error "range with step 0 not allowed"))))))
1033 ((_ es in code . else
)
1036 (((#:power
#f
(#:tuple . l
) . _
))
1039 (let* ((es2 (map (g vs exp
) es
))
1040 (vs2 (union es2 vs
))
1041 (code2 (exp vs2 code
))
1042 (p (is-ec #t code2
#t
(list (C 'break
) (C 'continue
))))
1043 (else2 (if else
(exp vs2 else
) #f
))
1044 (in2 (map (g vs exp
) in
)))
1045 (list (C 'cfor
) es2 in2 code2 else2 p
)))))))
1050 (let ((lp (gensym "lp")))
1058 (let ((lp (gensym "lp")))
1067 ((_ x
(or #f
()) #f . fin
)
1069 `(,(T 'try
) ,(exp vs x
) #:finally
(lambda () fin
))
1073 ((_ x exc else . fin
)
1074 `(,(T 'try
) (lambda () ,(exp vs x
))
1075 ,@(let lp
((exc exc
) (r (if else
(exp vs else
) '())))
1077 ((((test .
#f
) code
) . exc
)
1078 (lp exc
(cons `(#:except
,(exp vs test
) ,(exp vs code
)) r
)))
1081 (lp exc
(cons `(#:except
,(exp vs code
)) r
)))
1083 ((((test . as
) code
) . exc
)
1084 (let ((l (gensym "l")))
1087 `(#:except
,(exp vs test
) => (lambda (,(exp vs as
) .
,l
)
1092 ,@(if fin
`(#:finally
(lambda () ,(exp vs fin
))) '()))))
1100 `(,(T 'raise
) (,(O 'Exception
))))
1103 `(,(T 'raise
) ,(exp vs code
)))
1106 (let ((o (gensym "o"))
1109 (let ((,c
,(exp vs code
)))
1110 (let ((,o
(if (,(O 'pyclass?
) ,c
)
1113 (,(O 'set
) ,o
'__cause__
,(exp vs from
))
1119 (let ((f (gensym "f")))
1121 (fluid-set! ,(Y 'in-yield
) #t
)
1122 (let ((,f
(scm.yield
,@(gen-yargs vs args
))))
1127 (let ((f (gen-yield (exp vs f
)))
1130 (set! ,(C 'inhibit-finally
) #t
)
1131 (let ((,g
(,f
,@(gen-yargs vs args
))))
1136 (#:types-args-list . args
)
1139 (let* ((decor (let ((r (fluid-ref decorations
)))
1140 (fluid-set! decorations
'())
1142 (arg_ (get-args_ vs args
))
1143 (arg= (get-args= vs args
))
1144 (dd= (map cadr arg
=))
1145 (c?
(fluid-ref is-class?
))
1147 (y?
(is-yield f
#f code
))
1148 (r (gensym "return"))
1149 (*f
(get-args* vs args
))
1151 (**f
(get-args** vs args
))
1152 (dd** (map cadr
**f
))
1154 (vs (union dd
** (union dd
* (union dd
= (union args vs
)))))
1155 (ns (scope code vs
))
1156 (df (defs code
'()))
1160 (ls (diff (diff ns vs
) df
)))
1163 `(let-syntax ((,y
(syntax-rules ()
1165 (abort-to-prompt ,ab . args
))))
1166 (,y.f
(syntax-rules ()
1168 (abort-to-prompt ,ab . args
)))))
1171 (with-fluids ((is-class?
#f
))
1175 (,(C 'def-decor
) ,decor
1176 (,(C 'def-wrap
) ,y?
,f
,ab
1177 (,(D 'lam
) (,@arg_
,@*f
,@arg
= ,@**f
)
1178 (,(C 'with-return
) ,r
1179 ,(mk `(let ,(map (lambda (x) (list x
#f
)) ls
)
1180 (,(C 'with-self
) ,c?
,args
1181 ,(with-fluids ((return r
))
1182 (exp ns code
))))))))))
1185 (,(C 'def-decor
) ,decor
1186 (,(D 'lam
) (,@arg_
,@*f
,@arg
= ,@**f
)
1187 (,(C 'with-return
) ,r
1188 ,(mk `(let ,(map (lambda (x) (list x
#f
)) ls
)
1189 (,(C 'with-self
) ,c?
,args
1190 ,(with-fluids ((return r
))
1191 (exp ns code
))))))))))
1195 (,(C 'def-decor
) ,decor
1196 (,(C 'def-wrap
) ,y?
,f
,ab
1197 (,(D 'lam
) (,@arg_
,@*f
,@arg
= ,@**f
)
1198 (,(C 'with-return
) ,r
1199 (let ,(map (lambda (x) (list x
#f
)) ls
)
1200 (,(C 'with-self
) ,c?
,args
1201 ,(with-fluids ((return r
))
1203 (exp ns code
))))))))))
1205 (,(C 'def-decor
) ,decor
1206 (,(D 'lam
) (,@arg_
,@*f
,@arg
= ,@**f
)
1207 (,(C 'with-return
) ,r
1208 (let ,(map (lambda (x) (list x
#f
)) ls
)
1209 (,(C 'with-self
) ,c?
,args
1210 ,(with-fluids ((return r
))
1211 (exp ns code
))))))))))))))
1218 ((_ x
(and e
(#:cfor . _
)))
1219 (let ((l (gensym "l")))
1220 `(let ((,l
(,(L 'to-pylist
) '())))
1221 ,(gen-sel vs e
`(,(L 'pylist-append
!) ,l
,(exp vs x
)))
1225 (list (L 'to-pylist
) (let lp
((l l
))
1228 (((#:starexpr
#:power
#f
(#:list . l
) . _
) . _
)
1230 (((#:starexpr
#:power
#f
(#:tuple . l
) . _
) . _
)
1232 (((#:starexpr . l
) . _
)
1233 `(,(L 'to-list
) ,(exp vs l
)))
1235 `(cons ,(exp vs x
) ,(lp l
))))))))
1237 ((_ x
(and e
(#:cfor . _
)))
1238 (let ((l (gensym "l")))
1240 ,(gen-sel vs e
`(set! ,l
(cons ,(exp vs x
) ,l
)))
1247 (((#:starexpr
#:power
#f
(#:list . l
) . _
) . _
)
1249 (((#:starexpr
#:power
#f
(#:tuple . l
) . _
) . _
)
1251 (((#:starexpr . l
) . _
)
1252 `(,(L 'to-list
) ,(exp vs l
)))
1254 `(cons ,(exp vs x
) ,(lp l
)))))))
1257 ((_ (#:var-args-list . v
) e
)
1258 (let ((as (get-args_ vs v
))
1259 (a= (get-args= vs v
))
1260 (a* (get-args* vs v
))
1261 (** (get-args** vs v
)))
1262 (list (C `lam
) `(,@as
,@a
* ,@a
= ,@**) (exp vs e
)))))
1266 (if (> (length l
) 1)
1267 (cons 'values
(map (g vs exp
) l
))
1271 ((_ (l ...
) (#:assign
))
1272 (let ((l (map (g vs exp
) l
)))
1273 (if (= (length l
) 1)
1275 `(,(G 'values
) ,@l
))))
1277 ((_ l
(#:assign x y . u
))
1278 (let ((z (gensym "x")))
1279 `(let ((,x
,(exp vs
`(#:expr-stmt1
((#:verb
,z
)) (#:assign
,y .
,u
)))))
1280 ,(exp vs
`(#:expr-stmt
,x
(#:assign
((#:verb
,z
))))))))
1285 (lambda () (match type
1294 ((= (length l
) (length u
))
1295 (if (= (length l
) 1)
1297 ,(make-set vs op
(car l
) (exp vs
(car u
)))
1300 @,(map (lambda (l u
) (make-set vs op l u
))
1305 ((and (= (length u
) 1) (not op
))
1306 (let ((vars (map (lambda (x) (gensym "v")) l
))
1310 (call-with-values (lambda () ,(exp vs
(car u
)))
1316 (apply ,f
(,(L 'to-list
) ,q
))))
1318 ,@(map (lambda (l v
) (make-set vs op l v
))
1323 ((and (= (length l
) 1) (not op
))
1325 ,(make-set vs op
(car l
) `(,(G 'list
) ,@(map (g vs exp
) u
)))
1329 ((#:test
(#:power
#f
(#:identifier v . _
) () .
#f
) #f
))
1331 (let ((s (string->symbol v
)))
1332 `(,s
/d
,s
,(exp vs l
)))))
1336 `(if (,(G 'not
) (,(G 'and
) ,@(map (lambda (x) `(,(C 'boolit
) ,(exp vs x
)))
1338 (,(C 'raise
) ,(C 'AssertionError
) ',f
,n
,m
))))
1343 ((_ l
(#:assign x y . u
))
1344 (let ((z (gensym "x")))
1345 `(let ((,x
,(exp vs
`(#:expr-stmt1
((#:verb
,z
))
1346 (#:assign
,y .
,u
)))))
1347 ,(exp vs
`(#:expr-stmt
,x
(#:assign
((#:verb
,z
))))))))
1352 (lambda () (match type
1361 ((= (length l
) (length u
))
1362 (if (= (length l
) 1)
1364 ,(make-set vs op
(car l
) (exp vs
(car u
)))
1367 @,(map (lambda (l u
) (make-set vs op l u
))
1370 (values ,@(map (g exp vs
) l
)))))
1372 ((and (= (length u
) 1) (not op
))
1373 (let ((vars (map (lambda (x) (gensym "v")) l
))
1377 (call-with-values (lambda () ,(exp vs
(car u
)))
1383 (apply ,f
(,(L 'to-list
) ,q
))))
1385 ,@(map (lambda (l v
) (make-set vs op l v
))
1388 (values ,@(map (g exp vs
) l
)))))
1390 ((and (= (length l
) 1) (not op
))
1392 ,(make-set vs op
(car l
) `(,(G 'list
) ,@(map (g vs exp
) u
)))
1393 (values ,(exp vs
(car l
))))))))))
1398 `(,(fluid-ref return
) ,@(map (g vs exp
) x
))
1399 `(,(fluid-ref return
)))))
1404 `(,(Di 'make-py-hashtable
)))
1406 ((_ (#:e k . v
) (and e
(#:cfor . _
)))
1407 (let ((dict (gensym "dict")))
1408 `(let ((,dict
(,(Di 'make-py-hashtable
))))
1409 ,(gen-sel vs e
`(,(L 'pylist-set
!) ,dict
,(exp vs k
) ,(exp vs v
)))
1412 ((_ (#:e k . v
) ...
)
1413 (let ((dict (gensym "dict")))
1414 `(let ((,dict
(,(Di 'make-py-hashtable
))))
1415 ,@(map (lambda (k v
)
1416 `(,(L 'pylist-set
!) ,dict
,(exp vs k
) ,(exp vs v
)))
1420 ((_ k
(and e
(#:cfor . _
)))
1421 (let ((dict (gensym "dict")))
1422 `(let ((,dict
(,(Se 'set
))))
1423 ,(gen-sel vs e
`((,(O 'ref
) ,dict
'add
) ,(exp vs k
)))
1427 (let ((set (gensym "dict")))
1428 `(let ((,set
(,(Se 'set
))))
1430 `((,(O 'ref
) ,set
'add
) ,(exp vs k
)))
1440 (tr-comp op
(exp vs x
) (exp vs y
)))
1443 (let ((m (gensym "op")))
1444 `(let ((,m
,(exp vs y
)))
1445 (and ,(tr-comp op
(exp vs x
) m
)
1446 ,(exp vs
`(#:comp
(#:verb
,m
) .
,l
))))))))
1454 ((hash-ref tagis tag
1455 (lambda y
(warn (format #f
"not tag in tagis ~a" tag
)) x
))
1469 (define-syntax-rule (define- n x
) (define! 'n x
))
1478 (#:identifier
"module" . _
)
1479 ((#:arglist arglist
))
1481 (#:assign
)))) . rest
)
1489 `((,(G 'define-module
) (language python module
,@args
)
1490 #:use-module
(language python module python
)
1491 #:use-module
(language python exceptions
))
1493 (define __module__
'(language python module
,@args
)))))
1496 (if (fluid-ref (@@ (system base compile
) %in-compile
))
1497 (with-fluids ((*prefixes
* '()))
1498 (if (fluid-ref (@@ (system base compile
) %in-compile
))
1500 (set! s
/d
(C 'define-
)))
1505 (let ((globs (get-globals x
)))
1508 ,(C 'clear-warning-data
)
1509 (fluid-set! (@@ (system base message
) %dont-warn-list
) '())
1510 ,@(map (lambda (s) `(,(C 'var
) ,s
)) globs
)
1511 ,@(map (g globs exp
) x
)
1512 (,(C 'export-all
)))))
1514 (if (fluid-ref (@@ (system base compile
) %in-compile
))
1516 (set! s
/d
(C 'define-
)))
1521 (let ((globs (get-globals x
)))
1524 ,(C 'clear-warning-data
)
1525 (fluid-set! (@@ (system base message
) %dont-warn-list
) '())
1526 ,@(map (lambda (s) `(,(C 'var
) ,s
)) globs
)
1527 ,@(map (g globs exp
) x
))))))
1530 (define-syntax-parameter break
1531 (lambda (x) #'(values)))
1533 (define-syntax-parameter continue
1534 (lambda (x) (error "continue must be bound")))
1536 (define (is-yield f p x
)
1538 ((#:def nm args _ code
)
1539 (is-yield f
#t code
))
1541 (eq? f
(exp '() x
)))
1553 (define-syntax-rule (with-sp ((x v
) ...
) code ...
)
1554 (syntax-parameterize ((x (lambda (y) #'v
)) ...
) code ...
))
1556 (define (is-ec ret x tail tags
)
1557 (syntax-case (pr 'is-ec x
) (begin let if define
@@)
1561 (or-map (lambda (x) (is-ec ret x
#f tags
)) #'(a ...
))
1562 (is-ec ret
#'b tail tags
)))
1564 ((let lp
((y x
) ...
) a ... b
)
1565 (symbol?
(syntax->datum
#'lp
))
1567 (or-map (lambda (x) (is-ec ret x
#f tags
)) #'(x ...
))
1568 (or-map (lambda (x) (is-ec ret x
#f tags
)) #'(a ...
))
1569 (is-ec ret
#'b tail tags
)))
1571 ((let ((y x
) ...
) a ... b
)
1574 (or-map (lambda (x) (is-ec ret x
#f tags
)) #'(x ...
))
1575 (or-map (lambda (x) (is-ec ret x
#f tags
)) #'(a ...
))
1576 (is-ec ret
#'b tail tags
)))
1581 (is-ec ret
#'p
#f tags
)
1582 (is-ec ret
#'a tail tags
)
1583 (is-ec ret
#'b tail tags
)))
1592 (is-ec ret
#'p
#f tags
)
1593 (is-ec ret
#'a tail tags
)))
1597 (if (member (pr (syntax->datum x
)) tags
)
1603 (or-map (lambda (x) (is-ec ret x
#f tags
)) #'(a ...
)))
1609 (define-syntax with-return
1611 (define (analyze ret x
)
1612 (syntax-case x
(begin let if
)
1614 #`(begin a ...
#,(analyze ret
#'b
)))
1616 (symbol?
(syntax->datum
#'lp
))
1617 #`(let lp v a ...
#,(analyze ret
#'b
)))
1619 #`(let v a ...
#,(analyze ret
#'b
)))
1621 #`(if p
#,(analyze ret
#'a
) #,(analyze ret
#'b
)))
1623 #`(if p
#,(analyze ret
#'a
)))
1625 (equal?
(syntax->datum
#'return
) (syntax->datum ret
))
1626 (if (eq?
#'(b ...
) '())
1628 #`(values a b ...
)))
1631 (define (is-ec ret x tail
)
1632 (syntax-case x
(begin let if define
@@)
1636 (or-map (lambda (x) (is-ec ret x
#f
)) #'(a ...
))
1637 (is-ec ret
#'b tail
)))
1639 ((let lp
((y x
) ...
) a ... b
)
1640 (symbol?
(syntax->datum
#'lp
))
1642 (or-map (lambda (x) (is-ec ret x
#f
)) #'(x ...
))
1643 (or-map (lambda (x) (is-ec ret x
#f
)) #'(a ...
))
1644 (is-ec ret
#'b tail
)))
1646 ((let ((y x
) ...
) a ... b
)
1649 (or-map (lambda (x) (is-ec ret x
#f
)) #'(x ...
))
1650 (or-map (lambda (x) (is-ec ret x
#f
)) #'(a ...
))
1651 (is-ec ret
#'b tail
)))
1661 (is-ec ret
#'a tail
)
1662 (is-ec ret
#'b tail
)))
1668 (is-ec ret
#'a tail
)))
1671 (equal?
(syntax->datum
#'return
) (syntax->datum ret
))
1676 (or-map (lambda (x) (is-ec ret x
#f
)) #'(a ...
)))
1684 (let ((code (analyze #'ret
#'l
)))
1685 (if (is-ec #'ret
#'l
#t
)
1686 #`(let/ec ret
#,code
)
1694 (dont-warn (syntax->datum
#'v
))
1695 #'(if (module-defined?
(current-module) 'v
)
1697 (define! 'v
#f
)))))))
1699 (define-inlinable (non? x
) (eq? x
#:nil
))
1701 (define (gentemp stx
) (datum->syntax stx
(gensym "x")))
1705 ((_ (x) (a) code
#f
#f
)
1710 (with-sp ((continue (lp (cdr l
)))
1714 (for/adv1
(x) (a) code
#f
#f
)))
1716 ((_ (x) (a) code
#f
#t
)
1722 (let/ec continue-ret
1724 (with-sp ((continue (continue-ret))
1725 (break (break-ret)))
1728 (for/adv1
(x) (a) code
#f
#t
)))
1730 ((_ (x) (a) code next
#f
)
1733 (let ((x (let lp
((l a
) (old #f
))
1736 (let/ec continue-ret
1737 (with-sp ((continue (continue-ret))
1738 (break (break-ret)))
1743 (for/adv1
(x) (a) code next
#f
)))
1745 ((_ x a code next p
)
1746 (for/adv1 x a code next p
))))
1748 (define-syntax for
/adv1
1751 ((_ (x ...
) (in) code
#f
#f
)
1752 (with-syntax ((inv (gentemp #'in
)))
1753 #'(let ((inv (wrap-in in
)))
1754 (catch StopIteration
1757 (call-with-values (lambda () (next inv
))
1759 (with-sp ((break (values))
1760 (continue (values)))
1763 (lambda z
(values))))))
1765 ((_ (x ...
) (in ...
) code
#f
#f
)
1766 (with-syntax (((inv ...
) (generate-temporaries #'(in ...
))))
1767 #'(let ((inv (wrap-in in
)) ...
)
1768 (catch StopIteration
1771 (call-with-values (lambda () (values (next inv
) ...
))
1773 (with-sp ((break (values))
1774 (continue (values)))
1777 (lambda z
(values))))))
1779 ((_ (x ...
) (in) code
#f
#t
)
1780 (with-syntax ((inv (gentemp #'in
)))
1781 #'(let ((inv (wrap-in in
)))
1784 (catch StopIteration
1786 (call-with-values (lambda () (next inv
))
1788 (let/ec continue-ret
1789 (with-sp ((break (break-ret))
1790 (continue (continue-ret)))
1793 (lambda z
(values))))))))
1795 ((_ (x ...
) (in ...
) code
#f
#t
)
1796 (with-syntax (((inv ...
) (generate-temporaries #'(in ...
))))
1797 #'(let ((inv (wrap-in in
)) ...
)
1800 (catch StopIteration
1802 (call-with-values (lambda () (values (next inv
) ...
))
1804 (let/ec continue-ret
1805 (with-sp ((break (break-ret))
1806 (continue (continue-ret)))
1809 (lambda z
(values))))))))
1811 ((_ (x ...
) in code else
#f
)
1812 #'(for-adv (x ...
) in code else
#f
))
1814 ((_ (x ...
) in code else
#t
)
1815 #'(for-adv (x ...
) in code else
#t
)))))
1818 (define-syntax for-adv
1821 (if (= (length (syntax->datum x
)) (= (length (syntax->datum y
))))
1823 ((x ...
) #'(values (next x
) ...
)))
1828 ((_ (x ...
) (in) code else p
)
1829 (with-syntax ((inv (gentemp #'in
)))
1830 (with-syntax (((xx ...
) (generate-temporaries #'(x ...
))))
1831 (if (syntax->datum
#'p
)
1832 #'(let ((inv (wrap-in in
)))
1835 (catch StopIteration
1838 (call-with-values (lambda () (next inv
))
1841 (let/ec continue-ret
1842 (with-sp ((break (break-ret))
1843 (continue (continue-ret)))
1848 #'(let ((inv (wrap-in in
)))
1851 (catch StopIteration
1854 (call-with-values (lambda () (next inv
))
1857 (with-sp ((break (break-ret))
1858 (continue (values)))
1861 (lambda e else
)))))))))
1863 ((_ (x ...
) (in ...
) code else p
)
1864 (with-syntax (((inv ...
) (generate-temporaries #'(in ...
))))
1865 (with-syntax ((get (gen #'(inv ...
) #'(x ...
)))
1866 ((xx ...
) (generate-temporaries #'(x ...
))))
1867 (if (syntax->datum
#'p
)
1868 #'(let ((inv (wrap-in in
)) ...
)
1871 (catch StopIteration
1874 (call-with-values (lambda () get
)
1877 (let/ec continue-ret
1878 (with-sp ((break (break-ret))
1879 (continue (continue-ret)))
1884 #'(let ((inv (wrap-in in
)) ...
)
1887 (catch StopIteration
1890 (call-with-values (lambda () get
)
1893 (with-sp ((break (break-ret))
1894 (continue (values)))
1897 (lambda e else
))))))))))))
1899 (define-syntax def-wrap
1903 (pr 'def-wrap
#'f
'false
)
1907 (pr 'def-wrap
#'f
'true
)
1909 (define obj
(make <yield
>))
1910 (define ab
(make-prompt-tag))
1911 (slot-set! obj
'k
#f
)
1912 (slot-set! obj
'closed
#f
)
1920 (slot-set! obj
'closed
#t
)
1921 (throw StopIteration
))
1924 (fluid-set! in-yield
#f
)
1936 (define-syntax ref-x
1941 ((_ v
(#:fastfkn-ref f _
) . l
)
1942 #'(ref-x (lambda x
(if (pyclass? v
) (apply f x
) (apply f v x
))) . l
))
1943 ((_ v
(#:fast-id f _
) . l
)
1944 #'(ref-x (f v
) . l
))
1945 ((_ v
(#:identifier x
) . l
)
1946 #'(ref-x (ref v x
) . l
))
1947 ((_ v
(#:call-obj x
) . l
)
1948 #'(ref-x (x v
) . l
))
1949 ((_ v
(#:call x ...
) . l
)
1950 #'(ref-x (v x ...
) . l
))
1951 ((_ v
(#:apply x ...
) . l
)
1952 #'(ref-x (py-apply v x ...
) . l
))
1953 ((_ v
(#:apply x ...
) . l
)
1954 #'(ref-x (py-apply v x ...
) . l
))
1955 ((_ v
(#:vecref x
) . l
)
1956 #'(ref-x (pylist-ref v x
) . l
))
1957 ((_ v
(#:vecsub . x
) . l
)
1958 #'(ref-x (pylist-slice v . x
) . l
)))))
1960 (define-syntax del-x
1962 ((_ v
(#:identifier x
))
1964 ((_ v
(#:call-obj x
))
1966 ((_ v
(#:call x ...
))
1968 ((_ v
(#:apply x ...
))
1971 (pylist-delete! v x
))
1972 ((_ v
(#:vecsub x ...
))
1973 (pylist-subset! v x ... pylist-null
))))
1975 (define-syntax set-x
1977 ((_ v
(a ... b
) val
)
1978 (set-x-2 (ref-x v a ...
) b val
))
1979 ((_ v
#f p pa a val
)
1980 (set-x p pa
(fset-x v a val
)))
1981 ((_ v pre p pa a val
)
1982 (set-c v pre a val
))
1983 ((_ v
(a ... b
) val
)
1984 (set-x-2 (ref-x v a ...
) b val
))))
1986 (define-syntax set-c
1991 (tr v
(fset-x v as val
)))
1992 ((_ v
((#:identifier a
) . as
) (b . bs
) val
)
1993 (set-c (ref v a
) as bs val
))))
1995 (define-syntax fset-x
1997 ((_ v
((#:identifier x
) ...
) val
)
1998 ((@ (oop pf-objects
) fset-x
) v
(list x ...
) val
))))
2000 (define-syntax set-x-2
2002 ((_ v
(#:fastfkn-ref f id
) val
)
2004 ((_ v
(#:fastid-ref f id
) val
)
2006 ((_ v
(#:identifier x
) val
)
2008 ((_ v
(#:vecref n
) val
)
2009 (pylist-set! v n val
))
2010 ((_ v
(#:vecsub x ...
) val
)
2011 (pylist-subset! v x ... val
))))
2014 (define-syntax class-decor
2018 (class-decor (f ...
) (r y
)))))
2020 (define-syntax def-decor
2024 (def-decor (f ...
) (r y
)))))
2026 (define-syntax with-self
2031 (syntax-parameterize ((*self
* (lambda (x) #'s
))) c
))))
2033 (define-syntax with-class
2036 (syntax-parameterize ((*class
* (lambda (x) #'s
))) c
))))
2039 (define-syntax boolit
2040 (syntax-rules (and or not
< <= > >=)
2041 ((_ (and x y
)) (and (boolit x
) (boolit y
)))
2042 ((_ (or x y
)) (or (boolit x
) (boolit y
)))
2043 ((_ (not x
)) (not (boolit x
)))
2044 ((_ (< x y
)) (< x y
))
2045 ((_ (<= x y
)) (<= x y
))
2046 ((_ (> x y
)) (> x y
))
2047 ((_ (>= x y
)) (>= x y
))
2052 (define (export-all)
2053 (define mod
(current-module))
2054 (if (module-defined? mod
'__all__
)
2056 (for ((x : (module-ref mod
'__all__
))) ((l '()))
2057 (cons (string->symbol
(scm-str x
)) l
)