I have been using the MTASC compiler for about a month
now for some work on Flash Lite and it has been working
wonderfully. That is until I tried to call FSCommand2
from a constructor.
The call was properly made, but when the constructor
returned the instance was undefined. Due to the fact that
I really need to be able to call FSCommand2 from
constructors, I did a bit of digging in the Flash Lite source
code. After a ton of poking around I was able to determine
that the problem was caused by some sort of stack usage
anomaly.
After successfully running the same code compiled with
CS3, it appears that there is a bug in MTASC. I have never
written (or read for that matter) OCaml, but I was able to
hack together a solution based on the EArrayDecl code.
Basically I figured that because FSCommand2 pops all the
args plus a count off the stack, the compiler needs to be
aware of this to properly configure the stack. Luckily for me,
the Array code appears to do just that.
I have no idea if my solution is the proper one, but it does
work. I have included a diff which shows my changes in
genSwf.ml below. Please let me know if this is the correct
solution or if this is going to come back to haunt me. Also,
just for my own knowledge what's the difference in the
stack and stack_size attributes of the ctx?
Thanks,
Jens
-=-= SNIP =-=-
diff -u -r1.94 genSwf.ml
--- ocaml/mtasc/genSwf.ml 6 May 2007 09:20:11 -0000 1.94
+++ ocaml/mtasc/genSwf.ml 28 Apr 2008 23:22:31 -0000
@@ -697,7 +697,8 @@
let nargs = List.length l in
push ctx [VInt nargs];
write ctx AFSCommand2;
- ctx.stack <- ctx.stack - (nargs - 1)
+ (* ctx.stack <- ctx.stack - (nargs - 1) *)
+ ctx.stack_size <- ctx.stack_size - nargs
| EConst (Ident "fscommand") , [v] ->
push ctx [VStr "FSCommand:"];
generate_val ctx v;
--
MTASC : no more coffee break while compiling