1 (in-package #:avm2-compiler
)
3 ;;; implement lower level functions from conses dictionary
5 ;;; not all match CL semantics very closely yet...
7 ;;; conses dictionary (14.2)
9 ;;; not sure what best internal rep for conses is,
10 ;;; could use anonymous object
12 ;;; instances of named class
15 ;;; named class is probably easiest to recognize for type checking
16 ;;; so trying that first
17 ;;; anon object with car and cdr properties might also be nice, and
18 ;;; just allow any object with those to be used as a 'cons', but
19 ;;; wouldn't match CL sematics very well
20 (let ((*symbol-table
* *cl-symbol-table
*))
21 ;; todo: probably should figure out how to make this final/sealed/etc.
22 (def-swf-class cons-type
"cons" object
(%car %cdr
)
24 (%set-property this %car a
)
25 (%set-property this %cdr b
)))
27 (swf-defmemfun cons
(a b
)
28 (%asm
(:find-property-strict cons-type
)
31 (:construct-prop cons-type
2)))
33 #||
(def-swf-class cons-type
"cons" object
(%car %cdr
)
37 (swf-defmemfun cons
(a b
)
38 (%asm
(:find-property-strict cons-type
)
39 (:construct-prop cons-type
0)
48 (swf-defmemfun consp
(a)
51 (swf-defmemfun atom
(object)
54 (swf-defmemfun %type-error
(fun arg
)
55 (%error
(+ "type-error: unknown type in " fun
":" (%type-of arg
))))
57 #+nil
(swf-defmemfun car
(a)
63 (%type-error
"CAR" a
))))
65 #+nil
(swf-defmemfun cdr
(a)
71 (%type-error
"CDR" a
))))
74 (swf-defmemfun car
(a)
78 (:get-property %car
))))
80 (swf-defmemfun cdr
(a)
84 (:get-property %cdr
))))
87 (swf-defmacro rplaca
(cons object
)
88 (let ((temp (gensym "RPLACA-TEMP-")))
91 (unless (consp ,temp
) (%type-error
"RPLACA" ,temp
))
92 (%set-property
,temp %car
,object
)
95 (swf-defmacro rplacd
(cons object
)
96 (let ((temp (gensym "REPLACD-TEMP-")))
99 (unless (consp ,temp
) (%type-error
"RPLACD" ,temp
))
100 (%set-property
,temp %cdr
,object
)
104 (swf-defmemfun caar
(x) (car (car x
)))
105 (swf-defmemfun cadr
(x) (car (cdr x
)))
106 (swf-defmemfun cdar
(x) (cdr (car x
)))
107 (swf-defmemfun cddr
(x) (cdr (cdr x
)))
108 (swf-defmemfun caaar
(x) (car (car (car x
))))
109 (swf-defmemfun caadr
(x) (car (car (cdr x
))))
110 (swf-defmemfun cadar
(x) (car (cdr (car x
))))
111 (swf-defmemfun caddr
(x) (car (cdr (cdr x
))))
112 (swf-defmemfun cdaar
(x) (cdr (car (car x
))))
113 (swf-defmemfun cdadr
(x) (cdr (car (cdr x
))))
114 (swf-defmemfun cddar
(x) (cdr (cdr (car x
))))
115 (swf-defmemfun cdddr
(x) (cdr (cdr (cdr x
))))
116 (swf-defmemfun caaaar
(x) (car (car (car (car x
)))))
117 (swf-defmemfun caaadr
(x) (car (car (car (cdr x
)))))
118 (swf-defmemfun caadar
(x) (car (car (cdr (car x
)))))
119 (swf-defmemfun caaddr
(x) (car (car (cdr (cdr x
)))))
120 (swf-defmemfun cadaar
(x) (car (cdr (car (car x
)))))
121 (swf-defmemfun cadadr
(x) (car (cdr (car (cdr x
)))))
122 (swf-defmemfun caddar
(x) (car (cdr (cdr (car x
)))))
123 (swf-defmemfun cadddr
(x) (car (cdr (cdr (cdr x
)))))
124 (swf-defmemfun cdaaar
(x) (cdr (car (car (car x
)))))
125 (swf-defmemfun cdaadr
(x) (cdr (car (car (cdr x
)))))
126 (swf-defmemfun cdadar
(x) (cdr (car (cdr (car x
)))))
127 (swf-defmemfun cdaddr
(x) (cdr (car (cdr (cdr x
)))))
128 (swf-defmemfun cddaar
(x) (cdr (cdr (car (car x
)))))
129 (swf-defmemfun cddadr
(x) (cdr (cdr (car (cdr x
)))))
130 (swf-defmemfun cdddar
(x) (cdr (cdr (cdr (car x
)))))
131 (swf-defmemfun cddddr
(x) (cdr (cdr (cdr (cdr x
)))))
134 (swf-defmemfun copy-tree
(tree)
136 (cons (copy-tree (car tree
)) (copy-tree (cdr tree
)))
139 (swf-defmemfun listp
(a)
140 (or (%typep a cons-type
) (eq a nil
)))
142 ;; fixme: implement pop according to spec
143 (swf-defmacro pop
(a)
144 (let ((temp (gensym "POP-TEMP-")))
146 (%asm
(:comment
"pop") (:push-null
))
150 (setf ,a
(cdr ,temp
)))))))
152 ;; fixme: implement PUSH according to spec
153 (swf-defmacro push
(item place
)
154 (let ((temp (gensym "PUSH-TEMP-")))
156 (let ((,temp
,place
))
157 (setf ,place
(cons ,item
,temp
))))))
160 (swf-defmemfun first
(list) (car list
))
161 (swf-defmemfun second
(list) (car (cdr list
)))
162 (swf-defmemfun third
(list) (car (cddr list
)))
163 (swf-defmemfun fourth
(list) (car (cdddr list
)))
164 (swf-defmemfun fifth
(list) (car (cddddr list
)))
165 (swf-defmemfun sixth
(list) (car (cdr (cddddr list
))))
166 (swf-defmemfun seventh
(list) (car (cddr (cddddr list
))))
167 (swf-defmemfun eighth
(list) (car (cdddr (cddddr list
))))
168 (swf-defmemfun ninth
(list) (car (cddddr (cddddr list
))))
169 (swf-defmemfun tenth
(list) (car (cdr (cddddr (cddddr list
)))))
172 (swf-defmemfun endp
(a)
177 (%type-error
"ENDP" a
))))
179 (swf-defmemfun null
(a)
182 ;; fixme: add optional count arg
183 (swf-defmemfun last
(a)
188 (unless (consp (cdr a
))
193 (swf-defmemfun nconc
(&arest lists
)
194 (let* ((a (if (zerop (:length lists
))
198 (dotimes (i (1- (:length lists
)) a
)
199 (let ((next (aref lists
(1+ i
))))
200 (rplacd (last end
) next
)
208 (nconc (cons 1 2) (cons 3 4)))