Looks like it nearly works except the code generation part