1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-05-28 23:41:32 +00:00

ecs: var/init/const allocation

This commit is contained in:
Steven Hugg 2022-02-10 12:55:36 -06:00
parent fc0a43b9af
commit bea49e2b11

View File

@ -941,13 +941,12 @@ export class EntityScope implements SourceLocated {
}
}
// TODO: cull unused entity fields
allocateSegment(segment: DataSegment, readonly: boolean) {
allocateSegment(segment: DataSegment, alloc: boolean, type: 'init' | 'const' | undefined) {
let fields: FieldArray[] = Object.values(segment.fieldranges);
// TODO: fields.sort((a, b) => (a.ehi - a.elo + 1) * getPackedFieldSize(a.field));
let f: FieldArray | undefined;
while (f = fields.pop()) {
for (let f of fields) {
if (this.fieldtypes[mksymbol(f.component, f.field.name)] == type) {
let rangelen = (f.ehi - f.elo + 1);
let alloc = !readonly;
// TODO: doesn't work for packed arrays too well
let bits = getPackedFieldSize(f.field);
// variable size? make it a pointer
@ -966,6 +965,7 @@ export class EntityScope implements SourceLocated {
f.access = access;
}
}
}
allocateROData(segment: DataSegment) {
let iter = this.iterateEntityFields(this.entities);
for (var o = iter.next(); o.value; o = iter.next()) {
@ -1034,8 +1034,8 @@ export class EntityScope implements SourceLocated {
let initvalue = e.inits[scfname];
if (initvalue !== undefined) {
let range = segment.getFieldRange(c, f.name);
if (!range) throw new ECSError(`no range`, e);
if (!range.access) throw new ECSError(`no range access`, e);
if (!range) throw new ECSError(`no init range for ${scfname}`, e);
if (!range.access) throw new ECSError(`no init range access for ${scfname}`, e);
if (typeof initvalue === 'number') {
for (let a of range.access) {
let offset = segment.getByteOffset(range, a, e.id);
@ -1172,8 +1172,9 @@ export class EntityScope implements SourceLocated {
}
private analyzeEntities() {
this.buildSegments();
this.allocateSegment(this.bss, false);
this.allocateSegment(this.rodata, true);
this.allocateSegment(this.bss, true, undefined); // uninitialized vars
this.allocateSegment(this.bss, true, 'init'); // initialized vars
this.allocateSegment(this.rodata, false, 'const'); // constants
this.allocateROData(this.rodata);
}
private generateCode() {