view test/compile/bytecode_if.m @ 32151:72dcb1cef2c9

maint: Strip trailing whitespace from source files. Modified files: NEWS.8.md, file-editor-tab.cc, call-stack.cc, compile.cc, perms.cc, stack-frame.cc, ov-base.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.cc, ov-oncleanup.h, ov-range.cc, ov-range.h, ov-ref.cc, ov-ref.h, ov-scalar.h, ov-struct.cc, ov-vm.h, pt-bytecode-vm-internal.h, pt-bytecode-vm.cc, pt-bytecode-vm.h, pt-bytecode-walk.cc, pt-eval.cc, isuniform.m, inputParser.m, xlim.m, ylim.m, zlim.m, movfun.m, std.m, var.m, isstrprop.m, bench.m, bench.py, bytecode.tst, bytecode_anon_handles.m, bytecode_cell.m, bytecode_dountil.m, bytecode_end.m, bytecode_errors.m, bytecode_eval_1.m, bytecode_for.m, bytecode_global_1.m, bytecode_if.m, bytecode_leaks.m, bytecode_matrix.m, bytecode_multi_assign.m, bytecode_persistant.m, bytecode_range.m, bytecode_trycatch.m, bytecode_unwind.m, bytecode_while.m, bytecode_disp.m, bytecode_disp.tst, parser.tst.
author John W. Eaton <jwe@octave.org>
date Mon, 19 Jun 2023 23:21:41 -0400
parents 6e6e99e8a4de
children 8e4f14837db2
line wrap: on
line source

function bytecode_if()
  ctr = 0;
  a = 1;
  b = 0;

  if a
    __printf_assert__ ("%d ", ctr++);
  end

  if a
    __printf_assert__ ("%d ", ctr++);
  else
    __printf_assert__ ("booo ");
  end

  if a
    __printf_assert__ ("%d ", ctr++);
  elseif a
    __printf_assert__ ("booo ");
  else
    __printf_assert__ ("booo ");
  end

  if b
    __printf_assert__ ("booo ", ctr++);
  end

  if b
    __printf_assert__ ("booo ");
  else
    __printf_assert__ ("%d ", ctr++);
  end

  if b
    __printf_assert__ ("booo ");
  elseif b
    __printf_assert__ ("booo ");
  else
    __printf_assert__ ("%d ", ctr++);
  end

  if b
    __printf_assert__ ("booo ");
  elseif a
    __printf_assert__ ("%d ", ctr++);
  else
    __printf_assert__ ("booo ");
  end

  if a
    if a
      if a
        if a
          if a
            if b
              __printf_assert__ ("booo ");
            else
              if a
                if a
                  if b
                    __printf_assert__ ("booo ");
                  elseif a
                    if b
                      __printf_assert__ ("booo ");
                    else
                      __printf_assert__ ("%d ", ctr++);
                    end
                  else
                    __printf_assert__ ("booo ");
                  end
                end
              end
            end
          end
        else
          __printf_assert__ ("booo ");
        end
      end
    end
  end

  if 3 > 2
    __printf_assert__ ("%d ", ctr++);
  end

  if []
    __printf_assert__ ("booo ");
  end

  if ~b
    __printf_assert__ ("%d ", ctr++);
  end

  if b
  end

  % "Braindead" short circuit
  %
  % We also check that there is a proper short circuit
  if truthy (1) & truthy (2)
    __printf_assert__ ("yay1 ");
  end

  if falsy (3) & truthy (4)
    __printf_assert__ ("booo ");
  end

  if falsy (5) & falsy (6)
    __printf_assert__ ("booo ");
  end

  if truthy (7) & falsy (8)
    __printf_assert__ ("booo ");
  end

  if truthy (1)| truthy (2)
    __printf_assert__ ("yay1 ");
  end

  if falsy (3) | truthy (4)
    __printf_assert__ ("yay2 ");
  end

  if falsy (5) | falsy (6)
    __printf_assert__ ("booo ");
  end

  if truthy (7) | falsy (8)
    __printf_assert__ ("yay3 ");
  end
end

function a = truthy (b)
  __printf_assert__ ("%d ", b);
  a = 1;
end

function a = falsy (b)
  __printf_assert__ ("%d ", b);
  a = 0;
end