From a4bac40c03ab7d0e2544b45f8de1f95cb77dd90b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=8D=93?= Date: Mon, 22 Mar 2021 15:38:17 +0800 Subject: [PATCH] feature: add progress info for loop in main component --- src/construction_phase.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/construction_phase.js b/src/construction_phase.js index af590e9..69ca982 100644 --- a/src/construction_phase.js +++ b/src/construction_phase.js @@ -795,7 +795,18 @@ function execLoop(ctx, ast) { return; } + let loopIdx = 0; + let isTopLevelLoop = !ctx.hasParentLoop; + ctx.hasParentLoop = true; while ((! ctx.F.isZero(v.v[0].v))&&(!ctx.returnValue)) { + if (ctx.verbose && ctx.main && isTopLevelLoop) { + let logStr = `main loop: loopIdx ${loopIdx}`; + if (ast.condition.type === 'OP') { + logStr += ` condition ${ast.condition.values.map(item => item.name).join(ast.condition.op)}`; + } + logStr += ` at ${ctx.fileName}:${ast.first_line}`; + console.log(logStr) + } exec(ctx, ast.body); if (ctx.error) return; @@ -808,6 +819,10 @@ function execLoop(ctx, ast) { if (ctx.error) return; if (v.s[0] != 1) return ctx.throwError(ast.condition, "Condition in loop cannot be an array"); if (v.v[0].t != "N") return ctx.throwError(ast.condition, "Condition result not a number"); + loopIdx++; + } + if (isTopLevelLoop) { + ctx.hasParentLoop = null; } }