diff --git a/matl_compile.m b/matl_compile.m index d1ab5ae..47d1d22 100644 --- a/matl_compile.m +++ b/matl_compile.m @@ -19,8 +19,8 @@ % % The multi-level clipboard L (variable 'CB_L') is a cell array of cells. The "outer" cells % refer to clipboard levels. The "inner cells" refer to copied elements within that clipboard -% level. CB_L is a dynamic cell array: outer cells are created on the fly -% when clipboard levels are copied to. +% level. CB_L is a dynamic cell array: outer cells are created on the fly when clipboard levels +% are copied to. global indStepComp C implicitInputBlock @@ -256,7 +256,7 @@ appendLines(implicitInputBlock, S(n).nesting); % code block for implicit input newLines = { sprintf('condDoWhile%i = STACK{end}; if ~isreal(condDoWhile%i), condDoWhile%i = real(condDoWhile%i); end', S(n).nesting, S(n).nesting, S(n).nesting, S(n).nesting) ... 'STACK(end) = [];' ... - sprintf('if condDoWhile%i, else', S(n).nesting) }; % We use 'if condDoWhile%i, else' rather than 'if ~condDoWhile%i' + sprintf('if condDoWhile%i, else', S(n).nesting) }; % we use 'if condDoWhile%i, else' rather than 'if ~condDoWhile%i' % so as to reproduce Matlab's behaviour when the condition is an array ('if ~condDoWhile%i' wouldn't do) appendLines(newLines, S(n).nesting); elseif strcmp(S(S(n).from).type, 'controlFlow.while') @@ -312,7 +312,25 @@ case 'controlFlow.break' appendLines('break', S(n).nesting) case 'controlFlow.continue' - appendLines('continue', S(n).nesting) + if strcmp(S(S(n).from).type, 'controlFlow.for') || strcmp(S(S(n).from).type, 'controlFlow.doTwice') + appendLines('continue', S(n).nesting) + elseif strcmp(S(S(n).from).type, 'controlFlow.doWhile') + % evaluate loop condition before 'continue', as would be done before 'end'. The + % loop condition has nesting corresponding to the "from" statement, not to the + % current statement + newLines = { sprintf('condDoWhile%i = STACK{end}; if ~isreal(condDoWhile%i), condDoWhile%i = real(condDoWhile%i); end', S(S(n).from).nesting, S(S(n).from).nesting, S(S(n).from).nesting, S(S(n).from).nesting) ... + 'STACK(end) = [];' ... + 'continue' }; + appendLines(newLines, S(n).nesting); + elseif strcmp(S(S(n).from).type, 'controlFlow.while') + % same as for 'doWhile' loop, just changing the root of the name of the condition variable + newLines = { sprintf('condWhile%i = STACK{end}; if ~isreal(condWhile%i), condWhile%i = real(condWhile%i); end', S(S(n).from).nesting, S(S(n).from).nesting, S(S(n).from).nesting, S(S(n).from).nesting) ... + 'STACK(end) = [];' ... + 'continue' }; + appendLines(newLines, S(n).nesting); + else + error('MATL:compiler:internal', 'MATL internal error while compiling statement %s%s%s', strongBegin, S(n).source, strongEnd) + end case 'controlFlow.forValue' k = S(S(n).from).nesting; appendLines(sprintf('STACK{end+1} = varFor%i;', k), S(n).nesting) diff --git a/spec/MATL_spec.pdf b/spec/MATL_spec.pdf index 743fe1b..1a04b9e 100644 Binary files a/spec/MATL_spec.pdf and b/spec/MATL_spec.pdf differ diff --git a/spec/MATL_spec.tex b/spec/MATL_spec.tex index a1ed5a3..33d6865 100644 --- a/spec/MATL_spec.tex +++ b/spec/MATL_spec.tex @@ -1597,11 +1597,12 @@ \section{Acknowledgments} % http://chat.stackoverflow.com/transcript/message/30154628#30154628 % http://codegolf.stackexchange.com/questions/82981/leyland-numbers#comment202388_82995 \item -\user{@sundar} for prompting me to clarify that strings are understood as row vectors of chars in MATL; for several corrections in the documentation, for a correction in \matl{Z\{}; for a correction in \matl{S}; and for suggesting the \matl{Zx} function, two-input char mode for \matl{Yo} and a modification in \matl{Yb}. +\user{@sundar} for prompting me to clarify that strings are understood as row vectors of chars in MATL; for several corrections in the documentation, for a correction in \matl{Z\{}; for a correction in \matl{S}; for finding a bug in \matl{X.}; and for suggesting the \matl{Zx} function, two-input char mode for \matl{Yo} and a modification in \matl{Yb}. % https://chat.stackexchange.com/transcript/message/46222193#46222193 % https://codegolf.stackexchange.com/questions/166527/decoding-the-kaadi-system/168021#comment405995_168021 % https://chat.stackexchange.com/transcript/message/45568841#45568841 % https://chat.stackexchange.com/transcript/39466?m=45568698#45568698 +% https://github.com/lmendo/MATL/issues/11 \item{@TasosPapastylianou} for pointing out that a shadowed function \matlab+disp(x)+ for symbolic \matlab+x+ can be called as \matlab+builtin('@sym/disp', x)+ in Octave (\matlab+builtin('disp', x)+ doesn't work). % https://stackoverflow.com/questions/58727452/how-to-call-a-shadowed-function-in-octave?noredirect=1#comment103801920_58727452 \end{itemize}