immortalvm / ivm-implementations

iVM contemporary implementations
5 stars 0 forks source link

Initialization of uninitialized data #9

Closed elnv closed 4 years ago

elnv commented 4 years ago

This is a question that we discussed in the last London meeting about the data initialization and that is still open although it's not a high priority issue.

At the moment the compiler is initializing data by means of null element lists, for example, data8 [0 0 ... 0].

In the meeting it was commented the possibility of using the space directive to implement that, avoiding large list of zeros (a:space N a=(load8 a)).

Although this could be fine for named data, there are situations where the initialization has not any associated label. For example consider the partial initialization of a structure:

struct s {
    long a;
    long c[10];
} ss = { .a=2, .c[5]=3};

that currently will generate this piece of assembly:

ss:
    data8 [2]
    data8 [ 0 0 0 0 0 ]
    data8 [3]
    data8 [ 0 0 0 0 ]

In this case the space based solution cannot be used because the structure needs to be a contiguous block of memory positions, and also these zero sequences have no name.

The main problem lies in the initialization of large elements, as the resulting asm file could be huge and consequently will need a high processing time (both for the compiler when writing, and for the ivm tool when reading).

We suggest to have a kind of sugar for such large zero sequences in order to make the asm smaller in these cases. It could be something like skip n as equivalent to data1 [0 0 ...n-times) ... 0] (sequence of n null bytes).

Note that we are not requesting to remove the space directive, as it can be useful for other scenarios.

ivar-rummelhoff commented 4 years ago

I am skeptical to including e.g. large chunks of zeros in the VM binaries, but maybe we should worry about that later. The feature should be easy to add, e.g. as data8 [0] * 1000 if this does not confuse the parser.