1 === modified file 'compile.ss'
2 --- compile.ss 2007-05-20 14:25:27 +0000
3 +++ compile.ss 2007-05-30 09:17:20 +0000
5 (require (lib "match.ss"))
6 +(require (lib "stx.ss" "syntax")) ;; provides module-or-top-identifier=?
7 (require (only (lib "1.ss" "srfi") fold))
8 (require (only (lib "13.ss" "srfi") string-contains))
11 (string=? (symbol->string s)
17 + (syntax-case* expr (: + and not = set! :tuple if begin cond for in while break print)
18 + module-or-top-identifier=?
19 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23 - (@> Add (list (T left) (T right))))
26 + (@>* Add 7 (list (T #'left) (T #'right))))
28 ;; fold into multiple forms of (+ A B)
29 ;; eg: (+ a b c d) => (+ (+ (+ a b) c) d)
30 (T (fold (lambda (a b) `(+ ,b ,a))
33 + (car (syntax->list #'(args ...)))
34 + (cdr (syntax->list #'(args ...))))))
36 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40 - (@> And : (map T nodes)))
44 + (@> And : (map T (syntax->list #'(nodes ...)))))
46 + (@> Not (T #'node)))
49 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
50 ;; COMPARISON operators
52 - (('= first rest ...)
58 - (py/tuple (list (ss->py "==") (T r))))
60 + (py/tuple (list (ss->py "==") (T (syntax->list #'r)))))
61 + (syntax->list #'(rest ...)))))
64 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
65 ;; Variable ASSIGNMENT
67 - (('set! (targets ...) value)
68 + ((set! (targets ...) value)
72 (unpack-assign-name t))
75 + (syntax->list #'(targets ...)))))
78 - (('set! target value)
79 + ((set! target value)
81 - (list (unpack-assign-name target))
83 + (list (unpack-assign-name (syntax-object->datum #'target)))
87 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
90 - ((':tuple items ...)
91 - (@> Tuple (map T items)))
93 + (@> Tuple (map T (syntax->list #'(items ...)))))
96 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
99 ;;;; (if <exp> (begin ...) else (begin ...)
100 - (('if exp ('begin body1 ...) ('begin body2 ...))
102 - (list (py/tuple (list (T exp) (@> Stmt (map T body1)))))
103 - (@> Stmt (map T body2))))
105 - (('if exp ('begin body1 ...))
107 - (list (py/tuple (list (T exp) (@> Stmt (map T body1)))))
110 - (('if exp body1 body2)
111 - (T `(if ,exp (begin ,body1) (begin ,body2))))
115 - (list (py/tuple (list (T exp) (@> Stmt (list (T body1))))))
118 - (('cond ((and exp (? (not-symbol "else"))) body ...) ...)
121 - (py/tuple (list (T e) (@> Stmt (map T b)))))
124 + ((if exp (begin body1 ...) (begin body2 ...))
126 + (list (py/tuple (list (T #'exp) (@> Stmt (map T (syntax->list #'(body1 ...)))))))
127 + (@> Stmt (map T (syntax->list #'(body2 ...))))))
129 + ((if exp (begin body1 ...))
131 + (list (py/tuple (list (T #'exp) (@> Stmt (map T (syntax->list #'(body1 ...)))))))
134 + ;((if exp body1 body2)
135 + ; (T `(if ,exp (begin ,body1) (begin ,body2))))
137 + ((if exp body1 ...)
139 + (list (py/tuple (list (T #'exp) (@> Stmt (list (T (syntax->list #'(body1 ...))))))))
142 +; ((cond ((and exp (? (not-symbol "else"))) body ...) ...)
144 +; (map (lambda (e b)
145 +; (py/tuple (list (T #'e) (@> Stmt (map T (syntax->list #'(b ...)))))))
151 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
154 - (('for var 'in seq suite ...)
155 + ((for var in seq suite ...)
157 - (@> AssName var "OP_ASSIGN")
159 - (@> Stmt (map T suite))
160 + (@> AssName (syntax-object->datum #'var) "OP_ASSIGN")
162 + (@> Stmt (map T (syntax->list #'(suite ...))))
165 - (('while cond body ...)
166 + ((while cond body ...)
169 - (@> Stmt (map T body))
171 + (@> Stmt (map T (syntax->list #'(body ...))))
172 py/none)) ;; TODO: else
179 @@ -148,33 +150,34 @@
180 ;; FUNCTION definition
182 (('def name (args ...) body ...)
183 - (display args)(newline)
185 - (lambda () (match-function-args args))
186 - (lambda (args defaults flag)
191 - (map ss->py args) ;; XXX: @> macro does not do
192 - ;; a deep translation of types
194 - flag ;; TODO: flags
195 - py/none ;; TODO: doc string
196 - (@> Stmt (map T body)))))
197 - (filename-hack! ast)
200 + ;(display #'args)(newline)
202 + (lambda () (match-function-args (syntax->list #'(args ...))))
203 + (lambda (args defaults flag)
208 + (map ss->py args) ;; XXX: @> macro does not do
209 + ;; a deep translation of types
211 + flag ;; TODO: flags
212 + py/none ;; TODO: doc string
213 + (@> Stmt (map T (syntax->list #'(body ...)))))))
214 + (filename-hack! ast)
218 - (@> Return (T exp)))
219 + (@> Return (T #'exp)))
221 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
224 (('class name (bases ...) statements ...)
225 (let ((class (@> Class
226 - name bases "DOCSTRING"
227 - (@> Stmt (map T statements)))))
228 + #'name (syntax->list #'(bases ...)) "DOCSTRING"
229 + (@> Stmt (map T (syntax->list #'(statements ...)))))))
230 (filename-hack! class)
233 @@ -183,38 +186,40 @@
234 ;; PRINT, IMPORT, ....
237 - (('print exps ...) ;; ???
238 - (@> Printnl (map T exps) py/none))
239 + ((print exps ...) ;; ???
240 + (display (syntax-line #'(exps ...)))
241 + (@>* Printnl (syntax-line #'print) (map T (syntax->list #'(exps ...))) py/none))
244 - (('display exps ...)
245 - (@> Print (map T exps) py/none))
246 + ((display exps ...)
247 + (@> Print (map T (syntax->list #'(exps ...))) py/none))
249 ;;;; (import name1 name2 ...)
250 - (('import names ...)
251 + ((import names ...)
252 (@> Import (map (lambda (n)
253 (py/tuple (list (ss->py n) py/none)))
255 + (syntax->list #'(names ...)))))
258 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
262 - (@> CallFunc (T proc) (map T args)
263 + (@> CallFunc (T #'proc) (map T (syntax->list #'(args ...)))
264 py/none py/none)) ;; TODO: *args, **kwargs
268 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
269 ;; CONSTANTS, VARIABLES
271 ;;;; a token -- var, 23, "foobar", 634.34
274 - ((symbol? name) (unpack-name name))
275 - ((number? name) (@> Const name))
276 - ((string? name) (@> Const name))
277 - (else (error "invalid exp" name))))))
278 + (let ((nam (syntax-object->datum #'name)))
280 + ((symbol? nam) (unpack-name nam))
281 + ((number? nam) (@>* Const 7 nam))
282 + ((string? nam) (@>* Const 7 nam))
283 + (else (error "invalid exp" nam)))))))
285 ;; These functions handle names of the forms,
288 (lname (last names*)))
290 (fold (lambda (a b) (@> Getattr b a))
291 - (T (string->symbol (car names)))
293 + (T (string->symbol (car names)))
297 (@> AssName name "OP_ASSIGN"))))
302 - (@ (: "__builtin__" 'chr) n)))
303 + (@ (: "__builtin__" 'chr) n) ))
305 (bitwise-and (arithmetic-shift ts (- n)) #xff))
310 (define (read-sexp fileh)
311 - (let ((sexp (read fileh)))
312 + (let ((sexp (read-syntax "d:\\Code\\boalisp\\lineno.boa" fileh)))
313 (if (eof-object? sexp)
315 (cons sexp (read-sexp fileh)))))
317 (set! *filename-hack* filename)
318 (call-with-input-file filename
320 + (port-count-lines! i)
321 (let* ((ast (@> Module "<DOCSTRING>" (@> Stmt (map T (read-sexp i)))))
322 (_ (filename-hack! ast))
323 (c (@ (: "compiler" 'pycodegen 'InteractiveCodeGenerator) ast))
325 === modified file 'examples/test.boa'
326 --- examples/test.boa 2007-05-18 11:20:08 +0000
327 +++ examples/test.boa 2007-05-24 04:58:08 +0000
330 (def foo (a b (c 99) (d 101))
334 (return (+ c d (+ c d) (+ d 3))))
337 === modified file 'python.ss'
338 --- python.ss 2007-05-18 11:20:08 +0000
339 +++ python.ss 2007-05-29 20:11:30 +0000
342 (@> node : (list c1 ...)))))
346 + ((_ node lineno : c-list)
347 + (let ((a (apply (ast (symbol->string 'node))
348 + (map ss->py c-list))))
349 + (py/setattr a "lineno" (py/int lineno))
351 + ((_ node lineno c1 ...)
352 + (@>* node lineno : (list c1 ...)))))
355 \ No newline at end of file