Mercurial > hg > xemacs-beta
comparison src/lread.c @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | de805c49cfc1 |
children | 11054d720c21 |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
216 ? (build_string ("internal input stream")) \ | 216 ? (build_string ("internal input stream")) \ |
217 : (x)) | 217 : (x)) |
218 | 218 |
219 | 219 |
220 static DOESNT_RETURN | 220 static DOESNT_RETURN |
221 syntax_error (const char *string) | 221 syntax_error (CONST char *string) |
222 { | 222 { |
223 signal_error (Qinvalid_read_syntax, | 223 signal_error (Qinvalid_read_syntax, |
224 list1 (build_translated_string (string))); | 224 list1 (build_translated_string (string))); |
225 } | 225 } |
226 | 226 |
227 static Lisp_Object | 227 static Lisp_Object |
228 continuable_syntax_error (const char *string) | 228 continuable_syntax_error (CONST char *string) |
229 { | 229 { |
230 return Fsignal (Qinvalid_read_syntax, | 230 return Fsignal (Qinvalid_read_syntax, |
231 list1 (build_translated_string (string))); | 231 list1 (build_translated_string (string))); |
232 } | 232 } |
233 | 233 |
257 { | 257 { |
258 Emchar c = Lstream_get_emchar (XLSTREAM (readcharfun)); | 258 Emchar c = Lstream_get_emchar (XLSTREAM (readcharfun)); |
259 #ifdef DEBUG_XEMACS /* testing Mule */ | 259 #ifdef DEBUG_XEMACS /* testing Mule */ |
260 static int testing_mule = 0; /* Change via debugger */ | 260 static int testing_mule = 0; /* Change via debugger */ |
261 if (testing_mule) { | 261 if (testing_mule) { |
262 if (c >= 0x20 && c <= 0x7E) stderr_out ("%c", c); | 262 if (c >= 0x20 && c <= 0x7E) fprintf (stderr, "%c", c); |
263 else if (c == '\n') stderr_out ("\\n\n"); | 263 else if (c == '\n') fprintf (stderr, "\\n\n"); |
264 else stderr_out ("\\%o ", c); | 264 else fprintf (stderr, "\\%o ", c); |
265 } | 265 } |
266 #endif | 266 #endif |
267 return c; | 267 return c; |
268 } | 268 } |
269 else if (MARKERP (readcharfun)) | 269 else if (MARKERP (readcharfun)) |
441 { | 441 { |
442 struct gcpro gcpro1; | 442 struct gcpro gcpro1; |
443 Lisp_Object list = Vload_force_doc_string_list; | 443 Lisp_Object list = Vload_force_doc_string_list; |
444 Lisp_Object tail; | 444 Lisp_Object tail; |
445 int fd = XINT (XCAR (Vload_descriptor_list)); | 445 int fd = XINT (XCAR (Vload_descriptor_list)); |
446 /* NOTE: If purify_flag is true, we're in-place modifying objects that | |
447 may be in purespace (and if not, they will be). Therefore, we have | |
448 to be VERY careful to make sure that all objects that we create | |
449 are purecopied -- objects in purespace are not marked for GC, and | |
450 if we leave any impure objects inside of pure ones, we're really | |
451 screwed. */ | |
446 | 452 |
447 GCPRO1 (list); | 453 GCPRO1 (list); |
448 /* restore the old value first just in case an error occurs. */ | 454 /* restore the old value first just in case an error occurs. */ |
449 Vload_force_doc_string_list = oldlist; | 455 Vload_force_doc_string_list = oldlist; |
450 | 456 |
471 | 477 |
472 NGCPRO1 (juan); | 478 NGCPRO1 (juan); |
473 ivan = Fread (juan); | 479 ivan = Fread (juan); |
474 if (!CONSP (ivan)) | 480 if (!CONSP (ivan)) |
475 signal_simple_error ("invalid lazy-loaded byte code", ivan); | 481 signal_simple_error ("invalid lazy-loaded byte code", ivan); |
476 XCOMPILED_FUNCTION (john)->instructions = XCAR (ivan); | 482 /* Remember to purecopy; see above. */ |
483 XCOMPILED_FUNCTION (john)->instructions = Fpurecopy (XCAR (ivan)); | |
477 /* v18 or v19 bytecode file. Need to Ebolify. */ | 484 /* v18 or v19 bytecode file. Need to Ebolify. */ |
478 if (XCOMPILED_FUNCTION (john)->flags.ebolified | 485 if (XCOMPILED_FUNCTION (john)->flags.ebolified |
479 && VECTORP (XCDR (ivan))) | 486 && VECTORP (XCDR (ivan))) |
480 ebolify_bytecode_constants (XCDR (ivan)); | 487 ebolify_bytecode_constants (XCDR (ivan)); |
481 XCOMPILED_FUNCTION (john)->constants = XCDR (ivan); | 488 XCOMPILED_FUNCTION (john)->constants = Fpurecopy (XCDR (ivan)); |
482 NUNGCPRO; | 489 NUNGCPRO; |
483 } | 490 } |
484 doc = compiled_function_documentation (XCOMPILED_FUNCTION (john)); | 491 doc = compiled_function_documentation (XCOMPILED_FUNCTION (john)); |
485 if (CONSP (doc)) | 492 if (CONSP (doc)) |
486 { | 493 { |
674 PRINT_LOADING_MESSAGE (""); | 681 PRINT_LOADING_MESSAGE (""); |
675 | 682 |
676 { | 683 { |
677 /* Lisp_Object's must be malloc'ed, not stack-allocated */ | 684 /* Lisp_Object's must be malloc'ed, not stack-allocated */ |
678 Lisp_Object lispstream = Qnil; | 685 Lisp_Object lispstream = Qnil; |
679 const int block_size = 8192; | 686 CONST int block_size = 8192; |
680 struct gcpro ngcpro1; | 687 struct gcpro ngcpro1; |
681 | 688 |
682 NGCPRO1 (lispstream); | 689 NGCPRO1 (lispstream); |
683 lispstream = make_filedesc_input_stream (fd, 0, -1, LSTR_CLOSING); | 690 lispstream = make_filedesc_input_stream (fd, 0, -1, LSTR_CLOSING); |
684 /* 64K is used for normal files; 8K should be OK here because Lisp | 691 /* 64K is used for normal files; 8K should be OK here because Lisp |
901 | 908 |
902 /* The SUFFIXES argument in any of the locate_file* functions can be | 909 /* The SUFFIXES argument in any of the locate_file* functions can be |
903 nil, a list, or a string (for backward compatibility), with the | 910 nil, a list, or a string (for backward compatibility), with the |
904 following semantics: | 911 following semantics: |
905 | 912 |
906 a) nil - no suffix, just search for file name intact | 913 a) nil - no suffix, just search for file name intact (semantically |
907 (semantically different from "empty suffix list", which | 914 different from "empty suffix list") |
908 would be meaningless.) | |
909 b) list - list of suffixes to append to file name. Each of these | 915 b) list - list of suffixes to append to file name. Each of these |
910 must be a string. | 916 must be a string. |
911 c) string - colon-separated suffixes to append to file name (backward | 917 c) string - colon-separated suffixes to append to file name (backward |
912 compatibility). | 918 compatibility). |
913 | 919 |
914 All of this got hairy, so I decided to use a mapper. Calling a | 920 All of this got hairy, so I decided to use write a mapper. Calling |
915 function for each suffix shouldn't slow things down, since | 921 a function for each suffix shouldn't slow things down, since |
916 locate_file is rarely called with enough suffixes for funcalls to | 922 locate_file is rarely call with enough suffixes for it to make a |
917 make any difference. */ | 923 difference. */ |
918 | 924 |
919 /* Map FUN over SUFFIXES, as described above. FUN will be called with a | 925 /* Map FUN over SUFFIXES, as described above. FUN will be called with a |
920 char * containing the current file name, and ARG. Mapping stops when | 926 char * containing the current file name, and ARG. Mapping stops when |
921 FUN returns non-zero. */ | 927 FUN returns non-zero. */ |
922 static void | 928 void |
923 locate_file_map_suffixes (Lisp_Object filename, Lisp_Object suffixes, | 929 locate_file_map_suffixes (Lisp_Object filename, Lisp_Object suffixes, |
924 int (*fun) (char *, void *), | 930 int (*fun) (char *, void *), |
925 void *arg) | 931 void *arg) |
926 { | 932 { |
927 /* This function can GC */ | 933 /* This function can GC */ |
976 } | 982 } |
977 } | 983 } |
978 else | 984 else |
979 { | 985 { |
980 /* Case c) */ | 986 /* Case c) */ |
981 const char *nsuffix = (const char *) XSTRING_DATA (suffixes); | 987 CONST char *nsuffix = XSTRING_DATA (suffixes); |
982 | 988 |
983 while (1) | 989 while (1) |
984 { | 990 { |
985 char *esuffix = (char *) strchr (nsuffix, ':'); | 991 char *esuffix = (char *) strchr (nsuffix, ':'); |
986 int lsuffix = esuffix ? esuffix - nsuffix : strlen (nsuffix); | 992 int lsuffix = ((esuffix) ? (esuffix - nsuffix) : strlen (nsuffix)); |
987 | 993 |
988 /* Concatenate path element/specified name with the suffix. */ | 994 /* Concatenate path element/specified name with the suffix. */ |
989 strncpy (fn + fn_len, nsuffix, lsuffix); | 995 strncpy (fn + fn_len, nsuffix, lsuffix); |
990 fn[fn_len + lsuffix] = 0; | 996 fn[fn_len + lsuffix] = 0; |
991 | 997 |
1027 { | 1033 { |
1028 /* We succeeded; return this descriptor and filename. */ | 1034 /* We succeeded; return this descriptor and filename. */ |
1029 if (closure->storeptr) | 1035 if (closure->storeptr) |
1030 *closure->storeptr = build_string (fn); | 1036 *closure->storeptr = build_string (fn); |
1031 | 1037 |
1032 #ifndef WIN32_NATIVE | 1038 #ifndef WINDOWSNT |
1033 /* If we actually opened the file, set close-on-exec flag | 1039 /* If we actually opened the file, set close-on-exec flag |
1034 on the new descriptor so that subprocesses can't whack | 1040 on the new descriptor so that subprocesses can't whack |
1035 at it. */ | 1041 at it. */ |
1036 if (closure->mode < 0) | 1042 if (closure->mode < 0) |
1037 (void) fcntl (closure->fd, F_SETFD, FD_CLOEXEC); | 1043 (void) fcntl (closure->fd, F_SETFD, FD_CLOEXEC); |
1868 Lstream_flush (XLSTREAM (Vread_buffer_stream)); | 1874 Lstream_flush (XLSTREAM (Vread_buffer_stream)); |
1869 | 1875 |
1870 return Lstream_byte_count (XLSTREAM (Vread_buffer_stream)) - 1; | 1876 return Lstream_byte_count (XLSTREAM (Vread_buffer_stream)) - 1; |
1871 } | 1877 } |
1872 | 1878 |
1873 static Lisp_Object parse_integer (const Bufbyte *buf, Bytecount len, int base); | 1879 static Lisp_Object parse_integer (CONST Bufbyte *buf, Bytecount len, int base); |
1874 | 1880 |
1875 static Lisp_Object | 1881 static Lisp_Object |
1876 read_atom (Lisp_Object readcharfun, | 1882 read_atom (Lisp_Object readcharfun, |
1877 Emchar firstchar, | 1883 Emchar firstchar, |
1878 int uninterned_symbol) | 1884 int uninterned_symbol) |
1939 Lisp_Object sym; | 1945 Lisp_Object sym; |
1940 if (uninterned_symbol) | 1946 if (uninterned_symbol) |
1941 sym = Fmake_symbol ( make_string ((Bufbyte *) read_ptr, len)); | 1947 sym = Fmake_symbol ( make_string ((Bufbyte *) read_ptr, len)); |
1942 else | 1948 else |
1943 { | 1949 { |
1950 /* intern will purecopy pname if necessary */ | |
1944 Lisp_Object name = make_string ((Bufbyte *) read_ptr, len); | 1951 Lisp_Object name = make_string ((Bufbyte *) read_ptr, len); |
1945 sym = Fintern (name, Qnil); | 1952 sym = Fintern (name, Qnil); |
1946 } | 1953 } |
1947 return sym; | 1954 return sym; |
1948 } | 1955 } |
1949 } | 1956 } |
1950 | 1957 |
1951 | 1958 |
1952 static Lisp_Object | 1959 static Lisp_Object |
1953 parse_integer (const Bufbyte *buf, Bytecount len, int base) | 1960 parse_integer (CONST Bufbyte *buf, Bytecount len, int base) |
1954 { | 1961 { |
1955 const Bufbyte *lim = buf + len; | 1962 CONST Bufbyte *lim = buf + len; |
1956 const Bufbyte *p = buf; | 1963 CONST Bufbyte *p = buf; |
1957 EMACS_UINT num = 0; | 1964 EMACS_UINT num = 0; |
1958 int negativland = 0; | 1965 int negativland = 0; |
1959 | 1966 |
1960 if (*p == '-') | 1967 if (*p == '-') |
1961 { | 1968 { |
2034 static Lisp_Object | 2041 static Lisp_Object |
2035 read_bit_vector (Lisp_Object readcharfun) | 2042 read_bit_vector (Lisp_Object readcharfun) |
2036 { | 2043 { |
2037 unsigned_char_dynarr *dyn = Dynarr_new (unsigned_char); | 2044 unsigned_char_dynarr *dyn = Dynarr_new (unsigned_char); |
2038 Emchar c; | 2045 Emchar c; |
2039 Lisp_Object val; | |
2040 | 2046 |
2041 while (1) | 2047 while (1) |
2042 { | 2048 { |
2043 c = readchar (readcharfun); | 2049 c = readchar (readcharfun); |
2044 if (c != '0' && c != '1') | 2050 if (c != '0' && c != '1') |
2047 } | 2053 } |
2048 | 2054 |
2049 if (c >= 0) | 2055 if (c >= 0) |
2050 unreadchar (readcharfun, c); | 2056 unreadchar (readcharfun, c); |
2051 | 2057 |
2052 val = make_bit_vector_from_byte_vector (Dynarr_atp (dyn, 0), | 2058 return make_bit_vector_from_byte_vector (Dynarr_atp (dyn, 0), |
2053 Dynarr_length (dyn)); | 2059 Dynarr_length (dyn)); |
2054 | |
2055 Dynarr_free (dyn); | |
2056 | |
2057 return val; | |
2058 } | 2060 } |
2059 | 2061 |
2060 | 2062 |
2061 | 2063 |
2062 /* structures */ | 2064 /* structures */ |
2694 #define TRAIL_INT 4 | 2696 #define TRAIL_INT 4 |
2695 #define E_CHAR 8 | 2697 #define E_CHAR 8 |
2696 #define EXP_INT 16 | 2698 #define EXP_INT 16 |
2697 | 2699 |
2698 int | 2700 int |
2699 isfloat_string (const char *cp) | 2701 isfloat_string (CONST char *cp) |
2700 { | 2702 { |
2701 int state = 0; | 2703 int state = 0; |
2702 const Bufbyte *ucp = (const Bufbyte *) cp; | 2704 CONST Bufbyte *ucp = (CONST Bufbyte *) cp; |
2703 | 2705 |
2704 if (*ucp == '+' || *ucp == '-') | 2706 if (*ucp == '+' || *ucp == '-') |
2705 ucp++; | 2707 ucp++; |
2706 | 2708 |
2707 if (*ucp >= '0' && *ucp <= '9') | 2709 if (*ucp >= '0' && *ucp <= '9') |
3000 | 3002 |
3001 for (i = 0, p = &(XVECTOR_DATA (s.head)[0]); | 3003 for (i = 0, p = &(XVECTOR_DATA (s.head)[0]); |
3002 i < len; | 3004 i < len; |
3003 i++, p++) | 3005 i++, p++) |
3004 { | 3006 { |
3005 Lisp_Cons *otem = XCONS (tem); | 3007 struct Lisp_Cons *otem = XCONS (tem); |
3006 tem = Fcar (tem); | 3008 #if 0 /* FSFmacs defun hack */ |
3009 if (read_pure) | |
3010 tem = Fpurecopy (Fcar (tem)); | |
3011 else | |
3012 #endif | |
3013 tem = Fcar (tem); | |
3007 *p = tem; | 3014 *p = tem; |
3008 tem = otem->cdr; | 3015 tem = otem->cdr; |
3009 free_cons (otem); | 3016 free_cons (otem); |
3010 } | 3017 } |
3011 return s.head; | 3018 return s.head; |
3032 return | 3039 return |
3033 continuable_syntax_error ("#[...] used with wrong number of elements"); | 3040 continuable_syntax_error ("#[...] used with wrong number of elements"); |
3034 | 3041 |
3035 for (iii = 0; CONSP (stuff); iii++) | 3042 for (iii = 0; CONSP (stuff); iii++) |
3036 { | 3043 { |
3037 Lisp_Cons *victim = XCONS (stuff); | 3044 struct Lisp_Cons *victim = XCONS (stuff); |
3038 make_byte_code_args[iii] = Fcar (stuff); | 3045 make_byte_code_args[iii] = Fcar (stuff); |
3039 if ((purify_flag || load_force_doc_strings) | 3046 if ((purify_flag || load_force_doc_strings) |
3040 && CONSP (make_byte_code_args[iii]) | 3047 && CONSP (make_byte_code_args[iii]) |
3041 && EQ (XCAR (make_byte_code_args[iii]), Vload_file_name_internal)) | 3048 && EQ (XCAR (make_byte_code_args[iii]), Vload_file_name_internal)) |
3042 { | 3049 { |
3140 { | 3147 { |
3141 the_structure_type_dynarr = Dynarr_new (structure_type); | 3148 the_structure_type_dynarr = Dynarr_new (structure_type); |
3142 } | 3149 } |
3143 | 3150 |
3144 void | 3151 void |
3145 reinit_vars_of_lread (void) | |
3146 { | |
3147 Vread_buffer_stream = Qnil; | |
3148 staticpro_nodump (&Vread_buffer_stream); | |
3149 } | |
3150 | |
3151 void | |
3152 vars_of_lread (void) | 3152 vars_of_lread (void) |
3153 { | 3153 { |
3154 reinit_vars_of_lread (); | |
3155 | |
3156 DEFVAR_LISP ("values", &Vvalues /* | 3154 DEFVAR_LISP ("values", &Vvalues /* |
3157 List of values of all expressions which were read, evaluated and printed. | 3155 List of values of all expressions which were read, evaluated and printed. |
3158 Order is reverse chronological. | 3156 Order is reverse chronological. |
3159 */ ); | 3157 */ ); |
3160 | 3158 |
3268 | 3266 |
3269 /* This must be initialized in init_lread otherwise it may start out | 3267 /* This must be initialized in init_lread otherwise it may start out |
3270 with values saved when the image is dumped. */ | 3268 with values saved when the image is dumped. */ |
3271 staticpro (&Vload_descriptor_list); | 3269 staticpro (&Vload_descriptor_list); |
3272 | 3270 |
3271 Vread_buffer_stream = Qnil; | |
3272 staticpro (&Vread_buffer_stream); | |
3273 | |
3273 /* Initialized in init_lread. */ | 3274 /* Initialized in init_lread. */ |
3274 staticpro (&Vload_force_doc_string_list); | 3275 staticpro (&Vload_force_doc_string_list); |
3275 | 3276 |
3276 Vload_file_name_internal = Qnil; | 3277 Vload_file_name_internal = Qnil; |
3277 staticpro (&Vload_file_name_internal); | 3278 staticpro (&Vload_file_name_internal); |