samer@0: % arrow_repl - Instantiate arrow system and drop into REPL. samer@0: % samer@0: % arrow_repl :: samer@27: % arrow(_@typelist(N),_@typelist(M),S) ~'arbitrary arrow', samer@0: % {[N]->size} ~'sizes of inputs' samer@0: % options { samer@0: % gui :: boolean/false ~'create Java GUI for viewables' samer@0: % } samer@0: % -> _. samer@0: % samer@0: % This function provides a command line with access to a live samer@0: % system instantiated from the given arrow. The command line samer@0: % has the prompt 'unit>> ' to distinguish it from the normal samer@0: % Matlab prompt, but in other respects, is the same. The only samer@0: % commands that function differently are 'quit' and 'exit', samer@0: % which are trapped and behave as 'return' does, returning control samer@0: % to this function. Arbitrary values can be returned through to samer@0: % the called of arrow_repl using ret, eg samer@0: % unit>> ret(get_state(),45); samer@0: % returns two values: the current state of the system and the samer@0: % value 45. samer@0: % samer@0: % The environment contains the following variables of interest: samer@0: % sys :: arrow(A,B,S). % the original arrow samer@0: % unit :: unit(A,B,S). % the live processing unit samer@0: % get_state :: () -> S. % returns the state of the system samer@0: % set_state :: S -> action (). % sets the state of the system samer@0: % samer@0: % Other useful functions which can operate on the live unit samer@0: % are: ugather, uiterate, ufold and utransfer. samer@0: samer@0: samer@0: function varargout=arrow_repl(sys,sizes_in,varargin) samer@37: opts = options('gui',0,varargin{:}); samer@0: [varargout{1:nargout}]=with_arrow(sys,@unit_repl,sizes_in,opts,'keyboard',0,'pause',0); samer@0: samer@0: function varargout=unit_repl(unit) samer@0: returns={}; samer@0: try samer@0: fprintf('\n\nEntering REPL. Type "return","exit", or "quit" to finish.\n'); samer@0: fprintf('The function ret(..) sets return values.\n\n'); samer@0: cont=true; samer@0: while cont, samer@0: str=input('unit>> ','s'); samer@0: if strcmp(str,'quit') break; end samer@0: if strcmp(str,'exit') break; end samer@0: if strcmp(str,'return') break; end samer@0: try, eval(str) samer@0: catch ex samer@0: fprintf('\n%s\n',getReport(ex)); samer@0: end samer@0: end samer@0: catch ex samer@0: if ~isempty(uihandles), delete(uihandles); end samer@0: rethrow(ex); samer@0: end samer@0: varargout=returns; samer@0: samer@0: function set_state(s), unit.set_state(s); end samer@0: function s=get_state, s=unit.get_state(); end samer@0: function ret(varargin), returns=varargin; cont=false; end samer@0: end samer@0: end