Add primitive dynamic loading ability to the microcode.
authorGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Sat, 28 Aug 1993 05:45:25 +0000 (05:45 +0000)
committerGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Sat, 28 Aug 1993 05:45:25 +0000 (05:45 +0000)
v7/src/microcode/primutl.c
v7/src/microcode/syscall.h
v7/src/microcode/unxutl/ymkfile
v7/src/microcode/usrdef.h
v7/src/microcode/utabmd.scm
v7/src/microcode/version.h
v8/src/microcode/utabmd.scm
v8/src/microcode/version.h

index 6a1c4fabcd647eef1f4b90b067a693ee33492f94..41338040e60e2f6faa2446d1267b9d7a35fb18e0 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: primutl.c,v 9.64 1993/08/04 22:21:35 cph Exp $
+$Id: primutl.c,v 9.65 1993/08/28 05:42:28 gjr Exp $
 
 Copyright (c) 1988-1993 Massachusetts Institute of Technology
 
@@ -90,6 +90,7 @@ extern SCHEME_OBJECT
   EXFUN (make_primitive, (char *)),
   EXFUN (find_primitive, (SCHEME_OBJECT, Boolean, Boolean, int)),
   EXFUN (declare_primitive, (char *, primitive_procedure_t, int, int, char *)),
+  EXFUN (install_primitive, (char *, primitive_procedure_t, int, int, char *)),
   EXFUN (dump_renumber_primitive, (SCHEME_OBJECT)),
   * EXFUN (initialize_primitive_table, (SCHEME_OBJECT *, SCHEME_OBJECT *)),
   * EXFUN (cons_primitive_table, (SCHEME_OBJECT *, SCHEME_OBJECT *, long *)),
@@ -461,19 +462,11 @@ DEFUN_VOID (initialize_primitives)
   return;
 }
 \f
