1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-06-01 05:41:31 +00:00
8bitworkshop/src/worker/tools/ecs.ts

52 lines
2.1 KiB
TypeScript
Raw Normal View History

2022-01-29 17:34:26 +00:00
import { ECSCompiler } from "../../common/ecs/compiler";
2022-02-03 02:06:44 +00:00
import { Dialect_CA65, ECSError, EntityManager } from "../../common/ecs/ecs";
2022-01-29 17:34:26 +00:00
import { CompileError } from "../../common/tokenizer";
import { CodeListingMap } from "../../common/workertypes";
2023-11-29 20:36:58 +00:00
import { BuildStep, BuildStepResult, getWorkFileAsString, gatherFiles, staleFiles, fixParamsWithDefines, putWorkFile } from "../builder";
2022-01-29 17:34:26 +00:00
export function assembleECS(step: BuildStep): BuildStepResult {
2022-02-03 02:06:44 +00:00
let em = new EntityManager(new Dialect_CA65()); // TODO
let compiler = new ECSCompiler(em, true);
2022-02-03 02:06:44 +00:00
compiler.getImportFile = (path: string) => {
return getWorkFileAsString(path);
}
2022-01-29 17:34:26 +00:00
gatherFiles(step, { mainFilePath: "main.ecs" });
2022-02-03 13:44:47 +00:00
if (step.mainfile) em.mainPath = step.path;
2022-01-29 17:34:26 +00:00
var destpath = step.prefix + '.ca65';
if (staleFiles(step, [destpath])) {
let code = getWorkFileAsString(step.path);
2022-02-21 15:24:03 +00:00
fixParamsWithDefines(step.path, step.params);
2022-01-29 17:34:26 +00:00
try {
compiler.includeDebugInfo = true;
2022-01-29 17:34:26 +00:00
compiler.parseFile(code, step.path);
2022-01-30 16:48:56 +00:00
let outtext = compiler.export().toString();
putWorkFile(destpath, outtext);
var listings: CodeListingMap = {};
listings[destpath] = {lines:[], text:outtext} // TODO
var debuginfo = compiler.em.getDebugTree();
2022-01-29 17:34:26 +00:00
} catch (e) {
2022-01-30 16:48:56 +00:00
if (e instanceof ECSError) {
compiler.addError(e.message, e.$loc);
2022-02-27 16:58:47 +00:00
for (let obj of e.$sources) {
let name = (obj as any).event;
if (name == 'start') break;
compiler.addError(`... ${name}`, obj.$loc); // TODO?
}
2022-01-30 16:48:56 +00:00
return { errors: compiler.errors };
} else if (e instanceof CompileError) {
2022-01-29 17:34:26 +00:00
return { errors: compiler.errors };
} else {
throw e;
}
}
return {
nexttool: "ca65",
path: destpath,
args: [destpath],
files: [destpath].concat(step.files),
listings,
debuginfo
};
2022-01-29 17:34:26 +00:00
}
}