[Laszlo-dev] compiler question

P T Withington ptw at pobox.com
Thu Dec 1 18:26:11 PST 2005


The semantics of Javascript require that all variables declared in a  
function have the scope of the entire function.  The compiler  
implements this by allocating a register for every variable  
declaration in a function on function entry.  So, you can put your  
`var`s wherever you like, the compiler has to emit the same code.

[I don't know how the Flash VM implements its registers, but my  
educated guess is that VM registers are just slots in a stack so  
there is no overhead to saving/restoring registers other than  
adjusting the stack pointer.]

On 1 Dec 2005, at 20:59, Adam Wolff wrote:

> If I have this:
>
> function func1(){
>     var a, b;
>     a=1;
>     func2();
>     b=2;
>     return a+b;
> }
>
> Question for the compiler folks: I assume that a and b are register
> variables. Is the compiler smart enough to know that I haven't  
> assigned a
> value to b before the call to func2, so that its value does not  
> need to be
> preserved on the stack when the call is made? If not, if I moved  
> the var b
> declaration below the function call, would that help?
>
> A
> _______________________________________________
> Laszlo-dev mailing list
> Laszlo-dev at openlaszlo.org
> http://www.openlaszlo.org/mailman/listinfo/laszlo-dev



More information about the Laszlo-dev mailing list