<commit_before>(in-package #:sys.int)

(declaim (special * ** ***
                  + ++ +++
                  / // ///
                  -))

(defun repl ()
  (let ((* nil) (** nil) (*** nil)
        (/ nil) (// nil) (/// nil)
        (+ nil) (++ nil) (+++ nil)
        (- nil))
    (loop
       (with-simple-restart (abort "Return to READ-EVAL-PRINT loop.")
         (fresh-line)
         (write-char #\>)
         (let ((form (read)))
           (fresh-line)
           (let ((result (multiple-value-list (let ((- form))
                                                (eval form)))))
             (setf *** **
                   ** *
                   * (first result)
                   /// //
                   // /
                   / result
                   +++ ++
                   ++ +
                   + form)
             (when result
               (dolist (v result)
                 (fresh-line)
                 (write v)))))))))

(defun run ()
  (sys.net::net-setup)
  (when (null sys.graphics::*screens*)
    (cond (*bochs-framebuffer*
           (sys.graphics::register-screen :bochs *bochs-framebuffer* *bochs-back-buffer* 'bochs-flip-buffer))
          ((eql (first *cold-stream-screen*) :framebuffer)
           (let ((buffer (make-array (array-dimensions (second *cold-stream-screen*))
                                     :element-type '(unsigned-byte 32)))
                 (width (second (array-dimensions (second *cold-stream-screen*))))
                 (height (first (array-dimensions (second *cold-stream-screen*)))))
             (sys.graphics::register-screen :cold-framebuffer buffer buffer
                                            (lambda ()
                                              (%bitblt height width buffer 0 0 (second *cold-stream-screen*) 0 0)))))
          ((typep *terminal-io* 'framebuffer-stream)
           (let ((fb (slot-value *terminal-io* 'framebuffer))
                 (buffer (make-array (array-dimensions fb)
                                     :element-type '(unsigned-byte 32)))
                 (width (second (array-dimensions fb)))
                 (height (first (array-dimensions fb))))
             (sys.graphics::register-screen :framebuffer buffer buffer
                                            (lambda ()
                                              (%bitblt height width buffer 0 0 fb 0 0)))))
          (t (error "No screens."))))
  (sys.graphics::invoke-graphics))

(defun hexdump-range (start end &optional stream)
  (when (< start end)
    (write-sequence (make-array (- end start)
                                :element-type '(unsigned-byte 8)
                                :memory (+ #x8000000000 start))
                    stream)))

(defmacro with-deferred-gc (options &body body)
  "Execute BODY with the garbage collector deferred.
BODY must not allocate!"
  `(progn ,@body))

(defgeneric documentation (x doc-type))
(defgeneric (setf documentation) (new-value x doc-type))

(defmethod documentation (x doc-type) nil)
(defmethod (setf documentation) (new-value x doc-type) new-value)

;; (%cpuid leaf ecx) -> eax ebx ecx edx
(sys.int::define-lap-function %cpuid ()
  (sys.lap-x86:mov64 :rax :r8)
  (sys.lap-x86:sar64 :rax 3)
  (sys.lap-x86:mov64 :rcx :r9)
  (sys.lap-x86:sar64 :rcx 3)
  (sys.lap-x86:cpuid)
  (sys.lap-x86:lea64 :r8 ((:rax 8)))
  (sys.lap-x86:lea64 :r9 ((:rbx 8)))
  (sys.lap-x86:lea64 :r10 ((:rcx 8)))
  (sys.lap-x86:lea64 :r11 ((:rdx 8)))
  (sys.lap-x86:mov32 :ecx #.(ash 4 3))
  (sys.lap-x86:mov64 :rbx :lsp)
  (sys.lap-x86:ret))

(defun cpuid (leaf &optional (rcx 0))
  (check-type leaf (unsigned-byte 32))
  (check-type rcx (unsigned-byte 32))
  (%cpuid leaf rcx))

(defun decode-cpuid-vendor (vendor-1 vendor-2 vendor-3)
  (let ((vendor (make-string (* 4 3))))
    (setf (char vendor 0) (code-char (ldb (byte 8 0) vendor-1))
          (char vendor 1) (code-char (ldb (byte 8 8) vendor-1))
          (char vendor 2) (code-char (ldb (byte 8 16) vendor-1))
          (char vendor 3) (code-char (ldb (byte 8 24) vendor-1))
          (char vendor 4) (code-char (ldb (byte 8 0) vendor-2))
          (char vendor 5) (code-char (ldb (byte 8 8) vendor-2))
          (char vendor 6) (code-char (ldb (byte 8 16) vendor-2))
          (char vendor 7) (code-char (ldb (byte 8 24) vendor-2))
          (char vendor 8) (code-char (ldb (byte 8 0) vendor-3))
          (char vendor 9) (code-char (ldb (byte 8 8) vendor-3))
          (char vendor 10) (code-char (ldb (byte 8 16) vendor-3))
          (char vendor 11) (code-char (ldb (byte 8 24) vendor-3)))
    vendor))

(defun make-string (size &key initial-element (element-type 'character))
  (if initial-element
      (make-array size :element-type element-type :initial-element initial-element)
      (make-array size :element-type element-type)))

(defvar *load-verbose* nil)
(defvar *load-print* nil)

(defun load-lisp-source (stream)
  (let ((*readtable* *readtable*)
        (*package* *package*)
        (*load-truename* stream)
        (*load-pathname* stream)
        (eof (cons nil nil)))
    (loop (let ((form (read stream nil eof)))
            (when *load-print* (format t ";; Loading ~S~%" form))
            (when (eql form eof) (return))
            (eval form)))
    t))

(defun load-from-stream (stream)
  (when *load-verbose*
    (format t ";;; Loading from ~S~%" stream))
  (if (subtypep (stream-element-type stream) 'character)<commit_msg>Don't print the EOF marker when loading source files.<commit_after>(in-package #:sys.int)

(declaim (special * ** ***
                  + ++ +++
                  / // ///
                  -))

(defun repl ()
  (let ((* nil) (** nil) (*** nil)
        (/ nil) (// nil) (/// nil)
        (+ nil) (++ nil) (+++ nil)
        (- nil))
    (loop
       (with-simple-restart (abort "Return to READ-EVAL-PRINT loop.")
         (fresh-line)
         (write-char #\>)
         (let ((form (read)))
           (fresh-line)
           (let ((result (multiple-value-list (let ((- form))
                                                (eval form)))))
             (setf *** **
                   ** *
                   * (first result)
                   /// //
                   // /
                   / result
                   +++ ++
                   ++ +
                   + form)
             (when result
               (dolist (v result)
                 (fresh-line)
                 (write v)))))))))

(defun run ()
  (sys.net::net-setup)
  (when (null sys.graphics::*screens*)
    (cond (*bochs-framebuffer*
           (sys.graphics::register-screen :bochs *bochs-framebuffer* *bochs-back-buffer* 'bochs-flip-buffer))
          ((eql (first *cold-stream-screen*) :framebuffer)
           (let ((buffer (make-array (array-dimensions (second *cold-stream-screen*))
                                     :element-type '(unsigned-byte 32)))
                 (width (second (array-dimensions (second *cold-stream-screen*))))
                 (height (first (array-dimensions (second *cold-stream-screen*)))))
             (sys.graphics::register-screen :cold-framebuffer buffer buffer
                                            (lambda ()
                                              (%bitblt height width buffer 0 0 (second *cold-stream-screen*) 0 0)))))
          ((typep *terminal-io* 'framebuffer-stream)
           (let ((fb (slot-value *terminal-io* 'framebuffer))
                 (buffer (make-array (array-dimensions fb)
                                     :element-type '(unsigned-byte 32)))
                 (width (second (array-dimensions fb)))
                 (height (first (array-dimensions fb))))
             (sys.graphics::register-screen :framebuffer buffer buffer
                                            (lambda ()
                                              (%bitblt height width buffer 0 0 fb 0 0)))))
          (t (error "No screens."))))
  (sys.graphics::invoke-graphics))

(defun hexdump-range (start end &optional stream)
  (when (< start end)
    (write-sequence (make-array (- end start)
                                :element-type '(unsigned-byte 8)
                                :memory (+ #x8000000000 start))
                    stream)))

(defmacro with-deferred-gc (options &body body)
  "Execute BODY with the garbage collector deferred.
BODY must not allocate!"
  `(progn ,@body))

(defgeneric documentation (x doc-type))
(defgeneric (setf documentation) (new-value x doc-type))

(defmethod documentation (x doc-type) nil)
(defmethod (setf documentation) (new-value x doc-type) new-value)

;; (%cpuid leaf ecx) -> eax ebx ecx edx
(sys.int::define-lap-function %cpuid ()
  (sys.lap-x86:mov64 :rax :r8)
  (sys.lap-x86:sar64 :rax 3)
  (sys.lap-x86:mov64 :rcx :r9)
  (sys.lap-x86:sar64 :rcx 3)
  (sys.lap-x86:cpuid)
  (sys.lap-x86:lea64 :r8 ((:rax 8)))
  (sys.lap-x86:lea64 :r9 ((:rbx 8)))
  (sys.lap-x86:lea64 :r10 ((:rcx 8)))
  (sys.lap-x86:lea64 :r11 ((:rdx 8)))
  (sys.lap-x86:mov32 :ecx #.(ash 4 3))
  (sys.lap-x86:mov64 :rbx :lsp)
  (sys.lap-x86:ret))

(defun cpuid (leaf &optional (rcx 0))
  (check-type leaf (unsigned-byte 32))
  (check-type rcx (unsigned-byte 32))
  (%cpuid leaf rcx))

(defun decode-cpuid-vendor (vendor-1 vendor-2 vendor-3)
  (let ((vendor (make-string (* 4 3))))
    (setf (char vendor 0) (code-char (ldb (byte 8 0) vendor-1))
          (char vendor 1) (code-char (ldb (byte 8 8) vendor-1))
          (char vendor 2) (code-char (ldb (byte 8 16) vendor-1))
          (char vendor 3) (code-char (ldb (byte 8 24) vendor-1))
          (char vendor 4) (code-char (ldb (byte 8 0) vendor-2))
          (char vendor 5) (code-char (ldb (byte 8 8) vendor-2))
          (char vendor 6) (code-char (ldb (byte 8 16) vendor-2))
          (char vendor 7) (code-char (ldb (byte 8 24) vendor-2))
          (char vendor 8) (code-char (ldb (byte 8 0) vendor-3))
          (char vendor 9) (code-char (ldb (byte 8 8) vendor-3))
          (char vendor 10) (code-char (ldb (byte 8 16) vendor-3))
          (char vendor 11) (code-char (ldb (byte 8 24) vendor-3)))
    vendor))

(defun make-string (size &key initial-element (element-type 'character))
  (if initial-element
      (make-array size :element-type element-type :initial-element initial-element)
      (make-array size :element-type element-type)))

(defvar *load-verbose* nil)
(defvar *load-print* nil)

(defun load-lisp-source (stream)
  (let ((*readtable* *readtable*)
        (*package* *package*)
        (*load-truename* stream)
        (*load-pathname* stream)
        (eof (cons nil nil)))
    (loop (let ((form (read stream nil eof)))
            (when (eql form eof) (return))
            (when *load-print* (format t ";; Loading ~S~%" form))
            (eval form)))
    t))

(defun load-from-stream (stream)
  (when *load-verbose*
    (format t ";;; Loading from ~S~%" stream))
  (if (subtypep (stream-element-type stream) 'character)
{'fraction_non_alphanumeric': 0.1588235294117647, 'fraction_numerical': 0.02738970588235294, 'mean_word_length': 1.8380281690140845, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '6553492', 'n_tokens_mistral': 3716, 'n_tokens_neox': 3411, 'n_words': 939}