Limit pass count

This commit is contained in:
Tony Garnock-Jones 2021-01-14 13:15:23 +01:00
parent 2105886c5e
commit c5efff9a0f
1 changed files with 4 additions and 0 deletions

View File

@ -12,6 +12,7 @@ export function main(argv: string[]) {
let tree = reader.readToEnd();
let macro = new S.Templates();
let passNumber = 1;
let expansionNeeded = true;
function expand<T>(p: S.Pattern<T>, f: (t: T) => S.Items) {
tree = S.replace(tree, p, t => {
@ -20,6 +21,9 @@ export function main(argv: string[]) {
});
}
while (expansionNeeded) {
if (passNumber >= 128) {
throw new Error(`Too many compiler passes (${passNumber})!`);
}
expansionNeeded = false;
expand(G.spawn,
s => macro.template()`SPAWN[${s.name ?? []}][${S.joinItems(s.initialAssertions, ', ')}][[${s.bootProcBody}]]`);