The Output:

In fact the compiler itself is not producing code, it is calling a class
which produces the code. The class has functions for different kinds of
push, registers, math, brances, labels and so on. The defintion of the
output class is for a one-argument stack machine with strict type -- e.g.
the compiler does not assume that we can add an integer to a byte without
prior extending the byte to an integer. For AVM conversion simple do not
produce output. This way we can afterwards re-implement the output class to
produce other code, for example AVM2 assembly, binary output or real machine
code for our washing machine. In fact the output class is very small, there
are only very few commands in AVM or AVM2.
The output class is also responsible for calculating branch distances and
optimization.

In respects to more advanced optimzation, probably the code must be
converted to a 3 operand virtual machine code, then converted to the real
output we want, because all theory is based on 3 operands code.

for example d=a+b*c in 1 op code is (what we nativly get from parsers)
  push a
  push b
  push c
  *
  +
  pop d

in two op code (what most real existing processors use)
  ld b,d
  mult c,d
  add a,d

in 3 Operand code (what theory is using)
  d = b*c
  d = d + a

The Input

Most part on the input part is Expression evaluation, assignment and
function call. This part is nearly done, the rest mostly straight forward,
for example on comiling a while create a label, compile the expression and
the conditional jump to the end of the block, then let the compiler compile
the block and put a backward branch at the end.

I want to have commands for movie, frame etc. with support for placing
things on the stage, this may produce .xml for to be compiled with swfmill,
later version may create binary movies and probably a script putting
everything together.

The language is currently something like Visual Basic with some aspects of
AS for example for a string you can say mid(s,a,b) or s.subString(a,b), for
arrays it is accepting a(x) and a[x] and so on at least in cases we know
that a property is an array.

some language elements borrowed from other languages may help in
optimization, for example we can create faster code with BASIC or Pascal for
loops by evaluating the end codition only once instead of calculating it on
each step.

Some ideas of how to help on optimization are:

use of with borrowed from BASIC

   _root.createTextField("tf",    0,   0,   0,    800, 400);
   with _root.tf    // compiles to r:4=root.tf (or whatever register is free
in the moment)
    .background = 1 // compiles to r:4.background = 1
    .multiline = 1 // etc.
    .html = 0
    // and so on
  end with // releases r:4

Giving the array dimension  // assuming getMember is a damn slow operation
    dim chessboard(10,10) as byte  // minimax needs a frame around the 8x8
board.
    ... some code ...
      figure = chessboard(x,y) // compiles as figure =
chessboard.getMember(y*10+x)

Borrowing TYPE from Basic and compiling as numeric array // assuming
getMember is a damn slow operation
     dim chessboard(10,10) as TypeChess
     figure = chessboard(x,y).figure // compiles as
chessboard.GetMember(sizeof(TypeChess)*(y*10+x) + ElementOffset of .figure)
This is what a compiler for a real processor also has to do.

Preloading things aproving that we have many registers
    preload foo, bar
  if foo and bar a functions, we call r:4=getMember(this.foo) once and store
into a register, later we call r:4()
  I Do not know if this works anyway but getMethod with string parameter
seems to be a slow operation. Do we need this in AVM2 also?

Adding some assembly style
    push MouseStyle
    MakeTheMouseBeAHourglass
      .. some slow math ...
    pop MouseStyle
instead of declaring a variable for temprary storing things we need to
restore afterwards, we are in a stack machine anyway.

borrwing asm{} from C and do some string replace
asm {
    ... some asm functions
    push r:$bar // assuming bar is a local variable or parameter stored in
some register we push whatever is nessary
}

Having some different for loops
   for i = 1 to 100: foo() : next i  // no need for counting 1..100, we can
push 99 and decrement until zero
   for i = 1 to 100: bar(i): next i  // push 100 to the stack, use it for
compare, than drop
   for i = 1 to z: ... some code probably :: next i // loops to the
evaluation of z
   for (some assignment;some condition, some statement) { } // compile like
we have written
will produce different code, depening if we need the for variable, have an
end condtion which may be calcualted in advance and so on.


... more ideas ?

Greetings

Thomas

----- Original Message ----- 
From: "Samuel Agesilas" <[EMAIL PROTECTED]>
To: "Open Source Flash Mailing List" <[email protected]>
Sent: Monday, September 10, 2007 11:37 PM
Subject: Re: [osflash] Anybody interest in developing a new compiler?


