Alchemy works by translating C/C++ code to ActionScript through a LLVM compiler which instead of producing machine or bytecode produces ActionScript. The translated C/C++ code uses a big ActionScript ByteArray as the C/C++ heap and stack. The performance of alchemy is slow if you martial data from C/C++ code to ActionScript or back but faster (supposedly up to 10 times faster) than ActionScript code you write yourself for data intensive actions where everything operates in the C/C++ memory space - speed improvements over AS code are also due to LLVM doing code optimization which is missing from the normal AS compiler.
After downloading and setting up Alchemy, I started trying to port over a few C/C++ libraries. The following libraries have given me some trouble mainly with needing to adjust makefiles or the ./configure script: Angband, Nethack, guile, Python, Ruby, ARToolkitPlus, SDL, and Squeak. I haven't given up on them but I wasn't in the mood to do battle with Makefiles; I wanted to learn Alchemy.
My success came with compiling the scripting language Lua 5.1.4 and embedding it into a Flex application. The following proof of concept can run a Lua script which returns one or more values and are shown in the Lua Stack Panel. Lua can make the following calls into Flex:
- getTextAreaProperty(property_name) - Returns the given property of the text area in the lower left hand corner.
- setTextAreaProperty(property_name, value) - Sets the given property on the text area in the lower left hand corner (must accept string values).
- callTextAreaFunction(function_name[, param1, ..., paramN]) - Calls a function on the text area in the lower left hand corner (must accept string values).
- average(value1, ..., valueN) - Returns the average and sum of the given values.
Note that the demo above requires Flash Player 10 (required by Alchemy and my use of the local file system to allow opening/saving files). It is also hosted here.
Should I continue working on this library, I'd want to allow Lua to create and call functions on any arbitrary ActionScript class. Alchemy is still in beta and does have its own problems - not everything builds easily and while pure Alchemy code can be faster than ActionScript, marshaling from ActionScript to C/C++ code and back can slow things down - for example life.lua takes 4 seconds with the standard compile of Lua and 13 minutes! with the Alchemy build. Still it works quite well for my purposes of embedding a runtime scripting language into my Flex applications.
For more information check out the following blog posts: