-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsix.scm
39 lines (35 loc) · 1.36 KB
/
six.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(define-syntax six.infix
(lambda (src)
(include "six-convert.scm")
;; TODO: from-import-handler
(##deconstruct-call
src
2
(lambda (ast-src)
(let ((ast (##source-strip ast-src)))
(if (and (pair? ast)
(eq? 'six.import (##source-strip (car ast)))
(pair? (cdr ast))
(null? (cddr ast)))
(let ((ident (##source-strip (cadr ast))))
(if (and (pair? ident)
(eq? 'six.identifier (##source-strip (car ident)))
(pair? (cdr ident))
(null? (cddr ident)))
`(begin
(py-import ,(symbol->string (##source-strip (cadr ident))))
(void))
(error "invalid import")))
(let* ((x (six->python ast-src))
(params (car x))
(body (cadr x))
(def
(string-append "def ___0("
(flatten-string
(comma-separated (map car params)))
"):\n "
body)))
`((begin
(py-exec ,def)
(PyObject*->object (py-eval "___0")))
,@(map cdr params)))))))))