1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-26 10:49:17 +00:00

ecs: skip parsing demo if not in main file

This commit is contained in:
Steven Hugg 2022-02-24 10:06:20 -06:00
parent 75fb2a8e5c
commit e7e5ea7847
5 changed files with 56 additions and 17 deletions

View File

@ -184,3 +184,8 @@ end
ldy {{<index}} ldy {{<index}}
{{!SetHorizPos}} {{!SetHorizPos}}
--- ---
Slice PNGs into sprites
Maybe output decoder text
Action priorities - before, after

View File

@ -22,10 +22,11 @@ export class ECSCompiler extends Tokenizer {
currentScope: EntityScope | null = null; currentScope: EntityScope | null = null;
currentContext: ActionContext | null = null; currentContext: ActionContext | null = null;
debuginfo = false; includeDebugInfo = false;
constructor( constructor(
public readonly em: EntityManager) { public readonly em: EntityManager,
public readonly isMainFile: boolean) {
super(); super();
//this.includeEOL = true; //this.includeEOL = true;
this.setTokenRules([ this.setTokenRules([
@ -71,8 +72,8 @@ export class ECSCompiler extends Tokenizer {
let text = this.getImportFile && this.getImportFile(path); let text = this.getImportFile && this.getImportFile(path);
if (!text) this.compileError(`I can't find the import file "${path}".`); if (!text) this.compileError(`I can't find the import file "${path}".`);
this.em.imported[path] = true; this.em.imported[path] = true;
let comp = new ECSCompiler(this.em); let comp = new ECSCompiler(this.em, false);
comp.debuginfo = this.debuginfo; // TODO: clone compiler comp.includeDebugInfo = this.includeDebugInfo; // TODO: clone compiler
try { try {
comp.parseFile(text, path); comp.parseFile(text, path);
} catch (e) { } catch (e) {
@ -103,11 +104,15 @@ export class ECSCompiler extends Tokenizer {
return this.importFile(path); return this.importFile(path);
} }
if (tok.str == 'demo') { if (tok.str == 'demo') {
let scope = this.parseScope(); if (this.isMainFile) {
scope.isDemo = true; let scope = this.parseScope();
// TODO: make required scope.isDemo = true;
if (this.peekToken().str == 'demo') this.expectToken('demo'); this.expectToken('demo');
return scope; return scope;
} else {
this.skipDemo(); // don't even parse it, just skip it
return;
}
} }
if (tok.str == 'comment') { if (tok.str == 'comment') {
this.expectTokenTypes([ECSTokenType.CodeFragment]); this.expectTokenTypes([ECSTokenType.CodeFragment]);
@ -116,6 +121,17 @@ export class ECSCompiler extends Tokenizer {
this.compileError(`Unexpected top-level keyword: ${tok.str}`); this.compileError(`Unexpected top-level keyword: ${tok.str}`);
} }
skipDemo() {
var tok;
while ((tok = this.consumeToken()) && !this.isEOF()) {
if (tok.str == 'end' && this.peekToken().str == 'demo') {
this.consumeToken();
return;
}
}
throw new ECSError(`Expected "end demo" after a "demo" declaration.`);
}
parseComponentDefinition(): ComponentType { parseComponentDefinition(): ComponentType {
let name = this.expectIdent().str; let name = this.expectIdent().str;
let fields = []; let fields = [];
@ -387,7 +403,7 @@ export class ECSCompiler extends Tokenizer {
let code = tok.str.substring(3, tok.str.length - 3); let code = tok.str.substring(3, tok.str.length - 3);
// TODO: add after parsing maybe? // TODO: add after parsing maybe?
let lines = code.split('\n'); let lines = code.split('\n');
if (this.debuginfo) this.addDebugInfo(lines, tok.$loc.line); if (this.includeDebugInfo) this.addDebugInfo(lines, tok.$loc.line);
code = lines.join('\n'); code = lines.join('\n');
let acomp = new ECSActionCompiler(context); let acomp = new ECSActionCompiler(context);

View File

@ -1149,6 +1149,11 @@ export class EntityScope implements SourceLocated {
} }
} }
} }
*iterateChildScopes() {
for (let scope of this.childScopes) {
yield scope;
}
}
entitiesMatching(atypes: EntityArchetype[]) { entitiesMatching(atypes: EntityArchetype[]) {
let result: Entity[] = []; let result: Entity[] = [];
for (let e of this.entities) { for (let e of this.entities) {
@ -1543,8 +1548,8 @@ export class EntityScope implements SourceLocated {
let subcall = this.dialect.call(stats.labels[0]); let subcall = this.dialect.call(stats.labels[0]);
for (let label of stats.labels) { for (let label of stats.labels) {
// TODO: use dialect // TODO: use dialect
let startdelim = `;;; start action ${label}` let startdelim = this.dialect.comment(`start action ${label}`);
let enddelim = `;;; end action ${label}` let enddelim = this.dialect.comment(`end action ${label}`);
let istart = code.indexOf(startdelim); let istart = code.indexOf(startdelim);
let iend = code.indexOf(enddelim, istart); let iend = code.indexOf(enddelim, istart);
if (istart >= 0 && iend > istart) { if (istart >= 0 && iend > istart) {
@ -1729,10 +1734,23 @@ export class EntityManager {
} }
} }
} }
*iterateScopes() {
for (let scope of Object.values(this.topScopes)) {
yield scope;
scope.iterateChildScopes();
}
}
getDebugTree() : {} { getDebugTree() : {} {
let scopes = this.topScopes; let scopes = this.topScopes;
let components = this.components; let components = this.components;
let fields = this.name2cfpairs;
let systems = this.systems; let systems = this.systems;
return { scopes, components, systems }; let events = this.event2systems;
let entities : {[key:string]:Entity} = {};
for (let scope of Array.from(this.iterateScopes())) {
for (let e of scope.entities)
entities[e.name || '#'+e.id.toString()] = e;
}
return { scopes, components, fields, systems, events, entities };
} }
} }

View File

@ -8,7 +8,7 @@ import { Dialect_CA65, EntityManager, SourceFileExport } from "../common/ecs/ecs
function testCompiler() { function testCompiler() {
let em = new EntityManager(new Dialect_CA65()); // TODO let em = new EntityManager(new Dialect_CA65()); // TODO
let c = new ECSCompiler(em); let c = new ECSCompiler(em, true);
try { try {
c.parseFile(` c.parseFile(`
// comment // comment
@ -93,7 +93,7 @@ describe('Compiler', function() {
let dialect = new Dialect_CA65(); let dialect = new Dialect_CA65();
let em = new EntityManager(dialect); let em = new EntityManager(dialect);
em.mainPath = ecspath; em.mainPath = ecspath;
let compiler = new ECSCompiler(em); let compiler = new ECSCompiler(em, true);
compiler.getImportFile = (path: string) => { compiler.getImportFile = (path: string) => {
return readFileSync(testdir + path, 'utf-8'); return readFileSync(testdir + path, 'utf-8');
} }

View File

@ -6,7 +6,7 @@ import { BuildStep, BuildStepResult, fixParamsWithDefines, gatherFiles, getWorkF
export function assembleECS(step: BuildStep): BuildStepResult { export function assembleECS(step: BuildStep): BuildStepResult {
let em = new EntityManager(new Dialect_CA65()); // TODO let em = new EntityManager(new Dialect_CA65()); // TODO
let compiler = new ECSCompiler(em); let compiler = new ECSCompiler(em, true);
compiler.getImportFile = (path: string) => { compiler.getImportFile = (path: string) => {
return getWorkFileAsString(path); return getWorkFileAsString(path);
} }
@ -17,7 +17,7 @@ export function assembleECS(step: BuildStep): BuildStepResult {
let code = getWorkFileAsString(step.path); let code = getWorkFileAsString(step.path);
fixParamsWithDefines(step.path, step.params); fixParamsWithDefines(step.path, step.params);
try { try {
compiler.debuginfo = true; compiler.includeDebugInfo = true;
compiler.parseFile(code, step.path); compiler.parseFile(code, step.path);
let outtext = compiler.export().toString(); let outtext = compiler.export().toString();
putWorkFile(destpath, outtext); putWorkFile(destpath, outtext);