Releases: SomeRanDev/reflaxe
Version 3.0.0
September 26th, 2023
Release Notes
After 9 months of on and off development, seems like it's finally a good time to bump up the big version number.
There have been too many changes for me reasonably list here, so I will instead focus on the major additions between the release of version 2.0 and now.
Project Management Scripts
There is now a haxelib run script providing the ability to create, build, and test Reflaxe projects:
new
Generates a new Reflaxe project.
haxelib run reflaxe new <Language Name> <Language Abbreviation>
build
Combines all the source folders together into a haxelib-ready library directory.
It has an optional argument to configure the directory the built project will be placed.
haxelib run reflaxe build <Output Directory=[./_Build]>
test
Tests the Reflaxe project on a Haxe .hxml project.
The argument can be a custom .hxml file, but otherwise test/Test.hxml
will be used.
haxelib run reflaxe test <HXML File=[test/Test.hxml]>
Plugin System
Reflaxe projects may choose to inherit their "Compiler" class from PluginCompiler
instead of BaseCompiler
. This will allow users of their Reflaxe library to hook into certain points of the compilation process (like "on expression" or "on class") and return their own custom content.
Dynamic DCE
Added a "Dynamic Dead Code Elimination" option, allowing Reflaxe projects fine control over which classes are generated. First the main function is transpiled; the transpilation process may add classes to the Dynamic DCE queue. The queued classes are then transpiled and may add more classes to the queue. This procedure repeats until the queue is empty at the end of generation.
Compile Class New Argument Types
BaseCompiler.compileClassImpl
now passes two new classes as arguments: reflaxe.data.ClassVarData
and reflaxe.data.ClassFuncData
.
These classes not only contain all the previous variable and function data (and more!), but they also now provide helpful functions like ClassVarData.findDefaultExpr
and ClassFuncData.findAllArgumentVariations
.
Compile Enum New Argument Types
BaseCompiler.compileEnumImpl
now passes an array of reflaxe.data.EnumOptionData
for options. Same as above, this class contains all the same data as before AND helper functions to make transpiling that much easier.
Compile Expression topLevel
Argument
BaseCompiler.compileExpressionImpl
had a new argument added named topLevel: Bool
.
If this argument is true
, that means the expression being compiled is part of a TBlock
list and is NOT being used as a value. This can be used to optimize or modify an expression's output content based on whether it needs to generate a value or not.
Class Hierarchy Tracker
If the trackClassHierarchy
option is enabled, the child classes of a class can be found using the reflaxe.input.ClassHierarchyTracker
class.
Get Main Expression
BaseCompiler.getMainExpr(): Null<TypedExpr>
returns a typed expression that is a call to the main function of the Haxe program. If used in Haxe 4.2.0 or below, the main class must be defined using the -D mainClass
define.
Prefix Expression Injection
Added a function to BaseCompiler
named injectExpressionPrefixContent(content: String)
.
If called while compiling a topLevel
expression in compileExpressionImpl
, this will place content
directly before the compiled expression.
Add Compile-End Callback
BaseCompiler.addCompileEndCallback(callback: () -> Void)
executes code once compilation is complete. Can be used to delay compiling things until the final state of the compiler is known.
@:nativeTypeCode
Add support for @:nativeTypeCode
by compiling types using BaseCompiler.compileNativeTypeCodeMeta
.
@:nativeVariableCode
Add support for @:nativeVariableCode
by compiling variable expressions using BaseCompiler.compileNativeVariableCodeMeta
.
Mark Unused Variables
Local variables that are unused are marked with the @-reflaxe.unused
metadata.
Added tabCount
to SyntaxHelper.tab
A optional tab count argument can be provided to the SyntaxHelper.tab
function:
using SyntaxHelper;
function getCode() {
return someCode.tab(2); // appends two tabs to every new line in "someCode" string
}
Numerous Helper Functions
Tons and tons and tons of new functions were added to the classes in the reflaxe.helpers
package.
Bug Fixes
Tons of bugs were fixed. However, the top three major ones were:
- Fixed target code injection to use
{number}
instead of{}
. - Fixed repeat variable bugs
- Fixed EIESantizier bugs
Version 2.0.0
December 20th, 2022
Release Notes
This is a much more stable and usable version of Reflaxe. Created and tested while developing the first release of Haxe-to-GDScript.
@:nativeFunctionCode
Added support for @:nativeFunctionCode
to help inject function content for the target language. Similar to Haxe/C#'s @:functionCode
, but you can also use "{this}" and "{argX}" to inject the "this" expression OR an argument passed to the function respectively.
While you could use an "extern inline" function + injection function (ie __gdscript__
) to achieve a similar result, this method bypasses typing issues the Haxe compiler has when you make certain standard library methods "extern inline".
@:nativeFunctionCode("{this}[{arg0}]")
public function charAt(index: Int): String;
Extra File Methods
There are now functions to help generate additional source files outside of the ones generated automatically for each module/class/etc. Both these extra files and files generated in manual mode are now tracked and also automatically deleted using the deleteOldOutput
feature.
Files are also no longer modified if they already contain the desired output (helps prevent triggering file-watchers in engines/editors even if nothing has changed).
EIE Sanitizer Improvements
Made huge improvements to EverythingIsExpressionSanitizer
.
Now supports:
• Properly converting while/do-while conditions to execute within the loop.
• Wrapping variables in arrays when captured by lambdas.
• Assignment expressions that are expected to return a value.
• Converting prefix/postfix increment/decrement operators.
• Wrapping references to non-physical functions in a lambda, allowing for functions that are always inlined or use @:native
/ @:nativeFunctionCode
to be passed and called like objects.
More BaseCompiler Options
• reservedVarNames - List of variable names that are reserved on the target. Reflaxe will rename any Haxe variables that share the same names.
• unwrapTypedefs - Unwraps typedefs automatically, helpful for ensuring static-calls (i.e. Class<haxe.Log>
) are accounted for in smartDCE.
• wrapLambdaCaptureVarsInArray - Enables/disables wrapping lambda-captured variables in Array.
• preventRepeatVars - If the target is picky about variable shadowing, this ensures all variable names are unique with each method.
• convertUnopIncrement - Converts uses of the ++
/--
operators to += 1
/-= 1
for targets that don't support those unary operators.
BaseCompiler Events
Added more methods to override on BaseCompiler: onCompileStart
, onCompileEnd
, and onOutputComplete
.
Repeat Variable Fixer
Added check/fixer to ensure there are no repeat variable names, even in sub-scopes. (GDScript very picky and doesn't even allow local variable shadowing). Can be enabled/disabled with preventRepeatVars
option.
Redundant Var Decl. Remover
Added optimization feature to move variable declarations to a subsequent assignment if unused in-between and on same scope level. Helps clean up code after "Everything Is Expression" sanitizer.
@:native Constructor Support
Added support for @:native
on constructors. Replaces the entire "new Class" part with a function name, similar to how Haxe/C++ works. @:nativeFunctionCode
also works for injecting exact target code.
ExpressionModifier/ClassModifier
Added the ExpressionModifier
and ClassModifier
helper classes for easily modifying certain class methods or expression patterns pre-typing using @:build
macros.
Bug Fixes
Various improvements and bug fixes to things like ModuleUsageTracker
and ExprOptimizer
. In general, recursive expression seeking is much more powerful and consistent now.