After a long stretch of 'just coding', it is getting back to making decisions again. I'm trying to spec out the next steps, wondering about the best paths. Ultimately it comes down to, if you could make swfs in C#, what would your 'dream code' look like? How would it interact with library items and timelines? What should the bytecode look like - optimized for speed/size/legibility? Any and all opinions welcome : ).
Plans on Transforming AS/SWF > C#?
I have some swf parsing stuff, I'm not sure how well that will integrate though. A lot of the metadata simply gets discarded when going to swf (interfaces, types, params etc), even when writing C#>swf. I've looked into getting swf7 code to reverse (to C#), it seems somewhat do-able, except there will be a lot of 'object' types and inserted casting if people didn't declare types. I'm not sure if it would be more valuable to reverse right to C#, or plan B...
Plan B
I would like to get a mode where you could insert bytecode and add C# stubs based on a flash file though. If someone has an actionscript class that works, why not use it, eh? Also I'm finding the need to do a lot of stuff manually by adding pushes/actions manually in the support code, but it is a total pain. An automated way to do this is crucial, however it isn't as simple as just adding bytecode as it probably has to integrate with the constant pool etc (that is for code that C# doesn't need to see, things like the extends class, or native swf calls)
How to attachMovieClip, access _width etc.
I'm really debating how to access the flash stuff as well. One idea is just to have an Swf.Native namespace that always compiles to actually internal flash methods. Ideally though it would work more like being able to get a 'DrawingCanvas' or 'AnimationReel', each with it's own properties, even though they both resolve to Movieclip on compile. I guess that still requires a Native call somewhere, but ideally they would be hidden unless making a wrapper class, and even then only used once, somewhere isolated.
Optimized Mode
C# maps everything except virtual dispatch at compile time, so you can really optimize things, where that might be harder in actionscript. I've been doing some tests, and I'm thinking of using arrays everywhere, and then registers for locals. Right now, from the parse, all definitions (namespaces, classes, fields, locals etc) are indexed. Already for overloads it writes out the name and the index, like Meth_22 (actually the top level matching overload index, so virtual dispatch works). So what I was thinking is putting all the methods/fields/props etc in the prototype in array slots. Eg:
cls = function(){}
cls.prototype[0] = "hello";
cls.prototype[1] = function(){ trace(this[0]); }
c1 = new cls();
c1[1]();
Obviously the types (classes, enums, delegates) could all be array indexes of an object stored in a permanent register, as would static methods, constructors, and internal functions like 'extends' (basically anything statically referenced).. Given a low number of static definitions, some of them could even be mapped to permanent registers.
This should be really easy to do, just reordering the indexes and push a number instead of a constant pool. I assume AS has better performance when indexes are sequential, instead of the first one starting at 276, haven't tested though. Then locals could be put in registers (though that will require some work) and everything should be pretty fast (again, haven't tested). It should also be quite a bit smaller, as there is basically no constant pool, and path lookups with always be simply a register/this push, and index, and a get member (instead of the much longer path.path.path lookups). Change a few things and it becomes painfully obfuscated too -- eg: r1:[231][64](this[3]()) becomes even harder to decipher when those numbers are the result of looked up calculations, and then there is still that evil 'eval' ; ).
Todo
Anyway, first the bug free mode. Hopefully by Monday there will be a new version. Right now inheritance/base/this (chaining), virtual dispatch is there, 'using' is almost there as are multiple files/namespaces. Todo before then, events, distinguish between int/long double/float, out/ref params, indexers, and deal with structs. (end of week)
After that, try/catch, attributes, some type reflection (for typeof, as, is), and experiment with optimized mode. Also work on native calls into swf in a type safe way, and a simple demo framework. (one month)
After that, import graphics, sound etc (eg, the Flash 'library' part). (Maybe maybe end of summer, depending on work)
posted on Thursday, July 15, 2004 4:35 PM