1 (in-package :avm2-compiler
)
3 ;;; expand multiple arg math/comparison ops into chained binary ops
5 (defmacro define-transitive-binops
(&body ops
)
8 ,@(loop for
(op opcode identity unary-op
) in ops
9 collect
`(defmethod scompile-cons ((car (eql ',op
)) cdr
)
11 (0 ,(if identity
`(scompile ,identity
) `(error "not enough arguments for ~a" ,op
)))
13 `(scompile `(,',unary-op
,(first cdr
)))
14 `(scompile (first cdr
))))
16 (scompile (first cdr
))
17 (scompile (second cdr
))
22 (scompile (first cdr
))
23 (loop for
,i in
(cdr cdr
)
26 '((:coerce-any
))))))))))
28 (define-transitive-binops
41 ;;(scompile '(+ 1 2 3))
43 (defmacro define-compare-binops
(&body ops
)
47 ,@(loop for
(op opcode
) in ops
48 collect
`(defmethod scompile-cons ((car (eql ',op
)) cdr
)
50 (0 (error "not enough arguments for ~a" ',op
))
54 (scompile (first cdr
))
55 (scompile (second cdr
))
60 (scompile (first cdr
))
61 (scompile (second cdr
))
63 (loop for
(,i
,j
) on
(cdr cdr
)
68 collect
`(:bit-and
) ;; no logical and?
70 '((:coerce-any
))))))))))
72 (define-compare-binops
79 ;; (scompile '(< 1 2 3 4))