diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2011-11-28 18:58:25 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2011-11-28 18:58:25 -0800 |
commit | 57bfb0fa5d8803fe9df5f1dac672b689e5f4e3d3 (patch) | |
tree | 08f536f7caecc9239ff76842406d1a3dcb7cbbe0 /eval.c | |
parent | b133159cf56dba53c53b3cbc05f7907a60bb7441 (diff) | |
download | txr-57bfb0fa5d8803fe9df5f1dac672b689e5f4e3d3.tar.gz txr-57bfb0fa5d8803fe9df5f1dac672b689e5f4e3d3.tar.bz2 txr-57bfb0fa5d8803fe9df5f1dac672b689e5f4e3d3.zip |
Adding streams functions to Lisp evaluator.
* eval.c (op_let): Bugfix: was not evaluating var init forms.
(reg_var): New static function.
(eval_init): Registered numerous stream functions and the
three standard streams.
* lib.c (obj_print, obj_pprint): Modified to return a value.
(init): eval_init called after stream_init, because eval
needs the three standrad streams prepared.
* lib.h (obj_print, obj_pprint): Declarations updated.
* stream.c (format): Support t as a shorthand for standard output.
(formatv, open_directory, open_file, open_pipe): New functions.
(w_opendir): New static function.
* stream.h (formatv, open_directory, open_file, open_pipe):
Declared.
* txr.vim: set iskeyword such that keyword can contain special
characters. Set b:current_syntax to "lisp".
(txl_keyword): New keyword category populated with TXR Lisp keywords
defined as separate category.
(txr_list): Contains txl_keyword.
(txr_meta): Contains txl_keyword and txr_list.
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 31 |
1 files changed, 30 insertions, 1 deletions
@@ -359,7 +359,7 @@ static val op_let(val form, val env) if (!consp(cdr(item))) eval_error(form, lit("let: invalid syntax: ~s"), item, nao); var = first(item); - val = second(item); + val = eval(second(item), env, form); } if (symbolp(var)) { @@ -766,6 +766,11 @@ static void reg_fun(val sym, val fun) sethash(top_fb, sym, cons(sym, fun)); } +static void reg_var(val sym, val obj) +{ + sethash(top_vb, sym, cons(sym, obj)); +} + void eval_init(void) { protect(&top_vb, &top_fb, &op_table, (val *) 0); @@ -858,6 +863,30 @@ void eval_init(void) reg_fun(intern(lit("eval"), user_package), func_n2(eval_intrinsic)); + reg_var(intern(lit("*stdout*"), user_package), std_output); + reg_var(intern(lit("*stdin*"), user_package), std_input); + reg_var(intern(lit("*stderr*"), user_package), std_error); + reg_fun(intern(lit("format"), user_package), func_n2v(formatv)); + reg_fun(intern(lit("print"), user_package), func_n2(obj_print)); + reg_fun(intern(lit("pprint"), user_package), func_n2(obj_pprint)); + reg_fun(intern(lit("make-string-input-stream"), user_package), func_n1(make_string_input_stream)); + reg_fun(intern(lit("make-string-byte-input-stream"), user_package), func_n1(make_string_byte_input_stream)); + reg_fun(intern(lit("make-string-output-stream"), user_package), func_n0(make_string_output_stream)); + reg_fun(intern(lit("get-string-from-stream"), user_package), func_n1(get_string_from_stream)); + reg_fun(intern(lit("make-strlist-output-stream"), user_package), func_n0(make_strlist_output_stream)); + reg_fun(intern(lit("get-list-from-stream"), user_package), func_n1(get_list_from_stream)); + reg_fun(intern(lit("close-stream"), user_package), func_n2(close_stream)); + reg_fun(intern(lit("get-line"), user_package), func_n1(get_line)); + reg_fun(intern(lit("get-char"), user_package), func_n1(get_char)); + reg_fun(intern(lit("get-byte"), user_package), func_n1(get_byte)); + reg_fun(intern(lit("put-string"), user_package), func_n2(put_string)); + reg_fun(intern(lit("put-line"), user_package), func_n2(put_line)); + reg_fun(intern(lit("put-char"), user_package), func_n2(put_char)); + reg_fun(intern(lit("flush-stream"), user_package), func_n1(flush_stream)); + reg_fun(intern(lit("open-directory"), user_package), func_n1(open_directory)); + reg_fun(intern(lit("open-file"), user_package), func_n2(open_file)); + reg_fun(intern(lit("open-pipe"), user_package), func_n2(open_pipe)); + eval_error_s = intern(lit("eval-error"), user_package); uw_register_subtype(eval_error_s, error_s); } |