-
Notifications
You must be signed in to change notification settings - Fork 2
genc transformations
Simon Krajewski edited this page Feb 18, 2014
·
3 revisions
- Turn
Method MethDynamic
toVar
and add default implementation as static field. Also add assignment to the constructor (for instance dynamic functions) or tocl_init
(for static ones). - Turn instance methods to static methods, add
this
argument to function and replaceTConst (TThis | TSuper)
accordingly. (expr mapping) - Detect all
TFun
variable fields and change their type toc.Closure<FieldType>
. - Infer type of all non-nullable optional basic type (Int, Float, Bool) to
Null<T>
.
- Determine VTable information and store them in static VTable field.
- Add instance VTable field to class.
Split constructor in three parts:
- A
hx_alloc
method allocating memory, assigning the instance VTable field and returning a pointer to it (called byType.createEmptyInstance
). - A
hx_initInstance
method containing the original user code (called throughsuper()
from a child class). - The normal
new
method callinghx_alloc
,hx_initInstance
and returning a pointer tothis
.
- Replace
TFor
withTWhile
. - Replace
TTry
with switch oversetjmp
. - Replace
TThrow
with call tolongjmp
. - Replace
TArrayDecl
with initialization call. - Replace
TSwitch
over string with something that compiles.
After running this reduction, we should not add any of the replaced nodes.
- Determine functions for which we can generate
_known
variants: These are functions with optional arguments where each optional argument has a default value. - Handle default values in original function with
if (arg == null) arg = defaultValue
, then make it call the_known
variant.
Find calls to fields that had a _known
variant found in previous pass. If we can be sure that all arguments are either == null
or != null
, make a call to the _known
variant instead, replacing definite null
values with the default values at call-site.
- Wrap any string literal (but guard against recursion).
- Replace
string == string
andstring != string
with a call toString.equals
. - Replace
string + string
andstring += string
with a call to `String.concat.
TODO
Find all variables that are not declared at the beginning of a block, move declaration to beginning of block and replace with assignment if exists.
This should probably be the last filter to run.
- Detect assignment of basic types to
Null<T>
and (un)wrap accordingly. - Detect assignment of non-dynamic types to Dynamic and (un)wrap accordingly.
- Detect assignment of wrapped string literal to
const char*
orvararg
and remove wrapping. - Detect assignment of wrapped string to
const char*
andvararg
and unwrap. - Detect assignment of smaller structure to larger one (optional fields) and pad with
null
.
- Detect local
TFunction
andTField(_,FClosure)
nodes, add closure field and replace with call to constructor of wrap-object. - Detect non-call
TField(_,FStatic)
nodes and replace with call to constructor of wrap-object.