Skip to content

Commit

Permalink
Addresses issue 11
Browse files Browse the repository at this point in the history
Found by @digital-carver
The issue affects the 'continue' ('X.') statement
  • Loading branch information
lmendo committed Nov 21, 2023
1 parent 663ca3a commit f0400d4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
26 changes: 22 additions & 4 deletions matl_compile.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down
Binary file modified spec/MATL_spec.pdf
Binary file not shown.
3 changes: 2 additions & 1 deletion spec/MATL_spec.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit f0400d4

Please sign in to comment.