1 (in-package :avm2-compiler
)
2 ;;; random tests for various features, need to figure out how to
3 ;;; automate these at some point
5 (with-open-file (s "/tmp/tests.swf"
7 :element-type
'(unsigned-byte 8)
9 (with-compilation-to-stream s
("frame1" `((0 "testClass")))
11 (def-swf-class :test-class
"test-class" flash.display
::sprite
()
16 #+nil
(swf-defmemfun flet-test1
()
17 (%flet
(foo (a b c
) (+ a b c
))
18 (call-%flet foo
"a" "b" "c")
19 (call-%flet foo
"1" "2" "3")))
21 (swf-defmemfun flet-test1
()
22 (%flet
(foo (a b c
) (+ a b c
))
23 (call-%flet foo
(%flet
(afoo (a b c
) (+ a b c
))
24 (call-%flet afoo
"a" "b" "c"))
27 #+nil
(swf-defmemfun uwp-test
()
32 (if :true
(return-from foo
"-ret-") 4)
33 (%set-local s2
(+ s2
"uwp")))
37 (swf-defmemfun uwp-test
()
42 (return-from foo
"-ret-")
44 (%set-local s2
(+ s2
123))))
47 (swf-defmemfun cons-test
()
50 (%set-property
(cdr b
) %car
123)
51 (+ "(" (car a
) " " (car b
) ")")))
53 (swf-defmemfun test-dolist
()
54 "not implemented"#+nil
(let ((temp ""))
55 (dolist (a (cons "a" (cons "b" (cons "c" nil
)))
57 (%set-local temp
(+ temp
(:to-string a
))))))
59 (swf-defmemfun i255
(a)
60 (flash::Math.max
(flash::Math.min
(floor (* a
256)) 255) 0))
62 (swf-defmemfun rgb
(r g b
)
63 (+ (* (i255 r
) 65536) (* (i255 g
) 256) (i255 b
)))
65 (swf-defmemfun rgba
(r g b a
)
66 (+ (* (i255 a
) 65536 256) (rgb r g b
)))
68 (swf-defmemfun main
(arg)
69 (let ((foo (%new flash.text
::Text-Field
0))
70 (canvas (%new flash.display
::Sprite
0)))
71 (%set-property foo
:width
350)
72 (%set-property foo
:auto-size
"left")
73 (%set-property foo
:text-color
(rgb 0.2 0.9 0.2 ))
74 (%set-property foo
:word-wrap
:true
)
75 (%set-property foo
:background
:true
)
76 (%set-property foo
:background-color
(rgba 0.1 0.1 0.1 0.1))
78 (%set-local str
(+ str
(flash::string.from-char-code
26085)))
79 (%set-local str
(+ str
(flash::string.from-char-code
26412)))
80 (%set-local str
(+ str
(flash::string.from-char-code
#x8a9e
)))
81 (let ((cc (cons 0 2)))
82 (%set-local str
(+ str
(cons 2 3)))
83 (%set-local str
(+ str
"=(" (car cc
) " " (cdr cc
) ")"))
84 (%set-local str
(+ str
" || car(nil)=" (car nil
)))
85 (%set-local str
(+ str
" || %typeof=" (%type-of cc
)))
86 (%set-local str
(+ str
" || %typep...=" (%typep cc cons-type
)))
87 (%set-local str
(+ str
" || %typep.1.=" (%typep
1 cons-type
)))
88 (%set-local str
(+ str
" || case="
95 (%set-local str
(+ str
" || case2="
100 (%set-local str
(+ str
" || block="
103 (if t
(return-from foo
"-ret-") 4)
105 #+nil
(%set-local str
(+ str
" uwp=" (uwp-test)))
106 (%set-local str
(+ str
" || cons=" (cons-test)))
107 (%set-local str
(+ str
" || %flet=" (flet-test1)))
108 ;;(%set-local str (+ str " %flet=" (flet-test2 "a" "b" "c")))
109 ;;(%set-local str (+ str " cdr(1)=" (cdr 1)))
110 (%set-local str
(+ str
" || <" (if (car :null
) "t" "f") ">"))
111 (%set-local str
(+ str
" || typecase 123="
116 (%set-local str
(+ str
" || typecase cons="
120 (%set-local str
(+ str
" || when t ="
122 (%set-local str
(+ str
" || when nil ="
124 (%set-local str
(+ str
" || unless t ="
126 (%set-local str
(+ str
" || unless nil ="
128 (%set-local str
(+ str
" || and ="
130 (%set-local str
(+ str
" || and t ="
132 (%set-local str
(+ str
" || and t nil ="
134 (%set-local str
(+ str
" || and nil t ="
136 (%set-local str
(+ str
" || and t t ="
138 (%set-local str
(+ str
" || or ="
140 (%set-local str
(+ str
" || or t ="
142 (%set-local str
(+ str
" || or t nil ="
144 (%set-local str
(+ str
" || or nil t ="
146 (%set-local str
(+ str
" || or t t ="
148 (%set-local str
(+ str
" || cond="
154 (let ((c2 (cons "a" (cons "b" nil
))))
155 (%set-local str
(+ str
" || pop1 =" (pop c2
)))
156 (%set-local str
(+ str
" || pop2 = (" (car c2
) " . " (cdr c2
) ")"))
158 (%set-local str
(+ str
" || dolist=" (test-dolist)))
161 (%set-property foo
:text
(+ str
" || " (%call-property
(%array
1 2 3) :to-string
))))
162 (:add-child arg canvas
)
164 (%set-property this
:canvas canvas
)
166 #+nil
(:add-event-listener arg
"enterFrame" (%get-lex
:frame
))
167 (:add-event-listener canvas
"click" (%asm
(:get-lex frame
)))))
169 (swf-defmacro with-fill
(gfx (color alpha
&key line-style
) &body body
)
172 `((:line-style
,gfx
,@line-style
)))
173 (:begin-fill
,gfx
,color
,alpha
)
177 (swf-defmemfun frame
(evt)
178 (let* ((canvas (%get-property this
:canvas
))
179 (gfx (:graphics canvas
))
180 (matrix (%new flash.geom
::Matrix
0)))
182 (%set-property canvas
:opaque-background
#x0d0f00
)
184 (with-fill gfx
(#x202600
0.5)
185 (:draw-rect gfx
0 0 400 300 ))
186 (:create-gradient-box matrix
188 (:begin-gradient-fill gfx
"radial"
189 (%array
#x202600
#x0d0f00
) ;; colors
190 (%array
1 1) ;; alpha
191 (%array
0 255) ;; ratios
193 (:draw-rect gfx
0 0 400 300 )