diff options
| author | Joel Martin <github@martintribe.org> | 2015-02-10 01:51:28 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-02-10 01:51:28 -0600 |
| commit | 0b234e13a114a9f7eb6e44c1febf11158907f0a5 (patch) | |
| tree | 0ee56d5e99a54ad5e987fc1a27465192b4cb042d | |
| parent | 53942f889aa103e5ea298b92b7a4fc7d7a133d1a (diff) | |
| download | mal-0b234e13a114a9f7eb6e44c1febf11158907f0a5.tar.gz mal-0b234e13a114a9f7eb6e44c1febf11158907f0a5.zip | |
matlab: fix do/slice, strings. Self-hosting!
Fix Makefile stats/stats-lisp.
| -rw-r--r-- | matlab/+types/List.m | 2 | ||||
| -rw-r--r-- | matlab/Env.m | 2 | ||||
| -rw-r--r-- | matlab/Makefile | 8 | ||||
| -rw-r--r-- | matlab/core.m | 1 | ||||
| -rw-r--r-- | matlab/printer.m | 10 | ||||
| -rw-r--r-- | matlab/reader.m | 4 | ||||
| -rw-r--r-- | matlab/step2_eval.m | 1 | ||||
| -rw-r--r-- | matlab/step3_env.m | 1 | ||||
| -rw-r--r-- | matlab/step4_if_fn_do.m | 1 | ||||
| -rw-r--r-- | matlab/step5_tco.m | 1 | ||||
| -rw-r--r-- | matlab/step6_file.m | 3 | ||||
| -rw-r--r-- | matlab/step7_quote.m | 3 | ||||
| -rw-r--r-- | matlab/step8_macros.m | 3 | ||||
| -rw-r--r-- | matlab/step9_try.m | 3 | ||||
| -rw-r--r-- | matlab/stepA_interop.m | 3 | ||||
| -rw-r--r-- | matlab/types.m | 4 |
16 files changed, 31 insertions, 19 deletions
diff --git a/matlab/+types/List.m b/matlab/+types/List.m index 3fc1429..1a9571c 100644 --- a/matlab/+types/List.m +++ b/matlab/+types/List.m @@ -30,7 +30,7 @@ classdef List < handle if nargin < 3 last = length(obj.data); end - ret = types.List(obj.data{start:end}); + ret = types.List(obj.data{start:last}); end function ret = clone(obj) diff --git a/matlab/Env.m b/matlab/Env.m index 0a09db8..66862ff 100644 --- a/matlab/Env.m +++ b/matlab/Env.m @@ -43,7 +43,7 @@ classdef Env < handle ret = fenv.data(k.name); else throw(MException('ENV:notfound', ... - strcat('''', k.name, ''' not found'))); + sprintf('''%s'' not found', k.name))); end end end diff --git a/matlab/Makefile b/matlab/Makefile index 445512a..a603822 100644 --- a/matlab/Makefile +++ b/matlab/Makefile @@ -1,6 +1,8 @@ -SOURCES_BASE = Reader.m types/Symbol.m reader.m printer.m -#SOURCES_LISP = env.m core.m stepA_interop.m -SOURCES_LISP = stepA_interop.m +SOURCES_BASE = types.m types/Nil.m types/MalException.m \ + types/Symbol.m types/List.m types/Vector.m \ + types/HashMap.m types/Function.m types/Atom.m \ + Reader.m reader.m printer.m +SOURCES_LISP = Env.m core.m stepA_interop.m SOURCES = $(SOURCES_BASE) $(SOURCES_LISP) diff --git a/matlab/core.m b/matlab/core.m index ef3848e..2f9e1f3 100644 --- a/matlab/core.m +++ b/matlab/core.m @@ -206,6 +206,7 @@ classdef core n('count') = @(a) length(a); n('apply') = @core.apply; n('map') = @core.map; + n('conj') = @(x) disp('not implemented yet'); n('with-meta') = @core.with_meta; n('meta') = @core.meta; diff --git a/matlab/printer.m b/matlab/printer.m index 0642e7b..5200a6e 100644 --- a/matlab/printer.m +++ b/matlab/printer.m @@ -9,13 +9,13 @@ classdef printer str = num2str(obj); case 'char' if types.keyword_Q(obj) - str = strcat(':', obj(2:end)); + str = sprintf(':%s', obj(2:end)); else if print_readably str = strrep(obj, '\', '\\'); str = strrep(str, '"', '\"'); str = strrep(str, char(10), '\n'); - str = strcat('"', str, '"'); + str = sprintf('"%s"', str); else str = obj; end @@ -23,11 +23,11 @@ classdef printer case 'types.List' strs = cellfun(@(x) printer.pr_str(x, print_readably), ... obj.data, 'UniformOutput', false); - str = strcat('(', strjoin(strs, ' '), ')'); + str = sprintf('(%s)', strjoin(strs, ' ')); case 'types.Vector' strs = cellfun(@(x) printer.pr_str(x, print_readably), ... obj.data, 'UniformOutput', false); - str = strcat('[', strjoin(strs, ' '), ']'); + str = sprintf('[%s]', strjoin(strs, ' ')); case 'types.HashMap' strs = {}; ks = obj.keys(); @@ -36,7 +36,7 @@ classdef printer strs{end+1} = printer.pr_str(k, print_readably); strs{end+1} = printer.pr_str(obj.get(k), print_readably); end - str = strcat('{', strjoin(strs, ' '), '}'); + str = sprintf('{%s}', strjoin(strs, ' ')); case 'types.Nil' str = 'nil'; case 'logical' diff --git a/matlab/reader.m b/matlab/reader.m index fc72ac5..84f6806 100644 --- a/matlab/reader.m +++ b/matlab/reader.m @@ -36,12 +36,12 @@ classdef reader seq = {}; token = rdr.next(); if not(strcmp(token, start)) - error(strcat('expected ''', start, '''')); + error(sprintf('expected ''%s''', start)); end token = rdr.peek(); while true if eq(token, false) - error(strcat('expected ''', last, '''')); + error(sprintf('expected ''%s''', last)); end if strcmp(token, last), break, end seq{end+1} = reader.read_form(rdr); diff --git a/matlab/step2_eval.m b/matlab/step2_eval.m index 34559c0..d742d6f 100644 --- a/matlab/step2_eval.m +++ b/matlab/step2_eval.m @@ -33,6 +33,7 @@ function ret = eval_ast(ast, env) end function ret = EVAL(ast, env) + %fprintf('EVAL: %s\n', printer.pr_str(ast, true)); if ~types.list_Q(ast) ret = eval_ast(ast, env); return; diff --git a/matlab/step3_env.m b/matlab/step3_env.m index 801ad6f..55a3668 100644 --- a/matlab/step3_env.m +++ b/matlab/step3_env.m @@ -33,6 +33,7 @@ function ret = eval_ast(ast, env) end function ret = EVAL(ast, env) + %fprintf('EVAL: %s\n', printer.pr_str(ast, true)); if ~types.list_Q(ast) ret = eval_ast(ast, env); return; diff --git a/matlab/step4_if_fn_do.m b/matlab/step4_if_fn_do.m index 0e24b28..a864194 100644 --- a/matlab/step4_if_fn_do.m +++ b/matlab/step4_if_fn_do.m @@ -33,6 +33,7 @@ function ret = eval_ast(ast, env) end function ret = EVAL(ast, env) + %fprintf('EVAL: %s\n', printer.pr_str(ast, true)); if ~types.list_Q(ast) ret = eval_ast(ast, env); return; diff --git a/matlab/step5_tco.m b/matlab/step5_tco.m index a4385e4..c0c46f6 100644 --- a/matlab/step5_tco.m +++ b/matlab/step5_tco.m @@ -34,6 +34,7 @@ end function ret = EVAL(ast, env) while true + %fprintf('EVAL: %s\n', printer.pr_str(ast, true)); if ~types.list_Q(ast) ret = eval_ast(ast, env); return; diff --git a/matlab/step6_file.m b/matlab/step6_file.m index cfca152..6a9476d 100644 --- a/matlab/step6_file.m +++ b/matlab/step6_file.m @@ -34,6 +34,7 @@ end function ret = EVAL(ast, env) while true + %fprintf('EVAL: %s\n', printer.pr_str(ast, true)); if ~types.list_Q(ast) ret = eval_ast(ast, env); return; @@ -120,7 +121,7 @@ function main(args) rep('(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))"', repl_env); if ~isempty(args) - rep(strcat('(load-file "', args{1}, '")'), repl_env); + rep(sprintf('(load-file "%s")', args{1}), repl_env); quit; end diff --git a/matlab/step7_quote.m b/matlab/step7_quote.m index cb572a6..3d1149a 100644 --- a/matlab/step7_quote.m +++ b/matlab/step7_quote.m @@ -57,6 +57,7 @@ end function ret = EVAL(ast, env) while true + %fprintf('EVAL: %s\n', printer.pr_str(ast, true)); if ~types.list_Q(ast) ret = eval_ast(ast, env); return; @@ -148,7 +149,7 @@ function main(args) rep('(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))"', repl_env); if ~isempty(args) - rep(strcat('(load-file "', args{1}, '")'), repl_env); + rep(sprintf('(load-file "%s")', args{1}), repl_env); quit; end diff --git a/matlab/step8_macros.m b/matlab/step8_macros.m index 8757c7a..5567649 100644 --- a/matlab/step8_macros.m +++ b/matlab/step8_macros.m @@ -76,6 +76,7 @@ end function ret = EVAL(ast, env) while true + %fprintf('EVAL: %s\n', printer.pr_str(ast, true)); if ~types.list_Q(ast) ret = eval_ast(ast, env); return; @@ -182,7 +183,7 @@ function main(args) rep('(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))', repl_env); if ~isempty(args) - rep(strcat('(load-file "', args{1}, '")'), repl_env); + rep(sprintf('(load-file "%s")', args{1}), repl_env); quit; end diff --git a/matlab/step9_try.m b/matlab/step9_try.m index a9bf92f..1f338b2 100644 --- a/matlab/step9_try.m +++ b/matlab/step9_try.m @@ -76,6 +76,7 @@ end function ret = EVAL(ast, env) while true + %fprintf('EVAL: %s\n', printer.pr_str(ast, true)); if ~types.list_Q(ast) ret = eval_ast(ast, env); return; @@ -201,7 +202,7 @@ function main(args) rep('(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))', repl_env); if ~isempty(args) - rep(strcat('(load-file "', args{1}, '")'), repl_env); + rep(sprintf('(load-file "%s")', args{1}), repl_env); quit; end diff --git a/matlab/stepA_interop.m b/matlab/stepA_interop.m index f9e3364..5b8e720 100644 --- a/matlab/stepA_interop.m +++ b/matlab/stepA_interop.m @@ -76,6 +76,7 @@ end function ret = EVAL(ast, env) while true + %fprintf('EVAL: %s\n', printer.pr_str(ast, true)); if ~types.list_Q(ast) ret = eval_ast(ast, env); return; @@ -202,7 +203,7 @@ function main(args) rep('(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))', repl_env); if ~isempty(args) - rep(strcat('(load-file "', args{1}, '")'), repl_env); + rep(sprintf('(load-file "%s")', args{1}), repl_env); quit; end diff --git a/matlab/types.m b/matlab/types.m index 91f052d..4d78f91 100644 --- a/matlab/types.m +++ b/matlab/types.m @@ -45,8 +45,8 @@ classdef types end function ret = keyword(str) - ret = strcat(native2unicode(hex2dec('029e'),'UTF-8'), ... - str(2:end)); + ret = sprintf('%s%s', native2unicode(hex2dec('029e'),'UTF-8'), ... + str(2:end)); end function ret = keyword_Q(obj) ret = length(obj) > 1 && ... |
