<commit_before>;;;; Copyright (c) 2011-2016 <NAME> <<EMAIL>>
;;;; This code is licensed under the MIT license.

(in-package :sys.int)

;; Undefine the following functions if they're not generic functions.
;; They have early non-generic definitions that these generics overwrite.
;; Undefining them beforehand prevents problems with redefinition.

(when (and (fboundp 'funcallable-instance-lambda-expression)
           (not (typep (fdefinition 'funcallable-instance-lambda-expression)
                       'standard-generic-function)))
  (fmakunbound 'funcallable-instance-lambda-expression))
(defgeneric funcallable-instance-lambda-expression (function)
  (:method ((function function))
    (declare (ignore function))
    (values nil t nil)))

(when (and (fboundp 'funcallable-instance-debug-info)
           (not (typep (fdefinition 'funcallable-instance-debug-info)
                       'standard-generic-function)))
  (fmakunbound 'funcallable-instance-debug-info))
(defgeneric funcallable-instance-debug-info (function)
  (:method ((function function))
    (declare (ignore function))
    nil))

(when (and (fboundp 'funcallable-instance-compiled-function-p)
           (not (typep (fdefinition 'funcallable-instance-compiled-function-p)
                       'standard-generic-function)))
  (fmakunbound 'funcallable-instance-compiled-function-p))
(defgeneric funcallable-instance-compiled-function-p (function)
  (:method ((function function))
    (declare (ignore function))
    nil))

(defmethod print-object ((object structure-object) stream)
  (write-string "#S" stream)
  (let ((class (class-of object)))
    (write (list* (class-name class)
                  (loop
                     for slot in (mezzano.clos:class-slots class)
                     for slot-name = (mezzano.clos:slot-definition-name slot)
                     collect (intern (symbol-name slot-name) "KEYWORD")
                     collect (if (mezzano.clos:structure-slot-definition-fixed-vector slot)
                                 (let ((vec (make-array (mezzano.clos:structure-slot-definition-fixed-vector slot))))
                                   (dotimes (i (mezzano.clos:structure-slot-definition-fixed-vector slot))
                                     (setf (aref vec i) (%struct-vector-slot object class slot-name i)))
                                   vec)
                                 (%struct-slot object class slot-name))))
           :stream stream)))

(defmethod print-object ((object layout) stream)
  (print-unreadable-object (object stream :type t :identity t)
    (format stream "~S" (class-name (layout-class object)))
    (when (layout-obsolete object)
      (format stream " [obsolete]"))))

(defmethod print-object ((object hash-table) stream)
  (print-unreadable-object (object stream :type t :identity t)))

(defmethod print-object ((object mezzano.supervisor:thread) stream)
  (print-unreadable-object (object stream :type t :identity t)
    (format stream "~S ~S"
            (mezzano.supervisor:thread-name object)
            (mezzano.supervisor:thread-state object))))

(defmethod print-object ((object mezzano.supervisor::disk) stream)
  (print-unreadable-object (object stream :identity t)
    (format stream "Disk")
    (when (typep (mezzano.supervisor::disk-device object) 'mezzano.supervisor::partition)
      (format stream " Partition on ~S" (mezzano.supervisor::partition-disk (mezzano.supervisor::disk-device object))))))

(defmethod print-object ((object mezzano.supervisor::wait-queue) stream)
  (print-unreadable-object (object stream :type t :identity t)
    (format stream "~S" (mezzano.supervisor::wait-queue-name object))))

(defmethod print-object ((object mezzano.supervisor::mutex) stream)
  (print-unreadable-object (object stream :type t :identity t)
    (format stream "~S" (mezzano.supervisor::mutex-name object))
    (let ((owner (mezzano.supervisor::mutex-owner object)))
      (if owner
          (format stream " held by ~S" owner)
          (format stream " unlocked")))))

(defmethod print-object ((object mezzano.supervisor::condition-variable) stream)
  (print-unreadable-object (object stream :type t :identity t)
    (format stream "~S" (mezzano.supervisor::condition-variable-name object))))

(defmethod print-object ((object package) stream)
  (print-unreadable-object (object stream :type t)
    (format stream "~:(~S~)" (package-shortest-name object))))

(defmethod print-object ((o structure-definition) stream)
  (print-unreadable-object (o stream :identity t :type t)
    (write (structure-definition-name o) :stream stream)))

(defmethod print-object ((o function-reference) stream)
  (print-unreadable-object (o stream :identity t :type t)
    (write (function-reference-name o) :stream stream)))

(defmethod print-object ((o mezzano.runtime::symbol-value-cell) stream)
  (print-unreadable-object (o stream :identity t :type t)
    (format stream "~A~A"
            (mezzano.runtime::symbol-value-cell-symbol o)
            (if (mezzano.runtime::symbol-global-value-cell-p o)
                " [global]"
                ""))))

(defmethod print-object ((o weak-pointer) stream)
  (print-unreadable-object (o stream :identity t :type t)
    (multiple-value-bind (key value livep)
        (weak-pointer-pair o)
      (cond (livep
             (if (eql key value)
                 (format stream "pointing to ~S" value)
                 (format stream "with key ~S pointing to ~S" key value)))
            (t
             (format stream "dead"))))))

(defmethod print-object ((o weak-pointer-vector) stream)
  (print-unreadable-object (o stream :identity t :type t)
    (let ((entries (loop
                      for i below (weak-pointer-vector-length o)
                      collect (multiple-value-bind (key value livep)
                                  (weak-pointer-vector-pair o i)
                                (if livep
                                    (if (and key (eql key value))
                                        key
                                        (cons key value))
                                    nil)))))
      (format stream "~:S" entries))))

(defmethod print-object ((o byte) stream)
  (print-unreadable-object (o stream :type t)
    (format stream ":Size ~D :Position ~D"
            (byte-size o) (byte-position o))))

(defmethod print-object ((object mezzano.supervisor.pci:pci-device) stream)
  (print-unreadable-object (object stream :type t)
    (multiple-value-bind (bus device function)
        (mezzano.supervisor.pci:pci-device-location object)
      (format stream "~2,'0X:~2,'0X:~X~A"
              bus device function
              (if (eql (mezzano.supervisor.pci:pci-device-boot-id object)
                       (mezzano.supervisor:current-boot-id))
                  ""
                  " (stale)")))))

(defmethod print-object ((object mezzano.supervisor::cpu) stream)
  (print-unreadable-object (object stream :type t :identity t)
    (format stream "~D ~S" (mezzano.supervisor::cpu-apic-id object) (mezzano.supervisor::cpu-state object))))

(defmethod print-object ((object mezzano.delimited-continuations:delimited-continuation) stream)
  (print-unreadable-object (object stream :type t :identity t)
    (if (mezzano.delimited-continuations:resumable-p object)
        (format stream "resumable")
        (format stream "consumed"))))

(defmethod print-object ((object bit-vector) stream)
  (if *print-array*
      (write-bit-vector object stream)
      (call-next-method)))

(defmethod print-object ((object vector) stream)
  (if *print-array*
      (write-vector object stream)
      (call-next-method)))

(defmethod print-object ((object array) stream)
  (cond (*print-array*
         (write-char #\# stream)
         (write (array-rank object) :stream stream :base 10)
         (write-char #\A stream)
         (labels ((print-level (dims index)
                    (cond ((null dims)
                           (write (row-major-aref object index) :stream stream)
                           (1+ index))
                          (t
                           (write-char #\( stream)
                           (dotimes (i (first dims))
                             (setf index (print-level (rest dims) index))
                             (when (not (eql i (1- (first dims))))<commit_msg>Fix printing of arrays when *PRINT-RADIX* is true<commit_after>;;;; Copyright (c) 2011-2016 <NAME> <<EMAIL>>
;;;; This code is licensed under the MIT license.

(in-package :sys.int)

;; Undefine the following functions if they're not generic functions.
;; They have early non-generic definitions that these generics overwrite.
;; Undefining them beforehand prevents problems with redefinition.

(when (and (fboundp 'funcallable-instance-lambda-expression)
           (not (typep (fdefinition 'funcallable-instance-lambda-expression)
                       'standard-generic-function)))
  (fmakunbound 'funcallable-instance-lambda-expression))
(defgeneric funcallable-instance-lambda-expression (function)
  (:method ((function function))
    (declare (ignore function))
    (values nil t nil)))

(when (and (fboundp 'funcallable-instance-debug-info)
           (not (typep (fdefinition 'funcallable-instance-debug-info)
                       'standard-generic-function)))
  (fmakunbound 'funcallable-instance-debug-info))
(defgeneric funcallable-instance-debug-info (function)
  (:method ((function function))
    (declare (ignore function))
    nil))

(when (and (fboundp 'funcallable-instance-compiled-function-p)
           (not (typep (fdefinition 'funcallable-instance-compiled-function-p)
                       'standard-generic-function)))
  (fmakunbound 'funcallable-instance-compiled-function-p))
(defgeneric funcallable-instance-compiled-function-p (function)
  (:method ((function function))
    (declare (ignore function))
    nil))

(defmethod print-object ((object structure-object) stream)
  (write-string "#S" stream)
  (let ((class (class-of object)))
    (write (list* (class-name class)
                  (loop
                     for slot in (mezzano.clos:class-slots class)
                     for slot-name = (mezzano.clos:slot-definition-name slot)
                     collect (intern (symbol-name slot-name) "KEYWORD")
                     collect (if (mezzano.clos:structure-slot-definition-fixed-vector slot)
                                 (let ((vec (make-array (mezzano.clos:structure-slot-definition-fixed-vector slot))))
                                   (dotimes (i (mezzano.clos:structure-slot-definition-fixed-vector slot))
                                     (setf (aref vec i) (%struct-vector-slot object class slot-name i)))
                                   vec)
                                 (%struct-slot object class slot-name))))
           :stream stream)))

(defmethod print-object ((object layout) stream)
  (print-unreadable-object (object stream :type t :identity t)
    (format stream "~S" (class-name (layout-class object)))
    (when (layout-obsolete object)
      (format stream " [obsolete]"))))

(defmethod print-object ((object hash-table) stream)
  (print-unreadable-object (object stream :type t :identity t)))

(defmethod print-object ((object mezzano.supervisor:thread) stream)
  (print-unreadable-object (object stream :type t :identity t)
    (format stream "~S ~S"
            (mezzano.supervisor:thread-name object)
            (mezzano.supervisor:thread-state object))))

(defmethod print-object ((object mezzano.supervisor::disk) stream)
  (print-unreadable-object (object stream :identity t)
    (format stream "Disk")
    (when (typep (mezzano.supervisor::disk-device object) 'mezzano.supervisor::partition)
      (format stream " Partition on ~S" (mezzano.supervisor::partition-disk (mezzano.supervisor::disk-device object))))))

(defmethod print-object ((object mezzano.supervisor::wait-queue) stream)
  (print-unreadable-object (object stream :type t :identity t)
    (format stream "~S" (mezzano.supervisor::wait-queue-name object))))

(defmethod print-object ((object mezzano.supervisor::mutex) stream)
  (print-unreadable-object (object stream :type t :identity t)
    (format stream "~S" (mezzano.supervisor::mutex-name object))
    (let ((owner (mezzano.supervisor::mutex-owner object)))
      (if owner
          (format stream " held by ~S" owner)
          (format stream " unlocked")))))

(defmethod print-object ((object mezzano.supervisor::condition-variable) stream)
  (print-unreadable-object (object stream :type t :identity t)
    (format stream "~S" (mezzano.supervisor::condition-variable-name object))))

(defmethod print-object ((object package) stream)
  (print-unreadable-object (object stream :type t)
    (format stream "~:(~S~)" (package-shortest-name object))))

(defmethod print-object ((o structure-definition) stream)
  (print-unreadable-object (o stream :identity t :type t)
    (write (structure-definition-name o) :stream stream)))

(defmethod print-object ((o function-reference) stream)
  (print-unreadable-object (o stream :identity t :type t)
    (write (function-reference-name o) :stream stream)))

(defmethod print-object ((o mezzano.runtime::symbol-value-cell) stream)
  (print-unreadable-object (o stream :identity t :type t)
    (format stream "~A~A"
            (mezzano.runtime::symbol-value-cell-symbol o)
            (if (mezzano.runtime::symbol-global-value-cell-p o)
                " [global]"
                ""))))

(defmethod print-object ((o weak-pointer) stream)
  (print-unreadable-object (o stream :identity t :type t)
    (multiple-value-bind (key value livep)
        (weak-pointer-pair o)
      (cond (livep
             (if (eql key value)
                 (format stream "pointing to ~S" value)
                 (format stream "with key ~S pointing to ~S" key value)))
            (t
             (format stream "dead"))))))

(defmethod print-object ((o weak-pointer-vector) stream)
  (print-unreadable-object (o stream :identity t :type t)
    (let ((entries (loop
                      for i below (weak-pointer-vector-length o)
                      collect (multiple-value-bind (key value livep)
                                  (weak-pointer-vector-pair o i)
                                (if livep
                                    (if (and key (eql key value))
                                        key
                                        (cons key value))
                                    nil)))))
      (format stream "~:S" entries))))

(defmethod print-object ((o byte) stream)
  (print-unreadable-object (o stream :type t)
    (format stream ":Size ~D :Position ~D"
            (byte-size o) (byte-position o))))

(defmethod print-object ((object mezzano.supervisor.pci:pci-device) stream)
  (print-unreadable-object (object stream :type t)
    (multiple-value-bind (bus device function)
        (mezzano.supervisor.pci:pci-device-location object)
      (format stream "~2,'0X:~2,'0X:~X~A"
              bus device function
              (if (eql (mezzano.supervisor.pci:pci-device-boot-id object)
                       (mezzano.supervisor:current-boot-id))
                  ""
                  " (stale)")))))

(defmethod print-object ((object mezzano.supervisor::cpu) stream)
  (print-unreadable-object (object stream :type t :identity t)
    (format stream "~D ~S" (mezzano.supervisor::cpu-apic-id object) (mezzano.supervisor::cpu-state object))))

(defmethod print-object ((object mezzano.delimited-continuations:delimited-continuation) stream)
  (print-unreadable-object (object stream :type t :identity t)
    (if (mezzano.delimited-continuations:resumable-p object)
        (format stream "resumable")
        (format stream "consumed"))))

(defmethod print-object ((object bit-vector) stream)
  (if *print-array*
      (write-bit-vector object stream)
      (call-next-method)))

(defmethod print-object ((object vector) stream)
  (if *print-array*
      (write-vector object stream)
      (call-next-method)))

(defmethod print-object ((object array) stream)
  (cond (*print-array*
         (write-char #\# stream)
         (write (array-rank object) :stream stream :base 10 :radix nil)
         (write-char #\A stream)
         (labels ((print-level (dims index)
                    (cond ((null dims)
                           (write (row-major-aref object index) :stream stream)
                           (1+ index))
                          (t
                           (write-char #\( stream)
                           (dotimes (i (first dims))
                             (setf index (print-level (rest dims) index))
                             (when (not (eql i (1- (first dims))))
{'fraction_non_alphanumeric': 0.12791185100904245, 'fraction_numerical': 0.0019162824121204862, 'mean_word_length': 2.5254380409541906, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3795129', 'n_tokens_mistral': 4874, 'n_tokens_neox': 4682, 'n_words': 1286}