1 (in-package :avm2-compiler
)
5 (defun %compile-defun
(name args body method constructor
&key
(nil-block t
))
6 ;; fixme: is the nil-block stuff still valid?
7 (with-lambda-context (:args args
:blocks
(when nil-block
(list nil
)))
9 (if (or method constructor
)
18 `(,@(scompile `(block ,name
,@body
))
21 `(,@(scompile `(block ,name
,@body
))
23 (compile-lambda-context-cleanup))))
25 (defun %swf-defun
(name args body
&key method constructor
)
26 ;; was pushnew, but that makes it hard to work on code (since can't
27 ;; redefine things) push isn't quite right either, should replace
28 ;; existing value or something
29 ;; (or more likely, just not have a list at all?)
30 (flet ((parse-arglist (args)
31 ;; fixme: add error checking, better lambda list parsing
40 when
(eq i
'&optional
)
44 when
(and i
(not rest
))
47 collect i into arg-names
49 collect i into optional-names
50 finally
(return (values arg-names count rest optional-names
)))))
51 (multiple-value-bind (names count rest-p optionals
)
53 (declare (ignorable optionals
))
54 (when optionals
(error "&optional args not supported yet"))
57 ;; swf name in format suitable for passing to asm (string/'(qname...))
58 ;; args to avm2-method:
60 ;; list of arg types (probably all T/* for now)
66 (avm2-asm::symbol-to-qname-list name
)
67 0 ;; name in method struct?
68 (loop repeat count collect
0) ;; arg types, 0 = t/*/any
69 0 ;; return type, 0 = any
70 (if rest-p
#x04
0) ;; flags, #x04 = &rest
71 (%compile-defun
name names body method constructor
))
72 (gethash name
(functions *symbol-table
*) (list))
77 ;;(format t "~{~s~%~}" (sixth (find-swf-function 'floor)))
78 ;;(format t "~{~s~%~}" (avm2-asm::avm2-disassemble (avm2-asm:assemble (sixth (find-swf-function 'random)))))
80 (defun old-%swf-defun
(name args body
&key method constructor
)
82 (setf name
(avm2-asm::symbol-to-qname name
)))
83 (with-lambda-context (:args args
)
85 (avm2-asm::avm2-method
0
86 (loop for i in args collect
0 ) ;; 0 = * (any type)
91 (if (or method constructor
)
100 `(,@(scompile `(progn ,@body
))
103 (scompile `(return (progn ,@body
)))))))))
105 (push (list name mid
) (function-names *compiler-context
*)))
108 (defmacro swf-defun
(name (&rest args
) &body body
)
109 `(%swf-defun
',name
',args
(list
110 ,@(loop for i in body
111 if
(and (consp i
) (eql (car i
) 'cl
))
114 collect
(list 'quote i
)))))
116 (defmacro swf-constructor
(name (&rest args
) &body body
)
117 `(%swf-defun
',name
',args
(list
118 ,@(loop for i in body
119 if
(and (consp i
) (eql (car i
) 'cl
))
122 collect
(list 'quote i
)))
125 (defmacro swf-defmemfun
(name (&rest args
) &body body
)
126 `(%swf-defun
',name
',args
(list
127 ,@(loop for i in body
128 if
(and (consp i
) (eql (car i
) 'cl
))
131 collect
(list 'quote i
)))
134 (defmacro swf-defmacro
(name (&rest args
) &body body
)
135 `(defmethod scompile-cons ((car (eql ',name
)) cdr
)
136 (destructuring-bind (,@args
) cdr
141 (defmacro dump-defun-asm
(args &body body
)
142 "debugging function to compile a defun to asm, and print results"
143 (let ((asm (gensym)))
144 `(let ((,asm
(%compile-defun
'foo
148 (format t
"~%~{~s~%~}" ,asm
)