2011/04/23 ActionScript   Flash
          #1




ActionScriptVM2
  mzp /




               1
mzp /

       SE



> ocaml-nagoya
> ProofCafe
>       Scala

                 2
)
Rails 3 + HTML5


http://codefirst.github.com/AsakusaSatellite/




                   3
2/26         Reject

            PHP swf                   !


                 OCaml swf


       Twitter

                 swf




                       !         !!


                             4
2/26         Reject

            PHP swf                   !


                 OCaml swf


       Twitter

                 swf




                       !         !!


                             4
!
ActionScript   Flash   !!
ActionScript
ActionScript

       !!
As1,2          As3
               v.s.          →


        VM      →        !

> As1,As2 → AVM1 Flash
> As3 → AVM2
       AVM2


                7
AVM2
AVM1

>   JIT     !

AS3

>   E4X

Flash9               AVM2



                 8
HappyABC
Flash9       Scheme(       )

As3      →

OCaml

>
>




                       9
HelloWorld
Hello, World!

As3

>                      swf

>   swf


trace("hello");
                  11
Flex SDK[1]             asc.jar

       > hello.abc
       > abc = Actionscript Byte Code

    $ java -jar asc.jar hello.as
    hello.abc, 79 bytes written


[1]http://opensource.adobe.com/wiki/display/flexsdk/Flex+SDK

                                 12
Tamarin[2]

        Flash Player           AVM2

       >   Adobe       Mozilla

       >   Firefox

    $ shell hello.abc
    hello
[2]http://www.mozilla.org/projects/tamarin/
                                   13
tamarin               abcdump[3]


    $ shell abcdump.abc -- hello.abc
    // magic 2e0010
    // Cpool numbers size 3 3 %
    // Cpool strings count 5 size 25 31 %
    // Cpool namespaces count 3 size 5 6 %
    // Cpool nssets count 2 size 4 5 %
    ( )
[3]http://d.hatena.ne.jp/nitoyon/20090123/abcdump_build
                                 14
function script0$init():*
{
  // local_count=2 max_scope=1 max_stack=2
code_len=15
  0       getlocal0
  1       pushscope
  2       findpropstrict    trace
  4       pushstring      "hello"
  6       callproperty    trace (1)
  9       coerce_a
  10       setlocal1
  11       getlocal1
  12       returnvalue
  13       kill         1
}
                        15
AVM2

            push/pop




       16
)
1+2




> pushbyte 1
 pushbyte 2         (   )
 add

               17
)
1+2

> pushbyte 1: 1




 pushbyte 1
> pushbyte 2
 add

                  18
)
1+2

> pushbyte 1: 1
> pushbyte 2: 2


 pushbyte 1
 pushbyte 2
> add

                  19
)
1+2

> pushbyte 1: 1
> pushbyte 2: 2


 pushbyte 1
 pushbyte 2
 add
>
                  20
+α
AVM2

            2




       21
(          )
function script0$init():*
{
  // local_count=2 max_scope=1 max_stack=2
code_len=15
  0       getlocal0
  1       pushscope
  2       findpropstrict    trace
  4       pushstring      "hello"
  6       callproperty    trace (1)
  9       coerce_a
  10       setlocal1
  11       getlocal1
  12       returnvalue
  13       kill         1
}
                        22
this
getlocal0 //       0               push
pushscope //

    AVM2

   >0                       this

   >1
    this ”     ”   push

                       23
) this
      this 0                       = this




//
addEventListener(MouseEvent.CLICK, function(e){
 //      this
});
                       24
(          )
function script0$init():*
{
  // local_count=2 max_scope=1 max_stack=2
code_len=15
  0       getlocal0
  1       pushscope
  2       findpropstrict    trace
  4       pushstring      "hello"
  6       callproperty    trace (1)
  9       coerce_a
  10       setlocal1
  11       getlocal1
  12       returnvalue
  13       kill         1
}
                        25
trace
// trace


findpropstrict trace
//                  push
pushstring    "hello"
// trace
           push
callproperty trace (1)

                         26
trace



findpropstrict trace
pushstring “hello”
callproperty trace(1)

                        27
trace
      findpropstrict      trace


                                AVM2



> findpropstrict trace
 pushstring “hello”
 callproperty trace(1)

                           28
trace
      findpropstrict      trace


                                AVM2



> findpropstrict trace
 pushstring “hello”
 callproperty trace(1)

                           28
trace

       pushstring




 findpropstrict trace
> pushstring “hello”
 callproperty trace(1)

                         29
trace

       pushstring




 findpropstrict trace
> pushstring “hello”
 callproperty trace(1)

                         29
trace
      callpropery    trace



      <obj>.trace(“hello”)


 findpropstrict trace
 pushstring “hello”
> callproperty trace(1)

                          30
trace
      callpropery    trace



      <obj>.trace(“hello”)


 findpropstrict trace
 pushstring “hello”
> callproperty trace(1)

                          30
