summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-11-28 18:58:25 -0800
committerKaz Kylheku <kaz@kylheku.com>2011-11-28 18:58:25 -0800
commit57bfb0fa5d8803fe9df5f1dac672b689e5f4e3d3 (patch)
tree08f536f7caecc9239ff76842406d1a3dcb7cbbe0 /lib.c
parentb133159cf56dba53c53b3cbc05f7907a60bb7441 (diff)
downloadtxr-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 'lib.c')
-rw-r--r--lib.c56
1 files changed, 29 insertions, 27 deletions
diff --git a/lib.c b/lib.c
index 63893f0b..fdf5758e 100644
--- a/lib.c
+++ b/lib.c
@@ -2970,11 +2970,11 @@ static void obj_init(void)
prog_string = string(progname);
}
-void obj_print(val obj, val out)
+val obj_print(val obj, val out)
{
if (obj == nil) {
put_string(out, lit("nil"));
- return;
+ return obj;
}
switch (type(obj)) {
@@ -3009,7 +3009,7 @@ void obj_print(val obj, val out)
}
}
}
- return;
+ return obj;
case LIT:
case STR:
{
@@ -3036,7 +3036,7 @@ void obj_print(val obj, val out)
}
put_char(out, chr('"'));
}
- return;
+ return obj;
case CHR:
{
wchar_t ch = c_chr(obj);
@@ -3060,10 +3060,10 @@ void obj_print(val obj, val out)
format(out, lit("x~x"), num(ch), nao);
}
}
- return;
+ return obj;
case NUM:
format(out, lit("~s"), obj, nao);
- return;
+ return obj;
case SYM:
if (obj->s.package != user_package) {
if (!obj->s.package)
@@ -3073,13 +3073,13 @@ void obj_print(val obj, val out)
put_char(out, chr(':'));
}
put_string(out, symbol_name(obj));
- return;
+ return obj;
case PKG:
format(out, lit("#<package: ~s>"), obj->pk.name, nao);
- return;
+ return obj;
case FUN:
format(out, lit("#<function: type ~a>"), num(obj->f.functype), nao);
- return;
+ return obj;
case VEC:
{
cnum i, fill = c_num(obj->v.vec[vec_fill]);
@@ -3091,27 +3091,28 @@ void obj_print(val obj, val out)
}
put_char(out, chr(')'));
}
- return;
+ return obj;
case LSTR:
obj_print(obj->ls.prefix, out);
put_string(out, lit("#<... lazy string>"));
- return;
+ return obj;
case COBJ:
obj->co.ops->print(obj, out);
- return;
+ return obj;
case ENV:
format(out, lit("#<environment: ~p>"), (void *) obj, nao);
- return;
+ return obj;
}
format(out, lit("#<garbage: ~p>"), (void *) obj, nao);
+ return obj;
}
-void obj_pprint(val obj, val out)
+val obj_pprint(val obj, val out)
{
if (obj == nil) {
put_string(out, lit("nil"));
- return;
+ return obj;
}
switch (type(obj)) {
@@ -3146,26 +3147,26 @@ void obj_pprint(val obj, val out)
}
}
}
- return;
+ return obj;
case LIT:
case STR:
put_string(out, obj);
- return;
+ return obj;
case CHR:
put_char(out, obj);
- return;
+ return obj;
case NUM:
format(out, lit("~s"), obj, nao);
- return;
+ return obj;
case SYM:
put_string(out, symbol_name(obj));
- return;
+ return obj;
case PKG:
format(out, lit("#<package: ~s>"), obj->pk.name, nao);
- return;
+ return obj;
case FUN:
format(out, lit("#<function: type ~a>"), num(obj->f.functype), nao);
- return;
+ return obj;
case VEC:
{
cnum i, fill = c_num(obj->v.vec[vec_fill]);
@@ -3177,20 +3178,21 @@ void obj_pprint(val obj, val out)
}
put_char(out, chr(')'));
}
- return;
+ return obj;
case LSTR:
obj_pprint(obj->ls.prefix, out);
put_string(out, lit("..."));
- return;
+ return obj;
case COBJ:
obj->co.ops->print(obj, out);
- return;
+ return obj;
case ENV:
format(out, lit("#<environment: ~p>"), (void *) obj, nao);
- return;
+ return obj;
}
format(out, lit("#<garbage: ~p>"), (void *) obj, nao);
+ return obj;
}
void init(const wchar_t *pn, mem_t *(*oom)(mem_t *, size_t),
@@ -3204,8 +3206,8 @@ void init(const wchar_t *pn, mem_t *(*oom)(mem_t *, size_t),
gc_init(stack_bottom);
obj_init();
uw_init();
- eval_init();
stream_init();
+ eval_init();
filter_init();
gc_state(gc_save);