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";
|
2022-02-21 15:24:03 +00:00
|
|
|
import { BuildStep, BuildStepResult, fixParamsWithDefines, gatherFiles, getWorkFileAsString, putWorkFile, staleFiles } from "../workermain";
|
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
|
2022-02-24 16:06:20 +00:00
|
|
|
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 {
|
2022-02-24 16:06:20 +00:00
|
|
|
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
|
2022-02-24 15:47:34 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2022-02-24 15:47:34 +00:00
|
|
|
return {
|
|
|
|
nexttool: "ca65",
|
|
|
|
path: destpath,
|
|
|
|
args: [destpath],
|
|
|
|
files: [destpath].concat(step.files),
|
|
|
|
listings,
|
|
|
|
debuginfo
|
|
|
|
};
|
2022-01-29 17:34:26 +00:00
|
|
|
}
|
|
|
|
}
|