summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* ffi: provide mmap through carray.Kaz Kylheku2021-08-226-0/+953
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * configure: configure test for mmap depositing HAVE_MMAP into config.h. * ffi.c (struct carray): Subject to HAVE_MMAP, new mm_len member which keeps track of the size of an underlying mapping so that we can unmap it, as well as peform operations like msync on it. (make_carray): Initialize mm_len to 0. (MAP_GROWSDOWN, MAP_LOCKED, MAP_NORESERVE, MAP_POPULATE, MAP_NONBLOCK, MAP_STACK, MAP_HUGETLB, MAP_SHARED, MAP_PRIVATE, MAP_FIXED, MAP_ANON, MAP_HUGE_SHIFT, MAP_HUGE_MASK, PROT_READ, PROT_WRITE, PROT_EXEC, PROT_NONE, PROT_GROWSDOWN, PROT_GROWSUP, MADV_NORMAL, MADV_RANDOM, MADV_SEQUENTIAL, MADV_WILLNEED, MADV_DONTNEED, MADV_FREE, MADV_REMOVE, MADV_DONTFORK, MADV_DOFORK, MADV_MERGEABLE, MADV_UNMERGEABLE, MADV_HUGEPAGE, MADV_NOHUGEPAGE, MADV_DONTDUMP, MADV_DODUMP, MADV_WIPEONFORK, MADV_KEEPONFORK, MADV_HWPOISON, MS_ASYNC, MS_SYNC, MS_INVALIDATE): #define as 0 if missing. (carray_munmap_op): New static function. (carray_mmap_ops): New static structure. (mmap_wrap, munmap_wrap): New functions. (mmap_op): New static function. (mprotect_wrap, madvise_wrap, msync_wrap): New functions. (ffi_init): Register mmap, munmap, mprotect, madvise and msync as well as numerous integer variables: map-growsdown, map-locked, map-noreserve, map-populate, map-nonblock, map-stack, map-hugetlb, map-shared, map-private, map-fixed, map-anon, map-huge-shift, map-huge-mask, prot-read, prot-write, prot-exec, prot-none, prot-growsdown, prot-growsup, madv-normal, madv-random, madv-sequential, madv-willneed, madv-dontneed, madv-free, madv-remove, madv-dontfork, madv-dofork, madv-mergeable, madv-unmergeable, madv-hugepage, madv-nohugepage, madv-dontdump, madv-dodump, madv-wipeonfork, madv-keeponfork, madv-hwpoison, ms-async, ms-sync, ms-invalidate, page-size. * ffi.h (mmap_wrap, munmap_wrap, mprotect_wrap madvise_wrap, msync_wrap): Declared. * tests/017/mmap.tl: New file. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* doc: misspelled cond in ecase section.Kaz Kylheku2021-08-221-1/+1
| | | | * txr.1: Fix cond to codn.
* sub: allow generic iterables.Kaz Kylheku2021-08-223-4/+109
| | | | | | | | | | | | | | | | In this patch we allow the s in (sub s from to) and [s from..to] to be any iterable. * lib.c (iter_dynamic, sub_iter): New static function. (generic_funcall): Handle all objects via the sequence case: ref, sub and all that. Unfortunately, we lose some error handling at the level of the sub function. But we allow any iterable to be passed through to sub. (sub): Handle default case through sub_iter. * tests/012/iter.tl: New cases. * txr.1: Documented.
* iter-begin: allow iterator argument.Kaz Kylheku2021-08-222-0/+16
| | | | | | | | * lib.c (seq_iter_init_with_info): Allow the iterated object to be an iterator, in which case a copy of the iterator is set up. * txr.1: Documented.
* sub-list: better handling of from value of t.Kaz Kylheku2021-08-221-4/+2
| | | | | | | | * lib.c (sub_list): If from is t, then just return nil. Do not reset it to nil in this case. After this we know from is not nil; we don't have to check for this inside one loop. That loop was wastefully iterating over the list in the from == nil case only to calculate nil.
* iter-begin: string range support.Kaz Kylheku2021-08-223-3/+178
| | | | | | | | | | | | | | Ranges like "AAA".."ZZZ" are now possible. * lib.c (seq_iter_get_range_str, seq_iter_peek_range_str, seq_iter_get_rev_range_str): New static functions. (seq_iter_init_with_info): Support string ranges via above new functions. Range direction test is now done with less and equal rather than lt and gt. * tests/012/iter.tl: New file. * txr.1: Documented.
* ecase: diagnose bad syntax.Kaz Kylheku2021-08-211-0/+4
| | | | * eval.c (me_ecase): Diagnose missing test form, like me_case.
* configure: implement full-repl option.Kaz Kylheku2021-08-205-39/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch unbundles the building of the full-featured REPL from HAVE_TERMIOS. We make it subject to its own configuration option CONFIG_FULL_REPL, which is 1 by default. This way, the downstream users or package maintainers can build TXR without the full-featured REPL even if HAVE_TERMIOS is 1, and the other termios material is built-in. * configure (full_repl): New variable. (help): Include full-repl in the help text. In the termios test, if we don't detect termios, then negate the full_repl variable. In the final config variable generation section, generate the CONFIG_FULL_REPL 1 define in config.h, if full_repl is true, ensuring it is subject to HAVE_TERMIOS, too. * linenoise/linenoise.c: Replace HAVE_TERMIOS with CONFIG_FULL_REPL. * linenoise/linenoise.h: Likewise. * parser.c: Likewise. * txr.c: Likewise and ... (if_termios): Macro renamed to if_full_repl. (if_full_repl): New macro. (opt_noninteractive): Use if_full_repl macro for initializing. (banner): Use if_ful_repl macro instead of if_termios.
* listener: additional reductions in non-termios build.Kaz Kylheku2021-08-203-6/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * linenoise/linenoise.c (struct lino_state): these members are now absent in non-termios build: atom_callback, ca_ctx, rawmode, mlmode, clip, result, buf, plen, pos, sel, end, len, dlen, dpos, dsel, dend, cols, oldrow, maxrows, history_index, need_resize, need_refresh, selmode, selinclusive, noninteractive and undo_stack. (lino_set_multiline, lino_get_multiline, lino_set_selinclusive, lino_get_selinculsive, lino_set_noninteractive, lino_get_noninteractive, lino_set_atom_cb): Functions now only defined in termios build. (linenoise): Adjustments for missing members in non-termios mode. (lino_make): We no longer need to set noninteractive to 1 in non-termios build. The flag no longer exists. (lino_copy, lino_cleanup): Avoid referencing nonexistent members in non-termios build. (lino_set_result): Another termios-only function. * linenoise/linenoise.h (lino_set_result, lino_clear_screen, lino_set_multiline, lino_get_multiline, lino_set_selinclusive, lino_get_selinculsive, lino_set_noninteractive, lino_get_noninteractive, lino_atom_cb_t, lino_set_atom_cb): Declare only in termios build. * parser.c (repl): Add #if HAVE_TERMIOS to avoid using linenoise features not available in non-termios build, and to remove any variables that thus become unused.
* listener: unbundle from termios.Kaz Kylheku2021-08-206-47/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes the conceptual issue that when there is no termios support (HAVE_TERMIOS is absent/false), then there is no listener at all, even though the listener supports plain mode that doesn't require termios. * Makefile (linenoise/linenoise.o): Link in unconditionally, not subject to have_termios. * linenoise.c: Include termios-related header only if HAVE_TERMIOS. (struct lino_state): Define the completion_callback and orig_termios members only if HAVE_TERMIOS. (wcnsprintf, atexit_handler, enable_raw_mode, disable_raw_mode, get_cursor_position, get_columns, lino_clear_screen, refresh_line, handle_resize, generate_beep, delete_undo, free_undo_stack, record_undo, record_triv_undo, remove_noop_undo, restore_undo, undo_subst_hist_idx, undo_renumber_hist_idx, free_completions, sync_data_to_buf, compare_completions, complete_line, lino_set_completion_cb, lino_add_completion, next_hist_match, copy_display_params, history_search, ab_init, ab_append, ab_free, sync_data_to_buf, copy_display_params, refresh_singleline, col_offset_in_str, refresh_multiline, refresh_line, move_cursor_multiline, move_cursor, scan_match_rev, scan_rev, scan_match_fwd, scan_fwd, find_nearest_paren, usec_delay, paren_jump, flash, yank, yank_by_ptr, update_sel, clear_sel, yank_sel, delete_sel, edit_insert, edit_insert_str, edit_move_left, edit_move_right, edit_move_home, edit_move_sol, edit_move_end, edit_move_eol, edit_move_matching_paren, edit_history_next, edit_delete, edit_backspace, edit_delete_prev_all, edit_delete_to_eol, edit_delete_prev_word, edit_delete_line, tr, char, edit_in_editor, edit, sigwinch_handler): Functions defined only if HAVE_TERMIOS. (struct abuf, struct row_values): Struct types defined only if HAVE_TERMIOS. (screen_rows): Defined only if HAVE_TERMIOS. (linenoise): Support only noninteractive read loop unless HAVE_TERMIOS. (lino_make): If HAVE_TERMIOS is false, then set the noninteractive flag, so the linenoise function enters the plain-mode loop. (lino_cleanup, lino_hist_add): Add #ifdefs to avoid calling nonexistent functions when HAVE_TERMIOS is false. * linenoise/linenoise.h (struct lino_completions, lino_compl_cb_t): Define these types only if HAVE_TERMIOS. (lino_set_completion_cb, lino_add_completion): Declare only if HAVE_TERMIOS. * parser.c: Include linenoise/linenoise.h unconditionally. (report_security_problem, load_rcfile, repl_intr, read_eval_ret_last, get_home_path, repl_warning, is_balanced_line, hist_save): Now define regardless of HAVE_TERMIOS. (repl): Define regardless of HAVE_TERMIOS, but don't set completion or atom callback if HAVE_TERMIOS is false. * parser.h (repl): Declare unconditionally, not subject to HAVE_TERMIOS. * txr.c (if_termios): New macro. (opt_noninteractive): Initialize to 1 if HAVE_TERMIOS is false. (help): Text about entering into listener mode is always present now, even in a build withou HAVE_TERMIOS. (banner): Function is always defined. If we don't HAVE_TERMIOS, then the unused string literal that will never be printed is replaced by nil. (hint): Function removed. (txr_main): Blocks conditional on HAVE_TERMIOS that either call banner and go to the repl, or else call hint and exit, are reduced to unconditionally calling banner and going to the repl. All #if HAVE_TERMIOS blocks are similarly replaced with just the HAVE_TERMIOS case.
* matcher: rename error-throwing macros.Kaz Kylheku2021-08-195-24/+24
| | | | | | | | | | | | | | | * stdlib/match.tl (must-match): Renamed to just match. It's just when-match without the "when". (must-match-case): Renamed to match-ecase, consistent with the case -> ecase naming scheme. * lisplib.c (match_set_entries): Names updated here. * tests/011/patmatch.tl: Test cases updated. * txr.1: Names updated here. * stdlib/doc-syms.tl: Updated.
* hash: use unsigned, and operation.Kaz Kylheku2021-08-192-16/+16
| | | | | | | | | | | | | | | | * hash.c (struct hash): modulus and count change from cnum to ucnum. (hash_mark, hash_grow, copy_hash, do_weak_tables): Use ucnum local vars. (do_make_hash, make_similar_hash): Use c_unum to obtain modulus. (gethash_c, gethash_e): Use & masking operation to reduce hash value to table size. (remhash): Move sanity check before decrement since unsigned value can't go below zero. (clearhash): Use ucnum and c_unum. (hash_iter_peek): Use ucnum for chain count local. * hash.h (struct hash_iter): chain changes from cnum to ucnum.
* New ecase macros.Kaz Kylheku2021-08-183-1/+116
| | | | | | | | | | | | | | | | | | | | Even prior to discovering the recent defect in deffi, which was caused by a missing case in caseql, combined with poor testing, I was already thinking about adding ecase macros. The introduction of must-match and must-match-case also shows my motivation. That deffi bug convinced me to take action and implement these. * eval.c (case_error_s) New symbol variable. (me_ecase): New static function. (eval_init): Register new intrinsic macros ecaseq, ecaseql, ecasequal, ecaseq*, ecaseql* and ecasequal*. Intern case-error and initialize case_error_s. * txr.1: Documented. Also updated Exception Hierarchy diagram with match-error and case-error. * stdlib/doc-syms.tl: Updated.
* eval: de-duplicate built-in macro definitions.Kaz Kylheku2021-08-181-19/+26
| | | | | | | * eval.c (eval_init): Numerous macros share the same implementation function, and their registrations make wasteful repeated func_f2 calls to hoist that function from C to Lisp more than once. Let's go through and condense all of them.
* ffi: fix broken deffi support for variadic functions.Kaz Kylheku2021-08-173-1/+9
| | | | | | | | * stdlib/ffi.c (sys:analyze-argtypes): Add missing fallback case in filtering loop. This wouldn't have happened if we had a ecaseql macro, and used it. Or if we had coverage of this in tests. * tests/017/variadic.tl, tests/017/variadic.expected: New files.
* doc: fix reference to nonexistent ffi-call-desc.Kaz Kylheku2021-08-171-1/+1
| | | | * txr.1: ffi-call-desc should be ffi-make-call-desc.
* license: reformat to fit 80 columns.Kaz Kylheku2021-08-16121-2173/+2253
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Makefile, alloca.h, args.c, args.h, arith.c, arith.h, buf.c, buf.h, chksum.c, chksum.h, chksums/crc32.c, chksums/crc32.h, combi.c, combi.h, debug.c, debug.h, eval.c, eval.h, ffi.c, ffi.h, filter.c, filter.h, ftw.c, ftw.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, itypes.c, itypes.h, jmp.S, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, signal.c, signal.h, socket.c, socket.h, stdlib/asm.tl, stdlib/awk.tl, stdlib/build.tl, stdlib/compiler.tl, stdlib/constfun.tl, stdlib/conv.tl, stdlib/copy-file.tl, stdlib/debugger.tl, stdlib/defset.tl, stdlib/doloop.tl, stdlib/each-prod.tl, stdlib/error.tl, stdlib/except.tl, stdlib/ffi.tl, stdlib/getopts.tl, stdlib/getput.tl, stdlib/hash.tl, stdlib/ifa.tl, stdlib/keyparams.tl, stdlib/match.tl, stdlib/op.tl, stdlib/optimize.tl, stdlib/package.tl, stdlib/param.tl, stdlib/path-test.tl, stdlib/pic.tl, stdlib/place.tl, stdlib/pmac.tl, stdlib/quips.tl, stdlib/save-exe.tl, stdlib/socket.tl, stdlib/stream-wrap.tl, stdlib/struct.tl, stdlib/tagbody.tl, stdlib/termios.tl, stdlib/trace.tl, stdlib/txr-case.tl, stdlib/type.tl, stdlib/vm-param.tl, stdlib/with-resources.tl, stdlib/with-stream.tl, stdlib/yield.tl, stream.c, stream.h, struct.c, struct.h, strudel.c, strudel.h, sysif.c, sysif.h, syslog.c, syslog.h, termios.c, termios.h, time.c, time.h, tree.c, tree.h, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h, vm.c, vm.h, vmop.h: License reformatted. * lex.yy.c.shipped, y.tab.c.shipped, y.tab.h.shipped: Updated.
* format: bug: sign not reset before each conversion.Kaz Kylheku2021-08-162-11/+12
| | | | | | | | | | | | | | | | | | For instance, this bad output is produced: (pic "+0####.## <<<<<" 123 1) -> "+00123.00 +1 " The second argument should not have any leading + sign. * stream.c (formatv): For each new conversion specifier introduced by ~, reset the sign variable to zero also. That's the semantic change here, occluded by the fact that I'm rearranging the declaration of the variables, adding comments, and condensing the assignments while also getting them into the same order as the declarations, in order that this sort of bug does not creep in in the future, should another such variable be added. * tests/018/format.tl: Adding correct version of above test case.
* quips: new system-programming-related quips.Kaz Kylheku2021-08-161-0/+2
|
* doc-syms: update.Kaz Kylheku2021-08-151-3/+5
|
* getaddrinfo: implement canonname.Kaz Kylheku2021-08-153-5/+39
| | | | | | | | | | | | | | | | Paul A. Patience noted that the canonname_s variable is not used in the C code. This indicates that the AI_CANONNAME functionality of getaddrinfo isn't implemented. Let's do that. * stdlib/socket.tl (sockaddr): New slot, canonname. (addrinfo): Default canonname to nil, not 0, since it is a string that may be absent. * socket.c (getaddrinfo_wrap): If the first address object has a non-null ai_canonname and it was requested via the flags, then stick that name into every returned structure. * txr.1: Documented.
* doc: improve.Paul A. Patience2021-08-144-141/+149
| | | | | | | | | | | | * RELNOTES: Fix various minor issues and stylistic issues. * configure: Remove repeated word and add missing word. * txr.1: Fix various minor, not-so-minor and stylistic issues. In particular, struct-from-args was misspelled in the .mets line and open-subprocess was missing from the .coNP line. * stdlib/doc-syms.tl: Updated.
* ffi: remove redundant assignment.Paul A. Patience2021-08-141-1/+0
| | | | * ffi.c (int8_s): Remove redundant assignment.
* matcher: new must-match and must-match-case macros.Kaz Kylheku2021-08-134-5/+55
| | | | | | | | | | | | | * lisplib.c (match_set_entries): Intern the match-error symbol. Register autoloads for must-match and must-match-case. * stdlib/match.tl (match-error): Register exception symbol, as subtype of match-error. (must-match, must-match-case): New macros. * tests/011/patmatch.tl: Test cases. * txr.1: Documented.
* tests: support BSD flavors loosely, not just OpenBSD.Kaz Kylheku2021-08-135-5/+5
| | | | | | | | | | | | * tests/common.tl (os-symbol): Look for the substring BSD in the system name, and map to symbol :bsd. Do not produce the :openbsd symbol. * tests/014/socket-basic.tl: Refer to :bsd, not :openbsd. * tests/017/glob-carray.tl: Likewise. * tests/018/chmod.tl: Likewise.
* termios: FreeBSD has no TAB1 and TAB2.Kaz Kylheku2021-08-131-0/+8
| | | | | | * termios.c (termios_init): Separate the #ifdef conditions for the TAB* identifiers, instead of assuming that TABDLY covers them all.
* int-str: 0x bug.Kaz Kylheku2021-08-132-7/+58
| | | | | | | | | | | | | | | * lib.c (int_str): The problem here is that we are recognizing and skipping the 0x prefix for all bases. So for instance (int-str "0x123") produces 123. The correct requirement, and the intent of the code, is that the C conventions are only honored if the base is specified as the character #\c. In any other base, including omitted base defaulting to 10, a leading zero is just a leading zero, and 0x is a zero followed by the junk character x. Therefore, if we have any valid base that isn't #\c, and 0x has been seen, we must return zero. We must not do this only in the base 16 case. * tests/016/conv.tl: New file.
* configure: superfluous printf argument.Kaz Kylheku2021-08-131-4/+4
| | | | | | | * configure: In the test for an alignming malloc, fix a copy-and-paste error. The $try_header expansion is passed to printf, but there is nothing in the format string. FreeBSD printf diagnoses this and dies.
* parser: @(mdo) must not be subject to expand-meta.Kaz Kylheku2021-08-113-406/+411
| | | | | | | | | | | | | | | | | | | | * parser.y (elem): When the elem is a list, if it starts with mdo, then we evaluate it immediately and substitute (do) as the semantic value. We no longer not allow mdo to precipitate into match_expand_elem, where expand_meta will be unleashed on it. Doing so causes the bug that expessions like @1, denoting the form (sys:var 1), are rewritten to (sys:expr 1), which op syntax. So two bugs are fixed: the incorrect treatment of meta-syntax, and the neglect to perform mdo in nested contexts. (check_parse_time_action): We need not handle mdo here any more; it will never make it into this function. Only actions done in the main clause list belong here, not parse time actions done at any nesting level. * tests/008/mdo.txr: New file. * y.tab.c.shipped: Updated.
* txr: add tests for :nothrow handling process death.Kaz Kylheku2021-08-074-0/+12
| | | | | | | | | | * tests/007/except-3.txr: New file. * tests/007/except-3.expected: Likewise. * tests/007/except-4.txr: Likewise. * tests/007/except-4.expected: Likewise.
* Version 268.txr-268Kaz Kylheku2021-08-077-1351/+1390
| | | | | | | | | | | | | | * RELNOTES: Updated. * configure (txr_ver): Bumped version. * stdlib/ver.tl (lib-version): Bumped. * txr.1: Bumped version and date. * txr.vim, tl.vim: Regenerated. * protsym.c: Likewise.
* windows: skip test requiring full Unicode.Kaz Kylheku2021-08-071-0/+3
| | | | | * tests/012/cont.tl: Exit before the test case that contains characters ouside of the BMP, if (sizeof wchar) is less than 4.
* lazy-stream-cons: control close throwing behavior.Kaz Kylheku2021-08-076-20/+82
| | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (eval_init): Update registrations of lazy-stream-cons and get-lines with one more optional argument. * lib.c (simple_lazy_stream_func_nt, lazy_stream_func_nt): New static functions. (lazy_stream_cons): Take a new argument, no_throw_close, defaulting it to nil. When calling close_stream directly, pass the inverted value of no_throw_close. Choose the new _nt functions for the lazy list if no_throw_close is true; those functions pass nil as the second argument of close_stream. * lib.h (lazy_stream_cons): Declaration updated. * match.c (v_next_impl, open_data_source, match_fun): Pass down the nothrow value to lazy_stream_cons, or else nil in situations when that is not applicable or there is no such value. Thus the :nothrow feature of v_next will now not only ensure that there is no exception when opening the stream but also when closing it. Unusual situations encountered when the lazy list reads from the stream still throw. * txr.1: Documented.
* doc: document nested do.Kaz Kylheku2021-08-061-0/+55
| | | | * txr.1: Document do being applied to do/op.
* txr: @(eof) takes argument for binding termination status.Kaz Kylheku2021-08-056-22/+114
| | | | | | | | | | | | | | | | | | | | | | | | | | | | We extend the matching context structures to keep track of the underlying stream from which lines are being taken via the lazy list. Then the implementation of the @(eof) directive, when it hits the eof condition, can use this stream to gain access to the termination status. * match.c (match_line_ctx, match_files_ctx): New member, stream. (ml_all): Take stream argument and initialize new member. (h_call, do_match_line): Pass stream argument to h_call. (mf_all, mf_file_data): Take stream argument and initialize new member. (mf_from_ml): Propagate stream from line context to file context. (freeform_prepare, v_next_impl, match_filter, match_fun, extract): Pass stream argument where now needed. (v_eof): Implement termination status binding via the stream stored in the context. (open_data_source): Store stream in match files context. * tests/010/eof-status.txr: New file. * tests/010/eof-status.expected: New file. * Makefile (tst/tests/010/eof-status.ok): -B option for new test. * txr.1: Documented eof directive, argument and all. * stdlib/doc-syms.tl: Updated.
* close-stream: make idemponent.Kaz Kylheku2021-08-043-10/+17
| | | | | | | | | | | | | | | | | | * stream.c (strm_base_init): Add new element to the initializer to initialize the close_result member to nao, indicating that the close operation has not been invoked. (strm_base_mark): Mark the close_result value, if it isn't nao. This is just in case it is a heap object. The structure delegate mechanism opens the possibility that the stream is actually user code that can return anything so we have to be careful. (close_stream): Only call ops->close if close_result is nao, indicating that close had never been called (or possibly that it had been called bu threw an exception) and store the return value in close_result, otherwise return the previously stored value. * stream.h (struct strm_base): New member, close_result. * txr.1: Documented.
* musl: fix missing <sys/time.h>.Kaz Kylheku2021-08-042-2/+7
| | | | | | | | | | | | | | | | Issue peported by Ethan Hawk. Our socket.c module is using struct timeval without including <sys/time.h>, which breaks on musl. * configure: in the select test, let's include <sys/time.h>, and if the test passes, let's set have_sys_time, so that HAVE_SELECT implies HAVE_SYS_TIME. This way code wrapped with HAVE_SELECT doesn't separately have to test for HAVE_SYS_TIME. * socket.c: If HAVE_SYS_TIME is true, then we include <sys/time.h>, independently of HAVE_SELECT. (sock_timeout, sock_load_init): Like the select-based code, code using SO_SNDTIMEO or SO_RCVTIMO also uses timeval, so needs to be wrapped with HAVE_SYS_TIME.
* listener: print prompts in plain mode if stdin is tty.Kaz Kylheku2021-08-032-11/+9
| | | | | | | * linenoise/linenoise.c (linenoise): Force the printing of prompts if the input file descriptor is a tty. * txr.1: Documentation updated.
* listener: print banner only if stdin is a tty.Kaz Kylheku2021-08-031-3/+7
| | | | | | * txr.c (banner): If standard input isn't a tty, bail. Now takes a self argument for the c_int function. (txr_main): Pass self value down to banner.
* listener: prompt feature for plain mode.Kaz Kylheku2021-08-034-2/+36
| | | | | | | | | | | | | | | | | | The :prompt-on command will enable prompting in plain mode. * linenoise/linenoise.c (struct lino_state): New member, show_prompt. (line_enable_noninteractive_prompt): New function. (linenoise): In the plain mode loop, the show_prompt flag is on, show the prompt. For continuation lines, show a condensed prompt, which consists of the suffix of the full prompt, starting on the last non-whitespace character. * linenoise/linenoise.h (lino_enable_noninteractive): Declared. * parser.c (repl): Implement :prompt-on command which enables the above mode. * txr.1: Documented.
* streams: document redundant close-stream.Kaz Kylheku2021-08-021-0/+10
| | | | | * txr.1: Document that if close-stream is applied to a closed stream, then nil is returned without throwing an exception.
* streams: bad argument defaulting in close-stream.Kaz Kylheku2021-08-023-7/+7
| | | | | | | | | | | | | | | * stream.c (stdio_close, pipe_close): Fix throw_on_error argument not being defaulted correctly, so that errors are thrown even when the argument is omitted. * strudel.c (strudel_close): Here, we also must default the argument. The corresponding close method does not have an optional argument; it is mandatory. The documentation is bungled for it, though. * txr.1: Fix documentation of structure delegate streams with regard to the close method. It does not take offs and whence parametrs, but throw-on-error-p, which is mandatory.
* tests: fix undefined variable warning.Kaz Kylheku2021-08-031-1/+3
| | | | | * tests/012/oop.tl: Adjust one recently added test case to eliminate undefined variable warning.
* listener: support multi-line expressions in plain mode.Kaz Kylheku2021-08-012-8/+44
| | | | | | | | | | | | | * linenoise/linenoise.c (linenoise): If we are in noninteractive mode, then do not just read one line and return it. If an enter_callback is defined then keep accumulating lines while the callback indicates incomplete syntax, until EOF occurs or the syntax appears complete. Return the lines glued together, with \n characters replaced by \r, so the line is correctly entered into the history, and the trailing LF obliterated, as usual. * txr.1: Documented new multi-line behavior of plain mode.
* oop: fix infelicity in new* and lnew* macros.Kaz Kylheku2021-07-313-10/+98
| | | | | | | | | | * stdlib/struct.tl (sys:new-expander): If the argument of new* or lnew* is dwim, then treat that as an expression, rather than as a boa-style construction. * tests/012/oop.tl: Tests for new* focusing on this issue. * txr.1: Documented.
* doc: *read-bad-json* fix and doc-syms update.Kaz Kylheku2021-07-312-1/+2
| | | | | | * txr.1: Fix code -> codn. * stdlib/doc-syms.tl: Updated.
* tests: multiple evaluation issue in amb.Kaz Kylheku2021-07-301-2/+2
| | | | | | | | | | | | | | | | This issue doesn't affect the tests. This is for the benefit of someone who happens to be copy-and-pasting the amb implementation from here. * tests/012/cont.tl (amb): This function has an issue in that it calls the continuation (future calculation) and then if that succeeds, it normally returns the value. This means that the future is executed again. In the case of N amb expressions, the successful future is executed 2**N times. What amb must do is this: call the continuation and capture the value. If the value is successful, then that is the master return value; just return that from amb-scope, bypassing the second re-execution of the future.
* tests: longer test for delimited continuations.Kaz Kylheku2021-07-301-0/+10
| | | | | * tests/012/cont.tl: New test case. This aborts prior to recent gc fixes.
* parser: allow trailing commas in json, via opt-in flag.Kaz Kylheku2021-07-296-1769/+1807
| | | | | | | | | | | | | | | | | | | | | | | * parser.c (read_bad_json_s): New symbol variable. (parser_common_init): Propagate value of *read-bad-json* into read_bad_json flag in parser structure. (parser_init): Initialize read_bad_json_s and register the *read-bad-json* dynamic variable. * parser.h (struct parser): New member, read_bad_json. (read_bad_json_s): Declared. * parser.y (json_val): Support an opt_comma symbol just before the closing bracket or brace. (opt_comma): New nonterminal symbol. Recognizes ',' or nothing. Error is flagged if ',' is recognized, and *read-bad-json* is nil. * y.tab.c.shipped: Updated. * tests/010/json.tl: New tests. * txr.1: Documented.
* gc: problem in environment-copying functions.Kaz Kylheku2021-07-291-7/+12
| | | | | | | | | | | | | * eval.c (copy_env, deep_copy_env): These functions are not following a protocol for object construction that is correct under generational GC. They are allocating a new object with make_obj first, and then calling functions to copy the constituent elements to populate into the object with a direct assignment. This direct assignment is wrong; the set macro is required. A better fix, rather than using the set macro, is to copy the constituent parts first, holding them in local variables, then allocate the new object, and finally, without doing any other memory allocating operations, assign the constituent parts into the new object.