scm-5f4/0000775000175000017500000000000014560303536007244 500000000000000scm-5f4/xevent.h0000755000175000017500000004147414560204227010656 00000000000000/* xgen.scm extracted typedef structs from /usr/include/X11/Xlib.h */ #ifdef SCM_EVENT_FIELDS case (KeyPress<<8)+0x10: case (KeyRelease<<8)+0x10: return MAKINUM(((XKeyEvent *) x)->type); case (KeyPress<<8)+0x11: case (KeyRelease<<8)+0x11: return MAKINUM(((XKeyEvent *) x)->serial); case (KeyPress<<8)+0x12: case (KeyRelease<<8)+0x12: return x_make_bool(((XKeyEvent *) x)->send_event); case (KeyPress<<8)+0x13: case (KeyRelease<<8)+0x13: return ulong2num(((XKeyEvent *) x)->time); case (KeyPress<<8)+0x14: case (KeyRelease<<8)+0x14: return MAKINUM(((XKeyEvent *) x)->x); case (KeyPress<<8)+0x15: case (KeyRelease<<8)+0x15: return MAKINUM(((XKeyEvent *) x)->y); case (KeyPress<<8)+0x16: case (KeyRelease<<8)+0x16: return MAKINUM(((XKeyEvent *) x)->x_root); case (KeyPress<<8)+0x17: case (KeyRelease<<8)+0x17: return MAKINUM(((XKeyEvent *) x)->y_root); case (KeyPress<<8)+0x18: case (KeyRelease<<8)+0x18: return MAKINUM(((XKeyEvent *) x)->state); case (KeyPress<<8)+0x19: case (KeyRelease<<8)+0x19: return MAKINUM(((XKeyEvent *) x)->keycode); case (KeyPress<<8)+0x1a: case (KeyRelease<<8)+0x1a: return x_make_bool(((XKeyEvent *) x)->same_screen); case (ButtonPress<<8)+0x10: case (ButtonRelease<<8)+0x10: return MAKINUM(((XButtonEvent *) x)->type); case (ButtonPress<<8)+0x11: case (ButtonRelease<<8)+0x11: return MAKINUM(((XButtonEvent *) x)->serial); case (ButtonPress<<8)+0x12: case (ButtonRelease<<8)+0x12: return x_make_bool(((XButtonEvent *) x)->send_event); case (ButtonPress<<8)+0x13: case (ButtonRelease<<8)+0x13: return ulong2num(((XButtonEvent *) x)->time); case (ButtonPress<<8)+0x14: case (ButtonRelease<<8)+0x14: return MAKINUM(((XButtonEvent *) x)->x); case (ButtonPress<<8)+0x15: case (ButtonRelease<<8)+0x15: return MAKINUM(((XButtonEvent *) x)->y); case (ButtonPress<<8)+0x16: case (ButtonRelease<<8)+0x16: return MAKINUM(((XButtonEvent *) x)->x_root); case (ButtonPress<<8)+0x17: case (ButtonRelease<<8)+0x17: return MAKINUM(((XButtonEvent *) x)->y_root); case (ButtonPress<<8)+0x18: case (ButtonRelease<<8)+0x18: return MAKINUM(((XButtonEvent *) x)->state); case (ButtonPress<<8)+0x1b: case (ButtonRelease<<8)+0x1b: return MAKINUM(((XButtonEvent *) x)->button); case (ButtonPress<<8)+0x1a: case (ButtonRelease<<8)+0x1a: return x_make_bool(((XButtonEvent *) x)->same_screen); case (MotionNotify<<8)+0x10: return MAKINUM(((XMotionEvent *) x)->type); case (MotionNotify<<8)+0x11: return MAKINUM(((XMotionEvent *) x)->serial); case (MotionNotify<<8)+0x12: return x_make_bool(((XMotionEvent *) x)->send_event); case (MotionNotify<<8)+0x13: return ulong2num(((XMotionEvent *) x)->time); case (MotionNotify<<8)+0x14: return MAKINUM(((XMotionEvent *) x)->x); case (MotionNotify<<8)+0x15: return MAKINUM(((XMotionEvent *) x)->y); case (MotionNotify<<8)+0x16: return MAKINUM(((XMotionEvent *) x)->x_root); case (MotionNotify<<8)+0x17: return MAKINUM(((XMotionEvent *) x)->y_root); case (MotionNotify<<8)+0x18: return MAKINUM(((XMotionEvent *) x)->state); case (MotionNotify<<8)+0x1c: return MAKINUM(((XMotionEvent *) x)->is_hint); case (MotionNotify<<8)+0x1a: return x_make_bool(((XMotionEvent *) x)->same_screen); case (EnterNotify<<8)+0x10: case (LeaveNotify<<8)+0x10: return MAKINUM(((XCrossingEvent *) x)->type); case (EnterNotify<<8)+0x11: case (LeaveNotify<<8)+0x11: return MAKINUM(((XCrossingEvent *) x)->serial); case (EnterNotify<<8)+0x12: case (LeaveNotify<<8)+0x12: return x_make_bool(((XCrossingEvent *) x)->send_event); case (EnterNotify<<8)+0x13: case (LeaveNotify<<8)+0x13: return ulong2num(((XCrossingEvent *) x)->time); case (EnterNotify<<8)+0x14: case (LeaveNotify<<8)+0x14: return MAKINUM(((XCrossingEvent *) x)->x); case (EnterNotify<<8)+0x15: case (LeaveNotify<<8)+0x15: return MAKINUM(((XCrossingEvent *) x)->y); case (EnterNotify<<8)+0x16: case (LeaveNotify<<8)+0x16: return MAKINUM(((XCrossingEvent *) x)->x_root); case (EnterNotify<<8)+0x17: case (LeaveNotify<<8)+0x17: return MAKINUM(((XCrossingEvent *) x)->y_root); case (EnterNotify<<8)+0x1d: case (LeaveNotify<<8)+0x1d: return MAKINUM(((XCrossingEvent *) x)->mode); case (EnterNotify<<8)+0x1e: case (LeaveNotify<<8)+0x1e: return MAKINUM(((XCrossingEvent *) x)->detail); case (EnterNotify<<8)+0x1a: case (LeaveNotify<<8)+0x1a: return x_make_bool(((XCrossingEvent *) x)->same_screen); case (EnterNotify<<8)+0x1f: case (LeaveNotify<<8)+0x1f: return x_make_bool(((XCrossingEvent *) x)->focus); case (EnterNotify<<8)+0x18: case (LeaveNotify<<8)+0x18: return MAKINUM(((XCrossingEvent *) x)->state); case (FocusIn<<8)+0x10: case (FocusOut<<8)+0x10: return MAKINUM(((XFocusChangeEvent *) x)->type); case (FocusIn<<8)+0x11: case (FocusOut<<8)+0x11: return MAKINUM(((XFocusChangeEvent *) x)->serial); case (FocusIn<<8)+0x12: case (FocusOut<<8)+0x12: return x_make_bool(((XFocusChangeEvent *) x)->send_event); case (FocusIn<<8)+0x1d: case (FocusOut<<8)+0x1d: return MAKINUM(((XFocusChangeEvent *) x)->mode); case (FocusIn<<8)+0x1e: case (FocusOut<<8)+0x1e: return MAKINUM(((XFocusChangeEvent *) x)->detail); case (KeymapNotify<<8)+0x10: return MAKINUM(((XKeymapEvent *) x)->type); case (KeymapNotify<<8)+0x11: return MAKINUM(((XKeymapEvent *) x)->serial); case (KeymapNotify<<8)+0x12: return x_make_bool(((XKeymapEvent *) x)->send_event); case (Expose<<8)+0x10: return MAKINUM(((XExposeEvent *) x)->type); case (Expose<<8)+0x11: return MAKINUM(((XExposeEvent *) x)->serial); case (Expose<<8)+0x12: return x_make_bool(((XExposeEvent *) x)->send_event); case (Expose<<8)+0x14: return MAKINUM(((XExposeEvent *) x)->x); case (Expose<<8)+0x15: return MAKINUM(((XExposeEvent *) x)->y); case (Expose<<8)+0x20: return MAKINUM(((XExposeEvent *) x)->width); case (Expose<<8)+0x21: return MAKINUM(((XExposeEvent *) x)->height); case (Expose<<8)+0x22: return MAKINUM(((XExposeEvent *) x)->count); case (GraphicsExpose<<8)+0x10: return MAKINUM(((XGraphicsExposeEvent *) x)->type); case (GraphicsExpose<<8)+0x11: return MAKINUM(((XGraphicsExposeEvent *) x)->serial); case (GraphicsExpose<<8)+0x12: return x_make_bool(((XGraphicsExposeEvent *) x)->send_event); case (GraphicsExpose<<8)+0x14: return MAKINUM(((XGraphicsExposeEvent *) x)->x); case (GraphicsExpose<<8)+0x15: return MAKINUM(((XGraphicsExposeEvent *) x)->y); case (GraphicsExpose<<8)+0x20: return MAKINUM(((XGraphicsExposeEvent *) x)->width); case (GraphicsExpose<<8)+0x21: return MAKINUM(((XGraphicsExposeEvent *) x)->height); case (GraphicsExpose<<8)+0x22: return MAKINUM(((XGraphicsExposeEvent *) x)->count); case (GraphicsExpose<<8)+0x23: return MAKINUM(((XGraphicsExposeEvent *) x)->major_code); case (GraphicsExpose<<8)+0x24: return MAKINUM(((XGraphicsExposeEvent *) x)->minor_code); case (NoExpose<<8)+0x10: return MAKINUM(((XNoExposeEvent *) x)->type); case (NoExpose<<8)+0x11: return MAKINUM(((XNoExposeEvent *) x)->serial); case (NoExpose<<8)+0x12: return x_make_bool(((XNoExposeEvent *) x)->send_event); case (NoExpose<<8)+0x23: return MAKINUM(((XNoExposeEvent *) x)->major_code); case (NoExpose<<8)+0x24: return MAKINUM(((XNoExposeEvent *) x)->minor_code); case (VisibilityNotify<<8)+0x10: return MAKINUM(((XVisibilityEvent *) x)->type); case (VisibilityNotify<<8)+0x11: return MAKINUM(((XVisibilityEvent *) x)->serial); case (VisibilityNotify<<8)+0x12: return x_make_bool(((XVisibilityEvent *) x)->send_event); case (VisibilityNotify<<8)+0x18: return MAKINUM(((XVisibilityEvent *) x)->state); case (CreateNotify<<8)+0x10: return MAKINUM(((XCreateWindowEvent *) x)->type); case (CreateNotify<<8)+0x11: return MAKINUM(((XCreateWindowEvent *) x)->serial); case (CreateNotify<<8)+0x12: return x_make_bool(((XCreateWindowEvent *) x)->send_event); case (CreateNotify<<8)+0x14: return MAKINUM(((XCreateWindowEvent *) x)->x); case (CreateNotify<<8)+0x15: return MAKINUM(((XCreateWindowEvent *) x)->y); case (CreateNotify<<8)+0x20: return MAKINUM(((XCreateWindowEvent *) x)->width); case (CreateNotify<<8)+0x21: return MAKINUM(((XCreateWindowEvent *) x)->height); case (CreateNotify<<8)+0x25: return MAKINUM(((XCreateWindowEvent *) x)->border_width); case (CreateNotify<<8)+0x26: return x_make_bool(((XCreateWindowEvent *) x)->override_redirect); case (DestroyNotify<<8)+0x10: return MAKINUM(((XDestroyWindowEvent *) x)->type); case (DestroyNotify<<8)+0x11: return MAKINUM(((XDestroyWindowEvent *) x)->serial); case (DestroyNotify<<8)+0x12: return x_make_bool(((XDestroyWindowEvent *) x)->send_event); case (UnmapNotify<<8)+0x10: return MAKINUM(((XUnmapEvent *) x)->type); case (UnmapNotify<<8)+0x11: return MAKINUM(((XUnmapEvent *) x)->serial); case (UnmapNotify<<8)+0x12: return x_make_bool(((XUnmapEvent *) x)->send_event); case (UnmapNotify<<8)+0x27: return x_make_bool(((XUnmapEvent *) x)->from_configure); case (MapNotify<<8)+0x10: return MAKINUM(((XMapEvent *) x)->type); case (MapNotify<<8)+0x11: return MAKINUM(((XMapEvent *) x)->serial); case (MapNotify<<8)+0x12: return x_make_bool(((XMapEvent *) x)->send_event); case (MapNotify<<8)+0x26: return x_make_bool(((XMapEvent *) x)->override_redirect); case (MapRequest<<8)+0x10: return MAKINUM(((XMapRequestEvent *) x)->type); case (MapRequest<<8)+0x11: return MAKINUM(((XMapRequestEvent *) x)->serial); case (MapRequest<<8)+0x12: return x_make_bool(((XMapRequestEvent *) x)->send_event); case (ReparentNotify<<8)+0x10: return MAKINUM(((XReparentEvent *) x)->type); case (ReparentNotify<<8)+0x11: return MAKINUM(((XReparentEvent *) x)->serial); case (ReparentNotify<<8)+0x12: return x_make_bool(((XReparentEvent *) x)->send_event); case (ReparentNotify<<8)+0x14: return MAKINUM(((XReparentEvent *) x)->x); case (ReparentNotify<<8)+0x15: return MAKINUM(((XReparentEvent *) x)->y); case (ReparentNotify<<8)+0x26: return x_make_bool(((XReparentEvent *) x)->override_redirect); case (ConfigureNotify<<8)+0x10: return MAKINUM(((XConfigureEvent *) x)->type); case (ConfigureNotify<<8)+0x11: return MAKINUM(((XConfigureEvent *) x)->serial); case (ConfigureNotify<<8)+0x12: return x_make_bool(((XConfigureEvent *) x)->send_event); case (ConfigureNotify<<8)+0x14: return MAKINUM(((XConfigureEvent *) x)->x); case (ConfigureNotify<<8)+0x15: return MAKINUM(((XConfigureEvent *) x)->y); case (ConfigureNotify<<8)+0x20: return MAKINUM(((XConfigureEvent *) x)->width); case (ConfigureNotify<<8)+0x21: return MAKINUM(((XConfigureEvent *) x)->height); case (ConfigureNotify<<8)+0x25: return MAKINUM(((XConfigureEvent *) x)->border_width); case (ConfigureNotify<<8)+0x26: return x_make_bool(((XConfigureEvent *) x)->override_redirect); case (GravityNotify<<8)+0x10: return MAKINUM(((XGravityEvent *) x)->type); case (GravityNotify<<8)+0x11: return MAKINUM(((XGravityEvent *) x)->serial); case (GravityNotify<<8)+0x12: return x_make_bool(((XGravityEvent *) x)->send_event); case (GravityNotify<<8)+0x14: return MAKINUM(((XGravityEvent *) x)->x); case (GravityNotify<<8)+0x15: return MAKINUM(((XGravityEvent *) x)->y); case (ResizeRequest<<8)+0x10: return MAKINUM(((XResizeRequestEvent *) x)->type); case (ResizeRequest<<8)+0x11: return MAKINUM(((XResizeRequestEvent *) x)->serial); case (ResizeRequest<<8)+0x12: return x_make_bool(((XResizeRequestEvent *) x)->send_event); case (ResizeRequest<<8)+0x20: return MAKINUM(((XResizeRequestEvent *) x)->width); case (ResizeRequest<<8)+0x21: return MAKINUM(((XResizeRequestEvent *) x)->height); case (ConfigureRequest<<8)+0x10: return MAKINUM(((XConfigureRequestEvent *) x)->type); case (ConfigureRequest<<8)+0x11: return MAKINUM(((XConfigureRequestEvent *) x)->serial); case (ConfigureRequest<<8)+0x12: return x_make_bool(((XConfigureRequestEvent *) x)->send_event); case (ConfigureRequest<<8)+0x14: return MAKINUM(((XConfigureRequestEvent *) x)->x); case (ConfigureRequest<<8)+0x15: return MAKINUM(((XConfigureRequestEvent *) x)->y); case (ConfigureRequest<<8)+0x20: return MAKINUM(((XConfigureRequestEvent *) x)->width); case (ConfigureRequest<<8)+0x21: return MAKINUM(((XConfigureRequestEvent *) x)->height); case (ConfigureRequest<<8)+0x25: return MAKINUM(((XConfigureRequestEvent *) x)->border_width); case (ConfigureRequest<<8)+0x1e: return MAKINUM(((XConfigureRequestEvent *) x)->detail); case (ConfigureRequest<<8)+0x28: return MAKINUM(((XConfigureRequestEvent *) x)->value_mask); case (CirculateNotify<<8)+0x10: return MAKINUM(((XCirculateEvent *) x)->type); case (CirculateNotify<<8)+0x11: return MAKINUM(((XCirculateEvent *) x)->serial); case (CirculateNotify<<8)+0x12: return x_make_bool(((XCirculateEvent *) x)->send_event); case (CirculateNotify<<8)+0x29: return MAKINUM(((XCirculateEvent *) x)->place); case (CirculateRequest<<8)+0x10: return MAKINUM(((XCirculateRequestEvent *) x)->type); case (CirculateRequest<<8)+0x11: return MAKINUM(((XCirculateRequestEvent *) x)->serial); case (CirculateRequest<<8)+0x12: return x_make_bool(((XCirculateRequestEvent *) x)->send_event); case (CirculateRequest<<8)+0x29: return MAKINUM(((XCirculateRequestEvent *) x)->place); case (PropertyNotify<<8)+0x10: return MAKINUM(((XPropertyEvent *) x)->type); case (PropertyNotify<<8)+0x11: return MAKINUM(((XPropertyEvent *) x)->serial); case (PropertyNotify<<8)+0x12: return x_make_bool(((XPropertyEvent *) x)->send_event); case (PropertyNotify<<8)+0x13: return ulong2num(((XPropertyEvent *) x)->time); case (PropertyNotify<<8)+0x18: return MAKINUM(((XPropertyEvent *) x)->state); case (SelectionClear<<8)+0x10: return MAKINUM(((XSelectionClearEvent *) x)->type); case (SelectionClear<<8)+0x11: return MAKINUM(((XSelectionClearEvent *) x)->serial); case (SelectionClear<<8)+0x12: return x_make_bool(((XSelectionClearEvent *) x)->send_event); case (SelectionClear<<8)+0x13: return ulong2num(((XSelectionClearEvent *) x)->time); case (SelectionRequest<<8)+0x10: return MAKINUM(((XSelectionRequestEvent *) x)->type); case (SelectionRequest<<8)+0x11: return MAKINUM(((XSelectionRequestEvent *) x)->serial); case (SelectionRequest<<8)+0x12: return x_make_bool(((XSelectionRequestEvent *) x)->send_event); case (SelectionRequest<<8)+0x13: return ulong2num(((XSelectionRequestEvent *) x)->time); case (SelectionNotify<<8)+0x10: return MAKINUM(((XSelectionEvent *) x)->type); case (SelectionNotify<<8)+0x11: return MAKINUM(((XSelectionEvent *) x)->serial); case (SelectionNotify<<8)+0x12: return x_make_bool(((XSelectionEvent *) x)->send_event); case (SelectionNotify<<8)+0x13: return ulong2num(((XSelectionEvent *) x)->time); case (ColormapNotify<<8)+0x10: return MAKINUM(((XColormapEvent *) x)->type); case (ColormapNotify<<8)+0x11: return MAKINUM(((XColormapEvent *) x)->serial); case (ColormapNotify<<8)+0x12: return x_make_bool(((XColormapEvent *) x)->send_event); case (ColormapNotify<<8)+0x2a: return x_make_bool(((XColormapEvent *) x)->new); case (ColormapNotify<<8)+0x18: return MAKINUM(((XColormapEvent *) x)->state); case (ClientMessage<<8)+0x10: return MAKINUM(((XClientMessageEvent *) x)->type); case (ClientMessage<<8)+0x11: return MAKINUM(((XClientMessageEvent *) x)->serial); case (ClientMessage<<8)+0x12: return x_make_bool(((XClientMessageEvent *) x)->send_event); case (ClientMessage<<8)+0x2b: return MAKINUM(((XClientMessageEvent *) x)->format); case (MappingNotify<<8)+0x10: return MAKINUM(((XMappingEvent *) x)->type); case (MappingNotify<<8)+0x11: return MAKINUM(((XMappingEvent *) x)->serial); case (MappingNotify<<8)+0x12: return x_make_bool(((XMappingEvent *) x)->send_event); case (MappingNotify<<8)+0x2c: return MAKINUM(((XMappingEvent *) x)->request); case (MappingNotify<<8)+0x2d: return MAKINUM(((XMappingEvent *) x)->first_keycode); case (MappingNotify<<8)+0x22: return MAKINUM(((XMappingEvent *) x)->count); #else {MotionNotify, "MotionNotify"}, {KeyPress, "KeyPress"}, {KeyRelease, "KeyRelease"}, {ButtonPress, "ButtonPress"}, {ButtonRelease, "ButtonRelease"}, {MotionNotify, "MotionNotify"}, {EnterNotify, "EnterNotify"}, {LeaveNotify, "LeaveNotify"}, {FocusIn, "FocusIn"}, {FocusOut, "FocusOut"}, {KeymapNotify, "KeymapNotify"}, {Expose, "Expose"}, {GraphicsExpose, "GraphicsExpose"}, {NoExpose, "NoExpose"}, {VisibilityNotify, "VisibilityNotify"}, {CreateNotify, "CreateNotify"}, {DestroyNotify, "DestroyNotify"}, {UnmapNotify, "UnmapNotify"}, {MapNotify, "MapNotify"}, {MapRequest, "MapRequest"}, {ReparentNotify, "ReparentNotify"}, {ConfigureNotify, "ConfigureNotify"}, {ConfigureRequest, "ConfigureRequest"}, {GravityNotify, "GravityNotify"}, {ResizeRequest, "ResizeRequest"}, {CirculateNotify, "CirculateNotify"}, {CirculateRequest, "CirculateRequest"}, {PropertyNotify, "PropertyNotify"}, {SelectionClear, "SelectionClear"}, {SelectionRequest, "SelectionRequest"}, {SelectionNotify, "SelectionNotify"}, {ColormapNotify, "ColormapNotify"}, {ClientMessage, "ClientMessage"}, {MappingNotify, "MappingNotify"}, #endif scm-5f4/subr.c0000644000175000017500000016715714505673610010324 00000000000000/* "subr.c" integer and other Scheme procedures * Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2013 Free Software Foundation, Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see * . */ /* Author: Aubrey Jaffer */ #include #include "scm.h" #define s_length (s_st_length+7) #define s_append (s_st_append+7) char s_make_string[] = "make-string"; char s_list[] = "list"; static char s_setcar[] = "set-car!", s_setcdr[] = "set-cdr!", s_reverse[] = "reverse", s_list_ref[] = "list-ref"; static char s_memq[] = "memq", s_member[] = "member", s_assq[] = "assq", s_assoc[] = "assoc"; static char s_symbol2string[] = "symbol->string", s_str2symbol[] = "string->symbol"; extern char s_inexactp[]; #define s_exactp (s_inexactp+2) static char s_oddp[] = "odd?", s_evenp[] = "even?"; static char s_rquotient[] = "round-quotient", s_remainder[] = "remainder", s_modulo[] = "modulo"; static char s_gcd[] = "gcd"; #define s_quotient (s_rquotient+6) static char s_ci_eq[] = "char-ci=?", s_ch_lessp[] = "char?", s_ch_geqp[] = "char>=?", s_ci_grp[] = "char-ci>?", s_ci_geqp[] = "char-ci>=?"; static char s_ch_alphap[] = "char-alphabetic?", s_ch_nump[] = "char-numeric?", s_ch_whitep[] = "char-whitespace?", s_ch_upperp[] = "char-upper-case?", s_ch_lowerp[] = "char-lower-case?"; static char s_char2int[] = "char->integer", s_int2char[] = "integer->char", s_ch_upcase[] = "char-upcase", s_ch_downcase[] = "char-downcase"; static char s_st_length[] = "string-length", s_st_ref[] = "string-ref", s_st_set[] = "string-set!"; static char s_st_equal[] = "string=?", s_stci_equal[] = "string-ci=?", s_st_lessp[] = "string= INUM0, x, ARG1, s_length); return i; } SCM append(args) SCM args; { SCM res = EOL; SCM *lloc = &res, arg; if (IMP(args)) { ASRTER(NULLP(args), args, ARGn, s_append); return res; } ASRTER(CONSP(args), args, ARGn, s_append); while (1) { arg = CAR(args); args = CDR(args); if (IMP(args)) { *lloc = arg; ASRTER(NULLP(args), args, ARGn, s_append); return res; } ASRTER(CONSP(args), args, ARGn, s_append); for (;NIMP(arg);arg = CDR(arg)) { ASRTER(CONSP(arg), arg, ARGn, s_append); *lloc = cons(CAR(arg), EOL); lloc = &CDR(*lloc); } ASRTER(NULLP(arg), arg, ARGn, s_append); } } SCM reverse(lst) SCM lst; { SCM res = EOL; SCM p = lst; for (;NIMP(p);p = CDR(p)) { ASRTER(CONSP(p), lst, ARG1, s_reverse); res = cons(CAR(p), res); } ASRTER(NULLP(p), lst, ARG1, s_reverse); return res; } SCM list_ref(lst, k) SCM lst, k; { register long i; ASRTER(INUMP(k), k, ARG2, s_list_ref); i = INUM(k); ASRTER(i >= 0, k, ARG2, s_list_ref); while (i-- > 0) { ASRTGO(NIMP(lst) && CONSP(lst), erout); lst = CDR(lst); } erout: ASRTER(NIMP(lst) && CONSP(lst), NULLP(lst)?k:lst, NULLP(lst)?OUTOFRANGE:ARG1, s_list_ref); return CAR(lst); } SCM memq(x, lst) SCM x, lst; { for (;NIMP(lst);lst = CDR(lst)) { ASRTER(CONSP(lst), lst, ARG2, s_memq); if (CAR(lst)==x) return lst; } ASRTER(NULLP(lst), lst, ARG2, s_memq); return BOOL_F; } SCM member(x, lst) SCM x, lst; { for (;NIMP(lst);lst = CDR(lst)) { ASRTER(CONSP(lst), lst, ARG2, s_member); if (NFALSEP(equal(CAR(lst), x))) return lst; } ASRTER(NULLP(lst), lst, ARG2, s_member); return BOOL_F; } SCM assq(x, alist) SCM x, alist; { SCM tmp; for (;NIMP(alist);alist = CDR(alist)) { ASRTER(CONSP(alist), alist, ARG2, s_assq); tmp = CAR(alist); ASRTER(NIMP(tmp) && CONSP(tmp), alist, ARG2, s_assq); if (CAR(tmp)==x) return tmp; } ASRTER(NULLP(alist), alist, ARG2, s_assq); return BOOL_F; } SCM assoc(x, alist) SCM x, alist; { SCM tmp; for (;NIMP(alist);alist = CDR(alist)) { ASRTER(CONSP(alist), alist, ARG2, s_assoc); tmp = CAR(alist); ASRTER(NIMP(tmp) && CONSP(tmp), alist, ARG2, s_assoc); if (NFALSEP(equal(CAR(tmp), x))) return tmp; } ASRTER(NULLP(alist), alist, ARG2, s_assoc); return BOOL_F; } extern long tc16_promise; SCM promisep(x) SCM x; { return NIMP(x) && (TYP16(x)==tc16_promise) ? BOOL_T : BOOL_F; } SCM symbolp(x) SCM x; { if (IMP(x)) return BOOL_F; return SYMBOLP(x) ? BOOL_T : BOOL_F; } SCM symbol2string(s) SCM s; { ASRTER(NIMP(s) && SYMBOLP(s), s, ARG1, s_symbol2string); return makfromstr(CHARS(s), (sizet)LENGTH(s)); } SCM string2symbol(s) SCM s; { ASRTER(NIMP(s) && STRINGP(s), s, ARG1, s_str2symbol); s = intern(CHARS(s), (sizet)LENGTH(s)); return CAR(s); } SCM exactp(x) SCM x; { if (INUMP(x)) return BOOL_T; #ifdef BIGDIG if (NIMP(x) && BIGP(x)) return BOOL_T; #endif return BOOL_F; } SCM oddp(n) SCM n; { #ifdef BIGDIG if (NINUMP(n)) { ASRTER(NIMP(n) && BIGP(n), n, ARG1, s_oddp); return (1 & BDIGITS(n)[0]) ? BOOL_T : BOOL_F; } #else ASRTER(INUMP(n), n, ARG1, s_oddp); #endif return (4 & (int)n) ? BOOL_T : BOOL_F; } SCM evenp(n) SCM n; { #ifdef BIGDIG if (NINUMP(n)) { ASRTER(NIMP(n) && BIGP(n), n, ARG1, s_evenp); return (1 & BDIGITS(n)[0]) ? BOOL_F : BOOL_T; } #else ASRTER(INUMP(n), n, ARG1, s_evenp); #endif return (4 & (int)n) ? BOOL_F : BOOL_T; } SCM scm_round_quotient(num, den) SCM num, den; { register long quo, rem; /* if (scm_verbose > 1) */ /* printf("%s / %s\n", */ /* CHARS(number2string(num, MAKINUM(10))), */ /* CHARS(number2string(den, MAKINUM(10)))); */ #ifdef BIGDIG if (NINUMP(num)) { long w; ASRTER(NIMP(num) && BIGP(num), num, ARG1, s_rquotient); if (NINUMP(den)) { ASRTGO(NIMP(den) && BIGP(den), badden); return divbigbig(BDIGITS(num), NUMDIGS(num), BDIGITS(den), NUMDIGS(den), BIGSIGN(num) ^ BIGSIGN(den), 3); } if (!(quo = INUM(den))) goto ov; if (1==quo) return num; /* divbigdig() hasn't been extended to perform rounding */ /* if (quo < 0) quo = -quo; */ /* if (quo < BIGRAD) { */ /* w = copybig(num, BIGSIGN(num) ? (den>0) : (den<0)); */ /* divbigdig(BDIGITS(w), NUMDIGS(w), (BIGDIG)quo); */ /* return normbig(w); */ /* } */ # ifndef DIGSTOOBIG w = pseudolong(quo); return divbigbig(BDIGITS(num), NUMDIGS(num), (BIGDIG *)&w, DIGSPERLONG, BIGSIGN(num) ? (den>0) : (den<0), 3); # else { BIGDIG quodigs[DIGSPERLONG]; longdigs(quo, quodigs); return divbigbig(BDIGITS(num), NUMDIGS(num), quodigs, DIGSPERLONG, BIGSIGN(num) ? (den>0) : (den<0), 3); } # endif } if (NINUMP(den)) { # ifndef RECKLESS if (!(NIMP(den) && BIGP(den))) badden: wta(den, (char *)ARG2, s_rquotient); # endif if (NUMDIGS(den) > DIGSPERLONG || (NUMDIGS(den)==DIGSPERLONG && BDIGITS(den)[DIGSPERLONG-1] >= BIGRAD/2)) return INUM0; quo = num2long(den, (char *)ARG2, s_rquotient); rem = INUM(num)%quo; if (labs(2*rem) > labs(quo)) return MAKINUM(((INUM(num) < 0)==(quo < 0)) ? 1 : -1); else return INUM0; } #else ASRTER(INUMP(num), num, ARG1, s_rquotient); ASRTER(INUMP(den), den, ARG2, s_rquotient); #endif if ((quo = INUM(den))==0) ov: wta(den, (char *)OVFLOW, s_rquotient); quo = INUM(num)/quo; { # if (__TURBOC__==1) rem = ((den<0) ? -INUM(num) : INUM(num))%INUM(den); # else rem = INUM(num)%INUM(den); # endif #ifdef BADIVSGNS if (rem==0) ; else if (rem < 0) { if (num < 0) ; else quo--; } else if (num < 0) quo++; #endif if ((1 & quo) ? labs(2*rem) >= labs(INUM(den)) : labs(2*rem) > labs(INUM(den))) quo = quo + (((INUM(num) < 0)==(INUM(den) < 0)) ? 1 : -1); } if (!FIXABLE(quo)) #ifdef BIGDIG return long2big(quo); #else wta(num, (char *)OVFLOW, s_rquotient); #endif return MAKINUM(quo); } /* SCM scm_round_quotient(num, den) */ /* SCM num, den; */ /* { */ /* SCM quo = lquotient(num, den); */ /* SCM rem = lremainder(num, den); */ /* if (BOOL_T==((BOOL_T==evenp(quo) ? greaterp : greqp) */ /* (scm_ash(scm_iabs(rem), MAKINUM(1L)), scm_iabs(den)))) */ /* quo = sum(quo, MAKINUM(negativep(num)==negativep(den) ? 1L : -1L)); */ /* return quo; */ /* } */ SCM lquotient(x, y) SCM x, y; { register long z; #ifdef BIGDIG if (NINUMP(x)) { long w; ASRTER(NIMP(x) && BIGP(x), x, ARG1, s_quotient); if (NINUMP(y)) { ASRTGO(NIMP(y) && BIGP(y), bady); return divbigbig(BDIGITS(x), NUMDIGS(x), BDIGITS(y), NUMDIGS(y), BIGSIGN(x) ^ BIGSIGN(y), 2); } if (!(z = INUM(y))) goto ov; if (1==z) return x; if (z < 0) z = -z; if (z < BIGRAD) { w = copybig(x, BIGSIGN(x) ? (y>0) : (y<0)); divbigdig(BDIGITS(w), NUMDIGS(w), (BIGDIG)z); return normbig(w); } # ifndef DIGSTOOBIG w = pseudolong(z); return divbigbig(BDIGITS(x), NUMDIGS(x), (BIGDIG *)&w, DIGSPERLONG, BIGSIGN(x) ? (y>0) : (y<0), 2); # else { BIGDIG zdigs[DIGSPERLONG]; longdigs(z, zdigs); return divbigbig(BDIGITS(x), NUMDIGS(x), zdigs, DIGSPERLONG, BIGSIGN(x) ? (y>0) : (y<0), 2); } # endif } if (NINUMP(y)) { # ifndef RECKLESS if (!(NIMP(y) && BIGP(y))) bady: wta(y, (char *)ARG2, s_quotient); # endif return INUM0; } #else ASRTER(INUMP(x), x, ARG1, s_quotient); ASRTER(INUMP(y), y, ARG2, s_quotient); #endif if ((z = INUM(y))==0) ov: wta(y, (char *)OVFLOW, s_quotient); z = INUM(x)/z; #ifdef BADIVSGNS { # if (__TURBOC__==1) long t = ((y<0) ? -INUM(x) : INUM(x))%INUM(y); # else long t = INUM(x)%INUM(y); # endif if (t==0) ; else if (t < 0) if (x < 0) ; else z--; else if (x < 0) z++; } #endif if (!FIXABLE(z)) #ifdef BIGDIG return long2big(z); #else wta(x, (char *)OVFLOW, s_quotient); #endif return MAKINUM(z); } SCM lremainder(x, y) SCM x, y; { register long z; #ifdef BIGDIG if (NINUMP(x)) { ASRTER(NIMP(x) && BIGP(x), x, ARG1, s_remainder); if (NINUMP(y)) { ASRTGO(NIMP(y) && BIGP(y), bady); return divbigbig(BDIGITS(x), NUMDIGS(x), BDIGITS(y), NUMDIGS(y), BIGSIGN(x), 0); } if (!(z = INUM(y))) goto ov; return divbigint(x, z, BIGSIGN(x), 0); } if (NINUMP(y)) { # ifndef RECKLESS if (!(NIMP(y) && BIGP(y))) bady: wta(y, (char *)ARG2, s_remainder); # endif return x; } #else ASRTER(INUMP(x), x, ARG1, s_remainder); ASRTER(INUMP(y), y, ARG2, s_remainder); #endif if (!(z = INUM(y))) ov: wta(y, (char *)OVFLOW, s_remainder); #if (__TURBOC__==1) if (z < 0) z = -z; #endif z = INUM(x)%z; #ifdef BADIVSGNS if (!z) ; else if (z < 0) if (x < 0) ; else z += INUM(y); else if (x < 0) z -= INUM(y); #endif return MAKINUM(z); } SCM modulo(x, y) SCM x, y; { register long yy, z; #ifdef BIGDIG if (NINUMP(x)) { ASRTER(NIMP(x) && BIGP(x), x, ARG1, s_modulo); if (NINUMP(y)) { ASRTGO(NIMP(y) && BIGP(y), bady); return divbigbig(BDIGITS(x), NUMDIGS(x), BDIGITS(y), NUMDIGS(y), BIGSIGN(y), (BIGSIGN(x) ^ BIGSIGN(y)) ? 1 : 0); } if (!(z = INUM(y))) goto ov; return divbigint(x, z, z < 0, (BIGSIGN(x) ? (z > 0) : (z < 0)) ? 1 : 0); } if (NINUMP(y)) { # ifndef RECKLESS if (!(NIMP(y) && BIGP(y))) bady: wta(y, (char *)ARG2, s_modulo); # endif return (BIGSIGN(y) ? (INUM(x)>0) : (INUM(x)<0)) ? sum(x, y) : x; } #else ASRTER(INUMP(x), x, ARG1, s_modulo); ASRTER(INUMP(y), y, ARG2, s_modulo); #endif if (!(yy = INUM(y))) ov: wta(y, (char *)OVFLOW, s_modulo); #if (__TURBOC__==1) z = INUM(x); z = ((yy<0) ? -z : z)%yy; #else z = INUM(x)%yy; #endif return MAKINUM(((yy<0) ? (z>0) : (z<0)) ? z+yy : z); } SCM lgcd(x, y) SCM x, y; { register long u, v, k, t; if (UNBNDP(y)) return UNBNDP(x) ? INUM0 : x; #ifdef BIGDIG tailrec: if (NINUMP(x)) { big_gcd: ASRTER(NIMP(x) && BIGP(x), x, ARG1, s_gcd); if (BIGSIGN(x)) x = copybig(x, 0); newy: if (NINUMP(y)) { ASRTER(NIMP(y) && BIGP(y), y, ARG2, s_gcd); if (BIGSIGN(y)) y = copybig(y, 0); switch (bigcomp(x, y)) { case -1: swaprec: t = lremainder(x, y); x = y; y = t; goto tailrec; case 0: return x; case 1: y = lremainder(y, x); goto newy; } /* instead of the switch, we could just return lgcd(y, modulo(x, y)); */ } if (INUM0==y) return x; goto swaprec; } if (NINUMP(y)) { t=x; x=y; y=t; goto big_gcd;} #else ASRTER(INUMP(x), x, ARG1, s_gcd); ASRTER(INUMP(y), y, ARG2, s_gcd); #endif u = INUM(x); if (u<0) u = -u; v = INUM(y); if (v<0) v = -v; else if (0==v) goto getout; if (0==u) {u = v; goto getout;} for (k = 1;!(1 & ((int)u|(int)v));k <<= 1, u >>= 1, v >>= 1); if (1 & (int)u) t = -v; else { t = u; b3: t = SRS(t, 1); } if (!(1 & (int)t)) goto b3; if (t>0) u = t; else v = -t; t = u-v; if (t) goto b3; u = u*k; getout: if (!POSFIXABLE(u)) #ifdef BIGDIG return long2big(u); #else wta(x, (char *)OVFLOW, s_gcd); #endif return MAKINUM(u); } SCM llcm(n1, n2) SCM n1, n2; { SCM d; if (UNBNDP(n2)) { n2 = MAKINUM(1L); if (UNBNDP(n1)) return n2; } d = lgcd(n1, n2); if (INUM0==d) return d; return scm_iabs(product(n1, lquotient(n2, d))); } /* Emulating 2's complement bignums with sign magnitude arithmetic: Logand: X Y Result Method: (len) + + + x (map digit:logand X Y) + - + x (map digit:logand X (lognot (+ -1 Y))) - + + y (map digit:logand (lognot (+ -1 X)) Y) - - - (+ 1 (map digit:logior (+ -1 X) (+ -1 Y))) Logior: X Y Result Method: + + + (map digit:logior X Y) + - - y (+ 1 (map digit:logand (lognot X) (+ -1 Y))) - + - x (+ 1 (map digit:logand (+ -1 X) (lognot Y))) - - - x (+ 1 (map digit:logand (+ -1 X) (+ -1 Y))) Logxor: X Y Result Method: + + + (map digit:logxor X Y) + - - (+ 1 (map digit:logxor X (+ -1 Y))) - + - (+ 1 (map digit:logxor (+ -1 X) Y)) - - + (map digit:logxor (+ -1 X) (+ -1 Y)) Logtest: X Y Result + + (any digit:logand X Y) + - (any digit:logand X (lognot (+ -1 Y))) - + (any digit:logand (lognot (+ -1 X)) Y) - - #t */ #ifdef BIGDIG SCM scm_big_ior P((BIGDIG *x, sizet nx, int xsgn, SCM bigy)); SCM scm_big_and P((BIGDIG *x, sizet nx, int xsgn, SCM bigy, int zsgn)); SCM scm_big_xor P((BIGDIG *x, sizet nx, int xsgn, SCM bigy)); SCM scm_big_test P((BIGDIG *x, sizet nx, int xsgn, SCM bigy)); SCM scm_big_ash P((SCM x, int cnt)); SCM scm_copy_big_dec(b, sign) SCM b; int sign; { long num = -1; sizet nx = NUMDIGS(b); sizet i = 0; SCM ans = mkbig(nx, sign); BIGDIG *src = BDIGITS(b), *dst = BDIGITS(ans); if (BIGSIGN(b)) do { num += src[i]; if (num < 0) {dst[i] = num + BIGRAD; num = -1;} else {dst[i] = BIGLO(num); num = 0;} } while (++i < nx); else while (nx--) dst[nx] = src[nx]; return ans; } SCM scm_copy_smaller(x, nx, zsgn) BIGDIG *x; sizet nx; int zsgn; { long num = -1; sizet i = 0; SCM z = mkbig(nx, zsgn); BIGDIG *zds = BDIGITS(z); if (zsgn) do { num += x[i]; if (num < 0) {zds[i] = num + BIGRAD; num = -1;} else {zds[i] = BIGLO(num); num = 0;} } while (++i < nx); else do zds[i] = x[i]; while (++i < nx); return z; } SCM scm_big_ior(x, nx, xsgn, bigy) BIGDIG *x; SCM bigy; sizet nx; /* Assumes nx <= NUMDIGS(bigy) */ int xsgn; /* Assumes xsgn equals either 0 or 0x0100 */ { long num = -1; sizet i = 0, ny = NUMDIGS(bigy); SCM z = scm_copy_big_dec(bigy, xsgn & BIGSIGN(bigy)); BIGDIG *zds = BDIGITS(z); if (xsgn) { do { num += x[i]; if (num < 0) {zds[i] |= num + BIGRAD; num = -1;} else {zds[i] |= BIGLO(num); num = 0;} } while (++i < nx); /* ========= Need to increment zds now =========== */ i = 0; num = 1; while (i < ny) { num += zds[i]; zds[i++] = BIGLO(num); num = BIGDN(num); if (!num) return z; } adjbig(z, 1 + ny); /* OOPS, overflowed into next digit. */ BDIGITS(z)[ny] = 1; return z; } else do zds[i] = zds[i] | x[i]; while (++i < nx); return z; } SCM scm_big_xor(x, nx, xsgn, bigy) BIGDIG *x; SCM bigy; sizet nx; /* Assumes nx <= NUMDIGS(bigy) */ int xsgn; /* Assumes xsgn equals either 0 or 0x0100 */ { long num = -1; sizet i = 0, ny = NUMDIGS(bigy); SCM z = scm_copy_big_dec(bigy, xsgn ^ BIGSIGN(bigy)); BIGDIG *zds = BDIGITS(z); if (xsgn) do { num += x[i]; if (num < 0) {zds[i] ^= num + BIGRAD; num = -1;} else {zds[i] ^= BIGLO(num); num = 0;} } while (++i < nx); else do { zds[i] = zds[i] ^ x[i]; } while (++i < nx); if (xsgn ^ BIGSIGN(bigy)) { /* ========= Need to increment zds now =========== */ i = 0; num = 1; while (i < ny) { num += zds[i]; zds[i++] = BIGLO(num); num = BIGDN(num); if (!num) return normbig(z); } } return normbig(z); } SCM scm_big_and(x, nx, xsgn, bigy, zsgn) BIGDIG *x; SCM bigy; sizet nx; /* Assumes nx <= NUMDIGS(bigy) */ int xsgn; /* Assumes xsgn equals either 0 or 0x0100 */ int zsgn; /* return sign equals either 0 or 0x0100 */ { long num = -1; sizet i = 0; SCM z; BIGDIG *zds; if (xsgn==zsgn) { z = scm_copy_smaller(x, nx, zsgn); x = BDIGITS(bigy); xsgn = BIGSIGN(bigy); } else z = scm_copy_big_dec(bigy, zsgn); zds = BDIGITS(z); if (zsgn) { if (xsgn) do { num += x[i]; if (num < 0) {zds[i] &= num + BIGRAD; num = -1;} else {zds[i] &= BIGLO(num); num = 0;} } while (++i < nx); else do zds[i] = zds[i] & ~x[i]; while (++i < nx); /* ========= need to increment zds now =========== */ i = 0; num = 1; nx = NUMDIGS(z); while (i < nx) { num += zds[i]; zds[i++] = BIGLO(num); num = BIGDN(num); if (!num) return normbig(z); } } else if (xsgn) do { num += x[i]; if (num < 0) {zds[i] &= ~(num + BIGRAD); num = -1;} else {zds[i] &= ~BIGLO(num); num = 0;} } while (++i < nx); else do zds[i] = zds[i] & x[i]; while (++i < nx); return normbig(z); } SCM scm_big_test(x, nx, xsgn, bigy) BIGDIG *x; SCM bigy; sizet nx; /* Assumes nx <= NUMDIGS(bigy) */ int xsgn; /* Assumes xsgn equals either 0 or 0x0100 */ { BIGDIG *y; sizet i = 0; long num = -1; if (BIGSIGN(bigy) & xsgn) return BOOL_T; if (NUMDIGS(bigy) != nx && xsgn) return BOOL_T; y = BDIGITS(bigy); if (xsgn) do { num += x[i]; if (num < 0) { if (y[i] & ~(num + BIGRAD)) return BOOL_T; num = -1; } else { if (y[i] & ~BIGLO(num)) return BOOL_T; num = 0; } } while (++i < nx); else if (BIGSIGN(bigy)) do { num += y[i]; if (num < 0) { if (x[i] & ~(num + BIGRAD)) return BOOL_T; num = -1; } else { if (x[i] & ~BIGLO(num)) return BOOL_T; num = 0; } } while (++i < nx); else do if (x[i] & y[i]) return BOOL_T; while (++i < nx); return BOOL_F; } static SCM scm_copy_big_2scomp P((SCM x, sizet blen, int sign)); static void scm_2scomp1 P((SCM b)); static SCM scm_copy_big_2scomp(x, blen, sign) SCM x; sizet blen; int sign; { sizet nres = (blen + BITSPERDIG - 1)/BITSPERDIG; SCM res; BIGDIG *rds; long num = 0; sizet i; if (INUMP(x)) { long lx = INUM(x); res = mkbig(nres, sign); rds = BDIGITS(res); if (lx < 0) { lx = -lx; for (i = 0; i < nres; i++) { num -= BIGLO(lx); lx = BIGDN(lx); if (num < 0) { rds[i] = num + BIGRAD; num = -1; } else { rds[i] = num; num = 0; } } } else { for (i = 0; i < nres; i++) { rds[i] = BIGLO(lx); lx = BIGDN(lx); } } } else { BIGDIG *xds = BDIGITS(x); sizet nx = NUMDIGS(x); if (nres < nx) nres = nx; res = mkbig(nres, sign); rds = BDIGITS(res); if (BIGSIGN(x)) { for (i = 0; i < nx; i++) { num -= xds[i]; if (num < 0) { rds[i] = num + BIGRAD; num = -1; } else { rds[i] = num; num = 0; } } for (; i < nres; i++) rds[i] = BIGRAD - 1; } else { for (i = 0; i < nx; i++) rds[i] = xds[i]; for (; i < nres; i++) rds[i] = 0; } } return res; } static void scm_2scomp1(b) SCM b; { long num = 0; sizet i, n = NUMDIGS(b); BIGDIG *bds = BDIGITS(b); for (i = 0; i < n; i++) { num -= bds[i]; if (num < 0) { bds[i] = num + BIGRAD; num = -1; } else { bds[i] = num; num = 0; } } } SCM scm_big_ash(x, cnt) SCM x; int cnt; { SCM res; BIGDIG *resds, d; int sign, i, ishf, fshf, blen, n; if (INUMP(x)) { blen = INUM(scm_intlength(x)); if (0==blen) { /* blen zero and fshf zero would lead to an array index of -1 in resds[i - ishf] below. */ if (INUM0==x) return x; else blen = 1; } sign = INUM(x) < 0 ? 0x0100 : 0; } else { blen = NUMDIGS(x)*BITSPERDIG; sign = BIGSIGN(x); } if (cnt < 0) { if (blen <= -cnt) return sign ? MAKINUM(-1) : INUM0; ishf = (-cnt) / BITSPERDIG; fshf = (-cnt) % BITSPERDIG; res = scm_copy_big_2scomp(x, blen, sign); resds = BDIGITS(res); n = NUMDIGS(res) - ishf - 1; for (i = 0; i < n; i++) { d = (resds[i + ishf]>>fshf); if (fshf) d |= ((resds[i + ishf + 1])<<(BITSPERDIG - fshf) & (BIGRAD - 1)); resds[i] = d; } d = (resds[i + ishf]>>fshf); if (sign && fshf) d |= ((BIGRAD - 1)<<(BITSPERDIG - fshf) & (BIGRAD - 1)); resds[i] = d; n = NUMDIGS(res); d = sign ? BIGRAD - 1 : 0; for (i++; i < n; i++) resds[i] = d; } else { ishf = cnt / BITSPERDIG; fshf = cnt % BITSPERDIG; res = scm_copy_big_2scomp(x, blen + cnt, sign); resds = BDIGITS(res); /* if (scm_verbose>1){for (i=NUMDIGS(res); i--;) printf(" %08x",resds[i]); printf("\n");} */ for (i = NUMDIGS(res) - 1; i > ishf; i--) if (fshf) { d = (((resds[i - ishf])<>(BITSPERDIG - fshf)); resds[i] = d; } else resds[i] = resds[i - ishf]; d = fshf ? (((resds[i - ishf])<= 0; i--) resds[i] = 0; } /* if (scm_verbose>1){for (i=NUMDIGS(res); i--;) printf(" %08x",resds[i]); printf("\n");} */ if (sign) scm_2scomp1(res); return normbig(res); } #endif static char s_logand[] = "logand", s_lognot[] = "lognot", s_logior[] = "logior", s_logxor[] = "logxor", s_logtest[] = "logtest", s_logbitp[] = "logbit?", s_copybit[] = "copy-bit", s_copybitfield[] = "copy-bit-field", s_ash[] = "ash", s_logcount[] = "logcount", s_bitwise_bit_count[] = "bitwise-bit-count", s_intlength[] = "integer-length", s_bitfield[] = "bit-field", s_bitif[] = "bitwise-if"; SCM scm_logior(x, y) SCM x, y; { if (UNBNDP(y)) { if (UNBNDP(x)) return INUM0; #ifndef RECKLESS if (!(NUMBERP(x))) badx: wta(x, (char *)ARG1, s_logior); #endif return x; } #ifdef BIGDIG if (NINUMP(x)) { SCM t; ASRTGO(NIMP(x) && BIGP(x), badx); if (INUMP(y)) {t = x; x = y; y = t; goto intbig;} ASRTGO(NIMP(y) && BIGP(y), bady); if (NUMDIGS(x) > NUMDIGS(y)) {t = x; x = y; y = t;} if ((!BIGSIGN(x)) && !BIGSIGN(y)) return scm_big_ior(BDIGITS(x), NUMDIGS(x), BIGSIGN(x), y); return scm_big_and(BDIGITS(x), NUMDIGS(x), BIGSIGN(x), y, 0x0100); } if (NINUMP(y)) { # ifndef RECKLESS if (!(NIMP(y) && BIGP(y))) bady: wta(y, (char *)ARG2, s_logior); # endif intbig: { # ifndef DIGSTOOBIG long z = pseudolong(INUM(x)); if ((!(x < 0)) && !BIGSIGN(y)) return scm_big_ior((BIGDIG *)&z, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y); return scm_big_and((BIGDIG *)&z, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y, 0x0100); # else BIGDIG zdigs[DIGSPERLONG]; longdigs(INUM(x), zdigs); if ((!(x < 0)) && !BIGSIGN(y)) return scm_big_ior(zdigs, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y); return scm_big_and(zdigs, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y, 0x0100); # endif }} #else ASRTGO(INUMP(x), badx); ASRTER(INUMP(y), y, ARG2, s_logior); #endif return MAKINUM(INUM(x) | INUM(y)); } SCM scm_logand(x, y) SCM x, y; { if (UNBNDP(y)) { if (UNBNDP(x)) return MAKINUM(-1); #ifndef RECKLESS if (!(NUMBERP(x))) badx: wta(x, (char *)ARG1, s_logand); #endif return x; } #ifdef BIGDIG if (NINUMP(x)) { SCM t; ASRTGO(NIMP(x) && BIGP(x), badx); if (INUMP(y)) {t = x; x = y; y = t; goto intbig;} ASRTGO(NIMP(y) && BIGP(y), bady); if (NUMDIGS(x) > NUMDIGS(y)) {t = x; x = y; y = t;} if ((BIGSIGN(x)) && BIGSIGN(y)) return scm_big_ior(BDIGITS(x), NUMDIGS(x), 0x0100, y); return scm_big_and(BDIGITS(x), NUMDIGS(x), BIGSIGN(x), y, 0); } if (NINUMP(y)) { # ifndef RECKLESS if (!(NIMP(y) && BIGP(y))) bady: wta(y, (char *)ARG2, s_logand); # endif intbig: { # ifndef DIGSTOOBIG long z = pseudolong(INUM(x)); if ((x < 0) && BIGSIGN(y)) return scm_big_ior((BIGDIG *)&z, DIGSPERLONG, 0x0100, y); return scm_big_and((BIGDIG *)&z, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y, 0); # else BIGDIG zdigs[DIGSPERLONG]; longdigs(INUM(x), zdigs); if ((x < 0) && BIGSIGN(y)) return scm_big_ior(zdigs, DIGSPERLONG, 0x0100, y); return scm_big_and(zdigs, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y, 0); # endif }} #else ASRTGO(INUMP(x), badx); ASRTER(INUMP(y), y, ARG2, s_logand); #endif return MAKINUM(INUM(x) & INUM(y)); } SCM scm_logxor(x, y) SCM x, y; { if (UNBNDP(y)) { if (UNBNDP(x)) return INUM0; #ifndef RECKLESS if (!(NUMBERP(x))) badx: wta(x, (char *)ARG1, s_logxor); #endif return x; } #ifdef BIGDIG if (NINUMP(x)) { SCM t; ASRTGO(NIMP(x) && BIGP(x), badx); if (INUMP(y)) {t = x; x = y; y = t; goto intbig;} ASRTGO(NIMP(y) && BIGP(y), bady); if (NUMDIGS(x) > NUMDIGS(y)) {t = x; x = y; y = t;} return scm_big_xor(BDIGITS(x), NUMDIGS(x), BIGSIGN(x), y); } if (NINUMP(y)) { # ifndef RECKLESS if (!(NIMP(y) && BIGP(y))) bady: wta(y, (char *)ARG2, s_logxor); # endif intbig: { # ifndef DIGSTOOBIG long z = pseudolong(INUM(x)); return scm_big_xor((BIGDIG *)&z, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y); # else BIGDIG zdigs[DIGSPERLONG]; longdigs(INUM(x), zdigs); return scm_big_xor(zdigs, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y); # endif }} #else ASRTGO(INUMP(x), badx); ASRTER(INUMP(y), y, ARG2, s_logxor); #endif return (x ^ y) + INUM0; } SCM scm_logtest(x, y) SCM x, y; { #ifndef RECKLESS if (!(NUMBERP(x))) badx: wta(x, (char *)ARG1, s_logtest); #endif #ifdef BIGDIG if (NINUMP(x)) { SCM t; ASRTGO(NIMP(x) && BIGP(x), badx); if (INUMP(y)) {t = x; x = y; y = t; goto intbig;} ASRTGO(NIMP(y) && BIGP(y), bady); if (NUMDIGS(x) > NUMDIGS(y)) {t = x; x = y; y = t;} return scm_big_test(BDIGITS(x), NUMDIGS(x), BIGSIGN(x), y); } if (NINUMP(y)) { # ifndef RECKLESS if (!(NIMP(y) && BIGP(y))) bady: wta(y, (char *)ARG2, s_logtest); # endif intbig: { # ifndef DIGSTOOBIG long z = pseudolong(INUM(x)); return scm_big_test((BIGDIG *)&z, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y); # else BIGDIG zdigs[DIGSPERLONG]; longdigs(INUM(x), zdigs); return scm_big_test(zdigs, DIGSPERLONG, (x < 0) ? 0x0100 : 0, y); # endif }} #else ASRTGO(INUMP(x), badx); ASRTER(INUMP(y), y, ARG2, s_logtest); #endif return (INUM(x) & INUM(y)) ? BOOL_T : BOOL_F; } SCM scm_logbitp(index, j1) SCM index, j1; { ASRTER(INUMP(index) && INUM(index) >= 0, index, ARG1, s_logbitp); #ifdef BIGDIG if (NINUMP(j1)) { ASRTER(NIMP(j1) && BIGP(j1), j1, ARG2, s_logbitp); if (NUMDIGS(j1) * BITSPERDIG < INUM(index)) return BOOL_F; else if (BIGSIGN(j1)) { long num = -1; sizet i = 0; BIGDIG *x = BDIGITS(j1); sizet nx = INUM(index)/BITSPERDIG; while (!0) { num += x[i]; if (nx==i++) return ((1L << (INUM(index)%BITSPERDIG)) & num) ? BOOL_F : BOOL_T; if (num < 0) num = -1; else num = 0; } } else return (BDIGITS(j1)[INUM(index)/BITSPERDIG] & (1L << (INUM(index)%BITSPERDIG))) ? BOOL_T : BOOL_F; } #else ASRTER(INUMP(j1), j1, ARG2, s_logbitp); #endif if (INUM(index) >= LONG_BIT) return j1 < 0 ? BOOL_T : BOOL_F; return ((1L << INUM(index)) & INUM(j1)) ? BOOL_T : BOOL_F; } SCM scm_copybit(index, j1, bit) SCM index, j1, bit; { ASRTER(INUMP(index) && INUM(index) >= 0, index, ARG1, s_copybit); #ifdef BIGDIG { SCM res; BIGDIG *rds; sizet i = INUM(index); int sign; if (!INUMP(j1)) { ASRTER(NIMP(j1) && BIGP(j1), j1, ARG2, s_copybit); sign = BIGSIGN(j1); ovflow: res = scm_copy_big_2scomp(j1, i + 1, sign); rds = BDIGITS(res); if (NFALSEP(bit)) rds[i / BITSPERDIG] |= 1 << (i % BITSPERDIG); else rds[i / BITSPERDIG] &= ~(1 << (i % BITSPERDIG)); if (sign) scm_2scomp1(res); return normbig(res); } if (i >= LONG_BIT - 3) { sign = INUM(j1) < 0 ? 0x0100 : 0; goto ovflow; } } #else ASRTER(INUMP(j1), j1, ARG2, s_copybit); ASRTER(INUM(index) < LONG_BIT - 3, index, OUTOFRANGE, s_copybit); #endif if (NFALSEP(bit)) return MAKINUM(INUM(j1) | (1L << INUM(index))); else return MAKINUM(INUM(j1) & (~(1L << INUM(index)))); } SCM scm_lognot(n) SCM n; { return difference(MAKINUM(-1L), n); } SCM scm_ash(n, cnt) SCM n, cnt; { SCM res; long ni = INUM(n); int icnt = INUM(cnt); ASRTER(INUMP(cnt), cnt, ARG2, s_ash); if (INUMP(n)) { if (icnt < 0) { if (-icnt >= LONG_BIT) return ni<0 ? MAKINUM(-1L) : INUM0; return MAKINUM(SRS(ni, -icnt)); } if (icnt >= LONG_BIT) goto ovflow; res = MAKINUM(ni<>icnt != INUM(n)) goto ovflow; else return res; } #ifdef BIGDIG ASRTER(NIMP(n) && BIGP(n), n, ARG1, s_ash); ovflow: if (0==icnt) return n; return scm_big_ash(n, icnt); #else ovflow: wta(n, INUMP(n) ? (char *)OVFLOW : (char *)ARG1, s_ash); return UNSPECIFIED; /* kill warning */ #endif } SCM scm_bitfield(n, start, end) SCM n, start, end; { int sign; int istart = INUM(start); int iend = INUM(end); ASRTER(INUMP(start), start, ARG2, s_bitfield); ASRTER(INUMP(end), end, ARG3, s_bitfield); ASRTER(iend >= istart, MAKINUM(iend), OUTOFRANGE, s_bitfield); #ifdef BIGDIG if (NINUMP(n)) { BIGDIG *ds; sizet i, nd; ASRTER(NIMP(n) && BIGP(n), n, ARG1, s_bitfield); sign = BIGSIGN(n); big: if (sign) n = scm_copy_big_2scomp(n, (sizet)iend, 0); n = scm_big_ash(n, -istart); if (INUMP(n)) { if (iend - istart >= LONG_BIT - 2) return n; return MAKINUM(INUM(n) & ((1L<<(iend - istart)) - 1)); } nd = NUMDIGS(n); ds = BDIGITS(n); i = (iend - istart) / BITSPERDIG; if (i >= nd) return n; ds[i] &= ((1 << ((iend - istart) % BITSPERDIG)) - 1); for (++i; i < nd; i++) ds[i] = 0; return normbig(n); } if (iend >= LONG_BIT - 2) { sign = INUM(n) < 0; goto big; } #else ASRTER(INUMP(n), n, ARG1, s_bitfield); ASRTER(iend < LONG_BIT - 2, MAKINUM(iend), OUTOFRANGE, s_bitfield); #endif return MAKINUM((INUM(n)>>istart) & ((1L<<(iend - istart)) - 1)); } SCM scm_bitif(mask, n0, n1) SCM mask, n0, n1; { #ifdef BIGDIG if (NINUMP(mask) || NINUMP(n0) || NINUMP(n1)) return scm_logior(scm_logand(mask, n0), scm_logand(scm_lognot(mask), n1)); #else ASRTER(INUMP(mask), mask, ARG1, s_bitif); ASRTER(INUMP(n0), n0, ARG2, s_bitif); ASRTER(INUMP(n1), n1, ARG3, s_bitif); #endif return MAKINUM((INUM(mask) & INUM(n0)) | (~(INUM(mask)) & INUM(n1))); } SCM scm_copybitfield(to, from, rest) SCM to, from, rest; { long len; SCM start, end; #ifndef RECKLESS if (!(NIMP(rest) && CONSP(rest))) wna: wta(UNDEFINED, (char *)WNA, s_copybitfield); #endif start = CAR(rest); rest = CDR(rest); ASRTGO(NIMP(rest) && CONSP(rest), wna); end = CAR(rest); ASRTGO(NULLP(CDR(rest)), wna); ASRTER(INUMP(start) && INUM(start)>=0, start, ARG2, s_copybitfield); len = INUM(end) - INUM(start); ASRTER(INUMP(end), end, ARG3, s_copybitfield); ASRTER(len >= 0, MAKINUM(len), OUTOFRANGE, s_copybitfield); #ifdef BIGDIG if (NINUMP(from) || NINUMP(to) || (INUM(end) >= LONG_BIT - 2)) { SCM mask = difference(scm_ash(MAKINUM(1L), MAKINUM(len)), MAKINUM(1L)); mask = scm_ash(mask, start); return scm_logior(scm_logand(mask, scm_ash(from, start)), scm_logand(scm_lognot(mask), to)); } #else ASRTER(INUMP(to), to, ARG1, s_copybitfield); ASRTER(INUMP(from), from, ARG4, s_copybitfield); ASRTER(INUM(end) < LONG_BIT - 2, end, OUTOFRANGE, s_copybitfield); #endif { long mask = ((1L<>= 4) c += logtab[15 & d]; if (BIGSIGN(n)) return MAKINUM(-1 - c); return MAKINUM(c); } #else ASRTER(INUMP(n), n, ARG1, s_bitwise_bit_count); #endif if ((nn = INUM(n)) < 0) nn = -1 - nn; for (; nn; nn >>= 4) c += logtab[15 & nn]; if (n < 0) return MAKINUM(-1 - c); return MAKINUM(c); } SCM scm_logcount(n) SCM n; { register unsigned long c = 0; register long nn; #ifdef BIGDIG if (NINUMP(n)) { ASRTER(NIMP(n) && BIGP(n), n, ARG1, s_logcount); if (BIGSIGN(n)) { SCM df = difference(MAKINUM(-1L), n); SCM bc = scm_bitwise_bit_count(df); bigrecy(df); return bc; } return scm_bitwise_bit_count(n); } #else ASRTER(INUMP(n), n, ARG1, s_logcount); #endif if ((nn = INUM(n)) < 0) nn = -1 - nn; for (; nn; nn >>= 4) c += logtab[15 & nn]; return MAKINUM(c); } char ilentab[] = {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4}; SCM scm_intlength(n) SCM n; { register unsigned long c = 0; register long nn; unsigned int l = 4; #ifdef BIGDIG if (NINUMP(n)) { BIGDIG *ds, d; ASRTER(NIMP(n) && BIGP(n), n, ARG1, s_intlength); if (BIGSIGN(n)) { SCM df = difference(MAKINUM(-1L), n); SCM si = scm_intlength(df); bigrecy(df); return si; } ds = BDIGITS(n); d = ds[c = NUMDIGS(n)-1]; for (c *= BITSPERDIG; d; d >>= 4) {c += 4; l = ilentab[15 & d];} return MAKINUM(c - 4 + l); } #else ASRTER(INUMP(n), n, ARG1, s_intlength); #endif if ((nn = INUM(n)) < 0) nn = -1 - nn; for (;nn; nn >>= 4) {c += 4; l = ilentab[15 & nn];} return MAKINUM(c - 4 + l); } SCM charp(x) SCM x; { return ICHRP(x) ? BOOL_T : BOOL_F; } SCM char_lessp(x, y) SCM x, y; { ASRTER(ICHRP(x), x, ARG1, s_ch_lessp); ASRTER(ICHRP(y), y, ARG2, s_ch_lessp); return (ICHR(x) < ICHR(y)) ? BOOL_T : BOOL_F; } SCM char_leqp(x, y) SCM x, y; { ASRTER(ICHRP(x), x, ARG1, s_ch_leqp); ASRTER(ICHRP(y), y, ARG2, s_ch_leqp); return (ICHR(x) <= ICHR(y)) ? BOOL_T : BOOL_F; } SCM char_grp(x, y) SCM x, y; { ASRTER(ICHRP(x), x, ARG1, s_ch_grp); ASRTER(ICHRP(y), y, ARG2, s_ch_grp); return (ICHR(x) > ICHR(y)) ? BOOL_T : BOOL_F; } SCM char_geqp(x, y) SCM x, y; { ASRTER(ICHRP(x), x, ARG1, s_ch_geqp); ASRTER(ICHRP(y), y, ARG2, s_ch_geqp); return (ICHR(x) >= ICHR(y)) ? BOOL_T : BOOL_F; } SCM chci_eq(x, y) SCM x, y; { ASRTER(ICHRP(x), x, ARG1, s_ci_eq); ASRTER(ICHRP(y), y, ARG2, s_ci_eq); return (upcase[ICHR(x)]==upcase[ICHR(y)]) ? BOOL_T : BOOL_F; } SCM chci_lessp(x, y) SCM x, y; { ASRTER(ICHRP(x), x, ARG1, s_ci_lessp); ASRTER(ICHRP(y), y, ARG2, s_ci_lessp); return (upcase[ICHR(x)] < upcase[ICHR(y)]) ? BOOL_T : BOOL_F; } SCM chci_leqp(x, y) SCM x, y; { ASRTER(ICHRP(x), x, ARG1, s_ci_leqp); ASRTER(ICHRP(y), y, ARG2, s_ci_leqp); return (upcase[ICHR(x)] <= upcase[ICHR(y)]) ? BOOL_T : BOOL_F; } SCM chci_grp(x, y) SCM x, y; { ASRTER(ICHRP(x), x, ARG1, s_ci_grp); ASRTER(ICHRP(y), y, ARG2, s_ci_grp); return (upcase[ICHR(x)] > upcase[ICHR(y)]) ? BOOL_T : BOOL_F; } SCM chci_geqp(x, y) SCM x, y; { ASRTER(ICHRP(x), x, ARG1, s_ci_geqp); ASRTER(ICHRP(y), y, ARG2, s_ci_geqp); return (upcase[ICHR(x)] >= upcase[ICHR(y)]) ? BOOL_T : BOOL_F; } SCM char_alphap(chr) SCM chr; { ASRTER(ICHRP(chr), chr, ARG1, s_ch_alphap); return (isascii(ICHR(chr)) && isalpha(ICHR(chr))) ? BOOL_T : BOOL_F; } SCM char_nump(chr) SCM chr; { ASRTER(ICHRP(chr), chr, ARG1, s_ch_nump); return (isascii(ICHR(chr)) && isdigit(ICHR(chr))) ? BOOL_T : BOOL_F; } SCM char_whitep(chr) SCM chr; { ASRTER(ICHRP(chr), chr, ARG1, s_ch_whitep); return (isascii(ICHR(chr)) && isspace(ICHR(chr))) ? BOOL_T : BOOL_F; } SCM char_upperp(chr) SCM chr; { ASRTER(ICHRP(chr), chr, ARG1, s_ch_upperp); return (isascii(ICHR(chr)) && isupper(ICHR(chr))) ? BOOL_T : BOOL_F; } SCM char_lowerp(chr) SCM chr; { ASRTER(ICHRP(chr), chr, ARG1, s_ch_lowerp); return (isascii(ICHR(chr)) && islower(ICHR(chr))) ? BOOL_T : BOOL_F; } SCM char2int(chr) SCM chr; { ASRTER(ICHRP(chr), chr, ARG1, s_char2int); return MAKINUM(ICHR(chr)); } SCM int2char(n) SCM n; { ASRTER(INUMP(n), n, ARG1, s_int2char); ASRTER((n >= INUM0) && (n < MAKINUM(CHAR_CODE_LIMIT)), n, OUTOFRANGE, s_int2char); return MAKICHR(INUM(n)); } SCM char_upcase(chr) SCM chr; { ASRTER(ICHRP(chr), chr, ARG1, s_ch_upcase); return MAKICHR(upcase[ICHR(chr)]); } SCM char_downcase(chr) SCM chr; { ASRTER(ICHRP(chr), chr, ARG1, s_ch_downcase); return MAKICHR(downcase[ICHR(chr)]); } SCM stringp(x) SCM x; { if (IMP(x)) return BOOL_F; return STRINGP(x) ? BOOL_T : BOOL_F; } SCM string(chrs) SCM chrs; { SCM res; register unsigned char *data; long i = ilength(chrs); ASRTER(i >= 0, chrs, ARG1, s_string); res = makstr(i); data = UCHARS(res); for (;NNULLP(chrs);chrs = CDR(chrs)) { ASRTER(ICHRP(CAR(chrs)), chrs, ARG1, s_string); *data++ = ICHR(CAR(chrs)); } return res; } SCM make_string(k, chr) SCM k, chr; { SCM res; register unsigned char *dst; register long i; ASRTER(INUMP(k) && (k >= 0), k, ARG1, s_make_string); i = INUM(k); res = makstr(i); dst = UCHARS(res); if (!UNBNDP(chr)) { ASRTER(ICHRP(chr), chr, ARG2, s_make_string); for (i--;i >= 0;i--) dst[i] = ICHR(chr); } return res; } SCM st_length(str) SCM str; { ASRTER(NIMP(str) && STRINGP(str), str, ARG1, s_st_length); return MAKINUM(LENGTH(str)); } SCM st_ref(str, k) SCM str, k; { ASRTER(NIMP(str) && STRINGP(str), str, ARG1, s_st_ref); ASRTER(INUMP(k), k, ARG2, s_st_ref); ASRTER(INUM(k) < LENGTH(str) && INUM(k) >= 0, k, OUTOFRANGE, s_st_ref); return MAKICHR(UCHARS(str)[INUM(k)]); } SCM st_set(str, k, chr) SCM str, k, chr; { ASRTER(NIMP(str) && STRINGP(str), str, ARG1, s_st_set); ASRTER(INUMP(k), k, ARG2, s_st_set); ASRTER(ICHRP(chr), chr, ARG3, s_st_set); ASRTER(INUM(k) < LENGTH(str) && INUM(k) >= 0, k, OUTOFRANGE, s_st_set); UCHARS(str)[INUM(k)] = ICHR(chr); return UNSPECIFIED; } SCM st_equal(s1, s2) SCM s1, s2; { register sizet i; register unsigned char *c1, *c2; ASRTER(NIMP(s1) && STRINGP(s1), s1, ARG1, s_st_equal); ASRTER(NIMP(s2) && STRINGP(s2), s2, ARG2, s_st_equal); i = LENGTH(s2); if (LENGTH(s1) != i) return BOOL_F; c1 = UCHARS(s1); c2 = UCHARS(s2); while(0 != i--) if (*c1++ != *c2++) return BOOL_F; return BOOL_T; } SCM stci_equal(s1, s2) SCM s1, s2; { register sizet i; register unsigned char *c1, *c2; ASRTER(NIMP(s1) && STRINGP(s1), s1, ARG1, s_stci_equal); ASRTER(NIMP(s2) && STRINGP(s2), s2, ARG2, s_stci_equal); i = LENGTH(s2); if (LENGTH(s1) != i) return BOOL_F; c1 = UCHARS(s1); c2 = UCHARS(s2); while(0 != i--) if (upcase[*c1++] != upcase[*c2++]) return BOOL_F; return BOOL_T; } SCM st_lessp(s1, s2) SCM s1, s2; { register sizet i, len; register unsigned char *c1, *c2; register int c; ASRTER(NIMP(s1) && STRINGP(s1), s1, ARG1, s_st_lessp); ASRTER(NIMP(s2) && STRINGP(s2), s2, ARG2, s_st_lessp); len = LENGTH(s1); i = LENGTH(s2); if (len>i) i = len; c1 = UCHARS(s1); c2 = UCHARS(s2); for (i = 0;i0) return BOOL_F; if (c<0) return BOOL_T; } return (LENGTH(s2) != len) ? BOOL_T : BOOL_F; } SCM st_leqp(s1, s2) SCM s1, s2; { return BOOL_NOT(st_lessp(s2, s1)); } SCM st_grp(s1, s2) SCM s1, s2; { return st_lessp(s2, s1); } SCM st_geqp(s1, s2) SCM s1, s2; { return BOOL_NOT(st_lessp(s1, s2)); } SCM stci_lessp(s1, s2) SCM s1, s2; { register sizet i, len; register unsigned char *c1, *c2; register int c; ASRTER(NIMP(s1) && STRINGP(s1), s1, ARG1, s_stci_lessp); ASRTER(NIMP(s2) && STRINGP(s2), s2, ARG2, s_stci_lessp); len = LENGTH(s1); i = LENGTH(s2); if (len>i) i=len; c1 = UCHARS(s1); c2 = UCHARS(s2); for (i = 0;i0) return BOOL_F; if (c<0) return BOOL_T; } return (LENGTH(s2) != len) ? BOOL_T : BOOL_F; } SCM stci_leqp(s1, s2) SCM s1, s2; { return BOOL_NOT(stci_lessp(s2, s1)); } SCM stci_grp(s1, s2) SCM s1, s2; { return stci_lessp(s2, s1); } SCM stci_geqp(s1, s2) SCM s1, s2; { return BOOL_NOT(stci_lessp(s1, s2)); } SCM substring(str, start, end) SCM str, start, end; { long l; ASRTER(NIMP(str) && STRINGP(str), str, ARG1, s_substring); ASRTER(INUMP(start), start, ARG2, s_substring); ASRTER(INUMP(end), end, ARG3, s_substring); ASRTER(INUM(start) <= LENGTH(str), start, OUTOFRANGE, s_substring); ASRTER(INUM(end) <= LENGTH(str), end, OUTOFRANGE, s_substring); l = INUM(end)-INUM(start); ASRTER(l >= 0, MAKINUM(l), OUTOFRANGE, s_substring); return makfromstr(&CHARS(str)[INUM(start)], (sizet)l); } SCM st_append(args) SCM args; { SCM res; register long i = 0; register SCM l, s; register unsigned char *data; for (l = args;NIMP(l);) { ASRTER(CONSP(l), l, ARGn, s_st_append); s = CAR(l); ASRTER(NIMP(s) && STRINGP(s), s, ARGn, s_st_append); i += LENGTH(s); l = CDR(l); } ASRTER(NULLP(l), args, ARGn, s_st_append); res = makstr(i); data = UCHARS(res); for (l = args;NIMP(l);l = CDR(l)) { s = CAR(l); for (i = 0;i= 0, l, ARG1, s_vector); res = make_vector(MAKINUM(i), UNSPECIFIED); data = VELTS(res); for (;NIMP(l);l = CDR(l)) *data++ = CAR(l); return res; } SCM vector_ref(v, k) SCM v, k; { ASRTER(NIMP(v) && VECTORP(v), v, ARG1, s_ve_ref); ASRTER(INUMP(k), k, ARG2, s_ve_ref); ASRTER((INUM(k) < LENGTH(v)) && (INUM(k) >= 0), k, OUTOFRANGE, s_ve_ref); return VELTS(v)[((long) INUM(k))]; } SCM vector_set(v, k, obj) SCM v, k, obj; { ASRTER(NIMP(v) && VECTORP(v), v, ARG1, s_ve_set); ASRTER(INUMP(k), k, ARG2, s_ve_set); ASRTER((INUM(k) < LENGTH(v)) && (INUM(k) >= 0), k, OUTOFRANGE, s_ve_set); VELTS(v)[((long) INUM(k))] = obj; return UNSPECIFIED; } char s_make_vector[] = "make-vector"; SCM make_vector(k, fill) SCM k, fill; { SCM v; register long i; register SCM *velts; #ifdef SHORT_SIZET ASRTER(INUMP(k), k, ARG1, s_make_vector); #else ASRTER(INUMP(k) && (!(~LENGTH_MAX & INUM(k))), k, ARG1, s_make_vector); #endif if (UNBNDP(fill)) fill = UNSPECIFIED; i = INUM(k); DEFER_INTS; v = must_malloc_cell(i ? i*sizeof(SCM) : 1L, MAKE_LENGTH(i, tc7_vector), s_vector); velts = VELTS(v); while(--i >= 0) (velts)[i] = fill; ALLOW_INTS; return v; } #ifdef BIGDIG char s_big_OVFLOW[] = "numerical overflow; NUMDIGS_MAX <"; char s_bignum[] = "bignum"; SCM mkbig(nlen, sign) sizet nlen; int sign; { SCM v; if (NUMDIGS_MAX <= nlen) wta(MAKINUM(nlen), s_big_OVFLOW, s_bignum); DEFER_INTS; v = must_malloc_cell((0L+nlen)*sizeof(BIGDIG), MAKE_NUMDIGS(nlen, sign ? tc16_bigneg : tc16_bigpos), s_bignum); ALLOW_INTS; return v; } /* big2inum() frees bignum b when it returns an INUM */ SCM big2inum(b, l) SCM b; sizet l; { unsigned long num = 0; BIGDIG *tmp = BDIGITS(b); while (l--) num = BIGUP(num) + tmp[l]; if (TYP16(b)==tc16_bigpos) { if (POSFIXABLE(num)) { bigrecy(b); return MAKINUM(num); }} else if (UNEGFIXABLE(num)) { bigrecy(b); return MAKINUM(-(long)num); } return b; } char s_adjbig[] = "adjbig"; SCM adjbig(b, nlen) SCM b; sizet nlen; { long nsiz = nlen; if (((nsiz << 16) >> 16) != nlen) wta(MAKINUM(nsiz), s_big_OVFLOW, s_adjbig); DEFER_INTS; must_realloc_cell(b, (long)(NUMDIGS(b)*sizeof(BIGDIG)), (long)(nsiz*sizeof(BIGDIG)), s_adjbig); SETNUMDIGS(b, nsiz, TYP16(b)); ALLOW_INTS; return b; } SCM normbig(b) SCM b; { # ifndef _UNICOS sizet nlen = NUMDIGS(b); # else int nlen = NUMDIGS(b); /* unsigned nlen breaks on Cray when nlen => 0 */ # endif BIGDIG *zds = BDIGITS(b); while (nlen-- && !zds[nlen]); nlen++; if (nlen * BITSPERDIG/CHAR_BIT <= sizeof(SCM)) if (INUMP(b = big2inum(b, (sizet)nlen))) return b; if (NUMDIGS(b)==nlen) return b; return adjbig(b, (sizet)nlen); } SCM copybig(b, sign) SCM b; int sign; { sizet i = NUMDIGS(b); SCM ans = mkbig(i, sign); BIGDIG *src = BDIGITS(b), *dst = BDIGITS(ans); while (i--) dst[i] = src[i]; return ans; } SCM long2big(n) long n; { sizet i = 0; BIGDIG *digits; SCM ans = mkbig(DIGSPERLONG, n<0); digits = BDIGITS(ans); if (n < 0) n = -n; while (i < DIGSPERLONG) { digits[i++] = BIGLO(n); n = BIGDN(n); } return ans; } SCM ulong2big(n) unsigned long n; { sizet i = 0; BIGDIG *digits; SCM ans = mkbig(DIGSPERLONG, 0); digits = BDIGITS(ans); while (i < DIGSPERLONG) { digits[i++] = BIGLO(n); n = BIGDN(n); } return ans; } int bigcomp(x, y) SCM x, y; { int xsign = BIGSIGN(x); int ysign = BIGSIGN(y); long xlen; sizet ylen; if (ysign < xsign) return 1; if (ysign > xsign) return -1; if ((ylen = NUMDIGS(y)) > (xlen = NUMDIGS(x))) return (xsign) ? -1 : 1; if (ylen < xlen) return (xsign) ? 1 : -1; while (xlen-- && (BDIGITS(y)[xlen]==BDIGITS(x)[xlen])); if (-1==xlen) return 0; return (BDIGITS(y)[xlen] > BDIGITS(x)[xlen]) ? (xsign ? -1 : 1) : (xsign ? 1 : -1); } # ifndef DIGSTOOBIG long pseudolong(x) long x; { union { long l; BIGDIG bd[DIGSPERLONG]; } p; sizet i = 0; if (x < 0) x = -x; while (i < DIGSPERLONG) {p.bd[i++] = BIGLO(x); x = BIGDN(x);} /* p.bd[0] = BIGLO(x); p.bd[1] = BIGDN(x); */ return p.l; } # else void longdigs(x, digs) long x; BIGDIG digs[DIGSPERLONG]; { sizet i = 0; if (x < 0) x = -x; while (i < DIGSPERLONG) {digs[i++] = BIGLO(x); x = BIGDN(x);} } # endif SCM addbig(x, nx, xsgn, bigy, sgny) BIGDIG *x; SCM bigy; sizet nx; /* Assumes nx <= NUMDIGS(bigy) */ int xsgn, sgny; /* Assumes xsgn and sgny equal either 0 or 0x0100 */ { SBIGLONG num = 0; sizet i = 0, ny = NUMDIGS(bigy); SCM z = copybig(bigy, BIGSIGN(bigy) ^ sgny); BIGDIG *zds = BDIGITS(z); if (xsgn ^ BIGSIGN(z)) { do { num += (long) zds[i] - x[i]; if (num < 0) {zds[i] = num + BIGRAD; num = -1;} else {zds[i] = BIGLO(num); num = 0;} } while (++i < nx); if (num && nx==ny) { num = 1; i = 0; CAR(z) ^= 0x0100; do { num += (BIGRAD-1) - zds[i]; zds[i++] = BIGLO(num); num = BIGDN(num); } while (i < ny); } else while (i < ny) { num += zds[i]; if (num < 0) {zds[i++] = num + BIGRAD; num = -1;} else {zds[i++] = BIGLO(num); num = 0;} } } else { do { num += (long) zds[i] + x[i]; zds[i++] = BIGLO(num); num = BIGDN(num); } while (i < nx); if (!num) return z; while (i < ny) { num += zds[i]; zds[i++] = BIGLO(num); num = BIGDN(num); if (!num) return z; } if (num) {z = adjbig(z, ny+1); BDIGITS(z)[ny] = num; return z;} } return normbig(z); } SCM mulbig(x, nx, y, ny, sgn) BIGDIG *x, *y; sizet nx, ny; int sgn; { sizet i = 0, j = nx + ny; UBIGLONG n = 0; SCM z = mkbig(j, sgn); BIGDIG *zds = BDIGITS(z); while (j--) zds[j] = 0; do { j = 0; if (x[i]) { do { n += zds[i + j] + ((UBIGLONG) x[i] * y[j]); zds[i + j++] = BIGLO(n); n = BIGDN(n); } while (j < ny); if (n) {zds[i + j] = n; n = 0;} } } while (++i < nx); return normbig(z); } UBIGLONG divbigdig(ds, h, div) BIGDIG *ds; sizet h; BIGDIG div; { register UBIGLONG t2 = 0L; while(h--) { t2 = BIGUP(t2) + ds[h]; ds[h] = t2 / div; t2 %= div; } return t2; } SCM divbigint(x, z, sgn, mode) SCM x; long z; int sgn, mode; { if (z < 0) z = -z; if (z < BIGRAD) { register UBIGLONG t2 = 0; register BIGDIG *ds = BDIGITS(x); sizet nd = NUMDIGS(x); while(nd--) t2 = (BIGUP(t2) + ds[nd]) % z; if (mode && t2) t2 = z - t2; return MAKINUM(sgn ? -(long)t2 : t2); } { # ifndef DIGSTOOBIG UBIGLONG t2 = pseudolong(z); return divbigbig(BDIGITS(x), NUMDIGS(x), (BIGDIG *)&t2, DIGSPERLONG, sgn, mode); # else BIGDIG t2[DIGSPERLONG]; longdigs(z, t2); return divbigbig(BDIGITS(x), NUMDIGS(x), t2, DIGSPERLONG, sgn, mode); # endif } } static SCM scm_copy_big_ash1 P((BIGDIG *xds, sizet xlen, BIGDIG dscl)); /* Make a copy of 2*xds and divide by dscl if dscl > 0 */ SCM scm_copy_big_ash1 (xds, xlen, dscl) BIGDIG *xds; sizet xlen; BIGDIG dscl; { sizet rlen = xlen + 1, i; SCM dencell = mkbig(rlen, 0); BIGDIG *dends = BDIGITS(dencell); dends[xlen] = xds[xlen-1]>>(BITSPERDIG - 1); for (i = xlen - 1; i > 0; i--) dends[i] = (((xds[i])<<1) & (BIGRAD - 1)) | ((xds[i-1])>>(BITSPERDIG - 1)); dends[0] = (((xds[0])<<1) & (BIGRAD - 1)); while(rlen && !dends[rlen-1]) rlen--; if (dscl) { divbigdig(dends, rlen, dscl); while(rlen && !dends[rlen-1]) rlen--; } SETNUMDIGS(dencell, rlen, TYP16(dencell)); return dencell; } SCM divbigbig(x, xlen, y, ylen, sgn, mode) BIGDIG *x, *y; sizet xlen, ylen; int sgn, mode; /* mode description 0 remainder 1 modulo 2 quotient 3 quotient with round-toward-even 4 quotient but returns NULL if division is not exact. */ { int roundup = 0; /* used for round-quotient */ sizet i = 0, j = 0; /* loop indexes */ SBIGLONG dds = 0; /* double-digit signed */ UBIGLONG ddu = 0; /* double-digit unsigned */ SCM quocell, dencell; volatile SCM gcpr[2]; sizet rlen; BIGDIG *quods, /* quotient digits */ *dends, /* scaled denominator digits */ dscl = 0, /* unscale quotient from scaled divisor */ qhat; while(!y[ylen-1]) ylen--; /* in case y came in as a psuedolong */ if (xlen < ylen) switch (mode) { case 0: /* remainder -- just return x */ quocell = gcpr[0] = mkbig(xlen, sgn); quods = BDIGITS(quocell); do {quods[i] = x[i];} while (++i < xlen); return quocell; case 1: /* modulo -- return y-x */ quocell = gcpr[0] = mkbig(ylen, sgn); quods = BDIGITS(quocell); do { dds += (long) y[i] - x[i]; if (dds < 0) {quods[i] = dds + BIGRAD; dds = -1;} else {quods[i] = dds; dds = 0;} } while (++i < xlen); while (i < ylen) { dds += y[i]; if (dds < 0) {quods[i++] = dds + BIGRAD; dds = -1;} else {quods[i++] = dds; dds = 0;} } goto doadj; case 2: return INUM0; /* quotient is zero */ case 3: /* round-toward-even */ /* Use dencell and dends variables to double the numerator */ dencell = gcpr[1] = scm_copy_big_ash1(x, xlen, dscl); dends = BDIGITS(dencell); rlen = NUMDIGS(dencell); if (rlen < ylen) return INUM0;; if (rlen > ylen) goto retone; i = rlen; while (i-- && (y[i]==dends[i])); if (-1==i || (y[i] > dends[i])) return INUM0; retone: return MAKINUM(sgn ? -1 : 1); case 4: return 0; /* the division is not exact */ } /* main algorithm requires xlen >= ylen */ quocell = gcpr[0] = mkbig(xlen==ylen ? xlen+2 : xlen+1, sgn); quods = BDIGITS(quocell); if (xlen==ylen) quods[xlen+1] = 0; if (y[ylen-1] < (BIGRAD>>1)) { /* normalize operands */ dscl = BIGRAD/(y[ylen-1]+1); dencell = gcpr[1] = mkbig(ylen, 0); dends = BDIGITS(dencell); while(j < ylen) { ddu += (UBIGLONG) y[j]*dscl; dends[j++] = BIGLO(ddu); ddu = BIGDN(ddu); } j = 0; ddu = 0; /* y = dends; */ while(j < xlen) { ddu += (UBIGLONG) x[j]*dscl; quods[j++] = BIGLO(ddu); ddu = BIGDN(ddu); } quods[j] = ddu; } else { dends = y; quods[j = xlen] = 0; while (j--) quods[j] = x[j]; } j = xlen==ylen ? xlen+1 : xlen; /* dividend needs more digits than divisor */ do { /* loop over digits of quotient */ if (quods[j]==dends[ylen-1]) qhat = BIGRAD-1; else qhat = (BIGUP(quods[j]) + quods[j-1])/dends[ylen-1]; if (!qhat) continue; i = 0; dds = 0; ddu = 0; do { /* multiply and subtract */ ddu += (UBIGLONG) dends[i] * qhat; dds += quods[j - ylen + i] - BIGLO(ddu); if (dds < 0) {quods[j - ylen + i] = dds + BIGRAD; dds = -1;} else {quods[j - ylen + i] = dds; dds = 0;} ddu = BIGDN(ddu); } while (++i < ylen); dds += quods[j - ylen + i] - ddu; /* borrow from high digit; don't update */ while (dds) { /* "add back" required */ i = 0; dds = 0; qhat--; do { dds += (long) quods[j - ylen + i] + dends[i]; quods[j - ylen + i] = BIGLO(dds); dds = BIGDN(dds); } while (++i < ylen); dds--; } if (mode >= 2) quods[j] = qhat; /* returning quotient */ } while (--j >= ylen); switch (mode) { case 4: /* check that remainder==0 */ for (j = ylen;j && !quods[j-1];--j) ; if (j) return 0; case 3: /* round toward even */ /* Reuse dencell and dends variables to double the remainder */ dencell = gcpr[1] = scm_copy_big_ash1(quods, ylen, dscl); dends = BDIGITS(dencell); rlen = NUMDIGS(dencell); if (rlen > ylen) roundup = 1; else if (rlen < ylen) ; else { i = rlen; while (i-- && (y[i]==dends[i])); if (-1==i) { if (0==roundup && quods[ylen] & 1) roundup = 1; } else if (y[i] < dends[i]) roundup = 1; } case 2: /* move quotient down in quocell */ j = (xlen==ylen ? xlen+2 : xlen+1) - ylen; for (i = 0;i < j;i++) quods[i] = quods[i+ylen]; ylen = i; if (roundup) { i = 0; dds = 1; while (i < ylen) { dds += quods[i]; quods[i++] = BIGLO(dds); dds = BIGDN(dds); if (!dds) break; } } break; case 1: /* subtract for modulo */ i = 0; dds = 0; j = 0; do {dds += dends[i] - quods[i]; j = j | quods[i]; if (dds < 0) {quods[i] = dds + BIGRAD; dds = -1;} else {quods[i] = dds; dds = 0;} } while (++i < ylen); if (!j) return INUM0; case 0: /* just normalize remainder */ if (dscl) divbigdig(quods, ylen, dscl); } doadj: for (j = ylen;j && !quods[j-1];--j) ; if (j * BITSPERDIG <= sizeof(SCM)*CHAR_BIT) if (INUMP(quocell = big2inum(quocell, j))) return quocell; return adjbig(quocell, j); } #endif static iproc cxrs[] = { {"cr", 0}, {"car", 0}, {"cdr", 0}, {"caar", 0}, {"cadr", 0}, {"cdar", 0}, {"cddr", 0}, {"caaar", 0}, {"caadr", 0}, {"cadar", 0}, {"caddr", 0}, {"cdaar", 0}, {"cdadr", 0}, {"cddar", 0}, {"cdddr", 0}, {"caaaar", 0}, {"caaadr", 0}, {"caadar", 0}, {"caaddr", 0}, {"cadaar", 0}, {"cadadr", 0}, {"caddar", 0}, {"cadddr", 0}, {"cdaaar", 0}, {"cdaadr", 0}, {"cdadar", 0}, {"cdaddr", 0}, {"cddaar", 0}, {"cddadr", 0}, {"cdddar", 0}, {"cddddr", 0}, {0, 0}}; static iproc subr1s[] = { {"not", lnot}, {"boolean?", booleanp}, {"pair?", consp}, {"null?", nullp}, {"list?", listp}, {s_length, length}, {s_reverse, reverse}, {"symbol?", symbolp}, {s_symbol2string, symbol2string}, {s_str2symbol, string2symbol}, {s_exactp, exactp}, {s_oddp, oddp}, {s_evenp, evenp}, {s_lognot, scm_lognot}, {s_logcount, scm_logcount}, {s_bitwise_bit_count, scm_bitwise_bit_count}, {s_intlength, scm_intlength}, {"char?", charp}, {s_ch_alphap, char_alphap}, {s_ch_nump, char_nump}, {s_ch_whitep, char_whitep}, {s_ch_upperp, char_upperp}, {s_ch_lowerp, char_lowerp}, {s_char2int, char2int}, {s_int2char, int2char}, {s_ch_upcase, char_upcase}, {s_ch_downcase, char_downcase}, {"string?", stringp}, {s_st_length, st_length}, {"vector?", vectorp}, {s_ve_length, vector_length}, {"procedure?", procedurep}, {"promise?", promisep}, {0, 0}}; static char s_acons[] = "acons"; static iproc subr2s[] = { {&s_acons[1], cons}, {s_setcar, setcar}, {s_setcdr, setcdr}, {s_list_ref, list_ref}, {s_memq, memq}, {s_member, member}, {s_assq, assq}, {s_assoc, assoc}, {s_quotient, lquotient}, /* {"rq", rq}, */ {s_rquotient, scm_round_quotient}, {s_remainder, lremainder}, {s_modulo, modulo}, {s_logtest, scm_logtest}, {s_logbitp, scm_logbitp}, {s_ash, scm_ash}, {s_st_ref, st_ref}, {"string<=?", st_leqp}, {"string-ci<=?", stci_leqp}, {s_ve_ref, vector_ref}, {0, 0}}; static iproc lsubrs[] = { {s_list, list}, {s_append, append}, {s_string, string}, {s_st_append, st_append}, {s_vector, vector}, {0, 0}}; static iproc subr2os[] = { {s_make_string, make_string}, {s_make_vector, make_vector}, {0, 0}}; static iproc asubrs[] = { {s_gcd, lgcd}, {"lcm", llcm}, {s_logand, scm_logand}, {s_logior, scm_logior}, {s_logxor, scm_logxor}, {0, 0}}; static iproc rpsubrs[] = { {"eq?", eq}, {"equal?", equal}, {"char=?", eq}, {s_ch_lessp, char_lessp}, {s_ci_eq, chci_eq}, {s_ci_lessp, chci_lessp}, {s_ch_leqp, char_leqp}, {s_ci_leqp, chci_leqp}, {s_ch_grp, char_grp}, {s_ci_grp, chci_grp}, {s_ch_geqp, char_geqp}, {s_ci_geqp, chci_geqp}, {s_st_equal, st_equal}, {s_stci_equal, stci_equal}, {s_st_lessp, st_lessp}, {s_stci_lessp, stci_lessp}, {"string>?", st_grp}, {"string-ci>?", stci_grp}, {"string>=?", st_geqp}, {"string-ci>=?", stci_geqp}, {0, 0}}; static iproc subr3s[] = { {s_bitfield, scm_bitfield}, {s_bitif, scm_bitif}, {s_copybit, scm_copybit}, {s_substring, substring}, {s_acons, acons}, {s_st_set, st_set}, {s_ve_set, vector_set}, {0, 0}}; void init_iprocs(subra, type) iproc *subra; int type; { for (;subra->string; subra++) make_subr(subra->string, type, subra->cproc); } void init_subrs() { init_iprocs(cxrs, tc7_cxr); init_iprocs(subr1s, tc7_subr_1); init_iprocs(subr2s, tc7_subr_2); init_iprocs(subr2os, tc7_subr_2o); init_iprocs(rpsubrs, tc7_rpsubr); init_iprocs(lsubrs, tc7_lsubr); init_iprocs(asubrs, tc7_asubr); init_iprocs(subr3s, tc7_subr_3); make_subr(s_copybitfield, tc7_lsubr_2, scm_copybitfield); } scm-5f4/unexec.c0000755000175000017500000010366510750242011010616 00000000000000/* Copyright (C) 1985,86,87,88,92,93,94 Free Software Foundation, Inc. This file is part of GNU Emacs. GNU Emacs is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. GNU Emacs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Emacs. If not, see . */ /* * unexec.c - Convert a running program into an a.out file. * * Author: Spencer W. Thomas * Computer Science Dept. * University of Utah * Date: Tue Mar 2 1982 * Modified heavily since then. * * Synopsis: * unexec (new_name, a_name, data_start, bss_start, entry_address) * char *new_name, *a_name; * unsigned data_start, bss_start, entry_address; * * Takes a snapshot of the program and makes an a.out format file in the * file named by the string argument new_name. * If a_name is non-NULL, the symbol table will be taken from the given file. * On some machines, an existing a_name file is required. * * The boundaries within the a.out file may be adjusted with the data_start * and bss_start arguments. Either or both may be given as 0 for defaults. * * Data_start gives the boundary between the text segment and the data * segment of the program. The text segment can contain shared, read-only * program code and literal data, while the data segment is always unshared * and unprotected. Data_start gives the lowest unprotected address. * The value you specify may be rounded down to a suitable boundary * as required by the machine you are using. * * Specifying zero for data_start means the boundary between text and data * should not be the same as when the program was loaded. * If NO_REMAP is defined, the argument data_start is ignored and the * segment boundaries are never changed. * * Bss_start indicates how much of the data segment is to be saved in the * a.out file and restored when the program is executed. It gives the lowest * unsaved address, and is rounded up to a page boundary. The default when 0 * is given assumes that the entire data segment is to be stored, including * the previous data and bss as well as any additional storage allocated with * break (2). * * The new file is set up to start at entry_address. * * If you make improvements I'd like to get them too. * harpo!utah-cs!thomas, thomas@Utah-20 * */ /* Modified to support SysVr3 shared libraries by James Van Artsdalen * of Dell Computer Corporation. james@bigtex.cactus.org. */ /* There are several compilation parameters affecting unexec: * COFF Define this if your system uses COFF for executables. * COFF_ENCAPSULATE Define this if you are using the GNU coff encapsulated a.out format. This is closer to a.out than COFF. You should *not* define COFF if you define COFF_ENCAPSULATE Otherwise we assume you use Berkeley format. * NO_REMAP Define this if you do not want to try to save Emacs's pure data areas as part of the text segment. Saving them as text is good because it allows users to share more. However, on machines that locate the text area far from the data area, the boundary cannot feasibly be moved. Such machines require NO_REMAP. Also, remapping can cause trouble with the built-in startup routine /lib/crt0.o, which defines `environ' as an initialized variable. Dumping `environ' as pure does not work! So, to use remapping, you must write a startup routine for your machine in Emacs's crt0.c. If NO_REMAP is defined, Emacs uses the system's crt0.o. * SECTION_ALIGNMENT Some machines that use COFF executables require that each section start on a certain boundary *in the COFF file*. Such machines should define SECTION_ALIGNMENT to a mask of the low-order bits that must be zero on such a boundary. This mask is used to control padding between segments in the COFF file. If SECTION_ALIGNMENT is not defined, the segments are written consecutively with no attempt at alignment. This is right for unmodified system V. * SEGMENT_MASK Some machines require that the beginnings and ends of segments *in core* be on certain boundaries. For most machines, a page boundary is sufficient. That is the default. When a larger boundary is needed, define SEGMENT_MASK to a mask of the bits that must be zero on such a boundary. * A_TEXT_OFFSET(HDR) Some machines count the a.out header as part of the size of the text segment (a_text); they may actually load the header into core as the first data in the text segment. Some have additional padding between the header and the real text of the program that is counted in a_text. For these machines, define A_TEXT_OFFSET(HDR) to examine the header structure HDR and return the number of bytes to add to `a_text' before writing it (above and beyond the number of bytes of actual program text). HDR's standard fields are already correct, except that this adjustment to the `a_text' field has not yet been made; thus, the amount of offset can depend on the data in the file. * A_TEXT_SEEK(HDR) If defined, this macro specifies the number of bytes to seek into the a.out file before starting to write the text segment. * EXEC_MAGIC For machines using COFF, this macro, if defined, is a value stored into the magic number field of the output file. * ADJUST_EXEC_HEADER This macro can be used to generate statements to adjust or initialize nonstandard fields in the file header * ADDR_CORRECT(ADDR) Macro to correct an int which is the bit pattern of a pointer to a byte into an int which is the number of a byte. This macro has a default definition which is usually right. This default definition is a no-op on most machines (where a pointer looks like an int) but not on all machines. */ #ifndef emacs #define PERROR(arg) perror (arg); return -1 #else #define IN_UNEXEC #include #define PERROR(file) report_error (file, new) #endif #ifndef CANNOT_DUMP /* all rest of file! */ #ifdef COFF_ENCAPSULATE int need_coff_header = 1; #include /* The location might be a poor assumption */ #else #ifdef MSDOS #if __DJGPP__ > 1 #include /* for O_RDONLY, O_RDWR */ #include /* for _crt0_startup_flags and its bits */ static int save_djgpp_startup_flags; #endif #include #define filehdr external_filehdr #define scnhdr external_scnhdr #define syment external_syment #define auxent external_auxent #define n_numaux e_numaux #define n_type e_type struct aouthdr { unsigned short magic; /* type of file */ unsigned short vstamp; /* version stamp */ unsigned long tsize; /* text size in bytes, padded to FW bdry*/ unsigned long dsize; /* initialized data " " */ unsigned long bsize; /* uninitialized data " " */ unsigned long entry; /* entry pt. */ unsigned long text_start;/* base of text used for this file */ unsigned long data_start;/* base of data used for this file */ }; #else /* not MSDOS */ #include #endif /* not MSDOS */ #endif /* Define getpagesize if the system does not. Note that this may depend on symbols defined in a.out.h. */ #include "getpagesize.h" #ifndef makedev /* Try to detect types.h already loaded */ #include #endif /* makedev */ #include #include #include #include /* Must be after sys/types.h for USG and BSD4_1*/ #ifdef USG5 #include #endif #ifndef O_RDONLY #define O_RDONLY 0 #endif #ifndef O_RDWR #define O_RDWR 2 #endif extern char *start_of_text (); /* Start of text */ extern char *start_of_data (); /* Start of initialized data */ #ifdef COFF static long block_copy_start; /* Old executable start point */ static struct filehdr f_hdr; /* File header */ static struct aouthdr f_ohdr; /* Optional file header (a.out) */ long bias; /* Bias to add for growth */ long lnnoptr; /* Pointer to line-number info within file */ #define SYMS_START block_copy_start static long text_scnptr; static long data_scnptr; #else /* not COFF */ #ifdef HPUX extern void *sbrk (); #else #if 0 /* Some systems with __STDC__ compilers still declare this `char *' in some header file, and our declaration conflicts. The return value is always cast, so it should be harmless to leave it undefined. Hopefully machines with different size pointers and ints declare sbrk in a header file. */ #ifdef __STDC__ extern void *sbrk (); #else extern char *sbrk (); #endif /* __STDC__ */ #endif #endif /* HPUX */ #define SYMS_START ((long) N_SYMOFF (ohdr)) /* Some machines override the structure name for an a.out header. */ #ifndef EXEC_HDR_TYPE #define EXEC_HDR_TYPE struct exec #endif #ifdef HPUX #ifdef HP9000S200_ID #define MY_ID HP9000S200_ID #else #include #define MY_ID MYSYS #endif /* no HP9000S200_ID */ static MAGIC OLDMAGIC = {MY_ID, SHARE_MAGIC}; static MAGIC NEWMAGIC = {MY_ID, DEMAND_MAGIC}; #define N_TXTOFF(x) TEXT_OFFSET(x) #define N_SYMOFF(x) LESYM_OFFSET(x) static EXEC_HDR_TYPE hdr, ohdr; #else /* not HPUX */ #if defined (USG) && !defined (IBMAIX) && !defined (IRIS) && !defined (COFF_ENCAPSULATE) && !defined (LINUX) static struct bhdr hdr, ohdr; #define a_magic fmagic #define a_text tsize #define a_data dsize #define a_bss bsize #define a_syms ssize #define a_trsize rtsize #define a_drsize rdsize #define a_entry entry #define N_BADMAG(x) \ (((x).fmagic)!=OMAGIC && ((x).fmagic)!=NMAGIC &&\ ((x).fmagic)!=FMAGIC && ((x).fmagic)!=IMAGIC) #define NEWMAGIC FMAGIC #else /* IRIS or IBMAIX or not USG */ static EXEC_HDR_TYPE hdr, ohdr; #define NEWMAGIC ZMAGIC #endif /* IRIS or IBMAIX not USG */ #endif /* not HPUX */ static int unexec_text_start; static int unexec_data_start; #ifdef COFF_ENCAPSULATE /* coffheader is defined in the GNU a.out.encap.h file. */ struct coffheader coffheader; #endif #endif /* not COFF */ static int pagemask; /* Correct an int which is the bit pattern of a pointer to a byte into an int which is the number of a byte. This is a no-op on ordinary machines, but not on all. */ #ifndef ADDR_CORRECT /* Let m-*.h files override this definition */ #define ADDR_CORRECT(x) ((char *)(x) - (char*)0) #endif #ifdef emacs #include "lisp.h" static report_error (file, fd) char *file; int fd; { if (fd) close (fd); report_file_error ("Cannot unexec", Fcons (build_string (file), Qnil)); } #endif /* emacs */ #define ERROR0(msg) report_error_1 (new, msg, 0, 0); return -1 #define ERROR1(msg,x) report_error_1 (new, msg, x, 0); return -1 #define ERROR2(msg,x,y) report_error_1 (new, msg, x, y); return -1 static report_error_1 (fd, msg, a1, a2) int fd; char *msg; int a1, a2; { close (fd); #ifdef emacs error (msg, a1, a2); #else fprintf (stderr, msg, a1, a2); fprintf (stderr, "\n"); #endif } static int make_hdr (); static int copy_text_and_data (); static int copy_sym (); static void mark_x (); /* **************************************************************** * unexec * * driving logic. */ unexec (new_name, a_name, data_start, bss_start, entry_address) char *new_name, *a_name; unsigned data_start, bss_start, entry_address; { int new, a_out = -1; if (a_name && (a_out = open (a_name, O_RDONLY)) < 0) { PERROR (a_name); } if ((new = creat (new_name, 0666)) < 0) { PERROR (new_name); } if (make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) < 0 || copy_text_and_data (new, a_out) < 0 || copy_sym (new, a_out, a_name, new_name) < 0 #ifdef COFF #ifndef COFF_BSD_SYMBOLS || adjust_lnnoptrs (new, a_out, new_name) < 0 #endif #endif ) { close (new); /* unlink (new_name); /* Failed, unlink new a.out */ return -1; } close (new); if (a_out >= 0) close (a_out); mark_x (new_name); return 0; } /* **************************************************************** * make_hdr * * Make the header in the new a.out from the header in core. * Modify the text and data sizes. */ static int make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) int new, a_out; unsigned data_start, bss_start, entry_address; char *a_name; char *new_name; { int tem; #ifdef COFF auto struct scnhdr f_thdr; /* Text section header */ auto struct scnhdr f_dhdr; /* Data section header */ auto struct scnhdr f_bhdr; /* Bss section header */ auto struct scnhdr scntemp; /* Temporary section header */ register int scns; #endif /* COFF */ #ifdef USG_SHARED_LIBRARIES extern unsigned int bss_end; #else unsigned int bss_end; #endif pagemask = getpagesize () - 1; /* Adjust text/data boundary. */ #ifdef NO_REMAP data_start = (int) start_of_data (); #else /* not NO_REMAP */ if (!data_start) data_start = (int) start_of_data (); #endif /* not NO_REMAP */ data_start = ADDR_CORRECT (data_start); #ifdef SEGMENT_MASK data_start = data_start & ~SEGMENT_MASK; /* (Down) to segment boundary. */ #else data_start = data_start & ~pagemask; /* (Down) to page boundary. */ #endif bss_end = ADDR_CORRECT (sbrk (0)) + pagemask; bss_end &= ~ pagemask; /* Adjust data/bss boundary. */ if (bss_start != 0) { bss_start = (ADDR_CORRECT (bss_start) + pagemask); /* (Up) to page bdry. */ bss_start &= ~ pagemask; if (bss_start > bss_end) { ERROR1 ("unexec: Specified bss_start (%u) is past end of program", bss_start); } } else bss_start = bss_end; if (data_start > bss_start) /* Can't have negative data size. */ { ERROR2 ("unexec: data_start (%u) can't be greater than bss_start (%u)", data_start, bss_start); } #ifdef COFF /* Salvage as much info from the existing file as possible */ if (a_out >= 0) { if (read (a_out, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr)) { PERROR (a_name); } block_copy_start += sizeof (f_hdr); if (f_hdr.f_opthdr > 0) { if (read (a_out, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr)) { PERROR (a_name); } block_copy_start += sizeof (f_ohdr); } /* Loop through section headers, copying them in */ lseek (a_out, sizeof (f_hdr) + f_hdr.f_opthdr, 0); for (scns = f_hdr.f_nscns; scns > 0; scns--) { if (read (a_out, &scntemp, sizeof (scntemp)) != sizeof (scntemp)) { PERROR (a_name); } if (scntemp.s_scnptr > 0L) { if (block_copy_start < scntemp.s_scnptr + scntemp.s_size) block_copy_start = scntemp.s_scnptr + scntemp.s_size; } if (strcmp (scntemp.s_name, ".text") == 0) { f_thdr = scntemp; } else if (strcmp (scntemp.s_name, ".data") == 0) { f_dhdr = scntemp; } else if (strcmp (scntemp.s_name, ".bss") == 0) { f_bhdr = scntemp; } } } else { ERROR0 ("can't build a COFF file from scratch yet"); } /* Now we alter the contents of all the f_*hdr variables to correspond to what we want to dump. */ #ifdef USG_SHARED_LIBRARIES /* The amount of data we're adding to the file is distance from the * end of the original .data space to the current end of the .data * space. */ bias = bss_start - (f_ohdr.data_start + f_dhdr.s_size); #endif f_hdr.f_flags |= (F_RELFLG | F_EXEC); #ifdef TPIX f_hdr.f_nscns = 3; #endif #ifdef EXEC_MAGIC f_ohdr.magic = EXEC_MAGIC; #endif #ifndef NO_REMAP f_ohdr.text_start = (long) start_of_text (); f_ohdr.tsize = data_start - f_ohdr.text_start; f_ohdr.data_start = data_start; #endif /* NO_REMAP */ f_ohdr.dsize = bss_start - f_ohdr.data_start; f_ohdr.bsize = bss_end - bss_start; #ifndef KEEP_OLD_TEXT_SCNPTR /* On some machines, the old values are right. ??? Maybe on all machines with NO_REMAP. */ f_thdr.s_size = f_ohdr.tsize; f_thdr.s_scnptr = sizeof (f_hdr) + sizeof (f_ohdr); f_thdr.s_scnptr += (f_hdr.f_nscns) * (sizeof (f_thdr)); #endif /* KEEP_OLD_TEXT_SCNPTR */ #ifdef ADJUST_TEXT_SCNHDR_SIZE /* On some machines, `text size' includes all headers. */ f_thdr.s_size -= f_thdr.s_scnptr; #endif /* ADJUST_TEST_SCNHDR_SIZE */ lnnoptr = f_thdr.s_lnnoptr; #ifdef SECTION_ALIGNMENT /* Some systems require special alignment of the sections in the file itself. */ f_thdr.s_scnptr = (f_thdr.s_scnptr + SECTION_ALIGNMENT) & ~SECTION_ALIGNMENT; #endif /* SECTION_ALIGNMENT */ #ifdef TPIX f_thdr.s_scnptr = 0xd0; #endif text_scnptr = f_thdr.s_scnptr; #ifdef ADJUST_TEXTBASE text_scnptr = sizeof (f_hdr) + sizeof (f_ohdr) + (f_hdr.f_nscns) * (sizeof (f_thdr)); #endif #ifndef KEEP_OLD_PADDR f_dhdr.s_paddr = f_ohdr.data_start; #endif /* KEEP_OLD_PADDR */ f_dhdr.s_vaddr = f_ohdr.data_start; f_dhdr.s_size = f_ohdr.dsize; f_dhdr.s_scnptr = f_thdr.s_scnptr + f_thdr.s_size; #ifdef SECTION_ALIGNMENT /* Some systems require special alignment of the sections in the file itself. */ f_dhdr.s_scnptr = (f_dhdr.s_scnptr + SECTION_ALIGNMENT) & ~SECTION_ALIGNMENT; #endif /* SECTION_ALIGNMENT */ #ifdef DATA_SECTION_ALIGNMENT /* Some systems require special alignment of the data section only. */ f_dhdr.s_scnptr = (f_dhdr.s_scnptr + DATA_SECTION_ALIGNMENT) & ~DATA_SECTION_ALIGNMENT; #endif /* DATA_SECTION_ALIGNMENT */ data_scnptr = f_dhdr.s_scnptr; #ifndef KEEP_OLD_PADDR f_bhdr.s_paddr = f_ohdr.data_start + f_ohdr.dsize; #endif /* KEEP_OLD_PADDR */ f_bhdr.s_vaddr = f_ohdr.data_start + f_ohdr.dsize; f_bhdr.s_size = f_ohdr.bsize; f_bhdr.s_scnptr = 0L; #ifndef USG_SHARED_LIBRARIES bias = f_dhdr.s_scnptr + f_dhdr.s_size - block_copy_start; #endif if (f_hdr.f_symptr > 0L) { f_hdr.f_symptr += bias; } if (f_thdr.s_lnnoptr > 0L) { f_thdr.s_lnnoptr += bias; } #ifdef ADJUST_EXEC_HEADER ADJUST_EXEC_HEADER; #endif /* ADJUST_EXEC_HEADER */ if (write (new, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr)) { PERROR (new_name); } if (write (new, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr)) { PERROR (new_name); } #ifndef USG_SHARED_LIBRARIES if (write (new, &f_thdr, sizeof (f_thdr)) != sizeof (f_thdr)) { PERROR (new_name); } if (write (new, &f_dhdr, sizeof (f_dhdr)) != sizeof (f_dhdr)) { PERROR (new_name); } if (write (new, &f_bhdr, sizeof (f_bhdr)) != sizeof (f_bhdr)) { PERROR (new_name); } #else /* USG_SHARED_LIBRARIES */ /* The purpose of this code is to write out the new file's section * header table. * * Scan through the original file's sections. If the encountered * section is one we know (.text, .data or .bss), write out the * correct header. If it is a section we do not know (such as * .lib), adjust the address of where the section data is in the * file, and write out the header. * * If any section precedes .text or .data in the file, this code * will not adjust the file pointer for that section correctly. */ /* This used to use sizeof (f_ohdr) instead of .f_opthdr. .f_opthdr is said to be right when there is no optional header. */ lseek (a_out, sizeof (f_hdr) + f_hdr.f_opthdr, 0); for (scns = f_hdr.f_nscns; scns > 0; scns--) { if (read (a_out, &scntemp, sizeof (scntemp)) != sizeof (scntemp)) PERROR (a_name); if (!strcmp (scntemp.s_name, f_thdr.s_name)) /* .text */ { if (write (new, &f_thdr, sizeof (f_thdr)) != sizeof (f_thdr)) PERROR (new_name); } else if (!strcmp (scntemp.s_name, f_dhdr.s_name)) /* .data */ { if (write (new, &f_dhdr, sizeof (f_dhdr)) != sizeof (f_dhdr)) PERROR (new_name); } else if (!strcmp (scntemp.s_name, f_bhdr.s_name)) /* .bss */ { if (write (new, &f_bhdr, sizeof (f_bhdr)) != sizeof (f_bhdr)) PERROR (new_name); } else { if (scntemp.s_scnptr) scntemp.s_scnptr += bias; if (write (new, &scntemp, sizeof (scntemp)) != sizeof (scntemp)) PERROR (new_name); } } #endif /* USG_SHARED_LIBRARIES */ return (0); #else /* if not COFF */ /* Get symbol table info from header of a.out file if given one. */ if (a_out >= 0) { #ifdef COFF_ENCAPSULATE if (read (a_out, &coffheader, sizeof coffheader) != sizeof coffheader) { PERROR(a_name); } if (coffheader.f_magic != COFF_MAGIC) { ERROR1("%s doesn't have legal coff magic number\n", a_name); } #endif if (read (a_out, &ohdr, sizeof hdr) != sizeof hdr) { PERROR (a_name); } if (N_BADMAG (ohdr)) { ERROR1 ("invalid magic number in %s", a_name); } hdr = ohdr; } else { #ifdef COFF_ENCAPSULATE /* We probably could without too much trouble. The code is in gld * but I don't have that much time or incentive. */ ERROR0 ("can't build a COFF file from scratch yet"); #else #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */ bzero ((void *)&hdr, sizeof hdr); #else bzero (&hdr, sizeof hdr); #endif #endif } unexec_text_start = (long) start_of_text (); unexec_data_start = data_start; /* Machine-dependent fixup for header, or maybe for unexec_text_start */ #ifdef ADJUST_EXEC_HEADER ADJUST_EXEC_HEADER; #endif /* ADJUST_EXEC_HEADER */ hdr.a_trsize = 0; hdr.a_drsize = 0; if (entry_address != 0) hdr.a_entry = entry_address; hdr.a_bss = bss_end - bss_start; hdr.a_data = bss_start - data_start; #ifdef NO_REMAP hdr.a_text = ohdr.a_text; #else /* not NO_REMAP */ hdr.a_text = data_start - unexec_text_start; #ifdef A_TEXT_OFFSET hdr.a_text += A_TEXT_OFFSET (ohdr); #endif #endif /* not NO_REMAP */ #ifdef COFF_ENCAPSULATE /* We are encapsulating BSD format within COFF format. */ { struct coffscn *tp, *dp, *bp; tp = &coffheader.scns[0]; dp = &coffheader.scns[1]; bp = &coffheader.scns[2]; tp->s_size = hdr.a_text + sizeof(struct exec); dp->s_paddr = data_start; dp->s_vaddr = data_start; dp->s_size = hdr.a_data; bp->s_paddr = dp->s_vaddr + dp->s_size; bp->s_vaddr = bp->s_paddr; bp->s_size = hdr.a_bss; coffheader.tsize = tp->s_size; coffheader.dsize = dp->s_size; coffheader.bsize = bp->s_size; coffheader.text_start = tp->s_vaddr; coffheader.data_start = dp->s_vaddr; } if (write (new, &coffheader, sizeof coffheader) != sizeof coffheader) { PERROR(new_name); } #endif /* COFF_ENCAPSULATE */ if (write (new, &hdr, sizeof hdr) != sizeof hdr) { PERROR (new_name); } #if 0 /* This #ifndef caused a bug on Linux when using QMAGIC. */ /* This adjustment was done above only #ifndef NO_REMAP, so only undo it now #ifndef NO_REMAP. */ /* #ifndef NO_REMAP */ #endif #ifdef A_TEXT_OFFSET hdr.a_text -= A_TEXT_OFFSET (ohdr); #endif return 0; #endif /* not COFF */ } /* **************************************************************** * copy_text_and_data * * Copy the text and data segments from memory to the new a.out */ static int copy_text_and_data (new, a_out) int new, a_out; { register char *end; register char *ptr; #ifdef COFF #ifdef USG_SHARED_LIBRARIES int scns; struct scnhdr scntemp; /* Temporary section header */ /* The purpose of this code is to write out the new file's section * contents. * * Step through the section table. If we know the section (.text, * .data) do the appropriate thing. Otherwise, if the section has * no allocated space in the file (.bss), do nothing. Otherwise, * the section has space allocated in the file, and is not a section * we know. So just copy it. */ lseek (a_out, sizeof (struct filehdr) + sizeof (struct aouthdr), 0); for (scns = f_hdr.f_nscns; scns > 0; scns--) { if (read (a_out, &scntemp, sizeof (scntemp)) != sizeof (scntemp)) PERROR ("temacs"); if (!strcmp (scntemp.s_name, ".text")) { lseek (new, (long) text_scnptr, 0); ptr = (char *) f_ohdr.text_start; end = ptr + f_ohdr.tsize; write_segment (new, ptr, end); } else if (!strcmp (scntemp.s_name, ".data")) { lseek (new, (long) data_scnptr, 0); ptr = (char *) f_ohdr.data_start; end = ptr + f_ohdr.dsize; write_segment (new, ptr, end); } else if (!scntemp.s_scnptr) ; /* do nothing - no data for this section */ else { char page[BUFSIZ]; int size, n; long old_a_out_ptr = lseek (a_out, 0, 1); lseek (a_out, scntemp.s_scnptr, 0); for (size = scntemp.s_size; size > 0; size -= sizeof (page)) { n = size > sizeof (page) ? sizeof (page) : size; if (read (a_out, page, n) != n || write (new, page, n) != n) PERROR ("emacs"); } lseek (a_out, old_a_out_ptr, 0); } } #else /* COFF, but not USG_SHARED_LIBRARIES */ #ifdef MSDOS #if __DJGPP__ >= 2 /* Dump the original table of exception handlers, not the one where our exception hooks are registered. */ __djgpp_exception_toggle (); /* Switch off startup flags that might have been set at runtime and which might change the way that dumped Emacs works. */ save_djgpp_startup_flags = _crt0_startup_flags; _crt0_startup_flags &= ~(_CRT0_FLAG_NO_LFN | _CRT0_FLAG_NEARPTR); #endif #endif lseek (new, (long) text_scnptr, 0); ptr = (char *) f_ohdr.text_start; #ifdef HEADER_INCL_IN_TEXT /* For Gould UTX/32, text starts after headers */ ptr = (char *) (ptr + text_scnptr); #endif /* HEADER_INCL_IN_TEXT */ end = ptr + f_ohdr.tsize; write_segment (new, ptr, end); lseek (new, (long) data_scnptr, 0); ptr = (char *) f_ohdr.data_start; end = ptr + f_ohdr.dsize; write_segment (new, ptr, end); #ifdef MSDOS #if __DJGPP__ >= 2 /* Restore our exception hooks. */ __djgpp_exception_toggle (); /* Restore the startup flags. */ _crt0_startup_flags = save_djgpp_startup_flags; #endif #endif #endif /* USG_SHARED_LIBRARIES */ #else /* if not COFF */ /* Some machines count the header as part of the text segment. That is to say, the header appears in core just before the address that start_of_text returns. For them, N_TXTOFF is the place where the header goes. We must adjust the seek to the place after the header. Note that at this point hdr.a_text does *not* count the extra A_TEXT_OFFSET bytes, only the actual bytes of code. */ #ifdef A_TEXT_SEEK lseek (new, (long) A_TEXT_SEEK (hdr), 0); #else lseek (new, (long) N_TXTOFF (hdr), 0); #endif /* no A_TEXT_SEEK */ #ifdef RISCiX /* Acorn's RISC-iX has a wacky way of initialising the position of the heap. * There is a little table in crt0.o that is filled at link time with * the min and current brk positions, among other things. When start * runs, it copies the table to where these parameters live during * execution. This data is in text space, so it cannot be modified here * before saving the executable, so the data is written manually. In * addition, the table does not have a label, and the nearest accessible * label (mcount) is not prefixed with a '_', thus making it inaccessible * from within C programs. To overcome this, emacs's executable is passed * through the command 'nm %s | fgrep mcount' into a pipe, and the * resultant output is then used to find the address of 'mcount'. As far as * is possible to determine, in RISC-iX releases prior to 1.2, the negative * offset of the table from mcount is 0x2c, whereas from 1.2 onwards it is * 0x30. bss_end has been rounded up to page boundary. This solution is * based on suggestions made by Kevin Welton and Steve Hunt of Acorn, and * avoids the need for a custom version of crt0.o for emacs which has its * table in data space. */ { char command[1024]; char errbuf[1024]; char address_text[32]; int proforma[4]; FILE *pfile; char *temp_ptr; char c; int mcount_address, mcount_offset, count; extern char *_execname; /* The use of _execname is incompatible with RISCiX 1.1 */ sprintf (command, "nm %s | fgrep mcount", _execname); if ( (pfile = popen(command, "r")) == NULL) { sprintf (errbuf, "Could not open pipe"); PERROR (errbuf); } count=0; while ( ((c=getc(pfile)) != EOF) && (c != ' ') && (count < 31)) address_text[count++]=c; address_text[count]=0; if ((count == 0) || pclose(pfile) != NULL) { sprintf (errbuf, "Failed to execute the command '%s'\n", command); PERROR (errbuf); } sscanf(address_text, "%x", &mcount_address); ptr = (char *) unexec_text_start; mcount_offset = (char *)mcount_address - ptr; #ifdef RISCiX_1_1 #define EDATA_OFFSET 0x2c #else #define EDATA_OFFSET 0x30 #endif end = ptr + mcount_offset - EDATA_OFFSET; write_segment (new, ptr, end); proforma[0] = bss_end; /* becomes _edata */ proforma[1] = bss_end; /* becomes _end */ proforma[2] = bss_end; /* becomes _minbrk */ proforma[3] = bss_end; /* becomes _curbrk */ write (new, proforma, 16); temp_ptr = ptr; ptr = end + 16; end = temp_ptr + hdr.a_text; write_segment (new, ptr, end); } #else /* !RISCiX */ ptr = (char *) unexec_text_start; end = ptr + hdr.a_text; write_segment (new, ptr, end); #endif /* RISCiX */ ptr = (char *) unexec_data_start; end = ptr + hdr.a_data; /* This lseek is certainly incorrect when A_TEXT_OFFSET and I believe it is a no-op otherwise. Let's see if its absence ever fails. */ /* lseek (new, (long) N_TXTOFF (hdr) + hdr.a_text, 0); */ write_segment (new, ptr, end); #endif /* not COFF */ return 0; } write_segment (new, ptr, end) int new; register char *ptr, *end; { register int i, nwrite, ret; char buf[80]; extern int errno; /* This is the normal amount to write at once. It is the size of block that NFS uses. */ int writesize = 1 << 13; int pagesize = getpagesize (); char zeros[1 << 13]; bzero (zeros, sizeof (zeros)); for (i = 0; ptr < end;) { /* Distance to next multiple of writesize. */ nwrite = (((int) ptr + writesize) & -writesize) - (int) ptr; /* But not beyond specified end. */ if (nwrite > end - ptr) nwrite = end - ptr; ret = write (new, ptr, nwrite); /* If write gets a page fault, it means we reached a gap between the old text segment and the old data segment. This gap has probably been remapped into part of the text segment. So write zeros for it. */ if (ret == -1 #ifdef EFAULT && errno == EFAULT #endif ) { /* Write only a page of zeros at once, so that we we don't overshoot the start of the valid memory in the old data segment. */ if (nwrite > pagesize) nwrite = pagesize; write (new, zeros, nwrite); } #if 0 /* Now that we have can ask `write' to write more than a page, it is legit for write do less than the whole amount specified. */ else if (nwrite != ret) { sprintf (buf, "unexec write failure: addr 0x%x, fileno %d, size 0x%x, wrote 0x%x, errno %d", ptr, new, nwrite, ret, errno); PERROR (buf); } #endif i += nwrite; ptr += nwrite; } } /* **************************************************************** * copy_sym * * Copy the relocation information and symbol table from the a.out to the new */ static int copy_sym (new, a_out, a_name, new_name) int new, a_out; char *a_name, *new_name; { char page[1024]; int n; if (a_out < 0) return 0; #ifdef COFF if (SYMS_START == 0L) return 0; #endif /* COFF */ #ifdef COFF if (lnnoptr) /* if there is line number info */ lseek (a_out, lnnoptr, 0); /* start copying from there */ else #endif /* COFF */ lseek (a_out, SYMS_START, 0); /* Position a.out to symtab. */ while ((n = read (a_out, page, sizeof page)) > 0) { if (write (new, page, n) != n) { PERROR (new_name); } } if (n < 0) { PERROR (a_name); } return 0; } /* **************************************************************** * mark_x * * After successfully building the new a.out, mark it executable */ static void mark_x (name) char *name; { struct stat sbuf; int um; int new = 0; /* for PERROR */ um = umask (777); umask (um); if (stat (name, &sbuf) == -1) { PERROR (name); } sbuf.st_mode |= 0111 & ~um; if (chmod (name, sbuf.st_mode) == -1) PERROR (name); } #ifdef COFF #ifndef COFF_BSD_SYMBOLS /* * If the COFF file contains a symbol table and a line number section, * then any auxiliary entries that have values for x_lnnoptr must * be adjusted by the amount that the line number section has moved * in the file (bias computed in make_hdr). The #@$%&* designers of * the auxiliary entry structures used the absolute file offsets for * the line number entry rather than an offset from the start of the * line number section! * * When I figure out how to scan through the symbol table and pick out * the auxiliary entries that need adjustment, this routine will * be fixed. As it is now, all such entries are wrong and sdb * will complain. Fred Fish, UniSoft Systems Inc. */ /* This function is probably very slow. Instead of reopening the new file for input and output it should copy from the old to the new using the two descriptors already open (WRITEDESC and READDESC). Instead of reading one small structure at a time it should use a reasonable size buffer. But I don't have time to work on such things, so I am installing it as submitted to me. -- RMS. */ adjust_lnnoptrs (writedesc, readdesc, new_name) int writedesc; int readdesc; char *new_name; { register int nsyms; register int new; #if defined (amdahl_uts) || defined (pfa) SYMENT symentry; AUXENT auxentry; #else struct syment symentry; union auxent auxentry; #endif if (!lnnoptr || !f_hdr.f_symptr) return 0; #ifdef MSDOS if ((new = writedesc) < 0) #else if ((new = open (new_name, O_RDWR)) < 0) #endif { PERROR (new_name); return -1; } lseek (new, f_hdr.f_symptr, 0); for (nsyms = 0; nsyms < f_hdr.f_nsyms; nsyms++) { read (new, &symentry, SYMESZ); if (symentry.n_numaux) { read (new, &auxentry, AUXESZ); nsyms++; if (ISFCN (symentry.n_type) || symentry.n_type == 0x2400) { auxentry.x_sym.x_fcnary.x_fcn.x_lnnoptr += bias; lseek (new, -AUXESZ, 1); write (new, &auxentry, AUXESZ); } } } #ifndef MSDOS close (new); #endif return 0; } #endif /* COFF_BSD_SYMBOLS */ #endif /* COFF */ #endif /* not CANNOT_DUMP */ scm-5f4/COPYING0000755000175000017500000010451311675010371010220 00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . scm-5f4/README0000664000175000017500000001254114551621663010053 00000000000000This directory contains the distribution of scm. SCM conforms to Revised^5 Report on the Algorithmic Language Scheme and the IEEE P1178 specification. SCM runs under Amiga, Atari-ST, MacOS, MS-DOS, OS/2, NOS/VE, Unicos, VMS, Unix and similar systems. SCM supports the SLIB Scheme library; both SCM and SLIB are GNU packages. 1 Manifest ========== '.gdbinit' provides commands for debugging SCM with GDB 'COPYING' GNU GENERAL PUBLIC LICENSE 'COPYING.LESSER' GNU LESSER GENERAL PUBLIC LICENSE 'ChangeLog' changes to SCM. 'Idiffer.scm' Linear-space O(PN) sequence comparison. 'Iedline.scm' Gnu readline input editing. 'Init.scm' Scheme initialization. 'Link.scm' Dynamic link/loading. 'Macro.scm' Supports Syntax-Rules Macros. 'Makefile' builds SCMLIT using the 'make' program. 'QUICKREF' Quick Reference card for R4RS and IEEE Scheme. 'README' contains a MANIFEST, INSTALLATION INSTRUCTIONS, hints for EDITING SCHEME CODE, and a TROUBLE SHOOTING GUIDE. 'Transcen.scm' inexact builtin procedures. 'bench.scm' computes and records performance statistics of pi.scm. 'build.bat' invokes build.scm for MS-DOS 'build.scm' database for compiling and linking new SCM programs. 'byte.c' strings as bytes. 'bytenumb.c' Byte-number conversions. 'compile.scm' Hobbit compilation to C. 'continue-ia64.S'replaces make_root_continuation(), make_continuation(), and dynthrow() in continue.c 'continue.c' continuations. 'continue.h' continuations. 'crs.c' interactive terminal control. 'debug.c' debugging, printing code. 'differ.c' Linear-space O(PN) sequence comparison. 'dynl.c' dynamically load object files. 'ecrt0.c' discover the start of initialized data space dynamically at runtime. 'edline.c' Gnu readline input editing (get ftp.sys.toronto.edu:/pub/rc/editline.shar). 'eval.c' evaluator, apply, map, and foreach. 'example.scm' example from R4RS which uses inexact numbers. 'fdl.texi' GNU Free Documentation License. 'findexec.c' find the executable file function. 'get-contoffset-ia64.c'makes contoffset-ia64.S for inclusion by continue-ia64.S 'gmalloc.c' Gnu malloc(); used for unexec. 'gsubr.c' make_gsubr for arbitrary (< 11) arguments to C functions. 'ioext.c' system calls in common between PC compilers and unix. 'lastfile.c' find the point in data space between data and libraries. 'macosx-config.h'Included by unexmacosx.c and lastfile.c. 'mkimpcat.scm' build SCM-specific catalog for SLIB. 'patchlvl.h' patchlevel of this release. 'pi.c' computes digits of pi [cc -o pi pi.c;time pi 100 5]. 'pi.scm' computes digits of pi [type (pi 100 5)]. Test performance against pi.c. 'posix.c' posix library interface. 'pre-crt0.c' loaded before crt0.o on machines which do not remap part of the data space into text space in unexec. 'r4rstest.scm' tests conformance with Scheme specifications. 'ramap.c' array mapping 'record.c' proposed 'Record' user definable datatypes. 'repl.c' error, read-eval-print loop, read, write and load. 'rgx.c' string regular expression match. 'rope.c' C interface functions. 'sc2.c' procedures from R2RS and R3RS not in R4RS. 'scl.c' inexact arithmetic 'scm.1' unix style man page. 'scm.c' initialization, interrupts, and non-IEEE utility functions. 'scm.doc' man page generated from scm.1. 'scm.h' data type and external definitions of SCM. 'scm.texi' SCM installation and use. 'scmfig.h' contains system dependent definitions. 'scmmain.c' initialization, interrupts, and non-IEEE utility functions. 'script.c' utilities for running as '#!' script. 'setjump.h' continuations, stacks, and memory allocation. 'setjump.mar' provides setjump and longjump which do not use $unwind utility on VMS. 'setjump.s' provides setjump and longjump for the Cray YMP. 'socket.c' BSD socket interface. 'split.scm' example use of crs.c. Input, output, and diagnostic output directed to separate windows. 'subr.c' the rest of IEEE functions. 'sys.c' call-with-current-continuation, opening and closing files, storage allocation and garbage collection. 'time.c' functions dealing with time. 'ugsetjump.s' provides setjump and longjump which work on Ultrix VAX. 'unexalpha.c' Convert a running program into an Alpha executable file. 'unexec.c' Convert a running program into an executable file. 'unexelf.c' Convert a running ELF program into an executable file. 'unexhp9k800.c' Convert a running HP-UX program into an executable file. 'unexmacosx.c' Convert a running program into an executable file under MacOS X. 'unexsgi.c' Convert a running program into an IRIX executable file. 'unexsunos4.c' Convert a running program into an executable file. 'unif.c' uniform vectors. 'unix.c' non-posix system calls on unix systems. scm-5f4/scmfig.h0000644000175000017500000005403714512635512010613 00000000000000/* "scmfig.h" system-dependent configuration. * Copyright (C) 1990-2006 Free Software Foundation, Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see * . */ /* Author: Aubrey Jaffer */ #ifdef sequent # include # define strchr index # define strrchr rindex #else # ifndef PLAN9 # include # endif #endif /* MS Windows signal handling hack added by Rainer Urian */ /* SCM crashes on WindowsNT after hitting control-c. This is because signal handling in windows console applications is rather different from unix apps. If control-c is hit on a console application Windows creates a new thread which executes the control-c signal handler. Now, if the SCM handler does the longjmp back to the repl loop it does it via the stack of the signal handler thread which results always ever is an access violation. The solution to this problem is to let the signal handler thread raise a software interrupt in the main thread. This is done with the following steps: 1. contol-c is hit 2. Windows creates the signal handler thread which in turn executes the routine win32_sigint as its signal handler. 3. The handler suspends the main thread and gets the main threads register context. 4. The handler simulates an interrupt call on the main thread by pointing Eip to the sigintstub stub function and also simulates a pushad , pushf of the main threads registers 5. The handler resumes the main thread which when scheduled will execute sigintstub, which in turn calls the proper signal interupt (scamble_signal) */ #ifdef _WIN32 /* POCKETCONSOLE has the signal handler implemented in the runtime */ # ifndef POCKETCONSOLE # define WINSIGNALS # endif #endif #include "scmflags.h" /* user specified, system independent flags */ /* IMPLINIT is the full pathname (surrounded by double quotes) of Init.scm, the Scheme initialization code. This is best defined in the makefile. If available, SCM uses the value of environment variable SCM_INIT_PATH instead of IMPLINIT. */ /* #define IMPLINIT "/usr/jaffer/scm/Init.scm" */ /* INITS is calls to initialization routines for any compiled libraries being linked into scm. This is best done in the makefile. File: INITS line: functions defined: sc2.c init_sc2(); substring-move-left!, substring-move-right!, substring-fill!, append!, and last-pair rgx.c init_rgx(); regcomp and regexec. */ /* #define INITS init_sc2(); */ /* #define SICP */ /* setbuf(0) needs to be done for tty ports in order for CHAR-READY? to work. This can cause problems under MSDOS and other systems. */ /* #define NOSETBUF */ /* #define RECKLESS */ /* #define CAUTIOUS */ /* #define BIGNUMS */ /* #define ARRAYS */ /* #define FLOATS */ /* Define SINGLES if you want single precision floats and (sizeof(float)==sizeof(long)) */ #ifdef FLOATS # ifndef _MSC_VER # define SINGLES # endif #endif /* #define SINGLESONLY */ /* Define CDR_DOUBLES if (sizeof(double)==sizeof(long)), i.e. a `single' is really a double. */ #ifdef FLOATS # ifdef __alpha # define CDR_DOUBLES # endif # ifdef _UNICOS /* doubles are no better than singles on Cray. */ # define SINGLESONLY # endif # ifdef CDR_DOUBLES # define SINGLES # define SINGLESONLY # endif #endif /* #define ENGNOT */ /* Define SUN_DL to configure code in "dynl.c" so that dynamic linking is done using the SUN dynamic linking library "dl". */ /* #define SUN_DL */ /* Define DLD to configure code in "dynl.c" so that dynamic linking is done using the "dld" library. DLD is ported to Linux, VAX (Ultrix), Sun 3 (SunOS 3.4 and 4.0), SPARCstation (SunOS 4.0), Sequent Symmetry (Dynix), and Atari ST. See scm/README or scm/ANNOUNCE for ftp sites offering dld. */ /* #define DLD */ /* Define HAVE_DYNL if dynamic linking is available */ #ifdef DLD # define HAVE_DYNL #endif #ifdef SUN_DL # define HAVE_DYNL #endif #ifdef HP_SHL # define HAVE_DYNL #endif #ifdef SCM_WIN_DLL # define HAVE_DYNL #endif #ifdef HAVE_DYNL # define CCLO #endif /* Define GC_FREE_SEGMENTS if you want segments of unused heap to be freed up after garbage collection. Don't define it if you never want the heap to shrink. */ #ifndef DONT_GC_FREE_SEGMENTS # define GC_FREE_SEGMENTS #endif /* MEMOIZE_LOCALS means to convert references to local variables to ILOCs, (relative lexical addresses into the environment). This memoization makes evaluated Scheme code harder to read, so you may want to undefine this flag for debugging -- but SCM will run 3 to 6 times slower */ #ifndef DONT_MEMOIZE_LOCALS # define MEMOIZE_LOCALS #endif /* #define CHEAP_CONTINUATIONS */ /* #define TICKS */ /* PROT386 should be defined on the compilation command line if the program is to be run on an intel 386 in protected mode. `Huge' pointers common on MSDOS compilers do not work in protected mode. PROT386 is required if scm is to run as part of a Microsoft Windows application. Added by Stephen Adams 8 May 92 */ /* #define PROT386 */ /* #define NON_PREEMPTIVE if you are using an non-preemptive operating system in which periodic polling for interrupts is necessary. Provide your own main procedure (e.g., WinMain, in Windows) or modify "scmmain.c". Define and initialize unsigned int poll_count, and provide a procedure named poll_routine(), which POLL calls each time poll_count reaches zero. poll_routine() must reinitialize poll_count. It may also check for external actions, such as Windows messages. The value assigned to poll_count can be quite large, e.g., 1000, while still maintaining good response time. */ /* #define CAREFUL_INTS */ /* Define MACRO if you want C level support for hygienic and referentially transparent macros. */ /* #define MACRO */ /* STDC_HEADERS indicates that the include file names are the same as ANSI C. For most modern systems this is the case. */ /* added by Yasuaki Honda */ #ifdef THINK_C # define __STDC__ # ifndef macintosh # define macintosh # endif #endif /* added by Bob Schumaker, cobblers@netcom.com */ #ifdef __MWERKS__ # ifndef macintosh # define macintosh # endif # define bzero(p, n) memset(p, 0, n) # define bcopy memcpy #endif /* added by Denys Duchier */ #ifndef SVR4 # ifdef __SVR4 # define SVR4 # endif #endif #ifdef __STDC__ # ifndef __HIGHC__ /* overly fussy compiler */ # define USE_ANSI_PROTOTYPES # endif # ifndef __GNUC__ # define STDC_HEADERS # else # ifdef sparc # ifdef SVR4 # define STDC_HEADERS # endif # else # ifndef tahoe # ifndef sun # define STDC_HEADERS # endif # endif # endif # endif #endif #ifdef __aarch64__ # define SHORT_INT # define CDR_DOUBLES #endif #ifdef __alpha # define SHORT_INT #endif #ifdef __ia64__ # define SHORT_INT # define CDR_DOUBLES #endif #ifdef __x86_64 # define SHORT_INT # define CDR_DOUBLES # ifdef __GNUC__ /* Includes gcc, clang, and llvm-gcc */ # define SCM_LLONG __int128 # endif #endif #ifdef _X86_ /* Includes at least gcc on 32-bit platforms */ # ifdef __STDC_VERSION__ # if (__STDC_VERSION__ >= 199901L) /* ISO C99, has long long */ # define SCM_LLONG long long # endif # endif #endif #ifdef MSDOS /* Microsoft C 5.10 and 6.00A */ # ifndef GO32 # define SHORT_INT # define SHORT_SIZET # endif #endif #ifdef _QC # define SHORT_INT # define SHORT_SIZET #endif #ifdef __TURBOC__ # define SHORT_INT # define SHORT_SIZET # define LACK_SBRK # ifndef __TOS__ # define MSDOS # endif #endif #ifdef __HIGHC__ # define LACK_SBRK #endif #ifdef _WIN32 # define MSDOS # define LACK_SBRK # define LACK_TIMES #endif #ifdef _MSDOS # define MSDOS #endif #ifdef MSDOS # define STDC_HEADERS #endif #ifdef POCKETCONSOLE # define NOSETBUF # define LACK_FTIME #endif #ifdef vms # define STDC_HEADERS #endif #ifdef nosve # define STDC_HEADERS #endif #ifdef linux # define HAVE_SELECT # define HAVE_SYS_TIME_H # define STDC_HEADERS #endif #ifdef _UNICOS # define STDC_HEADERS #endif #ifdef _AIX # define _POSIX_SOURCE # define LACK_FTIME #endif #ifdef __sgi__ # define LACK_FTIME # define STDC_HEADERS # define USE_ANSI_PROTOTYPES # define HAVE_SYS_TIME_H # define __SVR4 #endif #ifdef __SVR4 # define HAVE_SELECT #endif #ifdef PLAN9 # define STDC_HEADERS #endif #ifdef hpux # define LACK_E_IDs #endif /* C-Set++ for OS/2 */ #ifdef __IBMC__ # define STDC_HEADERS # define LACK_TIMES # define LACK_SBRK #endif #ifdef __CYGWIN__ /* # define LACK_FTIME */ # define HAVE_SELECT # define HAVE_SYS_TIME_H # undef MSDOS #endif #ifdef __amigaos__ # define HAVE_SELECT # define HAVE_SYS_TIME_H # define LACK_SBRK #endif /* PROMPT is the prompt string printed at top level */ #ifndef PROMPT # ifdef SICP # define PROMPT "==> " # else # define PROMPT "> " # endif #endif /* #define BRACKETS_AS_PARENS to have [ and ] be read as ( and ) in forms. */ /* #define BRACKETS_AS_PARENS */ /* LINE_INCREMENTORS are the characters which cause the line count to be incremented for the purposes of error reporting. This feature is only used for scheme code loaded from files. WHITE_SPACES are other characters which should be treated like spaces in programs. in both cases sparate characters with ":case " */ #define LINE_INCREMENTORS '\n' #ifdef MSDOS # define WHITE_SPACES ' ':case '\t':case '\r':case '\f':case 26 #else # define WHITE_SPACES ' ':case '\t':case '\r':case '\f' #endif #ifdef __ia64__ # define PTR2INT(x) ((long)(x)) #else # ifdef __x86_64 # define PTR2INT(x) ((long)(x)) # else # define PTR2INT(x) ((int)(x)) # endif #endif #ifndef __builtin_expect # ifndef __GNUC__ # define __builtin_expect(expr, expected) (expr) # else # if (__GNUC__ < 3) # define __builtin_expect(expr, expected) (expr) # endif # endif #endif #define SCM_EXPECT_TRUE(expr) (__builtin_expect(expr, !0)) #define SCM_EXPECT_FALSE(expr) (__builtin_expect(expr, 0)) #ifdef __GNUC__ # define FENCE asm volatile ("") #else # define FENCE /**/ #endif #ifdef NON_PREEMPTIVE # define VERIFY_INTS(s1, s2) /**/ # define DEFER_INTS /**/ # ifdef TICKS # define POLL {if (0==poll_count--) poll_routine(); \ if (0==tick_count--) tick_signal();} # else # define POLL {if (0==poll_count--) poll_routine();} # endif # define CHECK_INTS POLL # define ALLOW_INTS POLL # define DEFER_INTS_EGC /**/ # define ALLOW_INTS_EGC /**/ #else # ifdef CAREFUL_INTS typedef struct {char *fname; int linum;} ints_infot; extern ints_infot *ints_info; # define VERIFY_INTS(s1, s2) {if (!ints_disabled)\ ints_warn(s1, s2, __FILE__, __LINE__); } # define DEFER_INTS \ {static ints_infot info = {__FILE__, __LINE__};\ FENCE;if (1==ints_disabled) ints_viol(&info, 1);\ else {ints_info = &info; ints_disabled = 1;FENCE;}} # define ALLOW_INTS \ {static ints_infot info = {__FILE__, __LINE__};\ FENCE;if (1!=ints_disabled) ints_viol(&info, 0);\ else {ints_info = &info; ints_disabled = 0;FENCE;CHECK_INTS}} # define DEFER_INTS_EGC \ {static ints_infot info = {__FILE__, __LINE__};\ FENCE;if (1==ints_disabled) ints_viol(&info, 1);\ else {ints_info = &info; ints_disabled = 2;FENCE;}} # define ALLOW_INTS_EGC \ {static ints_infot info = {__FILE__, __LINE__};\ FENCE;if (1==ints_disabled) ints_viol(&info, 0);\ else {ints_info = &info; ints_disabled = 0;FENCE;CHECK_INTS}} # else # define VERIFY_INTS(s1, s2) /**/ # define DEFER_INTS {FENCE;ints_disabled = 1;FENCE;} # define ALLOW_INTS {FENCE;ints_disabled = 0;FENCE;CHECK_INTS} # define DEFER_INTS_EGC {FENCE;ints_disabled = 2;FENCE;} # define ALLOW_INTS_EGC {FENCE;ints_disabled = 0;FENCE;CHECK_INTS} # endif # ifdef TICKS # define CHECK_INTS {if (deferred_proc) (*deferred_proc)(); POLL;} # define POLL {if (0==tick_count--) tick_signal();} # else # define CHECK_INTS {if (deferred_proc) (*deferred_proc)();} # define POLL /**/ # endif #endif #ifndef STACK_LIMIT # define STACK_LIMIT (HEAP_SEG_SIZE) #endif #define CHECK_STACK {if (2 < scm_verbose) stack_check();} /* Cray machines have pointers that are incremented once for each word, rather than each byte, the 3 most significant bits encode the byte within the word. The following macros deal with this by storing the native Cray pointers like the ones that looks like scm expects. This is done for any pointers that might appear in the car of a cell, pointers to vector elts, functions, &c are not munged. */ #ifdef _UNICOS # define SCM2PTR(x) ((int)(x) >> 3) # define PTR2SCM(x) (((SCM)(x)) << 3) # define POINTERS_MUNGED #else # ifdef TEST_SCM2PTR # define SCM2PTR(x) ((x) ^ 0xf0L) # define PTR2SCM(x) (((SCM)(x)) ^ 0xf0L) # define POINTERS_MUNGED # else # define SCM2PTR(x) (x) # define PTR2SCM(x) ((SCM)(x)) # endif #endif /* FIXABLE is non-null if its long argument can be encoded in an INUM. */ #define POSFIXABLE(n) SCM_EXPECT_TRUE((n) <= MOST_POSITIVE_FIXNUM) #define NEGFIXABLE(n) SCM_EXPECT_TRUE((n) >= MOST_NEGATIVE_FIXNUM) #define UNEGFIXABLE(n) SCM_EXPECT_TRUE((n) <= -MOST_NEGATIVE_FIXNUM) #define FIXABLE(n) (POSFIXABLE(n) && NEGFIXABLE(n)) /* The following 8 definitions are defined automatically by the C pre-processor. You will need to override these if you are cross-compiling or if the C pre-processor has different properties than the compiler. */ #if (((-1)%2==-1) && ((-1)%(-2)==-1) && (1%2==1) && (1%(-2)==1)) #else # define BADIVSGNS #endif /* SRS is signed right shift */ /*--- Turbo C++ v1.0 has a bug with right shifts of signed longs! It is believed to be fixed in Turbo C++ v1.01 ---*/ #if (-1==(((-1)<<2)+2)>>2) && (__TURBOC__ != 0x295) # define SRS(x, y) ((x)>>y) # ifdef __TURBOC__ # define INUM(x) (((x)>>1)>>1) # else # define INUM(x) SRS(x, 2) # endif #else # define SRS(x, y) (((x)<0) ? ~((~(x))>>y) : (x)>>y) # define INUM(x) SRS(x, 2) #endif #ifdef __TURBOC__ /* shifts of more than one are done by a library call, single shifts are performed in registers */ # define MAKINUM(x) ((((x)<<1)<<1)+2L) #else # define MAKINUM(x) (((x)<<2)+2L) #endif #ifdef _DCC # define ASCII #else # if (('\n'=='\025') && (' '=='\100') && ('a'=='\201') && ('A'=='\301')) # define EBCDIC # endif # if (('\n'=='\012') && (' '=='\040') && ('a'=='\141') && ('A'=='\101')) # define ASCII # endif #endif /* CHAR_CODE_LIMIT is the number of distinct characters represented by the unsigned char datatype. */ /* MOST_POSITIVE_FIXNUM is the INUM closest to positive infinity. */ /* MOST_NEGATIVE_FIXNUM is the INUM closest to negative infinity. */ #ifdef __STDC__ # define HAVE_LIMITSH #endif #ifdef MWC # define HAVE_LIMITSH #endif #ifdef HAVE_LIMITSH # include # ifdef UCHAR_MAX # define CHAR_CODE_LIMIT (UCHAR_MAX+1L) # else # define CHAR_CODE_LIMIT 256L # endif # define MOST_POSITIVE_FIXNUM (LONG_MAX>>2) # ifdef _UNICOS /* Stupid cray bug */ # define MOST_NEGATIVE_FIXNUM ((long)LONG_MIN/4) # else # define MOST_NEGATIVE_FIXNUM SRS((long)LONG_MIN, 2) # endif /* UNICOS */ #else # define CHAR_CODE_LIMIT 256L # define MOST_POSITIVE_FIXNUM ((long)((unsigned long)~0L>>3)) # if (0 != ~0) # define MOST_NEGATIVE_FIXNUM (-MOST_POSITIVE_FIXNUM-1) # else # define MOST_NEGATIVE_FIXNUM (-MOST_POSITIVE_FIXNUM) # endif #endif /* INTBUFLEN is the maximum number of characters neccessary for the printed or string representation of an exact number. */ #ifndef CHAR_BIT # define CHAR_BIT 8 #endif #ifndef LONG_BIT # define LONG_BIT (CHAR_BIT*sizeof(long)/sizeof(char)) #endif #define INTBUFLEN (5+LONG_BIT) /* Define BIGDIG to an integer type whose size is smaller than long if you want bignums. BIGRAD is one greater than the biggest BIGDIG. */ /* Define DIGSTOOBIG if the digits equivalent to a long won't fit in a long. */ #ifdef BIGNUMS # define SBIGLONG long # define UBIGLONG unsigned SBIGLONG # ifdef _UNICOS # define DIGSTOOBIG # if (1L << 31) <= USHRT_MAX # define BIGDIG unsigned short # else # define BIGDIG unsigned int # endif # define BITSPERDIG 32 # else # if INT_MAX < LONG_MAX # define BIGDIG unsigned int # else # define BIGDIG unsigned short # endif # endif # define BITSPERDIG (sizeof(BIGDIG)*CHAR_BIT) # define BIGRAD (1L << BITSPERDIG) # define DIGSPERLONG ((sizet)((sizeof(UBIGLONG))/sizeof(BIGDIG))) # define BIGUP(x) (((UBIGLONG)(x)) << BITSPERDIG) # define BIGDN(x) (((UBIGLONG)(x)) >> BITSPERDIG) # define BIGLO(x) ((x) & (BIGRAD-1L)) /* NUMDIGS_MAX is the maximum number of digits for BIGNUMS */ # ifndef NUMDIGS_MAX # define NUMDIGS_MAX 1000 # endif #endif #ifndef BIGDIG # ifndef FLOATS # define INUMS_ONLY # endif #endif /* FLOBUFLEN is the maximum number of characters neccessary for the printed or string representation of an inexact number. */ #ifdef FLOATS # define FLOBUFLEN (10+2*(sizeof(double)/sizeof(char)*CHAR_BIT*3+9)/10) #endif /* FLOATS */ /* MAXEXP is the maximum double precision exponent */ /* FLTMAX is less than or equal the largest single precision float */ #ifdef FLOATS # ifdef STDC_HEADERS # ifndef macintosh # ifndef PLAN9 # include # endif # endif # endif # ifdef DBL_MAX_10_EXP # define MAXEXP DBL_MAX_10_EXP # else # define MAXEXP 308 /* IEEE doubles */ # endif # ifndef DBL_DIG # define DBL_DIG 15 # endif # ifndef DBL_MAX_EXP # define DBL_MAX_EXP 1024 # endif # ifdef FLT_MAX # define FLTMAX FLT_MAX # else # define FLTMAX 1e+23 # endif #endif #ifdef FLOATS # ifndef __MINGW32__ /* Also asinh and acosh */ # define HAVE_ATANH # endif #endif /* SCM_LLONG, if defined, must be a signed integer type wide enough to hold the product of SCM_LONG * SCM_LONG. */ #ifdef SCM_LLONG # define SCM_ULLONG unsigned SCM_LLONG #endif #ifdef unix # define HAVE_UNIX #endif #ifdef __unix__ # define HAVE_UNIX #endif #ifdef _IBMR2 # define HAVE_UNIX # define STDC_HEADERS #endif /* Only some machines have pipes */ #ifdef HAVE_UNIX /* DJGPP (gcc for i386) defines unix! */ # define HAVE_PIPE #endif #ifndef macintosh # ifndef _M_ARM # ifndef _M_ARMT # ifdef __WINDOWS__ /* there should be a better flag for this. */ # define PROT386 # endif # endif # endif #endif /* PTR_LT defines how to compare two CELLPTRs (which may not be in the same array). CELLPTR is a pointer to a cons cell which may be compared or differenced. SCMPTR is used for stack bounds. */ #if defined(__TURBOC__) && !defined(__TOS__) # ifdef PROT386 typedef cell *CELLPTR; typedef SCM *SCMPTR; # define PTR_LT(x, y) (((long)(x)) < ((long)(y))) # else typedef cell huge *CELLPTR; typedef SCM huge *SCMPTR; # define PTR_LT(x, y) ((x) < (y)) # endif #else /* not __TURBOC__ */ typedef cell *CELLPTR; typedef SCM *SCMPTR; # ifdef nosve # define PTR_MASK 0xffffffffffff # define PTR_LT(x, y) (((int)(x)&PTR_MASK) < ((int)(y)&PTR_MASK)) # else # define PTR_LT(x, y) ((x) < (y)) # endif #endif #define PTR_GT(x, y) PTR_LT(y, x) #define PTR_LE(x, y) (!PTR_GT(x, y)) #define PTR_GE(x, y) (!PTR_LT(x, y)) #ifdef STDC_HEADERS # ifdef PLAN9 # define sizet long # else # include # ifdef AMIGA # include # endif # define sizet size_t # endif #else # ifdef _SIZE_T # define sizet size_t # else # define sizet unsigned int # endif #endif #ifdef __APPLE__ # include #endif #ifdef macintosh # include #endif #ifdef __FreeBSD__ # include #endif #ifdef linux # include #endif /* On VMS, GNU C's errno.h contains a special hack to get link attributes for errno correct for linking with libc. */ #ifndef PLAN9 # include #endif /* SYSCALL retries system calls that have been interrupted (EINTR) */ #ifdef vms # ifndef __GNUC__ # include # define SCM_INTERRUPTED(errno) (EVMSERR==errno && \ (vaxc$errno>>3)==(SS$_CONTROLC>>3)) # endif #endif #ifndef SCM_INTERRUPTED # ifdef EINTR # if (EINTR > 0) # define SCM_INTERRUPTED(errno) (EINTR==errno) # endif # endif #endif #ifndef SCM_INTERRUPTED # define SCM_INTERRUPTED(errno) (0) #endif #ifdef _WIN32 // Windows doesn't set errno = EINTR # define SYSCALL(line) do{line;while(GetLastError() == ERROR_OPERATION_ABORTED){SetLastError(0);Sleep(10);line};}while(0) #else # define SYSCALL(line) do{errno = 0;line}while(SCM_INTERRUPTED(errno)) #endif #ifdef EMFILE # ifdef ENFILE # define SCM_NEED_FDS(errno) (EMFILE==errno || ENFILE==errno) # else # define SCM_NEED_FDS(errno) (EMFILE==errno) # endif #else # define SCM_NEED_FDS(errno) (0) #endif #define SCM_OPENCALL(line) {int gcs = 0;\ while (!0) {errno = 0; if ((line)) break;\ if (0==gcs++ && SCM_NEED_FDS(errno)) \ gc_for_open_files();\ else if (!SCM_INTERRUPTED(errno)) break;}} #ifndef MSDOS # ifdef ARM_ULIB extern volatile int errno; # else extern int errno; # endif #endif #ifdef __TURBOC__ # if (__TURBOC__==1) /* Needed for TURBOC V1.0 */ extern int errno; # endif #endif /* EXIT_SUCCESS is the default code to return from SCM if no errors were encountered. EXIT_FAILURE is the default code to return from SCM if errors were encountered. The return code can be explicitly specified in a SCM program with (quit ). */ #ifndef EXIT_SUCCESS # ifdef vms # define EXIT_SUCCESS 1 # else # define EXIT_SUCCESS 0 # endif #endif #ifndef EXIT_FAILURE # ifdef vms # define EXIT_FAILURE 2 # else # define EXIT_FAILURE 1 # endif #endif /* Yasuaki Honda, Bob Schumaker */ /* Think C and Metrowerks lack isascii macro */ #ifdef macintosh # define isascii(c) ((unsigned)(c) <= 0x7f) #endif #ifdef _DCC # define isascii(c) ((unsigned)(c) <= 0x7f) #endif #ifdef __STDC__ # define VOLATILE volatile #else # define VOLATILE /**/ #endif #ifdef _MSC_VER // Disable annoying warnings for: # pragma warning (disable: 4102) // unreferenced label # pragma warning (disable: 4018) // signed/unsigned mismatch # pragma warning (disable: 4101) // unreferenced variables # pragma warning (disable: 4244) // conversion from unsigned long to unsigned short #endif /* end of automatic C pre-processor definitions */ scm-5f4/unexhp9k800.c0000755000175000017500000002266706467700740011356 00000000000000/* Unexec for HP 9000 Series 800 machines. Bob Desinger Note that the GNU project considers support for HP operation a peripheral activity which should not be allowed to divert effort from development of the GNU system. Changes in this code will be installed when users send them in, but aside from that we don't plan to think about it, or about whether other Emacs maintenance might break it. Unexec creates a copy of the old a.out file, and replaces the old data area with the current data area. When the new file is executed, the process will see the same data structures and data values that the original process had when unexec was called. Unlike other versions of unexec, this one copies symbol table and debug information to the new a.out file. Thus, the new a.out file may be debugged with symbolic debuggers. If you fix any bugs in this, I'd like to incorporate your fixes. Send them to uunet!hpda!hpsemc!jmorris or jmorris%hpsemc@hplabs.HP.COM. CAVEATS: This routine saves the current value of all static and external variables. This means that any data structure that needs to be initialized must be explicitly reset. Variables will not have their expected default values. Unfortunately, the HP-UX signal handler has internal initialization flags which are not explicitly reset. Thus, for signals to work in conjunction with this routine, the following code must executed when the new process starts up. void _sigreturn (); ... sigsetreturn (_sigreturn); */ #include #include #include #include #ifdef emacs #include #endif #ifdef HPUX_USE_SHLIBS #include #endif /* brk value to restore, stored as a global. This is really used only if we used shared libraries. */ static long brk_on_dump = 0; /* Called from main, if we use shared libraries. */ int run_time_remap (ignored) char *ignored; { brk ((char *) brk_on_dump); } #undef roundup #define roundup(x,n) (((x) + ((n) - 1)) & ~((n) - 1)) /* n is power of 2 */ #define min(x,y) (((x) < (y)) ? (x) : (y)) /* Create a new a.out file, same as old but with current data space */ unexec (new_name, old_name, new_end_of_text, dummy1, dummy2) char new_name[]; /* name of the new a.out file to be created */ char old_name[]; /* name of the old a.out file */ char *new_end_of_text; /* ptr to new edata/etext; NOT USED YET */ int dummy1, dummy2; /* not used by emacs */ { int old, new; int old_size, new_size; struct header hdr; struct som_exec_auxhdr auxhdr; long i; /* For the greatest flexibility, should create a temporary file in the same directory as the new file. When everything is complete, rename the temp file to the new name. This way, a program could update its own a.out file even while it is still executing. If problems occur, everything is still intact. NOT implemented. */ /* Open the input and output a.out files */ old = open (old_name, O_RDONLY); if (old < 0) { perror (old_name); exit (1); } new = open (new_name, O_CREAT|O_RDWR|O_TRUNC, 0777); if (new < 0) { perror (new_name); exit (1); } /* Read the old headers */ read_header (old, &hdr, &auxhdr); brk_on_dump = (long) sbrk (0); /* Decide how large the new and old data areas are */ old_size = auxhdr.exec_dsize; /* I suspect these two statements are separate to avoid a compiler bug in hpux version 8. */ i = (long) sbrk (0); new_size = i - auxhdr.exec_dmem; /* Copy the old file to the new, up to the data space */ lseek (old, 0, 0); copy_file (old, new, auxhdr.exec_dfile); /* Skip the old data segment and write a new one */ lseek (old, old_size, 1); save_data_space (new, &hdr, &auxhdr, new_size); /* Copy the rest of the file */ copy_rest (old, new); /* Update file pointers since we probably changed size of data area */ update_file_ptrs (new, &hdr, &auxhdr, auxhdr.exec_dfile, new_size-old_size); /* Save the modified header */ write_header (new, &hdr, &auxhdr); /* Close the binary file */ close (old); close (new); return 0; } /* Save current data space in the file, update header. */ save_data_space (file, hdr, auxhdr, size) int file; struct header *hdr; struct som_exec_auxhdr *auxhdr; int size; { /* Write the entire data space out to the file */ if (write (file, auxhdr->exec_dmem, size) != size) { perror ("Can't save new data space"); exit (1); } /* Update the header to reflect the new data size */ auxhdr->exec_dsize = size; auxhdr->exec_bsize = 0; } /* Update the values of file pointers when something is inserted. */ update_file_ptrs (file, hdr, auxhdr, location, offset) int file; struct header *hdr; struct som_exec_auxhdr *auxhdr; unsigned int location; int offset; { struct subspace_dictionary_record subspace; int i; /* Increase the overall size of the module */ hdr->som_length += offset; /* Update the various file pointers in the header */ #define update(ptr) if (ptr > location) ptr = ptr + offset update (hdr->aux_header_location); update (hdr->space_strings_location); update (hdr->init_array_location); update (hdr->compiler_location); update (hdr->symbol_location); update (hdr->fixup_request_location); update (hdr->symbol_strings_location); update (hdr->unloadable_sp_location); update (auxhdr->exec_tfile); update (auxhdr->exec_dfile); /* Do for each subspace dictionary entry */ lseek (file, hdr->subspace_location, 0); for (i = 0; i < hdr->subspace_total; i++) { if (read (file, &subspace, sizeof (subspace)) != sizeof (subspace)) { perror ("Can't read subspace record"); exit (1); } /* If subspace has a file location, update it */ if (subspace.initialization_length > 0 && subspace.file_loc_init_value > location) { subspace.file_loc_init_value += offset; lseek (file, -sizeof (subspace), 1); if (write (file, &subspace, sizeof (subspace)) != sizeof (subspace)) { perror ("Can't update subspace record"); exit (1); } } } /* Do for each initialization pointer record */ /* (I don't think it applies to executable files, only relocatables) */ #undef update } /* Read in the header records from an a.out file. */ read_header (file, hdr, auxhdr) int file; struct header *hdr; struct som_exec_auxhdr *auxhdr; { /* Read the header in */ lseek (file, 0, 0); if (read (file, hdr, sizeof (*hdr)) != sizeof (*hdr)) { perror ("Couldn't read header from a.out file"); exit (1); } if (hdr->a_magic != EXEC_MAGIC && hdr->a_magic != SHARE_MAGIC && hdr->a_magic != DEMAND_MAGIC) { fprintf (stderr, "a.out file doesn't have legal magic number\n"); exit (1); } lseek (file, hdr->aux_header_location, 0); if (read (file, auxhdr, sizeof (*auxhdr)) != sizeof (*auxhdr)) { perror ("Couldn't read auxiliary header from a.out file"); exit (1); } } /* Write out the header records into an a.out file. */ write_header (file, hdr, auxhdr) int file; struct header *hdr; struct som_exec_auxhdr *auxhdr; { /* Update the checksum */ hdr->checksum = calculate_checksum (hdr); /* Write the header back into the a.out file */ lseek (file, 0, 0); if (write (file, hdr, sizeof (*hdr)) != sizeof (*hdr)) { perror ("Couldn't write header to a.out file"); exit (1); } lseek (file, hdr->aux_header_location, 0); if (write (file, auxhdr, sizeof (*auxhdr)) != sizeof (*auxhdr)) { perror ("Couldn't write auxiliary header to a.out file"); exit (1); } } /* Calculate the checksum of a SOM header record. */ calculate_checksum (hdr) struct header *hdr; { int checksum, i, *ptr; checksum = 0; ptr = (int *) hdr; for (i = 0; i < sizeof (*hdr) / sizeof (int) - 1; i++) checksum ^= ptr[i]; return (checksum); } /* Copy size bytes from the old file to the new one. */ copy_file (old, new, size) int new, old; int size; { int len; int buffer[8192]; /* word aligned will be faster */ for (; size > 0; size -= len) { len = min (size, sizeof (buffer)); if (read (old, buffer, len) != len) { perror ("Read failure on a.out file"); exit (1); } if (write (new, buffer, len) != len) { perror ("Write failure in a.out file"); exit (1); } } } /* Copy the rest of the file, up to EOF. */ copy_rest (old, new) int new, old; { int buffer[4096]; int len; /* Copy bytes until end of file or error */ while ((len = read (old, buffer, sizeof (buffer))) > 0) if (write (new, buffer, len) != len) break; if (len != 0) { perror ("Unable to copy the rest of the file"); exit (1); } } #ifdef DEBUG display_header (hdr, auxhdr) struct header *hdr; struct som_exec_auxhdr *auxhdr; { /* Display the header information (debug) */ printf ("\n\nFILE HEADER\n"); printf ("magic number %d \n", hdr->a_magic); printf ("text loc %.8x size %d \n", auxhdr->exec_tmem, auxhdr->exec_tsize); printf ("data loc %.8x size %d \n", auxhdr->exec_dmem, auxhdr->exec_dsize); printf ("entry %x \n", auxhdr->exec_entry); printf ("Bss segment size %u\n", auxhdr->exec_bsize); printf ("\n"); printf ("data file loc %d size %d\n", auxhdr->exec_dfile, auxhdr->exec_dsize); printf ("som_length %d\n", hdr->som_length); printf ("unloadable sploc %d size %d\n", hdr->unloadable_sp_location, hdr->unloadable_sp_size); } #endif /* DEBUG */ scm-5f4/indexes.texi0000755000175000017500000000206610601246054011514 00000000000000 @ifhtml @node Index, Procedure and Macro Index, The Implementation, Top @unnumbered Index @end ifhtml @ifnotinfo @menu * Procedure and Macro Index:: * Variable Index:: * Type Index:: * Concept Index:: @end menu @end ifnotinfo @ifnotinfo @node Procedure and Macro Index, Variable Index, Index, Index @end ifnotinfo @unnumbered Procedure and Macro Index @c This is an alphabetical list of all the procedures and macros in SCM. @printindex fn @ifnotinfo @node Variable Index, Type Index, Procedure and Macro Index, Index @end ifnotinfo @unnumbered Variable Index @c This is an alphabetical list of all the global variables in SCM. @printindex vr @ifnotinfo @node Type Index, Concept Index, Variable Index, Index @end ifnotinfo @unnumbered Type Index @c This is an alphabetical list of data types and feature names in SCM. @printindex tp @ifnotinfo @node Concept Index, , Type Index, Index @end ifnotinfo @unnumbered Concept Index @c This is an alphabetical list of concepts introduced in this manual. @printindex cp scm-5f4/scm.10000755000175000017500000002105211650443477010037 00000000000000.\" dummy line .TH SCM 1 "February 2008" .UC 4 .SH NAME scm \- a Scheme Language Interpreter .SH SYNOPSIS .B scm [-a .I kbytes ] [-muvqib] [--version] [--help] .br [[-]-no-init-file] [--no-symbol-case-fold] .br [-p .I int ] [-r .I feature ] [-h .I feature ] .br [-d .I filename ] [-f .I filename ] [-l .I filename ] .br [-c .I expression ] [-e .I expression ] [-o .I dumpname ] .br [-- | - | -s] [ .I filename ] [ .I arguments ... ] .br .sp 0.3 .SH DESCRIPTION .I Scm is a Scheme interpreter. .PP Upon startup .I scm loads the file specified by by the environment variable SCM_INIT_PATH or by the parameter IMPLINIT in the makefile (or scmfig.h) if SCM_INIT_PATH is not defined. The makefiles attempt to set IMPLINIT to "Init.scm" in the source directory. Unless the option .I -no-init-file or .I --no-init-file occurs in the command line or if .I scm is being invoked as a script, "Init.scm" checks to see if there is file "ScmInit.scm" in the path specified by the environment variable HOME (or in the current directory if HOME is undefined). If it finds such a file, then it is loaded. "Init.scm" then looks for command input from one of three sources: From an option on the command line, from a file named on the command line, or from standard input. .SH OPTIONS The options are processed in the order specified on the command line. .TP 5 .BI -a kbytes specifies that .I scm should allocate an initial heapsize of .I kbytes. This option, if present, must be the first on the command line. .TP .BI --no-init-file Inhibits the loading of "ScmInit.scm" as described above. .TP .BI --no-symbol-case-fold Symbol (and identifier) names are case-sensitive. .TP .BI -e expression .TP .BI -c expression specifies that the scheme expression .I expression is to be evaluated. These options are inspired by .I perl and .I sh respectively. On Amiga systems the entire option and argument need to be enclosed in quotes. For instance "-e(newline)". .TP .BI -r feature requires .I feature. This will load a file from SLIB if that .I feature is not already supported. If .I feature is 2, 3, 4, or 5 .I scm will require the features necessary to support R2RS, R3RS, R4RS, or R5RS, respectively. .TP .BI -h feature provides .I feature. .TP .BI -l filename .TP .BI -f filename loads .I filename. .I Scm will load the first (unoptioned) file named on the command line if no -c, -e, -f, -l, or -s option precedes it. .TP .BI -d filename opens (read-only) the extended relational database .I filename. If .I filename contains initialization code, it will be run when the database is opened. .TP .BI -o dumpname saves the current SCM session as the executable program .I dumpname. This option works only in SCM builds supporting .BI dump. If options appear on the command line after .I -o dumpname, then the saved session will continue with processing those options when it is invoked. Otherwise the (new) command line is processed as usual when the saved image is invoked. .TP .BI -p level sets the prolixity (verboseness) to .I level. This is the same as the .I scm command (verbose .I level ). .TP .B -v (verbose mode) specifies that .I scm will print prompts, evaluation times, notice of loading files, and garbage collection statistics. This is the same as .I -p3. .TP .B -q (quiet mode) specifies that .I scm will print no extra information. This is the same as .I -p0. .TP .B -m specifies that subsequent loads, evaluations, and user interactions will be with R4RS macro capability. To use a specific R4RS macro implementation from SLIB (instead of SLIB's default) put .I -r macropackage before .I -m on the command line. .TP .B -u specifies that subsequent loads, evaluations, and user interactions will be without R4RS macro capability. R4RS macro capability can be restored by a subsequent .I -m on the command line or from Scheme code. .TP .B -i specifies that .I scm should run interactively. That means that .I scm will not terminate until the .I (quit) or .I (exit) command is given, even if there are errors. It also sets the prolixity level to 2 if it is less than 2. This will print prompts, evaluation times, and notice of loading files. The prolixity level can be set by subsequent options. If .I scm is started from a tty, it will assume that it should be interactive unless given a subsequent .I -b option. .TP .B -b specifies that .I scm should run non-interactively. That means that .I scm will terminate after processing the command line or if there are errors. .TP .B -s specifies, by analogy with .I sh, that further options are to be treated as program arguments. .TP .BI - .BI -- specifies that there are no more options on the command line. .SH ENVIRONMENT VARIABLES .TP 5 .B SCM_INIT_PATH is the pathname where .I scm will look for its initialization code. The default is the file "Init.scm" in the source directory. .TP .B SCHEME_LIBRARY_PATH is the SLIB Scheme library directory. .TP .B HOME is the directory where "Init.scm" will look for the user initialization file "ScmInit.scm". .SH SCHEME VARIABLES .TP 5 .B *argv* contains the list of arguments to the program. .I *argv* can change during argument processing. This list is suitable for use as an argument to SLIB .I getopt. .TP .B *R4RS-macro* controls whether loading and interaction support R4RS macros. Define this in "ScmInit.scm" or files specified on the command line. This can be overridden by subsequent -m and -u options. .TP .B *interactive* controls interactivity as explained for the -i and -b options. Define this in "ScmInit.scm" or files specified on the command line. This can be overridden by subsequent -i and -b options. .SH EXAMPLES .ne 5 .TP 5 % scm foo.scm arg1 arg2 arg3 .br Load and execute the contents of foo.scm. Parameters arg1 arg2 and arg3 are stored in the global list *argv*. .TP % scm -f foo.scm arg1 arg2 arg3 .br The same. .TP % scm -s foo.scm arg1 arg2 .br Set *argv* to ("foo.scm" "arg1" "arg2") and enter interactive session. .TP % scm -e '(display (list-ref *argv* *optind*))' bar .br Print ``bar'' .TP % scm -rpretty-print -r format -i .br Load pretty-print and format and enter interactive mode. .TP % scm -r5 .br Load dynamic-wind, values, and R4RS macros and enter interactive (with macros) mode. .TP % scm -r5 -r4 .br Like above but rev4-optional-procedures are also loaded. .SH FEATURES .PP Runs under Amiga, Atari-ST, MacOS, MS-DOS, OS/2, NOS/VE, Unicos, VMS, Unix and similar systems. Support for ASCII and EBCDIC character sets. .PP Conforms to Revised^5 Report on the Algorithmic Language Scheme and the IEEE P1178 specification. .PP Support for SICP, R2RS, R3RS, and R4RS scheme code. .PP Many Common Lisp functions: logand, logor, logxor, lognot, ash, logcount, integer-length, bit-extract, defmacro, macroexpand, macroexpand1, gentemp, defvar, force-output, software-type, get-decoded-time, get-internal-run-time, get-internal-real-time, delete-file, rename-file, copy-tree, acons, and eval. .PP Char-code-limit, most-positive-fixnum, most-negative-fixnum, and internal-time-units-per-second constants. *Features* and *load-pathname* variables. .PP Arrays and bit-vectors. String ports and software emulation ports. I/O extensions providing most of ANSI C and POSIX.1 facilities. .PP User definable responses to interrupts and errors, Process-synchronization primitives, String regular expression matching, and the CURSES screen management package. .PP Available add-on packages including an interactive debugger, database, X-window graphics, BGI graphics, Motif, and Open-Windows packages. .PP A compiler (HOBBIT, available separately) and dynamic linking of compiled modules. .PP Setable levels of monitoring and timing information printed interactively (the `verbose' function). Restart, quit, and exec. .SH FILES .TP scm.texi .br Texinfo documentation of .I scm enhancements, internal representations, and how to extend or include .I scm in other programs. .SH AUTHORS Aubrey Jaffer (agj@alum.mit.edu) .br Radey Shouman .SH BUGS .SH SEE ALSO The SCM home-page: .br http://people.csail.mit.edu/jaffer/SCM.html .PP The Scheme specifications for details on specific procedures (http://groups.csail.mit.edu/mac/ftpdir/scheme-reports) or .PP IEEE Std 1178-1990, .br IEEE Standard for the Scheme Programming Language, .br Institute of Electrical and Electronic Engineers, Inc., .br New York, NY, 1991 .PP Brian Harvey and Matthew Wright .br Simply Scheme: Introducing Computer Science_ .br MIT Press, 1994 ISBN 0-262-08226-8 .PP R. Kent Dybvig, The Scheme Programming Language, .br Prentice-Hall Inc, Englewood Cliffs, New Jersey 07632, USA .PP H. Abelson, G. J. Sussman, and J. Sussman, .br Structure and Interpretation of Computer Programs, .br The MIT Press, Cambridge, Massachusetts, USA scm-5f4/pi.c0000755000175000017500000000320710750240510007730 00000000000000/* "pi.c", program for computing digits of numerical value of PI. * Copyright (C) 1991 1995 Free Software Foundation, Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program. If not, see * . */ /* Author: Aubrey Jaffer pi prints out digits of pi in groups of digits. 'Spigot' algorithm origionally due to Stanly Rabinowitz. This algorithm takes time proportional to the square of /. This fact can make comparisons of computational speed between systems of vastly differring performances quicker and more accurate. Try: pi 100 5 The digit size will have to be reduced for larger or an error due to overflow will occur. */ short *calloc(); main(c,v) int c;char **v;{ int n=200,j=0,m,b=2,k=0,t,r=1,d=5; long q; short *a; if(c>1)n=atoi(v[1]); if(c>2)d=atoi(v[2]); while(k++&2 { (exit 1); exit 1; }; } ;; esac shift done # Now take action based on given options. if test "$ac_init_help" = "long"; then cat <<_ACEOF \`configure' configures $PACKAGE_STRING installation. Usage: ./configure [OPTION]... Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit -V, --version display version information and exit -q, --quiet, --silent do not print configuration -n, --no-create do not create output file --srcdir=DIR find the sources in DIR [configure dir or \`..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [$ac_default_prefix] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, \`make install' will install all the files in \`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify an installation prefix other than \`$ac_default_prefix' using \`--prefix', for instance \`--prefix=\$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/$PACKAGE_TARNAME] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] --snapdir=DIR development snapshot destination [configure dir] --distdir=DIR release distribution destination [configure dir] _ACEOF exit fi if $ac_init_version; then echo "$PACKAGE_NAME configure $PACKAGE_VERSION" exit fi # Check all directory arguments for consistency. for ac_var in srcdir exec_prefix prefix bindir sbindir libexecdir \ datarootdir datadir sysconfdir sharedstatedir localstatedir \ includedir oldincludedir docdir infodir htmldir dvidir pdfdir \ psdir libdir localedir mandir snapdir distdir do eval ac_val=\$$ac_var # Assure trailing slashes. case $ac_val in *[}/] ) ;; * ) ac_val="$ac_val""/" eval $ac_var=\$ac_val;; esac # Be sure to have absolute directory names. case $ac_val in [\\/$]* | ?:[\\/]* ) continue;; * ) case $ac_var in *prefix | *srcdir | *snapdir | *distdir) continue;; esac;; esac { echo "error: expected an absolute directory name for --$ac_var: $ac_val" >&2 { (exit 1); exit 1; }; } done if test "$no_create" != yes; then echo "#! /bin/cat # Generated by configure for $PACKAGE_NAME $PACKAGE_VERSION. # This file ($CONFIG_STATUS) is included by the ($PACKAGE_TARNAME) Makefile. " > $CONFIG_STATUS for ac_var in $ac_subst_vars do eval ac_val=\$$ac_var echo "$ac_var=$ac_val" >> $CONFIG_STATUS done chmod +x $CONFIG_STATUS if test "$silent" != yes; then cat $CONFIG_STATUS; fi else if test "$silent" != yes; then echo "This is the $CONFIG_STATUS file which would have been created: # Generated by configure for $PACKAGE_NAME $PACKAGE_VERSION. # This file is included by the Makefile. " for ac_var in $ac_subst_vars do eval ac_val=\$$ac_var echo "$ac_var=$ac_val" done fi fi scm-5f4/ramap.c0000644000175000017500000014300714455110774010436 00000000000000/* "ramap.c" Array mapping functions for APL-Scheme. * Copyright (C) 1994, 1995, 2006 Free Software Foundation, Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see * . */ /* Author: Radey Shouman */ #include "scm.h" SCM sc2array P((SCM s, SCM ra, SCM prot)); typedef struct { char *name; SCM sproc; int (* vproc)(); } ra_iproc; # define BVE_REF(a, i) ((VELTS(a)[(i)/LONG_BIT] & (1L<<((i)%LONG_BIT))) ? 1 : 0) # define BVE_SET(a, i) (VELTS(a)[(i)/LONG_BIT] |= (1L<<((i)%LONG_BIT))) # define BVE_CLR(a, i) (VELTS(a)[(i)/LONG_BIT] &= ~(1L<<((i)%LONG_BIT))) /* Fast, recycling vector ref */ # define RVREF(ra, i, e) (e = cvref(ra, i, e)) /* #define RVREF(ra, i, e) (cvref(ra, i, UNDEFINED)) to turn off */ /* IVDEP means "ignore vector dependencies", meaning we guarantee that elements of vector operands are not aliased */ # ifdef _UNICOS # define IVDEP(test, line) if (test) {_Pragma("ivdep"); line} else {line} # else # define IVDEP(test, line) line # endif static sizet cind(ra, inds) SCM ra; long *inds; { sizet i; int k; if (!ARRAYP(ra)) return *inds; i = ARRAY_BASE(ra); for (k = 0; k < ARRAY_NDIM(ra); k++) i += (inds[k] - ARRAY_DIMS(ra)[k].lbnd)*ARRAY_DIMS(ra)[k].inc; return i; } /* Checker for array mapping functions: return values: 4 --> shapes, increments, and bases are the same; 3 --> shapes and increments are the same; 2 --> shapes are the same; 1 --> ras are at least as big as ra0; 0 --> no match. */ int ra_matchp(ra0, ras) SCM ra0, ras; { SCM ra1; array_dim dims; array_dim *s0 = &dims; array_dim *s1; sizet bas0 = 0; int i, ndim = 1; int exact = 2 /* 4 */; /* Don't care about values >2 (yet?) */ if (IMP(ra0)) return 0; switch TYP7(ra0) { default: return 0; case tc7_vector: case tcs_uves: s0->lbnd = 0; s0->inc = 1; s0->ubnd = (long)LENGTH(ra0) - 1; break; case tc7_smob: if (!ARRAYP(ra0)) return 0; ndim = ARRAY_NDIM(ra0); s0 = ARRAY_DIMS(ra0); bas0 = ARRAY_BASE(ra0); break; } while NIMP(ras) { ra1 = CAR(ras); switch (IMP(ra1) ? 0 : TYP7(ra1)) { default: scalar: CAR(ras) = sc2array(ra1, ra0, EOL); break; case tc7_vector: case tcs_uves: if (1 != ndim) return 0; switch (exact) { case 4: if (0 != bas0) exact = 3; case 3: if (1 != s0->inc) exact = 2; case 2: if ((0==s0->lbnd) && (s0->ubnd==LENGTH(ra1) - 1)) break; exact = 1; case 1: if (s0->lbnd < 0 || s0->ubnd >= LENGTH(ra1)) if (s0->lbnd <= s0->ubnd) return 0; } break; case tc7_smob: if (!ARRAYP(ra1)) goto scalar; if (ndim != ARRAY_NDIM(ra1)) { if (0==ARRAY_NDIM(ra1)) goto scalar; else return 0; } s1 = ARRAY_DIMS(ra1); if (bas0 != ARRAY_BASE(ra1)) exact = 3; for (i = 0; i < ndim; i++) switch (exact) { case 4: case 3: if (s0[i].inc != s1[i].inc) exact = 2; case 2: if (s0[i].lbnd==s1[i].lbnd && s0[i].ubnd==s1[i].ubnd) break; exact = 1; default: if (s0[i].lbnd < s1[i].lbnd || s0[i].ubnd > s1[i].ubnd) if (s0[i].lbnd <= s0[i].ubnd) return 0; } break; } ras = CDR(ras); } return exact; } static char s_ra_mismatch[] = "array shape mismatch"; int ramapc(cproc, data, ra0, lra, what) int (*cproc)(); SCM data, ra0, lra; const char *what; { SCM z, vra0, ra1, vra1; SCM lvra, *plvra; int k, kmax = (ARRAYP(ra0) ? ARRAY_NDIM(ra0) - 1 : 0); volatile SCM gcpr[1]; switch (ra_matchp(ra0, lra)) { default: case 0: wta(ra0, s_ra_mismatch, what); case 2: case 3: case 4: /* Try unrolling arrays */ if (kmax < 0) goto gencase; vra0 = (0==kmax ? ra0 : array_contents(ra0, UNDEFINED)); if (IMP(vra0)) goto gencase; if (!ARRAYP(vra0)) { vra1 = make_ra(1); ARRAY_BASE(vra1) = 0; ARRAY_DIMS(vra1)->lbnd = 0; ARRAY_DIMS(vra1)->ubnd = LENGTH(vra0) - 1; ARRAY_DIMS(vra1)->inc = 1; ARRAY_V(vra1) = vra0; vra0 = vra1; } lvra = EOL; plvra = &lvra; for (z = lra; NIMP(z); z = CDR(z)) { vra1 = ra1 = (0==kmax ? CAR(z) : array_contents(CAR(z), UNDEFINED)); if (FALSEP(ra1)) goto gencase; if (!ARRAYP(ra1)) { vra1 = make_ra(1); ARRAY_DIMS(vra1)->lbnd = ARRAY_DIMS(vra0)->lbnd; ARRAY_DIMS(vra1)->ubnd = ARRAY_DIMS(vra0)->ubnd; ARRAY_BASE(vra1) = 0; ARRAY_DIMS(vra1)->inc = 1; ARRAY_V(vra1) = ra1; } *plvra = cons(vra1, EOL); plvra = &CDR(*plvra); } return (UNBNDP(data) ? cproc(vra0, lvra) : cproc(vra0, data, lvra)); case 1: gencase: /* Have to loop over all dimensions. */ { SCM hp_indv; long auto_indv[5]; long *indv = &auto_indv[0]; if (ARRAY_NDIM(ra0) >= 5) { hp_indv = gcpr[0] = make_uve(ARRAY_NDIM(ra0)+0L, MAKINUM(-32L)); indv = (long *)VELTS(hp_indv); } vra0 = make_ra(1); if (ARRAYP(ra0)) { if (kmax < 0) { ARRAY_DIMS(vra0)->lbnd = 0; ARRAY_DIMS(vra0)->ubnd = 0; ARRAY_DIMS(vra0)->inc = 1; } else { ARRAY_DIMS(vra0)->lbnd = ARRAY_DIMS(ra0)[kmax].lbnd; ARRAY_DIMS(vra0)->ubnd = ARRAY_DIMS(ra0)[kmax].ubnd; ARRAY_DIMS(vra0)->inc = ARRAY_DIMS(ra0)[kmax].inc; } ARRAY_BASE(vra0) = ARRAY_BASE(ra0); ARRAY_V(vra0) = ARRAY_V(ra0); } else { ARRAY_DIMS(vra0)->lbnd = 0; ARRAY_DIMS(vra0)->ubnd = LENGTH(ra0) - 1; ARRAY_DIMS(vra0)->inc = 1; ARRAY_BASE(vra0) = 0; ARRAY_V(vra0) = ra0; ra0 = vra0; } lvra = EOL; plvra = &lvra; for (z = lra; NIMP(z); z = CDR(z)) { ra1 = CAR(z); vra1 = make_ra(1); ARRAY_DIMS(vra1)->lbnd = ARRAY_DIMS(vra0)->lbnd; ARRAY_DIMS(vra1)->ubnd = ARRAY_DIMS(vra0)->ubnd; if (ARRAYP(ra1)) { if (kmax >= 0) ARRAY_DIMS(vra1)->inc = ARRAY_DIMS(ra1)[kmax].inc; ARRAY_V(vra1) = ARRAY_V(ra1); } else { ARRAY_DIMS(vra1)->inc = 1; ARRAY_V(vra1) = ra1; } *plvra = cons(vra1, EOL); plvra = &CDR(*plvra); } for (k = 0; k <= kmax; k++) indv[k] = ARRAY_DIMS(ra0)[k].lbnd; k = kmax; do { if (k==kmax) { SCM y = lra; ARRAY_BASE(vra0) = cind(ra0, indv); for (z = lvra; NIMP(z); z = CDR(z), y = CDR(y)) ARRAY_BASE(CAR(z)) = cind(CAR(y), indv); if (0==(UNBNDP(data) ? cproc(vra0, lvra) : cproc(vra0, data, lvra))) return 0; k--; continue; } if (indv[k] < ARRAY_DIMS(ra0)[k].ubnd) { indv[k]++; k++; continue; } indv[k] = ARRAY_DIMS(ra0)[k].lbnd - 1; k--; } while (k >= 0); return 1; } } } SCM array_fill(ra, fill) SCM ra, fill; { ramapc(rafill, fill, ra, EOL, s_array_fill); return UNSPECIFIED; } static char s_sarray_copy[] = "serial-array:copy!"; static char s_array_copy[] = "array:copy!"; static int racp(src, dst) SCM dst, src; { long n = (ARRAY_DIMS(src)->ubnd - ARRAY_DIMS(src)->lbnd + 1); long inc_d, inc_s = ARRAY_DIMS(src)->inc; sizet i_d, i_s = ARRAY_BASE(src); dst = CAR(dst); inc_d = ARRAY_DIMS(dst)->inc; i_d = ARRAY_BASE(dst); src = ARRAY_V(src); dst = ARRAY_V(dst); switch TYP7(dst) { default: gencase: case tc7_vector: for (; n-- > 0; i_s += inc_s, i_d += inc_d) aset(dst, cvref(src, i_s, UNDEFINED), MAKINUM(i_d)); break; case tc7_string: if (tc7_string != TYP7(src)) goto gencase; for (; n-- > 0; i_s += inc_s, i_d += inc_d) CHARS(dst)[i_d] = CHARS(src)[i_s]; break; case tc7_Vbool: if (tc7_Vbool != TYP7(src)) goto gencase; if (1==inc_d && 1==inc_s && i_s%LONG_BIT==i_d%LONG_BIT && n>=LONG_BIT) { long *sv = (long *)VELTS(src); long *dv = (long *)VELTS(dst); sv += i_s/LONG_BIT; dv += i_d/LONG_BIT; if (i_s % LONG_BIT) { /* leading partial word */ *dv = (*dv & ~(~0L<<(i_s%LONG_BIT))) | (*sv & (~0L<<(i_s%LONG_BIT))); dv++; sv++; n -= LONG_BIT - (i_s % LONG_BIT); } IVDEP(src != dst, for (; n >= LONG_BIT; n -= LONG_BIT, sv++, dv++) *dv = *sv;) if (n) /* trailing partial word */ *dv = (*dv & (~0L< 0; i_s += inc_s, i_d += inc_d) if (VELTS(src)[i_s/LONG_BIT] & (1L << (i_s%LONG_BIT))) VELTS(dst)[i_d/LONG_BIT] |= (1L << (i_d%LONG_BIT)); else VELTS(dst)[i_d/LONG_BIT] &= ~(1L << (i_d%LONG_BIT)); } break; case tc7_VfixN32: case tc7_VfixZ32: { long *d = (long *)VELTS(dst), *s = (long *)VELTS(src); if (TYP7(src)==TYP7(dst)) { IVDEP(src != dst, for (; n-- > 0; i_s += inc_s, i_d += inc_d) d[i_d] = s[i_s];) } else if (tc7_VfixZ32==TYP7(dst)) for (; n-- > 0; i_s += inc_s, i_d += inc_d) d[i_d] = num2long(cvref(src, i_s, UNDEFINED), (char *)ARG2, s_array_copy); else for (; n-- > 0; i_s += inc_s, i_d += inc_d) d[i_d] = num2ulong(cvref(src, i_s, UNDEFINED), (char *)ARG2, s_array_copy); break; } # ifdef FLOATS case tc7_VfloR32: { float *d = (float *)VELTS(dst); float *s = (float *)VELTS(src); switch TYP7(src) { default: goto gencase; case tc7_VfixZ32: case tc7_VfixN32: IVDEP(src != dst, for (; n-- > 0; i_s += inc_s, i_d += inc_d) d[i_d] = ((long *)s)[i_s]; ) break; case tc7_VfloR32: IVDEP(src != dst, for (; n-- > 0; i_s += inc_s, i_d += inc_d) d[i_d] = s[i_s]; ) break; case tc7_VfloR64: IVDEP(src != dst, for (; n-- > 0; i_s += inc_s, i_d += inc_d) d[i_d] = ((double *)s)[i_s]; ) break; } break; } case tc7_VfloR64: { double *d = (double *)VELTS(dst); double *s = (double *)VELTS(src); switch TYP7(src) { default: goto gencase; case tc7_VfixZ32: case tc7_VfixN32: IVDEP(src != dst, for (; n-- > 0; i_s += inc_s, i_d += inc_d) d[i_d] = ((long *)s)[i_s]; ) break; case tc7_VfloR32: IVDEP(src != dst, for (; n-- > 0; i_s += inc_s, i_d += inc_d) d[i_d] = ((float *)s)[i_s];) break; case tc7_VfloR64: IVDEP(src != dst, for (; n-- > 0; i_s += inc_s, i_d += inc_d) d[i_d] = s[i_s];) break; } break; } case tc7_VfloC32: { float (*d)[2] = (float (*)[2])VELTS(dst); float (*s)[2] = (float (*)[2])VELTS(src); switch TYP7(src) { default: goto gencase; case tc7_VfixZ32: case tc7_VfixN32: IVDEP(src != dst, for (; n-- > 0; i_s += inc_s, i_d += inc_d) { d[i_d][0] = ((long *)s)[i_s]; d[i_d][1] = 0.0; }) break; case tc7_VfloR32: IVDEP(src != dst, for (; n-- > 0; i_s += inc_s, i_d += inc_d) { d[i_d][0] = ((float *)s)[i_s]; d[i_d][1] = 0.0; }) break; case tc7_VfloR64: IVDEP(src != dst, for (; n-- > 0; i_s += inc_s, i_d += inc_d) { d[i_d][0] = ((double *)s)[i_s]; d[i_d][1] = 0.0; }) break; case tc7_VfloC32: IVDEP(src != dst, for (; n-- > 0; i_s += inc_s, i_d += inc_d) { d[i_d][0] = s[i_s][0]; d[i_d][1] = s[i_s][1]; }) break; case tc7_VfloC64: IVDEP(src != dst, for (; n-- > 0; i_s += inc_s, i_d += inc_d) { d[i_d][0] = ((double (*)[2])s)[i_s][0]; d[i_d][1] = ((double (*)[2])s)[i_s][1]; }) break; } } case tc7_VfloC64: { double (*d)[2] = (double (*)[2])VELTS(dst); double (*s)[2] = (double (*)[2])VELTS(src); switch TYP7(src) { default: goto gencase; case tc7_VfixZ32: case tc7_VfixN32: IVDEP(src != dst, for (; n-- > 0; i_s += inc_s, i_d += inc_d) { d[i_d][0] = ((long *)s)[i_s]; d[i_d][1] = 0.0; }) break; case tc7_VfloR32: IVDEP(src != dst, for (; n-- > 0; i_s += inc_s, i_d += inc_d) { d[i_d][0] = ((float *)s)[i_s]; d[i_d][1] = 0.0; }) break; case tc7_VfloR64: IVDEP(src != dst, for (; n-- > 0; i_s += inc_s, i_d += inc_d) { d[i_d][0] = ((double *)s)[i_s]; d[i_d][1] = 0.0; }) break; case tc7_VfloC32: IVDEP(src != dst, for (; n-- > 0; i_s += inc_s, i_d += inc_d) { d[i_d][0] = ((float (*)[2])s)[i_s][0]; d[i_d][1] = ((float (*)[2])s)[i_s][1]; }) break; case tc7_VfloC64: IVDEP(src != dst, for (; n-- > 0; i_s += inc_s, i_d += inc_d) { d[i_d][0] = s[i_s][0]; d[i_d][1] = s[i_s][1]; }) break; } } # endif /* FLOATS */ } return 1; } SCM array_copy(dst, src) SCM dst; SCM src; { #ifndef RECKLESS if (INUM0==array_rank(dst)) ASRTER(NIMP(dst) && ARRAYP(dst) && INUM0==array_rank(src), dst, ARG2, s_array_copy); #endif ramapc(racp, UNDEFINED, src, cons(dst, EOL), s_array_copy); return UNSPECIFIED; } SCM ra2contig(ra, copy) SCM ra; int copy; { SCM ret; long inc = 1; sizet k, len = 1; for (k = ARRAY_NDIM(ra); k--;) len *= ARRAY_DIMS(ra)[k].ubnd - ARRAY_DIMS(ra)[k].lbnd + 1; k = ARRAY_NDIM(ra); if (ARRAY_CONTP(ra) && ((0==k) || (1==ARRAY_DIMS(ra)[k-1].inc))) { if (tc7_Vbool != TYP7(ARRAY_V(ra))) return ra; if ((len==LENGTH(ARRAY_V(ra)) && 0==ARRAY_BASE(ra) % LONG_BIT && 0==len % LONG_BIT)) return ra; } ret = make_ra(k); ARRAY_BASE(ret) = 0; while (k--) { ARRAY_DIMS(ret)[k].lbnd = ARRAY_DIMS(ra)[k].lbnd; ARRAY_DIMS(ret)[k].ubnd = ARRAY_DIMS(ra)[k].ubnd; ARRAY_DIMS(ret)[k].inc = inc; inc *= ARRAY_DIMS(ra)[k].ubnd - ARRAY_DIMS(ra)[k].lbnd + 1; } CAR(ret) |= ARRAY_CONTIGUOUS; ARRAY_V(ret) = make_uve(inc+0L, array_prot(ra)); if (copy) array_copy(ret, ra); return ret; } static char s_ura_rd[] = "uniform-array-read!"; SCM ura_read(ra, port) SCM ra, port; { SCM ret, cra; if (NIMP(ra) && ARRAYP(ra)) { cra = ra2contig(ra, 0); ret = uve_read(cra, port); if (cra != ra) array_copy(ra, cra); return ret; } else return uve_read(ra, port); } static char s_ura_wr[] = "uniform-array-write"; SCM ura_write(ra, port) SCM ra, port; { if (NIMP(ra) && ARRAYP(ra)) return uve_write(ra2contig(ra, 1), port); else return uve_write(ra, port); } static char s_sc2array[] = "scalar->array"; SCM sc2array(s, ra, prot) SCM s, ra, prot; { SCM res; ASRTER(NIMP(ra), ra, ARG2, s_sc2array); if (ARRAYP(ra)) { int k = ARRAY_NDIM(ra); res = make_ra(k); while (k--) { ARRAY_DIMS(res)[k].ubnd = ARRAY_DIMS(ra)[k].ubnd; ARRAY_DIMS(res)[k].lbnd = ARRAY_DIMS(ra)[k].lbnd; ARRAY_DIMS(res)[k].inc = 0; } ra = ARRAY_V(ra); } else { ASRTER(BOOL_T==arrayp(ra, UNDEFINED), ra, ARG2, s_sc2array); res = make_ra(1); ARRAY_DIMS(res)->ubnd = LENGTH(ra) - 1; ARRAY_DIMS(res)->lbnd = 0; ARRAY_DIMS(res)->inc = 0; } if (NIMP(s) && ARRAYP(s) && 0==ARRAY_NDIM(s)) { ARRAY_BASE(res) = ARRAY_BASE(s); ARRAY_V(res) = ARRAY_V(s); return res; } ARRAY_BASE(res) = 0; ARRAY_V(res) = make_uve(1L, NULLP(prot) ? array_prot(ra) : CAR(prot)); switch TYP7(ARRAY_V(res)) { case tc7_vector: break; case tc7_Vbool: if (BOOL_T==s || BOOL_F==s) break; goto mismatch; case tc7_string: if (ICHRP(s)) break; goto mismatch; case tc7_VfixN32: if (INUMP(s) && INUM(s)>=0) break; #ifdef BIGDIG if (NIMP(s) && tc16_bigpos==TYP16(s) && NUMDIGS(s)<=DIGSPERLONG) break; #endif goto mismatch; case tc7_VfixZ32: if (INUMP(s)) break; #ifdef BIGDIG if (NIMP(s) && BIGP(s) && NUMDIGS(s)<=DIGSPERLONG) break; #endif goto mismatch; #ifdef FLOATS case tc7_VfloR32: case tc7_VfloR64: if (NUMBERP(s) && !(NIMP(s) && CPLXP(s))) break; goto mismatch; case tc7_VfloC32: case tc7_VfloC64: if (NUMBERP(s)) break; goto mismatch; #endif mismatch: ARRAY_V(res) = make_vector(MAKINUM(1L), s); return res; } aset(ARRAY_V(res), s, INUM0); return res; } /* Functions callable by ARRAY-MAP! */ int ra_eqp(ra0, ras) SCM ra0, ras; { SCM ra1 = CAR(ras), ra2 = CAR(CDR(ras)); long n = ARRAY_DIMS(ra0)->ubnd - ARRAY_DIMS(ra0)->lbnd + 1; sizet i0 = ARRAY_BASE(ra0), i1 = ARRAY_BASE(ra1), i2 = ARRAY_BASE(ra2); long inc0 = ARRAY_DIMS(ra0)->inc; long inc1 = ARRAY_DIMS(ra1)->inc; long inc2 = ARRAY_DIMS(ra2)->inc; ra0 = ARRAY_V(ra0); ra1 = ARRAY_V(ra1); ra2 = ARRAY_V(ra2); switch (TYP7(ra1)==TYP7(ra2) ? TYP7(ra1) : 0) { default: { SCM e1 = UNDEFINED, e2 = UNDEFINED; for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2) if (BVE_REF(ra0, i0)) if (FALSEP(eqp(RVREF(ra1, i1, e1), RVREF(ra2, i2, e2)))) BVE_CLR(ra0, i0); break; } case tc7_VfixN32: case tc7_VfixZ32: for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2) if (BVE_REF(ra0, i0)) if (VELTS(ra1)[i1] != VELTS(ra2)[i2]) BVE_CLR(ra0, i0); break; # ifdef FLOATS case tc7_VfloR32: for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2) if (BVE_REF(ra0, i0)) if (((float *)VELTS(ra1))[i1] != ((float *)VELTS(ra2))[i2]) BVE_CLR(ra0, i0); break; case tc7_VfloR64: for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2) if (BVE_REF(ra0, i0)) if (((double *)VELTS(ra1))[i1] != ((double *)VELTS(ra2))[i2]) BVE_CLR(ra0, i0); break; case tc7_VfloC32: for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2) if (BVE_REF(ra0, i0)) if (((float *)VELTS(ra1))[2*i1] != ((float *)VELTS(ra2))[2*i2] || ((float *)VELTS(ra1))[2*i1+1] != ((float *)VELTS(ra2))[2*i2+1]) BVE_CLR(ra0, i0); break; case tc7_VfloC64: for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2) if (BVE_REF(ra0, i0)) if (((double *)VELTS(ra1))[2*i1] != ((double *)VELTS(ra2))[2*i2] || ((double *)VELTS(ra1))[2*i1+1] != ((double *)VELTS(ra2))[2*i2+1]) BVE_CLR(ra0, i0); break; # endif /*FLOATS*/ } return 1; } /* opt 0 means <, nonzero means >= */ static int ra_compare(ra0, ra1, ra2, opt) SCM ra0, ra1, ra2; int opt; { long n = ARRAY_DIMS(ra0)->ubnd - ARRAY_DIMS(ra0)->lbnd + 1; sizet i0 = ARRAY_BASE(ra0), i1 = ARRAY_BASE(ra1), i2 = ARRAY_BASE(ra2); long inc0 = ARRAY_DIMS(ra0)->inc; long inc1 = ARRAY_DIMS(ra1)->inc; long inc2 = ARRAY_DIMS(ra2)->inc; ra0 = ARRAY_V(ra0); ra1 = ARRAY_V(ra1); ra2 = ARRAY_V(ra2); switch (TYP7(ra1)==TYP7(ra2) ? TYP7(ra1) : 0) { default: { SCM e1 = UNDEFINED, e2 = UNDEFINED; for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2) if (BVE_REF(ra0, i0)) if (opt ? NFALSEP(lessp(RVREF(ra1, i1, e1), RVREF(ra2, i2, e2))) : FALSEP(lessp(RVREF(ra1, i1, e1), RVREF(ra2, i2, e2))) ) BVE_CLR(ra0, i0); break; } case tc7_VfixN32: for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2) { if (BVE_REF(ra0, i0)) if (opt ? ((unsigned long *)VELTS(ra1))[i1] < ((unsigned long *)VELTS(ra2))[i2] : ((unsigned long *)VELTS(ra1))[i1] >= ((unsigned long *)VELTS(ra2))[i2]) BVE_CLR(ra0, i0); } break; case tc7_VfixZ32: for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2) { if (BVE_REF(ra0, i0)) if (opt ? VELTS(ra1)[i1] < VELTS(ra2)[i2] : VELTS(ra1)[i1] >= VELTS(ra2)[i2]) BVE_CLR(ra0, i0); } break; # ifdef FLOATS case tc7_VfloR32: for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2) if (BVE_REF(ra0, i0)) if (opt ? ((float *)VELTS(ra1))[i1] < ((float *)VELTS(ra2))[i2] : ((float *)VELTS(ra1))[i1] >= ((float *)VELTS(ra2))[i2]) BVE_CLR(ra0, i0); break; case tc7_VfloR64: for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2) if (BVE_REF(ra0, i0)) if (opt ? ((double *)VELTS(ra1))[i1] < ((double *)VELTS(ra2))[i2] : ((double *)VELTS(ra1))[i1] >= ((double *)VELTS(ra2))[i2]) BVE_CLR(ra0, i0); break; # endif /*FLOATS*/ } return 1; } int ra_lessp(ra0, ras) SCM ra0, ras; { return ra_compare(ra0, CAR(ras), CAR(CDR(ras)), 0); } int ra_leqp(ra0, ras) SCM ra0, ras; { return ra_compare(ra0, CAR(CDR(ras)), CAR(ras), 1); } int ra_grp(ra0, ras) SCM ra0, ras; { return ra_compare(ra0, CAR(CDR(ras)), CAR(ras), 0); } int ra_greqp(ra0, ras) SCM ra0, ras; { return ra_compare(ra0, CAR(ras), CAR(CDR(ras)), 1); } int ra_sum(ra0, ras) SCM ra0, ras; { long n = ARRAY_DIMS(ra0)->ubnd - ARRAY_DIMS(ra0)->lbnd + 1; sizet i0 = ARRAY_BASE(ra0); long inc0 = ARRAY_DIMS(ra0)->inc; ra0 = ARRAY_V(ra0); if (NNULLP(ras)) { SCM ra1 = CAR(ras); sizet i1 = ARRAY_BASE(ra1); long inc1 = ARRAY_DIMS(ra1)->inc; ra1 = ARRAY_V(ra1); switch (TYP7(ra0)==TYP7(ra1) ? TYP7(ra0) : 0) { ovflow: wta(ra0, (char *)OVFLOW, "+"); default: { SCM e0 = UNDEFINED, e1 = UNDEFINED; for (; n-- > 0; i0 += inc0, i1 += inc1) aset(ra0, sum(RVREF(ra0, i0, e0), RVREF(ra1, i1, e1)), MAKINUM(i0)); break; } case tc7_VfixN32: { unsigned long r; unsigned long *v0 = (unsigned long *)VELTS(ra0); unsigned long *v1 = (unsigned long *)VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) { r = v0[i0] + v1[i1]; ASRTGO(r >= v0[i0], ovflow); /* Will prevent vectorization */ v0[i0] = r; } ); break; } case tc7_VfixZ32: { long r, *v0 = (long *)VELTS(ra0), *v1 = (long *)VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) { r = v0[i0] + v1[i1]; ASRTGO((v0[i0]>0 ? r>=0 || v1[i1]<0 : r<=0 || v1[i1]>0), ovflow); v0[i0] = r; } ); break; } # ifdef FLOATS case tc7_VfloR32: { float *v0 = (float *)VELTS(ra0); float *v1 = (float *)VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) v0[i0] += v1[i1]); break; } case tc7_VfloR64: { double *v0 = (double *)VELTS(ra0); double *v1 = (double *)VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) v0[i0] += v1[i1]); break; } case tc7_VfloC32: { float (*v0)[2] = (float (*)[2])VELTS(ra0); float (*v1)[2] = (float (*)[2])VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) { v0[i0][0] += v1[i1][0]; v0[i0][1] += v1[i1][1]; }); break; } case tc7_VfloC64: { double (*v0)[2] = (double (*)[2])VELTS(ra0); double (*v1)[2] = (double (*)[2])VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) { v0[i0][0] += v1[i1][0]; v0[i0][1] += v1[i1][1]; }); break; } # endif /* FLOATS */ } } return 1; } int ra_difference(ra0, ras) SCM ra0, ras; { long n = ARRAY_DIMS(ra0)->ubnd - ARRAY_DIMS(ra0)->lbnd + 1; sizet i0 = ARRAY_BASE(ra0); long inc0 = ARRAY_DIMS(ra0)->inc; ra0 = ARRAY_V(ra0); if (NULLP(ras)) { switch TYP7(ra0) { default: { SCM e0 = UNDEFINED; for (; n-- > 0; i0 += inc0) aset(ra0, difference(RVREF(ra0, i0, e0), UNDEFINED), MAKINUM(i0)); break; } case tc7_VfixZ32: { long *v0 = VELTS(ra0); for (; n-- > 0; i0 += inc0) v0[i0] = -v0[i0]; break; } # ifdef FLOATS case tc7_VfloR32: { float *v0 = (float *)VELTS(ra0); for (; n-- > 0; i0 += inc0) v0[i0] = -v0[i0]; break; } case tc7_VfloR64: { double *v0 = (double *)VELTS(ra0); for (; n-- > 0; i0 += inc0) v0[i0] = -v0[i0]; break; } case tc7_VfloC32: { float (*v0)[2] = (float (*)[2])VELTS(ra0); for (; n-- > 0; i0 += inc0) { v0[i0][0] = -v0[i0][0]; v0[i0][1] = -v0[i0][1]; } break; } case tc7_VfloC64: { double (*v0)[2] = (double (*)[2])VELTS(ra0); for (; n-- > 0; i0 += inc0) { v0[i0][0] = -v0[i0][0]; v0[i0][1] = -v0[i0][1]; } break; } # endif /* FLOATS */ } } else { SCM ra1 = CAR(ras); sizet i1 = ARRAY_BASE(ra1); long inc1 = ARRAY_DIMS(ra1)->inc; ra1 = ARRAY_V(ra1); switch (TYP7(ra0)==TYP7(ra1) ? TYP7(ra0) : 0) { ovflow: wta(ra0, (char *)OVFLOW, "-"); default: { SCM e0 = UNDEFINED, e1 = UNDEFINED; for (; n-- > 0; i0 += inc0, i1 += inc1) aset(ra0, difference(RVREF(ra0, i0, e0), RVREF(ra1, i1, e1)), MAKINUM(i0)); break; } case tc7_VfixN32: { unsigned long r; unsigned long *v0 = (unsigned long *)VELTS(ra0); unsigned long *v1 = (unsigned long *)VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) { r = v0[i0] - v1[i1]; ASRTGO(r <= v0[i0], ovflow); v0[i0] = r; } ); break; } case tc7_VfixZ32: { long r, *v0 = VELTS(ra0), *v1 = VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) { r = v0[i0] - v1[i1]; ASRTGO((v0[i0]>0 ? r>=0 || v1[i1]>0 : r<=0 || v1[i1]<0), ovflow); v0[i0] = r; } ); break; } # ifdef FLOATS case tc7_VfloR32: { float *v0 = (float *)VELTS(ra0); float *v1 = (float *)VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) v0[i0] -= v1[i1]); break; } case tc7_VfloR64: { double *v0 = (double *)VELTS(ra0); double *v1 = (double *)VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) v0[i0] -= v1[i1]); break; } case tc7_VfloC32: { float (*v0)[2] = (float (*)[2])VELTS(ra0); float (*v1)[2] = (float (*)[2])VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) { v0[i0][0] -= v1[i1][0]; v0[i0][1] -= v1[i1][1]; }) break; } case tc7_VfloC64: { double (*v0)[2] = (double (*)[2])VELTS(ra0); double (*v1)[2] = (double (*)[2])VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) { v0[i0][0] -= v1[i1][0]; v0[i0][1] -= v1[i1][1]; }) break; } # endif /* FLOATS */ } } return 1; } int ra_product(ra0, ras) SCM ra0, ras; { long n = ARRAY_DIMS(ra0)->ubnd - ARRAY_DIMS(ra0)->lbnd + 1; sizet i0 = ARRAY_BASE(ra0); long inc0 = ARRAY_DIMS(ra0)->inc; ra0 = ARRAY_V(ra0); if (NNULLP(ras)) { SCM ra1 = CAR(ras); sizet i1 = ARRAY_BASE(ra1); long inc1 = ARRAY_DIMS(ra1)->inc; ra1 = ARRAY_V(ra1); switch (TYP7(ra0)==TYP7(ra1) ? TYP7(ra0) : 0) { ovflow: wta(ra0, (char *)OVFLOW, "*"); default: { SCM e0 = UNDEFINED, e1 = UNDEFINED; for (; n-- > 0; i0 += inc0, i1 += inc1) aset(ra0, product(RVREF(ra0, i0, e0), RVREF(ra1, i1, e1)), MAKINUM(i0)); break; } case tc7_VfixN32: { unsigned long r; unsigned long *v0 = (unsigned long *)VELTS(ra0); unsigned long *v1 = (unsigned long *)VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) { r = v0[i0] * v1[i1]; ASRTGO(0==v0[i0] || v1[i1]==r/v0[i0], ovflow); v0[i0] = r; } ); break; } case tc7_VfixZ32: { long r, *v0 = VELTS(ra0), *v1 =VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) { r = v0[i0] * v1[i1]; ASRTGO(0==v0[i0] || v1[i1]==r/v0[i0], ovflow); v0[i0] = r; } ); break; } # ifdef FLOATS case tc7_VfloR32: { float *v0 = (float *)VELTS(ra0); float *v1 = (float *)VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) v0[i0] *= v1[i1]); break; } case tc7_VfloR64: { double *v0 = (double *)VELTS(ra0); double *v1 = (double *)VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) v0[i0] *= v1[i1]); break; } case tc7_VfloC32: { float (*v0)[2] = (float (*)[2])VELTS(ra0); register double r; float (*v1)[2] = (float (*)[2])VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) { r = v0[i0][0]*v1[i1][0] - v0[i0][1]*v1[i1][1]; v0[i0][1] = v0[i0][0]*v1[i1][1] + v0[i0][1]*v1[i1][0]; v0[i0][0] = r; }); break; } case tc7_VfloC64: { double (*v0)[2] = (double (*)[2])VELTS(ra0); register double r; double (*v1)[2] = (double (*)[2])VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) { r = v0[i0][0]*v1[i1][0] - v0[i0][1]*v1[i1][1]; v0[i0][1] = v0[i0][0]*v1[i1][1] + v0[i0][1]*v1[i1][0]; v0[i0][0] = r; }); break; } # endif /* FLOATS */ } } return 1; } int ra_divide(ra0, ras) SCM ra0, ras; { long n = ARRAY_DIMS(ra0)->ubnd - ARRAY_DIMS(ra0)->lbnd + 1; sizet i0 = ARRAY_BASE(ra0); long inc0 = ARRAY_DIMS(ra0)->inc; ra0 = ARRAY_V(ra0); if (NULLP(ras)) { switch TYP7(ra0) { default: { SCM e0 = UNDEFINED; for (; n-- > 0; i0 += inc0) aset(ra0, divide(RVREF(ra0, i0, e0), UNDEFINED), MAKINUM(i0)); break; } # ifdef FLOATS case tc7_VfloR32: { float *v0 = (float *)VELTS(ra0); for (; n-- > 0; i0 += inc0) v0[i0] = 1.0/v0[i0]; break; } case tc7_VfloR64: { double *v0 = (double *)VELTS(ra0); for (; n-- > 0; i0 += inc0) v0[i0] = 1.0/v0[i0]; break; } case tc7_VfloC32: { register double d; float (*v0)[2] = (float (*)[2])VELTS(ra0); for (; n-- > 0; i0 += inc0) { d = v0[i0][0]*v0[i0][0] + v0[i0][1]*v0[i0][1]; v0[i0][0] /= d; v0[i0][1] /= -d; } break; } case tc7_VfloC64: { register double d; double (*v0)[2] = (double (*)[2])VELTS(ra0); for (; n-- > 0; i0 += inc0) { d = v0[i0][0]*v0[i0][0] + v0[i0][1]*v0[i0][1]; v0[i0][0] /= d; v0[i0][1] /= -d; } break; } # endif /* FLOATS */ } } else { SCM ra1 = CAR(ras); sizet i1 = ARRAY_BASE(ra1); long inc1 = ARRAY_DIMS(ra1)->inc; ra1 = ARRAY_V(ra1); switch (TYP7(ra0)==TYP7(ra1) ? TYP7(ra0) : 0) { default: { SCM e0 = UNDEFINED, e1 = UNDEFINED; for (; n-- > 0; i0 += inc0, i1 += inc1) aset(ra0, divide(RVREF(ra0, i0, e0), RVREF(ra1, i1, e1)), MAKINUM(i0)); break; } # ifdef FLOATS case tc7_VfloR32: { float *v0 = (float *)VELTS(ra0); float *v1 = (float *)VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) v0[i0] /= v1[i1]); break; } case tc7_VfloR64: { double *v0 = (double *)VELTS(ra0); double *v1 = (double *)VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) v0[i0] /= v1[i1]); break; } case tc7_VfloC32: { register double d, r; float (*v0)[2] = (float (*)[2])VELTS(ra0); float (*v1)[2] = (float (*)[2])VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) { d = v1[i1][0]*v1[i1][0] + v1[i1][1]*v1[i1][1]; r = (v0[i0][0]*v1[i1][0] + v0[i0][1]*v1[i1][1])/d; v0[i0][1] = (v0[i0][1]*v1[i1][0] - v0[i0][0]*v1[i1][1])/d; v0[i0][0] = r; }) break; } case tc7_VfloC64: { register double d, r; double (*v0)[2] = (double (*)[2])VELTS(ra0); double (*v1)[2] = (double (*)[2])VELTS(ra1); IVDEP(ra0 != ra1, for (; n-- > 0; i0 += inc0, i1 += inc1) { d = v1[i1][0]*v1[i1][0] + v1[i1][1]*v1[i1][1]; r = (v0[i0][0]*v1[i1][0] + v0[i0][1]*v1[i1][1])/d; v0[i0][1] = (v0[i0][1]*v1[i1][0] - v0[i0][0]*v1[i1][1])/d; v0[i0][0] = r; }) break; } # endif /* FLOATS */ } } return 1; } static int ra_identity(dst, src) SCM src, dst; { return racp(CAR(src), cons(dst, EOL)); } static int ramap(ra0, proc, ras) SCM ra0, proc, ras; { SCM heap_ve, auto_rav[5], auto_argv[5]; SCM *rav = &auto_rav[0], *argv = &auto_argv[0]; long argc = ilength(ras); long i, k, inc, n, base; volatile SCM gcpr[1]; if (argc >= 5) { heap_ve = gcpr[0] = make_vector(MAKINUM(2*argc), BOOL_F); rav = VELTS(heap_ve); argv = &(rav[argc]); } for (k = 0; k < argc; k++) { rav[k] = CAR(ras); ras = CDR(ras); } i = ARRAY_DIMS(ra0)->lbnd; inc = ARRAY_DIMS(ra0)->inc; n = ARRAY_DIMS(ra0)->ubnd; base = ARRAY_BASE(ra0) - i*inc; ra0 = ARRAY_V(ra0); for (; i <= n; i++) { for (k = 0; k < argc; k++) argv[k] = aref(rav[k], MAKINUM(i)); aset(ra0, scm_cvapply(proc, argc, argv), MAKINUM(i*inc + base)); } return 1; } static int ramap_cxr(ra0, proc, ras) SCM ra0, proc, ras; { SCM ra1 = CAR(ras); SCM e1 = UNDEFINED; sizet i0 = ARRAY_BASE(ra0), i1 = ARRAY_BASE(ra1); long inc0 = ARRAY_DIMS(ra0)->inc, inc1 = ARRAY_DIMS(ra1)->inc; long n = ARRAY_DIMS(ra0)->ubnd - ARRAY_DIMS(ra1)->lbnd + 1; ra0 = ARRAY_V(ra0); ra1 = ARRAY_V(ra1); switch TYP7(ra0) { default: gencase: for (; n-- > 0; i0 += inc0, i1 += inc1) { e1 = cvref(ra1, i1, e1); aset(ra0, scm_cvapply(proc, 1L, &e1), MAKINUM(i0)); } break; # ifdef FLOATS case tc7_VfloR32: { float *dst = (float *)VELTS(ra0); switch TYP7(ra1) { default: goto gencase; case tc7_VfloR32: for (; n-- > 0; i0 += inc0, i1 += inc1) dst[i0] = DSUBRF(proc)((double)((float *)VELTS(ra1))[i1]); break; case tc7_VfixN32: case tc7_VfixZ32: for (; n-- > 0; i0 += inc0, i1 += inc1) dst[i0] = DSUBRF(proc)((double)VELTS(ra1)[i1]); break; } break; } case tc7_VfloR64: { double *dst = (double *)VELTS(ra0); switch TYP7(ra1) { default: goto gencase; case tc7_VfloR64: for (; n-- > 0; i0 += inc0, i1 += inc1) dst[i0] = DSUBRF(proc)(((double *)VELTS(ra1))[i1]); break; case tc7_VfixN32: case tc7_VfixZ32: for (; n-- > 0; i0 += inc0, i1 += inc1) dst[i0] = DSUBRF(proc)((double)VELTS(ra1)[i1]); break; } break; } # endif /* FLOATS */ } return 1; } static int ramap_rp(ra0, proc, ras) SCM ra0, proc, ras; { SCM ra1 = CAR(ras), ra2 = CAR(CDR(ras)); SCM e1 = UNDEFINED, e2 = UNDEFINED; long n = ARRAY_DIMS(ra0)->ubnd - ARRAY_DIMS(ra0)->lbnd + 1; sizet i0 = ARRAY_BASE(ra0), i1 = ARRAY_BASE(ra1), i2 = ARRAY_BASE(ra2); long inc0 = ARRAY_DIMS(ra0)->inc; long inc1 = ARRAY_DIMS(ra1)->inc; long inc2 = ARRAY_DIMS(ra2)->inc; ra0 = ARRAY_V(ra0); ra1 = ARRAY_V(ra1); ra2 = ARRAY_V(ra2); for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2) if (BVE_REF(ra0, i0)) if (FALSEP(SUBRF(proc)(RVREF(ra1, i1, e1), RVREF(ra2, i2, e2)))) BVE_CLR(ra0, i0); return 1; } static int ramap_1(ra0, proc, ras) SCM ra0, proc, ras; { SCM ra1 = CAR(ras); SCM e1 = UNDEFINED; long n = ARRAY_DIMS(ra0)->ubnd - ARRAY_DIMS(ra0)->lbnd + 1; sizet i0 = ARRAY_BASE(ra0), i1 = ARRAY_BASE(ra1); long inc0 = ARRAY_DIMS(ra0)->inc, inc1 = ARRAY_DIMS(ra1)->inc; ra0 = ARRAY_V(ra0); ra1 = ARRAY_V(ra1); if (tc7_vector==TYP7(ra0)) for (; n-- > 0; i0 += inc0, i1 += inc1) VELTS(ra0)[i0] = SUBRF(proc)(cvref(ra1, i1, UNDEFINED)); else for (; n-- > 0; i0 += inc0, i1 += inc1) aset(ra0, SUBRF(proc)(RVREF(ra1, i1, e1)), MAKINUM(i0)); return 1; } static int ramap_2o(ra0, proc, ras) SCM ra0, proc, ras; { SCM ra1 = CAR(ras); SCM e1 = UNDEFINED; long n = ARRAY_DIMS(ra0)->ubnd - ARRAY_DIMS(ra0)->lbnd + 1; sizet i0 = ARRAY_BASE(ra0), i1 = ARRAY_BASE(ra1); long inc0 = ARRAY_DIMS(ra0)->inc, inc1 = ARRAY_DIMS(ra1)->inc; ra0 = ARRAY_V(ra0); ra1 = ARRAY_V(ra1); ras = CDR(ras); if (NULLP(ras)) { if (tc7_vector==TYP7(ra0)) for (; n-- > 0; i0 += inc0, i1 += inc1) VELTS(ra0)[i0] = SUBRF(proc)(cvref(ra1, i1, UNDEFINED), UNDEFINED); else for (; n-- > 0; i0 += inc0, i1 += inc1) aset(ra0, SUBRF(proc)(RVREF(ra1, i1, e1), UNDEFINED), MAKINUM(i0)); } else { SCM ra2 = CAR(ras); SCM e2 = UNDEFINED; sizet i2 = ARRAY_BASE(ra2); long inc2 = ARRAY_DIMS(ra2)->inc; ra2 = ARRAY_V(ra2); if (tc7_vector==TYP7(ra0)) for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2) VELTS(ra0)[i0] = SUBRF(proc)(cvref(ra1, i1, UNDEFINED), cvref(ra2, i2, UNDEFINED)); else for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2) aset(ra0, SUBRF(proc)(RVREF(ra1, i1, e1), RVREF(ra2, i2, e2)), MAKINUM(i0)); } return 1; } static int ramap_a(ra0, proc, ras) SCM ra0, proc, ras; { SCM e0 = UNDEFINED, e1 = UNDEFINED; long n = ARRAY_DIMS(ra0)->ubnd - ARRAY_DIMS(ra0)->lbnd + 1; sizet i0 = ARRAY_BASE(ra0); long inc0 = ARRAY_DIMS(ra0)->inc; ra0 = ARRAY_V(ra0); if (NULLP(ras)) for (; n-- > 0; i0 += inc0) aset(ra0, SUBRF(proc)(RVREF(ra0, i0, e0), UNDEFINED), MAKINUM(i0)); else { SCM ra1 = CAR(ras); sizet i1 = ARRAY_BASE(ra1); long inc1 = ARRAY_DIMS(ra1)->inc; ra1 = ARRAY_V(ra1); for (; n-- > 0; i0 += inc0, i1 += inc1) aset(ra0, SUBRF(proc)(RVREF(ra0, i0, e0), RVREF(ra1, i1, e1)), MAKINUM(i0)); } return 1; } /* These tables are a kluge that will not scale well when more vectorized subrs are added. It is tempting to steal some bits from the CAR of all subrs (like those selected by SMOBNUM) to hold an offset into a table of vectorized subrs. */ static ra_iproc ra_rpsubrs[] = { {"=", UNDEFINED, ra_eqp}, {"<", UNDEFINED, ra_lessp}, {"<=", UNDEFINED, ra_leqp}, {">", UNDEFINED, ra_grp}, {">=", UNDEFINED, ra_greqp}, {0, 0, 0}}; static ra_iproc ra_asubrs[] = { {"+", UNDEFINED, ra_sum}, {"-", UNDEFINED, ra_difference}, {"*", UNDEFINED, ra_product}, {"/", UNDEFINED, ra_divide}, {0, 0, 0}}; static char s_sarray_map[] = "serial-array-map!"; # define s_array_map (s_sarray_map + 7) SCM array_map(ra0, proc, lra) SCM ra0, proc, lra; { long narg = ilength(lra); tail: #ifndef RECKLESS scm_arity_check(proc, narg, s_array_map); #endif switch TYP7(proc) { default: gencase: ramapc(ramap, proc, ra0, lra, s_array_map); return UNSPECIFIED; case tc7_subr_1: ramapc(ramap_1, proc, ra0, lra, s_array_map); return UNSPECIFIED; case tc7_subr_2: case tc7_subr_2o: ramapc(ramap_2o, proc, ra0, lra, s_array_map); return UNSPECIFIED; case tc7_cxr: if (! SUBRF(proc)) goto gencase; ramapc(ramap_cxr, proc, ra0, lra, s_array_map); return UNSPECIFIED; case tc7_rpsubr: { ra_iproc *p; if (FALSEP(arrayp(ra0, BOOL_T))) goto gencase; array_fill(ra0, BOOL_T); for (p = ra_rpsubrs; p->name; p++) if (proc==p->sproc) { while (NNULLP(lra) && NNULLP(CDR(lra))) { ramapc(p->vproc, UNDEFINED, ra0, lra, s_array_map); lra = CDR(lra); } return UNSPECIFIED; } while (NNULLP(lra) && NNULLP(CDR(lra))) { ramapc(ramap_rp, proc, ra0, lra, s_array_map); lra = CDR(lra); } return UNSPECIFIED; } case tc7_asubr: if (NULLP(lra)) { SCM prot, fill = SUBRF(proc)(UNDEFINED, UNDEFINED); if (INUMP(fill)) { prot = array_prot(ra0); # ifdef FLOATS if (NIMP(prot) && INEXP(prot)) fill = makdbl((double)INUM(fill), 0.0); # endif } array_fill(ra0, fill); } else { SCM tail, ra1 = CAR(lra); SCM v0 = (NIMP(ra0) && ARRAYP(ra0) ? ARRAY_V(ra0) : ra0); ra_iproc *p; /* Check to see if order might matter. This might be an argument for a separate SERIAL-ARRAY-MAP! */ if (v0==ra1 || (NIMP(ra1) && ARRAYP(ra1) && v0==ARRAY_V(ra1))) if (ra0 != ra1 || (ARRAYP(ra0) && !ARRAY_CONTP(ra0))) goto gencase; for (tail = CDR(lra); NNULLP(tail); tail = CDR(tail)) { ra1 = CAR(tail); if (v0==ra1 || (NIMP(ra1) && ARRAYP(ra1) && v0==ARRAY_V(ra1))) goto gencase; } for (p = ra_asubrs; p->name; p++) if (proc==p->sproc) { if (ra0 != CAR(lra)) ramapc(ra_identity, UNDEFINED, ra0, cons(CAR(lra), EOL), s_array_map); lra = CDR(lra); while (1) { ramapc(p->vproc, UNDEFINED, ra0, lra, s_array_map); if (IMP(lra) || IMP(CDR(lra))) return UNSPECIFIED; lra = CDR(lra); } } ramapc(ramap_2o, proc, ra0, lra, s_array_map); lra = CDR(lra); if (NIMP(lra)) for (lra = CDR(lra); NIMP(lra); lra = CDR(lra)) ramapc(ramap_a, proc, ra0, lra, s_array_map); } return UNSPECIFIED; #if 1 /* def CCLO */ case tc7_specfun: if (tc16_cclo==TYP16(proc)) { lra = cons(sc2array(proc, ra0, EOL), lra); proc = CCLO_SUBR(proc); narg++; goto tail; } goto gencase; #endif } } static int rafe(ra0, proc, ras) SCM ra0, proc, ras; { SCM heap_ve, auto_rav[5], auto_argv[5]; SCM *rav = &auto_rav[0], *argv = &auto_argv[0]; long argc = ilength(ras) + 1; long i, k, n; volatile SCM gcpr[1]; if (argc >= 5) { heap_ve = gcpr[0] = make_vector(MAKINUM(2*argc), BOOL_F); rav = VELTS(heap_ve); argv = &(rav[argc]); } rav[0] = ra0; for (k = 1; k < argc; k++) { rav[k] = CAR(ras); ras = CDR(ras); } i = ARRAY_DIMS(ra0)->lbnd; n = ARRAY_DIMS(ra0)->ubnd; for (; i <= n; i++) { for (k = 0; k < argc; k++) argv[k] = aref(rav[k], MAKINUM(i)); scm_cvapply(proc, argc, argv); } return 1; } static char s_array_for_each[] = "array-for-each"; SCM array_for_each(proc, ra0, lra) SCM proc, ra0, lra; { long narg = ilength(lra) + 1; tail: #ifndef RECKLESS scm_arity_check(proc, narg, s_array_for_each); #endif switch TYP7(proc) { default: gencase: ramapc(rafe, proc, ra0, lra, s_array_for_each); return UNSPECIFIED; #if 1 /* def CCLO */ case tc7_specfun: if (tc16_cclo==TYP16(proc)) { lra = cons(ra0, lra); ra0 = sc2array(proc, ra0, EOL); proc = CCLO_SUBR(proc); narg++; goto tail; } goto gencase; #endif } } static char s_array_index_for_each[] = "array-index-for-each"; SCM scm_array_index_for_each(ra, proc) SCM ra, proc; { SCM hp_av, hp_indv, auto_av[5]; SCM *av = &auto_av[0]; long auto_indv[5]; long *indv = &auto_indv[0]; sizet i; volatile SCM gcpr[2]; ASRTER(NIMP(ra), ra, ARG1, s_array_index_for_each); i = INUM(array_rank(ra)); #ifndef RECKLESS scm_arity_check(proc, i+0L, s_array_index_for_each); #endif if (i >= 5) { hp_av = gcpr[0] = make_vector(MAKINUM(i), BOOL_F); av = VELTS(hp_av); hp_indv = gcpr[1] = make_uve(i+0L, MAKINUM(-32L)); indv = (long *)VELTS(hp_indv); } switch TYP7(ra) { default: badarg: wta(ra, (char *)ARG1, s_array_index_for_each); case tc7_vector: { for (i = 0; i < LENGTH(ra); i++) { av[0] = MAKINUM(i); scm_cvapply(proc, 1L, av); } return UNSPECIFIED; } case tcs_uves: for (i = 0; i < LENGTH(ra); i++) { av[0] = MAKINUM(i); scm_cvapply(proc, 1L, auto_av); } return UNSPECIFIED; case tc7_smob: ASRTGO(ARRAYP(ra), badarg); { int j, k, kmax = ARRAY_NDIM(ra) - 1; if (kmax < 0) return apply(proc, EOL, EOL); for (k = 0; k <= kmax; k++) indv[k] = ARRAY_DIMS(ra)[k].lbnd; k = kmax; do { if (k==kmax) { indv[k] = ARRAY_DIMS(ra)[k].lbnd; i = cind(ra, indv); for (; indv[k] <= ARRAY_DIMS(ra)[k].ubnd; indv[k]++) { for (j = kmax+1; j--;) av[j] = MAKINUM(indv[j]); scm_cvapply(proc, kmax+1L, av); i += ARRAY_DIMS(ra)[k].inc; } k--; continue; } if (indv[k] < ARRAY_DIMS(ra)[k].ubnd) { indv[k]++; k++; continue; } indv[k] = ARRAY_DIMS(ra)[k].lbnd - 1; k--; } while (k >= 0); return UNSPECIFIED; } } } static char s_array_imap[] = "array-index-map!"; SCM array_imap(ra, proc) SCM ra, proc; { SCM hp_av, hp_indv, auto_av[5]; SCM *av = &auto_av[0]; long auto_indv[5]; long *indv = &auto_indv[0]; sizet i; volatile SCM gcpr[2]; ASRTER(NIMP(ra), ra, ARG1, s_array_imap); i = INUM(array_rank(ra)); #ifndef RECKLESS scm_arity_check(proc, i+0L, s_array_imap); #endif if (i >= 5) { hp_av = gcpr[0] = make_vector(MAKINUM(i), BOOL_F); av = VELTS(hp_av); hp_indv = gcpr[1] = make_uve(i+0L, MAKINUM(-32L)); indv = (long *)VELTS(hp_indv); } switch TYP7(ra) { default: badarg: wta(ra, (char *)ARG1, s_array_imap); case tc7_vector: { SCM *ve = VELTS(ra); for (i = 0; i < LENGTH(ra); i++) { av[0] = MAKINUM(i); ve[i] = scm_cvapply(proc, 1L, av); } return UNSPECIFIED; } case tcs_uves: for (i = 0; i < LENGTH(ra); i++) { av[0] = MAKINUM(i); aset(ra, scm_cvapply(proc, 1L, auto_av), MAKINUM(i)); } return UNSPECIFIED; case tc7_smob: ASRTGO(ARRAYP(ra), badarg); { int j, k, kmax = ARRAY_NDIM(ra) - 1; if (kmax < 0) return aset(ra, apply(proc, EOL, EOL), EOL); for (k = 0; k <= kmax; k++) indv[k] = ARRAY_DIMS(ra)[k].lbnd; k = kmax; do { if (k==kmax) { indv[k] = ARRAY_DIMS(ra)[k].lbnd; i = cind(ra, indv); for (; indv[k] <= ARRAY_DIMS(ra)[k].ubnd; indv[k]++) { for (j = kmax+1; j--;) av[j] = MAKINUM(indv[j]); aset(ARRAY_V(ra), scm_cvapply(proc, kmax+1L, av), MAKINUM(i)); i += ARRAY_DIMS(ra)[k].inc; } k--; continue; } if (indv[k] < ARRAY_DIMS(ra)[k].ubnd) { indv[k]++; k++; continue; } indv[k] = ARRAY_DIMS(ra)[k].lbnd - 1; k--; } while (k >= 0); return UNSPECIFIED; } } } SCM array_equal P((SCM ra0, SCM ra1)); static int raeql_1(ra0, as_equal, ra1) SCM ra0, as_equal, ra1; { SCM e0 = UNDEFINED, e1 = UNDEFINED; sizet i0 = 0, i1 = 0; long inc0 = 1, inc1 = 1; sizet n = LENGTH(ra0); ra1 = CAR(ra1); if (ARRAYP(ra0)) { n = ARRAY_DIMS(ra0)->ubnd - ARRAY_DIMS(ra0)->lbnd + 1; i0 = ARRAY_BASE(ra0); inc0 = ARRAY_DIMS(ra0)->inc; ra0 = ARRAY_V(ra0); } if (ARRAYP(ra1)) { i1 = ARRAY_BASE(ra1); inc1 = ARRAY_DIMS(ra1)->inc; ra1 = ARRAY_V(ra1); } switch TYP7(ra0) { case tc7_vector: default: for (; n--; i0+=inc0, i1+=inc1) { if (FALSEP(as_equal)) { if (FALSEP(array_equal(RVREF(ra0, i0, e0), RVREF(ra1, i1, e1)))) return 0; } else if (FALSEP(equal(RVREF(ra0, i0, e0), RVREF(ra1, i1, e1)))) return 0; } return 1; case tc7_string: { char *v0 = CHARS(ra0) + i0; char *v1 = CHARS(ra1) + i1; for (; n--; v0 += inc0, v1 += inc1) if (*v0 != *v1) return 0; return 1; } case tc7_Vbool: for (; n--; i0 += inc0, i1 += inc1) if (BVE_REF(ra0, i0) != BVE_REF(ra1, i1)) return 0; return 1; case tc7_VfixN32: case tc7_VfixZ32: { long *v0 = (long *)VELTS(ra0) + i0; long *v1 = (long *)VELTS(ra1) + i1; for (; n--; v0 += inc0, v1 += inc1) if (*v0 != *v1) return 0; return 1; } # ifdef FLOATS case tc7_VfloR32: { float *v0 = (float *)VELTS(ra0) + i0; float *v1 = (float *)VELTS(ra1) + i1; for (; n--; v0 += inc0, v1 += inc1) if (*v0 != *v1) return 0; return 1; } case tc7_VfloR64: { double *v0 = (double *)VELTS(ra0) + i0; double *v1 = (double *)VELTS(ra1) + i1; for (; n--; v0 += inc0, v1 += inc1) if (*v0 != *v1) return 0; return 1; } case tc7_VfloC32: { float (*v0)[2]= (float (*)[2])VELTS(ra0) + i0; float (*v1)[2] = (float (*)[2])VELTS(ra1) + i1; for (; n--; v0 += inc0, v1 += inc1) { if ((*v0)[0] != (*v1)[0]) return 0; if ((*v0)[1] != (*v1)[1]) return 0; } return 1; } case tc7_VfloC64: { double (*v0)[2]= (double (*)[2])VELTS(ra0) + i0; double (*v1)[2] = (double (*)[2])VELTS(ra1) + i1; for (; n--; v0 += inc0, v1 += inc1) { if ((*v0)[0] != (*v1)[0]) return 0; if ((*v0)[1] != (*v1)[1]) return 0; } return 1; } # endif /* FLOATS */ } } static int raeql(ra0, as_equal, ra1) SCM ra0, as_equal, ra1; { SCM v0 = ra0, v1 = ra1; array_dim dim0, dim1; array_dim *s0 = &dim0, *s1 = &dim1; sizet bas0 = 0, bas1 = 0; int k, unroll = 1, ndim = 1; if (ARRAYP(ra0)) { ndim = ARRAY_NDIM(ra0); s0 = ARRAY_DIMS(ra0); bas0 = ARRAY_BASE(ra0); v0 = ARRAY_V(ra0); } else { s0->inc = 1; s0->lbnd = 0; s0->ubnd = LENGTH(v0) - 1; } if (ARRAYP(ra1)) { if (ndim != ARRAY_NDIM(ra1)) return 0; s1 = ARRAY_DIMS(ra1); bas1 = ARRAY_BASE(ra1); v1 = ARRAY_V(ra1); } else { if (1 != ndim) return BOOL_F; s1->inc = 1; s1->lbnd = 0; s1->ubnd = LENGTH(v1) - 1; } if (TYP7(v0) != TYP7(v1)) return 0; unroll = (bas0==bas1); for (k = ndim; k--;) { if (s0[k].lbnd != s1[k].lbnd || s0[k].ubnd != s1[k].ubnd) return 0; if (unroll) unroll = (s0[k].inc==s1[k].inc); } if (unroll && v0==v1) return BOOL_T; return ramapc(raeql_1, as_equal, ra0, cons(ra1, EOL), ""); } SCM raequal(ra0, ra1) SCM ra0, ra1; { return (raeql(ra0, BOOL_T, ra1) ? BOOL_T : BOOL_F); } static char s_array_equalp[] = "array-equal?"; SCM array_equal(ra0, ra1) SCM ra0, ra1; { if (IMP(ra0) || IMP(ra1)) callequal: return equal(ra0, ra1); switch TYP7(ra0) { default: goto callequal; case tc7_vector: case tcs_uves: break; case tc7_smob: if (!ARRAYP(ra0)) goto callequal; } switch TYP7(ra1) { default: goto callequal; case tc7_vector: case tcs_uves: break; case tc7_smob: if (!ARRAYP(ra1)) goto callequal; } return (raeql(ra0, BOOL_F, ra1) ? BOOL_T : BOOL_F); } static iproc subr2os[] = { {s_ura_rd, ura_read}, {s_ura_wr, ura_write}, {0, 0}}; /* MinGW complains during a dll build that the string members are not constants, since they are defined in another dll. These functions individually initialized below. static iproc subr2s[] = { {s_array_fill, array_fill}, {s_array_copy, array_copy}, {s_sarray_copy, array_copy}, {0, 0}}; */ static iproc lsubr2s[] = { {s_sc2array, sc2array}, {s_array_map, array_map}, {s_sarray_map, array_map}, {s_array_for_each, array_for_each}, {s_array_imap, array_imap}, {s_array_index_for_each, scm_array_index_for_each}, {0, 0}}; static void init_raprocs(subra) ra_iproc *subra; { for (; subra->name; subra++) subra->sproc = CDR(sysintern(subra->name, UNDEFINED)); } SCM_DLL_EXPORT void init_ramap P((void)); void init_ramap() { init_raprocs(ra_rpsubrs); init_raprocs(ra_asubrs); init_iprocs(subr2os, tc7_subr_2o); /* init_iprocs(subr2s, tc7_subr_2); */ init_iprocs(lsubr2s, tc7_lsubr_2); make_subr(s_array_fill, tc7_subr_2, array_fill); make_subr(s_array_copy, tc7_subr_2, array_copy); make_subr(s_sarray_copy, tc7_subr_2, array_copy); make_subr(s_array_equalp, tc7_rpsubr, array_equal); smobs[0x0ff & (tc16_array>>8)].equalp = raequal; add_feature(s_array_for_each); scm_ldstr("\n\ (define (array-indexes ra)\n\ (let ((ra0 (apply make-array '#() (array-shape ra))))\n\ (array-index-map! ra0 list)\n\ ra0))\n\ (define (array-map prototype proc ra1 . ras)\n\ (define nra (apply make-array prototype (array-shape ra1)))\n\ (apply array-map! nra proc ra1 ras)\n\ nra)\n\ "); } scm-5f4/scm.texi0000755000175000017500000113023714551360116010646 00000000000000\input texinfo @c -*-texinfo-*- @c %**start of header @setfilename scm.info @settitle scm @include version.txi @setchapternewpage on @c Choices for setchapternewpage are {on,off,odd}. @paragraphindent 0 @defcodeindex ft @syncodeindex ft tp @c %**end of header @copying @noindent This manual is for SCM (version @value{SCMVERSION}, @value{SCMDATE}), an implementation of the algorithmic language Scheme. @noindent Copyright @copyright{} 1990-2007 Free Software Foundation, Inc. @quotation Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled ``GNU Free Documentation License.'' @end quotation @end copying @dircategory The Algorithmic Language Scheme @direntry * SCM: (scm). A Scheme interpreter. @end direntry @iftex @finalout @c DL: lose the egregious vertical whitespace, esp. around examples @c but paras in @defun-like things don't have parindent @parskip 4pt plus 1pt @end iftex @titlepage @title SCM @subtitle Scheme Implementation @subtitle Version @value{SCMVERSION} @author Aubrey Jaffer @page @vskip 0pt plus 1filll @insertcopying @end titlepage @contents @ifnottex @node Top, Overview, (dir), (dir) @top SCM @insertcopying @menu * Overview:: * Installing SCM:: How to * Operational Features:: * The Language:: Reference. * Packages:: Optional Capabilities. * The Implementation:: How it works. * Index:: @end menu @end ifnottex @node Overview, Installing SCM, Top, Top @chapter Overview @noindent SCM is a portable Scheme implementation written in C. SCM provides a machine independent platform for [JACAL], a symbolic algebra system. SCM supports and requires the SLIB Scheme library. SCM, SLIB, and JACAL are GNU projects. @iftex @noindent The most recent information about SCM can be found on SCM's @dfn{WWW} home page: @ifset html @end ifset @center @url{http://people.csail.mit.edu/jaffer/SCM} @ifset html @end ifset @end iftex @menu * SCM Features:: * SCM Authors:: * Copying:: * Bibliography:: @end menu @node SCM Features, SCM Authors, Overview, Overview @section Features @itemize @bullet @item Conforms to Revised^5 Report on the Algorithmic Language Scheme [R5RS] and the [IEEE] P1178 specification. @item Support for [SICP], [R2RS], [R3RS], and [R5RS] scheme code. @item Runs under Amiga, Atari-ST, MacOS, MS-DOS, OS/2, NOS/VE, Unicos, VMS, Unix and similar systems. Supports ASCII and EBCDIC character sets. @item Is fully documented in @TeX{}info form, allowing documentation to be generated in info, @TeX{}, html, nroff, and troff formats. @item Supports inexact real and complex numbers, 30 bit immediate integers and large precision integers. @item Many Common Lisp functions: @code{logand}, @code{logor}, @code{logxor}, @code{lognot}, @code{ash}, @code{logcount}, @code{integer-length}, @code{bit-extract}, @code{defmacro}, @code{macroexpand}, @code{macroexpand1}, @code{gentemp}, @code{defvar}, @code{force-output}, @code{software-type}, @code{get-decoded-time}, @code{get-internal-run-time}, @code{get-internal-real-time}, @code{delete-file}, @code{rename-file}, @code{copy-tree}, @code{acons}, and @code{eval}. @item @code{Char-code-limit}, @code{most-positive-fixnum}, @code{most-negative-fixnum}, @code{and internal-time-units-per-second} constants. @code{slib:features} and @code{*load-pathname*} variables. @item Arrays and bit-vectors. String ports and software emulation ports. I/O extensions providing ANSI C and POSIX.1 facilities. @item Interfaces to standard libraries including REGEX string regular expression matching and the CURSES screen management package. @item Available add-on packages including an interactive debugger, database, X-window graphics, BGI graphics, Motif, and Open-Windows packages. @item The Hobbit compiler and dynamic linking of compiled modules. @item User definable responses to interrupts and errors, Process-syncronization primitives. Setable levels of monitoring and timing information printed interactively (the @code{verbose} function). @code{Restart}, @code{quit}, and @code{exec}. @end itemize @node SCM Authors, Copying, SCM Features, Overview @section Authors @table @b @item Aubrey Jaffer (agj@@alum.mit.edu) Most of SCM. @item Radey Shouman Arrays, @code{gsubr}s, compiled closures, records, Ecache, syntax-rules macros, and @dfn{safeport}s. @item Jerry D. Hedden Real and Complex functions. Fast mixed type arithmetics. @item Hugh Secker-Walker Syntax checking and memoization of special forms by evaluator. Storage allocation strategy and parameters. @item George Carrette @dfn{Siod}, written by George Carrette, was the starting point for SCM. The major innovations taken from Siod are the evaluator's use of the C-stack and being able to garbage collect off the C-stack (@pxref{Garbage Collection}). @end table @noindent There are many other contributors to SCM. They are acknowledged in the file @file{ChangeLog}, a log of changes that have been made to scm. @node Copying, Bibliography, SCM Authors, Overview @section Copyright @noindent Authors have assigned their SCM copyrights to: @sp 1 @center Free Software Foundation, Inc. @center 59 Temple Place, Suite 330, Boston, MA 02111, USA @menu * The SCM License:: * SIOD copyright:: * GNU Free Documentation License:: Copying this Manual @end menu @node The SCM License, SIOD copyright, Copying, Copying @subsection The SCM License This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see @url{http://www.gnu.org/licenses/}. @node SIOD copyright, GNU Free Documentation License, The SCM License, Copying @subsection SIOD copyright @sp 1 @center COPYRIGHT @copyright{} 1989 BY @center PARADIGM ASSOCIATES INCORPORATED, CAMBRIDGE, MASSACHUSETTS. @center ALL RIGHTS RESERVED @noindent Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Paradigm Associates Inc not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. @noindent PARADIGM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL PARADIGM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. @noindent gjc@@paradigm.com @flushright Phone: 617-492-6079 @end flushright @flushleft Paradigm Associates Inc 29 Putnam Ave, Suite 6 Cambridge, MA 02138 @end flushleft @node GNU Free Documentation License, , SIOD copyright, Copying @subsection GNU Free Documentation License @include fdl.texi @node Bibliography, , Copying, Overview @section Bibliography @table @asis @item [IEEE] @cindex IEEE @cite{IEEE Standard 1178-1990. IEEE Standard for the Scheme Programming Language.} IEEE, New York, 1991. @item [R4RS] @cindex R4RS William Clinger and Jonathan Rees, Editors. @ifset html @end ifset Revised(4) Report on the Algorithmic Language Scheme. @ifset html @end ifset @cite{ACM Lisp Pointers} Volume IV, Number 3 (July-September 1991), pp. 1-55. @ifinfo @ref{Top, , , r4rs, Revised(4) Report on the Algorithmic Language Scheme}. @end ifinfo @item [R5RS] @cindex R5RS Richard Kelsey and William Clinger and Jonathan (Rees, editors) @ifset html @end ifset Revised(5) Report on the Algorithmic Language Scheme. @ifset html @end ifset @cite{Higher-Order and Symbolic Computation} Volume 11, Number 1 (1998), pp. 7-105, and @cite{ACM SIGPLAN Notices} 33(9), September 1998. @ifinfo @ref{Top, , , r5rs, Revised(5) Report on the Algorithmic Language Scheme}. @end ifinfo @item [Exrename] @cindex Exrename William Clinger @ifset html @end ifset Hygienic Macros Through Explicit Renaming @ifset html @end ifset @cite{Lisp Pointers} Volume IV, Number 4 (December 1991), pp 17-23. @item [SICP] @cindex SICP Harold Abelson and Gerald Jay Sussman with Julie Sussman. @cite{Structure and Interpretation of Computer Programs.} MIT Press, Cambridge, 1985. @item [Simply] @cindex Simply Brian Harvey and Matthew Wright. @ifset html @end ifset @cite{Simply Scheme: Introducing Computer Science} @ifset html @end ifset MIT Press, 1994 ISBN 0-262-08226-8 @item [SchemePrimer] @cindex SchemePrimer $B8$;tBg(B(Dai Inukai) @ifset html @end ifset @cite{$BF~Lg(BScheme} @ifset html @end ifset 1999$BG/(B12$B7n=iHG(B ISBN4-87966-954-7 @c @item [GUILE] @c @cindex GUILE @c Free Software Foundation @c @ifset html @c @c @end ifset @c Guile: Project GNU's extension language @c @ifset html @c @c @end ifset @item [SLIB] @cindex SLIB Todd R. Eigenschink, Dave Love, and Aubrey Jaffer. @ifset html @end ifset SLIB, The Portable Scheme Library. @ifset html @end ifset Version 2c8, June 2000. @ifinfo @ref{Top, , , slib, SLIB}. @end ifinfo @item [JACAL] @cindex JACAL Aubrey Jaffer. @ifset html @end ifset JACAL Symbolic Mathematics System. @ifset html @end ifset Version 1b0, Sep 1999. @ifinfo @ref{Top, , , jacal, JACAL}. @end ifinfo @end table @table @file @item scm.texi @itemx scm.info Documentation of @code{scm} extensions (beyond Scheme standards). Documentation on the internal representation and how to extend or include @code{scm} in other programs. @item Xlibscm.texi @itemx Xlibscm.info Documentation of the Xlib - SCM Language X Interface. @end table @node Installing SCM, Operational Features, Overview, Top @chapter Installing SCM SCM runs on a wide variety of platforms. ``Distributions'' is the starting point for all platforms. The process described in ``GNU configure and make'' will work on most Unix and GNU/Linux platforms. If it works for you, then you may skip the later sections of ``Installing SCM''. @menu * Distributions:: Source and Binaries * GNU configure and make:: For Unix and GNU/Linux * Building SCM:: * Saving Executable Images:: For Faster Startup * Installation:: * Troubleshooting and Testing:: @end menu @node Distributions, GNU configure and make, Installing SCM, Installing SCM @section Distributions @noindent The SCM homepage contains links to precompiled binaries and source distributions. @noindent Downloads and instructions for installing the precompiled binaries are at @uref{http://people.csail.mit.edu/jaffer/SCM#QuickStart}. @noindent If there is no precompiled binary for your platform, you may be able to build from the source distribution. The rest of these instructions deal with building and installing SCM and SLIB from sources. @noindent Download (both SCM and SLIB of) either the last release or current development snapshot from @uref{http://people.csail.mit.edu/jaffer/SCM#BuildFromSource}. @noindent Unzip both the SCM and SLIB zips. For example, if you are working in @file{/usr/local/src/}, this will create directories @file{/usr/local/src/scm/} and @file{/usr/local/src/slib/}. @node GNU configure and make, Building SCM, Distributions, Installing SCM @section GNU configure and make @file{scm/configure} and @file{slib/configure} are Shell scripts which create the files @file{scm/config.status} and @file{slib/config.status} on Unix and MinGW systems. The @file{config.status} files are used (included) by the Makefile to control where the packages will be installed by @code{make install}. With GNU shell (bash) and utilities, the following commands should build and install SCM and SLIB: @example bash$ (cd slib; ./configure --prefix=/usr/local/) bash$ (cd scm > ./configure --prefix=/usr/local/ > make scmlit > sudo make all > sudo make install) bash$ (cd slib; sudo make install) @end example If the install commands worked, skip to @ref{Testing}. If @file{configure} doesn't work on your system, make @file{scm/config.status} and @file{slib/config.status} be empty files. For additional help on using the @file{configure} script, run @w{@samp{./configure --help}}. @samp{make all} will attempt to create a dumped executable (@pxref{Saving Executable Images}), which has very small startup latency. If that fails, it will try to compile an ordinary @samp{scm} executable. Note that the compilation output may contain error messages; be concerned only if the @samp{make install} transcripts contain errors. @samp{sudo} runs the command after it as user @dfn{root}. On recent GNU/Linux systems, dumping requires that @samp{make all} be run as user root; hence the use of @samp{sudo}. @samp{make install} requires root privileges if you are installing to standard Unix locations as specified to (or defaulted by) @samp{./configure}. Note that this is independent of whether you did @w{@samp{sudo make all}} or @w{@samp{make all}}. @menu * Making scmlit:: * Makefile targets:: @end menu @node Making scmlit, Makefile targets, GNU configure and make, GNU configure and make @subsection Making scmlit @noindent The SCM distribution @file{Makefile} contains rules for making @dfn{scmlit}, a ``bare-bones'' version of SCM sufficient for running @file{build}. @file{build} is a Scheme program used to compile (or create scripts to compile) full featured versions of SCM (@pxref{Building SCM}). To create scmlit, run @w{@samp{make scmlit}} in the @file{scm/} directory. @noindent Makefiles are not portable to the majority of platforms. If you need to compile SCM without @samp{scmlit}, there are several ways to proceed: @itemize @bullet @item Use the @uref{http://people.csail.mit.edu/jaffer/buildscm.html, build} web page to create custom batch scripts for compiling SCM. @item Use SCM on a different platform to run @file{build} to create a script to build SCM; @item Use another implementation of Scheme to run @file{build} to create a script to build SCM; @item Create your own script or @file{Makefile}. @end itemize @subheading Finding SLIB If you didn't create scmlit using @samp{make scmlit}, then you must create a file named @file{scm/require.scm}. For most installations, @file{scm/require.scm} can just be copied from @file{scm/requires.scm}, which is part of the SCM distribution. @noindent If, when executing @samp{scmlit} or @samp{scm}, you get a message like: @example ERROR: "LOAD couldn't find file " "/usr/local/src/scm/require" @end example @noindent then create a file @file{require.scm} in the SCM @dfn{implementation-vicinity} (this is the same directory as where the file @file{Init@value{SCMVERSION}.scm} is). @file{require.scm} should have the contents: @example (define (library-vicinity) "/usr/local/lib/slib/") @end example @noindent where the pathname string @file{/usr/local/lib/slib/} is to be replaced by the pathname into which you unzipped (or installed) SLIB. @noindent Alternatively, you can set the (shell) environment variable @code{SCHEME_LIBRARY_PATH} to the pathname of the SLIB directory (@pxref{SCM Variables, SCHEME_LIBRARY_PATH, Environment Variables}). If set, this environment variable overrides @file{scm/require.scm}. @noindent Absolute pathnames are recommended here; if you use a relative pathname, SLIB can get confused when the working directory is changed (@pxref{I/O-Extensions, chmod}). The way to specify a relative pathname is to append it to the implementation-vicinity, which is absolute: @example (define library-vicinity (let ((lv (string-append (implementation-vicinity) "../slib/"))) (lambda () lv))) @end example @node Makefile targets, , Making scmlit, GNU configure and make @subsection Makefile targets Each of the following four @samp{make} targets creates an executable named @file{scm}. Each target takes its build options from a file with an @samp{.opt} suffix. If that options file doesn't exist, making that target will create the file with the @samp{-F} features: cautious, bignums, arrays, inexact, engineering-notation, and dynamic-linking. Once that @samp{.opt} file exists, you can edit it to your taste and it will be preserved. @table @code @item make scm4 Produces a R4RS executable named @file{scm} lacking hygienic macros (but with defmacro). The build options are taken from @file{scm4.opt}. If build or the executable fails, try removing @samp{dynamic-linking} from @file{scm4.opt}. @item make scm5 R5RS; like @samp{make scm4} but with @samp{-F macro}. The build options are taken from @file{scm5.opt}. If build or the executable fails, try removing @samp{dynamic-linking} from @file{scm5.opt}. @item make dscm4 Produces a R4RS executable named @file{udscm4}, which it starts and dumps to a low startup latency executable named @file{scm}. The build options are taken from @file{udscm4.opt}. If the build fails, then @samp{build scm4} instead. If the dumped executable fails to run, then send me a bug report (and use @w{@samp{build scm4}} until the problem with dump is corrected). @item make dscm5 Like @samp{make dscm4} but with @samp{-F macro}. The build options are taken from @file{udscm5.opt}. If the build fails, then @samp{build scm5} instead. If the dumped executable fails to run, then send me a bug report (and use @w{@samp{build scm5}} until the problem with dump is corrected). @end table @noindent If the above builds fail because of @w{@samp{-F dynamic-linking}}, then (because they can't be dynamically linked) you will likely want to add some other features to the build's @samp{.opt} file. See the @samp{-F} build option in @ref{Build Options}. @noindent If dynamic-linking is working, then you will likely want to compile most of the modules as @dfn{DLL}s. The build options for compiling DLLs are in @file{dlls.opt}. @table @code @item make x.so The @code{Xlib} module; @ref{Top, ,SCM Language X Interface , Xlibscm, Xlibscm}. @item make myturtle Creates a DLL named @file{turtlegr.so} which is a simple graphics API. @item make wbscm.so The @code{wb} module; @ref{Top, ,B-tree database implementation , wb, wb}. Compiling this requires that wb source be in a peer directory to scm. @item make dlls Compiles all the distributed library modules, but not @file{wbscm.so}. Many of the module compiles are recursively invoked in such a way that failure of one (which could be due to a system library not being installed) doesn't cause the top-level @samp{make dlls} to fail. If @samp{make dlls} fails as a whole, it is time to submit a bug report (@pxref{Reporting Problems}). @end table @node Building SCM, Saving Executable Images, GNU configure and make, Installing SCM @section Building SCM @cindex build @cindex build.scm The file @dfn{build} loads the file @dfn{build.scm}, which constructs a relational database of how to compile and link SCM executables. @file{build.scm} has information for the platforms which SCM has been ported to (of which I have been notified). Some of this information is old, incorrect, or incomplete. Send corrections and additions to agj@@alum.mit.edu. @menu * Invoking Build:: * Build Options:: build --help * Compiling and Linking Custom Files:: @end menu @node Invoking Build, Build Options, Building SCM, Building SCM @subsection Invoking Build This section teaches how to use @file{build}, a Scheme program for creating compilation scripts to produce SCM executables and library modules. The options accepted by @samp{build} are documented in @ref{Build Options}. @noindent Use the @emph{any} method if you encounter problems with the other two methods (MS-DOS, Unix). @table @asis @item MS-DOS From the SCM source directory, type @samp{build} followed by up to 9 command line arguments. @item Unix From the SCM source directory, type @samp{./build} followed by command line arguments. @item @emph{any} From the SCM source directory, start @samp{scm} or @samp{scmlit} and type @code{(load "build")}. Alternatively, start @samp{scm} or @samp{scmlit} with the command line argument @samp{-ilbuild}. This method will also work for MS-DOS and Unix. After loading various SLIB modules, the program will print: @example type (b "build ") to build type (b*) to enter build command loop @end example The @samp{b*} procedure enters into a @dfn{build shell} where you can enter commands (with or without the @samp{build}). Blank lines are ignored. To create a build script with all defaults type @samp{build}. If the build-shell encouters an error, you can reenter the build-shell by typing @samp{(b*)}. To exit scm type @samp{(quit)}. @end table @noindent Here is a transcript of an interactive (b*) build-shell. @example bash$ scmlit SCM version 5e7, Copyright (C) 1990-2006 Free Software Foundation. SCM comes with ABSOLUTELY NO WARRANTY; for details type `(terms)'. This is free software, and you are welcome to redistribute it under certain conditions; type `(terms)' for details. > (load "build") ;loading build ; loading /home/jaffer/slib/getparam ; loading /home/jaffer/slib/coerce ... ; done loading build.scm type (b "build ") to build type (b*) to enter build command loop ;done loading build # > (b*) ;loading /home/jaffer/slib/comparse ;done loading /home/jaffer/slib/comparse.scm build> -t exe #! /bin/sh # unix (linux) script created by SLIB/batch Wed Oct 26 17:14:23 2011 # [-p linux] # ================ Write file with C defines rm -f scmflags.h echo '#define IMPLINIT "Init5e7.scm"'>>scmflags.h echo '#define BIGNUMS'>>scmflags.h echo '#define FLOATS'>>scmflags.h echo '#define ARRAYS'>>scmflags.h # ================ Compile C source files gcc -c continue.c scm.c scmmain.c findexec.c script.c time.c repl.c scl.c eval.c sys.c subr.c debug.c unif.c rope.c # ================ Link C object files gcc -rdynamic -o scm continue.o scm.o scmmain.o findexec.o script.o time.o repl.o scl.o eval.o sys.o subr.o debug.o unif.o rope.o -lm -lc "scm" build> -t exe -w myscript.sh "scm" build> (quit) @end example @noindent No compilation was done. The @samp{-t exe} command shows the compile script. The @samp{-t exe -w myscript.sh} line creates a file @file{myscript.sh} containing the compile script. To actually compile and link it, type @samp{./myscript.sh}. @noindent Invoking build without the @samp{-F} option will build or create a shell script with the @code{arrays}, @code{inexact}, and @code{bignums} options as defaults. Invoking @samp{build} with @samp{-F lit -o scmlit} will make a script for compiling @samp{scmlit}. @example bash$ ./build @print{} #! /bin/sh # unix (linux) script created by SLIB/batch # ================ Write file with C defines rm -f scmflags.h echo '#define IMPLINIT "Init@value{SCMVERSION}.scm"'>>scmflags.h echo '#define BIGNUMS'>>scmflags.h echo '#define FLOATS'>>scmflags.h echo '#define ARRAYS'>>scmflags.h # ================ Compile C source files gcc -O2 -c continue.c scm.c scmmain.c findexec.c script.c time.c repl.c scl.c eval.c sys.c subr.c debug.c unif.c rope.c # ================ Link C object files gcc -rdynamic -o scm continue.o scm.o scmmain.o findexec.o script.o time.o repl.o scl.o eval.o sys.o subr.o debug.o unif.o rope.o -lm -lc @end example @noindent To cross compile for another platform, invoke build with the @samp{-p} or @samp{--platform=} option. This will create a script for the platform named in the @samp{-p} or @samp{--platform=} option. @example bash$ ./build -o scmlit -p darwin -F lit @print{} #! /bin/sh # unix (darwin) script created by SLIB/batch # ================ Write file with C defines rm -f scmflags.h echo '#define IMPLINIT "Init@value{SCMVERSION}.scm"'>>scmflags.h # ================ Compile C source files cc -O3 -c continue.c scm.c scmmain.c findexec.c script.c time.c repl.c scl.c eval.c sys.c subr.c debug.c unif.c rope.c # ================ Link C object files mv -f scmlit scmlit~ cc -o scmlit continue.o scm.o scmmain.o findexec.o script.o time.o repl.o scl.o eval.o sys.o subr.o debug.o unif.o rope.o @end example @node Build Options, Compiling and Linking Custom Files, Invoking Build, Building SCM @subsection Build Options @noindent The options to @dfn{build} specify what, where, and how to build a SCM program or dynamically linked module. These options are unrelated to the SCM command line options. @deffn {Build Option} -p @var{platform-name} @deffnx {Build Option} ---platform=@var{platform-name} specifies that the compilation should be for a computer/operating-system combination called @var{platform-name}. @emph{Note@:} The case of @var{platform-name} is distinguised. The current @var{platform-name}s are all lower-case. The platforms defined by table @dfn{platform} in @file{build.scm} are: @end deffn @example @include platform.txi @end example @deffn {Build Option} -f @var{pathname} specifies that the build options contained in @var{pathname} be spliced into the argument list at this point. The use of option files can separate functional features from platform-specific ones. The @file{Makefile} calls out builds with the options in @samp{.opt} files: @table @file @item dlls.opt Options for Makefile targets dlls, myturtle, and x.so. @item gdb.opt Options for udgdbscm and gdbscm. @item libscm.opt Options for libscm.a. @item pg.opt Options for pgscm, which instruments C functions. @item udscm4.opt Options for targets udscm4 and dscm4 (scm). @item udscm5.opt Options for targets udscm5 and dscm5 (scm). @end table The Makefile creates options files it depends on only if they do not already exist. @end deffn @deffn {Build Option} -o @var{filename} @deffnx {Build Option} ---outname=@var{filename} specifies that the compilation should produce an executable or object name of @var{filename}. The default is @samp{scm}. Executable suffixes will be added if neccessary, e.g. @samp{scm} @result{} @samp{scm.exe}. @end deffn @deffn {Build Option} -l @var{libname} @dots{} @deffnx {Build Option} ---libraries=@var{libname} specifies that the @var{libname} should be linked with the executable produced. If compile flags or include directories (@samp{-I}) are needed, they are automatically supplied for compilations. The @samp{c} library is always included. SCM @dfn{features} specify any libraries they need; so you shouldn't need this option often. @end deffn @deffn {Build Option} -D @var{definition} @dots{} @deffnx {Build Option} ---defines=@var{definition} specifies that the @var{definition} should be made in any C source compilations. If compile flags or include directories (@samp{-I}) are needed, they are automatically supplied for compilations. SCM @dfn{features} specify any flags they need; so you shouldn't need this option often. @end deffn @deffn {Build Option} ---compiler-options=@var{flag} specifies that that @var{flag} will be put on compiler command-lines. @end deffn @deffn {Build Option} ---linker-options=@var{flag} specifies that that @var{flag} will be put on linker command-lines. @end deffn @deffn {Build Option} -s @var{pathname} @deffnx {Build Option} ---scheme-initial=@var{pathname} specifies that @var{pathname} should be the default location of the SCM initialization file @file{Init@value{SCMVERSION}.scm}. SCM tries several likely locations before resorting to @var{pathname} (@pxref{File-System Habitat}). If not specified, the current directory (where build is building) is used. @end deffn @deffn {Build Option} -c @var{pathname} @dots{} @deffnx {Build Option} ---c-source-files=@var{pathname} specifies that the C source files @var{pathname} @dots{} are to be compiled. @end deffn @deffn {Build Option} -j @var{pathname} @dots{} @deffnx {Build Option} ---object-files=@var{pathname} specifies that the object files @var{pathname} @dots{} are to be linked. @end deffn @deffn {Build Option} -i @var{call} @dots{} @deffnx {Build Option} ---initialization=@var{call} specifies that the C functions @var{call} @dots{} are to be invoked during initialization. @end deffn @deffn {Build Option} -t @var{build-what} @deffnx {Build Option} ---type=@var{build-what} specifies in general terms what sort of thing to build. The choices are: @table @samp @item exe executable program. @item lib library module. @item dlls archived dynamically linked library object files. @item dll dynamically linked library object file. @end table The default is to build an executable. @end deffn @deffn {Build Option} -h @var{batch-syntax} @deffnx {Build Option} --batch-dialect=@var{batch-syntax} specifies how to build. The default is to create a batch file for the host system. The SLIB file @file{batch.scm} knows how to create batch files for: @itemize @bullet @item unix @item dos @item vms @item amigaos (was amigados) @item system This option executes the compilation and linking commands through the use of the @code{system} procedure. @item *unknown* This option outputs Scheme code. @end itemize @end deffn @deffn {Build Option} -w @var{batch-filename} @deffnx {Build Option} --script-name=@var{batch-filename} specifies where to write the build script. The default is to display it on @code{(current-output-port)}. @end deffn @deffn {Build Option} -F @var{feature} @dots{} @deffnx {Build Option} ---features=@var{feature} specifies to build the given features into the executable. The defined features are: @table @dfn @c @itemx none @c @cindex none @c Lightweight -- no features @include features.txi @end table @end deffn @node Compiling and Linking Custom Files, , Build Options, Building SCM @subsection Compiling and Linking Custom Files @noindent A correspondent asks: @quotation How can we link in our own c files to the SCM interpreter so that we can add our own functionality? (e.g. we have a bunch of tcp functions we want access to). Would this involve changing build.scm or the Makefile or both? @end quotation @noindent (@pxref{Changing Scm} has instructions describing the C code format). @cindex foo.c @cindex Extending Scm Suppose a C file @dfn{foo.c} has functions you wish to add to SCM. To compile and link your file at compile time, use the @samp{-c} and @samp{-i} options to build: @example bash$ ./build -c foo.c -i init_foo @print{} #! /bin/sh rm -f scmflags.h echo '#define IMPLINIT "/home/jaffer/scm/Init@value{SCMVERSION}.scm"'>>scmflags.h echo '#define COMPILED_INITS init_foo();'>>scmflags.h echo '#define BIGNUMS'>>scmflags.h echo '#define FLOATS'>>scmflags.h echo '#define ARRAYS'>>scmflags.h gcc -O2 -c continue.c scm.c findexec.c script.c time.c repl.c scl.c \ eval.c sys.c subr.c unif.c rope.c foo.c gcc -rdynamic -o scm continue.o scm.o findexec.o script.o time.o \ repl.o scl.o eval.o sys.o subr.o unif.o rope.o foo.o -lm -lc @end example @noindent To make a dynamically loadable object file use the @code{-t dll} option: @example bash$ ./build -t dll -c foo.c @print{} #! /bin/sh rm -f scmflags.h echo '#define IMPLINIT "/home/jaffer/scm/Init@value{SCMVERSION}.scm"'>>scmflags.h echo '#define BIGNUMS'>>scmflags.h echo '#define FLOATS'>>scmflags.h echo '#define ARRAYS'>>scmflags.h echo '#define DLL'>>scmflags.h gcc -O2 -fpic -c foo.c gcc -shared -o foo.so foo.o -lm -lc @end example @noindent Once @file{foo.c} compiles correctly (and your SCM build supports dynamic-loading), you can load the compiled file with the Scheme command @code{(load "./foo.so")}. See @ref{Configure Module Catalog} for how to add a compiled dll file to SLIB's catalog. @node Saving Executable Images, Installation, Building SCM, Installing SCM @section Saving Executable Images In SCM, the ability to save running program images is called @dfn{dump} (@pxref{Dump}). In order to make @code{dump} available to SCM, build with feature @samp{dump}. @code{dump}ed executables are compatible with dynamic linking. Most of the code for @dfn{dump} is taken from @file{emacs-19.34/src/unex*.c}. No modifications to the emacs source code were required to use @file{unexelf.c}. Dump has not been ported to all platforms. If @file{unexec.c} or @file{unexelf.c} don't work for you, try using the appropriate @file{unex*.c} file from emacs. The @samp{dscm4} and @samp{dscm5} targets in the SCM @file{Makefile} save images from @file{udscm4} and @file{udscm5} executables respectively. @dfn{Address space layout randomization} interferes with @code{dump}. Here are the fixes for various operating-systems: @table @asis @item Fedora-Core-1 Remove the @samp{#} from the line @samp{#SETARCH = setarch i386} in the @file{Makefile}. @item Fedora-Core-3 @url{http://jamesthornton.com/writing/emacs-compile.html} [For FC3] combreloc has become the default for recent GNU ld, which breaks the unexec/undump on all versions of both Emacs and XEmacs... Override by adding the following to @file{udscm5.opt}: @samp{--linker-options="-z nocombreloc"} @item Linux Kernels later than 2.6.11 @exdent @url{http://www.opensubscriber.com/message/emacs-devel@@gnu.org/1007118.html} mentions the @dfn{exec-shield} feature. Kernels later than 2.6.11 must do (as root): @example echo 0 > /proc/sys/kernel/randomize_va_space @end example before dumping. @file{Makefile} has this @file{randomize_va_space} stuffing scripted for targets @samp{dscm4} and @samp{dscm5}. You must either set @file{randomize_va_space} to 0 or run as root to dump. @item OS-X 10.6 @exdent @url{http://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/dyld.1.html} The dynamic linker uses the following environment variables. They affect any program that uses the dynamic linker. DYLD_NO_PIE Causes dyld to not randomize the load addresses of images in a process where the main executable was built position independent. This can be helpful when trying to reproduce and debug a problem in a PIE. @end table @node Installation, Troubleshooting and Testing, Saving Executable Images, Installing SCM @section Installation Once @code{scmlit}, @code{scm}, and @code{dlls} have been built, these commands will install them to the locations specified when you ran @samp{./configure}: @example bash$ (cd scm; make install) bash$ (cd slib; make install) @end example Note that installation to system directories (like @samp{/usr/bin/}) will require that those commands be run as root: @example bash$ (cd scm; sudo make install) bash$ (cd slib; sudo make install) @end example @node Troubleshooting and Testing, , Installation, Installing SCM @section Troubleshooting and Testing @menu * Problems Compiling:: * Problems Linking:: * Testing:: * Problems Starting:: * Problems Running:: * Reporting Problems:: @end menu @node Problems Compiling, Problems Linking, Troubleshooting and Testing, Troubleshooting and Testing @subsection Problems Compiling @multitable @columnfractions .10 .45 .45 @item FILE @tab PROBLEM / MESSAGE @tab HOW TO FIX @item *.c @tab include file not found. @tab Correct the status of @t{STDC_HEADERS} in scmfig.h. @item @tab @tab fix @t{#include} statement or add @t{#define} for system type to scmfig.h. @item *.c @tab Function should return a value. @tab Ignore. @item @tab Parameter is never used. @tab @item @tab Condition is always false. @tab @item @tab Unreachable code in function. @tab @item scm.c @tab assignment between incompatible types. @tab Change @t{SIGRETTYPE} in scm.c. @item time.c @tab CLK_TCK redefined. @tab incompatablility between and . @item @tab @tab Remove @t{STDC_HEADERS} in scmfig.h. @item @tab @tab Edit to remove incompatability. @item subr.c @tab Possibly incorrect assignment in function lgcd. @tab Ignore. @item sys.c @tab statement not reached. @tab Ignore. @item @tab constant in conditional expression. @tab @item sys.c @tab undeclared, outside of functions. @tab @t{#undef STDC_HEADERS} in scmfig.h. @item scl.c @tab syntax error. @tab @t{#define SYSTNAME} to your system type in scl.c (softtype). @end multitable @node Problems Linking, Testing, Problems Compiling, Troubleshooting and Testing @subsection Problems Linking @multitable @columnfractions .5 .5 @item PROBLEM @tab HOW TO FIX @item _sin etc. missing. @tab Uncomment @t{LIBS} in makefile. @end multitable @node Testing, Problems Starting, Problems Linking, Troubleshooting and Testing @subsection Testing @noindent Loading @file{r4rstest.scm} in the distribution will run an [R4RS] conformance test on @code{scm}. @example > (load "r4rstest.scm") @print{} ;loading r4rstest.scm SECTION(2 1) SECTION(3 4) # # # # @dots{} @end example @noindent Loading @file{pi.scm} in the distribution will enable you to compute digits of pi. @example > (load "pi.scm") ;loading pi.scm ;done loading pi.scm # > (pi 100 5) 00003 14159 26535 89793 23846 26433 83279 50288 41971 69399 37510 58209 74944 59230 78164 06286 20899 86280 34825 34211 70679 ;Evaluation took 550 ms (60 in gc) 36976 cells work, 1548.B other # @end example @subheading Performance @noindent Loading @file{bench.scm} will compute and display performance statistics of SCM running @file{pi.scm}. @samp{make bench} or @samp{make benchlit} appends the performance report to the file @file{BenchLog}, facilitating tracking effects of changes to SCM on performance. @node Problems Starting, Problems Running, Testing, Troubleshooting and Testing @subsection Problems Starting @multitable @columnfractions .5 .5 @item PROBLEM @tab HOW TO FIX @item /bin/bash: scm: program not found @tab Is @samp{scm} in a @samp{$PATH} directory? @item /bin/bash: /usr/local/bin/scm: Permission denied @tab @code{chmod +x /usr/local/bin/scm} @item Opening message and then machine crashes. @tab Change memory model option to C compiler (or makefile). @item @tab Make sure @t{sizet} definition is correct in scmfig.h. @item @tab Reduce the size of @t{HEAP_SEG_SIZE} in setjump.h. @item Input hangs. @tab @t{#define NOSETBUF} @item ERROR: heap: need larger initial. @tab Increase initial heap allocation using -a or @t{INIT_HEAP_SIZE}. @item ERROR: Could not allocate. @tab Check @t{sizet} definition. @item @tab Use 32 bit compiler mode. @item @tab Don't try to run as subproccess. @item remove in scmfig.h and recompile scm. @tab Do so and recompile files. @item add in scmfig.h and recompile scm. @tab @item ERROR: Init@value{SCMVERSION}.scm not found. @tab Assign correct @t{IMPLINIT} in makefile or scmfig.h. @item @tab Define environment variable @t{SCM_INIT_PATH} to be the full pathname of Init@value{SCMVERSION}.scm. @item WARNING: require.scm not found. @tab Define environment variable @t{SCHEME_LIBRARY_PATH} to be the full pathname of the scheme library [SLIB]. @item @tab Change @t{library-vicinity} in Init@value{SCMVERSION}.scm to point to library or remove. @item @tab Make sure the value of @t{(library-vicinity)} has a trailing file separator (like @t{/} or @t{\}). @end multitable @node Problems Running, Reporting Problems, Problems Starting, Troubleshooting and Testing @subsection Problems Running @multitable @columnfractions .5 .5 @item PROBLEM @tab HOW TO FIX @item Runs some and then machine crashes. @tab See above under machine crashes. @item Runs some and then ERROR: @dots{} (after a GC has happened). @tab Remove optimization option to C compiler and recompile. @item @tab @t{#define SHORT_ALIGN} in @file{scmfig.h}. @item Some symbol names print incorrectly. @tab Change memory model option to C compiler (or makefile). @item @tab Check that @t{HEAP_SEG_SIZE} fits within @t{sizet}. @item @tab Increase size of @t{HEAP_SEG_SIZE} (or @t{INIT_HEAP_SIZE} if it is smaller than @t{HEAP_SEG_SIZE}). @item ERROR: Rogue pointer in Heap. @tab See above under machine crashes. @item Newlines don't appear correctly in output files. @tab Check file mode (define OPEN_@dots{} in @file{Init@value{SCMVERSION}.scm}). @item Spaces or control characters appear in symbol names. @tab Check character defines in @file{scmfig.h}. @item Negative numbers turn positive. @tab Check SRS in @file{scmfig.h}. @item ;ERROR: bignum: numerical overflow @tab Increase NUMDIGS_MAX in @file{scmfig.h} and recompile. @item VMS: Couldn't unwind stack. @tab @t{#define CHEAP_CONTINUATIONS} in @file{scmfig.h}. @item VAX: botched longjmp. @end multitable @c @table @asis @c @item Sparc(SUN-4) heap is growing out of control @c You are experiencing a GC problem peculiar to the Sparc. The problem @c is that SCM doesn't know how to clear register windows. Every @c location which is not reused still gets marked at GC time. This @c causes lots of stuff which should be collected to not be. This will @c be a problem with any @emph{conservative} GC until we find what @c instruction will clear the register windows. This problem is @c exacerbated by using lots of call-with-current-continuations. @c A possible fix for dynthrow() is commented out in @file{continue.c}. @c @end table @node Reporting Problems, , Problems Running, Troubleshooting and Testing @subsection Reporting Problems @noindent Reported problems and solutions are grouped under Compiling, Linking, Running, and Testing. If you don't find your problem listed there, you can send a bug report to @code{agj@@alum.mit.edu} or @code{scm-discuss@@gnu.org}. The bug report should include: @enumerate @item The version of SCM (printed when SCM is invoked with no arguments). @item The type of computer you are using. @item The name and version of your computer's operating system. @item The values of the environment variables @code{SCM_INIT_PATH} and @code{SCHEME_LIBRARY_PATH}. @item The name and version of your C compiler. @item If you are using an executable from a distribution, the name, vendor, and date of that distribution. In this case, corresponding with the vendor is recommended. @end enumerate @node Operational Features, The Language, Installing SCM, Top @chapter Operational Features @menu * Invoking SCM:: * SCM Options:: * Invocation Examples:: * SCM Variables:: * SCM Session:: * Editing Scheme Code:: * Debugging Scheme Code:: * Debugging Continuations:: * Errors:: * Memoized Expressions:: * Internal State:: * Scripting:: @end menu @node Invoking SCM, SCM Options, Operational Features, Operational Features @section Invoking SCM @example @exdent @b{ scm } [-a @i{kbytes}] [-muvbiq] @w{[--version]} @w{[--help]} @w{[[-]-no-init-file]} @w{[--no-symbol-case-fold]} @w{[-p @i{int}]} @w{[-r @i{feature}]} @w{[-h @i{feature}]} @w{[-d @i{filename}]} @w{[-f @i{filename}]} @w{[-l @i{filename}]} @w{[-c @i{expression}]} @w{[-e @i{expression}]} @w{[-o @i{dumpname}]} @w{[-- | - | -s]} @w{[@i{filename}]} @w{[@i{arguments} @dots{}]} @end example @noindent Upon startup @code{scm} loads the file specified by by the environment variable @var{SCM_INIT_PATH}. @noindent If @var{SCM_INIT_PATH} is not defined or if the file it names is not present, @code{scm} tries to find the directory containing the executable file. If it is able to locate the executable, @code{scm} looks for the initialization file (usually @file{Init@value{SCMVERSION}.scm}) in platform-dependent directories relative to this directory. See @ref{File-System Habitat} for a blow-by-blow description. @noindent As a last resort (if initialization file cannot be located), the C compile parameter @var{IMPLINIT} (defined in the makefile or @file{scmfig.h}) is tried. @noindent Unless the option @code{-no-init-file} or @code{--no-init-file} occurs in the command line, or if @code{scm} is being invoked as a script, @file{Init@value{SCMVERSION}.scm} checks to see if there is file @file{ScmInit.scm} in the path specified by the environment variable @var{HOME} (or in the current directory if @var{HOME} is undefined). If it finds such a file, then it is loaded. @noindent @file{Init@value{SCMVERSION}.scm} then looks for command input from one of three sources: From an option on the command line, from a file named on the command line, or from standard input. @noindent This explanation applies to SCMLIT or other builds of SCM. @noindent Scheme-code files can also invoke SCM and its variants. @xref{Lexical Conventions, #!}. @node SCM Options, Invocation Examples, Invoking SCM, Operational Features @section Options @noindent The options are processed in the order specified on the command line. @deffn {Command Option} -a k specifies that @code{scm} should allocate an initial heapsize of @var{k} kilobytes. This option, if present, must be the first on the command line. If not specified, the default is @code{INIT_HEAP_SIZE} in source file @file{setjump.h} which the distribution sets at @code{25000*sizeof(cell)}. @end deffn @deffn {Command Option} -no-init-file @deffnx {Command Option} ---no-init-file Inhibits the loading of @file{ScmInit.scm} as described above. @end deffn @deffn {Command Option} --no-symbol-case-fold Symbol (and identifier) names will be case sensitive. @end deffn @deffn {Command Option} ---help prints usage information and URI; then exit. @end deffn @deffn {Command Option} ---version prints version information and exit. @end deffn @deffn {Command Option} -r feature requires @var{feature}. This will load a file from [SLIB] if that @var{feature} is not already provided. If @var{feature} is 2, 2rs, or r2rs; 3, 3rs, or r3rs; 4, 4rs, or r4rs; 5, 5rs, or r5rs; @code{scm} will require the features neccessary to support [R2RS]; [R3RS]; [R4RS]; or [R5RS], respectively. @end deffn @deffn {Command Option} -h feature provides @var{feature}. @end deffn @deffn {Command Option} -l filename @deffnx {Command Option} -f filename loads @var{filename}. @code{Scm} will load the first (unoptioned) file named on the command line if no @code{-c}, @code{-e}, @code{-f}, @code{-l}, or @code{-s} option preceeds it. @end deffn @deffn {Command Option} -d filename Loads SLIB @code{databases} feature and opens @var{filename} as a database. @end deffn @deffn {Command Option} -e expression @deffnx {Command Option} -c expression specifies that the scheme expression @var{expression} is to be evaluated. These options are inspired by @code{perl} and @code{sh} respectively. On Amiga systems the entire option and argument need to be enclosed in quotes. For instance @samp{"-e(newline)"}. @end deffn @deffn {Command Option} -o dumpname saves the current SCM session as the executable program @file{dumpname}. This option works only in SCM builds supporting @code{dump} (@pxref{Dump}). If options appear on the command line after @samp{-o @var{dumpname}}, then the saved session will continue with processing those options when it is invoked. Otherwise the (new) command line is processed as usual when the saved image is invoked. @end deffn @deffn {Command Option} -p level sets the prolixity (verboseness) to @var{level}. This is the same as the @code{scm} command (verobse @var{level}). @end deffn @deffn {Command Option} -v (verbose mode) specifies that @code{scm} will print prompts, evaluation times, notice of loading files, and garbage collection statistics. This is the same as @code{-p3}. @end deffn @deffn {Command Option} -q (quiet mode) specifies that @code{scm} will print no extra information. This is the same as @code{-p0}. @end deffn @deffn {Command Option} -m specifies that subsequent loads, evaluations, and user interactions will be with syntax-rules macro capability. To use a specific syntax-rules macro implementation from [SLIB] (instead of [SLIB]'s default) put @code{-r} @var{macropackage} before @code{-m} on the command line. @end deffn @deffn {Command Option} -u specifies that subsequent loads, evaluations, and user interactions will be without syntax-rules macro capability. Syntax-rules macro capability can be restored by a subsequent @code{-m} on the command line or from Scheme code. @end deffn @deffn {Command Option} -i specifies that @code{scm} should run interactively. That means that @code{scm} will not terminate until the @code{(quit)} or @code{(exit)} command is given, even if there are errors. It also sets the prolixity level to 2 if it is less than 2. This will print prompts, evaluation times, and notice of loading files. The prolixity level can be set by subsequent options. If @code{scm} is started from a tty, it will assume that it should be interactive unless given a subsequent @code{-b} option. @end deffn @deffn {Command Option} -b specifies that @code{scm} should run non-interactively. That means that @code{scm} will terminate after processing the command line or if there are errors. @end deffn @deffn {Command Option} -s specifies, by analogy with @code{sh}, that @code{scm} should run interactively and that further options are to be treated as program aguments. @end deffn @deffn {Command Option} - @deffnx {Command Option} --- specifies that further options are to be treated as program aguments. @end deffn @node Invocation Examples, SCM Variables, SCM Options, Operational Features @section Invocation Examples @table @code @item % scm foo.scm Loads and executes the contents of @file{foo.scm} and then enters interactive session. @item % scm -f foo.scm arg1 arg2 arg3 Parameters @code{arg1}, @code{arg2}, and @code{arg3} are stored in the global list @code{*argv*}; Loads and executes the contents of @file{foo.scm} and exits. @item % scm -s foo.scm arg1 arg2 Sets *argv* to @code{("foo.scm" "arg1" "arg2")} and enters interactive session. @item % scm -e `(write (list-ref *argv* *optind*))' bar Prints @samp{"bar"}. @item % scm -rpretty-print -r format -i Loads @code{pretty-print} and @code{format} and enters interactive session. @item % scm -r5 Loads @code{dynamic-wind}, @code{values}, and syntax-rules macros and enters interactive (with macros) session. @item % scm -r5 -r4 Like above but @code{rev4-optional-procedures} are also loaded. @end table @node SCM Variables, SCM Session, Invocation Examples, Operational Features @section Environment Variables @defvr {Environment Variable} SCM_INIT_PATH is the pathname where @code{scm} will look for its initialization code. The default is the file @file{Init@value{SCMVERSION}.scm} in the source directory. @end defvr @defvr {Environment Variable} SCHEME_LIBRARY_PATH is the [SLIB] Scheme library directory. @end defvr @defvr {Environment Variable} HOME is the directory where @file{Init@value{SCMVERSION}.scm} will look for the user initialization file @file{ScmInit.scm}. @end defvr @defvr {Environment Variable} EDITOR is the name of the program which @code{ed} will call. If @var{EDITOR} is not defined, the default is @samp{ed}. @end defvr @section Scheme Variables @defvar *argv* contains the list of arguments to the program. @code{*argv*} can change during argument processing. This list is suitable for use as an argument to [SLIB] @code{getopt}. @end defvar @defvar *syntax-rules* controls whether loading and interaction support syntax-rules macros. Define this in @file{ScmInit.scm} or files specified on the command line. This can be overridden by subsequent @code{-m} and @code{-u} options. @end defvar @defvar *interactive* controls interactivity as explained for the @code{-i} and @code{-b} options. Define this in @file{ScmInit.scm} or files specified on the command line. This can be overridden by subsequent @code{-i} and @code{-b} options. @end defvar @node SCM Session, Editing Scheme Code, SCM Variables, Operational Features @section SCM Session @itemize @bullet @item Options, file loading and features can be specified from the command line. @xref{System interface, , , scm, SCM}. @xref{Require, , , slib, SLIB}. @item Typing the end-of-file character at the top level session (while SCM is not waiting for parenthesis closure) causes SCM to exit. @item Typing the interrupt character aborts evaluation of the current form and resumes the top level read-eval-print loop. @end itemize @defun quit @defunx quit n @defunx exit @defunx exit n Aliases for @code{exit} (@pxref{System, exit, , slib, SLIB}). On many systems, SCM can also tail-call another program. @xref{I/O-Extensions, execp}. @end defun @deffn {Callback procedure} boot-tail dumped? @code{boot-tail} is called by @code{scm_top_level} just before entering interactive top-level. If @code{boot-tail} calls @code{quit}, then interactive top-level is not entered. @end deffn @defun program-arguments Returns a list of strings of the arguments scm was called with. @end defun @defun getlogin Returns the (login) name of the user logged in on the controlling terminal of the process, or #f if this information cannot be determined. @end defun @noindent For documentation of the procedures @code{getenv} and @code{system} @xref{System Interface, , , slib, SLIB}. SCM extends @code{getenv} as suggested by draft SRFI-98: @defun getenv name Looks up @var{name}, a string, in the program environment. If @var{name} is found a string of its value is returned. Otherwise, @code{#f} is returned. @end defun @defun getenv Returns names and values of all the environment variables as an association-list. @example (getenv) @result{} (("PATH" . "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin") ("USERNAME" . "taro")) @end example @end defun @defun vms-debug If SCM is compiled under VMS this @code{vms-debug} will invoke the VMS debugger. @end defun @node Editing Scheme Code, Debugging Scheme Code, SCM Session, Operational Features @section Editing Scheme Code @defun ed arg1 @dots{} The value of the environment variable @code{EDITOR} (or just @code{ed} if it isn't defined) is invoked as a command with arguments @var{arg1} @dots{}. @end defun @defun ed filename If SCM is compiled under VMS @code{ed} will invoke the editor with a single the single argument @var{filename}. @end defun @table @asis @item Gnu Emacs: Editing of Scheme code is supported by emacs. Buffers holding files ending in .scm are automatically put into scheme-mode. If your Emacs can run a process in a buffer you can use the Emacs command @samp{M-x run-scheme} with SCM. Otherwise, use the emacs command @samp{M-x suspend-emacs}; or see ``other systems'' below. @item Epsilon (MS-DOS): There is lisp (and scheme) mode available by use of the package @samp{LISP.E}. It offers several different indentation formats. With this package, buffers holding files ending in @samp{.L}, @samp{.LSP}, @samp{.S}, and @samp{.SCM} (my modification) are automatically put into lisp-mode. It is possible to run a process in a buffer under Epsilon. With Epsilon 5.0 the command line options @samp{-e512 -m0} are neccessary to manage RAM properly. It has been reported that when compiling SCM with Turbo C, you need to @samp{#define NOSETBUF} for proper operation in a process buffer with Epsilon 5.0. One can also call out to an editor from SCM if RAM is at a premium; See ``under other systems'' below. @item other systems: Define the environment variable @samp{EDITOR} to be the name of the editing program you use. The SCM procedure @code{(ed arg1 @dots{})} will invoke your editor and return to SCM when you exit the editor. The following definition is convenient: @example (define (e) (ed "work.scm") (load "work.scm")) @end example Typing @samp{(e)} will invoke the editor with the file of interest. After editing, the modified file will be loaded. @end table @node Debugging Scheme Code, Debugging Continuations, Editing Scheme Code, Operational Features @section Debugging Scheme Code @noindent The @code{cautious} option of @code{build} (@pxref{Build Options}) supports debugging in Scheme. @table @dfn @item CAUTIOUS If SCM is built with the @samp{CAUTIOUS} flag, then when an error occurs, a @dfn{stack trace} of certain pending calls are printed as part of the default error response. A (memoized) expression and newline are printed for each partially evaluated combination whose procedure is not builtin. See @ref{Memoized Expressions} for how to read memoized expressions. Also as the result of the @samp{CAUTIOUS} flag, both @code{error} and @code{user-interrupt} (invoked by @key{C-c}) to print stack traces and conclude by calling @code{breakpoint} (@pxref{Breakpoints, , , slib, SLIB}) instead of aborting to top level. Under either condition, program execution can be resumed by @code{(continue)}. In this configuration one can interrupt a running Scheme program with @key{C-c}, inspect or modify top-level values, trace or untrace procedures, and continue execution with @code{(continue)}. @end table If @code{verbose} (@pxref{Internal State, verbose}) is called with an argument greater than 2, then the interpreter will check stack size periodically. If the size of stack in use exceeds the C #define @code{STACK_LIMIT} (default is @code{HEAP_SEG_SIZE}), SCM generates a @samp{stack} @code{segment violation}. @noindent There are several SLIB macros which so useful that SCM automatically loads the appropriate module from SLIB if they are invoked. @defmac trace proc1 @dots{} Traces the top-level named procedures given as arguments. @end defmac @defmac trace With no arguments, makes sure that all the currently traced identifiers are traced (even if those identifiers have been redefined) and returns a list of the traced identifiers. @end defmac @defmac untrace proc1 @dots{} Turns tracing off for its arguments. @end defmac @defmac untrace With no arguments, untraces all currently traced identifiers and returns a list of these formerly traced identifiers. @end defmac The routines I use most frequently for debugging are: @defun print arg1 @dots{} @code{Print} writes all its arguments, separated by spaces. @code{Print} outputs a @code{newline} at the end and returns the value of the last argument. One can just insert @samp{(print '