ax4
ax4 is an ActionScript 3 to Haxe converter that tries to be very smart and precise about rewriting code. To achieve that, it actually resembles the typical compiler a lot, so here's how it works:
- parse AS3 modules into the ParseTree structure, containing all the syntactic information
- load classes and signatures from the SWC libraries so we have the external type information
- process ParseTree and build the TypedTree, resolving all imports and type references and assigning type to every piece of code
- run a sequence of "filters" which analyze and re-write the TypedTree structures to adapt the code for Haxe
- generate Haxe modules from the processed TypedTree
Disclaimer
ax4 is a fork of ax3, created by Dan Korostelev (nadako) at InnoGames, by way of another fork. I developed ax4 to make a fan-made native port of Dungeon Rampage (see Dungeon Rampage Haxe).
I may or may not continue to maintain ax4, and port other games in the future.
Quick start
1) Install
With a Java runtime and haxelib:
haxelib install ax4
To build it from source instead, see Quickstart.
2) Create a minimal config.json
{
"src": "path/to/as3/src",
"hxout": "path/to/haxe/out",
"swc": [
"path/to/playerglobal.swc"
]
}
3) Run conversion
haxelib run ax4 config.json
Documentation
- Home
- Quickstart
- Config reference
- Config examples
- Differences from ax3
- Filters overview
- Diagnostics catalogue
- Troubleshooting
- Contributing
- GitHub wiki setup and sync
Compat runtime
compat/contains AS3 compatibility/runtime helpers used by generated Haxe code (ASAny,ASDictionary, XML helpers, etc.).- Converted code depends on this layer: with the haxelib install, add
-lib ax4to your Haxe build; otherwise copycompat/with thecopyoption (see Quickstart). compat-test/contains tests for the compatibility layer itself and is not meant to be shipped with production output.- If you modify
compat/, updatecompat-test/and run:
npx haxe test-compat.hxml
Conversion Pipeline
The pipeline is implemented in src/ax4/Main.hx:
- Parse AS3 into
ParseTree - Load SWC externs/signatures
- Type into
TypedTree - Run rewrite filters
- Generate Haxe modules
Known limitations
- The parser doesn't currently support ASI (automatic semicolon insertion). The only case where a semicolon can be omitted is the last expression of a block.
- Only a small, most commonly used subset of E4X is supported. It's recommended to rewrite the unsupported things in AS3 sources to adapt it for conversion.
- XML literals (
<a>...</a>) are not supported:skipXmlLiteralscomments them out asnull. - Some forms stop the conversion, such as a
caseafterdefaultor asplitwith a limit.