1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-10 12:47:45 +03:00
mal/matlab/step1_read_print.m
Joel Martin 4769962955 matlab: support Octave 4.0.0
- Workarounds for Octave 4.0.0:
    - no containers.Map yet so use new Dict
      structure when running under Octave.
    - weird error when +FOO/ directory and FOO.m file both exist so
      rename types.m to type_utils.m
    - no getReport so implement custom stack printer
    - workaround weird issue that happens when a class initializer is
      called with the first argument of the same class as per
      Env(outer, ...). The class is not properly initialized. So for
      now, wrap the outer in a cell as Env({outer}, ...)
    - missing MException object types so when in Octave, use a global
      variable to store the error object.
    - missing native2unicode so just use 0xff character for keyword
      prefix.
    - workaround some function calling/passing differences. For
      example, the "@" anonymous function symbol does not seem to work
      for conveying an existing function but only for defininign a new
      one. E.g. this works:
          @(a,b) a+b
      but this doesn't
          @my_adder_fn.
      so just do this:
          @(a,b) my_adder_fn(a,b)

- Add Dockerfile with Octave

- Active Travis for matlab implementation using Octave
2015-12-31 13:55:18 -06:00

40 lines
772 B
Matlab

function step1_read_print(varargin), main(varargin), end
% read
function ret = READ(str)
ret = reader.read_str(str);
end
% eval
function ret = EVAL(ast, env)
ret = ast;
end
% print
function ret = PRINT(ast)
ret = printer.pr_str(ast, true);
end
% REPL
function ret = rep(str, env)
ret = PRINT(EVAL(READ(str), env));
end
function main(args)
%cleanObj = onCleanup(@() disp('*** here1 ***'));
while (true)
try
line = input('user> ', 's');
catch err
return
end
if strcmp(strtrim(line),''), continue, end
try
fprintf('%s\n', rep(line, ''));
catch err
fprintf('Error: %s\n', err.message);
type_utils.print_stack(err);
end
end
end