[Toybox] Bc Math Library

Gavin Howard gavin.d.howard at gmail.com
Fri Feb 16 11:32:14 PST 2018


Hello,

The bc is coming along nicely. I am at the point where I may be ready
to support the POSIX-required "-l" option
(http://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html#tag_20_09_04).
That option requires a bunch of code written in bc itself to be
included with the program.

The code will be in its own file in the bc repo. However, it needs to
be converted into C source in some way because as Rob requested, the
library can only be contained as read-only data in the executable
itself to make sure there is no outside dependency.

As it stands, I see two ways to do this:

1) Convert the text in the file into a proper C string and put that
into a C source file as a constant string. Then when users request the
"-l" option, the program parses that string into bc code. This option
requires very little change to the bc itself; the only change will be
to the build system in the bc repo (not the toybox repo), so toybox
will be unaffected besides having a large amount of read-only data
added to the executable.

2) Add a build step in the bc repo (not the toybox repo) that parses
the file into a C source file, but instead of a constant string, the
code will be constant data structures (structs, arrays, etc.) that can
then be loaded into the runtime data on user request. This option
would be mean less read-only data is put into the toybox executable.
However, this adds extra complication, to both the build step and
toybox. There will be code written in bc specifically to load those
data structures, and that code will end up in toybox.

The advantage of (1) is simplicity. The possible (I haven't run any
real tests) advantages of (2) are smaller executable and faster
startup. For a smaller executable, a preliminary attempt showed a
possible reduction from 7 kb to around 5.5 kb.

Here is my question: is the reduction in executable size and
(possible) faster startup time worth the complexity of the second
option?

Gavin Howard



More information about the Toybox mailing list