Beispiel #1
0
    void ValidateStack()
    {
        int?stack = null;

        foreach (Op op in Children)
        {
            if (op.Def.controlFlow == "RETURN")
            {
                // stack should be 1 if return type != void
                if (stack > 1)
                {
                    op.Errors.Add($"Stack depth is {stack} on RETURN");
                }
                stack = null;
                continue;
            }

            if (!stack.HasValue)
            {
                stack = 0;
            }

            ValidateOp(op, stack.Value);

            stack = Op.DataPopPush(op.Def, stack.Value);

            switch (op.Def.controlFlow)
            {
            case "NEXT":
            case "CALL":
            case "META":
            case "BREAK": // Debugger breakpoint
                break;

            case "BRANCH":
                ValidateBranch(op, stack.Value);
                stack = null;
                break;

            case "COND_BRANCH":
                ValidateBranch(op, stack.Value);
                break;

            case "THROW":
                throw new NotImplementedException();

            case "RETURN":
                stack = null;
                break;

            default:
                throw new InvalidOperationException(op.Def.controlFlow);
            }

            if (op.Def.controlFlow != "NEXT")
            {
                throw new NotImplementedException(op.Def.controlFlow);
            }
        }
    }