1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-06-08 08:33:32 +00:00

ecs: separate temp regions for now

This commit is contained in:
Steven Hugg 2022-02-03 22:38:35 -06:00
parent dbc84c94b2
commit 40ca02fc6b
2 changed files with 15 additions and 6 deletions

View File

@ -65,8 +65,7 @@ export class ECSCompiler extends Tokenizer {
try { try {
comp.parseFile(text, path); comp.parseFile(text, path);
} catch (e) { } catch (e) {
for (e of comp.errors) this.errors.push(e); for (var err of comp.errors) this.errors.push(err);
throw e;
} }
} }
} }

View File

@ -251,7 +251,8 @@ export class Dialect_CA65 {
` `
readonly FOOTER = ` readonly FOOTER = `
.segment "VECTORS" .segment "VECTORS"
VecNMI: .word Main::__NMI Return: .word $6060
VecNMI:
VecReset: .word Main::__Reset VecReset: .word Main::__Reset
VecBRK: .word Main::__BRK VecBRK: .word Main::__BRK
` `
@ -505,6 +506,7 @@ class ActionEval {
jr: EntitySet | undefined; jr: EntitySet | undefined;
oldState : ActionCPUState; oldState : ActionCPUState;
entities : Entity[]; entities : Entity[];
tmplabel = '';
constructor( constructor(
readonly scope: EntityScope, readonly scope: EntityScope,
@ -666,7 +668,8 @@ class ActionEval {
if (isNaN(tempinc)) throw new ECSError(`bad temporary offset`, this.action); if (isNaN(tempinc)) throw new ECSError(`bad temporary offset`, this.action);
if (!this.sys.tempbytes) throw new ECSError(`this system has no locals`, this.action); if (!this.sys.tempbytes) throw new ECSError(`this system has no locals`, this.action);
if (tempinc < 0 || tempinc >= this.sys.tempbytes) throw new ECSError(`this system only has ${this.sys.tempbytes} locals`, this.action); if (tempinc < 0 || tempinc >= this.sys.tempbytes) throw new ECSError(`this system only has ${this.sys.tempbytes} locals`, this.action);
return `TEMP+${this.scope.tempOffset}+${tempinc}`; return `${this.tmplabel}+${tempinc}`;
//return `TEMP+${this.scope.tempOffset}+${tempinc}`;
} }
wrapCodeInLoop(code: string, action: Action, ents: Entity[], joinfield?: ComponentFieldPair): string { wrapCodeInLoop(code: string, action: Action, ents: Entity[], joinfield?: ComponentFieldPair): string {
// TODO: check ents // TODO: check ents
@ -1044,7 +1047,12 @@ export class EntityScope implements SourceLocated {
for (let sys of systems) { for (let sys of systems) {
// TODO: does this work if multiple actions? // TODO: does this work if multiple actions?
// TODO: should 'emits' be on action? // TODO: should 'emits' be on action?
if (sys.tempbytes) this.allocateTempBytes(sys.tempbytes); // TODO: share storage
//if (sys.tempbytes) this.allocateTempBytes(sys.tempbytes);
let tmplabel = `${sys.name}_tmp`;
if (sys.tempbytes) this.bss.allocateBytes(tmplabel, sys.tempbytes);
//this.allocateTempBytes(1);
let numActions = 0;
for (let action of sys.actions) { for (let action of sys.actions) {
if (action.event == event) { if (action.event == event) {
if (action.emits) { if (action.emits) {
@ -1060,15 +1068,17 @@ export class EntityScope implements SourceLocated {
} }
// TODO: use Tokenizer so error msgs are better // TODO: use Tokenizer so error msgs are better
let codeeval = new ActionEval(this, sys, action); let codeeval = new ActionEval(this, sys, action);
codeeval.tmplabel = tmplabel;
codeeval.begin(); codeeval.begin();
s += this.dialect.comment(`<action ${sys.name}:${event}>`); // TODO s += this.dialect.comment(`<action ${sys.name}:${event}>`); // TODO
s += codeeval.codeToString(); s += codeeval.codeToString();
s += this.dialect.comment(`</action ${sys.name}:${event}>`); s += this.dialect.comment(`</action ${sys.name}:${event}>`);
// TODO: check that this happens once? // TODO: check that this happens once?
codeeval.end(); codeeval.end();
numActions++;
} }
} }
if (sys.tempbytes) this.allocateTempBytes(-sys.tempbytes); // TODO: if (sys.tempbytes && numActions) this.allocateTempBytes(-sys.tempbytes);
} }
return s; return s;
} }