summaryrefslogtreecommitdiffstats
path: root/stream.c
Commit message (Collapse)AuthorAgeFilesLines
* * stream.c (vformat): If width is specified for ~s or ~a, andKaz Kylheku2011-12-221-1/+7
| | | | | | | the object is not a string or number, then print it to a string and treat it as a string, adjusting it within the field. Also, do not simply abort on an unknown format directive but throw a proper exception.
* * stream.c (vformat): Left-adjusted field is now specifiedKaz Kylheku2011-12-221-11/+9
| | | | | using < rather than '-'. The +, space and leading 0 are specified on the precision, not the width.
* * stream.c (vformat): Combine ~a and ~s cases, so numbers andKaz Kylheku2011-12-221-30/+6
| | | | | strings are printed the same way under ~s and ~a. The only difference is printing other kinds of objects.
* Bug #35026Kaz Kylheku2011-12-221-14/+32
| | | | | | | | | | | * stream.c (format_num): New argument: sign character. Rewrote to handle precision, width, zero padding and leading sign similarly to printf. (vformat): New syntax accepted: a space or + before the width specifies that a positive sign is to be explicitly written as a space or + character. Pass one more argument to vormat_num calls. Bugfix: go back to vf_init state after processing ~~.
* Bignum support, here we go!Kaz Kylheku2011-12-091-14/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Bignums, based on Michael Fromberger's MPI library, are integrated into the input syntax, stream output, equality testing, the garbage collector, and hashing. The plus operation handles transitions between fixnums and bignums. Other operations are still fixnum only. * Makefile (CFLAGS): Add mpi directory to include file search. (OBJS): Include new arith.o module and all of MPI_OBJS. (MPI_OBJS, MPI_OBJS_BASE): New variables. * configure (mpi_version, have_quilt, have_patch): New variables. Script detects whether patch and quilt are available. Unpacks mpi library, applies patches. Detects 128 bit integer type. Records more information in config.h about the sizes of types. * dep.mk: Updated. * depend.txr: Make work with paths that have directory components. * eval.c (eval_init): Rename of nump to fixnump. * gc.c (finalize, mark_obj): Handle BGNUM case. * hash.c: (hash_c_str): Changed to return unsigned long instead of long. (equal_hash): Handle BGNUM case. (eql_hash): Handle bignums with equal-hash, but other objects as eq. * lib.c (num_s): Variable renamed to fixnum_s. (bignum_s): New symbol variable. (code2type): Follow rename of num_s. Handle BGNUM case. (typeof): Follow rename of num_s. (eql): Handle bignums using equal, and other types using eq. (equal): Handle BGNUM case. (chk_calloc): New function. (c_num): Wording change in error message: is not a fixnum. (nump): Renamed to fixnump. (bignump): New function. (plus): Function removed, reimplemented in arith.c. (int_str): Handle integers which are too large for wcstol using bignum conversion. Base 0 is no longer passed to wcstol but converted to 10 because the special semantics for 0 would be inconsistent for bignums. (obj_init): Follow rename of num_s. Initialize bignum_s.
* * stream.c (find_char): New function.Kaz Kylheku2011-12-061-3/+18
| | | | | | | | | (string_in_get_line): Following up TODO. Fixed broken function. Now get_line on a string stream properly returns characters up to and not including the next newlne character, and also consumes the newline character. Other cases are handled properly, also: the stream being at EOF already, or at the last line not being newline-terminated.
* * eval.c (op_unwind_protect): Fixed uninitialized variableKaz Kylheku2011-12-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | warning. (eval_init): New functions registered: typeof and vector functions, as well as length_list. * lib.c (length): Function renamed to length_list, because it is list specific. (length_vec, size_vec, vector_list): New functions. (length): New function, generic over lists, vectors and strings. * lib.h (length_list, length_vec, size_vec, vector_list): Declared. * match.c (h_var, h_fun, robust_length, v_deffilter, v_fun): Use length_list instead of length. * parser.l: Introduced # token. * parser.y (vector): New nonterminal. (expr): vector is a kind of expr. (chrlist): Bugfix: single-character syntax was not working; for instance #\x to denote the charcter x. (lit_char_helper): Use length_list instead of length. * stream.c (string_in_get_line): Bugfix: this was using the wrong length function: length was being applied to a string. The genericity of length makes that correct now, but changing to length_str anyway. * txr.1: Blank sections created for functions. Vector syntax documented.
* * lib.h (or2): Restore macro version of or2, because we needKaz Kylheku2011-11-301-0/+1
| | | | | | | | | | | | | | | | | | | | the sequencing! Making it an inline function broke the tests. But we can't have multiple evaluation either, so it's going to use a temporary lexical variable. (uses_or2): Macro which declares the lexical variable needed by or2. * debug.c (debug): add uses_or2. * eval.c (eval_intrinsic, op_modplace): Likewise. * lib.c (lazy_str, lazy_str_force_upto, lazy_str_get_trailing_list): Likewise. * match.c (h_parallel, v_freeform, v_parallel, v_output): Likewise. * parser.y (unquotes_occur): Likewise. * stream.c (format): Likewise.
* Adding streams functions to Lisp evaluator.Kaz Kylheku2011-11-281-1/+111
| | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Task #11436Kaz Kylheku2011-11-261-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Lisp interpreter added. * gc.c (finalize, mark_obj): Handle ENV objects. * hash.c (struct hash): acons_new_l_fun function pointer order of arguments change. (equal_hash): Handle ENV. (make_hash, gethash_l): Use cobj_handle for type safety. Follow change in acons_new_l. (gethash, gethash_f, remhash, hash_count, hash_get_userdata, hash_set_userdata, hash_next): Use cobj_handle. (gethash_n): New function. * hash.h (gethash_n): Declared. * lib.c (env_s): New symbol variable. (code2type, equal): Handle ENV. (plusv, minusv, mul, mulv, trunc, mod, gtv, ltv, gev, lev, maxv, minv, int_str): New functions. (rehome_sym): New static function. (func_f0, func_f1, func_f2, func_f3, func_f4, func_n0, func_n1, func_n2, func_n3, func_n4): Initialize new fields of struct func. (func_f0v, func_f1v, func_f2v, func_f3v, func_f4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_interp): New functions. (apply): Function removed: sanely re-implemented in new eval.c file. (funcall, funcall1, funcall2, funcall3, funcall4): Handle variadic and interpreted functions. (acons, acons_new, acons_new_l, aconsq_new, aconsq_new_l): Reordered arguments for compatibility with Common Lisp acons. (obj_init): Special hack to prepare hash_s symbol, which is needed for type checking inside the hash table funtions invoked by make_package, at a time when the symbol is not yet interned. Initialize new env_s variable. (obj_print, obj_pprint): Handle ENV. Fix confusing rendering of of function type. (init): Call new function eval_init. * lib.h (enum type): New enumeration member ENV. (struct func): functype member changed to bitfield. New bitfied members minparam and variadic. New members in f union: f0v, f1v, f2v, f3v, f4v, n0v, n1v, n2v, n3v, n4v. (struct env): New type. (union obj): New member e of type struct env. (env_s): Variable declared. (plusv, minusv, mul, mulv, trunc, mod, gtv, ltv, gev, lev, maxv, minv,
* Adding a debugger. This is an experimental prototype.Kaz Kylheku2011-11-131-3/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Makefile (OBJS): New object file debug.o. * dep.mk: Updated. * match.c (h_fun): Use debug_begin and debug_end macros to set up a debug frame for backtracing. (match_line, match_files): Call debug_check to give debugger a chance to instrument call. (v_fun): Use debug_begin and debug_end macros to set up a debug frame for backtracing. Call debug_check to give debugger a chance to instrument call. * stream.c (struct strm_ops): New function pointer, flush. (stdio_maybe_write_error): Wrong word in error message corrected. (stdio_flush): New static function. (stdio_ops, pipe_ops): New function entered into tables. (flush_stream): New function. * stream.h (flush_stream): Declared. * txr.c (help): New options documented. (main): call to debug_init added. New debug options parsed and opt_debugger set accordingly. * unwind.c (uw_push_debug, uw_current_frame): New function. * unwind.h (uw_frtype): New enumeration member UW_DBG. (struct uw_debug): New frame variant. (union uw_frame): New member, db. (uw_push_debug, uw_current_frame): Declared, * debug.c: New file. * debug.h: New file.
* Parse error handling improvements.Kaz Kylheku2011-10-261-2/+10
| | | | | | | | | | | | | | | | | | | | | | | | * parser.l (prepared_error_message): New static variable. (yyerror): Emit and clear prepared error message. (yyerrprepf): New static function. (yybadtoken): Function moved into parser.y. (grammar): For irrecoverable lexical errors, stash error message with yyerrprepf and return the special error token ERRTOK to generate a syntax error. I could find no other interface to the parser to make it cleanly exit. * parser.y (ERRTOK): New terminal symbol, does not appear anywhere in the grammar. (spec): Bail after 8 errors, recover to nearest newline, and use yyerrok to clear error situation. (YYEOF): Provided by Bison, conditionally defined for other yacc-s. (yybadtoken): Function moved from parser.l. Checks for the next token being YYEMPTY or YYEOF, and also handles ERRTOK. * stream.c (vformat_to_string): New function. (format): If stream is nil, format to string and return it. * stream.h (vformat_to_string): Declared.
* New features. Strling list output streams in streamKaz Kylheku2011-10-211-0/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | | library, allow output to be captured as a list of strings representing lines (in contrast to string streams which capture a single string). The output directive can output to a variable, and next can scan over a variable. * lib.c (span_str, compl_span_str, break_str): New functions. * lib.h (span_str, compl_span_str, break_str): New functions declared. * match.c (into_k, var_k): New keyword variables. (mf_file_data): New static function. (v_next): Refactored argument handling. Added support for :var keyword. (v_output): Added support for :into keyword. * stream.c (strlist_mark, strlist_out_put_string, strlist_out_put_char): New static functions. (strlist_out_ops): New static struct. (make_strlist_output_stream, get_list_from_stream): New functions. * stream.h (make_strlist_output_stream, get_list_from_stream): New functions declared.
* Whitespace.Kaz Kylheku2011-10-211-1/+1
|
* Quick and dirty port to MinGW.Kaz Kylheku2011-10-161-1/+5
| | | | | | | | | * configure: Test for presence of <sys/wait.h> added. Conditionally generates HAVE_SYS_WAIT variable in config.h. * stream.c: Include <sys/wait.h> conditionally. (pipe_close): Do not test ermination status with WIFEXITED, etc. if there is no <sys/wait.h> header.
* One more swing at this with the axe.Kaz Kylheku2011-10-091-12/+3
| | | | | | | * lib.h (wini, wref): New macros. * stream.c (string_out_put_char): Rewritten with macros to eliminate preprocessor #if test.
* Following up to previous commit's TODO.Kaz Kylheku2011-10-091-1/+2
| | | | | | | | | | | | | | | | | | | | | | * filter.c (struct filter_par): wchar_t becomes wchli_t. * lib.h (wchli_t): New type: an incomplete structure type, so that a pointer to this type is incompatible with anything else. (wli): Macro produces const wchli_t * pointer instead of const wchar_t *. (auto_str, static_str): Accept a const wchli_t * instead of const wchar_t *, making it impossible to misuse these functions by passing in a literal. * stream.c (string_out_put_char): These type changes showed this hack to have a bug. Confronted with the need to cast from const wchar_t * to const wchli_t *, it's obvious that the conversion has to be done properly with the + 1 in the one platform case, but not the other. * txr.c (version): Type changed to const wchli_t. * txr.h (version): Declaration updated.
* Ported to Cygwin.Kaz Kylheku2011-10-091-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | TODO: there should be some type safety with the new wli macro so that if it is forgotten, there will be a diagnostic. * configure (lit_align): New configuration variable and configuration test. Generates LIT_ALIGN in config.h. Fixed the integer-holds-pointer test for the different output from the nm program on Cygwin. The arrays become common symbols marked C which do not show an offset attribute, only size: one less column. * filter.c (to_html_table, from_html_table): wrap wide string literals with the wli macro. This must be done from now on for all literals and initializes of arrays that are going to be directly converted to type tagged val-s. * lib.h (wli): New macro. (auto_str, static_str, litptr, lit_noex): Handle wide literals on platforms where they are aligned to only two bytes, such that we don't have two bits in the pointer. We can still add our 11 bit type tag, but then when recovering the pointer to the data, we have may have to fix up the pointer. * parser.l: Another portability issue here. Flex generates a scanner which has #include <unistd.h> in the middle, after the source file's own #includes which can introduce macros. On Cygwin, there is some hygiene problem whereby our "noreturn" macro causes the <unistd.h> header to generate bad syntax and fail to compile. Stupid Cygwin and even stupider flex! The workaround is to include <unistd.h> at the top in the flex source. * stream.c (string_out_put_char): This is one more place where the string literal handling hack spreads. * txr.c (version): Wrap string in wli.
* * LICENSE, Makefile, configure, filter.c, filter.h, gc.c, gc.h, hash.c,Kaz Kylheku2011-10-041-1/+1
| | | | | | hash.h, lib.c, lib.h, match.c, match.h, parser.h, parser.l, parser.y, regex.c, regex.h, stream.c, stream.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Updated e-mail address.
* Trie compression. Hash table iteration.Kaz Kylheku2011-09-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Bugfix in typeof. * filter.c (trie_compress): New function. (trie_value_at, trie_lookup_feed_char, filter_string): Handle cons cell nodes in trie. (build_filter): Call trie_compress. * gc.c (cobj_destroy_op): Function renamed to cobj_destroy_stub_op since it doesn't do anything. (cobj_destroy_free_op): New function. * hash.c (struct hash_iter): New type. (hash_destroy): Function removed. (hash_ops): Reference to hash_destroy replaced with cobj_destroy_free_op. (hash_count, hash_iter_mark, hash_begin, hash_next): New functions. (hash_iter_ops): New static structure. * hash.h (hash_count, hash_begin, hash_next): New functions declared. * lib.c (hash_iter_s): New symbol variable. (typeof): Bugfix: TAG_LIT type tag not handled. (vecref): New function. (obj_init): Initialize hash_iter_s. * lib.h (cobj_destroy_op): Declaration renamed. (cobj_destroy_free_op, vecref): New functions declared. (hash_iter_s): New variable declared. * stream.c (string_in_ops, byte_in_ops): cobj_destroy_op renamed to cobj_destroy_stub_op.
* * LICENSE, Makefile, configure, gc.c, gc.h, hash.c, hash.h, lib.c,Kaz Kylheku2011-09-231-1/+1
| | | | | | lib.h, match.c, match.h, parser.h, parser.l, parser.y, regex.c, regex.h, stream.c, stream.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Updated copyright year.
* Bump copyrights to 2010.Kaz Kylheku2010-10-051-1/+1
|
* * stream.c (vformat_num): Fix bad width calculation.Kaz Kylheku2010-01-241-1/+1
|
* All COBJ operations have default implementations now;Kaz Kylheku2009-12-081-22/+17
| | | | | | no null pointer check over struct cobj_ops operations. New typechecking function for COBJ objects.
* More void * to mem_t * conversion.Kaz Kylheku2009-12-051-6/+6
|
* Eliminate the void * disease. Generic pointers are of mem_t *Kaz Kylheku2009-12-041-10/+11
| | | | | from now on, which is compatible with unsigned char *. No implicit conversion to or from this type, in C or C++.
* Code cleanup. All private functions static. Private stuffKaz Kylheku2009-11-281-8/+8
| | | | in regex module not exposed in header. Etc.
* Whitespace.Kaz Kylheku2009-11-241-1/+1
|
* Renaming global variables that denote symbols, such that theyKaz Kylheku2009-11-241-25/+25
| | | | have a _s suffix.
* Follow up on 64 bit compilation warnings.Kaz Kylheku2009-11-231-1/+1
|
* Improving portability. It is no longer assumed that pointersKaz Kylheku2009-11-231-7/+48
| | | | | | | | can be converted to a type long and vice versa. The configure script tries to detect the appropriate type to use. Also, some run-time checking is performed in the streams module to detect which conversions specifier strings to use for printing numbers.
* Introducing symbol packages. Internal symbols are now inKaz Kylheku2009-11-211-2/+7
| | | | | | | | | | a system package instead of being hacked with the $ prefix. Keyword symbols are provided. In the matcher, evaluation is tightened up. Keywords, nil and t are not bindeable, and errors are thrown if attempts are made to bind them. Destructuring in dest_bind is strict in the number of items. String streams are exploited to print bindings to objects that are not strings or characters. Numerous bugfixes.
* Changing ``obj_t *'' occurences to a ``val'' typedef. (Ideally,Kaz Kylheku2009-11-201-86/+86
| | | | | we wouldn't have to declare object variables at all, so why use an obtuse syntax to do so?)
* Following-up on diagnostics obtained by running code through C++Kaz Kylheku2009-11-181-4/+5
| | | | | | compiler. Idea: allocator functions return char * instead of void *, like malloc did in classic pre-ANSI C. That way we are forced to use a cast except when the target pointer is char * already.
* More removal of C99 wide character I/O, and tightening upKaz Kylheku2009-11-171-0/+1
| | | | of standard conformance.
* Removing use of C99 wide character I/O.Kaz Kylheku2009-11-171-52/+39
|
* Warning fixes.Kaz Kylheku2009-11-171-3/+9
|
* Big round of changes to switch the code base to use the streamKaz Kylheku2009-11-161-202/+289
| | | | | | | | | | | | | | | | | abstraction instead of directly using C standard I/O, to eliminate most uses of C formatted I/O, and fix numerous bugs, such variadic argument lists which lack a terminating ``nao'' sentinel. Bug 28033 is addressed by this patch, since streams no longer provide printf-compatible formatting. The native formatter is extended with some additional capabilities to take over. The work on literal objects is expanded and they are now used throughout the code base. Fixed bad realloc in string output stream: reallocating by number of wide chars rather than bytes.
* Version 021 preparation.txr-021Kaz Kylheku2009-11-151-2/+2
| | | | Bumped version numbers, and cleaned up trailing whitespace from some files.
* Provide both char * and unsigned char * interfaces in UTF-8 module.Kaz Kylheku2009-11-141-1/+1
| | | | Fix unsigned and plan char * mixing.
* Fixes for bug 28086. When constructing a cobj, whose associatedKaz Kylheku2009-11-141-4/+8
| | | | | | | | | | | | | | | | | C structure contains obj_t * references, we should initialize that C structure after allocating the cobj. If we initialize the structure first, it may end up having the /only/ references to the objects. In that case, the objects are invisible to the garbage collector. The subsquent allocation of the cobj itself then may invoke gc which will turn these objects into dust. The result is a cobj which contains a handle structure that contains references to free objects. The fix is to allocate the handle structure, then the cobj which is associated with that handle, and then initialize the handle, at which point it is okay if the handle has the only references to some objects. Care must be taken not to let a cobj escape with a partially initialized handle structure, and not to trigger gc between allocating the cobj, and initializing the fields.
* Previous commit broke UTF-8 lexing, by changing the get_charKaz Kylheku2009-11-131-0/+72
| | | | | | | | semantics on the input stream to wide character input. Also, reading a query the command line (-c) must read bytes from a UTF-8 encoding of the string. We introduce a new get_byte function which can extract bytes from streams which provide it.
* Continuing wchar_t conversion. Making sure all stdio callsKaz Kylheku2009-11-121-26/+15
| | | | | use wide character functions so that there is no illicit mixing. (But the goal is to replace this usage with txr streams).
* Documenting extended characters in man page.Kaz Kylheku2009-11-121-13/+47
| | | | Cleaned up some more issues related to extended characters.
* Big conversion to wide characters and UTF-8 support.Kaz Kylheku2009-11-111-57/+71
| | | | | | | | | This is incomplete. There are too many dependencies on wide character support from the C stream I/O library, and implicit use of some encoding which may not be UTF-8. The regex code does not handle wide characters properly. Character type is still int in some places, rather than wchar_t. Test suite passes though.
* Throw exception on stream error during close, or I/O operations. ThisKaz Kylheku2009-11-061-47/+129
| | | | | | is needed for pipes that terminate abnormally or return failed termination. Pipe and stdio streams have an extra description field so they are printed in a readable way.
* Bug ID 27895: Calls to protect have an argument list terminatedKaz Kylheku2009-11-011-1/+1
| | | | by the integer constant 0 rather than a proper null pointer constant.
* Version 019txr-019Kaz Kylheku2009-11-031-6/+6
| | | | | | Regexps can be bound to variables. New freeform directive.
* Start of implementation for freestyle matching.Kaz Kylheku2009-11-021-3/+3
| | | | | | | | | | | Lazy strings implemented, incompletely. Changed string function to implicitly strdup; non-strdup version changed to string_own. Fixed wrong uses of strdup rather than chk_strdup. Functions added to regex module to provide regex matching as a state machine to which characters are fed.
* txr-015 2009-10-15txr-015Kaz Kylheku2017-07-311-0/+641