(          )
function script0$init():*
{
  // local_count=2 max_scope=1 max_stack=2
code_len=15
  0       getlocal0
  1       pushscope
  2       findpropstrict    trace
  4       pushstring      "hello"
  6       callproperty    trace (1)
  9       coerce_a
  10       setlocal1
  11       getlocal1
  12       returnvalue
  13       kill         1
}
                        31
return
//            *(any)
coerce_a
//            1
setlocal1
// 1                    push
getlocal1
//
returnvalue
// 1
kill    1
                  32
?


//
pop
//
returnvoid



             33
ABC
 s24 : 24         signed int

 u8, u16: n         unsigned int

 u30, u32,s32 :          (un)signed int

 >       5

 >       1

 d64 :               (double)

 swf                                      (u30   )


                       35
getlocal_0        ABC




opcode   u8




                  36
function script0$init():*
{
  // local_count=2 max_scope=1 max_stack=2
code_len=15
  0       getlocal0
  1       pushscope
  2       findpropstrict    trace
  4       pushstring      "hello"
  6       callproperty    trace (1)
  9       coerce_a
  10       setlocal1
  11       getlocal1
  12       returnvalue
  13       kill         1
}

                        opcode

                        37
kill 1   1

> opcode 0x08
>                     u30

u30      7            u8

kill 1 => 0x08 0x01

                38
function script0$init():*
{
  // local_count=2 max_scope=1 max_stack=2
code_len=15
  0       getlocal0
  1       pushscope
  2       findpropstrict    trace
  4       pushstring      "hello"
  6       callproperty    trace (1)
  9       coerce_a
  10       setlocal1
  11       getlocal1
  12       returnvalue
  13       kill         1
}

     kill

                        39
pushstring
> opcode 0x2c
>      u30

30                !

>

             40
(constant pool; cpool)




int    1, 42, ...          pushstring “hello”

string “foo”,
       “hello”, ...
...    ...                     0x2c 0x02
                      41
ABC
>   int, uint, string, double



>                 +        (public       )

                 => As               ?



>            +

>

                            42
function script0$init():*
{
  // local_count=2 max_scope=1 max_stack=2
code_len=15
  0       getlocal0
  1       pushscope
  2       findpropstrict    trace
  4       pushstring      "hello"
  6       callproperty    trace (1)
  9       coerce_a
  10       setlocal1
  11       getlocal1
  12       returnvalue
  13       kill         1
}




                        43
AS1,2    AS3       VM        →AVM2

ABC     Tamarin

AVM2

> As3          1   1

>                  GC

                              swf




                        44
AVM2 Overview(                                     )
>   http://www.adobe.com/content/dam/Adobe/en/devnet/actionscript/articles/
    avm2overview.pdf

swfmill(trunk)
>   http://swfmill.org
>   svn trunk            ABC

tamarin

>   verbose


                                   45

