<commit_before>(library
  (harlan middle lift-complex)
  (export lift-complex)
  (import (rnrs) (elegant-weapons helpers)
    (harlan helpers))
  
(define lift-expr
  (lambda (expr finish)
    (match expr
      ((void) (finish `(void)))
      ((,t ,n) (guard (scalar-type? t)) (finish `(,t ,n)))
      ((var ,t ,x) (finish `(var ,t ,x)))
      ((int->float ,e)
       (lift-expr e (lambda (e) (finish `(int->float ,e)))))
      ((begin ,[lift-stmt -> stmt*] ... ,e)
       (lift-expr e
         (lambda (e) `(begin ,@stmt* ,(finish e)))))
      ((let () ,expr)
       (lift-expr expr (lambda (expr) (finish expr))))
      ((let ((,x ,t ,e) . ,rest) ,expr)
       (Expr e
         (lambda (e)
           `(let ((,x ,t ,e))
              ,(lift-expr `(let ,rest ,expr) finish)))))
      ((if ,test ,conseq ,alt)
       (lift-expr
         test
         (lambda (t)
           (lift-expr
             conseq
             (lambda (c)
               (lift-expr
                 alt
                 (lambda (a) (finish `(if ,t ,c ,a)))))))))
      ((vector-ref ,t ,e1 ,e2)
       (lift-expr
         e1
         (lambda (e1^)
           (lift-expr
             e2 (lambda (e2^)
                  (finish `(vector-ref ,t ,e1^ ,e2^)))))))
      ((make-vector ,t ,e)
       (lift-expr e (lambda (e^) (finish `(make-vector ,t ,e^)))))
      ((kernel ,t ,dims (((,x* ,t*) (,e* ,ts*) ,dim*) ...) ,body)
       (let ((finish
               (lambda (e*^)
                 (let ((v (gensym 'v)))
                   `(let ((,v ,t
                            (kernel ,t ,dims (((,x* ,t*) (,e*^ ,ts*) ,dim*) ...)
                              ,(lift-expr body (lambda (b) b)))))
                      ,(finish `(var ,t ,v)))))))
         (let loop ((e* e*) (e*^ '()))
           (if (null? e*)
               (finish (reverse e*^))
               (lift-expr
                 (car e*)
                 (lambda (e^)
                   (loop (cdr e*) (cons e^ e*^))))))))
      ((make-vector ,c)
       (finish `(make-vector ,c)))
      ((length ,e) 
       (lift-expr
         e (lambda (e^)
             (finish `(length ,e^)))))
      ((,op ,e1 ,e2) (guard (or (binop? op) (relop? op)))
       (lift-expr
         e1 (lambda (e1^)
              (lift-expr
                e2 (lambda (e2^)
                     (finish `(,op ,e1^ ,e2^)))))))
      ((call ,rator . ,rand*)
       (let loop ((e* (cons rator rand*)) (e*^ '()))
         (if (null? e*)
             (finish `(call . ,(reverse e*^)))
             (lift-expr
               (car e*)
               (lambda (e^)
                 (loop (cdr e*) (cons e^ e*^))))))))))

(define Expr
  (lambda (expr finish)
    (match expr
      ((kernel ,t ,dims (((,x* ,t*) (,e* ,ts*) ,dim*) ...) ,body)
       (let ((finish
               (lambda (e*^)
                 (finish `(kernel ,t ,dims (((,x* ,t*) (,e*^ ,ts*) ,dim*) ...)
                            ,(lift-expr body (lambda (b) b)))))))
         (let loop ((e* e*) (e*^ '()))
           (if (null? e*)
               (finish (reverse e*^))
               (lift-expr
                 (car e*)
                 (lambda (e^)
                   (loop (cdr e*) (cons e^ e*^))))))))
      ((make-vector ,t ,e)
       (lift-expr e
          (lambda (e)
            (finish `(make-vector ,t ,e)))))
      (,else (lift-expr else finish)))))

(define-match lift-stmt<commit_msg>Adding a match fallthrough error to lift-expr<commit_after>(library
  (harlan middle lift-complex)
  (export lift-complex)
  (import (rnrs) (elegant-weapons helpers)
    (harlan helpers))
  
(define lift-expr
  (lambda (expr finish)
    (match expr
      ((void) (finish `(void)))
      ((,t ,n) (guard (scalar-type? t)) (finish `(,t ,n)))
      ((var ,t ,x) (finish `(var ,t ,x)))
      ((int->float ,e)
       (lift-expr e (lambda (e) (finish `(int->float ,e)))))
      ((begin ,[lift-stmt -> stmt*] ... ,e)
       (lift-expr e
         (lambda (e) `(begin ,@stmt* ,(finish e)))))
      ((let () ,expr)
       (lift-expr expr (lambda (expr) (finish expr))))
      ((let ((,x ,t ,e) . ,rest) ,expr)
       (Expr e
         (lambda (e)
           `(let ((,x ,t ,e))
              ,(lift-expr `(let ,rest ,expr) finish)))))
      ((if ,test ,conseq ,alt)
       (lift-expr
         test
         (lambda (t)
           (lift-expr
             conseq
             (lambda (c)
               (lift-expr
                 alt
                 (lambda (a) (finish `(if ,t ,c ,a)))))))))
      ((vector-ref ,t ,e1 ,e2)
       (lift-expr
         e1
         (lambda (e1^)
           (lift-expr
             e2 (lambda (e2^)
                  (finish `(vector-ref ,t ,e1^ ,e2^)))))))
      ((make-vector ,t ,e)
       (lift-expr e (lambda (e^) (finish `(make-vector ,t ,e^)))))
      ((kernel ,t ,dims (((,x* ,t*) (,e* ,ts*) ,dim*) ...) ,body)
       (let ((finish
               (lambda (e*^)
                 (let ((v (gensym 'v)))
                   `(let ((,v ,t
                            (kernel ,t ,dims (((,x* ,t*) (,e*^ ,ts*) ,dim*) ...)
                              ,(lift-expr body (lambda (b) b)))))
                      ,(finish `(var ,t ,v)))))))
         (let loop ((e* e*) (e*^ '()))
           (if (null? e*)
               (finish (reverse e*^))
               (lift-expr
                 (car e*)
                 (lambda (e^)
                   (loop (cdr e*) (cons e^ e*^))))))))
      ((make-vector ,c)
       (finish `(make-vector ,c)))
      ((length ,e) 
       (lift-expr
         e (lambda (e^)
             (finish `(length ,e^)))))
      ((,op ,e1 ,e2) (guard (or (binop? op) (relop? op)))
       (lift-expr
         e1 (lambda (e1^)
              (lift-expr
                e2 (lambda (e2^)
                     (finish `(,op ,e1^ ,e2^)))))))
      ((call ,rator . ,rand*)
       (let loop ((e* (cons rator rand*)) (e*^ '()))
         (if (null? e*)
             (finish `(call . ,(reverse e*^)))
             (lift-expr
               (car e*)
               (lambda (e^)
                 (loop (cdr e*) (cons e^ e*^)))))))
      (,else (error 'lift-expr "unmatched datum" else)))))

(define Expr
  (lambda (expr finish)
    (match expr
      ((kernel ,t ,dims (((,x* ,t*) (,e* ,ts*) ,dim*) ...) ,body)
       (let ((finish
               (lambda (e*^)
                 (finish `(kernel ,t ,dims (((,x* ,t*) (,e*^ ,ts*) ,dim*) ...)
                            ,(lift-expr body (lambda (b) b)))))))
         (let loop ((e* e*) (e*^ '()))
           (if (null? e*)
               (finish (reverse e*^))
               (lift-expr
                 (car e*)
                 (lambda (e^)
                   (loop (cdr e*) (cons e^ e*^))))))))
      ((make-vector ,t ,e)
       (lift-expr e
          (lambda (e)
            (finish `(make-vector ,t ,e)))))
      (,else (lift-expr else finish)))))

(define-match lift-stmt
{'fraction_non_alphanumeric': 0.2141806413651074, 'fraction_numerical': 0.004707266843189173, 'mean_word_length': 1.3731239092495637, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5977067', 'n_tokens_mistral': 2405, 'n_tokens_neox': 2280, 'n_words': 669}