> Hmm Thomas,
>
> Sounds very interesting. I've been doing a lot of work writing lexers
> for Saffron so I could be of assistance if I find the time in the
> future. But I have some questions. Are you planning to do a full
> compiler that supports embedded images, fonts, sound, etc. or just an
> Actionscript one. Also what VM are you planning to target AVM1( Flash
> 8 and lower) or AVM2(Flash 9). I think a Flash 9 is needed. While
> Actionscript 3 is a great improvement it's a far cry from far more
> mature and professional languages like Objective C, C# or even Java.
> There are a lots and LOTS of things in Actionscript 3 that need to be
> added in order to make it into a mature language and I think that an
> open source AVM2 compiler would be great. This way the community
> could decided what features to add in and not some folks somewhere
> locked up in some ivory tower consortium!
>
> Cheers,
> Sam
>
> On Sep 9, 2007, at 5:51 AM, Thomas Quester wrote:
>
>> Mark,
>>
>> Thanks for all the information, the new VM seems to be cool and
>> mighty and
>> good documented and easier to read.
>>
>>> From the compilers point of view, it creates a stricly typed one
>>> operand
>> stack code with type conversion calls (if nessary) using an output
>> class,
>> which may be replaced to focus differnt targets, currently
>> supported is
>> assembly text output for the old VM but there have also been output
>> for a vm
>> on an embedded device on which bytes are real bytes.
>>
>>> From what I found out until now -- based on the old vm-- there may
>>> be some
>> optimizations in code by adding elements to the input language, for
>> example
>> it seems that getMember for array elements is expensive because all
>> arrays
>> are associative arrays (having string or numeric index). Laying out
>> "dim
>> chessboard(8,8) as integer" as flat 64 elements array instead of
>> instead of
>> "var chessboard:Array" would get rid of one call to getMember,
>> accessing
>> elements by chessboard[x+y*8] (or x+y<<3 after optimization)
>> instead of
>> twice calling getMember. If we really want want to implement the
>> minimax
>> algorythm a few nanoseconds on each array access will make some
>> difference
>> at the end.
>> Another idea is implementing a general assembly language, something
>> like
>> "var foo:Number" and later "push foo", "push myarray[foo]" and so on
>> approving names from the input language and expression evaluation in
>> assembly parts.
>>
>> Thomas
>>
>>
>>
>> ----- Original Message -----
>> From: "Mark Winterhalder" <[EMAIL PROTECTED]>
>> To: "Open Source Flash Mailing List" <[email protected]>
>> Sent: Sunday, September 09, 2007 5:23 AM
>> Subject: Re: [osflash] Anybody interest in developing a new compiler?
>>
>>
>>>> What I do not have
>>>>    _any_ expericence with flash ....    (and therefor lots of _silly
>>>> questions)
>>>
>>> Since you mentioned you don't know much about Flash yet:
>>>>> From your usage of flasm I take it that you're targeting the old
>>>>> VM,
>>> so just to make sure you know, there has been a new one introduced in
>>> Flashplayer 9. Adobe donated it to Mozilla, the Tamarin project [1].
>>>
>>> There's Adobe's AS3 compiler (which will be Open Source as part of
>>> the
>>> Flex 3 SDK [2]), haXe [3] of course, and it seems like we'll be
>>> getting IronRuby and IronPython soon, too [4].
>>> Opcodes are supported by hxASM [5] and Swfmill (on svn [6]).
>>>
>>> HTH,
>>> Mark
>>>
>>> [1] <http://en.wikipedia.org/wiki/Tamarin_(JIT)>
>>> [2] <http://labs.adobe.com/technologies/flex/sdk/>
>>> [3] <http://haxe.org/>
>>> [4]
>>> <http://weblogs.mozillazine.org/roadmap/archives/2007/07/
>>> new_projects.html>
>>> [5] <http://haxe.org/hxasm>
>>> [6] <http://swfmill.org/trac/browser/trunk/src/codegen/source.xml>
>>> (1483ff)
>>>
>>>
>>>
>>>
>>>
>>> On 9/8/07, Thomas Quester <[EMAIL PROTECTED]> wrote:
>>>>
>>>>
>>>> Hi list members,
>>>>
>>>> Is anybody interested in helping in developing a new compiler?.
>>>>
>>>> What I have:
>>>>   A compiler accepting something between Visual Basic and Action
>>>> Script
>>>> and
>>>> producing source code for FLASM with original code as comments.
>>>>   Some ideas for producing fast, short and probably nice obfuscated
>>>> assembler code.
>>>>
>>>> What I want:
>>>>   Easy to use language which produces either .swf or output for
>>>> swfmill
>>>> and
>>>> flasm accepting most VB and AS code and some elements of C like
>>>> inline
>>>> functions.
>>>>   Code optimizer at least for some silly optimizatoins
>>>>
>>>> What I do not have
>>>>    _any_ expericence with flash ....    (and therefor lots of _silly
>>>> questions)
>>>>
>>>> What I am looking for
>>>>
>>>>   persons answering silly questions, lots of small samples etc.
>>>>
>>>> Greetings
>>>>
>>>> Thomas Quester
>>>>
>>>> _______________________________________________
>>>> osflash mailing list
>>>> [email protected]
>>>> http://osflash.org/mailman/listinfo/osflash_osflash.org
>>>>
>>>>
>>>
>>> _______________________________________________
>>> osflash mailing list
>>> [email protected]
>>> http://osflash.org/mailman/listinfo/osflash_osflash.org
>>>
>>
>>
>> _______________________________________________
>> osflash mailing list
>> [email protected]
>> http://osflash.org/mailman/listinfo/osflash_osflash.org
>
>
> _______________________________________________
> osflash mailing list
> [email protected]
> http://osflash.org/mailman/listinfo/osflash_osflash.org
> 


_______________________________________________
osflash mailing list
[email protected]
http://osflash.org/mailman/listinfo/osflash_osflash.org

Reply via email to