id
int64
0
45.1k
file_name
stringlengths
4
68
file_path
stringlengths
14
193
content
stringlengths
32
9.62M
size
int64
32
9.62M
language
stringclasses
1 value
extension
stringclasses
6 values
total_lines
int64
1
136k
avg_line_length
float64
3
903k
max_line_length
int64
3
4.51M
alphanum_fraction
float64
0
1
repo_name
stringclasses
779 values
repo_stars
int64
0
882
repo_forks
int64
0
108
repo_open_issues
int64
0
90
repo_license
stringclasses
8 values
repo_extraction_date
stringclasses
146 values
sha
stringlengths
64
64
__index_level_0__
int64
0
45.1k
exdup_ids_cmlisp_stkv2
sequencelengths
1
47
21,364
grid.lisp
alexpalade_such-is-life/src/grid.lisp
(cl:in-package :sil-game) (defclass grid () ((rows :initform (error "grid needs row count") :initarg :rows :reader rows) (cols :initform (error "grid needs column count") :initarg :cols :reader cols) (cell-size :initform (error "grid needs cell size") :initarg :cell-size :reader cell-size))) (defmethod render ((this grid)) (with-pushed-canvas () (dotimes (row (rows this)) (dotimes (col (cols this)) (let ((x (* col *cell-size*)) (y (* row *cell-size*))) (render-tile this x y :tile) (draw-rect (vec2 x y) *cell-size* *cell-size* :thickness *grid-thickness* :stroke-paint *grid-color*)))))) (defmethod render-tile ((this grid) x y asset) (with-pushed-canvas () (let* ((width (image-width asset)) (scale (/ *cell-size* width))) (scale-canvas scale scale) (draw-image (vec2 (/ x scale) (/ y scale)) asset)))) (defmethod distance-between (row1 col1 row2 col2) (+ (abs (- row1 row2)) (abs (- col1 col2))))
1,017
Common Lisp
.lisp
23
38.304348
116
0.615385
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
087e91304603be9d85984b6409a4e64da35d112b2edf0d53f977815ff497b74b
21,364
[ -1 ]
21,365
main.lisp
alexpalade_such-is-life/src/main.lisp
(cl:in-package :sil-game) (defparameter *population-percentage* 15) (defparameter *sick-percentage* 10) (defparameter *medics-count* 1) (defparameter *police-count* 1) (defparameter *killers-count* 3) (defparameter *sick-cough-frequency* 5) (defparameter *sick-cough-damage* 1) (defparameter *rows-adjusted* nil) (defparameter *population-percentage-adjusted* nil) (defparameter *sick-percentage-adjusted* nil) (defparameter *medics-count-adjusted* nil) (defparameter *police-count-adjusted* nil) (defparameter *killers-count-adjusted* nil) (defparameter *sick-cough-frequency-adjusted* nil) (defparameter *sick-cough-damage-adjusted* nil) (defmethod restart-game ((game sil-game)) (setf (state game) 'in-progress) (when *rows-adjusted* (setf *rows* *rows-adjusted*)) (when *population-percentage-adjusted* (setf *population-percentage* *population-percentage-adjusted*)) (when *sick-percentage-adjusted* (setf *sick-percentage* *sick-percentage-adjusted*)) (when *medics-count-adjusted* (setf *medics-count* *medics-count-adjusted*)) (when *police-count-adjusted* (setf *police-count* *police-count-adjusted*)) (when *killers-count-adjusted* (setf *killers-count* *killers-count-adjusted*)) (when *sick-cough-damage-adjusted* (setf *sick-cough-damage* *sick-cough-damage-adjusted*)) (when *sick-cough-frequency-adjusted* (setf *sick-cough-frequency* *sick-cough-frequency-adjusted*)) ;; recalculating stuff. yuck! (setf *cell-size* (/ *grid-height* *rows*)) (setf *cell-half* (/ *cell-size* 2)) (setf *cols* (floor (/ (- *stage-width* (* 2 *padding-bottom*)) *cell-size*))) (setf *padding-left* (/ (- *stage-width* (* *cell-size* *cols*)) 2)) (setf *grid-width* (- *stage-width* (* 2 *padding-left*))) (setf *cols* (floor (/ *grid-width* *cell-size*))) (setf *cell-padding* (* 0.1 *cell-size*)) (setf *grid-thickness* (- 1 (/ *rows* *grid-thickness-to-rows-factor*))) (let ((r (x *grid-base-color*)) (g (y *grid-base-color*)) (b (z *grid-base-color*)) (a (alexandria:clamp (/ 0.2 *grid-thickness*) 0 1))) (setf *grid-color* (vec4 r g b a))) (with-slots (grid cells persons quarantine-from quarantine-to start-time statistics) game (setf grid (make-instance 'grid :rows *rows* :cols *cols* :cell-size *cell-size*)) (setf cells (make-array (list *rows* *cols*) :initial-element nil)) (setf persons nil) (setf quarantine-from nil) (setf quarantine-to nil) (setf start-time (real-time-seconds)) (setf (hospital game) nil) (let ((random-cell (random-empty-cell game))) (place-hospital game (first random-cell) (second random-cell))) (let* ((population-percentage (/ *population-percentage* 100)) (num-cells (* *rows* *cols*)) (how-many-persons (round (* population-percentage num-cells))) (sick-percentage (/ *sick-percentage* 100)) (how-many-sick (round (* sick-percentage how-many-persons)))) (spawn-persons game 'person how-many-persons) (setf (getf statistics :alive) how-many-persons) (setf (getf statistics :dead) 0) (setf (getf statistics :sick) how-many-sick) ;; have at least one sick person (when (plusp sick-percentage) (setf how-many-sick (max 1 how-many-sick))) (dotimes (n how-many-sick) (let ((person (nth n (persons game)))) (become-sick person) ;; randomize a bit, so they don't all die at once (setf (last-cough-time person) (+ (real-time-seconds) (/ (random 2000) 1000)))))) (spawn-persons game 'police *police-count*) (spawn-persons game 'killer *killers-count*) (spawn-persons game 'medic *medics-count*))) (defmethod update-label-alive ((game sil-game) (label label)) (setf (text label) (concatenate 'string "Alive: " (write-to-string (getf (statistics game) :alive))))) (defmethod update-label-dead ((game sil-game) (label label)) (setf (text label) (concatenate 'string "Dead: " (write-to-string (getf (statistics game) :dead))))) (defmethod update-label-sick ((game sil-game) (label label)) (let ((sick (getf (statistics game) :sick))) (if (plusp sick) (setf (status-image label) :not-ok-sign) (setf (status-image label) :ok-sign)) (setf (text label) (concatenate 'string "Sick: " (write-to-string sick))))) (defmethod update-label-killers ((game sil-game) (label label)) (let ((killers (getf (statistics game) :killers))) (if (plusp killers) (setf (status-image label) :not-ok-sign) (setf (status-image label) :ok-sign)) (setf (text label) (concatenate 'string "Killers: " (write-to-string killers))))) (defmethod update-status-bar ((game sil-game) (bar status-bar)) (setf (alive bar) (getf (statistics game) :alive)) (setf (sick bar) (getf (statistics game) :sick)) (setf (dead bar) (getf (statistics game) :dead))) (defmethod post-initialize ((game sil-game)) (restart-game game) ;; UI elements (let* ((panel (panel game)) (title (make-instance 'label :text "Such Is Life") :no-padding t) (subtitle (make-instance 'label :text "Lisp Game Jam" :no-padding t)) (alive (make-instance 'label :text "Alive: ?" :text-align 'left :update #'update-label-alive)) (dead (make-instance 'label :text "Dead: ?" :no-padding t :text-align 'left :update #'update-label-dead)) (sick (make-instance 'label :text "Sick: ?" :no-padding t :text-align 'left :update #'update-label-sick)) (killers (make-instance 'label :text "Killers: ?" :no-padding t :text-align 'left :update #'update-label-killers)) (status-bar (make-instance 'status-bar :no-padding t :update #'update-status-bar)) (restart-button (make-instance 'button :text "Restart" :action(lambda () (restart-game game)))) (size-adjuster (make-instance 'adjuster :allowed-values '(10 15 20 25 30 40 50) :current-value *rows* :text "Size" :action (lambda (value) (setf *rows-adjusted* value)))) (population-adjuster (make-instance 'adjuster :allowed-values '(1 2 3 4 5 7 10 15 20 30 40) :current-value *population-percentage* :text "People %" :action (lambda (value) (setf *population-percentage-adjusted* value)))) (sick-adjuster (make-instance 'adjuster :allowed-values '(0 1 5 10 15 20 30 40 50 60 70 80 90 100) :current-value *sick-percentage* :text "Sick %" :action (lambda (value) (setf *sick-percentage-adjusted* value)))) (police-adjuster (make-instance 'adjuster :allowed-values '(0 1 2 3 4 5 6 7 8 9 10) :current-value *police-count* :text "Police" :action (lambda (value) (setf *police-count-adjusted* value)))) (medics-adjuster (make-instance 'adjuster :allowed-values '(0 1 2 3 4 5 6 7 8 9 10) :current-value *medics-count* :text "Medics" :action (lambda (value) (setf *medics-count* value)))) (killers-adjuster (make-instance 'adjuster :allowed-values '(0 1 2 3 4 5 6 7 8 9 10) :current-value *killers-count* :text "Killers" :action (lambda (value) (setf *killers-count-adjusted* value)))) (cough-frequency-adjuster (make-instance 'adjuster :allowed-values '(0.5 1 2 3 4 5 6 7 8 9 10) :current-value *sick-cough-frequency* :text "Rate" :action (lambda (value) (setf *sick-cough-frequency-adjusted* value)))) (cough-damage-adjuster (make-instance 'adjuster :allowed-values '(0.1 0.5 1 2 5 10) :current-value *sick-cough-damage* :text "Damage" :action (lambda (value) (setf *sick-cough-damage-adjusted* value))))) (add-element panel title) (add-element panel subtitle) (add-element panel (make-instance 'separator)) (add-element panel (make-instance 'label :text "Statistics")) (add-element panel alive) (add-element panel dead) (add-element panel sick) (add-element panel killers) (add-element panel status-bar) (add-element panel (make-instance 'separator)) (add-element panel (make-instance 'label :text "Settings")) (add-element panel size-adjuster) (add-element panel population-adjuster) (add-element panel sick-adjuster) (add-element panel medics-adjuster) (add-element panel police-adjuster) (add-element panel killers-adjuster) (add-element panel (make-instance 'separator)) (add-element panel (make-instance 'label :text "Virus...")) (add-element panel cough-frequency-adjuster) (add-element panel cough-damage-adjuster) (add-element panel (make-instance 'separator)) (add-element panel restart-button)) (bind-button :escape :pressed #'gamekit:stop) (bind-button :q :pressed #'gamekit:stop) (bind-cursor (lambda (x y) "Save cursor position" (setf (gamekit:x *cursor-pos*) x (gamekit:y *cursor-pos*) y) (handle-cursor-move game))) (bind-button :mouse-right :pressed (lambda () (let ((row (first (cursor-to-cell))) (col (second (cursor-to-cell)))) (handle-right-click-cell game row col)))) (bind-button :mouse-left :released (lambda () (setf *area-dragging-p* nil))) (bind-button :mouse-left :pressed (lambda () (let ((row (first (cursor-to-cell))) (col (second (cursor-to-cell)))) (handle-click-cell game row col) (click-event (panel game) *cursor-pos*))))) (defun cursor-to-cell () (let* ((x-mouse (x *cursor-pos*)) (y-mouse (y *cursor-pos*)) (col (floor (/ (- x-mouse *padding-left*) *cell-size*))) (row (floor (/ (- y-mouse *padding-bottom*) *cell-size*)))) (list row col))) (defmethod handle-cursor-move ((this sil-game)) (when (and *area-dragging-p* (cell-valid-p this (first (cursor-to-cell)) (second (cursor-to-cell)))) (setf (quarantine-to this) (cursor-to-cell)))) (defmethod handle-click-cell ((this sil-game) row col) (when (cell-valid-p this row col) (let ((obj (aref (cells this) row col))) (format t "Cell: ~A x ~A ~%" row col) (when (not (cell-free-p this row col)) (when (person-p obj) (format t "State: ~A~%" (state (aref (cells this) row col))))) (setf *area-dragging-p* t) (setf (quarantine-to this) (cursor-to-cell)) (setf (quarantine-from this) (cursor-to-cell))))) (defmethod handle-right-click-cell ((this sil-game) row col) (when (and (cell-valid-p this row col) (cell-free-p this row col)) (place-hospital this row col))) (defmethod get-empty-cells ((this sil-game)) (let ((result '())) (dotimes (row *rows*) (dotimes (col *cols*) (when (null (aref (cells this) row col)) (push (list row col) result)))) result)) (defmethod random-empty-cell ((this sil-game)) (random-nth (get-empty-cells this))) (defmethod spawn-persons ((this sil-game) type &optional (how-many 1)) (dotimes (n how-many) (spawn-person this type))) (defmethod spawn-person ((this sil-game) type) (let ((person (make-instance type)) (free-pos (random-empty-cell this))) (when (null free-pos) (format t "Warning: couldn't spawn person on null position: ~A ~%" free-pos) (return-from spawn-person)) (push person (persons this)) (setf (row person) (first free-pos)) (setf (col person) (second free-pos)) (setf (aref (cells this) (first free-pos) (second free-pos)) person))) (defun cell-pos (row col) (vec2 (* col *cell-size*) (* row *cell-size*))) (defun translate-canvas-vec (vec) (translate-canvas (x vec) (y vec))) (defun real-time-seconds () "Return seconds since certain point of time" (/ (get-internal-real-time) internal-time-units-per-second)) (defmethod get-closest-sick-person ((game sil-game) from-row from-col) (let* ((closest-distance (* *rows* *cols*)) (closest-sick nil)) (dolist (p (persons game)) (when (and (not (and (typep p 'killer) (locked p))) (sick p) (state-p p 'wander)) (let ((distance (distance-between from-row from-col (row p) (col p)))) (when (< distance closest-distance) (setf closest-distance distance) (setf closest-sick p))))) closest-sick)) (defmethod get-closest-killer ((game sil-game) from-row from-col) (let* ((closest-distance (* *rows* *cols*)) (closest-killer nil)) (dolist (k (get-all-persons-of-type game 'killer)) (when (and (not (disguised k)) (not (locked k))) (let ((distance (distance-between from-row from-col (row k) (col k)))) (when (< distance closest-distance) (setf closest-distance distance) (setf closest-killer k))))) closest-killer)) (defmethod quarantine-corners ((this sil-game)) (when (and (quarantine-from this) (quarantine-to this)) (let* ((from-row (first (quarantine-from this))) (from-col (second (quarantine-from this))) (to-row (first (quarantine-to this))) (to-col (second (quarantine-to this))) (top-row (max from-row to-row)) (bottom-row (min from-row to-row)) (left-col (min from-col to-col)) (right-col (max from-col to-col))) (list :left-col left-col :right-col right-col :top-row top-row :bottom-row bottom-row)))) (defmethod in-quarantine-person-p ((this sil-game) (person person)) (in-quarantine-p this (row person) (col person))) (defmethod in-quarantine-p ((this sil-game) row col) (when (and (quarantine-from this) (quarantine-to this)) (let* ((corners (quarantine-corners this)) (top-row (getf corners :top-row)) (bottom-row (getf corners :bottom-row)) (left-col (getf corners :left-col)) (right-col (getf corners :right-col))) (and (<= row top-row) (>= row bottom-row) (>= col left-col) (<= col right-col))))) (defmethod reached-target-p ((game sil-game) (person person)) (find (target person) (get-near-persons game person))) (defmethod render-path ((game sil-game) (p person)) (when (null (path p)) (return-from render-path)) (dolist (node (path p)) (let* ((row (first node)) (col (second node)) (x (+ (* col *cell-size*) *cell-half*)) (y (+ (* row *cell-size*) *cell-half*))) (draw-circle (vec2 x y) (/ *cell-size* 30) :fill-paint *path-color*)))) (defmethod update-path-person ((game sil-game) (p person)) (setf (path p) (find-path game (row p) (col p) (first (destination p)) (second (destination p))))) (defun cells-adjacent-p (row1 col1 row2 col2) (<= (distance-between row1 col1 row2 col2) 1)) (defmethod get-cell ((this sil-game) row col) (when (cell-valid-p this row col) (aref (cells this) row col))) ;; retuns A LIST of elements like '(row col) (defmethod get-near-cells-person ((person person)) (get-near-cells (row person) (col person) *rows* *cols*)) ;; retuns a list of persons (defmethod get-near-persons ((game sil-game) (person person)) (let ((near-cells (get-near-cells-person person)) (cells (cells game))) (remove-if (lambda (cell) (or (null cell) (not (person-p cell)))) (map 'list (lambda (cell) (aref cells (first cell) (second cell))) near-cells)))) (defun person-p (o) (typep o 'person)) (defmethod get-near-persons-of-type ((game sil-game) (person person) type) (remove-if-not (lambda (p) (typep p type)) (get-near-persons game person))) (defmethod get-near-persons-not-of-type ((game sil-game) (person person) type) (remove-if (lambda (p) (typep p type)) (get-near-persons game person))) (defmethod get-near-sick-persons ((game sil-game) (person person)) (remove-if-not (lambda (p) (sick p)) (get-near-persons game person))) (defmethod cell-valid-p ((this sil-game) row col) (and (>= row 0) (>= col 0) (< row *rows*) (< col *cols*))) (defmethod cell-free-p ((this sil-game) row col) (cell-free-ignore-p this row col nil)) (defmethod cell-free-ignore-p ((this sil-game) row col ignore-type) (let ((cell (aref (cells this) row col))) (if (or (null cell) (and ignore-type (equal (type-of cell) ignore-type))) T nil))) (defmethod get-near-free-cells ((this sil-game) row col) (get-near-free-cells-ignore this row col nil)) (defmethod get-near-free-cells-ignore ((this sil-game) row col ignore-type) (let* ((result-cells '()) (near-cells (get-near-cells row col *rows* *cols*))) (dolist (try-cell near-cells) (when (and (cell-valid-p this (first try-cell) (second try-cell)) (cell-free-ignore-p this (first try-cell) (second try-cell) ignore-type)) (push try-cell result-cells))) result-cells)) (defmethod get-near-free-cells-person ((this sil-game) person) (get-near-free-cells this (row person) (col person))) (defmethod get-random-move-cell ((this sil-game) person) (let* ((cells (get-near-free-cells-person this person))) (when (and (in-quarantine-person-p this person) (regular-person-p person)) (setf cells (remove-if-not (lambda (cell) (in-quarantine-p this (first cell) (second cell))) cells))) (if cells (random-nth cells) nil))) (defmethod get-all-persons-of-type ((this sil-game) type) (remove-if-not (lambda (p) (typep p type)) (persons this))) (defmethod get-killers ((this sil-game)) (get-all-persons-of-type this 'killer)) (defmethod get-medics ((this sil-game)) (get-all-persons-of-type this 'medic)) (defmethod remove-person ((game sil-game) person) (when (regular-person-p person) (incf (getf (statistics game) :dead))) (setf (aref (cells game) (row person) (col person)) nil) (setf (persons game) (remove person (persons game)))) (defmethod do-kill ((this sil-game) killer person) ;; medic died, released grabbed person (when (and (typep person 'medic) (state-p person 'grab-sick) (not (null (target person)))) (setf (state (target person)) 'wander)) (remove-person this person) (move-person this killer (row person) (col person)) (play :kill)) (defclass hospital () ((row :initarg row :accessor row) (col :initarg col :accessor col))) (defmethod render ((this hospital)) (with-pushed-canvas () (let* ((asset :hospital) (width (image-width asset)) (height (image-height asset)) (scale-for (max width height)) (scale (/ (- *cell-size* *cell-padding*) scale-for)) (scaled-cell-size (/ *cell-size* scale))) (scale-canvas scale scale) (draw-image (vec2 (- (/ scaled-cell-size 2) (/ width 2)) (- (/ scaled-cell-size 2) (/ height 2))) asset)))) (defmethod place-hospital ((this sil-game) row col) (if (null (hospital this)) (setf (hospital this) (make-instance 'hospital)) (setf (aref (cells this) (row (hospital this)) (col (hospital this))) nil)) (setf (row (hospital this)) row) (setf (col (hospital this)) col) (setf (aref (cells this) row col) (hospital this))) (defmethod gamekit:draw ((game sil-game)) ;; background color (draw-rect (vec2 0 0) *width* *height* :fill-paint *background-color*) (draw-rect (vec2 *padding-left* *padding-bottom*) (- *stage-width* (* *padding-left* 2)) (- *stage-height* (* *padding-bottom* 2)) :stroke-paint *grid-border-color* :fill-paint nil :thickness *grid-border-thickness*) (render (panel game)) (with-pushed-canvas () (translate-canvas *padding-left* *padding-bottom*) (render (grid game)) (dolist (medic (get-medics game)) (when (not (state-p medic 'wander)) (render-path game medic))) (render game) ;; draw quarantine (when (and (quarantine-to game) (quarantine-from game)) (let* ((corners (quarantine-corners game)) (top-row (getf corners :top-row)) (bottom-row (getf corners :bottom-row)) (left-col (getf corners :left-col)) (right-col (getf corners :right-col)) (from-x (* left-col *cell-size*)) (from-y (* bottom-row *cell-size*)) (to-x (+ (* right-col *cell-size*) *cell-size*)) (to-y (+ (* top-row *cell-size*) *cell-size*)) (width (abs (- from-x to-x))) (height (abs (- from-y to-y)))) (draw-rect (vec2 from-x from-y) width height :thickness *quarantine-border-thickness* :stroke-paint *quarantine-border-color*))))) (defmethod render ((game sil-game)) (with-slots (cells) game (dotimes (row *rows*) (dotimes (col *cols*) (when (aref cells row col) (with-pushed-canvas () (translate-canvas-vec (cell-pos row col)) (render (aref cells row col)))))))) (defmethod update-statistics ((game sil-game)) (let ((persons (persons game)) (alive 0) (killers 0) (sick 0)) (dolist (person persons) (when (and (typep person 'killer) (not (locked person))) (incf killers)) (when (regular-person-p person) (incf alive) (when (sick person) (incf sick)))) (setf (getf (statistics game) :alive) alive) (setf (getf (statistics game) :sick) sick) (setf (getf (statistics game) :killers) killers))) (defmethod check-win-condition ((game sil-game)) (let ((sick (getf (statistics game) :sick)) (killers (getf (statistics game) :killers))) (when (and (equal (state game) 'in-progress) (zerop sick) (zerop killers)) (setf (state game) 'game-over) (play :win)))) (defmethod act ((game sil-game)) (dolist (person (persons game)) (tick game person)) (update-statistics game) (check-win-condition game) (panel-act game)) (defmethod run () (gamekit:start 'sil-game))
24,491
Common Lisp
.lisp
539
35.142857
117
0.571896
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
686e4f1a7d715dc3826883c4d4d7df33a7744332792bc177a7d6336edf270567
21,365
[ -1 ]
21,366
killer.lisp
alexpalade_such-is-life/src/killer.lisp
(cl:in-package :sil-game) (defclass killer (person) ((disguised :initform t :accessor disguised) (gender :initform (nth (random 2) (list 'male 'female)) :accessor gender) (locked :initform nil :accessor locked) (last-kill-time :initform nil :accessor last-kill-time))) (defmethod tick :before ((game sil-game) (killer killer)) (when (locked killer) (return-from tick)) ;; can disguise again after some time (when (and (not (disguised killer)) (> (time-since-last-kill killer) 1)) (setf (disguised killer) t)) (when (and (< (random 100) 2) (kill-cooldown-ok killer)) (let ((persons (get-near-persons-not-of-type game killer 'police))) ;; also remove other killers from the list (setf persons (remove-if (lambda (x) (typep x 'killer)) persons)) (when persons (setf (last-kill-time killer) (real-time-seconds)) (lose-disguise game killer) (do-kill game killer (first persons)))))) (defmethod lose-disguise ((game sil-game) (killer killer)) (setf (disguised killer) nil)) (defmethod time-since-last-kill ((this killer)) (- (real-time-seconds) (last-kill-time this))) (defmethod kill-cooldown-ok ((this killer)) (or (null (last-kill-time this)) (> (time-since-last-kill this) 1))) (defmethod render ((killer killer)) (if (locked killer) (progn (render-avatar killer :killer) (render-avatar killer :prison)) (if (disguised killer) (if (equal (gender killer) 'male) (render-avatar killer :killer-male-disguised) (render-avatar killer :killer-female-disguised)) (if (equal (gender killer) 'male) (render-avatar killer :killer) (render-avatar killer :killer)))))
1,787
Common Lisp
.lisp
44
34.318182
76
0.645941
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
ee2448ddba86d0784314e042aed3e479aefb6510487df0454f834b7b7f771505
21,366
[ -1 ]
21,367
sil-game.lisp
alexpalade_such-is-life/src/sil-game.lisp
(cl:in-package :sil-game) ;; resouces (register-resource-package :keyword (asdf:system-relative-pathname :such-is-life "assets/")) (define-image :person-male "person-male.png") (define-image :person-female "person-female.png") (define-image :killer "killer.png") (define-image :killer-male-disguised "person-male-disguised.png") (define-image :killer-female-disguised "person-female-disguised.png") (define-image :police-male "police-male.png") (define-image :police-female "police-female.png") (define-image :medic "medic.png") (define-image :prison "prison.png") (define-image :hospital "hospital.png") (define-image :tile "tile.png") (define-image :ok-sign "ok-sign.png") (define-image :not-ok-sign "not-ok-sign.png") (define-sound :death "sounds/death.wav") (define-sound :cough "sounds/cough.ogg") (define-sound :kill "sounds/kill.wav") (define-sound :lock "sounds/lock.ogg") (define-sound :heal "sounds/heal.wav") (define-sound :win "sounds/win.wav") (defvar *cursor-pos* (gamekit:vec2 0 0)) (defparameter *width* 1024) (defparameter *height* 768) (defparameter *panel-width* 200) (defparameter *stage-width* (- *width* *panel-width*)) (defparameter *stage-height* *height*) (defparameter *padding-bottom* 20) (defparameter *grid-height* (- *stage-height* (* 2 *padding-bottom*))) (defparameter *rows* 20) (defparameter *cell-size* (/ *grid-height* *rows*)) (defparameter *cell-half* (/ *cell-size* 2)) (defparameter *cols* (floor (/ (- *stage-width* (* 2 *padding-bottom*)) *cell-size*))) (defparameter *padding-left* (/ (- *stage-width* (* *cell-size* *cols*)) 2)) (defparameter *grid-width* (- *stage-width* (* 2 *padding-left*))) (defparameter *cols* (floor (/ *grid-width* *cell-size*))) (defparameter *area-dragging-p* nil) ;; % padding between a cell and the image assets (defparameter *cell-padding* (* 0.1 *cell-size*)) (gamekit:defgame sil-game () ((grid :initform (make-instance 'grid :rows *rows* :cols *cols* :cell-size *cell-size*) :accessor grid) (persons :initform '() :accessor persons) (cells :accessor cells) (hospital :accessor hospital :initform nil) (quarantine-from :accessor quarantine-from :initform nil) (quarantine-to :accessor quarantine-to :initform nil) (start-time :accessor start-time :initform nil) (statistics :accessor statistics :initform nil) (state :accessor state :initform 'in-progress) (panel :accessor panel :initform (make-instance 'panel :origin (vec2 *stage-width* 0) :width *panel-width* :height *height* :padding *padding-bottom*))) (:viewport-width *width*) (:viewport-height *height*) (:viewport-title "Such Is Life"))
2,775
Common Lisp
.lisp
59
42.627119
105
0.684815
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
65fd7b258c881c621f27685de5086b44bdb774e7844f6c05ed56bd40b20f9ec7
21,367
[ -1 ]
21,368
medic.lisp
alexpalade_such-is-life/src/medic.lisp
(cl:in-package :sil-game) (defclass medic (person) ()) (defmethod render ((this medic)) (render-avatar this :medic)) (defmethod tick ((game sil-game) (medic medic)) ;; medic is idle, take a patient (when (state-p medic 'wander) (let ((sick-person (get-closest-sick-person game (row medic) (col medic)))) (if (and sick-person (not (equal medic sick-person)) (state-p sick-person 'wander)) (progn (setf (target medic) sick-person) (setf (state medic) 'grab-sick)) (call-next-method)))) ;; medic is going for patient (when (and (state-p medic 'grab-sick) (> (- (real-time-seconds) (last-move-time medic)) (rest-time medic))) (with-slots (target path) medic (when (or (null target) (not (state-p target 'wander)) (not (find target (persons game)))) (setf (state medic) 'wander) (return-from tick)) (when (or (null path) (not (equal (row target) (first (first path)))) (not (equal (col target) (second (first path))))) (setf (destination medic) (list (row target) (col target))) (update-path-person game medic)) (let* ((next-cell (first (path medic))) (to-row (first next-cell)) (to-col (second next-cell))) (when (reached-target-p game medic) (setf (state medic) 'take-to-hospital) (setf (state (target medic)) 'grabbed) (setf (destination medic) (list (row (hospital game)) (col (hospital game)))) (update-path-person game medic) (return-from tick)) (if (and to-row to-col (cell-free-p game to-row to-col)) (progn (setf (rest-time medic) 0.3) (move-person game medic to-row to-col)) (update-path-person game medic))))) ;; medic is taking someone to the hospital (when (and (state-p medic 'take-to-hospital) (> (- (real-time-seconds) (last-move-time medic)) (rest-time medic))) (let* ((next-cell (first (path medic))) (to-row (first next-cell)) (to-col (second next-cell))) (when (not (find (target medic) (persons game))) (setf (state medic) 'wander) (return-from tick)) (if (and (path medic) (cell-free-p game to-row to-col)) (progn (setf (rest-time medic) 0.5) (let ((old-row (row medic)) (old-col (col medic))) (move-person game medic to-row to-col) (move-person game (target medic) old-row old-col))) (progn (setf (destination medic) (list (row (hospital game)) (col (hospital game)))) (update-path-person game medic))) ;; yay, reached hospital (when (member (list (row (hospital game)) (col (hospital game))) (get-near-cells-person medic) :test (lambda (x y) (and (equal (first x) (first y)) (equal (second x) (second y))))) (become-healthy medic) (become-healthy (target medic)) (setf (last-move-time medic) (real-time-seconds)) (setf (last-move-time (target medic)) (real-time-seconds)) (setf (state medic) 'wander) (setf (state (target medic)) 'wander)))))
3,413
Common Lisp
.lisp
76
34.026316
105
0.54952
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
c609fbac6ad0da0cd74fcebc724fe39ead0114526369aaf9d0c09224f12ff13d
21,368
[ -1 ]
21,369
pathfinding.lisp
alexpalade_such-is-life/src/pathfinding.lisp
(in-package :sil-game) ;; g, h, f represent the cost values (defmethod find-path ((game sil-game) from-row from-col to-row to-col) (let* ((result nil) (count 0) (next '()) (visited '()) (starting-distance (distance-between from-row from-col to-row to-col))) (push (list :row from-row :col from-col :g 0 :h starting-distance :f starting-distance) next) (loop while (and next (< count 50000)) do (progn ;; sort the next nodes, to get lowest f-cost node (setf next (sort next #'< :key (lambda (plist) (getf plist :f)))) ;(when (and (equal (getf (first next) :row) to-row) ; (equal (getf (first next) :col) to-col)) ; (return)) (when (cells-adjacent-p (getf (first next) :row) (getf (first next) :col) to-row to-col) (return)) ;; for this node, get all free neighbors (let* ((current (first next)) (row (getf current :row)) (col (getf current :col)) (neighbors (get-near-free-cells-ignore game row col 'hospital))) ;; add all neighbors to next, if not already ;; update their f and g ;; neighbor has form: '(row col) (setf neighbors (remove-if (lambda (x) (node-from-plist (first x) (second x) visited)) neighbors)) (dolist (neighbor neighbors) (let* ((neighbor-row (first neighbor)) (neighbor-col (second neighbor)) (g-score (1+ (getf current :g))) (h-score (distance-between neighbor-row neighbor-col to-row to-col)) (f-score (+ g-score h-score)) (neighbor-plist (node-from-plist neighbor-row neighbor-col next))) (if (null neighbor-plist) ;; add neighbor to next (push (list :row neighbor-row :col neighbor-col :from (list row col) :g g-score :h h-score :f f-score) (cdr (last next))) ;; ... or update existing values (when (< f-score (getf neighbor-plist :f)) (setf (getf neighbor-plist :f) f-score) (setf (getf neighbor-plist :g) g-score) (setf (getf neighbor-plist :from) (list row col)))))) ;; remember we visited this node (push current visited) ;; done visiting the first in queue (setf next (rest next)) (incf count)))) (if (and next (cells-adjacent-p (getf (first next) :row) (getf (first next) :col) to-row to-col)) (do ((current (first next))) ((and (equal (getf current :row) from-row) (equal (getf current :col) from-col)) T) (progn (let ((row (getf current :row)) (col (getf current :col))) (push (list row col) result)) (setf current (node-from-plist (first (getf current :from)) (second (getf current :from)) visited)))) (setf result nil)) result)) (defun node-from-plist (row col plist) (first (member (list :row row :col col) plist :test (lambda (a b) (and (equal (getf a :row) (getf b :row)) (equal (getf a :col) (getf b :col)))))))
4,537
Common Lisp
.lisp
99
24.858586
86
0.392591
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
f9d8e87a2ac1827c982d23d9199d56cf1fb77bc5d4488dcbe5a0e0bc2c739b89
21,369
[ -1 ]
21,370
police.lisp
alexpalade_such-is-life/src/police.lisp
(cl:in-package :sil-game) (defclass police (person) ((gender :initform (nth (random 2) (list 'male 'female)) :accessor gender))) (defmethod tick ((game sil-game) (police police)) ;; lock near killers (dolist (killer (get-near-persons-of-type game police 'killer)) (when (and (not (disguised killer)) (not (locked killer))) (setf (locked killer) t) (play :lock))) ;; police is idle, chase someone (when (state-p police 'wander) (let ((killer (get-closest-killer game (row police) (col police)))) (if (and killer (not (disguised killer))) (progn (setf (target police) killer) (setf (state police) 'chasing)) (call-next-method)))) ;; chase (when (and (state-p police 'chasing) (> (- (real-time-seconds) (last-move-time police)) (rest-time police))) (with-slots (target path) police (when (or (null target) (disguised target) (locked target) (not (find target (persons game)))) (setf (target police) nil) (setf (state police) 'wander) (return-from tick)) (when (or (null path) (not (equal (row target) (first (first path)))) (not (equal (col target) (second (first path))))) (setf (destination police) (list (row target) (col target))) (update-path-person game police)) (let* ((next-cell (first (path police))) (to-row (first next-cell)) (to-col (second next-cell))) (if (and to-row to-col (cell-free-p game to-row to-col)) (progn (setf (rest-time police) 0.8) (move-person game police to-row to-col)) (update-path-person game police)))))) (defmethod render ((this police)) (if (equal (gender this) 'female) (render-avatar this :police-female) (render-avatar this :police-male)))
1,958
Common Lisp
.lisp
48
31.833333
84
0.573753
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
0ea16acf6e6407da43168bb1ee1053078f194a23f8dc5b2d166a13ad124f74d1
21,370
[ -1 ]
21,371
parameters.lisp
alexpalade_such-is-life/src/parameters.lisp
(in-package :sil-game) (defvar *black* (vec4 0 0 0 1)) (defparameter *background-color* (vec4 0.8 0.8 0.8 1)) (defparameter *grid-border-color* (vec4 0 0 0 0.3)) (defparameter *grid-border-thickness* 3) (defparameter *grid-thickness-to-rows-factor* 150) (defparameter *grid-thickness* nil) (defparameter *grid-base-color* (vec3 0.0 0.0 0.0)) (defparameter *grid-color* nil) (defparameter *path-color* (vec4 0.1 0.1 0.1 0.6)) (defparameter *button-color* (vec4 0.75 0.75 0.75 1.0)) (defparameter *status-bar-healthy-color* (vec4 0.5 0.86 0.02 1)) (defparameter *status-bar-sick-color* (vec4 0.77 0.03 0.03 1)) (defparameter *status-bar-dead-color* *grid-border-color*) (defparameter *status-bar-stroke-color* (vec4 0.0 0.0 0.0 1.0)) (defparameter *quarantine-border-color* (vec4 0.5 0.1 0.1 1.0)) (defparameter *quarantine-border-thickness* 2)
851
Common Lisp
.lisp
17
48.588235
64
0.727603
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
dc8ca6030d3a88cbf1bf6cbff185b122aad1805d8ab4bcfc17878f55939a986a
21,371
[ -1 ]
21,372
panel.lisp
alexpalade_such-is-life/src/ui/panel.lisp
(cl:in-package :sil-game) (defparameter *element-base-height* 25) (defparameter *element-padding* 10) (defclass panel () ((origin :initarg :origin :accessor origin) (padding :initform 0 :initarg :padding :reader padding) (width :initarg :width :reader width) (height :initarg :height :reader height) (height-occupied :initform 0 :accessor height-occupied) (elements :initarg :elements :initform '() :accessor elements) (index :initform 0 :accessor index))) (defmethod initialize-instance :after ((panel panel) &key) (setf (height-occupied panel) (padding panel))) (defclass element () ((text :initform "Some text" :initarg :text :accessor text) (action :initform nil :initarg :action :accessor action) (origin :accessor origin) (row-span :initform 1 :initarg :row-span :accessor row-span) (no-padding :initform nil :initarg :no-padding :accessor no-padding) (height :accessor height) (width :accessor width))) (defmethod add-element ((panel panel) element) (with-slots (height index padding origin height-occupied) panel (let* ((element-height (+ (* (row-span element) *element-base-height*))) (element-y (- height height-occupied element-height))) (when (and (> index 0) (not (no-padding element))) (incf element-height *element-padding*) (decf element-y *element-padding*)) (incf index) (incf height-occupied element-height) (setf (origin element) (vec2 (x origin) element-y)) ;(gamekit:add origin (vec2 padding element-y))) (setf (width element) (- (width panel) (* 2 padding ))) (push element (elements panel))))) (defmethod draw-button-with-text (origin width height text fill) (with-pushed-canvas () (draw-rect origin width height :fill-paint fill) (draw-text-centered origin width height text))) (defmethod draw-round-button-with-text (origin radius text fill) (with-pushed-canvas () (draw-circle (add origin (vec2 radius radius)) radius :fill-paint fill) (draw-text-centered origin (* 2 radius) (* 2 radius) text))) (defmethod draw-text-aligned (origin width height text aligned) (cond ((equal aligned 'center) (draw-text-centered origin width height text)) ((equal aligned 'left) (draw-text-left origin width height text)))) (defmethod draw-text-left (origin width height text) (let* ((text-offset-x 0) (text-offset-y (- (/ height 2) (/ (text-height text) 2))) (text-origin-x (+ (x origin) text-offset-x)) (text-origin-y (+ (y origin) text-offset-y))) (draw-text text (vec2 text-origin-x text-origin-y)))) (defmethod draw-text-centered (origin width height text) (let* ((text-offset-x (- (/ width 2) (/ (text-width text) 2))) (text-offset-y (- (/ height 2) (/ (text-height text) 3))) (text-origin-x (+ (x origin) text-offset-x)) (text-origin-y (+ (y origin) text-offset-y))) (draw-text text (vec2 text-origin-x text-origin-y)))) (defun text-width (text) (nth-value 1 (calc-text-bounds text))) (defun text-height (text) (nth-value 2 (calc-text-bounds text))) (defmethod render ((panel panel)) (dolist (e (elements panel)) (render e))) (defmethod click-event ((panel panel) cursor-pos) (dolist (e (elements panel)) (click-event e cursor-pos))) (defmethod click-event ((element element) cursor-pos)) (defmethod element-act ((game sil-game) (element element))) (defmethod panel-act ((game sil-game)) (dolist (e (elements (panel game))) (element-act game e)))
3,518
Common Lisp
.lisp
74
43.108108
105
0.685731
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
1ac9b60d06f097d74a01bb3e346a2e169e9e261eb6d0dfaa0a39ed1778aef85b
21,372
[ -1 ]
21,373
label.lisp
alexpalade_such-is-life/src/ui/label.lisp
(cl:in-package :sil-game) (defclass label (element) ((text :initform "Button" :initarg :text :accessor text) (action :initform nil :initarg :action :accessor action) (origin :accessor origin) (height :accessor height) (width :accessor width) (status-image :initform nil :accessor status-image) (text-align :initarg :text-align :initform 'center :accessor text-align) (update :initform nil :initarg :update :accessor update))) (defmethod element-act ((game sil-game) (label label)) (when (update label) (funcall (update label) game label))) (defmethod render ((label label)) (with-pushed-canvas () (translate-canvas-vec (origin label)) (draw-text-aligned (vec2 0 0) (width label) *element-base-height* (text label) (text-align label)) (when (status-image label) (let* ((text-height (text-height (text label))) (scale (/ text-height (image-height (status-image label))))) (scale-canvas scale scale) (draw-image (vec2 (* (/ 1 scale) (- (width label) text-height)) (/ (text-height (text label)) 2)) (status-image label))))))
1,281
Common Lisp
.lisp
29
34.206897
75
0.588471
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
6b0fdca110aa001ca8f152341290d8f1cb3153f96125f4e0769a399fe1e25baa
21,373
[ -1 ]
21,374
adjuster.lisp
alexpalade_such-is-life/src/ui/adjuster.lisp
(cl:in-package :sil-game) (defparameter *decrease-button-offset-x* 80) (defclass adjuster (element) ((allowed-values :initarg :allowed-values :initform (error "Adjuster element needs allowed values") :accessor allowed-values) (current-value :initarg :current-value :initform (error "Adjuster element needs current value") :accessor current-value) (text :initarg :text :initform "Some text" :accessor text) (row-span :initform 1 :accessor row-span) (action :initform nil :initarg action :accessor action))) (defmethod render ((a adjuster)) (with-pushed-canvas () (translate-canvas-vec (origin a)) (draw-text-left (vec2 0 0) (width a) *element-base-height* (text a)) (draw-round-button-with-text (vec2 (- (width a) *element-base-height*) 0) (/ *element-base-height* 2) "+" *button-color*) (let* ((text (write-to-string (current-value a))) (text-offset-x (+ *decrease-button-offset-x* *element-base-height*))) (draw-text-centered (vec2 text-offset-x 0) (- (- (width a) *element-base-height*) text-offset-x) *element-base-height* text) (draw-round-button-with-text (vec2 *decrease-button-offset-x* 0) (/ *element-base-height* 2) "-" *button-color*)))) (defmethod click-event ((this adjuster) cursor-pos) (let ((x (x cursor-pos)) (y (y cursor-pos))) (when (and (> x (+ (x (origin this)) *decrease-button-offset-x*)) (< x (+ (x (origin this)) *decrease-button-offset-x* *element-base-height*)) (> y (y (origin this))) (< y (+ (y (origin this)) *element-base-height*))) (previous-value this)) (when (and (> x (+ (x (origin this)) (- (width this) *element-base-height*))) (< x (+ (x (origin this)) (width this))) (> y (y (origin this))) (< y (+ (y (origin this)) *element-base-height*))) (next-value this)))) (defmethod next-value ((this adjuster)) (let* ((current-value (current-value this)) (index (position current-value (allowed-values this)))) (when (and index (< index (1- (length (allowed-values this))))) (setf (current-value this) (nth (1+ index) (allowed-values this))) (when (action this) (funcall (action this) (current-value this)))))) (defmethod previous-value ((this adjuster)) (let* ((current-value (current-value this)) (index (position current-value (allowed-values this)))) (when (and index (> index 0)) (setf (current-value this) (nth (1- index) (allowed-values this))) (when (action this) (funcall (action this) (current-value this))))))
3,025
Common Lisp
.lisp
66
34.621212
127
0.548168
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
bd1fa937e7071117c6839c50c76d5d2754bc2cab89d7042d530a70b2115fa497
21,374
[ -1 ]
21,375
button.lisp
alexpalade_such-is-life/src/ui/button.lisp
(cl:in-package :sil-game) (defclass button (element) ()) (defmethod render ((button button)) (with-pushed-canvas () (translate-canvas-vec (origin button)) (draw-button-with-text (vec2 0 0) (width button) *element-base-height* (text button) *button-color*))) (defmethod click-event ((this button) cursor-pos) (let ((x (x cursor-pos)) (y (y cursor-pos))) (when (and (> x (x (origin this))) (< x (+ (x (origin this)) (width this))) (> y (y (origin this))) (< y (+ (y (origin this)) *element-base-height*))) (funcall (action this)))))
726
Common Lisp
.lisp
21
24.285714
59
0.492877
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
a7bff95289af66243c9fddf4bf564213b38b4ce2190cc9daba1899223ae0b72d
21,375
[ -1 ]
21,376
separator.lisp
alexpalade_such-is-life/src/ui/separator.lisp
(in-package :sil-game) (defclass separator (element) ((row-span :initform 0.2 :initarg :row-span :accessor row-span))) (defmethod render ((sep separator)) (with-pushed-canvas () (translate-canvas-vec (origin sep)) (let* ((sep-height (* (row-span sep) *element-base-height*)) (sep-y (/ sep-height 2))) (draw-line (vec2 0 sep-y) (vec2 (width sep) sep-y) *black*))))
395
Common Lisp
.lisp
9
39.444444
68
0.643229
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
0b1cdd4b2456f2a7dcdb0027f6ff8a463c86b3e1fca9d45ada73be9a71ceda11
21,376
[ -1 ]
21,377
status-bar.lisp
alexpalade_such-is-life/src/ui/status-bar.lisp
(in-package :sil-game) (defclass status-bar (element) ((population :initarg :population :accessor population) (alive :initarg :sick :initform 1 :accessor alive) (sick :initarg :sick :initform 1 :accessor sick) (dead :initarg :dead :initform 1 :accessor dead) (padding-vertical :initform 7 :accessor padding-vertical) (update :initform nil :initarg :update :accessor update))) (defmethod element-act ((game sil-game) (bar status-bar)) (when (update bar) (funcall (update bar) game bar))) (defmethod render ((bar status-bar)) (with-pushed-canvas () (translate-canvas-vec (origin bar)) (let* ((alive (alive bar)) (sick (sick bar)) (dead (dead bar)) (population (+ alive dead)) (healthy (- alive sick)) (padding-vertical (padding-vertical bar)) (width (width bar)) (height (- *element-base-height* (* 2 padding-vertical))) (offset-y (- (/ *element-base-height* 2) (/ height 2))) (healthy-width (* width (/ healthy population))) (sick-width (* width (/ sick population))) (dead-width (* width (/ dead population)))) (draw-rect (vec2 0 offset-y) width height :stroke-paint *status-bar-stroke-color* :fill-paint nil :thickness 1) (draw-rect (vec2 healthy-width offset-y) sick-width height :stroke-paint nil :fill-paint *status-bar-sick-color*) (draw-rect (vec2 0 offset-y) healthy-width height :stroke-paint nil :fill-paint *status-bar-healthy-color*) (draw-rect (vec2 (+ healthy-width sick-width) offset-y) dead-width height :stroke-paint nil :fill-paint *status-bar-dead-color*))))
1,811
Common Lisp
.lisp
39
36.871795
79
0.600904
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
3d349975514c488943c4cbacd5df74eff2eccb5f02e93822ebcfdb2642533777
21,377
[ -1 ]
21,378
such-is-life.asd
alexpalade_such-is-life/such-is-life.asd
(cl:pushnew :bodge-gl2 cl:*features*) (asdf:defsystem :such-is-life :description "Such Is Life Game" :author "Alexandru Palade" :license "GPLv3" :version "0.0.1" :serial t :depends-on (trivial-gamekit) :pathname "src/" :components ((:file "package") (:file "parameters") (:file "sil-game") (:file "math") (:file "ui/button") (:file "ui/adjuster") (:file "ui/label") (:file "ui/panel") (:file "ui/status-bar") (:file "ui/separator") (:file "grid") (:file "util") (:file "pathfinding") (:file "person") (:file "killer") (:file "police") (:file "medic") (:file "main")))
840
Common Lisp
.asd
27
20.037037
38
0.454433
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
ee7020a34e33684d4cc707f3774491536cef66eb68451b1df3bf586b167ff3e7
21,378
[ -1 ]
21,381
.travis.yml
alexpalade_such-is-life/.travis.yml
language: common-lisp sudo: false addons: apt: packages: - zip env: global: - GAMEKIT_SYSTEM_NAME: such-is-life - GAMEKIT_APPLICATION_PACKAGE: sil-game - GAMEKIT_APPLICATION_MAIN_CLASS: sil-game - PATH: ~/.bodge/bin/:$PATH - GAMEKIT_TARGET_PACKAGE: $GAMEKIT_SYSTEM_NAME-x86-64-$TRAVIS_OS_NAME-$TRAVIS_BRANCH.zip - GAMEKIT_BUILD_DIR: /tmp/$GAMEKIT_SYSTEM_NAME - secure: IGU7FYXAtRy2yYcizHB+5V9aRSDLKuZ0KUm9ZSYPbUWhMrqArDgyQxUJFI6FHzUN3ichd4yp/oshaQ6qjn5DwyTgAQU8AF5UC2z6Anyi8IA5RSPRmnTodn4jyv7NP0jehV4hK7QHmCC4B1Hynz3siUmwVwFRHPJmx8JnMq3odUismUUK9vrr/uuts9DAEsB335tPYW3k8VwokU5mGu2hyz8SQ3L4Hpq2gGOMU2QNaPncabggiOgsItEcaHP5RCn0/r0DPddRClDMUPmtGye79XKO2THk1nrvFp6avf7WLSBagV7K/4OBB7tWlWWFBnQxOuILLUTPmFso4DTmk0SMT6v1THZGDjgOVZ+cU/UhmREc8fHRxD5f3z7c54CoAtOSA21YzBm/A2WPkzciUXKCd7i78FQu0pAUwHEAqpclhHlYEvcDAOJ0nvIVY23PHGvprWhxIAFd/bN5RnF26U4sJFT2zFs1YR7Qh07O2Jer/PBe5cmFNrrOnkN8ONvEzylWPVBJ8ETiIWADKoEUNR/ym+b2bQ/mTNemTfTuuC3PhMKUYVzYOArroDSpvhFU6TXVguBDX9u+uqgKzDDCwSbfdiUJtFpAknhdc8B1fnVVczr7807JBA9g62vVYKRmUtFSpAn//tDTH/xMhDFc2DhG6BIedSZzrrO9CUKEu/kIrXk= branches: only: - "/^v\\d+(\\.\\d+)+$/" os: - linux - osx install: - curl -L http://bodge.borodust.org/files/install.sh | sh - lisp install-dist script: - > lisp build-gamekit-system $GAMEKIT_SYSTEM_NAME $GAMEKIT_APPLICATION_PACKAGE $GAMEKIT_APPLICATION_MAIN_CLASS $TRAVIS_BUILD_DIR $GAMEKIT_BUILD_DIR before_deploy: - mv "$GAMEKIT_BUILD_DIR/$GAMEKIT_SYSTEM_NAME.zip" $GAMEKIT_TARGET_PACKAGE deploy: provider: releases api-key: $GITHUB_TOKEN file: $GAMEKIT_TARGET_PACKAGE skip_cleanup: true overwrite: true on: tags: true
1,661
Common Lisp
.l
40
38.4
696
0.82134
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
a8c5e97df026141ff460b8384e641fd9def4d6a8d9622a3882246115950be830
21,381
[ -1 ]
21,382
.appveyor.yml
alexpalade_such-is-life/.appveyor.yml
image: - Visual Studio 2017 platform: - x64 environment: global: GAMEKIT_SYSTEM_NAME: such-is-life GAMEKIT_APPLICATION_PACKAGE: sil-game GAMEKIT_APPLICATION_MAIN_CLASS: sil-game GAMEKIT_ARTIFACT: $(GAMEKIT_SYSTEM_NAME)-x86-64-windows-$(APPVEYOR_REPO_TAG_NAME).zip GAMEKIT_BUILD_DIR: $(TMP)\$(GAMEKIT_SYSTEM_NAME) skip_non_tags: true branches: only: - master - "/^v\\d+(\\.\\d+)+$/" install: - set PATH=C:\msys64\usr\bin\;%PATH% - pacman --noconfirm -Syu - pacman --noconfirm -S zip - sh -c "curl -L http://bodge.borodust.org/files/install.sh | sh" - sh -c "$HOME/.bodge/bin/lisp install-dist" build_script: - > sh -c "$HOME/.bodge/bin/lisp build-gamekit-system %GAMEKIT_SYSTEM_NAME% %GAMEKIT_APPLICATION_PACKAGE% %GAMEKIT_APPLICATION_MAIN_CLASS% $(cygpath -u '%APPVEYOR_BUILD_FOLDER%') $(cygpath -u '%GAMEKIT_BUILD_DIR%')" - mv %GAMEKIT_BUILD_DIR%\%GAMEKIT_SYSTEM_NAME%.zip %GAMEKIT_ARTIFACT% artifacts: - path: "%GAMEKIT_ARTIFACT%" name: release_archive deploy: provider: GitHub release: $(APPVEYOR_REPO_TAG_NAME) tag: $(APPVEYOR_REPO_TAG_NAME) description: $(APPVEYOR_REPO_COMMIT_MESSAGE) auth_token: secure: Y8y1Rp4KNnmjxtXMa/K1kHEo9EBr1vjLjMztmxXkfn+2qA/YWGuve72liuG94X3H artifact: release_archive force_update: true draft: false prerelease: false on: appveyor_repo_tag: true
1,388
Common Lisp
.l
45
27.444444
89
0.710861
alexpalade/such-is-life
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
e56283984eef1f4cc2471f21f04df2b7c606416fe88255f187fc054802ef2307
21,382
[ -1 ]
21,414
pluto.lisp
tonyfischetti_pluto/pluto.lisp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; Pluto ;; ;; a common lisp library that's out there ;; ;; ;; ;; Tony Fischetti ;; ;; [email protected] ;; ;; ;; ;; License: GPL-3 ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #+clisp (unuse-package :ext) (defpackage :pluto (:use :common-lisp) (:export ; pluto parameters :*pluto-output-stream* :*pluto-log-level* :*pluto-log-file* :*pluto-curly-test* :*pluto-external-format* :*pluto-shell* :*unix-epoch-difference* :*whitespaces* ; formatting :fn :ft ; ansi colors and codes :make-ansi-escape :+reset-terminal-color+ :+magenta-bold+ :+red-bold+ :+yellow-bold+ :+green-bold+ :+cyan-bold+ :+blue-bold+ :+grey-bold+ :+ansi-escape-up+ :+ansi-escape-left-all+ :+ansi-escape-left-one+ :magenta :red :yellow :green :cyan :blue :grey ; string operations :str+ :str-join :substr :string->char-list :split-string->lines :repeat-string ; some essential utilities/macros :with-gensyms :mac :nil! :alambda :self! :abbr :flatten :take :group :create-symbol :create-keyword :walk-replace-sexp :-<> :<> :aif :it! :slurp :slurp-lines :barf :debug-these :with-a-file :stream! :interpose :delim :defparams :round-to :advise :alistp :with-hash-entry :entry! :if-hash-entry :if-not-hash-entry :capture-all-outputs :with-temp-file :tempfile! :display-table ; queries :y-or-n-def ; error handling :die :or-die :or-do :die-if-null :error! ; reader macros ; #? Ø ? « ; time :universal->unix-time :unix->universal-time :get-unix-time :make-pretty-time :get-current-time :with-time :time-for-humans :time! ; for-each and friends :with-interactive-interrupt-handler :progress :break! :continue! :index! :value! :key! :for-each/line :for-each/list :for-each/hash :for-each/vector :for-each/stream :for-each/alist :for-each/call :for-each :forever ; shell and zsh :zsh :sh :zsh-simple :sh-simple ; other abbreviations and shortcuts :λ ; system :hostname :sys/info :get-envvar ; command-line arguments :program/script-name :cmdargs :def-cli-args :args! :bare-args! :+USAGE-TEXT!+ :print-usage! :process-args! ; terminal things / terminal manipulation :clear-screen :get-terminal-columns :ansi-up-line :ansi-left-all :ansi-clear-line :ansi-left-one :progress-bar :loading-forever :with-loading :give-choices ; file/filename/directory operations :basename :pwd :realpath :size-for-humans :file-size :inspect-pathname :ls :directory-exists-p :file-exists-p :file-or-directory-exists-p :walk-directory :-path :+path :absolute->relative :change-extension :file-find )) (in-package :pluto) (pushnew :pluto *features*) ;---------------------------------------------------------; ; pluto parameters ---------------------------------------; (defparameter *pluto-output-stream* *terminal-io*) (defparameter *pluto-log-level* 2) (defparameter *pluto-log-file* "pluto-log.out") (defparameter *pluto-curly-test* #'equal) ; TODO: implementation dependent (defparameter *pluto-external-format* #+clisp CHARSET:UTF-8 #-clisp :UTF-8) (defparameter *pluto-shell* "/usr/local/bin/zsh") (defvar *unix-epoch-difference* (encode-universal-time 0 0 0 1 1 1970 0)) (defvar *whitespaces* '(#\Space #\Newline #\Backspace #\Tab #\Linefeed #\Page #\Return #\Rubout)) ;---------------------------------------------------------; ;---------------------------------------------------------; ; formatting ---------------------------------------------; (defmacro fn (&rest everything) "Alias to (format nil ...)" `(format nil ,@everything)) (defmacro ft (&rest everything) "Alias to (format t ...)" `(format t ,@everything)) ;---------------------------------------------------------; ;---------------------------------------------------------; ; ansi colors and codes ----------------------------------; (defun make-ansi-escape (anum &optional (decoration 'bold)) (format nil "~c[~A~Am" #\ESC anum (cond ((eq decoration 'bold) ";1") ((eq decoration 'underline) ";4") ((eq decoration 'reversed) ";7") (t "")))) (defvar +reset-terminal-color+ (make-ansi-escape 0 nil)) (defvar +magenta-bold+ (make-ansi-escape 35)) (defvar +red-bold+ (make-ansi-escape 31)) (defvar +yellow-bold+ (make-ansi-escape 33)) (defvar +green-bold+ (make-ansi-escape 32)) (defvar +cyan-bold+ (make-ansi-escape 36)) (defvar +blue-bold+ (make-ansi-escape 34)) (defvar +grey-bold+ (make-ansi-escape 90)) (defvar +ansi-escape-up+ (format nil "~c[1A" #\ESC)) (defvar +ansi-escape-left-all+ (format nil "~c[500D" #\ESC)) (defvar +ansi-escape-left-one+ (format nil "~c[1D" #\ESC)) (defun do-with-color (acolor thestring &rest everything) (apply #'format nil (format nil "~A~A~A" acolor thestring +reset-terminal-color+) everything)) (defmacro make-color-fun (thename acolor) `(defun ,thename (thestring &rest things) (apply #'do-with-color ,acolor thestring things))) (make-color-fun magenta +magenta-bold+) (make-color-fun red +red-bold+) (make-color-fun yellow +yellow-bold+) (make-color-fun green +green-bold+) (make-color-fun cyan +cyan-bold+) (make-color-fun blue +blue-bold+) (make-color-fun grey +grey-bold+) ;---------------------------------------------------------; ; ------------------------------------------------------- ; ; string operations ------------------------------------- ; (defun str+ (&rest args) "Combine (using princ) an arbitrary number of args into one string" (with-output-to-string (s) (dolist (a args) (princ a s)))) (defun str-join (delim strings) "Join STRINGS with DELIM." (format nil (format nil "~~{~~A~~^~A~~}" delim) strings)) ; TODO: did I take this from somewhere (defun substr (string start &optional end) "Efficient substring of STRING from START to END (optional), where both can be negative, which means counting from the end." (let ((len (length string))) (subseq string (if (minusp start) (+ len start) start) (if (and end (minusp end)) (+ len end) end)))) ; TODO: check all for undocumented (defun string->char-list (astring) "Make a string a list of single character strings" (map 'list #'string astring)) (defun split-string->lines (astring) "Split a string with new lines into a list of strings (one for each line)" (with-input-from-string (s astring) (loop for value = (read-line s nil) while value collect value))) ; TODO: document (defun repeat-string (str times) (fn "~{~A~}" (loop for i from 1 to times collect str))) ; ------------------------------------------------------- ; ;---------------------------------------------------------; ; some essential utilities/macros ------------------------; ; TODO: Do all of these need to be in _this_ section? (defmacro with-gensyms ((&rest names) &body body) "Why mess with the classics" `(let ,(loop for n in names collect `(,n (gensym))) ,@body)) ; Stolen from "On Lisp" (defmacro mac (sexp) "Let's you do `(mac (anunquotesmacro))`" `(pprint (macroexpand-1 ',sexp))) ; Adapted from "On Lisp" (defmacro nil! (&rest rest) "Sets all the arguments to nil" (let ((tmp (mapcar (lambda (x) `(setf ,x nil)) rest))) `(progn ,@tmp))) ; I forgot where I stole this from (defmacro alambda (params &body body) "Anaphoric lambda. SELF! is the function" `(labels ((self! ,params ,@body)) #'self!)) (defmacro abbr (short long) `(defmacro ,short (&rest everything) `(,',long ,@everything))) (defun flatten (alist) " Flattens a list (possibly inefficiently)" (if alist (if (listp (car alist)) (append (flatten (car alist)) (flatten (cdr alist))) (cons (car alist) (flatten (cdr alist)))))) (defun take (alist n &optional (acc nil)) "Takes `n` from beginning of `alist` and returns that in a list. It also returns the remainder of the list (use `multiple-value-bind` with it" (when (and (> n 0) (null alist)) (error "not enough to take")) (if (= n 0) (values (nreverse acc) alist) (take (cdr alist) (- n 1) (cons (car alist) acc)))) (defun group (alist &optional (n 2) (acc nil)) "Turn a (flat) list into a list of lists of length `n`" (if (null alist) (nreverse acc) (multiple-value-bind (eins zwei) (take alist n) (group zwei n (cons eins acc))))) (defun create-symbol (&rest args) "Interns an string as a symbol." (values (intern (string-upcase (apply #'str+ args))))) (defun create-keyword (&rest args) "Interns an UP-cased string as a keyword symbol." (values (intern (string-upcase (apply #'str+ args)) :keyword))) (defun walk-replace-sexp (alist oldform newform &key (test #'equal)) "Walks sexpression substituting `oldform` for `newform`. It works with lists and well as atoms. Checks equality with `test` (which is #'EQUAL by default)" (if alist (let ((thecar (car alist))) (if (listp thecar) (if (tree-equal thecar oldform :test test) (cons newform (walk-replace-sexp (cdr alist) oldform newform :test test)) (cons (walk-replace-sexp thecar oldform newform :test test) (walk-replace-sexp (cdr alist) oldform newform :test test))) (let ((rplment (if (funcall test thecar oldform) newform thecar))) (cons rplment (walk-replace-sexp (cdr alist) oldform newform :test test))))))) (defmacro -<> (expr &rest forms) "Threading macro (put <> where the argument should be) Stolen from https://github.com/sjl/cl-losh/blob/master/src/control-flow.lisp" `(let* ((<> ,expr) ,@(mapcar (lambda (form) (if (symbolp form) `(<> (,form <>)) `(<> ,form))) forms)) <>)) (defmacro aif (test then &optional else) "Like IF. IT is bound to TEST." `(let ((it! ,test)) (if it! ,then ,else))) ; TODO: IS IT MAYBE BIGGER THAN IT NEEDS TO BE BECAUSE MULTIBYTE? (defun slurp (path) "Reads file at PATH into a single string" (with-open-file (stream path :if-does-not-exist :error) (let ((data (make-string (file-length stream)))) (read-sequence data stream) data))) ; TODO: what? (defun slurp-stream (astream) (with-open-stream (s astream) (let ((data (make-string (file-length s)))) (read-sequence data s) data))) (defun slurp-lines (afilename) "Reads lines of a file into a list" (with-open-file (tmp afilename :if-does-not-exist :error :external-format *pluto-external-format*) (loop for value = (read-line tmp nil) while value collect value))) (defun barf (path contents &key (printfn #'write-string) (overwrite nil)) "Outputs CONTENTS into filename PATH with function PRINTFN (default WRITE-STRING) and appends by default (controllable by by boolean OVERWRITE)" (with-open-file (stream path :direction :output :if-exists (if overwrite :supersede :append) :if-does-not-exist :create) (funcall printfn contents stream))) (defmacro debug-these (&rest therest) "Macro that takes an arbitrary number of arguments, prints the symbol, and then prints it's evaluated value (for debugging)" (flet ((debug (this) `(format *error-output* "~20S -> ~S~%" ',this ,this))) `(progn ,@(mapcar #'debug therest)))) ; TODO: use gensyms? ; TODO: implementation specific (defmacro with-a-file (filename key &body body) "Anaphoric macro that binds `stream!` to the stream First argument is the filename The second argument is one of `:w` - write to a file (clobber if already exists) `:a` - append to a file (create if doesn't exist) `:r` - read a file (in text mode) `:b` - read a file (in binary mode [unsigned-byte 8]) Only provide one of these arguments" (let ((dir (cond ((eq key :w) :output) ((eq key :a) :output) ((eq key :r) :input) ((eq key :b) :input))) (iex (cond ((eq key :w) :supersede) ((eq key :a) :append) ((eq key :r) :append) ((eq key :b) :append)))) `(with-open-file (stream! ,filename :direction ,dir :if-exists ,iex ,@(when (eq key :b) `(':element-type 'unsigned-byte)) :if-does-not-exist :create :external-format *pluto-external-format*) ,@body))) (defun interpose (separator list) "Returns a sequence of the elements of SEQUENCE separated by SEPARATOR." (labels ((rec (s acc) (if s (rec (cdr s) (nconc acc (list separator (car s)))) acc))) (cdr (rec list nil)))) (defun delim (anlist &key (what :list) (sep #\Tab)) "Makes a string with tabs separating values. `:what` either :list :listoflist :hash or :alist `:sep` the (CHARACTER) separator to use (default is tab)" (labels ((join-with-sep (x) (str-join (format nil "~C" sep) x)) (join-with-newlines (x) (str-join (format nil "~C" #\Newline) x))) (cond ((eq :list what) (str-join (format nil "~C" sep) anlist)) ((eq :alist what) (join-with-newlines (loop for i in anlist for key = (car i) for val = (cdr i) collect (join-with-sep (list key val))))) ((eq :listoflists what) (join-with-newlines (loop for i in anlist collect (join-with-sep i)))) ((eq :hash what) (join-with-newlines (loop for key being the hash-keys in anlist using (hash-value val) collect (join-with-sep (list key val))))) (t (error "unsupported type"))))) (defmacro defparams (&body body) "Declares the arguments to by special defparameter parameters with a value on `nil`" (labels ((helper (alist) (loop for i in alist collect `(defparameter ,i nil)))) (let ((tmp (helper body))) `(progn ,@tmp)))) (defun round-to (number precision &optional (what #'round)) "Round `number` to `precision` decimal places. Stolen from somewhere" (let ((div (expt 10 precision))) (float (/ (funcall what (* number div)) div)))) (defun advise (message &key (yellow-p t)) "Prints MESSAGE to *ERROR-OUTPUT* but resumes (for use with OR-DIE's ERRFUN)" (format *error-output* "~A~A~A~%" (if yellow-p +yellow-bold+ "") message (if yellow-p +reset-terminal-color+ ""))) ; TODO: more we can test (defun alistp (something) "Test is something is an alist" (and (listp something) (every #'consp something))) (defmacro with-hash-entry ((ahash akey) &body body) "Establishes a lexical environment for referring to the _value_ of key `akey` on the hash table `ahash` using the anaphor `entry!`. So, you can setf `entry!` and the hash-table (for that key) will by modified." (with-gensyms (thehash thekey) `(let ((,thehash ,ahash) (,thekey ,akey)) (symbol-macrolet ((entry! (gethash ,thekey ,thehash))) ,@body)))) ; TODO: GOTTA BE A BETTER WAY! (defmacro if-hash-entry ((ahash akey) then &optional else) "Executes `then` if there's a key `akey` in hash-table `ahash` and `else` (optional) if not. For convenience, an anaphor `entry!` is introduced that is setf-able." (with-gensyms (thehash thekey) `(let ((,thehash ,ahash) (,thekey ,akey)) (with-hash-entry (,thehash ,thekey) (if entry! ,then ,else))))) (defmacro if-not-hash-entry ((ahash akey) then &optional else) "Executes `then` if there is _NOT_ key `akey` in hash-table `ahash` and `else` (optional) if exists. For convenience, an anaphor `entry!` is introduced that is setf-able." (with-gensyms (thehash thekey) `(let ((,thehash ,ahash) (,thekey ,akey)) (with-hash-entry (,thehash ,thekey) (if (not entry!) ,then ,else))))) (defun |•-reader| (stream char) "Alternate double quote" (declare (ignore char)) (let (chars) (do ((prev (read-char stream) curr) (curr (read-char stream) (read-char stream))) ((char= curr #\•) (push prev chars)) (push prev chars)) (coerce (nreverse chars) 'string))) (set-macro-character #\• #'|•-reader|) ; TODO: document ; TODO: TAKES A FUNCTION (defmacro capture-all-outputs (&body body) (let ((ret (gensym))) `(let ((*standard-output* (make-string-output-stream)) (*error-output* (make-string-output-stream))) (let ((,ret (funcall ,@body))) (values ,ret (get-output-stream-string *standard-output*) (get-output-stream-string *error-output*)))))) #+coreutils (defmacro with-temp-file (&body body) `(let ((tempfile! (zsh "mktemp"))) (unwind-protect (progn ,@body) (zsh (fn "rm ~A" tempfile!))))) ; TODO: document (defun display-table (header data width) (let ((num-cols (length header))) (ft (fn "~~{|~~{~~~AA|~~}~~%~~}" width) `(,(loop for i from 1 to num-cols collect (repeat-string "-" width)))) (ft (fn "~~{|~~{ ~~~AA|~~}~~%~~}" (- width 1)) `(,header)) (ft (fn "~~{|~~{~~~AA|~~}~~%~~}" width) `(,(loop for i from 1 to num-cols collect (repeat-string "-" width)))) (ft (fn "~~{|~~{ ~~~AA|~~}~~%~~}" (- width 1)) data) (ft (fn "~~{|~~{~~~AA|~~}~~%~~}" width) `(,(loop for i from 1 to num-cols collect (repeat-string "-" width)))))) ; ------------------------------------------------------- ; ; ------------------------------------------------------- ; ; Queries ------------------------------------------------; (defun yond-read-char (&key (default nil)) (clear-input *query-io*) (let ((tmp (read-char *query-io*))) (when (and default (char= tmp #\Newline)) (setq tmp default)) (clear-input *query-io*) tmp)) (defun yond-prompt (prompt &key (default nil)) (fresh-line *query-io*) (format *query-io* "~A ~A " prompt (if default (cond ((or (char= default #\y) (char= default #\Y)) "[Y/n]") ((or (char= default #\N) (char= default #\n)) "[y/N]") (t "(y or n)")) "(y or n)")) (finish-output *query-io*)) ; TODO: document (defun y-or-n-def (prompt &key (default nil)) (if default (loop (yond-prompt prompt :default default) (case (yond-read-char :default default) ((#\Y #\y) (return t)) ((#\N #\n) (return nil)) (t (format *query-io* "~&try again~%")))) (y-or-n-p prompt))) ; ------------------------------------------------------- ; ;---------------------------------------------------------; ; Error handling -----------------------------------------; ; TODO: implementation specific (defun die (message &key (status 1) (red-p t)) "Prints MESSAGE to *ERROR-OUTPUT* and quits with a STATUS (default 1)" (format *error-output* "~A~A~A~%" (if red-p +red-bold+ "") (fn message) (if red-p +reset-terminal-color+ "")) #+sbcl (sb-ext:quit :unix-status status) #+(or ecl clisp) (ext:exit status) #+abcl (ext:exit :status status)) (defmacro or-die ((message &key (errfun #'die)) &body body) "anaphoric macro that binds ERROR! to the error It takes a MESSAGE with can include ERROR! (via (format nil...) for example) It also takes ERRFUN which it will FUNCALL with the MESSAGE. The default is to DIE, but you can, for example, PRINC instead" `(handler-case (progn ,@body) (error (error!) (funcall ,errfun (format nil "~A" ,message))))) (defmacro or-do (orthis &body body) "anaphoric macro that binds ERROR! to the error. If the body fails, the form ORTHIS gets run." `(handler-case (progn ,@body) (error (error!) ,orthis))) (defmacro die-if-null (avar &rest therest) "Macro to check if any of the supplied arguments are null" (let ((whole (cons avar therest))) `(loop for i in ',whole do (unless (eval i) (die (format nil "Fatal error: ~A is null" i)))))) (defun ignore-the-errors-wrapper (stream char arg) (declare (ignore char)) (declare (ignore arg)) (let ((sexp (read stream t))) `(ignore-errors ,sexp))) (set-dispatch-macro-character #\# #\? #'ignore-the-errors-wrapper) (defun |ensure-not-null| (stream char) "Reader macro to check if symbol is null, otherwise, pass it on" (declare (ignore char)) (let ((sexp (read stream t))) `(progn (aif (eval ',sexp) it! (error "its null"))))) (set-macro-character #\Ø #'|ensure-not-null|) (defun |if-null->this| (stream char) "Reader macro that takes two s-expressions. If the first evaluates to not null, it is returned. If the first evaluates to null, the second s-expression is returned" (declare (ignore char)) (let ((sexp (read stream t)) (replacement (read stream t)) (res (gensym))) `(let ((,res ,sexp)) (if ,res ,res ,replacement)))) (set-macro-character #\? #'|if-null->this|) (defun |«-reader| (stream char) "Examples: « (/ 3 1) or die error! » ; returns 3 « (/ 3 0) or warn error! » ; stderrs error, continues, and returns NIL « (/ 3 0) or die error! » ; dies with error message « 3 or die error! » ; returns 3 « nil or die error! » ; dies because atom preceding `or` is NIL « 3 or do (format t •no~%•)! » ; returns 3 « nil or do (format t •no~%•) » ; prints 'no'" (declare (ignore char)) (let ((err-mess "« reader macro not written to specification") (ender "»") (before (read stream)) (theor (read stream)) (theoperator (read stream)) (after (read stream)) (theend-p (symbol-name (read stream)))) ; syntax error checking (unless (string= theend-p ender) (die err-mess)) (unless (string= (symbol-name theor) "OR") (die err-mess)) (cond ((consp before) (cond ((string= "DIE" (symbol-name theoperator)) `(or-die (,after) ,before)) ((string= "WARN" (symbol-name theoperator)) `(or-die (,after :errfun #'advise) ,before)) ((string= "DO" (symbol-name theoperator)) `(or-do ,after ,before)))) ((atom before) (cond ((string= "DIE" (symbol-name theoperator)) `(if ,before ,before (die ,after))) ((string= "WARN" (symbol-name theoperator)) `(if ,before ,before (advise ,after))) ((string= "DO" (symbol-name theoperator)) `(if ,before ,before ,after))))))) (set-macro-character #\« #'|«-reader|) ;---------------------------------------------------------; ; ------------------------------------------------------- ; ; what's the deal with T I M E ? ------------------------ ; (defun universal->unix-time (universal-time) "Converts universal (common lisp time from `(get-universal-time)` to UNIX time" (- universal-time *unix-epoch-difference*)) (defun unix->universal-time (unix-time) "Converts UNIX time to universal (common lisp time from `(get-universal-time)`" (+ unix-time *unix-epoch-difference*)) (defun get-unix-time () "Get current UNIX time" (universal->unix-time (get-universal-time))) (defun make-pretty-time (a-unix-time &key (just-date nil) (just-time nil) (time-sep ":") (dt-sep " ")) "Makes a nicely formatted (YYYY-MM-DD HH?:MM:SS) from a UNIX time `just-date` will return just the pretty date `just-time` will return just the pretty time `time-sep` will use the supplied string to separate the hours minutes and seconds (default ':') `dt-sep` will use the supplied string to separate the date from the time (default ' ')" (let ((thisuniversaltime (unix->universal-time a-unix-time))) (multiple-value-bind (second minute hour date month year) (decode-universal-time thisuniversaltime) (if (and (not just-date) (not just-time)) (format nil "~d-~2,'0d-~2,'0d~A~d~A~2,'0d~A~2,'0d" year month date dt-sep hour TIME-SEP minute TIME-SEP second) (if just-date (format nil "~d-~2,'0d-~2,'0d" year month date) (format nil "~d~A~2,'0d~A~2,'0d" hour TIME-SEP minute TIME-SEP second)))))) (defun get-current-time (&key (just-date nil) (just-time nil) (time-sep ":") (dt-sep " ")) "Uses `make-pretty-time` to get the current datetime" (make-pretty-time (-<> (get-universal-time) universal->unix-time) :just-date just-date :just-time just-time :time-sep time-sep :dt-sep dt-sep)) (defmacro with-time (&body aform) "Anaphoric macro that executes the car of the body and binds the seconds of execution time to TIME!. Then all the other forms in the body are executed" (let ((began (gensym)) (ended (gensym)) (ret (gensym))) `(let (,began ,ended time!) (setq ,began (get-universal-time)) (setq ,ret ,(car aform)) (setq ,ended (get-universal-time)) (setq time! (- ,ended ,began)) ,@(cdr aform) ,ret))) (defun time-for-humans (seconds) "Converts SECONDS into minutes, hours, or days (based on magnitude)" (cond ((> seconds 86400) (format nil "~$ days" (/ seconds 86400))) ((> seconds 3600) (format nil "~$ hours" (/ seconds 3600))) ((> seconds 60) (format nil "~$ minutes" (/ seconds 60))) ((< seconds 60) (format nil "~A seconds" seconds)))) ;---------------------------------------------------------; ;---------------------------------------------------------; ; for-each and friends ----------------------------------; (declaim (inline progress)) (defun progress (index limit &key (interval 1) (where *error-output*) (newline-p t)) (when (= 0 (mod index interval)) (format where (yellow "~A of ~A..... [~$%]" index limit (* 100 (/ index limit)))) (when newline-p (format where "~%")))) (defmacro break! () "For use with `for-each` It's short for `(return-from this-loop!" `(return-from this-loop!)) (defmacro continue! () "For use with `for-each` It's short for `(return-from this-pass!" `(return-from this-pass!)) ; TODO: implementation dependent (defmacro with-interactive-interrupt-handler (the-message &body body) `(handler-case (progn ,@body) (#+sbcl sb-sys:interactive-interrupt #+ecl ext:interactive-interrupt #+clisp system::simple-interrupt-condition #+ccl ccl:interrupt-signal-condition #+allegro excl:interrupt-signal () (die ,the-message)))) ; TODO: external format doesn't work on clisp (defmacro for-each/line (a-thing &body body) "(see documentation for `for-each`)" (let ((resolved-fn (gensym)) (instream (gensym))) `(with-interactive-interrupt-handler "~%Loop aborted. Bailing out.~%" (let ((index! 0) (value! nil) (,resolved-fn ,a-thing)) (declare (ignorable value!)) (with-open-file (,instream ,resolved-fn :if-does-not-exist :error :external-format *pluto-external-format*) (block this-loop! (loop for value! = (read-line ,instream nil) while value! do (progn (incf index!) (block this-pass! ,@body))))))))) (defmacro for-each/list (a-thing &body body) "(see documentation for `for-each`)" (let ((the-list (gensym))) `(with-interactive-interrupt-handler "~%Loop aborted. Bailing out.~%" (let ((index! 0) (value! nil) (,the-list ,a-thing)) (declare (ignorable value!)) (block this-loop! (dolist (value! ,the-list) (incf index!) (block this-pass! ,@body))))))) (defmacro for-each/hash (a-thing &body body) "(see documentation for `for-each`)" (let ((the-hash (gensym)) (tmp (gensym))) `(with-interactive-interrupt-handler "~%Loop aborted. Bailing out.~%" (let ((index! 0) (key! nil) (value! nil) (,the-hash ,a-thing)) (declare (ignorable value!)) (declare (ignorable key!)) (block this-loop! (loop for ,tmp being the hash-keys of ,the-hash do (progn (incf index!) (setq key! ,tmp) (setq value! (gethash key! ,the-hash)) (block this-pass! ,@body)))))))) (defmacro for-each/vector (a-thing &body body) "(see documentation for `for-each`)" (let ((the-vector (gensym))) `(with-interactive-interrupt-handler "~%Loop aborted. Bailing out.~%" (let ((index! 0) (value! nil) (,the-vector ,a-thing)) (declare (ignorable value!)) (block this-loop! (loop for value! across ,the-vector do (progn (incf index!) (block this-pass! ,@body)))))))) ; TODO: use unwind-protect? (defmacro for-each/stream (the-stream &body body) "(see documentation for `for-each`)" (let ((instream (gensym))) `(with-interactive-interrupt-handler "~%Loop aborted. Bailing out.~%" (let ((index! 0) (value! nil) (,instream ,the-stream)) (declare (ignorable value!)) (block this-loop! (loop for value! = (read-line ,instream nil) while value! do (progn (incf index!) (block this-pass! ,@body)))))))) (defmacro for-each/alist (aalist &body body) "This works like `for-each/hash` (see documentation for `for-each`) but it has to be called explicitly (as `for-each/alist`) instead of relying on `for-each`'s 'dispatch' mechanism." (let ((tmp (gensym)) (resolved (gensym))) `(with-interactive-interrupt-handler "~%Loop aborted. Bailing out.~%" (let ((index! 0) (key! nil) (value! nil) (,resolved ,aalist)) (declare (ignorable value!)) (declare (ignorable key!)) (block this-loop! (loop for ,tmp in ,resolved do (progn (incf index!) (setq key! (car ,tmp)) (setq value! (cdr ,tmp)) (block this-pass! ,@body)))))))) (defmacro for-each/call (aclosure &body body) "This works like `for-each` (see documentation for it) but due to differences, it is not automatically dispatched so if always needs to be called explicitly). It's only argument (besides the body) is a closure that is repeatedly `FUNCALL`ed and terminates when the closure returns NIL" `(with-interactive-interrupt-handler "~%Loop aborted. Bailing out.~%" (let ((index! 0) (value! nil)) (declare (ignorable value!)) (block this-loop! (loop for value! = (funcall ,aclosure) while value! do (progn (incf index!) (block this-pass! ,@body))))))) ; TODO: weird sbcl compiler notes (defmacro for-each (a-thing &body body) "A super-duper imperative looping construct. It takes either a filename string (to be treated as a file and goes line by line) a pathname (goes line by line) a hash-table a vector a list a string (that goes character by character) or a stream (that goes line by line) It is anaphoric and introduces index! (which is a zero indexed counter of which element we are on) key! (the key of the current hash-table entry [only for hash-tables and alists]) value! (the value of the current element) this-pass! (a block that returning from immediately moves to the next iteration) this-loop! (a block that returning from exits the loop) For convenience, (continue!) and (break!) will execute (return-from this-pass!) and (return-from this-loop!), respectively If it's a filename, the external format is *pluto-external-format* (:UTF-8 by default) Oh, it'll die gracefully if Control-C is used during the loops execution. And, finally, for extra performance, you can call it's subordinate functions directly. They are... for-each/line, for-each/list, for-each/hash, for-each/vector, for-each/stream, and for-each/alist" (let ((tmp (gensym))) `(let ((,tmp ,a-thing)) (cond ((and (stringp ,tmp) (probe-file ,tmp)) (for-each/line ,tmp ,@body)) (t (progn (etypecase ,tmp (pathname (for-each/line ,tmp ,@body)) (hash-table (for-each/hash ,tmp ,@body)) (vector (for-each/vector ,tmp ,@body)) (list (for-each/list ,tmp ,@body)) (stream (for-each/stream ,tmp ,@body))))))))) (defmacro forever (&body body) "Performed BODY forever. Must be terminated by RETURN-FROM NIL, or, simple RETURN Simple wrapper around `(loop (progn ,@body))`" `(with-interactive-interrupt-handler "~%Loop aborted. Bailing out.~%" (block nil (loop (progn ,@body))))) ;---------------------------------------------------------; ; ------------------------------------------------------- ; ; universal indexing operator syntax -------------------- ; (defun |{-reader| (stream char) (declare (ignore char)) (let ((inbetween nil)) (let ((chars nil)) (do ((prev (read-char stream) curr) (curr (read-char stream) (read-char stream))) ((char= curr #\}) (push prev chars)) (push prev chars)) (setf inbetween (coerce (nreverse chars) 'string))) (let ((leido (read-from-string (fn "(~A)" inbetween)))) `(pluto-get ,@leido)))) (defmethod get-at ((this list) that) (cond ((alistp this) (cdr (assoc that this :test *pluto-curly-test*))) (t (nth that this)))) (defmethod get-at ((this vector) that) (aref this that)) (defmethod get-at ((this hash-table) that) (gethash that this)) (defmethod get-at ((this structure-object) that) (slot-value this that)) (defmethod get-at ((this standard-object) that) (slot-value this that)) ; TODO: this ; (defmethod get-at ((this RUNE-DOM::DOCUMENT) that) ; (xpath this that)) (set-macro-character #\{ #'|{-reader|) (defun (setf get-at) (new this that) (cond ((simple-vector-p this) (setf (svref this that) new)) ((vectorp this) (setf (aref this that) new)) ((hash-table-p this) (setf (gethash that this) new)) ((alistp this) (setf (cdr (assoc that this :test *pluto-curly-test*)) new)) ((listp this) (setf (nth that this) new)) ((typep this 'structure-object) (setf (slot-value this that) new)) ((typep this 'standard-object) (setf (slot-value this that) new)) )) (defmacro suc-apply (afun &rest rest) (let ((built nil) (thing (car rest)) (thefirst (cadr rest)) (therest (cddr rest))) (setq built (reduce (lambda (x y) `(,afun ,x ,y)) therest :initial-value `(,afun ,thing ,thefirst))) built)) (defmacro pluto-get (x &rest rest) `(suc-apply get-at ,x ,@rest)) ;---------------------------------------------------------; ; ------------------------------------------------------- ; ; shell and zsh ----------------------------------------- ; ; workarounds for clisp and abcl (defun %slurp-stream-lines (astream) (loop for this = (read-line astream nil) while this collect this)) (defun %reconstruct-stream (lines) (let ((s (make-string-output-stream))) (for-each/list lines (format s "~A~%" value!)) (substr (get-output-stream-string s) 0 -1))) ; TODO: a whole bunch ; TODO: implementation dependent #+sbcl (defun zsh (acommand &key (dry-run nil) (err-fun #'(lambda (code stderr) (error (format nil "~A (~A)" stderr code)))) (echo nil) (enc *pluto-external-format*) (in t) (return-string t) (split nil) (interactive nil)) "Runs command `acommand` through the shell specified by the global *pluto-shell* `dry-run` just prints the command (default nil) `err-fun` takes a function that takes an error code and the STDERR output `echo` will print the command before running it `enc` takes a format (default is *pluto-external-format* [which is :UTF-8 by default]) `in` t is inherited STDIN. nil is /dev/null. (default t) `return-string` t returns the output string. nil inherits stdout (default t) `split` will separate the stdout by newlines and return a list (default: nil) `interactive` will use the '-i' option to make the shell interactive (default: nil)" (flet ((strip (astring) (if (string= "" astring) astring (subseq astring 0 (- (length astring) 1))))) (when (or echo dry-run) (format t "$ ~A~%" acommand)) (unless dry-run (let* ((arglist `(,(if interactive "-ic" "-c") ,(fn "~A;~A" acommand (if interactive "exit" "")))) (outs (if return-string (make-string-output-stream) t)) (errs (make-string-output-stream)) (theprocess (sb-ext:run-program *pluto-shell* arglist :input in :output outs :error errs :external-format enc)) (retcode (sb-ext:process-exit-code theprocess))) (when (> retcode 0) (funcall err-fun retcode (strip (get-output-stream-string errs)))) (when return-string (values (if split (split-string->lines (get-output-stream-string outs)) (strip (get-output-stream-string outs))) (strip (get-output-stream-string errs)) retcode)))))) ; TODO: fill in doc string #+ecl (defun zsh (acommand &key (dry-run nil) (err-fun #'(lambda (code stderr) (error (format nil "~A (~A)" stderr code)))) (echo nil) (return-string t) (split nil) (interactive nil)) (flet ((strip (astring) (if (string= "" astring) astring (subseq astring 0 (- (length astring) 1))))) (when (or echo dry-run) (format t "$ ~A~%" acommand)) (unless dry-run (let* ((arglist `(,(if interactive "-ic" "-c") ,(fn "~A;~A" acommand (if interactive "exit" "")))) (outs (if return-string (make-string-output-stream) t)) (errs (make-string-output-stream))) (multiple-value-bind (procstream retcode process) (ext:run-program *pluto-shell* arglist :output outs :error errs) (ext:external-process-wait process) (when (> retcode 0) (funcall err-fun retcode (strip (get-output-stream-string errs)))) (when return-string (values (if split (split-string->lines (get-output-stream-string outs)) (strip (get-output-stream-string outs))) (strip (get-output-stream-string errs)) retcode))))))) #+ clisp (defun zsh (acommand &key (dry-run nil) (err-fun #'error) (echo nil) (split nil) (interactive nil)) "Runs command `acommand` through the ZSH shell specified by the global *pluto-shell* `dry-run` just prints the command (default nil) `err-fun` takes a function that takes an error code and the STDERR output `echo` will print the command before running it `split` will separate the stdout by newlines and return a list (default: nil) `interactive` will use the '-i' option to make the shell interactive (default: nil)" (when (or echo dry-run) (format t "$ ~A~%" acommand)) (unless dry-run (let* ((arglist `(,(if interactive "-ic" "-c") ,(fn "~A;~A" acommand (if interactive "exit" ""))))) (or-die ((fn "error <~A> with shell command <~A>" error! acommand) :errfun error) (with-open-stream (s (ext:run-program *pluto-shell* :arguments arglist :output :stream)) (if split (%slurp-stream-lines s) (%reconstruct-stream (%slurp-stream-lines s)))))))) ; TODO: write documentation #+abcl (defun zsh (acommand &key (dry-run nil) (err-fun #'(lambda (code stderr) (error (format nil "~A (~A)" stderr code)))) (echo nil) (in t) (return-string t) (split nil) (interactive nil)) (when (or echo dry-run) (format t "$ ~A~%" acommand)) (unless dry-run (let* ((arglist `(,(if interactive "-ic" "-c") ,(fn "~A;~A" acommand (if interactive "exit" "")))) (theprocess (system:run-program *pluto-shell* arglist :input in))) (system:process-wait theprocess) (let ((retcode (system:process-exit-code theprocess)) (outstream (system:process-output theprocess)) (errstream (system:process-error theprocess))) (when (> retcode 0) (funcall err-fun retcode "returns non 0 exit code")) (when return-string (values (if split (%slurp-stream-lines outstream) (%reconstruct-stream (%slurp-stream-lines outstream))) retcode)))))) ; TODO: have a not-implememted error #+(or sbcl ecl clisp abcl) (setf (fdefinition 'sh) #'zsh) ; TODO document (defmacro sh-simple (acommand) #+sbcl `(sb-ext:run-program *pluto-shell* `("-c" ,,acommand)) #+ecl `(ext:run-program *pluto-shell* `("-c" ,,acommand)) #+clisp `(ext:run-program *pluto-shell* :arguments `("-c" ,,acommand)) ) #+(or sbcl ecl clisp) (abbr zsh-simple sh-simple) ; ------------------------------------------------------- ; ; ------------------------------------------------------- ; ; other abbreviations and shortcuts --------------------- ; (defmacro λ (&body body) `(lambda ,@body)) (defun %remove-after-first-whitespace (astring) (let ((pos1 (position-if (lambda (x) (member x *whitespaces*)) astring))) (substr astring 0 pos1))) ;---------------------------------------------------------; ; ------------------------------------------------------- ; ; system -------------------------------------------------; ; TODO: USE UIOP FOR THESE?! (defun hostname () #+clisp (%remove-after-first-whitespace (machine-instance)) #+(or abcl clasp clozure cmucl ecl genera lispworks mcl mezzano mkcl sbcl scl xcl) (machine-instance)) ; TODO: beef out ; TODO: distro (defun sys/info () (let ((kernel (zsh "uname -s")) (os (zsh "uname -o")) (hostname (hostname)) (architecture (zsh "uname -m"))) (let ((info `((:kernel . ,(cond ((string= kernel "Linux") :linux) ((string= kernel "Darwin") :darwin) (t :unknown))) (:os . ,(cond ((string= os "GNU/Linux") :gnu/linux) ((string= os "Darwin") :darwin) ((string= os "Android") :android) (t :unknown))) (:hostname . ,hostname) (:architecture . ,(cond ((search "x86" architecture) :x86) ((search "arm" architecture) :arm)))))) (when (eq (cdr (assoc :os info)) :gnu/linux) (push `(:distro . ,(create-keyword (zsh "lsb_release -a 2> /dev/null | head -n 1 | awk '{ print $3 }'"))) info)) info))) ; TODO: write documentation ; TODO: implementation dependent ; TODO: SBCL DOESN't get columns ; TODO: https://stackoverflow.com/questions/44236376/how-do-i-get-the-list-of-all-environment-variables-available-in-a-lisp-process (defun get-envvar (name &optional default) #+cmu (let ((x (assoc name ext:*environment-list* :test #'string=))) (if x (cdr x) default)) #-cmu (or #+sbcl (sb-ext:posix-getenv name) #+(or abcl clasp clisp ecl xcl) (ext:getenv name) #+allegro (sys:getenv name) #+lispworks (lispworks:environment-variable name) default)) ; ------------------------------------------------------- ; ;---------------------------------------------------------; ; command line arguments ---------------------------------; ; TODO: document ; TODO: implementation-dependent? with the envvar thing? (defun program/script-name () (basename (if *load-truename* (namestring *load-truename*) (get-envvar "_")))) ; TODO: implementation dependent ; TODO: get program name in clisp (defun cmdargs () "A multi-implementation function to return argv (program name is CAR)" (let ((tmp (or #+sbcl sb-ext:*posix-argv* #+ecl (ext:command-args) #+clisp (cons "program_name" ext:*args*) #+lispworks system:*line-arguments-list* #+cmu extensions:*command-line-words* nil ))) (cons (program/script-name) (cdr tmp)))) (defun %ext-flag-match-p (astring) (let ((as-chars (coerce astring 'list))) (and (char= (car as-chars) #\-) (> (length as-chars) 2) (every #'alpha-char-p (cdr as-chars))))) (defmacro def-cli-args (script-name after-name description &body body) (let* ((switches (mapcar #'second body)) (longswitches (mapcar #'third body)) (descriptions (mapcar #'fourth body)) (flag-lines (mapcar (lambda (x y z) (format nil " ~A, ~17A~A~%" x y z)) switches longswitches descriptions)) (tmp (mapcar (lambda (x) `((or (string= current ,(second x)) (string= current ,(third x))) (progn (or-die ((format nil "Fatal error processing ~A flag (~A)~%~%~A" ,(second x) error! +USAGE-TEXT!+)) ,@(nthcdr 4 x))))) body))) `(progn (defparameter args! nil) (defparameter bare-args! nil) (defparameter +USAGE-TEXT!+ nil) (macrolet ((assign-next-arg! (avar) `(progn (setq ,avar (cadr args!)) (process-args! (cddr args!))))) (or-die ("invalid arguments") (setq +USAGE-TEXT!+ (format nil "Usage: ~A ~A~%~A~%~%~A" ,script-name ,after-name ,description (format nil "~{~A~}" (list ,@flag-lines)))) (defun print-usage! () (format t "~A" +USAGE-TEXT!+) (die "" :status 0)) (defun process-args! (args) (setq args! args) (if (null args!) (setq bare-args! (reverse bare-args!)) (let ((current (car args!))) (cond ((%ext-flag-match-p current) (process-args! (append (mapcar (lambda (x) (format nil "-~A" x)) (cdr (string->char-list current))) (cdr args)))) ,@tmp (t (progn (setq bare-args! (cons current bare-args!)) (process-args! (cdr args!))))))))))))) ;---------------------------------------------------------; ; ------------------------------------------------------- ; ; terminal things / terminal manipulation --------------- ; ; :TODO: implementation dependent (defun clear-screen () "A multi-implementation function to clear the terminal screen" #+sbcl (sb-ext:run-program "/bin/sh" (list "-c" "clear") :input nil :output *standard-output*) #+clisp (ext:shell "clear") #+ecl (si:system "clear") #+clozure (ccl:run-program "/bin/sh" (list "-c" "clear") :input nil :output *standard-output*)) ; TODO: SBCL doesn't have the COLUMNS environment variable. fix it (defun get-terminal-columns () "Retrieves the number of columns in terminal by querying `$COLUMNS` environment variable. Returns (values num-of-columns t) if successful and (values 200 nil) if not" (let ((raw-res (ignore-errors (parse-integer #+sbcl (zsh "echo $COLUMNS") #-sbcl (get-envvar "COLUMNS" "80") )))) (if raw-res (values raw-res t) (values 200 nil)))) ; TODO: is there are better DRY way? (defun ansi-up-line (&optional (where *error-output*)) (format where "~A" +ansi-escape-up+)) (defun ansi-left-all (&optional (where *error-output*)) (format where "~A" +ansi-escape-left-all+)) (defun ansi-clear-line (&optional (where *error-output*)) (ansi-left-all) (format where "~A" (make-string (get-terminal-columns) :initial-element #\Space))) (defun ansi-left-one (&optional (where *error-output*)) (format where "~A" +ansi-escape-left-one+)) ; TODO: what if it's interactive ; TODO: test on different implementations (defun progress-bar (index limit &key (interval 1) (where *error-output*) (width 60) (one-line t) (out-of nil)) (when (or (= index limit) (and (= 0 (mod index interval)))) (let* ((perc-done (/ index limit)) (filled (round (* perc-done width)))) (when one-line (ansi-up-line where) (ansi-clear-line where) (ansi-left-all where)) (format where (yellow "~& ◖~A~A ◗ ~$% ~A" (make-string filled :initial-element #\▬) (make-string (max 0 (- width filled)) :initial-element #\▭) (float (* 100 perc-done)) (if out-of (fn " [~A/~A]" index limit) ""))) (force-output where)))) (defun loading-forever () (let ((counter -1)) (forever (incf counter) (setq counter (mod counter 4)) (let ((rune (case counter (0 "-") (1 "\\") (2 "|") (t "/")))) (format t "~A" rune) (force-output) (ansi-left-one *standard-output*) (sleep 0.1))))) ; TODO: only sbcl and ecl ; TODO: update doc string (defmacro with-loading (&body body) "This function runs `body` in a separate thread and also starts a thread that displays a spinner. When the `body` thread finishes, it kills the spinner thread. Here's an example.... ``` (for-each `(heaven or las vegas) (ft •processing: ~10A~C• value! #\Tab) (with-loading (sleep 3))) ``` its particularly neat combined with ``` (progress index! 5 :newline-p nil :where *standard-output*) (ft •~C• #\Tab #\Tab) ``` " (let ((long-thread (gensym)) (loading-thread (gensym)) (the-return (gensym))) `(progn (let ((,long-thread #+sbcl (sb-thread:make-thread (lambda () ,@body) :name "background-thread") #+ecl (mp:process-run-function 'background-thread (lambda () ,@body)) ; (bt:make-thread (lambda () ,@body) :name "long-thread") ) (,loading-thread #+sbcl (sb-thread:make-thread #'loading-forever :name "loading-thread") #+ecl (mp:process-run-function 'loading-thead #'loading-forever) ; (bt:make-thread #'loading-forever :name "loading-thread") )) (let ((,the-return #+sbcl (sb-thread:join-thread ,long-thread) #+ecl (mp:process-join ,long-thread) ; (bt:join-thread ,long-thread) )) #+sbcl (sb-thread:terminate-thread ,loading-thread) #+ecl (mp:process-kill ,loading-thread) ; (bt:destroy-thread ,loading-thread) (terpri) ,the-return))))) #-(or sbcl ecl) (defmacro with-loading (&body body) `(warn "only implemented for sbcl and ecl")) (defun give-choices (choices &key (limit 37) (num-p nil) (mode :table) (sep nil)) "Uses `smenu` (must be installed) to give the user some choices in a list (princs the elements). The user's choice(s) are returned unless they Control-C, in which case it return `nil`. You can also use '/' to search through the choices! It's (smenu) is very flexible and this function offers a lot of optional keyword parameters `limit` sets the limit of choices (and presents a scroll bar) `num-p` if true, puts a number next to the choices for easy selection (default nil) `mode` :table (default), :columns, :lines, and nil `sep` if not nil, it will allow the user to select multiple choices (with 't') and this string will separate them all" (let ((tmpvar (fn "tmp~A" (get-unix-time))) (xchoice (fn "'~A'" (str-join "'\\n'" choices))) (xmode (case mode (:columns "-c") (:table "-t") (:lines "-l") (otherwise "")))) (let ((response (zsh (fn "~A=$(echo -e \"~A\" | smenu ~A -n~A ~A ~A); echo $~A" tmpvar xchoice (if num-p "-N" "") limit xmode (if sep (fn "-T '~A'" sep) "") tmpvar) :echo nil))) (if (string= response "") nil response)))) ;---------------------------------------------------------; ; ------------------------------------------------------- ; ; file/filename/directory operations -------------------- ; ; TODO: document (defun basename (apath) (file-namestring apath)) (defparameter %%ylimit (expt 2 80)) (defparameter %%zlimit (expt 2 70)) (defparameter %%elimit (expt 2 60)) (defparameter %%plimit (expt 2 50)) (defparameter %%tlimit (expt 2 40)) (defparameter %%glimit (expt 2 30)) (defparameter %%mlimit (expt 2 20)) (defparameter %%klimit (expt 2 10)) (defun size-for-humans (asize) ; have block size? (cond ((> asize %%ylimit) (fn "~1$Y" (/ asize %%ylimit))) ((> asize %%zlimit) (fn "~1$Z" (/ asize %%zlimit))) ((> asize %%elimit) (fn "~1$E" (/ asize %%elimit))) ((> asize %%plimit) (fn "~1$P" (/ asize %%plimit))) ((> asize %%tlimit) (fn "~1$T" (/ asize %%tlimit))) ((> asize %%glimit) (fn "~1$G" (/ asize %%glimit))) ((> asize %%mlimit) (fn "~AM" (round (/ asize %%mlimit)))) ((> asize %%klimit) (fn "~AK" (round (/ asize %%klimit)))) (t (fn "~A" asize)))) (defun file-size (afilename &key (human nil)) (with-open-file (s afilename :element-type '(unsigned-byte 8)) (if human (size-for-humans (file-length s)) (file-length s)))) #-clisp (defun pwd () (let ((tmp #+(or abcl genera mezzano xcl) (truename *default-pathname-defaults*) #+clisp (ext:default-directory) #+(or clasp ecl) (ext:getcwd) #+clozure (ccl:current-directory) #+sbcl (sb-ext:parse-native-namestring (sb-unix:posix-getcwd/)))) (namestring tmp))) #+clisp (defun pwd () (namestring (ext:default-directory))) ; #+coreutils (defun realpath (apath &key (expand-symlinks t) (relative-to nil) (all-existing t)) "Prints resolved path. Needs coreutils and :coreutils must be in *features* `expand-symlinks` boolean (default t) `relative-to` print resolved path relative to supplied path `all-existing` requires that all the directories/files exist (default t) when false, all but the last component must exist. All paths must be escaped (if escaping is needed)" (unless (probe-file apath) (error "no such file")) (let ((command (fn "realpath ~A ~A ~A ~A" (if expand-symlinks "" "-s") (if all-existing "-e" "") apath (if relative-to (fn "--relative-to=~A" (realpath relative-to)) "")))) (nth-value 0 (zsh command)))) (defun inspect-pathname (apathname) (format *error-output* "received: ~S~%" apathname) ; (format *error-output* "probe file: ~S~%" (probe-file apathname)) (format *error-output* "pathname device: ~S~%" (pathname-device apathname)) (format *error-output* "pathname host: ~S~%" (pathname-host apathname)) (format *error-output* "pathname version: ~S~%" (pathname-version apathname)) (format *error-output* "pathname directory: ~S~%" (pathname-directory apathname)) (format *error-output* "pathname name: ~S~%" (pathname-name apathname)) (format *error-output* "pathname type: ~S~%" (pathname-type apathname)) (format *error-output* "truename: ~S~%" (truename apathname)) (format *error-output* "namestring: ~S~%" (namestring apathname)) (format *error-output* "wild pathname?: ~S~%" (wild-pathname-p apathname)) (format *error-output* "directory: ~S~%" (directory apathname)) (format *error-output* "directory namestring ~S~%" (directory-namestring apathname)) (format *error-output* "file author: ~S~%" (file-author apathname)) (format *error-output* "file namestring: ~S~%" (file-namestring apathname)) (format *error-output* "file write date: ~S~%" (file-write-date apathname)) (format *error-output* "host namestring: ~S~%" (host-namestring apathname)) (format *error-output* "enough namestring: ~S~%" (enough-namestring apathname))) ;;;;; ;;;;; STEALING FROM CL-FAD ;;;;; (defun component-present-p (value) "Helper function for DIRECTORY-PATHNAME-P which checks whether VALUE is neither NIL nor the keyword :UNSPECIFIC." (and value (not (eql value :unspecific)))) (defun directory-pathname-p (pathspec) "Returns NIL if PATHSPEC (a pathname designator) does not designate a directory, PATHSPEC otherwise. It is irrelevant whether file or directory designated by PATHSPEC does actually exist." (and (not (component-present-p (pathname-name pathspec))) (not (component-present-p (pathname-type pathspec))) pathspec)) ; to export (untested) (defun pathname-as-directory (pathspec) "Converts the non-wild pathname designator PATHSPEC to directory form." (let ((pathname (pathname pathspec))) (when (wild-pathname-p pathname) (error "Can't reliably convert wild pathnames.")) (cond ((not (directory-pathname-p pathspec)) (make-pathname :directory (append (or (pathname-directory pathname) (list :relative)) (list (file-namestring pathname))) :name nil :type nil :defaults pathname)) (t pathname)))) (defun directory-wildcard (dirname) "Returns a wild pathname designator that designates all files within the directory named by the non-wild pathname designator DIRNAME." (when (wild-pathname-p dirname) (error "Can only make wildcard directories from non-wildcard directories.")) (make-pathname :name #-:cormanlisp :wild #+:cormanlisp "*" :type #-(or :clisp :cormanlisp) :wild #+:clisp nil #+:cormanlisp "*" :defaults (pathname-as-directory dirname))) #+:clisp (defun clisp-subdirectories-wildcard (wildcard) "Creates a wild pathname specifically for CLISP such that sub-directories are returned by DIRECTORY." (make-pathname :directory (append (pathname-directory wildcard) (list :wild)) :name nil :type nil :defaults wildcard)) (defun pathname-as-file (pathspec) "Converts the non-wild pathname designator PATHSPEC to file form." (let ((pathname (pathname pathspec))) (when (wild-pathname-p pathname) (error "Can't reliably convert wild pathnames.")) (cond ((directory-pathname-p pathspec) (let* ((directory (pathname-directory pathname)) (name-and-type (pathname (first (last directory))))) (make-pathname :directory (butlast directory) :name (pathname-name name-and-type) :type (pathname-type name-and-type) :defaults pathname))) (t pathname)))) ; export ; TODO: ignore dot file option (defun ls (&optional (dirname "./") (follow-symlinks t)) "Returns a fresh list of pathnames corresponding to all files within the directory named by the non-wild pathname designator DIRNAME. The pathnames of sub-directories are returned in directory form - see PATHNAME-AS-DIRECTORY. If FOLLOW-SYMLINKS is true, then the returned list contains truenames (symlinks will be resolved) which essentially means that it might also return files from *outside* the directory. This works on all platforms. When FOLLOW-SYMLINKS is NIL, it should return the actual directory contents, which might include symlinks. Currently this works on SBCL and CCL." (declare (ignorable follow-symlinks)) (when (wild-pathname-p dirname) (error "Can only list concrete directory names.")) #-(or sbcl ccl) (unless follow-symlinks (error "implementation doesn't support _not_ following symlinks")) #+(or :ecl :clasp) (let ((dir (pathname-as-directory dirname))) (concatenate 'list (directory (merge-pathnames (pathname "*/") dir)) (directory (merge-pathnames (pathname "*.*") dir)))) #-(or :ecl :clasp) (let ((wildcard (directory-wildcard dirname))) #+:abcl (system::list-directory dirname) #+:sbcl (directory wildcard :resolve-symlinks follow-symlinks) #+(or :cmu :scl) (directory wildcard) #+:lispworks (directory wildcard :link-transparency follow-symlinks) #+(or :openmcl :digitool) (directory wildcard :directories t :follow-links follow-symlinks) #+:allegro (directory wildcard :directories-are-files nil) #+:clisp (nconc (directory wildcard :if-does-not-exist :keep) (directory (clisp-subdirectories-wildcard wildcard))) #+:cormanlisp (nconc (directory wildcard) (cl::directory-subdirs dirname))) #-(or :sbcl :cmu :scl :lispworks :openmcl :allegro :clisp :cormanlisp :ecl :abcl :digitool :clasp) (error "LIST-DIRECTORY not implemented")) (defun file-or-directory-exists-p (pathspec) "Checks whether the file named by the pathname designator PATHSPEC exists and returns its truename if this is the case, NIL otherwise. The truename is returned in `canonical' form, i.e. the truename of a directory is returned as if by PATHNAME-AS-DIRECTORY." ; #+ecl ; (if (or ; (search "*" (namestring pathspec)) ; (search "?" (namestring pathspec)) ; (search "\\" (namestring pathspec))) ; (error "ecl doesn't support '?', '*', or '\\' in the path")) #+(or :sbcl :lispworks :openmcl :ecl :digitool clasp) (probe-file pathspec) #+:allegro (or (excl:probe-directory (pathname-as-directory pathspec)) (probe-file pathspec)) #+(or :cmu :scl :abcl) (or (probe-file (pathname-as-directory pathspec)) (probe-file pathspec)) #+:cormanlisp (or (and (ccl:directory-p pathspec) (pathname-as-directory pathspec)) (probe-file pathspec)) #+:clisp (or (ignore-errors (let ((directory-form (pathname-as-directory pathspec))) (when (ext:probe-directory directory-form) (truename directory-form)))) (ignore-errors (probe-file (pathname-as-file pathspec)))) #-(or :sbcl :cmu :scl :lispworks :openmcl :allegro :clisp :cormanlisp :ecl :abcl :digitool :clasp) (error "FILE-EXISTS-P not implemented")) (defun directory-exists-p (pathspec) "Checks whether the file named by the pathname designator PATHSPEC exists and if it is a directory. Returns its truename if this is the case, NIL otherwise. The truename is returned in directory form as if by PATHNAME-AS-DIRECTORY." #+:allegro (and (excl:probe-directory pathspec) (pathname-as-directory (truename pathspec))) #+:lispworks (and (lw:file-directory-p pathspec) (pathname-as-directory (truename pathspec))) #-(or :allegro :lispworks) (let ((result (file-or-directory-exists-p pathspec))) (and result (directory-pathname-p result) result))) (defun file-exists-p (pathspec) (let ((tmp (file-or-directory-exists-p pathspec))) (and tmp (not (directory-exists-p pathspec))))) ; TODO: same options as ls? check symlink ability ; TODO: test if input is actually a directory (defun walk-directory (dirname fn &key directories (if-does-not-exist :error) (test (constantly t)) (follow-symlinks t)) "Recursively applies the function FN to all files within the directory named by the non-wild pathname designator DIRNAME and all of its sub-directories. FN will only be applied to files for which the function TEST returns a true value. If DIRECTORIES is not NIL, FN and TEST are applied to directories as well. If DIRECTORIES is :DEPTH-FIRST, FN will be applied to the directory's contents first. If DIRECTORIES is :BREADTH-FIRST and TEST returns NIL, the directory's content will be skipped. IF-DOES-NOT-EXIST must be one of :ERROR or :IGNORE where :ERROR means that an error will be signaled if the directory DIRNAME does not exist. If FOLLOW-SYMLINKS is T, then your callback will receive truenames. Otherwise you should get the actual directory contents, which might include symlinks. This might not be supported on all platforms. See LS." (labels ((walk (name) (cond ((directory-pathname-p name) ;; the code is written in a slightly awkward way for ;; backward compatibility (cond ((not directories) (dolist (file (ls name follow-symlinks)) (walk file))) ((eql directories :breadth-first) (when (funcall test name) (funcall fn name) (dolist (file (ls name follow-symlinks)) (walk file)))) ;; :DEPTH-FIRST is implicit (t (dolist (file (ls name follow-symlinks)) (walk file)) (when (funcall test name) (funcall fn name))))) ((funcall test name) (funcall fn name))))) (let ((pathname-as-directory (pathname-as-directory dirname))) (case if-does-not-exist ((:error) (cond ((not (file-or-directory-exists-p pathname-as-directory)) (error "File ~S does not exist." pathname-as-directory)) (t (walk pathname-as-directory)))) ((:ignore) (when (file-or-directory-exists-p pathname-as-directory) (walk pathname-as-directory))) (otherwise (error "IF-DOES-NOT-EXIST must be one of :ERROR or :IGNORE.")))) (values))) ; TODO: mention that it always FOLLOWS SYMLINKS (defun -path (pathone pathtwo) (pathname (enough-namestring (probe-file pathone) (directory-exists-p pathtwo)))) (defun +path (pathone pathtwo) (merge-pathnames pathtwo (directory-exists-p pathone))) (defun absolute->relative (apath &optional root) (when (eq :RELATIVE (car (pathname-directory apath))) (error "pathname is not absolute")) (-path apath (if root root (pwd)))) (defun change-extension (apath new-extension) (make-pathname :type new-extension :defaults apath)) ; TODO: document (defun file-find (apathname &key (type nil) (test (constantly t)) (ext nil) (regex nil) (inv-regex nil) (full t)) "ext implies type file regex is for full path if full is t (default)" (let (to-return) (walk-directory apathname #'(lambda (x) (push x to-return)) :directories :depth-first :test test) (setf (car to-return) (probe-file (car to-return))) (unless full (setq to-return (mapcar #'absolute->relative to-return))) (setq to-return (reverse to-return)) (when ext (setq type :file)) (when type (setq to-return (cond ((eq type :file) (remove-if-not #'file-exists-p to-return)) ((eq type :dir) (remove-if-not #'directory-exists-p to-return))))) (when ext (setq to-return (remove-if-not (lambda (x) (string= (pathname-type x) ext)) to-return))) (when regex (setq to-return (remove-if-not (lambda (x) (~m (namestring x) regex)) to-return))) (when inv-regex (setq to-return (remove-if (lambda (x) (~m (namestring x) inv-regex)) to-return))) to-return)) ; ------------------------------------------------------- ;
73,285
Common Lisp
.lisp
1,587
37.247637
131
0.54976
tonyfischetti/pluto
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
93606cfd5b1e2e4b8f78811af2bc0aacfbf4bf159f1bc89c10f33cd37bbe12c4
21,414
[ -1 ]
21,415
charon.lisp
tonyfischetti_pluto/charon.lisp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; Charon ;; ;; a companion to the pluto package that ;; ;; relies on external dependencies ;; ;; ;; ;; Tony Fischetti ;; ;; [email protected] ;; ;; ;; ;; License: GPL-3 ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defpackage :charon ; (:use :common-lisp) (:use :common-lisp :pluto) ; (:shadowing-import-from #:pluto #:realpath) (:import-from :parse-float :parse-float) (:export ; regular expressions / cl-ppcre wrappers :re-compile :str-split :str-replace :str-replace-all :str-detect :str-subset :str-extract :str-scan-to-strings :str-trim :~m :~r :~ra :~s :~f :~c :~e ; terminal things / terminal manipulation :with-loading ; HTML/XML stuff :request/get :request/post :parse-xml :parse-xml-file :xpath :xpath-compile :use-xml-namespace :xpath-string ; other abbriviations and shortcuts :alist->hash-table :hash-table->alist :hash-keys :parse-json :hash-table->json :parse-json-file :make-octet-vector :concat-octet-vector :parse-html :$$ ; re-exports :parse-float ; filename/namestring escaping :escape-namestring/shell :escape-namestring/c :pathname->shell :pathname->c ; ; rework of improve-able pluto functions ; :realpath )) (use-package :pluto) (in-package :charon) (pushnew :charon *features*) ;---------------------------------------------------------; ; regular expressions / cl-ppcre wrappers ----------------; (defmacro re-compile (&rest everything) `(cl-ppcre:create-scanner ,@everything)) (defmacro str-split (astr sep &rest everything) "Wrapper around cl-ppcre:split with string first" `(cl-ppcre:split ,sep ,astr ,@everything)) (defmacro str-replace (astr from to &rest everything) "Wrapper around cl-ppcre:regex-replace with string first" `(cl-ppcre:regex-replace ,from ,astr ,to ,@everything)) (defmacro str-replace-all (astr from to &rest everything) "Wrapper around cl-ppcre:regex-replace-all with string first" `(cl-ppcre:regex-replace-all ,from ,astr ,to ,@everything)) (defmacro str-detect (astr pattern &rest everything) "Returns true if `pattern` matches `astr` Wrapper around cl-ppcre:scan" `(if (cl-ppcre:scan ,pattern ,astr ,@everything) t nil)) (defun str-subset (anlist pattern) "Returns all elements that match pattern" (remove-if-not (lambda (x) (str-detect x pattern)) anlist)) (defun str-extract (astr pattern) "If one match, it returns the register group as a string. If more than one match/register-group, returns a list of register groups. If there is a match but no register group, it will still return nil" (multiple-value-bind (dontneed need) (cl-ppcre:scan-to-strings pattern astr) (let ((ret (coerce need 'list))) (if (= (length ret) 1) (car ret) ret)))) (defun str-scan-to-strings (astr pattern) "Wrapper around cl-ppcre:scan-to-strings with string first and only returns the important part (the vector of matches)" (multiple-value-bind (dontneed need) (cl-ppcre:scan-to-strings pattern astr) need)) (defun str-trim (astring) (string-trim *whitespaces* astring)) (defmacro ~m (&rest everything) "Alias to str-detect" `(str-detect ,@everything)) (defmacro ~r (&rest everything) "Alias to str-replace (one)" `(str-replace ,@everything)) (defmacro ~ra (&rest everything) "Alias to str-replace-all" `(str-replace-all ,@everything)) (defmacro ~s (&rest everything) "Alias to str-split" `(str-split ,@everything)) (defmacro ~f (&rest everything) "Alias to str-subset" `(str-subset ,@everything)) (defmacro ~c (&rest everything) "Alias to re-compile" `(re-compile ,@everything)) (defmacro ~e (&rest everything) "Alias to str-extract" `(str-extract ,@everything)) ; ------------------------------------------------------- ; ; ------------------------------------------------------- ; ; terminal things / terminal manipulation --------------- ; ; TODO: doesn't work on clisp ? (defmacro with-loading (&body body) "This function runs `body` in a separate thread and also starts a thread that displays a spinner. When the `body` thread finishes, it kills the spinner thread. Here's an example.... ``` (for-each `(heaven or las vegas) (ft •processing: ~10A~C• value! #\Tab) (with-loading (sleep 3))) ``` its particularly neat combined with ``` (progress index! 5 :newline-p nil :where *standard-output*) (ft •~C• #\Tab #\Tab) ``` " (let ((long-thread (gensym)) (loading-thread (gensym)) (the-return (gensym))) `(progn (let ((,long-thread #+sbcl (sb-thread:make-thread (lambda () ,@body) :name "background-thread") #+ecl (mp:process-run-function 'background-thread (lambda () ,@body)) #-(or sbcl ecl) (bt:make-thread (lambda () ,@body) :name "long-thread") ) (,loading-thread #+sbcl (sb-thread:make-thread #'loading-forever :name "loading-thread") #+ecl (mp:process-run-function 'loading-thead #'loading-forever) #-(or sbcl ecl) (bt:make-thread #'loading-forever :name "loading-thread") )) (let ((,the-return #+sbcl (sb-thread:join-thread ,long-thread) #+ecl (mp:process-join ,long-thread) #-(or sbcl ecl) (bt:join-thread ,long-thread) )) #+sbcl (sb-thread:terminate-thread ,loading-thread) #+ecl (mp:process-kill ,loading-thread) #-(or sbcl ecl) (bt:destroy-thread ,loading-thread) (terpri) ,the-return))))) ; ------------------------------------------------------- ; ;; !!! BELOW THIS IS UNTESTED ON CLISP ;; !!! AND DIDN'T PIECEMEAL COMPILE FOR SBCL WARNINGS ; ------------------------------------------------------- ; ; ------------------------------------------------------- ; ; ------------------------------------------------------- ; ; HTML/XML stuff ---------------------------------------- ; (defmacro request/get (&rest everything) `(dexador:get ,@everything)) (defmacro request/post (&rest everything) `(dexador:post ,@everything)) (defun parse-xml (astring) (cxml:parse astring (cxml-dom:make-dom-builder))) (defun parse-xml-file (afile) (cxml:parse-file afile (cxml-dom:make-dom-builder))) (defun xpath (doc anxpath &key (all t) (compiled-p nil) (text nil)) (let ((result (if compiled-p (xpath:evaluate-compiled anxpath doc) (xpath:evaluate anxpath doc)))) (unless (xpath:node-set-empty-p result) (if (and all text) (mapcar (lambda (x) (xpath:string-value x)) (xpath:all-nodes result)) (if (and all (not text)) (xpath:all-nodes result) (if (and (not all) text) (xpath:string-value result) result)))))) (defmacro xpath-compile (&rest everything) `(xpath:compile-xpath ,@everything)) (defmacro use-xml-namespace (anns) `(setq xpath::*dynamic-namespaces* (cons (cons nil ,anns) xpath::*dynamic-namespaces*))) (abbr xpath-string xpath:string-value) ; ------------------------------------------------------- ; ; ------------------------------------------------------- ; ; other abbriviations and shortcuts --------------------- ; (abbr alist->hash-table alexandria:alist-hash-table) (abbr hash-table->alist alexandria:hash-table-alist) (abbr hash-keys alexandria:hash-table-keys) (abbr parse-json yason:parse) (abbr export-json yason:encode) ; TODO: document (defun hash-table->json (ahashtable) (let ((s (make-string-output-stream))) (yason:encode ahashtable s) (get-output-stream-string s))) (defun parse-json-file (afile) (with-a-file afile :r (yason:parse stream!))) (defmacro make-octet-vector (n) `(make-array ,n :element-type '(unsigned-byte 8))) (defmacro concat-octet-vector (&rest everything) `(concatenate '(vector (unsigned-byte 8)) ,@everything)) (abbr parse-html plump:parse) (abbr $$ lquery:$) ;---------------------------------------------------------; ; ------------------------------------------------------- ; ; filename/namestring escaping -------------------------- ; #+(or sbcl clisp ecl abcl) (defun escape-namestring/shell (afilename) (-<> afilename (~ra <> •\t• •\ •) (~ra <> • • •\ •) (~ra <> •;• •\;•) (~ra <> •\^• •\^•) (~ra <> •\$• •\$•) (~ra <> •\\\?• •\?•) ; (~ra <> •"• •\"•) (~ra <> •\\\[• •\[•) (~ra <> •\]• •\]•) (~ra <> •"• •\"•) (~ra <> •\[• •\[•) (~ra <> •\]• •\]•) (~ra <> •\)• •\)•) (~ra <> •\(• •\(•) (~ra <> •'• •\\'•) (~ra <> •<• •\<•) (~ra <> •>• •\>•) (~ra <> •!• •\!•) (~ra <> •\\\*• •\*•) (~ra <> •\&• •\\&•) (~ra <> •=• •\=•) (~ra <> •`• •\\`•) (~ra <> •\|• •\|•))) #+(or clisp ecl abcl) (defun escape-namestring/shell (afilename) (-<> afilename (~ra <> •\\• •\\\•) (~ra <> •\t• •\ •) (~ra <> • • •\ •) (~ra <> •;• •\;•) (~ra <> •\^• •\^•) (~ra <> •\$• •\$•) (~ra <> •\?• •\?•) (~ra <> •"• •\"•) (~ra <> •\[• •\[•) (~ra <> •\]• •\]•) (~ra <> •\)• •\)•) (~ra <> •\(• •\(•) (~ra <> •'• •\\'•) (~ra <> •<• •\<•) (~ra <> •>• •\>•) (~ra <> •!• •\!•) (~ra <> •\*• •\*•) (~ra <> •\&• •\\&•) (~ra <> •=• •\=•) (~ra <> •`• •\\`•) (~ra <> •\|• •\|•))) #+sbcl (defun escape-namestring/c (afilename) (-<> afilename (~ra <> •\\• •\\\•) (~ra <> •\?• •\?•) (~ra <> •\[• •\[•) (~ra <> •\\\\\*• •*•) (~ra <> •\\\\\\\[• •[•) (~ra <> •\\\\\\• ""))) #+(or clisp ecl abcl) (defun escape-namestring/c (afilename) (-<> afilename (~ra <> •\\\\\*• •*•) (~ra <> •\\\\\\\[• •[•) (~ra <> •\\\\\\• ""))) (defun pathname->shell (apath) (escape-namestring/shell (namestring apath))) (defun pathname->c (apath) (escape-namestring/c (namestring apath))) ; ------------------------------------------------------- ; ; ------------------------------------------------------- ; ; some clippings that'll be helpful for reference ------- ; ; (defun dec->hex (something) ; (fn "~X" something)) ; ; (defun hex->dec (something) ; (parse-integer something :radix 16)) ; ; ; needs babel and ironclad ; ; (defun string->octets (something) ; (babel:string-to-octets something)) ; ; (defun octets->string (something) ; (babel:octets-to-string something)) ; ; (defun octets->hex (something) ; (ironclad:byte-array-to-hex-string something)) ; ; (defun hex->octets (something) ; (ironclad:hex-string-to-byte-array something)) ; ; (defun octets->int (something) ; (ironclad:octets-to-integer something)) ; ; (defun int->octets (something) ; (ironclad:integer-to-octets something)) ; ; (defun string->octets->integer (something) ; (-<> something (string->octets <>) (octets->integer <>))) ; ------------------------------------------------------- ; ; ;---------------------------------------------------------; ; ; experimental logging and reader macros ---------------- ; ; ; ; (defun prettify-time-output (thetimeoutput) ; ; (subseq thetimeoutput 0 (- (length thetimeoutput) 4))) ; ; ; ; ; TODO: REALLY LOOK INTO THIS BECAUSE THERE ARE A LOT OF WARNINGS AND IT SUCKS ; ; (defun clix-log-verbose (stream char arg) ; ; ;;;;;; HOW UNHYGENIC IS THIS???!! ; ; (declare (ignore char)) ; ; (multiple-value-bind (second minute hour date month year day-of-week dst-p tz) ; ; (get-decoded-time) ; ; (let ((sexp (read stream t)) ; ; (thetime (get-universal-time)) ; ; (thereturnvalue nil) ; ; (thetimingresults nil) ; ; (daoutputstream (make-string-output-stream))) ; ; `(progn ; ; (with-a-file *clix-log-file* :a ; ; (format stream! ; ; "--------------------~%[~A-~A-~A ~2,'0d:~2,'0d:~2,'0d]~%~%FORM:~%~A~%" ; ; ,year ,month ,date ,hour ,minute ,second ; ; ; (write-to-string ',sexp)) ; ; (format nil "λ ~S~%" ',sexp)) ; ; (let ((daoutputstream (make-string-output-stream))) ; ; (let ((*trace-output* daoutputstream)) ; ; (setq thereturnvalue (progn (time ,sexp)))) ; ; (setq thetimingresults ; ; (prettify-time-output ; ; (get-output-stream-string daoutputstream)))) ; ; (format stream! "RETURNED:~%~A~%" thereturnvalue) ; ; (format stream! "~%~A~%--------------------~%~%~%" thetimingresults) ; ; (finish-output stream!) ; ; thereturnvalue))))) ; ; ; ; ; ; ; REALLY LOOK INTO THIS BECAUSE THERE ARE A LOT OF WARNINGS AND IT SUCKS ; ; ; (defun clix-log-just-echo (stream char arg) ; ; ; ;;;;;; HOW UNHYGENIC IS THIS???!! ; ; ; (declare (ignore char)) ; ; ; (let ((sexp (read stream t)) ; ; ; ; (thetime (get-universal-time)) ; ; ; ; (thereturnvalue nil) ; ; ; ; (thetimingresults nil)) ; ; ; `(progn ; ; ; (with-a-file *clix-log-file* :a ; ; ; (format t "~S~%" ',sexp) ; ; ; (format stream! "~%λ ~S~%" ',sexp) ; ; ; (let* ((daoutputstream (make-string-output-stream)) ; ; ; (*trace-output* daoutputstream) ; ; ; (thereturnvalue (progn (time ,sexp)))) ; ; ; (finish-output stream!) ; ; ; ,thereturnvalue)))))) ; ; ; ; ; ; (defun clix-log (stream char arg) ; ; (cond ((= *clix-log-level* 2) (clix-log-verbose stream char arg)) ; ; ; ((= *clix-log-level* 1) (clix-log-just-echo stream char arg)) ; ; ( nil))) ; ; ; ; (set-dispatch-macro-character #\# #\! #'clix-log) ; ; ;---------------------------------------------------------;
14,938
Common Lisp
.lisp
344
37.723837
93
0.503796
tonyfischetti/pluto
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
a6c97e184bc56dcfbe7d75c5c3cb16501516e5dc0ae3199d2c4f57d23d68e658
21,415
[ -1 ]
21,416
styx.lisp
tonyfischetti_pluto/styx.lisp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; Styx ;; ;; a companion to the pluto and charon packages ;; ;; that uses helper C libraries ;; ;; (including libstyx) ;; ;; ;; ;; Tony Fischetti ;; ;; [email protected] ;; ;; ;; ;; License: GPL-3 ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defpackage :styx (:use :common-lisp :pluto :charon) ; (:shadowing-import-from #:pluto #:file-size) (:export ; systemd :*sd-log-priority* #+linux :sd-journal ; libstyx :stat-filesize :is-symlink-p :md5/string :md5/file :sha256/string :sha256/hexstring :sha256/file :sha512/string :sha512/file :ripemd160/string :ripemd160/hexstring )) (use-package :pluto) (use-package :charon) (in-package :styx) (pushnew :styx *features*) (push #P"~/.lisp/" cffi:*foreign-library-directories*) ; ------------------------------------------------------- ; ; systemd ----------------------------------------------- ; (defparameter *sd-log-priority* 4) #+linux (cffi:define-foreign-library libsystemd (t (:default "libsystemd"))) #+linux (cffi:use-foreign-library libsystemd) #+linux (cffi:defcfun "sd_journal_send" :int (theformat :string) &rest) #+linux (defun sd-journal (message &key (priority *sd-log-priority*) (identifier nil)) (unless identifier (setq identifier (program/script-name))) (let ((ret (sd-journal-send (fn "MESSAGE=~A" message) :string (fn "PRIORITY=~A" priority) :string (fn "SYSLOG_IDENTIFIER=~A" identifier) :pointer (cffi:null-pointer)))) (when (= ret 0) t))) ;---------------------------------------------------------; ; ------------------------------------------------------- ; ; libstyx ----------------------------------------------- ; (cffi:define-foreign-library libstyx (t (:default "libstyx"))) (cffi:use-foreign-library libstyx) ; ------------------- ;; stat-filesize (cffi:defcfun "styx_stat_filesize" :int64 (afilename :string) (follow_symlinks :int) &rest) ; TODO: everything ; TODO: check files (defun stat-filesize (afilename &key (follow-symlinks t)) (when (pathnamep afilename) (setq afilename (escape-namestring/c (namestring afilename)))) (let ((ret (styx-stat-filesize afilename (if follow-symlinks 1 0)))) (if (< ret 0) (error "something went wrong") ret))) ; ------------------- ;; is-symlink-p (cffi:defcfun "styx_stat_is_symlink_p" :int (afilename :string) &rest) ; TODO: everything ; TODO: check files (defun is-symlink-p (afilename) (when (pathnamep afilename) (setq afilename (escape-namestring/c (namestring afilename)))) (let ((ret (styx-stat-is-symlink-p afilename))) (if (< ret 0) (error "something went wrong") (if (= ret 0) nil t)))) ; if the namestring has a slash at the end, it doesn't work properly ; so we need to check if it's a directory and then strip the trailing ; slash ; ------------------- ;; md5 (cffi:defcfun "styx_md5_string" :string (astring :string) &rest) (cffi:defcfun "styx_md5_file" :string (afilename :string) &rest) ; TODO: everything ; TODO: check files, return values, etc... (defun md5/string (astring) (styx-md5-string astring)) (defun md5/file (afilename) (when (pathnamep afilename) (setq afilename (escape-namestring/c (namestring afilename)))) (styx-md5-file afilename)) ; ------------------- ;; sha256 (cffi:defcfun "styx_sha256_string" :string (astring :string) &rest) (cffi:defcfun "styx_sha256_hexstring" :string (astring :string) &rest) (cffi:defcfun "styx_sha256_file" :string (afilename :string) &rest) ; TODO: everything ; TODO: check files, return values, etc... (defun sha256/string (astring) (styx-sha256-string astring)) (defun sha256/hexstring (astring) (styx-sha256-hexstring astring)) (defun sha256/file (afilename) (when (pathnamep afilename) (setq afilename (escape-namestring/c (namestring afilename)))) (styx-sha256-file afilename)) ; ------------------- ;; sha512 (cffi:defcfun "styx_sha512_string" :string (astring :string) &rest) (cffi:defcfun "styx_sha512_file" :string (afilename :string) &rest) ; TODO: everything ; TODO: check files, return values, etc... (defun sha512/string (astring) (styx-sha512-string astring)) (defun sha512/file (afilename) (when (pathnamep afilename) (setq afilename (escape-namestring/c (namestring afilename)))) (styx-sha512-file afilename)) ; ------------------- ;; ripemd160 (cffi:defcfun "styx_ripemd160_string" :string (astring :string) &rest) (cffi:defcfun "styx_ripemd160_hexstring" :string (astring :string) &rest) ; TODO: everything ; TODO: check files, return values, etc... (defun ripemd160/string (astring) (styx-ripemd160-string astring)) (defun ripemd160/hexstring (astring) (styx-ripemd160-hexstring astring)) ;---------------------------------------------------------;
5,362
Common Lisp
.lisp
142
34.366197
91
0.567594
tonyfischetti/pluto
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
fecf4ba2710f57c9907172830090d3760444c5ede22db03915e4ecd745a5e18b
21,416
[ -1 ]
21,417
test-pluto.lisp
tonyfischetti_pluto/tests/test-pluto.lisp
(load "../pluto.lisp") (use-package :pluto) (load "def-test-doc.lisp") (declaim (optimize (speed 3))) (start-test/doc :title "Pluto") ; --------------------------------------------------------------- ; (def-raw-markdown (fn "-----~%~%### about~%~%a common lisp package that's out there~%~%")) ; --------------------------------------------------------------- ; (def-test/doc-section "pluto parameters") (def-raw-markdown "fill this out") ; --------------------------------------------------------------- ; (def-test/doc-section "formatting") (def-test/doc-test 'fn `(markdown-able (test-able returns)) 'function (string= test-return-value! "hello goodbye") (fn "~A ~A" "hello" "goodbye")) (def-test/doc-test 'ft `(markdown-able (test-able stdout)) 'function (string= test-stdout! "hello goodbye") (ft "~A ~A" "hello" "goodbye")) ; --------------------------------------------------------------- ; (def-test/doc-section "ansi colors and codes") (def-raw-markdown "fill this out") ; --------------------------------------------------------------- ; (def-test/doc-section "string operations") (def-test/doc-test 'str+ `(markdown-able (test-able returns)) 'function (string= test-return-value! "belleandsebastian") (str+ "belle" "and" "sebastian")) (def-test/doc-test 'str+ `(markdown-able (test-able returns)) 'function (string= test-return-value! "(1 2 3) go") (str+ '(1 2 3) " go")) (def-test/doc-test 'str-join `(markdown-able (test-able returns)) 'function (string= test-return-value! "one;two") (str-join ";" '("one" "two"))) (def-test/doc-test 'substr `(markdown-able (test-able returns)) 'function (string= test-return-value! "belle") (substr "belle and sebastian" 0 5)) (def-test/doc-test 'substr `(markdown-able (test-able returns)) 'function (string= test-return-value! "belle") (substr "belle and sebastian" 0 -14)) (def-test/doc-test 'substr `(markdown-able (test-able returns)) 'function (string= test-return-value! "sebastian") (substr "belle and sebastian" 10)) (def-test/doc-test 'string->char-list `(markdown-able (test-able returns)) 'function (equal test-return-value! `("b" "e" "l" "l" "e")) (string->char-list "belle")) (def-test/doc-test 'split-string->lines `(markdown-able (test-able returns)) 'function (equal test-return-value! '("this" "that" "and the other")) (split-string->lines (format nil "this~%that~%and the other"))) ; --------------------------------------------------------------- ; (def-test/doc-section "some essential utilities/macros") (def-test/doc-test 'alambda `(markdown-able (test-able returns)) 'function (equal test-return-value! (list 10 9 8 7 6 5 4 3 2 1)) (funcall (alambda (x) (when (> x 0) (cons x (self! (- x 1))))) 10)) (def-test/doc-test 'flatten `(markdown-able (test-able returns)) 'function (equal test-return-value! `(A B C D E)) (flatten `(a b (c d (e))))) (def-test/doc-test 'take `(markdown-able (test-able returns)) 'function (equal test-return-value! `((a b) (c d e f))) (multiple-value-bind (one two) (take `(a b c d e f) 2) (list one two))) (def-test/doc-test 'group `(markdown-able (test-able returns)) 'function (equal test-return-value! `((a b) (c d) (e f))) (group `(a b c d e f) 2)) (def-test/doc-test '-<> `(markdown-able (test-able returns) (bench-able 5)) 'function (= test-return-value! 2) (-<> "4" (parse-integer <>) (sqrt <>))) (def-test/doc-test 'interpose `((test-able returns) markdown-able) 'function (equal test-return-value! `(a sep b sep c)) (interpose 'sep `(a b c))) (def-test/doc-test 'with-time `((test-able returns) markdown-able) 'function (string= test-return-value! "time elapsed: 1") (with-time (sleep 1) (format nil "time elapsed: ~A" time!))) (def-test/doc-test 'time-for-humans `((test-able returns) markdown-able) 'function (string= test-return-value! "4 seconds") (time-for-humans 4)) (def-test/doc-test 'time-for-humans `((test-able returns) markdown-able) 'function (string= test-return-value! "1.11 hours") (time-for-humans 4000)) (def-test/doc-test 'time-for-humans `((test-able returns) markdown-able) 'function (string= test-return-value! "2.21 days") (time-for-humans 191000)) ; --------------------------------------------------------------- ; (def-test/doc-section "other abbreviations and shortcuts") (def-test/doc-test 'file-size `(markdown-able (test-able returns)) 'function (string= test-return-value! "17k") (file-size "interior-of-a-heart.txt")) (def-test/doc-test 'file-size `(markdown-able (test-able returns)) 'function (= test-return-value! 14433) (file-size "interior-of-a-heart.txt" :just-bytes t)) ; --------------------------------------------------------------- ; (def-test/doc-section "for-each and friends") (def-test/doc-test 'for-each `(markdown-able (test-able stdout)) 'function (string= test-stdout! "1 -> A;2 -> B;3 -> C;") (for-each/list '(a b c) (format t "~A -> ~A;" index! value!))) ; auto-"dispatch" variant (def-test/doc-test 'for-each `((test-able stdout)) 'function (string= test-stdout! "1 -> A;2 -> B;3 -> C;") (for-each '(a b c) (format t "~A -> ~A;" index! value!))) (def-test/doc-test 'for-each `(markdown-able (test-able stdout)) 'function (string= test-stdout! "A;B;") (for-each/list '(a b c d e) (if (> index! 2) (break!)) (format t "~A;" value!))) ; auto-"dispatch" variant (def-test/doc-test 'for-each `((test-able stdout)) 'function (string= test-stdout! "A;B;") (for-each '(a b c d e) (if (> index! 2) (break!)) (format t "~A;" value!))) (def-test/doc-test 'for-each `(markdown-able (test-able stdout)) 'function (string= test-stdout! "A;B;D;E;") (for-each/list '(a b c d e) (if (= index! 3) (continue!)) (format t "~A;" value!))) ; auto-"dispatch" variant (def-test/doc-test 'for-each `((test-able stdout)) 'function (string= test-stdout! "A;B;D;E;") (for-each '(a b c d e) (if (= index! 3) (continue!)) (format t "~A;" value!))) (def-test/doc-test 'for-each `((test-able stdout)) 'function (string= test-stdout! "a;b;d;e;") (for-each/vector #("a" "b" "c" "d" "e") (if (= index! 3) (continue!)) (format t "~A;" value!))) ; auto-"dispatch" variant (def-test/doc-test 'for-each `((test-able stdout)) 'function (string= test-stdout! "a;b;d;e;") (for-each #("a" "b" "c" "d" "e") (if (= index! 3) (continue!)) (format t "~A;" value!))) (def-raw-markdown "If the argument to `for-each` is a string and the file exists,\ `for-each/line` is dispatched. Otherwise, it is treated like a\ character vector") (def-test/doc-test 'for-each `(markdown-able (test-able stdout)) 'function (string= test-stdout! "1 -> we gotta celebrate diversity;2 -> in the university;") (for-each/line "somebody.txt" (when (> index! 2) (break!)) (format t "~A -> ~A;" index! value!))) ; auto-"dispatch" variant (def-test/doc-test 'for-each `((test-able stdout)) 'function (string= test-stdout! "1 -> we gotta celebrate diversity;2 -> in the university;") (for-each "somebody.txt" (when (> index! 2) (break!)) (format t "~A -> ~A;" index! value!))) (def-test/doc-test 'for-each `(markdown-able (test-able stdout)) 'function (string= test-stdout! "n;o;t;-;a;-;f;i;l;e;.;t;x;t;") (for-each "not-a-file.txt" (format t "~A;" value!))) (def-test/doc-test 'for-each `(markdown-able (test-able stdout)) 'function (or (string= test-stdout! (fn "GREEN -> veridian;RED -> cadmium;")) (string= test-stdout! (fn "RED -> cadmium;GREEN -> veridian;"))) (let ((tmp (make-hash-table))) (setf (gethash 'green tmp) "veridian") (setf (gethash 'red tmp) "cadmium") (for-each/hash tmp (format t "~A -> ~A;" key! value!)))) ; auto-"dispatch" variant (def-test/doc-test 'for-each `(markdown-able (test-able stdout)) 'function (or (string= test-stdout! (fn "GREEN -> veridian;RED -> cadmium;")) (string= test-stdout! (fn "RED -> cadmium;GREEN -> veridian;"))) (let ((tmp (make-hash-table))) (setf (gethash 'green tmp) "veridian") (setf (gethash 'red tmp) "cadmium") (for-each tmp (format t "~A -> ~A;" key! value!)))) (def-test/doc-test 'for-each/alist `(markdown-able (test-able stdout)) 'function (string= test-stdout! (fn "RED -> cadmium;GREEN -> veridian;")) (let ((tmp (list (cons 'red "cadmium") (cons 'green "veridian")))) (for-each/alist tmp (format t "~A -> ~A;" key! value!)))) ; --------------------------------------------------------------- ; ; --------------------------------------------------------------- ; #-clisp (load "~/quicklisp/setup.lisp") (ql:quickload :charon :silent t) (use-package :charon) (def-test/doc-section "temporary charon tests") (def-test/doc-test 'parse-float `(markdown-able (test-able returns)) 'function (= test-return-value! 5.4) (parse-float "5.4")) ; --------------------------------------------------------------- ; ; --------------------------------------------------------------- ; (ql:quickload :styx :silent t) (use-package :styx) (def-test/doc-section "temporary styx tests") (def-test/doc-test 'stat-filesize `(markdown-able (test-able returns)) 'function (= test-return-value! 14433) (stat-filesize "interior-of-a-heart.txt")) ; --------------------------------------------------------------- ; (end-test/doc) (if (run-tests) (with-a-file "pluto-results.md" :w (render-markdown stream!)) (die "~%at least one test failed"))
9,749
Common Lisp
.lisp
280
31.392857
88
0.579989
tonyfischetti/pluto
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
9dc1cdb2f2f15f9b316b8c031c6392e2842f2f7422a4fc3078302bd4a1eb4ec3
21,417
[ -1 ]
21,418
def-test-doc.lisp
tonyfischetti_pluto/tests/def-test-doc.lisp
(setq *print-pretty* t) (defparameter /all-test-docs/ nil) (defparameter /test-counter/ 0) (defparameter /test-section/ nil) (defparameter /last-element-rendered/ nil) (defparameter test-return-value! nil) (defparameter test-stdout! nil) (defparameter test-stderr! nil) ;; ----------------------------------- ;; classes (defclass test/doc-element () ((traits :initarg :traits) (section :initarg :section :initform /test-section/) (doc :initarg :doc :initform ""))) (defclass test/doc-title (test/doc-element) ()) (defclass test/doc-section (test/doc-element) ()) (defclass test/doc-test (test/doc-element) ((test-number :initform (incf /test-counter/)) (the-function :initarg :the-function) (test-closure :initarg :test-closure) (code-closure :initarg :code-closure) (raw-code :initarg :raw-code) (pass-p :initform nil) output)) ;; ----------------------------------- (defun has-trait (element atrait) (assoc atrait { element 'traits })) (defun output-type (element) (aif (assoc 'test-able { element 'traits }) (cadr it!) nil)) (defun process-docstring (astring) (when (not (null astring)) (-<> astring (split-string->lines <>) (mapcar (lambda (x) (fn "> ~A\\~%" x)) <>) (str-join (fn "") <>)))) ;; ----------------------------------- (defun start-test/doc (&key title) (setq /all-test-docs/ nil) (setq /test-counter/ 0) (push (make-instance 'test/doc-title :section title :traits `((markdown-able t))) /all-test-docs/)) (defun end-test/doc () (setq /all-test-docs/ (reverse /all-test-docs/))) ;; ----------------------------------- ;; "constructors" (defun def-test/doc-title (title) (push (make-instance 'test/doc-title :doc title :traits '((markdown-able t))) /all-test-docs/)) (defun def-test/doc-section (section-name) (setq /test-section/ section-name) (push (make-instance 'test/doc-section :traits '((markdown-able t))) /all-test-docs/)) (defmacro def-test/doc-test (&body body) (destructuring-bind (the-function traits doc test &rest code) body (let ((thetraits (gensym)) (newone (gensym))) `(let* ((,thetraits nil) (,newone (make-instance 'test/doc-test :the-function ,the-function :doc (if (symbolp ,doc) (process-docstring (documentation ,the-function ,doc)) ,doc) :test-closure (lambda () ,test) :raw-code (quote ,code) :code-closure (lambda () ,@code)))) (setf ,thetraits (mapcar (lambda (x) (if (listp x) x (list x t))) ,traits)) ; TODO: the following fails in ecl and clisp ; (setf { ,newone 'traits } ,thetraits) (setf (slot-value ,newone 'traits) ,thetraits) (push ,newone /all-test-docs/))))) (defmacro def-raw-markdown (astring) `(push (make-instance 'test/doc-element :doc ,astring :traits `((markdown-able t))) /all-test-docs/)) ;; ----------------------------------- ;; ----------------------------------- ;; testing ; TODO: implement (defmethod run-test :around ((test test/doc-test)) (if (has-trait test 'test-able) (aif (has-trait test 'bench-able) (progn (ft (magenta "benchmarking: ~S ~A times~%" { test 'the-function } (cadr it!))) (call-next-method)) (call-next-method)) (ft (grey "skipping test of ~S~%" { test 'the-function })))) (defmethod run-test ((test test/doc-element)) t) (defmethod run-test ((test test/doc-title)) (ft (cyan "beginning tests for ~A~%" { test 'section }))) (defmethod run-test ((test test/doc-section)) (ft (yellow "testing section: ~A~%" { test 'section }))) (defmethod run-test ((test test/doc-test)) (multiple-value-bind (test-return-value! test-stdout! test-stderr!) (capture-all-outputs { test 'code-closure }) (let ((test-result (funcall { test 'test-closure }))) (if test-result (progn (ft (green "passed: ~A~%" { test 'the-function })) (setf { test 'pass-p } t) (setf { test 'output } `(,test-return-value! ,test-stdout! ,test-stderr!))) (ft (red "failed: ~A~%" { test 'the-function })))))) (defmethod passed-p ((test test/doc-element)) t) (defmethod passed-p ((test test/doc-test)) (if (has-trait test 'test-able) { test 'pass-p } t)) (defun run-tests () (mapcar #'run-test /all-test-docs/) (every #'passed-p /all-test-docs/)) ;; ----------------------------------- ;; ----------------------------------- ;; markdown (defgeneric to-markdown (test/doc-element &optional stream)) (defmethod to-markdown :around ((test test/doc-element) &optional (stream t)) (declare (ignore stream)) (when (has-trait test 'markdown-able) (call-next-method))) (defmethod to-markdown ((test test/doc-element) &optional (stream t)) (format stream "~A~%" { test 'doc })) (defmethod to-markdown ((test test/doc-title) &optional (stream t)) (format stream "---~%title: ~A documentation~%...~%~%" { test 'section })) (defmethod to-markdown ((test test/doc-section) &optional (stream t)) (format stream "~%-----~%~%### ~A~%~%" { test 'section })) (defmethod to-markdown ((test test/doc-test) &optional (stream t)) (let ((thefun { test 'the-function })) (if (eq thefun /last-element-rendered/) (format stream "~%") (format stream "~%#### ~A~%~%~A~%" { test 'the-function } { test 'doc })) (format stream "```{.commonlisp}~%~S~%```~%~%" (car { test 'raw-code })) (setq /last-element-rendered/ thefun))) ; TODO: test test-able nil (defmethod to-markdown :after ((test test/doc-test) &optional (stream t)) (aif (output-type test) (let ((tmp (cond ((eq it! 'returns) (list "=>" (car { test 'output }))) ((eq it! 'stdout) (list ">>" (cadr { test 'output }))) ((eq it! 'stderr) (list "Std error" (caddr { test 'output })))))) ; (format stream "`~A ~A~%`~%~%" (format stream "<small><pre>~A ~S</pre></small>~%~%~%" (car tmp) (cadr tmp))))) (defun render-markdown (&optional (stream t)) (mapcar (lambda (x) (to-markdown x stream)) /all-test-docs/) (ft (blue "~%rendered markdown~%"))) ;; -----------------------------------
6,804
Common Lisp
.lisp
166
33.10241
78
0.539605
tonyfischetti/pluto
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
35e35ddda0b5fc523ea82f586e5b15433241fd23f322c210e8b108147fc43990
21,418
[ -1 ]
21,419
charon.asd
tonyfischetti_pluto/charon.asd
(asdf:defsystem :charon :description "A companion to pluto (with external dependencies)" :author "Tony Fischetti <[email protected]>" :homepage "https://github.com/tonyfischetti/pluto" :version "0.1.2" :license "GPL-3" ; TODO: do I really need all of these? :depends-on ( ; the venerable alexadria ; https://gitlab.common-lisp.net/alexandria/alexandria :alexandria ; ya tu sabes ; https://edicl.github.io/cl-ppcre/ :cl-ppcre ; https://github.com/soemraws/parse-float :parse-float ; awesome json parser ; https://github.com/phmarek/yason :yason ; portable threading ; https://github.com/sionescu/bordeaux-threads :bordeaux-threads ; Plexippus XPATH library ; https://common-lisp.net/project/plexippus-xpath/ :xpath ; lenient HTML parser ; https://github.com/Shinmera/plump :plump ; dope jquery like thing for plump ; https://shinmera.github.io/lquery/ :lquery ; XML parser of choice ; https://common-lisp.net/project/cxml/ :cxml ; foreign function interface :cffi ; HTTP client of choice ; https://github.com/fukamachi/dexador :dexador ; of course :pluto ) :components ((:file "charon")))
1,635
Common Lisp
.asd
43
24.465116
69
0.521546
tonyfischetti/pluto
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
fcfb914f003f89d1905e7dfd791850ec4c43eb86cc40f8dd4d2ad60fd82b33bb
21,419
[ -1 ]
21,420
styx.asd
tonyfischetti_pluto/styx.asd
(asdf:defsystem :styx ; :description "A companion to pluto (and charon) using a shared C libraries (including libstyx)" :author "Tony Fischetti <[email protected]>" :homepage "https://github.com/tonyfischetti/pluto" :version "0.0.1" :license "GPL-3" ; TODO: do I really need all of these? :depends-on ( ; of course :pluto ; of course :charon ; foreign function interface :cffi ) :components ((:file "styx")))
542
Common Lisp
.asd
16
25
99
0.579655
tonyfischetti/pluto
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
0de002575c162ce9bc128d453078dcce427c12a2711dba9b34e9c41c359daff2
21,420
[ -1 ]
21,421
pluto.asd
tonyfischetti_pluto/pluto.asd
(asdf:defsystem :pluto :description "A common lisp package that's out there" :author "Tony Fischetti <[email protected]>" :homepage "https://github.com/tonyfischetti/pluto" :version "0.9.11" :license "GPL-3" :components ((:file "pluto")))
260
Common Lisp
.asd
7
34.142857
55
0.721116
tonyfischetti/pluto
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
7444f9d7e3324bd2a99b63ce6b79f07d023de7e6c266aa880c3a9d3c2e97d144
21,421
[ -1 ]
21,425
Makefile
tonyfischetti_pluto/Makefile
.PHONY: all test doc all: test-sbcl doc test-sbcl: cd tests; sbcl --no-userinit --eval '(progn (load "test-pluto.lisp") (sb-ext:exit))' --warnings --without-pluto test-ecl: cd tests; ecl --norc --eval '(progn (load "test-pluto.lisp") (quit))' test-clisp: cd tests; clisp -x '(progn (load "test-pluto.lisp"))' test-abcl: cd tests; abcl --noinit --eval '(progn (load "test-pluto.lisp") (exit))' doc: pandoc --toc --toc-depth=4 -s -f markdown -t html5 -o ./docs/pluto-documentation.html ./tests/pluto-results.md
522
Common Lisp
.l
12
41.416667
112
0.689243
tonyfischetti/pluto
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
72efcfe0f2fce4643ff03e65f671f7f3273bccbf10c104081c4b3e2ce2f74dc9
21,425
[ -1 ]
21,428
pluto-documentation.html
tonyfischetti_pluto/docs/pluto-documentation.html
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang=""> <head> <meta charset="utf-8" /> <meta name="generator" content="pandoc" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> <title>Pluto documentation</title> <style> html { line-height: 1.5; font-family: Georgia, serif; font-size: 20px; color: #1a1a1a; background-color: #fdfdfd; } body { margin: 0 auto; max-width: 36em; padding-left: 50px; padding-right: 50px; padding-top: 50px; padding-bottom: 50px; hyphens: auto; word-wrap: break-word; text-rendering: optimizeLegibility; font-kerning: normal; } @media (max-width: 600px) { body { font-size: 0.9em; padding: 1em; } } @media print { body { background-color: transparent; color: black; font-size: 12pt; } p, h2, h3 { orphans: 3; widows: 3; } h2, h3, h4 { page-break-after: avoid; } } p { margin: 1em 0; } a { color: #1a1a1a; } a:visited { color: #1a1a1a; } img { max-width: 100%; } h1, h2, h3, h4, h5, h6 { margin-top: 1.4em; } h5, h6 { font-size: 1em; font-style: italic; } h6 { font-weight: normal; } ol, ul { padding-left: 1.7em; margin-top: 1em; } li > ol, li > ul { margin-top: 0; } blockquote { margin: 1em 0 1em 1.7em; padding-left: 1em; border-left: 2px solid #e6e6e6; color: #606060; } code { font-family: Menlo, Monaco, 'Lucida Console', Consolas, monospace; font-size: 85%; margin: 0; } pre { margin: 1em 0; overflow: auto; } pre code { padding: 0; overflow: visible; } .sourceCode { background-color: transparent; overflow: visible; } hr { background-color: #1a1a1a; border: none; height: 1px; margin: 1em 0; } table { margin: 1em 0; border-collapse: collapse; width: 100%; overflow-x: auto; display: block; font-variant-numeric: lining-nums tabular-nums; } table caption { margin-bottom: 0.75em; } tbody { margin-top: 0.5em; border-top: 1px solid #1a1a1a; border-bottom: 1px solid #1a1a1a; } th { border-top: 1px solid #1a1a1a; padding: 0.25em 0.5em 0.25em 0.5em; } td { padding: 0.125em 0.5em 0.25em 0.5em; } header { margin-bottom: 4em; text-align: center; } #TOC li { list-style: none; } #TOC a:not(:hover) { text-decoration: none; } code{white-space: pre-wrap;} span.smallcaps{font-variant: small-caps;} span.underline{text-decoration: underline;} div.column{display: inline-block; vertical-align: top; width: 50%;} div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} ul.task-list{list-style: none;} pre > code.sourceCode { white-space: pre; position: relative; } pre > code.sourceCode > span { display: inline-block; line-height: 1.25; } pre > code.sourceCode > span:empty { height: 1.2em; } .sourceCode { overflow: visible; } code.sourceCode > span { color: inherit; text-decoration: inherit; } div.sourceCode { margin: 1em 0; } pre.sourceCode { margin: 0; } @media screen { div.sourceCode { overflow: auto; } } @media print { pre > code.sourceCode { white-space: pre-wrap; } pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; } } pre.numberSource code { counter-reset: source-line 0; } pre.numberSource code > span { position: relative; left: -4em; counter-increment: source-line; } pre.numberSource code > span > a:first-child::before { content: counter(source-line); position: relative; left: -1em; text-align: right; vertical-align: baseline; border: none; display: inline-block; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; padding: 0 4px; width: 4em; color: #aaaaaa; } pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; } div.sourceCode { } @media screen { pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; } } code span.al { color: #ff0000; font-weight: bold; } /* Alert */ code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */ code span.at { color: #7d9029; } /* Attribute */ code span.bn { color: #40a070; } /* BaseN */ code span.bu { } /* BuiltIn */ code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */ code span.ch { color: #4070a0; } /* Char */ code span.cn { color: #880000; } /* Constant */ code span.co { color: #60a0b0; font-style: italic; } /* Comment */ code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */ code span.do { color: #ba2121; font-style: italic; } /* Documentation */ code span.dt { color: #902000; } /* DataType */ code span.dv { color: #40a070; } /* DecVal */ code span.er { color: #ff0000; font-weight: bold; } /* Error */ code span.ex { } /* Extension */ code span.fl { color: #40a070; } /* Float */ code span.fu { color: #06287e; } /* Function */ code span.im { } /* Import */ code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */ code span.kw { color: #007020; font-weight: bold; } /* Keyword */ code span.op { color: #666666; } /* Operator */ code span.ot { color: #007020; } /* Other */ code span.pp { color: #bc7a00; } /* Preprocessor */ code span.sc { color: #4070a0; } /* SpecialChar */ code span.ss { color: #bb6688; } /* SpecialString */ code span.st { color: #4070a0; } /* String */ code span.va { color: #19177c; } /* Variable */ code span.vs { color: #4070a0; } /* VerbatimString */ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */ .display.math{display: block; text-align: center; margin: 0.5rem auto;} </style> <!--[if lt IE 9]> <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script> <![endif]--> </head> <body> <header id="title-block-header"> <h1 class="title">Pluto documentation</h1> </header> <nav id="TOC" role="doc-toc"> <ul> <li><a href="#about">about</a></li> <li><a href="#pluto-parameters">pluto parameters</a></li> <li><a href="#formatting">formatting</a> <ul> <li><a href="#fn">FN</a></li> <li><a href="#ft">FT</a></li> </ul></li> <li><a href="#ansi-colors-and-codes">ansi colors and codes</a></li> <li><a href="#string-operations">string operations</a> <ul> <li><a href="#str">STR+</a></li> <li><a href="#str-join">STR-JOIN</a></li> <li><a href="#substr">SUBSTR</a></li> <li><a href="#string-char-list">STRING-&gt;CHAR-LIST</a></li> <li><a href="#split-string-lines">SPLIT-STRING-&gt;LINES</a></li> </ul></li> <li><a href="#some-essential-utilitiesmacros">some essential utilities/macros</a> <ul> <li><a href="#alambda">ALAMBDA</a></li> <li><a href="#flatten">FLATTEN</a></li> <li><a href="#take">TAKE</a></li> <li><a href="#group">GROUP</a></li> <li><a href="#section">-&lt;&gt;</a></li> <li><a href="#interpose">INTERPOSE</a></li> <li><a href="#with-time">WITH-TIME</a></li> <li><a href="#time-for-humans">TIME-FOR-HUMANS</a></li> </ul></li> <li><a href="#other-abbreviations-and-shortcuts">other abbreviations and shortcuts</a> <ul> <li><a href="#file-size">FILE-SIZE</a></li> </ul></li> <li><a href="#for-each-and-friends">for-each and friends</a> <ul> <li><a href="#for-each">FOR-EACH</a></li> <li><a href="#for-eachalist">FOR-EACH/ALIST</a></li> </ul></li> </ul> </nav> <hr /> <h3 id="about">about</h3> <p>a common lisp package that’s out there</p> <hr /> <h3 id="pluto-parameters">pluto parameters</h3> <p>fill this out</p> <hr /> <h3 id="formatting">formatting</h3> <h4 id="fn">FN</h4> <blockquote> <p>Alias to (format nil …)<br /> </p> </blockquote> <div class="sourceCode" id="cb1"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>(FN <span class="st">&quot;~A ~A&quot;</span> <span class="st">&quot;hello&quot;</span> <span class="st">&quot;goodbye&quot;</span>)</span></code></pre></div> <small> <pre>=> "hello goodbye"</pre> <p></small></p> <h4 id="ft">FT</h4> <blockquote> <p>Alias to (format t …)<br /> </p> </blockquote> <div class="sourceCode" id="cb2"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>(FT <span class="st">&quot;~A ~A&quot;</span> <span class="st">&quot;hello&quot;</span> <span class="st">&quot;goodbye&quot;</span>)</span></code></pre></div> <small> <pre>>> "hello goodbye"</pre> <p></small></p> <hr /> <h3 id="ansi-colors-and-codes">ansi colors and codes</h3> <p>fill this out</p> <hr /> <h3 id="string-operations">string operations</h3> <h4 id="str">STR+</h4> <blockquote> <p>Combine (using princ) an arbitrary number of args into one string<br /> </p> </blockquote> <div class="sourceCode" id="cb3"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>(STR+ <span class="st">&quot;belle&quot;</span> <span class="st">&quot;and&quot;</span> <span class="st">&quot;sebastian&quot;</span>)</span></code></pre></div> <small> <pre>=> "belleandsebastian"</pre> <p></small></p> <div class="sourceCode" id="cb4"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>(STR+ &#39;(<span class="dv">1</span> <span class="dv">2</span> <span class="dv">3</span>) <span class="st">&quot; go&quot;</span>)</span></code></pre></div> <small> <pre>=> "(1 2 3) go"</pre> <p></small></p> <h4 id="str-join">STR-JOIN</h4> <blockquote> <p>Join STRINGS with DELIM.<br /> </p> </blockquote> <div class="sourceCode" id="cb5"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>(STR-JOIN <span class="st">&quot;;&quot;</span> &#39;(<span class="st">&quot;one&quot;</span> <span class="st">&quot;two&quot;</span>))</span></code></pre></div> <small> <pre>=> "one;two"</pre> <p></small></p> <h4 id="substr">SUBSTR</h4> <blockquote> <p>Efficient substring of STRING from START to END (optional),<br /> where both can be negative, which means counting from the end.<br /> </p> </blockquote> <div class="sourceCode" id="cb6"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>(SUBSTR <span class="st">&quot;belle and sebastian&quot;</span> <span class="dv">0</span> <span class="dv">5</span>)</span></code></pre></div> <small> <pre>=> "belle"</pre> <p></small></p> <div class="sourceCode" id="cb7"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>(SUBSTR <span class="st">&quot;belle and sebastian&quot;</span> <span class="dv">0</span> -<span class="dv">14</span>)</span></code></pre></div> <small> <pre>=> "belle"</pre> <p></small></p> <div class="sourceCode" id="cb8"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>(SUBSTR <span class="st">&quot;belle and sebastian&quot;</span> <span class="dv">10</span>)</span></code></pre></div> <small> <pre>=> "sebastian"</pre> <p></small></p> <h4 id="string-char-list">STRING-&gt;CHAR-LIST</h4> <blockquote> <p>Make a string a list of single character strings<br /> </p> </blockquote> <div class="sourceCode" id="cb9"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>(STRING-&gt;CHAR-LIST <span class="st">&quot;belle&quot;</span>)</span></code></pre></div> <small> <pre>=> ("b" "e" "l" "l" "e")</pre> <p></small></p> <h4 id="split-string-lines">SPLIT-STRING-&gt;LINES</h4> <blockquote> <p>Split a string with new lines into a list of strings (one for each line)<br /> </p> </blockquote> <div class="sourceCode" id="cb10"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>(SPLIT-STRING-&gt;LINES (FORMAT NIL <span class="st">&quot;this~%that~%and the other&quot;</span>))</span></code></pre></div> <small> <pre>=> ("this" "that" "and the other")</pre> <p></small></p> <hr /> <h3 id="some-essential-utilitiesmacros">some essential utilities/macros</h3> <h4 id="alambda">ALAMBDA</h4> <blockquote> <p>Anaphoric lambda. SELF! is the function<br /> </p> </blockquote> <div class="sourceCode" id="cb11"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>(FUNCALL</span> <span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a> (ALAMBDA (X)</span> <span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a> (WHEN (<span class="op">&gt;</span> X <span class="dv">0</span>) (CONS X (SELF! (<span class="op">-</span> X <span class="dv">1</span>)))))</span> <span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a> <span class="dv">10</span>)</span></code></pre></div> <small> <pre>=> (10 9 8 7 6 5 4 3 2 1)</pre> <p></small></p> <h4 id="flatten">FLATTEN</h4> <blockquote> <p>Flattens a list (possibly inefficiently)<br /> </p> </blockquote> <div class="sourceCode" id="cb12"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a>(FLATTEN `(A B (C D (E))))</span></code></pre></div> <small> <pre>=> (A B C D E)</pre> <p></small></p> <h4 id="take">TAKE</h4> <blockquote> <p>Takes <code>n</code> from beginning of <code>alist</code> and returns that in a<br /> list. It also returns the remainder of the list (use<br /> <code>multiple-value-bind</code> with it<br /> </p> </blockquote> <div class="sourceCode" id="cb13"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>(MULTIPLE-VALUE-BIND (ONE TWO) (TAKE `(A B C D E F) <span class="dv">2</span>) (LIST ONE TWO))</span></code></pre></div> <small> <pre>=> ((A B) (C D E F))</pre> <p></small></p> <h4 id="group">GROUP</h4> <blockquote> <p>Turn a (flat) list into a list of lists of length <code>n</code><br /> </p> </blockquote> <div class="sourceCode" id="cb14"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a>(GROUP `(A B C D E F) <span class="dv">2</span>)</span></code></pre></div> <small> <pre>=> ((A B) (C D) (E F))</pre> <p></small></p> <h4 id="section">-&lt;&gt;</h4> <blockquote> <p>Threading macro (put &lt;&gt; where the argument should be)<br /> Stolen from https://github.com/sjl/cl-losh/blob/master/src/control-flow.lisp<br /> </p> </blockquote> <div class="sourceCode" id="cb15"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a>(-&lt;&gt; <span class="st">&quot;4&quot;</span> (PARSE-INTEGER &lt;&gt;) (SQRT &lt;&gt;))</span></code></pre></div> <small> <pre>=> 2.0</pre> <p></small></p> <h4 id="interpose">INTERPOSE</h4> <blockquote> <p>Returns a sequence of the elements of SEQUENCE separated by SEPARATOR.<br /> </p> </blockquote> <div class="sourceCode" id="cb16"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a>(INTERPOSE &#39;SEP `(A B C))</span></code></pre></div> <small> <pre>=> (A SEP B SEP C)</pre> <p></small></p> <h4 id="with-time">WITH-TIME</h4> <blockquote> <p>Anaphoric macro that executes the car of the body and<br /> binds the seconds of execution time to TIME!. Then<br /> all the other forms in the body are executed<br /> </p> </blockquote> <div class="sourceCode" id="cb17"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>(WITH-TIME</span> <span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a> (SLEEP <span class="dv">1</span>)</span> <span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a> (FORMAT NIL <span class="st">&quot;time elapsed: ~A&quot;</span> TIME!))</span></code></pre></div> <small> <pre>=> "time elapsed: 1"</pre> <p></small></p> <h4 id="time-for-humans">TIME-FOR-HUMANS</h4> <blockquote> <p>Converts SECONDS into minutes, hours, or days (based on magnitude)<br /> </p> </blockquote> <div class="sourceCode" id="cb18"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a>(TIME-FOR-HUMANS <span class="dv">4</span>)</span></code></pre></div> <small> <pre>=> "4 seconds"</pre> <p></small></p> <div class="sourceCode" id="cb19"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a>(TIME-FOR-HUMANS <span class="dv">4000</span>)</span></code></pre></div> <small> <pre>=> "1.11 hours"</pre> <p></small></p> <div class="sourceCode" id="cb20"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a>(TIME-FOR-HUMANS <span class="dv">191000</span>)</span></code></pre></div> <small> <pre>=> "2.21 days"</pre> <p></small></p> <hr /> <h3 id="other-abbreviations-and-shortcuts">other abbreviations and shortcuts</h3> <h4 id="file-size">FILE-SIZE</h4> <blockquote> <p>Uses <code>du</code> to return just the size of the provided file.<br /> <code>just-bytes</code> ensures that the size is only counted in bytes (returns integer) [default nil]<br /> </p> </blockquote> <div class="sourceCode" id="cb21"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a>(FILE-SIZE <span class="st">&quot;interior-of-a-heart.txt&quot;</span>)</span></code></pre></div> <small> <pre>=> "17k"</pre> <p></small></p> <div class="sourceCode" id="cb22"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a>(FILE-SIZE <span class="st">&quot;interior-of-a-heart.txt&quot;</span> :JUST-BYTES T)</span></code></pre></div> <small> <pre>=> 14433</pre> <p></small></p> <hr /> <h3 id="for-each-and-friends">for-each and friends</h3> <h4 id="for-each">FOR-EACH</h4> <blockquote> <p>A super-duper imperative looping construct.<br /> It takes either<br /> a filename string (to be treated as a file and goes line by line)<br /> a hash-table<br /> a vector<br /> a list<br /> a string (that goes character by character)<br /> or a stream (that goes line by line)<br /> It is anaphoric and introduces<br /> index! (which is a zero indexed counter of which element we are on)<br /> key! (the key of the current hash-table entry [only for hash-tables and alists])<br /> value! (the value of the current element)<br /> this-pass! (a block that returning from immediately moves to the next iteration)<br /> this-loop! (a block that returning from exits the loop)<br /> For convenience, (continue!) and (break!) will execute (return-from this-pass!)<br /> and (return-from this-loop!), respectively<br /> If it’s a filename, the external format is <em>pluto-external-format</em> (:UTF-8 by default)<br /> Oh, it’ll die gracefully if Control-C is used during the loops execution.<br /> And, finally, for extra performance, you can call it’s subordinate functions directly.<br /> They are… for-each/line, for-each/list, for-each/hash, for-each/vector,<br /> for-each/stream, and for-each/alist<br /> </p> </blockquote> <div class="sourceCode" id="cb23"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a>(FOR-EACH/LIST &#39;(A B C)</span> <span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a> (FORMAT T <span class="st">&quot;~A -&gt; ~A;&quot;</span> INDEX! VALUE!))</span></code></pre></div> <small> <pre>>> "1 -> A;2 -> B;3 -> C;"</pre> <p></small></p> <div class="sourceCode" id="cb24"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a>(FOR-EACH/LIST &#39;(A B C D E)</span> <span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a> (IF (<span class="op">&gt;</span> INDEX! <span class="dv">2</span>)</span> <span id="cb24-3"><a href="#cb24-3" aria-hidden="true" tabindex="-1"></a> (BREAK!))</span> <span id="cb24-4"><a href="#cb24-4" aria-hidden="true" tabindex="-1"></a> (FORMAT T <span class="st">&quot;~A;&quot;</span> VALUE!))</span></code></pre></div> <small> <pre>>> "A;B;"</pre> <p></small></p> <div class="sourceCode" id="cb25"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a>(FOR-EACH/LIST &#39;(A B C D E)</span> <span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a> (IF (<span class="op">=</span> INDEX! <span class="dv">3</span>)</span> <span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a> (CONTINUE!))</span> <span id="cb25-4"><a href="#cb25-4" aria-hidden="true" tabindex="-1"></a> (FORMAT T <span class="st">&quot;~A;&quot;</span> VALUE!))</span></code></pre></div> <small> <pre>>> "A;B;D;E;"</pre> <p></small></p> <p>If the argument to <code>for-each</code> is a string and the file exists, <code>for-each/line</code> is dispatched. Otherwise, it is treated like a character vector</p> <div class="sourceCode" id="cb26"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a>(FOR-EACH/LINE <span class="st">&quot;somebody.txt&quot;</span></span> <span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a> (WHEN (<span class="op">&gt;</span> INDEX! <span class="dv">2</span>) (BREAK!))</span> <span id="cb26-3"><a href="#cb26-3" aria-hidden="true" tabindex="-1"></a> (FORMAT T <span class="st">&quot;~A -&gt; ~A;&quot;</span> INDEX! VALUE!))</span></code></pre></div> <small> <pre>>> "1 -> we gotta celebrate diversity;2 -> in the university;"</pre> <p></small></p> <div class="sourceCode" id="cb27"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a>(FOR-EACH <span class="st">&quot;not-a-file.txt&quot;</span></span> <span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a> (FORMAT T <span class="st">&quot;~A;&quot;</span> VALUE!))</span></code></pre></div> <small> <pre>>> "n;o;t;-;a;-;f;i;l;e;.;t;x;t;"</pre> <p></small></p> <div class="sourceCode" id="cb28"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a>(LET ((TMP (MAKE-HASH-TABLE)))</span> <span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a> (SETF (GETHASH &#39;GREEN TMP) <span class="st">&quot;veridian&quot;</span>)</span> <span id="cb28-3"><a href="#cb28-3" aria-hidden="true" tabindex="-1"></a> (SETF (GETHASH &#39;RED TMP) <span class="st">&quot;cadmium&quot;</span>)</span> <span id="cb28-4"><a href="#cb28-4" aria-hidden="true" tabindex="-1"></a> (FOR-EACH/HASH TMP</span> <span id="cb28-5"><a href="#cb28-5" aria-hidden="true" tabindex="-1"></a> (FORMAT T <span class="st">&quot;~A -&gt; ~A;&quot;</span> KEY! VALUE!)))</span></code></pre></div> <small> <pre>>> "GREEN -> veridian;RED -> cadmium;"</pre> <p></small></p> <div class="sourceCode" id="cb29"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a>(LET ((TMP (MAKE-HASH-TABLE)))</span> <span id="cb29-2"><a href="#cb29-2" aria-hidden="true" tabindex="-1"></a> (SETF (GETHASH &#39;GREEN TMP) <span class="st">&quot;veridian&quot;</span>)</span> <span id="cb29-3"><a href="#cb29-3" aria-hidden="true" tabindex="-1"></a> (SETF (GETHASH &#39;RED TMP) <span class="st">&quot;cadmium&quot;</span>)</span> <span id="cb29-4"><a href="#cb29-4" aria-hidden="true" tabindex="-1"></a> (FOR-EACH TMP</span> <span id="cb29-5"><a href="#cb29-5" aria-hidden="true" tabindex="-1"></a> (FORMAT T <span class="st">&quot;~A -&gt; ~A;&quot;</span> KEY! VALUE!)))</span></code></pre></div> <small> <pre>>> "GREEN -> veridian;RED -> cadmium;"</pre> <p></small></p> <h4 id="for-eachalist">FOR-EACH/ALIST</h4> <blockquote> <p>This works like <code>for-each/hash</code> (see documentation for <code>for-each</code>)<br /> but it has to be called explicitly (as <code>for-each/alist</code>) instead<br /> of relying on <code>for-each</code>‘s ’dispatch’ mechanism.<br /> </p> </blockquote> <div class="sourceCode" id="cb30"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a>(LET ((TMP (LIST (CONS &#39;RED <span class="st">&quot;cadmium&quot;</span>) (CONS &#39;GREEN <span class="st">&quot;veridian&quot;</span>))))</span> <span id="cb30-2"><a href="#cb30-2" aria-hidden="true" tabindex="-1"></a> (FOR-EACH/ALIST TMP</span> <span id="cb30-3"><a href="#cb30-3" aria-hidden="true" tabindex="-1"></a> (FORMAT T <span class="st">&quot;~A -&gt; ~A;&quot;</span> KEY! VALUE!)))</span></code></pre></div> <small> <pre>>> "RED -> cadmium;GREEN -> veridian;"</pre> <p></small></p> </body> </html>
26,440
Common Lisp
.l
543
45.769797
336
0.642656
tonyfischetti/pluto
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
1e5b9d533c54bb11d4f85369d02cd90d3bc4fe57be172da5f5ea7193532b0794
21,428
[ -1 ]
21,431
pluto-results.md
tonyfischetti_pluto/tests/pluto-results.md
--- title: Pluto documentation ... ----- ### about a common lisp package that's out there ----- ### pluto parameters fill this out ----- ### formatting #### FN > Alias to (format nil ...)\ ```{.commonlisp} (FN "~A ~A" "hello" "goodbye") ``` <small><pre>=> "hello goodbye"</pre></small> #### FT > Alias to (format t ...)\ ```{.commonlisp} (FT "~A ~A" "hello" "goodbye") ``` <small><pre>>> "hello goodbye"</pre></small> ----- ### ansi colors and codes fill this out ----- ### string operations #### STR+ > Combine (using princ) an arbitrary number of args into one string\ ```{.commonlisp} (STR+ "belle" "and" "sebastian") ``` <small><pre>=> "belleandsebastian"</pre></small> ```{.commonlisp} (STR+ '(1 2 3) " go") ``` <small><pre>=> "(1 2 3) go"</pre></small> #### STR-JOIN > Join STRINGS with DELIM.\ ```{.commonlisp} (STR-JOIN ";" '("one" "two")) ``` <small><pre>=> "one;two"</pre></small> #### SUBSTR > Efficient substring of STRING from START to END (optional),\ > where both can be negative, which means counting from the end.\ ```{.commonlisp} (SUBSTR "belle and sebastian" 0 5) ``` <small><pre>=> "belle"</pre></small> ```{.commonlisp} (SUBSTR "belle and sebastian" 0 -14) ``` <small><pre>=> "belle"</pre></small> ```{.commonlisp} (SUBSTR "belle and sebastian" 10) ``` <small><pre>=> "sebastian"</pre></small> #### STRING->CHAR-LIST > Make a string a list of single character strings\ ```{.commonlisp} (STRING->CHAR-LIST "belle") ``` <small><pre>=> ("b" "e" "l" "l" "e")</pre></small> #### SPLIT-STRING->LINES > Split a string with new lines into a list of strings (one for each line)\ ```{.commonlisp} (SPLIT-STRING->LINES (FORMAT NIL "this~%that~%and the other")) ``` <small><pre>=> ("this" "that" "and the other")</pre></small> ----- ### some essential utilities/macros #### ALAMBDA > Anaphoric lambda. SELF! is the function\ ```{.commonlisp} (FUNCALL (ALAMBDA (X) (WHEN (> X 0) (CONS X (SELF! (- X 1))))) 10) ``` <small><pre>=> (10 9 8 7 6 5 4 3 2 1)</pre></small> #### FLATTEN > Flattens a list (possibly inefficiently)\ ```{.commonlisp} (FLATTEN `(A B (C D (E)))) ``` <small><pre>=> (A B C D E)</pre></small> #### TAKE > Takes `n` from beginning of `alist` and returns that in a\ > list. It also returns the remainder of the list (use\ > `multiple-value-bind` with it\ ```{.commonlisp} (MULTIPLE-VALUE-BIND (ONE TWO) (TAKE `(A B C D E F) 2) (LIST ONE TWO)) ``` <small><pre>=> ((A B) (C D E F))</pre></small> #### GROUP > Turn a (flat) list into a list of lists of length `n`\ ```{.commonlisp} (GROUP `(A B C D E F) 2) ``` <small><pre>=> ((A B) (C D) (E F))</pre></small> #### -<> > Threading macro (put <> where the argument should be)\ > Stolen from https://github.com/sjl/cl-losh/blob/master/src/control-flow.lisp\ ```{.commonlisp} (-<> "4" (PARSE-INTEGER <>) (SQRT <>)) ``` <small><pre>=> 2</pre></small> #### INTERPOSE > Returns a sequence of the elements of SEQUENCE separated by SEPARATOR.\ ```{.commonlisp} (INTERPOSE 'SEP `(A B C)) ``` <small><pre>=> (A SEP B SEP C)</pre></small> #### WITH-TIME > Anaphoric macro that executes the car of the body and\ > binds the seconds of execution time to TIME!. Then\ > all the other forms in the body are executed\ ```{.commonlisp} (WITH-TIME (SLEEP 1) (FORMAT NIL "time elapsed: ~A" TIME!)) ``` <small><pre>=> "time elapsed: 1"</pre></small> #### TIME-FOR-HUMANS > Converts SECONDS into minutes, hours, or days (based on magnitude)\ ```{.commonlisp} (TIME-FOR-HUMANS 4) ``` <small><pre>=> "4 seconds"</pre></small> ```{.commonlisp} (TIME-FOR-HUMANS 4000) ``` <small><pre>=> "1.11 hours"</pre></small> ```{.commonlisp} (TIME-FOR-HUMANS 191000) ``` <small><pre>=> "2.21 days"</pre></small> ----- ### other abbreviations and shortcuts #### FILE-SIZE > Uses `du` to return just the size of the provided file.\ > `just-bytes` ensures that the size is only counted in bytes (returns integer)\ > [default nil]\ > REQUIRES THAT :coreutils is in *features* (and requires coreutils)\ ```{.commonlisp} (FILE-SIZE "interior-of-a-heart.txt") ``` <small><pre>=> "17k"</pre></small> ```{.commonlisp} (FILE-SIZE "interior-of-a-heart.txt" :JUST-BYTES T) ``` <small><pre>=> 14433</pre></small> ----- ### for-each and friends #### FOR-EACH > A super-duper imperative looping construct.\ > It takes either\ > a filename string (to be treated as a file and goes line by line)\ > a hash-table\ > a vector\ > a list\ > a string (that goes character by character)\ > or a stream (that goes line by line)\ > It is anaphoric and introduces\ > index! (which is a zero indexed counter of which element we are on)\ > key! (the key of the current hash-table entry [only for hash-tables and alists])\ > value! (the value of the current element)\ > this-pass! (a block that returning from immediately moves to the next iteration)\ > this-loop! (a block that returning from exits the loop)\ > For convenience, (continue!) and (break!) will execute (return-from this-pass!)\ > and (return-from this-loop!), respectively\ > If it's a filename, the external format is *pluto-external-format* (:UTF-8 by default)\ > Oh, it'll die gracefully if Control-C is used during the loops execution.\ > And, finally, for extra performance, you can call it's subordinate functions directly.\ > They are... for-each/line, for-each/list, for-each/hash, for-each/vector,\ > for-each/stream, and for-each/alist\ ```{.commonlisp} (FOR-EACH/LIST '(A B C) (FORMAT T "~A -> ~A;" INDEX! VALUE!)) ``` <small><pre>>> "1 -> A;2 -> B;3 -> C;"</pre></small> ```{.commonlisp} (FOR-EACH/LIST '(A B C D E) (IF (> INDEX! 2) (BREAK!)) (FORMAT T "~A;" VALUE!)) ``` <small><pre>>> "A;B;"</pre></small> ```{.commonlisp} (FOR-EACH/LIST '(A B C D E) (IF (= INDEX! 3) (CONTINUE!)) (FORMAT T "~A;" VALUE!)) ``` <small><pre>>> "A;B;D;E;"</pre></small> If the argument to `for-each` is a string and the file exists, `for-each/line` is dispatched. Otherwise, it is treated like a character vector ```{.commonlisp} (FOR-EACH/LINE "somebody.txt" (WHEN (> INDEX! 2) (BREAK!)) (FORMAT T "~A -> ~A;" INDEX! VALUE!)) ``` <small><pre>>> "1 -> we gotta celebrate diversity;2 -> in the university;"</pre></small> ```{.commonlisp} (FOR-EACH "not-a-file.txt" (FORMAT T "~A;" VALUE!)) ``` <small><pre>>> "n;o;t;-;a;-;f;i;l;e;.;t;x;t;"</pre></small> ```{.commonlisp} (LET ((TMP (MAKE-HASH-TABLE))) (SETF (GETHASH 'GREEN TMP) "veridian") (SETF (GETHASH 'RED TMP) "cadmium") (FOR-EACH/HASH TMP (FORMAT T "~A -> ~A;" KEY! VALUE!))) ``` <small><pre>>> "RED -> cadmium;GREEN -> veridian;"</pre></small> ```{.commonlisp} (LET ((TMP (MAKE-HASH-TABLE))) (SETF (GETHASH 'GREEN TMP) "veridian") (SETF (GETHASH 'RED TMP) "cadmium") (FOR-EACH TMP (FORMAT T "~A -> ~A;" KEY! VALUE!))) ``` <small><pre>>> "RED -> cadmium;GREEN -> veridian;"</pre></small> #### FOR-EACH/ALIST > This works like `for-each/hash` (see documentation for `for-each`)\ > but it has to be called explicitly (as `for-each/alist`) instead\ > of relying on `for-each`'s 'dispatch' mechanism.\ ```{.commonlisp} (LET ((TMP (LIST (CONS 'RED "cadmium") (CONS 'GREEN "veridian")))) (FOR-EACH/ALIST TMP (FORMAT T "~A -> ~A;" KEY! VALUE!))) ``` <small><pre>>> "RED -> cadmium;GREEN -> veridian;"</pre></small> ----- ### temporary charon tests #### PARSE-FLOAT > Similar to PARSE-INTEGER, but parses a floating point value and\ > returns the value as the specified TYPE (by default\ > *READ-DEFAULT-FLOAT-FORMAT*). The DECIMAL-CHARACTER (by default #.)\ > specifies the separator between the integer and decimal parts, and\ > the EXPONENT-CHARACTER (by default #e, case insensitive) specifies\ > the character before the exponent. Note that the exponent is only\ > parsed if RADIX is 10.\ ```{.commonlisp} (PARSE-FLOAT "5.4") ``` <small><pre>=> 5.4</pre></small> ----- ### temporary styx tests #### STAT-FILESIZE NIL ```{.commonlisp} (STAT-FILESIZE "interior-of-a-heart.txt") ``` <small><pre>=> 14433</pre></small>
8,261
Common Lisp
.l
238
32.840336
104
0.637014
tonyfischetti/pluto
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
cd8f7a5cb50dde1d6464fc17d05cbac1683441b600fedab42f60c2aac1d8d604
21,431
[ -1 ]
21,432
compile.sh
tonyfischetti_pluto/libstyx/compile.sh
#!/bin/bash gcc -fpic -c styx.c -lsystemd -lssl -lcrypto && gcc -shared -o libstyx.so styx.o -lsystemd -lssl -lcrypto && cp libstyx.so ~/.lisp
152
Common Lisp
.l
4
34.75
64
0.659864
tonyfischetti/pluto
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
27b03ac1b4a6b97c5271e23c6ae7f8b5b0022d1044ad4c70bf1652e5ac13172b
21,432
[ -1 ]
21,447
util.lisp
easye_yuka/src/util.lisp
;;;; Copyright (c) 2012 Vijay Mathew Pandyalakal <[email protected]> ;;;; This file is part of yuka. ;;;; yuka 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. ;;;; yuka 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 <http://www.gnu.org/licenses/>. (in-package :yuka) ;;; Helper definitions used by the class-loader and the virtual machine runtime. (defconstant +magic+ #xCAFEBABE) (defconstant +max-code-len+ 65536) (defun read-u2 (stream) (let ((i 0)) (setf i (logior i (logand (read-byte stream) #xff))) (setf i (ash i 8)) (setf i (logior i (logand (read-byte stream) #xff))) i)) (defun read-u4 (stream) (let ((i 0)) (setf i (logior i (logand (read-byte stream) #xff))) (setf i (ash i 8)) (setf i (logior i (logand (read-byte stream) #xff))) (setf i (ash i 8)) (setf i (logior i (logand (read-byte stream) #xff))) (setf i (ash i 8)) (setf i (logior i (logand (read-byte stream) #xff))) i)) (defun read-array (stream count reader-fn) (let ((data (make-array count))) (dotimes (i count) (setf (aref data i) (funcall reader-fn stream))) data)) (defun read-array-with-user-data (stream count user-data reader-fn) (let ((data (make-array count))) (dotimes (i count) (setf (aref data i) (funcall reader-fn stream user-data))) data)) (declaim (inline neq)) (defun neq (a b) (not (eq a b))) (declaim (inline n=)) (defun n= (a b) (not (= a b))) (defstruct iterator (sequence nil) (state nil)) ;; length, current index etc. (defvar *eos* :eos) ;; end-of-sequence marker. (defmacro eos-p (obj) `(eq ,*eos* ,obj)) (defstruct array-state (len 0 :type integer) (index 0 :type integer)) (defun make-array-iterator (array) (make-iterator :sequence array :state (make-array-state :len (length array)))) (defun iterator-next (self) (let* ((state (iterator-state self)) (i (array-state-index state))) (cond ((>= i (array-state-len state)) *eos*) (t (let ((v (aref (iterator-sequence self) i))) (setf (array-state-index state) (1+ i)) v))))) (defmacro make-typed-array (dimensions type-name) `(cons (make-array ,dimensions) ,type-name)) (defmacro typed-array-elements (self) `(car ,self)) (defmacro typed-array-type-name (self) `(cdr ,self)) (defun atype-to-symbol (atype) (case atype (4 'boolean) (5 'char) (6 'float) (7 'double) (8 'byte) (9 'short) (10 'integer) (11 'long) (t (error "Invalid type passed to atype-to-symbol: ~a~%" atype))))
3,034
Common Lisp
.lisp
85
32.317647
80
0.663705
easye/yuka
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
d86f93998276c76c4baa9b55d7b1b6baff21a64806ff768c41cbd761a71ebc06
21,447
[ -1 ]
21,448
opc.lisp
easye_yuka/src/opc.lisp
;;;; Copyright (c) 2012 Vijay Mathew Pandyalakal <[email protected]> ;;;; This file is part of yuka. ;;;; yuka 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. ;;;; yuka 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 <http://www.gnu.org/licenses/>. (in-package :yuka) ;;; Representation of opcodes. (defparameter *opcode-symbols* (make-array 255)) (defun init-opcode-symbols-table () (setf (aref *opcode-symbols* 50) 'aaload) (setf (aref *opcode-symbols* 83) 'aastore) (setf (aref *opcode-symbols* 1) 'aconst_null) (setf (aref *opcode-symbols* 25) 'aload) (setf (aref *opcode-symbols* 42) 'aload_0) (setf (aref *opcode-symbols* 43) 'aload_1) (setf (aref *opcode-symbols* 44) 'aload_2) (setf (aref *opcode-symbols* 45) 'aload_3) (setf (aref *opcode-symbols* 189) 'anewarray) (setf (aref *opcode-symbols* 176) 'areturn) (setf (aref *opcode-symbols* 190) 'arraylength) (setf (aref *opcode-symbols* 58) 'astore) (setf (aref *opcode-symbols* 75) 'astore_0) (setf (aref *opcode-symbols* 76) 'astore_1) (setf (aref *opcode-symbols* 77) 'astore_2) (setf (aref *opcode-symbols* 78) 'astore_3) (setf (aref *opcode-symbols* 191) 'athrow) (setf (aref *opcode-symbols* 51) 'baload) (setf (aref *opcode-symbols* 84) 'bastore) (setf (aref *opcode-symbols* 16) 'bipush) (setf (aref *opcode-symbols* 52) 'caload) (setf (aref *opcode-symbols* 85) 'castore) (setf (aref *opcode-symbols* 192) 'checkcast) (setf (aref *opcode-symbols* 144) 'd2f) (setf (aref *opcode-symbols* 142) 'd2i) (setf (aref *opcode-symbols* 143) 'd2l) (setf (aref *opcode-symbols* 99) 'dadd) (setf (aref *opcode-symbols* 49) 'daload) (setf (aref *opcode-symbols* 82) 'dastore) (setf (aref *opcode-symbols* 152) 'dcmpg) (setf (aref *opcode-symbols* 151) 'dcmpl) (setf (aref *opcode-symbols* 14) 'dconst_0) (setf (aref *opcode-symbols* 15) 'dconst_1) (setf (aref *opcode-symbols* 111) 'ddiv) (setf (aref *opcode-symbols* 24) 'dload) (setf (aref *opcode-symbols* 38) 'dload_0) (setf (aref *opcode-symbols* 39) 'dload_1) (setf (aref *opcode-symbols* 40) 'dload_2) (setf (aref *opcode-symbols* 41) 'dload_3) (setf (aref *opcode-symbols* 107) 'dmul) (setf (aref *opcode-symbols* 119) 'dneg) (setf (aref *opcode-symbols* 115) 'drem) (setf (aref *opcode-symbols* 175) 'dreturn) (setf (aref *opcode-symbols* 57) 'dstore) (setf (aref *opcode-symbols* 71) 'dstore_0) (setf (aref *opcode-symbols* 72) 'dstore_1) (setf (aref *opcode-symbols* 73) 'dstore_2) (setf (aref *opcode-symbols* 74) 'dstore_3) (setf (aref *opcode-symbols* 103) 'dsub) (setf (aref *opcode-symbols* 89) 'dup) (setf (aref *opcode-symbols* 90) 'dup_x1) (setf (aref *opcode-symbols* 91) 'dup_x2) (setf (aref *opcode-symbols* 92) 'dup2) (setf (aref *opcode-symbols* 93) 'dup2_x1) (setf (aref *opcode-symbols* 94) 'dup2_x2) (setf (aref *opcode-symbols* 141) 'f2d) (setf (aref *opcode-symbols* 139) 'f2i) (setf (aref *opcode-symbols* 140) 'f2l) (setf (aref *opcode-symbols* 98) 'fadd) (setf (aref *opcode-symbols* 48) 'faload) (setf (aref *opcode-symbols* 81) 'fastore) (setf (aref *opcode-symbols* 150) 'fcmpg) (setf (aref *opcode-symbols* 149) 'fcmpl) (setf (aref *opcode-symbols* 11) 'fconst_0) (setf (aref *opcode-symbols* 12) 'fconst_1) (setf (aref *opcode-symbols* 13) 'fconst_2) (setf (aref *opcode-symbols* 110) 'fdiv) (setf (aref *opcode-symbols* 23) 'fload) (setf (aref *opcode-symbols* 34) 'fload_0) (setf (aref *opcode-symbols* 35) 'fload_1) (setf (aref *opcode-symbols* 36) 'fload_2) (setf (aref *opcode-symbols* 37) 'fload_3) (setf (aref *opcode-symbols* 106) 'fmul) (setf (aref *opcode-symbols* 118) 'fneg) (setf (aref *opcode-symbols* 114) 'frem) (setf (aref *opcode-symbols* 174) 'freturn) (setf (aref *opcode-symbols* 56) 'fstore) (setf (aref *opcode-symbols* 67) 'fstore_0) (setf (aref *opcode-symbols* 68) 'fstore_1) (setf (aref *opcode-symbols* 69) 'fstore_2) (setf (aref *opcode-symbols* 70) 'fstore_3) (setf (aref *opcode-symbols* 102) 'fsub) (setf (aref *opcode-symbols* 180) 'getfield) (setf (aref *opcode-symbols* 178) 'getstatic) (setf (aref *opcode-symbols* 167) 'goto) (setf (aref *opcode-symbols* 200) 'goto_w) (setf (aref *opcode-symbols* 145) 'i2b) (setf (aref *opcode-symbols* 146) 'i2c) (setf (aref *opcode-symbols* 135) 'i2d) (setf (aref *opcode-symbols* 134) 'i2f) (setf (aref *opcode-symbols* 133) 'i2l) (setf (aref *opcode-symbols* 147) 'i2s) (setf (aref *opcode-symbols* 96) 'iadd) (setf (aref *opcode-symbols* 46) 'iaload) (setf (aref *opcode-symbols* 126) 'iand) (setf (aref *opcode-symbols* 79) 'iastore) (setf (aref *opcode-symbols* 2) 'iconst_m1) (setf (aref *opcode-symbols* 3) 'iconst_0) (setf (aref *opcode-symbols* 4) 'iconst_1) (setf (aref *opcode-symbols* 5) 'iconst_2) (setf (aref *opcode-symbols* 6) 'iconst_3) (setf (aref *opcode-symbols* 7) 'iconst_4) (setf (aref *opcode-symbols* 8) 'iconst_5) (setf (aref *opcode-symbols* 108) 'idiv) (setf (aref *opcode-symbols* 165) 'if_acmpeq) (setf (aref *opcode-symbols* 166) 'if_acmpne) (setf (aref *opcode-symbols* 159) 'if_icmpeq) (setf (aref *opcode-symbols* 160) 'if_icmpne) (setf (aref *opcode-symbols* 161) 'if_icmplt) (setf (aref *opcode-symbols* 162) 'if_icmpge) (setf (aref *opcode-symbols* 163) 'if_icmpgt) (setf (aref *opcode-symbols* 164) 'if_icmple) (setf (aref *opcode-symbols* 153) 'ifeq) (setf (aref *opcode-symbols* 154) 'ifne) (setf (aref *opcode-symbols* 155) 'iflt) (setf (aref *opcode-symbols* 156) 'ifge) (setf (aref *opcode-symbols* 157) 'ifgt) (setf (aref *opcode-symbols* 158) 'ifle) (setf (aref *opcode-symbols* 199) 'ifnonnull) (setf (aref *opcode-symbols* 198) 'ifnull) (setf (aref *opcode-symbols* 132) 'iinc) (setf (aref *opcode-symbols* 21) 'iload) (setf (aref *opcode-symbols* 26) 'iload_0) (setf (aref *opcode-symbols* 27) 'iload_1) (setf (aref *opcode-symbols* 28) 'iload_2) (setf (aref *opcode-symbols* 29) 'iload_3) (setf (aref *opcode-symbols* 104) 'imul) (setf (aref *opcode-symbols* 116) 'ineg) (setf (aref *opcode-symbols* 193) 'instanceof) (setf (aref *opcode-symbols* 186) 'invokedynamic) (setf (aref *opcode-symbols* 185) 'invokeinterface) (setf (aref *opcode-symbols* 183) 'invokespecial) (setf (aref *opcode-symbols* 184) 'invokestatic) (setf (aref *opcode-symbols* 182) 'invokevirtual) (setf (aref *opcode-symbols* 128) 'ior) (setf (aref *opcode-symbols* 112) 'irem) (setf (aref *opcode-symbols* 172) 'ireturn) (setf (aref *opcode-symbols* 120) 'ishl) (setf (aref *opcode-symbols* 122) 'ishr) (setf (aref *opcode-symbols* 54) 'istore) (setf (aref *opcode-symbols* 59) 'istore_0) (setf (aref *opcode-symbols* 60) 'istore_1) (setf (aref *opcode-symbols* 61) 'istore_2) (setf (aref *opcode-symbols* 62) 'istore_3) (setf (aref *opcode-symbols* 100) 'isub) (setf (aref *opcode-symbols* 124) 'iushr) (setf (aref *opcode-symbols* 130) 'ixor) (setf (aref *opcode-symbols* 168) 'jsr) (setf (aref *opcode-symbols* 201) 'jsr_w) (setf (aref *opcode-symbols* 138) 'l2d) (setf (aref *opcode-symbols* 137) 'l2f) (setf (aref *opcode-symbols* 136) 'l2i) (setf (aref *opcode-symbols* 97) 'ladd) (setf (aref *opcode-symbols* 47) 'laload) (setf (aref *opcode-symbols* 127) 'land) (setf (aref *opcode-symbols* 80) 'lastore) (setf (aref *opcode-symbols* 148) 'lcmp) (setf (aref *opcode-symbols* 9) 'lconst_0) (setf (aref *opcode-symbols* 10) 'lconst_1) (setf (aref *opcode-symbols* 18) 'ldc) (setf (aref *opcode-symbols* 19) 'ldc_w) (setf (aref *opcode-symbols* 20) 'ldc2_w) (setf (aref *opcode-symbols* 109) 'ldiv) (setf (aref *opcode-symbols* 22) 'lload) (setf (aref *opcode-symbols* 30) 'lload_0) (setf (aref *opcode-symbols* 31) 'lload_1) (setf (aref *opcode-symbols* 32) 'lload_2) (setf (aref *opcode-symbols* 33) 'lload_3) (setf (aref *opcode-symbols* 105) 'lmul) (setf (aref *opcode-symbols* 117) 'lneg) (setf (aref *opcode-symbols* 171) 'lookupswitch) (setf (aref *opcode-symbols* 129) 'lor) (setf (aref *opcode-symbols* 113) 'lrem) (setf (aref *opcode-symbols* 173) 'lreturn) (setf (aref *opcode-symbols* 121) 'lshl) (setf (aref *opcode-symbols* 123) 'lshr) (setf (aref *opcode-symbols* 55) 'lstore) (setf (aref *opcode-symbols* 63) 'lstore_0) (setf (aref *opcode-symbols* 64) 'lstore_1) (setf (aref *opcode-symbols* 65) 'lstore_2) (setf (aref *opcode-symbols* 66) 'lstore_3) (setf (aref *opcode-symbols* 101) 'lsub) (setf (aref *opcode-symbols* 125) 'lushr) (setf (aref *opcode-symbols* 131) 'lxor) (setf (aref *opcode-symbols* 194) 'monitorenter) (setf (aref *opcode-symbols* 195) 'monitorexit) (setf (aref *opcode-symbols* 197) 'multianewarray) (setf (aref *opcode-symbols* 187) 'new) (setf (aref *opcode-symbols* 188) 'newarray) (setf (aref *opcode-symbols* 0) 'nop) (setf (aref *opcode-symbols* 87) 'pop) (setf (aref *opcode-symbols* 88) 'pop2) (setf (aref *opcode-symbols* 181) 'putfield) (setf (aref *opcode-symbols* 179) 'putstatic) (setf (aref *opcode-symbols* 169) 'ret) (setf (aref *opcode-symbols* 177) 'return) (setf (aref *opcode-symbols* 53) 'saload) (setf (aref *opcode-symbols* 86) 'sastore) (setf (aref *opcode-symbols* 17) 'sipush) (setf (aref *opcode-symbols* 95) 'swap) (setf (aref *opcode-symbols* 170) 'tableswitch) (setf (aref *opcode-symbols* 196) 'wide)) (init-opcode-symbols-table) (defmacro index-from-bytes (code offset) `(progn (logior (ash (aref ,code (1+ ,offset)) 8) (aref ,code (+ 2 ,offset))))) (defmacro wide-index-from-bytes (code offset) `(logior (ash (aref ,code (1+ ,offset)) 24) (ash (aref ,code (+ 2 ,offset)) 16) (ash (aref ,code (+ 3 ,offset)) 8) (aref ,code (+ 4 ,offset)))) (defun byte-index-from-bytes (code offset) (let ((a (aref code (1+ offset))) (b (aref code (+ 2 offset)))) (let ((x (mod (logior (ash a 8) b) 256))) (+ offset (if (> x 127) (- x 256) x))))) (defun skip-padding (offset) ;; Skip padding to an address that is a multiple of 4. ;; Padding must be between 0 and 3. (loop (when (= 0 (mod offset 4)) (return)) (setf offset (1+ offset))) offset) (defun get-lookupswitch (code offset) (let ((default-byte (wide-index-from-bytes code offset)) (match-pairs (make-array (wide-index-from-bytes code (+ 4 offset))))) (setf offset (+ 8 offset)) (dotimes (i (length match-pairs)) (setf (aref match-pairs i) (cons (wide-index-from-bytes code offset) (wide-index-from-bytes code (+ 4 offset)))) (setf offset (+ 8 offset))) (cons offset (cons default-byte match-pairs)))) (defstruct table-switch (default 0 :type integer) (low 0 :type integer) (hi 0 :type integer) (jump-offsets nil :type simple-array)) (defun get-tableswitch (code offset) (let* ((default (wide-index-from-bytes code offset)) (low (wide-index-from-bytes code (+ 4 offset))) (hi (wide-index-from-bytes code (+ 8 offset))) (count (1+ (- hi low))) (jump-indices (make-array count))) (setf offset (+ 12 offset)) (dotimes (i count) (setf (aref jump-indices i) (aref code offset)) (setf offset (1+ offset))) (cons offset (make-table-switch :default default :low low :hi hi :jump-offsets jump-indices)))) (defun get-wide (code offset) (let ((opc (aref *opcode-symbols* (aref code offset)))) (case opc ((iinc) (cons (+ 5 offset) (cons (index-from-bytes code (1+ offset)) (index-from-bytes code (+ 3 offset))))) (t (cons (+ 3 offset) (index-from-bytes code (1+ offset))))))) (defun next-opcode (code offset) (let ((opc (aref *opcode-symbols* (aref code offset)))) (case opc ((invokespecial anewarray checkcast getfield getstatic instanceof invokestatic invokevirtual ldc_w ldc2_w new putfield putstatic sipush) (cons (+ offset 2) (cons opc (index-from-bytes code offset)))) ((goto if_acmpne if_acmpeq if_icmpeq if_icmpne if_icmplt if_icmpge if_icmpgt if_icmple ifeq ifne iflt ifge ifgt ifle ifnonnull ifnull jsr) (cons (+ offset 2) (cons opc (byte-index-from-bytes code offset)))) ((aload astore bipush dload dstore fload fstore iload istore ldc lload lstore newarray ret) (cons (1+ offset) (cons opc (aref code (1+ offset))))) ((iinc) (cons (+ offset 2) (cons opc (cons (aref code (1+ offset)) (aref code (+ 2 offset)))))) ((invokedynamic) (cons (+ offset 4) (cons opc (index-from-bytes code offset)))) ((invokeinterface) (cons (+ offset 4) (cons opc (cons (index-from-bytes code offset) (aref code (+ 3 offset)))))) ((jsr_w goto_w) (cons (+ offset 4) (cons opc (wide-index-from-bytes code offset)))) ((lookupswitch) (get-lookupswitch code (skip-padding offset))) ((multianewarray) (cons (+ offset 3) (cons opc (cons (index-from-bytes code offset) (aref code (+ 2 offset)))))) ((tableswitch) (get-tableswitch code (skip-padding offset))) ((wide) (get-wide code offset)) (t (cons offset opc))))) (defmacro opcode-offset (self) `(car ,self)) (defun opcode-symbol (self) (let ((opc (cdr self))) (if (consp opc) (car opc) opc))) (defun opcode-operands (self) (let ((opc (cdr self))) (if (consp opc) (cdr opc) nil))) (defun bytes-to-opcode (bytes-array) (let ((res nil)) (loop for i from 0 to (1- (length bytes-array)) do (let ((i-opc (next-opcode bytes-array i))) (setf res (cons (cons i (cdr i-opc)) res)) (setf i (car i-opc)))) (coerce (reverse res) 'simple-vector))) (defun opcode-to-string (self) (with-output-to-string (s) (map nil #'(lambda (opc) (let ((oprnds (opcode-operands opc))) (if (null oprnds) (format s " ~3a ~15a~%" (format nil "~a:" (opcode-offset opc)) (opcode-symbol opc)) (format s " ~3a ~15a #~a~%" (format nil "~a:" (opcode-offset opc)) (opcode-symbol opc) oprnds)))) self)))
14,893
Common Lisp
.lisp
342
38.923977
94
0.645237
easye/yuka
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
0d5b3b6c9a7219f58d8dd16f43335dd9ca5e26e6d3efc285945c0ad9db9d7fd6
21,448
[ -1 ]
21,449
numeric.lisp
easye_yuka/src/numeric.lisp
;;;; Copyright (c) 2012 Vijay Mathew Pandyalakal <[email protected]> ;;;; This file is part of yuka. ;;;; yuka 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. ;;;; yuka 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 <http://www.gnu.org/licenses/>. (in-package :yuka) ;;; Low-level numeric types (byte, short, int, long, float and double). (defconstant +max-byte+ (1- (expt 2 7))) (defconstant +min-byte+ (expt -2 7)) (defconstant +max-short+ (1- (expt 2 15))) (defconstant +min-short+ (expt -2 15)) (defconstant +max-integer+ (1- (expt 2 31))) (defconstant +min-integer+ (expt -2 31)) (defconstant +max-long+ (1- (expt 2 63))) (defconstant +min-long+ (expt -2 63)) (defconstant +max-float+ (coerce (* (- 2 (expt 2 -23)) (expt 2 127)) 'double-float)) (defconstant +min-float+ (- +max-float+)) (defconstant +max-double+ (coerce (* (- 2 (expt 2 -52)) (expt 2 1023)) 'double-float)) (defconstant +min-double+ (- +max-double+)) (defconstant +negative-zero+ '-zero) (defconstant +float-zero+ 0.0) (defconstant +float-one+ 1.0) (defconstant +float-two+ 2.0) (declaim (inline in-range)) (defun in-range (n start end) (and (>= n start) (<= n end))) (declaim (inline is-int-in-range)) (defun is-int-in-range (i s e) (and (integerp i) (in-range i s e))) (declaim (inline is-float-in-range)) (defun is-float-in-range (f s e) (and (floatp f) (in-range f s e))) (defun make-i (v s e) (if (is-int-in-range v s e) v (if (> v 0) e s))) (defun make-f (v s e) (if (is-float-in-range v s e) v (if (> v 0) e s))) (defun make-char (v) (if (is-int-in-range v +min-short+ +max-short+) v (if (> v 0) +max-short+ +min-short+))) (declaim (inline make-byte)) (defun make-byte (v) (make-i v +min-byte+ +max-byte+)) (declaim (inline make-integer)) (defun make-integer (v) (make-i v +min-integer+ +max-integer+)) (declaim (inline integer-info-to-int)) (defun integer-info-to-int (iinfo) (make-integer (integer-info-bytes iinfo))) (declaim (inline make-short)) (defun make-short (v) (make-i v +min-byte+ +max-byte+)) (declaim (inline make-long)) (defun make-long (v) (make-i v +min-long+ +max-long+)) (declaim (inline make-float)) (defun make-float (v) (make-f v +min-float+ +max-float+)) (declaim (inline float-info-to-float)) (defun float-info-to-float (finfo) (make-float (float-info-value finfo))) (declaim (inline make-double)) (defun make-double (v) (make-f v +min-double+ +max-double+)) (declaim (inline is-nan)) (defun is-nan (v) (eq v +nan+)) (declaim (inline is-positive-infinity)) (defun is-positive-infinity (v) (eq v +positive-infinity+)) (declaim (inline is-negative-infinity)) (defun is-negative-infinity (v) (eq v +negative-infinity+)) (defun make-inf-from (inf) (if (is-positive-infinity inf) +positive-infinity+ +negative-infinity+)) (declaim (inline double-info-to-double)) (defun double-info-to-double (dinfo) (make-double (double-info-value dinfo))) (declaim (inline is-infinity)) (defun is-infinity (v) (or (is-positive-infinity v) (is-negative-infinity v))) (declaim (inline nanis-negative-infinity)) (defun nanis-negative-infinity (v) (or (is-nan v) (is-infinity v))) (declaim (inline is-boolean)) (defun is-boolean (obj) (or (null obj) (eq t obj))) (declaim (inline is-byte)) (defun is-byte (obj) (is-int-in-range obj +min-byte+ +max-byte+)) (declaim (inline is-char)) (defun is-char (obj) (characterp obj)) (declaim (inline is-short)) (defun is-short (obj) (is-int-in-range obj +min-short+ +max-short+)) (declaim (inline is-int)) (defun is-int (obj) (is-int-in-range obj +min-integer+ +max-integer+)) (declaim (inline is-long)) (defun is-long (obj) (is-int-in-range obj +min-long+ +max-long+)) (declaim (inline is-float)) (defun is-float (obj) (is-float-in-range obj +min-float+ +max-float+)) (declaim (inline is-double)) (defun is-double (obj) (is-float-in-range obj +min-double+ +max-double+)) ;; Implementation is FP-strict. (Section 2.8.2 of JVM Spec.) (defun double-to-float (v) (cond ((nanis-negative-infinity v) (make-float v)) (t (if (and (>= v +min-float+) (<= v +max-float+)) (make-float v) (if (< v 0) (make-float +min-float+) (make-float +max-float+)))))) (defun double-to-number (v constructor max-val min-val &optional (default-val 0)) (cond ((nanis-negative-infinity v) (funcall constructor default-val)) (t (funcall constructor (let ((iv (floor v))) (cond ((> iv max-val) max-val) ((< iv min-val) min-val) (t iv))))))) (declaim (inline double-to-int)) (defun double-to-int (self) (double-to-number self #'make-integer +max-integer+ +min-integer+)) (declaim (inline double-to-long)) (defun double-to-long (self) (double-to-number self #'make-long +max-long+ +min-long+)) (declaim (inline are-opposite-infs)) (defun are-opposite-infs (v1 v2) (or (and (is-positive-infinity v1) (is-negative-infinity v2)) (and (is-negative-infinity v1) (is-positive-infinity v2)))) (declaim (inline are-same-infs)) (defun are-same-infs (v1 v2) (or (and (is-positive-infinity v1) (is-positive-infinity v2)) (and (is-negative-infinity v1) (is-negative-infinity v2)))) (defun add-f (v1 v2 constructor) (cond ((or (is-nan v1) (is-nan v2) (are-opposite-infs v1 v2)) +nan+) ((are-same-infs v1 v2) (make-inf-from v1)) ((or (is-positive-infinity v1) (is-positive-infinity v2)) +positive-infinity+) ((or (is-negative-infinity v1) (is-negative-infinity v2)) +negative-infinity+) ;; TODO: positive and negative zeros (t (funcall constructor (+ v1 v2))))) (defun double-add (v1 v2) (add-f v1 v2 #'make-double)) (defun compare-nan-infs (v1 v2 is-l) (cond ((or (is-nan v1) (is-nan v2)) (if is-l -1 1)) ((or (and (is-positive-infinity v1) (is-positive-infinity v2)) (and (is-negative-infinity v1) (is-negative-infinity v2))) 0) ((is-positive-infinity v1) 1) ((is-negative-infinity v1) -1))) (defun double-compare (v1 v2 is-l) (if (and (numberp v1) (numberp v2)) (cond ((> v1 v2) 1) ((< v1 v2) -1) (t 0)) (compare-nan-infs v1 v2 is-l))) (declaim (inline is-nzero)) (defun is-nzero (v) (eq v +negative-zero+)) (declaim (inline is-zero)) (defun is-zero (v) (or (zerop v) (is-nzero v))) (defun div-f (v1 v2 constructor) (cond ((or (or (is-nan v1) (is-nan v2)) (and (is-infinity v1) (is-infinity v2)) (and (is-zero v1) (is-zero v2))) +nan+) ((and (is-infinity v1) (numberp v2)) (if (and (is-positive-infinity v1) (> v2 0.0)) +positive-infinity+ +negative-infinity+)) ((and (is-infinity v2) (numberp v1)) (if (and (is-positive-infinity v1) (> v2 0.0)) +float-zero+ +negative-zero+)) ((and (is-zero v1) (numberp v2)) +float-zero+) ((is-zero v2) (if (and (numberp v2) (> v2 0.0)) +positive-infinity+ +negative-infinity+)) (t (funcall constructor (/ v1 v2))))) (declaim (inline double-div)) (defun double-div (v1 v2) (div-f v1 v2 #'make-double)) (defun dbl-mul-with-inf (v infv) (cond ((is-zero v) +nan+) ((numberp v) (if (> v 0) +positive-infinity+ +negative-infinity+)) (t (if (or (is-negative-infinity infv) (is-negative-infinity v)) +negative-infinity+ +positive-infinity+)))) (defun mul-f (v1 v2 constructor) (cond ((or (is-nan v1) (is-nan v2)) +nan+) ((is-infinity v1) (dbl-mul-with-inf v2 v1)) ((is-infinity v2) (dbl-mul-with-inf v1 v2)) (t (funcall constructor (* v1 v2))))) (declaim (inline double-mul)) (defun double-mul (v1 v2) (mul-f v1 v2 #'make-double)) (defun neg-f (v constructor) (cond ((is-nan v) +nan+) ((is-positive-infinity v) +negative-infinity+) ((is-negative-infinity v) +positive-infinity+) ((is-nzero v) 0.0) ((zerop v) +negative-zero+) (t (funcall constructor (- v))))) (defun double-neg (v) (neg-f v #'make-double)) (declaim (inline is-finite)) (defun is-finite (self) (or (numberp self) (is-zero self))) (defun rem-f (dividend divisor constructor) (cond ((or (or (is-nan dividend) (is-nan divisor)) (and (is-infinity dividend) (or (is-zero divisor) (is-infinity divisor)))) +nan+) ((or (and (is-finite dividend) (is-infinity divisor)) (and (is-zero dividend) (is-finite divisor))) dividend) (t (funcall constructor (rem dividend divisor))))) (declaim (inline double-rem)) (defun double-rem (dividend divisor) (rem-f dividend divisor #'make-double)) (declaim (inline double-sub)) (defun double-sub (a b) (make-double (- a b))) (defun float-floor-helper (self min-val max-val constructor) (cond ((is-nan self) 0) ((is-positive-infinity self) max-val) ((is-negative-infinity self) min-val) (t (funcall constructor (floor self))))) (defun float-to-integer (self type) (case type ((integer) (float-floor-helper self +min-integer+ +max-integer+ #'make-integer)) ((long) (float-floor-helper self +min-long+ +max-long+ #'make-long)))) (defun is-category-1 (obj) (or (is-boolean obj) (is-byte obj) (is-char obj) (is-short obj) (is-int obj) (is-float obj) (is-reference obj) (is-return-address obj))) (declaim (inline is-category-2)) (defun is-category-2 (obj) (or (is-long obj) (is-double obj))) (declaim (inline float-add)) (defun float-add (v1 v2) (add-f v1 v2 #'make-float)) (declaim (inline float-div)) (defun float-div (v1 v2) (div-f v1 v2 #'make-float)) (declaim (inline float-mul)) (defun float-mul (v1 v2) (mul-f v1 v2 #'make-float)) (declaim (inline float-neg)) (defun float-neg (v) (neg-f v #'make-float)) (declaim (inline float-rem)) (defun float-rem (dividend divisor) (rem-f dividend divisor #'make-float)) (declaim (inline float-sub)) (defun float-sub (a b) (make-float (- a b))) (declaim (inline integer-to-double)) (defun integer-to-double (self) (make-double (coerce self 'double-float))) (declaim (inline integer-to-float)) (defun integer-to-float (self) (make-float (coerce self 'float))) (defun logical-shift-right-i (a b constructor) (funcall constructor (let* ((s (logand b #x1f)) (r (ash a (- s)))) (if (> a 0) r (+ r (ash 2 (lognot s))))))) (defmacro div-i (a b constructor) `(if (zerop ,b) 'ArithmeticException (funcall ,constructor (floor (/ ,a ,b))))) (defmacro rem-i (a b constructor) `(if (zerop ,b) 'ArithmeticException (funcall ,constructor (rem ,a ,b)))) (declaim (inline integer-add)) (defun integer-add (a b) (make-integer (+ a b))) (declaim (inline integer-sub)) (defun integer-sub (a b) (make-integer (- a b))) (declaim (inline integer-div)) (defun integer-div (a b) (div-i a b #'make-integer)) (declaim (inline integer-mul)) (defun integer-mul (a b) (make-integer (* a b))) (declaim (inline integer-and)) (defun integer-and (a b) (make-integer (logand a b))) (declaim (inline integer-or)) (defun integer-or (a b) (make-integer (logior a b))) (declaim (inline integer-neg)) (defun integer-neg (self) (make-integer (- self))) (declaim (inline integer-rem)) (defun integer-rem (a b) (rem-i a b #'make-integer)) (declaim (inline integer-shift-left)) (defun integer-shift-left (a b) (make-integer (ash a b))) (declaim (inline integer-shift-right)) (defun integer-shift-right (a b) (make-integer (ash a (- b)))) (declaim (inline integer-logical-shift-right)) (defun integer-logical-shift-right (a b) (logical-shift-right-i a b #'make-integer)) (declaim (inline integer-xor)) (defun integer-xor (a b) (make-integer (logxor a b))) (declaim (inline long-to-double)) (defun long-to-double (self) (make-double (coerce self 'double-float))) (declaim (inline long-to-float)) (defun long-to-float (self) (make-float (coerce self 'float))) (declaim (inline long-to-integer)) (defun long-to-integer (self) (make-integer self)) (declaim (inline long-add)) (defun long-add (a b) (make-long (+ a b))) (declaim (inline long-sub)) (defun long-sub (a b) (make-long (- a b))) (declaim (inline long-and)) (defun long-and (a b) (make-long (logand a b))) (declaim (inline long-compare)) (defun long-compare (a b) (make-long (cond ((= a b) 0) ((> a b) 1) ((< a b) -1)))) (declaim (inline long-div)) (defun long-div (a b) (div-i a b #'make-long)) (declaim (inline long-mul)) (defun long-mul (a b) (make-long (* a b))) (declaim (inline long-neg)) (defun long-neg (a) (make-long (- a))) (declaim (inline long-or)) (defun long-or (a b) (make-long (logior a b))) (declaim (inline long-rem)) (defun long-rem (a b) (rem-i a b #'make-long)) (declaim (inline long-shift-left)) (defun long-shift-left (a b) (make-long (ash a b))) (declaim (inline long-shift-right)) (defun long-shift-right (a b) (make-long (ash a (- b)))) (declaim (inline long-logical-shift-right)) (defun long-logical-shift-right (a b) (logical-shift-right-i a b #'make-long)) (declaim (inline long-xor)) (defun long-xor (a b) (make-long (logxor a b)))
13,662
Common Lisp
.lisp
434
28.294931
86
0.656583
easye/yuka
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
cb88385931e2769f0aac55136056156ea8f6b98b1758971249a93345a50d2ff0
21,449
[ -1 ]
21,450
field-method-info.lisp
easye_yuka/src/field-method-info.lisp
;;;; Copyright (c) 2012 Vijay Mathew Pandyalakal <[email protected]> ;;;; This file is part of yuka. ;;;; yuka 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. ;;;; yuka 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 <http://www.gnu.org/licenses/>. (in-package :yuka) ;;; Functions and structures required to deal with field and method information. (defstruct field/method-info (access-flags 0 :type integer) (name-index 0 :type integer) (descriptor-index 0 :type integer) (attributes-count 0 :type integer) (attributes nil :type simple-array)) (defun read-field/method-info (stream constant-pool) (let ((info (make-field/method-info :access-flags (read-u2 stream) :name-index (read-u2 stream) :descriptor-index (read-u2 stream) :attributes (read-attribute-infos stream (read-u2 stream) constant-pool #'read-code-attribute)))) (setf (field/method-info-attributes-count info) (length (field/method-info-attributes info))) info)) (defmacro read-field/method-infos (stream count constant-pool) `(read-array-with-user-data ,stream ,count ,constant-pool #'read-field/method-info)) (declaim (inline field/method-info-has-access-flag)) (defun field/method-info-has-access-flag (self flag) (> (logand (field/method-info-access-flags self) flag) 0)) (defun field/method-info-to-string (self constant-pool) (with-output-to-string (s) (format s "~a~a ~a ~a" (flags-to-string (field/method-info-access-flags self)) (constant-pool-string-at constant-pool (field/method-info-descriptor-index self)) (constant-pool-string-at constant-pool (field/method-info-name-index self)) (attribute-infos-to-string (field/method-info-attributes self) constant-pool #'attribute-info-to-string)))) (defun field/method-infos-to-string (self constant-pool) (with-output-to-string (s) (map nil #'(lambda (info) (format s "~a" (field/method-info-to-string info constant-pool))) self))) (defun method-code-attribute (self) (let ((iter (make-array-iterator (field/method-info-attributes self)))) (loop (let ((a (iterator-next iter))) (when (eq a *eos*) (return nil)) (when (is-code-attribute a) (return (attribute-info-info a)))))))
2,872
Common Lisp
.lisp
55
46.327273
86
0.689507
easye/yuka
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
41dfd43dc802d21625040b05edfc92fe15de847aea71a228d740f9bd78f847ae
21,450
[ -1 ]
21,451
bounded-stack.lisp
easye_yuka/src/bounded-stack.lisp
;;;; Copyright (c) 2012 Vijay Mathew Pandyalakal <[email protected]> ;;;; This file is part of yuka. ;;;; yuka 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. ;;;; yuka 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 <http://www.gnu.org/licenses/>. (in-package :yuka) ;;; Data structure used by the VM as the operand stack. (defstruct bounded-stack (elements nil :type simple-array) (index 0 :type integer)) (defmacro make-stack (max-depth) `(make-bounded-stack :elements (make-array ,max-depth))) (defun stack-push (self e) (let ((elements (bounded-stack-elements self)) (index (bounded-stack-index self))) (when (>= index (length elements)) (error "stack overflow.")) (when (< index 0) (setf index 0)) (setf (aref elements index) e) (setf (bounded-stack-index self) (1+ index))) self) (defun stack-pop (self) (let ((elements (bounded-stack-elements self)) (index (1- (bounded-stack-index self)))) (when (< index 0) (error "stack underflow.")) (setf (bounded-stack-index self) index) (aref elements index))) (defun stack-top (self) (let ((e (stack-pop self)) (i (bounded-stack-index self))) (setf (bounded-stack-index self) (1+ i)) e)) (defmacro stack-length (self) `(bounded-stack-index ,self)) (defun stack-at (self index) (let ((len (stack-length self))) (when (or (>= index len) (< index 0)) (error "invalid stack index.")) (aref (bounded-stack-elements self) (- (1- len) index)))) (defmacro stack-reset (self) `(setf (bounded-stack-index ,self) 0)) (defmacro stack-dup (self) `(stack-push ,self (stack-top ,self))) (defun stack-dup-x1 (self) (let ((v1 (stack-pop self)) (v2 (stack-pop self))) (stack-push (stack-push (stack-push self v1) v2) v1))) (defun stack-dup-x3 (self) (let ((v1 (stack-pop self)) (v2 (stack-pop self)) (v3 (stack-pop self))) (stack-push (stack-push (stack-push (stack-push self v1) v3) v2) v1))) (defun stack-dup-x2 (self) (if (and (is-category-1 (stack-at self 0)) (is-category-1 (stack-at self 1))) (stack-dup-x3 self) (stack-dup-x1 self))) (defun stack-dup2 (self) (if (is-category-2 (stack-at self 0)) (stack-dup self) (let ((v1 (stack-at self 0)) (v2 (stack-at self 1))) (stack-push (stack-push self v2) v1)))) (defun stack-dup2-x1-form2 (self) (let ((v1 (stack-pop self)) (v2 (stack-pop self))) (stack-push (stack-push (stack-push self v1) v2) v1))) (defun stack-dup2-x1 (self) (if (is-category-2 (stack-at self 0)) (stack-dup2-x1-form2 self) (let ((v1 (stack-pop self)) (v2 (stack-pop self)) (v3 (stack-pop self))) (stack-push (stack-push (stack-push (stack-push (stack-push self v2) v1) v3) v2) v1)))) (defun stack-dup2-x2-form1 (self) (let ((v1 (stack-pop self)) (v2 (stack-pop self)) (v3 (stack-pop self)) (v4 (stack-pop self))) (stack-push (stack-push (stack-push (stack-push (stack-push (stack-push self v2) v1) v4) v3) v2) v1))) (defun stack-dup2-x2-form2 (self) (let ((v1 (stack-pop self)) (v2 (stack-pop self)) (v3 (stack-pop self))) (stack-push (stack-push (stack-push (stack-push self v1) v3) v2) v1))) (defun stack-dup2-x2-form3 (self) (let ((v1 (stack-pop self)) (v2 (stack-pop self)) (v3 (stack-pop self))) (stack-push (stack-push (stack-push (stack-push (stack-push self v2) v1) v3) v2) v1))) (defun stack-dup2-x2 (self) (cond ((is-category-2 (stack-at self 0)) (if (is-category-1 (stack-at self 1)) (stack-dup2-x2-form2 self) (stack-dup2-x1-form2 self))) ((and (is-category-1 (stack-at self 0)) (is-category-1 (stack-at self 1))) (if (is-category-1 (stack-at self 2)) (stack-dup2-x2-form1 self) (stack-dup2-x2-form3 self))))) (declaim (inline stack-swap)) (defun stack-swap (self) (let ((a (stack-pop self)) (b (stack-pop self))) (stack-push (stack-push self a) b)))
4,420
Common Lisp
.lisp
116
34.543103
90
0.658953
easye/yuka
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
111647345008d0e7daabfb77cf9e63f792055e10b70f498fc87b42ab28047765
21,451
[ -1 ]
21,452
klass-loader.lisp
easye_yuka/src/klass-loader.lisp
;;;; Copyright (c) 2012 Vijay Mathew Pandyalakal <[email protected]> ;;;; This file is part of yuka. ;;;; yuka 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. ;;;; yuka 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 <http://www.gnu.org/licenses/>. (in-package :yuka) ;;; The system class loader - loads a binary file in the JVM class file format. (defun read-interfaces (stream count) (let ((interfaces (make-array count))) (dotimes (i count) (setf (aref interfaces i) (read-u2 stream))) interfaces)) (defun klass-from-stream (stream) (when (not (= (read-u4 stream) +magic+)) (error "Not a valid klass. Magic check failed.")) (let ((mav (read-u2 stream)) (miv (read-u2 stream)) (cp (read-constant-pool stream (1- (read-u2 stream))))) (let ((self (make-klass :minor-version mav :major-version miv :constant-pool cp :access-flags (read-u2 stream) :this (read-u2 stream) :super (read-u2 stream) :interfaces (read-interfaces stream (read-u2 stream)) :fields (read-field/method-infos stream (read-u2 stream) cp) :methods (read-field/method-infos stream (read-u2 stream) cp) :attributes (read-attribute-infos stream (read-u2 stream) cp #'read-code-attribute)))) (setf (klass-constant-pool-count self) (length (klass-constant-pool self))) (setf (klass-interfaces-count self) (length (klass-interfaces self))) (setf (klass-fields-count self) (length (klass-fields self))) (setf (klass-methods-count self) (length (klass-methods self))) (setf (klass-attributes-count self) (length (klass-attributes self))) self))) (defmacro verify-end-of-klass-stream (stream) `(when (not (null (read-byte ,stream nil))) (error "Class file verfication failed. Found extra bytes at end."))) (defun load-klass-file (file-name) (with-open-file (stream file-name :element-type '(unsigned-byte 8)) (let ((klass (klass-from-stream stream))) (verify-end-of-klass-stream stream) klass))) (defmacro find-klass (klass-name) `(format t "(find-klass ~a) not implemented!~%" ,klass-name))
2,686
Common Lisp
.lisp
51
47.176471
90
0.679116
easye/yuka
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
8d8eb6b43074e31ee091db703e6dcb86e88f438c284aefb8194c015a33325a29
21,452
[ -1 ]
21,453
attribute-info.lisp
easye_yuka/src/attribute-info.lisp
;;;; Copyright (c) 2012 Vijay Mathew Pandyalakal <[email protected]> ;;;; This file is part of yuka. ;;;; yuka 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. ;;;; yuka 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 <http://www.gnu.org/licenses/>. (in-package :yuka) ;;; Functions and structures required to deal with ;;; class/code/field/method attributes. (defstruct code-attribute (max-stack 0 :type integer) (max-locals 0 :type integer) (code nil :type simple-array) (exception-table nil :type simple-array) (attributes nil :type simple-array)) (defstruct local-variable (start-pc 0 :type integer) (length 0 :type integer) (name-index 0 :type integer) (descriptor-index 0 :type integer) (index 0 :type integer)) (defstruct exception-table-entry (from 0 :type integer) (to 0 :type integer) (target 0 :type integer) (type 0 :type integer)) (declaim (inline read-info)) (defun read-info (stream count) (read-array stream count #'read-byte)) (defun read-code (stream len) (if (or (= len 0) (>= len +max-code-len+)) (error "Invalid code length: ~a." len)) (read-array stream len #'read-byte)) (defun exception-table-to-string (self constant-pool) (with-output-to-string (s) (format s " from to target type~%") (map nil #'(lambda (e) (format s " ~5a ~5a ~5a ~20@a~%" (exception-table-entry-from e) (exception-table-entry-to e) (exception-table-entry-target e) (constant-pool-string-at constant-pool (exception-table-entry-type e)))) self))) (defun exception-table-find-handler (self ex-klass-name constant-pool) (let ((res nil)) (dotimes (i (length self)) (let ((et (aref self i))) (when (string= (constant-pool-string-at constant-pool (exception-table-entry-type et)) ex-klass-name) (setf res et) (return)))) res)) (defun code-attribute-to-string (self constant-pool to-string-fns) (with-output-to-string (s) (format s " Code:~% stack= ~a, locals= ~a~%" (code-attribute-max-stack self) (code-attribute-max-locals self)) (format s "~a~%" (opcode-to-string (code-attribute-code self))) (when (> (length (code-attribute-exception-table self)) 0) (format s " ExceptionTable:~%~a~%" (exception-table-to-string (code-attribute-exception-table self) constant-pool))) (format s "~% LineNumberTable:~%") (format s "~a~%" (funcall (car to-string-fns) (code-attribute-attributes self) constant-pool (cdr to-string-fns))))) (declaim (inline read-exception-table-entry)) (defun read-exception-table-entry (stream) (make-exception-table-entry :from (read-u2 stream) :to (read-u2 stream) :target (read-u2 stream) :type (read-u2 stream))) (declaim (inline read-exception-table)) (defun read-exception-table (stream count) (read-array stream count #'read-exception-table-entry)) (defun read-line-number-table (stream count) (let ((tbl (make-array count))) (dotimes (i count) (setf (aref tbl i) (cons (read-u2 stream) (read-u2 stream)))) tbl)) (declaim (inline read-local-variable-table-enrty)) (defun read-local-variable-table-enrty (stream) (make-local-variable :start-pc (read-u2 stream) :length (read-u2 stream) :name-index (read-u2 stream) :descriptor-index (read-u2 stream) :index (read-u2 stream))) (declaim (inline read-local-variable-table)) (defun read-local-variable-table (stream count) (read-array stream count #'read-local-variable-table-enrty)) (defun read-verification-type-info (stream tag) (case tag ((0) 'top) ((1) 'integer) ((2) 'float) ((3) 'double) ((4) 'long) ((5) 'null) ((6) 'uninitialized-this) ((7) (cons 'object (read-u2 stream))) ((8) (cons 'uninitialized (read-u2 stream))) (t (error "Invalid verification type info tag: ~a~%" tag)))) (declaim (inline verification-type-info-tag)) (defun verification-type-info-tag (self) (if (consp self) (car self) self)) (declaim (inline verification-type-info-data)) (defun verification-type-info-data (self) (if (consp self) (cdr self) nil)) (declaim (inline read-verification-type-info)) (defun read-verification-type-infos (stream count) (read-array stream count #'(lambda (stream) (read-verification-type-info stream (read-byte stream))))) (defun read-full-frame (stream) (cons (read-u2 stream) (cons (read-verification-type-infos stream (read-u2 stream)) (read-verification-type-infos stream (read-u2 stream))))) (defun read-stack-map-frame (stream tag) (cond ((and (>= tag 0) (<= tag 63)) (cons 'same nil)) ((and (>= tag 64) (<= tag 127)) (cons 'same-locals-1-stack-item (read-verification-type-infos stream 1))) ((= tag 247) (cons 'same-locals-1-stack-item-extended (cons (read-u2 stream) (read-verification-type-infos stream 1)))) ((and (>= tag 248) (<= tag 250)) (cons 'chop (read-u2 stream))) ((= tag 251) (cons 'same-extended (read-u2 stream))) ((and (>= tag 252) (<= tag 254)) (cons 'append (cons (read-u2 stream) (read-verification-type-infos stream 1)))) ((= tag 255) (cons 'full (read-full-frame stream))) (t (error "Invalid stack-map-frame tag: ~a~%" tag)))) (declaim (inline stack-map-frame-tag)) (defun stack-map-frame-tag (self) (car self)) (defun stack-map-frame-offset-delta (self) (if (consp (cdr self)) (cadr self) -1)) (defun stack-map-frame-data (self) (if (consp (cdr self)) (cddr self) (cdr self))) (declaim (inline full-frame-locals)) (defun full-frame-locals (self) (car (stack-map-frame-data self))) (declaim (inline full-frame-items)) (defun full-frame-items (self) (cdr (stack-map-frame-data self))) (declaim (inline read-stack-map-table)) (defun read-stack-map-table (stream count) (read-array stream count #'(lambda (stream) (read-stack-map-frame stream (read-byte stream))))) (defun read-attribute-info (stream user-data) (let* ((constant-pool (car user-data)) (read-code-attr-fn (cdr user-data)) (name-index (read-u2 stream)) (attr-len (read-u4 stream)) (attr-name (constant-pool-string-at constant-pool name-index))) (cond ((string= attr-name "Code") (cons 'code (funcall read-code-attr-fn stream constant-pool))) ((string= attr-name "LineNumberTable") (cons 'line-number-table (read-line-number-table stream (read-u2 stream)))) ((string= attr-name "LocalVariableTable") (cons 'local-variable-table (read-local-variable-table stream (read-u2 stream)))) ((string= attr-name "LocalVariableTypeTable") (cons 'local-variable-type-table (read-local-variable-table stream (read-u2 stream)))) ((string= attr-name "StackMapTable") (cons 'stack-map-table (read-stack-map-table stream (read-u2 stream)))) (t (cons name-index (read-info stream attr-len)))))) (declaim (inline read-attribute-infos)) (defun read-attribute-infos (stream count constant-pool read-code-attr-fn) (read-array-with-user-data stream count (cons constant-pool read-code-attr-fn) #'read-attribute-info)) (defun read-code-attribute (stream constant-pool) (make-code-attribute :max-stack (read-u2 stream) :max-locals (read-u2 stream) :code (bytes-to-opcode (read-code stream (read-u4 stream))) :exception-table (read-exception-table stream (read-u2 stream)) :attributes (read-attribute-infos stream (read-u2 stream) constant-pool #'read-code-attribute))) (defun line-number-table-to-string (self) (with-output-to-string (s) (dotimes (i (length self)) (let ((a (aref self i))) (format s " line ~a: ~a~%" (cdr a) (car a)))))) (defun verification-type-info-to-string (self constant-pool) (with-output-to-string (s) (let ((tag (verification-type-info-tag self))) (format s "~a " tag) (case tag ((object) (format s "~a " (constant-pool-string-at constant-pool (verification-type-info-data self)))) ((uninitialized) (format s "~a " (verification-type-info-data self))))))) (defun verification-type-infos-to-string (self constant-pool) (format t "~a~%" self) (with-output-to-string (s) (dotimes (i (length self)) (format s "~a" (verification-type-info-to-string (aref self i) constant-pool))))) (defun stack-map-frame-to-string (self constant-pool) (with-output-to-string (s) (let ((tag (stack-map-frame-tag self))) (format s " frame_type = ~a~%" tag) (case tag ((chop same-extended) (format s " offset_delta = ~a~%" (stack-map-frame-offset-delta self))) ((same-locals-1-stack-item) (format s " stack = ~a~%" (verification-type-infos-to-string (stack-map-frame-data self) constant-pool))) ((same-locals-1-stack-item-extended) (format s " offset_delta = ~a~% stack = [~a]~%" (stack-map-frame-offset-delta self) (verification-type-infos-to-string (stack-map-frame-data self) constant-pool))) ((append) (format s " offset_delta = ~a~% locals = [~a]~%" (stack-map-frame-offset-delta self) (verification-type-infos-to-string (stack-map-frame-data self) constant-pool))) ((full) (format s " offset_delta = ~a~% stack = [~a]~% locals = [~a]~%" (stack-map-frame-offset-delta self) (verification-type-infos-to-string (full-frame-items self) constant-pool) (verification-type-infos-to-string (full-frame-locals self) constant-pool))) (t (error "Invalid stack-map-frame-tag: ~a~%" tag)))))) (defun stack-map-table-to-string (self constant-pool) (with-output-to-string (s) (format s " StackMapTable: number_of_entries = ~a~%" (length self)) (dotimes (i (length self)) (let ((frame (aref self i))) (format s " ~a~%" (stack-map-frame-to-string frame constant-pool)))))) (defmacro attribute-info-tag (self) `(car ,self)) (defmacro attribute-info-info (self) `(cdr ,self)) (defmacro is-code-attribute (self) `(eq 'code (attribute-info-tag ,self))) (defun attribute-info-length (self) (length (attribute-info-info self))) (defun attribute-infos-to-string (self constant-pool ainfo-to-string-fn) (with-output-to-string (s) (map 'nil #'(lambda (ainfo) (format s "~%~a" (funcall ainfo-to-string-fn ainfo constant-pool))) self))) (defun attribute-info-to-string (self constant-pool) (let ((info (attribute-info-info self))) (case (attribute-info-tag self) ((code) (code-attribute-to-string info constant-pool (cons #'attribute-infos-to-string #'attribute-info-to-string))) ((line-number-table) (line-number-table-to-string info)) ((stack-map-table) (stack-map-table-to-string info constant-pool)) (t info))))
11,886
Common Lisp
.lisp
280
36.217857
97
0.637575
easye/yuka
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
b7b2b24a0bdb42078225c46e41ca2bbd2c3c0a1fad7f0ee03063f837e0eb903e
21,453
[ -1 ]
21,454
constant-pool.lisp
easye_yuka/src/constant-pool.lisp
;;;; Copyright (c) 2012 Vijay Mathew Pandyalakal <[email protected]> ;;;; This file is part of yuka. ;;;; yuka 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. ;;;; yuka 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 <http://www.gnu.org/licenses/>. (in-package :yuka) ;;; Representation of the constant pool. (defconstant +nan+ 'nan) (defconstant +positive-infinity+ 'infinity) (defconstant +negative-infinity+ '-infinity) (defmacro cp-info-tag (self) `(car ,self)) (defun read-klass-info (stream tag) (cons tag (read-u2 stream))) (defmacro klass-info-tag (self) `(car ,self)) (defmacro klass-info-name-index (self) `(cdr ,self)) (defun read-xxxref-info (stream tag) (cons tag (cons (read-u2 stream) (read-u2 stream)))) (defmacro xxxref-info-tag (self) `(car ,self)) (defmacro xxxref-info-klass-index (self) `(cadr ,self)) (defmacro xxxref-info-name-type-index (self) `(cddr ,self)) (defun read-string-info (stream tag) (cons tag (read-u2 stream))) (defmacro string-info-tag (self) `(car ,self)) (defmacro string-info-string-index (self) `(cdr ,self)) (defun read-integer-info (stream tag) (cons tag (read-u4 stream))) (defmacro integer-info-tag (self) `(car ,self)) (defmacro integer-info-bytes (self) `(cdr ,self)) (defun read-float-info (stream tag) (cons tag (read-u4 stream))) (defmacro float-info-tag (self) `(car ,self)) (defmacro float-info-bytes (self) `(cdr ,self)) (defun bits-to-float-value (bits) (let ((s (if (= 0 (ash bits -31)) 1 -1)) (e (logand (ash bits -23) #xff)) (m 0)) (if (= e 0) (setf m (ash (logand bits #x7fffff) 1)) (setf m (logior (logand bits #x7fffff) #x800000))) (* s m (expt 2 (- e 150))))) (defun float-info-value (self) (let ((bits (float-info-bytes self))) (cond ((= bits #x7f800000) +positive-infinity+) ((= bits #xff800000) +negative-infinity+) ((or (and (>= bits #x7f800001) (<= bits #x7fffffff)) (and (>= bits #xff800001) (<= bits #xffffffff))) +nan+) (t (bits-to-float-value bits))))) (defun read-long-info (stream tag) (cons tag (cons (read-u4 stream) (read-u4 stream)))) (defmacro long-info-tag (self) `(car ,self)) (defmacro long-info-high-bytes (self) `(cadr ,self)) (defmacro long-info-low-bytes (self) `(cddr ,self)) (defmacro long-info-value (hi low) `(+ (ash ,hi 32) ,low)) (defun read-double-info (stream tag) (cons tag (cons (read-u4 stream) (read-u4 stream)))) (defmacro double-info-tag (self) `(car ,self)) (defmacro double-info-high-bytes (self) `(cadr ,self)) (defmacro double-info-low-bytes (self) `(cddr ,self)) (defun bits-to-double-value (bits) (let ((s (if (= (ash bits -63) 0) 1 -1)) (e (logand (ash bits -52) #x7ff)) (m 0)) (if (= e 0) (setf m (ash (logand bits #xfffffffffffff) 1)) (setf m (logior (logand bits #xfffffffffffff) #x10000000000000))) (coerce (* s m (expt 2 (- e 1075))) 'double-float))) (defun double-info-value (self) (let ((bits (long-info-value (double-info-high-bytes self) (double-info-low-bytes self)))) (cond ((= bits #x7ff0000000000000) +positive-infinity+) ((= bits #xfff0000000000000) +negative-infinity+) ((or (and (>= bits #x7ff0000000000001) (<= bits #x7fffffffffffffff)) (and (>= bits #xfff0000000000001) (<= bits #xffffffffffffffff))) +nan+) (t (bits-to-double-value bits))))) (defun read-name-and-type-info (stream tag) (cons tag (cons (read-u2 stream) (read-u2 stream)))) (defmacro name-and-type-info-tag (self) `(car ,self)) (defmacro name-and-type-info-name-index (self) `(cadr ,self)) (defmacro name-and-type-info-descriptor-index (self) `(cddr ,self)) (defun read-utf8-str (stream len) (let ((utf8-str (make-array len :element-type '(unsigned-byte 8)))) (dotimes (i len) (setf (aref utf8-str i) (read-byte stream))) (trivial-utf-8:utf-8-bytes-to-string utf8-str))) (defun read-utf8-info (stream tag) (let ((len (read-u2 stream))) (cons tag (cons len (read-utf8-str stream len))))) (defmacro utf8-info-tag (self) `(car ,self)) (defmacro utf8-info-length (self) `(cadr ,self)) (defmacro utf8-info-str (self) `(cddr ,self)) (defun read-method-handle-info (stream tag) (cons tag (cons (read-byte stream) (read-u2 stream)))) (defmacro method-handle-info-tag (self) `(car ,self)) (defmacro method-handle-info-reference-kind (self) `(cadr ,self)) (defmacro method-handle-info-reference-index (self) `(cddr ,self)) (defun read-method-type-info (stream tag) (cons tag (read-u2 stream))) (defmacro method-type-info-tag (self) `(car ,self)) (defmacro method-type-info-descriptor-index (self) `(cdr ,self)) (defun read-invoke-dynamic-info (stream tag) (cons tag (cons (read-u2 stream) (read-u2 stream)))) (defmacro invoke-dynamic-info-tag (self) `(car ,self)) (defmacro invoke-dynamic-info-bootstrap-method-attr-index (self) `(cadr ,self)) (defmacro invoke-dynamic-info-name-and-type-index (self) `(cddr ,self)) (defun klass-info-to-string (self) (with-output-to-string (s) (format s "~20a#~a" "Class" (klass-info-name-index self)))) (defun fieldref-info-to-string (self) (with-output-to-string (s) (format s "~20a#~a.#~a" "Fieldref" (xxxref-info-klass-index self) (xxxref-info-name-type-index self)))) (defun methodref-info-to-string (self) (with-output-to-string (s) (format s "~20a#~a.#~a" "Methodref" (xxxref-info-klass-index self) (xxxref-info-name-type-index self)))) (defun interface-methodref-info-to-string (self) (with-output-to-string (s) (format s "~a (~a)" 'interface-method self))) (defun string-info-to-string (self) (with-output-to-string (s) (format s "~20a#~a" "String" (string-info-string-index self)))) (defun integer-info-to-string (self) (with-output-to-string (s) (format s "~20a~a" "Integer" (integer-info-bytes self)))) (defun float-info-to-string (self) (with-output-to-string (s) (format s "~20a~ff" "Float" (float-info-value self)))) (defun long-info-to-string (self) (with-output-to-string (s) (format s "~20a~a" "Long" (long-info-value (long-info-high-bytes self) (long-info-low-bytes self))))) (defun double-info-to-string (self) (with-output-to-string (s) (format s "~20a~a" "Double" (double-info-value self)))) (defun name-and-type-info-to-string (self) (with-output-to-string (s) (format s "~20a#~a:#~a" "NameAndType" (name-and-type-info-name-index self) (name-and-type-info-descriptor-index self)))) (defun utf8-info-to-string (self) (with-output-to-string (s) (format s "~20a~a" "Utf8" (utf8-info-str self)))) (defun method-handle-info-to-string (self) (with-output-to-string (s) (format s "~a (~a)" 'method-handle self))) (defun method-type-info-to-string (self) (with-output-to-string (s) (format s "~a (~a)" 'method-type self))) (defun invoke-dynamic-info-to-string (self) (with-output-to-string (s) (format s "~a (~a)" 'invoke-dynamic self))) (defconstant +klass-info+ 7) (defconstant +fieldref-info+ 9) (defconstant +methodref-info+ 10) (defconstant +interface-methodref-info+ 11) (defconstant +string-info+ 8) (defconstant +integer-info+ 3) (defconstant +float-info+ 4) (defconstant +long-info+ 5) (defconstant +double-info+ 6) (defconstant +name-and-type-info+ 12) (defconstant +utf8-info+ 1) (defconstant +method-handle-info+ 15) (defconstant +method-type-info+ 16) (defconstant +invoke-dynamic-info+ 18) (defparameter *cp-info-fns* (list (cons +klass-info+ (cons #'read-klass-info #'klass-info-to-string)) (cons +fieldref-info+ (cons #'read-xxxref-info #'fieldref-info-to-string)) (cons +methodref-info+ (cons #'read-xxxref-info #'methodref-info-to-string)) (cons +interface-methodref-info+ (cons #'read-xxxref-info #'interface-methodref-info-to-string)) (cons +string-info+ (cons #'read-string-info #'string-info-to-string)) (cons +integer-info+ (cons #'read-integer-info #'integer-info-to-string)) (cons +float-info+ (cons #'read-float-info #'float-info-to-string)) (cons +long-info+ (cons #'read-long-info #'long-info-to-string)) (cons +double-info+ (cons #'read-double-info #'double-info-to-string)) (cons +name-and-type-info+ (cons #'read-name-and-type-info #'name-and-type-info-to-string)) (cons +utf8-info+ (cons #'read-utf8-info #'utf8-info-to-string)) (cons +method-handle-info+ (cons #'read-method-handle-info #'method-handle-info-to-string)) (cons +method-type-info+ (cons #'read-method-type-info #'method-type-info-to-string)) (cons +invoke-dynamic-info+ (cons #'read-invoke-dynamic-info #'invoke-dynamic-info-to-string)))) (defun get-cp-info-fn (tag fn-picker) (let ((fn (assoc tag *cp-info-fns*))) (when (null fn) (error "Invalid constant pool tag: ~a~%" tag)) (funcall fn-picker fn))) (defun read-cp-info (stream tag) (funcall (get-cp-info-fn tag #'cadr) stream tag)) (defun read-constant-pool (stream count) (if (> count 0) (let ((cp (make-array count))) (dotimes (i count) (let ((tag (read-byte stream))) (setf (aref cp i) (read-cp-info stream tag)) (when (or (eq tag +long-info+) (eq tag +double-info+)) (setf i (1+ i))))) cp) (make-array 0))) (defun cp-info-to-string (self) (funcall (get-cp-info-fn (cp-info-tag self) #'cddr) self)) (defun constant-pool-to-string (self) (with-output-to-string (s) (dotimes (i (length self)) (let ((cp-info (aref self i))) (when (consp cp-info) (format s " #~2a = ~a~%" (1+ i) (cp-info-to-string cp-info))))))) (defun constant-pool-string-at (self index) (let* ((cp-info (aref self (1- index))) (tag (cp-info-tag cp-info))) (cond ((= +utf8-info+ tag) (utf8-info-str cp-info)) ((= +klass-info+ tag) (constant-pool-string-at self (klass-info-name-index cp-info))) ((= +methodref-info+ tag) (constant-pool-string-at self (xxxref-info-name-type-index cp-info))) ((= +name-and-type-info+ tag) (constant-pool-string-at self (name-and-type-info-name-index cp-info))) (t (error "(constant-pool-string-at ~a ~a) failed for for ~a." self index tag)))))
10,740
Common Lisp
.lisp
266
36.721805
97
0.668687
easye/yuka
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
47ec761892ba3981ebc8a38591a733efccb8d83454d9ecf6b4f909fd548a3e3a
21,454
[ -1 ]
21,455
vm-util.lisp
easye_yuka/src/vm-util.lisp
;;;; Copyright (c) 2012 Vijay Mathew Pandyalakal <[email protected]> ;;;; This file is part of yuka. ;;;; yuka 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. ;;;; yuka 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 <http://www.gnu.org/licenses/>. (in-package :yuka) ;;; Helper definitions used by the virtual machine run-time. (defun is-reference (obj) (format t "(is-reference ~a) not implemented!~%" obj) nil) (defun is-return-address (obj) (if (consp obj) (eq 'returnAddress (car obj)) nil)) (defun resolve-field (objectref field-name) (format t "resolve-field: ~a in ~a not implemented!~%" objectref field-name) nil) (defun resolve-static-field (objectref field-name) (format t "resolve-static-field: ~a in ~a not implemented!~%" objectref field-name) nil) (defmacro vm-panic (msg args) `(error "Fatal Error: ~a [~a]~%" ,msg ,args)) (defun is-instance-of (klass-name objectref) (format t "(is-instance-of ~a ~a) not implemented!~%" klass-name objectref) nil) (defun invoke-dynamic (call-site-spec operand-stack) (format t "(invoke-dynamic ~a ~a) not implemented!~%" call-site-spec operand-stack)) (defun invoke-interface (method-spec operand-stack count) (format t "(invoke-interface ~a ~a ~a) not implemented!~%" method-spec operand-stack count)) (defun invoke-special (method-spec operand-stack) (format t "(invoke-special ~a ~a) not implemented!~%" method-spec operand-stack)) (defun invoke-static (method-spec operand-stack) (format t "(invoke-static ~a ~a) not implemented!~%" method-spec operand-stack)) (defun invoke-virtual (method-spec operand-stack) (format t "(invoke-virtual ~a ~a) not implemented!~%" method-spec operand-stack)) (declaim (inline make-return-address)) (defun make-return-address (address) (cons 'returnAddress address)) (defmacro return-address-value (self) `(cdr ,self))
2,403
Common Lisp
.lisp
55
41.036364
77
0.724345
easye/yuka
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
84f501a168d5e0b25e75f1030cf6e95c3c50cb3b0c6a35af437e38a159de529e
21,455
[ -1 ]
21,456
frame.lisp
easye_yuka/src/frame.lisp
;;;; Copyright (c) 2012 Vijay Mathew Pandyalakal <[email protected]> ;;;; This file is part of yuka. ;;;; yuka 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. ;;;; yuka 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 <http://www.gnu.org/licenses/>. (in-package :yuka) ;;; The data structure and related functions required for ;;; executing the bytecode of a method. (defstruct frame (code nil) (klass nil) (locals nil :type simple-array) (operand-stack nil) (has-unhandled-exception nil) (return-value nil)) (defun make-frame-from-code (code klass) (make-frame :code code :klass klass :locals (make-array (code-attribute-max-locals code)) :operand-stack (make-stack (code-attribute-max-stack code)))) (defun frame-run (self) (let* ((pc 0) (new-pc nil) (code (frame-code self)) (bcode (code-attribute-code code)) (len (length bcode)) (cp (klass-constant-pool (frame-klass self))) (locals (frame-locals self)) (operand-stack (frame-operand-stack self)) (return-from-frame nil)) (format t "~a~%" code) (loop (when (or (>= pc len) return-from-frame) (return)) (let ((opc (aref bcode pc))) (case (opcode-symbol opc) ((aaload) (aaload operand-stack)) ((aastore) (aastore operand-stack)) ((aconst_null) (stack-push operand-stack nil)) ((aload) (aload locals operand-stack (opcode-operands opc))) ((aload_0) (aload locals operand-stack 0)) ((aload_1) (aload locals operand-stack 1)) ((aload_2) (aload locals operand-stack 2)) ((aload_3) (aload locals operand-stack 3)) ((anewarray) (anewarray operand-stack cp (opcode-operands opc))) ((areturn) (monitorexit operand-stack) (setf return-from-frame t)) ((arraylength) (arraylength operand-stack)) ((astore) (astore locals operand-stack (opcode-operands opc))) ((astore_0) (astore locals operand-stack 0)) ((astore_1) (astore locals operand-stack 1)) ((astore_2) (astore locals operand-stack 2)) ((astore_3) (astore locals operand-stack 3)) ((athrow) (setf new-pc (athrow operand-stack (code-attribute-exception-table code) cp)) (when (< new-pc 0) (monitorexit operand-stack) (setf (frame-has-unhandled-exception self) t) (setf return-from-frame t))) ((baload) (baload operand-stack)) ((bastore) (bastore operand-stack)) ((bipush) (stack-push operand-stack (opcode-operands opc))) ((caload) (caload operand-stack)) ((castore) (castore operand-stack)) ((checkcast) (checkcast operand-stack (opcode-operands opc) cp)) ((d2f) (d2f operand-stack)) ((d2i) (d2i operand-stack)) ((d2l) (d2l operand-stack)) ((dadd) (dadd operand-stack)) ((daload) (daload operand-stack)) ((dastore) (dastore operand-stack)) ((dcmpg) (dcmp operand-stack nil)) ((dcmpl) (dcmp operand-stack t)) ((dconst_0) (stack-push operand-stack +float-zero+)) ((dconst_1) (stack-push operand-stack +float-one+)) ((ddiv) (ddiv operand-stack)) ((dload fload iload lload) (loadv locals operand-stack (opcode-operands opc))) ((dload_0 fload_0 iload_0 lload_0) (loadv locals operand-stack 0)) ((dload_1 fload_1 iload_1 lload_1) (loadv locals operand-stack 1)) ((dload_2 fload_2 iload_2 lload_2) (loadv locals operand-stack 2)) ((dload_3 fload_3 iload_3 lload_3) (loadv locals operand-stack 3)) ((dmul) (dmul operand-stack)) ((dneg) (dneg operand-stack)) ((drem) (drem operand-stack)) ((dreturn freturn ireturn lreturn) (monitorexit operand-stack) (setf (frame-return-value self) (stack-pop operand-stack)) (setf return-from-frame t)) ((dstore fstore istore lstore) (storev locals operand-stack (opcode-operands opc))) ((dstore_0 fstore_0 istore_0 lstore_0) (storev locals operand-stack 0)) ((dstore_1 fstore_1 istore_1 lstore_1) (storev locals operand-stack 1)) ((dstore_2 fstore_2 istore_2 lstore_2) (storev locals operand-stack 2)) ((dstore_3 fstore_3 istore_3 lstore_3) (storev locals operand-stack 3)) ((dsub) (dsub operand-stack)) ((dup) (stack-dup operand-stack)) ((dup_x1) (stack-dup-x1 operand-stack)) ((dup_x2) (stack-dup-x2 operand-stack)) ((dup2) (stack-dup2 operand-stack)) ((dup2_x1) (stack-dup2-x1 operand-stack)) ((dup2_x2) (stack-dup2-x2 operand-stack)) ((f2i) (f2i operand-stack)) ((f2l) (f2l operand-stack)) ((fadd) (fadd operand-stack)) ((faload) (faload operand-stack)) ((fastore) (fastore operand-stack)) ((fcmpg) (dcmp operand-stack nil)) ((fcmpl) (dcmp operand-stack t)) ((fconst_0) (stack-push operand-stack +float-zero+)) ((fconst_1) (stack-push operand-stack +float-one+)) ((fconst_2) (stack-push operand-stack +float-two+)) ((fdiv) (fdiv operand-stack)) ((fmul) (fmul operand-stack)) ((fneg) (fneg operand-stack)) ((frem) (frem operand-stack)) ((fsub) (fsub operand-stack)) ((getfield) (getfield operand-stack cp (opcode-operands opc))) ((getstatic) (getstatic operand-stack cp (opcode-operands opc))) ((goto goto_w) (setf new-pc (goto bcode len (opcode-operands opc)))) ((i2b) (type-cast operand-stack #'make-byte)) ((i2c) (type-cast operand-stack #'make-char)) ((i2d) (type-cast operand-stack #'integer-to-double)) ((i2f) (type-cast operand-stack #'integer-to-float)) ((i2l) (type-cast operand-stack #'make-long)) ((i2s) (type-cast operand-stack #'make-short)) ((iadd) (iadd operand-stack)) ((iaload) (iaload operand-stack)) ((iand) (iand operand-stack)) ((iastore) (iastore operand-stack)) ((iconst_m1) (stack-push operand-stack -1)) ((iconst_0) (stack-push operand-stack 0)) ((iconst_1) (stack-push operand-stack 1)) ((iconst_2) (stack-push operand-stack 2)) ((iconst_3) (stack-push operand-stack 3)) ((iconst_4) (stack-push operand-stack 4)) ((iconst_5) (stack-push operand-stack 5)) ((idiv) (idiv operand-stack)) ((if_acmpeq) (setf new-pc (if-cmp operand-stack #'eq (opcode-operands opc)))) ((if_acmpne) (setf new-pc (if-cmp operand-stack #'neq (opcode-operands opc)))) ((if_icmpeq) (setf new-pc (if-cmp operand-stack #'= (opcode-operands opc)))) ((if_icmpne) (setf new-pc (if-cmp operand-stack #'n= (opcode-operands opc)))) ((if_icmplt) (setf new-pc (if-cmp operand-stack #'< (opcode-operands opc)))) ((if_icmpge) (setf new-pc (if-cmp operand-stack #'>= (opcode-operands opc)))) ((if_icmpgt) (setf new-pc (if-cmp operand-stack #'> (opcode-operands opc)))) ((if_icmple) (setf new-pc (if-cmp operand-stack #'<= (opcode-operands opc)))) ((ifeq) (setf new-pc (if-cmp-with operand-stack 0 #'= (opcode-operands opc)))) ((ifne) (setf new-pc (if-cmp-with operand-stack 0 #'n= (opcode-operands opc)))) ((iflt) (setf new-pc (if-cmp-with operand-stack 0 #'< (opcode-operands opc)))) ((ifge) (setf new-pc (if-cmp-with operand-stack 0 #'>= (opcode-operands opc)))) ((ifgt) (setf new-pc (if-cmp-with operand-stack 0 #'> (opcode-operands opc)))) ((ifle) (setf new-pc (if-cmp-with operand-stack 0 #'<= (opcode-operands opc)))) ((ifnonnull) (setf new-pc (if-cmp-with operand-stack nil #'neq (opcode-operands opc)))) ((ifnull) (setf new-pc (if-cmp-with operand-stack nil #'eq (opcode-operands opc)))) ((iinc) (let ((operands (opcode-operands opc))) (iinc locals (car operands) (cdr operands)))) ((imul) (imul operand-stack)) ((ineg) (ineg operand-stack)) ((instanceof) (instanceof operand-stack cp (opcode-operands opc))) ((invokedynamic) (invokedynamic operand-stack cp (car (opcode-operands opc)))) ((invokeinterface) (invokeinterface operand-stack cp (car (opcode-operands opc)) (cadr (opcode-operands opc)))) ((invokespecial) (invokespecial operand-stack cp (opcode-operands opc))) ((invokestatic) (invokestatic operand-stack cp (opcode-operands opc))) ((ior) (ior operand-stack)) ((irem) (irem operand-stack)) ((ishl) (ishl operand-stack)) ((ishr) (ishr operand-stack)) ((isub) (isub operand-stack)) ((iushr) (iushr operand-stack)) ((ixor) (ixor operand-stack)) ((jsr jsr_w) (setf new-pc (jsr operand-stack bcode len (opcode-operands opc) (aref bcode (1+ pc))))) ((l2d) (type-cast operand-stack #'long-to-double)) ((l2f) (type-cast operand-stack #'long-to-float)) ((l2i) (type-cast operand-stack #'long-to-integer)) ((ladd) (ladd operand-stack)) ((laload) (laload operand-stack)) ((land) (land operand-stack)) ((lastore) (lastore operand-stack)) ((lcmp) (lcmp operand-stack)) ((lconst_0) (stack-push operand-stack 0)) ((lconst_1) (stack-push operand-stack 1)) ((ldc ldc_w) (ldc operand-stack cp (opcode-operands opc))) ((ldc2_w) (ldc2 operand-stack cp (opcode-operands opc))) ((ldiv) (ldiv operand-stack)) ((lmul) (lmul operand-stack)) ((lneg) (lneg operand-stack)) ((lookupswitch) (setf new-pc (lookupswitch (stack-pop operand-stack) bcode len (opcode-offset opc) (opcode-operands opc)))) ((lor) (lor operand-stack)) ((lrem) (lrem operand-stack)) ((lshl) (lshl operand-stack)) ((lshr) (lshr operand-stack)) ((lsub) (lsub operand-stack)) ((lushr) (lushr operand-stack)) ((lxor) (lxor operand-stack)) ((monitorenter) (monitorenter operand-stack)) ((monitorexit) (monitorexit operand-stack)) ((multianewarray) (let ((operands (opcode-operands opc))) (multianewarray operand-stack (cdr operands) cp (car operands)))) ((new) (new operand-stack)) ((newarray) (newarray operand-stack (opcode-operands opc))) ((nop) nil) ((pop) (stack-pop operand-stack)) ((pop2) (pop2 operand-stack)) ((putfield) (putfield operand-stack cp (opcode-operands opc))) ((putstatic) (putstatic operand-stack cp (opcode-operands opc))) ((ret) (setf new-pc (ret locals (opcode-operands opc)))) ((return) (monitorexit operand-stack) (setf return-from-frame t)) ((saload) (saload operand-stack)) ((sastore) (sastore operand-stack)) ((sipush) (stack-push operand-stack (opcode-operands opc))) ((swap) (stack-swap operand-stack)) ((tableswitch) (tableswitch (stack-pop operand-stack) (opcode-operands opc) bcode len (opcode-offset opc))) ((wide) (error "wide instruction is not implemented!~%"))) (cond (new-pc (setf pc new-pc) (setf new-pc nil)) (t (setf pc (1+ pc))))))) self)
12,449
Common Lisp
.lisp
394
24.545685
79
0.588826
easye/yuka
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
fe879415dfb146566409fa4f841e33fcc686e20cddc036f0d029aab8011d3243
21,456
[ -1 ]
21,457
vm.lisp
easye_yuka/src/vm.lisp
;;;; Copyright (c) 2012 Vijay Mathew Pandyalakal <[email protected]> ;;;; This file is part of yuka. ;;;; yuka 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. ;;;; yuka 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 <http://www.gnu.org/licenses/>. (load "packages.lisp") (in-package :yuka) ;;; Main entry point. ;; Required by the class-loader. (load "trivial-utf-8.lisp") (load "util.lisp") (load "opc.lisp") (load "access-flags.lisp") (load "constant-pool.lisp") (load "attribute-info.lisp") (load "field-method-info.lisp") (load "klass.lisp") (load "klass-loader.lisp") ;; Required by the virtual machine. (load "vm-util.lisp") (load "numeric.lisp") (load "bounded-stack.lisp") (load "opc-impl.lisp") (load "frame.lisp") (defun execute-method (method klass) (frame-run (make-frame-from-code (method-code-attribute method) klass))) (defun run-method (klass method-name) (let ((method (klass-find-method-by-name klass method-name))) (when (null method) (error "Error: Method `~a` not found in class ~a.~%" method-name (klass-name klass))) (execute-method method klass))) (defun run-main (klass) (run-method klass "main"))
1,704
Common Lisp
.lisp
42
37.809524
77
0.706667
easye/yuka
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
d5187df48a38f3a82588567cead7f28657657c72a18bf2dc499e8ffc2a0d7cc8
21,457
[ -1 ]
21,458
trivial-utf-8.lisp
easye_yuka/src/trivial-utf-8.lisp
;;; Minimal utf-8 decoding and encoding library. ;;; ;;; See http://common-lisp.net/project/trivial-utf-8/ (defpackage :trivial-utf-8 (:use :common-lisp) (:export #:utf-8-byte-length #:string-to-utf-8-bytes #:write-utf-8-bytes #:utf-8-group-size #:utf-8-bytes-to-string #:read-utf-8-string #:utf-8-decoding-error)) (in-package :trivial-utf-8) (eval-when (:compile-toplevel :load-toplevel :execute) (defparameter *optimize* '(optimize (speed 3) (safety 0) (space 0) (debug 1) (compilation-speed 0)))) (defun utf-8-byte-length (string) "Calculate the amount of bytes needed to encode a string." (declare (type string string) #'*optimize*) (let ((length (length string)) (string (coerce string 'simple-string))) (loop :for char :across string :do (let ((code (char-code char))) (when (> code 127) (incf length (cond ((< code 2048) 1) ((< code 65536) 2) (t 3)))))) length)) (defmacro as-utf-8-bytes (char writer) "Given a character, calls the writer function for every byte in the encoded form of that character." (let ((char-code (gensym))) `(let ((,char-code (char-code ,char))) (declare (type fixnum ,char-code)) (cond ((< ,char-code 128) (,writer ,char-code)) ((< ,char-code 2048) (,writer (logior #b11000000 (ldb (byte 5 6) ,char-code))) (,writer (logior #b10000000 (ldb (byte 6 0) ,char-code)))) ((< ,char-code 65536) (,writer (logior #b11100000 (ldb (byte 4 12) ,char-code))) (,writer (logior #b10000000 (ldb (byte 6 6) ,char-code))) (,writer (logior #b10000000 (ldb (byte 6 0) ,char-code)))) (t (,writer (logior #b11110000 (ldb (byte 3 18) ,char-code))) (,writer (logior #b10000000 (ldb (byte 6 12) ,char-code))) (,writer (logior #b10000000 (ldb (byte 6 6) ,char-code))) (,writer (logior #b10000000 (ldb (byte 6 0) ,char-code)))))))) (defun string-to-utf-8-bytes (string &key null-terminate) "Convert a string into an array of unsigned bytes containing its utf-8 representation." (declare (type string string) #.*optimize*) (let ((buffer (make-array (+ (the fixnum (utf-8-byte-length string)) (if null-terminate 1 0)) :element-type '(unsigned-byte 8))) (position 0) (string (coerce string 'simple-string))) (declare (type (array (unsigned-byte 8)) buffer) (type fixnum position)) (macrolet ((add-byte (byte) `(progn (setf (aref buffer position) ,byte) (incf position)))) (loop :for char :across string :do (as-utf-8-bytes char add-byte))) (when null-terminate (setf (elt buffer (1- (length buffer))) 0)) buffer)) (defun write-utf-8-bytes (string output &key null-terminate) "Write a string to a byte-stream, encoding it as utf-8." (declare (type string string) (type stream output) #.*optimize*) (macrolet ((byte-out (byte) `(write-byte ,byte output))) (let ((string (coerce string 'simple-string))) (loop :for char :across string :do (as-utf-8-bytes char byte-out)))) (when null-terminate (write-byte 0 output))) (define-condition utf-8-decoding-error (simple-error) ((message :initarg :message) (byte :initarg :byte :initform nil)) (:report (lambda (err stream) (format stream (slot-value err 'message) (slot-value err 'byte))))) (declaim (inline utf-8-group-size)) (defun utf-8-group-size (byte) "Determine the amount of bytes that are part of the character starting with a given byte." (declare (type fixnum byte) #.*optimize*) (cond ((zerop (logand byte #b10000000)) 1) ((= (logand byte #b11100000) #b11000000) 2) ((= (logand byte #b11110000) #b11100000) 3) ((= (logand byte #b11111000) #b11110000) 4) (t (error 'utf-8-decoding-error :byte byte :message "Invalid byte at start of character: 0x~X")))) (defun utf-8-string-length (bytes &key (start 0) (end (length bytes))) "Calculate the length of the string encoded by the given bytes." (declare (type (simple-array (unsigned-byte 8) (*)) bytes) (type fixnum start end) #.*optimize*) (loop :with i :of-type fixnum = start :with string-length = 0 :while (< i end) :do (progn (incf (the fixnum string-length) 1) (incf i (utf-8-group-size (elt bytes i)))) :finally (return string-length))) (defun get-utf-8-character (bytes group-size &optional (start 0)) "Given an array of bytes and the amount of bytes to use, extract the character starting at the given start position." (declare (type (simple-array (unsigned-byte 8) (*)) bytes) (type fixnum group-size start) #.*optimize*) (labels ((next-byte () (prog1 (elt bytes start) (incf start))) (six-bits (byte) (unless (= (logand byte #b11000000) #b10000000) (error 'utf-8-decoding-error :byte byte :message "Invalid byte 0x~X inside a character.")) (ldb (byte 6 0) byte))) (case group-size (1 (next-byte)) (2 (logior (ash (ldb (byte 5 0) (next-byte)) 6) (six-bits (next-byte)))) (3 (logior (ash (ldb (byte 4 0) (next-byte)) 12) (ash (six-bits (next-byte)) 6) (six-bits (next-byte)))) (4 (logior (ash (ldb (byte 3 0) (next-byte)) 18) (ash (six-bits (next-byte)) 12) (ash (six-bits (next-byte)) 6) (six-bits (next-byte))))))) (defun utf-8-bytes-to-string (bytes-in &key (start 0) (end (length bytes-in))) "Convert a byte array containing utf-8 encoded characters into the string it encodes." (declare (type vector bytes-in) (type fixnum start end) #.*optimize*) (loop :with bytes = (coerce bytes-in '(simple-array (unsigned-byte 8) (*))) :with buffer = (make-string (utf-8-string-length bytes :start start :end end) :element-type 'character) :with array-position :of-type fixnum = start :with string-position :of-type fixnum = 0 :while (< array-position end) :do (let* ((char (elt bytes array-position)) (current-group (utf-8-group-size char))) (when (> (+ current-group array-position) end) (error 'utf-8-decoding-error :message "Unfinished character at end of byte array.")) (setf (char buffer string-position) (code-char (get-utf-8-character bytes current-group array-position))) (incf string-position 1) (incf array-position current-group)) :finally (return buffer))) (defun read-utf-8-string (input &key null-terminated stop-at-eof (char-length -1) (byte-length -1)) "Read utf-8 encoded data from a byte stream and construct a string with the characters found. When null-terminated is given it will stop reading at a null character, stop-at-eof tells it to stop at the end of file without raising an error, and the char-length and byte-length parameters can be used to specify the max amount of characters or bytes to read." (declare (type stream input) (type fixnum byte-length char-length) #.*optimize*) (let ((buffer (make-array 4 :element-type '(unsigned-byte 8))) (bytes-read 0) (string (make-array 64 :element-type 'character :adjustable t :fill-pointer 0))) (declare (type fixnum bytes-read)) (loop (when (or (and (/= -1 byte-length) (>= bytes-read byte-length)) (and (/= -1 char-length) (= char-length (length string)))) (return)) (let ((next-char (read-byte input (not stop-at-eof) :eof))) (when (or (eq next-char :eof) (and null-terminated (eq next-char 0))) (return)) (let ((current-group (utf-8-group-size next-char))) (incf bytes-read current-group) (cond ((= current-group 1) (vector-push-extend (code-char next-char) string)) (t (setf (elt buffer 0) next-char) (loop :for i :from 1 :below current-group :for next-char = (read-byte input nil :eof) :do (when (eq next-char :eof) (error 'utf-8-decoding-error :message "Unfinished character at end of input.")) :do (setf (elt buffer i) next-char)) (vector-push-extend (code-char (get-utf-8-character buffer current-group)) string)))))) string)) ;;; Copyright (c) Marijn Haverbeke ;;; ;;; This software is provided 'as-is', without any express or implied ;;; warranty. In no event will the authors be held liable for any ;;; damages arising from the use of this software. ;;; ;;; Permission is granted to anyone to use this software for any ;;; purpose, including commercial applications, and to alter it and ;;; redistribute it freely, subject to the following restrictions: ;;; ;;; 1. The origin of this software must not be misrepresented; you must ;;; not claim that you wrote the original software. If you use this ;;; software in a product, an acknowledgment in the product ;;; documentation would be appreciated but is not required. ;;; ;;; 2. Altered source versions must be plainly marked as such, and must ;;; not be misrepresented as being the original software. ;;; ;;; 3. This notice may not be removed or altered from any source ;;; distribution.
9,892
Common Lisp
.lisp
220
36.468182
111
0.60116
easye/yuka
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
c0c676325ea1a47175703146cf1f626c89d106456058b99d7d2a1b29b0b76870
21,458
[ 36936 ]
21,459
klass.lisp
easye_yuka/src/klass.lisp
;;;; Copyright (c) 2012 Vijay Mathew Pandyalakal <[email protected]> ;;;; This file is part of yuka. ;;;; yuka 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. ;;;; yuka 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 <http://www.gnu.org/licenses/>. (in-package :yuka) ;;; Representation of a class. (defstruct klass (minor-version 0 :type integer) (major-version 0 :type integer) (constant-pool-count 0 :type integer) (constant-pool nil :type simple-array) (access-flags 0 :type integer) (this 0 :type integer) (super 0 :type integer) (interfaces-count 0 :type integer) (interfaces nil :type simple-array) (fields-count 0 :type integer) (fields nil :type simple-array) (methods-count 0 :type integer) (methods nil :type simple-array) (attributes-count 0 :type integer) (attributes nil :type simple-array)) (defun klass-find-method-by-name (self name) (let ((methods (klass-methods self)) (cp (klass-constant-pool self)) (method nil)) (dotimes (i (length methods)) (let ((m (aref methods i))) (when (string= name (constant-pool-string-at cp (field/method-info-name-index m))) (setf method m) (return)))) method)) (defmacro klass-name (self) `(constant-pool-string-at (klass-constant-pool ,self) (klass-this ,self))) (defun klass-to-string (self) (with-output-to-string (s) (let ((cp (klass-constant-pool self))) (format s "Version: ~a.~a~%" (klass-major-version self) (klass-minor-version self)) (format s "Class: ~a~%" (constant-pool-string-at cp (klass-this self))) (format s "Super: ~a~%" (constant-pool-string-at cp (klass-super self))) (format s "Interfaces: ") (map nil #'(lambda (i) (format s "~a " (constant-pool-string-at cp i))) (klass-interfaces self)) (format s "~%Fields:~%~a~%" (field/method-infos-to-string (klass-fields self) cp)) (format s "Methods:~%~a~%" (field/method-infos-to-string (klass-methods self) cp)) (format s "Constant Pool:~%~a~%" (constant-pool-to-string cp)) (format s "Attributes: ~a~%" (klass-attributes self)))))
2,673
Common Lisp
.lisp
61
39.229508
78
0.672175
easye/yuka
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
9414eff1948946217bffd664c1d7703e4e2821d7c7ae9d53e427be69b89471a3
21,459
[ -1 ]
21,460
opc-impl.lisp
easye_yuka/src/opc-impl.lisp
;;;; Copyright (c) 2012 Vijay Mathew Pandyalakal <[email protected]> ;;;; This file is part of yuka. ;;;; yuka 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. ;;;; yuka 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 <http://www.gnu.org/licenses/>. (in-package :yuka) ;;; Implementation of opcode actions to be executed by the ;;; bytecode interpreter. (See frame.lisp) (defmacro throw-exception (exception) `(error "~a" ,exception)) (defmacro check-not-null (obj) `(when (null ,obj) (throw-exception 'NullPointerException))) (defmacro check-bounds (array index) `(when (>= ,index (length ,array)) (throw-exception 'ArrayIndexOutOfBoundsException))) (defmacro check-array-type (array types) `(format t "(check-array-type ~a ~a) not implemented!~%" ,array ,types)) (defmacro check-array-can-store (array value) `(format t "(check-array-can-store ~a ~a) not implemented!~%" ,array ,value)) (defmacro check-for-neg-array-size (size) `(when (< ,size 0) (throw-exception 'NegativeArraySizeException))) (defmacro check-obj-type (obj types) `(format t "(check-obj-type ~a ~a) not implemented!~%" ,obj ,types)) (defmacro check-subclass-of (objref super-classes) `(format t "(check-subclass-of ~a ~a) not implemented!~%" ,objref ,super-classes)) (defmacro can-cast (src target) `(format t "(can-cast ~a ~a) not implemented!~%" ,src ,target)) (defmacro check-array (array index) `(check-not-null ,array) `(check-bounds ,array ,index)) (defmacro storev (locals operand-stack index) `(setf (aref ,locals ,index) (stack-pop ,operand-stack))) (defun aaload (operand-stack) (let* ((a (stack-pop operand-stack)) (array (typed-array-elements a)) (index (stack-pop operand-stack))) (check-array array index) (stack-push operand-stack (aref array index)))) (defun aastore (operand-stack) (let* ((a (stack-pop operand-stack)) (array (typed-array-elements a)) (index (stack-pop operand-stack)) (value (stack-pop operand-stack))) (check-array array index) (check-array-can-store array value) (setf (aref array index) value))) (defmacro aload (locals operand-stack index) `(stack-push ,operand-stack (aref ,locals ,index))) (defun anewarray (operand-stack constant-pool index) (let ((count (stack-pop operand-stack))) (check-for-neg-array-size count) (stack-push operand-stack (make-typed-array count (constant-pool-string-at constant-pool index))))) (defun arraylength (operand-stack) (let ((array (stack-pop operand-stack))) (check-not-null array) (stack-push operand-stack (length (typed-array-elements array))))) (defun astore (locals operand-stack index) (let ((ref (stack-pop operand-stack))) (check-obj-type ref '(return-address reference)) (setf (aref locals index) ref))) (defun athrow (operand-stack exception-table constant-pool) (let ((ref (stack-pop operand-stack))) (check-obj-type ref '(reference)) (check-subclass-of ref '(Throwable)) (let ((h (exception-table-find-handler exception-table (klass-name ref) constant-pool))) (cond ((null h) (stack-reset operand-stack) (stack-push operand-stack ref) -1) (t (exception-table-entry-target h)))))) (defun array-load (operand-stack) (let ((array (stack-pop operand-stack)) (index (stack-pop operand-stack))) (check-array array index) (stack-push operand-stack (aref array index)))) (defun array-store (operand-stack types) (let ((array (stack-pop operand-stack)) (index (stack-pop operand-stack)) (value (stack-pop operand-stack))) (check-array array index) (check-obj-type value types) (setf (aref array index) value))) (defmacro baload (operand-stack) `(array-load ,operand-stack)) (defmacro bastore (operand-stack) `(array-store ,operand-stack '(byte boolean))) (defmacro caload (operand-stack) `(array-load ,operand-stack)) (defmacro castore (operand-stack) `(array-store ,operand-stack '(char))) (defun checkcast (operand-stack index constant-pool) (let ((objref (stack-top operand-stack))) (when (not (null objref)) (let ((name (constant-pool-string-at constant-pool index))) (when (not (can-cast objref (find-klass name))) (stack-pop operand-stack) (throw-exception 'ClassCastException)))))) (defmacro d2f (operand-stack) `(stack-push ,operand-stack (double-to-float (stack-pop ,operand-stack)))) (defmacro d2i (operand-stack) `(stack-push ,operand-stack (double-to-int (stack-pop ,operand-stack)))) (defmacro d2l (operand-stack) `(stack-push ,operand-stack (double-to-long (stack-pop ,operand-stack)))) (defmacro dadd (operand-stack) `(stack-push ,operand-stack (double-add (stack-pop ,operand-stack) (stack-pop ,operand-stack)))) (defmacro daload (operand-stack) `(array-load ,operand-stack)) (defmacro dastore (operand-stack) `(array-store ,operand-stack '(double))) (defmacro dcmp (operand-stack is-l) `(stack-push ,operand-stack (double-compare (stack-pop ,operand-stack) (stack-pop ,operand-stack) ,is-l))) (defmacro arith-helper (operand-stack b a fn) `(stack-push ,operand-stack (funcall ,fn ,a ,b))) (defmacro arith (operand-stack fn) `(arith-helper ,operand-stack (stack-pop ,operand-stack) (stack-pop ,operand-stack) ,fn)) (defmacro ddiv (operand-stack) `(arith ,operand-stack #'double-div)) (defmacro loadv (locals operand-stack index) `(stack-push ,operand-stack (aref ,locals ,index))) (defmacro dmul (operand-stack) `(arith ,operand-stack #'double-mul)) (defmacro dneg (operand-stack) `(stack-push ,operand-stack (double-neg (stack-pop ,operand-stack)))) (defmacro drem (operand-stack) `(arith ,operand-stack #'double-rem)) (defmacro dsub (operand-stack) `(arith ,operand-stack #'double-sub)) (defmacro f2i (operand-stack) `(stack-push ,operand-stack (float-to-integer (stack-pop ,operand-stack) 'integer))) (defmacro f2l (operand-stack) `(stack-push ,operand-stack (float-to-integer (stack-pop ,operand-stack) 'long))) (defmacro fadd (operand-stack) `(arith ,operand-stack #'float-add)) (defmacro faload (operand-stack) `(array-load ,operand-stack)) (defmacro fastore (operand-stack) `(array-store ,operand-stack '(float))) (defmacro fdiv (operand-stack) `(arith ,operand-stack #'float-div)) (defmacro fmul (operand-stack) `(arith ,operand-stack #'float-mul)) (defmacro fneg (operand-stack) `(stack-push ,operand-stack (float-neg (stack-pop ,operand-stack)))) (defmacro frem (operand-stack) `(arith ,operand-stack #'float-rem)) (defmacro fsub (operand-stack) `(arith ,operand-stack #'float-sub)) (defun getfield (operand-stack constant-pool index) (let ((objref (stack-pop operand-stack)) (sym (constant-pool-string-at constant-pool index))) (check-not-null objref) (stack-push operand-stack (resolve-field objref sym)))) (defun getstatic (operand-stack constant-pool index) (let ((objref (stack-pop operand-stack)) (sym (constant-pool-string-at constant-pool index))) (check-not-null objref) (stack-push operand-stack (resolve-static-field objref sym)))) (defun find-pc (dest-opc-sym byte-code byte-code-len jump-to) (let ((pc (dotimes (i byte-code-len) (let ((opc-offset (opcode-offset (aref byte-code i)))) (when (= opc-offset jump-to) (return opc-offset)))))) (when (null pc) (vm-panic "Invalid jump offset." (cons dest-opc-sym jump-to))) pc)) (defmacro goto (byte-code byte-code-len jump-to) `(find-pc 'goto ,byte-code ,byte-code-len ,jump-to)) (defmacro type-cast (operand-stack constructor) `(stack-push ,operand-stack (funcall ,constructor (stack-pop ,operand-stack)))) (defmacro iadd (operand-stack) `(arith ,operand-stack #'integer-add)) (defmacro iaload (operand-stack) `(array-load ,operand-stack)) (defmacro iand (operand-stack) `(arith ,operand-stack #'integer-and)) (defmacro iastore (operand-stack) `(array-store ,operand-stack '(integer))) (declaim (inline idiv)) (defun idiv (operand-stack) (let ((r (arith operand-stack #'integer-div))) (when (symbolp r) (throw-exception r)) r)) (defmacro if-cmp (operand-stack predicate jump-to) `(if (funcall ,predicate (stack-pop ,operand-stack) (stack-pop ,operand-stack)) ,jump-to nil)) (defmacro if-cmp-with (operand-stack value predicate jump-to) `(if (funcall ,predicate (stack-pop ,operand-stack) ,value) ,jump-to nil)) (declaim (inline iinc)) (defun iinc (locals index const) (let ((v (aref locals index))) (setf (aref locals index) (+ v const)))) (defmacro imul (operand-stack) `(arith ,operand-stack #'integer-mul)) (defmacro ineg (operand-stack) `(stack-push ,operand-stack (integer-neg (stack-pop ,operand-stack)))) (defmacro instanceof (operand-stack constant-pool index) `(stack-push ,operand-stack (is-instance-of (constant-pool-string-at ,constant-pool ,index) (stack-pop ,operand-stack)))) (defmacro invokedynamic (operand-stack constant-pool index) `(invoke-dynamic (constant-pool-string-at ,constant-pool ,index) ,operand-stack)) (defmacro invokeinterface (operand-stack constant-pool index count) `(invoke-interface (constant-pool-string-at ,constant-pool ,index) ,operand-stack ,count)) (defmacro invokespecial (operand-stack constant-pool index) `(invoke-special (constant-pool-string-at ,constant-pool ,index) ,operand-stack)) (defmacro invokestatic (operand-stack constant-pool index) `(invoke-static (constant-pool-string-at ,constant-pool ,index) ,operand-stack)) (defmacro invokevirtual (operand-stack constant-pool index) `(invoke-virtual (constant-pool-string-at ,constant-pool ,index) ,operand-stack)) (defmacro ior (operand-stack) `(arith ,operand-stack #'integer-or)) (declaim (inline irem)) (defun irem (operand-stack) (let ((r (arith operand-stack #'integer-rem))) (when (symbolp r) (throw-exception r)) r)) (defmacro ishl (operand-stack) `(arith ,operand-stack #'integer-shift-left)) (defmacro ishr (operand-stack) `(arith ,operand-stack #'integer-shift-right)) (defmacro isub (operand-stack) `(arith ,operand-stack #'integer-sub)) (defmacro iushr (operand-stack) `(arith ,operand-stack #'integer-logical-shift-right)) (defmacro ixor (operand-stack) `(arith ,operand-stack #'integer-xor)) (declaim (inline jsr)) (defun jsr (operand-stack byte-code byte-code-len jump-to next-opc) (let ((pc (find-pc 'jsr byte-code byte-code-len jump-to))) (stack-push operand-stack (make-return-address (opcode-offset next-opc))) pc)) (defmacro ladd (operand-stack) `(arith ,operand-stack #'long-add)) (defmacro laload (operand-stack) `(array-load ,operand-stack)) (defmacro land (operand-stack) `(arith ,operand-stack #'long-and)) (defmacro lastore (operand-stack) `(array-store ,operand-stack '(long))) (defmacro lcmp (operand-stack) `(arith ,operand-stack #'long-compare)) (defmacro ldc (operand-stack constant-pool index) `(format t "(ldc ~a ~a ~a) not implemented!~%" ,operand-stack ,constant-pool ,index)) (defmacro ldc2 (operand-stack constant-pool index) `(format t "(ldc2 ~a ~a ~a) not implemented!~%" ,operand-stack ,constant-pool ,index)) (defmacro ldiv (operand-stack) `(arith ,operand-stack #'long-div)) (defmacro lmul (operand-stack) `(arith ,operand-stack #'long-mul)) (defmacro lneg (operand-stack) `(stack-push ,operand-stack (long-neg (stack-pop ,operand-stack)))) (declaim (inline lookupswitch)) (defun lookupswitch (key byte-code byte-code-len current-offset operand) (let ((offset (car operand)) (match-offsets (cdr operand))) (dotimes (i (length match-offsets)) (let ((e (aref match-offsets i))) (when (= key (car e)) (setf offset (cdr e)) (return)))) (find-pc 'lookupswitch byte-code byte-code-len (+ current-offset offset)))) (defmacro lor (operand-stack) `(arith ,operand-stack #'long-or)) (defmacro lrem (operand-stack) `(arith ,operand-stack #'long-rem)) (defmacro lshl (operand-stack) `(arith ,operand-stack #'long-shift-left)) (defmacro lshr (operand-stack) `(arith ,operand-stack #'long-shift-right)) (defmacro lsub (operand-stack) `(arith ,operand-stack #'long-sub)) (defmacro lushr (operand-stack) `(arith ,operand-stack #'long-logical-shift-right)) (defmacro lxor (operand-stack) `(arith ,operand-stack #'long-xor)) (declaim (inline monitorenter)) (defun monitorenter (operand-stack) (format t "(monitorenter ~a) not fully implemented!~%" operand-stack) (stack-pop operand-stack)) (declaim (inline monitorexit)) (defun monitorexit (operand-stack) (format t "(monitorexit ~a) not fully implemented!~%" operand-stack) (stack-pop operand-stack)) (declaim (inline multianewarray)) (defun multianewarray (operand-stack dimensions-count constant-pool pool-index) (when (< dimensions-count 0) (throw-exception 'NegativeArraySizeException)) (let ((dimensions nil)) (dotimes (i dimensions-count) (setf dimensions (cons (stack-pop operand-stack) dimensions))) (stack-push operand-stack (make-typed-array (reverse dimensions) (constant-pool-string-at constant-pool pool-index))))) (declaim (inline new)) (defun new (operand-stack) (format t "(new ~a) not implemented!~%" operand-stack)) (declaim (inline newarray)) (defun newarray (operand-stack type) (let ((c (stack-pop operand-stack))) (when (< c 0) (throw-exception 'NegativeArraySizeException)) (stack-push operand-stack (make-typed-array c (atype-to-symbol type))))) (declaim (inline pop2)) (defun pop2 (operand-stack) (let ((v1 (stack-pop operand-stack))) (when (is-category-1 v1) (stack-pop operand-stack)))) (declaim (inline putfield)) (defun putfield (operand-stack constant-pool pool-index) (let ((value (stack-pop operand-stack)) (objref (stack-pop operand-stack)) (field-name (constant-pool-string-at constant-pool pool-index))) (format t "~a.~a = ~a~%" objref field-name value) (format t "putfield not fully implemented!~%"))) (declaim (inline putstatic)) (defun putstatic (operand-stack constant-pool pool-index) (let ((value (stack-pop operand-stack)) (field-name (constant-pool-string-at constant-pool pool-index))) (format t "~a = ~a~%" field-name value) (format t "putstatic not fully implemented!~%"))) (defmacro ret (locals index) `(return-address-value (aref ,locals ,index))) (defmacro saload (operand-stack) `(array-load ,operand-stack)) (defmacro sastore (operand-stack) `(array-store ,operand-stack '(short))) (declaim (inline tableswitch)) (defun tableswitch (index ts byte-code byte-code-len current-offset) (let ((default (table-switch-default ts)) (low (table-switch-low ts)) (hi (table-switch-hi ts))) (let ((offset (if (or (< default low) (> default hi)) default (aref (table-switch-jump-offsets ts) (- index low))))) (find-pc 'tableswitch byte-code byte-code-len (+ offset current-offset)))))
15,935
Common Lisp
.lisp
392
36.339286
92
0.693415
easye/yuka
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
925b64c7a8c70d8c887842983cddbc8f61eb02622bb6ca09aea9e34a1a4f48cd
21,460
[ -1 ]
21,461
access-flags.lisp
easye_yuka/src/access-flags.lisp
;;;; Copyright (c) 2012 Vijay Mathew Pandyalakal <[email protected]> ;;;; This file is part of yuka. ;;;; yuka 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. ;;;; yuka 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 <http://www.gnu.org/licenses/>. (in-package :yuka) ;;; Functions to deal with class/method/field access modifiers - ;;; private, protected, public etc. (defconstant +acc-public+ #x0001) (defconstant +acc-private+ #x0002) (defconstant +acc-protected+ #x0004) (defconstant +acc-static+ #x0008) (defconstant +acc-final+ #x0010) (defconstant +acc-synchronized+ #x0020) (defconstant +acc-volatile+ #x0040) (defconstant +acc-bridge+ #x0040) (defconstant +acc-transient+ #x0080) (defconstant +acc-varargs+ #x0080) (defconstant +acc-native+ #x0100) (defconstant +acc-abstract+ #x0400) (defconstant +acc-strict+ #x0800) (defconstant +acc-synthetic+ #x1000) (defconstant +acc-enum+ #x4000) (defmacro flag-set-p (flag i) `(not (= 0 (logand ,flag ,i)))) (defun flags-to-string (flag) (with-output-to-string (s) (when (flag-set-p +acc-public+ flag) (format s "public ")) (when (flag-set-p +acc-private+ flag) (format s "private ")) (when (flag-set-p +acc-protected+ flag) (format s "protected ")) (when (flag-set-p +acc-static+ flag) (format s "static ")) (when (flag-set-p +acc-final+ flag) (format s "final ")) (when (flag-set-p +acc-synchronized+ flag) (format s "synchronized ")) (when (flag-set-p +acc-volatile+ flag) (format s "volatile ")) (when (flag-set-p +acc-bridge+ flag) (format s "bridge ")) (when (flag-set-p +acc-transient+ flag) (format s "transient ")) (when (flag-set-p +acc-varargs+ flag) (format s "varargs ")) (when (flag-set-p +acc-native+ flag) (format s "native ")) (when (flag-set-p +acc-abstract+ flag) (format s "abstract ")) (when (flag-set-p +acc-strict+ flag) (format s "strict ")) (when (flag-set-p +acc-synthetic+ flag) (format s "synthetic ")) (when (flag-set-p +acc-enum+ flag) (format s "enum "))))
2,608
Common Lisp
.lisp
64
37.1875
77
0.676134
easye/yuka
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
c4b48396afc127aefa981ff279dbb6964086d5ac6e96d314961b821e63c959fd
21,461
[ -1 ]
21,462
packages.lisp
easye_yuka/src/packages.lisp
;;;; Copyright (c) 2012 Vijay Mathew Pandyalakal <[email protected]> ;;;; This file is part of yuka. ;;;; yuka 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. ;;;; yuka 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 <http://www.gnu.org/licenses/>. (in-package :cl-user) (defpackage :yuka (:use :cl) (:export :load-klass-file :run-main :klass-to-string))
884
Common Lisp
.lisp
18
46.777778
77
0.723577
easye/yuka
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
1b3354bd359374dd27a18a09d14698684316da5efb9a29f82fce6057c2a5a593
21,462
[ -1 ]
21,463
test.lisp
easye_yuka/src/test.lisp
(in-package :yuka) (setf s (make-stack 5)) (stack-push s 1) (stack-push s 2) (format t "~a~%" (stack-length s)) (stack-push s 3) (stack-dup2 s) (format t "~a~%" s) (loop for i from 0 to (1- (stack-length s)) do (format t "~a " (stack-at s i)))
249
Common Lisp
.lisp
10
23.4
43
0.615063
easye/yuka
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
8d869cf716ed0ad4969d0d78a46ebaf9aa90ea0923c09e64d0a1fb53bdc29969
21,463
[ -1 ]
21,465
SimpleMath.java
easye_yuka/test/SimpleMath.java
public class SimpleMath { public static void main(String args[]) { double a = 1000.4344; double b = 54.43; double d = a % b; System.out.println(d); } }
164
Common Lisp
.l
8
18
44
0.660256
easye/yuka
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
cdefba77c2c71506629651770429d5d6c15eec0de9844bced818b3f0a6d319ba
21,465
[ -1 ]
21,497
package.lisp
keithj_deoxybyte-run/test/package.lisp
;;; ;;; Copyright (C) 2007, 2008., 2009, 2010, 2011 Keith James. All ;;; rights reserved. ;;; ;;; 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 <http://www.gnu.org/licenses/>. ;;; (defpackage :uk.co.deoxybyte-run-test (:use #:common-lisp #:deoxybyte-run #:deoxybyte-utilities #:lift) (:documentation "Deoxybyte run tests.") (:export #:deoxybyte-run-tests))
940
Common Lisp
.lisp
21
43.428571
73
0.733115
keithj/deoxybyte-run
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
ca48d582e677a1059408c4a0f23f9eef845139b91ecfcb0145758739ce4e0ade
21,497
[ -1 ]
21,498
deoxybyte-run-test.lisp
keithj_deoxybyte-run/test/deoxybyte-run-test.lisp
;;; ;;; Copyright (C) 2007, 2008, 2009, 2010, 2011 Keith James. All rights ;;; reserved. ;;; ;;; 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 <http://www.gnu.org/licenses/>. ;;; (in-package :uk.co.deoxybyte-run-test) (deftestsuite deoxybyte-run-tests () ()) (defvar *png-signature* '(137 80 78 71 13 10 26 10) "The first eight bytes of any PNG file.") (defun as-bytes (str) (make-array (length str) :element-type 'octet :initial-contents (loop for c across str collect (char-code c)))) (defun as-chars (bytes) (make-array (length bytes) :element-type 'base-char :initial-contents (loop for b across bytes collect (code-char b)))) (addtest (deoxybyte-run-tests) gnuplot/png/1 (ensure-directories-exist (merge-pathnames "data/")) (let* ((png-filespec (namestring (merge-pathnames "data/xy-plot.png"))) (plotter (run-gnuplot)) (x #(0 1 2 3 4 5 6 7 8 9)) (y #(1 2.5 3 4 5 6 6.5 4 3.2 3)) (plot (make-instance '2d-plot :title "Test title" :x-axis (make-instance 'axis :label "Test x label" :position :x) :y-axis (make-instance 'axis :label "Test y label" :position :y) :series (make-instance 'xy-series :x-values x :y-values y :style '(:linespoints :smooth :csplines))))) (ensure (open-stream-p (input-of plotter))) (draw-plot plotter plot :terminal :png :output png-filespec) (stop-gnuplot plotter) (ensure (not (open-stream-p (input-of plotter)))) (with-open-file (png-stream png-filespec :direction :input :element-type 'octet) (ensure (equalp *png-signature* (loop repeat 8 collect (read-byte png-stream))))) (delete-file png-filespec))) (addtest (deoxybyte-run-tests) gnuplot/x11/histogram/1 (let* ((plotter (run-gnuplot :debug nil)) (x (list "foo" "bar" "baz")) (y (list 2.1 2.2 5.6)) (plot (make-instance 'histogram :x-axis (x-axis :label "x" :range (list -0.5 6.5)) :y-axis (y-axis :label "y" :range (list -0.5 6.5)) :series (make-instance 'category-series :categories x :values y) :title "Histogram"))) (draw-plot plotter plot :terminal :x11) (sleep 5) (stop-gnuplot plotter))) (addtest (deoxybyte-run-tests) gnuplot/x11/update/1 (let* ((plotter (run-gnuplot :debug nil)) (x (list 0)) (y0 (list 0 1.1 1.3 1.9 2.3 4.5)) (y1 (list 0 0.7 1.2 2.1 2.2 5.6)) (plot (2d-plot (x-axis :label "x" :range (list -0.5 6.5)) (y-axis :label "y" :range (list -0.5 6.5)) (list (xy-series x (list 0) :style '(:linespoints)) (xy-series x (list 0) :style '(:linespoints))) :title "Update"))) (draw-plot plotter plot :terminal :x11) (loop for i from 1 to 5 do (let ((s0 (nth-series-of 0 plot)) (s1 (nth-series-of 1 plot))) (sleep 1) (append-data s0 :x-values (list i) :y-values (list (nth i y0))) (append-data s1 :x-values (list i) :y-values (list (nth i y1))) (update-plot plotter plot))) (stop-gnuplot plotter)))
4,386
Common Lisp
.lisp
92
34.597826
80
0.527531
keithj/deoxybyte-run
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
a863e5959836729cf3ce21434ab00c6f9c4d824b3f40f159a5a8b5e6be881a55
21,498
[ -1 ]
21,499
package.lisp
keithj_deoxybyte-run/src/package.lisp
;;; ;;; Copyright (C) 2008, 2009, 2010, 2011, 2015 Keith James. All rights ;;; reserved. ;;; ;;; This file is part of deoxybyte-run. ;;; ;;; 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 <http://www.gnu.org/licenses/>. ;;; (defpackage :uk.co.deoxybyte-run (:use #:common-lisp #:deoxybyte-utilities #:deoxybyte-io) (:nicknames #:deoxybyte-run #:dxr) (:export ;; External programs #:external-program-error #:non-zero-exit-error #:external-program #:program-of #:args-of #:process-of #:input-of #:output-of #:error-of #:wait-for #:status-of #:exit-code-of #:close-process #:kill-process #:run #:runningp #:programs-running ;; Gnuplot #:gnuplot #:plot #:2d-plot #:histogram #:x-axis #:y-axis #:axis #:series #:xy-series #:category-series #:title-of #:series-of #:nth-series-of #:legend-of #:x-axis-of #:y-axis-of #:position-of #:range-of #:x-range-of #:y-range-of #:label-of #:tics-of #:minor-tics-of #:style-of #:x-values-of #:y-values-of #:length-of #:draw-plot #:update-plot #:append-data #:run-gnuplot #:stop-gnuplot) (:documentation "The deoxybyte-run system is a compatability and convenience layer for running external programs. In addition, wrappers for some software are included: - Gnuplot - rsh"))
1,951
Common Lisp
.lisp
81
20.987654
73
0.678629
keithj/deoxybyte-run
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
0d2cd4ae36a5882147f17a4639a158dce71ad3b90d684b51ac2ffe03bb1938ba
21,499
[ -1 ]
21,500
ccl.lisp
keithj_deoxybyte-run/src/ccl.lisp
;;; ;;; Copyright (C) 2012, 2015 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-run. ;;; ;;; 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 <http://www.gnu.org/licenses/>. ;;; (in-package :uk.co.deoxybyte-run) ;;; deoxybyte-run (defmethod start-process ((program external-program) &rest process-args &key &allow-other-keys) (flet ((as-strings (alist) (loop for (key . val) in alist collect (format nil "~a=~a" key val)))) (multiple-value-bind (args vals) (collect-key-values '(:input :output :error :if-input-does-not-exist :if-output-exists :if-error-exists :environment :pty :wait :status-hook) process-args) (let ((proc-args (loop for arg in args for val in vals nconc (if (eql :environment arg) (list arg (as-strings val)) (list arg val))))) (setf (slot-value program 'process) (apply #'ccl:run-program (program-of program) (args-of program) proc-args))))) program) (defmethod startedp ((program external-program)) (process-of program)) (defmethod input-of ((program external-program)) (ccl:external-process-input-stream (process-of program))) (defmethod output-of ((program external-program)) (ccl:external-process-output-stream (process-of program))) (defmethod error-of ((program external-program)) (ccl:external-process-error-stream (process-of program))) (defmethod wait-for ((program external-program)) nil) (defmethod status-of ((program external-program)) (ccl:external-process-status (process-of program))) (defmethod exit-code-of ((program external-program)) (multiple-value-bind (status exit-code) (ccl:external-process-status (process-of program)) (declare (ignore status)) exit-code)) (defmethod close-process ((program external-program)) (close (input-of program)) (close (output-of program)) (close (error-of program))) (defmethod kill-process ((program external-program) signal &optional (whom :pid)) (declare (ignore whom)) (ccl:signal-external-process (process-of program) signal)) (defmethod runningp ((program external-program)) (and (startedp program) (eql :running (status-of program)))) (defmethod finishedp ((program external-program)) (and (startedp program) (member (status-of program) '(:exited :signaled)))) (defun cleanup-process (process) (when (eql :exited (ccl:external-process-status process)) (let ((in (ccl:external-process-input-stream process)) (out (ccl:external-process-output-stream process)) (err (ccl:external-process-error-stream process))) (dolist (s (list in out err)) (when s (close s))))))
3,535
Common Lisp
.lisp
78
38
77
0.651656
keithj/deoxybyte-run
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
312d9f332b8b1a1d51ab505978755d0d12bc160045d6a2b9b3eb59d01853e24c
21,500
[ -1 ]
21,501
conditions.lisp
keithj_deoxybyte-run/src/conditions.lisp
;;; ;;; Copyright (C) 2009, 2010, 2011 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-run. ;;; ;;; 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 <http://www.gnu.org/licenses/>. ;;; (in-package :uk.co.deoxybyte-run) (define-condition external-program-error (error) ((text :initform nil :initarg :text :reader text-of :documentation "Error message text.")) (:documentation "The parent type of all external program error conditions.")) (define-condition non-zero-exit-error (external-program-error) ((program :initform nil :initarg :program :reader program-of :documentation "The object that failed to return a zero exit code.") (exit-code :initform nil :initarg :exit-code :reader exit-code-of :documentation "The exit code.")) (:report (lambda (condition stream) (format stream "Non-zero exit code~@[ ~a~] from ~a ~@[: ~a~]" (exit-code-of condition) (program-of condition) (text-of condition)))) (:documentation "An error that is raised when an external program returns a non-zero exit code."))
1,809
Common Lisp
.lisp
43
36.116279
74
0.663642
keithj/deoxybyte-run
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
941d231412af34590e4ebb01c681b3df6a6dc6f8e5cd78a2c5db570ec6509a00
21,501
[ -1 ]
21,502
default.lisp
keithj_deoxybyte-run/src/default.lisp
;;; ;;; Copyright (C) 2012 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-run. ;;; ;;; 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 <http://www.gnu.org/licenses/>. ;;; (in-package :uk.co.deoxybyte-run) (error "Running external programs not supported on this Lisp implementation.")
886
Common Lisp
.lisp
20
43.2
78
0.74537
keithj/deoxybyte-run
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
9bc5b2b60831738ff887b3a672c12dc9b28e5641755fab90a8efefc9df037b53
21,502
[ -1 ]
21,503
sbcl.lisp
keithj_deoxybyte-run/src/sbcl.lisp
;;; ;;; Copyright (C) 2012, 2015 Keith James. All rights reserved. ;;; ;;; This file is part of deoxybyte-run. ;;; ;;; 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 <http://www.gnu.org/licenses/>. ;;; (in-package :uk.co.deoxybyte-run) ;;; deoxybyte-run (defmethod start-process ((program external-program) &rest process-args &key &allow-other-keys) (flet ((as-strings (alist) (loop for (key . val) in alist collect (format nil "~a=~a" key val)))) (multiple-value-bind (args vals) (collect-key-values '(:input :output :error :if-input-does-not-exist :if-output-exists :if-error-exists :environment :search :pty :wait :status-hook) process-args) (let ((proc-args (loop for arg in args for val in vals nconc (if (eql :environment arg) (list arg (as-strings val)) (list arg val))))) (setf (slot-value program 'process) (apply #'sb-ext:run-program (program-of program) (args-of program) proc-args))))) program) (defmethod startedp ((program external-program)) (process-of program)) (defmethod input-of ((program external-program)) (sb-ext:process-input (process-of program))) (defmethod output-of ((program external-program)) (sb-ext:process-output (process-of program))) (defmethod error-of ((program external-program)) (sb-ext:process-error (process-of program))) (defmethod wait-for ((program external-program)) (sb-ext:process-wait (process-of program) nil)) ; check-for-stopped nil (defmethod status-of ((program external-program)) (sb-ext:process-status (process-of program))) (defmethod exit-code-of ((program external-program)) (and (process-of program) (sb-ext:process-exit-code (process-of program)))) (defmethod close-process ((program external-program)) (sb-ext:process-close (process-of program))) (defmethod kill-process ((program external-program) signal &optional (whom :pid)) (sb-ext:process-kill (process-of program) signal whom)) (defmethod runningp ((program external-program)) (and (startedp program) (eql :running (status-of program)))) (defmethod finishedp ((program external-program)) (and (startedp program) (member (status-of program) '(:exited :signaled)))) (defun cleanup-process (process) (when (eql :exited (sb-ext:process-status process)) (sb-ext:process-close process)))
3,182
Common Lisp
.lisp
66
41.030303
80
0.657207
keithj/deoxybyte-run
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
af821ca52785db6fc2747b888c09d88a76d0d0d49b8a1444a1685cabfaa7e8c3
21,503
[ -1 ]
21,504
deoxybyte-run.asd
keithj_deoxybyte-run/deoxybyte-run.asd
;;; ;;; Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Keith ;;; James. All rights reserved. ;;; ;;; This file is part of deoxybyte-run. ;;; ;;; 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 <http://www.gnu.org/licenses/>. ;;; (in-package :cl-user) (asdf:load-system :deoxybyte-systems) (in-package :uk.co.deoxybyte-systems) (defsystem deoxybyte-run :name "deoxybyte-run" :version "0.7.0" :author "Keith James" :licence "GPL v3" :in-order-to ((test-op (load-op :deoxybyte-run :deoxybyte-run-test)) (doc-op (load-op :deoxybyte-run :cldoc))) :depends-on ((:version :deoxybyte-systems "1.0.0") (:version :deoxybyte-io "0.15.0") (:version :deoxybyte-utilities "0.11.0")) :components ((:module :core :serial t :pathname "src/" :components ((:file "package") (:file "conditions") (:file "deoxybyte-run") #+:sbcl (:file "sbcl") #+:ccl (:file "ccl") #- (or :sbcl :ccl) (:file "default") (:file "gnuplot")))) :perform (test-op :after (op c) (maybe-run-lift-tests :deoxybyte-run "deoxybyte-run-test.config")) :perform (doc-op :after (op c) (maybe-build-cldoc-docs :deoxybyte-run "doc/html")))
2,054
Common Lisp
.asd
48
33.729167
73
0.580919
keithj/deoxybyte-run
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
5f1a5d27207d824c9b745c1174aac926cf963676119f8cc3b19ac44320a85ae9
21,504
[ -1 ]
21,505
deoxybyte-run-test.asd
keithj_deoxybyte-run/deoxybyte-run-test.asd
;;; ;;; Copyright (C) 2007, 2008, 2009, 2010, 2011 Keith James. All rights ;;; reserved. ;;; ;;; This file is part of deoxybyte-run. ;;; ;;; 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 <http://www.gnu.org/licenses/>. ;;; (defsystem deoxybyte-run-test :depends-on ((:version :lift "1.7.0") :deoxybyte-run) :components ((:module :deoxybyte-run-test :serial t :pathname "test/" :components ((:file "package") (:file "deoxybyte-run-test")))))
1,146
Common Lisp
.asd
27
36.666667
73
0.646691
keithj/deoxybyte-run
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
d41093afcc27c3d69220b1b8cd64a35c0208ce281e647dfa85f772e71833701b
21,505
[ -1 ]
21,530
trivial-garbage.lisp
rheaplex_minara/lib/trivial-garbage/trivial-garbage.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; ;;; trivial-garbage.lisp --- Trivial Garbage! ;;; ;;; This software is placed in the public domain by Luis Oliveira ;;; <[email protected]> and is provided with absolutely no ;;; warranty. (defpackage #:trivial-garbage (:use #:cl) (:shadow #:make-hash-table) (:nicknames #:tg) (:export #:gc #:make-weak-pointer #:weak-pointer-value #:weak-pointer-p #:make-weak-hash-table #:hash-table-weakness #:finalize #:cancel-finalization)) (in-package #:trivial-garbage) ;;;; GC (defun gc (&key full verbose) "Initiates a garbage collection." (declare (ignorable verbose full)) #+(or cmu scl) (ext:gc :verbose verbose :full full) #+sbcl (sb-ext:gc :full full) #+allegro (excl:gc (not (null full))) #+clisp (ext:gc) #+ecl (si:gc t) #+openmcl (ccl:gc) #+corman (ccl:gc (if full 3 0)) #+lispworks (hcl:mark-and-sweep (if full 3 0))) ;;;; Weak Pointers #+openmcl (defvar *weak-pointers* (cl:make-hash-table :test 'eq :weak :value) "Weak value hash-table mapping between pseudo weak pointers and its values.") #+(or allegro openmcl lispworks) (defstruct (weak-pointer (:constructor %make-weak-pointer)) #-openmcl pointer) (defun make-weak-pointer (object) "Creates a new weak pointer which points to OBJECT. For portability reasons, OBJECT most not be NIL." (assert (not (null object))) #+sbcl (sb-ext:make-weak-pointer object) #+(or cmu scl) (ext:make-weak-pointer object) #+clisp (ext:make-weak-pointer object) #+ecl (error "not implemented") #+allegro (let ((wv (excl:weak-vector 1))) (setf (svref wv 0) object) (%make-weak-pointer :pointer wv)) #+openmcl (let ((wp (%make-weak-pointer))) (setf (gethash wp *weak-pointers*) object) wp) #+corman (ccl:make-weak-pointer object) #+lispworks (let ((array (make-array 1))) (hcl:set-array-weak array t) (setf (svref array 0) object) (%make-weak-pointer :pointer array))) #-(or allegro openmcl lispworks) (defun weak-pointer-p (object) "Returns true if OBJECT is a weak pointer and NIL otherwise." #+sbcl (sb-ext:weak-pointer-p object) #+(or cmu scl) (ext:weak-pointer-p object) #+clisp (ext:weak-pointer-p object) #+ecl (error "not implemented") #+corman (ccl:weak-pointer-p object)) (defun weak-pointer-value (weak-pointer) "If WEAK-POINTER is valid, returns its value. Otherwise, returns NIL." #+sbcl (values (sb-ext:weak-pointer-value weak-pointer)) #+(or cmu scl) (values (ext:weak-pointer-value weak-pointer)) #+clisp (values (ext:weak-pointer-value weak-pointer)) #+ecl (error "not implemented") #+allegro (svref (weak-pointer-pointer weak-pointer) 0) #+openmcl (values (gethash weak-pointer *weak-pointers*)) #+corman (ccl:weak-pointer-obj weak-pointer) #+lispworks (svref (weak-pointer-pointer weak-pointer) 0)) ;;;; Weak Hash-tables ;;; Allegro can apparently create weak hash-tables with both weak keys ;;; and weak values but it's not obvious whether it's an OR or an AND ;;; relation. TODO: figure that out. (defun weakness-keyword-arg (weakness) (declare (ignorable weakness)) #+sbcl :weakness #+(or clisp openmcl) :weak #+lispworks :weak-kind #+allegro (case weakness (:key :weak-keys) (:value :values)) #+cmu :weak-p) (defun weakness-keyword-opt (weakness) (ecase weakness (:key #+(or lispworks sbcl clisp openmcl) :key #+(or allegro cmu) t #-(or lispworks sbcl clisp openmcl allegro cmu) (error "Your Lisp does not support weak key hash-tables.")) (:value #+allegro :weak #+(or clisp openmcl sbcl lispworks) :value #-(or allegro clisp openmcl sbcl lispworks) (error "Your Lisp does not support weak value hash-tables.")) (:key-or-value #+(or clisp sbcl) :key-or-value #+lispworks :either #-(or clisp sbcl lispworks) (error "Your Lisp does not support weak key-or-value hash-tables.")) (:key-and-value #+(or clisp sbcl) :key-and-value #+lispworks :both #-(or clisp sbcl lispworks) (error "Your Lisp does not support weak key-and-value hash-tables.")))) (defun make-weak-hash-table (&rest args &key weakness &allow-other-keys) "Returns a new weak hash table. In addition to the standard arguments accepted by CL:MAKE-HASH-TABLE, this function an extra keyword :WEAKNESS that determines the kind of weak table it should create. WEAKNESS can be one of :KEY, :VALUE, :KEY-OR-VALUE, :KEY-AND-VALUE. TG::MAKE-HASH-TABLE is available as an alias for this function should you wish to import it into your package and shadow CL:MAKE-HASH-TABLE." (remf args :weakness) (if weakness (apply #'cl:make-hash-table (weakness-keyword-arg weakness) (weakness-keyword-opt weakness) args) (apply #'cl:make-hash-table args))) ;;; If you want to use this function to override CL:MAKE-HASH-TABLE, ;;; it's necessary to shadow-import it. For example: ;;; ;;; (defpackage #:foo ;;; (:use #:common-lisp #:trivial-garbage) ;;; (:shadowing-import-from #:trivial-garbage #:make-hash-table)) ;;; (defun make-hash-table (&rest args) (apply #'make-weak-hash-table args)) (defun hash-table-weakness (ht) "Returns one of NIL, :KEY, :VALUE, :KEY-OR-VALUE or :KEY-AND-VALUE." #-(or allegro sbcl clisp cmu openmcl lispworks) (declare (ignore ht)) ;; keep this first if any of the other lisps bugously insert a NIL ;; for the returned (values) even when *read-suppress* is NIL (e.g. clisp) #.(if (find :sbcl *features*) (if (find-symbol "HASH-TABLE-WEAKNESS" "SB-EXT") (read-from-string "(sb-ext:hash-table-weakness ht)") nil) (values)) #+allegro (cond ((excl:hash-table-weak-keys ht) :key) ((eq (excl:hash-table-values ht) :weak) :value)) #+clisp (ext:hash-table-weak-p ht) #+cmu (if (lisp::hash-table-weak-p ht) :key nil) #+openmcl (ccl::hash-table-weak-p ht) #+lispworks (system::hash-table-weak-kind ht)) ;;;; Finalizers ;;; The fact that SBCL/CMUCL throw away the object *before* running ;;; the finalizer is somewhat unfortunate... ;;; Note: Lispworks can't finalize gensyms. #+(or allegro clisp lispworks openmcl) (defvar *finalizers* (cl:make-hash-table :test 'eq #+allegro :weak-keys #+:allegro t #+(or clisp openmcl) :weak #+lispworks :weak-kind #+(or clisp openmcl lispworks) :key) "Weak hashtable that holds registered finalizers.") #+corman (progn (defvar *finalizers* '() "Weak alist that holds registered finalizers.") (defvar *finalizers-cs* (threads:allocate-critical-section))) #+lispworks (progn (hcl:add-special-free-action 'free-action) (defun free-action (object) (let ((finalizers (gethash object *finalizers*))) (unless (null finalizers) (mapc #'funcall finalizers))))) (defun finalize (object function) "Pushes a new FUNCTION to the OBJECT's list of finalizers. FUNCTION should take no arguments. Returns OBJECT. For portability reasons, FUNCTION should not attempt to look at OBJECT by closing over it because, in some lisps, OBJECT will already have been garbage collected and is therefore not accessible when FUNCTION is invoked." #+(or cmu scl) (ext:finalize object function) #+sbcl (sb-ext:finalize object function) #+ecl (let ((next-fn (ext:get-finalizer object))) (ext:set-finalizer object (lambda (obj) (declare (ignore obj)) (funcall function) (when next-fn (funcall next-fn nil))))) #+allegro (progn (push (excl:schedule-finalization object (lambda (obj) (declare (ignore obj)) (funcall function))) (gethash object *finalizers*)) object) #+clisp ;; The CLISP code used to be a bit simpler but we had to workaround ;; a bug regarding the interaction between GC and weak hashtables. ;; See <http://article.gmane.org/gmane.lisp.clisp.general/11028> ;; and <http://article.gmane.org/gmane.lisp.cffi.devel/994>. (multiple-value-bind (finalizers presentp) (gethash object *finalizers* (cons 'finalizers nil)) (unless presentp (setf (gethash object *finalizers*) finalizers) (ext:finalize object (lambda (obj) (declare (ignore obj)) (mapc #'funcall (cdr finalizers))))) (push function (cdr finalizers)) object) #+openmcl (progn (ccl:terminate-when-unreachable object (lambda (obj) (declare (ignore obj)) (funcall function))) ;; store number of finalizers (incf (gethash object *finalizers* 0)) object) #+corman (flet ((get-finalizers (obj) (assoc obj *finalizers* :test #'eq :key #'ccl:weak-pointer-obj))) (threads:with-synchronization *finalizers-cs* (let ((pair (get-finalizers object))) (if (null pair) (push (list (ccl:make-weak-pointer object) function) *finalizers*) (push function (cdr pair))))) (ccl:register-finalization object (lambda (obj) (threads:with-synchronization *finalizers-cs* (mapc #'funcall (cdr (get-finalizers obj))) (setq *finalizers* (delete obj *finalizers* :test #'eq :key #'ccl:weak-pointer-obj))))) object) #+lispworks (progn (let ((finalizers (gethash object *finalizers*))) (unless finalizers (hcl:flag-special-free-action object)) (setf (gethash object *finalizers*) (cons function finalizers))) object)) (defun cancel-finalization (object) "Cancels all of OBJECT's finalizers, if any." #+cmu (ext:cancel-finalization object) #+scl (ext:cancel-finalization object nil) #+sbcl (sb-ext:cancel-finalization object) #+ecl (ext:set-finalizer object nil) #+allegro (progn (mapc #'excl:unschedule-finalization (gethash object *finalizers*)) (remhash object *finalizers*)) #+clisp (multiple-value-bind (finalizers present-p) (gethash object *finalizers*) (when present-p (setf (cdr finalizers) nil)) (remhash object *finalizers*)) #+openmcl (let ((count (gethash object *finalizers*))) (unless (null count) (dotimes (i count) (ccl:cancel-terminate-when-unreachable object)))) #+corman (threads:with-synchronization *finalizers-cs* (setq *finalizers* (delete object *finalizers* :test #'eq :key #'ccl:weak-pointer-obj))) #+lispworks (progn (remhash object *finalizers*) (hcl:flag-not-special-free-action object)))
10,758
Common Lisp
.lisp
273
33.956044
79
0.663575
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
82a4fe37e5dfe598599ec9ed84d3cbf8b4c9417d6cfc5b3d78a729b01e0d16a4
21,530
[ 280216 ]
21,531
tests.lisp
rheaplex_minara/lib/trivial-garbage/tests.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; ;;; tests.lisp --- trivial-garbage tests. ;;; ;;; This software is placed in the public domain by Luis Oliveira ;;; <[email protected]> and is provided with absolutely no ;;; warranty. (defpackage #:trivial-garbage-tests (:use #:cl #:trivial-garbage #:regression-test) (:nicknames #:tg-tests)) (in-package #:trivial-garbage-tests) ;;;; Weak Pointers (deftest pointers.1 (weak-pointer-p (make-weak-pointer 42)) t) (deftest pointers.2 (weak-pointer-value (make-weak-pointer 42)) 42) ;;;; Weak Hashtables #+(or sbcl corman scl) (progn (pushnew 'hashtables.weak-key.1 rt::*expected-failures*) (pushnew 'hashtables.weak-key.2 rt::*expected-failures*)) (deftest hashtables.weak-key.1 (let ((ht (make-weak-hash-table :weakness :key))) (values (hash-table-p ht) (hash-table-weakness ht))) t :key) (deftest hashtables.weak-key.2 (let ((ht (make-weak-hash-table :weakness :key :test 'eq))) (values (hash-table-p ht) (hash-table-weakness ht))) t :key) #+(or sbcl cmu corman scl) (pushnew 'hashtables.weak-value.1 rt::*expected-failures*) (deftest hashtables.weak-value.1 (let ((ht (make-weak-hash-table :weakness :value))) (values (hash-table-p ht) (hash-table-weakness ht))) t :value) (deftest hashtables.not-weak.1 (hash-table-weakness (make-hash-table)) nil) ;;;; Finalizers ;;; ;;; These tests are, of course, not very reliable. (defun dummy (x) (declare (ignore x)) nil) (defun test-finalizers-aux (count extra-action) (let ((cons (list 0)) (obj (string (gensym)))) (dotimes (i count) (finalize obj (lambda () (incf (car cons))))) (when extra-action (cancel-finalization obj) (when (eq extra-action :add-again) (dotimes (i count) (finalize obj (lambda () (incf (car cons))))))) (setq obj (gensym)) (setq obj (dummy obj)) cons)) (defvar *result*) ;;; I don't really understand this, but it seems to work, and stems ;;; from the observation that typing the code in sequence at the REPL ;;; achieves the desired result. Superstition at its best. (defmacro voodoo (string) `(funcall (compile nil `(lambda () (eval (let ((*package* (find-package :tg-tests))) (read-from-string ,,string))))))) (defun test-finalizers (count &optional remove) (gc :full t) (voodoo (format nil "(setq *result* (test-finalizers-aux ~S ~S))" count remove)) (voodoo "(gc :full t)") (voodoo "(car *result*)")) (deftest finalizers.1 (test-finalizers 1) 1) (deftest finalizers.2 (test-finalizers 1 t) 0) (deftest finalizers.3 (test-finalizers 5) 5) (deftest finalizers.4 (test-finalizers 5 t) 0) (deftest finalizers.5 (test-finalizers 5 :add-again) 5)
2,881
Common Lisp
.lisp
92
26.978261
69
0.652567
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
d2e135161cd9fc80a063b9b5e119e1bff18d30697a091f09cc276cf4d28eec42
21,531
[ 460576 ]
21,535
tf-sbcl.lisp
rheaplex_minara/lib/trivial-features/src/tf-sbcl.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; ;;; tf-sbcl.lisp --- SBCL trivial-features implementation. ;;; ;;; Copyright (C) 2007, Luis Oliveira <[email protected]> ;;; ;;; Permission is hereby granted, free of charge, to any person ;;; obtaining a copy of this software and associated documentation ;;; files (the "Software"), to deal in the Software without ;;; restriction, including without limitation the rights to use, copy, ;;; modify, merge, publish, distribute, sublicense, and/or sell copies ;;; of the Software, and to permit persons to whom the Software is ;;; furnished to do so, subject to the following conditions: ;;; ;;; The above copyright notice and this permission notice shall be ;;; included in all copies or substantial portions of the Software. ;;; ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT ;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, ;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ;;; DEALINGS IN THE SOFTWARE. (in-package :cl-user) ;;;; Endianness (pushnew (sb-alien:with-alien ((ptr (array (sb-alien:unsigned 8) 2))) (setf (sb-sys:sap-ref-16 (sb-alien:alien-sap ptr) 0) #xfeff) (ecase (sb-sys:sap-ref-8 (sb-alien:alien-sap ptr) 0) (#xfe (intern "BIG-ENDIAN" :keyword)) (#xff (intern "LITTLE-ENDIAN" :keyword)))) *features*) ;;;; OS ;;; SBCL already pushes :DARWIN, :LINUX, :BSD and :UNIX. #+win32 (progn (setq *features* (remove :unix *features*)) ; bad idea? (pushnew :windows *features*)) ;;;; CPU ;;; SBCL already pushes: :X86, :X86-64, and :PPC
1,892
Common Lisp
.lisp
41
43.463415
71
0.703201
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
4f257cab3ef833bd897a4f312c1f5794d73a54dccd0832f5584b4138d45024e5
21,535
[ 455321 ]
21,536
tf-ecl.lisp
rheaplex_minara/lib/trivial-features/src/tf-ecl.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; ;;; tf-ecl.lisp --- ECL implementation of trivial-features. ;;; ;;; Copyright (C) 2007, Luis Oliveira <[email protected]> ;;; ;;; Permission is hereby granted, free of charge, to any person ;;; obtaining a copy of this software and associated documentation ;;; files (the "Software"), to deal in the Software without ;;; restriction, including without limitation the rights to use, copy, ;;; modify, merge, publish, distribute, sublicense, and/or sell copies ;;; of the Software, and to permit persons to whom the Software is ;;; furnished to do so, subject to the following conditions: ;;; ;;; The above copyright notice and this permission notice shall be ;;; included in all copies or substantial portions of the Software. ;;; ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT ;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, ;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ;;; DEALINGS IN THE SOFTWARE. (in-package :cl-user) ;;;; Endianness (pushnew (let ((ptr (ffi:allocate-foreign-object :unsigned-short))) (unwind-protect (progn (setf (ffi:deref-pointer ptr :unsigned-short) #xfeff) (ecase (ffi:deref-pointer ptr :unsigned-byte) (#xfe (intern "BIG-ENDIAN" "KEYWORD")) (#xff (intern "LITTLE-ENDIAN" "KEYWORD")))) (ffi:free-foreign-object ptr))) *features*) ;;;; OS ;;; ECL already pushes :DARWIN, :LINUX, :UNIX (except on Darwin) and :BSD. #+darwin (pushnew :unix *features*) #+win32 (pushnew :windows *features*) ;;;; CPU ;;; FIXME: add more #+powerpc7450 (pushnew :ppc *features*) #+x86_64 (pushnew :x86-64 *features*)
2,037
Common Lisp
.lisp
44
42.272727
74
0.689169
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
32a653780f4beff302a876c60ac16cb9b03fd7058e94316e7feaa18b77677d7b
21,536
[ 130529 ]
21,545
package.lisp
rheaplex_minara/lib/alexandria/package.lisp
(defpackage :alexandria.0.dev (:nicknames :alexandria) (:use :cl) (:export ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; BLESSED ;; ;; Binding constructs #:if-let #:when-let #:when-let* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; REVIEW IN PROGRESS ;; ;; Control flow #:cswitch #:eswitch #:switch #:multiple-value-prog2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; REVIEW PENDING ;; #:nth-value-or #:whichever #:xor ;; Definitions #:define-constant ;; Hash tables #:alist-hash-table #:copy-hash-table #:ensure-gethash #:hash-table-alist #:hash-table-keys #:hash-table-plist #:hash-table-values #:maphash-keys #:maphash-values #:plist-hash-table ;; Functions #:compose #:conjoin #:curry #:disjoin #:ensure-function #:multiple-value-compose #:named-lambda #:rcurry ;; Lists #:alist-plist #:appendf #:nconcf #:reversef #:nreversef #:circular-list #:circular-list-p #:circular-tree-p #:doplist #:ensure-car #:ensure-cons #:ensure-list #:flatten #:lastcar #:make-circular-list #:map-product #:mappend #:nunionf #:plist-alist #:proper-list #:proper-list-length #:proper-list-p #:remove-from-plist #:remove-from-plistf #:delete-from-plist #:delete-from-plistf #:set-equal #:setp #:unionf ;; Numbers #:binomial-coefficient #:clamp #:count-permutations #:factorial #:gaussian-random #:iota #:lerp #:map-iota #:maxf #:mean #:median #:minf #:standard-deviation #:subfactorial #:variance ;; Arrays #:array-index #:array-length #:copy-array ;; Sequences #:copy-sequence #:deletef #:emptyp #:ends-with #:ends-with-subseq #:first-elt #:last-elt #:map-combinations #:map-derangements #:map-permutations #:proper-sequence #:random-elt #:removef #:rotate #:sequence-of-length-p #:length= #:shuffle #:starts-with #:starts-with-subseq ;; Macros #:once-only #:parse-body #:parse-ordinary-lambda-list #:with-gensyms #:with-unique-names ;; Symbols #:ensure-symbol #:format-symbol #:make-gensym #:make-gensym-list #:make-keyword ;; Strings #:string-designator ;; Types #:negative-double-float #:negative-fixnum-p #:negative-float #:negative-float-p #:negative-long-float #:negative-long-float-p #:negative-rational #:negative-rational-p #:negative-real #:negative-single-float-p #:non-negative-double-float #:non-negative-double-float-p #:non-negative-fixnum #:non-negative-fixnum-p #:non-negative-float #:non-negative-float-p #:non-negative-integer-p #:non-negative-long-float #:non-negative-rational #:non-negative-real-p #:non-negative-short-float-p #:non-negative-single-float #:non-negative-single-float-p #:non-positive-double-float #:non-positive-double-float-p #:non-positive-fixnum #:non-positive-fixnum-p #:non-positive-float #:non-positive-float-p #:non-positive-integer #:non-positive-rational #:non-positive-real #:non-positive-real-p #:non-positive-short-float #:non-positive-short-float-p #:non-positive-single-float-p #:ordinary-lambda-list-keywords #:positive-double-float #:positive-double-float-p #:positive-fixnum #:positive-fixnum-p #:positive-float #:positive-float-p #:positive-integer #:positive-rational #:positive-real #:positive-real-p #:positive-short-float #:positive-short-float-p #:positive-single-float #:positive-single-float-p #:coercef #:negative-double-float-p #:negative-fixnum #:negative-integer #:negative-integer-p #:negative-real-p #:negative-short-float #:negative-short-float-p #:negative-single-float #:non-negative-integer #:non-negative-long-float-p #:non-negative-rational-p #:non-negative-real #:non-negative-short-float #:non-positive-integer-p #:non-positive-long-float #:non-positive-long-float-p #:non-positive-rational-p #:non-positive-single-float #:of-type #:positive-integer-p #:positive-long-float #:positive-long-float-p #:positive-rational-p #:type= ;; Conditions #:required-argument #:ignore-some-conditions #:simple-style-warning #:simple-reader-error #:simple-parse-error #:simple-program-error #:unwind-protect-case ;; Features #:featurep ;; io #:with-input-from-file #:with-output-to-file #:read-file-into-string #:write-string-into-file #:copy-stream #:copy-file ;; new additions collected at the end #:symbolicate ))
4,831
Common Lisp
.lisp
228
17.210526
75
0.632631
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
39ecfb036558fea1f1435c6559cbd64cfc2c00b44583f1aa5e173505258123a0
21,545
[ -1 ]
21,546
types.lisp
rheaplex_minara/lib/alexandria/types.lisp
(in-package :alexandria) (deftype array-index (&optional (length array-dimension-limit)) "Type designator for an index into array of LENGTH: an integer between 0 (inclusive) and LENGTH (exclusive). LENGTH defaults to ARRAY-DIMENSION-LIMIT." `(integer 0 (,length))) (deftype array-length (&optional (length array-dimension-limit)) "Type designator for a dimension of an array of LENGTH: an integer between 0 (inclusive) and LENGTH (inclusive). LENGTH defaults to ARRAY-DIMENSION-LIMIT." `(integer 0 ,length)) ;; This MACROLET will generate most of CDR5 (http://cdr.eurolisp.org/document/5/) ;; except the RATIO related definitions and ARRAY-INDEX. (macrolet ((frob (type &optional (base-type type)) (let ((subtype-names (list)) (predicate-names (list))) (flet ((make-subtype-name (format-control) (let ((result (format-symbol :alexandria format-control (symbol-name type)))) (push result subtype-names) result)) (make-predicate-name (sybtype-name) (let ((result (format-symbol :alexandria "~A-P" (symbol-name sybtype-name)))) (push result predicate-names) result)) (make-docstring (range-beg range-end range-type) (let ((inf (ecase range-type (:negative "-inf") (:positive "+inf")))) (format nil "Type specifier denoting the ~(~A~) range from ~A to ~A." type (if (equal range-beg ''*) inf (ensure-car range-beg)) (if (equal range-end ''*) inf (ensure-car range-end)))))) (let* ((negative-name (make-subtype-name "NEGATIVE-~A")) (non-positive-name (make-subtype-name "NON-POSITIVE-~A")) (non-negative-name (make-subtype-name "NON-NEGATIVE-~A")) (positive-name (make-subtype-name "POSITIVE-~A")) (negative-p-name (make-predicate-name negative-name)) (non-positive-p-name (make-predicate-name non-positive-name)) (non-negative-p-name (make-predicate-name non-negative-name)) (positive-p-name (make-predicate-name positive-name)) (negative-extremum) (positive-extremum) (below-zero) (above-zero) (zero)) (setf (values negative-extremum below-zero above-zero positive-extremum zero) (ecase type (fixnum (values 'most-negative-fixnum -1 1 'most-positive-fixnum 0)) (integer (values ''* -1 1 ''* 0)) (rational (values ''* '(0) '(0) ''* 0)) (real (values ''* '(0) '(0) ''* 0)) (float (values ''* '(0.0E0) '(0.0E0) ''* 0.0E0)) (short-float (values ''* '(0.0S0) '(0.0S0) ''* 0.0S0)) (single-float (values ''* '(0.0F0) '(0.0F0) ''* 0.0F0)) (double-float (values ''* '(0.0D0) '(0.0D0) ''* 0.0D0)) (long-float (values ''* '(0.0L0) '(0.0L0) ''* 0.0L0)))) `(progn (deftype ,negative-name () ,(make-docstring negative-extremum below-zero :negative) `(,',base-type ,,negative-extremum ,',below-zero)) (deftype ,non-positive-name () ,(make-docstring negative-extremum zero :negative) `(,',base-type ,,negative-extremum ,',zero)) (deftype ,non-negative-name () ,(make-docstring zero positive-extremum :positive) `(,',base-type ,',zero ,,positive-extremum)) (deftype ,positive-name () ,(make-docstring above-zero positive-extremum :positive) `(,',base-type ,',above-zero ,,positive-extremum)) (declaim (inline ,@predicate-names)) (defun ,negative-p-name (n) (and (typep n ',type) (< n ,zero))) (defun ,non-positive-p-name (n) (and (typep n ',type) (<= n ,zero))) (defun ,non-negative-p-name (n) (and (typep n ',type) (<= ,zero n))) (defun ,positive-p-name (n) (and (typep n ',type) (< ,zero n))))))))) (frob fixnum integer) (frob integer) (frob rational) (frob real) (frob float) (frob short-float) (frob single-float) (frob double-float) (frob long-float)) (defun of-type (type) "Returns a function of one argument, which returns true when its argument is of TYPE." (lambda (thing) (typep thing type))) (define-compiler-macro of-type (&whole form type &environment env) ;; This can yeild a big benefit, but no point inlining the function ;; all over the place if TYPE is not constant. (if (constantp type env) (with-gensyms (thing) `(lambda (,thing) (typep ,thing ,type))) form)) (declaim (inline type=)) (defun type= (type1 type2) "Returns a primary value of T is TYPE1 and TYPE2 are the same type, and a secondary value that is true is the type equality could be reliably determined: primary value of NIL and secondary value of T indicates that the types are not equivalent." (multiple-value-bind (sub ok) (subtypep type1 type2) (cond ((and ok sub) (subtypep type2 type1)) (ok (values nil ok)) (t (multiple-value-bind (sub ok) (subtypep type2 type1) (declare (ignore sub)) (values nil ok)))))) (define-modify-macro coercef (type-spec) coerce "Modify-macro for COERCE.")
5,821
Common Lisp
.lisp
122
36.131148
95
0.550317
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
bb51d37bc781576999e1819a583e27465e60828cd7d5a3c1ec2ea23522c739b5
21,546
[ -1 ]
21,547
io.lisp
rheaplex_minara/lib/alexandria/io.lisp
;; Copyright (c) 2002-2006, Edward Marco Baringer ;; All rights reserved. (in-package :alexandria) (eval-when (:compile-toplevel :load-toplevel :execute) (defun %expand-with-input/output-file (body direction stream-name file-name &rest args &key external-format &allow-other-keys) (remove-from-plistf args :external-format) (with-unique-names (body-fn) (once-only (external-format) `(flet ((,body-fn (,stream-name) ,@body)) ;; this is needed not to screw up the default external-format when not specified (if ,external-format (with-open-file (,stream-name ,file-name :direction ,direction :external-format ,external-format ,@args) (,body-fn ,stream-name)) (with-open-file (,stream-name ,file-name :direction ,direction ,@args) (,body-fn ,stream-name)))))))) (defmacro with-input-from-file ((stream-name file-name &rest args &key (direction nil direction-p) &allow-other-keys) &body body) "Evaluate BODY with STREAM-NAME to an input stream on the file FILE-NAME. ARGS is sent as is to the call to OPEN except EXTERNAL-FORMAT, which is only sent to WITH-OPEN-FILE when it's not NIL." (declare (ignore direction)) (when direction-p (error "Can't specifiy :DIRECTION for WITH-INPUT-FROM-FILE.")) (apply '%expand-with-input/output-file body :input stream-name file-name args)) (defmacro with-output-to-file ((stream-name file-name &rest args &key (direction nil direction-p) &allow-other-keys) &body body) "Evaluate BODY with STREAM-NAME to an output stream on the file FILE-NAME. ARGS is sent as is to the call to OPEN except EXTERNAL-FORMAT, which is only sent to WITH-OPEN-FILE when it's not NIL." (declare (ignore direction)) (when direction-p (error "Can't specifiy :DIRECTION for WITH-OUTPUT-TO-FILE.")) (apply '%expand-with-input/output-file body :output stream-name file-name args)) (defun read-file-into-string (pathname &key (buffer-size 4096) external-format) "Return the contents of the file denoted by PATHNAME as a fresh string. The EXTERNAL-FORMAT parameter will be passed directly to WITH-OPEN-FILE unless it's NIL, which means the system default." (with-input-from-file (file-stream pathname :external-format external-format) (let ((*print-pretty* nil)) (with-output-to-string (datum) (let ((buffer (make-array buffer-size :element-type 'character))) (loop :for bytes-read = (read-sequence buffer file-stream) :do (write-sequence buffer datum :start 0 :end bytes-read) :while (= bytes-read buffer-size))))))) (defun write-string-into-file (string pathname &key (if-exists :error) (if-does-not-exist :error) external-format) "Write STRING to PATHNAME. The EXTERNAL-FORMAT parameter will be passed directly to WITH-OPEN-FILE unless it's NIL, which means the system default." (with-output-to-file (file-stream pathname :if-exists if-exists :if-does-not-exist if-does-not-exist :external-format external-format) (write-sequence string file-stream))) (defun copy-file (from to &key (if-to-exists :supersede) (element-type '(unsigned-byte 8)) finish-output) (with-input-from-file (input from :element-type element-type) (with-output-to-file (output to :element-type element-type :if-exists if-to-exists) (copy-stream input output :element-type element-type :finish-output finish-output)))) (defun copy-stream (input output &key (element-type (stream-element-type input)) (buffer-size 4096) (buffer (make-array buffer-size :element-type element-type)) finish-output) "Reads data from INPUT and writes it to OUTPUT. Both INPUT and OUTPUT must be streams, they will be passed to READ-SEQUENCE and WRITE-SEQUENCE and must have compatible element-types." (loop :for bytes-read = (read-sequence buffer input) :while (= bytes-read buffer-size) :do (write-sequence buffer output) :finally (progn (write-sequence buffer output :end bytes-read) (when finish-output (finish-output output)))))
4,651
Common Lisp
.lisp
89
41.561798
91
0.630931
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
997c1d199186f1e6a0716bd629737054b05d125e33507c0788b67d65cdfb0ca5
21,547
[ -1 ]
21,548
symbols.lisp
rheaplex_minara/lib/alexandria/symbols.lisp
(in-package :alexandria) (declaim (inline ensure-symbol)) (defun ensure-symbol (name &optional (package *package*)) "Returns a symbol with name designated by NAME, accessible in package designated by PACKAGE. If symbol is not already accessible in PACKAGE, it is interned there. Returns a secondary value reflecting the status of the symbol in the package, which matches the secondary return value of INTERN. Example: (ENSURE-SYMBOL :CONS :CL) => CL:CONS, :EXTERNAL" (intern (string name) package)) (defun maybe-intern (name package) (values (if package (intern name (if (eq t package) *package* package)) (make-symbol name)))) (declaim (inline format-symbol)) (defun format-symbol (package control &rest arguments) "Constructs a string by applying ARGUMENTS to CONTROL as if by FORMAT, and then creates a symbol named by that string. If PACKAGE is NIL, returns an uninterned symbol, if package is T, returns a symbol interned in the current package, and otherwise returns a symbol interned in the package designated by PACKAGE." (maybe-intern (apply #'format nil control arguments) package)) (defun make-keyword (name) "Interns the string designated by NAME in the KEYWORD package." (intern (string name) :keyword)) (defun make-gensym (name) "If NAME is a non-negative integer, calls GENSYM using it. Otherwise NAME must be a string designator, in which case calls GENSYM using the designated string as the argument." (gensym (if (typep name '(integer 0)) name (string name)))) (defun make-gensym-list (length &optional (x "G")) "Returns a list of LENGTH gensyms, each generated as if with a call to MAKE-GENSYM, using the second (optional, defaulting to \"G\") argument." (let ((g (if (typep x '(integer 0)) x (string x)))) (loop repeat length collect (gensym g)))) (defun symbolicate (&rest things) "Concatenate together the names of some strings and symbols, producing a symbol in the current package." (let* ((length (reduce #'+ things :key (lambda (x) (length (string x))))) (name (make-array length :element-type 'character))) (let ((index 0)) (dolist (thing things (values (intern name))) (let* ((x (string thing)) (len (length x))) (replace name x :start1 index) (incf index len))))))
2,374
Common Lisp
.lisp
50
42.88
85
0.707254
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
e1e9ec1d2e478632ec6b1ee3a4f934341e94d2c48787806b6a697ec0e08e3ebc
21,548
[ 190499 ]
21,550
sequences.lisp
rheaplex_minara/lib/alexandria/sequences.lisp
(in-package :alexandria) ;; Make these inlinable by declaiming them INLINE here and some of them ;; NOTINLINE at the end of the file. Exclude functions that have a compiler ;; macro, because inlining seems to cancel compiler macros (at least on SBCL). (declaim (inline copy-sequence sequence-of-length-p)) (defun rotate-tail-to-head (sequence n) (declare (type (integer 1) n)) (if (listp sequence) (let ((m (mod n (proper-list-length sequence)))) (if (null (cdr sequence)) sequence (let* ((tail (last sequence (+ m 1))) (last (cdr tail))) (setf (cdr tail) nil) (nconc last sequence)))) (let* ((len (length sequence)) (m (mod n len)) (tail (subseq sequence (- len m)))) (replace sequence sequence :start1 m :start2 0) (replace sequence tail) sequence))) (defun rotate-head-to-tail (sequence n) (declare (type (integer 1) n)) (if (listp sequence) (let ((m (mod (1- n) (proper-list-length sequence)))) (if (null (cdr sequence)) sequence (let* ((headtail (nthcdr m sequence)) (tail (cdr headtail))) (setf (cdr headtail) nil) (nconc tail sequence)))) (let* ((len (length sequence)) (m (mod n len)) (head (subseq sequence 0 m))) (replace sequence sequence :start1 0 :start2 m) (replace sequence head :start1 (- len m)) sequence))) (defun rotate (sequence &optional (n 1)) "Returns a sequence of the same type as SEQUENCE, with the elements of SEQUENCE rotated by N: N elements are moved from the end of the sequence to the front if N is positive, and -N elements moved from the front to the end if N is negative. SEQUENCE must be a proper sequence. N must be an integer, defaulting to 1. If absolute value of N is greater then the length of the sequence, the results are identical to calling ROTATE with (* (SIGNUM N) (MOD N (LENGTH SEQUENCE))). The original sequence may be destructively altered, and result sequence may share structure with it." (if (plusp n) (rotate-tail-to-head sequence n) (if (minusp n) (rotate-head-to-tail sequence (- n)) sequence))) (defun shuffle (sequence &key (start 0) end) "Returns a random permutation of SEQUENCE bounded by START and END. Permuted sequence may share storage with the original one. Signals an error if SEQUENCE is not a proper sequence." (declare (fixnum start) (type (or fixnum null) end)) (typecase sequence (list (let* ((end (or end (proper-list-length sequence))) (n (- end start))) (do ((tail (nthcdr start sequence) (cdr tail))) ((zerop n)) (rotatef (car tail) (car (nthcdr (random n) tail))) (decf n)))) (vector (let ((end (or end (length sequence)))) (loop for i from (- end 1) downto start do (rotatef (aref sequence i) (aref sequence (random (+ i 1))))))) (sequence (let ((end (or end (length sequence)))) (loop for i from (- end 1) downto start do (rotatef (elt sequence i) (elt sequence (random (+ i 1)))))))) sequence) (defun random-elt (sequence &key (start 0) end) "Returns a random element from SEQUENCE bounded by START and END. Signals an error if the SEQUENCE is not a proper sequence." (declare (sequence sequence) (fixnum start) (type (or fixnum null) end)) (let ((i (+ start (random (- (or end (if (listp sequence) (proper-list-length sequence) (length sequence))) start))))) (elt sequence i))) (declaim (inline remove/swapped-arguments)) (defun remove/swapped-arguments (sequence item &rest keyword-arguments) (apply #'remove item sequence keyword-arguments)) (define-modify-macro removef (item &rest remove-keywords) remove/swapped-arguments "Modify-macro for REMOVE. Sets place designated by the first argument to the result of calling REMOVE with ITEM, place, and the REMOVE-KEYWORDS.") (declaim (inline delete/swapped-arguments)) (defun delete/swapped-arguments (sequence item &rest keyword-arguments) (apply #'delete item sequence keyword-arguments)) (define-modify-macro deletef (item &rest remove-keywords) delete/swapped-arguments "Modify-macro for DELETE. Sets place designated by the first argument to the result of calling DELETE with ITEM, place, and the REMOVE-KEYWORDS.") (deftype proper-sequence () "Type designator for proper sequences, that is proper lists and sequences that are not lists." `(or proper-list (and (not list) sequence))) (defun emptyp (sequence) "Returns true if SEQUENCE is an empty sequence. Signals an error if SEQUENCE is not a sequence" (etypecase sequence (list (null sequence)) (sequence (zerop (length sequence))))) (defun length= (&rest sequences) "Takes any number of sequences or integers in any order. Returns true iff the length of all the sequences and the integers are equal. Hint: there's a compiler macro that expands into more efficient code if the first argument is a literal integer." (declare (dynamic-extent sequences) (inline sequence-of-length-p) (optimize speed)) (unless (cdr sequences) (error "You must call LENGTH= with at least two arguments")) ;; There's room for optimization here: multiple list arguments could be ;; traversed in parallel. (let* ((first (pop sequences)) (current (if (integerp first) first (length first)))) (declare (type array-index current)) (dolist (el sequences) (if (integerp el) (unless (= el current) (return-from length= nil)) (unless (sequence-of-length-p el current) (return-from length= nil))))) t) (define-compiler-macro length= (&whole form length &rest sequences) (cond ((zerop (length sequences)) form) (t (let ((optimizedp (integerp length))) (with-unique-names (tmp current) (declare (ignorable current)) `(locally (declare (inline sequence-of-length-p)) (let ((,tmp) ,@(unless optimizedp `((,current ,length)))) ,@(unless optimizedp `((unless (integerp ,current) (setf ,current (length ,current))))) (and ,@(loop :for sequence :in sequences :collect `(progn (setf ,tmp ,sequence) (if (integerp ,tmp) (= ,tmp ,(if optimizedp length current)) (sequence-of-length-p ,tmp ,(if optimizedp length current))))))))))))) (defun sequence-of-length-p (sequence length) "Return true if SEQUENCE is a sequence of length LENGTH. Signals an error if SEQUENCE is not a sequence. Returns FALSE for circular lists." (declare (type array-index length) (inline length) (optimize speed)) (etypecase sequence (null (zerop length)) (cons (let ((n (1- length))) (unless (minusp n) (let ((tail (nthcdr n sequence))) (and tail (null (cdr tail))))))) (vector (= length (length sequence))) (sequence (= length (length sequence))))) (defun copy-sequence (type sequence) "Returns a fresh sequence of TYPE, which has the same elements as SEQUENCE." (if (typep sequence type) (copy-seq sequence) (coerce sequence type))) (defun first-elt (sequence) "Returns the first element of SEQUENCE. Signals a type-error if SEQUENCE is not a sequence, or is an empty sequence." ;; Can't just directly use ELT, as it is not guaranteed to signal the ;; type-error. (cond ((consp sequence) (car sequence)) ((and (typep sequence '(and sequence (not list))) (plusp (length sequence))) (elt sequence 0)) (t (error 'type-error :datum sequence :expected-type '(and sequence (not (satisfies emptyp))))))) (defun (setf first-elt) (object sequence) "Sets the first element of SEQUENCE. Signals a type-error if SEQUENCE is not a sequence, is an empty sequence, or if OBJECT cannot be stored in SEQUENCE." ;; Can't just directly use ELT, as it is not guaranteed to signal the ;; type-error. (cond ((consp sequence) (setf (car sequence) object)) ((and (typep sequence '(and sequence (not list))) (plusp (length sequence))) (setf (elt sequence 0) object)) (t (error 'type-error :datum sequence :expected-type '(and sequence (not (satisfies emptyp))))))) (defun last-elt (sequence) "Returns the last element of SEQUENCE. Signals a type-error if SEQUENCE is not a proper sequence, or is an empty sequence." ;; Can't just directly use ELT, as it is not guaranteed to signal the ;; type-error. (let ((len 0)) (cond ((consp sequence) (lastcar sequence)) ((and (typep sequence '(and sequence (not list))) (plusp (setf len (length sequence)))) (elt sequence (1- len))) (t (error 'type-error :datum sequence :expected-type '(and proper-sequence (not (satisfies emptyp)))))))) (defun (setf last-elt) (object sequence) "Sets the last element of SEQUENCE. Signals a type-error if SEQUENCE is not a proper sequence, is an empty sequence, or if OBJECT cannot be stored in SEQUENCE." (let ((len 0)) (cond ((consp sequence) (setf (lastcar sequence) object)) ((and (typep sequence '(and sequence (not list))) (plusp (setf len (length sequence)))) (setf (elt sequence (1- len)) object)) (t (error 'type-error :datum sequence :expected-type '(and proper-sequence (not (satisfies emptyp)))))))) (defun starts-with-subseq (prefix sequence &rest args &key (return-suffix nil) &allow-other-keys) "Test whether the first elements of SEQUENCE are the same (as per TEST) as the elements of PREFIX. If RETURN-SUFFIX is T the functions returns, as a second value, a displaced array pointing to the sequence after PREFIX." (remove-from-plistf args :return-suffix) (let ((sequence-length (length sequence)) (prefix-length (length prefix))) (if (<= prefix-length sequence-length) (let ((mismatch (apply #'mismatch sequence prefix args))) (if mismatch (if (< mismatch prefix-length) (values nil nil) (values t (when return-suffix (make-array (- sequence-length mismatch) :element-type (array-element-type sequence) :displaced-to sequence :displaced-index-offset prefix-length :adjustable nil)))) (values t (when return-suffix (make-array 0 :element-type (array-element-type sequence) :adjustable nil))))) (values nil nil)))) (defun ends-with-subseq (suffix sequence &key (test #'eql)) "Test whether SEQUENCE ends with SUFFIX. In other words: return true if the last (length SUFFIX) elements of SEQUENCE are equal to SUFFIX." (let ((sequence-length (length sequence)) (suffix-length (length suffix))) (when (< sequence-length suffix-length) ;; if SEQUENCE is shorter than SUFFIX, then SEQUENCE can't end with SUFFIX. (return-from ends-with-subseq nil)) (loop for sequence-index from (- sequence-length suffix-length) below sequence-length for suffix-index from 0 below suffix-length when (not (funcall test (elt sequence sequence-index) (elt suffix suffix-index))) do (return-from ends-with-subseq nil) finally (return t)))) (defun starts-with (object sequence &key (test #'eql) (key #'identity)) "Returns true if SEQUENCE is a sequence whose first element is EQL to OBJECT. Returns NIL if the SEQUENCE is not a sequence or is an empty sequence." (funcall test (funcall key (typecase sequence (cons (car sequence)) (sequence (if (plusp (length sequence)) (elt sequence 0) (return-from starts-with nil))) (t (return-from starts-with nil)))) object)) (defun ends-with (object sequence &key (test #'eql) (key #'identity)) "Returns true if SEQUENCE is a sequence whose last element is EQL to OBJECT. Returns NIL if the SEQUENCE is not a sequence or is an empty sequence. Signals an error if SEQUENCE is an improper list." (funcall test (funcall key (typecase sequence (cons ;; signals for improper lists (lastcar sequence)) (sequence ;; Can't use last-elt, as that signals an error ;; for empty sequences (let ((len (length sequence))) (if (plusp len) (elt sequence (1- len)) (return-from ends-with nil)))) (t (return-from ends-with nil)))) object)) (defun map-combinations (function sequence &key (start 0) end length (copy t)) "Calls FUNCTION with each combination of LENGTH constructable from the elements of the subsequence of SEQUENCE delimited by START and END. START defaults to 0, END to length of SEQUENCE, and LENGTH to the length of the delimited subsequence. (So unless LENGTH is specified there is only a single combination, which has the same elements as the delimited subsequence.) If COPY is true (the default) each combination is freshly allocated. If COPY is false all combinations are EQ to each other, in which case consequences are specified if a combination is modified by FUNCTION." (let* ((end (or end (length sequence))) (size (- end start)) (length (or length size)) (combination (subseq sequence 0 length)) (function (ensure-function function))) (if (= length size) (funcall function combination) (flet ((call () (funcall function (if copy (copy-seq combination) combination)))) (etypecase sequence ;; When dealing with lists we prefer walking back and ;; forth instead of using indexes. (list (labels ((combine-list (c-tail o-tail) (if (not c-tail) (call) (do ((tail o-tail (cdr tail))) ((not tail)) (setf (car c-tail) (car tail)) (combine-list (cdr c-tail) (cdr tail)))))) (combine-list combination (nthcdr start sequence)))) (vector (labels ((combine (count start) (if (zerop count) (call) (loop for i from start below end do (let ((j (- count 1))) (setf (aref combination j) (aref sequence i)) (combine j (+ i 1))))))) (combine length start))) (sequence (labels ((combine (count start) (if (zerop count) (call) (loop for i from start below end do (let ((j (- count 1))) (setf (elt combination j) (elt sequence i)) (combine j (+ i 1))))))) (combine length start))))))) sequence) (defun map-permutations (function sequence &key (start 0) end length (copy t)) "Calls function with each permutation of LENGTH constructable from the subsequence of SEQUENCE delimited by START and END. START defaults to 0, END to length of the sequence, and LENGTH to the length of the delimited subsequence." (let* ((end (or end (length sequence))) (size (- end start)) (length (or length size))) (labels ((permute (seq n) (let ((n-1 (- n 1))) (if (zerop n-1) (funcall function (if copy (copy-seq seq) seq)) (loop for i from 0 upto n-1 do (permute seq n-1) (if (evenp n-1) (rotatef (elt seq 0) (elt seq n-1)) (rotatef (elt seq i) (elt seq n-1))))))) (permute-sequence (seq) (permute seq length))) (if (= length size) ;; Things are simple if we need to just permute the ;; full START-END range. (permute-sequence (subseq sequence start end)) ;; Otherwise we need to generate all the combinations ;; of LENGTH in the START-END range, and then permute ;; a copy of the result: can't permute the combination ;; directly, as they share structure with each other. (let ((permutation (subseq sequence 0 length))) (flet ((permute-combination (combination) (permute-sequence (replace permutation combination)))) (declare (dynamic-extent #'permute-combination)) (map-combinations #'permute-combination sequence :start start :end end :length length :copy nil))))))) (defun map-derangements (function sequence &key (start 0) end (copy t)) "Calls FUNCTION with each derangement of the subsequence of SEQUENCE denoted by the bounding index designators START and END. Derangement is a permutation of the sequence where no element remains in place. SEQUENCE is not modified, but individual derangements are EQ to each other. Consequences are unspecified if calling FUNCTION modifies either the derangement or SEQUENCE." (let* ((end (or end (length sequence))) (size (- end start)) ;; We don't really care about the elements here. (derangement (subseq sequence 0 size)) ;; Bitvector that has 1 for elements that have been deranged. (mask (make-array size :element-type 'bit :initial-element 0))) (declare (dynamic-extent mask)) ;; ad hoc algorith (labels ((derange (place n) ;; Perform one recursive step in deranging the ;; sequence: PLACE is index of the original sequence ;; to derange to another index, and N is the number of ;; indexes not yet deranged. (if (zerop n) (funcall function (if copy (copy-seq derangement) derangement)) ;; Itarate over the indexes I of the subsequence to ;; derange: if I != PLACE and I has not yet been ;; deranged by an earlier call put the element from ;; PLACE to I, mark I as deranged, and recurse, ;; finally removing the mark. (loop for i from 0 below size do (unless (or (= place (+ i start)) (not (zerop (bit mask i)))) (setf (elt derangement i) (elt sequence place) (bit mask i) 1) (derange (1+ place) (1- n)) (setf (bit mask i) 0)))))) (derange start size) sequence))) (declaim (notinline sequence-of-length-p))
20,715
Common Lisp
.lisp
433
35.547344
100
0.572557
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
422c8dd90f1d43db473cd42c739236755394154b8d44f9a3f7366c9f68ff54fe
21,550
[ -1 ]
21,551
tests.lisp
rheaplex_minara/lib/alexandria/tests.lisp
(in-package :cl-user) (defpackage :alexandria-tests (:use :cl :alexandria #+sbcl :sb-rt #-sbcl :rtest) (:import-from #+sbcl :sb-rt #-sbcl :rtest #:*compile-tests* #:*expected-failures*)) (in-package :alexandria-tests) (defun run-tests (&key ((:compiled *compile-tests))) (do-tests)) ;;;; Arrays (deftest copy-array.1 (let* ((orig (vector 1 2 3)) (copy (copy-array orig))) (values (eq orig copy) (equalp orig copy))) nil t) (deftest copy-array.2 (let ((orig (make-array 1024 :fill-pointer 0))) (vector-push-extend 1 orig) (vector-push-extend 2 orig) (vector-push-extend 3 orig) (let ((copy (copy-array orig))) (values (eq orig copy) (equalp orig copy) (array-has-fill-pointer-p copy) (eql (fill-pointer orig) (fill-pointer copy))))) nil t t t) (deftest array-index.1 (typep 0 'array-index) t) ;;;; Conditions (deftest unwind-protect-case.1 (let (result) (unwind-protect-case () (random 10) (:normal (push :normal result)) (:abort (push :abort result)) (:always (push :always result))) result) (:always :normal)) (deftest unwind-protect-case.2 (let (result) (unwind-protect-case () (random 10) (:always (push :always result)) (:normal (push :normal result)) (:abort (push :abort result))) result) (:normal :always)) (deftest unwind-protect-case.3 (let (result1 result2 result3) (ignore-errors (unwind-protect-case () (error "FOOF!") (:normal (push :normal result1)) (:abort (push :abort result1)) (:always (push :always result1)))) (catch 'foof (unwind-protect-case () (throw 'foof 42) (:normal (push :normal result2)) (:abort (push :abort result2)) (:always (push :always result2)))) (block foof (unwind-protect-case () (return-from foof 42) (:normal (push :normal result3)) (:abort (push :abort result3)) (:always (push :always result3)))) (values result1 result2 result3)) (:always :abort) (:always :abort) (:always :abort)) (deftest unwind-protect-case.4 (let (result) (unwind-protect-case (aborted-p) (random 42) (:always (setq result aborted-p))) result) nil) (deftest unwind-protect-case.5 (let (result) (block foof (unwind-protect-case (aborted-p) (return-from foof) (:always (setq result aborted-p)))) result) t) ;;;; Control flow (deftest switch.1 (switch (13 :test =) (12 :oops) (13.0 :yay)) :yay) (deftest switch.2 (switch (13) ((+ 12 2) :oops) ((- 13 1) :oops2) (t :yay)) :yay) (deftest eswitch.1 (let ((x 13)) (eswitch (x :test =) (12 :oops) (13.0 :yay))) :yay) (deftest eswitch.2 (let ((x 13)) (eswitch (x :key 1+) (11 :oops) (14 :yay))) :yay) (deftest cswitch.1 (cswitch (13 :test =) (12 :oops) (13.0 :yay)) :yay) (deftest cswitch.2 (cswitch (13 :key 1-) (12 :yay) (13.0 :oops)) :yay) (deftest whichever.1 (let ((x (whichever 1 2 3))) (and (member x '(1 2 3)) t)) t) (deftest whichever.2 (let* ((a 1) (b 2) (c 3) (x (whichever a b c))) (and (member x '(1 2 3)) t)) t) (deftest xor.1 (xor nil nil 1 nil) 1 t) ;;;; Definitions (deftest define-constant.1 (let ((name (gensym))) (eval `(define-constant ,name "FOO" :test 'equal)) (eval `(define-constant ,name "FOO" :test 'equal)) (values (equal "FOO" (symbol-value name)) (constantp name))) t t) (deftest define-constant.2 (let ((name (gensym))) (eval `(define-constant ,name 13)) (eval `(define-constant ,name 13)) (values (eql 13 (symbol-value name)) (constantp name))) t t) ;;;; Errors ;;; TYPEP is specified to return a generalized boolean and, for ;;; example, ECL exploits this by returning the superclasses of ERROR ;;; in this case. (defun errorp (x) (not (null (typep x 'error)))) (deftest required-argument.1 (multiple-value-bind (res err) (ignore-errors (required-argument)) (errorp err)) t) ;;;; Hash tables (deftest ensure-hash-table.1 (let ((table (make-hash-table)) (x (list 1))) (multiple-value-bind (value already-there) (ensure-gethash x table 42) (and (= value 42) (not already-there) (= 42 (gethash x table)) (multiple-value-bind (value2 already-there2) (ensure-gethash x table 13) (and (= value2 42) already-there2 (= 42 (gethash x table))))))) t) #+clisp (pushnew 'copy-hash-table.1 *expected-failures*) (deftest copy-hash-table.1 (let ((orig (make-hash-table :test 'eq :size 123)) (foo "foo")) (setf (gethash orig orig) t (gethash foo orig) t) (let ((eq-copy (copy-hash-table orig)) (eql-copy (copy-hash-table orig :test 'eql)) (equal-copy (copy-hash-table orig :test 'equal)) ;; CLISP overflows the stack with this bit. ;; See <http://sourceforge.net/tracker/index.php?func=detail&aid=2029069&group_id=1355&atid=101355>. #-clisp (equalp-copy (copy-hash-table orig :test 'equalp))) (list (eql (hash-table-size eq-copy) (hash-table-size orig)) (eql (hash-table-rehash-size eq-copy) (hash-table-rehash-size orig)) (hash-table-count eql-copy) (gethash orig eq-copy) (gethash (copy-seq foo) eql-copy) (gethash foo eql-copy) (gethash (copy-seq foo) equal-copy) (gethash "FOO" equal-copy) #-clisp (gethash "FOO" equalp-copy)))) (t t 2 t nil t t nil t)) (deftest copy-hash-table.2 (let ((ht (make-hash-table)) (list (list :list (vector :A :B :C)))) (setf (gethash 'list ht) list) (let* ((shallow-copy (copy-hash-table ht)) (deep1-copy (copy-hash-table ht :key 'copy-list)) (list (gethash 'list ht)) (shallow-list (gethash 'list shallow-copy)) (deep1-list (gethash 'list deep1-copy))) (list (eq ht shallow-copy) (eq ht deep1-copy) (eq list shallow-list) (eq list deep1-list) ; outer list was copied. (eq (second list) (second shallow-list)) (eq (second list) (second deep1-list)) ; inner vector wasn't copied. ))) (nil nil t nil t t)) (deftest maphash-keys.1 (let ((keys nil) (table (make-hash-table))) (declare (notinline maphash-keys)) (dotimes (i 10) (setf (gethash i table) t)) (maphash-keys (lambda (k) (push k keys)) table) (set-equal keys '(0 1 2 3 4 5 6 7 8 9))) t) (deftest maphash-values.1 (let ((vals nil) (table (make-hash-table))) (declare (notinline maphash-values)) (dotimes (i 10) (setf (gethash i table) (- i))) (maphash-values (lambda (v) (push v vals)) table) (set-equal vals '(0 -1 -2 -3 -4 -5 -6 -7 -8 -9))) t) (deftest hash-table-keys.1 (let ((table (make-hash-table))) (dotimes (i 10) (setf (gethash i table) t)) (set-equal (hash-table-keys table) '(0 1 2 3 4 5 6 7 8 9))) t) (deftest hash-table-values.1 (let ((table (make-hash-table))) (dotimes (i 10) (setf (gethash (gensym) table) i)) (set-equal (hash-table-values table) '(0 1 2 3 4 5 6 7 8 9))) t) (deftest hash-table-alist.1 (let ((table (make-hash-table))) (dotimes (i 10) (setf (gethash i table) (- i))) (let ((alist (hash-table-alist table))) (list (length alist) (assoc 0 alist) (assoc 3 alist) (assoc 9 alist) (assoc nil alist)))) (10 (0 . 0) (3 . -3) (9 . -9) nil)) (deftest hash-table-plist.1 (let ((table (make-hash-table))) (dotimes (i 10) (setf (gethash i table) (- i))) (let ((plist (hash-table-plist table))) (list (length plist) (getf plist 0) (getf plist 2) (getf plist 7) (getf plist nil)))) (20 0 -2 -7 nil)) #+clisp (pushnew 'alist-hash-table.1 *expected-failures*) (deftest alist-hash-table.1 (let* ((alist '((0 a) (1 b) (2 c))) (table (alist-hash-table alist))) (list (hash-table-count table) (gethash 0 table) (gethash 1 table) (gethash 2 table) (hash-table-test table))) ; CLISP returns EXT:FASTHASH-EQL. (3 (a) (b) (c) eql)) #+clisp (pushnew 'plist-hash-table.1 *expected-failures*) (deftest plist-hash-table.1 (let* ((plist '(:a 1 :b 2 :c 3)) (table (plist-hash-table plist :test 'eq))) (list (hash-table-count table) (gethash :a table) (gethash :b table) (gethash :c table) (gethash 2 table) (gethash nil table) (hash-table-test table))) ; CLISP returns EXT:FASTHASH-EQ. (3 1 2 3 nil nil eq)) ;;;; Functions (deftest disjoin.1 (let ((disjunction (disjoin (lambda (x) (and (consp x) :cons)) (lambda (x) (and (stringp x) :string))))) (list (funcall disjunction 'zot) (funcall disjunction '(foo bar)) (funcall disjunction "test"))) (nil :cons :string)) (deftest conjoin.1 (let ((conjunction (conjoin #'consp (lambda (x) (stringp (car x))) (lambda (x) (char (car x) 0))))) (list (funcall conjunction 'zot) (funcall conjunction '(foo)) (funcall conjunction '("foo")))) (nil nil #\f)) (deftest compose.1 (let ((composite (compose '1+ (lambda (x) (* x 2)) #'read-from-string))) (funcall composite "1")) 3) (deftest compose.2 (let ((composite (locally (declare (notinline compose)) (compose '1+ (lambda (x) (* x 2)) #'read-from-string)))) (funcall composite "2")) 5) (deftest compose.3 (let ((compose-form (funcall (compiler-macro-function 'compose) '(compose '1+ (lambda (x) (* x 2)) #'read-from-string) nil))) (let ((fun (funcall (compile nil `(lambda () ,compose-form))))) (funcall fun "3"))) 7) (deftest multiple-value-compose.1 (let ((composite (multiple-value-compose #'truncate (lambda (x y) (values y x)) (lambda (x) (with-input-from-string (s x) (values (read s) (read s))))))) (multiple-value-list (funcall composite "2 7"))) (3 1)) (deftest multiple-value-compose.2 (let ((composite (locally (declare (notinline multiple-value-compose)) (multiple-value-compose #'truncate (lambda (x y) (values y x)) (lambda (x) (with-input-from-string (s x) (values (read s) (read s)))))))) (multiple-value-list (funcall composite "2 11"))) (5 1)) (deftest multiple-value-compose.3 (let ((compose-form (funcall (compiler-macro-function 'multiple-value-compose) '(multiple-value-compose #'truncate (lambda (x y) (values y x)) (lambda (x) (with-input-from-string (s x) (values (read s) (read s))))) nil))) (let ((fun (funcall (compile nil `(lambda () ,compose-form))))) (multiple-value-list (funcall fun "2 9")))) (4 1)) (deftest curry.1 (let ((curried (curry '+ 3))) (funcall curried 1 5)) 9) (deftest curry.2 (let ((curried (locally (declare (notinline curry)) (curry '* 2 3)))) (funcall curried 7)) 42) (deftest curry.3 (let ((curried-form (funcall (compiler-macro-function 'curry) '(curry '/ 8) nil))) (let ((fun (funcall (compile nil `(lambda () ,curried-form))))) (funcall fun 2))) 4) (deftest rcurry.1 (let ((r (rcurry '/ 2))) (funcall r 8)) 4) (deftest named-lambda.1 (let ((fac (named-lambda fac (x) (if (> x 1) (* x (fac (- x 1))) x)))) (funcall fac 5)) 120) (deftest named-lambda.2 (let ((fac (named-lambda fac (&key x) (if (> x 1) (* x (fac :x (- x 1))) x)))) (funcall fac :x 5)) 120) ;;;; Lists (deftest alist-plist.1 (alist-plist '((a . 1) (b . 2) (c . 3))) (a 1 b 2 c 3)) (deftest plist-alist.1 (plist-alist '(a 1 b 2 c 3)) ((a . 1) (b . 2) (c . 3))) (deftest unionf.1 (let* ((list (list 1 2 3)) (orig list)) (unionf list (list 1 2 4)) (values (equal orig (list 1 2 3)) (eql (length list) 4) (set-difference list (list 1 2 3 4)) (set-difference (list 1 2 3 4) list))) t t nil nil) (deftest nunionf.1 (let ((list (list 1 2 3))) (nunionf list (list 1 2 4)) (values (eql (length list) 4) (set-difference (list 1 2 3 4) list) (set-difference list (list 1 2 3 4)))) t nil nil) (deftest appendf.1 (let* ((list (list 1 2 3)) (orig list)) (appendf list '(4 5 6) '(7 8)) (list list (eq list orig))) ((1 2 3 4 5 6 7 8) nil)) (deftest nconcf.1 (let ((list1 (list 1 2 3)) (list2 (list 4 5 6))) (nconcf list1 list2 (list 7 8 9)) list1) (1 2 3 4 5 6 7 8 9)) (deftest circular-list.1 (let ((circle (circular-list 1 2 3))) (list (first circle) (second circle) (third circle) (fourth circle) (eq circle (nthcdr 3 circle)))) (1 2 3 1 t)) (deftest circular-list-p.1 (let* ((circle (circular-list 1 2 3 4)) (tree (list circle circle)) (dotted (cons circle t)) (proper (list 1 2 3 circle)) (tailcirc (list* 1 2 3 circle))) (list (circular-list-p circle) (circular-list-p tree) (circular-list-p dotted) (circular-list-p proper) (circular-list-p tailcirc))) (t nil nil nil t)) (deftest circular-list-p.2 (circular-list-p 'foo) nil) (deftest circular-tree-p.1 (let* ((circle (circular-list 1 2 3 4)) (tree1 (list circle circle)) (tree2 (let* ((level2 (list 1 nil 2)) (level1 (list level2))) (setf (second level2) level1) level1)) (dotted (cons circle t)) (proper (list 1 2 3 circle)) (tailcirc (list* 1 2 3 circle)) (quite-proper (list 1 2 3)) (quite-dotted (list 1 (cons 2 3)))) (list (circular-tree-p circle) (circular-tree-p tree1) (circular-tree-p tree2) (circular-tree-p dotted) (circular-tree-p proper) (circular-tree-p tailcirc) (circular-tree-p quite-proper) (circular-tree-p quite-dotted))) (t t t t t t nil nil)) (deftest proper-list-p.1 (let ((l1 (list 1)) (l2 (list 1 2)) (l3 (cons 1 2)) (l4 (list (cons 1 2) 3)) (l5 (circular-list 1 2))) (list (proper-list-p l1) (proper-list-p l2) (proper-list-p l3) (proper-list-p l4) (proper-list-p l5))) (t t nil t nil)) (deftest proper-list-p.2 (proper-list-p '(1 2 . 3)) nil) (deftest proper-list.type.1 (let ((l1 (list 1)) (l2 (list 1 2)) (l3 (cons 1 2)) (l4 (list (cons 1 2) 3)) (l5 (circular-list 1 2))) (list (typep l1 'proper-list) (typep l2 'proper-list) (typep l3 'proper-list) (typep l4 'proper-list) (typep l5 'proper-list))) (t t nil t nil)) (deftest proper-list-length.1 (values (proper-list-length nil) (proper-list-length (list 1)) (proper-list-length (list 2 2)) (proper-list-length (list 3 3 3)) (proper-list-length (list 4 4 4 4)) (proper-list-length (list 5 5 5 5 5)) (proper-list-length (list 6 6 6 6 6 6)) (proper-list-length (list 7 7 7 7 7 7 7)) (proper-list-length (list 8 8 8 8 8 8 8 8)) (proper-list-length (list 9 9 9 9 9 9 9 9 9))) 0 1 2 3 4 5 6 7 8 9) (deftest proper-list-length.2 (flet ((plength (x) (handler-case (proper-list-length x) (type-error () :ok)))) (values (plength (list* 1)) (plength (list* 2 2)) (plength (list* 3 3 3)) (plength (list* 4 4 4 4)) (plength (list* 5 5 5 5 5)) (plength (list* 6 6 6 6 6 6)) (plength (list* 7 7 7 7 7 7 7)) (plength (list* 8 8 8 8 8 8 8 8)) (plength (list* 9 9 9 9 9 9 9 9 9)))) :ok :ok :ok :ok :ok :ok :ok :ok :ok) (deftest lastcar.1 (let ((l1 (list 1)) (l2 (list 1 2))) (list (lastcar l1) (lastcar l2))) (1 2)) (deftest lastcar.error.2 (handler-case (progn (lastcar (circular-list 1 2 3)) nil) (error () t)) t) (deftest setf-lastcar.1 (let ((l (list 1 2 3 4))) (values (lastcar l) (progn (setf (lastcar l) 42) (lastcar l)))) 4 42) (deftest setf-lastcar.2 (let ((l (circular-list 1 2 3))) (multiple-value-bind (res err) (ignore-errors (setf (lastcar l) 4)) (typep err 'type-error))) t) (deftest make-circular-list.1 (let ((l (make-circular-list 3 :initial-element :x))) (setf (car l) :y) (list (eq l (nthcdr 3 l)) (first l) (second l) (third l) (fourth l))) (t :y :x :x :y)) (deftest circular-list.type.1 (let* ((l1 (list 1 2 3)) (l2 (circular-list 1 2 3)) (l3 (list* 1 2 3 l2))) (list (typep l1 'circular-list) (typep l2 'circular-list) (typep l3 'circular-list))) (nil t t)) (deftest ensure-list.1 (let ((x (list 1)) (y 2)) (list (ensure-list x) (ensure-list y))) ((1) (2))) (deftest ensure-cons.1 (let ((x (cons 1 2)) (y nil) (z "foo")) (values (ensure-cons x) (ensure-cons y) (ensure-cons z))) (1 . 2) (nil) ("foo")) (deftest setp.1 (setp '(1)) t) (deftest setp.2 (setp nil) t) (deftest setp.3 (setp "foo") nil) (deftest setp.4 (setp '(1 2 3 1)) nil) (deftest setp.5 (setp '(1 2 3)) t) (deftest setp.6 (setp '(a :a)) t) (deftest setp.7 (setp '(a :a) :key 'character) nil) (deftest setp.8 (setp '(a :a) :key 'character :test (constantly nil)) t) (deftest set-equal.1 (set-equal '(1 2 3) '(3 1 2)) t) (deftest set-equal.2 (set-equal '("Xa") '("Xb") :test (lambda (a b) (eql (char a 0) (char b 0)))) t) (deftest set-equal.3 (set-equal '(1 2) '(4 2)) nil) (deftest set-equal.4 (set-equal '(a b c) '(:a :b :c) :key 'string :test 'equal) t) (deftest set-equal.5 (set-equal '(a d c) '(:a :b :c) :key 'string :test 'equal) nil) (deftest set-equal.6 (set-equal '(a b c) '(a b c d)) nil) (deftest map-product.1 (map-product 'cons '(2 3) '(1 4)) ((2 . 1) (2 . 4) (3 . 1) (3 . 4))) (deftest map-product.2 (map-product #'cons '(2 3) '(1 4)) ((2 . 1) (2 . 4) (3 . 1) (3 . 4))) (deftest flatten.1 (flatten '((1) 2 (((3 4))) ((((5)) 6)) 7)) (1 2 3 4 5 6 7)) (deftest remove-from-plist.1 (let ((orig '(a 1 b 2 c 3 d 4))) (list (remove-from-plist orig 'a 'c) (remove-from-plist orig 'b 'd) (remove-from-plist orig 'b) (remove-from-plist orig 'a) (remove-from-plist orig 'd 42 "zot") (remove-from-plist orig 'a 'b 'c 'd) (remove-from-plist orig 'a 'b 'c 'd 'x) (equal orig '(a 1 b 2 c 3 d 4)))) ((b 2 d 4) (a 1 c 3) (a 1 c 3 d 4) (b 2 c 3 d 4) (a 1 b 2 c 3) nil nil t)) (deftest mappend.1 (mappend (compose 'list '*) '(1 2 3) '(1 2 3)) (1 4 9)) ;;;; Numbers (deftest clamp.1 (list (clamp 1.5 1 2) (clamp 2.0 1 2) (clamp 1.0 1 2) (clamp 3 1 2) (clamp 0 1 2)) (1.5 2.0 1.0 2 1)) (deftest gaussian-random.1 (let ((min -0.2) (max +0.2)) (multiple-value-bind (g1 g2) (gaussian-random min max) (values (<= min g1 max) (<= min g2 max) (/= g1 g2) ;uh ))) t t t) (deftest iota.1 (iota 3) (0 1 2)) (deftest iota.2 (iota 3 :start 0.0d0) (0.0d0 1.0d0 2.0d0)) (deftest iota.3 (iota 3 :start 2 :step 3.0) (2.0 5.0 8.0)) (deftest map-iota.1 (let (all) (declare (notinline map-iota)) (values (map-iota (lambda (x) (push x all)) 3 :start 2 :step 1.1d0) all)) 3 (4.2d0 3.1d0 2.0d0)) (deftest lerp.1 (lerp 0.5 1 2) 1.5) (deftest lerp.2 (lerp 0.1 1 2) 1.1) (deftest mean.1 (mean '(1 2 3)) 2) (deftest mean.2 (mean '(1 2 3 4)) 5/2) (deftest mean.3 (mean '(1 2 10)) 13/3) (deftest median.1 (median '(100 0 99 1 98 2 97)) 97) (deftest median.2 (median '(100 0 99 1 98 2 97 96)) 195/2) (deftest variance.1 (variance (list 1 2 3)) 2/3) (deftest standard-deviation.1 (< 0 (standard-deviation (list 1 2 3)) 1) t) (deftest maxf.1 (let ((x 1)) (maxf x 2) x) 2) (deftest maxf.2 (let ((x 1)) (maxf x 0) x) 1) (deftest maxf.3 (let ((x 1) (c 0)) (maxf x (incf c)) (list x c)) (1 1)) (deftest maxf.4 (let ((xv (vector 0 0 0)) (p 0)) (maxf (svref xv (incf p)) (incf p)) (list p xv)) (2 #(0 2 0))) (deftest minf.1 (let ((y 1)) (minf y 0) y) 0) (deftest minf.2 (let ((xv (vector 10 10 10)) (p 0)) (minf (svref xv (incf p)) (incf p)) (list p xv)) (2 #(10 2 10))) ;;;; Arrays #+nil (deftest array-index.type) #+nil (deftest copy-array) ;;;; Sequences (deftest rotate.1 (list (rotate (list 1 2 3) 0) (rotate (list 1 2 3) 1) (rotate (list 1 2 3) 2) (rotate (list 1 2 3) 3) (rotate (list 1 2 3) 4)) ((1 2 3) (3 1 2) (2 3 1) (1 2 3) (3 1 2))) (deftest rotate.2 (list (rotate (vector 1 2 3 4) 0) (rotate (vector 1 2 3 4)) (rotate (vector 1 2 3 4) 2) (rotate (vector 1 2 3 4) 3) (rotate (vector 1 2 3 4) 4) (rotate (vector 1 2 3 4) 5)) (#(1 2 3 4) #(4 1 2 3) #(3 4 1 2) #(2 3 4 1) #(1 2 3 4) #(4 1 2 3))) (deftest rotate.3 (list (rotate (list 1 2 3) 0) (rotate (list 1 2 3) -1) (rotate (list 1 2 3) -2) (rotate (list 1 2 3) -3) (rotate (list 1 2 3) -4)) ((1 2 3) (2 3 1) (3 1 2) (1 2 3) (2 3 1))) (deftest rotate.4 (list (rotate (vector 1 2 3 4) 0) (rotate (vector 1 2 3 4) -1) (rotate (vector 1 2 3 4) -2) (rotate (vector 1 2 3 4) -3) (rotate (vector 1 2 3 4) -4) (rotate (vector 1 2 3 4) -5)) (#(1 2 3 4) #(2 3 4 1) #(3 4 1 2) #(4 1 2 3) #(1 2 3 4) #(2 3 4 1))) (deftest rotate.5 (values (rotate (list 1) 17) (rotate (list 1) -5)) (1) (1)) (deftest shuffle.1 (let ((s (shuffle (iota 100)))) (list (equal s (iota 100)) (every (lambda (x) (member x s)) (iota 100)) (every (lambda (x) (typep x '(integer 0 99))) s))) (nil t t)) (deftest shuffle.2 (let ((s (shuffle (coerce (iota 100) 'vector)))) (list (equal s (coerce (iota 100) 'vector)) (every (lambda (x) (find x s)) (iota 100)) (every (lambda (x) (typep x '(integer 0 99))) s))) (nil t t)) (deftest random-elt.1 (let ((s1 #(1 2 3 4)) (s2 '(1 2 3 4))) (list (dotimes (i 1000 nil) (unless (member (random-elt s1) s2) (return nil)) (when (/= (random-elt s1) (random-elt s1)) (return t))) (dotimes (i 1000 nil) (unless (member (random-elt s2) s2) (return nil)) (when (/= (random-elt s2) (random-elt s2)) (return t))))) (t t)) (deftest removef.1 (let* ((x '(1 2 3)) (x* x) (y #(1 2 3)) (y* y)) (removef x 1) (removef y 3) (list x x* y y*)) ((2 3) (1 2 3) #(1 2) #(1 2 3))) (deftest deletef.1 (let* ((x (list 1 2 3)) (x* x) (y (vector 1 2 3))) (deletef x 2) (deletef y 1) (list x x* y)) ((1 3) (1 3) #(2 3))) (deftest map-permutations.1 (let ((seq (list 1 2 3)) (seen nil) (ok t)) (map-permutations (lambda (s) (unless (set-equal s seq) (setf ok nil)) (when (member s seen :test 'equal) (setf ok nil)) (push s seen)) seq :copy t) (values ok (length seen))) t 6) (deftest proper-sequence.type.1 (mapcar (lambda (x) (typep x 'proper-sequence)) (list (list 1 2 3) (vector 1 2 3) #2a((1 2) (3 4)) (circular-list 1 2 3 4))) (t t nil nil)) (deftest emptyp.1 (mapcar #'emptyp (list (list 1) (circular-list 1) nil (vector) (vector 1))) (nil nil t t nil)) (deftest sequence-of-length-p.1 (mapcar #'sequence-of-length-p (list nil #() (list 1) (vector 1) (list 1 2) (vector 1 2) (list 1 2) (vector 1 2) (list 1 2) (vector 1 2)) (list 0 0 1 1 2 2 1 1 4 4)) (t t t t t t nil nil nil nil)) (deftest length=.1 (mapcar #'length= (list nil #() (list 1) (vector 1) (list 1 2) (vector 1 2) (list 1 2) (vector 1 2) (list 1 2) (vector 1 2)) (list 0 0 1 1 2 2 1 1 4 4)) (t t t t t t nil nil nil nil)) (deftest length=.2 ;; test the compiler macro (macrolet ((x (&rest args) (funcall (compile nil `(lambda () (length= ,@args)))))) (list (x 2 '(1 2)) (x '(1 2) '(3 4)) (x '(1 2) 2) (x '(1 2) 2 '(3 4)) (x 1 2 3))) (t t t t nil)) (deftest copy-sequence.1 (let ((l (list 1 2 3)) (v (vector #\a #\b #\c))) (declare (notinline copy-sequence)) (let ((l.list (copy-sequence 'list l)) (l.vector (copy-sequence 'vector l)) (l.spec-v (copy-sequence '(vector fixnum) l)) (v.vector (copy-sequence 'vector v)) (v.list (copy-sequence 'list v)) (v.string (copy-sequence 'string v))) (list (member l (list l.list l.vector l.spec-v)) (member v (list v.vector v.list v.string)) (equal l.list l) (equalp l.vector #(1 2 3)) (eql (upgraded-array-element-type 'fixnum) (array-element-type l.spec-v)) (equalp v.vector v) (equal v.list '(#\a #\b #\c)) (equal "abc" v.string)))) (nil nil t t t t t t)) (deftest first-elt.1 (mapcar #'first-elt (list (list 1 2 3) "abc" (vector :a :b :c))) (1 #\a :a)) (deftest first-elt.error.1 (mapcar (lambda (x) (handler-case (first-elt x) (type-error () :type-error))) (list nil #() 12 :zot)) (:type-error :type-error :type-error :type-error)) (deftest setf-first-elt.1 (let ((l (list 1 2 3)) (s (copy-seq "foobar")) (v (vector :a :b :c))) (setf (first-elt l) -1 (first-elt s) #\x (first-elt v) 'zot) (values l s v)) (-1 2 3) "xoobar" #(zot :b :c)) (deftest setf-first-elt.error.1 (let ((l 'foo)) (multiple-value-bind (res err) (ignore-errors (setf (first-elt l) 4)) (typep err 'type-error))) t) (deftest last-elt.1 (mapcar #'last-elt (list (list 1 2 3) (vector :a :b :c) "FOOBAR" #*001 #*010)) (3 :c #\R 1 0)) (deftest last-elt.error.1 (mapcar (lambda (x) (handler-case (last-elt x) (type-error () :type-error))) (list nil #() 12 :zot (circular-list 1 2 3) (list* 1 2 3 (circular-list 4 5)))) (:type-error :type-error :type-error :type-error :type-error :type-error)) (deftest setf-last-elt.1 (let ((l (list 1 2 3)) (s (copy-seq "foobar")) (b (copy-seq #*010101001))) (setf (last-elt l) '??? (last-elt s) #\? (last-elt b) 0) (values l s b)) (1 2 ???) "fooba?" #*010101000) (deftest setf-last-elt.error.1 (handler-case (setf (last-elt 'foo) 13) (type-error () :type-error)) :type-error) (deftest starts-with.1 (list (starts-with 1 '(1 2 3)) (starts-with 1 #(1 2 3)) (starts-with #\x "xyz") (starts-with 2 '(1 2 3)) (starts-with 3 #(1 2 3)) (starts-with 1 1) (starts-with nil nil)) (t t t nil nil nil nil)) (deftest starts-with.2 (values (starts-with 1 '(-1 2 3) :key '-) (starts-with "foo" '("foo" "bar") :test 'equal) (starts-with "f" '(#\f) :key 'string :test 'equal) (starts-with -1 '(0 1 2) :key #'1+) (starts-with "zot" '("ZOT") :test 'equal)) t t t nil nil) (deftest ends-with.1 (list (ends-with 3 '(1 2 3)) (ends-with 3 #(1 2 3)) (ends-with #\z "xyz") (ends-with 2 '(1 2 3)) (ends-with 1 #(1 2 3)) (ends-with 1 1) (ends-with nil nil)) (t t t nil nil nil nil)) (deftest ends-with.2 (values (ends-with 2 '(0 13 1) :key '1+) (ends-with "foo" (vector "bar" "foo") :test 'equal) (ends-with "X" (vector 1 2 #\X) :key 'string :test 'equal) (ends-with "foo" "foo" :test 'equal)) t t t nil) (deftest ends-with.error.1 (handler-case (ends-with 3 (circular-list 3 3 3 1 3 3)) (type-error () :type-error)) :type-error) (deftest sequences.passing-improper-lists (macrolet ((signals-error-p (form) `(handler-case (progn ,form nil) (type-error (e) t))) (cut (fn &rest args) (with-gensyms (arg) (print`(lambda (,arg) (apply ,fn (list ,@(substitute arg '_ args)))))))) (let ((circular-list (make-circular-list 5 :initial-element :foo)) (dotted-list (list* 'a 'b 'c 'd))) (loop for nth from 0 for fn in (list (cut #'lastcar _) (cut #'rotate _ 3) (cut #'rotate _ -3) (cut #'shuffle _) (cut #'random-elt _) (cut #'last-elt _) (cut #'ends-with :foo _)) nconcing (let ((on-circular-p (signals-error-p (funcall fn circular-list))) (on-dotted-p (signals-error-p (funcall fn dotted-list)))) (when (or (not on-circular-p) (not on-dotted-p)) (append (unless on-circular-p (let ((*print-circle* t)) (list (format nil "No appropriate error signalled when passing ~S to ~Ath entry." circular-list nth)))) (unless on-dotted-p (list (format nil "No appropriate error signalled when passing ~S to ~Ath entry." dotted-list nth))))))))) nil) (deftest with-unique-names.1 (let ((*gensym-counter* 0)) (let ((syms (with-unique-names (foo bar quux) (list foo bar quux)))) (list (find-if #'symbol-package syms) (equal '("FOO0" "BAR1" "QUUX2") (mapcar #'symbol-name syms))))) (nil t)) (deftest with-unique-names.2 (let ((*gensym-counter* 0)) (let ((syms (with-unique-names ((foo "_foo_") (bar -bar-) (quux #\q)) (list foo bar quux)))) (list (find-if #'symbol-package syms) (equal '("_foo_0" "-BAR-1" "q2") (mapcar #'symbol-name syms))))) (nil t)) (deftest with-unique-names.3 (let ((*gensym-counter* 0)) (multiple-value-bind (res err) (ignore-errors (eval '(let ((syms (with-unique-names ((foo "_foo_") (bar -bar-) (quux 42)) (list foo bar quux)))) (list (find-if #'symbol-package syms) (equal '("_foo_0" "-BAR-1" "q2") (mapcar #'symbol-name syms)))))) (errorp err))) t) (deftest once-only.1 (macrolet ((cons1.good (x) (once-only (x) `(cons ,x ,x))) (cons1.bad (x) `(cons ,x ,x))) (let ((y 0)) (list (cons1.good (incf y)) y (cons1.bad (incf y)) y))) ((1 . 1) 1 (2 . 3) 3)) (deftest once-only.2 (macrolet ((cons1 (x) (once-only ((y x)) `(cons ,y ,y)))) (let ((z 0)) (list (cons1 (incf z)) z (cons1 (incf z))))) ((1 . 1) 1 (2 . 2))) (deftest parse-body.1 (parse-body '("doc" "body") :documentation t) ("body") nil "doc") (deftest parse-body.2 (parse-body '("body") :documentation t) ("body") nil nil) (deftest parse-body.3 (parse-body '("doc" "body")) ("doc" "body") nil nil) (deftest parse-body.4 (parse-body '((declare (foo)) "doc" (declare (bar)) body) :documentation t) (body) ((declare (foo)) (declare (bar))) "doc") (deftest parse-body.5 (parse-body '((declare (foo)) "doc" (declare (bar)) body)) ("doc" (declare (bar)) body) ((declare (foo))) nil) (deftest parse-body.6 (multiple-value-bind (res err) (ignore-errors (parse-body '("foo" "bar" "quux") :documentation t)) (errorp err)) t) ;;;; Symbols (deftest ensure-symbol.1 (ensure-symbol :cons :cl) cons :external) (deftest ensure-symbol.2 (ensure-symbol "CONS" :alexandria) cons :inherited) (deftest ensure-symbol.3 (ensure-symbol 'foo :keyword) :foo :external) (deftest ensure-symbol.4 (ensure-symbol #\* :alexandria) * :inherited) (deftest format-symbol.1 (let ((s (format-symbol nil "X-~D" 13))) (list (symbol-package s) (symbol-name s))) (nil "X-13")) (deftest format-symbol.2 (format-symbol :keyword "SYM-~A" :bolic) :sym-bolic) (deftest format-symbol.3 (let ((*package* (find-package :cl))) (format-symbol t "FIND-~A" 'package)) find-package) (deftest make-keyword.1 (list (make-keyword 'zot) (make-keyword "FOO") (make-keyword #\Q)) (:zot :foo :q)) (deftest make-gensym-list.1 (let ((*gensym-counter* 0)) (let ((syms (make-gensym-list 3 "FOO"))) (list (find-if 'symbol-package syms) (equal '("FOO0" "FOO1" "FOO2") (mapcar 'symbol-name syms))))) (nil t)) (deftest make-gensym-list.2 (let ((*gensym-counter* 0)) (let ((syms (make-gensym-list 3))) (list (find-if 'symbol-package syms) (equal '("G0" "G1" "G2") (mapcar 'symbol-name syms))))) (nil t)) ;;;; Type-system (deftest of-type.1 (locally (declare (notinline of-type)) (let ((f (of-type 'string))) (list (funcall f "foo") (funcall f 'bar)))) (t nil)) (deftest type=.1 (type= 'string 'string) t t) (deftest type=.2 (type= 'list '(or null cons)) t t) (deftest type=.3 (type= 'null '(and symbol list)) t t) (deftest type=.4 (type= 'string '(satisfies emptyp)) nil nil) (deftest type=.5 (type= 'string 'list) nil t) (macrolet ((test (type numbers) `(deftest ,(format-symbol t "CDR5.~A" type) (let ((numbers ,numbers)) (values (mapcar (of-type ',(format-symbol t "NEGATIVE-~A" type)) numbers) (mapcar (of-type ',(format-symbol t "NON-POSITIVE-~A" type)) numbers) (mapcar (of-type ',(format-symbol t "NON-NEGATIVE-~A" type)) numbers) (mapcar (of-type ',(format-symbol t "POSITIVE-~A" type)) numbers))) (t t t nil nil nil nil) (t t t t nil nil nil) (nil nil nil t t t t) (nil nil nil nil t t t)))) (test fixnum (list most-negative-fixnum -42 -1 0 1 42 most-positive-fixnum)) (test integer (list (1- most-negative-fixnum) -42 -1 0 1 42 (1+ most-positive-fixnum))) (test rational (list (1- most-negative-fixnum) -42/13 -1 0 1 42/13 (1+ most-positive-fixnum))) (test real (list most-negative-long-float -42/13 -1 0 1 42/13 most-positive-long-float)) (test float (list most-negative-short-float -42.02 -1.0 0.0 1.0 42.02 most-positive-short-float)) (test short-float (list most-negative-short-float -42.02s0 -1.0s0 0.0s0 1.0s0 42.02s0 most-positive-short-float)) (test single-float (list most-negative-single-float -42.02f0 -1.0f0 0.0f0 1.0f0 42.02f0 most-positive-single-float)) (test double-float (list most-negative-double-float -42.02d0 -1.0d0 0.0d0 1.0d0 42.02d0 most-positive-double-float)) (test long-float (list most-negative-long-float -42.02l0 -1.0l0 0.0l0 1.0l0 42.02l0 most-positive-long-float))) ;;;; Bindings (declaim (notinline opaque)) (defun opaque (x) x) (deftest if-let.1 (if-let (x (opaque :ok)) x :bad) :ok) (deftest if-let.2 (if-let (x (opaque nil)) :bad (and (not x) :ok)) :ok) (deftest if-let.3 (let ((x 1)) (if-let ((x 2) (y x)) (+ x y) :oops)) 3) (deftest if-let.4 (if-let ((x 1) (y nil)) :oops (and (not y) x)) 1) (deftest if-let.5 (if-let (x) :oops (not x)) t) (deftest if-let.error.1 (handler-case (eval '(if-let x :oops :oops)) (type-error () :type-error)) :type-error) (deftest when-let.1 (when-let (x (opaque :ok)) (setf x (cons x x)) x) (:ok . :ok)) (deftest when-let.2 (when-let ((x 1) (y nil) (z 3)) :oops) nil) (deftest when-let.3 (let ((x 1)) (when-let ((x 2) (y x)) (+ x y))) 3) (deftest when-let.error.1 (handler-case (eval '(when-let x :oops)) (type-error () :type-error)) :type-error) (deftest when-let*.1 (let ((x 1)) (when-let* ((x 2) (y x)) (+ x y))) 4) (deftest when-let*.2 (let ((y 1)) (when-let* (x y) (1+ x))) 2) (deftest when-let*.3 (when-let* ((x t) (y (consp x)) (z (error "OOPS"))) t) nil) (deftest when-let*.error.1 (handler-case (eval '(when-let* x :oops)) (type-error () :type-error)) :type-error) (deftest nth-value-or.1 (multiple-value-bind (a b c) (nth-value-or 1 (values 1 nil 1) (values 2 2 2)) (= a b c 2)) t) (deftest doplist.1 (let (keys values) (doplist (k v '(a 1 b 2 c 3) (values t (reverse keys) (reverse values) k v)) (push k keys) (push v values))) t (a b c) (1 2 3) nil nil)
42,108
Common Lisp
.lisp
1,450
20.541379
118
0.489704
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
c9ce5e06e4dffb103a7f92220a95bf8b21e0490a1ed588f2041b52e9cdabdc34
21,551
[ -1 ]
21,552
control-flow.lisp
rheaplex_minara/lib/alexandria/control-flow.lisp
(in-package :alexandria) (defun extract-function-name (spec) "Useful for macros that want to mimic the functional interface for functions like #'eq and 'eq." (if (and (consp spec) (member (first spec) '(quote function))) (second spec) spec)) (defun generate-switch-body (whole object clauses test key &optional default) (with-gensyms (value) (setf test (extract-function-name test)) (setf key (extract-function-name key)) (when (and (consp default) (member (first default) '(error cerror))) (setf default `(,@default "No keys match in SWITCH. Testing against ~S with ~S." ,value ',test))) `(let ((,value (,key ,object))) (cond ,@(mapcar (lambda (clause) (if (member (first clause) '(t otherwise)) (progn (when default (error "Multiple default clauses or illegal use of a default clause in ~S." whole)) (setf default `(progn ,@(rest clause))) '(())) (destructuring-bind (key-form &body forms) clause `((,test ,value ,key-form) ,@forms)))) clauses) (t ,default))))) (defmacro switch (&whole whole (object &key (test 'eql) (key 'identity)) &body clauses) "Evaluates first matching clause, returning its values, or evaluates and returns the values of DEFAULT if no keys match." (generate-switch-body whole object clauses test key)) (defmacro eswitch (&whole whole (object &key (test 'eql) (key 'identity)) &body clauses) "Like SWITCH, but signals an error if no key matches." (generate-switch-body whole object clauses test key '(error))) (defmacro cswitch (&whole whole (object &key (test 'eql) (key 'identity)) &body clauses) "Like SWITCH, but signals a continuable error if no key matches." (generate-switch-body whole object clauses test key '(cerror "Return NIL from CSWITCH."))) (defmacro whichever (&rest possibilities &environment env) "Evaluates exactly one of POSSIBILITIES, chosen at random." (setf possibilities (mapcar (lambda (p) (macroexpand p env)) possibilities)) (if (every (lambda (p) (constantp p)) possibilities) `(svref (load-time-value (vector ,@possibilities)) (random ,(length possibilities))) (with-gensyms (function) `(let ((,function (lambda () ,(pop possibilities)))) (declare (function ,function)) ,@(let ((p 1)) (mapcar (lambda (possibility) `(when (zerop (random ,(incf p))) (setf ,function (lambda () ,possibility)))) possibilities)) (funcall ,function))))) (defmacro xor (&rest datums) "Evaluates its argument one at a time, from left to right. If more then one argument evaluates to a true value no further DATUMS are evaluated, and NIL is returned as both primary and secondary value. If exactly one argument evaluates to true, its value is returned as the primary value after all the arguments have been evaluated, and T is returned as the secondary value. If no arguments evaluate to true NIL is retuned as primary, and T as secondary value." (with-gensyms (xor tmp true) `(let (,tmp ,true) (block ,xor ,@(mapcar (lambda (datum) `(if (setf ,tmp ,datum) (if ,true (return-from ,xor (values nil nil)) (setf ,true ,tmp)))) datums) (return-from ,xor (values ,true t)))))) (defmacro nth-value-or (nth-value &body forms) "Evaluates FORM arguments one at a time, until the NTH-VALUE returned by one of the forms is non-NIL. It then returns all the values returned by evaluating that form. If none of the forms return a non-nil nth value, this form returns NIL." (once-only (nth-value) (with-gensyms (values) `(let ((,values (multiple-value-list ,(first forms)))) (if (nth ,nth-value ,values) (values-list ,values) ,(if (rest forms) `(nth-value-or ,nth-value ,@(rest forms)) nil)))))) (defmacro multiple-value-prog2 (first-form second-form &body body) "Like CL:MULTIPLE-VALUE-PROG1, except it saves the values of the second form." `(progn ,first-form (multiple-value-prog1 ,second-form ,@body)))
4,649
Common Lisp
.lisp
92
39.456522
107
0.595427
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
9a75fab3bf5d116c5f7660fbec1d187c95811e07a1f896de6763f8b841c7b261
21,552
[ -1 ]
21,553
conditions.lisp
rheaplex_minara/lib/alexandria/conditions.lisp
(in-package :alexandria) (defun required-argument (&optional name) "Signals an error for a missing argument of NAME. Intended for use as an initialization form for structure and class-slots, and a default value for required keyword arguments." (error "Required argument ~@[~S ~]missing." name)) (define-condition simple-style-warning (style-warning simple-warning) ()) (defun simple-style-warning (message &rest args) (warn 'simple-style-warning :format-control message :format-arguments args)) ;; We don't specify a :report for simple-reader-error to let the ;; underlying implementation report the line and column position for ;; us. Unfortunately this way the message from simple-error is not ;; displayed, unless there's special support for that in the ;; implementation. But even then it's still inspectable from the ;; debugger... (define-condition simple-reader-error #-sbcl(reader-error simple-error) #+sbcl(sb-int:simple-reader-error) ()) (defun simple-reader-error (stream message &rest args) (error 'simple-reader-error :stream stream :format-control message :format-arguments args)) (define-condition simple-parse-error (simple-error parse-error) ()) (defun simple-parse-error (message &rest args) (error 'simple-parse-error :format-control message :format-arguments args)) (define-condition simple-program-error (simple-error program-error) ()) (defun simple-program-error (message &rest args) (error 'simple-program-error :format-control message :format-arguments args)) (defmacro ignore-some-conditions ((&rest conditions) &body body) "Similar to CL:IGNORE-ERRORS but the (unevaluated) CONDITIONS list determines which specific conditions are to be ignored." `(handler-case (progn ,@body) ,@(loop for condition in conditions collect `(,condition (c) (values nil c))))) (defmacro unwind-protect-case ((&optional abort-flag) protected-form &body clauses) "Like CL:UNWIND-PROTECT, but you can specify the circumstances that the cleanup CLAUSES are run. clauses ::= (:NORMAL form*)* | (:ABORT form*)* | (:ALWAYS form*)* Clauses can be given in any order, and more than one clause can be given for each circumstance. The clauses whose denoted circumstance occured, are executed in the order the clauses appear. ABORT-FLAG is the name of a variable that will be bound to T in CLAUSES if the PROTECTED-FORM aborted preemptively, and to NIL otherwise. Examples: (unwind-protect-case () (protected-form) (:normal (format t \"This is only evaluated if PROTECTED-FORM executed normally.~%\")) (:abort (format t \"This is only evaluated if PROTECTED-FORM aborted preemptively.~%\")) (:always (format t \"This is evaluated in either case.~%\"))) (unwind-protect-case (aborted-p) (protected-form) (:always (perform-cleanup-if aborted-p))) " (check-type abort-flag (or null symbol)) (let ((gflag (gensym "FLAG+"))) `(let ((,gflag t)) (unwind-protect (multiple-value-prog1 ,protected-form (setf ,gflag nil)) (let ,(and abort-flag `((,abort-flag ,gflag))) ,@(loop for (cleanup-kind . forms) in clauses collect (ecase cleanup-kind (:normal `(when (not ,gflag) ,@forms)) (:abort `(when ,gflag ,@forms)) (:always `(progn ,@forms)))))))))
3,363
Common Lisp
.lisp
74
41.364865
94
0.718301
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
f21e6e9cb70c039553bc0f87338c1c4fb814511ef7febac32c027ad1ae0af0e4
21,553
[ -1 ]
21,554
numbers.lisp
rheaplex_minara/lib/alexandria/numbers.lisp
(in-package :alexandria) (declaim (inline clamp)) (defun clamp (number min max) "Clamps the NUMBER into [MIN, MAX] range. Returns MIN if NUMBER lesser then MIN and MAX if NUMBER is greater then MAX, otherwise returns NUMBER." (if (< number min) min (if (> number max) max number))) (defun gaussian-random (&optional min max) "Returns two gaussian random double floats as the primary and secondary value, optionally constrained by MIN and MAX. Gaussian random numbers form a standard normal distribution around 0.0d0." (labels ((gauss () (loop for x1 = (- (random 2.0d0) 1.0d0) for x2 = (- (random 2.0d0) 1.0d0) for w = (+ (expt x1 2) (expt x2 2)) when (< w 1.0d0) do (let ((v (sqrt (/ (* -2.0d0 (log w)) w)))) (return (values (* x1 v) (* x2 v)))))) (guard (x min max) (unless (<= min x max) (tagbody :retry (multiple-value-bind (x1 x2) (gauss) (when (<= min x1 max) (setf x x1) (go :done)) (when (<= min x2 max) (setf x x2) (go :done)) (go :retry)) :done)) x)) (multiple-value-bind (g1 g2) (gauss) (values (guard g1 (or min g1) (or max g1)) (guard g2 (or min g2) (or max g2)))))) (declaim (inline iota)) (defun iota (n &key (start 0) (step 1)) "Return a list of n numbers, starting from START (with numeric contagion from STEP applied), each consequtive number being the sum of the previous one and STEP. START defaults to 0 and STEP to 1. Examples: (iota 4) => (0 1 2 3 4) (iota 3 :start 1 :step 1.0) => (1.0 2.0 3.0) (iota 3 :start -1 :step -1/2) => (-1 -3/2 -2) " (declare (type (integer 0) n) (number start step)) (loop repeat n ;; KLUDGE: get numeric contagion right for the first element too for i = (+ start (- step step)) then (+ i step) collect i)) (declaim (inline map-iota)) (defun map-iota (function n &key (start 0) (step 1)) "Calls FUNCTION with N numbers, starting from START (with numeric contagion from STEP applied), each consequtive number being the sum of the previous one and STEP. START defaults to 0 and STEP to 1. Returns N. Examples: (map-iota #'print 3 :start 1 :step 1.0) => 3 ;;; 1.0 ;;; 2.0 ;;; 3.0 " (declare (type (integer 0) n) (number start step)) (loop repeat n ;; KLUDGE: get numeric contagion right for the first element too for i = (+ start (- step step)) then (+ i step) do (funcall function i)) n) (declaim (inline lerp)) (defun lerp (v a b) "Returns the result of linear interpolation between A and B, using the interpolation coefficient V." (+ a (* v (- b a)))) (declaim (inline mean)) (defun mean (sample) "Returns the mean of SAMPLE. SAMPLE must be a sequence of numbers." (/ (reduce #'+ sample) (length sample))) (declaim (inline median)) (defun median (sample) "Returns median of SAMPLE. SAMPLE must be a sequence of real numbers." (let* ((vector (sort (copy-sequence 'vector sample) #'<)) (length (length vector)) (middle (truncate length 2))) (if (oddp length) (aref vector middle) (/ (+ (aref vector middle) (aref vector (1+ middle))) 2)))) (declaim (inline variance)) (defun variance (sample &key (biased t)) "Variance of SAMPLE. Returns the biased variance if BIASED is true (the default), and the unbiased estimator of variance if BIASED is false. SAMPLE must be a sequence of numbers." (let ((mean (mean sample))) (/ (reduce (lambda (a b) (+ a (expt (- b mean) 2))) sample :initial-value 0) (- (length sample) (if biased 0 1))))) (declaim (inline standard-deviation)) (defun standard-deviation (sample &key (biased t)) "Standard deviation of SAMPLE. Returns the biased standard deviation if BIASED is true (the default), and the square root of the unbiased estimator for variance if BIASED is false (which is not the same as the unbiased estimator for standard deviation). SAMPLE must be a sequence of numbers." (sqrt (variance sample :biased biased))) (define-modify-macro maxf (&rest numbers) max "Modify-macro for MAX. Sets place designated by the first argument to the maximum of its original value and NUMBERS.") (define-modify-macro minf (&rest numbers) min "Modify-macro for MIN. Sets place designated by the first argument to the minimum of its original value and NUMBERS.") ;;;; Factorial ;;; KLUDGE: This is really dependant on the numbers in question: for ;;; small numbers this is larger, and vice versa. Ideally instead of a ;;; constant we would have RANGE-FAST-TO-MULTIPLY-DIRECTLY-P. (defconstant +factorial-bisection-range-limit+ 8) ;;; KLUDGE: This is really platform dependant: ideally we would use ;;; (load-time-value (find-good-direct-multiplication-limit)) instead. (defconstant +factorial-direct-multiplication-limit+ 13) (defun %multiply-range (i j) ;; We use a a bit of cleverness here: ;; ;; 1. For large factorials we bisect in order to avoid expensive bignum ;; multiplications: 1 x 2 x 3 x ... runs into bignums pretty soon, ;; and once it does that all further multiplications will be with bignums. ;; ;; By instead doing the multiplication in a tree like ;; ((1 x 2) x (3 x 4)) x ((5 x 6) x (7 x 8)) ;; we manage to get less bignums. ;; ;; 2. Division isn't exactly free either, however, so we don't bisect ;; all the way down, but multiply ranges of integers close to each ;; other directly. ;; ;; For even better results it should be possible to use prime ;; factorization magic, but Nikodemus ran out of steam. ;; ;; KLUDGE: We support factorials of bignums, but it seems quite ;; unlikely anyone would ever be able to use them on a modern lisp, ;; since the resulting numbers are unlikely to fit in memory... but ;; it would be extremely unelegant to define FACTORIAL only on ;; fixnums, _and_ on lisps with 16 bit fixnums this can actually be ;; needed. (labels ((bisect (j k) (declare (type (integer 1 #.most-positive-fixnum) j k)) (if (< (- k j) +factorial-bisection-range-limit+) (multiply-range j k) (let ((middle (+ j (truncate (- k j) 2)))) (* (bisect j middle) (bisect (+ middle 1) k))))) (bisect-big (j k) (declare (type (integer 1) j k)) (if (= j k) j (let ((middle (+ j (truncate (- k j) 2)))) (* (if (<= middle most-positive-fixnum) (bisect j middle) (bisect-big j middle)) (bisect-big (+ middle 1) k))))) (multiply-range (j k) (declare (type (integer 1 #.most-positive-fixnum) j k)) (do ((f k (* f m)) (m (1- k) (1- m))) ((< m j) f) (declare (type (integer 0 (#.most-positive-fixnum)) m) (type unsigned-byte f))))) (bisect i j))) (declaim (inline factorial)) (defun %factorial (n) (if (< n 2) 1 (%multiply-range 1 n))) (defun factorial (n) "Factorial of non-negative integer N." (check-type n (integer 0)) (%factorial n)) ;;;; Combinatorics (defun binomial-coefficient (n k) "Binomial coefficient of N and K, also expressed as N choose K. This is the number of K element combinations given N choises. N must be equal to or greater then K." (check-type n (integer 0)) (check-type k (integer 0)) (assert (>= n k)) (if (or (zerop k) (= n k)) 1 (let ((n-k (- n k))) (if (= 1 n-k) n ;; General case, avoid computing the 1x...xK twice: ;; ;; N! 1x...xN (K+1)x...xN ;; -------- = ---------------- = ------------, N>1 ;; K!(N-K)! 1x...xK x (N-K)! (N-K)! (/ (%multiply-range (+ k 1) n) (%factorial n-k)))))) (defun subfactorial (n) "Subfactorial of the non-negative integer N." (check-type n (integer 0)) (case n (0 1) (1 0) (otherwise (floor (/ (+ 1 (factorial n)) (exp 1)))))) (defun count-permutations (n &optional (k n)) "Number of K element permutations for a sequence of N objects. R defaults to N" ;; FIXME: Use %multiply-range and take care of 1 and 2, plus ;; check types. (/ (factorial n) (factorial (- n k))))
8,755
Common Lisp
.lisp
213
34.187793
83
0.595163
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
27a94470783a53913400487731ba312518d4ca655c76ed3470aaa8e8bf6b090b
21,554
[ -1 ]
21,555
hash-tables.lisp
rheaplex_minara/lib/alexandria/hash-tables.lisp
(in-package :alexandria) (defun copy-hash-table (table &key key test size rehash-size rehash-threshold) "Returns a copy of hash table TABLE, with the same keys and values as the TABLE. The copy has the same properties as the original, unless overridden by the keyword arguments. Before each of the original values is set into the new hash-table, KEY is invoked on the value. As KEY defaults to CL:IDENTITY, a shallow copy is returned by default." (setf key (or key 'identity)) (setf test (or test (hash-table-test table))) (setf size (or size (hash-table-size table))) (setf rehash-size (or rehash-size (hash-table-rehash-size table))) (setf rehash-threshold (or rehash-threshold (hash-table-rehash-threshold table))) (let ((copy (make-hash-table :test test :size size :rehash-size rehash-size :rehash-threshold rehash-threshold))) (maphash (lambda (k v) (setf (gethash k copy) (funcall key v))) table) copy)) (declaim (inline maphash-keys)) (defun maphash-keys (function table) "Like MAPHASH, but calls FUNCTION with each key in the hash table TABLE." (maphash (lambda (k v) (declare (ignore v)) (funcall function k)) table)) (declaim (inline maphash-values)) (defun maphash-values (function table) "Like MAPHASH, but calls FUNCTION with each value in the hash table TABLE." (maphash (lambda (k v) (declare (ignore k)) (funcall function v)) table)) (defun hash-table-keys (table) "Returns a list containing the keys of hash table TABLE." (let ((keys nil)) (maphash-keys (lambda (k) (push k keys)) table) keys)) (defun hash-table-values (table) "Returns a list containing the values of hash table TABLE." (let ((values nil)) (maphash-values (lambda (v) (push v values)) table) values)) (defun hash-table-alist (table) "Returns an association list containing the keys and values of hash table TABLE." (let ((alist nil)) (maphash (lambda (k v) (push (cons k v) alist)) table) alist)) (defun hash-table-plist (table) "Returns a property list containing the keys and values of hash table TABLE." (let ((plist nil)) (maphash (lambda (k v) (setf plist (list* k v plist))) table) plist)) (defun alist-hash-table (alist &rest hash-table-initargs) "Returns a hash table containing the keys and values of the association list ALIST. Hash table is initialized using the HASH-TABLE-INITARGS." (let ((table (apply #'make-hash-table hash-table-initargs))) (dolist (cons alist) (setf (gethash (car cons) table) (cdr cons))) table)) (defun plist-hash-table (plist &rest hash-table-initargs) "Returns a hash table containing the keys and values of the property list PLIST. Hash table is initialized using the HASH-TABLE-INITARGS." (let ((table (apply #'make-hash-table hash-table-initargs))) (do ((tail plist (cddr tail))) ((not tail)) (setf (gethash (car tail) table) (cadr tail))) table)) (defun ensure-gethash (key hash-table &optional default) "Like GETHASH, but if KEY is not found in the HASH-TABLE saves the DEFAULT under key before returning it. Secondary return value is true if key was already in the table." (multiple-value-bind (value ok) (gethash key hash-table) (if ok (values value ok) (values (setf (gethash key hash-table) default) nil))))
3,632
Common Lisp
.lisp
88
34.681818
83
0.659213
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
dd5469cf05ef9dfa2c9d548ae402f004e9e6842978bdb7d9500d0b03a1500de2
21,555
[ -1 ]
21,557
functions.lisp
rheaplex_minara/lib/alexandria/functions.lisp
(in-package :alexandria) (declaim (inline ensure-function)) ; to propagate return type. (declaim (ftype (function (t) (values function &optional)) ensure-function)) (defun ensure-function (function-designator) "Returns the function designated by FUNCTION-DESIGNATOR: if FUNCTION-DESIGNATOR is a function, it is returned, otherwise it must be a function name and its FDEFINITION is returned." (if (functionp function-designator) function-designator (fdefinition function-designator))) (defun disjoin (predicate &rest more-predicates) "Returns a function that applies each of PREDICATE and MORE-PREDICATE functions in turn to its arguments, returning the primary value of the first predicate that returns true, without calling the remaining predicates. If none of the predicates returns true, NIL is returned." (declare (optimize (speed 3) (safety 1) (debug 1))) (let ((predicate (ensure-function predicate)) (more-predicates (mapcar #'ensure-function more-predicates))) (lambda (&rest arguments) (or (apply predicate arguments) (some (lambda (p) (declare (type function p)) (apply p arguments)) more-predicates))))) (defun conjoin (predicate &rest more-predicates) "Returns a function that applies each of PREDICATE and MORE-PREDICATE functions in turn to its arguments, returning NIL if any of the predicates returns false, without calling the remaining predicates. If none of the predicates returns false, returns the primary value of the last predicate." (lambda (&rest arguments) (and (apply predicate arguments) ;; Cannot simply use CL:EVERY because we want to return the ;; non-NIL value of the last predicate if all succeed. (do ((tail (cdr more-predicates) (cdr tail)) (head (car more-predicates) (car tail))) ((not tail) (apply head arguments)) (unless (apply head arguments) (return nil)))))) (defun compose (function &rest more-functions) "Returns a function composed of FUNCTION and MORE-FUNCTIONS that applies its arguments to to each in turn, starting from the rightmost of MORE-FUNCTIONS, and then calling the next one with the primary value of the last." (declare (optimize (speed 3) (safety 1) (debug 1))) (reduce (lambda (f g) (let ((f (ensure-function f)) (g (ensure-function g))) (lambda (&rest arguments) (declare (dynamic-extent arguments)) (funcall f (apply g arguments))))) more-functions :initial-value function)) (define-compiler-macro compose (function &rest more-functions) (labels ((compose-1 (funs) (if (cdr funs) `(funcall ,(car funs) ,(compose-1 (cdr funs))) `(apply ,(car funs) arguments)))) (let* ((args (cons function more-functions)) (funs (make-gensym-list (length args) "COMPOSE"))) `(let ,(loop for f in funs for arg in args collect `(,f (ensure-function ,arg))) (declare (optimize (speed 3) (safety 1) (debug 1))) (lambda (&rest arguments) (declare (dynamic-extent arguments)) ,(compose-1 funs)))))) (defun multiple-value-compose (function &rest more-functions) "Returns a function composed of FUNCTION and MORE-FUNCTIONS that applies its arguments to to each in turn, starting from the rightmost of MORE-FUNCTIONS, and then calling the next one with all the return values of the last." (declare (optimize (speed 3) (safety 1) (debug 1))) (reduce (lambda (f g) (let ((f (ensure-function f)) (g (ensure-function g))) (lambda (&rest arguments) (declare (dynamic-extent arguments)) (multiple-value-call f (apply g arguments))))) more-functions :initial-value function)) (define-compiler-macro multiple-value-compose (function &rest more-functions) (labels ((compose-1 (funs) (if (cdr funs) `(multiple-value-call ,(car funs) ,(compose-1 (cdr funs))) `(apply ,(car funs) arguments)))) (let* ((args (cons function more-functions)) (funs (make-gensym-list (length args) "MV-COMPOSE"))) `(let ,(mapcar #'list funs args) (declare (optimize (speed 3) (safety 1) (debug 1))) (lambda (&rest arguments) (declare (dynamic-extent arguments)) ,(compose-1 funs)))))) (defun curry (function &rest arguments) "Returns a function that applies ARGUMENTS and the arguments it is called with to FUNCTION." (declare (optimize (speed 3) (safety 1) (debug 1))) (let ((fn (ensure-function function))) (lambda (&rest more) (declare (dynamic-extent more)) ;; Using M-V-C we don't need to append the arguments. (multiple-value-call fn (values-list arguments) (values-list more))))) (define-compiler-macro curry (function &rest arguments) (let ((curries (make-gensym-list (length arguments) "CURRY"))) `(let ,(mapcar #'list curries arguments) (declare (optimize (speed 3) (safety 1) (debug 1))) (lambda (&rest more) (apply ,function ,@curries more))))) (defun rcurry (function &rest arguments) "Returns a function that applies the arguments it is called with and ARGUMENTS to FUNCTION." (declare (optimize (speed 3) (safety 1) (debug 1))) (let ((fn (ensure-function function))) (lambda (&rest more) (declare (dynamic-extent more)) (multiple-value-call fn (values-list more) (values-list arguments))))) (defmacro named-lambda (name lambda-list &body body) "Expands into a lambda-expression within whose BODY NAME denotes the corresponding function." `(labels ((,name ,lambda-list ,@body)) #',name))
5,673
Common Lisp
.lisp
120
41.55
78
0.685075
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
5d98323f245d8454c62025c40a9b7d6553a291721225cda4cb2c8fd66f26ea98
21,557
[ -1 ]
21,559
lists.lisp
rheaplex_minara/lib/alexandria/lists.lisp
(in-package :alexandria) (declaim (inline safe-endp)) (defun safe-endp (x) (declare (optimize safety)) (endp x)) (defun alist-plist (alist) "Returns a property list containing the same keys and values as the association list ALIST in the same order." (let (plist) (dolist (pair alist) (push (car pair) plist) (push (cdr pair) plist)) (nreverse plist))) (defun plist-alist (plist) "Returns an association list containing the same keys and values as the property list PLIST in the same order." (let (alist) (do ((tail plist (cddr tail))) ((safe-endp tail) (nreverse alist)) (push (cons (car tail) (cadr tail)) alist)))) (defun malformed-plist (plist) (error "Malformed plist: ~S" plist)) (defmacro doplist ((key val plist &optional values) &body body) "Iterates over elements of PLIST. BODY can be preceded by declarations, and is like a TAGBODY. RETURN may be used to terminate the iteration early. If RETURN is not used, returns VALUES." (multiple-value-bind (forms declarations) (parse-body body) (with-gensyms (tail loop results) `(block nil (flet ((,results () (let (,key ,val) (declare (ignorable ,key ,val)) (return ,values)))) (let* ((,tail ,plist) (,key (if ,tail (pop ,tail) (,results))) (,val (if ,tail (pop ,tail) (malformed-plist ',plist)))) (declare (ignorable ,key ,val)) ,@declarations (tagbody ,loop ,@forms (setf ,key (if ,tail (pop ,tail) (,results)) ,val (if ,tail (pop ,tail) (malformed-plist ',plist))) (go ,loop)))))))) (define-modify-macro appendf (&rest lists) append "Modify-macro for APPEND. Appends LISTS to the place designated by the first argument.") (define-modify-macro nconcf (&rest lists) nconc "Modify-macro for NCONC. Concatenates LISTS to place designated by the first argument.") (define-modify-macro unionf (list) union "Modify-macro for UNION. Saves the union of LIST and the contents of the place designated by the first argument to the designated place.") (define-modify-macro nunionf (list) nunion "Modify-macro for NUNION. Saves the union of LIST and the contents of the place designated by the first argument to the designated place. May modify either argument.") (define-modify-macro reversef () reverse "Modify-macro for REVERSE. Copies and reverses the list stored in the given place and saves back the result into the place.") (define-modify-macro nreversef () nreverse "Modify-macro for NREVERSE. Reverses the list stored in the given place by destructively modifying it and saves back the result into the place.") (defun circular-list (&rest elements) "Creates a circular list of ELEMENTS." (let ((cycle (copy-list elements))) (nconc cycle cycle))) (defun circular-list-p (object) "Returns true if OBJECT is a circular list, NIL otherwise." (and (listp object) (do ((fast object (cddr fast)) (slow (cons (car object) (cdr object)) (cdr slow))) (nil) (unless (and (consp fast) (listp (cdr fast))) (return nil)) (when (eq fast slow) (return t))))) (defun circular-tree-p (object) "Returns true if OBJECT is a circular tree, NIL otherwise." (labels ((circularp (object seen) (and (consp object) (do ((fast (cons (car object) (cdr object)) (cddr fast)) (slow object (cdr slow))) ((or (not (consp fast)) (not (consp (cdr slow)))) (do ((tail object (cdr tail))) ((not (consp tail)) nil) (let ((elt (car tail))) (circularp elt (cons object seen))))) (when (or (eq fast slow) (member slow seen)) (return-from circular-tree-p t)))))) (circularp object nil))) (defun proper-list-p (object) "Returns true if OBJECT is a proper list." (cond ((not object) t) ((consp object) (do ((fast object (cddr fast)) (slow (cons (car object) (cdr object)) (cdr slow))) (nil) (unless (and (listp fast) (consp (cdr fast))) (return (and (listp fast) (not (cdr fast))))) (when (eq fast slow) (return nil)))) (t nil))) (deftype proper-list () "Type designator for proper lists. Implemented as a SATISFIES type, hence not recommended for performance intensive use. Main usefullness as a type designator of the expected type in a TYPE-ERROR." `(and list (satisfies proper-list-p))) (defun circular-list-error (list) (error 'type-error :datum list :expected-type '(and list (not circular-list)))) (macrolet ((def (name lambda-list doc step declare ret1 ret2) (assert (member 'list lambda-list)) `(defun ,name ,lambda-list ,doc (do ((last list fast) (fast list (cddr fast)) (slow (cons (car list) (cdr list)) (cdr slow)) ,@(when step (list step))) (nil) (declare (dynamic-extent slow) ,@(when declare (list declare))) (when (safe-endp fast) (return ,ret1)) (when (safe-endp (cdr fast)) (return ,ret2)) (when (eq fast slow) (circular-list-error list)))))) (def proper-list-length (list) "Returns length of LIST, signalling an error if it is not a proper list." (n 1 (+ n 2)) ;; KLUDGE: Most implementations don't actually support lists with bignum ;; elements -- and this is WAY faster on most implementations then declaring ;; N to be an UNSIGNED-BYTE. (fixnum n) (1- n) n) (def lastcar (list) "Returns the last element of LIST. Signals a type-error if LIST is not a proper list." nil nil (cadr last) (car fast)) (def (setf lastcar) (object list) "Sets the last element of LIST. Signals a type-error if LIST is not a proper list." nil nil (setf (cadr last) object) (setf (car fast) object))) (defun make-circular-list (length &key initial-element) "Creates a circular list of LENGTH with the given INITIAL-ELEMENT." (let ((cycle (make-list length :initial-element initial-element))) (nconc cycle cycle))) (deftype circular-list () "Type designator for circular lists. Implemented as a SATISFIES type, so not recommended for performance intensive use. Main usefullness as the expected-type designator of a TYPE-ERROR." `(satisfies circular-list-p)) (defun ensure-car (thing) "If THING is a CONS, its CAR is returned. Otherwise THING is returned." (if (consp thing) (car thing) thing)) (defun ensure-cons (cons) "If CONS is a cons, it is returned. Otherwise returns a fresh cons with CONS in the car, and NIL in the cdr." (if (consp cons) cons (cons cons nil))) (defun ensure-list (list) "If LIST is a list, it is returned. Otherwise returns the list designated by LIST." (if (listp list) list (list list))) (defun remove-from-plist (plist &rest keys) "Returns a propery-list with same keys and values as PLIST, except that keys in the list designated by KEYS and values corresponding to them are removed. The returned property-list may share structure with the PLIST, but PLIST is not destructively modified. Keys are compared using EQ." (declare (optimize (speed 3))) ;; FIXME: possible optimization: (remove-from-plist '(:x 0 :a 1 :b 2) :a) ;; could return the tail without consing up a new list. (loop for (key . rest) on plist by #'cddr do (assert rest () "Expected a proper plist, got ~S" plist) unless (member key keys :test #'eq) collect key and collect (first rest))) (defun delete-from-plist (plist &rest keys) "Just like REMOVE-FROM-PLIST, but this version may destructively modify the provided plist." ;; FIXME: should not cons (apply 'remove-from-plist plist keys)) (define-modify-macro remove-from-plistf (&rest keys) remove-from-plist) (define-modify-macro delete-from-plistf (&rest keys) delete-from-plist) (declaim (inline sans)) (defun sans (plist &rest keys) "Alias of REMOVE-FROM-PLIST for backward compatibility." (apply #'remove-from-plist plist keys)) (defun mappend (function &rest lists) "Applies FUNCTION to respective element(s) of each LIST, appending all the all the result list to a single list. FUNCTION must return a list." (loop for results in (apply #'mapcar function lists) append results)) (defun setp (object &key (test #'eql) (key #'identity)) "Returns true if OBJECT is a list that denotes a set, NIL otherwise. A list denotes a set if each element of the list is unique under KEY and TEST." (and (listp object) (let (seen) (dolist (elt object t) (let ((key (funcall key elt))) (if (member key seen :test test) (return nil) (push key seen))))))) (defun set-equal (list1 list2 &key (test #'eql) (key nil keyp)) "Returns true if every element of LIST1 matches some element of LIST2 and every element of LIST2 matches some element of LIST1. Otherwise returns false." (let ((keylist1 (if keyp (mapcar key list1) list1)) (keylist2 (if keyp (mapcar key list2) list2))) (and (dolist (elt keylist1 t) (or (member elt keylist2 :test test) (return nil))) (dolist (elt keylist2 t) (or (member elt keylist1 :test test) (return nil)))))) (defun map-product (function list &rest more-lists) "Returns a list containing the results of calling FUNCTION with one argument from LIST, and one from each of MORE-LISTS for each combination of arguments. In other words, returns the product of LIST and MORE-LISTS using FUNCTION. Example: (map-product 'list '(1 2) '(3 4) '(5 6)) => ((1 3 5) (1 3 6) (1 4 5) (1 4 6) (2 3 5) (2 3 6) (2 4 5) (2 4 6)) " (labels ((%map-product (f lists) (let ((more (cdr lists)) (one (car lists))) (if (not more) (mapcar f one) (mappend (lambda (x) (%map-product (curry f x) more)) one))))) (%map-product (ensure-function function) (cons list more-lists)))) (defun flatten (tree) "Traverses the tree in order, collecting non-null leaves into a list." (let (list) (labels ((traverse (subtree) (when subtree (if (consp subtree) (progn (traverse (car subtree)) (traverse (cdr subtree))) (push subtree list))))) (traverse tree)) (nreverse list)))
11,332
Common Lisp
.lisp
265
34.109434
85
0.609957
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
c4487140f870813fa679c1efd94456545c26e9965334f4fd068dd35df9fac0c4
21,559
[ -1 ]
21,560
arrays.lisp
rheaplex_minara/lib/alexandria/arrays.lisp
(in-package :alexandria) (defun copy-array (array &key (element-type (array-element-type array)) (fill-pointer (and (array-has-fill-pointer-p array) (fill-pointer array))) (adjustable (adjustable-array-p array))) "Returns an undisplaced copy of ARRAY, with same fill-pointer and adjustability (if any) as the original, unless overridden by the keyword arguments." (let ((dims (array-dimensions array))) ;; Dictionary entry for ADJUST-ARRAY requires adjusting a ;; displaced array to a non-displaced one to make a copy. (adjust-array (make-array dims :element-type element-type :fill-pointer fill-pointer :adjustable adjustable :displaced-to array) dims)))
813
Common Lisp
.lisp
17
37.588235
70
0.63602
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
e827f460150a03bca27042a63ab8353e311483d2f254ca2d2e0747bd4f73a169
21,560
[ -1 ]
21,562
macros.lisp
rheaplex_minara/lib/alexandria/macros.lisp
(in-package :alexandria) (defmacro with-gensyms (names &body forms) "Binds each variable named by a symbol in NAMES to a unique symbol around FORMS. Each of NAMES must either be either a symbol, or of the form: (symbol string-designator) Bare symbols appearing in NAMES are equivalent to: (symbol symbol) The string-designator is used as the argument to GENSYM when constructing the unique symbol the named variable will be bound to." `(let ,(mapcar (lambda (name) (multiple-value-bind (symbol string) (etypecase name (symbol (values name (symbol-name name))) ((cons symbol (cons string-designator null)) (values (first name) (string (second name))))) `(,symbol (gensym ,string)))) names) ,@forms)) (defmacro with-unique-names (names &body forms) "Alias for WITH-GENSYMS." `(with-gensyms ,names ,@forms)) (defmacro once-only (specs &body forms) "Each SPEC must be either a NAME, or a (NAME INITFORM), with plain NAME using the named variable as initform. Evaluates FORMS with names rebound to temporary variables, ensuring that each is evaluated only once. Example: (defmacro cons1 (x) (once-only (x) `(cons ,x ,x))) (let ((y 0)) (cons1 (incf y))) => (1 . 1)" (let ((gensyms (make-gensym-list (length specs) "ONCE-ONLY")) (names-and-forms (mapcar (lambda (spec) (etypecase spec (list (destructuring-bind (name form) spec (cons name form))) (symbol (cons spec spec)))) specs))) ;; bind in user-macro `(let ,(mapcar (lambda (g n) (list g `(gensym ,(string (car n))))) gensyms names-and-forms) ;; bind in final expansion `(let (,,@(mapcar (lambda (g n) ``(,,g ,,(cdr n))) gensyms names-and-forms)) ;; bind in user-macro ,(let ,(mapcar (lambda (n g) (list (car n) g)) names-and-forms gensyms) ,@forms))))) (defun parse-body (body &key documentation whole) "Parses BODY into (values remaining-forms declarations doc-string). Documentation strings are recognized only if DOCUMENTATION is true. Syntax errors in body are signalled and WHOLE is used in the signal arguments when given." (let ((doc nil) (decls nil) (current nil)) (tagbody :declarations (setf current (car body)) (when (and documentation (stringp current) (cdr body)) (if doc (error "Too many documentation strings in ~S." (or whole body)) (setf doc (pop body))) (go :declarations)) (when (and (listp current) (eql (first current) 'declare)) (push (pop body) decls) (go :declarations))) (values body (nreverse decls) doc))) (defun parse-ordinary-lambda-list (lambda-list) "Parses an ordinary lambda-list, returning as multiple values: 1. Required parameters. 2. Optional parameter specifications, normalized into form (NAME INIT SUPPLIEDP) where SUPPLIEDP is NIL if not present. 3. Name of the rest parameter, or NIL. 4. Keyword parameter specifications, normalized into form ((KEYWORD-NAME NAME) INIT SUPPLIEDP) where SUPPLIEDP is NIL if not present. 5. Boolean indicating &ALLOW-OTHER-KEYS presence. 6. &AUX parameter specifications, normalized into form (NAME INIT). Signals a PROGRAM-ERROR is the lambda-list is malformed." (let ((state :required) (allow-other-keys nil) (auxp nil) (required nil) (optional nil) (rest nil) (keys nil) (aux nil)) (labels ((fail (elt) (simple-program-error "Misplaced ~S in ordinary lambda-list:~% ~S" elt lambda-list)) (check-variable (elt what) (unless (and (symbolp elt) (not (constantp elt))) (simple-program-error "Invalid ~A ~S in ordinary lambda-list:~% ~S" what elt lambda-list))) (check-spec (spec what) (destructuring-bind (init suppliedp) spec (declare (ignore init)) (check-variable suppliedp what)))) (dolist (elt lambda-list) (case elt (&optional (if (eq state :required) (setf state elt) (fail elt))) (&rest (if (member state '(:required &optional)) (setf state elt) (progn (break "state=~S" state) (fail elt)))) (&key (if (member state '(:required &optional :after-rest)) (setf state elt) (fail elt))) (&allow-other-keys (if (eq state '&key) (setf allow-other-keys t state elt) (fail elt))) (&aux (cond ((eq state '&rest) (fail elt)) (auxp (simple-program-error "Multiple ~S in ordinary lambda-list:~% ~S" elt lambda-list)) (t (setf auxp t state elt)) )) (otherwise (when (member elt '#.(set-difference lambda-list-keywords '(&optional &rest &key &allow-other-keys &aux))) (simple-program-error "Bad lambda-list keyword ~S in ordinary lambda-list:~% ~S" elt lambda-list)) (case state (:required (check-variable elt "required parameter") (push elt required)) (&optional (cond ((consp elt) (destructuring-bind (name &rest tail) elt (check-variable name "optional parameter") (if (cdr tail) (check-spec tail "optional-supplied-p parameter") (setf elt (append elt '(nil)))))) (t (check-variable elt "optional parameter") (setf elt (cons elt '(nil nil))))) (push elt optional)) (&rest (check-variable elt "rest parameter") (setf rest elt state :after-rest)) (&key (cond ((consp elt) (destructuring-bind (var-or-kv &rest tail) elt (cond ((consp var-or-kv) (destructuring-bind (keyword var) var-or-kv (unless (symbolp keyword) (simple-program-error "Invalid keyword name ~S in ordinary ~ lambda-list:~% ~S" keyword lambda-list)) (check-variable var "keyword parameter"))) (t (check-variable var-or-kv "keyword parameter") (setf var-or-kv (list (make-keyword var-or-kv) var-or-kv)))) (if (cdr tail) (check-spec tail "keyword-supplied-p parameter") (setf tail (append tail '(nil)))) (setf elt (cons var-or-kv tail)))) (t (check-variable elt "keyword parameter") (setf elt (list (list (make-keyword elt) elt) nil nil)))) (push elt keys)) (&aux (if (consp elt) (destructuring-bind (var &optional init) elt (declare (ignore init)) (check-variable var "&aux parameter")) (check-variable elt "&aux parameter")) (push elt aux)) (t (simple-program-error "Invalid ordinary lambda-list:~% ~S" lambda-list))))))) (values (nreverse required) (nreverse optional) rest (nreverse keys) allow-other-keys (nreverse aux))))
8,486
Common Lisp
.lisp
188
29.920213
96
0.504948
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
d560e22b1bb53059587e17b967a475579f132fece5138698135ef38054ee0a3f
21,562
[ -1 ]
21,563
package.lisp
rheaplex_minara/lib/cl-colors/package.lisp
(defpackage :cl-colors (:use :common-lisp :cl-utilities) (:export rgb red green blue rgba alpha add-alpha hsv hue saturation value rgb->hsv hsv->rgb ->hsv ->rgb convex-combination hue-combination rgb-combination rgba-combination hsv-combination))
272
Common Lisp
.lisp
8
29.875
55
0.731061
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
cc005b20b1c0deb3d18a8f73acd7eecfdea812bad440fc04853aca0db61aea98
21,563
[ -1 ]
21,564
colors.lisp
rheaplex_minara/lib/cl-colors/colors.lisp
(in-package :cl-colors) ;;;; ;;;; rgb ;;;; (defclass rgb () ((red :initform 0 :type (real 0 1) :initarg :red :accessor red) (green :initform 0 :type (real 0 1) :initarg :green :accessor green) (blue :initform 0 :type (real 0 1) :initarg :blue :accessor blue))) (defmethod print-object ((obj rgb) stream) (print-unreadable-object (obj stream :type t) (with-slots (red green blue) obj (format stream "red: ~a green: ~a blue: ~a" red green blue)))) (defmethod make-load-form ((obj rgb) &optional environment) (make-load-form-saving-slots obj :environment environment)) ;;;; ;;;; rgba ;;;; (defclass rgba (rgb) ((alpha :initform 1 :type (real 0 1) :initarg :alpha :accessor alpha))) (defmethod print-object ((obj rgba) stream) (print-unreadable-object (obj stream :type t) (with-slots (red green blue alpha) obj (format stream "red: ~a green: ~a blue: ~a alpha: ~a" red green blue alpha)))) (defgeneric add-alpha (color alpha) (:documentation "Add an alpha channel to a given color.")) (defmethod add-alpha ((color rgb) alpha) (make-instance 'rgba :red (red color) :green (green color) :blue (blue color) :alpha alpha)) ;;;; ;;;; hsv ;;;; (defclass hsv () ((hue :initform 0 :type (real 0 360) :initarg :hue :accessor hue) (saturation :initform 0 :type (real 0 1) :initarg :saturation :accessor saturation) (value :initform 0 :type (real 0 1) :initarg :value :accessor value))) (defmethod print-object ((obj hsv) stream) (print-unreadable-object (obj stream :type t) (with-slots (hue saturation value) obj (format stream "hue: ~a saturation: ~a value: ~a" hue saturation value)))) (defun normalize-hue (hue) "Normalize hue into the interval [0,360)." (mod hue 360)) ;;;; ;;;; conversions ;;;; (defun rgb->hsv (rgb &optional (undefined-hue 0)) "Convert RGB to HSV representation. When hue is undefined \(saturation is zero), undefined-hue will be assigned." (with-slots (red green blue) rgb (let* ((value (max red green blue)) (delta (- value (min red green blue))) (saturation (if (plusp value) (/ delta value) 0))) (flet ((normalize (constant right left) (let ((hue (+ constant (/ (* 60 (- right left)) delta)))) (if (minusp hue) (+ hue 360) hue)))) (make-instance 'hsv :hue (cond ((zerop saturation) undefined-hue) ; undefined ((= red value) (normalize 0 green blue)) ; dominant red ((= green value) (normalize 120 blue red)) ; dominant green (t (normalize 240 red green))) :saturation saturation :value value))))) (defun hsv->rgb (hsv) "Convert HSV to RGB representation. When saturation is zero, hue is ignored." (with-slots (hue saturation value) hsv ;; if saturation=0, color is on the gray line (when (zerop saturation) (return-from hsv->rgb (make-instance 'rgb :red value :green value :blue value))) ;; nonzero saturation: normalize hue to [0,6) (let ((h (/ (normalize-hue hue) 60))) (multiple-value-bind (quotient remainder) (floor h) (let ((p (* value (- 1 saturation))) (q (* value (- 1 (* saturation remainder)))) (r (* value (- 1 (* saturation (- 1 remainder)))))) (multiple-value-bind (red green blue) (case quotient (0 (values value r p)) (1 (values q value p)) (2 (values p value r)) (3 (values p q value)) (4 (values r p value)) (t (values value p q))) (make-instance 'rgb :red red :green green :blue blue))))))) ;;;; ;;;; conversion with generic functions ;;;; (defgeneric ->hsv (color &optional undefined-hue)) (defmethod ->hsv ((color rgb) &optional (undefined-hue 0)) (rgb->hsv color undefined-hue)) (defmethod ->hsv ((color hsv) &optional undefined-hue) (declare (ignore undefined-hue)) color) (defgeneric ->rgb (color)) (defmethod ->rgb ((color rgb)) color) (defmethod ->rgb ((color hsv)) (hsv->rgb color)) ;;;; ;;;; convex combinations ;;;; (defun convex-combination (a b alpha) "Convex combination (1-alpha*a+alpha*b." (declare ((real 0 1) alpha)) (+ (* (- 1 alpha) a) (* alpha b))) (defun hue-combination (hue1 hue2 alpha &optional (positivep t)) "Return a convex combination of hue1 (with weight 1-alpha) and hue2 \(with weight alpha), in the positive or negative direction on the color wheel." (cond ((and positivep (> hue1 hue2)) (normalize-hue (convex-combination hue1 (+ hue2 360) alpha))) ((and (not positivep) (< hue1 hue2)) (normalize-hue (convex-combination (+ hue1 360) hue2 alpha))) (t (convex-combination hue1 hue2 alpha)))) (defmacro with-convex-combination ((cc instance1 instance2 alpha) &body body) "Wrap body in a macrolet so that (cc #'accessor) returns the convex combination of the slots of instance1 and instance2 accessed by accessor." `(macrolet ((,cc (accessor) (once-only (accessor) `(convex-combination (funcall ,accessor ,',instance1) (funcall ,accessor ,',instance2) ,',alpha)))) ,@body)) (defun rgb-combination (rgb1 rgb2 alpha) "Convex combination in RGB space." (with-convex-combination (cc rgb1 rgb2 alpha) (make-instance 'rgb :red (cc #'red) :green (cc #'green) :blue (cc #'blue)))) (defun rgba-combination (rgba1 rgba2 alpha) "Convex combination in RGBA space." (with-convex-combination (cc rgba1 rgba2 alpha) (make-instance 'rgba :red (cc #'red) :green (cc #'green) :blue (cc #'blue) :alpha (cc #'alpha)))) (defun hsv-combination (hsv1 hsv2 alpha &optional (positivep t)) (with-convex-combination (cc hsv1 hsv2 alpha) (make-instance 'hsv :hue (hue-combination (hue hsv1) (hue hsv2) alpha positivep) :saturation (cc #'saturation) :value (cc #'value))))
5,760
Common Lisp
.lisp
156
33.089744
80
0.662356
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
85b2ee6bf1ae8459d1f2b66b45d7da569428fba535d4c3ad454002c6dd06af4c
21,564
[ -1 ]
21,565
colornames.lisp
rheaplex_minara/lib/cl-colors/colornames.lisp
;;;; This file was generated automatically by parse-x11.lisp ;;;; Please do not edit directly. (in-package :cl-colors) (defmacro define-rgb-color (name red green blue) `(progn (defconstant ,name (if (boundp ',name) (symbol-value ',name) (make-instance 'rgb :red ,red :green ,green :blue ,blue))) (export ',name))) (define-rgb-color +snow+ 1.0d0 0.9803921568627451d0 0.9803921568627451d0) (define-rgb-color +ghostwhite+ 0.9725490196078431d0 0.9725490196078431d0 1.0d0) (define-rgb-color +whitesmoke+ 0.9607843137254902d0 0.9607843137254902d0 0.9607843137254902d0) (define-rgb-color +gainsboro+ 0.8627450980392157d0 0.8627450980392157d0 0.8627450980392157d0) (define-rgb-color +floralwhite+ 1.0d0 0.9803921568627451d0 0.9411764705882353d0) (define-rgb-color +oldlace+ 0.9921568627450981d0 0.9607843137254902d0 0.9019607843137255d0) (define-rgb-color +linen+ 0.9803921568627451d0 0.9411764705882353d0 0.9019607843137255d0) (define-rgb-color +antiquewhite+ 0.9803921568627451d0 0.9215686274509803d0 0.8431372549019608d0) (define-rgb-color +papayawhip+ 1.0d0 0.9372549019607843d0 0.8352941176470589d0) (define-rgb-color +blanchedalmond+ 1.0d0 0.9215686274509803d0 0.803921568627451d0) (define-rgb-color +bisque+ 1.0d0 0.8941176470588236d0 0.7686274509803922d0) (define-rgb-color +peachpuff+ 1.0d0 0.8549019607843137d0 0.7254901960784313d0) (define-rgb-color +navajowhite+ 1.0d0 0.8705882352941177d0 0.6784313725490196d0) (define-rgb-color +moccasin+ 1.0d0 0.8941176470588236d0 0.7098039215686275d0) (define-rgb-color +cornsilk+ 1.0d0 0.9725490196078431d0 0.8627450980392157d0) (define-rgb-color +ivory+ 1.0d0 1.0d0 0.9411764705882353d0) (define-rgb-color +lemonchiffon+ 1.0d0 0.9803921568627451d0 0.803921568627451d0) (define-rgb-color +seashell+ 1.0d0 0.9607843137254902d0 0.9333333333333333d0) (define-rgb-color +honeydew+ 0.9411764705882353d0 1.0d0 0.9411764705882353d0) (define-rgb-color +mintcream+ 0.9607843137254902d0 1.0d0 0.9803921568627451d0) (define-rgb-color +azure+ 0.9411764705882353d0 1.0d0 1.0d0) (define-rgb-color +aliceblue+ 0.9411764705882353d0 0.9725490196078431d0 1.0d0) (define-rgb-color +lavender+ 0.9019607843137255d0 0.9019607843137255d0 0.9803921568627451d0) (define-rgb-color +lavenderblush+ 1.0d0 0.9411764705882353d0 0.9607843137254902d0) (define-rgb-color +mistyrose+ 1.0d0 0.8941176470588236d0 0.8823529411764706d0) (define-rgb-color +white+ 1.0d0 1.0d0 1.0d0) (define-rgb-color +black+ 0.0d0 0.0d0 0.0d0) (define-rgb-color +darkslategray+ 0.1843137254901961d0 0.30980392156862746d0 0.30980392156862746d0) (define-rgb-color +darkslategrey+ 0.1843137254901961d0 0.30980392156862746d0 0.30980392156862746d0) (define-rgb-color +dimgray+ 0.4117647058823529d0 0.4117647058823529d0 0.4117647058823529d0) (define-rgb-color +dimgrey+ 0.4117647058823529d0 0.4117647058823529d0 0.4117647058823529d0) (define-rgb-color +slategray+ 0.4392156862745098d0 0.5019607843137255d0 0.5647058823529412d0) (define-rgb-color +slategrey+ 0.4392156862745098d0 0.5019607843137255d0 0.5647058823529412d0) (define-rgb-color +lightslategray+ 0.4666666666666667d0 0.5333333333333333d0 0.6d0) (define-rgb-color +lightslategrey+ 0.4666666666666667d0 0.5333333333333333d0 0.6d0) (define-rgb-color +gray+ 0.7450980392156863d0 0.7450980392156863d0 0.7450980392156863d0) (define-rgb-color +grey+ 0.7450980392156863d0 0.7450980392156863d0 0.7450980392156863d0) (define-rgb-color +lightgrey+ 0.8274509803921568d0 0.8274509803921568d0 0.8274509803921568d0) (define-rgb-color +lightgray+ 0.8274509803921568d0 0.8274509803921568d0 0.8274509803921568d0) (define-rgb-color +midnightblue+ 0.09803921568627451d0 0.09803921568627451d0 0.4392156862745098d0) (define-rgb-color +navy+ 0.0d0 0.0d0 0.5019607843137255d0) (define-rgb-color +navyblue+ 0.0d0 0.0d0 0.5019607843137255d0) (define-rgb-color +cornflowerblue+ 0.39215686274509803d0 0.5843137254901961d0 0.9294117647058824d0) (define-rgb-color +darkslateblue+ 0.2823529411764706d0 0.23921568627450981d0 0.5450980392156862d0) (define-rgb-color +slateblue+ 0.41568627450980394d0 0.35294117647058826d0 0.803921568627451d0) (define-rgb-color +mediumslateblue+ 0.4823529411764706d0 0.40784313725490196d0 0.9333333333333333d0) (define-rgb-color +lightslateblue+ 0.5176470588235295d0 0.4392156862745098d0 1.0d0) (define-rgb-color +mediumblue+ 0.0d0 0.0d0 0.803921568627451d0) (define-rgb-color +royalblue+ 0.2549019607843137d0 0.4117647058823529d0 0.8823529411764706d0) (define-rgb-color +blue+ 0.0d0 0.0d0 1.0d0) (define-rgb-color +dodgerblue+ 0.11764705882352941d0 0.5647058823529412d0 1.0d0) (define-rgb-color +deepskyblue+ 0.0d0 0.7490196078431373d0 1.0d0) (define-rgb-color +skyblue+ 0.5294117647058824d0 0.807843137254902d0 0.9215686274509803d0) (define-rgb-color +lightskyblue+ 0.5294117647058824d0 0.807843137254902d0 0.9803921568627451d0) (define-rgb-color +steelblue+ 0.27450980392156865d0 0.5098039215686274d0 0.7058823529411765d0) (define-rgb-color +lightsteelblue+ 0.6901960784313725d0 0.7686274509803922d0 0.8705882352941177d0) (define-rgb-color +lightblue+ 0.6784313725490196d0 0.8470588235294118d0 0.9019607843137255d0) (define-rgb-color +powderblue+ 0.6901960784313725d0 0.8784313725490196d0 0.9019607843137255d0) (define-rgb-color +paleturquoise+ 0.6862745098039216d0 0.9333333333333333d0 0.9333333333333333d0) (define-rgb-color +darkturquoise+ 0.0d0 0.807843137254902d0 0.8196078431372549d0) (define-rgb-color +mediumturquoise+ 0.2823529411764706d0 0.8196078431372549d0 0.8d0) (define-rgb-color +turquoise+ 0.25098039215686274d0 0.8784313725490196d0 0.8156862745098039d0) (define-rgb-color +cyan+ 0.0d0 1.0d0 1.0d0) (define-rgb-color +lightcyan+ 0.8784313725490196d0 1.0d0 1.0d0) (define-rgb-color +cadetblue+ 0.37254901960784315d0 0.6196078431372549d0 0.6274509803921569d0) (define-rgb-color +mediumaquamarine+ 0.4d0 0.803921568627451d0 0.6666666666666666d0) (define-rgb-color +aquamarine+ 0.4980392156862745d0 1.0d0 0.8313725490196079d0) (define-rgb-color +darkgreen+ 0.0d0 0.39215686274509803d0 0.0d0) (define-rgb-color +darkolivegreen+ 0.3333333333333333d0 0.4196078431372549d0 0.1843137254901961d0) (define-rgb-color +darkseagreen+ 0.5607843137254902d0 0.7372549019607844d0 0.5607843137254902d0) (define-rgb-color +seagreen+ 0.1803921568627451d0 0.5450980392156862d0 0.3411764705882353d0) (define-rgb-color +mediumseagreen+ 0.23529411764705882d0 0.7019607843137254d0 0.44313725490196076d0) (define-rgb-color +lightseagreen+ 0.12549019607843137d0 0.6980392156862745d0 0.6666666666666666d0) (define-rgb-color +palegreen+ 0.596078431372549d0 0.984313725490196d0 0.596078431372549d0) (define-rgb-color +springgreen+ 0.0d0 1.0d0 0.4980392156862745d0) (define-rgb-color +lawngreen+ 0.48627450980392156d0 0.9882352941176471d0 0.0d0) (define-rgb-color +green+ 0.0d0 1.0d0 0.0d0) (define-rgb-color +chartreuse+ 0.4980392156862745d0 1.0d0 0.0d0) (define-rgb-color +mediumspringgreen+ 0.0d0 0.9803921568627451d0 0.6039215686274509d0) (define-rgb-color +greenyellow+ 0.6784313725490196d0 1.0d0 0.1843137254901961d0) (define-rgb-color +limegreen+ 0.19607843137254902d0 0.803921568627451d0 0.19607843137254902d0) (define-rgb-color +yellowgreen+ 0.6039215686274509d0 0.803921568627451d0 0.19607843137254902d0) (define-rgb-color +forestgreen+ 0.13333333333333333d0 0.5450980392156862d0 0.13333333333333333d0) (define-rgb-color +olivedrab+ 0.4196078431372549d0 0.5568627450980392d0 0.13725490196078433d0) (define-rgb-color +darkkhaki+ 0.7411764705882353d0 0.7176470588235294d0 0.4196078431372549d0) (define-rgb-color +khaki+ 0.9411764705882353d0 0.9019607843137255d0 0.5490196078431373d0) (define-rgb-color +palegoldenrod+ 0.9333333333333333d0 0.9098039215686274d0 0.6666666666666666d0) (define-rgb-color +lightgoldenrodyellow+ 0.9803921568627451d0 0.9803921568627451d0 0.8235294117647058d0) (define-rgb-color +lightyellow+ 1.0d0 1.0d0 0.8784313725490196d0) (define-rgb-color +yellow+ 1.0d0 1.0d0 0.0d0) (define-rgb-color +gold+ 1.0d0 0.8431372549019608d0 0.0d0) (define-rgb-color +lightgoldenrod+ 0.9333333333333333d0 0.8666666666666667d0 0.5098039215686274d0) (define-rgb-color +goldenrod+ 0.8549019607843137d0 0.6470588235294118d0 0.12549019607843137d0) (define-rgb-color +darkgoldenrod+ 0.7215686274509804d0 0.5254901960784314d0 0.043137254901960784d0) (define-rgb-color +rosybrown+ 0.7372549019607844d0 0.5607843137254902d0 0.5607843137254902d0) (define-rgb-color +indianred+ 0.803921568627451d0 0.3607843137254902d0 0.3607843137254902d0) (define-rgb-color +saddlebrown+ 0.5450980392156862d0 0.27058823529411763d0 0.07450980392156863d0) (define-rgb-color +sienna+ 0.6274509803921569d0 0.3215686274509804d0 0.17647058823529413d0) (define-rgb-color +peru+ 0.803921568627451d0 0.5215686274509804d0 0.24705882352941178d0) (define-rgb-color +burlywood+ 0.8705882352941177d0 0.7215686274509804d0 0.5294117647058824d0) (define-rgb-color +beige+ 0.9607843137254902d0 0.9607843137254902d0 0.8627450980392157d0) (define-rgb-color +wheat+ 0.9607843137254902d0 0.8705882352941177d0 0.7019607843137254d0) (define-rgb-color +sandybrown+ 0.9568627450980393d0 0.6431372549019608d0 0.3764705882352941d0) (define-rgb-color +tan+ 0.8235294117647058d0 0.7058823529411765d0 0.5490196078431373d0) (define-rgb-color +chocolate+ 0.8235294117647058d0 0.4117647058823529d0 0.11764705882352941d0) (define-rgb-color +firebrick+ 0.6980392156862745d0 0.13333333333333333d0 0.13333333333333333d0) (define-rgb-color +brown+ 0.6470588235294118d0 0.16470588235294117d0 0.16470588235294117d0) (define-rgb-color +darksalmon+ 0.9137254901960784d0 0.5882352941176471d0 0.47843137254901963d0) (define-rgb-color +salmon+ 0.9803921568627451d0 0.5019607843137255d0 0.4470588235294118d0) (define-rgb-color +lightsalmon+ 1.0d0 0.6274509803921569d0 0.47843137254901963d0) (define-rgb-color +orange+ 1.0d0 0.6470588235294118d0 0.0d0) (define-rgb-color +darkorange+ 1.0d0 0.5490196078431373d0 0.0d0) (define-rgb-color +coral+ 1.0d0 0.4980392156862745d0 0.3137254901960784d0) (define-rgb-color +lightcoral+ 0.9411764705882353d0 0.5019607843137255d0 0.5019607843137255d0) (define-rgb-color +tomato+ 1.0d0 0.38823529411764707d0 0.2784313725490196d0) (define-rgb-color +orangered+ 1.0d0 0.27058823529411763d0 0.0d0) (define-rgb-color +red+ 1.0d0 0.0d0 0.0d0) (define-rgb-color +hotpink+ 1.0d0 0.4117647058823529d0 0.7058823529411765d0) (define-rgb-color +deeppink+ 1.0d0 0.0784313725490196d0 0.5764705882352941d0) (define-rgb-color +pink+ 1.0d0 0.7529411764705882d0 0.796078431372549d0) (define-rgb-color +lightpink+ 1.0d0 0.7137254901960784d0 0.7568627450980392d0) (define-rgb-color +palevioletred+ 0.8588235294117647d0 0.4392156862745098d0 0.5764705882352941d0) (define-rgb-color +maroon+ 0.6901960784313725d0 0.18823529411764706d0 0.3764705882352941d0) (define-rgb-color +mediumvioletred+ 0.7803921568627451d0 0.08235294117647059d0 0.5215686274509804d0) (define-rgb-color +violetred+ 0.8156862745098039d0 0.12549019607843137d0 0.5647058823529412d0) (define-rgb-color +magenta+ 1.0d0 0.0d0 1.0d0) (define-rgb-color +violet+ 0.9333333333333333d0 0.5098039215686274d0 0.9333333333333333d0) (define-rgb-color +plum+ 0.8666666666666667d0 0.6274509803921569d0 0.8666666666666667d0) (define-rgb-color +orchid+ 0.8549019607843137d0 0.4392156862745098d0 0.8392156862745098d0) (define-rgb-color +mediumorchid+ 0.7294117647058823d0 0.3333333333333333d0 0.8274509803921568d0) (define-rgb-color +darkorchid+ 0.6d0 0.19607843137254902d0 0.8d0) (define-rgb-color +darkviolet+ 0.5803921568627451d0 0.0d0 0.8274509803921568d0) (define-rgb-color +blueviolet+ 0.5411764705882353d0 0.16862745098039217d0 0.8862745098039215d0) (define-rgb-color +purple+ 0.6274509803921569d0 0.12549019607843137d0 0.9411764705882353d0) (define-rgb-color +mediumpurple+ 0.5764705882352941d0 0.4392156862745098d0 0.8588235294117647d0) (define-rgb-color +thistle+ 0.8470588235294118d0 0.7490196078431373d0 0.8470588235294118d0) (define-rgb-color +snow1+ 1.0d0 0.9803921568627451d0 0.9803921568627451d0) (define-rgb-color +snow2+ 0.9333333333333333d0 0.9137254901960784d0 0.9137254901960784d0) (define-rgb-color +snow3+ 0.803921568627451d0 0.788235294117647d0 0.788235294117647d0) (define-rgb-color +snow4+ 0.5450980392156862d0 0.5372549019607843d0 0.5372549019607843d0) (define-rgb-color +seashell1+ 1.0d0 0.9607843137254902d0 0.9333333333333333d0) (define-rgb-color +seashell2+ 0.9333333333333333d0 0.8980392156862745d0 0.8705882352941177d0) (define-rgb-color +seashell3+ 0.803921568627451d0 0.7725490196078432d0 0.7490196078431373d0) (define-rgb-color +seashell4+ 0.5450980392156862d0 0.5254901960784314d0 0.5098039215686274d0) (define-rgb-color +antiquewhite1+ 1.0d0 0.9372549019607843d0 0.8588235294117647d0) (define-rgb-color +antiquewhite2+ 0.9333333333333333d0 0.8745098039215686d0 0.8d0) (define-rgb-color +antiquewhite3+ 0.803921568627451d0 0.7529411764705882d0 0.6901960784313725d0) (define-rgb-color +antiquewhite4+ 0.5450980392156862d0 0.5137254901960784d0 0.47058823529411764d0) (define-rgb-color +bisque1+ 1.0d0 0.8941176470588236d0 0.7686274509803922d0) (define-rgb-color +bisque2+ 0.9333333333333333d0 0.8352941176470589d0 0.7176470588235294d0) (define-rgb-color +bisque3+ 0.803921568627451d0 0.7176470588235294d0 0.6196078431372549d0) (define-rgb-color +bisque4+ 0.5450980392156862d0 0.49019607843137253d0 0.4196078431372549d0) (define-rgb-color +peachpuff1+ 1.0d0 0.8549019607843137d0 0.7254901960784313d0) (define-rgb-color +peachpuff2+ 0.9333333333333333d0 0.796078431372549d0 0.6784313725490196d0) (define-rgb-color +peachpuff3+ 0.803921568627451d0 0.6862745098039216d0 0.5843137254901961d0) (define-rgb-color +peachpuff4+ 0.5450980392156862d0 0.4666666666666667d0 0.396078431372549d0) (define-rgb-color +navajowhite1+ 1.0d0 0.8705882352941177d0 0.6784313725490196d0) (define-rgb-color +navajowhite2+ 0.9333333333333333d0 0.8117647058823529d0 0.6313725490196078d0) (define-rgb-color +navajowhite3+ 0.803921568627451d0 0.7019607843137254d0 0.5450980392156862d0) (define-rgb-color +navajowhite4+ 0.5450980392156862d0 0.4745098039215686d0 0.3686274509803922d0) (define-rgb-color +lemonchiffon1+ 1.0d0 0.9803921568627451d0 0.803921568627451d0) (define-rgb-color +lemonchiffon2+ 0.9333333333333333d0 0.9137254901960784d0 0.7490196078431373d0) (define-rgb-color +lemonchiffon3+ 0.803921568627451d0 0.788235294117647d0 0.6470588235294118d0) (define-rgb-color +lemonchiffon4+ 0.5450980392156862d0 0.5372549019607843d0 0.4392156862745098d0) (define-rgb-color +cornsilk1+ 1.0d0 0.9725490196078431d0 0.8627450980392157d0) (define-rgb-color +cornsilk2+ 0.9333333333333333d0 0.9098039215686274d0 0.803921568627451d0) (define-rgb-color +cornsilk3+ 0.803921568627451d0 0.7843137254901961d0 0.6941176470588235d0) (define-rgb-color +cornsilk4+ 0.5450980392156862d0 0.5333333333333333d0 0.47058823529411764d0) (define-rgb-color +ivory1+ 1.0d0 1.0d0 0.9411764705882353d0) (define-rgb-color +ivory2+ 0.9333333333333333d0 0.9333333333333333d0 0.8784313725490196d0) (define-rgb-color +ivory3+ 0.803921568627451d0 0.803921568627451d0 0.7568627450980392d0) (define-rgb-color +ivory4+ 0.5450980392156862d0 0.5450980392156862d0 0.5137254901960784d0) (define-rgb-color +honeydew1+ 0.9411764705882353d0 1.0d0 0.9411764705882353d0) (define-rgb-color +honeydew2+ 0.8784313725490196d0 0.9333333333333333d0 0.8784313725490196d0) (define-rgb-color +honeydew3+ 0.7568627450980392d0 0.803921568627451d0 0.7568627450980392d0) (define-rgb-color +honeydew4+ 0.5137254901960784d0 0.5450980392156862d0 0.5137254901960784d0) (define-rgb-color +lavenderblush1+ 1.0d0 0.9411764705882353d0 0.9607843137254902d0) (define-rgb-color +lavenderblush2+ 0.9333333333333333d0 0.8784313725490196d0 0.8980392156862745d0) (define-rgb-color +lavenderblush3+ 0.803921568627451d0 0.7568627450980392d0 0.7725490196078432d0) (define-rgb-color +lavenderblush4+ 0.5450980392156862d0 0.5137254901960784d0 0.5254901960784314d0) (define-rgb-color +mistyrose1+ 1.0d0 0.8941176470588236d0 0.8823529411764706d0) (define-rgb-color +mistyrose2+ 0.9333333333333333d0 0.8352941176470589d0 0.8235294117647058d0) (define-rgb-color +mistyrose3+ 0.803921568627451d0 0.7176470588235294d0 0.7098039215686275d0) (define-rgb-color +mistyrose4+ 0.5450980392156862d0 0.49019607843137253d0 0.4823529411764706d0) (define-rgb-color +azure1+ 0.9411764705882353d0 1.0d0 1.0d0) (define-rgb-color +azure2+ 0.8784313725490196d0 0.9333333333333333d0 0.9333333333333333d0) (define-rgb-color +azure3+ 0.7568627450980392d0 0.803921568627451d0 0.803921568627451d0) (define-rgb-color +azure4+ 0.5137254901960784d0 0.5450980392156862d0 0.5450980392156862d0) (define-rgb-color +slateblue1+ 0.5137254901960784d0 0.43529411764705883d0 1.0d0) (define-rgb-color +slateblue2+ 0.47843137254901963d0 0.403921568627451d0 0.9333333333333333d0) (define-rgb-color +slateblue3+ 0.4117647058823529d0 0.34901960784313724d0 0.803921568627451d0) (define-rgb-color +slateblue4+ 0.2784313725490196d0 0.23529411764705882d0 0.5450980392156862d0) (define-rgb-color +royalblue1+ 0.2823529411764706d0 0.4627450980392157d0 1.0d0) (define-rgb-color +royalblue2+ 0.2627450980392157d0 0.43137254901960786d0 0.9333333333333333d0) (define-rgb-color +royalblue3+ 0.22745098039215686d0 0.37254901960784315d0 0.803921568627451d0) (define-rgb-color +royalblue4+ 0.15294117647058825d0 0.25098039215686274d0 0.5450980392156862d0) (define-rgb-color +blue1+ 0.0d0 0.0d0 1.0d0) (define-rgb-color +blue2+ 0.0d0 0.0d0 0.9333333333333333d0) (define-rgb-color +blue3+ 0.0d0 0.0d0 0.803921568627451d0) (define-rgb-color +blue4+ 0.0d0 0.0d0 0.5450980392156862d0) (define-rgb-color +dodgerblue1+ 0.11764705882352941d0 0.5647058823529412d0 1.0d0) (define-rgb-color +dodgerblue2+ 0.10980392156862745d0 0.5254901960784314d0 0.9333333333333333d0) (define-rgb-color +dodgerblue3+ 0.09411764705882353d0 0.4549019607843137d0 0.803921568627451d0) (define-rgb-color +dodgerblue4+ 0.06274509803921569d0 0.3058823529411765d0 0.5450980392156862d0) (define-rgb-color +steelblue1+ 0.38823529411764707d0 0.7215686274509804d0 1.0d0) (define-rgb-color +steelblue2+ 0.3607843137254902d0 0.6745098039215687d0 0.9333333333333333d0) (define-rgb-color +steelblue3+ 0.30980392156862746d0 0.5803921568627451d0 0.803921568627451d0) (define-rgb-color +steelblue4+ 0.21176470588235294d0 0.39215686274509803d0 0.5450980392156862d0) (define-rgb-color +deepskyblue1+ 0.0d0 0.7490196078431373d0 1.0d0) (define-rgb-color +deepskyblue2+ 0.0d0 0.6980392156862745d0 0.9333333333333333d0) (define-rgb-color +deepskyblue3+ 0.0d0 0.6039215686274509d0 0.803921568627451d0) (define-rgb-color +deepskyblue4+ 0.0d0 0.40784313725490196d0 0.5450980392156862d0) (define-rgb-color +skyblue1+ 0.5294117647058824d0 0.807843137254902d0 1.0d0) (define-rgb-color +skyblue2+ 0.49411764705882355d0 0.7529411764705882d0 0.9333333333333333d0) (define-rgb-color +skyblue3+ 0.4235294117647059d0 0.6509803921568628d0 0.803921568627451d0) (define-rgb-color +skyblue4+ 0.2901960784313726d0 0.4392156862745098d0 0.5450980392156862d0) (define-rgb-color +lightskyblue1+ 0.6901960784313725d0 0.8862745098039215d0 1.0d0) (define-rgb-color +lightskyblue2+ 0.6431372549019608d0 0.8274509803921568d0 0.9333333333333333d0) (define-rgb-color +lightskyblue3+ 0.5529411764705883d0 0.7137254901960784d0 0.803921568627451d0) (define-rgb-color +lightskyblue4+ 0.3764705882352941d0 0.4823529411764706d0 0.5450980392156862d0) (define-rgb-color +slategray1+ 0.7764705882352941d0 0.8862745098039215d0 1.0d0) (define-rgb-color +slategray2+ 0.7254901960784313d0 0.8274509803921568d0 0.9333333333333333d0) (define-rgb-color +slategray3+ 0.6235294117647059d0 0.7137254901960784d0 0.803921568627451d0) (define-rgb-color +slategray4+ 0.4235294117647059d0 0.4823529411764706d0 0.5450980392156862d0) (define-rgb-color +lightsteelblue1+ 0.792156862745098d0 0.8823529411764706d0 1.0d0) (define-rgb-color +lightsteelblue2+ 0.7372549019607844d0 0.8235294117647058d0 0.9333333333333333d0) (define-rgb-color +lightsteelblue3+ 0.6352941176470588d0 0.7098039215686275d0 0.803921568627451d0) (define-rgb-color +lightsteelblue4+ 0.43137254901960786d0 0.4823529411764706d0 0.5450980392156862d0) (define-rgb-color +lightblue1+ 0.7490196078431373d0 0.9372549019607843d0 1.0d0) (define-rgb-color +lightblue2+ 0.6980392156862745d0 0.8745098039215686d0 0.9333333333333333d0) (define-rgb-color +lightblue3+ 0.6039215686274509d0 0.7529411764705882d0 0.803921568627451d0) (define-rgb-color +lightblue4+ 0.40784313725490196d0 0.5137254901960784d0 0.5450980392156862d0) (define-rgb-color +lightcyan1+ 0.8784313725490196d0 1.0d0 1.0d0) (define-rgb-color +lightcyan2+ 0.8196078431372549d0 0.9333333333333333d0 0.9333333333333333d0) (define-rgb-color +lightcyan3+ 0.7058823529411765d0 0.803921568627451d0 0.803921568627451d0) (define-rgb-color +lightcyan4+ 0.47843137254901963d0 0.5450980392156862d0 0.5450980392156862d0) (define-rgb-color +paleturquoise1+ 0.7333333333333333d0 1.0d0 1.0d0) (define-rgb-color +paleturquoise2+ 0.6823529411764706d0 0.9333333333333333d0 0.9333333333333333d0) (define-rgb-color +paleturquoise3+ 0.5882352941176471d0 0.803921568627451d0 0.803921568627451d0) (define-rgb-color +paleturquoise4+ 0.4d0 0.5450980392156862d0 0.5450980392156862d0) (define-rgb-color +cadetblue1+ 0.596078431372549d0 0.9607843137254902d0 1.0d0) (define-rgb-color +cadetblue2+ 0.5568627450980392d0 0.8980392156862745d0 0.9333333333333333d0) (define-rgb-color +cadetblue3+ 0.47843137254901963d0 0.7725490196078432d0 0.803921568627451d0) (define-rgb-color +cadetblue4+ 0.3254901960784314d0 0.5254901960784314d0 0.5450980392156862d0) (define-rgb-color +turquoise1+ 0.0d0 0.9607843137254902d0 1.0d0) (define-rgb-color +turquoise2+ 0.0d0 0.8980392156862745d0 0.9333333333333333d0) (define-rgb-color +turquoise3+ 0.0d0 0.7725490196078432d0 0.803921568627451d0) (define-rgb-color +turquoise4+ 0.0d0 0.5254901960784314d0 0.5450980392156862d0) (define-rgb-color +cyan1+ 0.0d0 1.0d0 1.0d0) (define-rgb-color +cyan2+ 0.0d0 0.9333333333333333d0 0.9333333333333333d0) (define-rgb-color +cyan3+ 0.0d0 0.803921568627451d0 0.803921568627451d0) (define-rgb-color +cyan4+ 0.0d0 0.5450980392156862d0 0.5450980392156862d0) (define-rgb-color +darkslategray1+ 0.592156862745098d0 1.0d0 1.0d0) (define-rgb-color +darkslategray2+ 0.5529411764705883d0 0.9333333333333333d0 0.9333333333333333d0) (define-rgb-color +darkslategray3+ 0.4745098039215686d0 0.803921568627451d0 0.803921568627451d0) (define-rgb-color +darkslategray4+ 0.3215686274509804d0 0.5450980392156862d0 0.5450980392156862d0) (define-rgb-color +aquamarine1+ 0.4980392156862745d0 1.0d0 0.8313725490196079d0) (define-rgb-color +aquamarine2+ 0.4627450980392157d0 0.9333333333333333d0 0.7764705882352941d0) (define-rgb-color +aquamarine3+ 0.4d0 0.803921568627451d0 0.6666666666666666d0) (define-rgb-color +aquamarine4+ 0.27058823529411763d0 0.5450980392156862d0 0.4549019607843137d0) (define-rgb-color +darkseagreen1+ 0.7568627450980392d0 1.0d0 0.7568627450980392d0) (define-rgb-color +darkseagreen2+ 0.7058823529411765d0 0.9333333333333333d0 0.7058823529411765d0) (define-rgb-color +darkseagreen3+ 0.6078431372549019d0 0.803921568627451d0 0.6078431372549019d0) (define-rgb-color +darkseagreen4+ 0.4117647058823529d0 0.5450980392156862d0 0.4117647058823529d0) (define-rgb-color +seagreen1+ 0.32941176470588235d0 1.0d0 0.6235294117647059d0) (define-rgb-color +seagreen2+ 0.3058823529411765d0 0.9333333333333333d0 0.5803921568627451d0) (define-rgb-color +seagreen3+ 0.2627450980392157d0 0.803921568627451d0 0.5019607843137255d0) (define-rgb-color +seagreen4+ 0.1803921568627451d0 0.5450980392156862d0 0.3411764705882353d0) (define-rgb-color +palegreen1+ 0.6039215686274509d0 1.0d0 0.6039215686274509d0) (define-rgb-color +palegreen2+ 0.5647058823529412d0 0.9333333333333333d0 0.5647058823529412d0) (define-rgb-color +palegreen3+ 0.48627450980392156d0 0.803921568627451d0 0.48627450980392156d0) (define-rgb-color +palegreen4+ 0.32941176470588235d0 0.5450980392156862d0 0.32941176470588235d0) (define-rgb-color +springgreen1+ 0.0d0 1.0d0 0.4980392156862745d0) (define-rgb-color +springgreen2+ 0.0d0 0.9333333333333333d0 0.4627450980392157d0) (define-rgb-color +springgreen3+ 0.0d0 0.803921568627451d0 0.4d0) (define-rgb-color +springgreen4+ 0.0d0 0.5450980392156862d0 0.27058823529411763d0) (define-rgb-color +green1+ 0.0d0 1.0d0 0.0d0) (define-rgb-color +green2+ 0.0d0 0.9333333333333333d0 0.0d0) (define-rgb-color +green3+ 0.0d0 0.803921568627451d0 0.0d0) (define-rgb-color +green4+ 0.0d0 0.5450980392156862d0 0.0d0) (define-rgb-color +chartreuse1+ 0.4980392156862745d0 1.0d0 0.0d0) (define-rgb-color +chartreuse2+ 0.4627450980392157d0 0.9333333333333333d0 0.0d0) (define-rgb-color +chartreuse3+ 0.4d0 0.803921568627451d0 0.0d0) (define-rgb-color +chartreuse4+ 0.27058823529411763d0 0.5450980392156862d0 0.0d0) (define-rgb-color +olivedrab1+ 0.7529411764705882d0 1.0d0 0.24313725490196078d0) (define-rgb-color +olivedrab2+ 0.7019607843137254d0 0.9333333333333333d0 0.22745098039215686d0) (define-rgb-color +olivedrab3+ 0.6039215686274509d0 0.803921568627451d0 0.19607843137254902d0) (define-rgb-color +olivedrab4+ 0.4117647058823529d0 0.5450980392156862d0 0.13333333333333333d0) (define-rgb-color +darkolivegreen1+ 0.792156862745098d0 1.0d0 0.4392156862745098d0) (define-rgb-color +darkolivegreen2+ 0.7372549019607844d0 0.9333333333333333d0 0.40784313725490196d0) (define-rgb-color +darkolivegreen3+ 0.6352941176470588d0 0.803921568627451d0 0.35294117647058826d0) (define-rgb-color +darkolivegreen4+ 0.43137254901960786d0 0.5450980392156862d0 0.23921568627450981d0) (define-rgb-color +khaki1+ 1.0d0 0.9647058823529412d0 0.5607843137254902d0) (define-rgb-color +khaki2+ 0.9333333333333333d0 0.9019607843137255d0 0.5215686274509804d0) (define-rgb-color +khaki3+ 0.803921568627451d0 0.7764705882352941d0 0.45098039215686275d0) (define-rgb-color +khaki4+ 0.5450980392156862d0 0.5254901960784314d0 0.3058823529411765d0) (define-rgb-color +lightgoldenrod1+ 1.0d0 0.9254901960784314d0 0.5450980392156862d0) (define-rgb-color +lightgoldenrod2+ 0.9333333333333333d0 0.8627450980392157d0 0.5098039215686274d0) (define-rgb-color +lightgoldenrod3+ 0.803921568627451d0 0.7450980392156863d0 0.4392156862745098d0) (define-rgb-color +lightgoldenrod4+ 0.5450980392156862d0 0.5058823529411764d0 0.2980392156862745d0) (define-rgb-color +lightyellow1+ 1.0d0 1.0d0 0.8784313725490196d0) (define-rgb-color +lightyellow2+ 0.9333333333333333d0 0.9333333333333333d0 0.8196078431372549d0) (define-rgb-color +lightyellow3+ 0.803921568627451d0 0.803921568627451d0 0.7058823529411765d0) (define-rgb-color +lightyellow4+ 0.5450980392156862d0 0.5450980392156862d0 0.47843137254901963d0) (define-rgb-color +yellow1+ 1.0d0 1.0d0 0.0d0) (define-rgb-color +yellow2+ 0.9333333333333333d0 0.9333333333333333d0 0.0d0) (define-rgb-color +yellow3+ 0.803921568627451d0 0.803921568627451d0 0.0d0) (define-rgb-color +yellow4+ 0.5450980392156862d0 0.5450980392156862d0 0.0d0) (define-rgb-color +gold1+ 1.0d0 0.8431372549019608d0 0.0d0) (define-rgb-color +gold2+ 0.9333333333333333d0 0.788235294117647d0 0.0d0) (define-rgb-color +gold3+ 0.803921568627451d0 0.6784313725490196d0 0.0d0) (define-rgb-color +gold4+ 0.5450980392156862d0 0.4588235294117647d0 0.0d0) (define-rgb-color +goldenrod1+ 1.0d0 0.7568627450980392d0 0.1450980392156863d0) (define-rgb-color +goldenrod2+ 0.9333333333333333d0 0.7058823529411765d0 0.13333333333333333d0) (define-rgb-color +goldenrod3+ 0.803921568627451d0 0.6078431372549019d0 0.11372549019607843d0) (define-rgb-color +goldenrod4+ 0.5450980392156862d0 0.4117647058823529d0 0.0784313725490196d0) (define-rgb-color +darkgoldenrod1+ 1.0d0 0.7254901960784313d0 0.058823529411764705d0) (define-rgb-color +darkgoldenrod2+ 0.9333333333333333d0 0.6784313725490196d0 0.054901960784313725d0) (define-rgb-color +darkgoldenrod3+ 0.803921568627451d0 0.5843137254901961d0 0.047058823529411764d0) (define-rgb-color +darkgoldenrod4+ 0.5450980392156862d0 0.396078431372549d0 0.03137254901960784d0) (define-rgb-color +rosybrown1+ 1.0d0 0.7568627450980392d0 0.7568627450980392d0) (define-rgb-color +rosybrown2+ 0.9333333333333333d0 0.7058823529411765d0 0.7058823529411765d0) (define-rgb-color +rosybrown3+ 0.803921568627451d0 0.6078431372549019d0 0.6078431372549019d0) (define-rgb-color +rosybrown4+ 0.5450980392156862d0 0.4117647058823529d0 0.4117647058823529d0) (define-rgb-color +indianred1+ 1.0d0 0.41568627450980394d0 0.41568627450980394d0) (define-rgb-color +indianred2+ 0.9333333333333333d0 0.38823529411764707d0 0.38823529411764707d0) (define-rgb-color +indianred3+ 0.803921568627451d0 0.3333333333333333d0 0.3333333333333333d0) (define-rgb-color +indianred4+ 0.5450980392156862d0 0.22745098039215686d0 0.22745098039215686d0) (define-rgb-color +sienna1+ 1.0d0 0.5098039215686274d0 0.2784313725490196d0) (define-rgb-color +sienna2+ 0.9333333333333333d0 0.4745098039215686d0 0.25882352941176473d0) (define-rgb-color +sienna3+ 0.803921568627451d0 0.40784313725490196d0 0.2235294117647059d0) (define-rgb-color +sienna4+ 0.5450980392156862d0 0.2784313725490196d0 0.14901960784313725d0) (define-rgb-color +burlywood1+ 1.0d0 0.8274509803921568d0 0.6078431372549019d0) (define-rgb-color +burlywood2+ 0.9333333333333333d0 0.7725490196078432d0 0.5686274509803921d0) (define-rgb-color +burlywood3+ 0.803921568627451d0 0.6666666666666666d0 0.49019607843137253d0) (define-rgb-color +burlywood4+ 0.5450980392156862d0 0.45098039215686275d0 0.3333333333333333d0) (define-rgb-color +wheat1+ 1.0d0 0.9058823529411765d0 0.7294117647058823d0) (define-rgb-color +wheat2+ 0.9333333333333333d0 0.8470588235294118d0 0.6823529411764706d0) (define-rgb-color +wheat3+ 0.803921568627451d0 0.7294117647058823d0 0.5882352941176471d0) (define-rgb-color +wheat4+ 0.5450980392156862d0 0.49411764705882355d0 0.4d0) (define-rgb-color +tan1+ 1.0d0 0.6470588235294118d0 0.30980392156862746d0) (define-rgb-color +tan2+ 0.9333333333333333d0 0.6039215686274509d0 0.28627450980392155d0) (define-rgb-color +tan3+ 0.803921568627451d0 0.5215686274509804d0 0.24705882352941178d0) (define-rgb-color +tan4+ 0.5450980392156862d0 0.35294117647058826d0 0.16862745098039217d0) (define-rgb-color +chocolate1+ 1.0d0 0.4980392156862745d0 0.1411764705882353d0) (define-rgb-color +chocolate2+ 0.9333333333333333d0 0.4627450980392157d0 0.12941176470588237d0) (define-rgb-color +chocolate3+ 0.803921568627451d0 0.4d0 0.11372549019607843d0) (define-rgb-color +chocolate4+ 0.5450980392156862d0 0.27058823529411763d0 0.07450980392156863d0) (define-rgb-color +firebrick1+ 1.0d0 0.18823529411764706d0 0.18823529411764706d0) (define-rgb-color +firebrick2+ 0.9333333333333333d0 0.17254901960784313d0 0.17254901960784313d0) (define-rgb-color +firebrick3+ 0.803921568627451d0 0.14901960784313725d0 0.14901960784313725d0) (define-rgb-color +firebrick4+ 0.5450980392156862d0 0.10196078431372549d0 0.10196078431372549d0) (define-rgb-color +brown1+ 1.0d0 0.25098039215686274d0 0.25098039215686274d0) (define-rgb-color +brown2+ 0.9333333333333333d0 0.23137254901960785d0 0.23137254901960785d0) (define-rgb-color +brown3+ 0.803921568627451d0 0.2d0 0.2d0) (define-rgb-color +brown4+ 0.5450980392156862d0 0.13725490196078433d0 0.13725490196078433d0) (define-rgb-color +salmon1+ 1.0d0 0.5490196078431373d0 0.4117647058823529d0) (define-rgb-color +salmon2+ 0.9333333333333333d0 0.5098039215686274d0 0.3843137254901961d0) (define-rgb-color +salmon3+ 0.803921568627451d0 0.4392156862745098d0 0.32941176470588235d0) (define-rgb-color +salmon4+ 0.5450980392156862d0 0.2980392156862745d0 0.2235294117647059d0) (define-rgb-color +lightsalmon1+ 1.0d0 0.6274509803921569d0 0.47843137254901963d0) (define-rgb-color +lightsalmon2+ 0.9333333333333333d0 0.5843137254901961d0 0.4470588235294118d0) (define-rgb-color +lightsalmon3+ 0.803921568627451d0 0.5058823529411764d0 0.3843137254901961d0) (define-rgb-color +lightsalmon4+ 0.5450980392156862d0 0.3411764705882353d0 0.25882352941176473d0) (define-rgb-color +orange1+ 1.0d0 0.6470588235294118d0 0.0d0) (define-rgb-color +orange2+ 0.9333333333333333d0 0.6039215686274509d0 0.0d0) (define-rgb-color +orange3+ 0.803921568627451d0 0.5215686274509804d0 0.0d0) (define-rgb-color +orange4+ 0.5450980392156862d0 0.35294117647058826d0 0.0d0) (define-rgb-color +darkorange1+ 1.0d0 0.4980392156862745d0 0.0d0) (define-rgb-color +darkorange2+ 0.9333333333333333d0 0.4627450980392157d0 0.0d0) (define-rgb-color +darkorange3+ 0.803921568627451d0 0.4d0 0.0d0) (define-rgb-color +darkorange4+ 0.5450980392156862d0 0.27058823529411763d0 0.0d0) (define-rgb-color +coral1+ 1.0d0 0.4470588235294118d0 0.33725490196078434d0) (define-rgb-color +coral2+ 0.9333333333333333d0 0.41568627450980394d0 0.3137254901960784d0) (define-rgb-color +coral3+ 0.803921568627451d0 0.3568627450980392d0 0.27058823529411763d0) (define-rgb-color +coral4+ 0.5450980392156862d0 0.24313725490196078d0 0.1843137254901961d0) (define-rgb-color +tomato1+ 1.0d0 0.38823529411764707d0 0.2784313725490196d0) (define-rgb-color +tomato2+ 0.9333333333333333d0 0.3607843137254902d0 0.25882352941176473d0) (define-rgb-color +tomato3+ 0.803921568627451d0 0.30980392156862746d0 0.2235294117647059d0) (define-rgb-color +tomato4+ 0.5450980392156862d0 0.21176470588235294d0 0.14901960784313725d0) (define-rgb-color +orangered1+ 1.0d0 0.27058823529411763d0 0.0d0) (define-rgb-color +orangered2+ 0.9333333333333333d0 0.25098039215686274d0 0.0d0) (define-rgb-color +orangered3+ 0.803921568627451d0 0.21568627450980393d0 0.0d0) (define-rgb-color +orangered4+ 0.5450980392156862d0 0.1450980392156863d0 0.0d0) (define-rgb-color +red1+ 1.0d0 0.0d0 0.0d0) (define-rgb-color +red2+ 0.9333333333333333d0 0.0d0 0.0d0) (define-rgb-color +red3+ 0.803921568627451d0 0.0d0 0.0d0) (define-rgb-color +red4+ 0.5450980392156862d0 0.0d0 0.0d0) (define-rgb-color +debianred+ 0.8431372549019608d0 0.027450980392156862d0 0.3176470588235294d0) (define-rgb-color +deeppink1+ 1.0d0 0.0784313725490196d0 0.5764705882352941d0) (define-rgb-color +deeppink2+ 0.9333333333333333d0 0.07058823529411765d0 0.5372549019607843d0) (define-rgb-color +deeppink3+ 0.803921568627451d0 0.06274509803921569d0 0.4627450980392157d0) (define-rgb-color +deeppink4+ 0.5450980392156862d0 0.0392156862745098d0 0.3137254901960784d0) (define-rgb-color +hotpink1+ 1.0d0 0.43137254901960786d0 0.7058823529411765d0) (define-rgb-color +hotpink2+ 0.9333333333333333d0 0.41568627450980394d0 0.6549019607843137d0) (define-rgb-color +hotpink3+ 0.803921568627451d0 0.3764705882352941d0 0.5647058823529412d0) (define-rgb-color +hotpink4+ 0.5450980392156862d0 0.22745098039215686d0 0.3843137254901961d0) (define-rgb-color +pink1+ 1.0d0 0.7098039215686275d0 0.7725490196078432d0) (define-rgb-color +pink2+ 0.9333333333333333d0 0.6627450980392157d0 0.7215686274509804d0) (define-rgb-color +pink3+ 0.803921568627451d0 0.5686274509803921d0 0.6196078431372549d0) (define-rgb-color +pink4+ 0.5450980392156862d0 0.38823529411764707d0 0.4235294117647059d0) (define-rgb-color +lightpink1+ 1.0d0 0.6823529411764706d0 0.7254901960784313d0) (define-rgb-color +lightpink2+ 0.9333333333333333d0 0.6352941176470588d0 0.6784313725490196d0) (define-rgb-color +lightpink3+ 0.803921568627451d0 0.5490196078431373d0 0.5843137254901961d0) (define-rgb-color +lightpink4+ 0.5450980392156862d0 0.37254901960784315d0 0.396078431372549d0) (define-rgb-color +palevioletred1+ 1.0d0 0.5098039215686274d0 0.6705882352941176d0) (define-rgb-color +palevioletred2+ 0.9333333333333333d0 0.4745098039215686d0 0.6235294117647059d0) (define-rgb-color +palevioletred3+ 0.803921568627451d0 0.40784313725490196d0 0.5372549019607843d0) (define-rgb-color +palevioletred4+ 0.5450980392156862d0 0.2784313725490196d0 0.36470588235294116d0) (define-rgb-color +maroon1+ 1.0d0 0.20392156862745098d0 0.7019607843137254d0) (define-rgb-color +maroon2+ 0.9333333333333333d0 0.18823529411764706d0 0.6549019607843137d0) (define-rgb-color +maroon3+ 0.803921568627451d0 0.1607843137254902d0 0.5647058823529412d0) (define-rgb-color +maroon4+ 0.5450980392156862d0 0.10980392156862745d0 0.3843137254901961d0) (define-rgb-color +violetred1+ 1.0d0 0.24313725490196078d0 0.5882352941176471d0) (define-rgb-color +violetred2+ 0.9333333333333333d0 0.22745098039215686d0 0.5490196078431373d0) (define-rgb-color +violetred3+ 0.803921568627451d0 0.19607843137254902d0 0.47058823529411764d0) (define-rgb-color +violetred4+ 0.5450980392156862d0 0.13333333333333333d0 0.3215686274509804d0) (define-rgb-color +magenta1+ 1.0d0 0.0d0 1.0d0) (define-rgb-color +magenta2+ 0.9333333333333333d0 0.0d0 0.9333333333333333d0) (define-rgb-color +magenta3+ 0.803921568627451d0 0.0d0 0.803921568627451d0) (define-rgb-color +magenta4+ 0.5450980392156862d0 0.0d0 0.5450980392156862d0) (define-rgb-color +orchid1+ 1.0d0 0.5137254901960784d0 0.9803921568627451d0) (define-rgb-color +orchid2+ 0.9333333333333333d0 0.47843137254901963d0 0.9137254901960784d0) (define-rgb-color +orchid3+ 0.803921568627451d0 0.4117647058823529d0 0.788235294117647d0) (define-rgb-color +orchid4+ 0.5450980392156862d0 0.2784313725490196d0 0.5372549019607843d0) (define-rgb-color +plum1+ 1.0d0 0.7333333333333333d0 1.0d0) (define-rgb-color +plum2+ 0.9333333333333333d0 0.6823529411764706d0 0.9333333333333333d0) (define-rgb-color +plum3+ 0.803921568627451d0 0.5882352941176471d0 0.803921568627451d0) (define-rgb-color +plum4+ 0.5450980392156862d0 0.4d0 0.5450980392156862d0) (define-rgb-color +mediumorchid1+ 0.8784313725490196d0 0.4d0 1.0d0) (define-rgb-color +mediumorchid2+ 0.8196078431372549d0 0.37254901960784315d0 0.9333333333333333d0) (define-rgb-color +mediumorchid3+ 0.7058823529411765d0 0.3215686274509804d0 0.803921568627451d0) (define-rgb-color +mediumorchid4+ 0.47843137254901963d0 0.21568627450980393d0 0.5450980392156862d0) (define-rgb-color +darkorchid1+ 0.7490196078431373d0 0.24313725490196078d0 1.0d0) (define-rgb-color +darkorchid2+ 0.6980392156862745d0 0.22745098039215686d0 0.9333333333333333d0) (define-rgb-color +darkorchid3+ 0.6039215686274509d0 0.19607843137254902d0 0.803921568627451d0) (define-rgb-color +darkorchid4+ 0.40784313725490196d0 0.13333333333333333d0 0.5450980392156862d0) (define-rgb-color +purple1+ 0.6078431372549019d0 0.18823529411764706d0 1.0d0) (define-rgb-color +purple2+ 0.5686274509803921d0 0.17254901960784313d0 0.9333333333333333d0) (define-rgb-color +purple3+ 0.49019607843137253d0 0.14901960784313725d0 0.803921568627451d0) (define-rgb-color +purple4+ 0.3333333333333333d0 0.10196078431372549d0 0.5450980392156862d0) (define-rgb-color +mediumpurple1+ 0.6705882352941176d0 0.5098039215686274d0 1.0d0) (define-rgb-color +mediumpurple2+ 0.6235294117647059d0 0.4745098039215686d0 0.9333333333333333d0) (define-rgb-color +mediumpurple3+ 0.5372549019607843d0 0.40784313725490196d0 0.803921568627451d0) (define-rgb-color +mediumpurple4+ 0.36470588235294116d0 0.2784313725490196d0 0.5450980392156862d0) (define-rgb-color +thistle1+ 1.0d0 0.8823529411764706d0 1.0d0) (define-rgb-color +thistle2+ 0.9333333333333333d0 0.8235294117647058d0 0.9333333333333333d0) (define-rgb-color +thistle3+ 0.803921568627451d0 0.7098039215686275d0 0.803921568627451d0) (define-rgb-color +thistle4+ 0.5450980392156862d0 0.4823529411764706d0 0.5450980392156862d0) (define-rgb-color +gray0+ 0.0d0 0.0d0 0.0d0) (define-rgb-color +grey0+ 0.0d0 0.0d0 0.0d0) (define-rgb-color +gray1+ 0.011764705882352941d0 0.011764705882352941d0 0.011764705882352941d0) (define-rgb-color +grey1+ 0.011764705882352941d0 0.011764705882352941d0 0.011764705882352941d0) (define-rgb-color +gray2+ 0.0196078431372549d0 0.0196078431372549d0 0.0196078431372549d0) (define-rgb-color +grey2+ 0.0196078431372549d0 0.0196078431372549d0 0.0196078431372549d0) (define-rgb-color +gray3+ 0.03137254901960784d0 0.03137254901960784d0 0.03137254901960784d0) (define-rgb-color +grey3+ 0.03137254901960784d0 0.03137254901960784d0 0.03137254901960784d0) (define-rgb-color +gray4+ 0.0392156862745098d0 0.0392156862745098d0 0.0392156862745098d0) (define-rgb-color +grey4+ 0.0392156862745098d0 0.0392156862745098d0 0.0392156862745098d0) (define-rgb-color +gray5+ 0.050980392156862744d0 0.050980392156862744d0 0.050980392156862744d0) (define-rgb-color +grey5+ 0.050980392156862744d0 0.050980392156862744d0 0.050980392156862744d0) (define-rgb-color +gray6+ 0.058823529411764705d0 0.058823529411764705d0 0.058823529411764705d0) (define-rgb-color +grey6+ 0.058823529411764705d0 0.058823529411764705d0 0.058823529411764705d0) (define-rgb-color +gray7+ 0.07058823529411765d0 0.07058823529411765d0 0.07058823529411765d0) (define-rgb-color +grey7+ 0.07058823529411765d0 0.07058823529411765d0 0.07058823529411765d0) (define-rgb-color +gray8+ 0.0784313725490196d0 0.0784313725490196d0 0.0784313725490196d0) (define-rgb-color +grey8+ 0.0784313725490196d0 0.0784313725490196d0 0.0784313725490196d0) (define-rgb-color +gray9+ 0.09019607843137255d0 0.09019607843137255d0 0.09019607843137255d0) (define-rgb-color +grey9+ 0.09019607843137255d0 0.09019607843137255d0 0.09019607843137255d0) (define-rgb-color +gray10+ 0.10196078431372549d0 0.10196078431372549d0 0.10196078431372549d0) (define-rgb-color +grey10+ 0.10196078431372549d0 0.10196078431372549d0 0.10196078431372549d0) (define-rgb-color +gray11+ 0.10980392156862745d0 0.10980392156862745d0 0.10980392156862745d0) (define-rgb-color +grey11+ 0.10980392156862745d0 0.10980392156862745d0 0.10980392156862745d0) (define-rgb-color +gray12+ 0.12156862745098039d0 0.12156862745098039d0 0.12156862745098039d0) (define-rgb-color +grey12+ 0.12156862745098039d0 0.12156862745098039d0 0.12156862745098039d0) (define-rgb-color +gray13+ 0.12941176470588237d0 0.12941176470588237d0 0.12941176470588237d0) (define-rgb-color +grey13+ 0.12941176470588237d0 0.12941176470588237d0 0.12941176470588237d0) (define-rgb-color +gray14+ 0.1411764705882353d0 0.1411764705882353d0 0.1411764705882353d0) (define-rgb-color +grey14+ 0.1411764705882353d0 0.1411764705882353d0 0.1411764705882353d0) (define-rgb-color +gray15+ 0.14901960784313725d0 0.14901960784313725d0 0.14901960784313725d0) (define-rgb-color +grey15+ 0.14901960784313725d0 0.14901960784313725d0 0.14901960784313725d0) (define-rgb-color +gray16+ 0.1607843137254902d0 0.1607843137254902d0 0.1607843137254902d0) (define-rgb-color +grey16+ 0.1607843137254902d0 0.1607843137254902d0 0.1607843137254902d0) (define-rgb-color +gray17+ 0.16862745098039217d0 0.16862745098039217d0 0.16862745098039217d0) (define-rgb-color +grey17+ 0.16862745098039217d0 0.16862745098039217d0 0.16862745098039217d0) (define-rgb-color +gray18+ 0.1803921568627451d0 0.1803921568627451d0 0.1803921568627451d0) (define-rgb-color +grey18+ 0.1803921568627451d0 0.1803921568627451d0 0.1803921568627451d0) (define-rgb-color +gray19+ 0.18823529411764706d0 0.18823529411764706d0 0.18823529411764706d0) (define-rgb-color +grey19+ 0.18823529411764706d0 0.18823529411764706d0 0.18823529411764706d0) (define-rgb-color +gray20+ 0.2d0 0.2d0 0.2d0) (define-rgb-color +grey20+ 0.2d0 0.2d0 0.2d0) (define-rgb-color +gray21+ 0.21176470588235294d0 0.21176470588235294d0 0.21176470588235294d0) (define-rgb-color +grey21+ 0.21176470588235294d0 0.21176470588235294d0 0.21176470588235294d0) (define-rgb-color +gray22+ 0.2196078431372549d0 0.2196078431372549d0 0.2196078431372549d0) (define-rgb-color +grey22+ 0.2196078431372549d0 0.2196078431372549d0 0.2196078431372549d0) (define-rgb-color +gray23+ 0.23137254901960785d0 0.23137254901960785d0 0.23137254901960785d0) (define-rgb-color +grey23+ 0.23137254901960785d0 0.23137254901960785d0 0.23137254901960785d0) (define-rgb-color +gray24+ 0.23921568627450981d0 0.23921568627450981d0 0.23921568627450981d0) (define-rgb-color +grey24+ 0.23921568627450981d0 0.23921568627450981d0 0.23921568627450981d0) (define-rgb-color +gray25+ 0.25098039215686274d0 0.25098039215686274d0 0.25098039215686274d0) (define-rgb-color +grey25+ 0.25098039215686274d0 0.25098039215686274d0 0.25098039215686274d0) (define-rgb-color +gray26+ 0.25882352941176473d0 0.25882352941176473d0 0.25882352941176473d0) (define-rgb-color +grey26+ 0.25882352941176473d0 0.25882352941176473d0 0.25882352941176473d0) (define-rgb-color +gray27+ 0.27058823529411763d0 0.27058823529411763d0 0.27058823529411763d0) (define-rgb-color +grey27+ 0.27058823529411763d0 0.27058823529411763d0 0.27058823529411763d0) (define-rgb-color +gray28+ 0.2784313725490196d0 0.2784313725490196d0 0.2784313725490196d0) (define-rgb-color +grey28+ 0.2784313725490196d0 0.2784313725490196d0 0.2784313725490196d0) (define-rgb-color +gray29+ 0.2901960784313726d0 0.2901960784313726d0 0.2901960784313726d0) (define-rgb-color +grey29+ 0.2901960784313726d0 0.2901960784313726d0 0.2901960784313726d0) (define-rgb-color +gray30+ 0.30196078431372547d0 0.30196078431372547d0 0.30196078431372547d0) (define-rgb-color +grey30+ 0.30196078431372547d0 0.30196078431372547d0 0.30196078431372547d0) (define-rgb-color +gray31+ 0.30980392156862746d0 0.30980392156862746d0 0.30980392156862746d0) (define-rgb-color +grey31+ 0.30980392156862746d0 0.30980392156862746d0 0.30980392156862746d0) (define-rgb-color +gray32+ 0.3215686274509804d0 0.3215686274509804d0 0.3215686274509804d0) (define-rgb-color +grey32+ 0.3215686274509804d0 0.3215686274509804d0 0.3215686274509804d0) (define-rgb-color +gray33+ 0.32941176470588235d0 0.32941176470588235d0 0.32941176470588235d0) (define-rgb-color +grey33+ 0.32941176470588235d0 0.32941176470588235d0 0.32941176470588235d0) (define-rgb-color +gray34+ 0.3411764705882353d0 0.3411764705882353d0 0.3411764705882353d0) (define-rgb-color +grey34+ 0.3411764705882353d0 0.3411764705882353d0 0.3411764705882353d0) (define-rgb-color +gray35+ 0.34901960784313724d0 0.34901960784313724d0 0.34901960784313724d0) (define-rgb-color +grey35+ 0.34901960784313724d0 0.34901960784313724d0 0.34901960784313724d0) (define-rgb-color +gray36+ 0.3607843137254902d0 0.3607843137254902d0 0.3607843137254902d0) (define-rgb-color +grey36+ 0.3607843137254902d0 0.3607843137254902d0 0.3607843137254902d0) (define-rgb-color +gray37+ 0.3686274509803922d0 0.3686274509803922d0 0.3686274509803922d0) (define-rgb-color +grey37+ 0.3686274509803922d0 0.3686274509803922d0 0.3686274509803922d0) (define-rgb-color +gray38+ 0.3803921568627451d0 0.3803921568627451d0 0.3803921568627451d0) (define-rgb-color +grey38+ 0.3803921568627451d0 0.3803921568627451d0 0.3803921568627451d0) (define-rgb-color +gray39+ 0.38823529411764707d0 0.38823529411764707d0 0.38823529411764707d0) (define-rgb-color +grey39+ 0.38823529411764707d0 0.38823529411764707d0 0.38823529411764707d0) (define-rgb-color +gray40+ 0.4d0 0.4d0 0.4d0) (define-rgb-color +grey40+ 0.4d0 0.4d0 0.4d0) (define-rgb-color +gray41+ 0.4117647058823529d0 0.4117647058823529d0 0.4117647058823529d0) (define-rgb-color +grey41+ 0.4117647058823529d0 0.4117647058823529d0 0.4117647058823529d0) (define-rgb-color +gray42+ 0.4196078431372549d0 0.4196078431372549d0 0.4196078431372549d0) (define-rgb-color +grey42+ 0.4196078431372549d0 0.4196078431372549d0 0.4196078431372549d0) (define-rgb-color +gray43+ 0.43137254901960786d0 0.43137254901960786d0 0.43137254901960786d0) (define-rgb-color +grey43+ 0.43137254901960786d0 0.43137254901960786d0 0.43137254901960786d0) (define-rgb-color +gray44+ 0.4392156862745098d0 0.4392156862745098d0 0.4392156862745098d0) (define-rgb-color +grey44+ 0.4392156862745098d0 0.4392156862745098d0 0.4392156862745098d0) (define-rgb-color +gray45+ 0.45098039215686275d0 0.45098039215686275d0 0.45098039215686275d0) (define-rgb-color +grey45+ 0.45098039215686275d0 0.45098039215686275d0 0.45098039215686275d0) (define-rgb-color +gray46+ 0.4588235294117647d0 0.4588235294117647d0 0.4588235294117647d0) (define-rgb-color +grey46+ 0.4588235294117647d0 0.4588235294117647d0 0.4588235294117647d0) (define-rgb-color +gray47+ 0.47058823529411764d0 0.47058823529411764d0 0.47058823529411764d0) (define-rgb-color +grey47+ 0.47058823529411764d0 0.47058823529411764d0 0.47058823529411764d0) (define-rgb-color +gray48+ 0.47843137254901963d0 0.47843137254901963d0 0.47843137254901963d0) (define-rgb-color +grey48+ 0.47843137254901963d0 0.47843137254901963d0 0.47843137254901963d0) (define-rgb-color +gray49+ 0.49019607843137253d0 0.49019607843137253d0 0.49019607843137253d0) (define-rgb-color +grey49+ 0.49019607843137253d0 0.49019607843137253d0 0.49019607843137253d0) (define-rgb-color +gray50+ 0.4980392156862745d0 0.4980392156862745d0 0.4980392156862745d0) (define-rgb-color +grey50+ 0.4980392156862745d0 0.4980392156862745d0 0.4980392156862745d0) (define-rgb-color +gray51+ 0.5098039215686274d0 0.5098039215686274d0 0.5098039215686274d0) (define-rgb-color +grey51+ 0.5098039215686274d0 0.5098039215686274d0 0.5098039215686274d0) (define-rgb-color +gray52+ 0.5215686274509804d0 0.5215686274509804d0 0.5215686274509804d0) (define-rgb-color +grey52+ 0.5215686274509804d0 0.5215686274509804d0 0.5215686274509804d0) (define-rgb-color +gray53+ 0.5294117647058824d0 0.5294117647058824d0 0.5294117647058824d0) (define-rgb-color +grey53+ 0.5294117647058824d0 0.5294117647058824d0 0.5294117647058824d0) (define-rgb-color +gray54+ 0.5411764705882353d0 0.5411764705882353d0 0.5411764705882353d0) (define-rgb-color +grey54+ 0.5411764705882353d0 0.5411764705882353d0 0.5411764705882353d0) (define-rgb-color +gray55+ 0.5490196078431373d0 0.5490196078431373d0 0.5490196078431373d0) (define-rgb-color +grey55+ 0.5490196078431373d0 0.5490196078431373d0 0.5490196078431373d0) (define-rgb-color +gray56+ 0.5607843137254902d0 0.5607843137254902d0 0.5607843137254902d0) (define-rgb-color +grey56+ 0.5607843137254902d0 0.5607843137254902d0 0.5607843137254902d0) (define-rgb-color +gray57+ 0.5686274509803921d0 0.5686274509803921d0 0.5686274509803921d0) (define-rgb-color +grey57+ 0.5686274509803921d0 0.5686274509803921d0 0.5686274509803921d0) (define-rgb-color +gray58+ 0.5803921568627451d0 0.5803921568627451d0 0.5803921568627451d0) (define-rgb-color +grey58+ 0.5803921568627451d0 0.5803921568627451d0 0.5803921568627451d0) (define-rgb-color +gray59+ 0.5882352941176471d0 0.5882352941176471d0 0.5882352941176471d0) (define-rgb-color +grey59+ 0.5882352941176471d0 0.5882352941176471d0 0.5882352941176471d0) (define-rgb-color +gray60+ 0.6d0 0.6d0 0.6d0) (define-rgb-color +grey60+ 0.6d0 0.6d0 0.6d0) (define-rgb-color +gray61+ 0.611764705882353d0 0.611764705882353d0 0.611764705882353d0) (define-rgb-color +grey61+ 0.611764705882353d0 0.611764705882353d0 0.611764705882353d0) (define-rgb-color +gray62+ 0.6196078431372549d0 0.6196078431372549d0 0.6196078431372549d0) (define-rgb-color +grey62+ 0.6196078431372549d0 0.6196078431372549d0 0.6196078431372549d0) (define-rgb-color +gray63+ 0.6313725490196078d0 0.6313725490196078d0 0.6313725490196078d0) (define-rgb-color +grey63+ 0.6313725490196078d0 0.6313725490196078d0 0.6313725490196078d0) (define-rgb-color +gray64+ 0.6392156862745098d0 0.6392156862745098d0 0.6392156862745098d0) (define-rgb-color +grey64+ 0.6392156862745098d0 0.6392156862745098d0 0.6392156862745098d0) (define-rgb-color +gray65+ 0.6509803921568628d0 0.6509803921568628d0 0.6509803921568628d0) (define-rgb-color +grey65+ 0.6509803921568628d0 0.6509803921568628d0 0.6509803921568628d0) (define-rgb-color +gray66+ 0.6588235294117647d0 0.6588235294117647d0 0.6588235294117647d0) (define-rgb-color +grey66+ 0.6588235294117647d0 0.6588235294117647d0 0.6588235294117647d0) (define-rgb-color +gray67+ 0.6705882352941176d0 0.6705882352941176d0 0.6705882352941176d0) (define-rgb-color +grey67+ 0.6705882352941176d0 0.6705882352941176d0 0.6705882352941176d0) (define-rgb-color +gray68+ 0.6784313725490196d0 0.6784313725490196d0 0.6784313725490196d0) (define-rgb-color +grey68+ 0.6784313725490196d0 0.6784313725490196d0 0.6784313725490196d0) (define-rgb-color +gray69+ 0.6901960784313725d0 0.6901960784313725d0 0.6901960784313725d0) (define-rgb-color +grey69+ 0.6901960784313725d0 0.6901960784313725d0 0.6901960784313725d0) (define-rgb-color +gray70+ 0.7019607843137254d0 0.7019607843137254d0 0.7019607843137254d0) (define-rgb-color +grey70+ 0.7019607843137254d0 0.7019607843137254d0 0.7019607843137254d0) (define-rgb-color +gray71+ 0.7098039215686275d0 0.7098039215686275d0 0.7098039215686275d0) (define-rgb-color +grey71+ 0.7098039215686275d0 0.7098039215686275d0 0.7098039215686275d0) (define-rgb-color +gray72+ 0.7215686274509804d0 0.7215686274509804d0 0.7215686274509804d0) (define-rgb-color +grey72+ 0.7215686274509804d0 0.7215686274509804d0 0.7215686274509804d0) (define-rgb-color +gray73+ 0.7294117647058823d0 0.7294117647058823d0 0.7294117647058823d0) (define-rgb-color +grey73+ 0.7294117647058823d0 0.7294117647058823d0 0.7294117647058823d0) (define-rgb-color +gray74+ 0.7411764705882353d0 0.7411764705882353d0 0.7411764705882353d0) (define-rgb-color +grey74+ 0.7411764705882353d0 0.7411764705882353d0 0.7411764705882353d0) (define-rgb-color +gray75+ 0.7490196078431373d0 0.7490196078431373d0 0.7490196078431373d0) (define-rgb-color +grey75+ 0.7490196078431373d0 0.7490196078431373d0 0.7490196078431373d0) (define-rgb-color +gray76+ 0.7607843137254902d0 0.7607843137254902d0 0.7607843137254902d0) (define-rgb-color +grey76+ 0.7607843137254902d0 0.7607843137254902d0 0.7607843137254902d0) (define-rgb-color +gray77+ 0.7686274509803922d0 0.7686274509803922d0 0.7686274509803922d0) (define-rgb-color +grey77+ 0.7686274509803922d0 0.7686274509803922d0 0.7686274509803922d0) (define-rgb-color +gray78+ 0.7803921568627451d0 0.7803921568627451d0 0.7803921568627451d0) (define-rgb-color +grey78+ 0.7803921568627451d0 0.7803921568627451d0 0.7803921568627451d0) (define-rgb-color +gray79+ 0.788235294117647d0 0.788235294117647d0 0.788235294117647d0) (define-rgb-color +grey79+ 0.788235294117647d0 0.788235294117647d0 0.788235294117647d0) (define-rgb-color +gray80+ 0.8d0 0.8d0 0.8d0) (define-rgb-color +grey80+ 0.8d0 0.8d0 0.8d0) (define-rgb-color +gray81+ 0.8117647058823529d0 0.8117647058823529d0 0.8117647058823529d0) (define-rgb-color +grey81+ 0.8117647058823529d0 0.8117647058823529d0 0.8117647058823529d0) (define-rgb-color +gray82+ 0.8196078431372549d0 0.8196078431372549d0 0.8196078431372549d0) (define-rgb-color +grey82+ 0.8196078431372549d0 0.8196078431372549d0 0.8196078431372549d0) (define-rgb-color +gray83+ 0.8313725490196079d0 0.8313725490196079d0 0.8313725490196079d0) (define-rgb-color +grey83+ 0.8313725490196079d0 0.8313725490196079d0 0.8313725490196079d0) (define-rgb-color +gray84+ 0.8392156862745098d0 0.8392156862745098d0 0.8392156862745098d0) (define-rgb-color +grey84+ 0.8392156862745098d0 0.8392156862745098d0 0.8392156862745098d0) (define-rgb-color +gray85+ 0.8509803921568627d0 0.8509803921568627d0 0.8509803921568627d0) (define-rgb-color +grey85+ 0.8509803921568627d0 0.8509803921568627d0 0.8509803921568627d0) (define-rgb-color +gray86+ 0.8588235294117647d0 0.8588235294117647d0 0.8588235294117647d0) (define-rgb-color +grey86+ 0.8588235294117647d0 0.8588235294117647d0 0.8588235294117647d0) (define-rgb-color +gray87+ 0.8705882352941177d0 0.8705882352941177d0 0.8705882352941177d0) (define-rgb-color +grey87+ 0.8705882352941177d0 0.8705882352941177d0 0.8705882352941177d0) (define-rgb-color +gray88+ 0.8784313725490196d0 0.8784313725490196d0 0.8784313725490196d0) (define-rgb-color +grey88+ 0.8784313725490196d0 0.8784313725490196d0 0.8784313725490196d0) (define-rgb-color +gray89+ 0.8901960784313725d0 0.8901960784313725d0 0.8901960784313725d0) (define-rgb-color +grey89+ 0.8901960784313725d0 0.8901960784313725d0 0.8901960784313725d0) (define-rgb-color +gray90+ 0.8980392156862745d0 0.8980392156862745d0 0.8980392156862745d0) (define-rgb-color +grey90+ 0.8980392156862745d0 0.8980392156862745d0 0.8980392156862745d0) (define-rgb-color +gray91+ 0.9098039215686274d0 0.9098039215686274d0 0.9098039215686274d0) (define-rgb-color +grey91+ 0.9098039215686274d0 0.9098039215686274d0 0.9098039215686274d0) (define-rgb-color +gray92+ 0.9215686274509803d0 0.9215686274509803d0 0.9215686274509803d0) (define-rgb-color +grey92+ 0.9215686274509803d0 0.9215686274509803d0 0.9215686274509803d0) (define-rgb-color +gray93+ 0.9294117647058824d0 0.9294117647058824d0 0.9294117647058824d0) (define-rgb-color +grey93+ 0.9294117647058824d0 0.9294117647058824d0 0.9294117647058824d0) (define-rgb-color +gray94+ 0.9411764705882353d0 0.9411764705882353d0 0.9411764705882353d0) (define-rgb-color +grey94+ 0.9411764705882353d0 0.9411764705882353d0 0.9411764705882353d0) (define-rgb-color +gray95+ 0.9490196078431372d0 0.9490196078431372d0 0.9490196078431372d0) (define-rgb-color +grey95+ 0.9490196078431372d0 0.9490196078431372d0 0.9490196078431372d0) (define-rgb-color +gray96+ 0.9607843137254902d0 0.9607843137254902d0 0.9607843137254902d0) (define-rgb-color +grey96+ 0.9607843137254902d0 0.9607843137254902d0 0.9607843137254902d0) (define-rgb-color +gray97+ 0.9686274509803922d0 0.9686274509803922d0 0.9686274509803922d0) (define-rgb-color +grey97+ 0.9686274509803922d0 0.9686274509803922d0 0.9686274509803922d0) (define-rgb-color +gray98+ 0.9803921568627451d0 0.9803921568627451d0 0.9803921568627451d0) (define-rgb-color +grey98+ 0.9803921568627451d0 0.9803921568627451d0 0.9803921568627451d0) (define-rgb-color +gray99+ 0.9882352941176471d0 0.9882352941176471d0 0.9882352941176471d0) (define-rgb-color +grey99+ 0.9882352941176471d0 0.9882352941176471d0 0.9882352941176471d0) (define-rgb-color +gray100+ 1.0d0 1.0d0 1.0d0) (define-rgb-color +grey100+ 1.0d0 1.0d0 1.0d0) (define-rgb-color +darkgrey+ 0.6627450980392157d0 0.6627450980392157d0 0.6627450980392157d0) (define-rgb-color +darkgray+ 0.6627450980392157d0 0.6627450980392157d0 0.6627450980392157d0) (define-rgb-color +darkblue+ 0.0d0 0.0d0 0.5450980392156862d0) (define-rgb-color +darkcyan+ 0.0d0 0.5450980392156862d0 0.5450980392156862d0) (define-rgb-color +darkmagenta+ 0.5450980392156862d0 0.0d0 0.5450980392156862d0) (define-rgb-color +darkred+ 0.5450980392156862d0 0.0d0 0.0d0) (define-rgb-color +lightgreen+ 0.5647058823529412d0 0.9333333333333333d0 0.5647058823529412d0)
57,575
Common Lisp
.lisp
670
84.689552
104
0.845391
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
00654e743dde369bd41e527562c1097aa499294de0ea2199557f9fdc9482c6ea
21,565
[ -1 ]
21,566
parse-x11.lisp
rheaplex_minara/lib/cl-colors/parse-x11.lisp
;; parse X11's rgb.txt (require :cl-ppcre) (let ((color-scanner ; will only take names w/o spaces (cl-ppcre:create-scanner "^\\s*(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+([\\s\\w]+\?)\\s*$" :extended-mode t)) (comment-scanner (cl-ppcre:create-scanner "^\\s*!"))) (with-open-file (s "/usr/share/X11/rgb.txt" :direction :input :if-does-not-exist :error) (with-open-file (colornames "colornames.lisp" :direction :output :if-exists :overwrite :if-does-not-exist :create) (format colornames ";;;; This file was generated automatically ~ by parse-x11.lisp~%~ ;;;; Please do not edit directly.~%~ (in-package :cl-colors)~%~ (defmacro define-rgb-color (name red green blue) `(progn (defconstant ,name (if (boundp ',name) (symbol-value ',name) (make-instance 'rgb :red ,red :green ,green :blue ,blue))) (export ',name)))~%") (labels ((string-to-float (string) (let ((i (read-from-string string))) (assert (and (typep i 'integer) (<= i 255))) (/ i 255d0)))) (do ((line (read-line s nil nil) (read-line s nil nil))) ((not line)) (unless (cl-ppcre:scan-to-strings comment-scanner line) (multiple-value-bind (match registers) (cl-ppcre:scan-to-strings color-scanner line) (if (and match (not (find #\space (aref registers 3)))) (format colornames "(define-rgb-color +~A+ ~A ~A ~A)~%" (string-downcase (aref registers 3)) (string-to-float (aref registers 0)) (string-to-float (aref registers 1)) (string-to-float (aref registers 2))) (format t "ignoring line ~A~%" line)))))))))
1,755
Common Lisp
.lisp
46
30.73913
70
0.570006
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
dfde6fab498ed1f0a5b982bd3a72034765bda1ea329248650ba264e62d5f0e2f
21,566
[ -1 ]
21,567
test.lisp
rheaplex_minara/lib/cl-colors/test.lisp
(in-package :cl-colors) (defun rgb= (rgb1 rgb2 &optional (epsilon 1e-10)) (flet ((eps= (a b) (<= (abs (- a b)) epsilon))) (with-slots ((red1 red) (green1 green) (blue1 blue)) rgb1 (with-slots ((red2 red) (green2 green) (blue2 blue)) rgb2 (and (eps= red1 red2) (eps= green1 green2) (eps= blue1 blue2)))))) (defun test-hsv-rgb () (let* ((rgb (make-instance 'rgb :red (random 1d0) :green (random 1d0) :blue (random 1d0))) (hsv (rgb->hsv rgb)) (rgb2 (hsv->rgb hsv)) (result (rgb= rgb rgb2))) (unless result (format t "~a does not equal ~a~%" rgb rgb2)) result)) (dotimes (i 1000) (test-hsv-rgb)) (defun test-hue-combination (from to positivep) (dotimes (i 21) (format t "~a " (hue-combination from to (/ i 20) positivep))))
793
Common Lisp
.lisp
22
31.727273
67
0.610458
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
abb741f1348fe4527f28368cb7808c9e643068de515d17d6a43624af633731fa
21,567
[ -1 ]
21,568
generate-enums.lisp
rheaplex_minara/lib/cl-opengl/tools/generate-enums.lisp
;;; -*- Mode: Lisp; indent-tabs-mode: nil -*- ;;; ;;; generate-enums.lisp --- Generate OpenGL enums from a .spec file. ;;; ;;; Copyright (c) 2006, Oliver Markovic <[email protected]> ;;; Copyright (c) 2006, Luis Oliveira <[email protected]> ;;; Copyright (c) 2006, James Bielman <[email protected]> ;;; All rights reserved. ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; o Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; o Redistributions in binary form must reproduce the above copyright ;;; notice, this list of conditions and the following disclaimer in the ;;; documentation and/or other materials provided with the distribution. ;;; o Neither the name of the author nor the names of the contributors may ;;; be used to endorse or promote products derived from this software ;;; without specific prior written permission. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ;;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ;;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ;;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ;;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ;;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;;; Bind VAR to VALUE and evaluate BODY is VALUE is non-nil. (defmacro when-bind ((var value) &body body) `(let ((,var ,value)) (when ,var ,@body))) ;;; Recursively apply WHEN-BIND to each binding in BINDINGS, ;;; evaluating BODY only if all bindings are non-nil. (defmacro when-bind* (bindings &body body) (if (null (cdr bindings)) `(when-bind ,(car bindings) ,@body) `(when-bind ,(car bindings) (when-bind* ,(cdr bindings) ,@body)))) ;;; Return true if a character is a whitespace character. (defun whitespacep (char) (member char '(#\Space #\Tab #\Newline #\Return))) (defun string-ends-with (string1 string2) (when (>= (length string1) (length string2)) (string-equal string1 string2 :start1 (- (length string1) (length string2))))) ;;; Smash comments from a line of input (assumed without newlines). ;;; Returns a fresh copy of LINE with comments removed, or LINE ;;; unchanged if no comments were present. (defun smash-comments (line) (let ((pos (position #\# line))) (if pos (subseq line 0 pos) line))) ;;; Remove trailing whitespace from a line of input. (defun smash-trailing-whitespace (line) (string-right-trim '(#\Space #\Tab #\Newline) line)) ;;; Parse a top-level declaration into a name and type. The input ;;; line should be of the form "<name> <type>:". The name and type ;;; are returned as two values. This is more permissive than it ;;; should be, but okay for our purposes here. (defun parse-name-and-type (line) (when-bind* ((space (position #\Space line)) (colon (position #\: line))) (unless (< colon space) (values (subseq line 0 space) (subseq line (1+ space) colon))))) ;;; Parse an inner enum declaration into a name and value. The input ;;; line should begin with a tab, followed by a name, whitespace, an ;;; equals sign, and the numeric value of the constant. (defun parse-enum (line) (when (char= (char line 0) #\Tab) (when-bind* ((space (position-if #'whitespacep line :start 1)) (eq (position #\= line :start space)) (val (position-if-not #'whitespacep line :start (1+ eq)))) (values (subseq line 1 space) (subseq line val))))) ;;; Convert the name of an enum into a CL keyword symbol. (defun convert-enum-name (name) (intern (string-upcase (substitute #\- #\_ name)) :keyword)) ;;; Convert the value into a number, if possible. (defun convert-value (value) (let ((base 10) (start 0)) (when (and (> (length value) 2) (equalp (subseq value 0 2) "0x")) (setf base 16 start 2)) (parse-integer value :start start :radix base :junk-allowed t))) ;;; An instance of PARSER contains the state of the spec file parser. (defclass parser () ((mode :initform :toplevel :accessor parser-mode) (block-type :initform nil :accessor parser-block-type) (enums :initform (make-hash-table) :accessor parser-enums))) (defun maybe-generate-shorthand-name (symbol) (let* ((name (symbol-name symbol)) (len (length name))) (or (and (string-ends-with name "-BITS") (intern (subseq name 0 (- len 5)) '#:keyword)) (and (string-ends-with name "-BIT") (intern (subseq name 0 (- len 4)) '#:keyword))))) ;;; Process the next line of input for the spec parser. (defun parse-line (parser line) (let ((line (smash-trailing-whitespace (smash-comments line))) (block-type (parser-block-type parser)) (enums (parser-enums parser))) (when (plusp (length line)) ;; If we're in :ENUM mode and the first character is not a tab, ;; kick the parser back into toplevel mode. (when (and (eql (parser-mode parser) :enum) (char/= (char line 0) #\Tab)) (setf (parser-mode parser) :toplevel)) (ecase (parser-mode parser) (:toplevel (multiple-value-bind (name type) (parse-name-and-type line) (when name (setf (parser-mode parser) :enum) (setf (parser-block-type parser) type)))) (:enum (when (equalp block-type "enum") (multiple-value-bind (name value) (parse-enum line) (when name (let ((sym (convert-enum-name name)) (value (convert-value value))) (when value ;; We additionally generate versions without the ;; -BIT and -BITS suffixes. (let ((short-symbol (maybe-generate-shorthand-name sym))) (when short-symbol (setf (gethash short-symbol enums) value))) (setf (gethash sym enums) value))))))))))) ;;; Parse a file and build a data structure containing its enums. (defun parse-file (pathname &optional (parser (make-instance 'parser))) (with-open-file (s pathname) (loop for line = (read-line s nil s) until (eql line s) do (parse-line parser line))) parser) ;;; Return a list of the keys of a hash table. (defun hash-table-keys (hash) (loop for name being the hash-keys in hash collect name)) ;;; Write an expression to define a CFFI enum for the enums in PARSER ;;; to STREAM. ;;; ;;; We print them downcased for the convenience of "modern" lisps, and ;;; that requires ~A instead of ~S, otherwise we'd get things like ;;; :|3d|. (defun write-enums (enum-name parser stream) (format stream "(defcenum (~A :unsigned-int)" enum-name) (let* ((enums (parser-enums parser)) (keys (sort (hash-table-keys enums) #'string-lessp)) (*print-case* :downcase)) (dolist (key keys) (format stream "~% (:~A #x~X)" key (gethash key enums)))) (format stream ")~%")) ;;; Generate the CL-OPENGL source file containing the enums from the ;;; two spec files in the distribution. (defun main () (let* ((parser (make-instance 'parser)) (this-file (load-time-value *load-pathname*)) (this-dir (make-pathname :directory (pathname-directory this-file))) (relative-gl (make-pathname :directory '(:relative :up "gl"))) (gl-dir (merge-pathnames relative-gl this-dir)) (relative-spec (make-pathname :directory '(:relative :up "spec"))) (spec-dir (merge-pathnames relative-spec this-dir)) (gl-spec (merge-pathnames "enum.spec" spec-dir)) (ext-spec (merge-pathnames "enumext.spec" spec-dir)) (constants-file (merge-pathnames "constants.lisp" gl-dir))) (format t "~&;; Parsing ~A~%" (namestring gl-spec)) (parse-file gl-spec parser) (format t "~&;; Parsing ~A.~%" (namestring ext-spec)) (parse-file ext-spec parser) (format t "~&;; Writing ~A.~%" (namestring constants-file)) (with-open-file (s constants-file :direction :output :if-exists :supersede) (format s "~&;;; this file is automatically generated, do not edit~%") (format s "(in-package #:cl-opengl-bindings)~%~%") (write-enums "enum" parser s)) (force-output) #+sbcl (sb-ext:quit :unix-status 0)))
8,888
Common Lisp
.lisp
183
43.202186
79
0.661142
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
dab266949ecc95e1fc308df5c4e506b79cd51cc408a8b00ea8589a760a93af86
21,568
[ 175886 ]
21,569
generate-funcs.lisp
rheaplex_minara/lib/cl-opengl/tools/generate-funcs.lisp
;;; -*- Mode: Lisp; indent-tabs-mode: nil -*- ;;; ;;; generate-funcs.lisp --- generate CFFI bindings from .spec files. ;;; ;;; Copyright (c) 2006, Bart Botta <[email protected]> ;;; All rights reserved. ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; o Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; o Redistributions in binary form must reproduce the above copyright ;;; notice, this list of conditions and the following disclaimer in the ;;; documentation and/or other materials provided with the distribution. ;;; o Neither the name of the author nor the names of the contributors may ;;; be used to endorse or promote products derived from this software ;;; without specific prior written permission. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ;;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ;;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ;;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ;;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ;;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; #+:sbcl (require :asdf) (eval-when (:compile-toplevel :load-toplevel :execute) (asdf:operate 'asdf:load-op :cl-ppcre) (asdf:operate 'asdf:load-op :cffi)) (defpackage #:spec-parser (:use #:common-lisp #:cffi #:cl-ppcre) (:export #:main)) (in-package #:spec-parser) ;;; use names-like-this (if nil, make names like %glFooBar) (defparameter *lispy-function-names* t) (defparameter *define-package* t) (defparameter *in-package-name* "cl-opengl-bindings") (defparameter *package-nicknames* "#:%gl") (defparameter *dump-functions* t) (defparameter *core-definer* "defglfun") (defparameter *ext-definer* "defglextfun") ;;; list of names that confuse the regexes, so get renamed by hand ;;; include anything that uses 's' or 'sv' type specifier, or that ;;; ends in 'd' that isn't intended to mean 'double' (defparameter *special-case-list* '(("Rects" . "rect-s") ;; ("Rectsv" . "rect-sv") ("Indexs" . "index-s") ("GlobalAlphaFactorsSUN" . "global-alpha-factor-s-sun") ("TexSubImage4DSGIS" . "tex-sub-image-4d-sgis") ("TexImage4DSGIS" . "tex-image-4d-sgis") ;;("ShaderOp1EXT" . "shader-op-1-ext") ;;("ShaderOp2EXT" . "shader-op-2-ext") ;;("ShaderOp3EXT" . "shader-op-3-ext") ("UniformMatrix2x3fv" . "uniform-matrix-2x3-fv") ("UniformMatrix3x2fv" . "uniform-matrix-3x2-fv") ("UniformMatrix2x4fv" . "uniform-matrix-2x4-fv") ("UniformMatrix4x2fv" . "uniform-matrix-4x2-fv") ("UniformMatrix3x4fv" . "uniform-matrix-3x4-fv") ("UniformMatrix4x3fv" . "uniform-matrix-4x3-fv") ("GetQueryObjecti64vEXT" . "get-query-object-i64v-ext") ("GetQueryObjectui64vEXT" . "get-query-object-ui64v-ext") ("GetBooleanIndexedvEXT" . "get-boolean-indexed-v-ext") ("GetIntegerIndexedvEXT" . "get-integer-indexed-v-ext"))) (defparameter *whole-words* '("push" "depth" "mesh" "finish" "flush" "attach" "detach" "through" "width" "interleaved" "load" "end" "bind" "named" "grid" "coord" "read" "blend" "compressed" "attached" "enabled" "attrib" "multi" "status" "mapped" "instanced" "indexed")) ;;; words ending in 's'... ;;; is arrays textures names pixels lists attribs parameters programs ;;; queries fences points maps pos buffers elements renderbuffers ;;; framebuffers status shaders symbols bounds pntriangles (defun fix-type-suffix (name) (cond ((string-equal name "nv") name) ; vendor name, not vector ((cl-ppcre:scan "^[0-9]N?u?[hbifds]v?$" name) name) ;count+type ((member name *whole-words* :test #'string-equal) name) ;; fix [1-3]D(EXT|ARB) (TexImage1DEXT etc) (but don't break -3dfx) ((cl-ppcre:scan "[1-3]D(EXT|ARB)" name) ;; fixme: stop running the regex twice here... (cl-ppcre:regex-replace "([1-3]D)(EXT|ARB)" name "\\1-\\2")) ;; fix Op1ATI etc from ATI_fragment_shader and Op1EXT from ;; ext_vertex_shader ((cl-ppcre:scan "[1-3](ATI|EXT)" name) (cl-ppcre:regex-replace "([1-3])(EXT|ATI)" name "\\1-\\2")) ;; nv-gpu-program4 extension has a bunch of functions with I before the ;; type signature, not sure if it should be separate or not, ;; leaving it as i4ui etc. for now, but still gets special cased ;; since it confuses the main regex... ((cl-ppcre:scan "^I[1-4]?[bisuv]+$" name) name) (t ; anything else, try to split (cl-ppcre:regex-replace-all ;;# ;;N (normalized VertexAttrib) ;;b s i f d ub us ui ;;v ;; (can't catch the u?i64v? types here, so special case them for now...) ;; 's' catches too many plurals, so skipping for now... ;; (just rect,index anyway, can special case them...) "([a-z][a-tv-z])((?:h|b|i|f|d|ub|us|ui|hv|bv|iv|fv|dv|sv|ubv|usv|uiv|v)|[0-9]+)$" name (lambda (match r1 r2) (declare (ignore match)) (format nil "~A-~A" r1 r2)) :simple-calls t)))) ;;; TODO: fix special cases. (defun fix-type-suffixes (name) (cl-ppcre:regex-replace-all "([^-]+)(-|$)" name (lambda (match r1 r2) (declare (ignore match)) (format nil "~A~A" (fix-type-suffix r1) (or r2 ""))) :simple-calls t)) (defun mixedcaps->lcdash (str) (string-downcase (if (assoc str *special-case-list* :test #'string=) (cdr (assoc str *special-case-list* :test #'string=)) (fix-type-suffixes (cl-ppcre:regex-replace-all "([a-z])([0-9A-Z])" str (lambda (match r1 r2) (declare (ignore match)) (format nil "~A-~A" r1 r2)) :simple-calls t))))) (defun fix-gl-function-name (name) (mixedcaps->lcdash name)) ;;; tags in gl.spec file: ;;; required-props: ;;; param: ... ;;; dlflags: ... ;;; glxflags: ... ;;; vectorequiv: ... ;;; catgory: ... ;;; version: .... ;;; glxsingle: ... ;;; glxropcode: ... ;;; glxvendorpriv: ... ;;; glsflags: ... ;;; glsopcode: ... ;;; glsalias: ... ;;; wglflags: ... ;;; extension: ... ;;; alias: ... ;;; offset: ... ;;; passthru: ... ;;; newcategory ;;; ;;; function def: ;;; name({var{,var2{,...}}) ;;; return type ;;; param name type [in/out] [value/array ...] ;;; dlflags ... ;;; category cat ;;; version ver ;;; extension ;;; glxsingle ... ;;; glsopcode ... ;;; wglflags ... ;;; offset ... (defparameter *gl-types* '("char" "char-arb" "intptr" "sizeiptr" "intptr-arb" "sizeiptr-arb" "handle-arb" "half" "half-arb" "half-nv" "int64" "uint64" "clampd" "double" "clampf" "float" "sizei" "uint" "ushort" "ubyte" "int" "short" "byte" "void" "bitfield" "boolean" #| "enum" |# "string" "int64-ext" "uint64-ext")) (defparameter *type-map* (make-hash-table :test 'equal)) (defun add-type-map (line) (unless (scan "^\\s*#.*" line) (multiple-value-bind (match regs) (scan-to-strings "^([^,]+),\\*,\\*,\\s*([^, ]+),*,*\\s*" line) (if match (if (string= (aref regs 1) "*") (setf (gethash (aref regs 0) *type-map*) (aref regs 0)) (setf (gethash (aref regs 0) *type-map*) (aref regs 1))) (format t "failed to parse type-map line: ~a ~%" line))))) (defun load-type-map (stream) (setf *type-map* (make-hash-table :test 'equal)) (loop for line = (read-line stream nil nil) while line do (add-type-map line)) ;; add some missing types by hand... (setf (gethash "Int64EXT" *type-map*) (gethash "Int64EXT" *type-map* "GLint64EXT")) (setf (gethash "UInt64EXT" *type-map*) (gethash "UInt64EXT" *type-map* "GLuint64EXT")) ;; more types. The gl.tm file is outdated and apparently belongs to ;; the ogl-sample project at: http://oss.sgi.com/projects/ogl-sample/ (loop for (from to) in '(("BufferSize" "GLsizeiptr") ("BufferOffset" "GLintptr") ("BufferTargetARB" "GLenum") ("BufferUsageARB" "GLenum") ("BufferAccessARB" "GLenum") ("BufferPNameARB" "GLenum") ("BufferPointerNameARB" "GLenum") ("BufferSizeARB" "GLsizeiptrARB") ("BufferOffsetARB" "GLintptrARB") ("ProgramTarget" "GLenum") ("FramebufferTarget" "GLenum") ("FramebufferAttachment" "GLenum") ("RenderbufferTarget" "GLenum") ("VertexAttribEnum" "GLenum") ("ProgramParameterPName" "GLenum")) do (setf (gethash from *type-map*) to))) (defparameter *current-fun* nil) (defparameter *function-list* nil) (defclass fun-spec () ((name :initarg :name :accessor name) (return-type :initform "void" :accessor return-type) (category :initform "" :accessor category) (major-version :initform 1 :accessor major) (minor-version :initform 0 :accessor minor) (extension :initform nil :accessor extension) (parameters :initform nil :accessor parameters))) (defclass fun-parm () ((name :initarg :name :accessor name) (ctype :initarg :type :accessor ctype) (array :initarg :array-flag :accessor array-flag) (inout :initarg :inout :accessor in-out) (retained :initarg :retained :accessor retained))) (defun mangle-for-c (name) (concatenate 'string "gl" name)) (defun mangle-for-lisp (name) (if *lispy-function-names* (mixedcaps->lcdash name) (concatenate 'string "%gl" name))) ;; ("GLenum" "handleARB" "UInt32" "VoidPointer" "Boolean" "String" ;; "ErrorCode" "Int32" "List" "void") (defparameter *return-types* nil) (defparameter *parm-types* nil) (defparameter *base-types* '(("int" . ":int") ("unsigned int" . ":unsigned-int") ("char" . ":char") ("signed char" . ":char") ("unsigned char" . ":unsigned-char") ("ptrdiff_t" . ":unsigned-long") ("short" . ":short") ("unsigned short" . ":unsigned-short") ("float" . ":float") ("double" . ":double") ("void" . ":void"))) (defun multi-replace (string regexes replacements) (if (null regexes) string (multi-replace (regex-replace (first regexes) string (first replacements)) (rest regexes) (rest replacements)))) (defun remap-base-types (type) (cond ((assoc type *base-types* :test #'string=) (cdr (assoc type *base-types* :test #'string=))) ((string= type "GL" :end1 2) (multi-replace (subseq type 2) '("EXT" "NV" "ARB") '("-ext" "-nv" "-arb"))) (t type))) (defun remap-base-and-pointer-types (type) (cond ((find #\* type :test #'char=) ;; quick hack to extract types from "foo*", probably breaks ;; on foo**...just replace last '*' with '' (let* ((base (regex-replace "[*]$" type "")) (remapped (remap-base-types base))) (format nil "(:pointer ~a)" remapped))) (t (remap-base-types type)))) (defun fix-arg (arg) (cond ((string= arg "t") "tee") (t arg))) (defun remap-return (type) (let ((remapped (gethash type *type-map* nil))) (if remapped (remap-base-and-pointer-types remapped) (progn (format t "unable to remap return type ~a ~%" type) type)))) (defun remap-type (type) (let ((remapped (gethash type *type-map* nil))) (if remapped (remap-base-and-pointer-types remapped) (progn (format t "unable to remap type ~a ~%" type) type)))) (defun dump-param (stream parm) (format stream "~& (~a ~a)" (fix-arg (name parm)) (if (array-flag parm) (format nil "(:pointer ~a)" (remap-type (ctype parm))) (remap-type (ctype parm))))) (defun dump-fun-wrapper (stream fun) ;; these might be better in docstrings or something, but defcfun ;; doesn't seem to have those, so at least dump some comments with ;; extra info... (format stream "~&~%;;; GL version: ~A.~A, ~A~%" (major fun) (minor fun) (category fun)) ;; spec files don't have consistent extension flags, so use ;; the same heuristic as the perl parsers do: ;; version >= 1.2, or category starting with capital letter (format stream "(~A (\"~A\" ~A) ~A" (if (or (extension fun) (or (>= (major fun) 2) (>= (minor fun) 2)) (upper-case-p (char (category fun) 0))) *ext-definer* *core-definer*) (mangle-for-c (name fun)) (mangle-for-lisp (name fun)) (remap-return (return-type fun))) (loop for i in (parameters fun) do (dump-param stream i)) (format stream ")~%")) (defun new-fun (name) ;; (format t " starting function : ~a ~%" name) (setf *current-fun* (make-instance 'fun-spec :name name))) (defun finish-fun () (when *current-fun* ;;(format t " finishing function ~a ~%" *current-fun*) ;; (dump-fun-wrapper t *current-fun*) (push *current-fun* *function-list*) (setf *current-fun* nil))) (defun add-param (name type io val-array array-size retained) (declare (ignorable io array-size retained)) (setf (parameters *current-fun*) (append (parameters *current-fun*) (list (make-instance 'fun-parm :name name :type type :array-flag (string= val-array "array") :inout io :retained retained))))) (defun set-return (return-type) (setf (return-type *current-fun*) return-type)) (defun set-category (cat) (setf (category *current-fun*) cat)) (defun set-version (ver) (setf (major *current-fun*) (parse-integer ver :junk-allowed t)) (setf (minor *current-fun*) (parse-integer ver :junk-allowed t :start (1+ (position #\. ver))))) (defun set-extension (&optional flags) (setf (extension *current-fun*) (or flags t))) (defmacro make-matcher (regex &body body) `(lambda (line) (multiple-value-bind (match regs) (scan-to-strings ,regex line) (flet ((reg (n) (aref regs n))) (if match (progn ,@body t) nil))))) (defmacro ignore-matcher (regex) `(lambda (line) (multiple-value-bind (match regs) (scan-to-strings ,regex line) (declare (ignorable regs)) (if match (progn ;;(format t "ignoring line ~s (~s ~s)~%" line match regs) t) nil)))) (defmacro ignore-tag (tag) `(ignore-matcher ,(format nil "^~a:.*$" tag))) (defmacro ignore-ftag (tag) `(ignore-matcher ,(format nil "^\\s+~a(?:\\s+.*)?$" tag))) (defparameter *parsers* (list (ignore-tag "required-props") (ignore-tag "param") (ignore-tag "dlflags") (ignore-tag "glxflags") (ignore-tag "vectorequiv") (ignore-tag "category") (ignore-tag "version") (ignore-tag "glxsingle") (ignore-tag "glxropcode") (ignore-tag "glxvendorpriv") (ignore-tag "glsflags") (ignore-tag "glsopcode") (ignore-tag "glsalias") (ignore-tag "wglflags") (ignore-tag "extension") (ignore-tag "alias") (ignore-tag "offset") (ignore-tag "passthru") (ignore-tag "newcategory") (ignore-tag "glfflags") (ignore-tag "beginend") (ignore-tag "glxvectorequiv") (make-matcher "^(\\w+)\\(.*\\)$" (new-fun (reg 0))) (make-matcher "^\\s*$" (finish-fun)) (make-matcher "^\\s+return\\\s+(\\w+)$" (set-return (reg 0))) ;; param name type [in/out] [value/array \[#/name/compsize(...)\] [retained]] (make-matcher "^\\s+param\\s+(\\w+)\\s+(\\w+)\\s+(in|out)\\s+(\\w+)(?:\\s+([^\\s]+))?(?:\\s+(retained))?$" (add-param (reg 0) (reg 1) (reg 2) (reg 3) (reg 4) (reg 5))) (make-matcher "^\\s+category\\s+([\\w-]+)$" (set-category (reg 0))) (make-matcher "^\\s+version\\s+([^\\s]+)$" (set-version (reg 0))) (make-matcher "^\\s+extension(?:\\s+(.*))?$$" (set-extension (reg 0))) (ignore-ftag "vectorequiv") (ignore-ftag "glsopcode") (ignore-ftag "glxropcode") (ignore-ftag "offset") (ignore-ftag "wglflags") (ignore-ftag "glsflags") (ignore-ftag "glxflags") (ignore-ftag "dlflags") (ignore-ftag "glxsingle") (ignore-ftag "glxvendorpriv") (ignore-ftag "glsalias") (ignore-ftag "alias") (ignore-ftag "glfflags") (ignore-ftag "glxvectorequiv") (ignore-ftag "beginend") (make-matcher ".*" (format t " unmatched line? ~s ~%" line)))) (defun parse-glspec-line (line) (loop for regex in *parsers* until (funcall regex line))) (defun clean-line (line) "remove comments and trailing whitespace, nil->empty string" (if (null line) "" (cl-ppcre:regex-replace "\\s*(#.*)?$" line ""))) (defun parse-gl.spec (stream) (setf *current-fun* nil) (setf *function-list* nil) (loop for line = (read-line stream nil nil) for cleaned = (clean-line line) do (parse-glspec-line cleaned) while line) ;; (setf *function-list* (sort *function-list* #'string< :key #'category))) (setf *function-list* (nreverse *function-list*))) (defparameter *glext-version* nil) (defparameter *glext-last-updated* "<unknown>") ;;; quick hack to grab version/modified data from enumext.spec ;;; ;;; really should do it while parsing the file, looks easier to do ;;; separately than patch into the enum parsing code though... (defun get-glext-version (stream) (loop for line = (read-line stream nil nil) while line do (multiple-value-bind (match regs) (scan-to-strings "^passthru:\\s+.*last updated ([^\\s]+)\\s*" line) (when match (setf *glext-last-updated* (aref regs 0)))) (multiple-value-bind (match regs) (scan-to-strings "^passthru:\\s+#define GL_GLEXT_VERSION\\s+([^\\s]+)" line) (when match (setf *glext-version* (parse-integer (aref regs 0))))))) (defun main () (let* ((this-file (load-time-value *load-pathname*)) (this-dir (make-pathname :directory (pathname-directory this-file))) (relative-gl (make-pathname :directory '(:relative :up "gl"))) (gl-dir (merge-pathnames relative-gl this-dir)) (relative-spec (make-pathname :directory '(:relative :up "spec"))) (spec-dir (merge-pathnames relative-spec this-dir)) (gl-tm (merge-pathnames "gl.tm" this-dir)) (copyright-file (merge-pathnames "OSSCOPYRIGHT" this-dir)) (gl-spec (merge-pathnames "gl.spec" spec-dir)) ;(enum-spec (merge-pathnames "enum.spec" spec-dir)) (enumext-spec (merge-pathnames "enumext.spec" spec-dir)) (binding-package-file (merge-pathnames "bindings-package.lisp" gl-dir)) (funcs-file (merge-pathnames "funcs.lisp" gl-dir))) (format t "~&;; loading .tm file ~A~%" (namestring gl-tm)) (with-open-file (s gl-tm) (load-type-map s)) (format t "~&;; parsing gl.spec file ~A~%" (namestring gl-spec)) (with-open-file (s gl-spec) (parse-gl.spec s)) (format t "~&;; getting enumext version from ~A~%" (namestring gl-tm)) (with-open-file (s enumext-spec) (get-glext-version s)) (when *define-package* (format t "~&;; Writing ~A.~%" (namestring binding-package-file)) (with-open-file (out binding-package-file :direction :output :if-exists :supersede) (format out ";;; generated file, do not edit~%") (format out ";;; glext version ~a ( ~a )~%~%" *glext-version* *glext-last-updated*) (format out "(defpackage #:~a~%" *in-package-name*) (when *package-nicknames* (format out " (:nicknames ~a)~%" *package-nicknames*)) (format out " (:use #:common-lisp #:cffi)~%") (format out " (:shadow #:char #:float #:byte #:boolean #:string)~%") (format out " (:export~%") (format out " #:enum~%") (format out " #:*glext-version*~%") (format out " #:*glext-last-updated*~%") (format out " #:*gl-get-proc-address*~%") ;; types (format out "~% ;; Types.~% ") (loop for type in *gl-types* do (format out "~<~% ~1,70:;#:~A ~>" type)) ;; functions (format out "~%~% ;; Functions.~% ") (loop for i in *function-list* do (format out "~<~% ~1,70:;#:~A ~>" (string-downcase (mangle-for-lisp (name i))))) (format out "))~%~%"))) (format t "~&;; Writing ~A.~%" (namestring funcs-file)) (with-open-file (out funcs-file :direction :output :if-exists :supersede) (format out ";;; generated file, do not edit~%~%") (format out ";;; generated from files with following copyright:~%;;;~%") (with-open-file (copyright copyright-file) (loop for line = (read-line copyright nil nil) while line do (format out ";;; ~a~%" line))) (format out ";;;~%~%") (format out ";;; glext version ~a ( ~a )~%~%" *glext-version* *glext-last-updated*) (when *in-package-name* (format out "(in-package #:~a)~%~%" *in-package-name*)) (format out "(defparameter *glext-version* ~s)~%" *glext-version*) (format out "(defparameter *glext-last-updated* ~s)~%" *glext-last-updated*) (when *dump-functions* (loop for i in *function-list* do (dump-fun-wrapper out i)))) (force-output) #+sbcl (sb-ext:quit :unix-status 0)))
22,092
Common Lisp
.lisp
523
36.195029
99
0.605253
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
ff8c06f9e3a303680db6763cae7c577577db216c73f77f1734a4310de5ac5684
21,569
[ -1 ]
21,570
glut-teapot.lisp
rheaplex_minara/lib/cl-opengl/examples/misc/glut-teapot.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; glut-teapot.lisp --- Simple usage of glut:solid-teapot. (in-package #:cl-glut-examples) (defclass glut-teapot-window (glut:window) () (:default-initargs :width 250 :height 250 :title "glut-teapot.lisp" :mode '(:single :rgb :depth))) (defmethod glut:display-window :before ((w glut-teapot-window)) (gl:clear-color 0 0 0 0) (gl:cull-face :back) (gl:depth-func :less) (gl:disable :dither) (gl:shade-model :smooth) (gl:light-model :light-model-local-viewer 1) (gl:color-material :front :ambient-and-diffuse) (gl:enable :light0 :lighting :cull-face :depth-test)) (defmethod glut:display ((window glut-teapot-window)) (gl:load-identity) (gl:translate 0 0 -5) (gl:rotate 30 1 1 0) (gl:light :light0 :position '(0 1 1 0)) (gl:light :light0 :diffuse '(0.2 0.4 0.6 0)) (gl:clear :color-buffer :depth-buffer) (gl:color 1 1 1) (gl:front-face :cw) (glut:solid-teapot 1.3) (gl:front-face :ccw) (gl:flush)) (defmethod glut:reshape ((window glut-teapot-window) width height) (gl:viewport 0 0 width height) (gl:matrix-mode :projection) (gl:load-identity) (glu:perspective 50 (/ width height) 0.5 20) (gl:matrix-mode :modelview) (gl:load-identity)) (defmethod glut:keyboard ((window glut-teapot-window) key x y) (declare (ignore x y)) (when (eql key #\Esc) (glut:destroy-current-window))) (defun glut-teapot () (glut:display-window (make-instance 'glut-teapot-window)))
1,494
Common Lisp
.lisp
41
33.219512
69
0.686247
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
1669a76bcd089803fae477126558ee0234501f268981385c50fc4249e14b7934
21,570
[ 237055 ]
21,571
molview.lisp
rheaplex_minara/lib/cl-opengl/examples/misc/molview.lisp
;; Doug Hoyte, March 2007 ;; Assignment 2: Molecule Viewer ;; COSC414 with Dr. Alan Paeth, UBC Okanagan ;; To protect your rights, this program is distributed under ;; the terms and conditions of the GNU GPL, http://gnu.org ;; For power I decided to use Common Lisp instead of C. ;; This should be ANSI Common Lisp code that uses the OpenGL ;; libraries through the cl-opengl bindings. ;; Tested with SBCL 1.0.3 and the most recent cl-opengl bindings ;; available here: http://common-lisp.net/project/cl-opengl/ ;; Usage: ;; $ sbcl --load molview.lisp ;; ... ;; * (molview ethanol) ;; or ;; * (molview (with-open-file ...)) ;; Commands: ;; x/X - Rotate molecule around X axis ;; y/Y - Rotate molecule around Y axis ;; z/Z - Rotate molecule around Z axis ;; t/T - Rotate light source around theta ;; p/P - Rotate light source around phi ;; r/R - Increase/decrease red light component ;; g/G - Increase/decrease green light component ;; b/B - Increase/decrease blue light component ;; s/S - Increase/decrease number of sphere slices ;; w - Toggle "random walk" frame-rate testing mode ;; m - Toggle solid sphere vs wire sphere ;; l - Toggle showing light source ;; We depend on cl-glut (which depends on cl-opengl and cffi) (require :cl-glut) ;; Hard-coded molecules (defconstant water '((O 0.000 0.000 0.000) (H -0.900 0.000 0.000) (H 0.000 1.000 0.000))) (defconstant ethanol '((C -0.426 -0.115 -0.147) (O -0.599 1.244 -0.481) (H -0.750 -0.738 -0.981) (H -1.022 -0.351 0.735) (H -1.642 1.434 -0.689) (C 1.047 -0.383 0.147) (H 1.370 0.240 0.981) (H 1.642 -0.147 -0.735) (H 1.180 -1.434 0.405))) ;; Variables/Constants (defconstant spin-speed 5) (defvar slices 40) ; number of hori/verti slices on spheres (defvar model-type 'solid) (defvar curr-mol) (defvar view-rotx 20) (defvar view-roty 30) (defvar view-rotz 0) (defvar show-light-source nil) (defvar light-theta 0) (defvar light-phi 0) (defvar light-dist 5) (defconstant light-spin-speed .0872664625) ; 5 degrees in radians (defvar light-r .8) (defvar light-g .8) (defvar light-b .8) (defconstant light-colour-vel .1) (defvar walk-mode nil) ;; Main function (defun molview (mol) (setq curr-mol mol) (glut:display-window (make-instance 'mol-window))) ;; Our molecule viewer class (defclass mol-window (glut:window) () (:default-initargs :title "Doug Hoyte - Molecule Viewer" :width 500 :height 500 :mode '(:double :rgb :depth))) (defun draw-light-source () (gl:with-pushed-matrix (gl:material :front :ambient (vector light-r light-g light-b 1)) (gl:translate (* light-dist (cos light-theta) (sin light-phi)) (* light-dist (sin light-theta) (sin light-phi)) (* light-dist (cos light-phi))) (glut:solid-sphere 0.1 20 20))) (defun draw-atom (element x y z) (gl:with-pushed-matrix (gl:rotate view-rotx 1 0 0) (gl:rotate view-roty 0 1 0) (gl:rotate view-rotz 0 0 1) (gl:material :front :ambient-and-diffuse (case element ((H) #(0.8 0.8 0.8 1)) ((O) #(0.8 0.1 0.0 1)) ((C) #(0.2 0.2 0.2 1)))) (gl:translate x y z) (funcall (if (eq model-type 'wire) #'glut:wire-sphere #'glut:solid-sphere) (case element ((H) 0.7) ((O) 1.0) ((C) 1.2)) slices slices))) (defmethod glut:display ((window mol-window)) (gl:clear :color-buffer-bit :depth-buffer-bit) (gl:light :light0 :position (vector (* light-dist (cos light-theta) (sin light-phi)) (* light-dist (sin light-theta) (sin light-phi)) (* light-dist (cos light-phi)) 0)) (gl:light :light0 :diffuse (vector light-r light-g light-b 1)) (gl:enable :cull-face :lighting :light0 :depth-test) (if show-light-source (draw-light-source)) (dolist (a curr-mol) (apply #'draw-atom a)) (glut:swap-buffers)) (defmethod glut:reshape ((w mol-window) width height) (gl:viewport 0 0 width height) (gl:matrix-mode :projection) (gl:load-identity) (let ((h (/ height width))) (gl:frustum -1 1 (- h) h 9 50)) (gl:matrix-mode :modelview) (gl:load-identity) (gl:translate 0 0 -40)) ;; Input methods (defmacro lim-between (sym bot top) `(setq ,sym (max ,bot (min ,top ,sym)))) (defmethod glut:keyboard ((window mol-window) key x y) (declare (ignore x y)) (case key (#\x (incf view-rotx spin-speed)) (#\X (decf view-rotx spin-speed)) (#\y (incf view-roty spin-speed)) (#\Y (decf view-roty spin-speed)) (#\z (incf view-rotz spin-speed)) (#\Z (decf view-rotz spin-speed)) (#\t (incf light-theta light-spin-speed)) (#\T (decf light-theta light-spin-speed)) (#\p (incf light-phi light-spin-speed)) (#\P (decf light-phi light-spin-speed)) (#\r (incf light-r light-colour-vel)) (#\R (decf light-r light-colour-vel)) (#\g (incf light-g light-colour-vel)) (#\G (decf light-g light-colour-vel)) (#\b (incf light-b light-colour-vel)) (#\B (decf light-b light-colour-vel)) (#\w (if walk-mode (glut:disable-event window :idle) (glut:enable-event window :idle)) (setq walk-mode (not walk-mode))) (#\m (setq model-type (if (eq model-type 'wire) 'solid 'wire))) (#\s (incf slices)) (#\S (decf slices)) (#\l (setq show-light-source (not show-light-source))) (#\q (glut:destroy-current-window) (return-from glut:keyboard))) (lim-between light-r 0 1) (lim-between light-g 0 1) (lim-between light-b 0 1) (lim-between slices 1 100) (glut:post-redisplay)) (defvar origclick) (defvar origrot) (defmethod glut:mouse ((window mol-window) button state x y) (if (eq button :left-button) (if (eq state :down) (progn (setf origrot (list view-rotx view-roty)) (setf origclick (list x y))) (setf origclick ())))) (defmethod glut:motion ((window mol-window) x y) (setf view-rotx (+ (car origrot) (- y (cadr origclick)))) (setf view-roty (+ (cadr origrot) (- x (car origclick)))) (glut:post-redisplay)) (defun random-interval (bot top) (+ (* (- top bot) (/ (random 100000) 100000.0)) bot)) (defvar view-rotx-vel 0) (defvar view-roty-vel 0) (defvar view-rotz-vel 0) (defvar last-update 0) (defvar counter 0) (defmethod glut:idle ((window mol-window)) (if walk-mode (progn (incf counter) (if (< (+ last-update internal-time-units-per-second) (get-internal-real-time)) (progn (format t "~a frames per second with ~a slices.~%" counter slices) (setq counter 0) (setq last-update (get-internal-real-time)))) (incf view-rotx-vel (random-interval -.1 .1)) (incf view-roty-vel (random-interval -.1 .1)) (incf view-rotz-vel (random-interval -.1 .1)) (lim-between view-rotx-vel -2 2) (lim-between view-roty-vel -2 2) (lim-between view-rotz-vel -2 2) (incf view-rotx view-rotx-vel) (incf view-roty view-roty-vel) (incf view-rotz view-rotz-vel) (incf light-r (random-interval -.02 .02)) (incf light-g (random-interval -.02 .02)) (incf light-b (random-interval -.02 .02)) (lim-between light-r 0 1) (lim-between light-g 0 1) (lim-between light-b 0 1))) (glut:post-redisplay))
7,399
Common Lisp
.lisp
200
32.165
86
0.635841
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
a0f37a8b4874f11610319cacd5f1c0419b7d8f4784c87e9238bb424a1a27ca4f
21,571
[ 301664 ]
21,572
opengl-array.lisp
rheaplex_minara/lib/cl-opengl/examples/misc/opengl-array.lisp
;;; -*- Mode: Lisp; indent-tabs-mode: nil -*- (in-package #:cl-glut-examples) (gl:define-gl-array-format position-color (gl:vertex :type :float :components (x y)) (gl:color :type :unsigned-char :components (r g b))) (defclass opengl-array-window (glut:window) ((vertex-array :accessor vertex-array :initform (gl:alloc-gl-array 'position-color 5)) (indices-array :accessor indices-array :initform (gl:alloc-gl-array :unsigned-short 10))) (:default-initargs :title "opengl-array.lisp")) (defmethod glut:display-window :before ((w opengl-array-window)) (dotimes (i 5) (let ((phi (float (+ (/ pi 2) (* (/ i 5) (* 2 pi))) 0.0))) ;; vertices (setf (gl:glaref (vertex-array w) i 'x) (cos phi)) (setf (gl:glaref (vertex-array w) i 'y) (sin phi)) ;; indices (setf (gl:glaref (indices-array w) (* 2 i)) i) (setf (gl:glaref (indices-array w) (1+ (* 2 i))) (mod (+ i 2) 5)) ;; colors (setf (gl:glaref (vertex-array w) i 'r) 255) (setf (gl:glaref (vertex-array w) i 'g) 0) (setf (gl:glaref (vertex-array w) i 'b) 0))) (gl:clear-color 0 0 0 0)) (defmethod glut:display ((w opengl-array-window)) (gl:clear :color-buffer) (gl:enable-client-state :vertex-array) (gl:enable-client-state :color-array) (gl:bind-gl-vertex-array (vertex-array w)) (gl:draw-elements :lines (indices-array w)) (gl:flush)) (defmethod glut:close ((w opengl-array-window)) (gl:free-gl-array (vertex-array w)) (gl:free-gl-array (indices-array w))) (defun misc-opengl-array () (glut:display-window (make-instance 'opengl-array-window)))
1,631
Common Lisp
.lisp
37
39.324324
71
0.640202
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
0ab3e18fe924fc0009f2409dae026ba14f5b3caf505e383ba4a5acf821c3207a
21,572
[ -1 ]
21,573
render-to-texture.lisp
rheaplex_minara/lib/cl-opengl/examples/misc/render-to-texture.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; render-to-texture.lisp --- Simple usage of the EXT_framebuffer_object extension (in-package #:cl-glut-examples) (defclass render-to-texture-window (glut:window) ((texture :accessor texture) (framebuffer :accessor framebuffer)) (:default-initargs :width 640 :height 480 :title "render-to-texture.lisp" :mode '(:double :rgb :depth :multisample))) ;;; Do initialization here: ;;; ;;; In order to render to a texture, we need to setup a complete framebuffer, ;;; which consists of color-buffers, a depth-buffer and a stencil-buffer. ;;; In our simple case, we setup a texture as color-buffer and add a 24-bit ;;; depth-buffer so we can render the teapot correctly. We don't attach a ;;; stencil-buffer since it isn't needed in this simple example. (defmethod glut:display-window :before ((w render-to-texture-window)) (let ((framebuffer (first (gl:gen-framebuffers-ext 1))) (depthbuffer (first (gl:gen-renderbuffers-ext 1))) (texture (first (gl:gen-textures 1)))) ;; setup framebuffer (gl:bind-framebuffer-ext :framebuffer-ext framebuffer) ;; setup texture and attach it to the framebuffer (gl:bind-texture :texture-2d texture) (gl:tex-parameter :texture-2d :texture-min-filter :linear-mipmap-linear) (gl:tex-parameter :texture-2d :texture-mag-filter :linear) (gl:tex-image-2d :texture-2d 0 :rgba 512 512 0 :rgba :unsigned-byte (cffi:null-pointer)) (gl:generate-mipmap-ext :texture-2d) (gl:bind-texture :texture-2d 0) (gl:framebuffer-texture-2d-ext :framebuffer-ext :color-attachment0-ext :texture-2d texture 0) ;; setup depth-buffer and attach it to the framebuffer (gl:bind-renderbuffer-ext :renderbuffer-ext depthbuffer) (gl:renderbuffer-storage-ext :renderbuffer-ext :depth-component24 512 512) (gl:framebuffer-renderbuffer-ext :framebuffer-ext :depth-attachment-ext :renderbuffer-ext depthbuffer) ;; validate framebuffer (let ((framebuffer-status (gl:check-framebuffer-status-ext :framebuffer-ext))) (unless (eql framebuffer-status :framebuffer-complete-ext) (error "Framebuffer not complete: ~A." framebuffer-status))) (setf (texture w) texture (framebuffer w) framebuffer)) (gl:enable :depth-test :multisample)) (defmethod glut:display ((window render-to-texture-window)) (gl:load-identity) ;; We render the teapot in the first pass. To do this, we switch to our ;; custom framebuffer, set the viewport to the texture size and render it ;; normally. (gl:bind-framebuffer-ext :framebuffer-ext (framebuffer window)) (gl:viewport 0 0 512 512) (gl:matrix-mode :projection) (gl:load-identity) (glu:perspective 50 1 0.5 20) (gl:matrix-mode :modelview) (draw-teapot) ;; Now that the texture has been updated, we can draw the spinning quad(s) in ;; the second pass. We want to render into the window, so we need to bind to ;; the default framebuffer, which always has the ID 0. (gl:bind-framebuffer-ext :framebuffer-ext 0) (gl:viewport 0 0 (glut:width window) (glut:height window)) (gl:matrix-mode :projection) (gl:load-identity) (glu:perspective 50 (/ (glut:width window) (glut:height window)) 0.5 20) (gl:matrix-mode :modelview) (draw-spinning-quad (texture window)) (glut:swap-buffers)) (defmethod glut:idle ((window render-to-texture-window)) (glut:post-redisplay)) (defmethod glut:reshape ((window render-to-texture-window) width height) (setf (glut:width window) width (glut:height window) height)) (defmethod glut:keyboard ((window render-to-texture-window) key x y) (declare (ignore x y)) (when (eql key #\Esc) (glut:destroy-current-window))) (defun render-to-texture () (glut:display-window (make-instance 'render-to-texture-window))) ;;; FIXME: the rotations are dependent on the frame rate. ;;; I'd need to calculate the frametime, but I'm too lazy right now. (defparameter *teapot-rotation-x* 0.0) (defparameter *teapot-rotation-y* 0.0) (defparameter *teapot-rotation-z* 0.0) (defun draw-teapot () (gl:clear-color 0 0.3 0.5 1.0) (gl:clear :color-buffer :depth-buffer) (gl:disable :blend :texture-2d) (gl:enable :lighting :light0 :depth-test) (gl:color-material :front :ambient-and-diffuse) (gl:light :light0 :position '(0 1 1 0)) (gl:light :light0 :diffuse '(0.2 0.4 0.6 0)) (gl:load-identity) (gl:translate 0 0 -4) (gl:rotate *teapot-rotation-x* 1 0 0) (gl:rotate *teapot-rotation-y* 0 1 0) (gl:rotate *teapot-rotation-z* 0 0 1) (gl:color 1 1 1) (glut:solid-teapot 1.3) (incf *teapot-rotation-x* 0.01) (incf *teapot-rotation-y* 0.05) (incf *teapot-rotation-z* 0.03)) (defparameter *quad-rotation* 0.0) (defun draw-spinning-quad (texture) (gl:clear-color 0 0 0 0) (gl:clear :color-buffer :depth-buffer) (gl:disable :lighting) (gl:enable :blend :texture-2d :depth-test) (gl:blend-func :src-alpha :one) (gl:load-identity) (gl:translate 0 -1 -3) (gl:rotate *quad-rotation* 0 1 0) (gl:bind-texture :texture-2d texture) ;; the teapot texture gets regenerated every frame, so we also need to ;; recalculate the mipmaps every frame since trilinear filtering is enabled. (gl:generate-mipmap-ext :texture-2d) ;; draw textured quad (gl:color 1 1 1) (gl:with-primitives :quads (gl:tex-coord 0 1) (gl:vertex -1 2) (gl:tex-coord 1 1) (gl:vertex 1 2) (gl:tex-coord 1 0) (gl:vertex 1 0) (gl:tex-coord 0 0) (gl:vertex -1 0)) ;; draw fake reflection (gl:with-primitives :quads (gl:color 1 1 1 0.7) (gl:tex-coord 0 0) (gl:vertex -1 0) (gl:tex-coord 1 0) (gl:vertex 1 0) (gl:tex-coord 1 0.5) (gl:color 1 1 1 0) (gl:vertex 1 -1) (gl:tex-coord 0 0.5) (gl:vertex -1 -1)) (incf *quad-rotation* 0.1))
6,071
Common Lisp
.lisp
142
37.274648
92
0.676341
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
03b593634ccc24cb649743896078e58c1ca0f58885a134774c4d7ed593ec3ab1
21,573
[ 53189 ]
21,574
gears.lisp
rheaplex_minara/lib/cl-opengl/examples/mesademos/gears.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; gears.lisp --- Lisp version of gears.c (GLUT Mesa demos). ;;; ;;; Simple program with rotating 3-D gear wheels. ;;; (lispier version) (in-package #:cl-glut-examples) ;(declaim (optimize (speed 3) (safety 0) (compilation-speed 0) (debug 0))) (defconstant +pif+ (coerce pi 'single-float)) (defun draw-gear (inner-radius outer-radius width n-teeth tooth-depth) "Draw a gear." (declare (single-float inner-radius outer-radius width tooth-depth) (fixnum n-teeth)) (let ((r0 inner-radius) (r1 (- outer-radius (/ tooth-depth 2.0))) (r2 (+ outer-radius (/ tooth-depth 2.0))) (da (/ (* 2.0 +pif+) n-teeth 4.0))) (gl:shade-model :flat) (gl:normal 0 0 1) ;; Draw front face. (gl:with-primitives :quad-strip (dotimes (i (1+ n-teeth)) (let ((angle (/ (* i 2.0 +pif+) n-teeth))) (gl:vertex (* r0 (cos angle)) (* r0 (sin angle)) (* width 0.5)) (gl:vertex (* r1 (cos angle)) (* r1 (sin angle)) (* width 0.5)) (gl:vertex (* r0 (cos angle)) (* r0 (sin angle)) (* width 0.5)) (gl:vertex (* r1 (cos (+ angle (* 3 da)))) (* r1 (sin (+ angle (* 3 da)))) (* width 0.5))))) ;; Draw front sides of teeth. (gl:with-primitives :quads (dotimes (i n-teeth) (let ((angle (/ (* i 2.0 +pif+) n-teeth))) (gl:vertex (* r1 (cos angle)) (* r1 (sin angle)) (* width 0.5)) (gl:vertex (* r2 (cos (+ angle da))) (* r2 (sin (+ angle da))) (* width 0.5)) (gl:vertex (* r2 (cos (+ angle (* 2 da)))) (* r2 (sin (+ angle (* 2 da)))) (* width 0.5)) (gl:vertex (* r1 (cos (+ angle (* 3 da)))) (* r1 (sin (+ angle (* 3 da)))) (* width 0.5))))) (gl:normal 0 0 -1) ;; Draw back face. (gl:with-primitives :quad-strip (dotimes (i (1+ n-teeth)) (let ((angle (/ (* i 2.0 +pif+) n-teeth))) (gl:vertex (* r1 (cos angle)) (* r1 (sin angle)) (* width -0.5)) (gl:vertex (* r0 (cos angle)) (* r0 (sin angle)) (* width -0.5)) (gl:vertex (* r1 (cos (+ angle (* 3 da)))) (* r1 (sin (+ angle (* 3 da)))) (* width -0.5)) (gl:vertex (* r0 (cos angle)) (* r0 (sin angle)) (* width -0.5))))) ;; Draw back sides of teeth. (gl:with-primitives :quads (dotimes (i n-teeth) (let ((angle (/ (* i 2.0 +pif+) n-teeth))) (gl:vertex (* r1 (cos (+ angle (* 3 da)))) (* r1 (sin (+ angle (* 3 da)))) (* (- width) 0.5)) (gl:vertex (* r2 (cos (+ angle (* 2 da)))) (* r2 (sin (+ angle (* 2 da)))) (* (- width) 0.5)) (gl:vertex (* r2 (cos (+ angle da))) (* r2 (sin (+ angle da))) (* (- width) 0.5)) (gl:vertex (* r1 (cos angle)) (* r1 (sin angle)) (* (- width) 0.5))))) ;; Draw outward faces of teeth. (gl:with-primitives :quad-strip (dotimes (i n-teeth) (let ((angle (/ (* i 2.0 +pif+) n-teeth))) (gl:vertex (* r1 (cos angle)) (* r1 (sin angle)) (* width 0.5)) (gl:vertex (* r1 (cos angle)) (* r1 (sin angle)) (* (- width) 0.5)) (let* ((u (- (* r2 (cos (+ angle da))) (* r1 (cos angle)))) (v (- (* r2 (sin (+ angle da))) (* r1 (sin angle)))) (len (sqrt (+ (* u u) (* v v))))) (setq u (/ u len)) (setq v (/ u len)) (gl:normal v (- u) 0.0) (gl:vertex (* r2 (cos (+ angle da))) (* r2 (sin (+ angle da))) (* width 0.5)) (gl:vertex (* r2 (cos (+ angle da))) (* r2 (sin (+ angle da))) (* (- width) 0.5)) (gl:normal (cos angle) (sin angle) 0.0) (gl:vertex (* r2 (cos (+ angle (* 2 da)))) (* r2 (sin (+ angle (* 2 da)))) (* width 0.5)) (gl:vertex (* r2 (cos (+ angle (* 2 da)))) (* r2 (sin (+ angle (* 2 da)))) (* (- width) 0.5)) (setq u (- (* r1 (cos (+ angle (* 3 da)))) (* r2 (cos (+ angle (* 2 da)))))) (setq v (- (* r1 (sin (+ angle (* 3 da)))) (* r2 (sin (+ angle (* 2 da)))))) (gl:normal v (- u) 0.0) (gl:vertex (* r1 (cos (+ angle (* 3 da)))) (* r1 (sin (+ angle (* 3 da)))) (* width 0.5)) (gl:vertex (* r1 (cos (+ angle (* 3 da)))) (* r1 (sin (+ angle (* 3 da)))) (* (- width) 0.5)) (gl:normal (cos angle) (sin angle) 0.0)))) (gl:vertex (* r1 (cos 0)) (* r1 (sin 0)) (* width 0.5)) (gl:vertex (* r1 (cos 0)) (* r1 (sin 0)) (* (- width) 0.5))) ;; Draw inside radius cylinder. (gl:shade-model :smooth) (gl:with-primitives :quad-strip (dotimes (i (1+ n-teeth)) (let ((angle (/ (* i 2.0 +pif+) n-teeth))) (gl:normal (- (cos angle)) (- (sin angle)) 0.0) (gl:vertex (* r0 (cos angle)) (* r0 (sin angle)) (* (- width) 0.5)) (gl:vertex (* r0 (cos angle)) (* r0 (sin angle)) (* width 0.5))))))) (defclass gears-window (glut:window) ((view-rotx :initform 20.0) (view-roty :initform 30.0) (view-rotz :initform 0.0) gear1 gear2 gear3 (angle :initform 0.0) (count :initform 1) (t0 :initform 0)) (:default-initargs :title "Gears" :mode '(:double :rgb :depth))) (defmethod glut:display-window :before ((window gears-window)) (with-slots (gear1 gear2 gear3) window (gl:light :light0 :position #(5.0 5.0 10.0 0.0)) (gl:enable :cull-face :lighting :light0 :depth-test) ;; gear 1 (setq gear1 (gl:gen-lists 1)) (gl:with-new-list (gear1 :compile) (gl:material :front :ambient-and-diffuse #(0.8 0.1 0.0 1.0)) ; red (draw-gear 1.0 4.0 1.0 20 0.7)) ;; gear 2 (setq gear2 (gl:gen-lists 1)) (gl:with-new-list (gear2 :compile) (gl:material :front :ambient-and-diffuse #(0.0 0.8 0.2 1.0)) ; green (draw-gear 0.5 2.0 2.0 10 0.7)) ;; gear 3 (setq gear3 (gl:gen-lists 1)) (gl:with-new-list (gear3 :compile) (gl:material :front :ambient-and-diffuse #(0.2 0.2 1.0 1.0)) ; blue (draw-gear 1.3 2.0 0.5 10 0.7)) (gl:enable :normalize))) (defun print-frame-rate (window) "Prints the frame rate every ~5 seconds." (with-slots (count t0) window (incf count) (let ((time (get-internal-real-time))) (when (= t0 0) (setq t0 time)) (when (>= (- time t0) (* 5 internal-time-units-per-second)) (let* ((seconds (/ (- time t0) internal-time-units-per-second)) (fps (/ count seconds))) (format *terminal-io* "~D frames in ~3,1F seconds = ~6,3F FPS~%" count seconds fps)) (setq t0 time) (setq count 0))))) (defmethod glut:display ((window gears-window)) (with-slots (view-rotx view-roty view-rotz angle gear1 gear2 gear3) window (gl:clear :color-buffer :depth-buffer) (gl:with-pushed-matrix (gl:rotate view-rotx 1 0 0) (gl:rotate view-roty 0 1 0) (gl:rotate view-rotz 0 0 1) (gl:with-pushed-matrix ; gear1 (gl:translate -3 -2 0) (gl:rotate angle 0 0 1) (gl:call-list gear1)) (gl:with-pushed-matrix ; gear2 (gl:translate 3.1 -2 0) (gl:rotate (- (* -2 angle) 9) 0 0 1) (gl:call-list gear2)) (gl:with-pushed-matrix ; gear3 (gl:translate -3.1 4.2 0.0) (gl:rotate (- (* -2 angle) 25) 0 0 1) (gl:call-list gear3))) (glut:swap-buffers) (print-frame-rate window))) (defmethod glut:idle ((window gears-window)) (incf (slot-value window 'angle) 2.0) (glut:post-redisplay)) (defmethod glut:keyboard ((window gears-window) key x y) (declare (ignore x y)) (case key (#\z (incf (slot-value window 'view-rotz) 5.0) (glut:post-redisplay)) (#\Z (decf (slot-value window 'view-rotz) 5.0) (glut:post-redisplay)) (#\Esc (glut:destroy-current-window)))) (defmethod glut:special ((window gears-window) special-key x y) (declare (ignore x y)) (with-slots (view-rotx view-roty) window (case special-key (:key-up (incf view-rotx 5.0)) (:key-down (decf view-rotx 5.0)) (:key-left (incf view-roty 5.0)) (:key-right (decf view-roty 5.0))) (glut:post-redisplay))) (defmethod glut:reshape ((w gears-window) width height) (gl:viewport 0 0 width height) (gl:matrix-mode :projection) (gl:load-identity) (let ((h (/ height width))) (gl:frustum -1 1 (- h) h 5 60)) (gl:matrix-mode :modelview) (gl:load-identity) (gl:translate 0 0 -40)) (defmethod glut:visibility ((w gears-window) state) (case state (:visible (glut:enable-event w :idle)) (t (glut:disable-event w :idle)))) (defun gears () (glut:display-window (make-instance 'gears-window)))
9,082
Common Lisp
.lisp
210
34.366667
80
0.504911
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
0d63351316d050f7806f8d1508213157862bf5c221c9e7058816a569dd0f7d2c
21,574
[ -1 ]
21,575
gears-raw.lisp
rheaplex_minara/lib/cl-opengl/examples/mesademos/gears-raw.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; gears.lisp --- Lisp version of gears.c (GLUT Mesa demos). ;;; ;;; Simple program with rotating 3-D gear wheels. ;;; This is an example using the raw bindings to GLUT and CFFI. ;;; Compare with the CLOS version in gears.lisp (defpackage #:mesademos-gears-raw (:use #:cl) (:export #:run)) (in-package #:mesademos-gears-raw) ;(declaim (optimize (speed 3) (safety 0) (compilation-speed 0) (debug 0))) (defconstant +pif+ (coerce pi 'single-float)) (defun gear (inner-radius outer-radius width n-teeth tooth-depth) (declare (single-float inner-radius outer-radius width tooth-depth) (fixnum n-teeth)) (let ((r0 inner-radius) (r1 (- outer-radius (/ tooth-depth 2.0))) (r2 (+ outer-radius (/ tooth-depth 2.0))) (da (/ (* 2.0 +pif+) n-teeth 4.0))) (gl:shade-model :flat) (gl:normal 0 0 1) ;; Draw front face. (gl:with-primitives :quad-strip (dotimes (i (1+ n-teeth)) (let ((angle (/ (* i 2.0 +pif+) n-teeth))) (gl:vertex (* r0 (cos angle)) (* r0 (sin angle)) (* width 0.5)) (gl:vertex (* r1 (cos angle)) (* r1 (sin angle)) (* width 0.5)) (gl:vertex (* r0 (cos angle)) (* r0 (sin angle)) (* width 0.5)) (gl:vertex (* r1 (cos (+ angle (* 3 da)))) (* r1 (sin (+ angle (* 3 da)))) (* width 0.5))))) ;; Draw front sides of teeth. (gl:with-primitives :quads (dotimes (i n-teeth) (let ((angle (/ (* i 2.0 +pif+) n-teeth))) (gl:vertex (* r1 (cos angle)) (* r1 (sin angle)) (* width 0.5)) (gl:vertex (* r2 (cos (+ angle da))) (* r2 (sin (+ angle da))) (* width 0.5)) (gl:vertex (* r2 (cos (+ angle (* 2 da)))) (* r2 (sin (+ angle (* 2 da)))) (* width 0.5)) (gl:vertex (* r1 (cos (+ angle (* 3 da)))) (* r1 (sin (+ angle (* 3 da)))) (* width 0.5))))) (gl:normal 0 0 -1) ;; Draw back face. (gl:with-primitives :quad-strip (dotimes (i (1+ n-teeth)) (let ((angle (/ (* i 2.0 +pif+) n-teeth))) (gl:vertex (* r1 (cos angle)) (* r1 (sin angle)) (* width -0.5)) (gl:vertex (* r0 (cos angle)) (* r0 (sin angle)) (* width -0.5)) (gl:vertex (* r1 (cos (+ angle (* 3 da)))) (* r1 (sin (+ angle (* 3 da)))) (* width -0.5)) (gl:vertex (* r0 (cos angle)) (* r0 (sin angle)) (* width -0.5))))) ;; Draw back sides of teeth. (gl:with-primitives :quads (dotimes (i n-teeth) (let ((angle (/ (* i 2.0 +pif+) n-teeth))) (gl:vertex (* r1 (cos (+ angle (* 3 da)))) (* r1 (sin (+ angle (* 3 da)))) (* (- width) 0.5)) (gl:vertex (* r2 (cos (+ angle (* 2 da)))) (* r2 (sin (+ angle (* 2 da)))) (* (- width) 0.5)) (gl:vertex (* r2 (cos (+ angle da))) (* r2 (sin (+ angle da))) (* (- width) 0.5)) (gl:vertex (* r1 (cos angle)) (* r1 (sin angle)) (* (- width) 0.5))))) ;; Draw outward faces of teeth. (gl:with-primitives :quad-strip (dotimes (i n-teeth) (let ((angle (/ (* i 2.0 +pif+) n-teeth))) (gl:vertex (* r1 (cos angle)) (* r1 (sin angle)) (* width 0.5)) (gl:vertex (* r1 (cos angle)) (* r1 (sin angle)) (* (- width) 0.5)) (let* ((u (- (* r2 (cos (+ angle da))) (* r1 (cos angle)))) (v (- (* r2 (sin (+ angle da))) (* r1 (sin angle)))) (len (sqrt (+ (* u u) (* v v))))) (setq u (/ u len)) (setq v (/ u len)) (gl:normal v (- u) 0.0) (gl:vertex (* r2 (cos (+ angle da))) (* r2 (sin (+ angle da))) (* width 0.5)) (gl:vertex (* r2 (cos (+ angle da))) (* r2 (sin (+ angle da))) (* (- width) 0.5)) (gl:normal (cos angle) (sin angle) 0.0) (gl:vertex (* r2 (cos (+ angle (* 2 da)))) (* r2 (sin (+ angle (* 2 da)))) (* width 0.5)) (gl:vertex (* r2 (cos (+ angle (* 2 da)))) (* r2 (sin (+ angle (* 2 da)))) (* (- width) 0.5)) (setq u (- (* r1 (cos (+ angle (* 3 da)))) (* r2 (cos (+ angle (* 2 da)))))) (setq v (- (* r1 (sin (+ angle (* 3 da)))) (* r2 (sin (+ angle (* 2 da)))))) (gl:normal v (- u) 0.0) (gl:vertex (* r1 (cos (+ angle (* 3 da)))) (* r1 (sin (+ angle (* 3 da)))) (* width 0.5)) (gl:vertex (* r1 (cos (+ angle (* 3 da)))) (* r1 (sin (+ angle (* 3 da)))) (* (- width) 0.5)) (gl:normal (cos angle) (sin angle) 0.0)))) (gl:vertex (* r1 (cos 0)) (* r1 (sin 0)) (* width 0.5)) (gl:vertex (* r1 (cos 0)) (* r1 (sin 0)) (* (- width) 0.5))) ;; Draw inside radius cylinder. (gl:shade-model :smooth) (gl:with-primitives :quad-strip (dotimes (i (1+ n-teeth)) (let ((angle (/ (* i 2.0 +pif+) n-teeth))) (gl:normal (- (cos angle)) (- (sin angle)) 0.0) (gl:vertex (* r0 (cos angle)) (* r0 (sin angle)) (* (- width) 0.5)) (gl:vertex (* r0 (cos angle)) (* r0 (sin angle)) (* width 0.5))))))) (declaim (single-float *view-rotx* *view-roty* *view-rotz* *angle*) (fixnum *gear1* *gear2* *gear3* *limit* *count* *t0*)) (defvar *view-rotx* 20.0) (defvar *view-roty* 30.0) (defvar *view-rotz* 0.0) (defvar *gear1*) (defvar *gear2*) (defvar *gear3*) (defvar *angle* 0.0) (defvar *limit*) (defvar *count* 1) (defvar *t0* 0) (cffi:defcallback draw :void () (gl:clear :color-buffer :depth-buffer) (gl:push-matrix) (gl:rotate *view-rotx* 1 0 0) (gl:rotate *view-roty* 0 1 0) (gl:rotate *view-rotz* 0 0 1) ;; gear 1 (gl:push-matrix) (gl:translate -3 -2 0) (gl:rotate *angle* 0 0 1) (gl:call-list *gear1*) (gl:pop-matrix) ;; gear 2 (gl:push-matrix) (gl:translate 3.1 -2 0) (gl:rotate (- (* -2 *angle*) 9) 0 0 1) (gl:call-list *gear2*) (gl:pop-matrix) ;; gear 3 (gl:push-matrix) (gl:translate -3.1 4.2 0.0) (gl:rotate (- (* -2 *angle*) 25) 0 0 1) (gl:call-list *gear3*) (gl:pop-matrix) ;; .. (gl:pop-matrix) (glut:swap-buffers) ;; Calculating frame rate (incf *count*) ; if count == limit: exit? nahhh (let ((time (get-internal-real-time))) (declare (fixnum time)) ; bogus? (when (= *t0* 0) (setq *t0* time)) (when (>= (- time *t0*) (* 5 internal-time-units-per-second)) (let* ((seconds (/ (- time *t0*) internal-time-units-per-second)) (fps (/ *count* seconds))) (format *terminal-io* "~D frames in ~3,1F seconds = ~6,3F FPS~%" *count* seconds fps)) (setq *t0* time) (setq *count* 0)))) (cffi:defcallback idle :void () (incf *angle* 2.0) (glut:post-redisplay)) (cffi:defcallback key :void ((key :uchar) (x :int) (y :int)) (declare (ignore x y)) (case (code-char key) (#\z (incf *view-rotz* 5.0)) (#\Z (decf *view-rotz* 5.0)) (#\Esc (glut:leave-main-loop))) (glut:post-redisplay)) (cffi:defcallback special :void ((key glut:special-keys) (x :int) (y :int)) (declare (ignore x y)) (case key (:key-up (incf *view-rotx* 5.0)) (:key-down (decf *view-rotx* 5.0)) (:key-left (incf *view-roty* 5.0)) (:key-right (decf *view-roty* 5.0))) (glut:post-redisplay)) (cffi:defcallback reshape :void ((width :int) (height :int)) (gl:viewport 0 0 width height) (gl:matrix-mode :projection) (gl:load-identity) (let ((h (coerce (/ height width) 'double-float))) (gl:frustum -1 1 (- h) h 5 60)) (gl:matrix-mode :modelview) (gl:load-identity) (gl:translate 0 0 -40)) (defun init () (gl:light :light0 :position #(5.0 5.0 10.0 0.0)) (gl:enable :cull-face :lighting :light0 :depth-test) ;; Make the gears. ;; gear 1 (setq *gear1* (gl:gen-lists 1)) (gl:new-list *gear1* :compile) (gl:material :front :ambient-and-diffuse #(0.8 0.1 0.0 1.0)) ; red (gear 1.0 4.0 1.0 20 0.7) (gl:end-list) ;; gear 2 (setq *gear2* (gl:gen-lists 1)) (gl:new-list *gear2* :compile) (gl:material :front :ambient-and-diffuse #(0.0 0.8 0.2 1.0)) ; green (gear 0.5 2.0 2.0 10 0.7) (gl:end-list) ;; gear 3 (setq *gear3* (gl:gen-lists 1)) (gl:new-list *gear3* :compile) (gl:material :front :ambient-and-diffuse #(0.2 0.2 1.0 1.0)) ; blue (gear 1.3 2.0 0.5 10 0.7) (gl:end-list) ;; .. (gl:enable :normalize)) (cffi:defcallback visible :void ((visibility glut:visibility-state)) (if (eq visibility :visible) (glut:idle-func (cffi:callback idle)) (glut:idle-func (cffi:null-pointer)))) (defun run (&optional (limit 0)) (glut:init) (setq *limit* limit) (glut:init-display-mode :double :rgb :depth) (glut:create-window "Gears") (init) (glut:display-func (cffi:callback draw)) (glut:reshape-func (cffi:callback reshape)) (glut:keyboard-func (cffi:callback key)) (glut:special-func (cffi:callback special)) (glut:visibility-func (cffi:callback visible)) (glut:main-loop))
9,296
Common Lisp
.lisp
232
32.62069
80
0.510772
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
b07ba3da96e66549dd3ea186b1157a404d82e2c3a9566e03e375ee7363258303
21,575
[ -1 ]
21,576
varray.lisp
rheaplex_minara/lib/cl-opengl/examples/redbook/varray.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; varray.lisp --- Lisp version of varray.c (Red Book examples) ;;; ;;; Original C version contains the following copyright notice: ;;; Copyright (c) 1993-1997, Silicon Graphics, Inc. ;;; ALL RIGHTS RESERVED ;;; This program demonstrates vertex arrays. (in-package #:cl-glut-examples) (defclass varray-window (glut:window) ((setup-method :accessor setup-method :initform 'pointer) (deref-method :accessor deref-method :initform 'draw-array)) (:default-initargs :width 350 :height 350 :title "varray.lisp" :mode '(:single :rgb))) (defun setup-pointers () (let ((vertices '(25 25 100 325 175 25 175 325 250 25 325 325)) (colors '(1.0 0.2 0.2 0.2 0.2 1.0 0.8 1.0 0.2 0.75 0.75 0.75 0.35 0.35 0.35 0.5 0.5 0.5))) (gl:enable-client-state :vertex-array) (gl:enable-client-state :color-array) (gl:vertex-pointer 2 :int 0 vertices) (gl:color-pointer 3 :float 0 colors))) (defun setup-interleave () (let ((intertwined '(1.0 0.2 1.0 100.0 100.0 0.0 1.0 0.2 0.2 0.0 200.0 0.0 1.0 1.0 0.2 100.0 300.0 0.0 0.2 1.0 0.2 200.0 300.0 0.0 0.2 1.0 1.0 300.0 200.0 0.0 0.2 0.2 1.0 200.0 100.0 0.0))) (gl:interleaved-arrays :c3f-v3f 0 intertwined))) (defmethod glut:display-window :before ((w varray-window)) (gl:clear-color 0 0 0 0) (gl:shade-model :smooth) (setup-pointers)) (defmethod glut:display ((w varray-window)) (gl:clear :color-buffer) (ecase (deref-method w) (draw-array (gl:draw-arrays :triangles 0 6)) (array-element (gl:with-primitives :triangles (gl:array-element 2) (gl:array-element 3) (gl:array-element 5))) (draw-elements (gl:draw-elements :polygon 4 :unsigned-int '(0 1 3 4)))) (gl:flush)) (defmethod glut:reshape ((w varray-window) width height) (gl:viewport 0 0 width height) (gl:matrix-mode :projection) (gl:load-identity) (glu:ortho-2d 0 width 0 height)) (defmethod glut:mouse ((w varray-window) button state x y) (declare (ignore x y)) (case button (:left-button (when (eql state :down) (case (setup-method w) (pointer (setf (setup-method w) 'interleaved) (setup-interleave)) (interleaved (setf (setup-method w) 'pointer) (setup-pointers))) (glut:post-redisplay))) ((:middle-button :right-button) (when (eql state :down) (setf (deref-method w) (ecase (deref-method w) (draw-array 'array-element) (array-element 'draw-elements) (draw-elements 'draw-array))) (glut:post-redisplay))))) (defmethod glut:keyboard ((w varray-window) key x y) (declare (ignore x y)) (case (code-char key) (#\Esc (glut:leave-main-loop)))) ;;; XXX verificar GL_VERSION_1_1 (defun rb-varray () (glut:display-window (make-instance 'varray-window)))
3,204
Common Lisp
.lisp
88
28.284091
64
0.581988
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
abeba6b3764351efd8b508a36960168674ada17909668ab9665271ac54e3f7a9
21,576
[ 312369 ]
21,577
hello.lisp
rheaplex_minara/lib/cl-opengl/examples/redbook/hello.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; hello.lisp --- Lisp version of hello.c (Red Book examples) ;;; ;;; Original C version contains the following copyright notice: ;;; Copyright (c) 1993-1997, Silicon Graphics, Inc. ;;; ALL RIGHTS RESERVED ;;; This is a simple, introductory OpenGL program. ;;; Declare initial window size, position, and display mode (single ;;; buffer and RGBA). Open window with "hello" in its title bar. ;;; Call initialization routines. Register callback function to ;;; display graphics. Enter main loop and process events. (in-package #:cl-glut-examples) (defclass hello-window (glut:window) () (:default-initargs :pos-x 100 :pos-y 100 :width 250 :height 250 :mode '(:single :rgb) :title "hello.lisp")) (defmethod glut:display-window :before ((w hello-window)) ;; Select clearing color. (gl:clear-color 0 0 0 0) ;; Initialize viewing values. (gl:matrix-mode :projection) (gl:load-identity) (gl:ortho 0 1 0 1 -1 1)) (defmethod glut:display ((w hello-window)) (gl:clear :color-buffer) ;; Draw white polygon (rectangle) with corners at ;; (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0). (gl:color 1 1 1) (gl:with-primitive :polygon (gl:vertex 0.25 0.25 0) (gl:vertex 0.75 0.25 0) (gl:vertex 0.75 0.75 0) (gl:vertex 0.25 0.75 0)) ;; Start processing buffered OpenGL routines. (gl:flush)) (defun rb-hello () (glut:display-window (make-instance 'hello-window)))
1,469
Common Lisp
.lisp
37
36.648649
67
0.683509
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
d877ca4eb1f5ac95511cfe58cb6d557363e98af01bfd6c67a6d6fab3dd7d91ec
21,577
[ 36816 ]
21,578
model.lisp
rheaplex_minara/lib/cl-opengl/examples/redbook/model.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; model.lisp --- Lisp version of model.c (Red Book examples) ;;; ;;; Original C version contains the following copyright notice: ;;; Copyright (c) 1993-1997, Silicon Graphics, Inc. ;;; ALL RIGHTS RESERVED ;;; This program demonstrates modeling transformations (in-package #:cl-glut-examples) (defclass model-window (glut:window) () (:default-initargs :pos-x 100 :pos-y 100 :width 500 :height 500 :mode '(:single :rgb) :title "model.lisp")) (defmethod glut:display-window :before ((w model-window)) (gl:clear-color 0 0 0 0) (gl:shade-model :flat)) (defmethod glut:display ((w model-window)) (flet ((draw-triangle () (gl:with-primitives :line-loop (gl:vertex 0 25) (gl:vertex 25 -25) (gl:vertex -25 -25)))) (gl:clear :color-buffer) (gl:color 1 1 1) ;; triangle with solid-lines (gl:load-identity) (gl:color 1 1 1) (draw-triangle) ;; triangle with dashed-lines (gl:enable :line-stipple) (gl:line-stipple 1 #xF0F0) (gl:load-identity) (gl:translate -20 0 0) (draw-triangle) ;; triangle with long dashed-lines (gl:line-stipple 1 #xF00F) (gl:load-identity) (gl:scale 1.5 0.5 1.0) (draw-triangle) ;; triangle with dotted lines (gl:line-stipple 1 #x8888) (gl:load-identity) (gl:rotate 90 0 0 1) (draw-triangle) (gl:disable :line-stipple) (gl:flush))) (defmethod glut:reshape ((w model-window) width height) (gl:viewport 0 0 width height) (gl:matrix-mode :projection) (gl:load-identity) (if (<= width height) (gl:ortho -50 50 (/ (* -50 height) width) (/ (* 50 height) width) -1 1) (gl:ortho (/ (* -50 width) height) (/ (* 50 width) height) -50 50.0 -1 1)) (gl:matrix-mode :modelview)) (defmethod glut:keyboard ((w model-window) key x y) (declare (ignore x y)) (when (eql key #\Esc) (glut:destroy-current-window))) (defun rb-model () (glut:display-window (make-instance 'model-window)))
2,030
Common Lisp
.lisp
61
28.983607
68
0.644569
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
39ba8f9bfdc6a11a767a3a3c13cd22ba5278c60112e0d4eb5d979742b4f6744d
21,578
[ 73680 ]
21,579
lines.lisp
rheaplex_minara/lib/cl-opengl/examples/redbook/lines.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; lines.lisp --- Lisp version of lines.c (Red Book examples) ;;; ;;; Original C version contains the following copyright notice: ;;; Copyright (c) 1993-1997, Silicon Graphics, Inc. ;;; ALL RIGHTS RESERVED ;;; This program demonstrates geometric primitives and ;;; their attributes. (in-package #:cl-glut-examples) (defun draw-one-line (x1 y1 x2 y2) (gl:with-primitives :lines (gl:vertex x1 y1) (gl:vertex x2 y2))) (defclass lines-window (glut:window) () (:default-initargs :width 400 :height 150 :pos-x 100 :pos-y 100 :mode '(:single :rgb) :title "lines.lisp")) (defmethod glut:display-window :before ((w lines-window)) (gl:clear-color 0 0 0 0) (gl:shade-model :flat)) (defmethod glut:display ((w lines-window)) (gl:clear :color-buffer) ;; Select white for all lines. (gl:color 1 1 1) ;; In 1st row, 3 lines, each with a different stipple. (gl:enable :line-stipple) (gl:line-stipple 1 #b0000000100000001) ; dotted (draw-one-line 50 125 150 125) (gl:line-stipple 1 #b0000000011111111) ; dashed (draw-one-line 150 125 250 125) (gl:line-stipple 1 #b0001110001000111) ; dash/dot/dash (draw-one-line 250 125 350 125) ;; In 2nd row, 3 wide lines, each with different stipple. (gl:line-width 5) (gl:line-stipple 1 #b0000000100000001) ; dotted (draw-one-line 50 100 150 100) (gl:line-stipple 1 #b0000000011111111) ; dashed (draw-one-line 150 100 250 100) (gl:line-stipple 1 #b0001110001000111) ; dash/dot/dash (draw-one-line 250 100 350 100) (gl:line-width 1) ;; In 3rd row, 6 lines, with dash/dot/dash stipple as part ;; of a single connected line strip. (gl:line-stipple 1 #b0001110001000111) ; dash/dot/dash (gl:with-primitives :line-strip (dotimes (i 7) (gl:vertex (+ 50 (* i 50)) 75))) ;; In 4th row, 6 independent lines with same stipple. (dotimes (i 6) (draw-one-line (+ 50 (* i 50)) 50 (+ 50 (* (1+ i) 50)) 50)) ;; In 5th row, 1 line, with dash/dot/dash stipple and ;; a stipple repeat factor of 5. (gl:line-stipple 5 #b0001110001000111) ; dash/dot/dash (draw-one-line 50 25 350 25) ;; Finally, (gl:disable :line-stipple) (gl:flush)) (defmethod glut:reshape ((w lines-window) width height) (gl:viewport 0 0 width height) (gl:matrix-mode :projection) (gl:load-identity) (glu:ortho-2d 0 width 0 height)) (defmethod glut:keyboard ((w lines-window) key x y) (declare (ignore x y)) (when (eql key #\Esc) (glut:destroy-current-window))) (defun rb-lines () (glut:display-window (make-instance 'lines-window)))
2,606
Common Lisp
.lisp
70
34.085714
63
0.686585
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
0e6b1c9275f13c4443e528edcc4cc7801ae80f9d3a1d2996916af57b2eb49277
21,579
[ 478557 ]
21,580
smooth.lisp
rheaplex_minara/lib/cl-opengl/examples/redbook/smooth.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; smooth.lisp --- Lisp version of smooth.c (Red Book examples) ;;; ;;; Original C version contains the following copyright notice: ;;; Copyright (c) 1993-1997, Silicon Graphics, Inc. ;;; ALL RIGHTS RESERVED ;;; This program demonstrates smooth shading. ;;; A smooth shaded polygon is drawn in a 2-D projection. (in-package #:cl-glut-examples) (defclass smooth-window (glut:window) () (:default-initargs :width 500 :height 500 :pos-x 100 :pos-y 100 :mode '(:single :rgb) :title "smooth.lisp")) (defmethod glut:display-window :before ((w smooth-window)) (gl:clear-color 0 0 0 0) (gl:shade-model :smooth)) (defmethod glut:display ((w smooth-window)) (gl:clear :color-buffer) (gl:with-primitives :triangles (gl:color 1 0 0) (gl:vertex 5 5) (gl:color 0 1 0) (gl:vertex 25 5) (gl:color 0 0 1) (gl:vertex 5 25)) (gl:flush)) (defmethod glut:reshape ((w smooth-window) width height) (gl:viewport 0 0 width height) (gl:matrix-mode :projection) (gl:load-identity) (if (<= width height) (glu:ortho-2d 0 30 0 (* 30 (/ height width))) (glu:ortho-2d 0 (* 30 (/ width height)) 0 30)) (gl:matrix-mode :modelview)) (defmethod glut:keyboard ((w smooth-window) key x y) (declare (ignore x y)) (case key (#\Esc (glut:destroy-current-window)))) (defun rb-smooth () (glut:display-window (make-instance 'smooth-window)))
1,449
Common Lisp
.lisp
40
32.75
65
0.668094
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
e9386fb6324b0bd4f88c0fc0dbb68b57488722e3bad0f0125e04179afdcee9cb
21,580
[ 263907 ]
21,581
double.lisp
rheaplex_minara/lib/cl-opengl/examples/redbook/double.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; double.lisp --- Lisp version of double.c (Red Book examples) ;;; ;;; Original C version contains the following copyright notice: ;;; Copyright (c) 1993-1997, Silicon Graphics, Inc. ;;; ALL RIGHTS RESERVED ;;; This is a simple double buffered program. ;;; Pressing the left mouse button rotates the rectangle. ;;; Pressing the middle mouse button stops the rotation. (in-package #:cl-glut-examples) (defclass double-window (glut:window) ((spin :initform 0.0)) (:default-initargs :width 250 :height 250 :pos-x 100 :pos-y 100 :mode '(:double :rgb) :title "double.lisp")) (defmethod glut:display-window :before ((w double-window)) (gl:clear-color 0 0 0 0) (gl:shade-model :flat)) (defmethod glut:display ((w double-window)) (gl:clear :color-buffer) (gl:with-pushed-matrix (gl:rotate (slot-value w 'spin) 0 0 1) (gl:color 1 1 1) (gl:rect -25 -25 25 25)) (glut:swap-buffers)) (defmethod glut:idle ((w double-window)) (with-slots (spin) w (incf spin 2.0) (when (> spin 360.0) (decf spin 360.0)) (glut:post-redisplay))) (defmethod glut:reshape ((w double-window) width height) (gl:viewport 0 0 width height) (gl:matrix-mode :projection) (gl:load-identity) (gl:ortho -50 50 -50 50 -1 1) (gl:matrix-mode :modelview) (gl:load-identity)) (defmethod glut:mouse ((w double-window) button state x y) (declare (ignore x y)) (case button (:left-button (when (eq state :down) (glut:enable-event w :idle))) ((:middle-button :right-button) (when (eq state :down) (glut:disable-event w :idle))))) (defun rb-double () (glut:display-window (make-instance 'double-window)))
1,731
Common Lisp
.lisp
48
32.4375
65
0.672043
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
d35c6fd01a2e8bcd5f9e2cbeb03da525da0f5982b9e23d634921e1f26f239b26
21,581
[ 151686 ]
21,582
planet.lisp
rheaplex_minara/lib/cl-opengl/examples/redbook/planet.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; planet.lisp --- Lisp version of planet.c (Red Book examples) ;;; ;;; Original C version contains the following copyright notice: ;;; Copyright (c) 1993-1997, Silicon Graphics, Inc. ;;; ALL RIGHTS RESERVED ;;; This program shows how to composite modeling transformations ;;; to draw translated and rotated models. ;;; Interaction: pressing the d and y keys (day and year) ;;; alters the rotation of the planet around the sun. (in-package #:cl-glut-examples) (defclass planet-window (glut:window) ((year :accessor year :initform 0) (day :accessor day :initform 0)) (:default-initargs :pos-x 100 :pos-y 100 :width 500 :height 500 :mode '(:double :rgb) :title "planet.lisp")) (defmethod glut:display-window :before ((w planet-window)) (gl:clear-color 0 0 0 0) (gl:shade-model :flat)) (defmethod glut:display ((w planet-window)) (gl:clear :color-buffer) (gl:color 1 1 1) (gl:with-pushed-matrix ;; draw sun (glut:wire-sphere 1 20 16) ;; draw smaller planet (gl:rotate (year w) 0 1 0) (gl:translate 2 0 0) (gl:rotate (day w) 0 1 0) (glut:wire-sphere 0.2 10 8)) (glut:swap-buffers)) (defmethod glut:reshape ((w planet-window) width height) (gl:viewport 0 0 width height) (gl:matrix-mode :projection) (gl:load-identity) (glu:perspective 60 (/ width height) 1 20) (gl:matrix-mode :modelview) (gl:load-identity) (glu:look-at 0 0 5 0 0 0 0 1 0)) (defmethod glut:keyboard ((w planet-window) key x y) (declare (ignore x y)) (flet ((update (slot n) (setf (slot-value w slot) (mod (+ (slot-value w slot) n) 360)) (glut:post-redisplay))) (case key (#\d (update 'day 10)) (#\D (update 'day -10)) (#\y (update 'year 5)) (#\Y (update 'year -5)) (#\Esc (glut:destroy-current-window))))) (defun rb-planet () (glut:display-window (make-instance 'planet-window)))
1,933
Common Lisp
.lisp
53
32.886792
73
0.662393
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
bb9d388e8cb399198f1fafb0565d159f78cc90ae17fe90e62597fdf562f749a0
21,582
[ 213875 ]
21,583
movelight.lisp
rheaplex_minara/lib/cl-opengl/examples/redbook/movelight.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; movelight.lisp --- Lisp version of movelight.c (Red Book examples) ;;; ;;; Original C version contains the following copyright notice: ;;; Copyright (c) 1993-1997, Silicon Graphics, Inc. ;;; ALL RIGHTS RESERVED ;;; This program demonstrates when to issue lighting and ;;; transformation commands to render a model with a light ;;; which is moved by a modeling transformation (rotate or ;;; translate). The light position is reset after the modeling ;;; transformation is called. The eye position does not change. ;;; ;;; A sphere is drawn using a grey material characteristic. ;;; A single light source illuminates the object. ;;; ;;; Interaction: pressing the left mouse button alters ;;; the modeling transformation (x rotation) by 30 degrees. ;;; The scene is then redrawn with the light in a new position. (in-package #:cl-glut-examples) (defclass movelight-window (glut:window) ((spin :initform 0)) (:default-initargs :width 500 :height 500 :pos-x 100 :pos-y 100 :mode '(:single :rgb) :title "movelight.lisp")) (defmethod glut:display-window :before ((w movelight-window)) (gl:clear-color 0 0 0 0) (gl:shade-model :smooth) (gl:enable :lighting) (gl:enable :light0) (gl:enable :depth-test)) ;;; Here is where the light position is reset after the modeling ;;; transformation (GL:ROTATE) is called. This places the ;;; light at a new position in world coordinates. The cube ;;; represents the position of the light. (defmethod glut:display ((w movelight-window)) (gl:clear :color-buffer :depth-buffer) (gl:with-pushed-matrix (glu:look-at 0 0 5 0 0 0 0 1 0) (gl:with-pushed-matrix (gl:rotate (slot-value w 'spin) 1 0 0) (gl:light :light0 :position #(0 0 1.5 1)) (gl:translate 0 0 1.5) (gl:disable :lighting) (gl:color 0 1 1) (glut:wire-cube 0.1) (gl:enable :lighting)) (glut:solid-torus 0.275 0.85 8 15)) (gl:flush)) (defmethod glut:reshape ((w movelight-window) width height) (gl:viewport 0 0 width height) (gl:matrix-mode :projection) (gl:load-identity) (glu:perspective 40 (/ width height) 1 20) (gl:matrix-mode :modelview) (gl:load-identity)) (defmethod glut:mouse ((w movelight-window) button state x y) (declare (ignore x y)) (when (and (eq button :left-button) (eq state :down)) (with-slots (spin) w (setf spin (mod (+ spin 30) 360))) (glut:post-redisplay))) (defmethod glut:keyboard ((w movelight-window) key x y) (declare (ignore x y)) (case key (#\Esc (glut:destroy-current-window)))) (defun rb-movelight () (glut:display-window (make-instance 'movelight-window)))
2,681
Common Lisp
.lisp
66
37.439394
70
0.698005
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
8dcfb77313d4f81ea4c24a18758fcb15e01ae50e51e8f6fddf644a348892aaaf
21,583
[ 227210 ]
21,584
stroke.lisp
rheaplex_minara/lib/cl-opengl/examples/redbook/stroke.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; stroke.lisp --- Lisp version of stroke.c (Red Book examples) ;;; ;;; Original C version contains the following copyright notice: ;;; Copyright (c) 1993-1997, Silicon Graphics, Inc. ;;; ALL RIGHTS RESERVED ;;; This program demonstrates some characters of a ;;; stroke (vector) font. The characters are represented ;;; by display lists, which are given numbers which ;;; correspond to the ASCII values of the characters. ;;; Use of GL:CALL-LISTS is demonstrated. (in-package #:cl-glut-examples) (defclass stroke-window (glut:window) () (:default-initargs :width 440 :height 120 :title "stroke.lisp" :mode '(:single :rgb))) ;;; FIXME: like in the RB-LIST example we'll want some sort of ;;; mechanism to automatically deallocate display lists. (defmethod glut:display-window :before ((w stroke-window)) (let ((a '(#\A (0 0 pt) (0 9 pt) (1 10 pt) (4 10 pt) (5 9 pt) (5 0 stroke) (0 5 pt) (5 5 end))) (e '(#\E (5 0 pt) (0 0 pt) (0 10 pt) (5 10 stroke) (0 5 pt) (4 5 end))) (p '(#\P (0 0 pt) (0 10 pt) (4 10 pt) (5 9 pt) (5 6 pt) (4 5 pt) (0 5 end))) (r '(#\R (0 0 pt) (0 10 pt) (4 10 pt) (5 9 pt) (5 6 pt) (4 5 pt) (0 5 stroke) (3 5 pt) (5 0 end))) (s '(#\S (0 1 pt) (1 0 pt) (4 0 pt) (5 1 pt) (5 4 pt) (4 5 pt) (1 5 pt) (0 6 pt) (0 9 pt) (1 10 pt) (4 10 pt) (5 9 end)))) ;; draw-letter interprets the instructions above (flet ((draw-letter (instructions) (gl:begin :line-strip) (loop for (x y what) in instructions do (case what (pt (gl:vertex x y)) (stroke (gl:vertex x y) (gl:end) (gl:begin :line-strip)) (end (gl:vertex x y) (gl:end) (gl:translate 8 0 0)))))) ;; create a display list for each of 6 characters (gl:shade-model :flat) (let ((base (gl:gen-lists 128))) (gl:list-base base) (loop for char in (list a e p r s) do (gl:with-new-list ((+ base (char-code (car char))) :compile) (draw-letter (cdr char)))) ;; space (gl:with-new-list ((+ base (char-code #\Space)) :compile) (gl:translate 8 0 0)))))) (defmethod glut:display ((w stroke-window)) (flet ((print-stroked-string (string) (gl:call-lists (map 'vector #'char-code string)))) (gl:clear :color-buffer) (gl:color 1 1 1) (gl:with-pushed-matrix (gl:scale 2 2 2) (gl:translate 10 30 0) (print-stroked-string "A SPARE SERAPE APPEARS AS")) (gl:with-pushed-matrix (gl:scale 2 2 2) (gl:translate 10 13 0) (print-stroked-string "APES PREPARE RARE PEPPERS")) (gl:flush))) (defmethod glut:reshape ((w stroke-window) width height) (gl:viewport 0 0 width height) (gl:matrix-mode :projection) (gl:load-identity) (glu:ortho-2d 0 width 0 height)) (defmethod glut:keyboard ((w stroke-window) key x y) (declare (ignore x y)) (case key (#\Space (glut:post-redisplay)) (#\Esc (glut:destroy-current-window)))) (defun rb-stroke () (glut:display-window (make-instance 'stroke-window)))
3,322
Common Lisp
.lisp
76
35.565789
79
0.566883
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
29820d3492de04eacb0769d7987323cc3eac6406999f80377b7789f9b6d6af41
21,584
[ 458707 ]
21,585
cube.lisp
rheaplex_minara/lib/cl-opengl/examples/redbook/cube.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; cube.lisp --- Lisp version of cube.c (Red Book examples) ;;; ;;; Original C version contains the following copyright notice: ;;; Copyright (c) 1993-1997, Silicon Graphics, Inc. ;;; ALL RIGHTS RESERVED ;;; This program demonstrates a single modeling transformation, ;;; GL:SCALE and a single viewing transformation, GLU:LOOK-AT. ;;; A wireframe cube is rendered. (in-package #:cl-glut-examples) (defclass cube-window (glut:window) () (:default-initargs :width 500 :height 500 :title "cube.lisp" :mode '(:single :rgb))) (defmethod glut:display-window :before ((w cube-window)) (gl:clear-color 0 0 0 0) (gl:shade-model :flat)) (defmethod glut:display ((w cube-window)) (gl:clear :color-buffer) (gl:color 1 1 1) (gl:load-identity) ; clear the matrix ;; viewing transformation (glu:look-at 0 0 5 0 0 0 0 1 0) ;; modeling transformation (gl:scale 1 2 1) (glut:wire-cube 1) (gl:flush)) (defmethod glut:reshape ((w cube-window) width height) (gl:viewport 0 0 width height) (gl:matrix-mode :projection) (gl:load-identity) (gl:frustum -1 1 -1 1 1.5 20) (gl:matrix-mode :modelview)) (defmethod glut:keyboard ((w cube-window) key x y) (declare (ignore x y)) (when (eql key #\Esc) (glut:destroy-current-window))) (defun rb-cube () (glut:display-window (make-instance 'cube-window)))
1,400
Common Lisp
.lisp
39
32.974359
63
0.689579
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
89156b348c55b6332f4039190a258fe42d8855461fa75531b1c4ef15a2646ad0
21,585
[ 13538 ]
21,586
list.lisp
rheaplex_minara/lib/cl-opengl/examples/redbook/list.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; list.lisp --- Lisp version of list.c (Red Book examples) ;;; ;;; Original C version contains the following copyright notice: ;;; Copyright (c) 1993-1997, Silicon Graphics, Inc. ;;; ALL RIGHTS RESERVED ;;; This program demonstrates how to make and execute a ;;; display list. Note that attributes, such as current ;;; color and matrix, are changed. (in-package #:cl-glut-examples) (defclass list-window (glut:window) ((list-name :accessor list-name :initform (gl:gen-lists 1))) (:default-initargs :width 600 :height 50 :title "list.lisp" :mode '(:single :rgb))) (defmethod glut:display-window :before ((w list-window)) (gl:with-new-list ((list-name w) :compile) (gl:color 1 0 0) ; red (gl:with-primitives :triangles (gl:vertex 0 0) (gl:vertex 1 0) (gl:vertex 0 1)) (gl:translate 1.5 0 0)) ; move position (gl:shade-model :flat)) (defmethod glut:display ((w list-window)) (gl:clear :color-buffer) (gl:color 0 1 0) ; current color green (loop repeat 10 do (gl:call-list (list-name w))) (gl:with-primitives :lines ; is this line green? NO! (gl:vertex 0 0.5) ; where is the line drawn? (gl:vertex 15 0.5)) (gl:flush)) (defmethod glut:reshape ((w list-window) width height) (gl:viewport 0 0 width height) (gl:matrix-mode :projection) (gl:load-identity) (if (<= width height) (glu:ortho-2d 0 2 (* -0.5 (/ height width)) (* 1.5 (/ height width))) (glu:ortho-2d 0 (* 2 (/ width height)) -0.5 1.5)) (gl:matrix-mode :modelview) (gl:load-identity)) (defmethod glut:keyboard ((w list-window) key x y) (declare (ignore x y)) (when (eql key #\Esc) (glut:destroy-current-window))) (defun rb-list () (glut:display-window (make-instance 'list-window)))
1,873
Common Lisp
.lisp
46
37.521739
75
0.638813
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
e07173c57a1db17711f1b15d42d6dde84d4d0e8ee1c5edd41f26d9b14e376f9b
21,586
[ 78212 ]
21,587
clip.lisp
rheaplex_minara/lib/cl-opengl/examples/redbook/clip.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; clip.lisp --- Lisp version of clip.c (Red Book examples) ;;; ;;; Original C version contains the following copyright notice: ;;; Copyright (c) 1993-1997, Silicon Graphics, Inc. ;;; ALL RIGHTS RESERVED ;;; This program demonstrates arbitrary clipping planes. (in-package #:cl-glut-examples) (defclass clip-window (glut:window) () (:default-initargs :pos-x 100 :pos-y 100 :width 500 :height 500 :mode '(:single :rgb) :title "clip.lisp")) (defmethod glut:display-window :before ((w clip-window)) (gl:clear-color 0 0 0 0) (gl:shade-model :flat)) (defmethod glut:display ((w clip-window)) (gl:clear :color-buffer) (gl:color 1 1 1) (gl:with-pushed-matrix (gl:translate 0 0 -5) ;; clip lower half -- y < 0 (gl:clip-plane :clip-plane0 '(0 1 0 0)) (gl:enable :clip-plane0) ;; clip left half -- x < 0 (gl:clip-plane :clip-plane1 '(1 0 0 0)) (gl:enable :clip-plane1) ;; sphere (gl:rotate 90 1 0 0) (glut:wire-sphere 1 20 16)) (gl:flush)) (defmethod glut:reshape ((w clip-window) width height) (gl:viewport 0 0 width height) (gl:matrix-mode :projection) (gl:load-identity) (glu:perspective 60 (/ width height) 1 20) (gl:matrix-mode :modelview)) (defmethod glut:keyboard ((w clip-window) key x y) (declare (ignore x y)) (when (eql key #\Esc) (glut:destroy-current-window))) (defun rb-clip () (glut:display-window (make-instance 'clip-window)))
1,491
Common Lisp
.lisp
42
32
65
0.663428
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
76bab9308899f2ca7c871403bc16491ab413ce2de9122e8ad2424425ccee7d58
21,587
[ 296422 ]
21,588
polys.lisp
rheaplex_minara/lib/cl-opengl/examples/redbook/polys.lisp
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- ;;; polys.lisp --- Lisp version of polys.c (Red Book examples) ;;; ;;; Original C version contains the following copyright notice: ;;; Copyright (c) 1993-1997, Silicon Graphics, Inc. ;;; ALL RIGHTS RESERVED ;;; This program demonstrates polygon stippling. (in-package #:cl-glut-examples) (defclass polys-window (glut:window) () (:default-initargs :width 350 :height 150 :title "polys.lisp" :mode '(:single :rgb))) (defmethod glut:display-window :before ((w polys-window)) (gl:clear-color 0 0 0 0) (gl:shade-model :flat)) (defparameter *fly* #(#x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x03 #x80 #x01 #xC0 #x06 #xC0 #x03 #x60 #x04 #x60 #x06 #x20 #x04 #x30 #x0C #x20 #x04 #x18 #x18 #x20 #x04 #x0C #x30 #x20 #x04 #x06 #x60 #x20 #x44 #x03 #xC0 #x22 #x44 #x01 #x80 #x22 #x44 #x01 #x80 #x22 #x44 #x01 #x80 #x22 #x44 #x01 #x80 #x22 #x44 #x01 #x80 #x22 #x44 #x01 #x80 #x22 #x66 #x01 #x80 #x66 #x33 #x01 #x80 #xCC #x19 #x81 #x81 #x98 #x0C #xC1 #x83 #x30 #x07 #xe1 #x87 #xe0 #x03 #x3f #xfc #xc0 #x03 #x31 #x8c #xc0 #x03 #x33 #xcc #xc0 #x06 #x64 #x26 #x60 #x0c #xcc #x33 #x30 #x18 #xcc #x33 #x18 #x10 #xc4 #x23 #x08 #x10 #x63 #xC6 #x08 #x10 #x30 #x0c #x08 #x10 #x18 #x18 #x08 #x10 #x00 #x00 #x08)) (defparameter *halftone* #(#xAA #xAA #xAA #xAA #x55 #x55 #x55 #x55 #xAA #xAA #xAA #xAA #x55 #x55 #x55 #x55 #xAA #xAA #xAA #xAA #x55 #x55 #x55 #x55 #xAA #xAA #xAA #xAA #x55 #x55 #x55 #x55 #xAA #xAA #xAA #xAA #x55 #x55 #x55 #x55 #xAA #xAA #xAA #xAA #x55 #x55 #x55 #x55 #xAA #xAA #xAA #xAA #x55 #x55 #x55 #x55 #xAA #xAA #xAA #xAA #x55 #x55 #x55 #x55 #xAA #xAA #xAA #xAA #x55 #x55 #x55 #x55 #xAA #xAA #xAA #xAA #x55 #x55 #x55 #x55 #xAA #xAA #xAA #xAA #x55 #x55 #x55 #x55 #xAA #xAA #xAA #xAA #x55 #x55 #x55 #x55 #xAA #xAA #xAA #xAA #x55 #x55 #x55 #x55 #xAA #xAA #xAA #xAA #x55 #x55 #x55 #x55 #xAA #xAA #xAA #xAA #x55 #x55 #x55 #x55 #xAA #xAA #xAA #xAA #x55 #x55 #x55 #x55)) (defmethod glut:display ((w polys-window)) (gl:clear :color-buffer) (gl:color 1 1 1) ;; Draw one solid, unstippled rectangles then two ;; stippled rectangles. (gl:rect 25 25 125 125) (gl:enable :polygon-stipple) (gl:polygon-stipple *fly*) (gl:rect 125 25 225 125) (gl:polygon-stipple *halftone*) (gl:rect 225 25 325 125) (gl:disable :polygon-stipple) (gl:flush)) (defmethod glut:reshape ((w polys-window) width height) (gl:viewport 0 0 width height) (gl:matrix-mode :projection) (gl:load-identity) (glu:ortho-2d 0 width 0 height)) (defmethod glut:keyboard ((w polys-window) key x y) (declare (ignore x y)) (when (eql key #\Esc) (glut:destroy-current-window))) (defun rb-polys () (glut:display-window (make-instance 'polys-window)))
2,842
Common Lisp
.lisp
73
35.123288
63
0.627039
rheaplex/minara
2
0
0
GPL-3.0
9/19/2024, 11:28:00 AM (Europe/Amsterdam)
9d537c62a10826eed8569af5d60c3f0c8330612cbc19769eec992349bc7addc1
21,588
[ 60723 ]