samer@0
|
1 % arrow_repl - Instantiate arrow system and drop into REPL.
|
samer@0
|
2 %
|
samer@0
|
3 % arrow_repl ::
|
samer@27
|
4 % arrow(_@typelist(N),_@typelist(M),S) ~'arbitrary arrow',
|
samer@0
|
5 % {[N]->size} ~'sizes of inputs'
|
samer@0
|
6 % options {
|
samer@0
|
7 % gui :: boolean/false ~'create Java GUI for viewables'
|
samer@0
|
8 % }
|
samer@0
|
9 % -> _.
|
samer@0
|
10 %
|
samer@0
|
11 % This function provides a command line with access to a live
|
samer@0
|
12 % system instantiated from the given arrow. The command line
|
samer@0
|
13 % has the prompt 'unit>> ' to distinguish it from the normal
|
samer@0
|
14 % Matlab prompt, but in other respects, is the same. The only
|
samer@0
|
15 % commands that function differently are 'quit' and 'exit',
|
samer@0
|
16 % which are trapped and behave as 'return' does, returning control
|
samer@0
|
17 % to this function. Arbitrary values can be returned through to
|
samer@0
|
18 % the called of arrow_repl using ret, eg
|
samer@0
|
19 % unit>> ret(get_state(),45);
|
samer@0
|
20 % returns two values: the current state of the system and the
|
samer@0
|
21 % value 45.
|
samer@0
|
22 %
|
samer@0
|
23 % The environment contains the following variables of interest:
|
samer@0
|
24 % sys :: arrow(A,B,S). % the original arrow
|
samer@0
|
25 % unit :: unit(A,B,S). % the live processing unit
|
samer@0
|
26 % get_state :: () -> S. % returns the state of the system
|
samer@0
|
27 % set_state :: S -> action (). % sets the state of the system
|
samer@0
|
28 %
|
samer@0
|
29 % Other useful functions which can operate on the live unit
|
samer@0
|
30 % are: ugather, uiterate, ufold and utransfer.
|
samer@0
|
31
|
samer@0
|
32
|
samer@0
|
33 function varargout=arrow_repl(sys,sizes_in,varargin)
|
samer@37
|
34 opts = options('gui',0,varargin{:});
|
samer@0
|
35 [varargout{1:nargout}]=with_arrow(sys,@unit_repl,sizes_in,opts,'keyboard',0,'pause',0);
|
samer@0
|
36
|
samer@0
|
37 function varargout=unit_repl(unit)
|
samer@0
|
38 returns={};
|
samer@0
|
39 try
|
samer@0
|
40 fprintf('\n\nEntering REPL. Type "return","exit", or "quit" to finish.\n');
|
samer@0
|
41 fprintf('The function ret(..) sets return values.\n\n');
|
samer@0
|
42 cont=true;
|
samer@0
|
43 while cont,
|
samer@0
|
44 str=input('unit>> ','s');
|
samer@0
|
45 if strcmp(str,'quit') break; end
|
samer@0
|
46 if strcmp(str,'exit') break; end
|
samer@0
|
47 if strcmp(str,'return') break; end
|
samer@0
|
48 try, eval(str)
|
samer@0
|
49 catch ex
|
samer@0
|
50 fprintf('\n%s\n',getReport(ex));
|
samer@0
|
51 end
|
samer@0
|
52 end
|
samer@0
|
53 catch ex
|
samer@0
|
54 if ~isempty(uihandles), delete(uihandles); end
|
samer@0
|
55 rethrow(ex);
|
samer@0
|
56 end
|
samer@0
|
57 varargout=returns;
|
samer@0
|
58
|
samer@0
|
59 function set_state(s), unit.set_state(s); end
|
samer@0
|
60 function s=get_state, s=unit.get_state(); end
|
samer@0
|
61 function ret(varargin), returns=varargin; cont=false; end
|
samer@0
|
62 end
|
samer@0
|
63 end
|