mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-01-13 06:29:57 +00:00
ecs: codesegment vs data
This commit is contained in:
parent
0803b80485
commit
10784585d9
@ -35,7 +35,9 @@ should references be zero-indexed to a field, or global?
|
|||||||
should we limit # of entities passed to systems? min-max
|
should we limit # of entities passed to systems? min-max
|
||||||
join thru a reference? load both x and y
|
join thru a reference? load both x and y
|
||||||
|
|
||||||
|
code fragments can be parameterized like macros
|
||||||
|
if two fragments are identical, do a JSR
|
||||||
|
(do we have to look for labels?)
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -233,11 +235,11 @@ export class SourceFileExport {
|
|||||||
comment(text: string) {
|
comment(text: string) {
|
||||||
this.lines.push(';' + text);
|
this.lines.push(';' + text);
|
||||||
}
|
}
|
||||||
segment(seg: string, segtype: 'rodata' | 'bss') {
|
segment(seg: string, segtype: 'rodata' | 'bss' | 'code') {
|
||||||
if (segtype == 'bss') {
|
if (segtype == 'bss') {
|
||||||
this.lines.push(`.zeropage`); // TODO
|
this.lines.push(`.zeropage`); // TODO
|
||||||
} else {
|
} else {
|
||||||
this.lines.push(`.code`); // TODO
|
this.lines.push(`.code`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
label(sym: string) {
|
label(sym: string) {
|
||||||
@ -270,17 +272,26 @@ export class SourceFileExport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Segment {
|
class CodeSegment {
|
||||||
symbols: { [sym: string]: number } = {};
|
|
||||||
ofs2sym = new Map<number, string[]>();
|
|
||||||
fieldranges: { [cfname: string]: FieldArray } = {};
|
|
||||||
size: number = 0;
|
|
||||||
initdata: (number | ConstByte | undefined)[] = [];
|
|
||||||
codefrags: string[] = [];
|
codefrags: string[] = [];
|
||||||
|
|
||||||
addCodeFragment(code: string) {
|
addCodeFragment(code: string) {
|
||||||
this.codefrags.push(code);
|
this.codefrags.push(code);
|
||||||
}
|
}
|
||||||
|
dump(file: SourceFileExport) {
|
||||||
|
for (let code of this.codefrags) {
|
||||||
|
file.text(code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DataSegment {
|
||||||
|
symbols: { [sym: string]: number } = {};
|
||||||
|
ofs2sym = new Map<number, string[]>();
|
||||||
|
fieldranges: { [cfname: string]: FieldArray } = {};
|
||||||
|
size: number = 0;
|
||||||
|
initdata: (number | ConstByte | undefined)[] = [];
|
||||||
|
|
||||||
allocateBytes(name: string, bytes: number) {
|
allocateBytes(name: string, bytes: number) {
|
||||||
let ofs = this.symbols[name];
|
let ofs = this.symbols[name];
|
||||||
if (ofs == null) {
|
if (ofs == null) {
|
||||||
@ -301,9 +312,6 @@ class Segment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dump(file: SourceFileExport) {
|
dump(file: SourceFileExport) {
|
||||||
for (let code of this.codefrags) {
|
|
||||||
file.text(code);
|
|
||||||
}
|
|
||||||
for (let i = 0; i < this.size; i++) {
|
for (let i = 0; i < this.size; i++) {
|
||||||
let syms = this.ofs2sym.get(i);
|
let syms = this.ofs2sym.get(i);
|
||||||
if (syms) {
|
if (syms) {
|
||||||
@ -376,9 +384,9 @@ export class EntityScope implements SourceLocated {
|
|||||||
$loc: SourceLocation;
|
$loc: SourceLocation;
|
||||||
childScopes: EntityScope[] = [];
|
childScopes: EntityScope[] = [];
|
||||||
entities: Entity[] = [];
|
entities: Entity[] = [];
|
||||||
bss = new Segment();
|
bss = new DataSegment();
|
||||||
rodata = new Segment();
|
rodata = new DataSegment();
|
||||||
code = new Segment();
|
code = new CodeSegment();
|
||||||
componentsInScope = new Set();
|
componentsInScope = new Set();
|
||||||
tempOffset = 0;
|
tempOffset = 0;
|
||||||
tempSize = 0;
|
tempSize = 0;
|
||||||
@ -481,7 +489,7 @@ export class EntityScope implements SourceLocated {
|
|||||||
//console.log(i,array,cfname);
|
//console.log(i,array,cfname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
allocateSegment(segment: Segment, readonly: boolean) {
|
allocateSegment(segment: DataSegment, readonly: boolean) {
|
||||||
let fields : FieldArray[] = Object.values(segment.fieldranges);
|
let fields : FieldArray[] = Object.values(segment.fieldranges);
|
||||||
// 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));
|
||||||
let f : FieldArray | undefined;
|
let f : FieldArray | undefined;
|
||||||
@ -506,7 +514,7 @@ export class EntityScope implements SourceLocated {
|
|||||||
f.access = access;
|
f.access = access;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
allocateROData(segment: Segment) {
|
allocateROData(segment: DataSegment) {
|
||||||
let iter = this.iterateEntityFields(this.entities);
|
let iter = this.iterateEntityFields(this.entities);
|
||||||
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;
|
||||||
@ -558,7 +566,7 @@ export class EntityScope implements SourceLocated {
|
|||||||
}
|
}
|
||||||
//console.log(segment.initdata)
|
//console.log(segment.initdata)
|
||||||
}
|
}
|
||||||
allocateInitData(segment: Segment) {
|
allocateInitData(segment: DataSegment) {
|
||||||
if (segment.size == 0) return ''; // TODO: warning for no init data?
|
if (segment.size == 0) return ''; // TODO: warning for no init data?
|
||||||
let initbytes = new Uint8Array(segment.size);
|
let initbytes = new Uint8Array(segment.size);
|
||||||
let iter = this.iterateEntityFields(this.entities);
|
let iter = this.iterateEntityFields(this.entities);
|
||||||
@ -826,8 +834,9 @@ export class EntityScope implements SourceLocated {
|
|||||||
file.segment(`${this.name}_DATA`, 'bss');
|
file.segment(`${this.name}_DATA`, 'bss');
|
||||||
if (this.maxTempBytes) this.bss.allocateBytes('TEMP', this.maxTempBytes);
|
if (this.maxTempBytes) this.bss.allocateBytes('TEMP', this.maxTempBytes);
|
||||||
this.bss.dump(file);
|
this.bss.dump(file);
|
||||||
file.segment(`${this.name}_CODE`, 'rodata');
|
file.segment(`${this.name}_RODATA`, 'rodata');
|
||||||
this.rodata.dump(file);
|
this.rodata.dump(file);
|
||||||
|
//file.segment(`${this.name}_CODE`, 'code');
|
||||||
this.code.dump(file);
|
this.code.dump(file);
|
||||||
file.text(this.dialect.FOOTER); // TODO
|
file.text(this.dialect.FOOTER); // TODO
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user