(define (fastfkn x) (hash-ref fasthash x))
(define (get-kwarg vs arg)
- (let lp ((arg arg) (l '()) (kw '()))
+ (let lp ((arg arg))
(match arg
+ (((#:comp . (and x (_ (#:cfor . _) . _))) . arg2)
+ (cons `(* ,(exp vs `(#:tuple ,@x))) (lp arg2)))
+ (((#:* a) . arg)
+ (cons `(* ,(exp vs a)) (lp arg)))
+ (((#:** a) . arg)
+ (cons `(** ,(exp vs a)) (lp arg)))
(((#:= a b) . arg)
- (lp arg
- l
- (cons*
- (exp vs b)
- (symbol->keyword
- (exp vs a))
- kw)))
+ (cons `(= ,(exp vs a) ,(exp vs b)) (lp arg)))
((x . arg)
- (lp arg (cons (exp vs x) l) kw))
+ (cons (exp vs x) (lp arg)))
(()
- (values (reverse l) (reverse kw))))))
+ '()))))
(define (get-args_ vs arg)
(let lp ((arg arg))
`(#:fast-id ,it ',tag)
`(#:identifier ',tag))))))
- ((#:arglist args apply kw)
- (call-with-values (lambda () (get-kwarg vs args))
- (lambda (args kwarg)
- (if (or kw apply)
- `(#:apply ,@args ,@kwarg
- ,`(,(L 'to-list)
- (,(G 'append)
- (if apply (exp vs apply) ''())
- (if kw
- '(,(C 'kw->li) (exp vs kw))
- ''()))))
- `(#:call ,@args ,@kwarg)))))
+ ((#:arglist args)
+ `(#:apply ,@(get-kwarg vs args)))
((#:subscripts (n #f #f))
`(#:vecref ,(exp vs n)))
(#: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* ((b (make-bytevector (length l))))
(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)))))
- `(,(B 'bytes) ,b))))
+ (begin
+ (bytevector-u8-set! b i (car l))
+ (lp (cdr l) (+ i 1)))
+ `(,(B 'bytes) ,b))))))
(#:+
(#:assign (l)))
(let ((s (string->symbol v)))
`(,s/d ,s ,(exp vs l)))))
-
+
+ (#:assert
+ ((_ x f n m)
+ `(if (,(G 'not) (,(G 'and) ,@(map (lambda (x) `(,(C 'boolit) ,(exp vs x)))
+ x)))
+ (,(C 'raise) ,(C 'AssertionError) ',f ,n ,m))))
(#:return
((_ x)
((_ v (#:call x ...) . l)
(ref-x (v x ...) . l))
((_ v (#:apply x ...) . l)
- (ref-x (apply v x ...) . l))
+ (ref-x (py-apply v x ...) . l))
((_ v (#:apply x ...) . l)
- (ref-x (apply v x ...) . l))
+ (ref-x (py-apply v x ...) . l))
((_ v (#:vecref x) . l)
(ref-x (pylist-ref v x) . l))
((_ v (#:vecsub . x) . l)
SyntaxError SystemException
OSError ProcessLookupError PermissionError
None NotImplemented NotImplementedError
- RunTimeError))
+ RunTimeError AssertionError))
(define-syntax-rule (aif it p x y) (let ((it p)) (if it x y)))
(define PermissionError 'PermissionError)
(define NotImplementedError 'NotImplementedError)
(define RunTimeError 'RunTimeError)
+(define AssertionError 'AssertionError)
(define-python-class Exception ()
(define __init__
(define-exp-C *do-extension-dispatch* #t)
(define-exp-C *extension-dispatches* '((("py" "python") . python)
(("pl" "prolog") . prolog)))
+(define-exp-C %current-file% (make-fluid '(guile)))
(define-C default-language
(lambda (file)
(env ((C default-environment) from))
(opts '())
(canonicalization 'relative))
+
(with-fluids (((C %in-compile ) #t )
((M %dont-warn-list ) '() )
- ((C %file-port-name-canonicalization) canonicalization))
+ ((C %file-port-name-canonicalization) canonicalization )
+ ((C %current-file% ) file))
+
(let* ((comp (or output-file ((C compiled-file-name) file)
(error "failed to create path for auto-compiled file"
file)))