-/* declare_primitive returns SHARP_F if it could not allocate
-   the storage needed for the new primitive, or a primitive object.
-   The primitive object may correspond to a pre-existend primitive
-   if there is already a primitive by the same name.
-   If it is a new primitive, its PRIMITIVE_NUMBER will be the
-   previous value of MAX_PRIMITIVE.
-   Note that it can return the value of an old primitive if it
-   was previously unimplemented and the arity matches.
- */
-
-SCHEME_OBJECT
-DEFUN (declare_primitive, (name, code, nargs_lo, nargs_hi, docstr),
-       char * name
+static SCHEME_OBJECT
+DEFUN (declare_primitive_internal,
+       (override_p, code, nargs_lo, nargs_hi, docstr),
+       Boolean override_p
+       AND char * name
        AND primitive_procedure_t code
        AND int nargs_lo
        AND int nargs_hi
@@ -482,16 +475,19 @@ DEFUN (declare_primitive, (name, code, nargs_lo, nargs_hi, docstr),
 {
   int index;
   SCHEME_OBJECT primitive;
+  char * ndocstr = docstr;
   node prim = (tree_lookup (prim_procedure_tree, name));
 
   if (prim != ((node) NULL))
   {
     index = prim->value;
     primitive = (MAKE_PRIMITIVE_OBJECT (prim->value));
-    if ((IMPLEMENTED_PRIMITIVE_P (primitive))
-       || (((PRIMITIVE_ARITY (primitive)) != nargs_hi)
-           && ((PRIMITIVE_ARITY (primitive)) != UNKNOWN_PRIMITIVE_ARITY)))
-      return (primitive);
+    if ((((PRIMITIVE_ARITY (primitive)) != nargs_hi)
+        && ((PRIMITIVE_ARITY (primitive)) != UNKNOWN_PRIMITIVE_ARITY))
+       || ((IMPLEMENTED_PRIMITIVE_P (primitive)) && (! override_p)))
+      return (LONG_TO_UNSIGNED_FIXNUM (PRIMITIVE_NUMBER (primitive)));
+    if (docstr == ((char *) NULL))
+      ndocstr = Primitive_Documentation_Table[index];
   }
   else
   {
@@ -518,13 +514,53 @@ DEFUN (declare_primitive, (name, code, nargs_lo, nargs_hi, docstr),
 
   Primitive_Procedure_Table[index]     = code;
   Primitive_Arity_Table[index]         = nargs_hi;
-  Primitive_Count_Table[index]         = (nargs_hi
-                                         * (sizeof (SCHEME_OBJECT)));
-  Primitive_Documentation_Table[index] = docstr;
+  Primitive_Count_Table[index]         = (nargs_hi * (sizeof (SCHEME_OBJECT)));
+  Primitive_Documentation_Table[index] = ndocstr;
   UPDATE_PRIMITIVE_TABLE_HOOK (index, (index + 1));
   return (primitive);
 }
 \f
+/* declare_primitive installs a new primitive in the system.
+   It returns:
+   - A primitive object if it succeeds.
+   - SHARP_F if there was a problem trying to install it (e.g. out of memory).
+   - A fixnum whose value is the number of the pre-existing primitive
+     that it would replace.
+   Note that even if a primitive is returned, its number may not
+   be the previous value of MAX_PRIMITIVE, since the system may
+   have pre-existent references to the previously-unimplemented primitive.
+ */
+
+SCHEME_OBJECT
+DEFUN (declare_primitive, (name, code, nargs_lo, nargs_hi, docstr),
+       char * name
+       AND primitive_procedure_t code
+       AND int nargs_lo
+       AND int nargs_hi
+       AND char * docstr)
+{
+  return (declare_primitive_internal (false, name, code,
+                                     nargs_lo, nargs_hi, docstr));
+}
+
+/* install_primitive is similar to declare_primitive, but will
+   replace a pre-existing primitive if the arities are consistent.
+   If they are not, it returns a fixnum whose value is the index
+   of the pre-existing primitive.
+ */
+
+SCHEME_OBJECT
+DEFUN (install_primitive, (name, code, nargs_lo, nargs_hi, docstr),
+       char * name
+       AND primitive_procedure_t code
+       AND int nargs_lo
+       AND int nargs_hi
+       AND char * docstr)
+{
+  return (declare_primitive_internal (true, name, code,
+                                     nargs_lo, nargs_hi, docstr));
+}
+\f
 /*
   make_primitive returns a primitive object,
   constructing one if necessary.
@@ -533,11 +569,16 @@ DEFUN (declare_primitive, (name, code, nargs_lo, nargs_hi, docstr),
 SCHEME_OBJECT
 DEFUN (make_primitive, (name), char * name)
 {
-  return (declare_primitive (name,
-                            Prim_unimplemented,
-                            UNKNOWN_PRIMITIVE_ARITY,
-                            UNKNOWN_PRIMITIVE_ARITY,
-                            ((char *) NULL)));
+  SCHEME_OBJECT result;
+
+  result = (declare_primitive (name,
+                              Prim_unimplemented,
+                              UNKNOWN_PRIMITIVE_ARITY,
+                              UNKNOWN_PRIMITIVE_ARITY,
+                              ((char *) NULL)));
+  return ((result == SHARP_F)
+         ? SHARP_F
+         : (OBJECT_NEW_TYPE (TC_PRIMITIVE, result)));
 }
 
 /* This returns all sorts of different things that the runtime
index 2c0187dd1d0e664fa64f60bfe778ffa8d54574e5..e96701e16836a8ff0d982e9e3367a44c0a3e2670 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: syscall.h,v 1.2 1993/08/03 17:40:04 gjr Exp $
+$Id: syscall.h,v 1.3 1993/08/28 05:43:32 gjr Exp $
 
 Copyright (c) 1993 Massachusetts Institute of Technology
 
@@ -96,7 +96,8 @@ enum syscall_names
   syscall_write,
   syscall_stat,
   syscall_lstat,
-  syscall_mktime
+  syscall_mktime,
+  syscall_dld
 };
 \f
 enum syserr_names
index b8dad10d5c96ff720e4bc8b7a0746e7cd42e50a7..9f1cde4d2cb74505ee885729b75fb219eb01b431 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: ymkfile,v 1.77 1993/08/24 18:27:43 bal Exp $
+$Id: ymkfile,v 1.78 1993/08/28 05:45:00 gjr Exp $
 
 Copyright (c) 1989-1993 Massachusetts Institute of Technology
 
@@ -87,6 +87,10 @@ MIT in each case. */
 #define C_OPTIMIZE_SWITCH -O
 #endif
 
+#ifndef LD_SWITCH_CF
+#define LD_SWITCH_CF
+#endif
+
 #ifndef LD_SWITCH_SYSTEM
 #define LD_SWITCH_SYSTEM
 #endif
@@ -297,9 +301,9 @@ MACHINE_OBJECTS = cmpint.o
 GC_HEAD_FILES = gccode.h cmpgc.h
 #endif /* PROC_TYPE_KNOWN */
 
-USER_PRIM_SOURCES =
-USER_PRIM_OBJECTS =
-USER_LIBS =
+USER_PRIM_SOURCES = $(CF_USER_PRIM_SOURCES)
+USER_PRIM_OBJECTS = $(CF_USER_PRIM_OBJECTS)
+USER_LIBS = $(CF_USER_LIBS)
 
 SHELL = /bin/sh
 
@@ -341,7 +345,7 @@ AS = as
 #define LIB_DEBUG
 #endif
 
-LDFLAGS = LD_SWITCH_SYSTEM LD_SWITCH_MACHINE C_DEBUG_SWITCH
+LDFLAGS = LD_SWITCH_CF LD_SWITCH_SYSTEM LD_SWITCH_MACHINE C_DEBUG_SWITCH
 
 CFLAGS = -DMIT_SCHEME C_OPTIMIZE_SWITCH C_DEBUG_SWITCH C_SWITCH_MACHINE C_SWITCH_SYSTEM C_SWITCH_FEATURES $(MACHINE_SWITCHES)
 
index a55c0811c370c8f0ecdb574c880147a13915ff6b..63da155c9ba7a16ed45772d6c850e3f45a6ddced 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: usrdef.h,v 9.40 1993/08/03 08:30:02 gjr Exp $
+$Id: usrdef.h,v 9.41 1993/08/28 05:43:00 gjr Exp $
 
 Copyright (c) 1987-1993 Massachusetts Institute of Technology
 
@@ -54,6 +54,9 @@ extern long MAX_STATIC_PRIMITIVE;
 extern SCHEME_OBJECT
   EXFUN (declare_primitive, (char *, primitive_procedure_t, int, int, char *));
 
+extern SCHEME_OBJECT
+  EXFUN (install_primitive, (char *, primitive_procedure_t, int, int, char *));
+
 extern void
   EXFUN (Microcode_Termination, (int)),
   EXFUN (signal_error_from_primitive, (long));
index 90cac649e724f64b414b7867dce3e0a9b3309641..3b7fd5070465ee7f47513d4f62a833bef2f36621 100644 (file)
@@ -1,6 +1,6 @@
 ;;; -*-Scheme-*-
 ;;;
-;;; $Id: utabmd.scm,v 9.68 1993/08/23 22:30:08 cph Exp $
+;;; $Id: utabmd.scm,v 9.69 1993/08/28 05:44:07 gjr Exp $
 ;;;
 ;;;    Copyright (c) 1987-1993 Massachusetts Institute of Technology
 ;;;
               STAT
               LSTAT
               MKTIME
+              DYNAMIC-LOAD
               ))
 \f
 ;;; [] System-call errors
 
 ;;; This identification string is saved by the system.
 
-"$Id: utabmd.scm,v 9.68 1993/08/23 22:30:08 cph Exp $"
\ No newline at end of file
+"$Id: utabmd.scm,v 9.69 1993/08/28 05:44:07 gjr Exp $"
\ No newline at end of file
index 22555cb0a6da2d336f4d3e9e9bff8c160281ac8e..1ac7e237224e11e4301b8a1b896f4e7ab2fa3f92 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: version.h,v 11.138 1993/08/22 22:39:06 gjr Exp $
+$Id: version.h,v 11.139 1993/08/28 05:45:25 gjr Exp $
 
 Copyright (c) 1988-1993 Massachusetts Institute of Technology
 
@@ -46,5 +46,5 @@ MIT in each case. */
 #define VERSION                11
 #endif
 #ifndef SUBVERSION
-#define SUBVERSION     138
+#define SUBVERSION     139
 #endif
index 90cac649e724f64b414b7867dce3e0a9b3309641..3b7fd5070465ee7f47513d4f62a833bef2f36621 100644 (file)
@@ -1,6 +1,6 @@
 ;;; -*-Scheme-*-
 ;;;
-;;; $Id: utabmd.scm,v 9.68 1993/08/23 22:30:08 cph Exp $
+;;; $Id: utabmd.scm,v 9.69 1993/08/28 05:44:07 gjr Exp $
 ;;;
 ;;;    Copyright (c) 1987-1993 Massachusetts Institute of Technology
 ;;;
               STAT
               LSTAT
               MKTIME
+              DYNAMIC-LOAD
               ))
 \f
 ;;; [] System-call errors
 
 ;;; This identification string is saved by the system.
 
-"$Id: utabmd.scm,v 9.68 1993/08/23 22:30:08 cph Exp $"
\ No newline at end of file
+"$Id: utabmd.scm,v 9.69 1993/08/28 05:44:07 gjr Exp $"
\ No newline at end of file
index 22555cb0a6da2d336f4d3e9e9bff8c160281ac8e..1ac7e237224e11e4301b8a1b896f4e7ab2fa3f92 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: version.h,v 11.138 1993/08/22 22:39:06 gjr Exp $
+$Id: version.h,v 11.139 1993/08/28 05:45:25 gjr Exp $
 
 Copyright (c) 1988-1993 Massachusetts Institute of Technology
 
@@ -46,5 +46,5 @@ MIT in each case. */
 #define VERSION                11
 #endif
 #ifndef SUBVERSION
-#define SUBVERSION     138
+#define SUBVERSION     139
 #endif