From 40ca02fc6b27cd5596fba1ea00820cbb0422b606 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Thu, 3 Feb 2022 22:38:35 -0600 Subject: [PATCH] ecs: separate temp regions for now --- src/common/ecs/compiler.ts | 3 +-- src/common/ecs/ecs.ts | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/common/ecs/compiler.ts b/src/common/ecs/compiler.ts index 1bd61d6a..bfb8b3b0 100644 --- a/src/common/ecs/compiler.ts +++ b/src/common/ecs/compiler.ts @@ -65,8 +65,7 @@ export class ECSCompiler extends Tokenizer { try { comp.parseFile(text, path); } catch (e) { - for (e of comp.errors) this.errors.push(e); - throw e; + for (var err of comp.errors) this.errors.push(err); } } } diff --git a/src/common/ecs/ecs.ts b/src/common/ecs/ecs.ts index dc2ecf57..fd654973 100644 --- a/src/common/ecs/ecs.ts +++ b/src/common/ecs/ecs.ts @@ -251,7 +251,8 @@ export class Dialect_CA65 { ` readonly FOOTER = ` .segment "VECTORS" -VecNMI: .word Main::__NMI +Return: .word $6060 +VecNMI: VecReset: .word Main::__Reset VecBRK: .word Main::__BRK ` @@ -505,6 +506,7 @@ class ActionEval { jr: EntitySet | undefined; oldState : ActionCPUState; entities : Entity[]; + tmplabel = ''; constructor( readonly scope: EntityScope, @@ -666,7 +668,8 @@ class ActionEval { 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 (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 { // TODO: check ents @@ -1044,7 +1047,12 @@ export class EntityScope implements SourceLocated { for (let sys of systems) { // TODO: does this work if multiple actions? // 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) { if (action.event == event) { if (action.emits) { @@ -1060,15 +1068,17 @@ export class EntityScope implements SourceLocated { } // TODO: use Tokenizer so error msgs are better let codeeval = new ActionEval(this, sys, action); + codeeval.tmplabel = tmplabel; codeeval.begin(); s += this.dialect.comment(``); // TODO s += codeeval.codeToString(); s += this.dialect.comment(``); // TODO: check that this happens once? codeeval.end(); + numActions++; } } - if (sys.tempbytes) this.allocateTempBytes(-sys.tempbytes); + // TODO: if (sys.tempbytes && numActions) this.allocateTempBytes(-sys.tempbytes); } return s; }