4.4.3 Generators
We had made three different implementations of a Java state
machine whilst making the original watch, with ideas sketched out for another
two. The implementation we went with required the reflection abilities of Java,
which unfortunately are not present in MIDP. Hence we moved to a switch case
based implementation, using initialized static final variables as labels.
This required an addition to the _Variables generator to
generate the new static final variable for each Action and DisplayFn. Similarly,
a minor change was made to the _TransitionData generator to generate the
variable names rather than a string containing the same text.
The _Actions and _DisplayFn generators were similarly
changed to place their body inside a case statement, rather than a similarly
named function.
These changes were all largely cosmetic, and only the
generation of the initialization values for the static final variables required
a little ingenuity, as Java limits these to being integer expressions which do
not refer to any other variable – not even another static final. The
addition of variables to the generator definition language has since made other,
easier, approaches possible.
A larger amount of work was required for the new
‘_create make for MIDP’ generator. MIDP compiles its Java as for
other platforms, but it also requires a pre-verify step, and a couple of
configuration files naming and providing information about the MIDP suite (Watch
family) and the MIDP applications (Watch models) it contains. Normally these
configuration files would be written by hand, or filled in to a form, but in
principle all the information needed can be obtained from the code (or in this
case, the models).
The overly-tight constraints on these configuration
files’ formats made generating them with only the MetaEdit+ 3.0 reporting
language and DOS batch commands something of a challenge (more recent MetaEdit+
versions make this easy). Having to support several Windows versions, each with
different DOS commands and behavior, hardly made the task any easier. In the end
it was accomplished with a couple of helper batch files, which generate
sequential numbers and report the size of a specified
file.