C# to AS3 (maybe Haxe?)

Topics: Developer Forum
Dec 29, 2008 at 10:12 PM
I'm working on a C# to AS3 converter using this parser and so far things are going well. I would like to know if there is a way to hook a custom "toSource" method, as I'm currently doing in the hard way, ie, looping through every construction and parsing using a lot of IF...

Things are progressing slowly (as I can work on this only one or two hours a day) but I'm optimistic. In fact, I think that maybe I should move from AS3 and start working on an Haxe version. Haxe can later export to AS3, and since Haxe has support for generics (at least up to some point) and generates better bytecode, maybe it's a better idea.
Dec 29, 2008 at 10:30 PM
You'll notice that there is some stub code in the parser for implementing the Visitor pattern properly. However, those efforts are fairly nascent, and it is not even clear who is in charge of this development.
Dec 30, 2008 at 2:14 AM
That sounds pretty neat -- if you get stuck let me know, I did the generator for the Xamlon product which was IL>swf. Basically it came down to static constructors were tricky, but other than that everything went reasonably well. That was pre-generics though. Haxe might be a great target, it is closer to the flavor of C#, and indeed has great bytecode. There are multiple targets with it as well, so that is great.

Like nesteruk says, the Visitor pattern is the way to go there. Maybe I can be the one to bite the bullet and finish it, unless there are any takers : ). I recently finished a project and have a bit of time over the holidays here (if I can pry myself from the AVR world!).
Dec 30, 2008 at 8:23 AM
I might take a shot at this Visitor thing, but I remember having some source control problems. For some reason, CodePlex wouldn't let me check out some times, and would mess with me in other strange ways. What I do have, however, is a CodeBuilder class that I have used in many code generation scenarios - together with CSharpBuilder which builds code the C# way. One other thing I wouldn't mind, of course, is a VhdlBuilder. ))
Dec 30, 2008 at 5:28 PM
Directions on how to use the Visitor pattern? I suppose I should inherit the AbstractVisitor and start overriding, but how do I tell the parser to use that visitor class?
Dec 30, 2008 at 5:59 PM
Umm, that's one of the problems. At the moment, some elements in the tree hierarchy have the visitor method written in a haphazard fashion. It's far from being ready for actual code generation. In addition to this problem, you'll of course need to write about a hundred VisitXXX functions in your visitor.

What's really needed is an effort to create the traversal code correctly (I'm not sure it is, at the moment, but I haven't checked), then make sure that C# works, and only then does it make sense to start translating to other languages. Unless you want to traverse the parse tree yourself, which is certainly an option  - but in this case, you'll be writing a de factor Visitor yourself. It might actually be easy if you only need a subset of C# 2.0 and not the whole thing.
Apr 8, 2009 at 1:35 AM


I almost have a working version of the transliterator (AS3). Now, I'm facing some problems that I really don't know how to solve.

For example, when trying to implement the indexers, I have several ways to implement them:

1) Use the flash "Proxy" class:
* Pros: Easy to implement, works similar to c#
* Cons: Ultra-slow access, can not have multiple-indexers (for example, by int, by string), must extends Proxy class (if the class already extends another class, that's not possible)

2) Convert the indexers to __get[paramType](name):type and __set[paramType](name, value):void.
* Pros: Fast, supports multiple-indexers.
* Cons: Since I don't know the base type for the statement that called the indexer, I can not be sure if the indexer exists and what types of indexers I have.

I have the similar problems with overloaded methods. I can create unique methods, but then I don't know how to call them.

Ideas? Directions?