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

ecs: changed constant array declaraiton

This commit is contained in:
Steven Hugg 2022-02-10 15:33:27 -06:00
parent bea49e2b11
commit acb50ac4b9
2 changed files with 53 additions and 47 deletions

View File

@ -566,7 +566,7 @@ class ActionEval {
} }
} else if (this.action.select == 'with') { } else if (this.action.select == 'with') {
if (this.qr.entities.length != 1) if (this.qr.entities.length != 1)
throw new ECSError(`query outside of loop must match exactly one entity`, this.action); throw new ECSError(`${this.sys.name} query outside of loop must match exactly one entity`, this.action); //TODO
} }
break; break;
} }
@ -946,6 +946,7 @@ export class EntityScope implements SourceLocated {
// TODO: fields.sort((a, b) => (a.ehi - a.elo + 1) * getPackedFieldSize(a.field)); // TODO: fields.sort((a, b) => (a.ehi - a.elo + 1) * getPackedFieldSize(a.field));
for (let f of fields) { for (let f of fields) {
if (this.fieldtypes[mksymbol(f.component, f.field.name)] == type) { if (this.fieldtypes[mksymbol(f.component, f.field.name)] == type) {
//console.log(f.component.name, f.field.name, type);
let rangelen = (f.ehi - f.elo + 1); let rangelen = (f.ehi - f.elo + 1);
// TODO: doesn't work for packed arrays too well // TODO: doesn't work for packed arrays too well
let bits = getPackedFieldSize(f.field); let bits = getPackedFieldSize(f.field);
@ -971,27 +972,14 @@ export class EntityScope implements SourceLocated {
for (var o = iter.next(); o.value; o = iter.next()) { for (var o = iter.next(); o.value; o = iter.next()) {
let { i, e, c, f, v } = o.value; let { i, e, c, f, v } = o.value;
let cfname = mksymbol(c, f.name); let cfname = mksymbol(c, f.name);
let range = segment.fieldranges[cfname]; // TODO: what if mix of var, const, and init values?
let entcount = range ? range.ehi - range.elo + 1 : 0; if (this.fieldtypes[cfname] == 'const') {
// is this a constant value? let range = segment.fieldranges[cfname];
if (v === undefined) { let entcount = range ? range.ehi - range.elo + 1 : 0;
// this is not a constant if (v == null && f.dtype == 'int') v = 0;
// is it a bounded array? (TODO) if (v == null && f.dtype == 'ref') v = 0;
if (f.dtype == 'array' && f.index) { if (v == null && f.dtype == 'array') throw new ECSError(`no default value for array ${cfname}`)
let datasym = this.dialect.datasymbol(c, f, e.id, 0); //console.log(c.name, f.name, '#'+e.id, '=', v);
let databytes = getFieldLength(f.index);
let offset = this.bss.allocateBytes(datasym, databytes);
// TODO? this.allocatePointerArray(c, f, datasym, entcount);
let ptrlosym = this.dialect.fieldsymbol(c, f, 0);
let ptrhisym = this.dialect.fieldsymbol(c, f, 8);
// TODO: what if we don't need a pointer array?
let loofs = segment.allocateBytes(ptrlosym, entcount);
let hiofs = segment.allocateBytes(ptrhisym, entcount);
if (f.baseoffset) datasym = `(${datasym}+${f.baseoffset})`;
segment.initdata[loofs + e.id - range.elo] = { symbol: datasym, bitofs: 0 };
segment.initdata[hiofs + e.id - range.elo] = { symbol: datasym, bitofs: 8 };
}
} else {
// this is a constant // this is a constant
// is it a byte array? // is it a byte array?
//TODO? if (ArrayBuffer.isView(v) && f.dtype == 'array') { //TODO? if (ArrayBuffer.isView(v) && f.dtype == 'array') {
@ -1007,7 +995,8 @@ export class EntityScope implements SourceLocated {
segment.initdata[hiofs + e.id - range.elo] = { symbol: datasym, bitofs: 8 }; segment.initdata[hiofs + e.id - range.elo] = { symbol: datasym, bitofs: 8 };
} else if (typeof v === 'number') { } else if (typeof v === 'number') {
// more than 1 entity, add an array // more than 1 entity, add an array
if (entcount > 1) { // TODO: infer need for array by usage
/*if (entcount > 1)*/ {
if (!range.access) throw new ECSError(`no access for field ${cfname}`) if (!range.access) throw new ECSError(`no access for field ${cfname}`)
for (let a of range.access) { for (let a of range.access) {
segment.allocateBytes(a.symbol, entcount); segment.allocateBytes(a.symbol, entcount);
@ -1015,7 +1004,20 @@ export class EntityScope implements SourceLocated {
segment.initdata[ofs] = (v >> a.bit) & 0xff; segment.initdata[ofs] = (v >> a.bit) & 0xff;
} }
} }
// TODO: what if mix of var, const, and init values? } else if (v == null && f.dtype == 'array' && f.index) {
// TODO
let datasym = this.dialect.datasymbol(c, f, e.id, 0);
let databytes = getFieldLength(f.index);
let offset = this.bss.allocateBytes(datasym, databytes);
// TODO? this.allocatePointerArray(c, f, datasym, entcount);
let ptrlosym = this.dialect.fieldsymbol(c, f, 0);
let ptrhisym = this.dialect.fieldsymbol(c, f, 8);
// TODO: what if we don't need a pointer array?
let loofs = segment.allocateBytes(ptrlosym, entcount);
let hiofs = segment.allocateBytes(ptrhisym, entcount);
if (f.baseoffset) datasym = `(${datasym}+${f.baseoffset})`;
segment.initdata[loofs + e.id - range.elo] = { symbol: datasym, bitofs: 0 };
segment.initdata[hiofs + e.id - range.elo] = { symbol: datasym, bitofs: 8 };
} else { } else {
// TODO: bad error message - should say "wrong type, should be array" // TODO: bad error message - should say "wrong type, should be array"
throw new ECSError(`unhandled constant ${e.id}:${cfname} -- ${typeof v}`); throw new ECSError(`unhandled constant ${e.id}:${cfname} -- ${typeof v}`);
@ -1172,8 +1174,8 @@ export class EntityScope implements SourceLocated {
} }
private analyzeEntities() { private analyzeEntities() {
this.buildSegments(); this.buildSegments();
this.allocateSegment(this.bss, true, undefined); // uninitialized vars
this.allocateSegment(this.bss, true, 'init'); // initialized vars this.allocateSegment(this.bss, true, 'init'); // initialized vars
this.allocateSegment(this.bss, true, undefined); // uninitialized vars
this.allocateSegment(this.rodata, false, 'const'); // constants this.allocateSegment(this.rodata, false, 'const'); // constants
this.allocateROData(this.rodata); this.allocateROData(this.rodata);
} }

View File

@ -1,11 +1,6 @@
.scope Main .scope Main
.zeropage .zeropage
SpriteSlot_sprite_b0: HasBitmap_bitmap_b0:
.res 1
.res 1
.res 1
.res 1
HasYpos_ypos_b0:
.res 1 .res 1
.res 1 .res 1
.res 1 .res 1
@ -15,16 +10,21 @@ HasXpos_xpos_b0:
.res 1 .res 1
.res 1 .res 1
.res 1 .res 1
HasYpos_ypos_b0:
.res 1
.res 1
.res 1
.res 1
SpriteSlot_sprite_b0:
.res 1
.res 1
.res 1
.res 1
HasColormap_colormap_b0: HasColormap_colormap_b0:
.res 1 .res 1
.res 1 .res 1
.res 1 .res 1
.res 1 .res 1
HasBitmap_bitmap_b0:
.res 1
.res 1
.res 1
.res 1
TEMP: TEMP:
.res 1 .res 1
.res 1 .res 1
@ -44,6 +44,10 @@ Joystick__tmp = TEMP+0
SpriteShuffler__tmp = TEMP+1 SpriteShuffler__tmp = TEMP+1
SpriteHider__tmp = TEMP+3 SpriteHider__tmp = TEMP+3
.code .code
KernelSection_lines_b0:
.byte 192
BGColor_bgcolor_b0:
.byte 162
Bitmap_bitmapdata_e1_b0: Bitmap_bitmapdata_e1_b0:
.byte 1 .byte 1
.byte 1 .byte 1
@ -90,25 +94,25 @@ Sprite_plyrflags_b0:
.byte 0 .byte 0
.byte 0 .byte 0
Main__INITDATA: Main__INITDATA:
.byte 1
.byte 0 .byte 0
.byte 1 .byte 1
.byte 2 .byte 0
.byte 3
.byte 150
.byte 60
.byte 90
.byte 150
.byte 50 .byte 50
.byte 100 .byte 100
.byte 80 .byte 80
.byte 40 .byte 40
.byte 0 .byte 150
.byte 0 .byte 60
.byte 0 .byte 90
.byte 150
.byte 0 .byte 0
.byte 1 .byte 1
.byte 2
.byte 3
.byte 0
.byte 0
.byte 0 .byte 0
.byte 1
.byte 0 .byte 0
__Start: __Start:
.code .code
@ -125,7 +129,7 @@ __BRK:
ldy #20 ldy #20
: lda Main__INITDATA-1,y : lda Main__INITDATA-1,y
sta SpriteSlot_sprite_b0-1,y sta HasBitmap_bitmap_b0-1,y
dey dey
bne :- bne :-
; initialize data segment ; initialize data segment