annotate src/data.c @ 1204:e22b0213b713

[xemacs-hg @ 2003-01-12 11:07:58 by michaels] modules/ChangeLog: 2002-12-16 Ben Wing <ben@xemacs.org> * postgresql/postgresql.c: remove ifdef USE_KKCC. src/ChangeLog: 2003-01-08 Mike Sperber <mike@xemacs.org> * console.h (CDFW_CONSOLE): Don't lead to a crash if we're dealing with a dead window/frame/device/console. 2002-12-20 Mike Sperber <mike@xemacs.org> * ui-gtk.c: Fix typo from Ben's patch: emacs_ffi_data is a typedef, not a struct. emacs_gtk_object_data is a typedef, not a struct. * gtk-glue.c (gdk_event_to_emacs_event): Fix typos from Ben's patch: le -> emacs_event + rearrange the code. * event-gtk.c (gtk_event_to_emacs_event): Fix typos from Ben's patch: ..._UNDERLYING_GDK_EVENT -> ..._GDK_EVENT, ev -> key_event. * device-gtk.c: Fix typo from Ben's patch: x_keysym_map_hash_table -> x_keysym_map_hashtable. 2002-12-19 Mike Sperber <mike@xemacs.org> * menubar-x.c (set_frame_menubar): Initialize protect_me field of popup_data. 2002-12-16 Ben Wing <ben@xemacs.org> Major cleanup of KKCC, etc. KKCC, pdump-related: -- descriptions are written for all objects. this required some changes in the format of some objects, e.g. extents, popup-data, coding system, lstream, lcrecord-list. -- KKCC now handles weakness in markers, hash tables, elsewhere correctly (formerly, you'd eventually get a stack overflow due to endlessly expanding markers). -- textual changes: lrecord_description -> memory_description, struct_description -> sized_memory_description. -- extensive comment describing descriptions and pdump. -- redo XD_UNION so it works inline and change its format to provide sufficient info for pdump. implement XD_UNION in pdump. also add XD_UNION_DYNAMIC_SIZE, which works like XD_UNION except for when auto-computing structure sizes. -- add support for XD_INDIRECT in description offsets (used by extents). -- add support for "description maps", allowing for indirect descriptions that are retrieved from an object at run-time. this generalizes XD_CODING_SYSTEM_END, XD_SPECIFIER_END, etc., which have now been eliminated. -- add a fifth field "flags" to memory_description, to support flags that can be specified for this particular line. Currently defined flags are XD_FLAG_NO_KKCC (KKCC should ignore this entry; useful for the weakness above in markers, etc.), XD_FLAG_NO_PDUMP (pdump should ignore this entry), XD_FLAG_UNION_DEFAULT_ENTRY (in union maps, this specifies a "default" entry for all remaining values), and XD_FLAG_FREE_LISP_OBJECT (for use with lcrecord-lists). -- clean up the kkcc-itis in events, so that the differences between event data as separate objects and as a union are now minimized to a small number of places. with the new XD_UNION, we no longer need event data as separate objects, so this code is no longer ifdef USE_KKCC, but instead ifdef EVENT_DATA_AS_OBJECTS, not used by default. make sure that we explicitly free the separate event data objects when no longer in use, to maintain the invariant the event processing causes no consing. -- also remove other USE_KKCC ifdefs when not necessary. -- allow for KKCC compilation under MS Windows. -- fix README.kkcc. -- dump_add_root_object -> dump_add_root_lisp_object. -- implement dump_add_root_block and use this to handle dump_add_opaque. -- factor out some code duplicated in kkcc and pdump. Other allocation/object-related: -- change various *slots.h so MARKED_SLOT() call no longer includes semicolon. -- free_marker() takes a Lisp_Object not a direct pointer. -- make bit vectors lcrecords, like vectors, and eliminate code that essentially duplicated the lcrecord handling. -- additional asserts in FREE_FIXED_TYPE, formerly duplicated in the various callers of this. -- all lcrecord allocation functions now zero out the returned lcrecords. unnecessary calls to zero_lcrecord removed. add long comment describing these functions. -- extract out process and coding system slots, like for buffers, frames, etc. -- lcrecords now set the type of items sitting on the free list to lcrecord_type_free. -- changes to the way that gap arrays are allocated, for kkcc's benefit -- now, one single memory block with a stretchy array on the end, instead of a separate block holding the array. Error-checking-related: -- now can compile with C++ under MS Windows. clean up compile errors discovered that way. (a few were real problems) -- add C++ error-checking code to verify problems with mismatched GCPRO/UNGCPRO. (there were a few in the kkcc code.) add long comment about how to catch insufficient GCPRO (yes, it's possible using C++). -- add debug_p4(), a simple object printer, when debug_print() doesn't work. -- add dp() and db() as short synonyms of debug_print(), debug_backtrace(). -- `print' tries EXTREMELY hard to avoid core dumping when printing when crashing or from debug_print(), and tries as hard as it reasonably can in other situations. -- Correct the message output upon crashing to be more up-to-date. Event-related: -- document event-matches-key-specifier-p better. -- generalize the dispatch queues formerly duplicated in the various event implementations. add event methods to drain pending events. generalize and clean up QUIT handling, removing event-specific quit processing. allow arbitrary keystrokes, not just ASCII, to be the QUIT char. among other things, this should fix some longstanding bugs in X quit handling. long comment describing the various event queues. -- implement delaying of XFlush() if there are pending expose events. SOMEONE PLEASE TRY THIS OUT. -- Fix `xemacs -batch -l dunnet' under Cygwin. Try to fix under MS Windows but not quite there yet. Other: -- class -> class_ and no more C++ games with this item. new -> new_ in the lwlib code, so far not elsewhere. -- use `struct htentry' not `struct hentry' in elhash.c to avoid debugger confusion with hash.c. -- new macros ALIST_LOOP_3, ALIST_LOOP_4. * README.kkcc: * alloc.c: * alloc.c (deadbeef_memory): * alloc.c (allocate_lisp_storage): * alloc.c (copy_lisp_object): * alloc.c (ALLOCATE_FIXED_TYPE_1): * alloc.c (FREE_FIXED_TYPE): * alloc.c (make_vector_internal): * alloc.c (make_bit_vector_internal): * alloc.c (make_key_data): * alloc.c (make_button_data): * alloc.c (make_motion_data): * alloc.c (make_process_data): * alloc.c (make_timeout_data): * alloc.c (make_magic_data): * alloc.c (make_magic_eval_data): * alloc.c (make_eval_data): * alloc.c (make_misc_user_data): * alloc.c (struct string_chars_block): * alloc.c (mark_lcrecord_list): * alloc.c (make_lcrecord_list): * alloc.c (alloc_managed_lcrecord): * alloc.c (free_managed_lcrecord): * alloc.c (alloc_automanaged_lcrecord): * alloc.c (staticpro_1): * alloc.c (staticpro): * alloc.c (lispdesc_indirect_count_1): * alloc.c (lispdesc_indirect_description_1): * alloc.c (lispdesc_one_description_line_size): * alloc.c (lispdesc_structure_size): * alloc.c (mark_object_maybe_checking_free): * alloc.c (mark_with_description): * alloc.c (mark_struct_contents): * alloc.c (mark_object): * alloc.c (tick_lcrecord_stats): * alloc.c (free_cons): * alloc.c (free_key_data): * alloc.c (free_button_data): * alloc.c (free_motion_data): * alloc.c (free_process_data): * alloc.c (free_timeout_data): * alloc.c (free_magic_data): * alloc.c (free_magic_eval_data): * alloc.c (free_eval_data): * alloc.c (free_misc_user_data): * alloc.c (free_marker): * alloc.c (compact_string_chars): * alloc.c (gc_sweep): * alloc.c (garbage_collect_1): * alloc.c (Fgarbage_collect): * alloc.c (common_init_alloc_early): * alloc.c (init_alloc_early): * alloc.c (init_alloc_once_early): * buffer.c: * buffer.c (mark_buffer): * buffer.c (MARKED_SLOT): * buffer.c (cleanup_buffer_undo_lists): * buffer.c (Fget_file_buffer): * buffer.h (MARKED_SLOT): * bufslots.h: * bytecode.c: * callint.c: * casetab.c: * chartab.c: * chartab.c (symbol_to_char_table_type): * cmdloop.c: * cmdloop.c (Fcommand_loop_1): * config.h.in (new): * conslots.h: * console-gtk-impl.h (struct gtk_frame): * console-impl.h: * console-impl.h (struct console): * console-impl.h (MARKED_SLOT): * console-impl.h (CONSOLE_QUIT_EVENT): * console-msw-impl.h (XM_BUMPQUEUE): * console-msw.c (write_string_to_mswindows_debugging_output): * console-msw.h: * console-stream-impl.h: * console-stream-impl.h (struct stream_console): * console-stream.c: * console-stream.c (stream_init_console): * console-stream.h: * console-tty.c: * console-tty.h: * console-x.h: * console.c: * console.c (mark_console): * console.c (MARKED_SLOT): * console.c (allocate_console): * console.c (get_console_variant): * console.c (create_console): * console.c (delete_console_internal): * console.c (Fset_input_mode): * console.c (Fcurrent_input_mode): * console.c (common_init_complex_vars_of_console): * console.h: * console.h (console_variant): * console.h (device_metrics): * data.c: * data.c (Faref): * data.c (Faset): * data.c (decode_weak_list_type): * database.c: * debug.c (xemacs_debug_loop): * debug.c (FROB): * debug.c (Fadd_debug_class_to_check): * debug.c (Fdelete_debug_class_to_check): * debug.c (Fset_debug_classes_to_check): * debug.c (Fset_debug_class_types_to_check): * debug.c (Fdebug_types_being_checked): * debug.h (DASSERT): * device-gtk.c: * device-impl.h (struct device): * device-impl.h (MARKED_SLOT): * device-msw.c: * device-x.c: * device-x.c (x_init_device_class): * device-x.c (x_comp_visual_info): * device-x.c (x_try_best_visual_class): * device-x.c (x_init_device): * device-x.c (construct_name_list): * device-x.c (x_get_resource_prefix): * device-x.c (Fx_get_resource): * device-x.c (Fx_display_visual_class): * device.c: * device.c (MARKED_SLOT): * device.c (allocate_device): * device.c (Fmake_device): * device.c (delete_device_internal): * device.c (Fset_device_class): * device.h: * devslots.h: * devslots.h (MARKED_SLOT): * dialog-msw.c: * dired-msw.c (mswindows_ls_sort_fcn): * dired-msw.c (mswindows_get_files): * dired-msw.c (mswindows_format_file): * doprnt.c (parse_doprnt_spec): * dumper.c: * dumper.c (struct): * dumper.c (dump_add_root_block): * dumper.c (dump_add_root_struct_ptr): * dumper.c (dump_add_root_lisp_object): * dumper.c (pdump_struct_list_elt): * dumper.c (pdump_get_entry_list): * dumper.c (pdump_backtrace): * dumper.c (pdump_bump_depth): * dumper.c (pdump_register_sub): * dumper.c (pdump_register_object): * dumper.c (pdump_register_struct_contents): * dumper.c (pdump_register_struct): * dumper.c (pdump_store_new_pointer_offsets): * dumper.c (pdump_dump_data): * dumper.c (pdump_reloc_one): * dumper.c (pdump_allocate_offset): * dumper.c (pdump_scan_by_alignment): * dumper.c (pdump_dump_root_blocks): * dumper.c (pdump_dump_rtables): * dumper.c (pdump_dump_root_lisp_objects): * dumper.c (pdump): * dumper.c (pdump_load_finish): * dumper.c (pdump_file_get): * dumper.c (pdump_resource_get): * dumper.c (pdump_load): * editfns.c (save_excursion_restore): * editfns.c (user_login_name): * editfns.c (save_restriction_restore): * elhash.c: * elhash.c (htentry): * elhash.c (struct Lisp_Hash_Table): * elhash.c (HTENTRY_CLEAR_P): * elhash.c (LINEAR_PROBING_LOOP): * elhash.c (check_hash_table_invariants): * elhash.c (mark_hash_table): * elhash.c (hash_table_equal): * elhash.c (print_hash_table_data): * elhash.c (free_hentries): * elhash.c (make_general_lisp_hash_table): * elhash.c (decode_hash_table_weakness): * elhash.c (decode_hash_table_test): * elhash.c (Fcopy_hash_table): * elhash.c (resize_hash_table): * elhash.c (pdump_reorganize_hash_table): * elhash.c (find_htentry): * elhash.c (Fgethash): * elhash.c (Fputhash): * elhash.c (remhash_1): * elhash.c (Fremhash): * elhash.c (Fclrhash): * elhash.c (copy_compress_hentries): * elhash.c (elisp_maphash_unsafe): * elhash.c (finish_marking_weak_hash_tables): * elhash.c (prune_weak_hash_tables): * elhash.h: * emacs.c: * emacs.c (main_1): * emacs.c (main): * emacs.c (shut_down_emacs): * emodules.h (dump_add_root_lisp_object): * eval.c: * eval.c (unwind_to_catch): * eval.c (maybe_signal_error_1): * eval.c (maybe_signal_continuable_error_1): * eval.c (maybe_signal_error): * eval.c (maybe_signal_continuable_error): * eval.c (maybe_signal_error_2): * eval.c (maybe_signal_continuable_error_2): * eval.c (maybe_signal_ferror): * eval.c (maybe_signal_continuable_ferror): * eval.c (maybe_signal_ferror_with_frob): * eval.c (maybe_signal_continuable_ferror_with_frob): * eval.c (maybe_syntax_error): * eval.c (maybe_sferror): * eval.c (maybe_invalid_argument): * eval.c (maybe_invalid_constant): * eval.c (maybe_invalid_operation): * eval.c (maybe_invalid_change): * eval.c (maybe_invalid_state): * eval.c (Feval): * eval.c (call_trapping_problems): * eval.c (call_with_suspended_errors): * eval.c (warn_when_safe_lispobj): * eval.c (warn_when_safe): * eval.c (vars_of_eval): * event-Xt.c: * event-Xt.c (maybe_define_x_key_as_self_inserting_character): * event-Xt.c (x_to_emacs_keysym): * event-Xt.c (x_event_to_emacs_event): * event-Xt.c (emacs_Xt_enqueue_focus_event): * event-Xt.c (emacs_Xt_format_magic_event): * event-Xt.c (emacs_Xt_compare_magic_event): * event-Xt.c (emacs_Xt_hash_magic_event): * event-Xt.c (emacs_Xt_handle_magic_event): * event-Xt.c (Xt_timeout_to_emacs_event): * event-Xt.c (Xt_process_to_emacs_event): * event-Xt.c (signal_special_Xt_user_event): * event-Xt.c (emacs_Xt_next_event): * event-Xt.c (emacs_Xt_event_handler): * event-Xt.c (emacs_Xt_drain_queue): * event-Xt.c (emacs_Xt_event_pending_p): * event-Xt.c (check_if_pending_expose_event): * event-Xt.c (reinit_vars_of_event_Xt): * event-Xt.c (vars_of_event_Xt): * event-gtk.c: * event-gtk.c (IS_MODIFIER_KEY): * event-gtk.c (emacs_gtk_format_magic_event): * event-gtk.c (emacs_gtk_compare_magic_event): * event-gtk.c (emacs_gtk_hash_magic_event): * event-gtk.c (emacs_gtk_handle_magic_event): * event-gtk.c (gtk_to_emacs_keysym): * event-gtk.c (gtk_timeout_to_emacs_event): * event-gtk.c (gtk_process_to_emacs_event): * event-gtk.c (dragndrop_data_received): * event-gtk.c (signal_special_gtk_user_event): * event-gtk.c (emacs_gtk_next_event): * event-gtk.c (gtk_event_to_emacs_event): * event-gtk.c (generic_event_handler): * event-gtk.c (emacs_shell_event_handler): * event-gtk.c (emacs_gtk_drain_queue): * event-gtk.c (emacs_gtk_event_pending_p): * event-gtk.c (reinit_vars_of_event_gtk): * event-gtk.c (vars_of_event_gtk): * event-msw.c: * event-msw.c (struct winsock_stream): * event-msw.c (winsock_reader): * event-msw.c (winsock_writer): * event-msw.c (mswindows_enqueue_dispatch_event): * event-msw.c (mswindows_enqueue_misc_user_event): * event-msw.c (mswindows_enqueue_magic_event): * event-msw.c (mswindows_enqueue_process_event): * event-msw.c (mswindows_enqueue_mouse_button_event): * event-msw.c (mswindows_enqueue_keypress_event): * event-msw.c (mswindows_dequeue_dispatch_event): * event-msw.c (emacs_mswindows_drain_queue): * event-msw.c (mswindows_need_event_in_modal_loop): * event-msw.c (mswindows_need_event): * event-msw.c (mswindows_wm_timer_callback): * event-msw.c (dde_eval_string): * event-msw.c (Fdde_alloc_advise_item): * event-msw.c (mswindows_dde_callback): * event-msw.c (mswindows_wnd_proc): * event-msw.c (remove_timeout_mapper): * event-msw.c (emacs_mswindows_remove_timeout): * event-msw.c (emacs_mswindows_event_pending_p): * event-msw.c (emacs_mswindows_format_magic_event): * event-msw.c (emacs_mswindows_compare_magic_event): * event-msw.c (emacs_mswindows_hash_magic_event): * event-msw.c (emacs_mswindows_handle_magic_event): * event-msw.c (emacs_mswindows_select_console): * event-msw.c (emacs_mswindows_unselect_console): * event-msw.c (reinit_vars_of_event_mswindows): * event-msw.c (vars_of_event_mswindows): * event-stream.c: * event-stream.c (mark_command_builder): * event-stream.c (reset_command_builder_event_chain): * event-stream.c (allocate_command_builder): * event-stream.c (copy_command_builder): * event-stream.c (command_builder_append_event): * event-stream.c (event_stream_event_pending_p): * event-stream.c (event_stream_force_event_pending): * event-stream.c (maybe_read_quit_event): * event-stream.c (event_stream_drain_queue): * event-stream.c (remove_quit_p_event): * event-stream.c (event_stream_quit_p): * event-stream.c (echo_key_event): * event-stream.c (maybe_kbd_translate): * event-stream.c (execute_help_form): * event-stream.c (event_stream_generate_wakeup): * event-stream.c (enqueue_dispatch_event): * event-stream.c (enqueue_magic_eval_event): * event-stream.c (Fenqueue_eval_event): * event-stream.c (enqueue_misc_user_event): * event-stream.c (enqueue_misc_user_event_pos): * event-stream.c (next_event_internal): * event-stream.c (Fnext_event): * event-stream.c (Faccept_process_output): * event-stream.c (execute_internal_event): * event-stream.c (munge_keymap_translate): * event-stream.c (command_builder_find_leaf_no_mule_processing): * event-stream.c (command_builder_find_leaf): * event-stream.c (lookup_command_event): * event-stream.c (is_scrollbar_event): * event-stream.c (execute_command_event): * event-stream.c (Fdispatch_event): * event-stream.c (Fread_key_sequence): * event-stream.c (dribble_out_event): * event-stream.c (vars_of_event_stream): * event-tty.c (tty_timeout_to_emacs_event): * event-tty.c (emacs_tty_next_event): * event-tty.c (emacs_tty_drain_queue): * event-tty.c (reinit_vars_of_event_tty): * event-unixoid.c: * event-unixoid.c (find_tty_or_stream_console_from_fd): * event-unixoid.c (read_event_from_tty_or_stream_desc): * event-unixoid.c (drain_tty_devices): * event-unixoid.c (poll_fds_for_input): * events.c: * events.c (deinitialize_event): * events.c (zero_event): * events.c (mark_event): * events.c (print_event_1): * events.c (print_event): * events.c (event_equal): * events.c (event_hash): * events.c (Fmake_event): * events.c (Fdeallocate_event): * events.c (Fcopy_event): * events.c (map_event_chain_remove): * events.c (character_to_event): * events.c (event_to_character): * events.c (Fevent_to_character): * events.c (format_event_object): * events.c (upshift_event): * events.c (downshift_event): * events.c (event_upshifted_p): * events.c (Fevent_live_p): * events.c (Fevent_type): * events.c (Fevent_timestamp): * events.c (CHECK_EVENT_TYPE): * events.c (CHECK_EVENT_TYPE2): * events.c (CHECK_EVENT_TYPE3): * events.c (Fevent_key): * events.c (Fevent_button): * events.c (Fevent_modifier_bits): * events.c (event_x_y_pixel_internal): * events.c (event_pixel_translation): * events.c (Fevent_process): * events.c (Fevent_function): * events.c (Fevent_object): * events.c (Fevent_properties): * events.c (syms_of_events): * events.c (vars_of_events): * events.h: * events.h (struct event_stream): * events.h (struct Lisp_Key_Data): * events.h (KEY_DATA_KEYSYM): * events.h (EVENT_KEY_KEYSYM): * events.h (struct Lisp_Button_Data): * events.h (EVENT_BUTTON_BUTTON): * events.h (struct Lisp_Motion_Data): * events.h (EVENT_MOTION_X): * events.h (struct Lisp_Process_Data): * events.h (EVENT_PROCESS_PROCESS): * events.h (struct Lisp_Timeout_Data): * events.h (EVENT_TIMEOUT_INTERVAL_ID): * events.h (struct Lisp_Eval_Data): * events.h (EVENT_EVAL_FUNCTION): * events.h (struct Lisp_Misc_User_Data): * events.h (EVENT_MISC_USER_FUNCTION): * events.h (struct Lisp_Magic_Eval_Data): * events.h (EVENT_MAGIC_EVAL_INTERNAL_FUNCTION): * events.h (struct Lisp_Magic_Data): * events.h (EVENT_MAGIC_UNDERLYING): * events.h (EVENT_MAGIC_GDK_EVENT): * events.h (struct Lisp_Event): * events.h (XEVENT_CHANNEL): * events.h (SET_EVENT_TIMESTAMP_ZERO): * events.h (SET_EVENT_CHANNEL): * events.h (SET_EVENT_NEXT): * events.h (XSET_EVENT_TYPE): * events.h (struct command_builder): * extents.c: * extents.c (gap_array_adjust_markers): * extents.c (gap_array_recompute_derived_values): * extents.c (gap_array_move_gap): * extents.c (gap_array_make_gap): * extents.c (gap_array_insert_els): * extents.c (gap_array_delete_els): * extents.c (gap_array_make_marker): * extents.c (gap_array_delete_marker): * extents.c (gap_array_move_marker): * extents.c (make_gap_array): * extents.c (free_gap_array): * extents.c (extent_list_num_els): * extents.c (extent_list_insert): * extents.c (mark_extent_auxiliary): * extents.c (allocate_extent_auxiliary): * extents.c (decode_extent_at_flag): * extents.c (verify_extent_mapper): * extents.c (symbol_to_glyph_layout): * extents.c (syms_of_extents): * faces.c: * file-coding.c: * file-coding.c (struct_detector_category_description =): * file-coding.c (detector_category_dynarr_description_1): * file-coding.c (struct_detector_description =): * file-coding.c (detector_dynarr_description_1): * file-coding.c (MARKED_SLOT): * file-coding.c (mark_coding_system): * file-coding.c (coding_system_extra_description_map): * file-coding.c (coding_system_description): * file-coding.c (allocate_coding_system): * file-coding.c (symbol_to_eol_type): * file-coding.c (Fcoding_system_aliasee): * file-coding.c (set_coding_stream_coding_system): * file-coding.c (struct convert_eol_coding_system): * file-coding.c (struct undecided_coding_system): * file-coding.c (undecided_mark_coding_stream): * file-coding.c (coding_category_symbol_to_id): * file-coding.c (struct gzip_coding_system): * file-coding.c (coding_system_type_create): * file-coding.h: * file-coding.h (struct Lisp_Coding_System): * file-coding.h (CODING_SYSTEM_SLOT_DECLARATION): * file-coding.h (coding_system_variant): * file-coding.h (struct coding_system_methods): * file-coding.h (DEFINE_CODING_SYSTEM_TYPE_WITH_DATA): * file-coding.h (INITIALIZE_CODING_SYSTEM_TYPE_WITH_DATA): * file-coding.h (struct coding_stream): * fileio.c (Fsubstitute_in_file_name): * floatfns.c: * fns.c: * fns.c (base64_encode_1): * frame-gtk.c: * frame-gtk.c (Fgtk_start_drag_internal): * frame-impl.h (struct frame): * frame-impl.h (MARKED_SLOT): * frame-msw.c: * frame-x.c: * frame-x.c (Fcde_start_drag_internal): * frame-x.c (Foffix_start_drag_internal): * frame.c: * frame.c (MARKED_SLOT): * frame.c (allocate_frame_core): * frame.c (delete_frame_internal): * frame.c (Fmouse_position_as_motion_event): * frameslots.h: * frameslots.h (MARKED_SLOT_ARRAY): * free-hook.c: * glyphs-msw.c (mswindows_widget_instantiate): * glyphs-x.c: * glyphs-x.c (convert_EImage_to_XImage): * glyphs.c: * glyphs.c (process_image_string_instantiator): * glyphs.c (mark_image_instance): * glyphs.c (allocate_image_instance): * glyphs.c (unmap_subwindow): * glyphs.c (map_subwindow): * glyphs.c (syms_of_glyphs): * glyphs.c (specifier_type_create_image): * glyphs.h: * glyphs.h (struct text_image_instance): * glyphs.h (struct Lisp_Image_Instance): * gmalloc.c: * gmalloc.c ("C"): * gpmevent.c (Freceive_gpm_event): * gpmevent.c (gpm_next_event_cb): * gpmevent.c (vars_of_gpmevent): * gtk-glue.c (gdk_event_to_emacs_event): * gtk-xemacs.c (gtk_xemacs_class_init): * gui-msw.c: * gui-msw.c (mswindows_handle_gui_wm_command): * gui-msw.c (mswindows_translate_menu_or_dialog_item): * gui-x.c: * gui-x.c (mark_popup_data): * gui-x.c (snarf_widget_value_mapper): * gui-x.c (gcpro_popup_callbacks): * gui-x.c (ungcpro_popup_callbacks): * gui-x.c (free_popup_widget_value_tree): * gui-x.c (popup_selection_callback): * gui-x.h: * gui-x.h (struct popup_data): * gui.c: * gui.c (allocate_gui_item): * gutter.c (decode_gutter_position): * hash.c (NULL_ENTRY): * indent.c (vmotion_1): * indent.c (vmotion_pixels): * input-method-motif.c (res): * input-method-xlib.c (IMInstantiateCallback): * input-method-xlib.c (XIM_init_device): * input-method-xlib.c (res): * intl-encap-win32.c: * intl-encap-win32.c (qxeSHGetDataFromIDList): * intl-win32.c: * intl-win32.c (mswindows_multibyte_cp_type): * intl-win32.c (struct mswindows_multibyte_coding_system): * keymap.c: * keymap.c (make_key_description): * keymap.c (keymap_store): * keymap.c (get_keyelt): * keymap.c (keymap_lookup_1): * keymap.c (define_key_parser): * keymap.c (key_desc_list_to_event): * keymap.c (event_matches_key_specifier_p): * keymap.c (meta_prefix_char_p): * keymap.c (ensure_meta_prefix_char_keymapp): * keymap.c (Fdefine_key): * keymap.c (struct raw_lookup_key_mapper_closure): * keymap.c (raw_lookup_key): * keymap.c (raw_lookup_key_mapper): * keymap.c (lookup_keys): * keymap.c (lookup_events): * keymap.c (Flookup_key): * keymap.c (struct map_keymap_unsorted_closure): * keymap.c (map_keymap_unsorted_mapper): * keymap.c (map_keymap_sorted): * keymap.c (map_keymap_mapper): * keymap.c (map_keymap): * keymap.c (accessible_keymaps_mapper_1): * keymap.c (Faccessible_keymaps): * keymap.c (Fsingle_key_description): * keymap.c (raw_keys_to_keys): * keymap.c (format_raw_keys): * keymap.c (where_is_recursive_mapper): * keymap.c (where_is_internal): * keymap.c (describe_map_mapper_shadow_search): * keymap.c (keymap_lookup_inherited_mapper): * keymap.c (describe_map_mapper): * keymap.h (event_matches_key_specifier_p): * lisp.h: * lisp.h (this): * lisp.h (RETURN_NOT_REACHED): * lisp.h (struct Lisp_Vector): * lisp.h (struct Lisp_Bit_Vector): * lisp.h (UNGCPRO_1): * lisp.h (NUNGCPRO): * lisp.h (NNUNGCPRO): * lisp.h (DECLARE_INLINE_HEADER): * lrecord.h: * lrecord.h (struct lrecord_header): * lrecord.h (struct lcrecord_header): * lrecord.h (lrecord_type): * lrecord.h (struct lrecord_implementation): * lrecord.h (RECORD_DUMPABLE): * lrecord.h (memory_description_type): * lrecord.h (data_description_entry_flags): * lrecord.h (struct memory_description): * lrecord.h (struct sized_memory_description): * lrecord.h (XD_INDIRECT): * lrecord.h (XD_IS_INDIRECT): * lrecord.h (XD_DYNARR_DESC): * lrecord.h (DEFINE_BASIC_LRECORD_IMPLEMENTATION): * lrecord.h (MAKE_LRECORD_IMPLEMENTATION): * lrecord.h (MAKE_EXTERNAL_LRECORD_IMPLEMENTATION): * lrecord.h (alloc_lcrecord_type): * lstream.c: * lstream.c (Lstream_new): * lstream.c (lisp_buffer_marker): * lstream.h: * lstream.h (lstream_implementation): * lstream.h (DEFINE_LSTREAM_IMPLEMENTATION): * lstream.h (DEFINE_LSTREAM_IMPLEMENTATION_WITH_DATA): * marker.c: * marker.c (copy_marker_1): * mem-limits.h: * menubar-gtk.c: * menubar-gtk.c (gtk_popup_menu): * menubar-msw.c: * menubar-msw.c (mswindows_popup_menu): * menubar-x.c (make_dummy_xbutton_event): * menubar-x.c (command_builder_operate_menu_accelerator): * menubar-x.c (menu_accelerator_safe_compare): * menubar-x.c (menu_accelerator_safe_mod_compare): * mule-charset.c: * mule-charset.c (make_charset): * mule-charset.c (Fcharset_property): * mule-coding.c: * mule-coding.c (ccs_description_1): * mule-coding.c (ccs_description =): * mule-coding.c (ccsd_description_1): * mule-coding.c (ccsd_description =): * nt.c (getpwnam): * nt.c (init_mswindows_environment): * nt.c (get_cached_volume_information): * nt.c (mswindows_is_executable): * nt.c (read_unc_volume): * nt.c (mswindows_access): * nt.c (mswindows_link): * nt.c (mswindows_fstat): * nt.c (mswindows_stat): * nt.c (mswindows_executable_type): * nt.c (Fmswindows_short_file_name): * nt.c (Fmswindows_long_file_name): * objects-impl.h (struct Lisp_Color_Instance): * objects-impl.h (struct Lisp_Font_Instance): * objects-tty.c: * objects-x.c (allocate_nearest_color): * objects.c: * objects.c (Fmake_color_instance): * objects.c (Fmake_font_instance): * objects.c (font_instantiate): * opaque.c: * opaque.c (make_opaque): * opaque.c (make_opaque_ptr): * opaque.c (reinit_opaque_early): * opaque.c (init_opaque_once_early): * print.c: * print.c (printing_badness): * print.c (printing_major_badness): * print.c (print_internal): * print.c (debug_p4): * print.c (dp): * print.c (debug_backtrace): * process-nt.c (nt_create_process): * process-nt.c (get_internet_address): * process-unix.c: * process-unix.c (struct unix_process_data): * process-unix.c (get_internet_address): * process-unix.c (unix_alloc_process_data): * process-unix.c (unix_create_process): * process-unix.c (try_to_initialize_subtty): * process-unix.c (unix_kill_child_process): * process-unix.c (process_type_create_unix): * process.c: * process.c (mark_process): * process.c (MARKED_SLOT): * process.c (make_process_internal): * process.c (Fprocess_tty_name): * process.c (decode_signal): * process.h: * procimpl.h: * procimpl.h (struct process_methods): * procimpl.h (struct Lisp_Process): * rangetab.c: * realpath.c (readlink_and_correct_case): * redisplay-x.c (x_window_output_end): * redisplay-x.c (x_redraw_exposed_area): * redisplay-x.c (x_clear_frame): * redisplay.c: * redisplay.h: * redisplay.h (struct rune_dglyph): * redisplay.h (struct rune): * scrollbar.c: * scrollbar.c (create_scrollbar_instance): * specifier.c: * specifier.c (specifier_empty_extra_description_1): * specifier.c (make_specifier_internal): * specifier.c (decode_locale_type): * specifier.c (decode_how_to_add_specification): * specifier.h: * specifier.h (struct specifier_methods): * specifier.h (DEFINE_SPECIFIER_TYPE_WITH_DATA): * specifier.h (INITIALIZE_SPECIFIER_TYPE_WITH_DATA): * symbols.c: * symbols.c (Fsetplist): * symbols.c (default_value): * symbols.c (decode_magic_handler_type): * symbols.c (handler_type_from_function_symbol): * symbols.c (Fdefvaralias): * symbols.c (init_symbols_once_early): * symbols.c (reinit_symbols_early): * symsinit.h: * sysdep.c (sys_subshell): * sysdep.c (tty_init_sys_modes_on_device): * syswindows.h: * text.c (dfc_convert_to_external_format): * text.c (dfc_convert_to_internal_format): * text.c (reinit_eistring_early): * text.c (init_eistring_once_early): * text.c (reinit_vars_of_text): * text.h: * text.h (INC_IBYTEPTR_FMT): * text.h (DEC_IBYTEPTR_FMT): * toolbar.c: * toolbar.c (decode_toolbar_position): * tooltalk.c: * ui-gtk.c: * unexnt.c: * unexnt.c (_start): * unexnt.c (unexec): * unexnt.c (get_section_info): * unicode.c: * unicode.c (vars_of_unicode): * window.c: * window.c (allocate_window): * window.c (new_window_mirror): * window.c (update_mirror_internal): * winslots.h:
author michaels
date Sun, 12 Jan 2003 11:08:22 +0000
parents 8b464283e891
children 4542b72c005e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Primitive operations on Lisp data types for XEmacs Lisp interpreter.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1988, 1992, 1993, 1994, 1995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Free Software Foundation, Inc.
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
4 Copyright (C) 2000, 2001, 2002 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 /* Synched up with: Mule 2.0, FSF 19.30. Some of FSF's data.c is in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 XEmacs' symbols.c. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 /* This file has been Mule-ized. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #include "bytecode.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 #include "syssignal.h"
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
34 #include "sysfloat.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 Lisp_Object Qerror_conditions, Qerror_message;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
38 Lisp_Object Qerror, Qquit, Qsyntax_error, Qinvalid_read_syntax;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
39 Lisp_Object Qlist_formation_error, Qstructure_formation_error;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
40 Lisp_Object Qmalformed_list, Qmalformed_property_list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
41 Lisp_Object Qcircular_list, Qcircular_property_list;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
42 Lisp_Object Qinvalid_argument, Qinvalid_constant, Qwrong_type_argument;
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
43 Lisp_Object Qargs_out_of_range;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
44 Lisp_Object Qwrong_number_of_arguments, Qinvalid_function, Qno_catch;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
45 Lisp_Object Qinternal_error, Qinvalid_state, Qstack_overflow, Qout_of_memory;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 Lisp_Object Qvoid_variable, Qcyclic_variable_indirection;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 Lisp_Object Qvoid_function, Qcyclic_function_indirection;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
48 Lisp_Object Qinvalid_operation, Qinvalid_change, Qprinting_unreadable_object;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
49 Lisp_Object Qsetting_constant;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
50 Lisp_Object Qediting_error;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
51 Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
52 Lisp_Object Qio_error, Qfile_error, Qconversion_error, Qend_of_file;
580
55e998c311f5 [xemacs-hg @ 2001-05-26 12:24:50 by ben]
ben
parents: 563
diff changeset
53 Lisp_Object Qtext_conversion_error;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 Lisp_Object Qarith_error, Qrange_error, Qdomain_error;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 Lisp_Object Qsingularity_error, Qoverflow_error, Qunderflow_error;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 Lisp_Object Qintegerp, Qnatnump, Qsymbolp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 Lisp_Object Qlistp, Qtrue_list_p, Qweak_listp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 Lisp_Object Qconsp, Qsubrp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 Lisp_Object Qcharacterp, Qstringp, Qarrayp, Qsequencep, Qvectorp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qbufferp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 Lisp_Object Qinteger_or_char_p, Qinteger_char_or_marker_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 Lisp_Object Qnumberp, Qnumber_char_or_marker_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 Lisp_Object Qbit_vectorp, Qbitp, Qcdr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
65 Lisp_Object Qerror_lacks_explanatory_string;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 Lisp_Object Qfloatp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 #ifdef DEBUG_XEMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 int debug_issue_ebola_notices;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
72 Fixnum debug_ebola_backtrace_length;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 eq_with_ebola_notice (Lisp_Object obj1, Lisp_Object obj2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 if (debug_issue_ebola_notices
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 && ((CHARP (obj1) && INTP (obj2)) || (CHARP (obj2) && INTP (obj1))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 /* #### It would be really nice if this were a proper warning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 instead of brain-dead print ro Qexternal_debugging_output. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 801
diff changeset
82 write_c_string
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 801
diff changeset
83 (Qexternal_debugging_output,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 801
diff changeset
84 "Comparison between integer and character is constant nil (");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 Fprinc (obj1, Qexternal_debugging_output);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 801
diff changeset
86 write_c_string (Qexternal_debugging_output, " and ");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 Fprinc (obj2, Qexternal_debugging_output);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 801
diff changeset
88 write_c_string (Qexternal_debugging_output, ")\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 debug_short_backtrace (debug_ebola_backtrace_length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 return EQ (obj1, obj2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 #endif /* DEBUG_XEMACS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 wrong_type_argument (Lisp_Object predicate, Lisp_Object value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 REGISTER Lisp_Object tem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 value = Fsignal (Qwrong_type_argument, list2 (predicate, value));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 tem = call1 (predicate, value);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 while (NILP (tem));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 return value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 DOESNT_RETURN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 dead_wrong_type_argument (Lisp_Object predicate, Lisp_Object value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
115 signal_error_1 (Qwrong_type_argument, list2 (predicate, value));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 DEFUN ("wrong-type-argument", Fwrong_type_argument, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 Signal an error until the correct type value is given by the user.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 This function loops, signalling a continuable `wrong-type-argument' error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 with PREDICATE and VALUE as the data associated with the error and then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 calling PREDICATE on the returned value, until the value gotten satisfies
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 PREDICATE. At that point, the gotten value is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 (predicate, value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 return wrong_type_argument (predicate, value);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 DOESNT_RETURN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 c_write_error (Lisp_Object obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
133 signal_error (Qsetting_constant,
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
134 "Attempt to modify read-only object (c)", obj);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 DOESNT_RETURN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 lisp_write_error (Lisp_Object obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
140 signal_error (Qsetting_constant,
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
141 "Attempt to modify read-only object (lisp)", obj);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 DOESNT_RETURN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 args_out_of_range (Lisp_Object a1, Lisp_Object a2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
147 signal_error_1 (Qargs_out_of_range, list2 (a1, a2));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 DOESNT_RETURN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 args_out_of_range_3 (Lisp_Object a1, Lisp_Object a2, Lisp_Object a3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
153 signal_error_1 (Qargs_out_of_range, list3 (a1, a2, a3));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 check_int_range (EMACS_INT val, EMACS_INT min, EMACS_INT max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 if (val < min || val > max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 args_out_of_range_3 (make_int (val), make_int (min), make_int (max));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 /* On some machines, XINT needs a temporary location.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 Here it is, in case it is needed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 EMACS_INT sign_extend_temp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 /* On a few machines, XINT can only be done by calling this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 /* XEmacs: only used by m/convex.h */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 EMACS_INT sign_extend_lisp_int (EMACS_INT num);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 EMACS_INT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 sign_extend_lisp_int (EMACS_INT num)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 if (num & (1L << (VALBITS - 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 return num | ((-1L) << VALBITS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 return num & ((1L << VALBITS) - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 /* Data type predicates */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 DEFUN ("eq", Feq, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 Return t if the two args are the same Lisp object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
186 (object1, object2))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
188 return EQ_WITH_EBOLA_NOTICE (object1, object2) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 DEFUN ("old-eq", Fold_eq, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 Return t if the two args are (in most cases) the same Lisp object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 Special kludge: A character is considered `old-eq' to its equivalent integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 even though they are not the same object and are in fact of different
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 types. This is ABSOLUTELY AND UTTERLY HORRENDOUS but is necessary to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 preserve byte-code compatibility with v19. This kludge is known as the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 \"char-int confoundance disease\" and appears in a number of other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 functions with `old-foo' equivalents.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 Do not use this function!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
203 (object1, object2))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 /* #### blasphemy */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
206 return HACKEQ_UNSAFE (object1, object2) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 DEFUN ("null", Fnull, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 Return t if OBJECT is nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 return NILP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 DEFUN ("consp", Fconsp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 Return t if OBJECT is a cons cell. `nil' is not a cons cell.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 return CONSP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 DEFUN ("atom", Fatom, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 Return t if OBJECT is not a cons cell. `nil' is not a cons cell.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 return CONSP (object) ? Qnil : Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 DEFUN ("listp", Flistp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 Return t if OBJECT is a list. `nil' is a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 return LISTP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 DEFUN ("nlistp", Fnlistp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 Return t if OBJECT is not a list. `nil' is a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 return LISTP (object) ? Qnil : Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 DEFUN ("true-list-p", Ftrue_list_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 Return t if OBJECT is a non-dotted, i.e. nil-terminated, list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 return TRUE_LIST_P (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 DEFUN ("symbolp", Fsymbolp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 Return t if OBJECT is a symbol.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 return SYMBOLP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 DEFUN ("keywordp", Fkeywordp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 Return t if OBJECT is a keyword.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 return KEYWORDP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 DEFUN ("vectorp", Fvectorp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 Return t if OBJECT is a vector.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 return VECTORP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 DEFUN ("bit-vector-p", Fbit_vector_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 Return t if OBJECT is a bit vector.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 return BIT_VECTORP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 DEFUN ("stringp", Fstringp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 Return t if OBJECT is a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 return STRINGP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 DEFUN ("arrayp", Farrayp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 Return t if OBJECT is an array (string, vector, or bit vector).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 return (VECTORP (object) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 STRINGP (object) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 BIT_VECTORP (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 DEFUN ("sequencep", Fsequencep, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 Return t if OBJECT is a sequence (list or array).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 return (LISTP (object) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 VECTORP (object) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 STRINGP (object) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 BIT_VECTORP (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 DEFUN ("markerp", Fmarkerp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 Return t if OBJECT is a marker (editor pointer).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 return MARKERP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 DEFUN ("subrp", Fsubrp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 Return t if OBJECT is a built-in function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 return SUBRP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 DEFUN ("subr-min-args", Fsubr_min_args, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 Return minimum number of args built-in function SUBR may be called with.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 (subr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 CHECK_SUBR (subr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 return make_int (XSUBR (subr)->min_args);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 DEFUN ("subr-max-args", Fsubr_max_args, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 Return maximum number of args built-in function SUBR may be called with,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 or nil if it takes an arbitrary number of arguments or is a special form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 (subr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 int nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 CHECK_SUBR (subr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 nargs = XSUBR (subr)->max_args;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 if (nargs == MANY || nargs == UNEVALLED)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 return make_int (nargs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 DEFUN ("subr-interactive", Fsubr_interactive, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
361 Return the interactive spec of the subr object SUBR, or nil.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 If non-nil, the return value will be a list whose first element is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 `interactive' and whose second element is the interactive spec.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 (subr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 858
diff changeset
367 const CIbyte *prompt;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 CHECK_SUBR (subr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 prompt = XSUBR (subr)->prompt;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
370 return prompt ? list2 (Qinteractive, build_msg_string (prompt)) : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 DEFUN ("characterp", Fcharacterp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 Return t if OBJECT is a character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 Unlike in XEmacs v19 and FSF Emacs, a character is its own primitive type.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 Any character can be converted into an equivalent integer using
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 `char-int'. To convert the other way, use `int-char'; however,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 only some integers can be converted into characters. Such an integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 is called a `char-int'; see `char-int-p'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 Some functions that work on integers (e.g. the comparison functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 <, <=, =, /=, etc. and the arithmetic functions +, -, *, etc.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 accept characters and implicitly convert them into integers. In
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 general, functions that work on characters also accept char-ints and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 implicitly convert them into characters. WARNING: Neither of these
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 behaviors is very desirable, and they are maintained for backward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 compatibility with old E-Lisp programs that confounded characters and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 integers willy-nilly. These behaviors may change in the future; therefore,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 do not rely on them. Instead, use the character-specific functions such
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 as `char='.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 return CHARP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 DEFUN ("char-to-int", Fchar_to_int, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
399 Convert CHARACTER into an equivalent integer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 The resulting integer will always be non-negative. The integers in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 the range 0 - 255 map to characters as follows:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 0 - 31 Control set 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 32 - 127 ASCII
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 128 - 159 Control set 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 160 - 255 Right half of ISO-8859-1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 If support for Mule does not exist, these are the only valid character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 values. When Mule support exists, the values assigned to other characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 may vary depending on the particular version of XEmacs, the order in which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 character sets were loaded, etc., and you should not depend on them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
413 (character))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
415 CHECK_CHAR (character);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
416 return make_int (XCHAR (character));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 DEFUN ("int-to-char", Fint_to_char, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
420 Convert integer INTEGER into the equivalent character.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 Not all integers correspond to valid characters; use `char-int-p' to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 determine whether this is the case. If the integer cannot be converted,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 nil is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 (integer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 CHECK_INT (integer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 if (CHAR_INTP (integer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 return make_char (XINT (integer));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 DEFUN ("char-int-p", Fchar_int_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 Return t if OBJECT is an integer that can be converted into a character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 See `char-int'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 return CHAR_INTP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 DEFUN ("char-or-char-int-p", Fchar_or_char_int_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 Return t if OBJECT is a character or an integer that can be converted into one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 return CHAR_OR_CHAR_INTP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 DEFUN ("char-or-string-p", Fchar_or_string_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 Return t if OBJECT is a character (or a char-int) or a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 It is semi-hateful that we allow a char-int here, as it goes against
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 the name of this function, but it makes the most sense considering the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 other steps we take to maintain compatibility with the old character/integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 confoundedness in older versions of E-Lisp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 return CHAR_OR_CHAR_INTP (object) || STRINGP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 DEFUN ("integerp", Fintegerp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 Return t if OBJECT is an integer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 return INTP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 DEFUN ("integer-or-marker-p", Finteger_or_marker_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 Return t if OBJECT is an integer or a marker (editor pointer).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 return INTP (object) || MARKERP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 DEFUN ("integer-or-char-p", Finteger_or_char_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 Return t if OBJECT is an integer or a character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 return INTP (object) || CHARP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 DEFUN ("integer-char-or-marker-p", Finteger_char_or_marker_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 Return t if OBJECT is an integer, character or a marker (editor pointer).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 return INTP (object) || CHARP (object) || MARKERP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 DEFUN ("natnump", Fnatnump, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 Return t if OBJECT is a nonnegative integer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 return NATNUMP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 DEFUN ("bitp", Fbitp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 Return t if OBJECT is a bit (0 or 1).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 return BITP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 DEFUN ("numberp", Fnumberp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 Return t if OBJECT is a number (floating point or integer).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 return INT_OR_FLOATP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 DEFUN ("number-or-marker-p", Fnumber_or_marker_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 Return t if OBJECT is a number or a marker.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 return INT_OR_FLOATP (object) || MARKERP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 DEFUN ("number-char-or-marker-p", Fnumber_char_or_marker_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 Return t if OBJECT is a number, character or a marker.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 return (INT_OR_FLOATP (object) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 CHARP (object) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 MARKERP (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 DEFUN ("floatp", Ffloatp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 Return t if OBJECT is a floating point number.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 return FLOATP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 DEFUN ("type-of", Ftype_of, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 Return a symbol representing the type of OBJECT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 switch (XTYPE (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 case Lisp_Type_Record:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 return intern (XRECORD_LHEADER_IMPLEMENTATION (object)->name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 case Lisp_Type_Char: return Qcharacter;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 default: return Qinteger;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 /* Extract and set components of lists */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 DEFUN ("car", Fcar, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 Return the car of LIST. If arg is nil, return nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 Error if arg is not nil and not a cons cell. See also `car-safe'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 (list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 if (CONSP (list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 return XCAR (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 else if (NILP (list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 list = wrong_type_argument (Qlistp, list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 DEFUN ("car-safe", Fcar_safe, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 Return the car of OBJECT if it is a cons cell, or else nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 return CONSP (object) ? XCAR (object) : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 DEFUN ("cdr", Fcdr, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 Return the cdr of LIST. If arg is nil, return nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 Error if arg is not nil and not a cons cell. See also `cdr-safe'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 (list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 if (CONSP (list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 return XCDR (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 else if (NILP (list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 list = wrong_type_argument (Qlistp, list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 DEFUN ("cdr-safe", Fcdr_safe, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 Return the cdr of OBJECT if it is a cons cell, else nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 return CONSP (object) ? XCDR (object) : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 DEFUN ("setcar", Fsetcar, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
616 Set the car of CONS-CELL to be NEWCAR. Return NEWCAR.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
618 (cons_cell, newcar))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
620 if (!CONSP (cons_cell))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
621 cons_cell = wrong_type_argument (Qconsp, cons_cell);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
623 XCAR (cons_cell) = newcar;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 return newcar;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 DEFUN ("setcdr", Fsetcdr, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
628 Set the cdr of CONS-CELL to be NEWCDR. Return NEWCDR.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
630 (cons_cell, newcdr))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
632 if (!CONSP (cons_cell))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
633 cons_cell = wrong_type_argument (Qconsp, cons_cell);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
635 XCDR (cons_cell) = newcdr;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 return newcdr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 /* Find the function at the end of a chain of symbol function indirections.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 If OBJECT is a symbol, find the end of its function chain and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 return the value found there. If OBJECT is not a symbol, just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 return it. If there is a cycle in the function chain, signal a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 cyclic-function-indirection error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
646 This is like Findirect_function when VOID_FUNCTION_ERRORP is true.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
647 When VOID_FUNCTION_ERRORP is false, no error is signaled if the end
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
648 of the chain ends up being Qunbound. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 Lisp_Object
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
650 indirect_function (Lisp_Object object, int void_function_errorp)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 #define FUNCTION_INDIRECTION_SUSPICION_LENGTH 16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 Lisp_Object tortoise, hare;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 int count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 for (hare = tortoise = object, count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 SYMBOLP (hare);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 hare = XSYMBOL (hare)->function, count++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 if (count < FUNCTION_INDIRECTION_SUSPICION_LENGTH) continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 if (count & 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 tortoise = XSYMBOL (tortoise)->function;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 if (EQ (hare, tortoise))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 return Fsignal (Qcyclic_function_indirection, list1 (object));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
668 if (void_function_errorp && UNBOUNDP (hare))
436
080151679be2 Import from CVS: tag r21-2-26
cvs
parents: 428
diff changeset
669 return signal_void_function_error (object);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 return hare;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 DEFUN ("indirect-function", Findirect_function, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 Return the function at the end of OBJECT's function chain.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 If OBJECT is a symbol, follow all function indirections and return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 the final function binding.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 If OBJECT is not a symbol, just return it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 Signal a void-function error if the final symbol is unbound.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 Signal a cyclic-function-indirection error if there is a loop in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 function chain of symbols.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 return indirect_function (object, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 /* Extract and set vector and string elements */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 DEFUN ("aref", Faref, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 Return the element of ARRAY at index INDEX.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 ARRAY may be a vector, bit vector, or string. INDEX starts at 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 (array, index_))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 EMACS_INT idx;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 if (INTP (index_)) idx = XINT (index_);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 else if (CHARP (index_)) idx = XCHAR (index_); /* yuck! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 index_ = wrong_type_argument (Qinteger_or_char_p, index_);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 if (idx < 0) goto range_error;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 if (VECTORP (array))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 if (idx >= XVECTOR_LENGTH (array)) goto range_error;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 return XVECTOR_DATA (array)[idx];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 else if (BIT_VECTORP (array))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
717 if (idx >= (EMACS_INT) bit_vector_length (XBIT_VECTOR (array)))
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
718 goto range_error;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 return make_int (bit_vector_bit (XBIT_VECTOR (array), idx));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 else if (STRINGP (array))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 801
diff changeset
723 if (idx >= string_char_length (array)) goto range_error;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 858
diff changeset
724 return make_char (string_ichar (array, idx));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 #ifdef LOSING_BYTECODE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 else if (COMPILED_FUNCTIONP (array))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 /* Weird, gross compatibility kludge */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 return Felt (array, index_);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 check_losing_bytecode ("aref", array);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 array = wrong_type_argument (Qarrayp, array);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 range_error:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 args_out_of_range (array, index_);
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
742 RETURN_NOT_REACHED (Qnil);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 DEFUN ("aset", Faset, 3, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 Store into the element of ARRAY at index INDEX the value NEWVAL.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 ARRAY may be a vector, bit vector, or string. INDEX starts at 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 (array, index_, newval))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 EMACS_INT idx;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 if (INTP (index_)) idx = XINT (index_);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 else if (CHARP (index_)) idx = XCHAR (index_); /* yuck! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 index_ = wrong_type_argument (Qinteger_or_char_p, index_);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 if (idx < 0) goto range_error;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
765 CHECK_LISP_WRITEABLE (array);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 if (VECTORP (array))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 if (idx >= XVECTOR_LENGTH (array)) goto range_error;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 XVECTOR_DATA (array)[idx] = newval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 else if (BIT_VECTORP (array))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
773 if (idx >= (EMACS_INT) bit_vector_length (XBIT_VECTOR (array)))
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
774 goto range_error;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 CHECK_BIT (newval);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 set_bit_vector_bit (XBIT_VECTOR (array), idx, !ZEROP (newval));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 else if (STRINGP (array))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 CHECK_CHAR_COERCE_INT (newval);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 801
diff changeset
781 if (idx >= string_char_length (array)) goto range_error;
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
782 set_string_char (array, idx, XCHAR (newval));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 bump_string_modiff (array);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 array = wrong_type_argument (Qarrayp, array);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 return newval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 range_error:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 args_out_of_range (array, index_);
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
795 RETURN_NOT_REACHED (Qnil);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 /**********************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 /* Arithmetic functions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 /**********************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 typedef struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 int int_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 union
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 EMACS_INT ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 double dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 } c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 } int_or_double;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 number_char_or_marker_to_int_or_double (Lisp_Object obj, int_or_double *p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 p->int_p = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 if (INTP (obj)) p->c.ival = XINT (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 else if (CHARP (obj)) p->c.ival = XCHAR (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 else if (MARKERP (obj)) p->c.ival = marker_position (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 else if (FLOATP (obj)) p->c.dval = XFLOAT_DATA (obj), p->int_p = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 obj = wrong_type_argument (Qnumber_char_or_marker_p, obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 static double
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 number_char_or_marker_to_double (Lisp_Object obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 if (INTP (obj)) return (double) XINT (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 else if (CHARP (obj)) return (double) XCHAR (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 else if (MARKERP (obj)) return (double) marker_position (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 else if (FLOATP (obj)) return XFLOAT_DATA (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 obj = wrong_type_argument (Qnumber_char_or_marker_p, obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 static EMACS_INT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 integer_char_or_marker_to_int (Lisp_Object obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 if (INTP (obj)) return XINT (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 else if (CHARP (obj)) return XCHAR (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 else if (MARKERP (obj)) return marker_position (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 obj = wrong_type_argument (Qinteger_char_or_marker_p, obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 #define ARITHCOMPARE_MANY(op) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 int_or_double iod1, iod2, *p = &iod1, *q = &iod2; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 Lisp_Object *args_end = args + nargs; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 number_char_or_marker_to_int_or_double (*args++, p); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 while (args < args_end) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 number_char_or_marker_to_int_or_double (*args++, q); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 if (!((p->int_p && q->int_p) ? \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 (p->c.ival op q->c.ival) : \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 ((p->int_p ? (double) p->c.ival : p->c.dval) op \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 (q->int_p ? (double) q->c.ival : q->c.dval)))) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 return Qnil; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 { /* swap */ int_or_double *r = p; p = q; q = r; } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 return Qt; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 DEFUN ("=", Feqlsign, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 Return t if all the arguments are numerically equal.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 The arguments may be numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 ARITHCOMPARE_MANY (==)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 DEFUN ("<", Flss, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 Return t if the sequence of arguments is monotonically increasing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 The arguments may be numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 ARITHCOMPARE_MANY (<)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 DEFUN (">", Fgtr, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 Return t if the sequence of arguments is monotonically decreasing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 The arguments may be numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 ARITHCOMPARE_MANY (>)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 DEFUN ("<=", Fleq, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 Return t if the sequence of arguments is monotonically nondecreasing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 The arguments may be numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 ARITHCOMPARE_MANY (<=)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 DEFUN (">=", Fgeq, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 Return t if the sequence of arguments is monotonically nonincreasing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 The arguments may be numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 ARITHCOMPARE_MANY (>=)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 DEFUN ("/=", Fneq, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 Return t if no two arguments are numerically equal.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 The arguments may be numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 Lisp_Object *p, *q;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 /* Unlike all the other comparisons, this is an N*N algorithm.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 We could use a hash table for nargs > 50 to make this linear. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 for (p = args; p < args_end; p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 int_or_double iod1, iod2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 number_char_or_marker_to_int_or_double (*p, &iod1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 for (q = p + 1; q < args_end; q++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 number_char_or_marker_to_int_or_double (*q, &iod2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 if (!((iod1.int_p && iod2.int_p) ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 (iod1.c.ival != iod2.c.ival) :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 ((iod1.int_p ? (double) iod1.c.ival : iod1.c.dval) !=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 (iod2.int_p ? (double) iod2.c.ival : iod2.c.dval))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 return Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 DEFUN ("zerop", Fzerop, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 Return t if NUMBER is zero.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 (number))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 if (INTP (number))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 return EQ (number, Qzero) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 else if (FLOATP (number))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 return XFLOAT_DATA (number) == 0.0 ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 number = wrong_type_argument (Qnumberp, number);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 /* Convert between a 32-bit value and a cons of two 16-bit values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 This is used to pass 32-bit integers to and from the user.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 Use time_to_lisp() and lisp_to_time() for time values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 If you're thinking of using this to store a pointer into a Lisp Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 for internal purposes (such as when calling record_unwind_protect()),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 try using make_opaque_ptr()/get_opaque_ptr() instead. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 word_to_lisp (unsigned int item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 return Fcons (make_int (item >> 16), make_int (item & 0xffff));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 unsigned int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 lisp_to_word (Lisp_Object item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 if (INTP (item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 return XINT (item);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 Lisp_Object top = Fcar (item);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 Lisp_Object bot = Fcdr (item);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 CHECK_INT (top);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 CHECK_INT (bot);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 return (XINT (top) << 16) | (XINT (bot) & 0xffff);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 DEFUN ("number-to-string", Fnumber_to_string, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1001 Convert NUMBER to a string by printing it in decimal.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 Uses a minus sign if negative.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1003 NUMBER may be an integer or a floating point number.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1005 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1007 CHECK_INT_OR_FLOAT (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1009 if (FLOATP (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 char pigbuf[350]; /* see comments in float_to_string */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1013 float_to_string (pigbuf, XFLOAT_DATA (number));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 return build_string (pigbuf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016
603
1c880911c386 [xemacs-hg @ 2001-06-01 08:23:09 by martinb]
martinb
parents: 580
diff changeset
1017 {
1c880911c386 [xemacs-hg @ 2001-06-01 08:23:09 by martinb]
martinb
parents: 580
diff changeset
1018 char buffer[DECIMAL_PRINT_SIZE (long)];
1c880911c386 [xemacs-hg @ 2001-06-01 08:23:09 by martinb]
martinb
parents: 580
diff changeset
1019
1c880911c386 [xemacs-hg @ 2001-06-01 08:23:09 by martinb]
martinb
parents: 580
diff changeset
1020 long_to_string (buffer, XINT (number));
1c880911c386 [xemacs-hg @ 2001-06-01 08:23:09 by martinb]
martinb
parents: 580
diff changeset
1021 return build_string (buffer);
1c880911c386 [xemacs-hg @ 2001-06-01 08:23:09 by martinb]
martinb
parents: 580
diff changeset
1022 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 digit_to_number (int character, int base)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 /* Assumes ASCII */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 int digit = ((character >= '0' && character <= '9') ? character - '0' :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 (character >= 'a' && character <= 'z') ? character - 'a' + 10 :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 (character >= 'A' && character <= 'Z') ? character - 'A' + 10 :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 -1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 return digit >= base ? -1 : digit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 DEFUN ("string-to-number", Fstring_to_number, 1, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1038 Convert STRING to a number by parsing it as a number in base BASE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 This parses both integers and floating point numbers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 It ignores leading spaces and tabs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1042 If BASE is nil or omitted, base 10 is used.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1043 BASE must be an integer between 2 and 16 (inclusive).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 Floating point numbers always use base 10.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 (string, base))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 char *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 int b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 CHECK_STRING (string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 if (NILP (base))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 b = 10;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 CHECK_INT (base);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 b = XINT (base);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 check_int_range (b, 2, 16);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 p = (char *) XSTRING_DATA (string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 /* Skip any whitespace at the front of the number. Some versions of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 atoi do this anyway, so we might as well make Emacs lisp consistent. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 while (*p == ' ' || *p == '\t')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1069 if (isfloat_string (p) && b == 10)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 return make_float (atof (p));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 if (b == 10)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 /* Use the system-provided functions for base 10. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 #if SIZEOF_EMACS_INT == SIZEOF_INT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 return make_int (atoi (p));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 #elif SIZEOF_EMACS_INT == SIZEOF_LONG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 return make_int (atol (p));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 #elif SIZEOF_EMACS_INT == SIZEOF_LONG_LONG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 return make_int (atoll (p));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1085 int negative = 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 EMACS_INT v = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 if (*p == '-')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 negative = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 else if (*p == '+')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1097 int digit = digit_to_number (*p++, b);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 if (digit < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 v = v * b + digit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 return make_int (negative * v);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 DEFUN ("+", Fplus, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 Return sum of any number of arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 The arguments should all be numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 EMACS_INT iaccum = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 int_or_double iod;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 iaccum += iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 double daccum = (double) iaccum + iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 daccum += number_char_or_marker_to_double (*args++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 return make_float (daccum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 return make_int (iaccum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 DEFUN ("-", Fminus, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 Negate number or subtract numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 With one arg, negates it. With more than one arg,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 subtracts all but the first from the first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 EMACS_INT iaccum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 double daccum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 int_or_double iod;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 iaccum = nargs > 1 ? iod.c.ival : - iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 daccum = nargs > 1 ? iod.c.dval : - iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 goto do_float;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 iaccum -= iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 daccum = (double) iaccum - iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 goto do_float;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 return make_int (iaccum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 do_float:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 for (; args < args_end; args++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 daccum -= number_char_or_marker_to_double (*args);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 return make_float (daccum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 DEFUN ("*", Ftimes, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 Return product of any number of arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 The arguments should all be numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 EMACS_INT iaccum = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 int_or_double iod;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 iaccum *= iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 double daccum = (double) iaccum * iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 daccum *= number_char_or_marker_to_double (*args++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 return make_float (daccum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 return make_int (iaccum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 DEFUN ("/", Fquo, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 Return first argument divided by all the remaining arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 The arguments must be numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 With one argument, reciprocates the argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 EMACS_INT iaccum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 double daccum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 int_or_double iod;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 if (nargs == 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 iaccum = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 iaccum = iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 daccum = iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 goto divide_floats;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 if (iod.c.ival == 0) goto divide_by_zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 iaccum /= iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 if (iod.c.dval == 0) goto divide_by_zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 daccum = (double) iaccum / iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 goto divide_floats;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 return make_int (iaccum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 divide_floats:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 for (; args < args_end; args++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 double dval = number_char_or_marker_to_double (*args);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 if (dval == 0) goto divide_by_zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 daccum /= dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 return make_float (daccum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 divide_by_zero:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 Fsignal (Qarith_error, Qnil);
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 800
diff changeset
1257 return Qnil; /* not (usually) reached */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 DEFUN ("max", Fmax, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 Return largest of all the arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 All arguments must be numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 The value is always a number; markers and characters are converted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 to numbers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 EMACS_INT imax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 double dmax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 int_or_double iod;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 imax = iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 dmax = iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 goto max_floats;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 if (imax < iod.c.ival) imax = iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 dmax = (double) imax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 if (dmax < iod.c.dval) dmax = iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 goto max_floats;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 return make_int (imax);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 max_floats:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 double dval = number_char_or_marker_to_double (*args++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 if (dmax < dval) dmax = dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 return make_float (dmax);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 DEFUN ("min", Fmin, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 Return smallest of all the arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 All arguments must be numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 The value is always a number; markers and characters are converted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 to numbers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 EMACS_INT imin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 double dmin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 int_or_double iod;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 imin = iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 dmin = iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 goto min_floats;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 if (imin > iod.c.ival) imin = iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 dmin = (double) imin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 if (dmin > iod.c.dval) dmin = iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 goto min_floats;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 return make_int (imin);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 min_floats:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 double dval = number_char_or_marker_to_double (*args++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 if (dmin > dval) dmin = dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 return make_float (dmin);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 DEFUN ("logand", Flogand, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 Return bitwise-and of all the arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 Arguments may be integers, or markers or characters converted to integers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 EMACS_INT bits = ~0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 bits &= integer_char_or_marker_to_int (*args++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 return make_int (bits);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 DEFUN ("logior", Flogior, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 Return bitwise-or of all the arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 Arguments may be integers, or markers or characters converted to integers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 EMACS_INT bits = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 bits |= integer_char_or_marker_to_int (*args++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 return make_int (bits);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 DEFUN ("logxor", Flogxor, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 Return bitwise-exclusive-or of all the arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 Arguments may be integers, or markers or characters converted to integers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392 EMACS_INT bits = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 bits ^= integer_char_or_marker_to_int (*args++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 return make_int (bits);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 DEFUN ("lognot", Flognot, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 Return the bitwise complement of NUMBER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 NUMBER may be an integer, marker or character converted to integer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 (number))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 return make_int (~ integer_char_or_marker_to_int (number));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 DEFUN ("%", Frem, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411 Return remainder of first arg divided by second.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 Both must be integers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1414 (number1, number2))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1416 EMACS_INT ival1 = integer_char_or_marker_to_int (number1);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1417 EMACS_INT ival2 = integer_char_or_marker_to_int (number2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 if (ival2 == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 Fsignal (Qarith_error, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 return make_int (ival1 % ival2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 /* Note, ANSI *requires* the presence of the fmod() library routine.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 If your system doesn't have it, complain to your vendor, because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 that is a bug. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 #ifndef HAVE_FMOD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 double
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 fmod (double f1, double f2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 if (f2 < 0.0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 f2 = -f2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 return f1 - f2 * floor (f1/f2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 #endif /* ! HAVE_FMOD */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 DEFUN ("mod", Fmod, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 Return X modulo Y.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442 The result falls between zero (inclusive) and Y (exclusive).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 Both X and Y must be numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 If either argument is a float, a float will be returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446 (x, y))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 int_or_double iod1, iod2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 number_char_or_marker_to_int_or_double (x, &iod1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 number_char_or_marker_to_int_or_double (y, &iod2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452 if (!iod1.int_p || !iod2.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 double dval1 = iod1.int_p ? (double) iod1.c.ival : iod1.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455 double dval2 = iod2.int_p ? (double) iod2.c.ival : iod2.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456 if (dval2 == 0) goto divide_by_zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 dval1 = fmod (dval1, dval2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 /* If the "remainder" comes out with the wrong sign, fix it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 if (dval2 < 0 ? dval1 > 0 : dval1 < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 dval1 += dval2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 return make_float (dval1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 }
1104
8b464283e891 [xemacs-hg @ 2002-11-12 18:58:13 by james]
james
parents: 993
diff changeset
1465
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467 EMACS_INT ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 if (iod2.c.ival == 0) goto divide_by_zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 ival = iod1.c.ival % iod2.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472 /* If the "remainder" comes out with the wrong sign, fix it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 if (iod2.c.ival < 0 ? ival > 0 : ival < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 ival += iod2.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 return make_int (ival);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 divide_by_zero:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 Fsignal (Qarith_error, Qnil);
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 800
diff changeset
1481 return Qnil; /* not (usually) reached */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 DEFUN ("ash", Fash, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 Return VALUE with its bits shifted left by COUNT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 If COUNT is negative, shifting is actually to the right.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 In this case, the sign bit is duplicated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 (value, count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 CHECK_INT_COERCE_CHAR (value);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 CONCHECK_INT (count);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 return make_int (XINT (count) > 0 ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495 XINT (value) << XINT (count) :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 XINT (value) >> -XINT (count));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 DEFUN ("lsh", Flsh, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 Return VALUE with its bits shifted left by COUNT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 If COUNT is negative, shifting is actually to the right.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 In this case, zeros are shifted in on the left.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 (value, count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 CHECK_INT_COERCE_CHAR (value);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 CONCHECK_INT (count);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 return make_int (XINT (count) > 0 ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 XUINT (value) << XINT (count) :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 XUINT (value) >> -XINT (count));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 DEFUN ("1+", Fadd1, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 Return NUMBER plus one. NUMBER may be a number, character or marker.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 Markers and characters are converted to integers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 (number))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 if (INTP (number)) return make_int (XINT (number) + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 if (CHARP (number)) return make_int (XCHAR (number) + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 if (MARKERP (number)) return make_int (marker_position (number) + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 if (FLOATP (number)) return make_float (XFLOAT_DATA (number) + 1.0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 number = wrong_type_argument (Qnumber_char_or_marker_p, number);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 DEFUN ("1-", Fsub1, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 Return NUMBER minus one. NUMBER may be a number, character or marker.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533 Markers and characters are converted to integers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 (number))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 if (INTP (number)) return make_int (XINT (number) - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 if (CHARP (number)) return make_int (XCHAR (number) - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 if (MARKERP (number)) return make_int (marker_position (number) - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 if (FLOATP (number)) return make_float (XFLOAT_DATA (number) - 1.0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544 number = wrong_type_argument (Qnumber_char_or_marker_p, number);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 /* weak lists */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553 /* A weak list is like a normal list except that elements automatically
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 disappear when no longer in use, i.e. when no longer GC-protected.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555 The basic idea is that we don't mark the elements during GC, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556 wait for them to be marked elsewhere. If they're not marked, we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557 remove them. This is analogous to weak hash tables; see the explanation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 there for more info. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 static Lisp_Object Vall_weak_lists; /* Gemarke es nicht!!! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 static Lisp_Object encode_weak_list_type (enum weak_list_type type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 mark_weak_list (Lisp_Object obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567 return Qnil; /* nichts ist gemarkt */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 print_weak_list (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573 if (print_readably)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
1574 printing_unreadable_object ("#<weak-list>");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1575
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
1576 write_fmt_string_lisp (printcharfun, "#<weak-list %s %S>", 2,
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
1577 encode_weak_list_type (XWEAK_LIST (obj)->type),
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
1578 XWEAK_LIST (obj)->list);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1581 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582 weak_list_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1584 struct weak_list *w1 = XWEAK_LIST (obj1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 struct weak_list *w2 = XWEAK_LIST (obj2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587 return ((w1->type == w2->type) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588 internal_equal (w1->list, w2->list, depth + 1));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1591 static Hashcode
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 weak_list_hash (Lisp_Object obj, int depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 struct weak_list *w = XWEAK_LIST (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1596 return HASH2 ((Hashcode) w->type,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597 internal_hash (w->list, depth + 1));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 make_weak_list (enum weak_list_type type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 Lisp_Object result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604 struct weak_list *wl =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 alloc_lcrecord_type (struct weak_list, &lrecord_weak_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 wl->list = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 wl->type = type;
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
1609 result = wrap_weak_list (wl);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 wl->next_weak = Vall_weak_lists;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 Vall_weak_lists = result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
1615 static const struct memory_description weak_list_description[] = {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1616 { XD_LISP_OBJECT, offsetof (struct weak_list, list) },
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1617 { XD_LO_LINK, offsetof (struct weak_list, next_weak) },
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 { XD_END }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620
934
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 888
diff changeset
1621 DEFINE_LRECORD_IMPLEMENTATION ("weak-list", weak_list,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 888
diff changeset
1622 1, /*dumpable-flag*/
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 888
diff changeset
1623 mark_weak_list, print_weak_list,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 888
diff changeset
1624 0, weak_list_equal, weak_list_hash,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 888
diff changeset
1625 weak_list_description,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 888
diff changeset
1626 struct weak_list);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628 -- we do not mark the list elements (either the elements themselves
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629 or the cons cells that hold them) in the normal marking phase.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 -- at the end of marking, we go through all weak lists that are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 marked, and mark the cons cells that hold all marked
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632 objects, and possibly parts of the objects themselves.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 (See alloc.c, "after-mark".)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 -- after that, we prune away all the cons cells that are not marked.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636 WARNING WARNING WARNING WARNING WARNING:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638 The code in the following two functions is *unbelievably* tricky.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1639 Don't mess with it. You'll be sorry.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 Linked lists just majorly suck, d'ya know?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1644 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645 finish_marking_weak_lists (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1646 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1647 Lisp_Object rest;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648 int did_mark = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1650 for (rest = Vall_weak_lists;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651 !NILP (rest);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652 rest = XWEAK_LIST (rest)->next_weak)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654 Lisp_Object rest2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655 enum weak_list_type type = XWEAK_LIST (rest)->type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657 if (! marked_p (rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 /* The weak list is probably garbage. Ignore it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661 for (rest2 = XWEAK_LIST (rest)->list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662 /* We need to be trickier since we're inside of GC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 use CONSP instead of !NILP in case of user-visible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 imperfect lists */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 CONSP (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 rest2 = XCDR (rest2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668 Lisp_Object elem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 /* If the element is "marked" (meaning depends on the type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670 of weak list), we need to mark the cons containing the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 element, and maybe the element itself (if only some part
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672 was already marked). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 int need_to_mark_cons = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 int need_to_mark_elem = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676 /* If a cons is already marked, then its car is already marked
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677 (either because of an external pointer or because of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678 a previous call to this function), and likewise for all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 the rest of the elements in the list, so we can stop now. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680 if (marked_p (rest2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 elem = XCAR (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 switch (type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 case WEAK_LIST_SIMPLE:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688 if (marked_p (elem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692 case WEAK_LIST_ASSOC:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 if (!CONSP (elem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695 /* just leave bogus elements there */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697 need_to_mark_elem = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 else if (marked_p (XCAR (elem)) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 marked_p (XCDR (elem)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 /* We still need to mark elem, because it's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 probably not marked. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705 need_to_mark_elem = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 case WEAK_LIST_KEY_ASSOC:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 if (!CONSP (elem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 /* just leave bogus elements there */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 need_to_mark_elem = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716 else if (marked_p (XCAR (elem)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719 /* We still need to mark elem and XCDR (elem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720 marking elem does both */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 need_to_mark_elem = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725 case WEAK_LIST_VALUE_ASSOC:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 if (!CONSP (elem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 /* just leave bogus elements there */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730 need_to_mark_elem = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 else if (marked_p (XCDR (elem)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 /* We still need to mark elem and XCAR (elem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736 marking elem does both */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 need_to_mark_elem = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1741 case WEAK_LIST_FULL_ASSOC:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1742 if (!CONSP (elem))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1743 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1744 /* just leave bogus elements there */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1745 need_to_mark_cons = 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1746 need_to_mark_elem = 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1747 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1748 else if (marked_p (XCAR (elem)) ||
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1749 marked_p (XCDR (elem)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1750 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1751 need_to_mark_cons = 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1752 /* We still need to mark elem and XCAR (elem);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1753 marking elem does both */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1754 need_to_mark_elem = 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1755 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1756 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1757
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1759 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 if (need_to_mark_elem && ! marked_p (elem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764 mark_object (elem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765 did_mark = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1767
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1768 /* We also need to mark the cons that holds the elem or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 assoc-pair. We do *not* want to call (mark_object) here
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1770 because that will mark the entire list; we just want to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1771 mark the cons itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1772 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773 if (need_to_mark_cons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1774 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1775 Lisp_Cons *c = XCONS (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776 if (!CONS_MARKED_P (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778 MARK_CONS (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779 did_mark = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1780 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784 /* In case of imperfect list, need to mark the final cons
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 because we're not removing it */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786 if (!NILP (rest2) && ! marked_p (rest2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788 mark_object (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789 did_mark = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1791 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 return did_mark;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1796 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 prune_weak_lists (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799 Lisp_Object rest, prev = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1800
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801 for (rest = Vall_weak_lists;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802 !NILP (rest);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 rest = XWEAK_LIST (rest)->next_weak)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805 if (! (marked_p (rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1806 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807 /* This weak list itself is garbage. Remove it from the list. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808 if (NILP (prev))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809 Vall_weak_lists = XWEAK_LIST (rest)->next_weak;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1811 XWEAK_LIST (prev)->next_weak =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812 XWEAK_LIST (rest)->next_weak;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1813 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1814 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816 Lisp_Object rest2, prev2 = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1817 Lisp_Object tortoise;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1818 int go_tortoise = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1820 for (rest2 = XWEAK_LIST (rest)->list, tortoise = rest2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 /* We need to be trickier since we're inside of GC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1822 use CONSP instead of !NILP in case of user-visible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1823 imperfect lists */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1824 CONSP (rest2);)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1826 /* It suffices to check the cons for marking,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1827 regardless of the type of weak list:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1828
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1829 -- if the cons is pointed to somewhere else,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830 then it should stay around and will be marked.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831 -- otherwise, if it should stay around, it will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1832 have been marked in finish_marking_weak_lists().
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1833 -- otherwise, it's not marked and should disappear.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1834 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1835 if (! marked_p (rest2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1837 /* bye bye :-( */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1838 if (NILP (prev2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839 XWEAK_LIST (rest)->list = XCDR (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1840 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1841 XCDR (prev2) = XCDR (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1842 rest2 = XCDR (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1843 /* Ouch. Circularity checking is even trickier
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1844 than I thought. When we cut out a link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845 like this, we can't advance the turtle or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1846 it'll catch up to us. Imagine that we're
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847 standing on floor tiles and moving forward --
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1848 what we just did here is as if the floor
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849 tile under us just disappeared and all the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1850 ones ahead of us slid one tile towards us.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851 In other words, we didn't move at all;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1852 if the tortoise was one step behind us
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853 previously, it still is, and therefore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1854 it must not move. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1855 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 prev2 = rest2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 /* Implementing circularity checking is trickier here
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 than in other places because we have to guarantee
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862 that we've processed all elements before exiting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863 due to a circularity. (In most places, an error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 is issued upon encountering a circularity, so it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865 doesn't really matter if all elements are processed.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 The idea is that we process along with the hare
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 rather than the tortoise. If at any point in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 our forward process we encounter the tortoise,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869 we must have already visited the spot, so we exit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870 (If we process with the tortoise, we can fail to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 process cases where a cons points to itself, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872 where cons A points to cons B, which points to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873 cons A.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875 rest2 = XCDR (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 if (go_tortoise)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 tortoise = XCDR (tortoise);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878 go_tortoise = !go_tortoise;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879 if (EQ (rest2, tortoise))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1883
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884 prev = rest;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 static enum weak_list_type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890 decode_weak_list_type (Lisp_Object symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 CHECK_SYMBOL (symbol);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893 if (EQ (symbol, Qsimple)) return WEAK_LIST_SIMPLE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894 if (EQ (symbol, Qassoc)) return WEAK_LIST_ASSOC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 if (EQ (symbol, Qold_assoc)) return WEAK_LIST_ASSOC; /* EBOLA ALERT! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896 if (EQ (symbol, Qkey_assoc)) return WEAK_LIST_KEY_ASSOC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 if (EQ (symbol, Qvalue_assoc)) return WEAK_LIST_VALUE_ASSOC;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1898 if (EQ (symbol, Qfull_assoc)) return WEAK_LIST_FULL_ASSOC;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
1900 invalid_constant ("Invalid weak list type", symbol);
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
1901 RETURN_NOT_REACHED (WEAK_LIST_SIMPLE);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1902 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1903
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905 encode_weak_list_type (enum weak_list_type type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1906 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1907 switch (type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1908 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909 case WEAK_LIST_SIMPLE: return Qsimple;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910 case WEAK_LIST_ASSOC: return Qassoc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911 case WEAK_LIST_KEY_ASSOC: return Qkey_assoc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912 case WEAK_LIST_VALUE_ASSOC: return Qvalue_assoc;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1913 case WEAK_LIST_FULL_ASSOC: return Qfull_assoc;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1914 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 800
diff changeset
1918 return Qnil; /* not (usually) reached */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921 DEFUN ("weak-list-p", Fweak_list_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 Return non-nil if OBJECT is a weak list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1923 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1924 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1925 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 return WEAK_LISTP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1929 DEFUN ("make-weak-list", Fmake_weak_list, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1930 Return a new weak list object of type TYPE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1931 A weak list object is an object that contains a list. This list behaves
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 like any other list except that its elements do not count towards
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 452
diff changeset
1933 garbage collection -- if the only pointer to an object is inside a weak
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934 list (other than pointers in similar objects such as weak hash tables),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1935 the object is garbage collected and automatically removed from the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936 This is used internally, for example, to manage the list holding the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1937 children of an extent -- an extent that is unused but has a parent will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1938 still be reclaimed, and will automatically be removed from its parent's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1939 list of children.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1940
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1941 Optional argument TYPE specifies the type of the weak list, and defaults
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1942 to `simple'. Recognized types are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944 `simple' Objects in the list disappear if not pointed to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 `assoc' Objects in the list disappear if they are conses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946 and either the car or the cdr of the cons is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 pointed to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948 `key-assoc' Objects in the list disappear if they are conses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949 and the car is not pointed to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 `value-assoc' Objects in the list disappear if they are conses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951 and the cdr is not pointed to.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1952 `full-assoc' Objects in the list disappear if they are conses
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1953 and neither the car nor the cdr is pointed to.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 (type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1957 if (NILP (type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958 type = Qsimple;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1959
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 return make_weak_list (decode_weak_list_type (type));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963 DEFUN ("weak-list-type", Fweak_list_type, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964 Return the type of the given weak-list object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966 (weak))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968 CHECK_WEAK_LIST (weak);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969 return encode_weak_list_type (XWEAK_LIST (weak)->type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972 DEFUN ("weak-list-list", Fweak_list_list, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1973 Return the list contained in a weak-list object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1974 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1975 (weak))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1977 CHECK_WEAK_LIST (weak);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978 return XWEAK_LIST_LIST (weak);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981 DEFUN ("set-weak-list-list", Fset_weak_list_list, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982 Change the list contained in a weak-list object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984 (weak, new_list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1986 CHECK_WEAK_LIST (weak);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987 XWEAK_LIST_LIST (weak) = new_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1988 return new_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
1991
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
1992 /************************************************************************/
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
1993 /* weak boxes */
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
1994 /************************************************************************/
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
1995
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
1996 static Lisp_Object Vall_weak_boxes; /* Gemarke es niemals ever!!! */
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
1997
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
1998 void
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
1999 prune_weak_boxes (void)
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2000 {
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2001 Lisp_Object rest, prev = Qnil;
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2002 int removep = 0;
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2003
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2004 for (rest = Vall_weak_boxes;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2005 !NILP(rest);
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2006 rest = XWEAK_BOX (rest)->next_weak_box)
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2007 {
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2008 if (! (marked_p (rest)))
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2009 /* This weak box itself is garbage. */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2010 removep = 1;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2011
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2012 if (! marked_p (XWEAK_BOX (rest)->value))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2013 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2014 XSET_WEAK_BOX (rest, Qnil);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2015 removep = 1;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2016 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2017
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2018 if (removep)
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2019 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2020 /* Remove weak box from list. */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2021 if (NILP (prev))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2022 Vall_weak_boxes = XWEAK_BOX (rest)->next_weak_box;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2023 else
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2024 XWEAK_BOX (prev)->next_weak_box = XWEAK_BOX (rest)->next_weak_box;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2025 removep = 0;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2026 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2027 else
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2028 prev = rest;
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2029 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2030 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2031
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2032 static Lisp_Object
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2033 mark_weak_box (Lisp_Object obj)
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2034 {
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2035 return Qnil;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2036 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2037
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2038 static void
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2039 print_weak_box (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2040 {
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2041 if (print_readably)
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2042 printing_unreadable_object ("#<weak_box>");
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2043 write_fmt_string (printcharfun, "#<weak_box>");
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2044 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2045
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2046 static int
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2047 weak_box_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2048 {
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2049 struct weak_box *wb1 = XWEAK_BOX (obj1);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2050 struct weak_box *wb2 = XWEAK_BOX (obj2);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2051
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2052 return (internal_equal (wb1->value, wb2->value, depth + 1));
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2053 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2054
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2055 static Hashcode
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2056 weak_box_hash (Lisp_Object obj, int depth)
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2057 {
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2058 struct weak_box *wb = XWEAK_BOX (obj);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2059
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2060 return internal_hash (wb->value, depth + 1);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2061 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2062
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2063 Lisp_Object
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2064 make_weak_box (Lisp_Object value)
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2065 {
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2066 Lisp_Object result;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2067
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2068 struct weak_box *wb =
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2069 alloc_lcrecord_type (struct weak_box, &lrecord_weak_box);
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2070
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2071 wb->value = value;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2072 result = wrap_weak_box (wb);
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2073 wb->next_weak_box = Vall_weak_boxes;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2074 Vall_weak_boxes = result;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2075 return result;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2076 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2077
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
2078 static const struct memory_description weak_box_description[] = {
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2079 { XD_LO_LINK, offsetof (struct weak_box, value) },
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2080 { XD_END}
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2081 };
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2082
934
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 888
diff changeset
2083 DEFINE_LRECORD_IMPLEMENTATION ("weak_box", weak_box,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 888
diff changeset
2084 0, /*dumpable-flag*/
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 888
diff changeset
2085 mark_weak_box, print_weak_box,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 888
diff changeset
2086 0, weak_box_equal, weak_box_hash,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 888
diff changeset
2087 weak_box_description,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 888
diff changeset
2088 struct weak_box);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2089
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2090 DEFUN ("make-weak-box", Fmake_weak_box, 1, 1, 0, /*
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2091 Return a new weak box from value CONTENTS.
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2092 The weak box is a reference to CONTENTS which may be extracted with
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2093 `weak-box-ref'. However, the weak box does not contribute to the
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2094 reachability of CONTENTS. When CONTENTS is garbage-collected,
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2095 `weak-box-ref' will return NIL.
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2096 */
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2097 (value))
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2098 {
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2099 return make_weak_box(value);
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2100 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2101
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2102 DEFUN ("weak-box-ref", Fweak_box_ref, 1, 1, 0, /*
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2103 Return the contents of weak box WEAK-BOX.
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2104 If the contents have been GCed, return NIL.
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2105 */
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2106 (wb))
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2107 {
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2108 return XWEAK_BOX (wb)->value;
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2109 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2110
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2111 DEFUN ("weak-box-p", Fweak_boxp, 1, 1, 0, /*
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2112 Return non-nil if OBJECT is a weak box.
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2113 */
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2114 (object))
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2115 {
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2116 return WEAK_BOXP (object) ? Qt : Qnil;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2117 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2118
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2119 /************************************************************************/
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2120 /* ephemerons */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2121 /************************************************************************/
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2122
993
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
2123 /* The concept of ephemerons is due to:
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
2124 * Barry Hayes: Ephemerons: A New Finalization Mechanism. OOPSLA 1997: 176-183
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
2125 * The original idea is due to George Bosworth of Digitalk, Inc.
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
2126 *
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
2127 * For a discussion of finalization and weakness that also reviews
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
2128 * ephemerons, refer to:
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
2129 * Simon Peyton Jones, Simon Marlow, Conal Elliot:
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
2130 * Stretching the storage manager
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
2131 * Implementation of Functional Languages, 1999
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
2132 */
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
2133
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2134 static Lisp_Object Vall_ephemerons; /* Gemarke es niemals ever!!! */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2135 static Lisp_Object Vfinalize_list;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2136
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2137 int
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2138 finish_marking_ephemerons(void)
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2139 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2140 Lisp_Object rest;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2141 int did_mark = 0;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2142
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2143 for (rest = Vall_ephemerons;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2144 !NILP (rest);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2145 rest = XEPHEMERON_NEXT (rest))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2146 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2147 if (marked_p (rest) && ! marked_p (XEPHEMERON (rest)->cons_chain))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2148 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2149 MARK_CONS (XCONS (XEPHEMERON (rest)->cons_chain));
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2150 mark_object (XCAR (XEPHEMERON (rest)->cons_chain));
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2151 did_mark = 1;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2152 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2153 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2154 return did_mark;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2155 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2156
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2157 void
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2158 prune_ephemerons(void)
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2159 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2160 int removep = 0;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2161 Lisp_Object rest = Vall_ephemerons, next, prev = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2162
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2163 while (! NILP (rest))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2164 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2165 next = XEPHEMERON_NEXT (rest);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2166
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2167 if (marked_p (rest))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2168 /* The ephemeron itself is live ... */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2169 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2170 if (! marked_p(XEPHEMERON (rest)->key))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2171 /* ... but its key is garbage */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2172 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2173 removep = 1;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2174 XSET_EPHEMERON_VALUE (rest, Qnil);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2175 if (! NILP (XEPHEMERON_FINALIZER (rest)))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2176 /* Register the finalizer */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2177 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2178 XSET_EPHEMERON_NEXT (rest, Vfinalize_list);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2179 Vfinalize_list = XEPHEMERON (rest)->cons_chain;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2180 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2181 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2182 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2183 else
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2184 /* The ephemeron itself is dead. */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2185 removep = 1;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2186
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2187 if (removep)
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2188 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2189 /* Remove it from the list. */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2190 if (NILP (prev))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2191 Vall_ephemerons = next;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2192 else
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2193 XSET_EPHEMERON_NEXT (prev, next);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2194 removep = 0;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2195 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2196 else
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2197 prev = rest;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2198
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2199 rest = next;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2200 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2201 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2202
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2203 Lisp_Object
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2204 zap_finalize_list(void)
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2205 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2206 Lisp_Object finalizers = Vfinalize_list;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2207
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2208 Vfinalize_list = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2209
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2210 return finalizers;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2211 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2212
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2213 static Lisp_Object
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2214 mark_ephemeron (Lisp_Object obj)
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2215 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2216 return Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2217 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2218
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2219 static void
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2220 print_ephemeron (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2221 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2222 if (print_readably)
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2223 printing_unreadable_object ("#<ephemeron>");
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2224 write_fmt_string (printcharfun, "#<ephemeron>");
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2225 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2226
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2227 static int
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2228 ephemeron_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2229 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2230 return
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2231 internal_equal (XEPHEMERON_REF (obj1), XEPHEMERON_REF(obj2), depth + 1);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2232 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2233
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2234 static Hashcode
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2235 ephemeron_hash(Lisp_Object obj, int depth)
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2236 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2237 return internal_hash (XEPHEMERON_REF (obj), depth + 1);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2238 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2239
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2240 Lisp_Object
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2241 make_ephemeron(Lisp_Object key, Lisp_Object value, Lisp_Object finalizer)
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2242 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2243 Lisp_Object result, temp = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2244 struct gcpro gcpro1, gcpro2;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2245
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2246 struct ephemeron *eph =
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2247 alloc_lcrecord_type (struct ephemeron, &lrecord_ephemeron);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2248
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2249 eph->key = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2250 eph->cons_chain = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2251 eph->value = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2252
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2253 result = wrap_ephemeron(eph);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2254 GCPRO2 (result, temp);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2255
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2256 eph->key = key;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2257 temp = Fcons(value, finalizer);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2258 eph->cons_chain = Fcons(temp, Vall_ephemerons);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2259 eph->value = value;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2260
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2261 Vall_ephemerons = result;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2262
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2263 UNGCPRO;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2264 return result;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2265 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2266
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
2267 static const struct memory_description ephemeron_description[] = {
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
2268 { XD_LISP_OBJECT, offsetof(struct ephemeron, key),
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
2269 0, 0, XD_FLAG_NO_KKCC },
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
2270 { XD_LISP_OBJECT, offsetof(struct ephemeron, cons_chain),
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
2271 0, 0, XD_FLAG_NO_KKCC },
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
2272 { XD_LISP_OBJECT, offsetof(struct ephemeron, value),
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
2273 0, 0, XD_FLAG_NO_KKCC },
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2274 { XD_END }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2275 };
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2276
934
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 888
diff changeset
2277 DEFINE_LRECORD_IMPLEMENTATION ("ephemeron", ephemeron,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 888
diff changeset
2278 0, /*dumpable-flag*/
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 888
diff changeset
2279 mark_ephemeron, print_ephemeron,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 888
diff changeset
2280 0, ephemeron_equal, ephemeron_hash,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 888
diff changeset
2281 ephemeron_description,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 888
diff changeset
2282 struct ephemeron);
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2283
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2284 DEFUN ("make-ephemeron", Fmake_ephemeron, 2, 3, 0, /*
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2285 Return a new ephemeron with key KEY, value CONTENTS, and finalizer FINALIZER.
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2286 The ephemeron is a reference to CONTENTS which may be extracted with
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2287 `ephemeron-ref'. CONTENTS is only reachable through the ephemeron as
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2288 long as KEY is reachable; the ephemeron does not contribute to the
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2289 reachability of KEY. When KEY becomes unreachable while the ephemeron
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2290 itself is still reachable, CONTENTS is queued for finalization: FINALIZER
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2291 will possibly be called on CONTENTS some time in the future. Moreover,
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2292 future calls to `ephemeron-ref' will return NIL.
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2293 */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2294 (key, value, finalizer))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2295 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2296 return make_ephemeron(key, value, finalizer);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2297 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2298
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2299 DEFUN ("ephemeron-ref", Fephemeron_ref, 1, 1, 0, /*
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2300 Return the contents of ephemeron EPHEMERON.
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2301 If the contents have been GCed, return NIL.
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2302 */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2303 (eph))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2304 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2305 return XEPHEMERON_REF (eph);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2306 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2307
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2308 DEFUN ("ephemeron-p", Fephemeronp, 1, 1, 0, /*
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2309 Return non-nil if OBJECT is an ephemeron.
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2310 */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2311 (object))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2312 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2313 return EPHEMERONP (object) ? Qt : Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2314 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2315
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2316 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2317 /* initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2318 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2319
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2320 static SIGTYPE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2321 arith_error (int signo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2322 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2323 EMACS_REESTABLISH_SIGNAL (signo, arith_error);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2324 EMACS_UNBLOCK_SIGNAL (signo);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2325 signal_error (Qarith_error, 0, Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2326 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2327
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2328 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2329 init_data_very_early (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2330 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2331 /* Don't do this if just dumping out.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2332 We don't want to call `signal' in this case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2333 so that we don't have trouble with dumping
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2334 signal-delivering routines in an inconsistent state. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2335 #ifndef CANNOT_DUMP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2336 if (!initialized)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2337 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2338 #endif /* CANNOT_DUMP */
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 603
diff changeset
2339 EMACS_SIGNAL (SIGFPE, arith_error);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2340 #ifdef uts
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 603
diff changeset
2341 EMACS_SIGNAL (SIGEMT, arith_error);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2342 #endif /* uts */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2343 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2345 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2346 init_errors_once_early (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2347 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2348 DEFSYMBOL (Qerror_conditions);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2349 DEFSYMBOL (Qerror_message);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2350
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2351 /* We declare the errors here because some other deferrors depend
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2352 on some of the errors below. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2353
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2354 /* ERROR is used as a signaler for random errors for which nothing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2355 else is right */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2356
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2357 DEFERROR (Qerror, "error", Qnil);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2358 DEFERROR_STANDARD (Qquit, Qnil);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2359
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2360 DEFERROR_STANDARD (Qinvalid_argument, Qerror);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2361
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2362 DEFERROR_STANDARD (Qsyntax_error, Qinvalid_argument);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2363 DEFERROR_STANDARD (Qinvalid_read_syntax, Qsyntax_error);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2364 DEFERROR_STANDARD (Qstructure_formation_error, Qsyntax_error);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2365 DEFERROR_STANDARD (Qlist_formation_error, Qstructure_formation_error);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2366 DEFERROR_STANDARD (Qmalformed_list, Qlist_formation_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2367 DEFERROR_STANDARD (Qmalformed_property_list, Qmalformed_list);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2368 DEFERROR_STANDARD (Qcircular_list, Qlist_formation_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2369 DEFERROR_STANDARD (Qcircular_property_list, Qcircular_list);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2370
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2371 DEFERROR_STANDARD (Qwrong_type_argument, Qinvalid_argument);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2372 DEFERROR_STANDARD (Qargs_out_of_range, Qinvalid_argument);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2373 DEFERROR_STANDARD (Qwrong_number_of_arguments, Qinvalid_argument);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2374 DEFERROR_STANDARD (Qinvalid_function, Qinvalid_argument);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2375 DEFERROR_STANDARD (Qinvalid_constant, Qinvalid_argument);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2376 DEFERROR (Qno_catch, "No catch for tag", Qinvalid_argument);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2377
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2378 DEFERROR_STANDARD (Qinvalid_state, Qerror);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2379 DEFERROR (Qvoid_function, "Symbol's function definition is void",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2380 Qinvalid_state);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2381 DEFERROR (Qcyclic_function_indirection,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2382 "Symbol's chain of function indirections contains a loop",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2383 Qinvalid_state);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2384 DEFERROR (Qvoid_variable, "Symbol's value as variable is void",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2385 Qinvalid_state);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2386 DEFERROR (Qcyclic_variable_indirection,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2387 "Symbol's chain of variable indirections contains a loop",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2388 Qinvalid_state);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2389 DEFERROR_STANDARD (Qstack_overflow, Qinvalid_state);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2390 DEFERROR_STANDARD (Qinternal_error, Qinvalid_state);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2391 DEFERROR_STANDARD (Qout_of_memory, Qinvalid_state);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2392
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2393 DEFERROR_STANDARD (Qinvalid_operation, Qerror);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2394 DEFERROR_STANDARD (Qinvalid_change, Qinvalid_operation);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2395 DEFERROR (Qsetting_constant, "Attempt to set a constant symbol",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2396 Qinvalid_change);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2397 DEFERROR_STANDARD (Qprinting_unreadable_object, Qinvalid_operation);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2398 DEFERROR (Qunimplemented, "Feature not yet implemented", Qinvalid_operation);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2399
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2400 DEFERROR_STANDARD (Qediting_error, Qinvalid_operation);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2401 DEFERROR_STANDARD (Qbeginning_of_buffer, Qediting_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2402 DEFERROR_STANDARD (Qend_of_buffer, Qediting_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2403 DEFERROR (Qbuffer_read_only, "Buffer is read-only", Qediting_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2404
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2405 DEFERROR (Qio_error, "IO Error", Qinvalid_operation);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2406 DEFERROR_STANDARD (Qfile_error, Qio_error);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2407 DEFERROR (Qend_of_file, "End of file or stream", Qfile_error);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2408 DEFERROR_STANDARD (Qconversion_error, Qio_error);
580
55e998c311f5 [xemacs-hg @ 2001-05-26 12:24:50 by ben]
ben
parents: 563
diff changeset
2409 DEFERROR_STANDARD (Qtext_conversion_error, Qconversion_error);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2410
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2411 DEFERROR (Qarith_error, "Arithmetic error", Qinvalid_operation);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2412 DEFERROR (Qrange_error, "Arithmetic range error", Qarith_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2413 DEFERROR (Qdomain_error, "Arithmetic domain error", Qarith_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2414 DEFERROR (Qsingularity_error, "Arithmetic singularity error", Qdomain_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2415 DEFERROR (Qoverflow_error, "Arithmetic overflow error", Qdomain_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2416 DEFERROR (Qunderflow_error, "Arithmetic underflow error", Qdomain_error);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2417 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2419 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2420 syms_of_data (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2421 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2422 INIT_LRECORD_IMPLEMENTATION (weak_list);
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2423 INIT_LRECORD_IMPLEMENTATION (ephemeron);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2424 INIT_LRECORD_IMPLEMENTATION (weak_box);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2425
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2426 DEFSYMBOL (Qquote);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2427 DEFSYMBOL (Qlambda);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2428 DEFSYMBOL (Qlistp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2429 DEFSYMBOL (Qtrue_list_p);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2430 DEFSYMBOL (Qconsp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2431 DEFSYMBOL (Qsubrp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2432 DEFSYMBOL (Qsymbolp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2433 DEFSYMBOL (Qintegerp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2434 DEFSYMBOL (Qcharacterp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2435 DEFSYMBOL (Qnatnump);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2436 DEFSYMBOL (Qstringp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2437 DEFSYMBOL (Qarrayp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2438 DEFSYMBOL (Qsequencep);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2439 DEFSYMBOL (Qbufferp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2440 DEFSYMBOL (Qbitp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2441 DEFSYMBOL_MULTIWORD_PREDICATE (Qbit_vectorp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2442 DEFSYMBOL (Qvectorp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2443 DEFSYMBOL (Qchar_or_string_p);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2444 DEFSYMBOL (Qmarkerp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2445 DEFSYMBOL (Qinteger_or_marker_p);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2446 DEFSYMBOL (Qinteger_or_char_p);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2447 DEFSYMBOL (Qinteger_char_or_marker_p);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2448 DEFSYMBOL (Qnumberp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2449 DEFSYMBOL (Qnumber_char_or_marker_p);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2450 DEFSYMBOL (Qcdr);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2451 DEFSYMBOL (Qerror_lacks_explanatory_string);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2452 DEFSYMBOL_MULTIWORD_PREDICATE (Qweak_listp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2453 DEFSYMBOL (Qfloatp);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2454
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2455 DEFSUBR (Fwrong_type_argument);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2456
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2457 DEFSUBR (Feq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2458 DEFSUBR (Fold_eq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2459 DEFSUBR (Fnull);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2460 Ffset (intern ("not"), intern ("null"));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2461 DEFSUBR (Flistp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2462 DEFSUBR (Fnlistp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2463 DEFSUBR (Ftrue_list_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2464 DEFSUBR (Fconsp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2465 DEFSUBR (Fatom);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2466 DEFSUBR (Fchar_or_string_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2467 DEFSUBR (Fcharacterp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2468 DEFSUBR (Fchar_int_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2469 DEFSUBR (Fchar_to_int);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2470 DEFSUBR (Fint_to_char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2471 DEFSUBR (Fchar_or_char_int_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2472 DEFSUBR (Fintegerp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2473 DEFSUBR (Finteger_or_marker_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2474 DEFSUBR (Finteger_or_char_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2475 DEFSUBR (Finteger_char_or_marker_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2476 DEFSUBR (Fnumberp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2477 DEFSUBR (Fnumber_or_marker_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2478 DEFSUBR (Fnumber_char_or_marker_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2479 DEFSUBR (Ffloatp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2480 DEFSUBR (Fnatnump);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2481 DEFSUBR (Fsymbolp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2482 DEFSUBR (Fkeywordp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2483 DEFSUBR (Fstringp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2484 DEFSUBR (Fvectorp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2485 DEFSUBR (Fbitp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2486 DEFSUBR (Fbit_vector_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2487 DEFSUBR (Farrayp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2488 DEFSUBR (Fsequencep);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2489 DEFSUBR (Fmarkerp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2490 DEFSUBR (Fsubrp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2491 DEFSUBR (Fsubr_min_args);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2492 DEFSUBR (Fsubr_max_args);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2493 DEFSUBR (Fsubr_interactive);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2494 DEFSUBR (Ftype_of);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2495 DEFSUBR (Fcar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2496 DEFSUBR (Fcdr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2497 DEFSUBR (Fcar_safe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2498 DEFSUBR (Fcdr_safe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2499 DEFSUBR (Fsetcar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2500 DEFSUBR (Fsetcdr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2501 DEFSUBR (Findirect_function);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2502 DEFSUBR (Faref);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2503 DEFSUBR (Faset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2504
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2505 DEFSUBR (Fnumber_to_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2506 DEFSUBR (Fstring_to_number);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2507 DEFSUBR (Feqlsign);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2508 DEFSUBR (Flss);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2509 DEFSUBR (Fgtr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2510 DEFSUBR (Fleq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2511 DEFSUBR (Fgeq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2512 DEFSUBR (Fneq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2513 DEFSUBR (Fzerop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2514 DEFSUBR (Fplus);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2515 DEFSUBR (Fminus);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2516 DEFSUBR (Ftimes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2517 DEFSUBR (Fquo);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2518 DEFSUBR (Frem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2519 DEFSUBR (Fmod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2520 DEFSUBR (Fmax);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2521 DEFSUBR (Fmin);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2522 DEFSUBR (Flogand);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2523 DEFSUBR (Flogior);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2524 DEFSUBR (Flogxor);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2525 DEFSUBR (Flsh);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2526 DEFSUBR (Fash);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2527 DEFSUBR (Fadd1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2528 DEFSUBR (Fsub1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2529 DEFSUBR (Flognot);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2530
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2531 DEFSUBR (Fweak_list_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2532 DEFSUBR (Fmake_weak_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2533 DEFSUBR (Fweak_list_type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2534 DEFSUBR (Fweak_list_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2535 DEFSUBR (Fset_weak_list_list);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2536
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2537 DEFSUBR (Fmake_ephemeron);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2538 DEFSUBR (Fephemeron_ref);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2539 DEFSUBR (Fephemeronp);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2540 DEFSUBR (Fmake_weak_box);
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2541 DEFSUBR (Fweak_box_ref);
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2542 DEFSUBR (Fweak_boxp);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2543 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2544
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2545 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2546 vars_of_data (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2547 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2548 /* This must not be staticpro'd */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2549 Vall_weak_lists = Qnil;
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 444
diff changeset
2550 dump_add_weak_object_chain (&Vall_weak_lists);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2551
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2552 Vall_ephemerons = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2553 dump_add_weak_object_chain (&Vall_ephemerons);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2554
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2555 Vfinalize_list = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2556 staticpro (&Vfinalize_list);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
2557
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2558 Vall_weak_boxes = Qnil;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2559 dump_add_weak_object_chain (&Vall_weak_boxes);
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
2560
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2561 #ifdef DEBUG_XEMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2562 DEFVAR_BOOL ("debug-issue-ebola-notices", &debug_issue_ebola_notices /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2563 If non-zero, note when your code may be suffering from char-int confoundance.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2564 That is to say, if XEmacs encounters a usage of `eq', `memq', `equal',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2565 etc. where an int and a char with the same value are being compared,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2566 it will issue a notice on stderr to this effect, along with a backtrace.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2567 In such situations, the result would be different in XEmacs 19 versus
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2568 XEmacs 20, and you probably don't want this.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2569
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2570 Note that in order to see these notices, you have to byte compile your
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2571 code under XEmacs 20 -- any code byte-compiled under XEmacs 19 will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2572 have its chars and ints all confounded in the byte code, making it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2573 impossible to accurately determine Ebola infection.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2574 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2575
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2576 debug_issue_ebola_notices = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2577
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2578 DEFVAR_INT ("debug-ebola-backtrace-length",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2579 &debug_ebola_backtrace_length /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2580 Length (in stack frames) of short backtrace printed out in Ebola notices.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2581 See `debug-issue-ebola-notices'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2582 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2583 debug_ebola_backtrace_length = 32;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2585 #endif /* DEBUG_XEMACS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2586 }