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
))
21 (scompile (first cdr
))
22 (loop for
,i in
(cdr cdr
)
24 collect
`(,',opcode
))))))))))
26 (define-transitive-binops
39 ;;(scompile '(+ 1 2 3))
41 (defmacro define-compare-binops
(&body ops
)
45 ,@(loop for
(op opcode
) in ops
46 collect
`(defmethod scompile-cons ((car (eql ',op
)) cdr
)
48 (0 (error "not enough arguments for ~a" ',op
))
51 (scompile (first cdr
))
52 (scompile (second cdr
))
56 (scompile (first cdr
))
57 (scompile (second cdr
))
59 (loop for
(,i
,j
) on
(cdr cdr
)
64 collect
`(:bit-and
) ;; no logical and?
67 (define-compare-binops
74 ;; (scompile '(< 1 2 3 4))