Re: Pass by Reference
- Posted by petelomax Jan 15, 2015
- 2036 views
dcuny said...
With disparate values, why would you want to use multiple returns here? Wouldn't this make more sense (ignoring keywords, of course):
sequence result = get_operand() switch result[1] do case P_REG then { op, size, flags } = result case P_VAR then { op, size, n, type } = result case P_MEM then { op, size, scale, index, base, offset } = result case P_LBL then { op, lblidx } = result case P_IMM then { op, atom } = result end case
Yes, but you can also, and indeed in places the current code actually does, do something like this
{ op, size, reg } = get_operand(P_REG)
or this
{ op, size, scale, index, base, offset } = get_operand(P_MEM)
In Phix, you get a fatal error if there aren't enough values, whereas OpenEuphoria just quietly leaves some values as-is, and on both, no messages if there are too many.
If anything, slightly tongue in cheek, it would be nice for
{ P_REG, size, reg, $ } = get_operand(P_REG) { P_MEM, size, scale, index, base, offset, $ } = get_operand(P_MEM)
to check, because P_REG/P_MEM are constants, that res[1] is the expected value and deliver a fatal runtime crash if not, and (from the ",$") check that the exact number of values was returned.
Pete