1 (in-package #:avm2-compiler
)
3 ;;; implement functions/macros from CL package
5 ;;; most probably don't match CL semantics very closely yet...
8 ;;; define this here for now instead of special-forms.lisp, as it needs %flash
9 (defmethod %quote
((object symbol
))
10 ;; fixme: need to intern symbols somewhere, this doesn't make symbols that are EQ (though they are EQL with current implementation, which probably means EQL should be EQUAL)
11 (scompile `(%new
* %flash
:q-name
12 ,(package-name (symbol-package object
))
13 ,(symbol-name object
))))
16 (let ((*symbol-table
* *cl-symbol-table
*))
18 (swf-defmacro %apply
(function this-arg rest-array
)
19 `(%flash
:apply
,function
,this-arg
,rest-array
))
21 (swf-defmacro %funcall
(function this-arg
&rest rest
)
22 `(%flash
:call
,function
,this-arg
,@rest
))
24 (swf-defmacro return
(value)
25 `(return-from nil
,value
))
28 ;; partial implementation of setf, only handles setting local vars,
29 ;; so we can start using it while waiting on real implementation
30 ;; adding hack for (setf foo) functions also (doesn't work yet though)
31 (swf-defmacro %setf-1
(place value
)
32 (print (if (consp place
)
34 ((find-swf-property (first place
))
35 `(%set-property
,(second place
) ,(first place
) ,value
))
36 (t `((setf ,(first place
)) ,(second place
) ,(first place
) ,value
)))
37 `(%set-local
,place
,value
))))
39 (swf-defmacro setf
(&rest args
)
41 ,@(loop for
(var value
) on args by
#'cddr
42 collect
`(%setf-1
,var
,value
))))
44 ;; partial implementation of psetf, only handles setting local vars,
45 ;; so we can start using it while waiting on real implementation
46 (swf-defmacro psetf
(&rest args
)
47 (let ((temps (loop repeat
(/ (length args
) 2)
51 for
(nil value
) on args by
#'cddr
52 collect
`(,temp
,value
)))
55 for
(var nil
) on args by
#'cddr
56 collect
`(setf ,var
,temp
)))))
58 ;; setq and psetq just calling setf/psetf for now, after checking vars
59 (swf-defmacro setq
(&rest args
)
60 (loop for
(var nil
) on args by
#'cddr
62 do
(error "variable name is not a symbol in SETQ: ~s" var
))
65 (swf-defmacro psetq
(&rest args
)
66 (loop for
(var nil
) on args by
#'cddr
68 do
(error "variable name is not a symbol in PSETQ: ~s" var
))
71 (swf-defmemfun random
(a)
72 ;;todo: return int for int args
73 ;;fixme: don't seem to be able to set seeds, so can't do random-state arg
74 (* (%flash
:random
) a
))
81 (swf-defmemfun floor
(number)
82 ;; todo implement optional divisor arg (need multiple values)
83 (%flash
:floor number
))
85 (swf-defmemfun cos
(radians)
87 (swf-defmemfun sin
(radians)
89 (swf-defmemfun tan
(radians)
92 (swf-defmemfun min
(&arest numbers
)
93 (%apply
(function %flash
:min
) nil numbers
))
95 (swf-defmemfun max
(&arest numbers
)
96 (%apply
(function %flash
:max
) nil numbers
))
98 (swf-defmemfun eq
(a b
)
103 (swf-defmemfun eql
(a b
)
106 ;; not quite right, since it compares all numbers by value
107 ;; also compares strings, but since strings are immutable,
108 ;; that is arguably OK
111 (swf-defmemfun equal
(a b
)
114 ;;even less correct than EQL, since it converts
115 ;;string<->number<->Boolean, and a few other things
118 #+nil
(swf-defmemfun error
(datum &rest args
) )
120 #+nil
(swf-defmemfun typep
(object type
)
121 (%typep object type
))
123 (swf-defmacro let
* (bindings &body body
)
124 `(let (,(car bindings
))
126 `((let* ,(cdr bindings
) ,@body
))
131 ;;; sicl-conditionals.lisp: OR AND WHEN UNLESS COND CASE TYPECASE
132 ;;; sicl-iteration.lisp: DOLIST DOTIMES
134 ;; temporary hack until SETF is implemented
137 (swf-defmacro incf
(place &optional
(delta 1))
138 `(setf ,place
(+ ,place
,delta
)))
140 (swf-defmemfun zerop
(x)
143 (swf-defmemfun vector
(&arest objects
)
146 ;; fixme: figure out symbol stuff so this can be a function
147 (swf-defmacro slot-value
(object slot
)
148 (let ((slot-name (if (and (consp slot
) (eq 'quote
(car slot
)))
152 (:get-property
, (find-swf-property slot-name
)))))
157 #+nil
(let ((*symbol-table
* (make-instance 'symbol-table
:inherit
(list *cl-symbol-table
* *player-symbol-table
*))))
158 (dump-defun-asm (&arest rest
)
159 (%apply
(function %flash
:max
) nil rest
)))