20110424 action scriptを使わないflash勉強会

  • 1.
    2011/04/23 ActionScript Flash #1 ActionScriptVM2 mzp / 1
  • 2.
    mzp / SE > ocaml-nagoya > ProofCafe > Scala 2
  • 3.
    ) Rails 3 +HTML5 http://codefirst.github.com/AsakusaSatellite/ 3
  • 4.
    2/26 Reject PHP swf ! OCaml swf Twitter swf ! !! 4
  • 5.
    2/26 Reject PHP swf ! OCaml swf Twitter swf ! !! 4
  • 6.
  • 7.
  • 8.
  • 9.
    As1,2 As3 v.s. → VM → ! > As1,As2 → AVM1 Flash > As3 → AVM2 AVM2 7
  • 10.
    AVM2 AVM1 > JIT ! AS3 > E4X Flash9 AVM2 8
  • 11.
    HappyABC Flash9 Scheme( ) As3 → OCaml > > 9
  • 12.
  • 13.
    Hello, World! As3 > swf > swf trace("hello"); 11
  • 14.
    Flex SDK[1] asc.jar > hello.abc > abc = Actionscript Byte Code $ java -jar asc.jar hello.as hello.abc, 79 bytes written [1]http://opensource.adobe.com/wiki/display/flexsdk/Flex+SDK 12
  • 15.
    Tamarin[2] Flash Player AVM2 > Adobe Mozilla > Firefox $ shell hello.abc hello [2]http://www.mozilla.org/projects/tamarin/ 13
  • 16.
    tamarin abcdump[3] $ shell abcdump.abc -- hello.abc // magic 2e0010 // Cpool numbers size 3 3 % // Cpool strings count 5 size 25 31 % // Cpool namespaces count 3 size 5 6 % // Cpool nssets count 2 size 4 5 % ( ) [3]http://d.hatena.ne.jp/nitoyon/20090123/abcdump_build 14
  • 17.
    function script0$init():* { // local_count=2 max_scope=1 max_stack=2 code_len=15 0 getlocal0 1 pushscope 2 findpropstrict trace 4 pushstring "hello" 6 callproperty trace (1) 9 coerce_a 10 setlocal1 11 getlocal1 12 returnvalue 13 kill 1 } 15
  • 18.
    AVM2 push/pop 16
  • 19.
    ) 1+2 > pushbyte 1 pushbyte 2 ( ) add 17
  • 20.
    ) 1+2 > pushbyte 1:1 pushbyte 1 > pushbyte 2 add 18
  • 21.
    ) 1+2 > pushbyte 1:1 > pushbyte 2: 2 pushbyte 1 pushbyte 2 > add 19
  • 22.
    ) 1+2 > pushbyte 1:1 > pushbyte 2: 2 pushbyte 1 pushbyte 2 add > 20
  • 23.
  • 24.
    ( ) function script0$init():* { // local_count=2 max_scope=1 max_stack=2 code_len=15 0 getlocal0 1 pushscope 2 findpropstrict trace 4 pushstring "hello" 6 callproperty trace (1) 9 coerce_a 10 setlocal1 11 getlocal1 12 returnvalue 13 kill 1 } 22
  • 25.
    this getlocal0 // 0 push pushscope // AVM2 >0 this >1 this ” ” push 23
  • 26.
    ) this this 0 = this // addEventListener(MouseEvent.CLICK, function(e){ // this }); 24
  • 27.
    ( ) function script0$init():* { // local_count=2 max_scope=1 max_stack=2 code_len=15 0 getlocal0 1 pushscope 2 findpropstrict trace 4 pushstring "hello" 6 callproperty trace (1) 9 coerce_a 10 setlocal1 11 getlocal1 12 returnvalue 13 kill 1 } 25
  • 28.
    trace // trace findpropstrict trace // push pushstring "hello" // trace push callproperty trace (1) 26
  • 29.
  • 30.
    trace findpropstrict trace AVM2 > findpropstrict trace pushstring “hello” callproperty trace(1) 28
  • 31.
    trace findpropstrict trace AVM2 > findpropstrict trace pushstring “hello” callproperty trace(1) 28
  • 32.
    trace pushstring findpropstrict trace > pushstring “hello” callproperty trace(1) 29
  • 33.
    trace pushstring findpropstrict trace > pushstring “hello” callproperty trace(1) 29
  • 34.
    trace callpropery trace <obj>.trace(“hello”) findpropstrict trace pushstring “hello” > callproperty trace(1) 30
  • 35.
    trace callpropery trace <obj>.trace(“hello”) findpropstrict trace pushstring “hello” > callproperty trace(1) 30
  • 36.
    ( ) function script0$init():* { // local_count=2 max_scope=1 max_stack=2 code_len=15 0 getlocal0 1 pushscope 2 findpropstrict trace 4 pushstring "hello" 6 callproperty trace (1) 9 coerce_a 10 setlocal1 11 getlocal1 12 returnvalue 13 kill 1 } 31
  • 37.
    return // *(any) coerce_a // 1 setlocal1 // 1 push getlocal1 // returnvalue // 1 kill 1 32
  • 38.
  • 40.
    ABC s24 :24 signed int u8, u16: n unsigned int u30, u32,s32 : (un)signed int > 5 > 1 d64 : (double) swf (u30 ) 35
  • 41.
    getlocal_0 ABC opcode u8 36
  • 42.
    function script0$init():* { // local_count=2 max_scope=1 max_stack=2 code_len=15 0 getlocal0 1 pushscope 2 findpropstrict trace 4 pushstring "hello" 6 callproperty trace (1) 9 coerce_a 10 setlocal1 11 getlocal1 12 returnvalue 13 kill 1 } opcode 37
  • 43.
    kill 1 1 > opcode 0x08 > u30 u30 7 u8 kill 1 => 0x08 0x01 38
  • 44.
    function script0$init():* { // local_count=2 max_scope=1 max_stack=2 code_len=15 0 getlocal0 1 pushscope 2 findpropstrict trace 4 pushstring "hello" 6 callproperty trace (1) 9 coerce_a 10 setlocal1 11 getlocal1 12 returnvalue 13 kill 1 } kill 39
  • 45.
  • 46.
    (constant pool; cpool) int 1, 42, ... pushstring “hello” string “foo”, “hello”, ... ... ... 0x2c 0x02 41
  • 47.
    ABC > int, uint, string, double > + (public ) => As ? > + > 42
  • 48.
    function script0$init():* { // local_count=2 max_scope=1 max_stack=2 code_len=15 0 getlocal0 1 pushscope 2 findpropstrict trace 4 pushstring "hello" 6 callproperty trace (1) 9 coerce_a 10 setlocal1 11 getlocal1 12 returnvalue 13 kill 1 } 43
  • 49.
    AS1,2 AS3 VM →AVM2 ABC Tamarin AVM2 > As3 1 1 > GC swf 44
  • 50.
    AVM2 Overview( ) > http://www.adobe.com/content/dam/Adobe/en/devnet/actionscript/articles/ avm2overview.pdf swfmill(trunk) > http://swfmill.org > svn trunk ABC tamarin > verbose 45