diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2013-12-05 23:18:35 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2013-12-05 23:18:35 -0800 |
commit | f128b3e3f1ab9fb724d09486b59ae2a2b4cab29c (patch) | |
tree | 0f71acbb110df777c7e30b90c32525e8bd8a9d3e /stream.c | |
parent | 7563a6d0330a4ac02e3e0df169d35f9f395b8d71 (diff) | |
download | txr-f128b3e3f1ab9fb724d09486b59ae2a2b4cab29c.tar.gz txr-f128b3e3f1ab9fb724d09486b59ae2a2b4cab29c.tar.bz2 txr-f128b3e3f1ab9fb724d09486b59ae2a2b4cab29c.zip |
* eval.c (eval_init): Registered regex_parse as new
intrinsic function and std_null as new variable.
* parser.h (yylex_destroy): Existing function declared.
* parser.l (regex_parse): New function.
New lexical syntax added which returns SECRET_ESCAPE_R.
* parser.y (SECRET_ESCAPE_R): New token.
(spec): Added syntactic variant which lets us
smuggle a regex into the parser easily.
* stream.c:x (std_null): New global variable.
(null_stream_print): New static function.
(null_ops): New static structure.
(make_null_stream): New function.
(stream_init): Protect and initialize std_null.
* stream.h (std_null, make_null_stream): Declared.
* txr.1: New features documented: regex-parse, *stdnull*.
* txr.c (txr_main): Call yylex_destroy after parsing the program now
that I know about this function; this can free up some memory.
Diffstat (limited to 'stream.c')
-rw-r--r-- | stream.c | 34 |
1 files changed, 32 insertions, 2 deletions
@@ -51,7 +51,7 @@ #include "stream.h" #include "utf8.h" -val std_input, std_output, std_debug, std_error; +val std_input, std_output, std_debug, std_error, std_null; val output_produced; val dev_k, ino_k, mode_k, nlink_k, uid_k; @@ -91,6 +91,35 @@ static void common_destroy(val obj) (void) close_stream(obj, nil); } +static void null_stream_print(val stream, val out) +{ + format(out, lit("#<~s null>"), stream->co.cls, nao); +} + +static struct strm_ops null_ops = { + { cobj_equal_op, + null_stream_print, + cobj_destroy_stub_op, + cobj_mark_op, + cobj_hash_op }, + 0, /* put_string */ + 0, /*_put_char */ + 0, /* put_byte, */ + 0, /* get_line, */ + 0, /* get_char, */ + 0, /* get_byte, */ + 0, /* close, */ + 0, /* flush, */ + 0, /* seek, */ + 0, /* get_prop, */ + 0, /* set_prop */ +}; + +val make_null_stream(void) +{ + return cobj((mem_t *) 0, stream_s, &null_ops.cobj_ops); +} + struct stdio_handle { FILE *f; val descr; @@ -1951,11 +1980,12 @@ val open_process(val name, val mode_str, val args) void stream_init(void) { - protect(&std_input, &std_output, &std_debug, &std_error, (val *) 0); + protect(&std_input, &std_output, &std_debug, &std_error, &std_null, (val *) 0); std_input = make_stdio_stream(stdin, string(L"stdin")); std_output = make_stdio_stream(stdout, string(L"stdout")); std_debug = make_stdio_stream(stdout, string(L"debug")); std_error = make_stdio_stream(stderr, string(L"stderr")); + std_null = make_null_stream(); detect_format_string(); dev_k = intern(lit("dev"), keyword_package); |