view test/compile/bytecode_multi_assign.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 6d2f6ca0996f
line wrap: on
line source

function bytecode_multi_assign ()
  A = [1 2; 3 4];
  [a, b] = max (A);
  __printf_assert__ ("%d ", a);
  __printf_assert__ ("%d ", b);

  [a,b,c,d] = foo ();
  __printf_assert__ ("%d ", a);
  __printf_assert__ ("%d ", b);
  __printf_assert__ ("%d ", c);
  __printf_assert__ ("%d ", d);

  % Non ids in lhs
  % Eval is used as a cheat since
  % rhs need to know how many lhs values
  % there are.

  [e, f.a, g, h.b] = foo ();
  __printf_assert__ ("%d ", e);
  __printf_assert__ ("%d ", f.a);
  __printf_assert__ ("%d ", g);
  __printf_assert__ ("%d ", h.b);

  e = [1 2 3];
  g = {1, 2, 3};
  [e(2), f.a, g{2}, h.b] = foo ();
  __printf_assert__ ("%d ", e);
  __printf_assert__ ("%d ", f.a);
  __printf_assert__ ("%d ", g{2});
  __printf_assert__ ("%d ", h.b);

  [e(end), f.a, g{min (100, end)}, h.b] = foo ();
  __printf_assert__ ("%d ", e);
  __printf_assert__ ("%d ", f.a);
  __printf_assert__ ("%d ", g{min (100, end)});
  __printf_assert__ ("%d ", h.b);

  [e(end), f.a, ~, h.b] = foo ();
  __printf_assert__ ("%d ", e);
  __printf_assert__ ("%d ", f.a);
  __printf_assert__ ("%d ", g{end});
  __printf_assert__ ("%d ", h.b);


  [C{1:2}, D] = {1,2,3}{:};
  __printf_assert__ ("%d ", C{1});
  __printf_assert__ ("%d ", C{2});
  __printf_assert__ ("%d ", D);
end

function [a,b,c,d] = foo ()
  a = 1;
  b = 2;
  c = 3;
  d = 4;
end