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
8,688
simple-gui.asd
ailisp_simple-gui/simple-gui.asd
;;;; cl-gui.asd (defsystem #:simple-gui :name "simple-gui" :description "A declarative GUI definition tool for Common Lisp" :author "Bo Yao" :license "BSD" :version "0.1" :serial t :components ((:file "package") (:file "utils" ) (:file "qt-utils") (:file "simple-gui")) :depends-on (:qt :alexandria :cl-ppcre :named-readtables))
377
Common Lisp
.asd
13
24.307692
66
0.62259
ailisp/simple-gui
15
5
0
LGPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
e5881fbf73811b93edc7d8758dee5b5ebb4b8bf1e77b37463d3d091f84f5fa51
8,688
[ -1 ]
8,712
package.lisp
bohonghuang_cl-gobject-introspection-wrapper/package.lisp
;;;; package.lisp ;;;; Copyright (C) 2022-2023 Bohong Huang ;;;; ;;;; This program is free software: you can redistribute it and/or modify ;;;; it under the terms of the GNU Lesser General Public License as published by ;;;; the Free Software Foundation, either version 3 of the License, or ;;;; (at your option) any later version. ;;;; ;;;; This program is distributed in the hope that it will be useful, ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;;; GNU Lesser General Public License for more details. ;;;; ;;;; You should have received a copy of the GNU Lesser General Public License ;;;; along with this program. If not, see <https://www.gnu.org/licenses/>. (defpackage gobject-introspection-wrapper (:use #:cl #:alexandria) (:nicknames #:gir-wrapper) (:export #:*quoted-name-alist* #:*class* #:*namespace* #:define-gir-class #:define-gir-namespace #:define-gir-constant #:define-gir-enum #:define-gir-function #:pointer-object #:object-pointer))
1,153
Common Lisp
.lisp
28
36.357143
80
0.673197
bohonghuang/cl-gobject-introspection-wrapper
17
4
1
LGPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
d368ad83301eb44890d3b93d686c40e236f6c9c62b61e135bc0cef39ab53b1bc
8,712
[ -1 ]
8,713
util.lisp
bohonghuang_cl-gobject-introspection-wrapper/util.lisp
;;;; util.lisp ;;;; Copyright (C) 2022-2023 Bohong Huang ;;;; ;;;; This program is free software: you can redistribute it and/or modify ;;;; it under the terms of the GNU Lesser General Public License as published by ;;;; the Free Software Foundation, either version 3 of the License, or ;;;; (at your option) any later version. ;;;; ;;;; This program is distributed in the hope that it will be useful, ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;;; GNU Lesser General Public License for more details. ;;;; ;;;; You should have received a copy of the GNU Lesser General Public License ;;;; along with this program. If not, see <https://www.gnu.org/licenses/>. (in-package #:gir) (defmethod info-of ((desc callable-desc)) (slot-value desc 'info)) (in-package #:gir-wrapper) (defgeneric pointer-object (pointer type) (:documentation "Construct GObject from a CFFI pointer.")) (eval-when (:compile-toplevel :load-toplevel :execute) (setf (fdefinition 'object-pointer) (fdefinition 'gir::this-of))) (defun subclassp (class-a class-b) (loop :for class := class-a :then (gir:parent-of class) :while class :thereis (gir:info-equal (gir::info-of class) (gir::info-of class-b)))) (defun class-instance-p (instance class) (subclassp (typecase instance (gir::object-instance (gir:gir-class-of instance)) (gir::struct-instance (gir::struct-class-of instance)) (t (return-from class-instance-p nil))) class)) (defun interface-instance-p (instance interface) (loop :with interface-info := (gir::info-of interface) :for info :in (gir::interface-infos-of (typecase instance (gir::object-instance (gir:gir-class-of instance)) (gir::struct-instance (gir::struct-class-of instance)) (t (return-from interface-instance-p nil)))) :thereis (gir:info-equal info interface-info)) )
2,110
Common Lisp
.lisp
40
45.3
103
0.655507
bohonghuang/cl-gobject-introspection-wrapper
17
4
1
LGPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
d0323d3e0b963e741a350e980eaa0f48eb14043e950758f8dbc975558c5d6c6a
8,713
[ -1 ]
8,714
desc.lisp
bohonghuang_cl-gobject-introspection-wrapper/desc.lisp
;;;; desc.lisp ;;;; Copyright (C) 2022-2023 Bohong Huang ;;;; ;;;; This program is free software: you can redistribute it and/or modify ;;;; it under the terms of the GNU Lesser General Public License as published by ;;;; the Free Software Foundation, either version 3 of the License, or ;;;; (at your option) any later version. ;;;; ;;;; This program is distributed in the hope that it will be useful, ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;;; GNU Lesser General Public License for more details. ;;;; ;;;; You should have received a copy of the GNU Lesser General Public License ;;;; along with this program. If not, see <https://www.gnu.org/licenses/>. (in-package #:gir-wrapper) (defparameter *namespace* nil) (defparameter *class* nil) (defparameter *quoted-name-alist* nil) (defun quoted-name-symbol (name) (multiple-value-bind (value exists-p) (assoc-value *quoted-name-alist* name :test #'equal) (when (and (not value) exists-p) (throw 'skip nil)) value)) (defun camel-case->lisp-name (phrase) (string-right-trim "-" (nstring-upcase (cl-ppcre:regex-replace-all "((?<!\d)(\d+))|(([A-Z][a-z]+))|((?<![a-z])([a-z]+))|((?<![A-Z])(([A-Z](?![a-z]))+))" phrase "\\1\\3\\5\\7-")))) (defun camel-case->lisp-symbol (phrase) (intern (string-upcase (camel-case->lisp-name phrase)))) (defun underscores->lisp-name (phrase) (substitute #\- #\_ phrase)) (defun underscores->lisp-symbol (phrase &optional case-sensitive-p) (intern (funcall (if case-sensitive-p #'identity #'string-upcase) (underscores->lisp-name phrase)))) (defun callable-desc-argument-names (desc) (let ((argument-name-case-sensitive-p nil)) (flet ((desc-args () (mapcar (lambda (desc) (let ((name (gir:name-of desc))) (or (quoted-name-symbol name) (underscores->lisp-symbol name argument-name-case-sensitive-p)))) (gir:arguments-desc-of desc)))) (let ((args (desc-args))) (unless (= (length (remove-duplicates args)) (length args)) (setf argument-name-case-sensitive-p t args (desc-args))) (values args))))) (defun transform-class-desc (desc &optional (namespace *namespace*) (class *class*)) (catch 'skip (let* ((class-symbol (or (quoted-name-symbol class) (camel-case->lisp-symbol class))) (pred-symbol (symbolicate class-symbol (if (find #\- (symbol-name class-symbol)) '#:-p '#:p)))) `((defun ,pred-symbol (instance) (class-instance-p instance (gir:nget ,namespace ,class))) (deftype ,class-symbol () '(satisfies ,pred-symbol)) (defmethod gir-wrapper:pointer-object (pointer (type (eql ',class-symbol))) (declare (ignore type)) (make-instance ',(etypecase desc (gir::object-class 'gir::object-instance) (gir::struct-class 'gir::struct-instance)) :class (gir:nget ,namespace ,class) :this pointer)))))) (defun transform-interface-desc (desc &optional (namespace *namespace*) (class *class*)) (declare (ignore desc)) (catch 'skip (let* ((interface-symbol (or (quoted-name-symbol class) (camel-case->lisp-symbol class))) (pred-symbol (symbolicate interface-symbol (if (find #\- (symbol-name interface-symbol)) '#:-p '#:p)))) `((defun ,pred-symbol (instance) (interface-instance-p instance (gir:nget ,namespace ,class))) (deftype ,interface-symbol () '(satisfies ,pred-symbol)))))) (defparameter +getter-pattern-1-base+ "(?:(.+?(?=\\bIS\\b))?(?:IS-)?(.+))") ; xxx_is_xxx, xxx (defparameter +getter-pattern-1+ (format nil "(?:(.*?(?=\\b(?:GET|IS)\\b))(?:GET-|IS-)~A)" +getter-pattern-1-base+)) ; get_xxx_is_xxx, get_xxx, is_xxx, get_is_xxx (defparameter +getter-pattern-2+ "(.*?(?=\\b(?:HAS|SHOULD|CAN)\\b)(?:HAS|SHOULD|CAN)-.+)") ; xxx_should_xxx, xxx_has_xxx, has_xxx, should_xxx (defparameter +getter-pattern+ (format nil "(?:~A|~A)" +getter-pattern-1+ +getter-pattern-2+)) (defparameter +setter-pattern+ (format nil "(?:SET-(?:~A|~A))" +getter-pattern-1-base+ +getter-pattern-2+)) (defparameter +constructor-pattern+ "^(NEW|CREATE)(-WITH|-FROM|-FOR|$)?(-.+|$)") (defun scan-to-string (regex target-string) (multiple-value-bind (match-string groups) (ppcre:scan-to-strings regex target-string) (when (and match-string (= (length match-string) (length target-string))) (loop :with string := (make-string (loop :for group :across groups :summing (length group))) :for i := 0 :then (+ i (length group)) :for group :across groups :if group :do (loop :for char :across group :for j :from 0 :do (setf (aref string (+ i j)) char)) :finally (return string))))) (defun transform-method-desc (desc &optional (namespace *namespace*) (class *class*)) (declare (ignore namespace)) (catch 'skip (let* ((info (gir::info-of desc)) (name (nstring-upcase (underscores->lisp-name (gir:info-get-name info)))) (symbol (intern name)) (args (callable-desc-argument-names desc)) (arg-types (mapcar #'gir:type-desc-of (gir:arguments-desc-of desc))) (ret-types (mapcar #'gir:type-desc-of (gir:returns-desc-of desc))) (class-name (or (quoted-name-symbol class) (camel-case->lisp-symbol class))) (proc-arg-fn (loop :for (arg-text arg-len) :on args ; (const char* text, int len, ...) -> (text ... &aux (len (length text))) :for (arg-text-type arg-len-type) :on arg-types :for i :from 0 :when (and (eql arg-len-type 'integer) (eql arg-text-type 'string) (member (symbol-name arg-len) '("LENGTH" "LEN") :test #'string-equal)) :return (lambda (args) (loop :for arg :in args :for j :from 0 :when (/= (1+ i) j) :collect arg :into result-args :finally (return `(,@result-args &aux (,arg-len (length ,arg-text)))))) :finally (return #'identity))) (proc-ret-fn (if (and (eq (car ret-types) :void) (cdr ret-types)) (lambda (body) (let ((syms (loop :for tpe :in ret-types :collect (gensym)))) `(multiple-value-bind ,syms ,body (declare (ignore ,(car syms))) (values . ,(cdr syms))))) #'identity))) (if-let ((name-symbol (quoted-name-symbol (cons class (gir:info-get-name info))))) `(defun ,name-symbol (instance ,@args) ,(funcall proc-ret-fn `(gir:invoke (instance ',symbol) ,@args))) (cond ((and (not args) (when-let ((name (scan-to-string +getter-pattern+ name))) `(defun ,(intern (format nil (if (equal ret-types '(boolean)) "~A-~A-P" "~A-~A") class-name name)) (instance) ,(funcall proc-ret-fn `(gir:invoke (instance ',symbol))))))) ((and args (when-let ((name (scan-to-string +setter-pattern+ name))) `(defun (setf ,(intern (format nil (if (eql (car arg-types) 'boolean) "~A-~A-P" "~A-~A") class-name name))) (value instance) (,@(if (cdr args) `(destructuring-bind ,args value) `(symbol-macrolet ((,(car args) value)))) ,(funcall proc-ret-fn `(gir:invoke (instance ',symbol) ,@args))))))) (t `(defun ,(intern (format nil "~A-~A" class-name name)) (instance ,@(funcall proc-arg-fn args)) ,(funcall proc-ret-fn `(gir:invoke (instance ',symbol) ,@args))))))))) (defun transform-constructor-desc (desc &optional (namespace *namespace*) (class *class*)) (catch 'skip (let* ((info (gir::info-of desc)) (name (nstring-upcase (underscores->lisp-name (gir:info-get-name info)))) (symbol (intern name)) (args (callable-desc-argument-names desc)) (class-name (or (quoted-name-symbol class) (camel-case->lisp-symbol class)))) (let ((body `(gir:invoke (,namespace ,class ',symbol) ,@args))) (if-let ((name-symbol (quoted-name-symbol (cons class (gir:info-get-name info))))) (values `(defun ,name-symbol ,args ,body) nil) (if-let ((method (ppcre:register-groups-bind (verb prep method) (+constructor-pattern+ name) (declare (ignore verb)) (if prep (list prep method) (list method))))) (values `(defun ,(intern (format nil "MAKE~A-~A" (ecase (length method) (1 (first method)) (2 "")) class-name)) (&key ,@args) ,body) (and method (every (compose #'plusp #'length) method) (mapcar (lambda (str) (subseq str 1)) method))) (values `(defun ,(intern (format nil "~A-~A" class-name name)) ,args ,body) nil))))))) (defun merge-constructor-forms (forms descs subst-arg-names) (let ((grouped nil)) (loop :for (defun-symbol name lambda-list body) :in forms :for desc :in descs :for subst-arg-name :in subst-arg-names :when (eq (car lambda-list) '&key) :do (pop lambda-list) :do (push (list desc subst-arg-name body) (assoc-value (assoc-value grouped name) lambda-list :test #'equal))) (loop :with unmergeable-constructors :for (name . arg-groups) :in grouped :do (setf arg-groups (mapcan (lambda (arg-group) (destructuring-bind (args . bodies) arg-group (if (> (length bodies) 1) (if (= (length args) 1) (loop :for (desc subst-arg-name body) :in bodies :if subst-arg-name :collect (let ((subst-symbol (intern (lastcar subst-arg-name)))) `((,subst-symbol) (let ((,(first args) ,subst-symbol)) ,body))) :into result :else :count t :into no-subst-name-count :and :collect `(,args ,body) :into result :finally (assert (<= no-subst-name-count 1)) (return result)) (loop :for (desc subst-arg-name body) :in bodies :if subst-arg-name :do (let ((*quoted-name-alist* (cons (let ((name (gir:info-get-name (gir::info-of desc)))) (cons (cons *class* name) (intern (format nil "MAKE-~A-~A-~A" (camel-case->lisp-symbol *class*) (first subst-arg-name) (second subst-arg-name))))) *quoted-name-alist*))) (push (transform-constructor-desc desc) unmergeable-constructors)) :else :collect `(,args ,(third bodies)))) (mapcar (compose (lambda (body) `(,args ,body)) #'third) bodies)))) (sort arg-groups #'> :key (compose #'length #'first)))) :collect `(defun ,name (&key ,@(mapcar (lambda (arg) `(,arg :unspecified)) (remove-duplicates (loop :for (args body) :in arg-groups :append args)))) (cond ,@(mapcar (lambda (arg-group) (destructuring-bind (args body) arg-group `((not (or ,@(mapcar (lambda (arg) `(eql ,arg :unspecified)) args))) ,body))) arg-groups) (t (error "Invalid arguments for constructor ~A" ',name)))) :into merged-constructors :finally (return (values merged-constructors unmergeable-constructors))))) (defun transform-class-function-desc (desc &optional (namespace *namespace*) (class *class*)) (catch 'skip (let* ((info (gir::info-of desc)) (name (nstring-upcase (underscores->lisp-name (gir:info-get-name info)))) (symbol (intern name)) (args (callable-desc-argument-names desc)) (arg-types (mapcar #'gir:type-desc-of (gir:arguments-desc-of desc))) (ret-types (mapcar #'gir:type-desc-of (gir:returns-desc-of desc))) (class-name (or (quoted-name-symbol class) (camel-case->lisp-symbol class))) (proc-arg-fn (loop :for (arg-text arg-len) :on args ; (const char* text, int len, ...) -> (text ... &aux (len (length text))) :for (arg-text-type arg-len-type) :on arg-types :for i :from 0 :when (and (eql arg-len-type 'integer) (eql arg-text-type 'string) (member (symbol-name arg-len) '("LENGTH" "LEN") :test #'string-equal)) :return (lambda (args) (loop :for arg :in args :for j :from 0 :when (/= (1+ i) j) :collect arg :into result-args :finally (return `(,@result-args &aux (,arg-len (length ,arg-text)))))) :finally (return #'identity))) (proc-ret-fn (if (and (eq (car ret-types) :void) (cdr ret-types)) (lambda (body) (let ((syms (loop :for tpe :in ret-types :collect (gensym)))) `(multiple-value-bind ,syms ,body (declare (ignore ,(car syms))) (values . ,(cdr syms))))) #'identity))) (if-let ((name-symbol (quoted-name-symbol (cons class (gir:info-get-name info))))) `(defun ,name-symbol ,args (gir:invoke (,namespace ,class ',symbol) ,@args)) (cond ((and (not args) (when-let ((name (scan-to-string +getter-pattern+ name))) `(defun ,(intern (format nil (if (equal ret-types '(boolean)) "~A-~A-P" "~A-~A") class-name name)) () ,(funcall proc-ret-fn `(gir:invoke (,namespace ,class ',symbol))))))) ((and args (when-let ((name (scan-to-string +setter-pattern+ name))) `(defun (setf ,(intern (format nil (if (eql (car arg-types) 'boolean) "~A-~A-P" "~A-~A") class-name name))) (value) (,@(if (cdr args) `(destructuring-bind ,args value) `(symbol-macrolet ((,(car args) value)))) ,(funcall proc-ret-fn `(gir:invoke (,namespace ,class ',symbol) ,@args))))))) (t `(defun ,(intern (format nil "~A-~A" class-name name)) ,(funcall proc-arg-fn args) ,(funcall proc-ret-fn `(gir:invoke (,namespace ,class ',symbol) ,@args))))))))) (defun transform-function-desc (desc &optional (namespace *namespace*) (class *class*)) (declare (ignore class)) (catch 'skip (let* ((info (gir::info-of desc)) (name (nstring-upcase (underscores->lisp-name (gir:info-get-name info)))) (symbol (intern name)) (args (callable-desc-argument-names desc)) (arg-types (mapcar #'gir:type-desc-of (gir:arguments-desc-of desc))) (ret-type (gir:type-desc-of (car (gir:returns-desc-of desc))))) (if-let ((name-symbol (quoted-name-symbol (gir:info-get-name info)))) `(defun ,name-symbol ,args (gir:invoke (,namespace ',symbol) ,@args)) (cond ((and (not args) (when-let ((name (scan-to-string +getter-pattern+ name))) `(defun ,(intern (format nil (if (eql ret-type 'boolean) "~A-P" "~A") name)) () (gir:invoke (,namespace ',symbol)))))) ((and args (when-let ((name (scan-to-string +setter-pattern+ name))) `(defun (setf ,(intern (format nil (if (eql (car arg-types) 'boolean) "~A-P" "~A") name))) (value) (,@(if (cdr args) `(destructuring-bind ,args value) `(symbol-macrolet ((,(car args) value)))) (gir:invoke (,namespace ',symbol) ,@args)))))) (t `(defun ,(intern (format nil "~A" name)) ,args (gir:invoke (,namespace ',symbol) ,@args)))))))) (defun transform-enum-desc (desc &optional (namespace *namespace*) (class *class*)) (declare (ignore namespace)) (catch 'skip `(defconstant ,(or (quoted-name-symbol (cons class (car desc))) (intern (format nil "+~A-~A+" (or (quoted-name-symbol class) (camel-case->lisp-symbol class)) (underscores->lisp-symbol (car desc))))) ,(cdr desc)))) (defun transform-constant-desc (desc &optional (namespace *namespace*) (class *class*)) (declare (ignore class)) (catch 'skip `(define-constant ,(or (quoted-name-symbol desc) (symbolicate '#:+ (underscores->lisp-symbol desc) '#:+)) (handler-case (gir:nget ,namespace ,desc) (warning ())) :test #'equal)))
19,180
Common Lisp
.lisp
294
45.768707
181
0.493186
bohonghuang/cl-gobject-introspection-wrapper
17
4
1
LGPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
1fc7703eaab35bbc3201121670946e027df1394182728fc3c32b80555ff358c1
8,714
[ -1 ]
8,715
macro.lisp
bohonghuang_cl-gobject-introspection-wrapper/macro.lisp
;;;; macro.lisp ;;;; Copyright (C) 2022-2023 Bohong Huang ;;;; ;;;; This program is free software: you can redistribute it and/or modify ;;;; it under the terms of the GNU Lesser General Public License as published by ;;;; the Free Software Foundation, either version 3 of the License, or ;;;; (at your option) any later version. ;;;; ;;;; This program is distributed in the hope that it will be useful, ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;;; GNU Lesser General Public License for more details. ;;;; ;;;; You should have received a copy of the GNU Lesser General Public License ;;;; along with this program. If not, see <https://www.gnu.org/licenses/>. (in-package #:gir-wrapper) (defun defun-form->symbol (form) (setf form (second form)) (etypecase form (list (second form)) (symbol form))) (defmacro define-gir-class (name &optional (namespace *namespace*)) (let ((desc (gir:nget-desc (eval namespace) name)) (*namespace* namespace) (*class* name)) (let ((class (transform-class-desc desc)) (constructors (loop :for desc :in (gir:list-constructors-desc desc) :for (form subst-arg-name) := (multiple-value-list (transform-constructor-desc desc)) :collect form :into forms :collect subst-arg-name :into subst-arg-names :collect desc :into descs :finally (return (merge-constructor-forms forms descs subst-arg-names)))) (methods (mapcar #'transform-method-desc (gir:list-methods-desc desc))) (class-functions (when (typep desc 'gir:object-class) (mapcar #'transform-class-function-desc (gir:list-class-functions-desc desc))))) `(progn ,@class ,@constructors ,@methods ,@class-functions ,(when-let ((symbols (delete-if #'null (mapcar #'defun-form->symbol (append (remove 'gir-wrapper:pointer-object class :key #'second) constructors methods class-functions))))) `(export ',symbols)))))) (defmacro define-gir-interface (name &optional (namespace *namespace*)) (let ((desc (gir:nget-desc (eval namespace) name)) (*namespace* namespace) (*class* name)) (let ((interface (transform-interface-desc desc)) (methods (mapcar #'transform-method-desc (gir:list-methods-desc desc)))) `(progn ,@interface ,@methods ,(when-let ((symbols (delete-if #'null (mapcar #'defun-form->symbol (append interface methods))))) `(export ',symbols)))))) (defmacro define-gir-constant (name &optional (namespace *namespace*)) (let ((constant (transform-constant-desc name namespace))) `(progn ,constant ,(when constant `(export ',(second constant)))))) (defmacro define-gir-enum (name &optional (namespace *namespace*)) (let ((*namespace* namespace) (*class* name)) (let ((members (mapcar #'transform-enum-desc (gir:values-of (gir:nget-desc (eval namespace) name))))) `(progn ,@members ,(when members `(export ',(delete-if #'null (mapcar #'second members)))))))) (defmacro define-gir-function (name &optional (namespace *namespace*)) (let ((*namespace* namespace) (*class* name)) (let ((function (transform-function-desc (gir:nget-desc (eval namespace) name)))) `(progn ,function ,(when-let ((symbol (defun-form->symbol function))) `(export ',symbol)))))) (defmacro define-gir-namespace (name &optional version repository) (let ((*namespace* (gir:require-namespace name version)) (namespace-symbol (intern "*NS*"))) `(progn (eval-when (:execute :load-toplevel :compile-toplevel) (defparameter ,namespace-symbol (gir:require-namespace ,name ,version))) ,@(mapcar (lambda (info) (let ((name (gir:info-get-name info)) (type (gir:info-get-type info))) (switch (type) (:object `(define-gir-class ,name ,namespace-symbol)) (:struct (unless (ppcre:all-matches "Iface$" name) `(define-gir-class ,name ,namespace-symbol))) (:function `(define-gir-function ,name ,namespace-symbol)) (:constant `(define-gir-constant ,name ,namespace-symbol)) (:enum `(define-gir-enum ,name ,namespace-symbol)) (:flags `(define-gir-enum ,name ,namespace-symbol)) (:interface `(define-gir-interface ,name ,namespace-symbol))))) (gir:repository-get-infos repository name)))))
4,842
Common Lisp
.lisp
93
42.204301
183
0.611603
bohonghuang/cl-gobject-introspection-wrapper
17
4
1
LGPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
eb13b609ffa8b443969c72b822a050de006b566118abb8c044d5cd00688020cf
8,715
[ -1 ]
8,716
cl-gobject-introspection-wrapper.asd
bohonghuang_cl-gobject-introspection-wrapper/cl-gobject-introspection-wrapper.asd
(defsystem cl-gobject-introspection-wrapper :version "1.0.0" :author "Bohong Huang <[email protected]>" :maintainer "Bohong Huang <[email protected]>" :license "lgpl3" :description "Wrap and call GObject Introspection FFI function in LISP style, based on cl-gobject-introspection." :homepage "https://github.com/BohongHuang/cl-gobject-introspection-wrapper" :bug-tracker "https://github.com/BohongHuang/cl-gobject-introspection-wrapper/issues" :source-control (:git "https://github.com/BohongHuang/cl-gobject-introspection-wrapper.git") :serial t :components ((:file "package") (:file "util") (:file "desc") (:file "macro")) :depends-on (#:alexandria #:cl-gobject-introspection #:cl-ppcre)) (uiop:register-image-dump-hook (lambda () (setf (symbol-value (find-symbol "*NAMESPACE-CACHE*" :gir)) (make-hash-table :test #'equal))))
909
Common Lisp
.asd
19
42.578947
115
0.699663
bohonghuang/cl-gobject-introspection-wrapper
17
4
1
LGPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
6f3b3bf393a35a9bc9f4afcaf6a4ec4ad5a1ae1ab557ebeb918f4e069a602839
8,716
[ -1 ]
8,737
package2.lisp
gregcman_lisp-in-small-pieces/package2.lisp
(defpackage #:lisp-in-small-pieces (:use #:cl #:utility #:scheme2common-lisp) (:nicknames #:lisp)) (in-package #:lisp) (setf *print-case* :downcase) (setf *print-circle* t) (defparameter *dir* (asdf:system-source-directory :lisp-in-small-pieces)) (defparameter *scheme-test-file* (rebase-path "scheme.tst" *dir*))
319
Common Lisp
.lisp
8
38.25
73
0.722581
gregcman/lisp-in-small-pieces
11
2
0
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
2e36fe412f6a4ccc50f38ebdb0baf222fab66788a34efa662fbd91c992e5f495
8,737
[ -1 ]
8,738
tester.lisp
gregcman_lisp-in-small-pieces/tester.lisp
(in-package :lisp) ;;; ********************************************* ;;; An engine to test interpreters or compilers ;;; Christian Queinnec ;;; \'Ecole Polytechnique & INRIA-Rocquencourt ;;; ********************************************* ;;; This file contains the basic facility to easily run an interpreter ;;; defining a language. It can ask the user for expressions to be ;;; evaluated and print their results or take expressions from a file, ;;; evaluate them and compare their value to the expected value. If an ;;; error occurs then the test suite is aborted. ;;; A validation suite is a sequence of expressions followed by their ;;; expected results. The expression is evaluated in the language being ;;; tested then its result is compared to the expected result. ;;; An example of a test suite is: ;;; /------------------------ ;;; | (car '(a b)) ;;; | a ;;; | (car (list)) ;;; | *** ; means that an error is expected ;;; | (oblist) ;;; | --- ; means that no error is expected but the value is unimportant ;;; It is an error of course to expect an error if no error occurrs. ;;; This package may use the tester-error function in case of an ;;; internal error. It is not defined here since errors are not ;;; portable. You must have a location to define that variable for ;;; some compilers. Two cases may trigger this error: a suite test ;;; missing an expecting result or a (toplevel) form returning an ;;; unprinted value. Other errors are caught within engine-tester. ;;; The testing engine can be parameterized in various ways. ;;; Apart the engine itself, two functions are offered that ease its use. ;;; These are the `interpreter' and `suite-test' functions: ;;; This is the read function to use. It is possible to tailor this ;;; function to suit particular needs (for instance when generating ;;; tests instead of reading them out of a file). (defparameter +eof+ (cons "end of" "file")) (alias0 tester-read (lambda (&optional (stream *standard-input*)) (read stream nil +eof+))) (defun eof-object? (obj) (eq obj +eof+)) ;;; This is an internal variable that, in real Scheme, may be true or ;;; false without perceivable difference. It does make a difference ;;; however in non compliant Scheme systems. If your Scheme only ;;; offers dynamic-extent continuations, you must set it to false (in ;;; that case, all continuations created by tester.scm will be used in ;;; their dynamic extent). Alternatively, in Scheme->C which seems to ;;; have problems to garbage collect continuations, set it to true to ;;; only take one continuation and use it out of its dynamic extent. (defparameter tester-take-only-one-continuation +false+) ;;; This is the call/cc to use. It is possible to use dynamic-extent ;;; continuations instead. For instance, in Bigloo, you may use: ;;; (set! tester-call/cc (lambda (f) ;;; (bind-exit (k) (f k)))) ;;; But don't forget to define tester-take-only-one-continuation to false. (alias0 tester-call/cc call/cc) ;;; The interpreter function takes four arguments: ;;; -- an input prompt. This string will be printed whenever the ;;; interpreter wants to read an expression to evaluate. ;;; -- an output prompt. Values are printed preceded by this string. ;;; -- an error handler which is called whenever an error is detected. ;;; -- a make-toplevel function that will return a thunk implementing ;;; one interpreting step (read-eval-print). ;;; make-toplevel may be roughly defined as ;;; (lambda (read-exression display-value error-catcher) ;;; (lambda () (display-value (tested-eval (read-expression))))) ;;; The toplevel function will be repeatedly invoked from the ;;; interpreter. make-toplevel is invoked only once ;;; by the testing-engine with ;;; == (read-expression): a function that reads an expression and echoes it ;;; after printing the input-prompt. It returns the read expression. ;;; == (display-value v): the function that prints a value preceded by ;;; the output prompt. A new toplevel step is performed right after. ;;; == (error-catcher message . culprits): a function that reports the error, ;;; aborts the current computation and restarts a new cycle. ;;; You must write your interpreter so that when it detects errors, ;;; it calls this error-catcher function. You can have single error ;;; function or trap the native error function of your particular ;;; system. (defun interpreter (prompt-in ; prompt to read expression prompt-out ; prompt preceding results continue? ; continue after unexpected error make-toplevel) ; toplevel generator ;; display the result of an evaluation (labels ((display-status (status expected v) (case status ((unexpected-error) (newline) (display v) (display " an unexpected ERROR occurs !!!") (newline) continue?) ((correct-result) (display prompt-out) (display v) (newline) +true+) ; continue iteration (otherwise +false+)))) ; stop iteration ;; starts toplevel (tester-call/cc (lambda (exit) ; exit when test suite is finished (engine-tester (lambda () ; read expression (display prompt-in) (let ((e (tester-read))) (if (eof-object? e) (funcall exit 'end)) e)) (lambda () 'nothing) ; read expected result (useless) (lambda (expected obtained) ; compare expected and obtained results (cond ((eq? obtained '***) +false+) ((eq? obtained '---) +false+) (t +true+))) (function display-status) make-toplevel))))) ;;; suite-test is similar to the preceding one except that tests are taken ;;; from a file, possibly echoed on the console and checked to be correct. ;;; The suite contains expressions followed by their expected result. ;;; The result of the evaluation is compared to this result, the ;;; suite is aborted if an error occurs. ;;; suite-test takes six arguments: ;;; -- a file-name: The file contains the expressions to be evaluated and ;;; the expected results. ;;; -- an input prompt ;;; -- an output prompt ;;; -- a boolean flag which governs if read expressions from the file are ;;; echoed on the console. ;;; -- a make-toplevel function that will return the toplevel function ;;; make-toplevel may be roughly defined as ;;; (lambda (test-read test-checker wrong) ;;; (lambda () (test-checker (tested-eval (test-read))))) ;;; The toplevel function will be repeatedly invoked from the ;;; interpreter. The arguments of make-toplevel are ;;; == (test-read): the function that reads an expression, echoing it ;;; after printing the input-prompt. ;;; == (test-checker v): this function takes a value, reads the expected ;;; result, compares them and if according, prints the value preceded by ;;; the output prompt. A new toplevel is started after that. ;;; == (wrong message . culprits): a function that reports the error, ;;; aborts the current computation and restart a new cycle. ;;; -- a (comparator) function that takes the obtained result and the ;;; expected result and compares them yielding a boolean. ;;; Very often, result-eval is just `equal?' but must ;;; recognize the *** and --- items which meaning is "an error is ;;; expected" or "an unimportant value (but no error)". (defun suite-test (file ; the test suite prompt-in ; the prompt to read prompt-out ; the prompt to display echo? ; echo expressions ? make-toplevel ; a toplevel generator compare) ; how to compare results (let ((in (open-input-file file)) (native-display (function display)) (native-newline (function newline))) (labels ( ;; Two small utilities to display things (display (exp) (if echo? (funcall native-display exp))) (newline () (if echo? (funcall native-newline))) ;; Display the result of the test, return a boolean to indicate ;; whether the tests should continue or not. (display-status (status expected v) (case status ((expected-error) (set! echo? +true+) (display prompt-out) (display v) (display " an ERROR was expected !!! ") (newline) +false+) ; stop iteration ((error-occurred) (display " OK OK") (newline) +true+) ; continue iteration ((unexpected-error) (newline) (display v) (set! echo? +true+) (display " an unexpected ERROR occured !!!") (newline) (display " value expected: ") (display expected) (newline) +false+) ; stop iteration ((correct-result) (display prompt-out) (display v) (display " OK") (newline) +true+) ; continue iteration ((incorrect-result) (set! echo? +true+) (display prompt-out) (display v) (display " ERROR !!!") (newline) (display "value expected:") (display expected) (newline) +false+) ; stop iteration ((uninteresting-result) (display " OK") (newline) +true+) ; continue iteration (else (display "No such status") (newline) +false+)))) ; stop iteration (tester-call/cc (lambda (exit) ; exit when test suite is finished (engine-tester (lambda () ; read test (let ((e (tester-read in))) (if (eof-object? e) (begin (close-input-port in) (funcall exit 'done))) (display prompt-in) (display e) (newline) e)) (lambda () ; read result (let ((expected (tester-read in))) (if (eof-object? expected) (tester-error "Missing expected result" expected) expected))) compare (function display-status) make-toplevel)))))) ;;; A test engine on top of which the two previous are written: ;;; (read-test) reads an expression to evaluate ;;; (read-result) reads the expected result ;;; (compare expected obtained) compares what was obtained from what ;;; was expected. The value of `expected' can also ;;; be *** or --- ;;; (display-status message expected obtained) displays the result of the ;;; test. It usually prints the result and a comment like `OK'. ;;; Testing is abandoned if display-status returns +false+. ;;; (make-toplevel read print error) returns a thunk implementing one step ;;; of the intepreter. (defun engine-tester (read-test ; read a test read-result ; read the expected result compare ; compare the two display-status ; display the comparison make-toplevel) ; make a toplevel (tester-call/cc (lambda (abort) ; exit all tests (let ((resume +false+)) ; will be initialized below. ;; compare the result V with what was expected. If that ;; function is called then no error ocurred (unless *** is ;; given to it simulating an error internally caught). (labels ((check-result (v) (let ((expected (funcall read-result))) (if (cond ((funcall compare expected v) (funcall display-status 'correct-result expected v)) ((eq? expected '***) (funcall display-status 'expected-error expected v)) ((eq? expected '---) (funcall display-status 'uninteresting-result expected v)) (t (funcall display-status 'incorrect-result expected v))) (funcall resume +true+) (funcall abort +false+)))) ;; This function is called whenever an error is detected. (handle-exception (msg &rest culprits) ;;(write `(handle-exception called))(newline) ; DEBUG (let ((expected (funcall read-result)) (v (cons msg culprits))) (if (cond ((eq? expected '***) (funcall display-status 'error-occurred expected v)) (t (funcall display-status 'unexpected-error expected v))) (funcall resume +true+) (funcall abort +false+))))) (let ((toplevel (funcall make-toplevel read-test (function check-result) (function handle-exception)))) ;; The goal is to call (toplevel) ever and ever but to ensure ;; that the continuation is correctly reset. (named-let named-loop () (tester-call/cc (lambda (k) (if (and tester-take-only-one-continuation resume) 'nothing (set! resume k)) (let ((r (funcall toplevel))) ;; if this error is triggered, see note below. (tester-error "(toplevel) should not return!" r)))) (named-loop)))))))) (defun tester-error (msg &rest other) (print other) (error msg)) ;;; Examples: ;;; Suppose you have written an interpreter called `evaluate', then the ;;; following will start a toplevel loop. Errors detected in evaluate ;;; are supposed to call the `wrong' function. ;;;(define (scheme) ;;; (interpreter "?? " " == " +true+ ;;; (lambda (read print error) ;;; (set! wrong error) ;; Errors in the interpreter calls wrong ;;; (lambda () (print (evaluate (read))))))) ;;; The problem is that errors in the underlying system are not caught. ;;; Suppose at that time to have something to trap errors, say catch-error ;;; as in Mac-Lisp (it returns the result in a pair or the string that names ;;; the error if any), then you can write: ;;;(define (scheme) ;;; (interpreter "?? " " == " +true+ ;;; (lambda (read print error) ;;; (set! wrong error) ;; Errors in the interpreter calls wrong ;;; (lambda () (let ((r (catch-error (evaluate (read))))) ;;; (if (pair? r) (print (car r)) ;;; (error r))))))) ;;; NOTE: Both the print and error functions (in interpreter and ;;; suite-test) have a control effect. They restart a new toplevel ;;; iteration. So it is *important* not to forget to call them to ;;; reiterate the toplevel. If you return a value from toplevel ;;; without calling print or error, you'll get an internal error (ie ;;; an invocation of tester-error). [The reason lies with toplevel ;;; returning more than once in some concurrent interpreter I wrote]. ;;; If you have a file containing a test suite, say suite.tst, then you ;;; can try it with: ;;;(define (test-scheme) ;;; (suite-test "suite.tst" ;;; "?? " "== " +true+ ;;; (lambda (read print error) ;;; (set! wrong error) ;;; (lambda () ;;; (print (eval (read))))) ;;; equal?)) ;;; Another comparison function could be: ;;; (lambda (expected obtained) ;;; (cond ((or (eq? obtained '---)(eq? obtained '***)) ;;; (equal? expected obtained)) ;;; (else (member obtained expected)))) ;;; Other suggestions: tests and results can be read from two different files. ;;; You can use other compare functions such as member, set-equal? or even ;;; use pattern-matching. Here are the two lastly mentioned comparators. ;;; Compares if sets X and Y have the same (with equal?) elements. (defun set-equal? (x y) (labels ((remove-one (item list) (if (pair? list) (if (equal? item (car list)) (cdr list) (cons (car list) (remove-one item (cdr list)))) '()))) (if (pair? x) (and (member (car x) y) (set-equal? (cdr x) (remove-one (car x) y))) (null? y)))) ;;; Compares if the expression fits the pattern. Two special patterns exist: ;;; ?- which accepts anything ;;; ??- which accepts a (possibly empty) sequence of anything. ;;; Otherwise comparisons are performed with equal?. (defun naive-match (pattern expression) (labels ((naive-match-list (patterns expressions) (if (pair? patterns) (if (eq? (car patterns) '??-) ; accepts any sequence of things (or (naive-match-list (cdr patterns) expressions) (and (pair? expressions) (naive-match-list patterns (cdr expressions)))) (and (pair? expressions) (naive-match (car patterns) (car expressions)) (naive-match-list (cdr patterns) (cdr expressions)))) (naive-match patterns expressions)))) (or (eq? pattern '?-) ; accepts anything (if (pair? pattern) (naive-match-list pattern expression) (equal? pattern expression))))) ;;; AGAIN A NOTE: ;;; To catch the errors of the underlying Scheme is difficult. ;;; This tester engine has been used since 1992 on a wide variety of ;;; interpreters, some of which are concurrent and/or return multiple ;;; results. ;;; end of tester.scm
16,940
Common Lisp
.lisp
373
41.796247
79
0.637804
gregcman/lisp-in-small-pieces
11
2
0
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
7428a8f53885891c72cc95c076b9f230453b4cae18963239278867ce221324ab
8,738
[ -1 ]
8,739
chap7d.lisp
gregcman_lisp-in-small-pieces/chap7d.lisp
(in-package :lisp) ;;; Refinement of chap6d and chap7c. This interpreter introduces a ;;; *val* register and a *stack* to save/restore arguments that wait ;;; to be stored in an activation block. Functions now take their ;;; activation frame in the *val* register. Code is now a list of ;;; bytes. ;;; Load chap6d before. ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; The runtime machine ;(defparameter *env* +false+) ; already appears in chap6d (defparameter *val* +false+) (defparameter *fun* +false+) (defparameter *arg1* +false+) (defparameter *arg2* +false+) (defparameter *pc* 0) (defparameter *code* (vector 20)) (defparameter *constants* (vector)) ;;; Some tests depend on 100 being the depth of the stack. (defparameter *stack* (make-vector 100)) (defparameter *stack-index* 0) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo (defun stack-push (v) (vector-set! *stack* *stack-index* v) (incf *stack-index*)) (defun stack-pop () (decf *stack-index*) (vector-ref *stack* *stack-index*)) (defun save-stack () (let ((copy (make-vector *stack-index*))) (vector-copy! *stack* copy 0 *stack-index*) copy)) (defun restore-stack (copy) (set! *stack-index* (vector-length copy)) (vector-copy! copy *stack* 0 *stack-index*)) ;;; Copy vector old[start..end[ into vector new[start..end[ (defun vector-copy! (old new start end) (named-let copy ((i start)) (when (< i end) (vector-set! new i (vector-ref old i)) (copy (+ i 1))))) (defun quotation-fetch (i) (vector-ref *constants* i)) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; make them inherit from invokable. (progn (defclass primitive () ((address :initarg address))) (defun primitive? (obj) (typep obj 'primitive)) (defun primitive-address (obj) (slot-value obj 'address)) (defun set-primitive-address! (obj new) (setf (slot-value obj 'address) new)) (defun make-primitive (address) (make-instance 'primitive 'address address))) (progn (defclass continuation () ((stack :initarg stack))) (defun continuation? (obj) (typep obj 'continuation)) (defun continuation-stack (obj) (slot-value obj 'stack)) (defun set-continuation-stack! (obj new) (setf (slot-value obj 'stack) new)) (defun make-continuation (stack) (make-instance 'continuation 'stack stack))) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; This global variable holds at preparation time all the interesting ;;; quotations. It will be converted into *constants* for run-time. ;;; Quotations are not compressed and can appear multiply. (defparameter *quotations* (list)) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; Combinators that just expand into instructions. (defun SHALLOW-ARGUMENT-SET! (j m) (append m (SET-SHALLOW-ARGUMENT! j))) (defun DEEP-ARGUMENT-SET! (i j m) (append m (SET-DEEP-ARGUMENT! i j))) (defun GLOBAL-SET! (i m) (append m (SET-GLOBAL! i))) ;;; GOTO is not necessary if m2 is a tail-call but don't care. ;;; This one changed since chap7c.scm (defun ALTERNATIVE (m1 m2 m3) (let ((mm2 (append m2 (GOTO (length m3))))) (append m1 (JUMP-FALSE (length mm2)) mm2 m3))) (defun %SEQUENCE% (m m+) (append m m+)) (defun TR-FIX-LET (m* m+) (append m* (EXTEND-ENV) m+)) (defun FIX-LET (m* m+) (append m* (EXTEND-ENV) m+ (UNLINK-ENV))) (defun FIX-CLOSURE (m+ arity) (let* ((the-function (append (ARITY=? (+ arity 1)) (EXTEND-ENV) m+ (%RET%))) (the-goto (GOTO (length the-function)))) (append (CREATE-CLOSURE (length the-goto)) the-goto the-function))) (defun NARY-CLOSURE (m+ arity) (let* ((the-function (append (ARITY>=? (+ arity 1)) (PACK-FRAME! arity) (EXTEND-ENV) m+ (%RET%))) (the-goto (GOTO (length the-function)))) (append (CREATE-CLOSURE (length the-goto)) the-goto the-function))) (defun TR-REGULAR-CALL (m m*) (append m (PUSH-VALUE) m* (POP-FUNCTION) (FUNCTION-GOTO))) (defun REGULAR-CALL (m m*) (append m (PUSH-VALUE) m* (POP-FUNCTION) (PRESERVE-ENV) (FUNCTION-INVOKE) (RESTORE-ENV))) (defun STORE-ARGUMENT (m m* rank) (append m (PUSH-VALUE) m* (POP-FRAME! rank))) (defun CONS-ARGUMENT (m m* arity) (append m (PUSH-VALUE) m* (POP-CONS-FRAME! arity))) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; Instructions definers ;;; This uses the global fetch-byte function that increments *pc*. (eval-always (defparameter *instructions* (make-array 256 :initial-element nil)) (defparameter *instruction-names* (make-array 256 :initial-element nil)) (defparameter *instruction-arity* (make-array 256 :initial-element nil))) (defmacro define-instruction ((name &rest args) n &body body) (setf (aref *instruction-names* n) name) (setf (aref *instructions* n) `(lambda ,args ,@body)) (setf (aref *instruction-arity* n) (length args))) (eval-always (defun instructionp (byte) (aref *instructions* byte))) (defmacro define-instruction-set () `(defun dispatch-instruction (instruction) (case instruction ,@(let (acc) (dotimes (byte 256) (when (instructionp byte) (push `((,byte) (,(aref *instructions* byte) ,@(make-list (aref *instruction-arity* byte) :initial-element '(fetch-byte)))) acc))) (nreverse acc))))) #+nil (defparameter *debugging* t) (defun run () (let ((instruction (fetch-byte))) #+nil (when *debugging* (inspect *val*) (print (aref *instructions* instruction)) (format t ": ~s" (instruction-decode *code* (1- *pc*)))) (dispatch-instruction instruction)) (run)) (defun instruction-size (code pc) (let ((instruction (vector-ref code pc))) (+ 1 (aref *instruction-arity* instruction)))) (defun instruction-decode (code pc) (labels ((fetch-byte () (prog1 (vector-ref code pc) (incf pc)))) (let ((instruction (fetch-byte))) (let ((dump (list (aref *instruction-names* instruction)))) (dotimes (x (aref *instruction-arity* instruction)) (push (fetch-byte) dump)) (nreverse dump))))) ;;; Combinators (defun check-byte (j) (unless (and (<= 0 j) (<= j 255)) (static-wrong "Cannot pack this number within a byte" j))) (defun SHALLOW-ARGUMENT-REF (j) (check-byte j) (list 5 j)) (define-instruction (SHALLOW-ARGUMENT-REF j) 5 (set! *val* (activation-frame-argument *env* j))) (defun PREDEFINED (i) (check-byte i) (list 19 i)) (define-instruction (PREDEFINED i) 19 (set! *val* (predefined-fetch i))) (defun DEEP-ARGUMENT-REF (i j) (list 6 i j)) (define-instruction (DEEP-ARGUMENT-REF i j) 6 (set! *val* (deep-fetch *env* i j))) (defun SET-SHALLOW-ARGUMENT! (j) (list 25 j)) (define-instruction (SET-SHALLOW-ARGUMENT! j) 25 (set-activation-frame-argument! *env* j *val*)) (defun SET-DEEP-ARGUMENT! (i j) (list 26 i j)) (define-instruction (SET-DEEP-ARGUMENT! i j) 26 (deep-update! *env* i j *val*)) (defun GLOBAL-REF (i) (list 7 i)) (define-instruction (GLOBAL-REF i) 7 (set! *val* (global-fetch i))) (defun CHECKED-GLOBAL-REF (i) (list 8 i)) (define-instruction (CHECKED-GLOBAL-REF i) 8 (set! *val* (global-fetch i)) (when (eq? *val* undefined-value) (signal-exception +true+ (list "Uninitialized global variable" i)))) #+nil (define-instruction (CHECKED-GLOBAL-REF i) 8 (set! *val* (global-fetch i)) (if (eq? *val* undefined-value) (signal-exception +true+ (list "Uninitialized global variable" i)) (vector-set! *code* (- *pc* 2) 7))) (defun SET-GLOBAL! (i) (list 27 i)) (define-instruction (SET-GLOBAL! i) 27 (global-update! i *val*)) (defun CONSTANT (value) (if (and (integer? value) ; immediate value (<= 0 value) (< value 255)) (list 79 value) (EXPLICIT-CONSTANT value))) (define-instruction (SHORT-NUMBER value) 79 (set! *val* value)) (defun EXPLICIT-CONSTANT (value) (set! *quotations* (append *quotations* (list value))) (list 9 (- (length *quotations*) 1))) (define-instruction (CONSTANT i) 9 (set! *val* (quotation-fetch i))) ;;; All gotos have positive offsets (due to the generation) (defun GOTO (offset) (cond ((< offset 255) (list 30 offset)) ((< offset (+ 255 (* 255 256))) (let ((offset1 (modulo offset 256)) (offset2 (quotient offset 256))) (list 28 offset1 offset2))) (t (static-wrong "too long jump" offset)))) (define-instruction (SHORT-GOTO offset) 30 (incf *pc* offset)) (define-instruction (LONG-GOTO offset1 offset2) 28 (let ((offset (+ offset1 (* 256 offset2)))) (incf *pc* offset))) (defun JUMP-FALSE (offset) (cond ((< offset 255) (list 31 offset)) ((< offset (+ 255 (* 255 256))) (let ((offset1 (modulo offset 256)) (offset2 (quotient offset 256))) (list 29 offset1 offset2))) (t (static-wrong "too long jump" offset)))) (define-instruction (SHORT-JUMP-FALSE offset) 31 (when (not *val*) (incf *pc* offset))) (define-instruction (LONG-JUMP-FALSE offset1 offset2) 29 (let ((offset (+ offset1 (* 256 offset2)))) (when (not *val*) (incf *pc* offset)))) (defun EXTEND-ENV () (list 32)) (define-instruction (EXTEND-ENV) 32 (set! *env* (sr-extend* *env* *val*))) (defun UNLINK-ENV () (list 33)) (define-instruction (UNLINK-ENV) 33 (set! *env* (activation-frame-next *env*))) (defun PUSH-VALUE () (list 34)) (define-instruction (PUSH-VALUE) 34 (stack-push *val*)) (defun POP-ARG1 () (list 35)) (define-instruction (POP-ARG1) 35 (set! *arg1* (stack-pop))) (defun POP-ARG2 () (list 36)) (define-instruction (POP-ARG2) 36 (set! *arg2* (stack-pop))) (defun CREATE-CLOSURE (offset) (list 40 offset)) (define-instruction (CREATE-CLOSURE offset) 40 (set! *val* (make-closure (+ *pc* offset) *env*))) (defun ARITY=? (arity+1) (list 75 arity+1)) (define-instruction (ARITY=? arity+1) 75 (unless (= (activation-frame-argument-length *val*) arity+1) (signal-exception +false+ (list "Incorrect arity")))) (defun %RET% () (list 43)) (define-instruction (%RET%) 43 (set! *pc* (stack-pop))) (defun PACK-FRAME! (arity) (list 44 arity)) (define-instruction (PACK-FRAME! arity) 44 (listify! *val* arity)) (defun ARITY>=? (arity+1) (list 78 arity+1)) (define-instruction (ARITY>=? arity+1) 78 (unless (>= (activation-frame-argument-length *val*) arity+1) (signal-exception +false+ (list "Too less arguments for a nary function")))) (defun FUNCTION-GOTO () (list 46)) (define-instruction (FUNCTION-GOTO) 46 (invoke *fun* +true+)) (defun POP-FUNCTION () (list 39)) (define-instruction (POP-FUNCTION) 39 (set! *fun* (stack-pop))) (defun FUNCTION-INVOKE () (list 45)) (define-instruction (FUNCTION-INVOKE) 45 (invoke *fun* +false+)) (defun PRESERVE-ENV () (list 37)) (define-instruction (PRESERVE-ENV) 37 (preserve-environment)) (defun RESTORE-ENV () (list 38)) (define-instruction (RESTORE-ENV) 38 (restore-environment)) (defun POP-FRAME! (rank) (list 64 rank)) (define-instruction (POP-FRAME! rank) 64 (set-activation-frame-argument! *val* rank (stack-pop))) (defun POP-CONS-FRAME! (arity) (list 47 arity)) (define-instruction (POP-CONS-FRAME! arity) 47 (set-activation-frame-argument! *val* arity (cons (stack-pop) (activation-frame-argument *val* arity)))) (defun ALLOCATE-FRAME (size) (list 55 (+ size 1))) (define-instruction (ALLOCATE-FRAME size+1) 55 (set! *val* (allocate-activation-frame size+1))) (defun ALLOCATE-DOTTED-FRAME (arity) (list 56 (+ arity 1))) (define-instruction (ALLOCATE-DOTTED-FRAME arity) 56 (let ((v* (allocate-activation-frame arity))) (set-activation-frame-argument! v* (- arity 1) '()) (set! *val* v*))) (defun FINISH () (list 20)) (define-instruction (FINISH) 20 (funcall *exit* *val*)) (define-instruction-set) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; Preserve the state of the machine ie the three environments. (defun preserve-environment () (stack-push *env*)) (defun restore-environment () (set! *env* (stack-pop))) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo (defun fetch-byte () (let ((byte (vector-ref *code* *pc*))) (incf *pc*) byte)) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; Disassemble code (defun %disassemble% (code) (named-let rec ((result '()) (pc 0)) (if (>= pc (vector-length code)) (reverse! result) (rec (cons (instruction-decode code pc) result) (+ pc (instruction-size code pc)))))) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; If tail? is +true+ then the return address is on top of stack so no ;;; need to push another one. (defmethod invoke ((f t) tail?) (signal-exception +false+ (list "Not a function" f))) (defmethod invoke ((f closure) tail?) (unless tail? (stack-push *pc*)) (set! *env* (closure-closed-environment f)) (set! *pc* (closure-code f))) (defmethod invoke ((f primitive) tail?) (unless tail? (stack-push *pc*)) (funcall (primitive-address f))) (defmethod invoke ((f continuation) tail?) (if (= (+ 1 1) (activation-frame-argument-length *val*)) (begin (restore-stack (continuation-stack f)) (set! *val* (activation-frame-argument *val* 0)) (set! *pc* (stack-pop))) (signal-exception +false+ (list "Incorrect arity" 'continuation)))) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo (defmacro defprimitive0 (name value) `(definitial ,name (letrec ((arity+1 (+ 1 0)) (behavior (lambda () (if (= arity+1 (activation-frame-argument-length *val*)) (begin (set! *val* (,value)) (set! *pc* (stack-pop))) (signal-exception +true+ (list "Incorrect arity" ',name)))))) (description-extend! ',name `(function ,',value)) (make-primitive behavior)))) (defmacro defprimitive1 (name value) `(definitial ,name (letrec ((arity+1 (+ 1 1)) (behavior (lambda () (if (= arity+1 (activation-frame-argument-length *val*)) (let ((arg1 (activation-frame-argument *val* 0))) (set! *val* (,value arg1)) (set! *pc* (stack-pop))) (signal-exception +true+ (list "Incorrect arity" ',name)))))) (description-extend! ',name `(function ,',value a)) (make-primitive behavior)))) (defmacro defprimitive2 (name value) `(definitial ,name (letrec ((arity+1 (+ 2 1)) (behavior (lambda () (if (= arity+1 (activation-frame-argument-length *val*)) (let ((arg1 (activation-frame-argument *val* 0)) (arg2 (activation-frame-argument *val* 1))) (set! *val* (,value arg1 arg2)) (set! *pc* (stack-pop))) (signal-exception +true+ (list "Incorrect arity" ',name)))))) (description-extend! ',name `(function ,',value a b)) (make-primitive behavior)))) (definitial t +true+) (definitial f +false+) (definitial nil '()) (defprimitive cons cons 2) (defprimitive car car 1) (defprimitive cdr cdr 1) (defprimitive pair? pair? 1) (defprimitive symbol? symbol? 1) (defprimitive eq? eq? 2) (defprimitive set-car! set-car! 2) (defprimitive set-cdr! set-cdr! 2) (defprimitive + + 2) (defprimitive - - 2) (defprimitive = = 2) (defprimitive < < 2) (defprimitive > > 2) (defprimitive * * 2) (defprimitive <= <= 2) (defprimitive >= >= 2) (defprimitive remainder remainder 2) (defprimitive display display 1) (defprimitive read read 0) (defprimitive primitive? primitive? 1) (defprimitive continuation? continuation? 1) (defprimitive null? null? 1) (defprimitive newline newline 0) (defprimitive eof-object? eof-object? 1) ;;; The function which is invoked by call/cc always waits for an ;;; activation frame. (definitial call/cc (let* ((arity 1) (arity+1 (+ arity 1))) (make-primitive (lambda () (if (= arity+1 (activation-frame-argument-length *val*)) (let ((f (activation-frame-argument *val* 0)) (frame (allocate-activation-frame (+ 1 1)))) (set-activation-frame-argument! frame 0 (make-continuation (save-stack))) (set! *val* frame) (set! *fun* f) ; useful for debug (invoke f +true+)) (signal-exception +true+ (list "Incorrect arity" 'call/cc))))))) (definitial apply (let* ((arity 2) (arity+1 (+ arity 1))) (make-primitive (lambda () (if (>= (activation-frame-argument-length *val*) arity+1) (let* ((proc (activation-frame-argument *val* 0)) (args-number (activation-frame-argument-length *val*)) (last-arg-index (- args-number 2)) (last-arg (activation-frame-argument *val* last-arg-index)) (size (+ last-arg-index (length last-arg))) (frame (allocate-activation-frame size))) (do ((i 1 (+ i 1))) ((= i last-arg-index)) (set-activation-frame-argument! frame (- i 1) (activation-frame-argument *val* i))) (do ((i (- last-arg-index 1) (+ i 1)) (last-arg last-arg (cdr last-arg))) ((null? last-arg)) (set-activation-frame-argument! frame i (car last-arg))) (set! *val* frame) (set! *fun* proc) ; useful for debug (invoke proc +true+)) (signal-exception +false+ (list "Incorrect arity" 'apply))))))) (definitial list (make-primitive (lambda () (let ((args-number (- (activation-frame-argument-length *val*) 1)) (result '())) (do ((i args-number (- i 1))) ((= i 0)) (set! result (cons (activation-frame-argument *val* (- i 1)) result))) (set! *val* result) (set! *pc* (stack-pop)))))) ;;; Reserve some variables for future use in future chapters. (defmacro defreserve (name) `(definitial ,name (make-primitive (lambda () (signal-exception +false+ (list "Not yet implemented" ',name)))))) (defreserve global-value) (defreserve load) (defreserve eval) (defreserve eval/at) (defreserve eval/b) (defreserve enrich) (defreserve procedure->environment) (defreserve procedure->definition) (defreserve variable-value) (defreserve set-variable-value!) (defreserve variable-defined?) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; Use Meroon show functions to describe the inner working. (defparameter *debug* +false+) (defun show-registers (message) (when *debug* (format +true+ "~%----------------~A" message) (format +true+ "~%ENV = ") (show *env*) (format +true+ "~%VAL = ") (show *val*) (format +true+ "~%FUN = ") (show *fun*) (show-stack (save-stack)) (format +true+ "~%(PC = ~A), next INSTR to be executed = ~A~%" *pc* (instruction-decode *code* *pc*)))) (defun show-stack (stack) (let ((n (vector-length stack))) (do ((i 0 (+ i 1))) ((= i n)) (format +true+ "~%STK[~A]= " i) (show (vector-ref *stack* i))))) (defmethod show ((f t) &optional (stream *standard-output*)) (format stream "~A" f)) (defmethod show ((f closure) &optional (stream *standard-output*)) (format stream "#<Closure(pc=~A)>" (closure-code f))) (defmethod show ((a activation-frame) &optional (stream *standard-output*)) (display "[Frame next=" stream) (show (activation-frame-next a) stream) (display ", content=" stream) (do ((i 0 (+ 1 i))) ((= i (activation-frame-argument-length a))) (show (activation-frame-argument a i) stream) (display " & " stream)) (display "]" stream)) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo (defun code-prologue () (set! finish-pc 0) (FINISH)) (defun make-code-segment (m) (apply (function vector) (append (code-prologue) m (%RET%)))) (defun chapter7d-interpreter () (labels ((toplevel () (display (funcall (stand-alone-producer7d (read)) 100)) (toplevel))) (toplevel))) (defun stand-alone-producer7d (e) (set! g.current (original.g.current)) (set! *quotations* '()) (let* ((code (make-code-segment (meaning e r.init +true+))) (start-pc (length (code-prologue))) (global-names (mapcar (function car) (reverse g.current))) (constants (apply (function vector) *quotations*))) (lambda (stack-size) (run-machine stack-size start-pc code constants global-names)))) (defun run-machine (stack-size pc code constants global-names) #+nil (when *debugging* (mapc (function print) (%disassemble% code))) (set! sg.current (make-vector (length global-names) undefined-value)) (set! sg.current.names global-names) (set! *constants* constants) (set! *code* code) (set! *env* sr.init) (set! *stack* (make-vector stack-size)) (set! *stack-index* 0) (set! *val* 'anything) (set! *fun* 'anything) (set! *arg1* 'anything) (set! *arg2* 'anything) (stack-push finish-pc) ; pc for FINISH (set! *pc* pc) (call/cc (lambda (exit) (set! *exit* exit) (run)))) ;;; Patch run to show registers in debug mode. (let ((native-run (function run))) (setf (symbol-function 'run) (lambda () (when *debug* (show-registers "")) (funcall native-run)))) (let ((native-run-machine (function run-machine))) (setf (symbol-function 'run-machine) (lambda (stack-size pc code constants global-names) (when *debug* ; DEBUG (format +true+ "Code= ~A~%" (%disassemble% code))) (funcall native-run-machine stack-size pc code constants global-names)))) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; Tests (defun %eval (form) (funcall (stand-alone-producer7d form) 100) *val*) (defun scheme7d () (interpreter "Scheme? " "Scheme= " +true+ (lambda (read print error) (setup-wrong-functions error) (lambda () (funcall (stand-alone-producer7d (funcall read)) 100) (funcall print *val*))))) (defun test-scheme7d (&optional (file *scheme-test-file*)) (suite-test file "Scheme? " "Scheme= " +true+ (lambda (read check error) (setup-wrong-functions error) (lambda () (funcall (stand-alone-producer7d (funcall read)) 100) (funcall check *val*))) (function equal?))) (defun setup-wrong-functions (error) (setf (symbol-function 'signal-exception) (lambda (c &rest args) #+nil (declare (ignorable c)) (apply error args))) (setf (symbol-function 'wrong) (lambda (&rest args) (format +true+ " >>>>>>>>>>>>>>>>>>RunTime PANIC<<<<<<<<<<<<<<<<<<<<<<<<< ~A~%" (activation-frame-argument *val* 1)) (apply error args))) (setf (symbol-function 'static-wrong) (lambda (&rest args) (format +true+ " >>>>>>>>>>>>>>>>>>Static WARNING<<<<<<<<<<<<<<<<<<<<<<<<< ~A~%" args) (apply error args)))) ;;; Missing global variables (defparameter signal-exception 'wait) (defparameter finish-pc 'wait) (defparameter *exit* 'wait) ;;; end of chap7d.scm
23,749
Common Lisp
.lisp
683
30.225476
84
0.645701
gregcman/lisp-in-small-pieces
11
2
0
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
f991828a36794b9e57eabf6fe31a53de429e95719ea1b1fd15e161e8c9f9059d
8,739
[ -1 ]
8,740
chap6d.lisp
gregcman_lisp-in-small-pieces/chap6d.lisp
(in-package :lisp) ;;; Threaded interpreter. ;;; Environment is held by a global variable. This is bad for //ism. ;;; Continuation are now implicit and call/cc is a magical operator. ;;; Also try to introduce combinators as much as possible. ;;; Closures are explicitely represented. (defparameter *env* '()) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; Determine the nature of a variable. ;;; Three different answers. Or the variable is local (ie appears in R) ;;; then return (LOCAL index . depth) ;;; global (ie created by the user) then return ;;; (GLOBAL . index) ;;; or predefined (and immutable) then return ;;; (PREDEFINED . index) (defun compute-kind (r n) (or (local-variable? r 0 n) (global-variable? g.current n) (global-variable? g.init n))) (defun local-variable? (r i n) (and (pair? r) (named-let scan ((names (car r)) (j 0)) (cond ((pair? names) (if (eq? n (car names)) `(local ,i ,@j) (scan (cdr names) (+ 1 j)))) ((null? names) (local-variable? (cdr r) (+ i 1) n)) ((eq? n names) `(local ,i ,@j)))))) (defun global-variable? (g n) (let ((var (assq n g))) (and (pair? var) (cdr var)))) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; Representation of local environments, they contain the values of ;;; the local variables (but global and predefined variables). ;;; Runtime environment or, activation frames, are represented by ;;; vectors (named v*). They have the following structure: ;;; +------------+ ;;; | next | ---> next V* ;;; | argument 0 | value of the first argument ;;; | argument 1 | value of the second argument ;;; . . ;;; | free slot | Free slot for nary variable ;;; +------------+ ;;; The number of arguments can be extracted from the size of the ;;; activation frame. ;;; A direct implementation with inlined vectors is approximatively ;;; 7 times faster under sci. (progn (defclass environment () ((next :initarg next))) (defun environment? (obj) (typep obj 'environment)) (defun environment-next (obj) (slot-value obj 'next)) (defun set-environment-next! (obj new) (setf (slot-value obj 'next) new)) (defun make-environment (next) (make-instance 'environment 'next next))) (progn (defclass activation-frame (environment) ((argument :initarg argument))) (defun activation-frame? (obj) (typep obj 'activation-frame)) (defun activation-frame-argument (obj index) (aref (slot-value obj 'argument) index)) (defun activation-frame-argument-length (obj) (array-total-size (slot-value obj 'argument))) (defun set-activation-frame-argument! (obj index new) (setf (aref (slot-value obj 'argument) index) new)) (defun activation-frame-next (obj) (slot-value obj 'next)) (defun set-activation-frame-next! (obj new) (setf (slot-value obj 'next) new)) (defun allocate-activation-frame (n) (make-instance 'activation-frame 'argument (make-vector n)))) (defun sr-extend* (sr v*) (set-environment-next! v* sr) v*) (defparameter sr.init '()) ;;; Fetch the value of the Ith argument of the Jth frame. (defun deep-fetch (sr i j) (if (= i 0) (activation-frame-argument sr j) (deep-fetch (environment-next sr) (- i 1) j))) (defun deep-update! (sr i j v) (if (= i 0) (set-activation-frame-argument! sr j v) (deep-update! (environment-next sr) (- i 1) j v))) ;;; R is the static representation of the runtime local environment. ;;; It is represented by a list of list of variables (the classical ;;; rib cage). (defun r-extend* (r n*) (cons n* r)) (defparameter r.init '()) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; User-defined global environment definition. This environment is ;;; initially completely empty and can be extended by the user. ;;; It actually tolerates only 100 new global variables. ;;; G.CURRENT represents the `static' user-defined global environment. ;;; It is represented by the list of the symbols naming these global ;;; variables. Their values are held in the SG.CURRENT vector. (defparameter g.current '()) (defparameter sg.current (make-vector 100)) (defparameter sg.current.names (list 'foo)) (defun g.current-extend! (n) (let ((level (length g.current))) (push (cons n `(global ,@level)) g.current) level)) (defun global-fetch (i) (vector-ref sg.current i)) (defun global-update! (i v) (vector-set! sg.current i v)) (defun g.current-initialize! (name) (let ((kind (compute-kind r.init name))) (if kind (case (car kind) ((global) (vector-set! sg.current (cdr kind) undefined-value)) (otherwise (static-wrong "Wrong redefinition" name))) (let ((index (g.current-extend! name))) (vector-set! sg.current index undefined-value)))) name) ;;; This tag is used in the value cell of uninitialized variables. (defparameter undefined-value (cons 'undefined 'value)) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; Predefined global environment definition. This global environment ;;; is immutable. G.INIT represents the static predefined global ;;; environment and is represented by the list of the symbols naming ;;; these global variables. Their values are held in the SG.INIT vector. (defparameter g.init '()) (defparameter sg.init (make-vector 100)) (defun predefined-fetch (i) (vector-ref sg.init i)) (defun g.init-extend! (n) (let ((level (length g.init))) (push (cons n `(predefined ,@level)) g.init) level)) ;;; Add that value is associated to name in the predefined global environment. (defun g.init-initialize! (name value) (let ((kind (compute-kind r.init name))) (if kind (case (car kind) ((predefined) (vector-set! sg.init (cdr kind) value)) (otherwise (static-wrong "Wrong redefinition" name))) (let ((index (g.init-extend! name))) (vector-set! sg.init index value)))) name) ;;; Definitial allows to redefine immutable global variables. Useful ;;; when debugging interactively. (defmacro definitial (name value) `(g.init-initialize! ',name ,value)) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; Some free global locations: ;;; Define a location in the user global environment. (defmacro defvariable (name) `(g.current-initialize! ',name)) (defvariable x) (defvariable y) (defvariable z) (defvariable a) (defvariable b) (defvariable c) (defvariable foo) (defvariable bar) (defvariable hux) (defvariable fib) (defvariable fact) (defvariable visit) (defvariable length) (defvariable primes) ;;; Preserve the current modifiable global environment (containing a, ;;; b, foo, fact, fib etc.) All tests will be compiled in that environment. (let ((g g.current)) (defun original.g.current () g)) (defmacro defprimitive (name value number) (ecase number (0 `(defprimitive0 ,name ,value)) (1 `(defprimitive1 ,name ,value)) (2 `(defprimitive2 ,name ,value)) (3 `(defprimitive3 ,name ,value)))) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; Representation of functions. A redefinition with inlined vectors ;;; for more speed. (progn (defclass closure () ((code :initarg code) (closed-environment :initarg closed-environment))) (defun closure? (obj) (typep obj 'closure)) (defun closure-code (obj) (slot-value obj 'code)) (defun closure-closed-environment (obj) (slot-value obj 'closed-environment)) (defun set-closure-code! (obj new) (setf (slot-value obj 'code) new)) (defun set-closure-closed-environment! (obj) (setf (slot-value obj 'closed-environment) obj)) (defun make-closure (code closed-environment) (make-instance 'closure 'code code 'closed-environment closed-environment))) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; Describe a predefined value. ;;; The description language only represents primitives with their arity: ;;; (FUNCTION address . variables-list) ;;; with variables-list := () | (a) | (a b) | (a b c) ;;; Only the structure of the VARIABLES-LIST is interesting (not the ;;; names of the variables). ADDRESS is the address of the primitive ;;; to use when inlining an invokation to it. This address is ;;; represented by a Scheme procedure. (defparameter desc.init '()) (defun description-extend! (name description) (push (cons name description) desc.init) name) ;;; Return the description or +false+ if absent. (defun get-description (name) (let ((p (assq name desc.init))) (and (pair? p) (cdr p)))) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; The threaded interpreter. ;;; E is the expression to evaluate ;;; SR is the representation of the local lexical environment ;;; TAIL? is a boolean that indicates if E is a terminal call (also ;;; means whether the *env* register should be restored or not). (defun meaning (e r tail?) (if (atom? e) (if (symbol? e) (meaning-reference e r tail?) (meaning-quotation e r tail?)) (case (car e) ((quote) (meaning-quotation (cadr e) r tail?)) ((lambda) (meaning-abstraction (cadr e) (cddr e) r tail?)) ((if) (meaning-alternative (cadr e) (caddr e) (cadddr e) r tail?)) ((begin) (meaning-sequence (cdr e) r tail?)) ((set!) (meaning-assignment (cadr e) (caddr e) r tail?)) (otherwise (meaning-application (car e) (cdr e) r tail?))))) (defun meaning-reference (n r tail?) (let ((kind (compute-kind r n))) (if kind (case (car kind) ((local) (let ((i (cadr kind)) (j (cddr kind))) (if (= i 0) (SHALLOW-ARGUMENT-REF j) (DEEP-ARGUMENT-REF i j)))) ((global) (let ((i (cdr kind))) (CHECKED-GLOBAL-REF i))) ((predefined) (let ((i (cdr kind))) (PREDEFINED i)))) (static-wrong "No such variable" n)))) (defun meaning-quotation (v r tail?) (CONSTANT v)) (defun meaning-alternative (e1 e2 e3 r tail?) (let ((m1 (meaning e1 r +false+)) (m2 (meaning e2 r tail?)) (m3 (meaning e3 r tail?))) (ALTERNATIVE m1 m2 m3))) (defun meaning-assignment (n e r tail?) (let ((m (meaning e r +false+)) (kind (compute-kind r n))) (if kind (case (car kind) ((local) (let ((i (cadr kind)) (j (cddr kind))) (if (= i 0) (SHALLOW-ARGUMENT-SET! j m) (DEEP-ARGUMENT-SET! i j m)))) ((global) (let ((i (cdr kind))) (GLOBAL-SET! i m))) ((predefined) (static-wrong "Immutable predefined variable" n))) (static-wrong "No such variable" n)))) (defun meaning-sequence (e+ r tail?) (if (pair? e+) (if (pair? (cdr e+)) (meaning*-multiple-sequence (car e+) (cdr e+) r tail?) (meaning*-single-sequence (car e+) r tail?)) (static-wrong "Illegal syntax: (begin)"))) (defun meaning*-single-sequence (e r tail?) (meaning e r tail?)) (defun meaning*-multiple-sequence (e e+ r tail?) (let ((m1 (meaning e r +false+)) (m+ (meaning-sequence e+ r tail?))) (%SEQUENCE% m1 m+))) (defun meaning-abstraction (nn* e+ r tail?) (named-let parse ((n* nn*) (regular '())) (cond ((pair? n*) (parse (cdr n*) (cons (car n*) regular))) ((null? n*) (meaning-fix-abstraction nn* e+ r tail?)) (t (meaning-dotted-abstraction (reverse regular) n* e+ r tail?))))) (defun meaning-fix-abstraction (n* e+ r tail?) (let* ((arity (length n*)) (r2 (r-extend* r n*)) (m+ (meaning-sequence e+ r2 +true+))) (FIX-CLOSURE m+ arity))) (defun meaning-dotted-abstraction (n* n e+ r tail?) (let* ((arity (length n*)) (r2 (r-extend* r (append n* (list n)))) (m+ (meaning-sequence e+ r2 +true+))) (NARY-CLOSURE m+ arity))) ;;; Application meaning. (defun meaning-application (e e* r tail?) (if (and (pair? e) (eq? 'lambda (car e))) (meaning-closed-application e e* r tail?) (meaning-regular-application e e* r tail?))) ;;; Parse the variable list to check the arity and detect wether the ;;; abstraction is dotted or not. (defun meaning-closed-application (e ee* r tail?) (let ((nn* (cadr e))) (named-let parse ((n* nn*) (e* ee*) (regular '())) (cond ((pair? n*) (if (pair? e*) (parse (cdr n*) (cdr e*) (cons (car n*) regular)) (static-wrong "Too less arguments" e ee*))) ((null? n*) (if (null? e*) (meaning-fix-closed-application nn* (cddr e) ee* r tail?) (static-wrong "Too much arguments" e ee*))) (t (meaning-dotted-closed-application (reverse regular) n* (cddr e) ee* r tail?)))))) (defun meaning-fix-closed-application (n* body e* r tail?) (let* ((m* (meaning* e* r (length e*) +false+)) (r2 (r-extend* r n*)) (m+ (meaning-sequence body r2 tail?))) (if tail? (TR-FIX-LET m* m+) (FIX-LET m* m+)))) (defun meaning-dotted-closed-application (n* n body e* r tail?) (let* ((m* (meaning-dotted* e* r (length e*) (length n*) +false+)) (r2 (r-extend* r (append n* (list n)))) (m+ (meaning-sequence body r2 tail?))) (if tail? (TR-FIX-LET m* m+) (FIX-LET m* m+)))) ;;; In a regular application, the invocation protocol is to call the ;;; function with an activation frame and a continuation: (f v* k). (defun meaning-regular-application (e e* r tail?) (let* ((m (meaning e r +false+)) (m* (meaning* e* r (length e*) +false+))) (if tail? (TR-REGULAR-CALL m m*) (REGULAR-CALL m m*)))) (defun meaning* (e* r size tail?) (if (pair? e*) (meaning-some-arguments (car e*) (cdr e*) r size tail?) (meaning-no-argument r size tail?))) (defun meaning-dotted* (e* r size arity tail?) (if (pair? e*) (meaning-some-dotted-arguments (car e*) (cdr e*) r size arity tail?) (meaning-no-dotted-argument r size arity tail?))) (defun meaning-some-arguments (e e* r size tail?) (let ((m (meaning e r +false+)) (m* (meaning* e* r size tail?)) (rank (- size (+ (length e*) 1)))) (STORE-ARGUMENT m m* rank))) (defun meaning-some-dotted-arguments (e e* r size arity tail?) (let ((m (meaning e r +false+)) (m* (meaning-dotted* e* r size arity tail?)) (rank (- size (+ (length e*) 1)))) (if (< rank arity) (STORE-ARGUMENT m m* rank) (CONS-ARGUMENT m m* arity)))) (defun meaning-no-argument (r size tail?) (ALLOCATE-FRAME size)) (defun meaning-no-dotted-argument (r size arity tail?) (ALLOCATE-DOTTED-FRAME arity)) ;;; Gather into a list all arguments from arity+1 to the end of the ;;; activation frame and store this list into the arity+1th slot. (defun listify! (v* arity) (named-let rec ((index (- (activation-frame-argument-length v*) 1)) (result '())) (if (= arity index) (set-activation-frame-argument! v* arity result) (rec (- index 1) (cons (activation-frame-argument v* (- index 1)) result)))))
15,529
Common Lisp
.lisp
403
33.875931
79
0.644662
gregcman/lisp-in-small-pieces
11
2
0
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
7df6dbe5e16291be4b08953d4fa4c10bd5eecfc34c397509ed0fb0de1e19c8bf
8,740
[ -1 ]
8,741
other2.lisp
gregcman_lisp-in-small-pieces/other2.lisp
(in-package :lisp) (defun static-wrong (message &rest args) (print args) (error message)) (defun wrong (message &rest args) (print args) (error message)) (defun signal-exception (message args) (declare (ignore message)) (print args))
249
Common Lisp
.lisp
10
22.4
40
0.724576
gregcman/lisp-in-small-pieces
11
2
0
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
06be063794a4de4b54a333045d0e1bb4f3ae11e222f536e93bbf304baf7bef87
8,741
[ -1 ]
8,742
chap7d-unused.lisp
gregcman_lisp-in-small-pieces/unused/chap7d-unused.lisp
#+nil (define-class primitive Object (address)) #+nil (define-class continuation Object (stack)) #+nil (progn (defun CALL0 (address) (INVOKE0 address)) (defun CALL1 (address m1) (append m1 (INVOKE1 address))) (defun CALL2 (address m1 m2) (append m1 (PUSH-VALUE) m2 (POP-ARG1) (INVOKE2 address))) (defun CALL3 (address m1 m2 m3) (append m1 (PUSH-VALUE) m2 (PUSH-VALUE) m3 (POP-ARG2) (POP-ARG1) (INVOKE3 address)))) (defun SHALLOW-ARGUMENT-REF (j) (check-byte j) (case j ((0 1 2 3) (list (+ 1 j))) (otherwise (list 5 j)))) (defun PREDEFINED (i) (check-byte i) (case i ;; 0=\+true+, 1=\+false+, 2=(), 3=cons, 4=car, 5=cdr, 6=pair?, 7=symbol?, 8=eq? ((0 1 2 3 4 5 6 7 8) (list (+ 10 i))) (otherwise (list 19 i)))) (defun SET-SHALLOW-ARGUMENT! (j) (case j ((0 1 2 3) (list (+ 21 j))) (otherwise (list 25 j)))) (defun CONSTANT (value) (cond ((eq? value +true+) (list 10)) ((eq? value +false+) (list 11)) ((eq? value '()) (list 12)) ((equal? value -1) (list 80)) ((equal? value 0) (list 81)) ((equal? value 1) (list 82)) ((equal? value 2) (list 83)) ((equal? value 4) (list 84)) ((and (integer? value) ; immediate value (<= 0 value) (< value 255)) (list 79 value)) (t (EXPLICIT-CONSTANT value)))) (defun INVOKE0 (address) (case address ((read) (list 89)) ((newline) (list 88)) (otherwise (static-wrong "Cannot integrate" address)))) #+nil (defun INVOKE1 (address) (case address ((car) (list 90)) ((cdr) (list 91)) ((pair?) (list 92)) ((symbol?) (list 93)) ((display) (list 94)) (otherwise (static-wrong "Cannot integrate" address)))) ;;; The same one with other unary primitives. (defun INVOKE1 (address) (case address ((car) (list 90)) ((cdr) (list 91)) ((pair?) (list 92)) ((symbol?) (list 93)) ((display) (list 94)) ((primitive?) (list 95)) ((null?) (list 96)) ((continuation?) (list 97)) ((eof-object?) (list 98)) (otherwise (static-wrong "Cannot integrate" address)))) (defun INVOKE2 (address) (case address ((cons) (list 100)) ((eq?) (list 101)) ((set-car!) (list 102)) ((set-cdr!) (list 103)) ((+) (list 104)) ((-) (list 105)) ((=) (list 106)) ((<) (list 107)) ((>) (list 108)) ((*) (list 109)) ((<=) (list 110)) ((>=) (list 111)) ((remainder)(list 112)) (otherwise (static-wrong "Cannot integrate" address)))) (defun INVOKE3 (address) (static-wrong "No ternary integrated procedure" address)) (defun ARITY=? (arity+1) (case arity+1 ((1 2 3 4) (list (+ 70 arity+1))) (otherwise (list 75 arity+1)))) (defun POP-FRAME! (rank) (case rank ((0 1 2 3) (list (+ 60 rank))) (otherwise (list 64 rank)))) (defun ALLOCATE-FRAME (size) (case size ((0 1 2 3 4) (list (+ 50 size))) (otherwise (list 55 (+ size 1)))))
3,086
Common Lisp
.lisp
115
22.634783
83
0.551234
gregcman/lisp-in-small-pieces
11
2
0
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
11420fd9e5b47d7f1d4db0fc328ede60a7ec218766a8278e3453fe1b87de1e9e
8,742
[ -1 ]
8,743
chap6d-unused.lisp
gregcman_lisp-in-small-pieces/unused/chap6d-unused.lisp
(in-package :lisp) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo #+nil (defun invoke (f v*) (if (closure? f) (funcall (closure-code f) v* (closure-closed-environment f)) (wrong "Not a function" f))) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; Combinators (defun SHALLOW-ARGUMENT-REF (j) (lambda () (activation-frame-argument *env* j))) (defun PREDEFINED (i) (lambda () (predefined-fetch i))) (defun DEEP-ARGUMENT-REF (i j) (lambda () (deep-fetch *env* i j))) (defun SHALLOW-ARGUMENT-SET! (j m) (lambda () (set-activation-frame-argument! *env* j (m)))) (defun DEEP-ARGUMENT-SET! (i j m) (lambda () (deep-update! *env* i j (m)))) (defun GLOBAL-REF (i) (lambda () (global-fetch i))) ;;; Note that we lost the name of the variable, it must be retrieved ;;; from elsewhere. TOBEDONE (defun CHECKED-GLOBAL-REF (i) (lambda () (let ((v (global-fetch i))) (if (eq? v undefined-value) (wrong "Uninitialized variable") v)))) (defun GLOBAL-SET! (i m) (lambda () (global-update! i (m)))) (defun CONSTANT (value) (lambda () value)) (defun ALTERNATIVE (m1 m2 m3) (lambda () (if (m1) (m2) (m3)))) (defun %SEQUENCE% (m m+) (lambda () (m) (m+))) (defun TR-FIX-LET (m* m+) (lambda () (set! *env* (sr-extend* *env* (m*))) (m+))) (defun FIX-LET (m* m+) (lambda () (set! *env* (sr-extend* *env* (m*))) (let ((result (m+))) (set! *env* (environment-next *env*)) result))) (defun CALL0 (address) (lambda () (address))) (defun CALL1 (address m1) (lambda () (address (m1)))) (defun CALL2 (address m1 m2) (lambda () (let ((v1 (m1))) (address v1 (m2))))) (defun CALL3 (address m1 m2 m3) (lambda () (let* ((v1 (m1)) (v2 (m2))) (address v1 v2 (m3))))) (defun FIX-CLOSURE (m+ arity) (let ((arity+1 (+ arity 1))) (lambda () (labels ((the-function (v* sr) (if (= (activation-frame-argument-length v*) arity+1) (begin (set! *env* (sr-extend* sr v*)) (m+)) (wrong "Incorrect arity")))) (make-closure (function the-function) *env*))))) (defun NARY-CLOSURE (m+ arity) (let ((arity+1 (+ arity 1))) (lambda () (labels ((the-function (v* sr) (if (>= (activation-frame-argument-length v*) arity+1) (begin (listify! v* arity) (set! *env* (sr-extend* sr v*)) (m+)) (wrong "Incorrect arity")))) (make-closure (function the-function) *env*))))) (defun TR-REGULAR-CALL (m m*) (lambda () (let ((f (m))) (invoke f (m*))))) (defun REGULAR-CALL (m m*) (lambda () (let* ((f (m)) (v* (m*)) (sr *env*) (result (invoke f v*))) (set! *env* sr) result))) (defun STORE-ARGUMENT (m m* rank) (lambda () (let* ((v (m)) (v* (m*))) (set-activation-frame-argument! v* rank v) v*))) (defun CONS-ARGUMENT (m m* arity) (lambda () (let* ((v (m)) (v* (m*))) (set-activation-frame-argument! v* arity (cons v (activation-frame-argument v* arity))) v*))) (defun ALLOCATE-FRAME (size) (let ((size+1 (+ size 1))) (lambda () (allocate-activation-frame size+1)))) (defun ALLOCATE-DOTTED-FRAME (arity) (let ((arity+1 (+ arity 1))) (lambda () (let ((v* (allocate-activation-frame arity+1))) (set-activation-frame-argument! v* arity '()) v*)))) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; Global environment initializers. (defmacro defprimitive1 (name value) `(definitial ,name (letrec ((arity+1 (+ 1 1)) (behavior (lambda (v* sr) (if (= (activation-frame-argument-length v*) arity+1) (,value (activation-frame-argument v* 0)) (wrong "Incorrect arity" ',name))))) (description-extend! ',name `(function ,',value a)) (make-closure behavior sr.init)))) (defmacro defprimitive2 (name value) `(definitial ,name (letrec ((arity+1 (+ 2 1)) (behavior (lambda (v* sr) (if (= (activation-frame-argument-length v*) arity+1) (value (activation-frame-argument v* 0) (activation-frame-argument v* 1)) (wrong "Incorrect arity" ',name))))) (description-extend! ',name `(function ,',value a b)) (make-closure behavior sr.init)))) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; Initialization of the predefined global environment. (defprimitive cons cons 2) (defprimitive car car 1) (defprimitive cdr cdr 1) (defprimitive pair? pair? 1) (defprimitive symbol? symbol? 1) (defprimitive eq? eq? 2) (defprimitive set-car! set-car! 2) (defprimitive set-cdr! set-cdr! 2) (defprimitive + + 2) (defprimitive - - 2) (defprimitive = = 2) (defprimitive < < 2) (defprimitive > > 2) (defprimitive * * 2) (defprimitive <= <= 2) (defprimitive >= >= 2) (defprimitive remainder remainder 2) (defprimitive display display 1) ;;; We do not need to save the register *env* since call/cc is not a ;;; primitive (it is defined by definitial and not by defprimitive) ;;; and non-primitive invokations are regularly handled. (definitial call/cc (let* ((arity 1) (arity+1 (+ arity 1))) (make-closure (lambda (v* sr) (if (= arity+1 (activation-frame-argument-length v*)) (call/cc (lambda (k) (invoke (activation-frame-argument v* 0) (let ((frame (allocate-activation-frame (+ 1 1)))) (set-activation-frame-argument! frame 0 (make-closure (lambda (values r) (if (= (activation-frame-argument-length values) arity+1) (k (activation-frame-argument values 0)) (wrong "Incorrect arity" 'continuation))) sr.init)) frame)))) (wrong "Incorrect arity" 'call/cc))) sr.init))) (definitial apply (let* ((arity 2) (arity+1 (+ arity 1))) (make-closure (lambda (v* sr) (if (>= (activation-frame-argument-length v*) arity+1) (let* ((proc (activation-frame-argument v* 0)) (last-arg-index (- (activation-frame-argument-length v*) 2)) (last-arg (activation-frame-argument v* last-arg-index)) (size (+ last-arg-index (length last-arg))) (frame (allocate-activation-frame size))) (do ((i 1 (+ i 1))) ((= i last-arg-index)) (set-activation-frame-argument! frame (- i 1) (activation-frame-argument v* i))) (do ((i (- last-arg-index 1) (+ i 1)) (last-arg last-arg (cdr last-arg))) ((null? last-arg)) (set-activation-frame-argument! frame i (car last-arg))) (invoke proc frame)) (wrong "Incorrect arity" 'apply))) sr.init))) (definitial list (funcall (NARY-CLOSURE (SHALLOW-ARGUMENT-REF 0) 0))) ;;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; Testing (defun chapter63-interpreter () (labels ((toplevel () (set! *env* sr.init) (display (funcall (meaning (read) r.init +true+))) (toplevel))) (toplevel))) ;;; This variant produces a table of symbols. (defun stand-alone-producer (e) (set! g.current (original.g.current)) (let* ((m (meaning e r.init +true+)) (size (length g.current)) (global-names (mapcar (function car) (reverse g.current)))) (lambda () (set! sg.current (make-vector size undefined-value)) (set! sg.current.names global-names) (set! *env* sr.init) (m)))) (defun CHECKED-GLOBAL-REF+ (i) (lambda () (let ((v (global-fetch i))) (if (eq? v undefined-value) (wrong "Uninitialized variable" (list-ref sg.current.names i)) v)))) ;;; this one requires to close the name of the variables that must be ;;; checked. To use it you must also change meaning-reference that calls it. (defun CHECKED-GLOBAL-REF- (i n) (lambda () (let ((v (global-fetch i))) (if (eq? v undefined-value) (wrong "Uninitialized variable" n) v)))) ;;; retrofit for tests. (setf (symbol-function 'CHECKED-GLOBAL-REF) (function CHECKED-GLOBAL-REF+)) (defun scheme6d () (interpreter "Scheme? " "Scheme= " +true+ (lambda (read print error) (set! wrong error) (set! static-wrong error) (lambda () (set! *env* sr.init) (print (funcall (stand-alone-producer (read)))))))) (defun test-scheme6d (file) (suite-test file "Scheme? " "Scheme= " +true+ (lambda (read check error) (set! wrong error) (set! static-wrong error) (lambda () (check (funcall (stand-alone-producer (read)))))) equal?)) ;;; Pay attention to tail-rec in Scheme->C. (defun bench6d (factor e) (let ((start (get-internal-run-time)) (m (meaning e r.init +true+))) (named-let rec ((factor factor)) (set! *env* sr.init) (let ((v (m))) (let ((duration (- (get-internal-run-time) start))) (when (<= factor 1) (display (list duration v)) (newline)))) (if (> factor 1) (rec (- factor 1)))))) ;;;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;;; The following code use ;;; pp to pretty-print expressions, ;;; and eval for a local hack (should be made of macros instead). (defparameter combinator-names '(SHALLOW-ARGUMENT-REF PREDEFINED DEEP-ARGUMENT-REF SHALLOW-ARGUMENT-SET! DEEP-ARGUMENT-SET! GLOBAL-REF CHECKED-GLOBAL-REF GLOBAL-SET! CONSTANT ALTERNATIVE %SEQUENCE% TR-FIX-LET FIX-LET CALL0 CALL1 CALL2 CALL3 FIX-CLOSURE NARY-CLOSURE TR-REGULAR-CALL REGULAR-CALL STORE-ARGUMENT CONS-ARGUMENT ALLOCATE-FRAME ALLOCATE-DOTTED-FRAME)) (let ((originals (mapcar (function symbol-function) combinator-names))) (defun install-regular-combinators () (for-each (lambda (old-value name) (eval `(set! ,name ',old-value))) originals combinator-names))) (defun install-disassembling-combinators () (for-each (lambda (name) (eval `(set! ,name (lambda args (,name ,@args))))) combinator-names)) (defun %disassemble% (e) (install-disassembling-combinators) (pp (meaning e r.init +true+)) (install-regular-combinators) (newline)) ;;; (disassemble '(lambda (n) (if (= n 0) 1 (* n (fact (- n 1)))))) ;;; (disassemble '(lambda (n) (if (= n 0) 1 (* (fact (- n 1)) n)))) ;;; end of chap6d.scm ;;;;*****************************modified functions******************************* (define-class environment Object (next)) (define-class activation-frame environment ((* argument))) (define-class closure Object (code closed-environment)) (defun meaning-application (e e* r tail?) (cond ((and (symbol? e) (let ((kind (compute-kind r e))) (and (pair? kind) (eq? 'predefined (car kind)) (let ((desc (get-description e))) (and desc (eq? 'function (car desc)) (or (= (length (cddr desc)) (length e*)) (static-wrong "Incorrect arity for primitive" e) )))))) (meaning-primitive-application e e* r tail?)) ((and (pair? e) (eq? 'lambda (car e))) (meaning-closed-application e e* r tail?)) (t (meaning-regular-application e e* r tail?)))) ;;; Handles a call to a predefined primitive. The arity is already checked. ;;; The optimization is to avoid the allocation of the activation frame. ;;; These primitives never change the *env* register nor have control effect. (defun meaning-primitive-application (e e* r tail?) (let* ((desc (get-description e)) ;; desc = (function address . variables-list) (address (cadr desc)) (size (length e*))) (case size ((0) (CALL0 address)) ((1) (let ((m1 (meaning (car e*) r +false+))) (CALL1 address m1))) ((2) (let ((m1 (meaning (car e*) r +false+)) (m2 (meaning (cadr e*) r +false+))) (CALL2 address m1 m2))) ((3) (let ((m1 (meaning (car e*) r +false+)) (m2 (meaning (cadr e*) r +false+)) (m3 (meaning (caddr e*) r +false+))) (CALL3 address m1 m2 m3))) (otherwise (meaning-regular-application e e* r tail?)))))
12,660
Common Lisp
.lisp
382
27.041885
82
0.594236
gregcman/lisp-in-small-pieces
11
2
0
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
ee9dc7a42d2b884de03656023628b737a0c7abd460c90aff606eed2618e9fe38
8,743
[ -1 ]
8,744
chap7f.lisp
gregcman_lisp-in-small-pieces/unused/chap7f.lisp
;;; Instruction set. ;;; This file is read by chap7d.scm
57
Common Lisp
.lisp
2
27.5
35
0.709091
gregcman/lisp-in-small-pieces
11
2
0
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
a5f423e40e6df73d88a9e9d2f28854b0c48438df690620256088f0b503865c68
8,744
[ -1 ]
8,745
chap7f-unused.lisp
gregcman_lisp-in-small-pieces/unused/chap7f-unused.lisp
#+nil (progn (define-instruction (SHALLOW-ARGUMENT-REF0) 1 (set! *val* (activation-frame-argument *env* 0))) (define-instruction (SHALLOW-ARGUMENT-REF1) 2 (set! *val* (activation-frame-argument *env* 1))) (define-instruction (SHALLOW-ARGUMENT-REF2) 3 (set! *val* (activation-frame-argument *env* 2))) (define-instruction (SHALLOW-ARGUMENT-REF3) 4 (set! *val* (activation-frame-argument *env* 3)))) #+nil (progn (define-instruction (PREDEFINED0) 10 ; \+true+ (set! *val* +true+)) (define-instruction (PREDEFINED1) 11 ; \+false+ (set! *val* +false+)) (define-instruction (PREDEFINED2) 12 ; () (set! *val* '())) (define-instruction (PREDEFINED3) 13 ; cons (set! *val* (predefined-fetch 3))) (define-instruction (PREDEFINED4) 14 ; car (set! *val* (predefined-fetch 4))) (define-instruction (PREDEFINED5) 15 ; cdr (set! *val* (predefined-fetch 5))) (define-instruction (PREDEFINED6) 16 ; pair? (set! *val* (predefined-fetch 6))) (define-instruction (PREDEFINED7) 17 ; symbol? (set! *val* (predefined-fetch 7))) (define-instruction (PREDEFINED8) 18 ; eq? (set! *val* (predefined-fetch 8)))) #+nil (progn (define-instruction (SET-SHALLOW-ARGUMENT!0) 21 (set-activation-frame-argument! *env* 0 *val*)) (define-instruction (SET-SHALLOW-ARGUMENT!1) 22 (set-activation-frame-argument! *env* 1 *val*)) (define-instruction (SET-SHALLOW-ARGUMENT!2) 23 (set-activation-frame-argument! *env* 2 *val*)) (define-instruction (SET-SHALLOW-ARGUMENT!3) 24 (set-activation-frame-argument! *env* 3 *val*))) #+nil (progn (define-instruction (ALLOCATE-FRAME1) 50 (set! *val* (allocate-activation-frame 1))) (define-instruction (ALLOCATE-FRAME2) 51 (set! *val* (allocate-activation-frame 2))) (define-instruction (ALLOCATE-FRAME3) 52 (set! *val* (allocate-activation-frame 3))) (define-instruction (ALLOCATE-FRAME4) 53 (set! *val* (allocate-activation-frame 4))) (define-instruction (ALLOCATE-FRAME5) 54 (set! *val* (allocate-activation-frame 5)))) #+nil (progn (define-instruction (POP-FRAME!0) 60 (set-activation-frame-argument! *val* 0 (stack-pop))) (define-instruction (POP-FRAME!1) 61 (set-activation-frame-argument! *val* 1 (stack-pop))) (define-instruction (POP-FRAME!2) 62 (set-activation-frame-argument! *val* 2 (stack-pop))) (define-instruction (POP-FRAME!3) 63 (set-activation-frame-argument! *val* 3 (stack-pop)))) #+nil (progn (define-instruction (ARITY=?1) 71 (unless (= (activation-frame-argument-length *val*) 1) (signal-exception +false+ (list "Too much arguments for a thunk")))) (define-instruction (ARITY=?2) 72 (unless (= (activation-frame-argument-length *val*) 2) (signal-exception +false+ (list "Incorrect arity for unary function")))) (define-instruction (ARITY=?3) 73 (unless (= (activation-frame-argument-length *val*) 3) (signal-exception +false+ (list "Incorrect arity for binary function")))) (define-instruction (ARITY=?4) 74 (unless (= (activation-frame-argument-length *val*) 4) (signal-exception +false+ (list "Incorrect arity for ternary function"))))) #+nil (progn (define-instruction (CONSTANT-1) 80 (set! *val* -1)) (define-instruction (CONSTANT0) 81 (set! *val* 0)) (define-instruction (CONSTANT1) 82 (set! *val* 1)) (define-instruction (CONSTANT2) 83 (set! *val* 2)) (define-instruction (CONSTANT4) 84 (set! *val* 4))) #+nil (progn (define-instruction (CALL0-newline) 88 (set! *val* (newline))) (define-instruction (CALL0-read) 89 (set! *val* (read))) (define-instruction (CALL1-car) 90 (set! *val* (car *val*))) (define-instruction (CALL1-cdr) 91 (set! *val* (cdr *val*))) (define-instruction (CALL1-pair?) 92 (set! *val* (pair? *val*))) (define-instruction (CALL1-symbol?) 93 (set! *val* (symbol? *val*))) (define-instruction (CALL1-display) 94 (set! *val* (show *val*))) (define-instruction (CALL1-primitive?) 95 (set! *val* (primitive? *val*))) (define-instruction (CALL1-null?) 96 (set! *val* (null? *val*))) (define-instruction (CALL1-continuation?) 97 (set! *val* (continuation? *val*))) (define-instruction (CALL1-eof-object?) 98 (set! *val* (eof-object? *val*))) (define-instruction (CALL2-cons) 100 (set! *val* (cons *arg1* *val*))) (define-instruction (CALL2-eq?) 101 (set! *val* (eq? *arg1* *val*))) (define-instruction (CALL2-set-car!) 102 (set! *val* (set-car! *arg1* *val*))) (define-instruction (CALL2-set-cdr!) 103 (set! *val* (set-cdr! *arg1* *val*))) (define-instruction (CALL2-+) 104 (set! *val* (+ *arg1* *val*))) (define-instruction (CALL2--) 105 (set! *val* (- *arg1* *val*))) (define-instruction (CALL2-=) 106 (set! *val* (= *arg1* *val*))) (define-instruction (CALL2-<) 107 (set! *val* (< *arg1* *val*))) (define-instruction (CALL2->) 108 (set! *val* (> *arg1* *val*))) (define-instruction (CALL2-*) 109 (set! *val* (* *arg1* *val*))) (define-instruction (CALL2-<=) 110 (set! *val* (<= *arg1* *val*))) (define-instruction (CALL2->=) 111 (set! *val* (>= *arg1* *val*))) (define-instruction (CALL2-remainder) 112 (set! *val* (remainder *arg1* *val*)))) (define-instruction (DYNAMIC-REF index) 240 (set! *val* (find-dynamic-value index))) (define-instruction (DYNAMIC-POP) 241 (pop-dynamic-binding)) (define-instruction (DYNAMIC-PUSH index) 242 (push-dynamic-binding index *val*)) (define-instruction (NON-CONT-ERR) 245 (signal-exception +false+ (list "Non continuable exception continued"))) (define-instruction (PUSH-HANDLER) 246 (push-exception-handler)) (define-instruction (POP-HANDLER) 247 (pop-exception-handler)) (define-instruction (POP-ESCAPER) 250 (let* ((tag (stack-pop)) (escape (stack-pop))) (restore-environment))) (define-instruction (PUSH-ESCAPER offset) 251 (preserve-environment) (let* ((escape (make-escape (+ *stack-index* 3))) (frame (allocate-activation-frame 1))) (set-activation-frame-argument! frame 0 escape) (set! *env* (sr-extend* *env* frame)) (stack-push escape) (stack-push escape-tag) (stack-push (+ *pc* offset)))) ;;; Used by chap8d.scm (eval as a special form) (define-instruction (COMPILE-RUN) 255 (let ((v *val*) (r (stack-pop))) (if (program? v) (compile-and-run v r +false+) (signal-exception +true+ (list "Illegal program" v))))) ;;; Used by chap8h.scm (export special form) (define-instruction (CREATE-1ST-CLASS-ENV) 254 (create-first-class-environment *val* *env*)) (define-instruction (CHECKED-DEEP-REF i j) 253 (set! *val* (deep-fetch *env* i j)) (when (eq? *val* undefined-value) (signal-exception +true+ (list "Uninitialized local variable")))) (define-instruction (CREATE-PSEUDO-ENV) 252 (create-pseudo-environment (stack-pop) *val* *env*)) (define-instruction (SHADOW-REF i j) 231 (shadowable-fetch *env* i j)) (define-instruction (SET-SHADOW! i j) 232 (shadowable-update! *env* i j *val*)) ;;; end of chap7f.scm
7,191
Common Lisp
.lisp
185
34.762162
81
0.655637
gregcman/lisp-in-small-pieces
11
2
0
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
11a498907bf3e61bf2316796d6fb6e7d350067f38c8142812048039425fce4d7
8,745
[ -1 ]
8,746
package.lisp
gregcman_lisp-in-small-pieces/interpreters/package.lisp
(defpackage #:lisp-in-small-pieces (:use :cl) (:shadow #:defun #:defparameter #:fmakunbound #:makunbound #:boundp #:fboundp ) (:nicknames #:lisp)) (in-package #:lisp) (defmacro defun (name args &body body) `(progn (cl:defun ,name ,args ,@body) (setf (gethash ',name *function-namespace*) t) (setf (get ',name 'defun) '(lambda ,args ,@body)) (setf (get ',name 'arity) ,(length args)))) (defmacro defparameter (name value) `(progn (cl:defparameter ,name ,value) (setf (gethash ',name *variable-namespace*) t) (setf (get ',name 'defparameter) ',value))) (defparameter *variable-namespace* (make-hash-table :test 'eq)) (defparameter *function-namespace* (make-hash-table :test 'eq)) (defparameter *not-found* (cons "not" "found")) (defun prop-exists (name indicator) (not (eq *not-found* (get name indicator *not-found*)))) (defun boundp (name) (or (prop-exists name 'defvar) (prop-exists name 'defparameter))) (defun fboundp (name) (prop-exists name 'defun)) (defun fmakunbound (name) (remf name 'defun) (remhash name *function-namespace*) (cl:fmakunbound name)) (defun makunbound (name) (remf name 'defparameter) (remf name 'defvar) (remhash name *variable-namespace*) (cl:makunbound name)) (setf *print-case* :downcase) (setf *print-circle* t)
1,337
Common Lisp
.lisp
49
24.367347
63
0.683801
gregcman/lisp-in-small-pieces
11
2
0
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
d5734decb2f08584c8eb54e59dea41bad91a95ee92f9560be962793f6fc1a67d
8,746
[ -1 ]
8,747
other.lisp
gregcman_lisp-in-small-pieces/interpreters/other.lisp
(in-package :lisp) ;;;;values (defparameter *the-false-value* nil) (defun truep (value) (not (eq *the-false-value* value))) (defun booleanp (value) (or (eq *the-false-value* value) (eq t value))) (defparameter *empty-progn* 69) ;;;;environments ;;;;represented as alists where each cell is (symbol . value) (defparameter *initial-environment* '()) (defun lookup (id env) (if (consp env) (if (eq (car (car env)) id) (cdr (car env)) (lookup id (cdr env))) (error "no such binding ~s" id))) (defun update! (id env value) (if (consp env) (if (eq (car (car env)) id) (progn (rplacd (car env) value) value) (update! id (cdr env) value)) (error "no such binding ~s" id))) (defun extend (env variables values) (cond ((consp variables) (if (consp values) (cons (cons (car variables) (car values)) (extend env (cdr variables) (cdr values))) (error "too few values"))) ((null variables) (if (null values) env (error "too many values"))) ((symbolp variables) (cons (cons variables values) env))))
1,110
Common Lisp
.lisp
42
22.452381
61
0.624765
gregcman/lisp-in-small-pieces
11
2
0
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
a16affe2cfd431540e81e63edc9e23a6733c18c98263306d644e45d025d38fdc
8,747
[ -1 ]
8,748
lisp-in-small-pieces2.lisp
gregcman_lisp-in-small-pieces/interpreters/lisp-in-small-pieces2.lisp
(in-package :lisp) ;;;;f.eval (defun %eval (form env fenv) (if (atom form) (if (symbolp form) (lookup form env) form) (case (car form) (quote (car (cdr form))) (if (if (truep (%eval (car (cdr form)) env fenv)) (%eval (car (cdr (cdr form))) env fenv) (%eval (car (cdr (cdr (cdr form)))) env fenv))) (progn (evaluate-progn (cdr form) env fenv)) (setq (update! (car (cdr form)) env (%eval (car (cdr (cdr form))) env fenv))) (lambda (make-function (car (cdr form)) (cdr (cdr form)) env fenv)) (function (cond ((symbolp (car (cdr form))) (lookup (car (cdr form)) fenv)) (t (error "incorrect function ~a" (car (cdr form)))))) (otherwise (evaluate-application (car form) (evlis (cdr form) env fenv) env fenv))))) (defun evaluate-application (var params env fenv) (cond ((symbolp var) (%apply (lookup var fenv) params)) ((and (consp var) (eq (car var) 'lambda)) (evaluate-progn (cdr (cdr var)) (extend env (car (cdr var)) params) fenv)) (t (error "incorrect functional term ~s" var)))) (defun evlis (params env fenv) (if (consp params) (let ((arg0 (%eval (car params) env fenv))) (cons arg0 (evlis (cdr params) env fenv))) nil)) (defun evaluate-progn (body env fenv) (if (consp body) (if (consp (cdr body)) (progn (%eval (car body) env fenv) (evaluate-progn (cdr body) env fenv)) (%eval (car body) env fenv)) *empty-progn*)) (defun %apply (function args) (if (functionp function) (funcall function args) (error "not a function ~s" function))) (defun make-function (parameters body env fenv) (lambda (values) (evaluate-progn body (extend env parameters values) fenv)))
1,938
Common Lisp
.lisp
89
16.52809
62
0.568022
gregcman/lisp-in-small-pieces
11
2
0
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
8b521cebb336a2d7edae4cab26bd1d0a6475ffa6c5c1ab248eb9f20fcbd2e760
8,748
[ -1 ]
8,749
lisp-in-small-pieces.lisp
gregcman_lisp-in-small-pieces/interpreters/lisp-in-small-pieces.lisp
(in-package #:lisp) ;;;;evaluation -> dynamic, no closures (defun %eval (form env) (if (atom form) (if (symbolp form) (lookup form env) form) (case (car form) (quote (car (cdr form))) (if (if (truep (%eval (car (cdr form)) env)) (%eval (car (cdr (cdr form))) env) (%eval (car (cdr (cdr (cdr form)))) env))) (progn (evaluate-progn (cdr form) env)) (setq (update! (car (cdr form)) env (%eval (car (cdr (cdr form))) env))) (lambda (make-function (car (cdr form)) (cdr (cdr form)) env)) (otherwise (%apply (%eval (car form) env) (evlis (cdr form) env)))))) (defun evlis (params env) (if (consp params) (let ((arg0 (%eval (car params) env))) (cons arg0 (evlis (cdr params) env))) nil)) (defun evaluate-progn (body env) (if (consp body) (if (consp (cdr body)) (progn (%eval (car body) env) (evaluate-progn (cdr body) env)) (%eval (car body) env)) *empty-progn*)) (defun %apply (function args) (if (functionp function) (funcall function args) (error "not a function ~s" function))) (defun make-function (parameters body env) (lambda (values) (evaluate-progn body (extend env parameters values)))) ;;;;evaluation.d ;;;;closures are created with the "function" special form (defun %eval.d (form env) (if (atom form) (if (symbolp form) (lookup form env) form) (case (car form) (quote (car (cdr form))) (if (if (truep (%eval.d (car (cdr form)) env)) (%eval.d (car (cdr (cdr form))) env) (%eval.d (car (cdr (cdr (cdr form)))) env))) (progn (evaluate-progn.d (cdr form) env)) (setq (update! (car (cdr form)) env (%eval.d (car (cdr (cdr form))) env))) (function (let* ((f (car (cdr form))) (fun (make-function.d (car (cdr f)) (cdr (cdr f)) env))) (d.make-closure fun env))) (lambda (make-function.d (car (cdr form)) (cdr (cdr form)) env)) (otherwise (%apply.d (%eval.d (car form) env) (evlis (cdr form) env) env))))) (defun evlis.d (params env) (if (consp params) (let ((arg0 (%eval.d (car params) env))) (cons arg0 (evlis.d (cdr params) env))) nil)) (defun evaluate-progn.d (body env) (if (consp body) (if (consp (cdr body)) (progn (%eval.d (car body) env) (evaluate-progn.d (cdr body) env)) (%eval.d (car body) env)) *empty-progn*)) (defun %apply.d (function args env) (if (functionp function) (funcall function args env) (error "not a function ~s" function))) (defun make-function.d (parameters body definition-env) #+nil (declare (ignore definition-env)) (lambda (values current-env) (evaluate-progn body (extend current-env parameters values)))) (defun d.make-closure (fun env) (lambda (values current-env) #+nil (declare (ignore current-env)) (funcall fun values env))) ;;;;evaluation.s ;;;shallow binding is an implementation of dynamic binding ;;;where the symbol has a value cell that is changed and restored (defun setvar (var new) (setf (get var 'apval) new)) (defun getvar (var) (get var 'apval)) (defun for-each (fun sequence &rest sequences) (apply #'map nil fun sequence sequences)) (defun s.make-function (variables body env) #+nil (declare (ignore env)) (lambda (values current-env) (let ((old-bindings (mapcar (lambda (var val) (let ((old-value (getvar var))) (setvar var val) (cons var old-value))) variables values))) (let ((result (evaluate-progn body current-env))) (for-each (lambda (b) (setvar (car b) (cdr b))) old-bindings) result)))) (defun s.lookup (id env) #+nil (declare (ignore env)) (getvar id)) (defun s.update! (id env value) #+nil (declare (ignore env)) (setvar id value)) ;;;misc (defun %mapcar (function list) (if (consp list) (cons (funcall function (car list)) (%mapcar function (cdr list))) (quote ()))) (defparameter *global-environment* *initial-environment*) (defmacro definitial (name &optional (value nil value-supplied-p)) `(progn (push (cons (quote ,name) ,(if value-supplied-p value ''void)) *global-environment*))) (defmacro defprimitive (name value arity) `(definitial ,name (lambda (values) (if (= ,arity (length values)) (apply (function ,value) values) (error "Incorrect arity ~s" (list (quote ,name) values)))))) (definitial t t) (definitial f *the-false-value*) (definitial nil '()) (definitial foo) (definitial fib) (definitial bar) (definitial fact) (progn (defprimitive cons cons 2) (defprimitive car car 1) (defprimitive rplacd rplacd 2) (defprimitive eq eq 2)) (progn (defprimitive + + 2) (defprimitive < < 2)) ;;;type ":exit" to exit (defun chapter1-scheme () (labels ((toplevel () (let ((value (read))) (unless (eq :exit value) (print (%eval value *global-environment*)) (terpri) (toplevel))))) (toplevel))) ;#+nil ;#+nil (maphash (lambda (k v) (declare (ignore v)) (push (cons k (get k 'defun)) *global-environment*)) *function-namespace*) (maphash (lambda (k v) (declare (ignore v)) (eval `(definitial ,k ',(symbol-value k)))) *variable-namespace*) (setf (cdr (assoc '*global-environment* *global-environment*)) *global-environment*) (cl:defun test (form &optional (eval-nest 1)) (dotimes (times eval-nest) (setf form `(%eval (quote ,form) *global-environment*))) (print form) (eval form)) ;;;tests #+nil ((lambda (a b c) (+ c (a b))) (lambda (x) (+ x x)) 2 3)
5,772
Common Lisp
.lisp
233
20.506438
66
0.614172
gregcman/lisp-in-small-pieces
11
2
0
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
f5d389644dedb200010f7d11ab4b4478746a595f3bcedf85dd3d7a3ada900361
8,749
[ -1 ]
8,750
lisp-in-small-pieces.asd
gregcman_lisp-in-small-pieces/lisp-in-small-pieces.asd
(asdf:defsystem #:lisp-in-small-pieces :depends-on (#:utility #:scheme2common-lisp) :serial t :components ((:file "package2") (:file "other2") (:file "tester") (:file "chap6d") (:file "chap7d") #+nil (:file "package") #+nil (:module "interpreters" #+nil (:file "lisp-in-small-pieces") (:file "other") (:file "lisp-in-small-pieces2"))))
393
Common Lisp
.asd
18
17.666667
38
0.593583
gregcman/lisp-in-small-pieces
11
2
0
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
17dc344fb3d295a13576ecc6e94b716cc1ef4fc6eb5ec1e2e2233a07975eef8f
8,750
[ -1 ]
8,780
keybindings.lisp
szos_CLFM/keybindings.lisp
(in-package :clfm-2) (make-command-table 'clfm-control-x :errorp nil) (add-keystroke-to-command-table 'clfm '(#\x :control) :menu 'clfm-control-x :errorp nil) (add-keystroke-to-command-table 'clfm-control-x '(#\c :control) :command '(com-exit) :errorp nil) ;; (clim:add-keystroke-to-command-table 'clfm-control-x) ;;; this doesnt work, but it should.... hmmmmmm....
382
Common Lisp
.lisp
9
39.666667
75
0.696477
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
ecf5feaae995d47604a786bfbc397363f2a7dd6887f86ed5591fed2d69df25f4
8,780
[ -1 ]
8,781
package.lisp
szos_CLFM/package.lisp
;;;; package.lisp (defpackage #:clfm-2 (:use #:clim #:clim-lisp #:clim-tab-layout #:clim-extensions) (:export "APP-MAIN"))
128
Common Lisp
.lisp
4
29.75
63
0.658537
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
e0d2277e0a919b04620637fad0eefb89acc0a98e9bcb6be3b135457ad42986f2
8,781
[ -1 ]
8,782
dialog.lisp
szos_CLFM/dialog.lisp
(in-package :clfm-2) (define-application-frame clfm-notify-user-frame () ((message-string :initarg :message-string) (message-body :initarg :message-body) (exit-boxes :initarg :exit-boxes) (title :initarg :title) (style :initarg :style) (text-style :initarg :text-style) (width :initarg :width) (return-value :initarg nil :initform :abort)) (:pane (clfm-notify-user-dialog *application-frame*))) (defun clfm-notify-generate-exit-box-buttons (specs) (mapcar (lambda (spec) (destructuring-bind (action string &rest args) spec (spacing (:thickness 2) (apply #'make-pane 'push-button :label string :text-style (make-text-style :sans-serif :roman :small) ; XXX :activate-callback (lambda (gadget) (declare (ignore gadget)) ;; This is fboundp business is weird, and only implied by a ;; random message on the old CLIM list. Does the user function ;; take arguments? (when (or (typep action 'function) (fboundp action)) (funcall action)) (setf (slot-value *application-frame* 'return-value) action) ;; This doesn't work: #+NIL (when (eql action :abort) (and (find-restart 'abort) (invoke-restart 'abort))) (frame-exit *application-frame*)) args)))) specs)) (defun clfm-notify-user-dialog (frame) (with-slots (message-string message-body exit-boxes text-style width) frame (vertically () (spacing (:thickness 6) (make-pane 'label-pane :label (or message-string "I'm speechless.") :text-style text-style)) (spacing (:thickness 6) (make-pane 'application-pane :display-function (or (and message-body (eval `(lambda (frame pane) (declare (ignore frame)) ,message-body))) (lambda (frame pane) (declare (ignore frame) (ignore pane)))) :width width)) (spacing (:thickness 4) (make-pane 'hbox-pane :contents (cons '+fill+ (clfm-notify-generate-exit-box-buttons exit-boxes))))))) (defun clfm-notify-user-frame-manager (frame-manager &key frame associated-window message-body message-string width (title "") documentation (exit-boxes '((:exit "OK"))) ;; The 'name' arg is in the spec but absent from the Lispworks ;; manual, and I can't imagine what it would do differently ;; than 'title'. name style (text-style (make-text-style :sans-serif :roman :small))) (declare (ignore associated-window documentation)) (let ((frame (make-application-frame 'clfm-notify-user-frame :calling-frame frame :pretty-name title :message-string message-string :message-body message-body :frame-manager frame-manager :exit-boxes exit-boxes :title (or name title) :style style :text-style text-style :width width))) (run-frame-top-level frame) (slot-value frame 'return-value))) (defparameter *clfm-notify-pass-to-notification* nil) (defmacro clfm-notify ((frame message (&rest args-to-pass) &rest args) &body message-body) `(progn (setf *clfm-notify-pass-to-notification* `(,,@(loop for arg in args-to-pass collect arg))) (apply #'clfm-notify-user-frame-manager (if ,frame (frame-manager ,frame) (find-frame-manager)) :message-string ,message :message-body `(let ,(loop for arg in ',args-to-pass for v in *clfm-notify-pass-to-notification* collect `(,arg (handler-case ,v (t () ',v)))) ,@',message-body) :frame ,frame ',args)))
3,886
Common Lisp
.lisp
100
29.92
93
0.601113
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
b2a71b8fe025fd81732e365ba67bddc12be24572e56952eda809137ae3513388
8,782
[ -1 ]
8,783
chdir.lisp
szos_CLFM/chdir.lisp
(in-package :clfm-2) (defparameter *passwd-test* nil) (define-clfm-command (com-change-directory) ((directory string)) (handler-case (when (uiop:directory-exists-p directory) (uiop:chdir directory)) (sb-posix:syscall-error (err) (case (notify-user *application-frame* (let ((errno (sb-posix:syscall-errno err))) (cond ((= errno 13) "You don't have permission to access this directory To access this directory CLFM needs to be running as root To relaunch CLFM please ensure it is in your $PATH") (t (format nil "SB-POSIX Error Code: ~a" errno)))) :title "CLFM Error" :name "CLFM Error" :documentation "CLFM Error" :text-style (make-text-style "ETBembo" "BoldLF" 18) :exit-boxes '((t "OK") (:sudo "Relaunch as root"))) ((:sudo) (and (notify-user *application-frame* "WARNING: CLFM will now be running with root privilidges. This is not safe, and should be avoided. If you continue, type your password when presented with the blank window and use M-RET (meta + return or Alt + return) to submit it" :exit-boxes '((t "CONTINUE") (nil "ABORT")) :text-style (make-text-style "ETBembo" "BoldLF" 18)) (let (passwd (stream (frame-standard-input *application-frame*))) (accepting-values (stream :own-window t :initially-select-query-identifier 'password) (formatting-table (stream) (formatting-column (stream) (formatting-cell (stream) (setf passwd (accept 'password ;; 'string :prompt "sudo password" :stream stream :query-identifier 'password)))))) (uiop:launch-program (format nil "echo \"~a\" | sudo -S clfm" passwd))))))))) (define-clfm-command (com-chdir-~/ :name "Go Home") () (com-change-directory-temper "~/"))
1,863
Common Lisp
.lisp
47
33.255319
81
0.644162
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
b07186fbeddebe24961fc76e9148b5cfdf1ac26ec01a238be54d7f3b50245a45
8,783
[ -1 ]
8,784
open-files.lisp
szos_CLFM/open-files.lisp
(in-package :clfm-2) (defun open-file (file) "Opens the provided file with the default application a la xdg-open" (check-type file string) (uiop:launch-program (format nil "xdg-open ~a" (escape-spaces file)))) (define-clfm-command (com-open-file) ((file string)) "This command opens a file after checking that it exists" (when (uiop:file-exists-p (escape-spaces file)) (open-file file))) (define-clfm-command (com-open-file-with) ((file string)) "Takes a file and prompts for a program to open it with" (let (program (stream (frame-standard-input *application-frame*)) ;; (x (framex )) ) (restart-case (progn (accepting-values (stream :own-window t :label "Enter Program" :initially-select-query-identifier 'program :resynchronize-every-pass t ;; :resize-frame t :height 150 :width 500) (formatting-table (stream) (formatting-column (stream) (formatting-cell (stream) (setf program (accept 'string :prompt "Program" :stream stream :query-identifier 'program)))))) (and program (uiop:launch-program (format nil "~a ~a" program (escape-spaces file))))) (abort () ()))))
1,194
Common Lisp
.lisp
34
30.411765
72
0.67474
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
8008087f2c24d996411043fb209edf7106ac8c4073e96f14b191cd652b62e625
8,784
[ -1 ]
8,785
command-utilities.lisp
szos_CLFM/command-utilities.lisp
(in-package :clfm-2) (defmacro accept-with-table ((stream) &body accept-statements) "this simple macro wraps every accept statement in a formatting table, column, and cell. " `(formatting-table (,stream) ,@(loop for item in accept-statements collect `(formatting-column (,stream) (formatting-cell (,stream) ,item))))) (defmacro make-popup ((stream label) &body body) `(restart-case (let ((stream ,stream)) (accepting-values (stream :own-window t :label ,label) ,@body (terpri stream) (terpri stream) (accept 'string :prompt "DUMMY INPUT DO NOT USE" :stream stream))) (abort () ()))) (defun file-or-directory-exists-p (item) (or (uiop:file-exists-p item) (uiop:directory-exists-p))) (defun escape-spaces (string) (coerce (loop for char in (coerce string 'list) if (char= #\space char) collect #\\ and collect #\space else collect char) 'string)) (defun test/escape-spaces (string) (coerce (loop for char in (coerce string 'list) if (char= #\space char) collect #\\ and collect #\space else collect char) 'string)) ;; (nlet churner ((charlist '(#\\ #\space #\\ )) ;; (counter 1)) ; count down ;; (cond ((not (char= #\\ (car charlist))) ;; counter) ;; (t ;; (if (= counter 0) ;; (churner (cdr charlist) 1) ;; (churner (cdr charlist) 0))))) ;; (defun spaces-escaped (string) ;; (nlet spaceloop ((s (coerce string 'list)) ;; (previous-chars '())) ;; (if (char= (car s) #\space) ;; (if (and (char= (car previous-chars) #\\) ;; (char= (cadr previous-chars #\\))) ;; )) ;; (cond ((char= (car s) #\\) ;; )))) (defun string-contains (string character) (let ((char (if (stringp character) (coerce character 'character) character))) (loop for c across string when (char= c char) do (return-from string-contains t)))) (define-clfm-command (com-run-shell-command :name "Run Shell Command") ((command string :prompt "/bin/sh -c")) (uiop:launch-program (format nil "/bin/sh -c ~a" command))) (define-gesture-name :exit-clfm :keyboard (#\q :control :meta)) (define-clfm-command (com-quit :name "Quit" :keystroke :exit-clfm) () (frame-exit *application-frame*)) (define-clfm-command (com-exit :name "Exit") () (frame-exit *application-frame*)) (define-clfm-command (com-display-help-window) () (let ((frame (make-application-frame 'clfm-help))) (run-frame-top-level frame))) (define-clfm-command (com-loadrc :name "Load Init File") () (handler-case (load "~/.clfm.d/init.lisp") (t () ()))) (define-clfm-command (com-show-marks) () (setf (frame-current-layout *application-frame*) 'default)) (define-clfm-command (com-hide-marks) () (setf (frame-current-layout *application-frame*) 'no-marks)) (define-clfm-command (com-toggle-hidden-files) () (setf *hide-files* (not *hide-files*)) (redisplay-frame-panes *application-frame* :force-p t))
2,958
Common Lisp
.lisp
81
33.271605
80
0.647552
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
b591b7937925673a33c93193d938f743d4a6b6466d9350e31c7c63306dd9da0f
8,785
[ -1 ]
8,786
create-file.lisp
szos_CLFM/create-file.lisp
(in-package :clfm-2) (defparameter *touch-file* nil) (define-clfm-command (com-touch) ((filename string)) (let ((file (if (string-contains filename "/") filename (concatenate 'string (namestring (uiop:getcwd)) filename)))) (open file :direction :probe :if-does-not-exist :create))) (define-clfm-command (com-new-file) () (restart-case (let (file (stream (frame-standard-input *application-frame*))) (accepting-values (stream :own-window t :label "Enter a new file name" :initially-select-query-identifier 'fileprompt) (formatting-table (stream) (formatting-column (stream) (formatting-cell (stream) (setf file (accept 'string :prompt "Filename" :stream stream :query-identifier 'fileprompt)))))) (and file (com-touch file))) (abort () ())))
829
Common Lisp
.lisp
23
31.217391
64
0.67207
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
6d9cb0cd7173a73d7d172032dfa15c54c06cb26b40dbab4327b5ea0b56ba56e2
8,786
[ -1 ]
8,787
help.lisp
szos_CLFM/help.lisp
(in-package :clfm-2) (define-application-frame clfm-help () () (:menu-bar clfm-help-window-menu-bar) (:panes (keybindings :application :display-function #'help-display-keybindings :width 600) (generic :application :display-function #'help-display-generic :width 600)) (:layouts (default generic) (keybindings keybindings))) (define-clfm-help-command (com-switch-to-generic-page) () (setf (frame-current-layout *application-frame*) 'default)) (define-clfm-help-command (com-switch-to-keybindings-page) () (setf (frame-current-layout *application-frame*) 'keybindings)) ;; (define-clfm-help-command (com-switch-to-opening-files) () ;; ) (make-command-table 'clfm-help-window-menu-bar :errorp nil :menu '(("General" :command com-switch-to-generic-page) ("Keybindings" :command com-switch-to-keybindings-page))) (defun help-display-keybindings (frame pane) (declare (ignore frame)) (slim:with-table (pane) (slim:row (slim:cell (format pane "Keybindings: "))) (slim:row (slim:cell (format pane " "))) (slim:row (slim:cell (format pane "M-RET")) (slim:cell (format pane "Submit Input"))))) (defun help-display-generic (frame pane) (declare (ignore frame)) (with-end-of-line-action (pane :wrap*) (with-etbembo (pane :bold) (format pane "This is the help page for CLFM. It should contain documentation on the usage and settings of CLFM")) (terpri pane) (terpri pane) (with-etbembo (pane) (format pane "CLFM stands for ") (with-etbembo (pane :italic) (format pane "Common Lisp File Manager")) (format pane ". It is primarily mouse driven, though it is planned to implement keybindings (and an init file where users can change them) to drive this application via the keyboard. "))))
1,822
Common Lisp
.lisp
45
36.222222
194
0.697569
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
8774bcb29dc4a1fdbc77c8c385ab78deb298ee98d0d17386fc32ae07542a2c77
8,787
[ -1 ]
8,788
delete.lisp
szos_CLFM/delete.lisp
(in-package :clfm-2) (defparameter *directory-deletion-validation-function* 'validate-directory) (defun validate-directory (directory) (uiop:directory-exists-p directory)) (defun %delete-directory (dir) (uiop:delete-directory-tree dir :validate *directory-deletion-validation-function*)) (defun delete-directory (directory) (let ((reter (clfm-notify (*application-frame* "IRREVERSIBLE OPERATION" nil :exit-boxes ((t "PROCEED") (nil "ABORT")) :width 400) (with-end-of-line-action (pane :wrap*) (with-etbembo (pane nil 18) (format pane "You are attempting to delete a file or directory. This operation is ") (with-etbembo (pane :bold 18) (format pane "IRREVERSIBLE")) (format pane ". Proceed with caution.")))))) (when reter (%delete-directory (pathname directory))))) (defun delete-item (item) (let ((reter (clfm-notify (*application-frame* "IRREVERSIBLE OPERATION" nil :exit-boxes ((t "PROCEED") (nil "ABORT")) :width 400) (with-end-of-line-action (pane :wrap*) (with-etbembo (pane nil 18) (format pane "You are attempting to delete a file or directory. This operation is ") (with-etbembo (pane :bold 18) (format pane "IRREVERSIBLE")) (format pane ". Proceed with caution.")))))) (when reter (cond ((uiop:directory-exists-p item) (%delete-directory (pathname item))) ((uiop:file-exists-p item) (delete-file item)))))) (define-clfm-command (com-delete) ((item string)) (cond ((uiop:directory-exists-p item) (delete-directory item)) ((uiop:file-exists-p item) (delete-item item))))
1,678
Common Lisp
.lisp
41
35.097561
91
0.662577
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
563fb68d609515d034c85ebe9760c197f237587a69b966efa2b2c9029768ef77
8,788
[ -1 ]
8,789
copy.lisp
szos_CLFM/copy.lisp
(in-package :clfm-2) (defun %copy-file (f1 f2) (with-open-file (infile f1 :direction :input :element-type '(unsigned-byte 8)) (with-open-file (outfile f2 :direction :output :element-type '(unsigned-byte 8) :if-exists :error) (when infile (loop for byte = (read-byte infile nil) while byte do (write-byte byte outfile)))))) (defun copy-file (&optional file new-file) (restart-case (let ((stream (frame-standard-input *application-frame*)) oldname newname) (accepting-values (stream :own-window t :label (or (and file (format nil "Copy ~a" file)) "Copy a file") :initially-select-query-identifier (or (and file 'newfile) 'file)) (accept-with-table (stream) (or (and file (setf oldname file)) (setf oldname (accept 'string :prompt "Filename" :stream stream :query-identifier 'file))) (or (and new-file (setf newname new-file)) (setf newname (accept 'string :prompt "Copy to" :stream stream :query-identifier 'newfile))))) (unless (member #\/ (coerce newname 'list)) (setf newname (concatenate 'string (namestring (uiop:getcwd)) newname))) (and oldname newname (%copy-file oldname newname))) (abort () ()))) (define-clfm-command (com-copy-file) ((file string) (copy-to string)) (copy-file file copy-to)) (define-clfm-command (com-copy-file-prompt) ((file string)) (copy-file file)) (defun %copy-directory-contents (from to) "copy the contents of from to to. This is a helper" (ensure-directories-exist to) (labels ((copier (tdir fdir list) (print fdir) (print list) (cond ((uiop:directory-exists-p (car list)) (let ((dirname (coerce (reverse (loop for c in (cdr (coerce (reverse (namestring (car list))) 'list)) while (not (char= c #\/)) collect c)) 'string))) (ensure-directories-exist (concatenate 'string (namestring tdir) dirname "/")) (copier (concatenate 'string (namestring tdir) dirname "/") (concatenate 'string (namestring fdir) dirname "/") (append (uiop:subdirectories (pathname (concatenate 'string (namestring fdir) dirname "/"))) (uiop:directory-files (pathname (concatenate 'string (namestring fdir) dirname "/"))))) (copier tdir fdir (cdr list)))) ((uiop:file-exists-p (car list)) (let ((cto (coerce (reverse (loop for c in (coerce (reverse (namestring (car list))) 'list) while (not (char= c #\/)) collect c)) 'string))) (%copy-file (car list) (concatenate 'string (namestring tdir) cto)) (copier tdir fdir (cdr list))))))) (copier to from (append (uiop:subdirectories (pathname from)) (uiop:directory-files (pathname from)))))) (defun copy-directory (old-dir new-dir) (let (ndir (n (cdr (reverse (coerce (namestring new-dir) 'list))))) (setf ndir (if (member #\/ n :test #'char=) ;; TODO: ;; if new-dir is an absolute path... no thats not what this does. ;; this checks if theres any other directories in the path... ;; so it would fail if we were in ~/docs/ and copying from ;; ~/docs/lisp to scheme/docs/new. This is not the behavior we ;; want, this needs to be reworked to allow relative paths with ;; subdirectories new-dir (concatenate 'string (namestring (uiop:getcwd)) (namestring new-dir)))) (ensure-directories-exist ndir) (%copy-directory-contents old-dir ndir))) (defun test/copy-directory (&optional old new) (restart-case (let ((stream (frame-standard-input *application-frame*)) oldname newname) (accepting-values (stream :own-window t :label (or (and old (format nil "Copy ~a" old)) "Copy a directory") :initially-select-query-identifier (or (and old 'newname) 'directory)) (accept-with-table (stream) (or (and old (setf oldname old)) (setf oldname (accept 'string :prompt "Directory" :stream stream :query-identifier 'directory))) (or (and new (setf newname new)) (setf newname (accept 'string :prompt "Copy to" :stream stream :query-identifier 'newname))))) (ensure-directories-exist newname) (%copy-directory-contents oldname newname)) (abort () ()))) (define-clfm-command (com-copy-directory) ((file string) (copy-to string)) (test/copy-directory file copy-to)) (define-clfm-command (com-copy-directory-prompt) ((file string)) (test/copy-directory file))
4,688
Common Lisp
.lisp
134
28.776119
74
0.629817
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
0781077347a04b8c369c9437f345062ad40554ed8d649bed3c5dd36c50f05911
8,789
[ -1 ]
8,790
create-directory.lisp
szos_CLFM/create-directory.lisp
(in-package :clfm-2) (defun %new-directory (&optional redo) (restart-case (let (dir (stream (frame-standard-input *application-frame*))) (accepting-values (stream :own-window t :label (or (and redo "That didnt appear to be a directory, please try again, and ensure theres a trailing “/”. ") "Enter a new directory name") :initially-select-query-identifier 'dirprompt) (formatting-table (stream) (formatting-column (stream) (formatting-cell (stream) (setf dir (accept 'string :prompt "Directory" :stream stream :query-identifier 'dirprompt)))))) (and dir (com-make-directory dir))) (abort () ()))) (define-clfm-command (com-new-dir) () (%new-directory)) (define-clfm-command (com-make-directory) ((dir 'string)) (let ((fd (coerce dir 'list)) (rd (reverse (coerce dir 'list)))) (if (char= #\/ (car rd)) (if (or (char= (car fd) #\/) (char= (car fd) #\~)) (ensure-directories-exist dir) (ensure-directories-exist (concatenate 'string (namestring (uiop:getcwd)) dir))) (%new-directory t))))
1,099
Common Lisp
.lisp
30
31.866667
119
0.649387
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
db23b40bfb00d13f6246da90fae7ada82c37b335e629ced669b07b055b16c657
8,790
[ -1 ]
8,791
commands-update.lisp
szos_CLFM/commands-update.lisp
(in-package :clfm-2) (defparameter *override-characters-as-string* '(("RET" . :return) ("SPC" . #\space) ("TAB" . #\tab) ("æ" . #\latin_small_letter_ae) ("ø" . #\LATIN_SMALL_LETTER_O_WITH_STROKE) ("å" . #\LATIN_SMALL_LETTER_A_WITH_RING_ABOVE) ("ł" . #\LATIN_SMALL_LETTER_L_WITH_STROKE))) (defun key-chord (chord-def) (let* ((elements (reverse (cl-ppcre:split "-" chord-def))) (char (pop elements))) (setf char (if (assoc char *override-characters-as-string* :test #'string-equal) (cdr (assoc char *override-characters-as-string* :test #'string-equal)) (coerce char 'character))) (cons char (remove-if #'not (loop for s in elements collect (cond ((string= s "S") (setf char (char-upcase char)) nil) ((string= s "C") :control) ((string= s "M") :Meta) ((string= s "s") :super) ((string= s "H") :Hyper))))))) (defun kbd (key-seq) "This function parses a string into a list of gestures. The string is split by spaces, and every one of these is parsed into a single gesture. the final character is the character, all others are modifiers, and hyphens are ignored. Modifier translation is as follows: C - :control, M - :meta, H - :hyper, s - :super. a capital S in the modifier position changes the character to a capital. " (let* ((str-seq (cl-ppcre:split " " key-seq)) (seq (loop for str in str-seq collect (let* ((charbag (reverse (coerce str 'list))) (char (pop charbag)) (mods (loop for c in charbag unless (char= c #\-) collect (cond ((char= c #\S) (setf char (char-upcase char)) nil) ((char= c #\C) :control) ((char= c #\M) :Meta) ((char= c #\s) :super) ((char= c #\H) :Hyper))))) (cons char (remove-if #'not mods)))))) seq)) (defun display-info (frame pane) (declare (ignore frame)) (labels ((looper (input &optional ac) (if input (progn (with-output-as-presentation (pane (format nil "~{~a~^/~}/" (append ac (list (car input)))) 'chdir-presentation) (format pane "~a/" (car input))) (looper (cdr input) (append ac (list (car input))))) (unless ac (with-output-as-presentation (pane "/" 'chdir-presentation) (format pane "/")))))) (with-etbembo (pane :bold) (format pane "Current Directory: ")) (with-etbembo (pane :italic-bold) (looper (cl-ppcre:split "/" (namestring (uiop:getcwd)))) (with-etbembo (pane) (format pane "[~a]" (car (reverse (cl-ppcre:split "/" (namestring (current-item)))))))))) (define-clfm-command (com-change-directory-temper) ((directory string)) (handler-case (when (uiop:directory-exists-p directory) (change-directory directory)) (sb-posix:syscall-error (err) (case (notify-user *application-frame* (let ((errno (sb-posix:syscall-errno err))) (cond ((= errno 13) "You don't have permission to access this directory To access this directory CLFM needs to be running as root To relaunch CLFM please ensure it is in your $PATH") (t (format nil "SB-POSIX Error Code: ~a" errno)))) :title "CLFM Error" :name "CLFM Error" :documentation "CLFM Error" :text-style (make-text-style "ETBembo" "BoldLF" 18) :exit-boxes '((t "OK") (:sudo "Relaunch as root"))) ((:sudo) (and (notify-user *application-frame* "WARNING: CLFM will now be running with root privilidges. This is not safe, and should be avoided. If you continue, type your password when presented with the blank window and use M-RET (meta + return or Alt + return) to submit it" :exit-boxes '((t "CONTINUE") (nil "ABORT")) :text-style (make-text-style "ETBembo" "BoldLF" 18)) (let (passwd (stream (frame-standard-input *application-frame*))) (accepting-values (stream :own-window t :initially-select-query-identifier 'password) (formatting-table (stream) (formatting-column (stream) (formatting-cell (stream) (setf passwd (accept 'password ;; 'string :prompt "sudo password" :stream stream :query-identifier 'password)))))) (uiop:launch-program (format nil "echo \"~a\" | sudo -S clfm" passwd))))))))) (define-clfm-command (com-add-mark) ((markl t)) (let ((mark (if (listp markl) (namestring (car markl)) markl))) (if (member mark *marks* :test #'string=) (setf *marks* (remove mark *marks* :test #'string=)) (setf *marks* (cons mark *marks*))))) (define-clfm-command (com-delete) ((thing t)) (let ((item (if (listp thing) (namestring (car thing)) thing))) (cond ((uiop:directory-exists-p item) (delete-directory item)) ((uiop:file-exists-p item) (delete-item item))))) (define-clfm-command (com-open) ((thing t)) (let ((item (if (listp thing) (namestring (car thing)) thing))) (cond ((uiop:directory-exists-p item) (com-change-directory-temper item)) ((uiop:file-exists-p item) (open-file (namestring item)))))) (define-clfm-command (com-open-with) ((thing t)) (let (program (item (if (listp thing) (namestring (car thing)) thing))) (cond ((uiop:file-exists-p item) (restart-case (progn (accepting-values (stream :own-window t :label "Enter Program" :initially-select-query-identifier 'program :resynchronize-every-pass t ;; :resize-frame t :height 150 :width 500) (formatting-table (stream) (formatting-column (stream) (formatting-cell (stream) (setf program (accept 'string :prompt "Program" :stream stream :query-identifier 'program)))))) (and program (uiop:launch-program (format nil "~a ~a" program (escape-spaces item))))) (abort () ()))) ))) (define-gesture-name :meta-click-left :pointer-button (:left :meta)) (define-gesture-name :meta-control :keyboard (:control :meta)) (define-gesture-name :prev-item :keyboard (#\p :control)) (define-gesture-name :mark-item :keyboard (#\m :control)) (define-presentation-type filesystem-presentation ()) (defun set-operation-order (&key (delete -1) (open 4) (open-with 3) (rename 2) (copy 1)) (define-presentation-to-command-translator up-selection (filesystem-presentation com-move-up clfm :gesture :control-p :documentation "Up one selection") (item) (list item)) (define-presentation-to-command-translator down-selection (filesystem-presentation com-move-down clfm :gesture :control-n :documentation "Down one selection") (item) (list item)) (define-presentation-to-command-translator filesystem-mark (filesystem-presentation com-add-mark clfm :gesture :meta-click-left :documentation "Mark") (item) (list item)) (define-presentation-to-command-translator filesystem-delete (filesystem-presentation com-delete clfm :gesture :select :documentation "Delete (PERMANENT)" :priority delete) (item) (list item)) (define-presentation-to-command-translator filesystem-open (filesystem-presentation com-open clfm :gesture :select :documentation "Open" :priority open) (item) (list item)) (define-presentation-to-command-translator filesystem-open-with (filesystem-presentation com-open-with clfm :gesture :select :documentation "Open With" :priority open-with :tester ((item) (uiop:file-exists-p (if (listp item) (namestring (car item)) item)))) (item) (list item)) (define-presentation-to-command-translator filesystem-rename (filesystem-presentation com-rename clfm :gesture :select :documentation "Rename" :priority rename) (item) (list item)) (define-presentation-to-command-translator filesystem-copy (filesystem-presentation com-copy clfm :gesture :select :documentation "Copy" :priority copy) (item) (list item))) (set-operation-order) (defun pane-scrolled-to-bottom-p (pane) (multiple-value-bind (x y) (transform-position (sheet-transformation pane) 0 0) (declare (ignore x)) (with-bounding-rectangle* (x1 y1 x2 y2) pane (declare (ignore x1 y1 x2)) (with-bounding-rectangle* (ax1 ay1 ax2 ay2) (sheet-parent pane) (declare (ignore ax1 ay1 ax2)) (<= (+ y y2) ay2))))) (defun scroll-pane-to-bottom (pane) (scroll-extent pane 0 (max 0 (- (bounding-rectangle-height pane) (bounding-rectangle-height (sheet-parent pane)))))) (defmacro with-pane-kept-scrolled-to-bottom ((pane-form) &body body) "Ensure that the pane in PANE-FORM has the same scroll state after BODY terminates as it had before: If the pane is scrolled to some position before the end, it is kept there. If the pane is at the bottom of the pane, the viewport is reset to the then-current bottom after BODY is finished." (let ((pane (gensym)) (bottom-p (gensym))) `(let* ((,pane ,pane-form) (,bottom-p (pane-scrolled-to-bottom-p ,pane))) (multiple-value-prog1 (progn ,@body) (when ,bottom-p (scroll-pane-to-bottom ,pane)))))) (let ((pre-selection-contents nil) (selected-item (let ((all (append (sort (uiop:subdirectories (uiop:getcwd)) #'path<) (sort (uiop:directory-files (uiop:getcwd)) #'path<)))) (if *hide-files* (car (remove-if #'hidden-pathname-p all)) (car all)))) (post-selection-contents (let ((all (append (sort (uiop:subdirectories (uiop:getcwd)) #'path<) (sort (uiop:directory-files (uiop:getcwd)) #'path<)))) (if *hide-files* (cdr (remove-if #'hidden-pathname-p all)) (cdr all))))) (defun current-item () selected-item) (defun add-current-selected-to-marks () (com-add-mark (namestring selected-item))) (defun enter-or-open-current-selection () (com-open selected-item)) (defun change-directory (directory) (uiop:chdir directory) (let ((contents (append (sort (uiop:subdirectories (uiop:getcwd)) #'path<) (sort (uiop:directory-files (uiop:getcwd)) #'path<)))) (setf pre-selection-contents nil selected-item (if *hide-files* (car (remove-if #'hidden-pathname-p contents)) (car contents)) post-selection-contents (if *hide-files* (cdr (remove-if #'hidden-pathname-p contents)) (cdr contents)))) (redisplay-frame-panes *application-frame* :force-p t)) (defun move-selection-up () (when pre-selection-contents (setf post-selection-contents (cons selected-item post-selection-contents)) (setf selected-item (pop pre-selection-contents)))) (defun move-selection-down () (when post-selection-contents (setf pre-selection-contents (cons selected-item pre-selection-contents)) (setf selected-item (pop post-selection-contents)) ;; (scroll-extent ()) )) (defun display-current-directory (frame pane) (declare (ignore frame)) (display-current-directory-worker pane pre-selection-contents selected-item post-selection-contents))) (defun display-current-directory-worker (pane pre-selection-contents selected-item post-selection-contents) (slim:with-table (pane) (labels ((display-item (path &optional current) (let ((stat (handler-case (osicat-posix:stat path) (t () nil)))) (with-output-as-presentation (pane (namestring path) 'filesystem-presentation :single-box t) (slim:row (slim:cell (if (member (namestring path) *marks* :test #'string-equal) (with-drawing-options (pane :ink +red+) (format pane "*")) (with-drawing-options (pane :ink +black+) (format pane " ")))) (with-drawing-options (pane :ink (if (member (namestring path) *marks* :test #'string=) (if current +purple+ +orange-red+) (if current +purple+ +black+))) (with-text-style (pane (make-text-style "ETBembo" (cond ((member (namestring path) *marks* :test #'string=) "DisplayItalicBold") ;; (current "SuperBoldOSF") (t "RomanLF")) 16)) (slim:cell (if (uiop:directory-exists-p path) (with-drawing-options (pane :ink (if (member (namestring path) *marks* :test #'string=) +orange-red+ +blue+)) (format pane "DIR")) (with-drawing-options (pane :ink (if (member (namestring path) *marks* :test #'string=) +orange-red+ +green4+)) (format pane "FILE")))) (slim:cell (format pane "~a" (file/directory-name (namestring path)))) (slim:cell (format pane "~a" (cdr (assoc (format nil "~a" (and stat (osicat-posix:stat-uid stat))) *uid-username* :test #'string-equal)))) ) (slim:cell (format pane "~a" (and stat (permissions-as-string path)))) ;; (let ((strs (permissions-as-list path))) ;; (loop for s in strs ;; do (slim:cell (format pane s)))) )))) )) (when pre-selection-contents (loop for path in (reverse pre-selection-contents) unless (and *hide-files* (hidden-pathname-p path)) do (display-item path))) (when selected-item (display-item selected-item t)) (when post-selection-contents (loop for path in post-selection-contents unless (and *hide-files* (hidden-pathname-p path)) do (display-item path))) ;; (when (< (length post-selection-contents) (length pre-selection-contents)) ;; (scroll-pane-to-bottom pane)) ))) (define-gesture-name :next-item :keyboard (#\n :control)) (define-gesture-name :prev-item :keyboard (#\p :control)) (define-gesture-name :mark-item :keyboard (#\space :control)) (define-gesture-name :up-directory :keyboard (#\p :meta)) ;; (define-gesture-name :open :keyboard (#\o :control)) (define-gesture-name :open :keyboard (:return :control)) (define-gesture-name :test :keyboard (#\t :control :meta) ;; (:return :control) ) ;; broken (define-gesture-name :carriage-return :keyboard ( )) (define-gesture-name :carriage-return :keyboard (#\m :control)) (define-clfm-command (com-move-up :name "Move Up Selection" :keystroke :prev-item) () (move-selection-up)) (define-clfm-command (com-move-down :name "Move Down Selection" :keystroke :next-item) () (move-selection-down)) (define-clfm-command (com-keyboard-mark :keystroke :mark-item) () (add-current-selected-to-marks)) (define-clfm-command (com-up-directory :keystroke :up-directory) () (change-directory (concatenate 'string (namestring (uiop:getcwd)) "../"))) (define-clfm-command (com-keyboard-open :keystroke :open) () (enter-or-open-current-selection)) ;; (define-clfm-command (com-test-test-keyboard :keystroke ;; (#\k :control) ;; (:test-cc :test-mc)) () ;; (enter-or-open-current-selection)) (define-clfm-command (com-keyboard-open :keystroke (#\i :shift :super)) () (enter-or-open-current-selection)) ;; (add-input-editor-command ;; ) (define-gesture-name :test-cc :keyboard (#\c :control)) (define-gesture-name :test-mc :keyboard (#\c :meta)) ;; ok this is broken... somehow... IDK why... (defmacro define-main-keybinding (gesture &body body) "Takes a gesture by name or by specification, and defines a command which runs body. If gesture is a string, it MUST be a single key chord. " (let ((command (intern (symbol-name (gensym "COM-ANONYMOUS-KEYBINDING-")))) (key-seq (if (stringp gesture) (key-chord gesture) gesture))) `(define-clfm-command (,command :keystroke ,key-seq) () ,@body))) ;; (define-main-keybinding "C-ł" ;; ;; "M- " ;; (#\j :meta) ;; (add-current-selected-to-marks)) ;; (define-main-keybinding (#\latin_small_letter_ae :control) ;; (add-current-selected-to-marks)) ;; (define-main-keybinding (:return :control) ;; (enter-or-open-current-selection))
18,119
Common Lisp
.lisp
427
32.103044
107
0.571891
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
29a6ae5760eebb1e6cb1da5cd1532e9ad0abac033708a653731854c13416e694
8,791
[ -1 ]
8,792
mark-and-operate.lisp
szos_CLFM/mark-and-operate.lisp
(in-package :clfm-2) (defparameter *marks* nil) (define-clfm-command (com-add-mark) ((mark string)) (if (member mark *marks* :test #'string=) (setf *marks* (remove mark *marks* :test #'string=)) (setf *marks* (cons mark *marks*)))) (define-clfm-command (com-add-mark) ((markl t)) (let ((mark (if (listp markl) (namestring (car markl)) markl))) (if (member mark *marks* :test #'string=) (setf *marks* (remove mark *marks* :test #'string=)) (setf *marks* (cons mark *marks*))))) (defun operate-on-marks (operation) (let* ((op (symbol-name operation)) (function (if (assoc operation *mark-operation-commands*) (cdr (assoc operation *mark-operation-commands*)) (let ((reter (clfm-notify (*application-frame* "Unknown Operation" (op) :exit-boxes ((t "Retry") (nil "OK")) :width 300 :text-style ("ETBembo" "BoldLF" 18)) (with-end-of-line-action (pane :wrap*) (with-etbembo (pane nil 18) (format pane "The operation \"~a\" is unknown" op)))))) (when reter (com-operate-on-marks)))))) (when function (loop for thing in *marks* do (handler-case (funcall function thing nil) (t (err) (let ((ret (notify-user *application-frame* (format nil "Error '~a'~%was encountered while running~%function '~a'~%with argument '~a'" err function thing) :exit-boxes '((nil "Continue") (:destroy-marks "Abort") (t "Abort Preserving Marks")) :title "CLFM Mark Error"))) (when ret (when (eq :destroy-marks ret) (setf *marks* nil)) (return-from operate-on-marks)))))) (funcall function nil t) (setf *marks* nil)))) (define-clfm-command (com-operate-on-marks) () ;; ((function 'symbol :prompt "Function")) (let (fun (stream (frame-standard-input *application-frame*))) (accepting-values (stream :own-window t :initially-select-query-identifier 'function) (formatting-table (stream) (formatting-column (stream) (formatting-cell (stream) (setf fun (accept 'symbol :prompt "Operate Using Function" :stream stream :query-identifier 'function)))))) (operate-on-marks fun) ;; (if (assoc fun *mark-operation-commands*) ;; (operate-on-marks (cdr (assoc fun *mark-operation-commands*))) ;; (let ((reter ;; (clfm-notify (*application-frame* "Unknown Operation" (fun) ;; :exit-boxes ((t "Retry") ;; (nil "OK")) ;; :width 300 ;; :text-style ;; ("ETBembo" "BoldLF" 18)) ;; (with-end-of-line-action (pane :wrap*) ;; (with-etbembo (pane nil 18) ;; (format pane "The operation \"~a\" is unknown" fun)))))) ;; (when reter ;; (com-operate-on-marks)))) )) ;;; IDEA: ;;; Make a «defcommand» type thing and an accompanying accept type to use which ;;; searches through all commands and then calls one that matches, searching as ;;; strings! - this would mean that in the command com-operate-on-marks, we first ;;; accept a string or symbol, and then search in our faux-database for it, and ;;; call the associated function! (defparameter *mark-operation-commands* nil) (defun replace-alist-entry (alist key value &optional unintern-value) (alexandria:when-let ((k (assoc key alist))) (when unintern-value (unintern (cdr k))) (setf (cdr k) value))) (defmacro define-operation (name args &body body) "This macro defines a function and stores it in an alist. these functions can be used to operate on marks. Each function must take two arguments - the item to be operated upon, and a finished argument. This function will be called on every mark with with the finished argument being nil. When no marks remain it will be called one last time with the item being nil and the finished argument being t. The function that is defined is named after a gensym and cannot be called normally. When redefining a command the old gensym is uninterned to keep the function namespace clean." (let ((n (gensym (symbol-name name)))) `(progn (unless (replace-alist-entry *mark-operation-commands* ',name ',n t) (setf *mark-operation-commands* (cons (cons ',name ',n) *mark-operation-commands*))) (defun ,n ,args ,@body)))) (define-operation delete (item finished) (declare (ignore finished)) (when item (let ((reter (clfm-notify (*application-frame* "IRREVERSIBLE OPERATION" nil :exit-boxes ((t "PROCEED") (nil "ABORT")) :width 400) (with-end-of-line-action (pane :wrap*) (with-etbembo (pane nil 18) (format pane "You are attempting to delete a file or directory. This operation is ") (with-etbembo (pane :bold 18) (format pane "IRREVERSIBLE")) (format pane ". Proceed with caution.")))))) (when reter (cond ((uiop:directory-exists-p item) (com-delete-directory item)) ((uiop:file-exists-p item) (com-rm-file item)) (t (clfm-notify (*application-frame* "Not a file or directory" (item) :width 400) (with-etbembo (pane :italic 18) (format pane "~a~%is not an existing file or directory, and cannot be deleted" item))))))))) (define-operation display (item finished) (declare (ignore finished)) (when item (let ((message "The item is: ")) (test/clfm-notify (*application-frame* message (item) :width 500) (with-end-of-line-action (pane :wrap*) (with-etbembo (pane) (format pane "~a" item))))))) (let (copy-to) (define-operation copy (item finished) (when finished (setf copy-to nil)) (when item (unless copy-to (let ((stream (frame-standard-input *application-frame*))) (accepting-values (stream :own-window t :initially-select-query-identifier 'copy) (formatting-table (stream) (formatting-column (stream) (formatting-cell (stream) (setf copy-to (accept 'string :prompt "Copy To" :stream stream :query-identifier 'copy)))))))) (ensure-directories-exist copy-to) (if (uiop:file-exists-p item) (%%copy-file item (concatenate 'string copy-to (coerce (reverse (loop for c across (reverse item) while (not (char= c #\/)) collect c)) 'string))) (%copy-directory-contents item copy-to))))) ;; (let (move-to) ;; (define-operation move (item finished) ;; (when finished (setf move-to nil)) ;; (when item ;; (unless move-to ;; (let ((stream (frame-standard-input *application-frame*))) ;; (accepting-values (stream :own-window t ;; :initially-select-query-identifier 'move) ;; (formatting-table (stream) ;; (formatting-column (stream) ;; (formatting-cell (stream) ;; (setf move-to ;; (accept 'string ;; :prompt "Move To" ;; :stream stream ;; :query-identifier 'move)))))))) ;; (com-move-to )) ;; ))
7,044
Common Lisp
.lisp
183
33.234973
118
0.630972
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
0286688178b887f12de476be33f741715cb68b265226ebbe1b412b9f9ba8b405
8,792
[ -1 ]
8,793
rename-file-directory.lisp
szos_CLFM/rename-file-directory.lisp
(in-package :clfm-2) (defun %rename-file-directory (&optional old-name new-name) (restart-case (let ((stream (frame-standard-input *application-frame*)) oldname newname) (accepting-values (stream :own-window t :label (or (and old-name (format nil "Rename ~a" old-name)) "Rename a file") :initially-select-query-identifier (or (and old-name 'newfile) 'file)) (formatting-table (stream) (or (and old-name (setf oldname old-name)) (formatting-row (stream) (formatting-column (stream) (formatting-cell (stream) (setf oldname (accept 'string :prompt "Filename " :stream stream :query-identifier 'file)))))) (or (and new-name (setf newname new-name)) (formatting-row (stream) (formatting-column (stream) (formatting-cell (stream) (setf newname (accept 'string :prompt "Rename to" :stream stream :query-identifier 'newfile)))))))) (and oldname newname (rename-file oldname newname))) (abort () ()))) (define-clfm-command (com-rename) ((thing string) (newname string)) (rename-file thing newname)) (define-clfm-command (com-rename-this) ((thing string)) (%rename-file-directory thing)) (define-clfm-command (com-rename-this) ((thing t)) (%rename-file-directory thing)) (define-clfm-command (com-rename-prompt) () (%rename-file-directory))
1,423
Common Lisp
.lisp
39
30.615385
67
0.652395
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
8f830b31f300700573dc194442d85ea7d91404935587d5de9261a90796bde796
8,793
[ -1 ]
8,794
password.lisp
szos_CLFM/password.lisp
(in-package :clfm-2) (define-presentation-type password () :inherit-from '((string) :description "Password") :description "password") (define-presentation-method present (password (type password) stream (view textual-view) &key acceptably) (when acceptably (error "Not acceptably")) (write-string (make-string (length password) :initial-element #\*) stream)) (define-presentation-method accept ((type password) stream view ;; (view textual-view) &key) (let* ((s (stream-scan-pointer stream)) (p (with-output-recording-options (stream :draw nil :record nil) (read-token stream)))) (presentation-replace-input stream p 'password view :buffer-start s) (return-from accept p))) ;; (define-presentation-method accept ((type password) stream view ;; (view textual-view) ;; &key) ;; (let* ((s (stream-scan-pointer stream)) ;; (p (clim:with-output-recording-options (stream :draw t :record nil) ;; (read-token stream)))) ;; (presentation-replace-input stream p 'password view ;; :buffer-start s) ;; (return-from accept p)))
1,120
Common Lisp
.lisp
26
39.346154
89
0.677982
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
deb2e1a7aa8efd7fd316f95cd78d383ab59661f249ab78c6912df27a1b53025a
8,794
[ -1 ]
8,795
move-file-directory.lisp
szos_CLFM/move-file-directory.lisp
(in-package :clfm-2) #+NIL (defun move-item (item new-item) (unless (file-or-directory-exists-p new-item) (let ((typeof-item (or (and (uiop:directory-exists-p item) :directory) (and (uiop:file-exists-p item) :file) :nonexistant)) (typeof-new-item (or (and (uiop:directory-exists-p item) :directory) (and (uiop:file-exists-p item) :file) :nonexistant))) (cond ((eq typeof-item :nonexistant) nil) ((eq typeof-item :directory) (when (eq typeof-new-item :nonexistant) )) ((eq typeof-item :file)))) (let ((r (reverse (coerce new-file 'list))) newpath) (cond ((uiop:directory-exists-p item) (if (and (char= (car r) #\/) ; if it ends in a / and contains other /s (string-contains (coerce (cdr r) 'string) #\/)) ;; then move to another directory name (rename-file item ))) ((uiop:file-exists-p item) ) ) (if (char= (car r) #\/) (if (string-contains (coerce (cdr r) 'string) #\/) ;; then we want to move it to some other directory nil ;; else we want to move it to something else in the current directory (setf newpath (concatenate 'string (namestring (uiop:getcwd)) new-file)))))) (if (string-contains new-file ))) ;; ok.. what we want to do here, is to immitate mv... we could just shell out, ;; but that isnt optimal... ;; (define-clfm-command )
1,409
Common Lisp
.lisp
36
33.444444
78
0.619708
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
12d16178ea0f873b14e4e429e9994ae723c22b32e76635268c2c6a4eb5c2e2f7
8,795
[ -1 ]
8,796
commands.lisp
szos_CLFM/commands.lisp
(in-package :clfm-2) (define-gesture-name :meta-click-left :pointer-button (:left :meta)) (define-gesture-name :meta-control :keyboard (:control :meta)) (define-presentation-type fopen-presentation ()) (defun set-file-command-order (&key (delete -1) (open 4) (open-with 3) (rename 2) (copy 1) ;; (mark 0) ) "the higher the number, the higher on the list it will be" ;; (define-presentation-to-command-translator fshift-click ;; (fopen-presentation com-mark-between-items)) (define-presentation-to-command-translator fmark (fopen-presentation com-add-mark clfm ;; :gesture :select :gesture :meta-click-left :documentation "Mark File" ;; :priority mark ) (file) (list file)) (define-presentation-to-command-translator fdelete (fopen-presentation com-rm-file clfm :gesture :select :documentation "Delete File (PERMANENT)" :priority delete) (f) (list f)) (define-presentation-to-command-translator fopen (fopen-presentation com-open-file clfm :gesture :select :documentation "Open File" :priority open) (f) (list f)) (define-presentation-to-command-translator fopen-with (fopen-presentation com-open-file-with clfm :gesture :select :documentation "Open File With" :priority open-with) (f) (list f)) (define-presentation-to-command-translator frename (fopen-presentation com-rename-this clfm :gesture :select :documentation "Rename this" :priority rename) (f) (list f)) (define-presentation-to-command-translator fcopy (fopen-presentation com-copy-file-prompt clfm :gesture :select :documentation "Copy this file" :priority copy) (f) (list f))) (set-file-command-order) (define-presentation-type chdir-presentation ()) ;; (define-gesture-name :double-click :pointer-button (:left :double)) (defun set-directory-command-order (&key (change-directory 3) (delete -1) ;; (mark 2) (copy 1)) (define-presentation-to-command-translator dcopy (chdir-presentation com-copy-directory-prompt clfm :gesture :select :documentation "Copy Directory" :priority copy) (dir) (list dir)) (define-presentation-to-command-translator chdir (chdir-presentation com-change-directory-temper clfm :gesture :select ;; :gesture :double-click :Documentation "Change to Directory" :priority change-directory ) (dir) (list dir)) (define-presentation-to-command-translator dir-delete (chdir-presentation com-delete-directory clfm :gesture :select :documentation "Delete Directory (PERMANENT)" :priority delete) (dir) (list dir)) (define-presentation-to-command-translator dmark (chdir-presentation com-add-mark clfm ;; :gesture :select :gesture :meta-click-left :documentation "Mark Directory" ;; :priority mark ) (file) (list file))) (set-directory-command-order) (defun file-prefer-marks () (set-file-command-order :mark 5)) (defun directory-prefer-marks () (set-directory-command-order :mark 3)) ;; (define-drag-and-drop-translator drag-and-drop-directory ;; (chdir-presentation ;; chdir-presentation dcopy clfm ;; :documentation "drag and drop file" ;; :gesture )) (make-command-table 'clfm-menu-bar :errorp nil :menu '(("Quit" :command com-quit) ("File" :menu clfm-file) ("Operate/Marks" :menu clfm-operation-menu) ("View" :menu clfm-view-menu) ("Help" :menu clfm-help-menu))) (make-command-table 'clfm-file :errorp nil :menu '(("New File" :command com-new-file) ("New Directory" :command com-new-dir) ("Go Home" :command com-chdir-~/) ("Rename…" :command com-rename-prompt) ("Load Init File" :command com-loadrc))) (make-command-table 'clfm-operation-menu :errorp nil :menu '(("Select Operation" :command com-operate-on-marks))) (make-command-table 'clfm-view-menu :errorp nil :menu '(("Marks" :menu clfm-view-marks-menu) ("Display Hidden Files" :command com-toggle-hidden-files))) (make-command-table 'clfm-view-marks-menu :errorp nil :menu '(("Show Marks" :command com-show-marks) ("Hide Marks" :command com-hide-marks))) (make-command-table 'clfm-help-menu :errorp nil :menu '(("Help Window" :command com-display-help-window) ("test" :command com-move-down :keystroke (:n :control))))
4,685
Common Lisp
.lisp
140
27.442857
70
0.655393
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
d1444567d9377b650eda1f3dca7d4a20a69a0de890fc2e3e533fe4e4e07ebf6c
8,796
[ -1 ]
8,797
init.lisp
szos_CLFM/init.lisp
;;; This is an example init file, which has some basic configuration stuff. (in-package :clfm-2) (define-operation notify-me (item finished) (declare (ignore finished)) (when item (clfm-notify (*application-frame* "A Notification" (item)) (format pane "This is a notificaton of an item were operating on.") (print item pane)))) (file-prefer-marks)
371
Common Lisp
.lisp
9
37.666667
75
0.718663
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
e6536c439544080c4679223add80dae1bceac70cb5c13211b93c6e95b6a759c9
8,797
[ -1 ]
8,798
clfm-2.asd
szos_CLFM/clfm-2.asd
;;;; clfm-2.asd (asdf:defsystem #:clfm-2 :description "Describe clfm-2 here" :author "Your Name <[email protected]>" :license "Specify license here" :version "0.0.1" :serial t :depends-on (#:osicat #:alexandria #:mcclim #:slim) :components ((:file "package") (:file "clfm-2") (:file "dialog") (:file "help") (:file "password") (:file "command-utilities") (:file "open-files") (:file "chdir") (:file "delete") (:file "create-file") (:file "create-directory") (:file "rename-file-directory") (:file "copy") (:file "move-file-directory") (:file "mark-and-operate") (:file "commands") (:file "commands-update") (:file "keybindings")))
818
Common Lisp
.asd
29
20.931034
45
0.536802
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
5118b13c354dfb54a595f82f097f0be54af43bf2feea73fb4733bf965efcaf8c
8,798
[ -1 ]
8,815
make-executable.sh
szos_CLFM/make-executable.sh
#!/bin/sh LISP=$(which sbcl) exit="$?" if [ ! "$exit" -eq 0 ]; then /bin/echo -e "\e[1;31mSBCL not installed, exiting\e[0m" exit 1 else /bin/echo -e "\e[1;32mSBCL is installed, proceeding\e[0m" fi sbcl --eval "(progn (handler-case (in-package :ql) (PACKAGE-DOES-NOT-EXIST () (exit :code 1))) (sb-ext:exit :code 0))" > /dev/null 2>&1 exit="$?" if [ ! "$exit" -eq 0 ]; then /bin/echo -e "\e[1;31mQuicklisp not installed, exiting\e[0m" exit 1 else /bin/echo -e "\e[1;32mQuicklisp is installed, proceeding\e[0m" fi sbcl --eval "(push #p\"./\" asdf:*central-registry*)" --eval "(ql:quickload :clfm-2)" --eval "(clfm-2::make-executable)" exit="$?" if [ ! "$exit" -eq 0 ]; then /bin/echo -e "\e[1;31m:CLFM not found, aborting\e[0m" exit 1 fi
776
Common Lisp
.l
23
30.956522
135
0.625
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
65a7490718c702cde045042c24911cd5f2936872430b965c7051cac89b58bc2c
8,815
[ -1 ]
8,820
et-book-display-italic-bold-old-style-figures.ttf
szos_CLFM/fonts/et-book-display-italic-bold-old-style-figures.ttf
 ÄPFFTMɸ6<˜åGDEF'˜d&OS/2WâXVcmap&¿ì\gaspˇˇ˜\glyfO¢˙z HËhead ëx?‹6hheaqı$hmtxıÂ˚∞¨locaa√ôÃpÿmaxp4ˆ8 name&˙®-ÒP˘postÈyí#ıLA>»ó_<ı ËœD*~⁄ê Aˇ@˛·[yy˛·ZUˇ@˛”[ÎÎÛ@ìêäºå亇1Äß@JPfEd! ˚ ˇ8ZyM˛)H®ó®E_–Mflé2Uˇ«-Qß6%L*Ù:]ˇÂÏ<öF⁄!Áˇˇ¸@Ï  V’. 9*%)_)ß7ß7ß7ìO•UÒˇ’¬ Uˇ˛“a'=Aˇ†éˇOó Øˇ˘Q oXpˇÏZ> ˇ˛A ≤D 9ª1∏+¸ˇÛªdΡˇ3(fl83ˇ∆≤˝ˇÊSô‹%€6J#˛1®&WˇJ ˇ≠101ˇm51fi+( &˘ˇæÊ4| 8;#>“&û4ÒˇÎ$ì0◊ì!'L˛)%Ê!ßM˝◊Áˇ S_R UæLß6?SLìtß6>D>LSµ»ˇË)uS>{ aæAE{E{ELì%Òˇ’Òˇ’Òˇ’Òˇ’Òˇ’Òˇ’ˇÊ““““††††AQ oXoXoXoXoX‰]bn 9 9 9 9ªdy,˙ˇB‹%‹%‹%‹%‹%‹%É%h®&®&®&®&33#3‰.( & & & & &‰Fœ#>#>#>#>ÒˇÎ˙ˇπÒˇÎ3ç U]Å!X | ªd¯ˇˇ$SQSÅSuS±SéSˇ˘SFSy9ˇŸi96W)¡})C˝–˝ù˝(ÁN¸ˇMhr˘z˘.⁄ˇN·ˇMøˇ@œ‰ßE¸ˇM¯ˇgÁˇQ⁄ˇN·ˇM 8 ~¨¥ˇ1BSax~í«›º    " & 0 : D ¨!""˚ˇ˝ˇˇ †Æ∂1AR`x}í∆ÿº    & 0 9 D ¨!""˚ˇ˝ˇˇˇ„ˇ¬ˇ¡ˇ¿ˇèˇÄˇqˇeˇOˇK˛n˛˝Ù˝‡¿‡Ω‡º‡ª‡∏‡Ø‡ß‡û‡7fl¬fi”Ê  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`aÑÖáâëñú°†¢§£•ß©®™´≠¨ÆØ±≥≤¥∂µ∫πªº€qdei›vüok‰ujÜòrglz¶∏cnm{fibÄÉï√ƒ”‘ÿŸ’÷∑ø«‚„‡·ÁË‹w◊⁄flÇäÅãàçéèåìîíöõô¿ –pÃÕŒx—œÀNñʃV^ä≤ÊÙ\é∞Ó*pÙl¿z¯ ` Œ 8 z » Ë , ñ j ‰ ~ ‹N‘tNÆ ⁄p8  ¶&–j †Ó∏RæÏ2TÜÆöÇÚú L ‹!D!∫"X"†#b$$X%%Ç%‚&f&¬'@'®(H)) *§++2+™+¸+¸,D,∫-p-¯/:/^/‰0"0∞11J1d22>2l2û33®3‹4"4@4~4“55L6788î9 9»:b; ;º<Z=Z=Ï>Ë@A B"BòCCúDD EîE¯FpF⁄GNGºGÏHZI IŒJÇKJL*L˛M¬NLNËOÇPPÿQdQR|SS∏TXU UÄU¸VxWWÜXàXˆYtYÚZÄ[ [^[÷\v],]‘^Ü_l`aabbbúcòdd¿eVf8fºg≤g‰hh8hNhth§hfih˛iÜi†i¿i‚jj(jpj¨jÓk<ll(l^lÿmŒn¬n‹o8pppÍqårstHˇ„9•1&'&=>76;2#"'&547676329|  <  w É ˛@ ø  ˝ò  ó\ı•/+?67632+?>7632ı  E & ∂ D  0q "ï î41    Eñ ó-$ &ˇ◊â«;?%#+?#+?+=;7+=;?;3?;;+;'#3zó& 9(π& 8'Te"áô( 7(∏( 7(Sd"Ü»π"∫ß√ Ω√ Ω9¢9ƒ æƒ æ9¢9˘°Eˇû†rÅÜéû#"'&546747454&'#*.'&'7"'"'#.'.17&'&54763276'&547>?5>32237632?*#'7654&'676'&'.#>˛1 6]+/S   &3E'7#       ´20B)f "U.5 -*B  ÈTMA,+ 8 9= E!( Ÿ BNA-.  #+/‹◊…Lw.˛|è ¿‹_ˇÍ;Ñ0BPa#"&'&767632'1+&'&6757>71>3#".'&76763227654&#"27654&#" 4 "#7!99DC*˛D_+ ˛ƒ!89D 56DHˇ; < ˛Ö< . I9QN79QN78‚ ˝§  j:' /7ò557MK56˝ºã- å+! É*?D#Mˇfi¶ƒ#".'&'&547>7&5467>32#"&'&'.=#.'&"#"3026326232"'*&'&#"327>54.'&'&#""#03&'#5.5&767>763:323267>5.'&'=4632 365EDC+*>-.1$'L&$8="(%) ?M    ! 3XKI)  !8    â)!*J97 44KE6&K(D  , K@#   &9-%.0      $    é\6•2#"=76767676˚  9   •  !n&{"U˛˛®«.'&5>ù ñ;<Q   U! ∫∂ÂÁË  ªß%ˇ∆ˇÃ&'#5&>?67676'&6736áCR G.8 9O  UO«≈dP  RXo|›ı ºQËı∆¬#".'.'&'.'3"'&54676?5>74645"'&54767>7>767&'.'.'&'&5476763235&'&547>326367>7632ı!2 .       "    # 4    x"$         "+-    $  6-po#+=+=;=;;a„:··:„!ÂÂ:ÁÁ:%ˇCflh+7#".'&>?36767>7>7654'5.547632flí  uV     *ßD˛%'#".'.46547567262;2@Œ  —fl  :ˇ‚∑o7#"'&767632∑  0  ˇ‰ˇØÇz%/#&'&757676767>76761}ÕcAa_6   D˛a◊ x∆¬y <ˇÿ∆&#"'&547>7632654'&#"32«<9i0-#!(7*W6(s,/()3u:eJH%:7CE@ 7/˛Í@T.<BU-FˇÒ^Ã+#'"'&767;6767'&'514?632T H *ßA +97  √ ˛Æ    D!ˇ˛’«Y$2#&+&'&7475767>76767>54.'.#"#&'&757632327676í   ôî );Q"      jr7##  -+K ù) ¢ B/ +'5   s""-" *ˇˇˇH·ƒS#"54763232>767654&'.#"&'=476767654'&#"'.6753632fi  &  &9<WWHS +  ;  I," ?[zu z   $-RGF'&8 :R   Q v @ˇEÓø+/5%+"'#"'&?#"&5476?37632/73673Á=+ ' ,≥  ·z &8Z3~$V]zW $∞≠ # ˆi  ∑ÅÁ¯v@Lj ˇTøÿÜ##"'"&*&"##"&'.5467>32327>7654'&'&'&'".'&7>?>76?>?>23262;23:627>757676ø4  c54O!DA      /&1"    $   ¬> -+N[S"    2B!  *H  Vˇ˜.û9S6767632#"'&54767>7>767;2654'&#"32# aX "% ",Z.H(&¨,** Ω#&  'ôG  7%IE"25IDT≥ö"  ˝›<O1" & .ˇW·¿D+"'&7>7'&#"#"#'#&'&71745>76762676‡˛œ ;IJ #)[U ú˛ »8 É 9ˇÙ˛f 8J#"&'&547&'.5476767632654'&#">767>654'32€#Ü&$T\K1(° /,.2!G b/a; >(#HO"H&WA@ 51[\#  ù   '<  ˛ò#6FD#   %ˇ)Ù«+F'&'1546?6767#"'.5476767632654.'.'.#"32767>Ã('&HI]*H qI6(.*4&),/$J. )!%  ~FWLTT@;"  %9-C+5 B>=((˛·$+  27X0#  _ˇ‚∏)#"'&75>32#"'&767>32 #@   w  $˛û    ˇ<∏3#".'.547632&/5&?654.'.4>32  ;ï I  u    ˛ô~X/.  75pg-'=7%7 [˝Â  ˛U´ >È 3 Ë @ ¥¥ @7≠pÚ !#=3!3!#=3!3a˝Â˝Âô;;Ï;;75pg=7-'=g˝Â ¨˛T  &Ë @ ≥¥ A È 3 Oˇ„õ•2F'&=6767>76767>54'&#"#"&'.547632#"&=67632õ: &*  -     #,G,,” ıi8  ) }<  %  !11˝Ì '  Uˇ⁄◊|ò%#"'.5432#"&5<7#"'&547>7>326?37;2327>7>7654'.#"326?6;4.'.#"327676÷/zxû√Ä?@Œ¶fgS*g=,1A=/$/(((6 )      T*mDWê<w43g•Ö≈6  ˛ó #-"" 2DOìPP?§c÷ `a°ôn78-* ;('8CO'E  * !,)'"   ADÄN''AAǬUà3gÅÅ .5NL1[)8Cˇ‘ˇÚ‚õOT$'&"&'&7>327>5'#";2#'"'&76767676763623;235÷  y´  @œÑ  vÇ $'∑     ≈ï6     ü•    /  ˝‰ ø¿ ˇ¸∏Ü?]o'&"&'&763276767>56'.+&#"#"&75>3!2654.'.+"32>654'.+32z=+!3 %PQèµî  [ /lB=3"3,0E.C+8.(Sa'G9) -9_65  0w    ‚!> Ã˛¥+S:!æ ˇÓó?#&7>54'&#"327676#"'&#"#"'&547676323%'(Wõn77<;j°k    /U:ïeaABwvéh ;{  @_/sEk==ê  KP PQàkXX32- ˇ˝ˇ¸IÜ4L'!"'&76?32767>74.'&'&'".*'*+"&763!2654'&'&'&##3271~Ñø˛ï ! Z   9Wç5"øÄ-/:;Gl >^;‹L,óih  5Ç  '(˛Q¶fA1/ ˛- ˇÚfiÜí#"'.5&?4'&+:;267676&54'&+"322;276767>76#'"'&75>7623>767654+1&'&756763!2’  <≥ 6Æ    ?í.  K\8    '˛≈Î    ]6  @=+fl # $Y6 º&       +ê    ˇ˛¢áá+&'.5&454754'.'&+";2>7>7676'&54'&+3621#"#&"&'&7632767654+"'&7>3327:3ñ  >E %@/       (í* -   Ñ  # `6  Éñ\\ | -,0 888 aO- ∞(    .ç   =ˇÓ=ñr3+;#"'&'&54767232#&'5#&'.#"3276767654'./".5&7637)  KLLKeUV55~√sÖ  9K/Jv-]}Ä/)'    çg   !"FG`ümh. w J'./_åvr  "$ ˇÔˇ¸âêù+272+&"'&7>76;676?45!"#1376'&"&76;2767654&+'&7>362#"+"!0?>56'.#".'&454>3732Ö  Z   èè   &˛π) -  €I ' Z# èò- %J&  ßg e˛}    )°Æ'   3É      1®¨    ˇ˝ÁÜ?5>3172'72+&1"&7563767356'&'#".'.<è ëå  *  e 8”V * e / l   /˛p*   ,é" ˇO˛·›Ü>'##"5467>32327676'1&'#"'".=>;732Ÿ   p4jvV  #? Ä    Çò d )˝˜K+-'R+   8'\+   ˇ¸gêî2+##;2+&1"'36#&+&'&7676236767654&+"&45>362+>767>54'&#*'.7>;N)A^}R⁄ HS˜$  îÑ   _  ìx  , #@-l>   QÖ =S:˜  % ®%   +ê    1ü , J(   ˇ˙¨Ül%#"%&'&767;27;67>7>54'&+""#"'"1.76=76;712+"136767>™  ˛Û˙   [ îî  ,^  oZ5+)î,   Å     ˛|2 ˇ¯ˇ˘˘áä2+";:'.&75>3:627>767'"./5 #&#"'&7=676767716'&'"/&7>72326327€   ] )  Ni?     V˛µ Dk$ ÅU -d ( fIGS 4PÜ /˛r   )v˛ βí    XF! ˛Í ˇÔúá_72#/2#&'&75676767&'&'."&#&'".'.76763172>.'.'&=>¶Ä[   t ˛§K 0 çZ+ _  .M& OU" Ü /˛   ˛ì0  5® ˛p    XˇÓJñ)#"'&'&547632654'.#"7ZxµH=<-Xy±í-8I/$! 5?65_X>XÇõnm,WÉòon˛ÅNh>  5ôMo><gˇÎˇ˛âán'+.7>37>7>54&'&'.#"3032#1&#"&75636767>76.+&'&74>7633:2=L #*fC  :3' B0n •n ( [   Õ  .[3[/*'    8" ˛1    4}     >ˇ6NñAW#"'.'.'.'#1&'#&'&547632676654'&#"327H:J+7- & uJHyÄ≥3..O ^V8!/M/ + Æ)97`&B;+ <<gÉPó2    VVjóoo &WÉÜg .  O|Kc<;=$IJg<<`ˇ˝ˇÙá_r##"&'.'.'&'&'&'&'#32#&.76327>7>&'&#"'&'.7>33332&'&#"2>?67>·$!$! $#  ªr -x&  ÒpE<77\ !4&  ≤%'_:"'*6   ,ó*   é    --LH4/ 8(7%  ¸+˛ÒR ˇÓ;êl#"54&'.#""#"'#5&'&7>767632367>54'&'&'&'&'&547632332763 ,2 =!'B" >!,,6 zr  (+WA$*+,.CDf  Ü"T8 <>$#%( ;I2+ A RF%& #  )J32DˇÚ®p#"&'=4'.'&'&+32#'"&763:6;676765#"'#'.767576323!2726767>32  àl !   õû  #  nd)     ™ ¢  !    ˛6'    ,ƒ  l8 9ˇÓaäf##"'.'&'&?>56'&+"'&753>72#&32767>76&'&#"&7=676232676` (6"K1;K_>/ 7   |å  -  8 /1X7*,' 4;,K) i  ˛˙J4'8 ',20/ı       3˝5'=#% N3   1ˇÍ&îK#"'"654'&#".+&'.=7>362#"&=6'&+.'5'&?3636c #n$    gb$˛   $ •^áB˛pã*    (˝¯  ˇ'   +ˇÌ4ìõ/#&=5654'&'"'.767>37654'&'"&'&7>362>76.'&#"'&7>3712#*&"'".=Ü .   n     'F ,  xÇ       ã8   ˛|˛ç     "˛ç{        ˛Éu        ˝˝¨˛JˇÚˇ˝Qìé'&7>7676?65'&'.'"=76362#7>54'&'&7632713#.&?567>36276?6'&/4'3#& 5 )ËzÄî (  Kí ) JÅ8 0$%(Øì ! 0\Y+  tÆ &  ∏0  '›’  ëå  %ü-    Ã∞    dˇ˝:àj&767>;7;17674.+'&5476712720#&#'&5467>367676?.'&'r  ^~   hø%   gK  ˛ı / ó®   !Ç S    fl–'    ˛Ìã)    /ã  ˇ˛ˇ˝áG!27676?>3#$#'&7476#"1+"=67>767=63%:Æ˛Y2&-  "˛’˛  I ªL,+  ©Q Xú˛Ñ !F D◊H'# (ˇ ≈∏+";+77;¡ ]ùH ¬µ ¬¶ ¸Í  ç 8ˇ·˘• +'';ÁD YD Y ¶ ˝Zˇ≈ˇ b∏+?;26767>5&+?;^∂ ¬ ^ ù G √¶¸s   ?À+' +77;ı3 ü† 3 Ÿ  ÷ ?˛Òn˛íˇÂˇˇ\'!'&75?57>7>3 7; ˛ –∑  ôflI†#"'5/.7>;2H  {Jı í  %ˇÙœ¨2C%##"&767#"'&547>7676767267>76'76≈( .D'""7+!-2*0;  õ+%"&R* )(9&",LP. ˛Ë   X∑ (8@6ˇÙø˝=V6?66767>7>767632#"'&76767&'&4654'&'3276y [+e       4;=N'%◊ 42*&*¨0 ˛s   ,97! /3/C¬∑g  ˛6%--/] +/#ˇÙZ≠G#*.'.#"3276#"'&54767>7632U     (/ &-*/8 18 é $   7  - " 3<HI: (1ˇÙ ÛEU67>#"&54>747#"'&5476767676157&'5&6?>7.#"3676 z ' *'4%,+O$5   q Ω "+> '+Ó ˝ö-   +))$7NML1  Û   :˝–èAbc! "'&ˇÙôØ8H367>#"'.54767632676'&6ã1/C  %2G  -6 93"I%477 o5 8 Aç&>   0$ -4o[-Ö. (&  ˇI˛Ó˘ˆt'#.'&#"32+#"'&7633:23276767676#.5&47676726?6767>7632Í!    9  ;/ *:%2  6,*  4< Ÿ  N<V  Ì:C3:)+/ 6-B+U1V/ &ˇ≠˛Ì—≤Idz/#"'.54767&7&'&547676232654'&#"32654.'&'32— (!E( NK$[7`:!C)K2!%$:BF +ø/     & J9F %<K|' *R$ . 7  '+,%+$ &-/44'/˛Ê=[,'-.  ˛Ã 0-$  1ˇÙˆÛe%#"'&7676?>'10+"'&67.6?>32>763:26?6Ú%)-  >8E/ % É p f `8>:$e." –  <I:  o  ; ˛I ^ x‘$ 0ˇıÑA#"'.7>7>3#&?67./&7>76326761     )  :5   - ; É)> 0 ˝Â ! YÏ    * /˛Ú   ˇl˛DàJ#.7>72#"'&7676676767671#'&'&76767632D  /T!?00#   h  ,' W $-"% Ó˛∆{K#!  : f   .5ˇˆ˙Uh6716#"'.'.'"#"'&'&'&5475.'&6?667632654'&#":367È<1k   ,*'$ "   Ü   m bT53  [  <8+'é#H&     5 !(& ¶ q :(˛cB ¢*$ '+ 1ˇÛ+˘+">7672#"'&7#".'&>?67676%Ñ    S45v  _  ˝É ^ Y9  8+ˇÙ¡¨Ü%#"&7671465+"'&757#*#"#"'&7'&?67632>7632>767>767>7632>753>7>º$'*!&) *H)8"  =   !-1 ^=   ;5 Ñ0!-!ìö 0#9 &i! R 1D3(     .&'%` h    a   (ˇÙØo%#"'&76'+"'.'&47'&'&7676>7>7676767>32676716˙%'*"8K       :  3 !/   <  â/ T   % ï @C9, '! ÿ &ˇÙ≤≠4#"'&47>7632654'&#"32¢:&0.& +"&5'T5  m*    3b6^F 74=3, ˛¸<O, G)# ˇΩ˛Ì⁄≠i'2#&+.7471>276767>767676547'.767676326767>7>32654&'.#327— &(?;  < ys  \  )2&     g('$ <2]347+- w'    Sy  6% .     ÈT0!  /2û G4˛Ï◊≠8J;6'&+.54676367>767#"'&54763273676Õ r   Üu 0  2&""WĶÉ'"9   #¢ ˝Ò6     >« )%/_^¸±9>ˇÙì¨</+"'&7&'&7>3267632Å &    5  49 &"ü   ; 1"  $ ;4  % ; ˇÙv≠Y#"'.'&#"#"'&7>76327654'&'.'&'&7676767632X     =U*    +2 í   13!  /**.  ;ˇÙG4:2'#676#"'&5476767#".'&67676735>76,>D5 c= )  3 !# " £' ˛Î 4   c"Q#ó ##9 R>ˇÙÆU%#"&5467"?'&'<6753676326767676767>;73213676') $#E&?*  +. <9 :    = m.# C(( AѬ *.Yˆ !K+P  ˛fl &ˇÙ›≠E#"'.6?'&'.>?>32>7>767654'&547632⁄=Z]1   -C -.  6'# ~ F,WDF ,2"¨   <:3  Ò <GF   ˇÌ≤≠m'&546?#"'&7>7671&'.67>7>7632676?>326232>76767>54'&547632¢P78  E1    #5'1@  5/% ñEjI0   #*   ?# |E    kÙ 9K0† ˛√4G*!  ˇÙ5≤ñ0&'.'51.#"#212>7>#"'./#"'&74>;2767>7>?45'&'&#"'.6767632>7>7676   ,/*      #;+( 4-  .6    *#!  $ †%  5 8_!    #. O#@ r    0r    C G ' ˇÍ˛Ïı≠};2#+&"&7>3676767>7>76&'.'.'.676767632676'.'.54>7>32Ì%H ""   nl  * :  %& l ê %Ab  $FK$   n> -\/! " $LFmR Æ0   ˇÙ%´ó63232676?>#"'.'&'&'&'&'#&#"##"'&'&547676767&'&'.'&#""#&'&75676323327>7>=7>32 6 "-- 3@)   &(    C*   $!Mî03     $&(*2B     ù +2     .$,9@   /# 0˛˝oÀU7+&'&547654.'&'.'&=476767>54'&54>7>76#ón 15Y99    J, 3 ‰=l63(4 <=R41    24&$"$  !37# ◊ˇfi/\ +55; ::"`¸†!˛¸mÀS7*.'&476767654'&546767&547654'#'&'&76;#ˆ :9Y2 o f   Y99 #   `$4S==  '37$@@i@7P  <<R42"  L‡Nß7#"'&#"#".'=67632327>757>2M()<6cC *+=  4A   èI026%  H13 %   %˛˛∏/#".'&767632+"'&7=6;  <;  {w  ®˛G Ω ˇNîBN".'67>31/"&'&?&'.547>7>57>3232# 8 # 8=$ $' 2  % # & áO˛–*  D» ¡ *\b*"   Ω +% !˛˛ÀÉ#"'&'&'&'&/&#";+263232765<&4./&547632#".'&'&+#"'&5476?>767+?;76767>7632   ?) é ®  ,#/@) 6G,, +AB'8 (#- q É@DED05+   #*3îX  :0  ' "$A7 )96 ""2 ©àãM MDWXE[%/#"&'&'/?&'&54>767/?67>32?'4.'.#"326M' 5#0&!6 ( 8  8 ( 6!&0"4 ' 6   5 l  4'!,4 @Yx( 6  7 ( 8&- #6 ) 7 6 ) 6 0 7 À  6B7.ZˇÌê√ÎÚ&=7474>7>172#"37327676=4'&'"'&?5>36732'&"##2:;7;29+&"2+&"&=763236:36232767>?"+'&'&?5>;'4"'#'&?5757>57567;7&'&'./&'+>] vU  K8    64%  D  1'" *Ç3 ' \ë 8¬  ¢p H Jè  !#        4 Ø6    Ω   P  1ßQ ◊ˇfi/\ +55;+55; ::::Õq˛è˛q˛èˇ ˛˛/ÀI_#"'.'&#"#"'&5475363232>7654.'&'.547676324'&'&5<56/    & 43Z[U-$      # **F\e*!%”1;' &@ã  (&f@Z((1XSQ99  )<  #H)HBOQR8J˝ΩFoD@EXNQPBNJK_’å](#"&4632#".'&54>7>32å   ((®       (8(    Rˇfi;Œ d '.547>32&"27#"&54767632121?;2+"'&/5&#"32>76;€˛Ãm# m6ÑM&HB<)≤˛X'±˛ON~jêMFe '<    #]"5*  7$&" Ò˛ ›n047:õo77)˛v≥ZDL+Ä≥ßjågmGB  u Z0S)#  UÄ`•.G>76?#"'&5<7#"'&54>7>76;6767>?\(! !$  !23[    ì∏$    D  # L·¥+/?;+/?;“k Nüóé; n ≈ܶ¢ ® ™º∏¡ ¡6ßpˆ%+=!#=3!3a9˛,ßÁ;˛œ?ˇ›0‘QYz4.'.#"6764& &=4637>54.'&'"&=467626 &6 &.'5/#2'&'"'32Ï 4ˇ¥ˇ≥Z  Y`I/dZ  QEfi˛ ››6,+ å (  [LTssø  ïEǵµÇÅZ     $1X$ÇX˛∆fifi:fl˝ó√`%  JL˘•`'!".753765676;!2¢ ˛¯    7" & tN∆¶#"&46324&#"2∆cFEddE L6' 7N˙Geeée  >KP8"(76ˇ€p¬'#+=+=;=;;!#=3!3a„:··:„˝‰tÁÁ:ÁÁ:˛g;;D'ŧX32>5>3232'"'"#"54>7>76?67>7>7676&'.#"#".767632ÅmJD * %'$#$       ,  $#1+E@R:           . , #L#s•b'".54763232>7>54.'.#"&/76?367654'&#"##".1/.67632s $.&8.       ;   )> ].6/(         1 µ‡i£662#.'&73>7576* ^    ° (j(<%ˇË˛¸flï3'#'&'.='"1#"11#"5<5*#.'&5476;2fl& 6""NjA@pÔy"¸ø 9¸¿◊43/8b77u·¸j#".'&47>32¸   B8 8 ˇ+fi (#"'#'&76?3327654.'.75?;fi+)E  & !   `8   A{(W¶7#&0'&'&707>76326?#'&?>7>;2VA  Q/ -  $;  ŞÁ  ∆  & aÄY•0#".'.5467>324'&#"32>76Y "  2/%  K    94   .M  %#'3 &A◊¥%+?/;+?/;Œ≈è: n¥†m OŸ¡º∏¡ ™¶° ® {ˇÕ;ª9Tåë%+"#'"&?#*./&>?3>7;232".'.757>76#&0'&'&707>76326?#'&?>7>;2365; ( #eà ( ˝ó [   ˛'A  Q/ -  $;  h?1z G  I …ß  ˝N £  ˛Á  ∆  & ˛N>{ˇÕQªRm•32>5>323:'&/=7>7>767>7>7676&#"#"&7>32".'.757>76#&0'&'&707>76326?#'&?>7>;2Ql F   -/Ö   +  #*$˝ó [   ˛'A  Q/ -  $;   ;S    2   -  #  n˝N £  ˛Á  ∆  & LˇÕ;ª9T∑º%+"#'"&?#*./&>?3>7;232".'.757>76'".54763232>7>54.'.#"&/76?367654'&#"##".1/.67632365; ( #eà ( ˝ó [   ˛D $.&8.       ;   )> L?1z G  I …ß  ˝N £  +.6/(         1 ˛i>%˛˛r∏X#"&'.567>32327632#".547676767>753>7;2r    >  :- !   +#:-:'%   w     ö)?1!   2?&j7   ˇ‘ˇÚ‚l[`#"/&76;2+&#""'&7>327>5'#";2#'"'&7676767676;235a2 Ç  Ou 2HJ` @œÑ  vÇ $'∑ ≈ï\õ í ¸◊   ü•    / ˝‰ ø¿ˇ‘ˇÚÊo&pu636:1#&'&71>?56+&#""'&7>327>5'#";2#'"'&7676767676;235m +    r 2HJ` @œÑ  vÇ $'∑ ≈ïh #<I  ¸”   ü•    / ˝‰ ø¿ˇ‘ˇÚ‰]INl$+&#""'&7>327>5'#";2#'"'&7676767676;235+/+.?6762;÷ 2HK_ @œÑ  wÅ $'∑ ≈ïn Kö ö  6   ü•    / ˝‰ ø¿e [^í  ˇ‘ˇÚ WHMw$+&""'&7>327>5'#";2#'"'&7676767676;235#".'.#"#"&5>3232>7>3÷ 2î` @ŒÉ   vÅ $'µ «ïê /"#   93)=4  6   ü•    / ˝‰ ø¿ 9')     AF%!  ˇ‘ˇÚˇ).x}#".'.547632#".'.54>7>32+&#""'&7>327>5'#";2#'"'&7676767676;235Ï ò    ´ 2JJ_ @œÉ  vÅ $'∂ ∆ï8     ˝   ü•    / ˝‰ ø¿ˇ‘ˇÚ‚y jo64&#"3703;+&#""'&7>327>5'#";2#'"'&76767676767&'&54>7632235v O -  2HJ` @œÑ  vÇ $'∑ # "0/çï€& }!^!˝‰    ü•    / !.  !˝€ø¿ˇÊˇ˝à∏æ&767323632/5'.'&+"3275676;#+.'&7=4'&+;27>?;2#"&*&"#""'&715>3676?#"30#&#'&=76?36767>?7&'1&346¥ òû6756   3X^1ø=   9†+ 4!#TA )&%%$$†ê ' ∏/7  ô4  ''8 '<5“õ` =C  ·5 ?a  ! ø *u  ,u7?  ,n˛‹˛˚ˇ1óf#"'#'.76?332>7>54.'.75?&'&54767632#&7>54'&#"327676#"'&#"™.+I     UZABwvçA;93%'(Wõn77<;j°k    /@1 " 8   ( IPÉkXX32  "{  @_/sEk==ê  KP ˇÚfil∑#"'5/5&7>;2#"'.5&?4'&+:;2676761&'.454'&+"#::;276767>76#'"'&75>7623>767654+1&'&756763!2˘4   Ñ O‹  <≥ 6Æ  ?í-  K\8    '˛≈Ï    ]6  \õ í  ˛·=+fl # "   º &       +ê    ˇÚfio/–6362# 1#&'&73675#"'.5&?4'&+:;2676761&'.454'&+"#::;276767>76#'"'&75>7623>767654+1&'&756763!2Ï-     (Í  <≥ 6Æ  ?í-  K\8    '˛≈Ï    ]6  Z z˛Ë=+fl # "   º &       +ê    ˇÚfi]†¡#"'.5&?4'&+:;2676761&'.454'&+"#::;276767>76#'"'&75>7623>767654+1&'&756763!2'+/+.6?676222;’  <≥ 6Æ  ?í-  K\8    '˛≈Ï    ]6  x Qõ  õ   @=+fl # "   º &       +ê    Z [^í  ˇÚfi)) #".54632#".'.54>7>32#"'.5&?4'&+:;2676761&'.454'&+"#::;276767>76#'"'&75>7623>767654+1&'&756763!2u *û     '  <≥ 6Æ  ?í-  K\8    '˛≈Ï    ]6  8 (     Ë=+fl # "   º &       +ê    ˇ˝ËlN23#"/.7>3'72+&1"&7563767716'&''.763172D 2 ê ˘ *  f 8”V * e . ëå lò ì Û  /˛p*   ,ê# ˇ˝Ëp"Y#'&767>76?5676:'72+&1"&7563767716'&''.763172“e      )  *  f 8”V * e . ëå H$n "  ‚  /˛p*   ,ê# ˇ˝Î^6W'72+&1"&7563767716'&''.7631727+/+&4?>36222;Á *  f 8”V * e . ëå  Lßß     y  /˛p*   ,ê# : [^í ˇ˝)"X#"'&54>7>32"'&54>32'72+&1"&7563767516'&''.76;72Ô  ü> ¿ *  e 8–V * d . éè    Ø  /˛p*   ,ê# ˇ¸?âGz'%"'.?56;27>?'"+&'.7576'57>;6?654&+"&=?6362654'.'&'&+"62+"327‚]rx¥˛õ * H O#7(%%A<2 +46B/o É" +ód7OÑòhh   $ã û   ˛lmF>-"  Œ ô  S ˇÔõ8_â272#/2#&'&75676767&'&'."&#&'".#.76763172>.'.'&=>36#"&'.#"#"&7>3232>7>3“r>    t ˛§K 0 éZ+ _  .M& OU" - 24   2")=6  Ñ /˛   ˛ì1  5® ˛p    ± 9')    +;!%!  XˇÓJl+C#"/&7>;23#"'&'&547632654'.#"7C4  Ñ P ≠ZxµH=<-Xy±í-8I/$! 5?65_X\õ ì ˛·XÇõnm,WÉòon˛ÅNh>  5ôMo><gXˇÓJo'9Q#'&767>76?567>6#"'&'&547632654'.#"7ó     YZxµH=<-Xy±í-8I/$! 5?65_XH  "  ˛ˆXÇõnm,WÉòon˛ÅNh>  5ôMo><gXˇÓJ_)I#"'&'&547632654'.#"7+/+.6?6762;ZxµH=<-Xy±í-8I/$! 5?65_XD Qö  ö   >XÇõnm,WÉòon˛ÅNh>  5ôMo><gG [^í  XˇÓJW)Q#"'&'&547632654'.#"7#".'.#"#"&5>3232763ZxµH=<-Xy±í-8I/$! 5?65_XN !3     ")>6  >XÇõnm,WÉòon˛ÅNh>  5ôMo><g„ 9')   *! %!-XˇÓJ)"4L#"'&54>32"'&54>32#"'&'&547632654'.#"7µ  û: ZxµH=<-Xy±í-8I/$! 5?65_X   ÍXÇõnm,WÉòon˛ÅNh>  5ôMo><g]HìV//?/??âŒÃ ( –” ) ÕÕ ( ”” (  æº ) ºº ) ºæ * øø * nˇƒh≥-<F#"''.'&?>3&547632?6 &'&#"654'32h<<?MMZoVK  I]x¨#B<;  ˝“ï8MrH ™Y'˛à!:WEVâNÖ769V  R\}ñpo A ˝º+I(-MLNiöU9˛c$79ˇÓalw#"/5&7>;2'#"'.'&'&?>56'&+"'&?>;72#&32767>76&'&#"&7=67676˜4   Ç Ng (6"K1;K_>/ 7   ~ï  /  = /1X7*,' 69 ¨6 \õ í  Á   ˛˙J4'8 ',20/ı       3˝5'=#% N3  9ˇÓao%Ü636211#.'&71675'#"'.'&'&?>56'&+"'&?>;72#&32767>76&'&#"&7=67676-    (L (6"K1;K_>/ 7   ~ï  /  = /1X7*,' 69 ¨6 Z z‡   ˛˙J4'8 ',20/ı       3˝5'=#% N3  9ˇÓab}+/+&4?>362'#"'.'&'&?>56'&+"'&?>;72#&32767>76&'&#"&7=67676è Oö ö " Û (6"K1;K_>/ 7   ~ï  /  = /1X7*,' 69 ¨6 Ω [^ì Œ   ˛˙J4'8 ',20/ı       3˝5'=#% N3  9ˇÓa)(â#".54632#".'.54>7>32'#"'.'&'&?>56'&+"'&?>;72#&32767>76&'&#"&7=67676á *ù      ù (6"K1;K_>/ 7   ~ï  /  = /1X7*,' 69 ¨6 8 (      ∞   ˛˙J4'8 ',20/ı       3˝5'=#% N3  dˇ˝:o/†63621 ##&'&71675&767>;7317674.+'&547>32712720#&#'&5467>367676?.'.'„-    (˛è  ^}   gΩ$    1^'   ˛˜ /ñ¶   Å Z z˛˚    fl–'    ˛Ìã)    /ã ,ˇ¸îçôú76326236767>54&#"'&75676:23276#1:;2#0"*#".#&'&756762327654.'&'&#"32"##&1"'&70564567039 V )/.0    N++#H *)54;  l4%W O. ñX1.Ñ     " 5Z ,   F1?  ˛©      ˇBˇ ªá#"'&54>7>323276764'.'#'&7>7>767654.'.#"#"'&5467>3232>76767676767>767632 - SZ,   -   >  )/+7B)"   9&( '%" }2-'0crV ! 5õ&   /S  64J÷õY7)4!   1X"ç;<0!   %ˇÙœëJ[#"./&76;2##"&767#"'&547>7676767267>76'76a2 ç X j( .D'""7+!-2*0;  õ+%"&çûí ˝¡* )(9&",LP. ˛Ë   X∑ (8@%ˇÙœï"Uf#.'&716?56762##"&767#"'&547>7676767267>76'76Ø  $ . * ( .D'""7+!-2*0;  õ+%"&m $z ˝Â* )(9&",LP. ˛Ë   X∑ (8@%ˇÙ¸Ç2Cj%##"&747#"'&547>7676767267>76'76+/+.6?>363622:13≈( 3A%""7+!+010;  °+$!%J Kß ß  R* )(9&",LP. ˛Ë   X∑ (8@ë [^í %ˇÙr2Ce%##"&747#"'&547>7676767267>76'76#"'.#"#"&76763232763≈( 4A%!"7+ +002<  ¢*$ $K /.A   7,B6 R* )(9&",LP. ˛Ë   X∑ (8@% 9')%   A##%!-%ˇÙflN),/kÄ#"'&4762#".'&546767>3'747#"'&547676767672>75676#"&76767676à  8∑/    * @F?'$"7#(1+1.0;      !;/ ,:  8(    ˛1  2!9&",LP' ˛Í    (è-ä <   "%ˇÙœë2CP]%##"&767#"'&547>7676767267>76'76#"&47>3264&#"3≈( .D'""7+!-2*0;  õ+%"&˜ @.5O(0.R* )(9&",LP. ˛Ë   X∑ (8@$!^AB\"û&  %ˇÚë©9La"132?32#"'&'#"'&547632632654&'.#"67676732>t2IE#N uL4".)/qyô 75++ K, 2!˚+ )  #@ì$" "1 O*!+(#Gza`  %Ä ó c¬ )&(%3ˇ?y≠b&7637654&/.?&'&5476767632#"&'&#"327>'+0#&.  ;A8       52 Ha  0O ±   & +;HI: %   #,*7T   !&ˇÙôëSc#"/5.7>;23676##"'.54767632676'&670 ô `U1/C %2G .@13"I%477 o5 8 AÄö ì  ˜&> 0  -4o[-Ö. (&  &ˇÙúî(dt.'&715>767>75767>3623676##"'.54767632676'&6èb    )  1/C %2G .@13"I%477 o5 8 Am(j ! ‡&> 0  -4o[-Ö. (&  &ˇÙ√Ç=Mo3676##"'.54767632676'&67+/+&4?676222;2ã12#> "/N ;.3"I%13: v: 6 = KØ ™   ç&> 0  -4o[-Ö. (&  ⁄ [^í  &ˇÙ∏K0m}#"&'&47632&#".'.54767633676##"'.54767632676'&6¥       .   …11"? #/M =.3"I%14; u; 7 =#   6 &   Ω&> 0  -4o[-Ö. (&  3ˇÚˇë2L7#"'&?47'&'&757>32>7>76#"'5/&7>;:˙$/3  1? :   C0 { J^# Q  30/˛Ú     ò í 3ˇÚJî2Q7#"'&?47'&'&757>32>7>7663662#.'&73>75˙$/3  1? :   7* ^    ^# Q  30/˛Ú    ! (j(<%#ˇÚMÇ2T7#"'&?47'&'&757>32>7>76+/+&4?6762;2¯$/3 1? :   R Lí í  ^# Q  30/˛Ú     [^í 3ˇÚdN2F]7#"'&?47'&'&757>32>7>76#"&54>7632#".'&54>32˙$/3  1? :   U   (î     ^# Q  30/˛Ú    ‹  (     .ˇÛÊõM^#"'&54763:2&'&1&1/5'=46?37.'&?576332?6654'&#"327Ê >#DLd1 ïM8+5 b E2> ¶,''1)+>Z\VW>@30Cå[*."    9 ˛XH))9=N/9(ˇÙcC¥+"=763232>7>70>3:#"&'&##"'&76'+"'.'&47'&'&7>766767>76767>32676716fl "x%%    %&48&$'.!8I       :  %$  =   ç ;""˛Ä/ T   % ï    *"-9- '! ÿ &ˇÙ≤ë2H#"/.76;2#"'&47>7632654'&#"32M1  ë \Y:&0.& +"&5'T5  m*    3àù í ˛÷6^F 74=3, ˛¸<O, G)# &ˇÙ∑î ?U#.'&716757676366##"'&47>7632654'&#"32o( / )  :&0.& +"&5'T5  m*    3#-z  Ê6^F 74=3, ˛¸<O, G)# &ˇÙ“Ç4Y#"'&47>7632654'&#"32+/+&4?>36222;¢:,.,% +"&5&Q5  r-    2Ÿ K≠´   b6^F 74=3, ˛¸<O, G)# ° [^í &ˇÙÔr5c#"'&47>7632654'&#"32#"#.'.#"#"&76763232>7>3¢:,-+$ +"&5%O4 u,    0Ô /  !  8,D6   b6^F 74=3, ˛¸<O, G)# 5 9')   A##%! &ˇÙ⁄N(H^#"'&47632#".'&54>7>3#"'&47>7632654'&#"32«  π/    »:,.,$ +"&5&P5 s-    1:  8(    Î6^F 74=3, ˛¸<O, G)# FYûE':#".'&74>7632#!#=3!3#".54632ô ˝∆:˛¸ "6   ˛›99~, ˇÚ”©5BQ#"''&?6'.547>763271762'.#"7665453276√ 9 ---%T3<*!!~ +')± ≤  1)†(]F$ ! dQ #j=CV∞w&+±>">ˇÙëm#"./.7>;2#"&547"?'&'<6753676326767676767>;73213676R7  ìV∂')$E&?*  +. <9 :    = çû î ˝‹.# 2S%AѬ *.Yˆ !K+P  ˛fl >ˇÙî&|.'&715>767>757>36:#"&547"?'&'<6753676326767676767>;73213676Œg    - 1')$E&?*  +. <9 :    = m(j  !  ˛.# 2S%AѬ *.Yˆ !K+P  ˛fl >ˇÙÇUu%#"&547"?'&'<6753676326767676767>;73213676+/+&4?676222;')$E&?*  +. <9 :    =  N™®   m.# 2S%AѬ *.Yˆ !K+P  ˛fl m [^í  >ˇÙN%{#"'&4762#".'&547>32#"&547"?'&'<6753676326767676767>;73213676Î 8°   ‡')$E&?*  +. <9 :    = : 8    ˛ .# 2S%AѬ *.Yˆ !K+P  ˛fl ˇÍ˛Ïıî!ü6362#.'&716?;2#+&"&7>3676767>7>76&'.'.'.676767632676'.'.54>7>32? -   #  *Æ%H ""   nl  * :  %& l   $zÌ %Ab  $FK$   n> -\/! " $LFmR Æ0   ˇ∏ˇ κ_x#"''&&'&?5>7>7647'.4>7>763267632654'&#1327ËOTp   ÜZ  !ù   -1=%9$ t '/<1%lVX^  %Ø   )$#"˛Î2 ! †T0(%6êGˇÍ˛ÏıK.¨#".'&47632&#".'.54>7>3;2#+&"&7>3676767>7>76&'.'.'.676767632676'.'.54>7>32‰    ƒ+    Ú%H ""   nl  * :  %& l #   6 &   ∫ %Ab  $FK$   n> -\/! " $LFmR Æ0   3ˇÚˇ©27#"'&?47'&'&757>32>7>76˙$/3  1? :   ^# Q  30/˛Ú     ˇÛÆàp$#%"'&?576;276?'.4?6753767>767>54&+"'&4?6;72#"676;276763°  Ô˛”  "    Q   wë* & Y0S3&" Æ <#    5Z  ;>1     // :B” -ˇÒM¡k'&/&4>?672>7667>72167>1#*'&?.?676?65îY  )!   G8  $5   A3 K  3  Œ / 5ˇ  &Zï +-¯]ˇ˙[ãõπ"/=4'&+";>?62'&'57454'&+2122:;2767>76?6?32'"#!"#"'&5476767>32!2654#"32676767S7ô 33H5#*   9ë*.! ))˛_:8îXWMM}>" Xê ˛2p2.+(\ 8b+     -„ "%'# ª  $ e PPÑxaañ:!hÖ < :!ˇÒå®/:M"3276##"'#"'&547632632654&#">654.'&#"326o2.KT #0C  eWL#?*.ì=1C C^.E&(>'<Ò%,%%?$ë&#8  ,%/ HQ%1.=ô^$OOù#KO Ö?P 37Np ˇÓgUsÜ#"54&'.#""#"'#5&'&7>767632367>54'&'&'&'&'&547632332>7>7+/;?;3 01 < '@", A!,,5 yr  (+U@$)++- CBe   6§S )RöÜ"T8 <>$#%( ;I2 A R F%& #  )J32Õ£ £\_ ˇÙ ÅVi#"'.#"#"'&7>76327654'&'.'&'&76767676327+/;?;P!    4L*     *0 $⁄¶V +Uùí  13!  /**.  ‘£ £\_dˇ˝:)/†#".'.54632#".'.54>7>32&767>;7317674.+'&547>32712720#&#'&5467>367676?.'.'Å *ù     ˛∂  ^}   gΩ$    1^'   ˛˜ /ñ¶   Å 8 (      ’    fl–'    ˛Ìã)    /ã ˇ˛ˇ˝UH[!27676?>31#$#'&7476#"1+"=67>767=63%:'+/;?;Æ˛Y2&-  ˛’˛  I ªL,+  ©Q 4•Q (PöXú˛Ñ !F B[D◊H'# ˘£ £\_ˇÙDÅù∞632326757>#*&"&#.'&'.'.'#.#"##"'&'&547676767&'&'.'&#""#&'&75676323327>7>=7>327+/;?; 6!B-,   2?) #)(    7   $!Lì/3    $&()1B    (•S *Sõù +2)     .,9@   /# fl£ £\_Qœ{ë +/+&4?67622:13y Kí í   "Î [^í  àÅœ»ê+/;?;ØûL & Kí#w£ £\_u◊µñ#"'.'57>327>≤*37;! '#JC y&:,.='" H ±“<_ "'&4632<):)5:):*éøk† #"&46324&"32[email protected]. !&  ^^AB\C!c& ˇ˘ˇ16#"'&54?;32ÿ D8:#%, %x , 570! F€£Å$#".'.#"#"&7>323267>32£/!!  70&;2  d9')    AF%! y‘‰§+?+?;Œô,á6 v h!ä±èù± ˇŸˇ=¿^$#"&'&''#".547676?6;23276767>7676?576;3276?;2=  &)" sF?  ` . J   6 "O   y  OI9Ue   90^*'# fi<  "A†˛˛5  &9∫2 %#!"?47!22˛&  ⁄„   W∂ÔÓ%'!&746543!νç p   ¡âfî#"&54676\0( ME } 2)8e# }x Ñ&67>54'&54632 ND 1(  =7g#  2'CˇLÂ`7'&67>54'&54632Âí 1(rU!3*–â8ñ0 #"&54676#"&546766 LDƒ0( MDã  )8f"  2)8e#ùÑë%&7>54'&54632&7>54'&54632KD 0( »MC 0( H7e# 2) 8e" 2)(ˇMó`)%&5&7>54'&54632&7&67>54'&4632óNF 1(œMF 1(:h% !3+ :h% !3,*Nˇ ıº3#"/#"&54767#"54?63237>327632ı îR"ëú  õIô ¨!˝«&  BÌ ÁˇM˛Ì∆Úó676767>32'."32#"&'##"&762326767>766&'"#*"#"#"&7>232>7>766&'5&7676767>32'.#"3:32Ü $H$.,*   9 + 012 1%  +   4 ?* /12 1  +  .* .%S$6 0#  <D°>-R."'!!)$&xL0Û5/d;D$$! BH1 Ì8)h8E$$  .6Q>  c)S+!'(  7'wQ r√oƒ #"&5462oJ54JJhKD6KK65KKzˇÚ~`  %#"&7>32#"&7>32#"&>2~˛Æ*˛¨&0$#$0# 0.ˇŒh (4<DL$#"&7>32#"&7>32+.76>763#"&7>326#"32%6#"326#"32b9;:c9:˛Ùb9;:c9::o˛^  {÷* ˛Íb9;:c9::V@DBD˛ÂADBC˛¨ADBCÒîgiKJg¥JgiKJgia˝à  ªC%>  §JgiKJgi˛≠îóîóîóî¢îóîˇN˛Ì–Ò´676767>32'."7276763276#"7>76#&"#"&7623267676766&#&+#"&7>2326767>766&'&567676767>32'.#"3:32%M$4.*#   ()%= 0 J82 I , #4%121$  +   / F"*#;12 0   +  .*/%S$6 /$  8@ °;0P/"&%/ 2(vL ˛ï = _J&lY,  ÛD<tN$$!  EE- Ìô@X+$$  2Q>   uQ. '(  7'wQ ˇM˛ÌÍıö™#"&7>232>7>766&'5&7676767>32'.#"3:;276767>767623276#"'&76&'&##"&7>23267676766'&+"*#3:32?.ø* /12 1  +  .* .%S$6 0#  "&!% %BK!  u -K8#/ %[) !6$12 1   + .  #$F  70)WZÌ8)h8E$$  .6Q>  c)S+!'(  7'wQ C0T+(  ˝Y8 `&+ˇÒ=GmP$$ 6;;=0'wKŸ0ˇ@ˇ÷Û≥ '&76Ë˝ëoú˝G π ˇÓeD2+3267632&#"#"&'#"546;47#"546;>2#"54#"32+u π473U    \&QeA :0 3ú∂?  hCa…   [}BA -^u}  * ]ê)!Sís_ $&Ÿ∞Zô+&54>23>=4#"+"'&;2+&&547>=4&'.545463766?6;2+.#*;##&"&=473>54.#"#"&?>376Ÿ ´ Ö Ö F5   P2y r q   ˝∑ '/ ?` -& öØ  #“ ˛€ ≈)  &Î) ˝˘  'Î'- ) ˛ˆ%  %  )J E2ak!5!a˝‰29ˇM˛Ì∆Úó676767>32'."32#"&'##"&762326767>766&'"#*"#"#"&7>232>7>766&'5&7676767>32'.#"3:32Ü $H$.,*   9 + 012 1%  +   4 ?* /12 1  +  .* .%S$6 0#  <D°>-R."'!!)$&xL0Û5/d;D$$! BH1 Ì8)h8E$$  .6Q>  c)S+!'(  7'wQ ˇg˛ÌÏÓp%#"7676#&"#"&7>3267676766&+&767676767>32'.'&"372627>72>3276ËI9/ $ FA, "5%12 0 ,  030%T$6    %  0- ? 2 P^HZ–˝>FnO$# !< l=    U7S, ''  ${^ ˛î@ ˇQ˛ÌÒˆQ_3276#"'&74+"#"&7>326767>766.+"767676767>676.3727Òx 5 J8! 3 ë , "5%12 0 ,  /3  &'FP!  IZ!CN Ô˝KA _%. ˚B?rN$# !9OC  c)Q.(i2.${Y  ˇN˛Ì–Ò´676767>32'."7276763276#"7>76#&"#"&7623267676766&#&+#"&7>2326767>766&'&567676767>32'.#"3:32%M$4.*#   ()%= 0 J82 I , #4%121$  +   / F"*#;12 0   +  .*/%S$6 /$  8@ °;0P/"&%/ 2(vL ˛ï = _J&lY,  ÛD<tN$$!  EE- Ìô@X+$$  2Q>   uQ. '(  7'wQ ˇM˛ÌÍıö™#"&7>232>7>766&'5&7676767>32'.#"3:;276767>767623276#"'&76&'&##"&7>23267676766'&+"*#3:32?.ø* /12 1  +  .* .%S$6 0#  "&!% %BK!  u -K8#/ %[) !6$12 1   + .  #$F  70)WZÌ8)h8E$$  .6Q>  c)S+!'(  7'wQ C0T+(  ˝Y8 `&+ˇÒ=GmP$$ 6;;=0'wKŸ0Æêº7>ÆÏ1 ˛ Ä "ò nŒ 6v    2˝ETBembo Italic designed for Eward Tufte / Graphics Press (c) 2004 Dmitry Krasny / Deka Design. Converted to Bold via fontforge.ETBembo Italic designed for Eward Tufte / Graphics Press (c) 2004 Dmitry Krasny / Deka Design. Converted to Bold via fontforge.ETBemboETBemboDisplayItalicBoldDisplayItalicBoldFontForge 2.0 : ETBembo Display Italic Bold : 12-3-2020FontForge 2.0 : ETBembo Display Italic Bold : 12-3-2020ETBembo Display Italic BoldETBembo Display Italic BoldVersion 001.001 Version 001.001 ETBembo-DisplayItalicBoldETBembo-DisplayItalicBoldˇx2Î  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`a£ÑÖΩñËÜéãù©§ä⁄ÉìÚÛçà√fiÒû™ıÙˆ¢≠…«ÆbcêdÀe» œÃÕŒÈf”–—Øgë÷‘’hÎÌâjikmln†oqprsutvwÍxzy{}|∏°~ÄÅÏÓ∫◊‚„∞±‰ÂªÊÁÿ·€‹›‡Ÿfló≤≥∂∑ƒ¥µ≈Ǭá´∆æøºåÔ¿¡uni00A0Euroffffifflˇˇ Í⁄(|œD*~⁄ê A
63,400
Common Lisp
.l
1,156
53.101211
1,430
0.176769
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
5fa4b54a2f645a9a87f916bd2ec3616afc0a21dc2083b98cc70afa29bc1fcaa1
8,820
[ -1 ]
8,821
et-book-super-bold-roman-old-style-figures.ttf
szos_CLFM/fonts/et-book-super-bold-roman-old-style-figures.ttf
 ÄPFFTMɡı‡<GDEF'&OS/2WìiXVcmap.Èê¢`gaspˇˇ glyf5ºm Phead 7fi‹6hhea‡$hmtx(‚∂∞∞loca:7ˆ∂t⁄maxp48 namen[Sú `ñpostêÖκ¯A>„I~_<ı ËœD"v⁄ì—Ìˇï˛’èÄIJflZ¢ˇïˇrèÏÏ@⁄êäºå亇1ÄØ@JPfEd ˚ ˇ8ZÄ!‰Mı9©)ªC$,˚π F6<ˇÌ4∫.˚%≥Ã(fl M(Ê+M <M%6Z0M*4Gb03Ê&∫*∫+∫,j¿_+ Ù^8i œÉ'_9xù4®ˇ¶H∑¶ü5•ö-e8 "ì]¢u< %#QHfl WΡ¸ ˇ›\-O e•Gr<[ˇïj8ê h [[\¬l"£zVUnL˛ıM”ıO7ˇˇı6øˇˆ∫A ˇ‰”Î\ˇ˛s∫.]ˇü∫.,ˇ,ˇÈ]Y’ˇfi3]M, hsÀ À Àˇ¯s+ + + + + + ˜ˇ≈^8œœœœù4ù4Œœ¶ü5ü5ü5ü5ü5d∑2ììììI ±ÖÚ%     8ˇˆ8jˇıjˇÛÖ.h SSSSSJÖ.zzzzOoLB¶ˇ˝_ˇ‚p<k0e8†< )# oˇ˛]]ˇ˛]]Z]-]0]ˇı] pa W8,,*ˆ7ı3Ÿ. sˇ˜s e-pˇ˜\ˇ˚Úˇ§ÈˇÎˇˆ∫.◊è%‘¿ 8 ~¨¥ˇ1BSax~í«›º    " & 0 : D ¨!""˚ˇ˝ˇˇ †Æ∂1AR`x}í∆ÿº    & 0 9 D ¨!""˚ˇ˝ˇˇˇ„ˇ¬ˇ¡ˇ¿ˇèˇÄˇqˇeˇOˇKˇ8˛˝ı˝‡¡‡æ‡Ω‡º‡π‡∞‡®‡ü‡8fl√fi‘Á  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`aÑÖáâëñú°†¢§£•ß©®™´≠¨ÆØ±≥≤¥∂µ∫πªº‹qdeifivüokÂujÜòrglz¶∏cn m{flbÄÉï√ƒ‘’Ÿ⁄÷◊∑ø«„‰·‚ËÈ›wÿ€‡ÇäÅãàçéèåìîíöõô¿À—pÕŒœx“–ÃN™ Ä6vº® LÄú⁄ tÏf∆ 6 î Ê L ¶ ‚ 0 r Œ  à j"ƒ4æ™bTÿ÷R4“ê˙Œä2∆V(¸êXå⁄Fz  î Ê!\!∂"L##‘$^$Ê%ê%Ú''≤'(|))ä*:*ú+>+æ,¢-í.B.⁄/l/®0$0î0î0Ã1^2(2æ3ö3æ4Ü4∏5>5û5–5Í6ê6∂6‹7x88§8–99J9ê9ÿ::@:‚;fi<æ=.=˙>∫?®@êAhB&C4CÊD˛FG2HFH⁄IjJJ¶KTLBLúLÓMfM‰NfNÍOVPP–QöRdSS¿TjU0UÏV¿W¨XvYRZ$Z∏[B[æ\V\‚]R]æ^D^æ_D`J`¥aaîbbúb˙cfd:eefif¿gíhi iZjjrkHkÃl∫mûnlooËptp¥pÊqqBqÄq∞rrVr‡ssPsäs¬sÙtZtºuuåvúv∫w w‰y,zdz|{|t|≤}»~¥ÄÄÃÇ9ˇÿ⁄À2/=45&>763#"'&547632÷&  &"   ""  Ö˛0 –    ˝ï "# )JѪ">'.54632'.''&'./&54632*(   ?   )& qí)# ,7 /ô ˛ ö  å@)4 !ˇ ¨‚’›>76767676:3:::3676567674567676763767;2+7:36"##*'#+"&'&?&*##++*&'&'&76?5?#"#*'.'.54&<65>;7+*&'&5&&"63D;$     "     +7  '&    !VE   3  J.# ´-N&TLÁ≠   õ|! õ  Ä  ú ö£  ñ  ä 8à$ˇïìtzÜ%+.?"#0+'&'&7='&'&5476325.'&547>7=767137323=76?;2#"''5&#654'3504'¸+%A  8%)"#'     .'  ÿ yy Ô&,=/(( 1/   <%&2¢'43(* #$ p  ï˛-Éæ ,ˇ∫ÁÄ.>Pe#"&54632%#&#"&'.7?>#"'&5467632%654'&#"3264&'.#"32>7y6OJcaK0*-˛O   ≥ (20/ML876NL˛Ü" z   />I>1bGJb ˝å "x !˛ô0ì1100I$?1v.--! ˛ª"/"  -- ˇ‘ ÉÄê™>;7:""32?6#"&'&/#"'&547>7.5476326767>5&'"&"+'.'<6'4'&#">&'&'32>76 @k$     1%J#* uqT::D /!10KD/1]    √    D ,0#*'  '    %$. "  :n;;VZ; ?"D+)#&;M<   '#!  1   $˛™0-1 A#    Qƪ'&'&'4/.54632Æ  )& c ä à+7 !6ˇU‡'&'&'&5476?6I  V4356\"  )$(1  ∂!  _~}~Ç~c  <H*0l=_ìU ˇÏˇ‹,%&'.?>7654&'.'.767>55\" #9$(2  -E2ÚÑa  $&c=`z^ìW  1n>|4»Ïª§#"'.'.'#".'.547576767#"&'.546767>7>7>7&'&'&'&#'#.'&547632&'.54>7>267>32#3Ï        !  $      c              #      $  %.êÖ`*+*#'"'".'"1&'&545&=#"'&=476?6;5<5&<546;:32è∆»   Ã'… C      º   %ˇR◊k7'&/&767"'&547632◊/ '  *2.-# $!¨•( %+&'"/=467>3762• Lab3 !ss8 ˚'  (  (ˇ’—z7#"'&547632—%$%$(#$% ˇ—‚æ' '+'"&'&5475767574>32◊˛∞  :‡92 {˝x"  m≥o  (ˇÚ1«#"'&547632654'&#"32AAF|FAAE~('%D=$''/!AÉBgeABBAcgCE˛Ø$BE$!"$Ö%+ˇ˙ªæH%2#&'&76?627;276=#'&?167676?>2322332ã ›H    D5  /W'   º (+˛À  ˇ¸ «Q%+!#'&54?6?654'&#"'.?67>32:632767>?>"  ˛É gS ^(  10@"Q81 0 $7# ∂ ~  >3;+  7 $%7  %$  <ˇNº S>767>54'&#"'&'.?>767>32#"&547633327>7654'&&'&ÄL+6(   $3,A?=CX4B" 0  2":ê## . +  1E82\^?')')D  ˇL.Õ9?%#*&"#+'&5&7'+&'&?15767232$27&7,  < e{:!G ˛õ7p6" 4=   N/Ü ˛¨ V7é6ˇO‚…K+'#"'&547632327>7654'&'&'&'.6?67676fl n?9cs%'&'# ?$*-%( &%/.~é  %WbmB  )0*'! 0ˇÚ(n+=#"'&547676767676232654'&#"32  ?,1:{FA##=FO(*&% *"'! ;2,Z+#8)"1)LM-/P?EEfKBB//   ˛œ ML'" %$G'"*ˇN¿5/+.'&7'"#"'&=?67636)%-T&&"   C≠   ø∂" á'%aSTç: ƒ .åGˇÚf#3D%#"'&54>767&547632&654'&#">7654'.'32‰:8nj78 +R43id23 )2\ ))Å   9&"2+¸*5J10..I  CWE-,*+C  )e#.7G˛Â&&/00ˇK(»":'&54>767#"'&547632654&'.#"3267>7È? .#M)SW ∞SrA??Bv &.#7%ÅEhRD"9%  3M>=Y^@A˛Õ8$7 YK'#3ˇ›œ™&#"'&54>7>32#"'&54762œ !  ! !B^ !  ˛©  !!&ˇSÿ®3#"'&547632.'.6767"#"&'&547>32ƒ  !!!$$8   .  *\  !!˛à710  !*6èn'%'&%.'&767$7>è(©˛¢ Y≤  ˛‰hΩœ  j  ?†  ôE    x+RR +¢ê$?+!'&/5'57>3:3>72*1!"'&=4763!2ê  ˛  rijé&    ˛  UØ  º   # ‘    ,7ëu1"&545&547>7>7&'"./5.=476è`˛†  |«JóÌ  ÎF *mC 2R!@b   a{ˇ÷\∑4I'&'&547676765<5&'&#"#"&54632#".'.547632\*)/    ;2=' '3C6];:m $  #$›7V   F:- ##)'>=˝Í   #_ˇÉw“ѧ%#"&547632#".'#"'&5467>763267>7>72?262320327>7>7>54&'&'&#"32676763;4.'.#"32767>s,jjà™‚{|¥=j+ _''Pn  <:0*KH!       "$<R31-*b*)SÖiü-   ˛¥% #5 îII„ƪÅÇ  ZèBt0d  7)%4@""<N &W97   33R! &#mûEm*Tif  ->2F ,, ˇ¸°Äá$#&"'&5476;2674.'&'.'&#1#'3:760#&+.7>3276767'&7>7676:;:;223&' v®  3   :n)   µ1   À     9\   ˛W,   <-TW(%  Œ À880 b990Aˇ˙…î=Tq'&#"+&54?362>7654'&+".56737632&654'&'&":23676767654'.'.'&'&'*#*#32ê91!*&N*XSQD    * MÓH"#.1 p'.    ,'    *1=UR3H:#! 1_2$% /&?" 4¬˛’&8# ñ38ˇÌ!ôM%'&#"#"'&5476327632&/&'&#"32767>7630  1'%ªuknx¡Uk   54LzGGOOy MB % ∫VP__íöaa$ 6+    D%%@BosLJ5  ˇ¸5ìD`#"'&67;632727676747>756=4&'.+".76?363:654&'&'.'&'."327∞Ö%I44@Tåˇ#    “j K +/#=() (ôXLXõ8f[# ^$ ˛CgH#?9!  ˛  Dˇ¸®å≤%#"#"#+.'&76763>3654.'.+*&'&/.'&?636322"&'".5&'.#&#&#;2>76757>;'&'&'#';267676767>?326ß:[QÉ_Z2  &     ¬Öo:  #.# ;?  .1>8%7$*  æ !   0\ 2 .≤ # /y ! í# .  'ˇ¸Yãè/4.1.'&+:3:32363:>2>34>5>76#"'5&'&#"'3;#&"'&76?367654'.'#'&'&5474767>3!32L  8N     ! 7 !"# (   ƒU !   #º|m   ú   ®"∏    † 9ˇÌ@õâ%""#"'&54676767>32212?63:3#.'.#"32767654'45<7&'&/".'&7>7;727  <T,# ´lc :=D"O-Ks  XN+F9G Dq 28 )*  m∫ ˚27 ^^è%G"E20  "(  OFF{*&#C   ˇ˝kèú$#!"&'&7>;276=#"';6+!"'=&?6367654'&'#'&'&47676;732+"7272754.'.+.6757>3676#3C ˛“  # JTS^#   ˛Ú  Öz !$ FRR_  )ea  S    ¥¥ #° ôò    ?OOTT 4ˇÁuãD##:#'"'&547676?'4.5".#.7576327;T$|| %   ,6] ã/ 4˛à   &  _  !ˇ¶˛flíü\2*1"##"'&54763276767654'4'&#/*+&'.'&70>7>;6g    .BW2"&     (    mä  ˛E"@.%%94)  !#bÈˇ  ˇ˚1éõ≥67>23:7267676##32+&#"+&'&7>7;27&'.'.'.'.'.'.#32*1&"'&767627>54'&+&'&'#">7676767&/   <56W" ùq D &! (  KQÑ -     & àî  !  $É ( -:6  ^  !* +    4   ©    û π'FB ˇ˘£êX$#&'&'&76?36;2>1654'&+.'&763672""#;276?6ú bQ◊^    #  5NPe   +47>!#» 1A )t  ˛]*. ˇ˘ıç£%&7632>76'.'*#"' ##'+&'&673567>76746756=67>765'&'.76767217?6327;2232#'"&'5ô' /ú ! — " VÑ    <M% ‘JÜ#&E    Vª   1,RKE f˛Æπ˛‹(      ,T)L!C;  ˛>†    ˛ñ6   ˇÒå£n1#'&'&'./;76#&&'&763265.#&'.54763624/5#&'&'0.5&7>372â '   "A+(„   ^s(    S<™ &I≠"b ˛ &E+(‚˛∞/   √   ˛K)*  5ˇÌeõ&#"'&547632654'&#"327676˙kmv≥µwnmvπ∂0 LJzc<=M*/5?-+>^éógg__éòee˛<+4yLJADouM !#ˇ˘}ìHX#"'7;'&"/5&=>3274654.'4.#'&'=467>767632654&'.32>7gKMí *) !ïû ! 0  $;C[1P O,â 8#( ';!d:9Ä  ¶    3¡7%,6 ˛Ï  -ˇ-íõ,F+#"./&'&'&547632654'&#"327>76u  *[\1K©fbpx∏¥pj%$@b1=0#¬IFx%! @NKuC2z3&9 [\àñee\]è:h.J'0& U+ÜSP KyÄUS( #ˇÒìÜñ#*"#"'&'&'&'&'&'.''3262623:"#&#'&'&7=>:3276=4.'.#"'&76?632654&'.#"76  ( &:1'  %˛    $ #  Cøe2  F"- >    ˛± 2 >- !(S 'Z0#   Y  5P91)N  _&0$4  ˛Î8ˇÌ/õà#"&'&'/.'=46762327654'.'&'.'.'&'&'&/#&'&'.547632326?62#"'.'&"#"!AC}C,      ,*:"! -99n      .==A&&.3T75   Q? +#    >$J/. y  #' "ˇ¸£}"#*&#".'&'.'&'.+;2#&"&'&?>?32276=+"#'.=6?63636223:365?6   JL )   #|Ÿ  " N0      %ø    ÷ 9r¶x   ê ?  S[  ≠ˇÌ~¶i+#"'.'&=4'&'"'&7>76322'#"32676=4'&'#/&'&76362u.   465S·S  , `fC .+oKY 1 yå}  C´ "%(ò DÒ    ∞g:6.0#S¶F  ˇÊM†c#""#654'&+'.'&7>3:162+"'.'&'&'#'&/5&67636262Ñ   ™ü  (   us  ! ÷   ⁄ ' !á~  t  ˛ô^!    6˛  Ú0 ˇÎèß#àî&'+"#17&/.'.+'&'6362#67&'+.'&7672#"*#*./&#".'&'.'&'"'&767667"']   ùUM  ) Xv 4 6lö    FÅ ÷   pn  — ' !y√  ?  +˛ì¿´  P  'yÔy  0˛¯¯  Â,(R  ˇ˝dåî$#&"'5'&7>;2627&/;2#&"'&54>7676767676?'.'&'.'".'&7>3732#"6767*+"'&6763727;#V MÕ   }ê   ¡8 ' òó   óí  cf$  -U))$ &0bπ, 7H   ú•    §•   z|   6oœ1 ˇ¸>ãc272#&"'&'&76763>76'&'.'&'.'&767>72#"7>7&+'.7>726, &û  ÿZ  $  ≈ % R  Üq    _å}  7„*:$     @;   ºØ #ˇ˝·ä\7&'6753+"0'./546757> 1;!2!276?67>#"#"##"/&,ºjj    ˛>I 1$(@~E·    Á   2G˛F  $@<!H˛˛)œ/'#.'&54676762;02)++U   b+&  ‹! µ¥   ˛i˛à  ˇ“”ª%&/&>;2À*˛∫  ò ˛˛ÈÀ6#'".=467>3>74545&'".#.=46;·U+       Ä — yó   ˛ ˇ˚3Û‡(.'&'#"'"'&'&7676?;È EI !  ob}q  zw(.4:   «ô Ãˇ›˛ˇ1ˇh+!"=4763623!236;21˛#?   â ‹  + -¬ˇ´*./&'.76372˛4P M  Í  DX  'S,ˇÙ˜Ø[l%#"'#"'&546767'.#'&5467676326;72>?>;%67532ÌJ5: !*6"#B<.A  &#!!/   ˛¯"  19(  ,(74"    3   ¢% - 5   ˇÒ+◊>V#"'#'&'&'=645&<5#&'&'.546?>>76767>?>3264'.#"32˜4FKÖ@f   Ä    \8$$'( 4l;QfDE „(  * bÃ˛¬!p# #1  ˇÙÙ∞6$#"&'&'&54767632#"'&#"32767>;›$39O&E:N+D8@?(1$$3+(>& ü8 :XbD%+$*&6-! ˇÔY·@P%'&'&5#"'&5476326'&"'"'&'&7>76766?3636232'75&#"326IDMZ:_86GL~#.  M>    362"$&5h   /?<UbDD A   ˝—  ¢1!6:%ˇÒ˚≠3;#'32763#"'&'&5476321%3&'&#"¯ LÏ/-CI.  #(FY90(;AE}ä2˛∫ü &9%$6 ) 0?Ya@AZ   ˇ˝◊m#&'&'&#"321#';#&#"5476326?6=#"54?36767>767>767632  ./  N  Y) ∫f!  2!  P[#)ü  !,@ - §'  %  3≤"  !57ˇ'≠Jaç%#"'&'&5476767&5467>7&547632676#".'#".'*'#:323'654&'.#"32654.'.'.#*'326ÂBY_å&%A#7=8<bV7@   ;Cd !Cé{   h,' $   64FUY<8 '>*. *GI21*    H.-g&" #   ˛‘   ˇ˚i⁄%ë%26;262>1>7654'&'&#"&'#'&''&76?>27;>3565/&'&'&'&67>7626767>3213:#"#"'"#"&     M SK     C-   .&    (P Q0?5 ¬M   4£&    ˛fi  %(  '   ˇ˝)ôc#".'&54632#&#"/=&767621;676=4'&#&'&'&?367>767636œ  - "p ÖB       É"   -˝ï    *ù     ˇ! ˇïˇ é\#".'.'.54>767>32#"'&5467632327676=<'&/#&'&/.54?36762¯!    ",  :\4!(!   YHxB  ˛˛ú#'' ' :> ˇË]‘y%26767&5'3"'#&"'&7632765<&5.'+&#/&'"1"#'.547;>767>2?'&7676372#;+  n K }`  %  = \u9<#Db  ZP c S( 3é    ˛u'  *!  2I ˇ¸)“C%#"'&"'&'.6?;2765&"."&#&'#'.'&6?36?63036);:     B@  %* ⁄   ˝÷  ˇ¸ä∏Fƒ%6>7>3276=4'&#"2>;2>767>54'&#"232"''&"'&75672>=4'.".#'&7464>767>>76326767>3236323'&*"&/##&   ) J    " Ú  hr # .^  B2) %%&    =]:  àO 0à  µ  :I µQ   ~'  !     "& #.    ˇ¸^æÄ%2>;6767654&#"&'+&*'".'&7>;27>=4'&/.54?>76766767632236+*'"#"    9 T&1    - 8'Q#!   %UQ/a(≤G  w)     10V ( ˇÒCÆ'#"'&547632654'&#"32676%%G36>NIHL?64*0-;1!$03( LO/-O??@_`?@˛˛C/, 1F0 ˛È?»Se&7>?>32632#"';2+&"#".'&7>;26?65=.'&'.#.654'&#"03267r  Z<V64INv*&   .b.5    ó&#1&54#W ?(1?;O^FF i    B|“'8%!™ ˛’VÆL_+'"&54>?6326?6=#"'&5476326?367636;27'&'&'.#"32S wÇ   (  JHb75FJy##"   ‘  8 $(%5)·  BÖ)>;X`CC   )(˛u S^?  <:&#ˇ˚∫∑\'&'&'&#";2#&#"'&=476;276='"'./=4767676767>>762´      oI5  $  9Gê    ë !   1°    "ˇÚO≥|&'&'&#"#".'&#5'.'&7&67632654&'&'.'&'.'&'.'#'&'&'&54>767>32"#".'0#.Î   )/-@            $  +3$ )  '17&% M'   !  B(ˇıçC%27>#"'&=#"&/.7=>767>7632#'  0j]'$   / u g a'  j&$8$°  Y  ' Ü(ˇˆpæs%'&/#"'&=4'*#&'&'0.5&767176767;632767416=4.'.'+.#"&#&/&767;67667>3>?36l6? '*'N'#  /2  x1  5   '&DΩ    Œ> ï    ˛Â ˇÙUªV&'#'&'&'&'&767676:732+"67>765&'&'#'&5<>362R &e  ì  R/E$ #    _b s 6I± ' ! )  3F;,     ˇÒP££&'#"7.#.'"'"#'6>3:76#"67676'&'*&+'&'45&6372+1'&/+"&'&'5/&'&'+&'<676232327+   N  F  %>3'   B! Hd    $F    [M    Ç   &3P "+8†  P    ¢G-5      Jç÷-¶  .ˇ¸c£¨%'&""&546;23&'&/32'&".4'=4>3676?'.'&'&'#'&74763:6323:+67>7>7&'+"'&/&7>76#3O&EA" ? ax  .,.T   &-2       ë'  & &"0 C    G      &%%S           %"5˛¯Bßz#"'&5467>7>7>?&'&/.'&?567672#""?67>4'.+'.5&67;62@  {(!'! é  ¶  B    c; à   0˛ B'!  &6     (åF3   ˇ˚Û’j$#'"&'.6=7>?"#""&'.76?>3667:6236:727267>?6fl*>GÖk ˙=       ï, Ö{!*/ !õc   2 zë|M˛Ï´‡h#'&'.547654'&'#'.'&7>73767>54.'.546767;20¶ .?35 X  ^< . + =] ß " .P; W5+0*D   ? L+"33     -+M ? ”ˇ–Gu(+&"+"'&5467>;7;2F     ¶˛Z  >  O˛Ï®‚V%'.74741=767>7654'&547>7&547>54.'.'&74>® 99X "  ? h     _<=$È 17U?? !28O= @j8&   ?@W) ˇˇ‘>ºK#"/#&'&'&'&#"'#'&'&5676322232>7>;;</E>^     /1F:X     ì'B82    O560   6˛Ó‹À""'&547632+"'&75762‹F## & & %9{$$"˝ì "œˇ0∏OYg23#".'32767>#*&*&"&"''+'.75?&'&5463:757>&#"| '6c Nx :+ùo+ m'"N f/˘   q<F  ë37?oùo fi+.C  ˇˆ˛¸!‘í7.?656767>;676767>7>32#"'&'.#"732#'6323267654'&54632#"'./.'&'&#"#"'&5476767#*&0  } .. 63  %*W*o ñ2*(,&   '$FDWA7   4"  *&-&/_'  3G&yN$!  )  0j◊^ !  ' (Q?=#  '  )'*#/7A3|sSg%/#"'.'/?.'.54>767/?67632?&4'&#"32>7j.0 )3 2-3 2-2 2 0.21è)*9# ))9$s.1  2.3   2/3  2/2 ))1ëx** $<** ˇ„ˇ·)⁄•®676326732+:;7>5&'+.=46;76"32+73#'#"#;20"&#&#"'&?>;276='+"&=4633'#"&=46;'&'&'.'&545#764 n   [F  9cy  r"    |u  5e`b5   Hπ :2    )+ ´5     3†'+#   ›%”ˇ—Fu +55;+55;-AAAA∆}˛É˛ |˛Ñ˛˙“‘sä%#".'&54763:327>7>4.'&'&54767632#"./&/&#"4&'&'&'&'&'464“O,6*/ 7     f5>M,5*0!#*     S ! f%" 1?AqT/ - ç^mbxV1  *     w8:;.D'K$$#%65(Ta4^`.  »]r#".'.54632#"&462]#  2##ò #22F AH #2+" 2F2 ˇ⁄fiR_&'45'.#"327>#"'&5476762326?3&#"27>54'+". &7>32 ,:#$$"@N0  AM+nKLQHe   >L=f+U™ÚU+*U  ı·˛ƒ·p%V`4û·™$),OX-+? $0HIlqKC"*,U{z¨V,g=zVc  Hü„„>r%3‚ˇ˛y.ª0A#"'#"'&54676754&#"'&54>7>326?'5327> 6""&2( 7 &9 • ¶-%"+     ;S+  ˇˇp«!%+/?;'+/?;K } } $ ?@ fi_) g5 3i ) ≥∑ "Æ™"Õª$ ÑABÜ $.ùè %+=!#=3!3vB˛,/ùflC˛≈ˇ”Ê 4D^x4'&#*67>2654&'&#"2123:362367#"&547>32"#"/32+&32%676326261>54/".'&'µ ( ™ >+,W|>4  M35*Ræ9rãP°Âr9ãP°Â‡ Å  OCH^]˛ø   K√Ş˝Oi?i,X ')B3% w™Qãs:Á¢£t9:Á˛c≥N"  2j     Ttpˇ€nX#!"'&=46;!:n˛‹    - Gäæ "'&547624&"26ämõ5665õmh0D//D0Mn77MN77nN#00#"00.ˇÕêŸRz*+#&'&/=47=#"'&=<6?6;5<5&4546;:32"*#!"/./=4763272è∆    »  Ã'… r˛Ä  µµÉó       º  ˛F    ˇ1üu3+"&=7676?>53>76767676767<6454'&#"'&=67>32#32765>56;2(  Ë 9     ),64    % +M#  2   ?&/       ˇÈ !ü^#"'&54>7>3232767654'&#"&/5.7676?14'.#"'&?5>7632!!' +$.      #  0  !  '0- %  ® 9 &     % % + YΩ:Ø"#.?>;69è1 U  䨧 ˇfi˛Ì˙Ø8+*+"&5++"'&5&'&'.54767:3276˙ P26 GEv# | u¸«8¸≈ ‘87j<;3 œh#"&'&47632œ  !     @Mˇ$.627654&5#'.46?;#"'.7b  R*   π  å % #+  #  û2#&".54?'#".'&?670>325;2 QP #  A -  ;)&ß'%˛Ë ydª!#".'&47624'&#"3276d>#,(331î24p"; /ä..-/T+-v«!7/;+?+?/;„_) h5 5h )T{ $ ?? $ { Áº$ ÖCBÉ $¨≥ "™Æ" ∑ ˇ≈—≠,Kru$++"'&'=7#"=?6320+"&'&>7?6;2#&"&=6?5#"&'&?67>232365—  n'± L˛( Ÿ )˛ç SO   C  .  f A D ‚ © ˝c  û  ˛¬)#© )$˛Á ∑  ˇ≈”≠bŪ%3+"&=7>76767>54'&#"*1"=676323:7>5>;2+"'&767>;2#&"&=6?5#"&'&?6?5>23:362   Ë   "   *,,>    %  +J˛'  › " ˛ç SO   D    #     ?&& 0     J˝b § ˛ƒ  #™ )# ˛Òˇ¯ˇƒ∂≠*Böù.'=7#"'.7=?632++"%6;2#'".'4&6#"'&54>7>32327>7654'&#"'&'.>767654&'.#"'.7676325! n  ±  "˛‡  ˛' Ó$+$/      0  !''0-!%6“( D ‚ ©0A ® ˝d ∏(" &       /+ ˛∂ ˛ÓYÀL#".'.54>2#"'&'&54767>54'&'&67>327632##  " 6C6]:. R1   91>' '4{$   ˝≤)'=0Fo9   $G8- " ˇ¸qì23&'#&"'&5476;2674.'&'.'&#1#'3:760#&+.7>3276767'&7>7676:;:323&'&'.76372;2f,∏ v®  3   ;o#   ¥1   À   $,T"  9\   l990A˛î   <-+V,(%%  Œ "', Ea À880  ˇ¸uà23&'#&"'&5476;2674.'&'.'&#1#'3:760#&+.7>3276767'&7&'&?>37:232;2f,∏ v®  3   ;o#   ¥1   À 7a  ì  9\   l990A˛î   <-+V,(%%  Œ  £ †À880  ˇ¸i#•¨/'.75?5>?26:36#&"&'&5476;2674'&'.'&#1#'327:6230#&+.7>3276767'&7>7676:;:;223&'Âa rm b   " ' vß  4   9q,   µ1     À    9\    ˛W,Pó XZ  ú  ¸®    <-Gc (%  Œ À880 b990A ˇ¸Jü¶;2#&"'&5476;2674.'&'.'&#1#'3:760#&+.7>3276767'&7>7676:;&'&'"#"./7>323276767623&'S 9\    v®  3   ;o#   ¥1   À %   D@5G% # Ï,* 5À880     <-+V,(%%  Œ   JU,  ˛?990A ˇ¸8ä†23&'#&"'&5476;2674.'&'.'&#1#'3:760#&+.7>3276767'&7#".54632;:;2#".'.54632f,∏ v®  3   ;o#   ¥1   À"7'&   9\   ÷7(   7'#l990A˛î   <-+V,(%%  Œ  #2$ À880 F2 #2  ˇ¸Ä Åà654'&#"32>;2#&"'&5476;2674.'&'.'&#1#'3:760#&+.7>3276767'&7&'&463223&'™  e)9\    v®  3   ;o#   ¥1   À )R;2v,Ô  c.5&À880     <-+V,(%%  Œ  &jK˝ˇ990Aˇƒˇ˙Œ샠%76;2#!"&754636?5#321#"&#&#"+"'&7>2367676757061&#"'&?5>376362+"'.'&'&'&5&'&+7272767=>;2"'.'.'.1;3:6367>767461%4=|    ˝‹ "!¡V   "2(&   K”:.v     ∆x     { #  1  ˛P:Hª k Pv    ." / ( ´!  ì   ù %ìÃVx8ˇ!ô7627654&5#"'.?&'&5476327632&/&'&#"3:767>763'&#""##"&'.V    Dí]cnx¡Uk   54LzGGOOyMC % 0  1-;   &7  æ gQ^çôaa$ 6+    D%%@BosLJ6 VP  # ##ˇ¸®q÷%#"#"#+.'&76763>3654.'.+*&'&/.'&?6363&'#5&'5#.4>7637222"&'".5&'.#&#&#;2>76757>;'.'.+;267676767>?326ß:[QÉ_Z2  &     Ø} ?YW  j8  #.# ><  . #<:%7$*  æ !   0\ IS-S% 2 .≤ # 2Å å! .  ˇ¸®uÕ%#"#"#+.'&76763>3654.'.+*&'&/.'&?6363&'&?63722322"&'".5&'.#&#&#;2>76757>;'.'.+;267676767>?326ß:[QÉ_Z2  &     i[ 8 &e  •($o:  #.# ><  . #<:%7$*  æ !   0\ £  Æ2 .≤ # 2Å å! .  ˇ¸®i“‹%#"#"#+.'&76763>3654.'.+*&'&/.'&?6327#'.75?5>?2623632"&'".5&'.#&#&#;2>76757>;'.'.+;267676767>?3262323&/ß:[QÉ_Z2  &     12d #  c  #.# ><  . #<:%7$*  ˛ScM$uæ !   0\  ú ó2 .≤ # 2Å å! .  ÀXˇ¸®5 –#"&463"#".54>7>3#"#"#+.'&76763>3654.'.+*&'&/.'&?636322"&'".5&'.#&#&#;2>76757>;'.'.+;267676767>?326Ú66(&77&ô76'" "ú:[QÉ_Z2  &     ¬Öo:  #.# ><  . #<:%7$*  50D01B11!"0   ˝â !   0\ 2 .≤ # 2Å å! .  4ˇÁtqh*./&'.76372+#:#'"'&547676?'4.5".#.7576327; 4P M  >|| %   ,6] ± DX  'S,( 4˛à   &  _  !4ˇÁtuf+#:#'"'&547676?'4.5".#.757632&'&?637227;T|| %   # 1X è ] ã 4˛à   &  _  ! § ¨ˇÁ¶idq76767>?'&'&'.75767"/.75757>?636#*##32#'"'&542327&/8"  Y  0/ W    êô .-Kj$É8 _ !  ú  ó    4˛à    `XˇÁ©8j#"'.54632#"&4632+#:#'"'&547676?'4.'"'.#.75763227;ú 2$!D$ ¿D-#22#-"«åû %   Is #2#2  #22F2î 4˛à   &  _  !ˇ¯KõNÇ#"#"'&5476;232767146<=+.=476;54.'.#"&5467;7632654'&'.'.#"#72#32767>«ÑK%45?:%H8sFA  $ N HSS•7^&O ,. ï óJ%#$$:SZùq^.   w  x   ˛E@N@64»õ -ˇÒãJp®#'&/;76#&&'&763265.#&'.5476362<'4'&'4.#&'0.5&7>372&#"'&'"#"*./7>3232767676à '   Ó„   ^s(    S<™&I≠ ’"$?6I&  GB+*  " h˛ ¯„˛∞/   √   ˛K)  π ?*,+ JU    5ˇÌeq=%654'&#"327676#"'&5476323&'.76372∑ LJzc<=M*/5?-+Nkmv≥µwnmvπ 9US" x◊+4yLJADouM !#ë^éógg__éòeeBV Ea 5ˇÌeu5%654'&#"327676#"'&54767&?637∑ LJzc<=M*/5?-+Nkmv≥µwnm_ç6 %`  ñ≠◊+4yLJADouM !#ë^éógg__éòeR £  •5ˇÌeiIQ%654'&#"327676#"'&54767&'.75757>?26:36#'632&'∑ LJzc<=M*/5?-+Nkmv¥∂vmmD[ b   " _ Nfle)-H=◊+4yLJADouM !#ê^éófg__çòe: ú  ó {S5ˇÌeI@W#"'&54767&'.#"#"&'=>3232767676654'&#"327676ë$mNkmv≥µwnmo¨   D@4F% #( LJzc<=M*/5?-+- ?* @]éógg__éòe_   JU,  ˝ü+4yLJADouM !#5ˇÌe8]%654'&#"327676#"'&54767&'&5467>32632"1.'.54632#∑ LJzc<=M*/5?-+Nkmv≥µwnmOn     6'    j◊+4yLJADouM !#ê]éógg__çôdD$    #  #2    dU¬PU##&'&/&'#"&'./&'&54676?'&76?6267676723¥  Kº≈:Ü   æπUxMp  3    Dû û1f °ùCd7c2ˇ∑âø.9G'467>?&547632?>#"'/&'&767&#"654'32WKvvªBy4?   3pt~∏~pP ≤”öLigCEº;26F+à,L_w( NaíògfG 6^éôgh8X ∑Ìõ<JMy4ZLjgL8K/í/:ˇÌ~qä'1'./#&67>372+#"'.'&=4.'.#"'&7>76322'#"32676=4'&'#/&'&76362' .3 S !N.   465S·S  `fC .+oKY 1 yå∞  35  NX6  C´ "%(ò D     ∞g:6.0#S¶F  ˇÌ~uÑ'.?6372+#"'.'&=4.'.#"'&7>76322'#"32676=4'&'#/&'&76362] ú 5 $a .   465S·S  `fC .+oKY 1 yåj ¨  £ Û  C´ "%(ò D     ∞g:6.0#S¶F  ˇÌ~iYé+#"'.'&=4.'.#"'&7>7632&'&75?5>?2623662%'#"32676=4'&'#/&'&767&/u.   465S·S  `G7 `  "  _kx˝ˆ   .+oKY 1  p}  C´ "%(ò D    ú ó   ∞g:6.0#S¶F  XˇÌ~8%í#"'&5467>3#"'&5467>32+#"'.'&=4.'.#"'&7>76322'#"32676=4'&'#/&'&76362X66'& j6&&  ∫.   465S·S  `fC .+oKY 1 yå82F2$  4 #2$   ö  C´ "%(ò D     ∞g:6.0#S¶F   ˇ¸?uz'.?6372272#&"'&'&76763>76'&'.'&'&'&7676362#"7>7&+'&7>3627û6a , &û   ŸZ  $  ≈ %  ÀS  Ür   _çe ¨§Ì  7„*:$     @;   ºØ ˇ˚éìmÄ+32#"';#&"'&756763267>=4.'*#'#0"+"&"&+"'&=46327320654'.'&#"#326q ! -*(I''Pë$ */ ©Ñ   díF/ (A !'>H  5Y/O7    ,}    ˛£)E*˛ËˇÔZ«8|&'#&'&547>21;676=476767632#"'67>3267654'&#"./&547>263>7654'&#";A yW   $;ZdA<&&'@%+2$N   b & !-      $Ël.5.@56O<08R(Hb  /y    44  "/A˛˚'ˇÙ˜ízã'#5&/#&676372#"'#"'&546767'.#'&5467676326;72>?>;%67532gGY a(áJ5: !*6"#B<.A  &#!!/   ˛¯"  — IS  UQ˛]9(  ,(74"    3   ¢% - 5   ˇÙ˜ïÉ767532#"'#"'&546767'.#'&54676767&'&?6;26;72>?>;Á"  "J5: !*6"#B<.A  &#!  > +p Æ   d 5   %9(  ,(74"    3  £  Æ   ¢% ˇÙ˜ä[lî%#"'#"'&546767'.#'&5467676326;72>?>;%67532&/'.475?5>?6361ÌJ5: !*6"#B<.A  &#!!/   ˛¯"  „ ÉvY  (' c19(  ,(74"    3   ¢% - 5   Ç  XZ ú òˇÙ˜fò©#"'6;72>?>;#"'#"'&546767'.#'&54676763201&'.'.#"1&/5>323276767667532»"    J5: !*6"#B<.A  &#!! #(   >>0/  fi"  I 5   ¢% 9(  ,(74"    3  JU    ˛ 5   ˇÙ˜V!}é#".'&5463#".'&54632#"'#"'&546767'.#'&5467676326;72>?>;%67532ë11%  >+~<, 1# J5: !*6"#B<.A  &#!!/   ˛¯"  V1B1 #!1$"0 #!1 ˝Û9(  ,(74"    3   ¢% - 5   ˇÙ˜®äõ654'&#"32>7>726;72>?>;#"'#"'&546767'.#'&54676767&'&'&4763267532  q       J5: !*6"#B<.A  &#! %%,DA/ì"     @     ¢% 9(  ,(74"    3  &j&%%˝Ù 5   %ˇÔ◊±sÄí#!32>7>7>7>#"'#"'&54767>754&#"&'&546767>32632%3.'.#"275◊˛ˆ @%   9<eB")3.4#$$ U*8 '%&BDWE(&˛÷à  Ï)    4#  !H!+0 1#  2 17  Î!8  ˇÎ∞f%#"'.'&6?4763:2>54'&#&'.75?&'&54767632#"'&#"327>3€K8 .>#      AR.6N+D8@?(1$$2+(>I& ¢ -9 ( #     U 1:UcE%+$*&6-!6 ˇÒ˘í^3&'&#"#'32?5>;#"'&'&547632&#./&'.76372"#"#Øü &5 LÏ/-AK/   #(FY90(;AE} Bb a&" "1  + ! 9%$7 ) 0?Ya@ADX Ea  ( ˇÒ˘ïS3&'&#"#'32?5>;#"'&'&54767&'&?>;2632Øü &5 LÏ/-AK/   #(FY90(;A.N >j  ® 3)"1  + ! 9%$7 ) 0?Y`@. £ Ø ( ˇÒ˘ä4<e#'32?5>;#"'&'&547632%3&'&#"%&/&'.475757>?6361Ù LÏ/-AK/   #(FY90(;AE}3)"1  ˛ºü &  }a  ('\$ 9%$7 ) 0?Ya@A (  ì XZ ú  òˇÒ˘V !V^#"&'&5463#"'.'.54632#'32?5>;#"'&'&547632%3&'&#"ß00"%>({<,  1) ˘ LÏ/-AK/   #(FY90(;AE}3)"1  ˛ºü &V0D0 #!1$"0  !1 ˛Ê 9%$7 ) 0?Ya@A (  ˇıˇ¸%íM;#&'.'5&>;276=4'"'&'&'&?&/&'.76372≈   Zv   e5P M  “  ˛˝! & +õ  "DX 'S,ˇ¸)ñ4I$#&'.'5&>;276=4'"'&'&'&?632;'.?576;6'Zw       è 1 U 9& +õ  ,˛˝! @ ¨   §ˇÙˇ¸tä4[$#&'.'5&>;276=4'"'&'&'&?632;/'.?57>?6361Yhö   £   $ Ç{Y  00  X9& +õ  ,˛˝! å XZ ú  òˇÛˇ¸ÅY5EU$#&'.'5&>;276=4'"'&'&'&?632;#"'.54632"#".'&46Ymï   û    ##I$#‚H# 29& +õ  , ˛˝! ÙH#22# F2.ˇÔ[®IY#"'&54>767632.'&'5'&.'5'&>?&'&'.?6?6654'&#"32=QMwÉMH $36='ë   _ *O>b 4 n$1-@1"%1.=4πblÉ@9@@b93 C  /   )  ˛°3K0- 1I2. ˇ¸^f{õ¡%&'+&*'".'&7>;27>=4'&/.54?>767&'&/567632327>76216236+*'"#"'2>;6767654&#"1667676701.'.#"1"; T&1    #D8K' %  9!   %U7    P  !     w)  J*+,     '1U ( S/a(≤i       ˇÒAí2G&'1'&/#.4>76372#"'&547632654'&#"3267>•  A]\!#w%%G36>NIHL?64&0-;1!$03(“ ISNXàO/-O??@_`?@˜ C/, 1F0ˇÒAïD$654'&#"3267>#"'&54767&'.?6;2≠0-;1!$03(x%%G36>NIH;^ :j ¶924ï C/, 1F0ÃO/-O??@_`?3  § ¨ˇÒAâ(T#"'&547632654'&#"3267>&/'.475?5>?636:323%%G36>NIHL?64&0-;1!$03(=  {vc %   dLO/-O??@_`?@˜ C/, 1F0X  XZ ú òˇÒAfI^#"'&5476323&'&'"#"./56763232767676654'&#"3267>˜ 4I%%G36>NIHL!&(    E9L(% G0-;1!$03(I %" @O/-O??@_`?@  J*+,  ˛= C/, 1F0ˇÒAV,@U#"&'.54632#"&'&547632#"'&547632654'&#"3267>·   #:' π9)$ '  %%G36>NIHL?64&0-;1!$03(2  !1 "0 "! ÚO/-O??@_`?@˜ C/, 1F0JW‹P/=#"&7>7632#!"'&=467>3!32#"'&4763≈ !. +  ˝‡   ˛ÿ,  =  ) Î  ï':.ˇÃ\≈->G#"'&/.67537&547632?567.#"654'32O IN|TK0  .<INÄSK'   ˛òæ( ‚%º&/13_A@#:   0<T`@@$.  Ã∏  !'=)'∏!ˇˆpí!ó.'1'&/#.4>7>372'&/#"'&=4'*'+.'.'&'&767176767;632767416=4'.+&"&#&#&'".'#'&7>7>7;67626?36ì @Z Y!"Ÿ6? '*'N'# /2   x1  “IS NX˛a   '&Dº   Œ> î#    ˛Â ˇˆpïê'.?6;2'&/#"'&=4'*'+.'.'&'&767176767;632767416=4'.+&"&#&#&'".'#'&7>7>7;67626?36›• 9g ï6? '*'N'# /2   x1  à ¨  §˝®   '&Dº   Œ> î#    ˛Â ˇˆpâeù67626?36'&/#"'&=4'*'+.'.'&'&767176767&'&75?5>?6362367&/32767416=4'.+&"&#&#&'".'#'&7>7>73‚   6? '*'N'# /b $ fñ-$xd   ÿ  ˛Â    '&Dº   ú ò: XN Œ> î#   ˇˆpVä§%'&/#"'&=4'*'+.'.'&'&767176767&'&'&547632#0#32767416=4'.+&"&#&#&'".'#'&7>7>7;67626?36#".'.54632l6? '*'N'# /.&  #   x1  ~   8(# 5   '&Dº  "! !  Œ> î#    ˛Â ‡   !1 ˛¯Bïñ#"'&5467>7>7>?&'4.#/.'&?56767"#.?56;2#""?67>54'1".+'.5&67;62@  {(!'! è   £:!i ®    K     c; à   0˛ B'!  &7   § ¨  ûF3   ˇD LY767667>765545/&546?>632#"'?6'&#"".=654'&#"32  p Z?W85J%35;#'   '^A:# õ!'$0)466,÷0Z% B ˛Ï0?=O_F# ^=   P18$"¨!˛¯BY5¥#".'.54632#".'&'.54>7>32#"'&5467>7>7>?&'4.#/.'&?567672#""?67>54'1".+'.5&67;62÷) ;*)•%  8  {(!'! è   ¶'   K     c; @H  #2%"    ∏   0˛ B'!  &7    ûF3   ˇ¸)π4$#&'.'5&>;276=4'"'&'&'&?632;'Zw      9& +õ  ,˛˝! ˇ˝ˇˆ©óÖ%#"#""'&/5476327>7="=?54'&#"'&'=05&546767;6232#*#7>;26?;0:ùFSDçTO  # >! t $ &79ON % O z  !939 $" óÅ  07. %C XØ I5 A U¬,.  ˇ‚ˇ˚ÀQ1#32#&+.5463276=#".=?536=&/&5&?67632W   ∫V :  g )Ø$8  ’:Aê(    $@,  H Nß0  ( “/ <ˇÙFòïß$#"&#"#"'&5476767>323:362;2#*+"&#./&'.+2;27675>;21+"'&'.+2;2>767>7=6567>76;654&#"32767 >¯? %6ünh6%'1=D&(P5   ≤   V^B<$        EF]>   ˛:Dn<>HEc3!” faaäcS*   S* ) ´   5~  % ¡ QP-(=?rrMJ 0ˇÔOØ=EZ%'#"'#"'&547632>32#!"#327>7632%3&'&#"654'&#"3267= &4;=O7EfvKIIKt!;4#S."!  ˛ˇ%#.%B ˛ˆ{´&!1 -)2 ï *$#::AA`]A@  %  ?,+A©Ò,K-) *B1- 8ˇÌ/v´#"&'&'/.'=46762327654'.'&'.'.'&'&'&'#'&'&'.54767&'&'&'&67>32?63:326?62#"'.'&"#"!AC}C,      ,*:"! -9)C#    èx i       .==A&&.3T75   Q? +#    >$J/!  67 ZZ ´ y  #' ˇÚúó¢&'&'&#"#".'&'&#''.5&7&67632654&'&'.'&'.'&'.5#'&'&'&54>76767#"/5&6?3632?632"#".'0#.'&   #% )/-\      "   +& `  êw   a  $ )  '17&% M'   !  § ZZ ´  B( ˇ¸?8 0ë#".546#".'.54>7>32272#&"'&'&76763>76'&'.'&'&'&7676362#"7>7&+'&7>362,66'!7E6'      ®, &û   ŸZ  $  ≈ %  ÀS  Ür   _ç82F2 #24 #2  ö  7„*:$     @;   ºØ #ˇ˝‡w%Å+"/5&>7>:12?632#"#"##"/&'&=67+""'./546757> 1;!2!276?67>YmU% j   Çm  c1$(@~E·  ºjj    ˛?I L´ £ZZ˝¢$@<!  Ê   2G˛F  ˇ˚Ûó&ë+"./&67632?6322#'"&'.6=7>?"#""&'.76?>3667:6236:727267>?6Õd a g  ëv   *>GÖk ˙=       ï, Ö{!*/ !m´§ ZZ ˛&c   2 zë|ˇ˛ˇs‡d#"'.'32+#"'&5467>326?+.?57>7;>36767676767632l 6  ?  2Ev&  398    !3 % ™   g 0:"&îÀ) '  $Cƒ¥  6U') ªY£'&/&'5#&75?5>?62363P  ga  Y   XÔ  YYú  òˇ˝»_∞6327>32+"&'.'&6 ua %a L ? ≠ZZ´ m »_ô""'.'=4>7632?632^2é1   +Q  t&=10 #  0Z√n"'&54>7>32H   ##   -¡+¡)#"&46324'&#"32>+ -5KK53&a  A KjK%.  0ˇ(b&#"'&54?;32?J1?(+2 ')"" ™ !#:F3$   ˇÙ∂i;#"'&'"1""./5>323272>7676i .0?"   >:8  Q%"+  JU   ºhØ6'4.=?>;##'5".=>7>;an  ! [ ûq    X ∞ ±  ≤ uˇr‹b%#".''"&'#"'&546?67676<'&76;7;2327676'&76?2>?;rS, %2  ##  ! $8&  ém *($%? %:dTD"  &&Z) ÅÖ! ˛Ì    ªW/ %#$".'&5757>7;62W ˛ËÊ  πE ⁄ $  %8Ø!&'$&'&54'45&767>36 3 ˛ó˛Á  ¶Aö     ,´Ê÷&#"'&547676232‰"-&%=1   ¸#$!/:0/   ,™Êœ#".'.6767"#"&'&5467>32Ê"   4   ,^50   " *ˇOÿj67#"'.547>32./5&691   *"8  f ! !-3- 7´”◊D#"&'&54767376232#"&'.5476736:32—"%$#83  · %$#8 3   ¸#!.71/  $    (71/ &   3•œœ A&'&5473767"'&54>32#'#5&673767#"&'&54>32œ "7 6 ,·##6 6  ,^  /     !!/50/  %     !!.ˇM¥j <'&54>?67*#"'&547>32#'&6767"#"'&547>32¥$";0  +‘$"9 .  +7.,  ! !-7-- ! !˛ˇ T"&'&547#""##"&=463:32;.'&7>;2>7>7632#"'&''&"È  â ç  &9  D :B  'ˇ  &%#/J: *"&$/   %& ˝‰  ˇˆˇ‚Ìà≤∆#'&'&#"72#'36:3#&"'4&'#&"'&7>736276=#"&#/&'&?67;674676767676763267632>?;2>36=*;23.'&#"76ˇ    (( B  I  U•  ãf    #   /'34; 9?!&˛E  Q;  g!,  MU¨    -+! .         Î    7#!+"  ' ˝a7«*.)'    Re™XÊ#"&54762X 9 A[--É]H($\BA./]eˇ÷¬x%5%#"&547632#"'&54>7>32#"&'&47632¬$$2$$˛®  %  $˛•$ $$'$2"%%  # ## H-ˇ©˝§!>\oì%4.'.#"2764'&#"2764.'.#"32>7> +'&7?>#"'&54632#"'&'#"'&546763267>32J7˛«8Ä    ˛Õ˛{   Ö  fl/GD22aE! ò0/GD2$ "/GD221EF2  !%*F1r   -.í.--˛æ    "- ˝]¶   lI>110HJb  ˛Éì111#00#110H$?1/ /" 0ˇˆˇ‚wÎê≤‘Ó67675>76767>230276767>#"'&'.#"72676360#&".'#&"&'#&#"'&76?;276=#"'&5<>?652567>2>76=4.#&;2%6?;2707>56=&5.#"323.'&#"74=>!@&59&"28(     /{(  ]x xx  ìi  #" R  [+ ˛’ ,6 i!2bGú 1;"    "   ;* ˛º #   Î ˛Ü 7öŒ7 '∆ˆ "Oˇ˙ˇ‚b¯&S∆–È%>762376574&*+326:2676367676=45+302223>3#&"'#&""'&7676:367>=#"/&?6?6767>756767632363232>?636323622+"&5&#"'6=/.#"736F  ˛¯  -C,   ?ó B|>  #"  @'34;6:J     — K+!!_ %6f >È  4¬»  5  Î 1;".˝Ñ  …´ -}ã   ,Rˇ£ˇ{Õ +77;m˛†.%`.%™¸Å"ˇÎˇ’€ôu%>212'"&#"#"'&'#"&=46;<5#"&=46;67>7:32676'".'5#.'&#*#32+32+327>Ö  #"VB:("'8D'4    Bõûôë 3&$ ´ WG LCn l? $NF  !2 ê PV0ˇı˚ÿ.1&".'.<1=6?;767>5#"+"'.465767632727667637;2?;23230"#"332#"'"#*'.=46;676=+/;26:+'&#&"#"&=4>3276=4'.#"'"&+'&'.+303:L"Q.   $   (UY'(  1B kRÇ      '&     cb   X"      G    J  ‡8≤   Ó      s◊‘]     _è '  ˛˜ .èé(*#&*'".'&=476336262726è  ◊˛Â   Ö¥,H3  J     ˇ‰M‘â≥«#'&'&#"72#'6:3#'"'.'#'"'&7>?63276=#"&#/&'&?67;674676767676763267632>?;2>36=*;12367.'&#"     *, H  O  ]¥  òh    #   4*88A  ?D#&˛D  XA `$0   Uø    -+! .≠     …    7#!+"  ' ˝Ü7«*.)' Ne3   R%ˇ˚fÀ≠%#&+"#'&'"1&'&6?>3>=4&4&4&'&#&#*3#&#"+"'&4>?676=045/&'&7>76767>7676767>32#"'&'.#"23326367623 Ab    $&H3.)    ?#  % $)$  U.%F  ≠ –  %∫$)W '!  gW  7í ˇ˘v‰'âñ$2>7;:362676765464=&13&'+"'&#"'5&7>3676746=#"'&76?>763:32>?67>362+&#"#635&#"32    Ç3 N 21*   %***Vl     25:? 2&& %O    Õ˙ Q  ¥ Ho)S ˝ß   §´.|ˇ˚¬“ë≥’Ô6767675>76767>230256767>#"'&'.#"7267660#&".'#&"&'#&#"'&76?;276=#"'&5<>?50567>2>76=4.#&;2%6?;2725>76=&'"&#"3267.'&#"74=4>%!F(9=!)&6;*   3Ñ+   ]Å  ÅÅ  ùk  #"    c. ˛©  /: w#6 !iM} 1;"    "   ;*  ˛·   À ˛¿ 7öŒ7 £…ƒ  "Oˇ‰≠fl&S«—Í%>762376574&*+326:2676367676=45+302223>&'#'"'#&#""'&76763:367>=#"/&7576?36767>756767632363232>?6362323:3+35&#"6765/.#"7j   ˛‚  1I/ Q C£ FDA>  #"  F*78?!:?P     €u©/$$é  ) :n3 >È  4¬»     –  1;".˝Ø  •´ -ÇR>   ,ÆVÆ 7@∆$Qò” ¨   ÄD H  v (©ETBembo designed for Eward Tufte / Graphics Press (c) 2002 Dmitry Krasny / Deka DesignETBembo designed for Eward Tufte / Graphics Press (c) 2002 Dmitry Krasny / Deka DesignETBemboETBemboSuperBoldOSFSuperBoldOSFFontForge 2.0 : ETBembo Super Bold Old Style Figures : 15-3-2020FontForge 2.0 : ETBembo Super Bold Old Style Figures : 15-3-2020ETBembo Super Bold Old Style FiguresETBembo Super Bold Old Style FiguresVersion 001.001 Version 001.001 ETBembo-SuperBoldOSFETBembo-SuperBoldOSFˇx2Ï  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`a£ÑÖΩñËÜéãù©§ä⁄ÉìÚÛçà√fiÒû™ıÙˆ¢≠…«ÆbcêdÀe» œÃÕŒÈf”–—Øgë÷‘’hÎÌâjikmln†oqprsutvwÍxzy{}|∏°~ÄÅÏÓ∫◊‚„∞±‰ÂªÊÁ¶ÿ·€‹›‡Ÿfló≤≥∂∑ƒ¥µ≈Ǭá´∆æøºåÔ¿¡uni00A0Euroffffifflˇˇ Î⁄(|œD"v⁄ì—Ì
70,488
Common Lisp
.l
1,088
63.203125
1,000
0.15958
szos/CLFM
12
2
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
3b3950eaf4db70e57278c8e5ead0dba1ce115892586a64349cd5a7c6e38b82a5
8,821
[ -1 ]
8,836
lips.lisp
zc1036_lips/source/lips.lisp
;;;; lips the non-dumb text macro system (defpackage :lips (:use :cl) (:export :process-stream :*finish-hooks* :*paragraph-end* :*paragraph-begin* :*use-smart-quotes* :*hot-char*)) (defpackage :lips-user (:use :cl)) (in-package :lips-user) (declaim (ftype (function (t) t) include-defs)) (in-package :lips) (defparameter *paragraph-begin* nil) (defparameter *paragraph-end* nil) (defparameter *finish-hooks* nil) (defparameter *hot-char* #\\) (defparameter *silent-char* #\-) (defun princ-if (x) "If the given object is a function, prints the return value when the return value is non-NIL; otherwise, prints the object if it is non-NIL." (let ((res (etypecase x (function (funcall x)) (t x)))) (when res (princ res)))) (defparameter *whitespace* (list #\Space #\Newline #\Backspace #\Tab #\Linefeed #\Page #\Return #\Rubout)) (defparameter *use-smart-quotes* nil) (defparameter *left-quote-exceptions* '(#\{ #\( #\[ #\- #\– #\—)) (defun update-quote-char (char last-char) (let ((leftside (or (null last-char) (member last-char *whitespace*) (member last-char *left-quote-exceptions*)))) (ecase char (#\' (if leftside #\‘ #\’)) (#\" (if leftside #\“ #\”))))) (defun call-or-write (object) (etypecase object (null (values)) (function (funcall object)) (string (write-string object)) (t (format t "~a" object)))) (defmacro write-char-update-state (last-char in-paragraph allow-eof c &key (fake nil)) (let ((c% (gensym))) `(progn (let ((,c% ,c)) (when (and ,allow-eof (not ,in-paragraph) (not (member ,c% *whitespace*))) (call-or-write *paragraph-begin*) (setf ,in-paragraph t)) (unless ,fake (write-char ,c%)) (when (char= ,c% #\Newline) (when (and ,allow-eof ,in-paragraph (char= ,last-char #\Newline)) (call-or-write *paragraph-end*) (setf ,in-paragraph nil))) (setf ,last-char ,c%))))) (defmacro write-object-update-state (last-char in-paragraph allow-eof object &key (fake nil)) (let ((evald% (gensym)) (string% (gensym)) (i% (gensym))) `(let* ((,evald% ,object) (,string% (format nil "~a" ,evald%))) (when ,evald% (loop for ,i% from 0 below (length ,string%) do (write-char-update-state ,last-char ,in-paragraph ,allow-eof (char ,string% ,i%) :fake ,fake)))))) (defparameter *internal-write-update-state* nil) (defun read-interpolated-string (&optional arg-char end-char (allow-eof t) error-char) (let ((output-string (make-array 0 :element-type 'character :fill-pointer 0 :adjustable t))) (with-output-to-string (output-stream output-string) (let ((*standard-output* output-stream) (end-char-nest-level 1) (last-char nil) (in-paragraph nil)) (let ((*internal-write-update-state* (lambda (obj &optional fake) (write-object-update-state last-char in-paragraph allow-eof obj :fake fake)))) (loop for char = (read-char *standard-input* (not allow-eof)) while char do (cond ((and error-char (char= char error-char)) (error "Unexpected }")) ((and *use-smart-quotes* (or (char= char #\") (char= char #\'))) (write-char-update-state last-char in-paragraph allow-eof (update-quote-char char last-char))) ((char= char *hot-char*) (let ((next-char (peek-char))) (cond ;; escaped hot-char, like \\, or escaped opener or ;; closer, like \} ((or (char= next-char *hot-char*) (and end-char (char= next-char end-char)) (and arg-char (char= next-char arg-char))) (write-char-update-state last-char in-paragraph allow-eof (read-char))) ((char= next-char *silent-char*) ;; When *SILENT-CHAR* follows *HOT-CHAR*, evaluate the ;; following form for side effects only. (read-char) (eval (macroexpand (read)))) ;; any other char, evaluate the lisp code (t (let ((result (eval (macroexpand (read))))) (when result (write-object-update-state last-char in-paragraph allow-eof result))))))) ((and arg-char (char= char arg-char)) (incf end-char-nest-level) (write-char-update-state last-char in-paragraph allow-eof char)) ((and end-char (char= char end-char)) (when (= 0 (decf end-char-nest-level)) (return)) (write-char-update-state last-char in-paragraph allow-eof char)) (t (write-char-update-state last-char in-paragraph allow-eof char))) finally (setf last-char char)) (when in-paragraph (call-or-write *paragraph-end*)) (values output-string *internal-write-update-state*)))))) (defparameter *current-macro-body* nil) (defun lips-user::read-macro-argument (&optional (arg-char #\{) (end-char #\}) macro-name) (loop for char = (read-char *standard-input*) do (cond ((member char *whitespace*) :do-nothing) ((char= char arg-char) (return (read-interpolated-string arg-char end-char nil))) (t (error "Unexpected character '~a' while reading argument for macro ~a" char (or macro-name *current-macro-body* "")))))) (defparameter *lips-readtable* (copy-readtable *readtable*)) ;; We need { to be a terminating macro character so that, in cases ;; like \blah{1}, READ will read the symbol |BLAH| instead of the symbol ;; |BLAH{1}| ;; We also want } to be a terminating macro char so that we can catch unbalanced ;; braces that are adjacent to words like "blah}". (set-macro-character #\{ nil nil *lips-readtable*) (set-macro-character #\} nil nil *lips-readtable*) (defun process-stream (stream) (let ((*standard-input* stream) (*readtable* *lips-readtable*)) (multiple-value-bind (result writer-fn) (read-interpolated-string nil nil t #\}) (write-string result) writer-fn))) (defmacro when-option ((options opt) &body body) `(let ((it (getf ,options ,opt))) (when it ,@body))) (defparameter *include-defs* nil) (defun include-defs-parser (filename) (push filename *include-defs*)) (defun main () (opts:define-opts (:name :help :description "Print this help text" :short #\h :long "help") (:name :include-defs :description "Include definitions before processing any input" :short #\i :long "include-defs" :arg-parser #'include-defs-parser :meta-var "FILE")) (multiple-value-bind (options args) (opts:get-opts) (when-option (options :help) (opts:describe :prefix "Lips Iwesome Preprocessor System" :usage-of "lips" :args "[FILENAMES]") (return-from main)) (let ((*package* (find-package :lips-user))) (mapcar #'lips-user::include-defs *include-defs*)) (if args (loop for filename in args do (let ((writer (if (string= filename "-") (process-stream *standard-input*) (with-open-file (input-stream filename) (process-stream input-stream))))) (let ((*internal-write-update-state* writer)) (mapc #'princ-if *finish-hooks*)))) (progn (let ((writer (process-stream *standard-input*))) (let ((*internal-write-update-state* writer)) (mapc #'princ-if *finish-hooks*))))))) ;;; Functions for use in text to be processed. (in-package :lips-user) (defmacro macro (name args &body body) (let ((fn-name% (intern (concatenate 'string "$" (symbol-name name)) (symbol-package name))) (num-args (length args))) `(progn (defun ,fn-name% ,args (let ((*current-macro-body* ',name)) ,@body)) (define-symbol-macro ,name (apply #',fn-name% (loop for i from 0 below ,num-args collect (read-macro-argument #\{ #\} ',name)))) nil))) (defun add-finish-hook (func) (push func lips:*finish-hooks*) (values)) ;; To define a symbol macro (defmacro defsym (name args &body body) (let ((fn-name% (intern (concatenate 'string (symbol-name name) "%%") (symbol-package name)))) `(progn (defun ,fn-name% ,args ,@body) (define-symbol-macro ,name (let ((*current-macro-body* ',name)) (,fn-name%))) nil))) ;; To define functions without evaluating to the symbol name. (defmacro defn (name args &body body) `(progn (defun ,name ,args ,@body) (values))) ;; To define values without evaluating to the symbol name. (defmacro defv (name value) `(progn (defparameter ,name ,value) (values))) ;; Setf quietly (defmacro setv (place value) `(progn (setf ,place ,value) (values))) ;; Loads the file as lisp source code, that is, without requiring the ;; *hot-char* to evaluate lisp. (defun include-defs (filename) (load filename :verbose nil :print nil) (values)) ;; Treats "filename" as if its contents had appeared in the original ;; file at the position of "include-text". (defun include (filename) (with-open-file (input filename) (lips:process-stream input)) (values)) (defmacro $! (obj) `(progn (princ ,obj) nil)) (defmacro %! (&rest args) `(progn (format t ,@args) nil)) (defmacro $ (obj &optional fake) `(progn (funcall lips::*internal-write-update-state* ,obj ,fake) nil)) (defmacro % (&rest args) `(progn (funcall lips::*internal-write-update-state* (format nil ,@args)) nil)) (lips::main)
10,856
Common Lisp
.lisp
271
29.726937
106
0.550352
zc1036/lips
12
2
0
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
5ac9e45e967e849fa46c83dda3365ab7412fc7cad9ad89f036525bc17074b353
8,836
[ -1 ]
8,837
unix-opts.lisp
zc1036_lips/source/unix-opts.lisp
;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp -*- ;;; ;;; Unix-opts—a minimalistic parser of command line options. ;;; ;;; Copyright © 2015–2018 Mark Karpov ;;; Copyright © 2018–2020 Thomas Schaper ;;; ;;; 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. (defpackage :unix-opts (:nicknames :opts) (:use #:common-lisp) (:export ;; Conditions #:unknown-option #:unknown-option-provided #:troublesome-option #:missing-arg #:missing-required-option #:arg-parser-failed ;; Restarts #:skip-option #:use-value #:reparse-arg ;; Classes #:option ;; Readers #:missing-options #:raw-arg ;; Functions #:exit #:argv #:get-opts #:describe #:make-options ;; Macros #:define-opts) (:shadow #:describe)) (in-package #:unix-opts) (defclass option () ((name :initarg :name :accessor name :documentation "keyword that will be included in list returned by `get-opts' function if this option is given by user") (description :initarg :description :accessor description :documentation "description of the option") (short :initarg :short :accessor short :documentation "NIL or single char - short variant of the option") (long :initarg :long :accessor long :documentation "NIL or string - long variant of the option") (required :initarg :required :accessor required :initform nil :documentation "If not NIL this argument is required.") (arg-parser :initarg :arg-parser :accessor arg-parser :documentation "if not NIL, this option requires an argument, it will be parsed with this function") (meta-var :initarg :meta-var :accessor meta-var :documentation "if this option requires an argument, this is how it will be printed in option description") (default :initarg :default :accessor default :documentation "if the option is not passed this value will be used, cannot be used in combination with REQUIRED")) (:documentation "representation of an option")) (define-condition troublesome-option (simple-error) ((option :initarg :option :reader option)) (:report (lambda (c s) (format s "troublesome option: ~s" (option c)))) (:documentation "Generalization over conditions that have to do with some particular option.")) (define-condition unknown-option (troublesome-option) () (:report (lambda (c s) (format s "unknown option: ~s" (option c)))) (:documentation "This condition is thrown when parser encounters unknown (not previously defined with `define-opts') option.")) (define-condition unknown-option-provided (troublesome-option) () (:report (lambda (c s) (format s "Provided a unknown option: ~s" (option c)))) (:documentation "This condition is signaled when the restart `USE-VALUE' is called with an undefined option.")) (define-condition missing-arg (troublesome-option) () (:report (lambda (c s) (format s "missing arg for option: ~s" (option c)))) (:documentation "This condition is thrown when some option OPTION wants an argument, but there is no such argument given.")) (define-condition missing-required-option (troublesome-option) ((missing-options :initarg :missing-options :reader missing-options)) (:report (lambda (c s) (format s "missing required options: ~{\"~a\"~^, ~}" (mapcar (lambda (opt) (with-slots (short long name) opt (apply #'format nil (cond (long (list "--~A" long)) (short (list "-~A" short)) (t (list "~A" name)))))) (missing-options c))))) (:documentation "This condition is thrown when required options are missing.")) (define-condition arg-parser-failed (troublesome-option) ((raw-arg :initarg :raw-arg :reader raw-arg)) (:report (lambda (c s) (format s "argument parser failed (option: ~s, string to parse: ~s)" (option c) (raw-arg c)))) (:documentation "This condition is thrown when some option OPTION wants an argument, it's given but cannot be parsed by argument parser.")) (defparameter *options* nil "List of all defined options.") (declaim (ftype (function (t) t) make-option)) (defun make-options (opts) (mapcar #'make-option opts)) (defun make-option (args) "Register an option according to ARGS." (let ((name (getf args :name)) (description (getf args :description "?")) (short (getf args :short)) (long (getf args :long)) (arg-parser (getf args :arg-parser)) (required (getf args :required)) (default (getf args :default)) (meta-var (getf args :meta-var "ARG"))) (unless (or short long) (error "at least one form of the option must be provided")) (check-type name keyword) (check-type description string) (check-type short (or null character)) (check-type long (or null string)) (check-type arg-parser (or null function)) (check-type meta-var string) (check-type required boolean) (when required (check-type default null)) (when (and default (or (consp default) (and (not (stringp default)) (arrayp default)) (hash-table-p default) (typep default 'standard-object))) (warn "Providing mutable object as default value, please provide a function that returns a fresh instance of this object. ~ Default value of ~A was provided." default)) (make-instance 'option :name name :description description :short short :long long :required required :arg-parser arg-parser :default default :meta-var meta-var))) (defmacro define-opts (&body descriptions) "Define command line options. Arguments of this macro must be plists containing various parameters. Here we enumerate all allowed parameters: :NAME—keyword that will be included in list returned by GET-OPTS function if actual option is supplied by user. :DESCRIPTION—description of the option (it will be used in DESCRIBE function). This argument is optional, but it's recommended to supply it. :SHORT—single character, short variant of the option. You may omit this argument if you supply :LONG variant of option. :LONG—string, long variant of option. You may omit this argument if you supply :SHORT variant of option. :ARG-PARSER—if actual option must take an argument, supply this argument, it must be a function that takes a string and parses it. :META-VAR—if actual option requires an argument, this is how it will be printed in option description. :REQUIRED—whether the option is required. This only makes sense if the option takes an argument. :DEFAULT—the default value used if the option was not found. This can either be a function (which will be called to generate the default value) or a literal value. This option cannot be combined with :REQUIRED. The default value will not be provided to the :ARG-PARSER." `(progn (setf *options* (make-options (list ,@(mapcar (lambda (desc) (cons 'list desc)) descriptions)))) (values))) (defun argv () "Return a list of program's arguments, including command used to execute the program as first elements of the list. Portable across implementations." #+abcl ext:*command-line-argument-list* #+allegro (sys:command-line-arguments) #+:ccl ccl:*command-line-argument-list* #+clisp (cons *load-truename* ext:*args*) #+clozure ccl:*command-line-argument-list* #+cmu extensions:*command-line-words* #+ecl (ext:command-args) #+gcl si:*command-args* #+lispworks system:*line-arguments-list* #+sbcl sb-ext:*posix-argv*) (defun split-short-opts (arg) "Split short options, for example \"-ab\" will produce \"-a\" and \"-b\". ARG must be a string, return value is list of strings." (if (and (> (length arg) 1) (char= #\- (char arg 0)) (char/= #\- (char arg 1))) (mapcar (lambda (c) (format nil "-~c" c)) (cdr (coerce arg 'list))) (list arg))) (defun split-on-= (arg) "Split string ARG on \"=\", return value is list of strings." (if (and (> (length arg) 1) (char= #\- (char arg 0)) (char/= #\= (char arg 1))) (let ((pos (position #\= arg :test #'char=))) (if pos (list (subseq arg 0 pos) (subseq arg (1+ pos) (length arg))) (list arg))) (list arg))) (defun shortp (opt) "Predicate that checks if OPT is a short option." (and (= (length opt) 2) (char= #\- (char opt 0)) (char/= #\- (char opt 1)))) (defun longp (opt) "Predicate that checks if OPT is a long option." (and (> (length opt) 2) (char= #\- (char opt 0)) (char= #\- (char opt 1)))) (defun optionp (str) "This predicate checks if string STR is an option." (or (shortp str) (longp str))) (defun argp (str) "Check if string STR is an argument (not option)." (and (typep str 'string) (not (optionp str)))) (defun maybe-funcall (value-or-fun) (if (functionp value-or-fun) (funcall value-or-fun) value-or-fun)) (defun map-options-to-hash-table (options callback) (loop :with table = (make-hash-table) :for option :in options :when (funcall callback option) :do (setf (gethash (name option) table) option) :finally (return table))) (defun find-option (opt options) "Find option OPT and return object that represents it or NIL." (multiple-value-bind (opt key) (if (shortp opt) (values (subseq opt 1) #'short) (values (subseq opt 2) #'long)) (flet ((prefix-p (x) (let ((x (string x))) (when (>= (length x) (length opt)) (string= x opt :end1 (length opt)))))) (let* ((matches (remove-if-not #'prefix-p options :key key)) (exact-match (find-if #'(lambda (x) (string= x opt)) matches :key key))) (cond (exact-match exact-match) ((cadr matches) nil) (t (car matches))))))) (defun get-opts (&optional (options nil options-supplied-p) (defined-options *options*)) "Parse command line options. If OPTIONS is given, it should be a list to parse. If it's not given, the function will use `argv' function to get list of command line arguments. Return two values: * a list that contains keywords associated with command line options with `define-opts' macro, and * a list of free arguments. If some option requires an argument, you can use `getf' to test presence of the option and get its argument if the option is present. The parser may signal various conditions. Let's list them all specifying which restarts are available for every condition, and what kind of information the programmer can extract from the conditions. `unknown-option' is thrown when parser encounters unknown (not previously defined with `define-opts') option. Use the `option' reader to get name of the option (string). Available restarts: `use-value' (substitute the option and try again), `skip-option' (ignore the option). `missing-arg' is thrown when some option wants an argument, but there is no such argument given. Use the `option' reader to get name of the option (string). Available restarts: `use-value' (supplied value will be used), `skip-option' (ignore the option). `arg-parser-failed' is thrown when some option wants an argument, it's given but cannot be parsed by argument parser. Use the `option' reader to get name of the option (string) and `raw-arg' to get raw string representing the argument before parsing. Available restarts: `use-value' (supplied value will be used), `skip-option' (ignore the option), `reparse-arg' (supplied string will be parsed instead). `missing-required-option' is thrown when some option was required but was not given. Use the `missing-options' reader to get the list of options that are missing. Available restarts: `use-value' (supplied list of values will be used), `skip-option' (ignore all these options, effectively binding them to `nil')" (do ((tokens (mapcan #'split-short-opts (mapcan #'split-on-= (if options-supplied-p options (cdr (argv))))) (cdr tokens)) (required (map-options-to-hash-table defined-options #'required)) (default-values (map-options-to-hash-table defined-options #'default)) poption-name poption-raw poption-parser options free-args) ((and (null tokens) (null poption-name)) (progn (when (/= (hash-table-count required) 0) (let ((missing (loop :for val :being :the :hash-values :of required :collect val))) (restart-case (error 'missing-required-option :missing-options missing) (skip-option ()) (use-value (values) (loop :for option :in missing :for value :in values :do (push (name option) options) :do (push value options)))))) (loop :for option :being :the :hash-values :of default-values :do (progn (push (name option) options) (push (maybe-funcall (default option)) options))) (values (nreverse options) (nreverse free-args)))) (labels ((push-option (name value) (push name options) (push value options) (setf poption-name nil)) (process-arg (arg) (restart-case (handler-case (push-option poption-name (funcall poption-parser arg)) (error (condition) (declare (ignore condition)) (error 'arg-parser-failed :option poption-raw :raw-arg arg))) (use-value (value) (push-option poption-name value)) (skip-option () (setf poption-name nil)) (reparse-arg (str) (process-arg str)))) (process-option (opt) (let ((option (find-option opt defined-options))) (if option (progn (remhash (name option) required) (remhash (name option) default-values) (let ((parser (arg-parser option))) (if parser (setf poption-name (name option) poption-raw opt poption-parser parser) (push-option (name option) t)))) (restart-case (error 'unknown-option :option opt) (use-value (value) (if (find-option value defined-options) (process-option value) (restart-case (error 'unknown-option-provided :option value) (skip-option ())))) (skip-option ())))))) (let ((item (car tokens))) (cond ((and poption-name (argp item)) (process-arg item)) (poption-name (restart-case (error 'missing-arg :option poption-raw) (use-value (value) (push-option poption-name value) (when item (process-option item))) (skip-option () (setf poption-name nil) (when item (process-option item))))) ((string= item "--") (dolist (tok (cdr tokens)) (push tok free-args)) (setf tokens nil)) ((optionp item) (process-option item)) (t (push item free-args))))))) (defun add-text-padding (str &key padding newline) "Add padding to text STR. Every line except for the first one, will be prefixed with PADDING spaces. If NEWLINE is non-NIL, newline character will be prepended to the text making it start on the next line with padding applied to every single line." (let ((pad (make-string padding :initial-element #\Space)) (pad-next-lines (make-string (max 0 (1- padding)) :initial-element #\Space))) (with-output-to-string (s) (when newline (format s "~%~a" pad)) (map nil (lambda (x) (write-char x s) (when (char= x #\Newline) (write pad-next-lines :stream s :escape nil))) str)))) (defun print-opts (defined-options &optional (stream *standard-output*) (argument-block-width 25)) "Print info about defined options to STREAM. Every option get its own line with description. A newline is printed after the options if this part of the text is wider than ARGUMENT-BLOCK-WIDTH." (flet ((pad-right (string max-size) (concatenate 'string string (make-string (- max-size (length string)) :initial-element #\Space)))) (let* ((option-strings (mapcar (lambda (opt) (with-slots (short long description required arg-parser meta-var default) opt (let ((opts-and-meta (concatenate 'string (if short (format nil "-~c" short) "") (if (and short long) ", " "") (if long (format nil "--~a" long) "") (if arg-parser (format nil " ~a" meta-var) "") (if required (format nil " (Required)") ""))) (full-description (concatenate 'string description (if default (format nil " [Default: ~A]" (maybe-funcall default)) "")))) (cons opts-and-meta full-description)))) defined-options)) (max-opts-length (reduce #'max (mapcar (lambda (el) (length (car el))) option-strings) :initial-value 0))) (loop :for (opt-meta . opt-description) :in option-strings :for newline = (>= (length opt-meta) argument-block-width) :do (format stream " ~a~a~%" (pad-right opt-meta (+ (if newline 0 1) max-opts-length)) (add-text-padding opt-description :padding (+ 3 max-opts-length) :newline newline))) (terpri stream)))) (defun print-opts* (margin defined-options) "Return a string containing info about defined options. All options are displayed on one line, although this function tries to print it elegantly if it gets too long. MARGIN specifies margin." (let ((fill-col (- 80 margin)) (i 0) (last-newline 0)) (with-output-to-string (s) (dolist (opt defined-options) (with-slots (short long required arg-parser meta-var) opt (let ((str (format nil " [~a]" (concatenate 'string (if short (format nil "-~c" short) "") (if (and short long) "|" "") (if long (format nil "--~a" long) "") (if arg-parser (format nil " ~a" meta-var) "") (if required (format nil " (Required)") ""))))) (incf i (length str)) (when (> (- i last-newline) fill-col) (terpri s) (dotimes (x margin) (princ #\space s)) (setf last-newline i)) (princ str s))))))) (defun describe (&key prefix suffix usage-of args (stream *standard-output*) (argument-block-width 25) (defined-options *options*)) "Return string describing options of the program that were defined with `define-opts' macro previously. You can supply PREFIX and SUFFIX arguments that will be printed before and after options respectively. If USAGE-OF is supplied, it should be a string, name of the program for \"Usage: \" section. This section is only printed if this name is given. If your program takes arguments (apart from options), you can specify how to print them in \"Usage: \" section with ARGS option (should be a string designator). For the \"Available options\" block: if the text that describes how to pass the option is wider than ARGUMENT-BLOCK-WIDTH a newline is printed before the description of that option. The output goes to STREAM." (flet ((print-part (str) (when str (princ str stream) (terpri stream)))) (print-part prefix) (when usage-of (terpri stream) (format stream "Usage: ~a~a~@[ ~a~]~%~%" usage-of (print-opts* (+ 7 (length usage-of)) defined-options) args)) (when defined-options (format stream "Available options:~%") (print-opts defined-options stream argument-block-width)) (print-part suffix))) (defun exit (&optional (status 0)) "Exit the program returning `status'." #+sbcl (sb-ext:exit :code status) #+cmu (unix:unix-exit status) #+ccl (ccl:quit status) #+ecl (ext:quit status) #+clisp (ext:exit status) #+abcl (extensions:exit :status status) #+allegro (excl:exit status :quiet t) #+lispworks (lispworks:quit :status status))
24,271
Common Lisp
.lisp
543
33.902394
129
0.577808
zc1036/lips
12
2
0
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
fd99d66b20ce0a41dd90aec8dddd49369c02004e6509627eb6517cfef5222dc0
8,837
[ -1 ]
8,838
lips.asd
zc1036_lips/source/lips.asd
(in-package :asdf-user) (defsystem "lips" :description "The non-dumb text macro system." :version "0.1" :author "Zach" :licence "GPL 3.0" :depends-on (:unix-opts) :components ((:file "packages") (:file "lips")))
255
Common Lisp
.asd
9
22.555556
50
0.590164
zc1036/lips
12
2
0
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
c7b8658f9ab6d712652087ee265c5a84d60d9302fbbff02c69a79e549f504203
8,838
[ -1 ]
8,856
types-utc-offset.lisp
davazp_cl-icalendar/types-utc-offset.lisp
;; types-utc-offset.lisp --- ;; ;; Copyrigth (C) 2009, 2010 Mario Castelán Castro <marioxcc> ;; Copyrigth (C) 2009, 2010 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) (deftype utc-offset () 'integer) (register-ical-value utc-offset) (defun utc-offset-hour (utc-offset) (values (truncate (abs utc-offset) 3600))) (defun utc-offset-minute (utc-offset) (values (truncate (mod (abs utc-offset) 3600) 60))) (defun utc-offset-second (utc-offset) (mod (abs utc-offset) 60)) (defun utc-offset-negative-p (utc-offset) (minusp utc-offset)) (defmethod format-value (x (type (eql 'utc-offset)) &optional params) (declare (ignore params)) (declare (type (integer -43200 43200) x)) (format nil "~:[+~;-~]~2,'0d~2,'0d~@[~2,'0d~]" (utc-offset-negative-p x) (utc-offset-hour x) (utc-offset-minute x) (let ((seconds (utc-offset-second x))) (if (zerop seconds) nil seconds)))) (defmethod parse-value (string (type (eql 'utc-offset)) &optional params) (declare (ignore params)) (let* ((sign (elt string 0)) (hour (parse-unsigned-integer string :start 1 :end 3)) (minute (parse-unsigned-integer string :start 3 :end 5)) (second (ecase (length string) (5 0) (7 (parse-unsigned-integer string :start 5 :end 7))))) (let ((value (+ (* 3600 hour) (* 60 minute) second))) (check-ical-type hour (integer 0 12)) (check-ical-type minute (integer 0 59)) (check-ical-type second (integer 0 59)) (cond ((char= sign #\+)) ((char= sign #\-) (when (zerop value) (%parse-error "The value -0000 or -000000 are not valid utc-offsets.")) (setf value (- value))) (t (%parse-error "Bad sign."))) value))) ;;; types-utc-offset.lisp ends here
2,521
Common Lisp
.lisp
61
36.442623
82
0.655088
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
d3c605b20c1a15072ffde67fc67e07bc1a800c6e113e485f20e3394eae33a910
8,856
[ -1 ]
8,857
package.lisp
davazp_cl-icalendar/package.lisp
;; package.lisp ;; ;; Copyrigth (C) 2010 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. ;;; Package definition (defpackage :cl-icalendar (:nicknames :icalendar :ical) (:use :common-lisp :trivial-gray-streams) (:shadow #:time #:standard :method) ;; Exported symbols. It could be mantained for each file separately, ;; however I think it will help to keep the API stable so. ;; Data types (:export #:ical-value #:x-ical-value #:utc-offset #:format-value #:format-values #:parse-value #:parse-values ;; Duration #:make-duration #:duration #:durationp #:duration-days #:duration-hours #:duration-minutes #:duration-seconds #:duration-backward-p ;; Period #:period #:periodp #:make-period #:period-start #:period-end #:period-duration ;; Binary #:binary #:read-binary-from-stream #:read-binary-from-file #:write-binary-to-stream #:write-binary-to-file ;; Recur #:recur #:recur-instance-p #:do-recur-instances #:list-recur-instances) ;; Properties and components (:export #:make-component #:add-property #:query-property #:delete-property) ;; Calendars (:export #:open-vcalendar #:save-vcalendar #:vcalendar #:valarm #:vtodo #:vevent #:vjournal #:vfreebusy #:vtimezone #:standard #:daylight ;; Functions #:do-property #:do-components #:add-property #:add-new-property #:query-property #:delete-property #:read-component #:write-component)) ;;; package.lisp ends here
2,652
Common Lisp
.lisp
87
22.206897
72
0.579523
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
29ffc0a39fe0264b9a2ee643def3fb050639ba1245e18b7456e0062b05c61630
8,857
[ -1 ]
8,858
types.lisp
davazp_cl-icalendar/types.lisp
;; types.lisp --- ;; ;; This file implements the iCalendar data types described in the ;; RFC5545 and provide a plataform in order to add new data types. ;; ;; Copyrigth (C) 2009, 2010 Mario Castelán Castro <marioxcc> ;; Copyrigth (C) 2009, 2010 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) ;;; This file contains code which implements the values that iCalendar ;;; properties can take. We provide a data type specifier, ;;; constructor, accessors, and utilities functions for each one of ;;; them. Indeed, we provide 3 common functions in order to turn these ;;; objects to strings and vice versa. (deftype ical-value () '(or boolean integer float text binary uri geo cal-address utc-offset date time datetime duration period recur x-ical-value)) ;;; Like `check-type' but it signals an error with %parse-error. (defmacro check-ical-type (place type) (with-gensyms (vplace) `(let ((,vplace ,place)) (unless (typep ,vplace ',type) (%parse-error "The ~a is not a ~a type." ',place ',type))))) ;;; Register a iCalendar data type in the standard vendor. (defmacro register-ical-value (symbol &key (name (string symbol))) (check-type symbol symbol) (check-type name string) `(register-translation ',symbol ,name :type)) ;;; Generic functions (defgeneric format-value (value type &optional params)) (defgeneric parse-value (value type &optional params)) ;;; Multiple-value versions (defun parse-values (string type &optional params) (declare (symbol type)) (labels (;; Find the position of the separator character (,) from ;; the character at START position. (position-separator (start) (let ((position (position #\, string :start start))) (if (and (integerp position) (< 0 position) (char= #\\ (char string (1- position)))) (position-separator (1+ position)) position)))) ;; Collect values (loop for start = 0 then (1+ end) for end = (position-separator start) for sub = (subseq string start end) collect (parse-value sub type params) while end))) (defun format-values (objects type &optional params) (flet ((format-value* (type x) (format-value x type params))) (join-strings (map1 #'format-value* type objects) #\,))) ;;;; Boolean (register-ical-value boolean) (define-predicate-type boolean) (defmethod format-value (value (type (eql 'boolean)) &optional params) (declare (ignore params)) (if value "TRUE" "FALSE")) (defmethod parse-value (string (type (eql 'boolean)) &optional params) (declare (ignore params)) (cond ((string-ci= string "TRUE") t) ((string-ci= string "FALSE") nil) (t (%parse-error "~a is not a boolean data type." string)))) ;;;; Integer (register-ical-value integer) (defmethod format-value (n (type (eql 'integer)) &optional params) (declare (ignore params)) (format nil "~d" n)) (defmethod parse-value (string (type (eql 'integer)) &optional params) (declare (ignore params)) (values (parse-integer string))) ;;;; Float (register-ical-value float) (defmethod format-value (value (type (eql 'float)) &optional params) (declare (ignore params)) (format nil "~f" value)) (defmethod parse-value (string (type (eql 'float)) &optional params) (declare (ignore params)) (let ((sign 1) ; the sign (x 0) ; integer part (y 0)) ; fractional part (with-input-from-string (in string) ;; Read sign (case (peek-char nil in) (#\+ (read-char in)) (#\- (setf sign -1) (read-char in))) ;; Read integer part (let ((istring (parse in (complement #'digit-char-p) nil nil))) (setf x (parse-integer istring))) ;; Read fractinal part (if any) (let ((dot (read-char in nil))) (unless (null dot) (unless (char= dot #\.) (%parse-error "Bad formed float.")) (let ((fstring (parse in (complement #'digit-char-p) nil nil))) (setf y (/ (float (parse-integer fstring)) (expt 10 (length fstring))))) (unless (null (read-char in nil)) (%parse-error "Junk is not allowed after a float value"))))) (* sign (+ x y)))) ;;;; URI (deftype uri () 'string) (register-ical-value uri) (defmethod format-value (value (type (eql 'uri)) &optional params) (declare (ignore params)) value) (defmethod parse-value (string (type (eql 'uri)) &optional params) (declare (ignore params)) string) ;;;; Geo (defclass geo () ((latitude :type float :initarg :latitude :reader latitude) (longitude :type float :initarg :longitude :reader longitude))) (define-predicate-type geo) (defun make-geo (latitude longitude) (make-instance 'geo :latitude latitude :longitude longitude)) (defprinter (x geo) (format t "~d;~d" (latitude x) (longitude x))) (defmethod format-value ((x geo) (type (eql 'geo)) &optional params) (declare (ignore params)) (format nil "~d;~d" (latitude x) (longitude x))) (defmethod parse-value (string (type (eql 'geo)) &optional params) (declare (ignore params)) (let* ((parts (split-string string #\;)) (length (length parts))) (unless (= 2 length) (%parse-error "Bad formed geo. 2 parts expected ~d found." length)) (make-geo (parse-value (first parts) 'float) (parse-value (second parts) 'float)))) ;;;; Cal-address (deftype cal-address () 'string) (register-ical-value cal-address) (defmethod format-value (string (type (eql 'cal-address)) &optional params) (declare (ignore params)) string) (defmethod parse-value (string (type (eql 'cal-address)) &optional params) (declare (ignore params)) string) ;;; Format-value and parse-value methods for unknown data types. (defmethod format-value ((string string) (type (eql 'nil)) &optional params) (declare (ignore params)) string) (defmethod parse-value ((string string) (type (eql 'nil)) &optional params) (declare (ignore params)) string) ;; User-defined iCalendar data types (defclass x-ical-value () nil) ;;; types.lisp ends here
6,966
Common Lisp
.lisp
174
35.402299
76
0.662363
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
9c07d96f695bf7f01504144fa3258cf4d83508433b6d227b709deb65fb9b2124
8,858
[ -1 ]
8,859
types-datetime.lisp
davazp_cl-icalendar/types-datetime.lisp
;; types-datetime.lisp --- ;; ;; Copyrigth (C) 2009, 2010 Mario Castelán Castro <marioxcc> ;; Copyrigth (C) 2009, 2010, 2011 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) ;;; Datetimes (deftype datetime () '(integer 0)) (register-ical-value datetime :name "DATE-TIME") (defun encode-datetime (day month year hour minute second) (+ (encode-date day month year) (encode-time hour minute second))) (defmethod format-value (datetime (type (eql 'datetime)) &optional params) (declare (ignore params)) (decoded-universal-time (:year y :month m :date d :hour h :minute min :second s) datetime (format nil "~4,'0d~2,'0d~2,'0dT~2,'0d~2,'0d~2,'0d" y m d h min s))) (defmethod parse-value (string (type (eql 'datetime)) &optional params) (declare (ignore params)) (flet ((ill-formed () (%parse-error "Bad datetime format."))) (when (< (length string) 9) (ill-formed)) (let ((string-date (subseq string 0 8)) (string-time (subseq string 9))) (unless (char= (elt string 8) #\T) (ill-formed)) (let ((date (parse-value string-date 'date)) (time (parse-value string-time 'time))) (+ date time))))) ;;; types-datetime.lisp ends here
1,900
Common Lisp
.lisp
44
39.931818
82
0.693933
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
3893157fd263f7b2d39826a5da51ceba6818506dab7c1fb9da4f9c457d03580c
8,859
[ -1 ]
8,860
content-line.lisp
davazp_cl-icalendar/content-line.lisp
;; content-line.lisp ;; ;; Copyrigth (C) 2009, 2010 David Vázquez ;; Copyrigth (C) 2009, 2010 Mario Castelán Castro <marioxcc> ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) (defun read-params-value (stream) (if (char= (peek-char nil stream) #\") (prog2 (read-char stream) (parse stream "#\"" #.(string #\newline)) (read-char stream)) (string-upcase (parse stream ",;:" #.(string #\Newline))))) (defun read-params-values (stream) (unlist (cons (read-params-value stream) (with-collect (while (char= (peek-char nil stream) #\,) (read-char stream) (collect (read-params-value stream))))))) (defun read-params (stream) (with-collect (while (char= (read-char stream) #\;) (let ((name (parse stream "=" #.(coerce #(#\Newline #\: #\;) 'string)))) (read-char stream) (collect (string-upcase name)) (collect (read-params-values stream)))))) (defun read-content-line (stream) ;; Skip whitespaces (newlines and spaces) characters. (loop for ch = (peek-char nil stream) while (or (char= ch #\newline) (char= ch #\space) (char= ch #\tab)) do (read-char stream)) (values (string-upcase (parse stream ";:" #.(string #\Newline))) (read-params stream) (read-line stream))) (defun read-content-line-from-string (string) (with-input-from-string (in string) (read-content-line in))) (defun escape-parameter-value (value) (if (loop for x across value thereis (find x ":;,")) (concat "\"" value "\"") value)) (defun write-content-line* (name params value stream) (format stream "~a~{;~a=~{~a~^,~}~}:~a" name (loop for (param value) on params by #'cddr for values = (mklist value) collect param collect (mapcar #'escape-parameter-value values)) value)) (defun write-content-line (name params value stream) (write-content-line* name params value stream) (terpri stream)) (defun write-content-line-to-string (name params value) (string-right-trim (list #\newline) (with-output-to-string (out) (write-content-line name params value out)))) ;; content-line.lisp ends here
2,977
Common Lisp
.lisp
73
34.835616
78
0.639792
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
3590544a1ccaa7e3a0345bfe3d8aed60e0d1af16191ceeb2fcde792b174fe4be
8,860
[ -1 ]
8,861
types-period.lisp
davazp_cl-icalendar/types-period.lisp
;; types-period.lisp --- ;; ;; Copyrigth (C) 2009, 2010 Mario Castelán Castro <marioxcc> ;; Copyrigth (C) 2009, 2010 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) ;;; This clase should not be instantiated directly. (defclass period () ((start :initarg :start :type datetime :reader period-start))) (register-ical-value period) (define-predicate-type period) ;;; Period between two explicit datetimes. (defclass period-explicit (period) ((end :initarg :end :type datetime :reader period-end))) ;;; Period from a dattetime for a duration. (defclass period-start (period) ((duration :initarg :duration :type duration :reader period-duration))) (defmethod period-duration ((period period-explicit)) (let* ((start (period-start period)) (end (period-end period)) (secs (seconds-between end start))) (if (<= start end) (make-duration :seconds secs) (make-duration :seconds secs :backward-p t)))) (defmethod period-end ((period period-start)) (let ((dur (period-duration period))) (if (duration-backward-p dur) (datetime+ (period-start period) (- (duration-days dur)) (- (duration-seconds dur))) (datetime+ (period-start period) (duration-days dur) (duration-seconds dur))))) ;;; Constructor (defun make-period (start duration-or-end) (etypecase duration-or-end (duration (make-instance 'period-start :start start :duration duration-or-end)) (datetime (make-instance 'period-explicit :start start :end duration-or-end)))) (defprinter (x period) (flet ((write-datetime (dt) (format t "~2,'0d-~2,'0d-~4,'0d ~2,'0d:~2,'0d:~2,'0d" (date-day dt) (date-month dt) (date-year dt) (time-hour dt) (time-minute dt) (time-hour dt)))) (write-string "PERIOD ") (write-datetime (period-start x)) (write-string " -- ") (write-datetime (period-end x)))) (defmethod format-value ((p period-explicit) (type (eql 'period)) &optional params) (declare (ignore params)) (concat (format-value (period-start p) 'datetime) "/" (format-value (period-end p) 'datetime))) (defmethod format-value ((p period-start) (type (eql 'period)) &optional params) (declare (ignore params)) (concat (format-value (period-start p) 'datetime) "/" (format-value (period-duration p) 'duration))) (defmethod parse-value (string (type (eql 'period)) &optional params) (declare (ignore params)) (destructuring-bind (start end) (split-string string "/") (list start end) (let ((dstart (parse-value start 'datetime))) (make-period dstart (if (char= (char end 0) #\P) (parse-value end 'duration) (parse-value end 'datetime)))))) ;;; types-period.lisp ends here
3,602
Common Lisp
.lisp
91
34.087912
86
0.657037
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
7dda338e44408f14341095abffb7c1b3a91869b2b8d94b2925eb9708b8c42a88
8,861
[ -1 ]
8,862
translate.lisp
davazp_cl-icalendar/translate.lisp
;; translate.lisp --- Dictionary between iCalendar names and Lisp objects ;; ;; Copyrigth (C) 2010,2011 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) ;;; Bidirectional mapping. (defclass translate-table () ((ical>lisp :initform (make-hash-table :test #'equal)) (lisp>ical :initform (make-hash-table)))) ;;; Table of translation tables indexed by entity. (defvar *translation-tables* (make-hash-table :test #'eq)) (defun intern-translation-table (entity) (or (gethash entity *translation-tables*) (setf (gethash entity *translation-tables*) (make-instance 'translate-table)))) ;;; Public functions ;;; ENTITY stands for any Lisp object which is used to specify a ;;; namespaces. Two ENTITY are equivalent if they are EQ. ;;; Register a translation between the Lisp value OBJECT and iCalendar ;;; name ICALNAME in the ENTITY namespace. (defun register-translation (object icalname entity) (with-slots (ical>lisp lisp>ical) (intern-translation-table entity) ;; Remove old associations for OBJECT and ICALNAME. (let ((oldlisp (gethash icalname ical>lisp)) (oldical (gethash object lisp>ical))) (remhash oldlisp lisp>ical) (remhash oldical ical>lisp)) ;; Set new associations (setf (gethash icalname ical>lisp) object) (setf (gethash object lisp>ical) icalname) (values))) ;;; Translate the iCalendar name ICALNAME to a corresponding Lisp ;;; object in the ENTITY namespace. (defun translate-to-lisp (icalname entity) (with-slots (ical>lisp) (intern-translation-table entity) (values (gethash icalname ical>lisp)))) ;;; Translate the Lisp value OBJECT to the corresponding iCalendar ;;; name in the ENTITY namespace. (defun translate-to-ical (object entity) (with-slots (lisp>ical) (intern-translation-table entity) (values (gethash object lisp>ical)))) ;;; translate.lisp ends here
2,568
Common Lisp
.lisp
58
41.482759
73
0.742297
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
5a9d85933c57a5f7b0fb3a7b36b52a4db5670f350b763e175555892e74e918c5
8,862
[ -1 ]
8,863
utils.lisp
davazp_cl-icalendar/utils.lisp
;; utils.lisp ;; ;; Copyrigth (C) 2009, 2010 Mario Castelán Castro <marioxcc> ;; Copyrigth (C) 2009, 2010 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) ;;;; Misc macros (eval-when (:compile-toplevel :load-toplevel :execute) ;; Given two string designators, concatenate the strings and intern ;; the symbol in a package. By default, current package is used. (defun symbolize (string1 string2 &optional (package *package*)) (intern (concatenate 'string (string string1) (string string2)) package))) (defmacro until (condition &body code) `(do () (,condition) ,@code)) (defmacro while (condition &body code) `(until (not ,condition) ,@code)) (defmacro with-gensyms ((&rest vars) &body code) `(let ,(loop for i in vars collect (etypecase i (symbol `(,i (gensym ,(symbol-name i)))) (list `(,(first i) (gensym ,(second i)))))) ,@code)) ;;; The famous and ugly once-only macro. (defmacro once-only ((&rest names) &body body) (let ((gensyms (loop for n in names collect (gensym)))) `(let (,@(loop for g in gensyms collect `(,g (gensym)))) `(let (,,@(loop for g in gensyms for n in names collect ``(,,g ,,n))) ,(let (,@(loop for n in names for g in gensyms collect `(,n ,g))) ,@body))))) ;;; Iterate ELEMENT across LIST and collect the the results of ;;; evaluate BODY in a progn. ;;; ;;; for example: expands to: ;;; ;;; (let ((list '(x y z))) (progn ;;; (progn-expand (var list) (1+ x) ;;; `(1+ ,var))) (1+ y) ;;; (1+ z)) ;;; (defmacro progn-expand ((element list) &body body) ``(progn ,@(loop for ,element in ,list collect (progn ,@body)))) (defmacro with-named-collector% ((accumulator initial collector) &body body) (check-type accumulator symbol) (check-type collector symbol) (let ((head (gensym)) (tail (gensym))) `(let* ((,head (cons :accumulator (copy-list ,initial))) (,tail (last ,head))) (flet ((,collector (item) (let ((c (list item))) (setf (cdr ,tail) c) (setf ,tail c)))) (symbol-macrolet ((,accumulator (cdr ,head))) ,@body))))) (defmacro with-collect (&body body) (let ((accumulator (gensym))) `(with-named-collector% (,accumulator nil collect) ,@body ,accumulator))) (defmacro with-collectors (names &body body) (if (null names) `(progn ,@body) (destructuring-bind (name &optional initial (collector (intern (format nil "COLLECT-~a" (string name))))) (mklist (car names)) `(with-named-collector% (,name ,initial ,collector) (with-collectors ,(cdr names) ,@body))))) ;;;; Declarations and definitions facilities ;;; Like `defun' but declare the function as inline. (defmacro definline (name args &body body) `(progn (declaim (inline ,name)) (defun ,name ,args ,@body))) ;;; Define a variable-arity transitive predicate from a body which ;;; define a transtivie relation of arity 2. The body is contained in ;;; an implicit block. (defmacro define-transitive-relation (name (arg1 arg2) &body body) (with-gensyms (argsvar) `(defun ,name (&rest ,argsvar) (loop for (,arg1 ,arg2) on ,argsvar while ,arg2 always (block nil ((lambda () ,@body))))))) ;;; Define a predicate named NAME in order to check if the type of an ;;; object is TYPE. If NAME is omitted, NAMEP is used. (defmacro define-predicate-type (type &optional name) (declare (type (or symbol null) name)) (let ((fname (or name (intern (format nil "~aP" type))))) `(defun ,fname (x) (typep x ',type)))) ;;; Mark a function as deprecated. When FUNCTION is called, it signals ;;; a simple warning. If REPLACEMENT is given, it will recommend to ;;; use REPLACEMENT instead. ;;; ;;; FUNCTION and REPLACEMENT are symbols. (defmacro deprecate-function (function &body ignore &key replacement) (declare (ignore ignore)) (declare (symbol function replacement)) `(define-compiler-macro ,function (&whole form &rest args) (declare (ignore args)) (warn "Function ~a is deprecated. ~@[Use ~a instead.~]" ',function ',replacement) form)) ;;; Define a printer for a object of class CLASS, bound to VAR. The ;;; body of the macro is supposed to write to the standard output ;;; stream. (defmacro defprinter ((var class) &body code) (with-gensyms (stream) `(defmethod print-object ((,var ,class) ,stream) (print-unreadable-object (,var ,stream :type t) (let ((*standard-output* ,stream)) ,@code))))) ;;;; Sequences ;; TODO: Enhanche this with a optional finally section, mantaning ;; backward compatibility is not need (defun %do-sequence (function sequence &key (start 0) end) (etypecase sequence (list (if (not end) (loop for x in (nthcdr start sequence) do (funcall function x)) (loop for x in (nthcdr start sequence) for i from start below end do (funcall function x)))) (sequence (loop for i from start below (or end (length sequence)) for x = (elt sequence i) do (funcall function x))))) ;;; Iterate for the elements of a sequence for side efects, from the ;;; START position element until the END position element. If END is ;;; omitted, then it iterates for all elements of sequence. (defmacro do-sequence ((var sequence &key (start 0) end) &body body) (declare (symbol var)) `(%do-sequence (lambda (,var) ,@body) ,sequence :start ,start :end ,end)) ;;; Return a fresh copy subsequence of SEQ bound from 0 until the ;;; first element what verifies the FUNC predicate. (defun strip-if (func seq &rest rest &key &allow-other-keys) (subseq seq 0 (apply #'position-if func seq rest))) ;;; Return a fresh copy subsequence of SEQ bound from 0 until the ;;; position of X in sequence. (defun strip (x seq &rest rest &key &allow-other-keys) (subseq seq 0 (apply #'position x seq rest))) ;;; Make sure that ITEM is an element of LIST, otherwise this function ;;; signals an simple-error condtion. (defmacro check-member (item list &key (test #'eql)) `(unless (find ,item ',list :test ,test) (error "Not a member of the specified list"))) ;;; Check that the type of every element of LIST is TYPE. (defmacro check-type-list (list type) `(dolist (x ,list) (check-type x ,type))) ;;; Like `some', but it works on bound sequences (defun some* (predicate sequence &key (start 0) end (key #'identity)) (do-sequence (item sequence :start start :end end) (when (funcall predicate (funcall key item)) (return-from some* t))) nil) (defun split-string (string &optional (separators " ") (omit-nulls t)) (declare (type string string)) (flet ((separator-p (char) (etypecase separators (character (char= char separators)) (sequence (find char separators)) (function (funcall separators char))))) (loop for start = 0 then (1+ end) for end = (position-if #'separator-p string :start start) as seq = (subseq string start end) unless (and omit-nulls (string= seq "")) collect seq while end))) ;;; Concatenate strings. (defun concat (&rest strings) (reduce (lambda (s1 s2) (concatenate 'string s1 s2)) strings :initial-value (make-string 0))) ;;; Concatenate the list of STRINGS. (defun join-strings (strings &optional (separator #\space)) (if (null strings) (make-string 0) (reduce (lambda (s1 s2) (concat s1 (string separator) s2)) strings))) ;;; Check if the PREFIX string matches with some substrings in the ;;; beginning of STRING, using TEST to compare the characters. (defun string-prefix-p (prefix string &key (test #'char=)) (declare (string string prefix)) (let ((offset (mismatch prefix string :test test))) (if offset (= offset (length prefix)) t))) ;;; Check if there are duplicated elements in LIST. KEY functions are ;;; applied to elements previosly. The elements are compared by TEST ;;; function. (defun duplicatep (list &key (test #'eql) (key #'identity)) (let ((list (mapcar key list))) (and (loop for (a . b) on list thereis (find a b :test test)) t))) ;;; Return a list with the nth element of list removed. (defun remove-nth (n list) (let* ((result (cons nil nil)) (tail result)) (do ((i 0 (1+ i)) (l list (cdr l))) ((or (= i n) (null l)) (setf (cdr tail) (cdr l)) (cdr result)) (setf (cdr tail) (cons (car l) nil)) (setf tail (cdr tail))))) ;;; delete-nth is like remove-nth but it could modify the list. ;;; ;;; NOTE: if you want delete the nth element of the value of a ;;; variable V, you should use '(setf v (delete-nth n v))', instead of ;;; '(delete-nth n v)', just as the standard delete function. (defun delete-nth (n list) (declare (type (integer 0 *) n) (list list)) (if (zerop n) (cdr list) (let ((tail (nthcdr (1- n) list))) (setf (cdr tail) (cddr tail)) list))) ;;; Return X if it is a list, (list X) otherwise. (defun mklist (x) (if (listp x) x (list x))) ;;; Check if X is a list of an element. (defun singlep (x) (and (consp x) (null (cdr x)))) ;;; If X is a single list, it returns the element. Otherwise, return ;;; the list itself. (defun unlist (x) (if (singlep x) (car x) x)) ;;; Build a circular list (defun circular (&rest list) (let ((result (copy-list list))) (nconc result result))) ;;; Map the function arg with the first argument fixed to ARG across ;;; the elements in LIST and LISTS like mapcar. (defun map1 (function arg list &rest lists) (apply #'mapcar function (circular arg) list lists)) ;;; Check if X appears before than Y in LIST. (defun member< (x y list &rest args &key &allow-other-keys ) (let ((sublist (apply #'member x list args))) (and (apply #'member y (cdr sublist) args) t))) ;;;; Streams ;;; Read characters from STREAM until it finds a char of CHAR-BAG. If ;;; it finds a NON-EXPECT character, it signals an error. If an end of ;;; file condition is signaled and EOF-ERROR-P is nil, return nil. (defun parse (stream char-bag &optional (not-expect "") (eof-error-p t)) (flet ((in (ch char-bag) ;; Check if CH is in CHAR-BAG. (etypecase char-bag (character (char= ch char-bag)) (sequence (find ch char-bag)) (function (funcall char-bag ch))))) ;; Read characters (with-output-to-string (out) (loop for ch = (peek-char nil stream eof-error-p) until (and (not eof-error-p) (null ch)) until (in ch char-bag) when (in ch not-expect) do (error "Character ~w is not expected." ch) do (write-char (read-char stream) out))))) ;;; An optimized version of `parse' specific for calls where ;;; `char-bag' and `not-expected' are simple strings. (declaim (inline parse-simple)) (defun parse-simple (stream char-bag &optional (not-expect "") (eof-error-p t)) (declare (optimize speed) (simple-string char-bag not-expect) (boolean eof-error-p)) ;; Read characters (with-output-to-string (out) (loop for ch = (peek-char nil stream eof-error-p) until (and (not eof-error-p) (null ch)) until (find (the character ch) char-bag) when (find (the character ch) not-expect) do (error "Character ~w is not expected." ch) do (write-char (read-char stream) out)))) (define-compiler-macro parse (&whole form stream char-bag &optional (not-expect "") (eof-error-p t)) (if (and (stringp char-bag) (stringp not-expect)) `(parse-simple ,stream ,char-bag ,not-expect ,eof-error-p) form)) ;;;; Comparators ;;; Like `char=' but it is case-insensitive. (defun char-ci= (char1 char2) (declare (character char1 char2)) (char= (char-upcase char1) (char-upcase char2))) ;;; Like `string=' but it is case-insensitive. (defun string-ci= (str1 str2) (and (= (length str1) (length str2)) (every #'char-ci= str1 str2))) ;;; Check if X and Y are not eq. (definline neq (x y) (not (eq x y))) ;;; Anaphoric IF. (defmacro aif (condition then &optional else) `(let ((it ,condition)) (if it ,then ,else))) (defmacro second-value (form) `(nth-value 1 ,form)) ;;;; setf-based ;;; The multiple-setf macro was written by Mario Castelán. It is a ;;; beautiful form to support multiple places in zerof and nilf. (defmacro multiple-setf (value &rest places) (once-only (value) `(setf ,@(loop for place in places append `(,place ,value))))) ;;; Set PLACES to 0 (defmacro zerof (&rest places) `(multiple-setf 0 ,@places)) ;;; Set PLACE to nil. (defmacro nilf (&rest places) `(multiple-setf nil ,@places)) ;;; (modf place N) set place to (mod place N) (define-modify-macro modf (n) mod) ;;; (appendf place list) set place to (append place list) (define-modify-macro appendf (list) append) ;;;; Others ;;; Like `parse-integer' but it is not allowed to have a sign (+\-). (defun parse-unsigned-integer (string &rest keyargs &key (start 0) end &allow-other-keys) (declare (string string)) (unless (or (eql start end) (digit-char-p (char string start))) (error "~w is not an unsigned integer." string)) (apply #'parse-integer string keyargs)) ;;; Set PLACE to zero. ;;; This function is thought to use this function as default-value in ;;; optional or keyword arguments. (defun required-arg (&optional fmt &rest args) (if fmt (error 'simple-error :format-control fmt :format-arguments args) (error "A required &KEY or &OPTIONAL argument was not supplied."))) (defmacro /debug1 (form) (with-gensyms (value) `(progn (let ((,value ,form)) (format *error-output* "~%; DEBUG~@[ (~a)~]" (load-time-value (aif *load-pathname* (enough-namestring it)))) (pprint ',form *error-output*) (write-string " ===> " *error-output*) (princ ,value *error-output*) (terpri *error-output*) ,value)))) ;;; Run CODE and print information about the evaluation of ;;; CODE. Useful for debugging. (defmacro /debug (&body code) `(progn ,@(loop for form in code collect `(/debug1 ,form)))) (defmacro implyp (p q) `(if ,p (and ,q t) t)) (defun range (m n &optional (step 1)) (loop for i from m to n by step collect i)) (defun curry (fn &rest preargs) (lambda (&rest postargs) (apply fn (append preargs postargs)))) (defun rcurry (fn &rest postargs) (lambda (&rest preargs) (apply fn (append preargs postargs)))) ;;; Iterate across entries in a hash table. (defmacro do-hash-table ((key value) hash-table &body code) (with-gensyms (iter morep) `(with-hash-table-iterator (,iter ,hash-table) (loop (multiple-value-bind (,morep ,key ,value) (,iter) (declare (ignorable ,key ,value)) (unless ,morep (return)) ((lambda () ,@code))))))) ;;; Return M si 0 < M <= N, and M+N+1 if M<0. (defun mod* (m n) (declare (integer m n)) (cond ((and (< m 0) (<= (- m) n)) (1+ (+ n m))) ((and (< 0 m) (<= m n)) m) (t (error "~a should be a integer in [-~a,1] or [~:*~a,1]." m n)))) ;;; iCalendar utilities ;;; Check if string starts with "X-" or "x-". (defun x-name-p (string) (string-prefix-p "X-" string :test #'char-ci=)) ;;; utils.lisp ends here
16,500
Common Lisp
.lisp
403
35.925558
100
0.636171
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
419bd97a6c32b7fe51409aae27ffb37541ddbad5036b709c79a673b8045684c1
8,863
[ -1 ]
8,864
types-binary.lisp
davazp_cl-icalendar/types-binary.lisp
;; types-binary.lisp --- ;; ;; Copyrigth (C) 2009, 2010 Mario Castelán Castro <marioxcc> ;; Copyrigth (C) 2009, 2010 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) (deftype binary () '(array (unsigned-byte 8))) (register-ical-value binary) (defun read-binary-from-stream (stream) (let ((buffer (make-array 1024 :element-type '(unsigned-byte 8))) (content (make-array 1024 :element-type '(unsigned-byte 8) :adjustable t))) ;; Read from STREAM sequences into buffer and fill content. When ;; content is exhausted, we will adjust it. (loop for index = 0 then (+ index nbytes) for nbytes = (read-sequence buffer stream) until (zerop nbytes) when (< (- (array-dimension content 0) index) nbytes) do (adjust-array content (* 2 (array-dimension content 0))) do (replace content buffer :start1 index :end1 (+ index nbytes)) finally (adjust-array content index)) ;; Finally return a binary instance. content)) (defun read-binary-from-file (pathname) (with-open-file (in pathname :element-type '(unsigned-byte 8)) (read-binary-from-stream in))) (defun write-binary-to-stream (binary stream) (write-sequence binary stream) (values)) (defun write-binary-to-file (binary pathname &key if-exists) (with-open-file (out pathname :direction :output :element-type '(unsigned-byte 8) :if-exists if-exists) (write-binary-to-stream binary out))) (defun binary-length (binary) (length binary)) (progn ;; The binary data value must be written as a base64-encoded ;; sequence. Therefore, the ENCODING=BASE64 parameter should be ;; present. We don't check this here; instead, we trust in the caller ;; (property code basically) will do the right thing. (defmethod format-value (value (type (eql 'binary)) &optional params) (declare (ignore params) (type binary value)) (base64:usb8-array-to-base64-string value)) (defmethod parse-value (string (type (eql 'binary)) &optional params) (declare (ignore params)) (base64:base64-string-to-usb8-array string))) ;;; types-binary.lisp
2,857
Common Lisp
.lisp
63
40.84127
83
0.701799
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
4bb9a6b38c046c663def8877d83430b428408cfda77328fd0e965bd01dfc6954
8,864
[ -1 ]
8,865
components.lisp
davazp_cl-icalendar/components.lisp
;; components.lisp --- iCalendar's component ;; ;; Copyrigth (C) 2012 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) ;;; Return the component class for the name COMPONENT-NAME. (defun find-component-class (component-name) (or (translate-to-lisp component-name :component) (and (x-name-p component-name) (find-class 'x-component)))) ;;; Base component. (defclass component () ((parent :initarg :parent :initform nil :reader component-parent) ;; A string which is the name of the component. This slot is ;; redundant because in standard components, we can do a reverse ;; translation with lisp-to-translate really. (name :initarg :name :initform (required-arg "Missing component name") :reader component-name) ;; Table of properties in the component. It is a hash table where ;; keys are property name strings and values are the list of ;; properties properties with that name. (property-table :initform (make-hash-table :test #'equalp) :reader property-table) ;; List of subcomponents in the property. (subcomponents :initform nil :accessor subcomponents))) (defmacro do-property ((propertyvar component &optional result) &body body) "Iterate across the properties in a component." (with-gensyms (ptable key value) `(let ((,ptable (property-table ,component))) (do-hash-table (,key ,value) ,ptable ;; Do not use dolist here in order to keep visible the ;; implicit block of do-hash-table. (map nil (lambda (,propertyvar) ,@body) ,value) ,result)))) (defmacro do-components ((componentvar component &optional result) &body body) "Iterate across the subcomponents in a component." `(dolist (,componentvar (subcomponents ,component) ,result) ,@body)) ;;;; Initialization protocol (defgeneric allocate-component (component-class name) (:method (component-class name) (make-instance component-class :name name)) (:documentation "Make an empty instance of a component class.")) (defgeneric initialize-component (component &rest initargs) (:method ((component component) &rest initargs) (declare (ignorable initargs))) (:documentation "Initialize a component with a set of convenient default properties and subcomponents.")) (defun make-component (name &rest initargs) "Make a instance of the component whose whose name is NAME." (let* ((component-class (find-component-class name)) (component (allocate-component component-class name))) (apply #'initialize-component component initargs) component)) ;;;; Subcomponents and properties protocol ;; Return the list of properties in component with name CLASS. (defmacro properties-with-name (name component) `(gethash ,name (property-table ,component))) (defgeneric add-property-to-component (property component) (:method ((property property) (component component)) (let ((name (property-name property))) (push property (properties-with-name name component)) property)) (:documentation "Add PROPERTY to COMPONENT.")) (defgeneric delete-property-from-component (property component) (:method ((property property) (component component)) (let ((pname (property-name property))) (symbol-macrolet ((plist (properties-with-name pname component))) (setf plist (delete property plist))))) (:documentation "Delete PROPERTY from COMPONENT.")) (defgeneric add-subcomponent-to-component (subcomponent component) (:method ((subcomponent component) (component component)) (setf (slot-value subcomponent 'parent) component) (push subcomponent (subcomponents component)) subcomponent) (:documentation "Add SUBCOMPONENT to COMPONENT.")) (defgeneric delete-subcomponent-from-component (subcomponent component) (:method ((subcomponent component) (component component)) (setf (subcomponents component) (delete subcomponent (subcomponents component)))) (:documentation "Delete SUBCOMPONENT from COMPONENT.")) ;;; Validation protocol (defgeneric validate-component (component) (:method ((component component)) (do-property (prop component) (validate-property prop) (validate-property-in-component component prop)) (do-components (comp component) (validate-component comp) (validate-subcomponent-in-component component comp)) (validate-property-constrains component)) (:documentation "Validate a component. By default, call to the generic functions: o `validate-property-in-component' o `validate-property-constrains' o `validate-subcomponent-in-component' ")) (defgeneric invalid-subcomponent (component subcomponent) (:method ((comp component) (subcomp component)) (error "The component ~a is not a valid subcomponent for ~a" subcomp comp))) (defgeneric invalid-property (component property) (:method ((comp component) (prop property)) (error "The property ~a is not a valid in the component ~a" prop comp))) (defgeneric validate-subcomponent-in-component (component subcomponent) (:method ((comp component) (subcomp component)) (invalid-subcomponent comp subcomp)) (:documentation "Validate SUBCOMPONENT as subcomponent of COMPONENT.")) (defgeneric validate-property-in-component (component property) (:method ((comp component) (prop property)) (invalid-property comp prop)) (:documentation "Validate PROPERTY as property of COMPONENT.")) (defgeneric validate-property-constrains (component) (:method ((comp component)) nil) (:documentation "Validate the constrains between different properties in the same component. It is used, for example, to avoid multiple instances of some properties in a component. But also to implement more complicated constrains. See the `property-constrains' macro facility.")) ;;;; Standard components (eval-when (:compile-toplevel :load-toplevel :execute) ;; Return the property names in the constrain RULE. (defun property-constrains-names (rule) (cond ((stringp rule) (list rule)) ((and (listp rule) (neq (car rule) 'quote)) (delete-duplicates (reduce #'append (mapcar #'property-constrains-names rule)) :test #'string-ci=)))) ;; Replace the property names in the constrain RULE by the values in ;; the alist ENVIRONMENT. This function is internal. (defun replace-property-names-with-vars (environment rule) (cond ((stringp rule) (let ((var (cdr (assoc rule environment :test #'string-ci=)))) (or var (error "Missing the '~a' symbol in ~a" rule environment)))) ((and (listp rule) (eq (car rule) 'quote) (stringp (cadr rule))) (cadr rule)) ((and (listp rule) (neq (car rule) 'quote)) (map1 #'replace-property-names-with-vars environment rule)) (t rule)))) ;;; Execute the property constrains in BODY against ;;; COMPONENT. Property constrains is like usual Lisp code, but ;;; literal strings are evaluated to the list of properties with the ;;; same name in COMPONENT, unless they are quoted. Also, useful local ;;; functions and macros are available. (defmacro property-constrains (component &body body) (let* ((compvar (gensym "COMPONENT")) ;; OPTIMIZATION: The success of the constrain does not ;; depends on the toplevel strings. However they are useful ;; to specify more-than-once properties, though. (body (remove-if #'stringp body)) (pnames (property-constrains-names body)) (pvars (mapcar #'gensym pnames)) (environment (mapcar #'cons pnames pvars))) `(let ((,compvar ,component)) (declare (ignorable ,compvar)) (let ,(loop for name in pnames for var in pvars collect `(,var (query-property ,compvar ,name t))) ;; Local macros for property constrain rules (macrolet ((name (property) (car (rassoc property ',environment))) (required (&rest properties) (progn-expand (property properties) `(if ,property t (error "The property `~a' is missing in the component ~a." (name ,property) ,',compvar)))) (once (&rest properties) (progn-expand (property properties) `(if (second ,property) (error "The property `~a' cannot appear more than once in the component ~a." (name ,property) ,',compvar) t))) (required-once (&rest properties) `(progn (required ,@properties) (once ,@properties)))) ,@(replace-property-names-with-vars environment body)))))) (defclass standard-component (component) nil) (defmethod validate-property-in-component ((component standard-component) (property x-property))) ;;; Extension components (defclass x-component (component) nil) (defmethod validate-subcomponent-in-component ((component x-component) subcomponent)) (defmethod validate-property-in-component ((component x-component) property)) ;;; CLHS says: "If a defclass form appears as a top level form, the ;;; compiler must make the class name be recognized as a valid type ;;; name in..." So we have to define the classes separately. (defmacro declare-component (name &optional abstract-components) `(defclass ,name (,@abstract-components standard-component) nil)) ;;; Define a component. (defmacro define-component (name options &body body) `(define-component-1 ,name ,@(loop for (option . value) in options append `(,option ,value)) :properties ,body)) (defmacro define-component-1 (name &key (icalname (string name)) (allow-x-components nil given-allow-x-components) (allow-x-properties t given-allow-x-properties) subcomponents properties) `(progn (register-translation (find-class ',name) ,icalname :component) ;; Subcomponents validation ,@(if given-allow-x-components `((defmethod validate-subcomponent-in-component ((component ,name) (subcomponent x-component)) ,(or allow-x-components `(invalid-subcomponent component subcomponent))))) ,@(loop for comp-class in subcomponents collect `(defmethod validate-subcomponent-in-component ((comp ,name) (subcomp ,comp-class)))) ;; Properties validation ,@(if given-allow-x-properties `((defmethod validate-property-in-component ((component ,name) (property x-property)) ,(or allow-x-properties `(invalid-property component property))))) ;; Declare known properties ,@(loop for pname in (property-constrains-names properties) for property-class = (or (find-property-class pname) (error "Unknown property name ~a" pname)) for property = (class-name property-class) collect `(defmethod validate-property-in-component ((component ,name) (property ,property)))) ;; Property constrains (defmethod validate-property-constrains ((,name ,name)) (property-constrains ,name ,@properties)))) ;;; VALARM (defun action (component) (let ((action (query-property component "ACTION"))) (cdr (assoc action '(("AUDIO" . :audio) ("EMAIL" . :email) ("DISPLAY" . :display)) :test #'string-ci=)))) (declare-component valarm) (defun valarm-audio-constrains (component) (property-constrains component (required "ATTACH"))) (defun valarm-display-constrains (component) (property-constrains component (required "DESCRIPTION"))) (defun valarm-email-constrains (component) (property-constrains component (required "DESCRIPTION" "SUMMARY"))) (define-component valarm () (required-once "ACTION" "TRIGGER") (unless (eql (and "DURATION" t) (and "REPEAT" t)) (error '"If the DURATION or REPEAT property appears in the component ~a, then the other must so." valarm)) ;; Declare possible properties "ATTACH" "DESCRIPTION" "SUMMARY" "ATTENDEE" ;; Dispatch constrains according to the action (ecase (action valarm) (:audio (valarm-audio-constrains valarm)) (:display (valarm-display-constrains valarm)) (:email (valarm-email-constrains valarm)))) (defun generate-new-uuid () (with-output-to-string (o) (print-object (uuid:make-v4-uuid) o))) ;;; VTODO (declare-component vtodo) (define-component vtodo ((:subcomponents valarm)) (required "DTSTAMP" "UID") (once "CLASS" "COMPLETED" "CREATED" "DESCRIPTION" "DTSTART" "GEO" "LAST-MODIFIED" "LOCATION" "ORGANIZER" "PERCENT-COMPLETE" "PRIORITY" "RECURRENCE-ID" "SEQUENCE" "STATUS" "SUMMARY" "URL" "RRULE") (once "DUE" "DURATION") (when (and "DUE" "DURATION") (error '"DUE and DURATION properties MUST NOT occur in ~a at same time." vtodo)) "ATTACH" "ATTENDEE" "CATEGORIES" "COMMENT" "CONTACT" "EXDATE" "REQUEST-STATUS" "RELATED-TO" "RESOURCES" "RDATE") ;;; VEVENT (declare-component vevent) (defprinter (event vevent) (let ((summary (query-property event "SUMMARY"))) (if summary (prin1 (property-value summary)) (write-string ":NO-SUMMARY")))) (define-component vevent ((:subcomponents valarm)) (required-once "DTSTAMP" "UID") (let ((parent (component-parent vevent))) (unless (or (null parent) (query-property parent '"METHOD")) (required "DTSTART"))) (once "CLASS" "CREATED" "DESCRIPTION" "GEO" "LAST-MODIFIED" "LOCATION" "ORGANIZER" "PRIORITY" "SEQUENCE" "STATUS" "SUMMARY" "TRANSP" "URL" "RECURRENCE-ID" "RRULE") (once "DTEND" "DURATION") (when (and "DTEND" "DURATION") (error '"DTEND and DURATION properties MUST NOT occur in ~a at same time." vevent)) "ATTACH" "ATTENDEE" "CATEGORIES" "COMMENT" "CONTACT" "EXDATE" "REQUEST-STATUS" "RELATED-TO" "RESOURCES" "RDATE") (defmethod initialize-component ((component vevent) &key (uid (generate-new-uuid)) (dtstamp (get-universal-time))) (add-new-property component "UID" nil uid) (add-new-property component "DTSTAMP" nil dtstamp)) ;;; VJOURNAL (declare-component vjournal) (define-component vjournal () (required-once "DTSTAMP" "UID") (once "CLASS" "CREATED" "DTSTART" "LAST-MODIFIED" "ORGANIZER" "RECURRENCE-ID" "SEQUENCE" "STATUS" "SUMMARY" "URL" "RRULE") "ATTACH" "ATTENDEE" "CATEGORIES" "COMMENT" "CONTACT" "DESCRIPTION" "EXDATE" "RELATED-TO" "RDATE" "REQUEST-STATUS") ;;; VFREEBUSY (declare-component vfreebusy) (define-component vfreebusy () (required-once "DTSTAMP" "UID") (once "CONTACT" "DTSTART" "DTEND" "ORGANIZER" "URL") "ATTENDEE" "COMMENT" "FREEBUSY" "REQUEST-STATUS") ;;; VTIMEZONE (declare-component vtimezone) (declare-component standard) (declare-component daylight) (define-component standard () (required-once "DTSTART" "TZOFFSETTO" "TZOFFSETFROM") (once "RRULE") "COMMENT" "RDATE" "TZNAME") (define-component daylight () (required-once "DTSTART" "TZOFFSETTO" "TZOFFSETFROM") (once "RRULE") "COMMENT" "RDATE" "TZNAME") (define-component vtimezone ((:subcomponents standard daylight)) (required-once "TZID") (once "LAST-MODIFIED" "TZURL")) ;;; VCALENDAR (defclass vcalendar (standard-component) ((uid-table :initform (make-hash-table :test #'equalp) :reader uid-table))) (define-component vcalendar ((:allow-x-components . t) (:subcomponents vtodo vevent vjournal vfreebusy vtimezone)) (required "PRODID" "VERSION") (once "CALSCALE" "METHOD")) (defmethod add-subcomponent-to-component :after ((event vevent) (component vcalendar)) (let ((uid (query-property event "UID"))) (when uid (setf (gethash (property-value uid) (uid-table component)) event)))) (defmethod initialize-component ((component vcalendar) &key (version "2.0") (prodid "-//cl-icalendar v0.0//EN") (method "PUBLISH")) (add-new-property component "PRODID" nil prodid) (add-new-property component "VERSION" nil version) (when method (add-new-property component "METHOD" nil method))) (defun read-vcalendar (stream) (let ((component (read-component stream))) (check-type component vcalendar) component)) ;;; Other components (defclass unknown-component (component) nil) (defmethod validate-component ((x unknown-component))) (defmethod allocate-component ((component-class null) name) (make-instance 'unknown-component :name name)) ;;;; Aplication programmer Interface (API) (defun add-property (component name parameters value) "Add the property named NAME, with the given PARAMETERS and VALUE to the list of properties of COMPONENT." (let ((property (make-property name parameters value))) (add-property-to-component property component))) (defun add-new-property (component name parameters value) "Like `add-property', but only add the property if there is not any property with the same name in the component already." (unless (query-property component name) (add-property component name parameters value))) (defun query-property (component property-name &optional all-p) "Return a property of COMPONENT with name PROPRETY-NAME. If ALL-P is present, return the list of all the properties with this name instead. The behaviour is undefined if the returned list is modified destructively." (let ((list (gethash property-name (property-table component)))) (if all-p list (first list)))) (defun delete-property (component property) "Delete PROPERTY of the table of properties of COMPONENT." (delete-property-from-component property component)) (defun read-object (stream) (multiple-value-bind (name params value) (read-content-line stream) (cond ((string-ci= name "BEGIN") (check-type params null) (let* ((component-class (find-component-class value)) (component (allocate-component component-class value))) (loop with begin-mark = value for (object end-mark) = (multiple-value-list (read-object stream)) while object do (typecase object (property (add-property-to-component object component)) (component (add-subcomponent-to-component object component))) finally (unless (string-ci= begin-mark end-mark) (error "A END:~:@(~a~) was expected, but it found a END:~a" begin-mark end-mark))) component)) ((string-ci= name "END") (check-type params null) (values nil value)) (t (let ((property (property-from-content-line name params value))) property))))) (defun read-component (stream) "Read a component or property from STREAM." (let ((object (read-object stream))) (check-type object component) object)) (defun write-component (component stream) "Write COMPONENT to STREAM." (let ((name (component-name component))) (write-content-line "BEGIN" nil name stream) (do-property (prop component) (write-property prop stream)) (dolist (comp (subcomponents component)) (write-component comp stream)) (write-content-line "END" nil name stream))) ;;; components.lisp ends here
20,387
Common Lisp
.lisp
453
38.677704
107
0.682017
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
6cbd46eca01a65183374454e1f27d862515cf55d8ef102823f32225025873a76
8,865
[ -1 ]
8,866
conditions.lisp
davazp_cl-icalendar/conditions.lisp
;; error.lisp --- Error handling machinery ;; ;; Copyrigth (C) 2010, 2012 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) (define-condition icalendar-condition () nil) (define-condition icalendar-error (icalendar-condition simple-error) nil) (define-condition icalendar-type-error (icalendar-error) ((expected) (found) (place))) (define-condition icalendar-parse-error (icalendar-error) ((stream :initarg :stream :reader icalendar-parse-error-stream) (line :initarg :line :reader icalendar-parse-error-line) (column :initarg :column :reader icalendar-parse-error-column))) (define-condition icalendar-warning (icalendar-condition warning) nil) (define-condition validation-error (icalendar-error) ((component :initarg :component :reader validation-error-component))) (define-condition missing-property (validation-error) ((property-name))) (define-condition invalid-parameter (validation-error) ((property) (parameter))) (define-condition invalid-property (validation-error) ((component) (property))) (define-condition invalid-component (validation-error) ((component))) ;;; Signal an icalendar-parse-error condition. (defun %parse-error (format &rest args) (error 'icalendar-parse-error :format-control format :format-arguments args)) (defun ical-error (format &rest args) (error 'icalendar-error :format-control format :format-arguments args)) ;;; error.lisp ends here
2,150
Common Lisp
.lisp
55
36.363636
72
0.756497
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
593ecf1efa042ba89c34d2aee9e622a406af94344f6f5cd942b0d149192a6178
8,866
[ -1 ]
8,867
cl-icalendar.lisp
davazp_cl-icalendar/cl-icalendar.lisp
;; cl-icalendar.lisp ;; ;; Copyrigth (C) 2009, 2010 Mario Castelán Castro <marioxcc> ;; Copyrigth (C) 2009, 2010 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) (defun open-vcalendar (pathname) (with-open-file (infile pathname :element-type :default) (with-folding-stream (in infile) (read-vcalendar in)))) (defun save-vcalendar (vcalendar pathname &key if-exists) (with-open-file (outfile pathname :element-type '(unsigned-byte 8) :direction :output :if-exists if-exists) (with-folding-stream (out outfile) (write-component vcalendar out)))) ;; cl-icalendar.lisp ends here
1,344
Common Lisp
.lisp
32
38.28125
72
0.717458
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
07b7e15fba05b5df7b46e392e95f520d962178b340d91e2a4a7335f8291b0a13
8,867
[ -1 ]
8,868
types-text.lisp
davazp_cl-icalendar/types-text.lisp
;; types-text.lisp --- ;; ;; Copyrigth (C) 2009, 2010 Mario Castelán Castro <marioxcc> ;; Copyrigth (C) 2009, 2010 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) (deftype text () 'string) (register-ical-value text) (define-predicate-type text) (defmethod format-value ((text string) (type (eql 'text)) &optional params) (declare (ignore params)) (with-input-from-string (in text) (with-output-to-string (out) (loop for ch = (read-char in nil) while ch do (cond ((char= ch #\newline) (write-char #\\ out) (write-char #\n out)) ((char= ch #\\) (write-char #\\ out) (write-char #\\ out)) ((char= ch #\,) (write-char #\\ out) (write-char #\, out)) ((char= ch #\;) (write-char #\\ out) (write-char #\; out)) (t (write-char ch out))))))) (defmethod parse-value (text (type (eql 'text)) &optional params) (declare (ignore params)) (let ((string text)) (with-input-from-string (in string) (with-output-to-string (out) (loop for ch = (read-char in nil) while ch do (write-char (if (char/= ch #\\) ch (let ((ch (read-char in nil))) (case ch (#\N #\newline) (#\n #\newline) (otherwise ch)))) out)))))) ;;; types-text.lisp ends here
2,317
Common Lisp
.lisp
61
28.590164
75
0.548488
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
6c427d2605950afda5d88995836869873d95fa535b7451ba633e536834b55a7c
8,868
[ -1 ]
8,869
types-date.lisp
davazp_cl-icalendar/types-date.lisp
;; types-date.lisp --- ;; ;; Copyrigth (C) 2009, 2010 Mario Castelán Castro <marioxcc> ;; Copyrigth (C) 2009, 2010, 2011 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) ;;; Dates (defvar *weekday-names* #("MO" "TU" "WE" "TH" "FR" "SA" "SU")) (deftype date () '(integer 0)) (register-ical-value date) (defun encode-date (date month year) (encode-universal-time 0 0 0 date month year)) (defmethod format-value (date (type (eql 'date)) &optional params) (declare (ignore params)) (decoded-universal-time (:date d :month m :year y) date (format nil "~4,'0d~2,'0d~2,'0d" y m d))) (defmethod parse-value (string (type (eql 'date)) &optional params) (declare (ignore params)) (unless (= (length string) 8) (%parse-error "parse error.")) (let ((d (parse-unsigned-integer string :start 6 :end 8)) (m (parse-unsigned-integer string :start 4 :end 6)) (y (max (parse-unsigned-integer string :start 0 :end 4) 1900))) (encode-date d m y))) ;;; types-date.lisp ends here
1,692
Common Lisp
.lisp
40
39.975
72
0.705058
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
c0b57d180a9c69f60cd0d372b502704a129df472c6377a6d3be24158df4fa993
8,869
[ -1 ]
8,870
property.lisp
davazp_cl-icalendar/property.lisp
;;; property.lisp --- Properties ;; ;; Copyright (C) 2012 David Vazquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) (defun find-property-class (name) (or (translate-to-lisp name :property) (and (x-name-p name) (find-class 'x-property)))) ;;;; Property protocol ;;; Make an uninitialized instance of a property, with the given NAME ;;; and PARAMETERS. If NAME is NIL, it will try to use a default ;;; name. The value of the property can be initialized with the ;;; generic function `initialize-property'. (defgeneric allocate-property (property-class name parameters)) ;;; Return a single iCalendar type. Initializing a property with a ;;; property value which belongs this type, is granted to validate. (defgeneric allocated-property-type (property)) ;;; Initialize the value of an allocated property to VALUE. This value ;;; must satisfy the type returned by `allocated-proprety-type'. (defgeneric initialize-property (property value)) ;;; Parse a string as value of a property. (defmethod parse-property-value (property string)) ;;; Make an instance of a property. PROPERTY is a string. PARAMETERS ;;; is a list of parameters as described in parameters.lisp. VALUE is ;;; an iCalendar value. (defgeneric make-property (property-name parameters value) (:method (property-name parameters value) (let* ((property-class (find-property-class property-name)) (prop (allocate-property property-class property-name parameters))) (initialize-property prop value) prop))) ;;; Make a property instance from a content line. (defun property-from-content-line (property-name parameters string) (let* ((property-class (find-property-class property-name)) (property (allocate-property property-class property-name parameters)) (value (parse-property-value property string))) (initialize-property property value) property)) (defun write-property* (property stream) (let ((value (property-value property)) (type (allocated-property-type property))) (write-content-line* (property-name property) (property-parameters property) (format-values (mklist value) type) stream))) ;;; Write PROPERTY in a content line to STREAM. (defun write-property (property stream) (write-property* property stream) (terpri stream)) ;;;; Property validation protocol ;;; Validate the property. The default method validate the parameters ;;; with `validate-property-parameters' and the value with ;;; `validate-property-value'. (defgeneric validate-property (property)) ;;; Validate the value of PROPERTY. The default method checks that the ;;; value of the property satisfies the iCalendar type returned by the ;;; generic function `allocated-property-type'. (defgeneric validate-property-value (property)) ;;; Validate the parameters of property. The default method validates ;;; each parameter calling `validate-property-parameter'. (defgeneric validate-property-parameters (property)) ;;; Validate a parameter in a property. The default method uses the ;;;`property-validated-parameters', `property-allow-x-parameters-p' ;;; and `property-allow-other-parameters-p' generic functions to get ;;; information about the validation. (defgeneric validate-property-parameter (property parameter-name parameter-value)) ;; Return a list of string, which are the names of the valid ;; parameters for instances of this property. (defgeneric property-validated-parameters (property) (:method-combination append)) ;; If it returns NIL, the property does not allow x-parameters, so it ;; will not validate if one is present. (defgeneric property-allow-x-parameters-p (property)) ;;; If it is NIL, the property class does not allow unknown ;;; parameters, so it will not validate if one is present. (defgeneric property-allow-other-parameters-p (property)) ;;; Base property class (defclass property () ((name :initarg :name :initform (required-arg) :type string :reader property-name) (parameters :initarg :parameters :type list :reader property-parameters) (value :initarg :value :reader property-value))) (defmethod allocate-property (property-class name parameters) (make-instance property-class :name name :parameters parameters)) (defmethod initialize-property ((allocated-property property) value) (setf (slot-value allocated-property 'value) value)) (defmethod parse-property-value ((prop property) string) (let ((type (allocated-property-type prop)) (params (property-parameters prop))) (parse-value string type params))) (defmethod print-object ((prop property) stream) (print-unreadable-object (prop stream) (write-property* prop stream))) (defmethod property-validated-parameters append ((x property)) nil) (defmethod property-allow-x-parameters-p ((x property)) t) (defmethod property-allow-other-parameters-p ((x property)) nil) (defmethod validate-property-value ((property property)) (let ((value (property-value property)) (type (allocated-property-type property))) (unless (and type (typep value type)) (cerror "Continue" "The value ~a is not of type ~a" value type)))) (defmethod validate-property-parameter ((property property) parameter-name parameter-value) (let ((parameters (property-validated-parameters property))) (or (find parameter-name parameters :test #'string-ci=) (and (property-allow-x-parameters-p property) (string-prefix-p "X-" parameter-name :test #'char-ci=)) (property-allow-other-parameters-p property) (cerror "" "The parameter ~a with value ~a is not allowed in property ~a" parameter-name parameter-value (property-name property))))) (defmethod validate-property-parameters ((prop property)) (loop for (param-name param-value) on (property-parameters prop) by #'cddr do (validate-property-parameter prop param-name param-value))) (defmethod validate-property ((prop property)) (validate-property-parameters prop) (validate-property-value prop)) ;;; Abstract properties classes ;;; Properties with a composed type (defclass multiple-type-property (property) nil) (defgeneric property-default-type (property)) (defgeneric property-types (property)) (defgeneric property-parameter-value (property) (:method ((property multiple-type-property)) (let ((value-param (parameter "VALUE" (property-parameters property)))) (if value-param (translate-to-lisp value-param :type) (property-default-type property))))) (defmethod property-validated-parameters append ((x multiple-type-property)) '("VALUE")) (defmethod allocated-property-type ((property multiple-type-property)) (property-parameter-value property)) (defmethod validate-property-parameters ((prop multiple-type-property)) (let ((value-param (property-parameter-value prop)) (validated-types (property-types prop))) (unless (find value-param validated-types) (error "The VALUE parameter was ~a, but one of ~a was expected." value-param validated-types))) (call-next-method)) ;;; Properties which allow multiple values in the same property (defclass multiple-value-property (property) nil) (defmethod parse-property-value ((prop multiple-value-property) string) (let ((type (allocated-property-type prop)) (params (property-parameters prop))) (parse-values string type params))) (defmethod validate-property-value ((prop multiple-value-property)) (let ((values (mklist (property-value prop))) (type (allocated-property-type prop))) (dolist (value values) (unless (typep value type) (error "The value ~a is not of type ~a" value type))))) ;;; Standard properties ;;; Define a standard property. See the examples. Just note that if ;;; you provide MULTIPLE-VALUE-P, then the first type of the list TYPE ;;; will be used as default type if the property parameter VALUE is ;;; ommited. (defmacro define-property (real-name &key type (multiple-value-p nil) (parameters nil) (allow-x-parameters-p t) (allow-other-parameters-p nil)) (check-type real-name string) (check-type multiple-value-p boolean) (check-type allow-x-parameters-p boolean) (check-type allow-other-parameters-p boolean) (let* ((superclasses '(property)) (name (symbolize "PROPERTY-" real-name)) (types (mklist type)) (default-type (first types)) (multiple-type-p (< 1 (length types)))) ;; Add some superclasses according to the options (when multiple-type-p (unless default-type (error "You must specify a default type for each multiple-type-property")) (push 'multiple-type-property superclasses)) (when multiple-value-p (push 'multiple-value-property superclasses)) ;; Expansion `(progn ;; Property class and registration (defclass ,name (,@superclasses) nil) (register-translation (find-class ',name) ,real-name :property) ;; Validation of parameters ,@(unless (null parameters) `((defmethod property-validated-parameters append ((,(gensym) ,name)) ',parameters))) ;; Validation of types ,@(if multiple-type-p `((defmethod property-default-type ((,(gensym) ,name)) ',default-type) (defmethod property-types ((,(gensym) ,name)) ',types)) `((defmethod allocated-property-type ((,(gensym) ,name)) ',(unlist types))))))) ;;; Calendar properties (define-property "CALSCALE" :type text) (define-property "METHOD" :type text) (define-property "PRODID" :type text) (define-property "VERSION" :type text) ;;; Component properties ;;;; Descriptive Component Properties (define-property "ATTACH" :type (uri binary) :parameters ("ENCODING" "FMTTYPE")) (define-property "CATEGORIES" :type text :multiple-value-p t :parameters ("LANGUAGE")) (define-property "CLASS" :type text) (define-property "COMMENT" :type text :parameters ("ALTREP" "LANGUAGE")) (define-property "DESCRIPTION" :type text :parameters ("ALTREP" "LANGUAGE")) (define-property "GEO" :type geo) (define-property "LOCATION" :type text :parameters ("ALTREP" "LANGUAGE")) (define-property "PERCENT-COMPLETE" :type integer ; TODO (integer 0 100) ) (define-property "PRIORITY" :type integer ; TODO: (integer 0 9) ) (define-property "RESOURCES" :type text :multiple-value-p t :parameters ("ALTREP" "LANGUAGE")) (define-property "STATUS" ; TODO: Enumerated types :type text) (define-property "SUMMARY" :type text :parameters ("ALTREP" "LANGUAGE")) ;;;; Date and Time Component Properties (define-property "COMPLETED" :type datetime) (define-property "DTEND" :type (datetime date) :parameters ("TZID")) (define-property "DUE" :type (datetime date) :parameters ("TZID")) (define-property "DTSTART" :type (datetime date) :parameters ("TZID")) (define-property "DURATION" :type duration) (define-property "FREEBUSY" :type period :parameters ("FBTYPE")) (define-property "TRANSP" :type text) ;;;; Time Zone Component Properties (define-property "TZID" :type text) (define-property "TZNAME" :type text :parameters ("LANGUAGE")) (define-property "TZOFFSETFROM" :type utc-offset) (define-property "TZOFFSETTO" :type utc-offset) (define-property "TZURL" :type uri) ;;;; Relationship Component Properties (define-property "ATTENDEE" :type cal-address :parameters ("CUTYPE" "MEMEBER" "ROLE" "PARTSTAT" "RSVP" "DELEGATED-TO" "DELEGATED-FROM" "SENT-BY" "CN" "DIR")) (define-property "CONTACT" :type text :parameters ("ALTREP" "LANGUAGE")) (define-property "ORGANIZER" :type cal-address :parameters ("LANGUAGE" "CN" "DIR" "SENT-BY")) (define-property "RECURRENCE-ID" :type (datetime date) :parameters ("TZID" "RANGE")) (define-property "RELATED-TO" :type text :parameters ("RELTYPE")) (define-property "URL" :type uri) (define-property "UID" :type text) ;;;; Recurrence Component Properties (define-property "EXDATE" :type (datetime date) :multiple-value-p t :parameters ("TZID")) (define-property "RDATE" :type (datetime date period) :multiple-value-p t :parameters ("TZID")) (define-property "RRULE" :type recur) ;;;; Alarm Component Properties (define-property "ACTION" :type text) (define-property "REPEAT" :type integer) (define-property "TRIGGER" :type (duration datetime) :parameters ("TZID" "RELATED")) ;;;; Change Management Component Properties (define-property "CREATED" :type datetime) (define-property "DTSTAMP" :type datetime) (define-property "LAST-MODIFIED" :type datetime) (define-property "SEQUENCE" :type integer) ;;;; Miscellaneous Component Properties (define-property "REQUEST-STATUS" :type text :parameters ("LANGUAGE")) ;;;; X properties (defclass x-property (property) nil) (defmethod allocated-property-type ((property x-property)) nil) (defmethod validate-property-value ((property x-property)) t) (defmethod property-allow-other-parameters-p ((property x-property)) t) ;;;; Unknown properties (defclass unknown-property (property) nil) (defmethod allocate-property ((property-class null) name parameters) (allocate-property 'unknown-property name parameters)) (defmethod allocated-property-type ((property unknown-property)) nil) (defmethod validate-property-value ((property unknown-property)) t) (defmethod property-allow-other-parameters-p ((property unknown-property)) t) ;;; property.lisp ends here
14,631
Common Lisp
.lisp
350
37.251429
91
0.712954
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
4e611b932151d3ad8fed881eccadce32954376851fa483de99681ceb3b7fbbe7
8,870
[ -1 ]
8,871
universal-time.lisp
davazp_cl-icalendar/universal-time.lisp
;; universal-time.lisp --- Basic universal time functions ;; ;; Copyrigth (C) 2012 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) (defmacro values-accessors (function &body accessors) (let ((var (gensym))) `(progn ,@(loop for i from 0 for x in accessors collect `(defun ,x (,var) (nth-value ,i (,function ,var))))))) (values-accessors decode-universal-time time-second time-minute time-hour date-day date-month date-year) ;;; Decode a universal time. (defmacro decoded-universal-time ((&key second minute hour date month year day zone (timezone nil timezone-p)) form &body body) (let ((vars)) (flet ((** (x) (or x (car (push (gensym) vars))))) `(multiple-value-bind (,(** second) ,(** minute) ,(** hour) ,(** date) ,(** month) ,(** year) ,(** day) ,(** zone)) ,(if timezone-p `(decode-universal-time ,form ,timezone) `(decode-universal-time ,form)) (declare (ignore ,@vars)) ,@body)))) (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *weekday* #(:monday :tuesday :wednesday :thursday :friday :saturday :sunday))) (deftype weekday () `(member ,@(coerce *weekday* 'list))) ;;; Determine if YEAR is leap. (defun leap-year-p (year) (and (zerop (mod year 4)) (or (not (zerop (mod year 100))) (zerop (mod year 400))))) (defun leap-years-before (year) (let ((years (- year 1901))) (+ (- (truncate years 4) (truncate years 100)) (truncate (+ years 300) 400)))) ;;; 1 January = 1 (defun day-from-new-year (day month year) (let ((days-before-month #(0 0 31 59 90 120 151 181 212 243 273 304 334)) (days-before-month-leap #(0 0 31 60 91 121 152 182 213 244 274 305 335))) (if (leap-year-p year) (+ day (svref days-before-month-leap month)) (+ day (svref days-before-month month))))) (defun 1900+days (stamp) (let (year month day rem) ;; Year (loop for t1 downfrom (truncate stamp 365) for t2 = (+ (* 365 t1) (leap-years-before (+ 1900 t1))) for t3 = (- stamp t2) while (<= t3 0) finally (setf year (+ 1900 t1) rem t3)) ;; Month (loop for m from 12 downto 1 as t1 = (day-from-new-year 1 m year) as t2 = (- rem t1) while (< t2 0) finally (setf month m rem t2)) ;; Day (setf day (1+ rem)) ;; Return information (encode-universal-time 0 0 0 day month year))) (defun day-from-1900 (universal-time) (decoded-universal-time (:date date :month month :year year) universal-time (+ (* 365 (- year 1900)) (leap-years-before year) (day-from-new-year date month year)))) ;;; Some useful numbers (defun second-from-midnight (universal-time) (decoded-universal-time (:date d :month m :year y) universal-time (- universal-time (encode-universal-time 0 0 0 d m y)))) (defun day-of-week (universal-time &optional (wkst :monday)) (decoded-universal-time (:day day) universal-time (values (elt *weekday* day) (mod (- (+ day 7) (position wkst *weekday*)) 7)))) (defun day-of-year (universal-time) (decoded-universal-time (:date day :month month :year year) universal-time (day-from-new-year day month year))) (defun nearest-weekday (universal-time wkst) (if (< 3 (second-value (day-of-week universal-time wkst))) (next-weekday universal-time wkst) (previous-weekday (date+ universal-time 1) wkst))) (defun week-of-year (ut &optional (wkst :monday)) (declare (weekday wkst)) (let ((1jan (beginning-of-year ut))) (cond ((>= ut (nearest-weekday (forward-year 1jan) wkst)) (setq 1jan (forward-year 1jan))) ((< ut (nearest-weekday 1jan wkst)) (setq 1jan (backward-year 1jan)))) (values(1+ (weeks-between (nearest-weekday 1jan wkst) ut)) (date-year 1jan)))) ;;; Components upgrading (defun adjust-datetime (universal-time &key day month year second minute hour) (multiple-value-bind (osecond ominute ohour oday omonth oyear) (decode-universal-time universal-time) (encode-universal-time (or second osecond) (or minute ominute) (or hour ohour) (or day oday) (or month omonth) (or year oyear)))) (defun adjust-time (universal-time &key second minute hour) (adjust-datetime universal-time :second second :minute minute :hour hour)) (defun adjust-date (universal-time &key day month year) (adjust-datetime universal-time :day day :month month :year year)) ;;; Differenting... ;;; Seconds between UT1 and UT2. (defun seconds-between (ut1 ut2) (- ut1 ut2)) ;;; Minutes between UT1 and UT2. (defun minutes-between (ut1 ut2) (truncate (seconds-between ut1 ut2) 60)) ;;; Hours between UT1 and UT2. (defun hours-between (ut1 ut2) (truncate (seconds-between ut1 ut2) 3600)) ;;; Days between UT1 and UT2. (defun days-between (ut1 ut2) (- (day-from-1900 ut2) (day-from-1900 ut1))) ;;; Weeks between UT1 and UT2. (defun weeks-between (ut1 ut2) (truncate (days-between ut1 ut2) 7)) ;;; Months between UT1 and UT2. (defun months-between (ut1 ut2) (decoded-universal-time (:month m1) ut1 (decoded-universal-time (:month m2) ut2 (+ (* 12 (years-between ut1 ut2)) (- m2 m1))))) ;;; Years between UT1 and UT2. (defun years-between (ut1 ut2) (decoded-universal-time (:year y1) ut1 (decoded-universal-time (:year y2) ut2 (- y2 y1)))) ;;; Arithmetic ;;; Add SECS to a universal time (defun time+ (universal-time secs) (+ universal-time secs)) ;;; Add DAYS to a universal time (defun date+ (universal-time days) (decoded-universal-time (:second sec :minute min :hour h) universal-time (let ((d (day-from-1900 universal-time))) (adjust-datetime (1900+days (+ d days)) :second sec :minute min :hour h)))) ;;; Add DAYS and SECS to a universal time (defun datetime+ (universal-time days secs) (time+ (date+ universal-time days) secs)) ;;; Return the following WEEKDAY from UT. (defun next-weekday (ut weekday) (date+ ut (- 7 (second-value (day-of-week ut weekday))))) ;;; Return the first WEEKDAY before of UT. (defun previous-weekday (ut weekday) (let ((dow (second-value (day-of-week ut weekday)))) (if (zerop dow) (date+ ut (- 7)) (date+ ut (- dow))))) ;;; Add N seconds to UT. (defun forward-second (ut &optional (n 1)) (time+ ut n)) ;;; Add N minutes to UT. (defun forward-minute (ut &optional (n 1)) (time+ ut (* 60 n))) ;;; Add N hours to UT. (defun forward-hour (ut &optional (n 1)) (time+ ut (* 3600 n))) ;;; Add N days to UT. (defun forward-day (ut &optional (n 1)) (date+ ut n)) ;;; Subtract N days to UT. (defun backward-day (ut &optional (n 1)) (forward-day ut (- n))) ;;; Add N days to UT. (defun forward-week (ut &optional (n 1)) (forward-day ut (* 7 n))) ;;; Subtract N days to UT. (defun backward-week (ut &optional (n 1)) (forward-week ut (- n))) ;;; Add N months to UT. (defun forward-month (ut &optional (n 1)) (decoded-universal-time (:year year :month month) ut (multiple-value-bind (delta-year delta-month) (truncate n 12) (multiple-value-bind (delta-year* month*) (truncate (+ delta-month (1- month)) 12) (adjust-date ut :month (1+ month*) :year (+ year delta-year delta-year*)))))) ;;; Subtract N months to UT. (defun backward-month (ut &optional (n 1)) (forward-month ut (- n))) ;;; Add N years to UT. (defun forward-year (ut &optional (n 1)) (adjust-date ut :year (+ (date-year ut) n))) ;;; Subtract N years to UT. (defun backward-year (ut &optional (n 1)) (forward-year ut (- n))) ;;; Return the the first day of the month of UT. (defun beginning-of-month (ut) (adjust-date ut :day 1)) ;;; Return the last day of the month of UT. (defun end-of-month (ut) (decoded-universal-time (:year year :month month) ut (let ((monthdays (if (leap-year-p year) #(0 31 29 31 30 31 30 31 31 30 31 30 31) #(0 31 28 31 30 31 30 31 31 30 31 30 31)))) (adjust-date ut :day (elt monthdays month))))) ;;; Return the first day of the year of UT. (defun beginning-of-year (ut) (adjust-date ut :day 1 :month 1)) ;;; Return the last day of the year of UT. (defun end-of-year (ut) (adjust-date ut :day 31 :month 12)) ;;; universal-time.lisp ends here
9,344
Common Lisp
.lisp
245
33.028571
81
0.63219
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
b4eff0e0fb2b8bb7b7fb71b1ad9ed384e41eb2c288c26ee3a2e04a5e5a919c9d
8,871
[ -1 ]
8,872
types-time.lisp
davazp_cl-icalendar/types-time.lisp
;; types-time.lisp --- ;; ;; Copyrigth (C) 2009, 2010 Mario Castelán Castro <marioxcc> ;; Copyrigth (C) 2009, 2010 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) ;;; Time (defconstant +seconds-per-day+ 86400) (deftype time () `(mod ,+seconds-per-day+)) (register-ical-value time) (defun encode-time (hour minute second) (encode-universal-time second minute hour 1 1 1900 0)) (defmethod format-value (time (type (eql 'time)) &optional params) (declare (ignore params)) (decoded-universal-time (:hour h :minute m :second s) time (format nil "~2,'0d~2,'0d~2,'0d" h m s))) (defmethod parse-value (string (type (eql 'time)) &optional params) (declare (ignore params)) (encode-time (parse-unsigned-integer string :start 0 :end 2) (parse-unsigned-integer string :start 2 :end 4) (parse-unsigned-integer string :start 4 :end 6))) ;;; types-time.lisp ends here
1,570
Common Lisp
.lisp
37
40.513514
72
0.732589
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
1d92c1f6682de1e05bac7c265e33cfc10aa72ee1ba45e1ea8a56bbb655524ba1
8,872
[ -1 ]
8,873
parameters.lisp
davazp_cl-icalendar/parameters.lisp
;; parameters.lisp -- Parameter list ;; ;; Copyrigth (C) 2012 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) ;;; A parameter list is a list of the form ;;; ;;; (PARAM-NAME1 PARAM-VALUE1 PARAM-NAME2 PARAM-NAME2 ...) ;;; ;;; PARAM-NAMEs are upcased strings. PARAM-VALUEs are strings or list ;;; of strings. ;;; Get the value of the parameter, whose name is given in the string ;;; designator PARAMETER, in the given PARAMETER-LIST. (defun parameter (parameter parameter-list) (let ((name (string parameter))) (loop for (param value) on parameter-list by #'cddr when (string= name param) return value))) #| See content-line.lisp about parameters reading and writing |# ;; parameters.lisp ends here
1,404
Common Lisp
.lisp
33
40.909091
72
0.740849
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
68fb2de27fda06742b955841ae8cdaa97f683305d9145e9b50d5564b1d3ff5bd
8,873
[ -1 ]
8,874
types-duration.lisp
davazp_cl-icalendar/types-duration.lisp
;; types-duration.lisp --- Duration data type implementation ;; ;; Copyrigth (C) 2009, 2010 Mario Castelán Castro <marioxcc> ;; Copyrigth (C) 2009, 2010 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) (defclass duration () ((days :initarg :days :initform 0 :reader %duration-days) (seconds :initarg :seconds :initform 0 :reader %duration-seconds))) (register-ical-value duration) (define-predicate-type duration) (defun make-duration (&key (days 0) (hours 0) (minutes 0) (seconds 0) backward-p) (declare (type (integer 0 *) days hours minutes seconds)) (make-instance 'duration :days (if backward-p (- days) days) :seconds (* (if backward-p -1 1) (+ (* hours 3600) (* minutes 60) seconds)))) (defun duration (durspec) (etypecase durspec (duration durspec) (string (parse-value durspec 'duration)))) ;;; Accessor for duration designators (defgeneric duration-days (duration) (:method ((x duration)) (abs (%duration-days x)))) (defgeneric duration-hours (duration) (:method ((x duration)) (truncate (abs (%duration-seconds x)) 3600))) (defgeneric duration-minutes (duration) (:method ((x duration)) (mod (abs (truncate (%duration-seconds x) 60)) 60))) (defgeneric duration-seconds (duration) (:method ((x duration)) (mod (abs (%duration-seconds x)) 60))) (defgeneric duration-backward-p (duration) (:method ((x duration)) (or (< (%duration-seconds x) 0) (< (%duration-days x) 0)))) (defmethod duration-days ((x string)) (duration-days (duration x))) (defmethod duration-hours ((x string)) (duration-hours (duration x))) (defmethod duration-minutes ((x string)) (duration-minutes (duration x))) (defmethod duration-seconds ((x string)) (duration-seconds (duration x))) (defmethod duration-backward-p ((x string)) (duration-backward-p (duration x))) (defgeneric duration-inverse (duration) (:method ((d1 duration)) (make-instance 'duration :days (- (%duration-days d1)) :seconds (- (%duration-seconds d1))))) ;;; Printer (defvar *print-duration-abbrev* nil) (defprinter (x duration) (let* ((component-names (if *print-duration-abbrev* '("d" "h" "m" "s") '("day" "hour" "minute" "second"))) (output (loop for c in component-names for n in (list (duration-days x) (duration-hours x) (duration-minutes x) (duration-seconds x)) unless (zerop n) collect n and collect c))) (cond ((null output) (format t "empty duration")) (*print-duration-abbrev* (format t "~{~d~a~^ ~}" output)) (t (format t "~{~d ~a~2:*~p~*~#[~;~; and ~:;, ~]~}" output))) (when (duration-backward-p x) (format t " to BACKWARD")))) ;;; Return a string which stand for DURSPECS in the format described ;;; in the RFC5545 section 3.3.6. (defmethod format-value ((dur duration) (type (eql 'duration)) &optional params) (declare (ignore params)) (let ((days (duration-days dur)) (hours (duration-hours dur)) (minutes (duration-minutes dur)) (seconds (duration-seconds dur)) (backward-p (duration-backward-p dur))) (with-output-to-string (out) (format out "~:[~;-~]" backward-p) (format out "P") (cond ((and (zerop (%duration-seconds dur)) (zerop (%duration-days dur))) (format out "T0S")) ((and (zerop (%duration-seconds dur)) (zerop (mod (%duration-days dur) 7))) (format out "~aW" (/ days 7))) (t (unless (zerop days) (format out "~aD" days)) (cond ((= 0 hours minutes seconds)) ((and (zerop minutes) (and (not (zerop hours)) (not (zerop seconds)))) (format out "T~aH~aM~aS" hours minutes seconds)) (t (format out "T~[~:;~:*~aH~]~[~:;~:*~aM~]~[~:;~:*~aS~]" hours minutes seconds)))))))) ;;; Parse a duration according to the format which is described in the ;;; RFC5545 section 3.3.6. (defmethod parse-value (string (type (eql 'duration)) &optional params) (declare (ignore params)) (with-input-from-string (in string) ;; The token1 and token2 variables keep the following token in the ;; automata and the following of the following one. (let* (token1 token2) (labels ( ;; Read and return a token from the input stream. This ;; is intended to be used by `scan' internally. (%scan-token () ;; Read and return a new token. (let ((ch (peek-char nil in nil))) (cond ((null ch) nil) ((digit-char-p ch) (values (parse-integer (parse in (complement #'digit-char-p) "" nil)))) (t (read-char in))))) ;; Return the following token, then upgrade the ;; values of token1 and token2. If there is not ;; following token, then signal a error. (scan () (if token1 (prog1 token1 (setf token1 token2) (setf token2 (%scan-token))) (ill-formed))) ;; Signal a ill-formed error (ill-formed () (%parse-error "bad formed duration.")) ;; Add a duration to other. It is consistent if both ;; D1 and D2 are not backward durations. (duration+ (d1 d2) (make-instance 'duration :days (+ (%duration-days d1) (%duration-days d2)) :seconds (+ (%duration-seconds d1) (%duration-seconds d2)))) ;; Check the current token is the character CH and ;; read a new token. Otherwise, a error is signaled. (check-character (ch) (unless (char= (scan) ch) (ill-formed))) ;; The following functions stand for a state, which ;; parse a subset of the grammar and return a partial ;; duration object. ;; ;; If the input is not matched then an error is ;; signaled. ;; ... (dur-value () (funcall (case (scan) (#\+ (check-character #\P) #'identity) (#\- (check-character #\P) #'duration-inverse) (#\P #'identity) (t (ill-formed))) (cond ((eql token1 #\T) (dur-time)) ((eql token2 #\W) (dur-week)) ((eql token2 #\D) (dur-date)) (t (ill-formed))))) (dur-date () (duration+ (dur-day) (if token1 (dur-time) (make-duration)))) (dur-time () (check-character #\T) (case token2 (#\H (dur-hour)) (#\M (dur-minute)) (#\S (dur-second)) (t (ill-formed)))) (dur-week () (prog1 (make-duration :days (* (scan) 7)) (check-character #\W))) (dur-hour () (duration+ (prog1 (make-duration :hours (scan)) (check-character #\H)) (if token1 (dur-minute) (make-duration)))) (dur-minute () (duration+ (prog1 (make-duration :minutes (scan)) (check-character #\M)) (if token1 (dur-second) (make-duration)))) (dur-second () (prog1 (make-duration :seconds (scan)) (check-character #\S))) (dur-day () (prog1 (make-duration :days (scan)) (check-character #\D)))) ;; Initialize scanner token1 and token2 variables. (setf token1 (%scan-token)) (setf token2 (%scan-token)) ;; Initial state (prog1 (duration (dur-value)) ;; We make sure we have parse all string. (unless (null token1) (ill-formed))))))) ;;; types-duration.lisp
10,227
Common Lisp
.lisp
253
26.766798
81
0.48354
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
c78b4646602ab5e7c4819e689f895809a54b073f630bc3679ad5a51e75492217
8,874
[ -1 ]
8,875
types-recur.lisp
davazp_cl-icalendar/types-recur.lisp
;; types-recur.lisp --- ;; ;; This file implements the recur data type. ;; ;; Copyrigth (C) 2009, 2010 Mario Castelán Castro <marioxcc> ;; Copyrigth (C) 2009, 2010, 2011 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) ;;; The RECUR data type implementation involves iteration across RECUR ;;; instances. Iteration is used in order to implement the COUNT and BYSETPOS ;;; rules basically. In the special case these rules are not present, we will ;;; say the recur is _simple_. We will use `%simple-recur-instance-p'. ;;; However, the iteration mechanism will works anyway. ;;; ;;; According to FREQ recur rule, the BY* rules could be classified in ;;; expansion rules and limitation ones. On the one hand, the expansion rules, ;;; are used to select what datetimes of a interval are instances in a ;;; recur. On the other hand, the limitation rules are used in order to ;;; distinguish which intervals are candidate to contain instances. See BYDAY ;;; for some exceptions. This is implemented in the source code described here ;;; by couples of functions which are named %recur-list-instances-* and ;;; %recur-next-*, respectively. These functions ignore COUNT and BYSETPOS ;;; recur rules. ;;; ;;; Finally, `recur-iterator-new' and `recur-iterator-next' will dispatch upon ;;; previous functions, in addition of add support for COUNT and BYSETPOS ;;; rules. A high level macro `do-recur-instances' is also provided. (deftype non-zero-integer (a b) `(and (integer ,a ,b) (not (eql 0)))) (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *frequencies* '(:secondly :minutely :hourly :daily :weekly :monthly :yearly))) (deftype recur-frequence () `(member ,@*frequencies*)) ;;; Alist of frequency strings and values. (defvar *frequency-table* (mapcar (lambda (s) (cons (string s) s)) *frequencies*)) ;;; The recur data type value is documented in the section 3.3.10, ;;; named `Recurrence Rule' of RFC5545. (defclass recur () ((freq :initarg :freq :type recur-frequence :reader recur-freq) (until :initarg :until :type (or null datetime date) :initform nil :reader recur-until) (count :initarg :count :type (or null unsigned-byte) :initform nil :reader recur-count) (interval :initarg :interval :type (integer 1 *) :initform 1 :reader recur-interval) (bysecond :initarg :bysecond :type list :initform nil :reader recur-bysecond) (byminute :initarg :byminute :type list :initform nil :reader recur-byminute) (byhour :initarg :byhour :type list :initform nil :reader recur-byhour) ;; Each element of byday list is a pair (wday . n), where wday is a weekday ;; value, and n is the optional prefix in the byday rule. (byday :initarg :byday :type list :initform nil :reader recur-byday) (bymonthday :initarg :bymonthday :type list :initform nil :reader recur-bymonthday) (byyearday :initarg :byyearday :type list :initform nil :reader recur-byyearday) (byweekno :initarg :byweekno :type list :initform nil :reader recur-byweekno) (bymonth :initarg :bymonth :type list :initform nil :reader recur-bymonth) (bysetpos :initarg :bysetpos :type list :initform nil :reader recur-bysetpos) (wkst :initarg :wkst :type weekday :initform :monday :reader recur-wkst))) (register-ical-value recur) ;;; Return a new recur value. (defun make-recur (freq &rest args) (apply #'make-instance 'recur :freq freq args)) ;;; The predicate function in order to check if an arbitrary object is a ;;; recurrence value. (define-predicate-type recur) (defprinter (obj recur) (write-string (format-value obj 'recur))) ;;; Bind the symbols FREQ, UNTIL, COUNT, INTERVAL, BYSECOND, BYMINUTE, BYHOUR, ;;; BYDAY, BYMONTHDAY, BYYEARDAY, BYWEEKNO, BYMONTH, BYSETPOSWKST, WKST and ;;; BYSETPOS to the respective slot values of RECUR. These symbols are ;;; setf-able too. (defmacro with-recur-slots (recur &body code) `(with-slots (freq until count interval bysecond byminute byhour byday bymonthday byyearday byweekno bymonth bysetposwkst wkst bysetpos) ,recur (declare (ignorable freq until count interval bysecond byminute byhour byday bymonthday byyearday byweekno bymonth bysetposwkst wkst bysetpos)) ,@code)) ;;; Check the consistency of RECUR. This function makes sure the type of ;;; slot's values in the recur instance are valid. This is not redundant with ;;; :type slots options. The slot types are checked when a recur is ;;; instantiated, while check-recur-consistency is called after ;;; parsing. Indeed, check-recur-consistency is more intensive. (defun check-recur-consistency (recur) (unless (slot-boundp recur 'freq) (%parse-error "FREQ rule is required.")) (with-recur-slots recur (check-type freq recur-frequence) (unless (or (not until) (not count)) (%parse-error "You cannot specify both UNTIL and COUNT recur rules.")) ;; Check optional slots (check-type until (or null date datetime)) (check-type count (or null (integer 0 *))) (check-type interval (or null (integer 0 *))) (check-type wkst weekday) ;; Check list slots (unless (or (eq freq :monthly) (eq freq :yearly)) (dolist (bydayrule byday) (when (cdr bydayrule) (%parse-error "prefix weekday cannot be specified in a other monthly or yearly recurs.")))) (check-type-list bysecond (integer 0 60)) (check-type-list byminute (integer 0 59)) (check-type-list byhour (integer 0 23)) (check-type-list bymonthday (non-zero-integer -31 31)) (check-type-list byyearday (non-zero-integer -366 366)) (check-type-list byweekno (non-zero-integer -53 53)) (check-type-list bymonth (integer 0 12)) (check-type-list bysetpos (non-zero-integer -366 366)))) ;;;; Date and time related functions ;;; Check if the frequence X is lesser than the Y one. (defun freq< (x y) (declare (recur-frequence x y)) (member< x y *frequencies*)) ;;; Return the nth DAY of month in year. This handles negative days propertily . (defun monthday (day month year) (let ((monthdays (if (leap-year-p year) #(0 31 29 31 30 31 30 31 31 30 31 30 31) #(0 31 28 31 30 31 30 31 31 30 31 30 31)))) (mod* day (svref monthdays month)))) (defun monthday-list (days month year) (mapcar #'monthday days (circular month) (circular year))) ;;; Return the nth DAY in year. This handles negative days propertily. (defun yearday (day year) (if (leap-year-p year) (mod* day 366) (mod* day 365))) (defun yearday-list (days year) (mapcar #'yearday days (circular year))) ;;; Iterate across the cartesian product of several lists. Each element of ;;; FORMS is a list of the form (variable list). LIST is evaluated and the ;;; body is run with variables bound to the values. (defmacro do-cartesian (forms &body code) (if (null forms) `(progn ,@code) (destructuring-bind ((var list) &rest others) forms `(dolist (,var ,list) (do-cartesian ,others ,@code))))) ;;; The until-satisfy-conditions macro implements a new control form. The syntax is: ;;; ;;; (until-satisfy-conditions (variable initial-form) ;;; (condition1 ;;; ...body1...) ;;; (condition2 ;;; ...body2...) ;;; ...) ;;; ;;; First, INITIAL-FORM is evaluated and VARIABLE is bound to its value. Then, ;;; for each iteration the conditions are evaluated in order, until one is not ;;; verified. In that case, the associated body is run and the we repeat the ;;; loop modifying the variable to the returned value by the last expression ;;; in that body. If all conditions are verified, the loop finishes and return ;;; the current value of VARIABLE. (defmacro until-satisfy-conditions ((variable value) &body code) (with-gensyms (initial) (check-type variable symbol) `(let ((,variable ,value)) (tagbody ,initial ,@(loop for (condition . body) in code collect `(unless ,condition (setf ,variable (progn ,@body)) (go ,initial)))) ,variable))) (defmacro belong (list element &key key) (once-only (list element key) `(implyp ,list (find ,element ,list :key ,key)))) ;;; Return a recur such that the omitted rules: BYSECOND, BYMINUTE, BYHOUR, ;;; BYMONTHDAY, BYMONTH, and BYDAY, are filled with default values taken from ;;; the DTSTART datetime. (defun %complete-recur (recur dtstart) (decoded-universal-time (:second dtsec :minute dtmin :hour dthour :date dtdate :month dtmonth) dtstart (with-recur-slots recur (make-instance 'recur :freq freq :until until :count count :interval interval :bysetpos bysetpos :wkst wkst :byyearday byyearday :byweekno byweekno :bysecond (or bysecond (list dtsec)) :byminute (or byminute (and (freq< :minutely freq) (list dtmin))) :byhour (or byhour (and (freq< :hourly freq) (list dthour))) :byday (or byday (and (or byweekno (eq freq :weekly)) (list (list (day-of-week dtstart))))) :bymonthday (or bymonthday (and (freq< :weekly freq) (not byday) (not byyearday) (not byweekno) (list dtdate))) :bymonth (or bymonth (and (freq< :monthly freq) (not byday) (not byyearday) (not byweekno) (list dtmonth))))))) ;;; Given a DATETIME and a RECUR, return a couple of values which are the ;;; limits of the interval which the datetime belongs to. (defun interval-limits (datetime recur) (case (recur-freq recur) (:secondly (values datetime datetime)) (:minutely (values (adjust-time datetime :second 0) (adjust-time datetime :second 59))) (:hourly (values (adjust-time datetime :minute 00 :second 00) (adjust-time datetime :minute 59 :second 59))) (:daily (values (adjust-time datetime :hour 00 :minute 00 :second 00) (adjust-time datetime :hour 23 :minute 59 :second 59))) (:weekly (values (previous-weekday (date+ datetime 1) (recur-wkst recur)) (date+ (next-weekday datetime (recur-wkst recur)) -1))) (:monthly (values (beginning-of-month datetime) (end-of-month datetime))) (:yearly (values (beginning-of-year datetime) (end-of-year datetime))))) ;;; Check if DATETIME is compatible with a byday VALUE for the interval given ;;; for START and END datetimes. The limits START and END are inclusive. (defun byday-compatible-p (value datetime start end) (let* ((day-of-week (day-of-week datetime)) (first-day (next-weekday (date+ start -1) day-of-week)) (last-day (previous-weekday (date+ end 1) day-of-week)) (total-weeks (1+ (weeks-between first-day last-day)))) (and value (loop for (weekday . n) in value thereis (when (eq day-of-week weekday) (or (null n) (let* ((weeks (1+ (weeks-between first-day datetime)))) (and (< 0 weeks) (= (mod* n total-weeks) (mod* weeks total-weeks)))))))))) ;;; Handle some very simple cases of `recur-instance-p'. In general, every ;;; recur without BYSETPOS either COUNT rules are handled here, because it is ;;; not needed to iterate. (defun %simple-recur-instance-p (start recur datetime) (with-recur-slots recur ;; (assert (not bysetpos)) ;; (assert (not count)) (and ;; DATETIME is an instance of RECUR if and only if all the following ;; conditions are satisfied. (ecase freq (:secondly (zerop (mod (seconds-between start datetime) interval))) (:minutely (zerop (mod (minutes-between start datetime) interval))) (:hourly (zerop (mod (hours-between start datetime) interval))) (:daily (zerop (mod (days-between start datetime) interval))) (:weekly (zerop (mod (weeks-between start datetime) interval))) (:monthly (zerop (mod (months-between start datetime) interval))) (:yearly (zerop (mod (years-between start datetime) interval)))) ;; Before UNTIL (or (null until) (<= start datetime)) ;; Other rules (multiple-value-bind (second minute hour date month year) (decode-universal-time datetime) (let ((byyearday (yearday-list byyearday year)) (bymonthday (monthday-list bymonthday month year))) (and (belong byhour hour) (belong byminute minute) (belong bysecond second) (belong bymonthday date) (belong bymonth month) (belong byweekno (week-of-year datetime wkst)) (belong byyearday (day-of-year datetime)) (implyp byday (multiple-value-bind (start end) (interval-limits datetime recur) (byday-compatible-p byday datetime start end))))))))) (defun %recur-list-instances-in-second (dt recur) (declare (ignorable recur)) (list dt)) (defun %recur-next-second (dt recur) (with-recur-slots recur (until-satisfy-conditions (datetime (forward-second dt interval)) ((belong bymonth (date-month datetime)) (adjust-datetime (forward-month datetime) :day 1 :hour 00 :minute 00 :second 00)) ((belong byyearday (day-of-year datetime) :key (lambda (yday) (yearday yday (date-year datetime)))) (adjust-time (forward-day datetime) :hour 00 :minute 00 :second 00)) ((belong bymonthday (date-day datetime) :key (lambda (mday) (let ((month (date-month datetime)) (year (date-year datetime))) (monthday mday month year)))) (adjust-time (forward-day datetime) :hour 00 :minute 00 :second 00)) ((belong byday (day-of-week datetime) :key #'car) (adjust-time (forward-day datetime) :hour 00 :minute 00 :second 00)) ((belong byhour (time-hour datetime)) (adjust-time (forward-hour datetime) :minute 00 :second 00)) ((belong byminute (time-minute datetime)) (adjust-time (forward-minute datetime) :second 00)) ((belong bysecond (time-second datetime)) (forward-second datetime interval))))) (defun %recur-list-instances-in-minute (dt recur) (with-collect (do-cartesian ((second (recur-bysecond recur))) (collect (adjust-time dt :second second))))) (defun %recur-next-minute (dt recur) (with-recur-slots recur (until-satisfy-conditions (datetime (forward-minute dt interval)) ((belong bymonth (date-month datetime)) (adjust-datetime (forward-month datetime) :day 01 :hour 00 :minute 00)) ((belong byyearday (day-of-year datetime) :key (lambda (yday) (yearday yday (date-year datetime)))) (adjust-time (forward-day datetime) :hour 00 :minute 00)) ((belong bymonthday (date-day datetime) :key (lambda (mday) (let ((month (date-month datetime)) (year (date-year datetime))) (monthday mday month year)))) (adjust-time (forward-day datetime) :hour 00 :minute 00)) ((belong byday (day-of-week datetime) :key #'car) (adjust-time (forward-day datetime) :hour 00 :minute 00)) ((belong byhour (time-hour datetime)) (adjust-time (forward-hour datetime) :minute 00)) ((belong byminute (time-minute datetime)) (forward-minute datetime interval))))) (defun %recur-list-instances-in-hour (dt recur) (with-collect (do-cartesian ((minute (recur-byminute recur)) (second (recur-bysecond recur))) (collect (adjust-time dt :minute minute :second second))))) (defun %recur-next-hour (dt recur) (with-recur-slots recur (until-satisfy-conditions (datetime (forward-hour dt interval)) ((belong bymonth (date-month datetime)) (adjust-datetime (forward-month datetime) :day 01 :hour 00)) ((belong byyearday (day-of-year datetime) :key (lambda (yday) (yearday yday (date-year datetime)))) (adjust-time (forward-day datetime) :hour 00)) ((belong bymonthday (date-day datetime) :key (lambda (mday) (let ((month (date-month datetime)) (year (date-year datetime))) (monthday mday month year)))) (adjust-time (forward-day datetime) :hour 00)) ((belong byday (day-of-week datetime) :key #'car) (adjust-time (forward-day datetime) :hour 00)) ((belong byhour (time-hour datetime)) (forward-hour datetime interval))))) (defun %recur-list-instances-in-day (dt recur) (with-collect (do-cartesian ((h (recur-byhour recur)) (m (recur-byminute recur)) (s (recur-bysecond recur))) (collect (adjust-time dt :hour h :minute m :second s))))) (defun %recur-next-day (dt recur) (with-recur-slots recur (until-satisfy-conditions (datetime (forward-day dt interval)) ((belong bymonth (date-month datetime)) (adjust-date (forward-month datetime) :day 01)) ((belong bymonthday (date-day datetime) :key (lambda (mday) (let ((month (date-month datetime)) (year (date-year datetime))) (monthday mday month year)))) (forward-day datetime interval)) ((belong byday (day-of-week datetime) :key #'car) (forward-day datetime interval))))) (defun %recur-list-instances-in-week (dt recur) (with-collect (do-cartesian ((d (recur-byday recur)) (h (recur-byhour recur)) (m (recur-byminute recur)) (s (recur-bysecond recur))) (let ((dt* (adjust-time dt :hour h :minute m :second s))) (collect (next-weekday dt* (car d))))))) (defun %recur-next-week (dt recur) (with-recur-slots recur (until-satisfy-conditions (datetime (forward-week dt interval)) ((belong bymonth (date-month datetime) :key (lambda (m) (let ((month (date-month datetime)) (year (date-year datetime))) (monthday m month year)))) (forward-month datetime interval))))) (defun %recur-list-instances-in-month (dt recur) (with-recur-slots recur (cond ;; If BYMONTHDAY is given, BYDAY rule limits the recur. So, we iterate ;; in order to collect the datetimes compatible with the BYMONTHDAY, ;; BYHOUR, BYMINUTE and BYSECOND. (bymonthday (with-collect (do-cartesian ((d bymonthday) (h byhour) (m byminute) (s bysecond)) (let* ((mday (monthday d (date-month dt) (date-year dt))) (dt* (adjust-datetime dt :day mday :hour h :minute m :second s))) (if (null byday) (collect dt*) (multiple-value-bind (start end) (interval-limits dt* recur) (when (byday-compatible-p byday dt* start end) (collect dt*)))))))) ;; If BYMONTHDAY is not present and byday does is, we collect ;; compatible datetimes without iterate. (byday (assert (not bymonthday)) (with-collect (do-cartesian ((d byday) (h byhour) (m byminute) (s bysecond)) (multiple-value-bind (start end) (interval-limits dt recur) (let* ((weekday (car d)) (nweekday (cdr d)) (first-day (next-weekday start weekday)) (last-day (previous-weekday end weekday)) (total-weeks (1+ (weeks-between first-day last-day))) (adjusted (adjust-time first-day :hour h :minute m :second s))) ;; We collect the computed datetime if NWEEKDAY is ;; non-nil. Otherwise, we collect datetimes which matches ;; with weekday. (if nweekday (let ((days (* 7 (1- (mod* nweekday total-weeks))))) (collect (forward-day adjusted days))) (dotimes (i total-weeks) (collect (forward-day adjusted (* i 7))))))))))))) (defun %recur-next-month (dt recur) (with-recur-slots recur (do ((delta interval (+ delta interval)) (datetime (forward-month dt interval) (forward-month datetime interval))) ((or (null bymonth) (>= delta (lcm 12 interval)) (find (date-month datetime) bymonth)) (if (<= delta (lcm 12 interval)) datetime nil))))) (defun %recur-list-instances-in-year (datetime recur) (with-recur-slots recur ;; The local function compatible-p checks if a datetime DT is compatible ;; with some BY* rules. This does not check all BY* rules, because we can ;; make sure some rules will be verified. (flet ((compatible-p (dt) (and (belong bymonth (date-month dt)) (belong byweekno (week-of-year dt (recur-wkst recur))) (belong byyearday (day-of-year dt) :key (lambda (n) (yearday n (date-year dt)))) (belong bymonthday (date-day dt) :key (lambda (n) (monthday n (date-month dt) (date-year dt)))) (implyp byday (if bymonth (let ((start (beginning-of-month dt)) (end (end-of-month dt))) (byday-compatible-p byday dt start end)) (multiple-value-bind (start end) (interval-limits dt recur) (byday-compatible-p byday dt start end))))))) (cond ;; If one of BYMONTH or BYMONTHDAY is given, then we iterate across ;; all dates which match with this description. We must check it is ;; compatible with the rest of the BY* rules. ((or bymonth bymonthday) (with-collect (do-cartesian ((month (or bymonth (range 1 12))) (day (or bymonthday (range 1 (monthday -1 month (date-year datetime))))) (hour byhour) (minute byminute) (second bysecond)) (let ((dt* (encode-universal-time second minute hour day month (date-year datetime)))) (when (compatible-p dt*) (collect dt*)))))) ;; In this point, not BYMONTH or BYMONTHDAY rule is present. If a ;; BYYEARDAY is present, then we can iterate across them. (byyearday (with-collect (let ((first (beginning-of-year datetime))) (dolist (yday byyearday) (let ((dt* (forward-day first (1- (yearday yday (date-year first)))))) (when (compatible-p dt*) (collect dt*))))))) ;; We have considered the BYMONTH rule previosly, so, the offset of ;; BYDAY rule here is considered relative to the year. (byday (assert (not bymonth)) (with-collect (dolist (rule byday) (multiple-value-bind (start end) (interval-limits datetime recur) (let* ((weekday (car rule)) (n (cdr rule)) (first (next-weekday start weekday)) (last (previous-weekday end weekday))) (cond ((null n) (dotimes (i (weeks-between first last)) (let ((dt* (forward-day first (* 7 (1+ i))))) (when (compatible-p dt*) (collect dt*))))) ((< n 0) (collect (backward-day last (* 7 (1+ (abs n)))))) ((> n 0) (collect (forward-day first (* 7 (1- n))))))))))) (t ;; Note that some of BYDAY, BYYEARDAY or BYMONTHDAY/BYMONTH rules ;; should be specified. In other case, %complete-recur should add a ;; BYDAY or BYMONTHDAY/BYMONTH rule. nil))))) (defun %recur-next-year (dt recur) ;; RECUR objects with FREQ set to YEARLY has not limitation rules, so we add ;; INTERVAL years to DT simply. (let ((year (date-year dt))) (adjust-date dt :year (+ year (recur-interval recur))))) (defstruct recur-iterator dtstart recur (count 0) interval instances) (defun filter-bysetpos (list bysetpos) (if (null bysetpos) list (loop with length = (length list) for index from 1 for x in list when (belong bysetpos index :key (lambda (m) (mod* m length))) collect x))) (defun clean-instances (list) (delete-duplicates (sort list #'<))) (defun recur-iterator-new (recur datetime) (let ((recur (%complete-recur recur datetime))) (let* ((first-instances (case (recur-freq recur) (:secondly (%recur-list-instances-in-second datetime recur)) (:minutely (%recur-list-instances-in-minute datetime recur)) (:hourly (%recur-list-instances-in-hour datetime recur)) (:daily (%recur-list-instances-in-day datetime recur)) (:weekly (%recur-list-instances-in-week datetime recur)) (:monthly (%recur-list-instances-in-month datetime recur)) (:yearly (%recur-list-instances-in-year datetime recur)))) (post-instances (remove-if (curry #'> datetime) first-instances)) (final-instances (filter-bysetpos (clean-instances post-instances) (recur-bysetpos recur)))) ;; Return the iterator (make-recur-iterator :dtstart datetime :interval datetime :recur recur :instances final-instances)))) (defun recur-iterator-next (iter) (let ((datetime (recur-iterator-interval iter)) (recur (recur-iterator-recur iter))) (cond ;; If COUNT rule is not verified, return NIL. ((and (recur-count recur) (>= (recur-iterator-count iter) (recur-count recur))) nil) ;; If UNTIL rule is not verified ((and (recur-until recur) (recur-iterator-instances iter) (< (recur-until recur) (first (recur-iterator-instances iter)))) nil) ;; If there is pending instances, return and increment the counter. ((recur-iterator-instances iter) (incf (recur-iterator-count iter)) (pop (recur-iterator-instances iter))) (t ;; Otherwise, we request more instances. (case (recur-freq recur) (:secondly (setf datetime (%recur-next-second datetime recur)) (setf (recur-iterator-instances iter) (%recur-list-instances-in-second datetime recur))) (:minutely (setf datetime (%recur-next-minute datetime recur)) (setf (recur-iterator-instances iter) (%recur-list-instances-in-minute datetime recur))) (:hourly (setf datetime (%recur-next-hour datetime recur)) (setf (recur-iterator-instances iter) (%recur-list-instances-in-hour datetime recur))) (:daily (setf datetime (%recur-next-day datetime recur)) (setf (recur-iterator-instances iter) (%recur-list-instances-in-day datetime recur))) (:weekly (setf datetime (%recur-next-week datetime recur)) (setf (recur-iterator-instances iter) (%recur-list-instances-in-week datetime recur))) (:monthly (setf datetime (%recur-next-month datetime recur)) (setf (recur-iterator-instances iter) (%recur-list-instances-in-month datetime recur))) (:yearly (setf datetime (%recur-next-year datetime recur)) (setf (recur-iterator-instances iter) (%recur-list-instances-in-year datetime recur)))) ;; ...and apply the BYSETPOS rule finally! (setf (recur-iterator-interval iter) datetime) (setf (recur-iterator-instances iter) (filter-bysetpos (clean-instances (recur-iterator-instances iter)) (recur-bysetpos recur))) (when (recur-iterator-instances iter) (recur-iterator-next iter)))))) (defmacro do-recur-instances ((variable recur dtstart &optional result) &body code) (check-type variable symbol) (with-gensyms (iterator) `(let ((,iterator (recur-iterator-new ,recur ,dtstart))) (do ((,variable (recur-iterator-next ,iterator) (recur-iterator-next ,iterator))) ((null ,variable) ,result) ,@code)))) ;; Check if DATETIME is a valid ocurrence in RECUR. (defun recur-instance-p (start recur datetime) (unless (%simple-recur-instance-p start recur start) (error "The recur and DTSTART must be synchronized.")) (let ((complete-recur (%complete-recur recur start))) (with-recur-slots complete-recur (cond ((and (null count) (null bysetpos)) (%simple-recur-instance-p start complete-recur datetime)) (t (do-recur-instances (dt recur start nil) (cond ((= dt datetime) (return t)) ((> dt datetime) (return nil))))))))) ;; List the instances of a bound RECUR. (defun list-recur-instances (start recur) (unless (%simple-recur-instance-p start recur start) (error "The recur and DTSTART must be synchronized.")) (let ((complete-recur (%complete-recur recur start))) (with-recur-slots complete-recur (when (and (not count) (not until)) (error "This recur is not an unbound recur.")) (with-collect (do-recur-instances (dt recur start nil) (collect dt)))))) ;;; Parsing and formatting (defun parse-byday-value (string) (multiple-value-bind (n end) (parse-integer string :junk-allowed t) (if (and (null n) (< 0 end)) (%parse-error "~a is not a weekday." string) (let* ((str (subseq string end))) (aif (position str #("MO" "TU" "WE" "TH" "FR" "SA" "SU") :test #'string-ci=) (cons (svref *weekday* it) n) (%parse-error "~a is not a weekday." str)))))) (defun parse-rule-part (string) (declare (string string)) (let ((eqpos (position #\= string))) (when (null eqpos) (%parse-error "Bad rule part ~a" string)) (cons (subseq string 0 eqpos) (subseq string (1+ eqpos))))) (defun parse-rules (string) (declare (string string)) (let ((parts (split-string string ";" nil))) (when (some #'null parts) (%parse-error "Empty rule part in the recurrence '~a'." string)) (mapcar #'parse-rule-part parts))) (defmethod parse-value (string (type (eql 'recur)) &optional params) (declare (string string) (ignore params)) (let ((rules (parse-rules string)) (recur (make-instance 'recur))) (when (duplicatep rules :key #'car :test #'string-ci=) (%parse-error "Duplicate key in recurrence.")) (flet ((parse-integer-list (x) (mapcar #'parse-integer (split-string x ","))) (parse-unsigned-integer-list (x) (mapcar #'parse-unsigned-integer (split-string x ",")))) (dolist (rule rules) (destructuring-bind (key . value) rule (cond ((string-ci= key "FREQ") (setf (slot-value recur 'freq) (or (cdr (assoc value *frequency-table* :test #'string-ci=)) (%parse-error "'~a' is not a valid value for the FREQ rule." value)))) ((string-ci= key "UNTIL") (setf (slot-value recur 'until) (handler-case (parse-value value 'datetime) (icalendar-parse-error () (parse-value value 'date))))) ((string-ci= key "COUNT") (setf (slot-value recur 'count) (parse-unsigned-integer value))) ((string-ci= key "INTERVAL") (setf (slot-value recur 'interval) (parse-unsigned-integer value))) ((string-ci= key "BYSECOND") (setf (slot-value recur 'bysecond) (sort (parse-unsigned-integer-list value) #'<))) ((string-ci= key "BYMINUTE") (setf (slot-value recur 'byminute) (sort (parse-unsigned-integer-list value) #'<))) ((string-ci= key "BYHOUR") (setf (slot-value recur 'byhour) (sort (parse-unsigned-integer-list value) #'<))) ((string-ci= key "BYDAY") (setf (slot-value recur 'byday) (mapcar #'parse-byday-value (split-string value ",")))) ((string-ci= key "BYMONTH") (setf (slot-value recur 'bymonth) (sort (parse-integer-list value) #'<))) ((string-ci= key "BYMONTHDAY") (setf (slot-value recur 'bymonthday) (parse-integer-list value))) ((string-ci= key "BYYEARDAY") (setf (slot-value recur 'byyearday) (parse-integer-list value))) ((string-ci= key "BYWEEKNO") (setf (slot-value recur 'byweekno) (parse-integer-list value))) ((string-ci= key "BYSETPOS") (setf (slot-value recur 'bysetpos) (sort (parse-integer-list value) #'<))) ((string-ci= key "WKST") (setf (slot-value recur 'wkst) (let ((nday (position value *weekday-names* :test #'string-ci=))) (when (null nday) (%parse-error "~a is not a weekday." value)) (svref *weekday* nday)))) (t (%parse-error "Unknown recurrence component ~a" key))))) ;; Return the recur instance (check-recur-consistency recur) recur))) (defmethod format-value ((recur recur) (type (eql 'recur)) &optional params) (declare (ignore params)) (with-recur-slots recur (with-output-to-string (s) (format s "FREQ=~a" (car (rassoc freq *frequency-table*))) ;; Print optional recur slots. (format s "~[~;~;~:;;INTERVAL=~:*~d~]" interval) (format s "~@[;COUNT=~a~]" count) (format s "~:[~;;UNTIL=~:*~a~]" (and until (format-value until 'datetime))) (format s "~@[;BYSECOND=~{~A~^,~}~]" bysecond) (format s "~@[;BYMINUTE=~{~A~^,~}~]" byminute) (format s "~@[;BYHOUR=~{~A~^,~}~]" byhour) (format s "~@[;BYDAY=~{~@[~d~]~a~^,~}~]" (with-collect (dolist (day byday) (destructuring-bind (wday . n) day (collect n) (collect (svref *weekday-names* (position wday *weekday*))))))) (format s "~@[;BYMONTH=~{~A~^,~}~]" bymonth) (format s "~@[;BYMONTHDAY=~{~A~^,~}~]" bymonthday) (format s "~@[;BYYEARDAY=~{~A~^,~}~]" byyearday) (format s "~@[;BYWEEKNO=~{~A~^,~}~]" byweekno) (format s "~@[;BYSETPOS=~{~A~^,~}~]" bysetpos) (unless (eq wkst :monday) (let ((nwkst (position (recur-wkst recur) *weekday*))) (format s ";WKST=~a" (svref *weekday-names* nwkst))))))) ;;; Local variables: ;;; fill-column: 78 ;;; indent-tabs-mode: nil ;;; End: ;;; types-recur.lisp ends here
37,569
Common Lisp
.lisp
848
34.456368
101
0.58966
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
1309a734e5d0a7fc4f353053fd3bae2597c48d0a6b93e99e2a0ed71027871a51
8,875
[ -1 ]
8,876
folding.lisp
davazp_cl-icalendar/folding.lisp
;; folding.lisp ;; ;; Copyrigth (C) 2009, 2010 Mario Castelán Castro <marioxcc> ;; Copyrigth (C) 2009, 2010 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar) (defconstant +tab-character+ (code-char #x09)) (defconstant +content-line-max-length+ 75) (defclass folding-stream (fundamental-character-input-stream fundamental-character-output-stream) ((column-octets :initform 0 :type fixnum :reader folding-column-octets) (backend-stream :initform (required-arg) :type stream :initarg :stream :reader folding-backend-stream))) (defun make-folding-stream (stream) (make-instance 'folding-stream :stream stream)) (defmacro with-folding-stream ((var stream) &body code) `(with-open-stream (,var (make-folding-stream ,stream)) ,@code)) (defun linear-whitespace-p (character) (or (char= character #\space) (char= character +tab-character+))) (defmethod stream-read-char ((stream folding-stream)) (with-slots (backend-stream) stream (let ((character (read-char backend-stream))) (cond ((eq character :eof) :eof) ;; #\return #\newline => #\newline ((char= character #\return) (when (eql (peek-char nil backend-stream nil) #\newline) (stream-read-char stream))) ((and (char= character #\newline) (linear-whitespace-p (peek-char nil backend-stream nil #\A))) ;; Skip the newline from folding algorithm and go on. (read-char backend-stream) (read-char backend-stream)) (t character))))) (defmethod stream-unread-char ((stream folding-stream) character) (unread-char character (folding-backend-stream stream))) ;;; This method is redundant as we have defined stream-read-char, but ;;; we provide it due to performance reasons. (defmethod stream-read-line ((stream folding-stream)) (let ((backend (folding-backend-stream stream)) (output (make-string-output-stream)) line missing-newline-p (finishp nil)) (while (not finishp) (multiple-value-setq (line missing-newline-p) (read-line backend nil)) (write-string (string-right-trim (list #\return) line) output) (if (linear-whitespace-p (peek-char nil backend nil #\A)) (read-char backend) (setq finishp t))) (values (get-output-stream-string output) missing-newline-p))) (defmethod stream-write-char ((stream folding-stream) character) (with-slots (column-octets backend-stream) stream (let* ((encoded (babel:string-to-octets (if (char= character #\newline) #.(coerce '(#\return #\linefeed) 'string) (string character)))) (size (length encoded))) (when (> (+ column-octets size) +content-line-max-length+) (stream-write-char stream #\newline) (stream-write-char stream #\space) (zerof column-octets)) (if (char= character #\linefeed) (zerof column-octets) (incf column-octets size)) (write-sequence encoded backend-stream)))) (defmethod stream-line-column ((stream folding-stream)) (stream-line-column (folding-backend-stream stream))) (defmethod stream-finish-output ((stream folding-stream)) (finish-output (folding-backend-stream stream))) (defmethod stream-force-output ((stream folding-stream)) (force-output (folding-backend-stream stream))) (defmethod stream-clear-output ((stream folding-stream)) (clear-output (folding-backend-stream stream))) (defmethod close ((stream folding-stream) &key abort) (close (folding-backend-stream stream) :abort abort)) ;;; folding.lisp ends here
4,393
Common Lisp
.lisp
100
38.02
76
0.68102
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
3eadd68405a8b4eca4704d50d0b3cfae4604a3542e35f013290a71b4156738f8
8,876
[ -1 ]
8,877
package.lisp
davazp_cl-icalendar/tests/package.lisp
;; package.lisp ;; ;; Copyrigth (C) 2010 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (defpackage :cl-icalendar-tests (:use :cl :cl-icalendar :fiveam) (:shadow #:standard) (:export #:run-tests)) ;;; package.lisp ends here
890
Common Lisp
.lisp
23
37.347826
72
0.745665
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
77d5e1a07ed3295008d4d5506abf121aac4de514a0c4ccc6373bdbee8712f117
8,877
[ -1 ]
8,878
test-types-recur.lisp
davazp_cl-icalendar/tests/test-types-recur.lisp
;; test-types-recur.lisp ;; ;; Copyrigth (C) 2010 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar-tests) (in-suite icalendar-types) ;;; Recur data type tests (test recur-instance-p-interval-001 "Check INTERVAL rule." (is (recur-instance-p (ical::encode-datetime 01 01 2000 00 00 00) (parse-value "FREQ=DAILY;INTERVAL=2" 'recur) (ical::encode-datetime 01 01 2000 00 00 00))) (is (recur-instance-p (ical::encode-datetime 01 01 2000 00 00 00) (parse-value "FREQ=DAILY;INTERVAL=2" 'recur) (ical::encode-datetime 03 01 2000 00 00 00))) (is (recur-instance-p (ical::encode-datetime 01 01 2000 00 00 00) (parse-value "FREQ=DAILY;INTERVAL=2" 'recur) (ical::encode-datetime 05 01 2000 00 00 00))) (is (not (recur-instance-p (ical::encode-datetime 01 01 2000 00 00 00) (parse-value "FREQ=DAILY;INTERVAL=2" 'recur) (ical::encode-datetime 02 01 2000 00 00 00)))) (is (not (recur-instance-p (ical::encode-datetime 01 01 2000 00 00 00) (parse-value "FREQ=DAILY;INTERVAL=2" 'recur) (ical::encode-datetime 04 01 2000 00 00 00)))) (is (not (recur-instance-p (ical::encode-datetime 01 01 2000 00 00 00) (parse-value "FREQ=DAILY;INTERVAL=2" 'recur) (ical::encode-datetime 06 01 2000 00 00 00))))) (test recur-instance-p-interval-002 "Check INTERVAL rule." (is (recur-instance-p (ical::encode-datetime 01 01 2000 00 00 00) (parse-value "FREQ=WEEKLY;INTERVAL=2" 'recur) (ical::encode-datetime 01 01 2000 00 00 00))) (is (recur-instance-p (ical::encode-datetime 01 01 2000 00 00 00) (parse-value "FREQ=WEEKLY;INTERVAL=2" 'recur) (ical::encode-datetime 15 01 2000 00 00 00))) (is (recur-instance-p (ical::encode-datetime 01 01 2000 00 00 00) (parse-value "FREQ=WEEKLY;INTERVAL=2" 'recur) (ical::encode-datetime 29 01 2000 00 00 00))) (is (recur-instance-p (ical::encode-datetime 01 01 2000 00 00 00) (parse-value "FREQ=WEEKLY;INTERVAL=2" 'recur) (ical::encode-datetime 12 02 2000 00 00 00))) (is (not (recur-instance-p (ical::encode-datetime 01 01 2000 00 00 00) (parse-value "FREQ=WEEKLY;INTERVAL=2" 'recur) (ical::encode-datetime 08 01 2000 00 00 00)))) (is (not (recur-instance-p (ical::encode-datetime 01 01 2000 00 00 00) (parse-value "FREQ=WEEKLY;INTERVAL=2" 'recur) (ical::encode-datetime 02 01 2000 00 00 00)))) (is (not (recur-instance-p (ical::encode-datetime 01 01 2000 00 00 00) (parse-value "FREQ=WEEKLY;INTERVAL=2" 'recur) (ical::encode-datetime 22 01 2000 00 00 00)))) (is (not (recur-instance-p (ical::encode-datetime 01 01 2000 00 00 00) (parse-value "FREQ=WEEKLY;INTERVAL=2" 'recur) (ical::encode-datetime 05 02 2000 00 00 00))))) (test recur-parser-interval-p-003 "Check intervals" (is (not (recur-instance-p (ical::encode-datetime 01 01 2000 00 00 00) (parse-value "FREQ=YEARLY;INTERVAL=4;UNTIL=20160101T010101" 'recur) (ical::encode-datetime 01 01 2009 00 00 00)))) (is (recur-instance-p (ical::encode-datetime 01 01 2000 00 00 00) (parse-value "FREQ=MONTHLY;INTERVAL=6;COUNT=18" 'recur) (ical::encode-datetime 01 07 2008 00 00 00)))) (test recur-instance-p-bymonth "Check BYMONTH rule." (is (recur-instance-p (ical::encode-datetime 1 1 2000 00 00 00) (parse-value "FREQ=DAILY;BYMONTH=1" 'recur) (ical::encode-datetime 01 01 2000 00 00 00))) (is (recur-instance-p (ical::encode-datetime 1 1 2000 00 00 00) (parse-value "FREQ=DAILY;BYMONTH=1" 'recur) (ical::encode-datetime 31 01 2000 00 00 00))) (is (not (recur-instance-p (ical::encode-datetime 01 01 2000 00 00 00) (parse-value "FREQ=DAILY;BYMONTH=1" 'recur) (ical::encode-datetime 01 02 2000 00 00 00)))) (is (recur-instance-p (ical::encode-datetime 1 1 2000 00 00 00) (parse-value "FREQ=YEARLY;BYMONTH=1,2" 'recur) (ical::encode-datetime 01 02 2000 00 00 00)))) (test recur-parser-complex-p-001 "Check parser for some complex recurrency values and other errors" (is (not (recur-instance-p (ical::encode-datetime 01 01 2000 00 00 00) (parse-value "FREQ=DAILY;UNTIL=20121212T230000;BYDAY=MO,TH,SA;BYMONTH=1,3,5,7,9,11" 'recur) (ical::encode-datetime 12 12 2012 00 00 00)))) (signals error (parse-value "FREQ=MONTHLY;COUNT=20 ;UNTIL=20240812T230000;BYDAY=FR" 'recur)) (signals error (parse-value "FREQ=DAILY;INTERVAL=4;?UNTIL=20121212T000000" 'recur)) (signals error (parse-value "INTERVAL=4;COUNT=8" 'recur))) (test recur-parser-complex-p-002 "Check parser for some complex syntax errors." (signals error (parse-value "FREQ=MONTLY" 'recur)) (signals error (parse-value "FREQ=DAILY; INTERVAL=8" 'recur)) (signals error (parse-value "FREQ=_DAILY" 'recur)) (finishes (parse-value "FREQ=WEEKLY;INTERVAL=2;UNTIL=20121212" 'recur))) (test recur-complex-sign-p-001 "Check dates with signs" (is (recur-instance-p (ical::encode-datetime 28 06 2010 00 00 00) (parse-value "FREQ=MONTHLY;INTERVAL=2;BYDAY=-1MO" 'recur) (ical::encode-datetime 30 8 2010 00 00 00))) (is (recur-instance-p (ical::encode-datetime 11 06 2010 00 00 00) (parse-value "FREQ=MONTHLY;BYDAY=-1MO,-2TH,-3FR" 'recur) (ical::encode-datetime 17 06 2010 00 00 00))) (is (recur-instance-p (ical::encode-datetime 31 12 2010 00 00 00) (parse-value "FREQ=YEARLY;BYDAY=-1MO,-1FR" 'recur) (ical::encode-datetime 29 12 2014 00 00 00)))) ;;; test-types-recur.lisp ends here
7,093
Common Lisp
.lisp
115
49.034783
120
0.600976
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
da28802fa77a89de2b80144bd146de500ac2e2333bbdca4866fd3a2615b96577
8,878
[ -1 ]
8,879
test-types-duration.lisp
davazp_cl-icalendar/tests/test-types-duration.lisp
;; test-types-duration.lisp ;; ;; Copyrigth (C) 2010 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar-tests) ;;; Parsing (test parse-value-duration-001 "Parse some simple duration values." (is (= (duration-days (parse-value "P1D" 'duration)) 1)) (is (= (duration-days (parse-value "P7D" 'duration)) 7)) (is (= (duration-days (parse-value "+P1W" 'duration)) 7)) (is (= (duration-days (parse-value "-P1W" 'duration)) 7)) (is (= (duration-days (parse-value "PT0H" 'duration)) 0))) (test parse-value-duration-002 "Parse some wrong duration strings." (signals error (parse-value "P1H" 'duration)) (signals error (parse-value "PT1H3S" 'duration)) (signals error (parse-value "PT1H3S" 'duration))) ;;; test-types-duration.lisp ends here
1,447
Common Lisp
.lisp
33
42.090909
72
0.720369
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
47dddca4c6fbab051e9879509c25ce1cd81640d9565f2394e583da5c08c21c78
8,879
[ -1 ]
8,880
test-types-date.lisp
davazp_cl-icalendar/tests/test-types-date.lisp
;; test-types-date.lisp ;; ;; Copyrigth (C) 2010 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar-tests) (in-suite icalendar-types) (test week-of-year-001 (is (= (ical::week-of-year (ical::encode-date 01 1 2010)) 53)) (is (= (ical::week-of-year (ical::encode-date 02 1 2010)) 53)) (is (= (ical::week-of-year (ical::encode-date 03 1 2010)) 53)) (is (= (ical::week-of-year (ical::encode-date 04 1 2010)) 1)) (is (= (ical::week-of-year (ical::encode-date 10 1 2010)) 1)) (is (= (ical::week-of-year (ical::encode-date 11 1 2010)) 2)) (is (= (ical::week-of-year (ical::encode-date 01 1 2013) :tuesday) 1)) (is (= (ical::week-of-year (ical::encode-date 07 1 2013) :tuesday) 1)) (is (= (ical::week-of-year (ical::encode-date 09 1 2013) :tuesday) 2))) ;;; test-types.lisp ends here
1,478
Common Lisp
.lisp
31
45.967742
73
0.697159
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
f5375bcc57f7c090fae44f4c54abf48295a3c5cb8f0f1f24fe414de8510cac53
8,880
[ -1 ]
8,881
test-types.lisp
davazp_cl-icalendar/tests/test-types.lisp
;; test-types.lisp ;; ;; Copyrigth (C) 2010 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar-tests) (in-suite icalendar-types) ;;; Boolean data type (test parse-value-boolean-001 "Parse some boolean values." (is (parse-value "true" 'boolean)) (is (parse-value "TRUE" 'boolean)) (is (parse-value "tRUE" 'boolean)) (is (not (parse-value "false" 'boolean))) (is (not (parse-value "FALSE" 'boolean))) (is (not (parse-value "fAlse" 'boolean)))) (test parse-value-boolean-002 "Parse some non-boolean values." (signals error (parse-value "23" 'boolean)) (signals error (parse-value "t" 'boolean)) (signals error (parse-value "true2" 'boolean)) (signals error (parse-value "falses" 'boolean))) (test format-value-boolean-001 "Format some boolean values." (is (string= (format-value t 'boolean) "TRUE")) (is (string= (format-value nil 'boolean) "FALSE"))) ;;; Integer data type (test parse-value-integer-001 "Parse some integer values." (is (= 23 (parse-value "23" 'integer))) (is (= -123 (parse-value "-123" 'integer))) (is (= 0 (parse-value "0" 'integer)))) (test parse-value-integer-002 "Parse some non-integer values." (signals error (parse-value "23.1" 'integer)) (signals error (parse-value "2x" 'integer)) (signals error (parse-value "++3" 'integer)) (signals error (parse-value "--2" 'integer))) (test format-value-integer-001 "Format some integer values." (is (string= (format-value 2 'integer) "2")) (is (string= (format-value 3 'integer) "3")) (is (string= (format-value -3 'integer) "-3")) (is (string= (format-value 0 'integer) "0"))) ;;; Float data type (test parse-value-float-001 "Parse some float values." (is (= 23 (parse-value "23" 'float))) (is (= 3.1415 (parse-value "3.1415" 'float))) (is (= -0.001 (parse-value "-0.001" 'float)))) (test parse-value-float-002 "Parse some non-integer values." (signals error (parse-value "23." 'float)) (signals error (parse-value ".1" 'float)) (signals error (parse-value "-.1" 'float))) (test format-value-float-001 "Format some integer values." (is (string= (format-value 2.0 'float) "2.0")) (is (string= (format-value 3.1 'float) "3.1")) (is (string= (format-value -3 'float) "-3.0"))) ;;; Binary data type (test read-binary-from-stream-001 "Read somes binary from a stream." (finishes (read-binary-from-file "tests/test-types.001"))) (test parse-value-binary-001 "Parse binary values." (is (= 446 (length (parse-value "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2ljaW5nIGVsaXQsIHNlZCBkbyBlaXVzbW9kIHRlbXBvciBpbmNpZGlkdW50IHV0IGxhYm9yZSBldCBkb2xvcmUgbWFnbmEgYWxpcXVhLiBVdCBlbmltIGFkIG1pbmltIHZlbmlhbSwgcXVpcyBub3N0cnVkIGV4ZXJjaXRhdGlvbiB1bGxhbWNvIGxhYm9yaXMgbmlzaSB1dCBhbGlxdWlwIGV4IGVhIGNvbW1vZG8gY29uc2VxdWF0LiBEdWlzIGF1dGUgaXJ1cmUgZG9sb3IgaW4gcmVwcmVoZW5kZXJpdCBpbiB2b2x1cHRhdGUgdmVsaXQgZXNzZSBjaWxsdW0gZG9sb3JlIGV1IGZ1Z2lhdCBudWxsYSBwYXJpYXR1ci4gRXhjZXB0ZXVyIHNpbnQgb2NjYWVjYXQgY3VwaWRhdGF0IG5vbiBwcm9pZGVudCwgc3VudCBpbiBjdWxwYSBxdWkgb2ZmaWNpYSBkZXNlcnVudCBtb2xsaXQgYW5pbSBpZCBlc3QgbGFib3J1bS4=" 'binary))))) (test format-value-binary-001 "Format binary values." (is (string= (format-value (read-binary-from-file "tests/test-types.001") 'binary) "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2ljaW5nIGVsaXQsIHNlZCBkbyBlaXVzbW9kIHRlbXBvciBpbmNpZGlkdW50IHV0IGxhYm9yZSBldCBkb2xvcmUgbWFnbmEgYWxpcXVhLiBVdCBlbmltIGFkIG1pbmltIHZlbmlhbSwgcXVpcyBub3N0cnVkIGV4ZXJjaXRhdGlvbiB1bGxhbWNvIGxhYm9yaXMgbmlzaSB1dCBhbGlxdWlwIGV4IGVhIGNvbW1vZG8gY29uc2VxdWF0LiBEdWlzIGF1dGUgaXJ1cmUgZG9sb3IgaW4gcmVwcmVoZW5kZXJpdCBpbiB2b2x1cHRhdGUgdmVsaXQgZXNzZSBjaWxsdW0gZG9sb3JlIGV1IGZ1Z2lhdCBudWxsYSBwYXJpYXR1ci4gRXhjZXB0ZXVyIHNpbnQgb2NjYWVjYXQgY3VwaWRhdGF0IG5vbiBwcm9pZGVudCwgc3VudCBpbiBjdWxwYSBxdWkgb2ZmaWNpYSBkZXNlcnVudCBtb2xsaXQgYW5pbSBpZCBlc3QgbGFib3J1bS4="))) ;;; Period type (test parse-value-period-001 (is (periodp (parse-value "19970101T180000Z/PT5H30M" 'period)))) (test parse-value-period-002 (is (periodp (parse-value "19970101T180000Z/19970102T070000Z" 'period)))) ;;; UTC Offset (test parse-utc-offset-001 ;; Positive (is (= (parse-value "+0530" 'utc-offset) 19800)) (is (= (parse-value "-0530" 'utc-offset) -19800)) (is (= (parse-value "-000001" 'utc-offset) -1)) (is (= (parse-value "+0000" 'utc-offset) 0)) (is (= (parse-value "+000000" 'utc-offset) 0)) ;; Negative tests (signals error (parse-value "+0" 'utc-offset)) (signals error (parse-value "-0" 'utc-offset)) (signals error (parse-value "-0000" 'utc-offset)) (signals error (parse-value "+05301" 'utc-offset)) (signals error (parse-value "+053" 'utc-offset)) (signals error (parse-value "5030" 'utc-offset))) (test format-utc-offset-001 ;; Positive (is (string= (format-value 19800 'utc-offset) "+0530")) (is (string= (format-value -19800 'utc-offset) "-0530")) (is (string= (format-value -1 'utc-offset) "-000001")) (is (string= (format-value 0 'utc-offset) "+0000")) ;; Negative tests (signals error (format-value -1000000 'utc-offset))) ;;; test-types.lisp ends here
5,780
Common Lisp
.lisp
113
48.539823
645
0.749202
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
d80f4bc8a91e08daed67ff5fd138b26fa8dbe14814a9e3b0ba9fbb692509485e
8,881
[ -1 ]
8,882
tsuite.lisp
davazp_cl-icalendar/tests/tsuite.lisp
;; tsuite.lisp ;; ;; Copyrigth (C) 2010 David Vázquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. (in-package :cl-icalendar-tests) (def-suite icalendar-types :description "Test suite to check the types related functions.") ;;; Run this function in order to run all registered tests. (defun run-tests () (run! 'icalendar-types)) ;;; tsuite.lisp ends here
1,009
Common Lisp
.lisp
25
39.04
72
0.755102
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
6783938dd0f07d87af4e1e8559eddf07a9d63880d8c2ba82bf79a97525122670
8,882
[ -1 ]
8,883
cl-icalendar.asd
davazp_cl-icalendar/cl-icalendar.asd
;; -*- Lisp -*- ;; cl-icalendar.asd -- ;; ;; Copyright (C) 2010, 2012 David Vazquez ;; ;; This file is part of cl-icalendar. ;; ;; cl-icalendar 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. ;; ;; cl-icalendar 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 cl-icalendar. If not, see <http://www.gnu.org/licenses/>. ;; (defsystem :cl-icalendar :name "iCalendar library" :license "GPLv3+" :version "0.0" :depends-on (:trivial-gray-streams :cl-base64 :uuid :babel) :serial t :components ((:static-file "COPYING") (:static-file "README") ;; Source code (:file "package") (:file "utils") (:file "conditions") (:file "translate") (:file "parameters") (:file "types") (:file "types-binary") (:file "types-utc-offset") (:file "types-text") (:file "universal-time") (:file "types-date") (:file "types-time") (:file "types-datetime") (:file "types-duration") (:file "types-period") (:file "types-recur") (:file "folding") (:file "content-line") (:file "property") (:file "components") (:file "cl-icalendar") ;; Documentation (:module "doc" :components ((:static-file "Makefile") (:doc-file "cl-icalendar.texi") (:doc-file "fdl.texi") (:doc-file "version.texi")))) :in-order-to ((test-op (load-op cl-icalendar-tests))) :perform (test-op :after (op c) (funcall (intern "RUN-TESTS" (find-package :cl-icalendar-tests))))) (defsystem :cl-icalendar-tests :name "iCalendar library tests" :license "GPLv3+" :depends-on (:cl-icalendar :fiveam) :serial t :components ((:module "tests" :serial t :components ((:static-file "test-types.001") (:static-file "test-icalendar.001") (:static-file "test-icalendar.002") (:static-file "test-icalendar.003") (:static-file "test-icalendar.004") (:static-file "test-icalendar.005") (:static-file "test-icalendar.006") (:file "package") (:file "tsuite") (:file "test-types") (:file "test-types-date") (:file "test-types-recur"))))) ;; cl-icalendar.asd ends here
2,773
Common Lisp
.asd
83
27.915663
87
0.606185
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
ea72748ce27b7541a67ec08eb260c146bf6648ae2ead404fe9e859e6ca5f0091
8,883
[ -1 ]
8,908
test-icalendar.006
davazp_cl-icalendar/tests/test-icalendar.006
BEGIN:VCALENDAR VERSION:2.0 PRODID:-//RDU Software//NONSGML HandCal//EN BEGIN:VFREEBUSY ORGANIZER:mailto:[email protected] DTSTART:19980313T141711Z DTEND:19980410T141711Z FREEBUSY:19980314T233000Z/19980315T003000Z FREEBUSY:19980316T153000Z/19980316T163000Z FREEBUSY:19980318T030000Z/19980318T040000Z URL:http://www.example.com/calendar/busytime/jsmith.ifb END:VFREEBUSY END:VCALENDAR
385
Common Lisp
.l
13
28.615385
55
0.897849
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
65844784ceda910b59a1999898f4754987c66c3cd6cd8f8ceb44970a173b46fb
8,908
[ -1 ]
8,911
test-icalendar.002
davazp_cl-icalendar/tests/test-icalendar.002
BEGIN:VCALENDAR PRODID:-//RDU Software//NONSGML HandCal//EN VERSION:2.0 BEGIN:VTIMEZONE TZID:America/New_York BEGIN:STANDARD DTSTART:19981025T020000 TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST END:STANDARD BEGIN:DAYLIGHT DTSTART:19990404T020000 TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT END:DAYLIGHT END:VTIMEZONE BEGIN:VEVENT DTSTAMP:19980309T231000Z UID:guid-1.example.com ORGANIZER:mailto:[email protected] ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP: mailto:[email protected] DESCRIPTION:Project XYZ Review Meeting CATEGORIES:MEETING CLASS:PUBLIC CREATED:19980309T130000Z SUMMARY:XYZ Project Review DTSTART;TZID=America/New_York:19980312T083000 DTEND;TZID=America/New_York:19980312T093000 LOCATION:1CP Conference Room 4350 END:VEVENT END:VCALENDAR
775
Common Lisp
.l
34
21.764706
53
0.887989
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
3c8812ec44c15771eee530057a93afa95adbf3aa69378684ec92e928cdfa8d25
8,911
[ -1 ]
8,913
test-icalendar.003
davazp_cl-icalendar/tests/test-icalendar.003
BEGIN:VCALENDAR METHOD:xyz VERSION:2.0 PRODID:-//ABC Corporation//NONSGML My Product//EN BEGIN:VEVENT DTSTAMP:19970324T120000Z SEQUENCE:0 UID:[email protected] ORGANIZER:mailto:[email protected] ATTENDEE;RSVP=TRUE:mailto:[email protected] DTSTART:19970324T123000Z DTEND:19970324T210000Z CATEGORIES:MEETING,PROJECT CLASS:PUBLIC SUMMARY:Calendaring Interoperability Planning Meeting DESCRIPTION:Discuss how we can test c&s interoperability\n using iCalendar and other IETF standards. LOCATION:LDB Lobby ATTACH;FMTTYPE=application/postscript:ftp://example.com/pub/ conf/bkgrnd.ps END:VEVENT END:VCALENDAR
603
Common Lisp
.l
22
26.318182
60
0.874355
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
0a37a72c8d82da019d699337b634433449ccc91d0459affc5d8bbd87682301e1
8,913
[ -1 ]
8,915
test-icalendar.001
davazp_cl-icalendar/tests/test-icalendar.001
BEGIN:VCALENDAR PRODID:-//xyz Corp//NONSGML PDA Calendar Version 1.0//EN VERSION:2.0 BEGIN:VEVENT DTSTAMP:19960704T120000Z UID:[email protected] ORGANIZER:mailto:[email protected] DTSTART:19960918T143000Z DTEND:19960920T220000Z STATUS:CONFIRMED CATEGORIES:CONFERENCE SUMMARY:Networld+Interop Conference DESCRIPTION:Networld+Interop Conference and Exhibit\nAtlanta World Congress Center\n Atlanta\, Georgia END:VEVENT END:VCALENDAR
434
Common Lisp
.l
17
24.352941
56
0.880096
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
1b5dbdc13a0bd9496c8ba04d70403ac9628418a2169d90b34e637b6e0c567dae
8,915
[ -1 ]
8,916
test-icalendar.005
davazp_cl-icalendar/tests/test-icalendar.005
BEGIN:VCALENDAR VERSION:2.0 PRODID:-//ABC Corporation//NONSGML My Product//EN BEGIN:VJOURNAL DTSTAMP:19970324T120000Z UID:[email protected] ORGANIZER:mailto:[email protected] STATUS:DRAFT CLASS:PUBLIC CATEGORIES:Project Report,XYZ,Weekly Meeting DESCRIPTION:Project xyz Review Meeting Minutes\n Agenda\n1. Review of project version 1.0 requirements.\n2. Definition of project processes.\n3. Review of project schedule.\n Participants: John Smith\, Jane Doe\, Jim Dandy\n-It was decided that the requirements need to be signed off by product marketing.\n-Project processes were accepted.\n -Project schedule needs to account for scheduled holidays and employee vacation time. Check with HR for specific dates.\n-New schedule will be distributed by Friday.\n- Next weeks meeting is cancelled. No meeting until 3/23. END:VJOURNAL END:VCALENDAR
856
Common Lisp
.l
23
35.565217
59
0.822329
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
55920cd48a1f6f6b5f7eca66e1a9d7b256c2c302575e7b4ce779eeac4756d38b
8,916
[ -1 ]
8,917
test-icalendar.004
davazp_cl-icalendar/tests/test-icalendar.004
BEGIN:VCALENDAR VERSION:2.0 PRODID:-//ABC Corporation//NONSGML My Product//EN BEGIN:VTODO DTSTAMP:19980130T134500Z SEQUENCE:2 UID:[email protected] ORGANIZER:mailto:[email protected] ATTENDEE;PARTSTAT=ACCEPTED:mailto:[email protected] DUE:19980415T000000 STATUS:NEEDS-ACTION SUMMARY:Submit Income Taxes BEGIN:VALARM ACTION:AUDIO TRIGGER:19980403T120000Z ATTACH;FMTTYPE=audio/basic:http://example.com/pub/audio- files/ssbanner.aud REPEAT:4 DURATION:PT1H END:VALARM END:VTODO END:VCALENDAR
494
Common Lisp
.l
22
21.409091
56
0.877119
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
555063b7f65cddcc849e614f1de2567d6ef4cd358188fa9cda0ff0872522e8cb
8,917
[ -1 ]
8,919
cl-icalendar.texi
davazp_cl-icalendar/doc/cl-icalendar.texi
\input texinfo @c -*-texinfo-*- @c %**start of header @setfilename cl-icalendar.info @settitle cl-icalendar @c %**end of header @include version.texi @c Copy the type, variable and function indexes to the cp one. @syncodeindex tp cp @syncodeindex vr cp @syncodeindex fn cp @copying This is the @cite{Common Lisp iCalendar Library} updated for the version @cite{@value{VERSION}}. Copyright @copyright{} 2010 Mario Castel@'an Castro Copyright @copyright{} 2010,2011 David V@'azquez P@'ua @quotation Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled ``GNU Free Documentation License''. A copy of the license is also available from the Free Software Foundation Web site at @url{http://www.gnu.org/licenses/fdl.html}. @end quotation The document was typeset with @uref{http://www.texinfo.org/, GNU Texinfo}. @end copying @titlepage @title Common Lisp iCalendar Library @subtitle An implementation of the iCalendar specification @subtitle for cl-icalendar version @value{VERSION}. @author Mario Castel@'an Castro @author David V@'azquez P@'ua @page @vskip 0pt plus 1filll @insertcopying @end titlepage @c Output the table of the contents at the beginning. @contents @ifnottex @node Top @top Common Lisp iCalendar Library @insertcopying @end ifnottex @c Generate the nodes for this menu with `C-c C-u C-m'. @menu * Introduction:: * Data types:: * GNU Free Documentation License:: * Index:: @end menu @node Introduction @chapter Introduction The @emph{Common Lisp iCalendar Library} is an implementation of iCalendar specification as described in RFC5545. It provides a convenient object-oriented abstractions so that user to be able treat with iCalendar as easy as possible, even it can be extended and suited to advanced uses. This document should not be considered a complete documentation of the Common Lisp iCalendar library. The object of this document is give an insight to the user about the usage of the library. @node Package structure @section Package structure The library provides a package named @samp{ICAL}. Every exported symbol will be in this package. It is granted you can @strong{use} this package and it will not cause collisions with the standard @samp{COMMON-LISP} package. @node Overview @section Overview @node Data types @chapter Data types The value of each property is always a @code{ical-value} type. This type includes the ANSI Common Lisp data types @code{Boolean}, @code{Integer}, @code{Float}, as well as specific iCal data types @code{URI}, @code{Geo}, @code{Cal-address}, @code{Binary}, @code{Text}, @code{UTC-Offset}, @code{Date}, @code{Time}, @code{Datetime}, @code{Duration}, @code{Period} and @code{Recur}. Indeed, it also covers the data type @code{x-ical-value}, which can be extend by defining a subclass of the class with the same name. It is explained in detail in the section ``Custom data types''. @node Boolean @section Boolean The boolean data type is defined as ``TRUE'' or ``FALSE''. They are mapped to the Common Lisp values @code{T} and @code{NIL} respectively. @node Integer @section Integer The Common Lisp integer type, a mathematical integer. The RFC5545 limits the magnitude of the integer type to the range -2147483648 to 2147483647. This limitation is not implemented in the library. @node Float @section Float The Common Lisp float type is used in properties that contain real number value. @node URI @section URI This value type is used to identify values that contain a uniform resource identifier (URI) type of reference to the property value. urip make-uri uri @node Geo @section Geo @node Cal-address @section Cal-address @node Binary @section Binary @node Text @section Text @node UTC-Offset @section UTC-Offset @node Date @section Date @node Time @section Time @node Datetime @section Datetime @node Duration @section Duration @node Period @section Period @node Recur @section Recur @node Custom data types @section Custom data types @node GNU Free Documentation License @appendix GNU Free Documentation License @c Get fdl.texi from http://www.gnu.org/licenses/fdl.html @include fdl.texi @node Index @unnumbered Index @printindex cp @bye @c cl-icalendar.texi ends here
4,471
Common Lisp
.l
135
31.703704
74
0.805607
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
98b4574a106c59b4521c5e8340a115e3e1b42480b76cc796081907453eae8dd4
8,919
[ -1 ]
8,920
Makefile
davazp_cl-icalendar/doc/Makefile
# Makefile for icalendar documentation # # This file is public domain. .PHONY: all clean html info pdf clean TEXINFO = makeinfo FILES=cl-icalendar.texi fdl.texi RM=rm all: info html: cl-icalendar/ info: cl-icalendar.info pdf: cl-icalendar.pdf cl-icalendar/: $(FILES) $(TEXINFO) --html $< cl-icalendar.info: $(FILES) $(TEXINFO) $< cl-icalendar.pdf: $(FILES) texi2pdf $< clean: -$(RM) -rf cl-icalendar/ -$(RM) cl-icalendar.info -$(RM) cl-icalendar.pdf -$(RM) *.aux *.cp *.cpx *.fn *.fns *.ky *.pg *.toc *.tp *.tps *.vr
532
Common Lisp
.l
22
22.5
67
0.699203
davazp/cl-icalendar
14
4
1
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
2eb36daf02a4a3e688897eaa4ed9107ca93ccf4fab11298e1a663911a086a278
8,920
[ -1 ]
8,936
package.lisp
cosmos72_hyperluminal-db/test/package.lisp
;; -*- lisp -*- ;; This file is part of hyperluminal-DB. ;; Copyright (c) 2013 Massimiliano Ghilardi ;; ;; 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/>. ;;;; * HYPERLUMINAL-DB.TEST (in-package :cl-user) (defpackage #:hyperluminal-db-test (:nicknames #:hldb-test) (:use #:cl #:fiveam #:stmx.util #:hyperluminal-mem #:hyperluminal-db) (:import-from #:hyperluminal-mem #:!mdump) (:import-from #:hyperluminal-db #:hldb-open #:hldb-close) (:export #:suite)) (in-package :hyperluminal-db-test) (fiveam:def-suite suite)
1,196
Common Lisp
.lisp
32
33.625
71
0.702609
cosmos72/hyperluminal-db
13
3
2
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
09222f3417b27646497ea2895e0e034703c1c57ba76f118f3eb6fba04006e0ff
8,936
[ -1 ]
8,937
mset-int.lisp
cosmos72_hyperluminal-db/test/mset-int.lisp
;; -*- lisp -*- ;; This file is part of hyperluminal-DB. ;; Copyright (c) 2013 Massimiliano Ghilardi ;; ;; 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 :hyperluminal-db-test) (defun mset-int-test (ptr index &optional (num-threads 8) (iterations 300000000)) (declare (type maddress ptr) (type mem-size index num-threads) (type mem-int iterations)) (let ((threads (loop for i from 0 below num-threads collect ;; assume cache lines are 64 bytes (let ((offset (the mem-size (+ index (* i (truncate 64 +msizeof-word+)))))) (bt:make-thread (lambda () (let* ((num-failed 0) (cons (cons 0 0)) (func (lambda () (mset-int ptr offset (first cons))))) (loop for i from 0 below iterations do #-(and) (if (eql (sb-transaction:transaction-begin) sb-transaction:+transaction-started+) (progn (mset-int ptr offset i) (sb-transaction:transaction-end)) (progn (mset-int ptr offset i) (incf (the fixnum num-failed)))) #+(and) (stmx::hw-atomic2 (nil :test-for-running-tx? nil) (mset-int ptr offset i) (progn (setf (first cons) i) (stmx::%run-sw-atomic func) (incf (the fixnum num-failed)))) #-(and) (progn (setf (first cons) i) (stmx:atomic (mset-int ptr offset (first cons))))) num-failed))))))) (loop for th in threads collect (bt:join-thread th)))) (defun mset-int-test-report (ptr index &optional (num-threads 8) (iterations 300000000)) (declare (type maddress ptr) (type mem-size index num-threads) (type mem-int iterations)) (let* ((start-tics (get-internal-real-time)) (fails (mset-int-test ptr index num-threads iterations)) (end-tics (get-internal-real-time)) (seconds (/ (- end-tics start-tics) (float internal-time-units-per-second)))) ;; benchmark results for 64 bit SBCL running on Intel Core i7 4770 ;; ;; if SW transactions are not used, ;; speed is 367 millions HW transactions per second. ;; ;; if SW transactions are used as fallback, and thus HW transactions ;; are augmented with compatibility constraints, ;; speed drops to 225 millions (hybrid) transactions per second ;; ;; the unoptimized version (stmx:atomic (mset-int ptr offset (first cons))) ;; reaches 197 millions (hybrid) transactions per second ;; ;; in all cases, HW transactions success rate is > 99.999% (format t "elapsed time: ~S seconds~%HW transactions per second: ~S~%" seconds (/ (* num-threads iterations) seconds)) (loop for fail in fails initially (format t "HW transactions success rate: ") do (format t "~5$% " (* 100 (1+ (- (/ fail (float iterations)))))) finally (format t "~%"))))
4,133
Common Lisp
.lisp
85
35.082353
89
0.546945
cosmos72/hyperluminal-db
13
3
2
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
7800f05db93ea381ea3857c8dbebc2015cc40c3d666a83da57e188f63addb391
8,937
[ -1 ]
8,938
x86.lisp
cosmos72_hyperluminal-db/sbcl/x86.lisp
;; -*- lisp -*- ;; This file is part of hyperluminal-DB. ;; Copyright (c) 2013-2016 Massimiliano Ghilardi ;; ;; 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 :hyperluminal-db-sbcl) (declaim (inline deref)) (defknown deref ;;arg-types (addr (or fixnum mindex)) ;;result-type t (sb-c::flushable sb-c::important-result sb-c::always-translatable)) (sb-c:define-vop (deref) (:policy :fast-safe) (:translate deref) ;; directly use a tagged FIXNUM as address... on SBCL ;; its representation is shifted by +n-fixnum-tag-bits+ ;; which means that only addresses aligned at 2 or 4 bytes can be represented (:args (address :scs (sb-vm::any-reg)) (index :scs (sb-vm::any-reg))) (:arg-types sb-vm::tagged-num sb-vm::tagged-num) (:results (r :scs (sb-vm::descriptor-reg))) (:result-types *) (:generator 5 (sb-assem:inst mov r (sb-vm::make-ea #+x86 :dword #-x86 :qword :base address :index index :scale (ash 1 (- +n-address-tag-bits+ +n-fixnum-tag-bits+)))))) (sb-c:define-vop (deref-c) (:policy :fast-safe) (:translate deref) ;; directly use a tagged FIXNUM as address... on SBCL ;; its representation is shifted by +n-fixnum-tag-bits+ ;; which means that only addresses aligned at 2 or 4 bytes can be represented (:args (address :scs (sb-vm::any-reg))) (:info index) (:arg-types sb-vm::tagged-num (:constant mindex)) (:results (r :scs (sb-vm::descriptor-reg))) (:result-types *) (:generator 4 (sb-assem:inst mov r (sb-vm::make-ea #+x86 :dword #-x86 :qword :base address :disp (the (signed-byte 32) (ash index +n-address-tag-bits+)))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (declaim (inline %set-deref)) (defknown set-deref ;;arg-types (addr (signed-byte 32) t) ;;result-type (values) (sb-c::always-translatable)) (sb-c:define-vop (%set-deref) (:policy :fast-safe) (:translate %set-deref) ;; directly use a tagged FIXNUM as address... on SBCL ;; its representation is shifted by +n-fixnum-tag-bits+ ;; which means that only addresses aligned at 2 or 4 bytes can be represented (:args (address :scs (sb-vm::any-reg)) (index :scs (sb-vm::any-reg)) (value :scs (sb-vm::descriptor-reg))) (:arg-types sb-vm::tagged-num sb-vm::tagged-num *) (:generator 5 (sb-assem:inst mov (sb-vm::make-ea #+x86 :dword #-x86 :qword :base address :index index :scale (ash 1 (- +n-address-tag-bits+ +n-fixnum-tag-bits+))) value))) (sb-c:define-vop (%set-deref-c) (:policy :fast-safe) (:translate %set-deref) ;; directly use a tagged FIXNUM as address... on SBCL ;; its representation is shifted by +n-fixnum-tag-bits+ ;; which means that only addresses aligned at 2 or 4 bytes can be represented (:args (address :scs (sb-vm::any-reg)) (value :scs (sb-vm::descriptor-reg))) (:info index) (:arg-types sb-vm::tagged-num (:constant mindex) *) (:generator 5 (sb-assem:inst mov (sb-vm::make-ea #+x86 :dword #-x86 :qword :base address :disp (ash index +n-address-tag-bits+)) value)))
4,216
Common Lisp
.lisp
104
32.644231
99
0.587143
cosmos72/hyperluminal-db
13
3
2
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
a40cd152da328584c25e7b67152d8ac592d72c100aca5f9b62693d8f826fc516
8,938
[ -1 ]
8,939
package.lisp
cosmos72_hyperluminal-db/sbcl/package.lisp
;; -*- lisp -*- ;; This file is part of Hyperluminal-db. ;; Copyright (c) 2016 Massimiliano Ghilardi ;; ;;;; * HYPERLUMINAL-DB-SBCL (in-package :cl-user) (defpackage #:hyperluminal-db-sbcl (:nicknames #:hldb-sbcl) (:use #:cl) (:export #:addr #:sap=>addr #:addr=>sap #:addr-ref-obj))
298
Common Lisp
.lisp
10
27.6
61
0.656028
cosmos72/hyperluminal-db
13
3
2
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
1b34549a1ef72c6afcf284b0ad6ac7a42c087047dc8a7f228afbf9e812a6acec
8,939
[ -1 ]
8,940
deref.lisp
cosmos72_hyperluminal-db/sbcl/deref.lisp
;; -*- lisp -*- ;; This file is part of hyperluminal-DB. ;; Copyright (c) 2013-2016 Massimiliano Ghilardi ;; ;; 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 :hyperluminal-db-sbcl) (defun deref (address offset) (declare (type addr address) (type (or fixnum addr-offset) offset)) (deref address offset)) (declaim (inline set-deref)) (defun set-deref (address offset value) (declare (type addr address) (type (or fixnum addr-offset) offset) (type t value)) (%set-deref address offset value) value) (defsetf deref set-deref)
1,180
Common Lisp
.lisp
29
37.931034
71
0.734033
cosmos72/hyperluminal-db
13
3
2
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
9213604cceeccb902fcd26eff141a6c77dc8d291a065cf8923796b9f40d25d54
8,940
[ -1 ]
8,941
compiler.lisp
cosmos72_hyperluminal-db/sbcl/compiler.lisp
;; -*- lisp -*- ;; This file is part of hyperluminal-DB. ;; Copyright (c) 2013-2016 Massimiliano Ghilardi ;; ;; 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 :hyperluminal-db-sbcl) (defconstant +msizeof-slot+ #.(cffi-sys:%foreign-type-size :pointer)) (defconstant +n-address-tag-bits+ (1- (integer-length +msizeof-slot+)) "Number of low bits that are always ZERO in a memory address aligned at +MSIZEOF-SLOT+") (defconstant +n-fixnum-tag-bits+ sb-vm:n-fixnum-tag-bits "Number of low bits that are always ZERO in the representation of a FIXNUM") ;; (assert (>= +n-address-tag-bits+ +n-fixnum-tag-bits+)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (deftype maddress () 'fixnum) (deftype mindex () `(signed-byte ,(- 32 +n-address-tag-bits+))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defconstant +defknown-has-overwrite-fndb-silently+ (dolist (arg (second (sb-kernel:type-specifier (sb-int:info :function :type 'sb-c::%defknown)))) (when (and (consp arg) (eq (first arg) :overwrite-fndb-silently)) (return t)))) (defmacro defknown (&rest args) `(sb-c:defknown ,@args ,@(if +defknown-has-overwrite-fndb-silently+ '(:overwrite-fndb-silently t) ())))
1,880
Common Lisp
.lisp
37
48.27027
98
0.663567
cosmos72/hyperluminal-db
13
3
2
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
d5e9762ba715a603f9b82a912df79170b27e3728f7b66d793114f6484cf80641
8,941
[ -1 ]
8,942
box.lisp
cosmos72_hyperluminal-db/db/box.lisp
;; -*- lisp -*- ;; This file is part of hyperluminal-DB. ;; Copyright (c) 2013 Massimiliano Ghilardi ;; ;; 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 :hyperluminal-db) ;;;; boxed values, i.e. mem-box, are variable-length mmap areas ;;;; used to store all kind of CL built-in types that do not fit a single CPU word: ;;;; bignums, ratios, single-floats and double-floats, complexes, ;;;; pathnames, cons cells and lists, vectors, arrays, strings and hash-tables. ;;;; ;;;; mem-boxes are allocates in multiples of 4 (actually +mem-box/min-words+) CPU words, ;;;; and they contain a 2 CPU-word header followed by type-specific payload: ;;;; ;;;; word 0: tag = type. it uses a different coding than pointer tags (see +mem-box/...+ constants) ;;;; value = pointer to owner. used by GC. ;;;; ;;;; word 1: tag = available for type-specific data, for example sign bits ;;;; value = number of allocated words / 4. also counts the header (i.e. words 0 and 1) ;;;; ;;;; word 2... : payload. depends on type ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (declaim (inline box-index (setf box-index) box-n-words (setf box-n-words) box-value (setf box-value) box-next (setf box-next) reuse-box)) ;; wrapper for values that cannot be stored as unboxed #| (declaim (inline %make-box setf-box-value-index-n-words)) (defstruct (box (:constructor %make-box)) (index 0 :type mem-size) (n-words 0 :type mem-size) (value nil)) (defun make-box (index n-words &optional value) "Create a new box to wrap VALUE. Assumes VALUE will be stored at INDEX in memory store." (declare (type mem-size index n-words)) (%make-box :index index :n-words n-words :value value)) (defun reuse-box (box index n-words value) (setf (box-value box) value (box-index box) index (box-n-words box) n-words) box) |# (deftype box () 'cons) (defun make-box (index n-words &optional value) "Create a new box to wrap VALUE. Assumes VALUE will be stored at INDEX in memory store." (declare (type mem-size index n-words)) `(,value ,index . ,n-words)) (defun box-value (box) (declare (type box box)) (first box)) (defun (setf box-value) (value box) (declare (type box box)) (setf (first box) value)) (defun box-index (box) (declare (type box box)) (the mem-size (second box))) (defun (setf box-index) (index box) (declare (type box box) (type mem-size index)) (setf (second box) index)) (defun box-n-words (box) (declare (type box box)) (the mem-size (rest (rest box)))) (defun (setf box-n-words) (n-words box) (declare (type box box) (type mem-size n-words)) (setf (rest (rest box)) n-words)) (defun reuse-box (box index n-words value) "Set BOX slots to specified values. Return BOX." (declare (type box box) (type mem-size index n-words)) (setf (box-value box) value) (let ((tail (rest box))) (setf (first tail) index (rest tail) n-words)) box) (defun box-next (box) (declare (type box box)) (box-value box)) (defun (setf box-next) (value box) (declare (type box box)) (setf (box-value box) value)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (declaim (inline mwrite-box/box-header)) (defun mwrite-box/box-header (ptr box boxed-type) "Write to mmap area the header common to all boxed values. Return INDEX pointing to box payload" (declare (type maddress ptr) (type box box) (type mem-tag boxed-type)) (mwrite-box/header ptr (box-index box) boxed-type (box-n-words box))) (declaim (inline mread-box/box-header)) (defun mread-box/box-header (ptr index) "Read from mmap area the header common to all boxed values. Return BOX and BOXED-TYPE as multiple values" (declare (type maddress ptr) (type mem-size index)) (with-tag-and-vid (boxed-type allocated-words/4) (ptr index) (values (make-box index (box-vid->size allocated-words/4)) boxed-type))) (defun mwrite-box/box (ptr value &optional box) "Write a boxed value into the object store, (re)allocating space if needed. Return the written box." (declare (type maddress ptr) (type (or null box) box)) (let* ((boxed-type (mdetect-box-type value)) (n-words (msize-box-rounded-up value boxed-type)) (allocated-n-words (if box (box-n-words box) 0))) (if (and (<= n-words allocated-n-words) (>= n-words (ash allocated-n-words -1))) ;; reuse the existing memory (setf n-words allocated-n-words) ;; we must (re)allocate memory (setf box (box-realloc ptr box n-words) ;; ABSOLUTELY NECESSARY! read back actually allocated ;; n-words (usually rounded up somewhat) n-words (box-n-words box))) (setf (box-value box) value) (let ((index (box-index box))) (mwrite-box ptr index (mem-size+ index n-words) value boxed-type)) box)) (defun mread-box/box (ptr index box) "Read a boxed value from the memory starting at (PTR+INDEX). Reuse box and return the boxed value." (declare (type maddress ptr) (type mem-size index) (type box box)) (let1 end-index (mem-size+ index (box-n-words box)) (multiple-value-bind (value n-words) (mread-box ptr index end-index) (reuse-box box index n-words value)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun box-null? (box) "Return T if box is full of zeroes, for example when loaded from a newly created file." (declare (type box box)) (and (< (box-index box) +mem-box/min-words+) (zerop (box-n-words box)) (null (box-value box)))) (declaim (inline mwrite-fbox-next mwrite-fbox-n-words)) (defun mwrite-fbox-next (ptr box) "Write the NEXT slot of a free box into mmap memory starting at (+ PTR (box-index BOX))" (declare (type maddress ptr) (type box box)) (let* ((index (box-index box)) (next (box-next box)) (next-index (if next (box-index next) 0))) (mset-tag-and-vid ptr (mem-size-1 index) +mem-unallocated+ (size->box-vid next-index)))) (defun mwrite-fbox-n-words (ptr box &optional (n-words (box-n-words box))) "Write the N-WORDS slot of a free box into mmap memory starting at (+ PTR (box-index BOX))" (let ((index (box-index box))) (mset-tag-and-vid ptr index +mem-unallocated+ (size->box-vid n-words)))) (defun mwrite-box/free (ptr box) "Write a free box into mmap memory starting at (+ PTR (box-index BOX))" (declare (type maddress ptr) (type box box)) (mwrite-fbox-next ptr box) (mwrite-fbox-n-words ptr box)) (declaim (inline mread-fbox-next mread-fbox-n-words)) (defun mread-fbox-next (ptr index) "Read the NEXT slot of a free box from mmap memory starting at PTR+INDEX" (declare (type maddress ptr) (type mem-size index)) (mem-size+ +mem-box/min-payload-words+ (box-vid->size (mget-vid ptr (mem-size-1 index))))) (defun mread-fbox-n-words (ptr index) "Read N-WORDS from box in mmap memory starting at (PTR+INDEX) and return it." (declare (type maddress ptr) (type mem-size index)) (box-vid->size (mget-vid ptr index))) (defun mread-box/free (ptr index) "Read a free box from mmap memory starting at (PTR+INDEX) and return it. Note: NEXT slot of returned object always contains NIL, instead NEXT value stored in mmap is returned as multiple values." (declare (type maddress ptr) (type mem-size index)) (let* ((next-index (mread-fbox-next ptr index)) (n-words (mread-fbox-n-words ptr index))) (values (make-box index n-words) (the mem-size next-index)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun !mzero-box (ptr box) "Fill an allocated box with zeroes." (declare (type maddress ptr) (type box box)) (let* ((index (box-index box)) (n-words (box-n-words box)) (start index) (end (mem-size+ start n-words))) (mzero-words ptr start end))) (defun !mzero-fbox (ptr box) "Fill a free box with zeroes." (declare (type maddress ptr) (type box box)) (let* ((index (box-index box)) (n-words (box-n-words box)) ;; free boxes are written at the end of the free mmap area they represent! (start (mem-size- index (mem-size- n-words +mem-box/header-words+))) (end (mem-size+ start n-words))) (mzero-words ptr start end)))
9,396
Common Lisp
.lisp
216
38.652778
101
0.634959
cosmos72/hyperluminal-db
13
3
2
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
2f0b3892246d04d3b3026e1ba0607d758fe569006de8066f24c2194caee91c64
8,942
[ -1 ]
8,943
package.lisp
cosmos72_hyperluminal-db/db/package.lisp
;; -*- lisp -*- ;; This file is part of hyperluminal-DB. ;; Copyright (c) 2013 Massimiliano Ghilardi ;; ;; 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/>. ;;;; * HYPERLUMINAL-DB (in-package :cl-user) (defpackage #:hyperluminal-db (:nicknames #:hl-db #:hldb) (:use #:cl) (:import-from #:stmx.lang #:enable-#?-syntax #:eval-always #:set-feature #:define-global #:define-constant-once #:with-gensym #:with-gensyms #:new #:let1 #:when-bind #:if-bind #:awhen #:aif #:log.debug #:log.trace #:log.make-logger) (:import-from #:hyperluminal-mem-ffi #:+null-pointer+ #:null-pointer? #:os-getpagesize #:+bad-fd+ #:os-open-fd #:os-close-fd #:os-stat-fd-size #:os-truncate-fd #:os-mmap-fd #:os-munmap-ptr #:os-msync-ptr) (:import-from #:hyperluminal-mem #:+null-pointer+ #:+mem-unallocated+ #:+most-positive-size+ #:+msizeof-word+ #:+mem-box/min-words+ #:+mem-box/max-words+ #:+mem-box/header-words+ #:+mem-box/min-payload-words+ #:maddress #:mem-word #:msizeof #:mget-t #:mset-t #:mzero-words #:mem-size #:mem-size+ #:mem-size+1 #:mem-size- #:mem-size-1 #:incf-mem-size #:mem-size* #:mem-tag #:mem-vid #:mget-vid #:with-tag-and-vid #:mset-tag-and-vid #:mdetect-box-type #:mread-box #:msize-box-rounded-up #:mwrite-box/header #:mwrite-box #:box-vid->size #:size->box-vid #:mread-magic #:mwrite-magic) (:export #:hldb-version #:hldb-abi-version #:hldb-open #:hldb-close))
2,616
Common Lisp
.lisp
50
39.94
80
0.565091
cosmos72/hyperluminal-db
13
3
2
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
3a42435e6fe61b492b104ba2a05de831915aab6ee20281048a1d1fc03f92a07c
8,943
[ -1 ]
8,944
ffi-btree.lisp
cosmos72_hyperluminal-db/db/ffi-btree.lisp
;; -*- lisp -*- ;; This file is part of hyperluminal-DB. ;; Copyright (c) 2013 Massimiliano Ghilardi ;; ;; 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 :hyperluminal-db) (eval-always (defconstant +btree-el-type+ hlmem::+chosen-word-type+) (deftype btree-el () 'mem-word) (defconstant +btree-nbytes+ 8192) (defconstant +btree-nelements+ (truncate +btree-nbytes+ (msizeof +btree-el-type+))) (defconstant +btree-payloads-elements+ 3) ;; one child index and one range [start, end) (defconstant +btree-npayloads+ (truncate (1+ +btree-nelements+) +btree-payloads-elements+)) (defconstant +btree-nindex+ +btree-npayloads+) (defconstant +btree-range-start-index+ +btree-nindex+)) (declaim (inline btree-el set-btree-el)) (defun btree-el (ptr index) (declare (type maddress ptr) (type mem-size index)) (mget-t #.+btree-el-type+ ptr index)) (defun set-btree-el (ptr index value) (declare (type maddress ptr) (type mem-size index) (type btree-el value)) (mset-t value #.+btree-el-type+ ptr index)) (defsetf btree-el set-btree-el) (defmacro btree-index (ptr index) `(btree-el ,ptr ,index)) (defmacro set-btree-index (ptr index value) `(set-btree-el ,ptr ,index ,value)) (defsetf btree-index set-btree-index) (defmacro with-btree-range ((rstart &optional rend) ptr index &body body) (with-gensyms (vptr vindex) `(let* ((,vptr ,ptr) (,vindex (mem-size+ +btree-nindex+ (mem-size* 2 ,index))) (,rstart (btree-el ,vptr ,vindex)) ,@(when rend `((,rend (btree-el ,vptr (mem-size+1 ,vindex)))))) ,@body))) (defmacro set-btree-range (ptr index &key rstart rend) (when (or rstart rend) (with-gensyms (vptr vindex) `(let* ((,vptr ,ptr) (,vindex (mem-size+ +btree-nindex+ (mem-size* 2 ,index)))) ,@(when rstart `((set-btree-el ,vptr ,vindex ,rstart))) ,@(when rend `((set-btree-el ,vptr (mem-size+1 ,vindex) ,rend))) nil))))
2,689
Common Lisp
.lisp
60
39.45
93
0.664474
cosmos72/hyperluminal-db
13
3
2
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
bf6372474f84d168808cb43f7c80c6a2f554032e412d8fcd9bec6245551384a1
8,944
[ -1 ]
8,945
store.lisp
cosmos72_hyperluminal-db/db/store.lisp
;; -*- lisp -*- ;; This file is part of hyperluminal-DB. ;; Copyright (c) 2013 Massimiliano Ghilardi ;; ;; 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 :hyperluminal-db) (defun get-abi () (load-time-value `((:hldb-version . ,+hldb-version+) (:hldb-abi-version . ,+hldb-abi-version+) (:hlmem-version . ,hlmem::+hlmem-version+) (:hlmem-abi-version . ,hlmem::+hlmem-abi-version+) (:bits-per-byte . ,hlmem::+mem-byte/bits+) (:bits-per-tag . ,hlmem::+mem-tag/bits+) (:bits-per-vid . ,hlmem::+mem-vid/bits+) (:bits-per-int . ,hlmem::+mem-int/bits+) (:bits-per-word . ,hlmem::+mem-word/bits+) (:bits-per-ascii-char . ,hlmem::+ascii-char/bits+) (:bits-per-character . ,hlmem::+character/bits+) (:sizeof-byte . ,hlmem::+msizeof-byte+) (:sizeof-word . ,+msizeof-word+) (:sizeof-single-float . ,hlmem::+msizeof-sfloat+) (:sizeof-double-float . ,hlmem::+msizeof-dfloat+) (:endianity . ,hlmem::+mem/chosen-endianity+)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (eval-always (defconstant +pagesize+ (os-getpagesize))) (defvar *fd* +bad-fd+) (declaim (type mem-size *fwords*)) (defvar *fwords* 0) ;; example MMAP length: 256MB on 32bit archs, 127TB on 64bit archs (defconstant +max-fwords+ (let* ;; assume 1/4 of addressable memory can be actually used ((arch-max-bytes (ash 1 (- hlmem::+mem-word/bits+ 2))) ;; assume maximum size of a mmap area is 127TB. ;; this is just an example, and not really needed (mmap-max-bytes #x7FE000000000) ;; compute maximum bytes addressable by a hyperluminal-db:mem-vid (persist-max-bytes (* +msizeof-word+ (box-vid->size hlmem::+most-positive-vid+))) (max-bytes (min arch-max-bytes mmap-max-bytes persist-max-bytes )) ;; round down to a multiple of +pagesize+ (max-bytes-rounded (logand max-bytes (- +pagesize+)))) (truncate max-bytes-rounded +msizeof-word+))) (defvar *p* +null-pointer+) (defun open-fd (filename &optional (min-words 0)) (declare (type mem-size min-words)) (let* ((fd (the fd (os-open-fd filename :read t :write t))) (file-words (truncate (the (integer 0) (os-stat-fd-size fd)) +msizeof-word+))) (unless (zerop min-words) (when (< file-words min-words) (os-truncate-fd fd (* min-words +msizeof-word+)) (setf file-words min-words))) (the (values fd mem-size) (values fd (min +most-positive-size+ file-words))))) (defun close-fd (fd) (declare (type fd fd)) (os-close-fd fd)) (defun mmap (fd n-words) (declare (type fd fd) (type mem-size n-words)) (os-mmap-fd fd :offset-bytes 0 :length-bytes (* n-words +msizeof-word+) :read t :write t)) (defun munmap (ptr n-words) (declare (type maddress ptr) (type mem-size n-words)) (os-munmap-ptr ptr (* n-words +msizeof-word+))) (defun msync (ptr n-words &key sync) (declare (type maddress ptr) (type mem-size n-words) (type boolean sync)) (os-msync-ptr ptr (* n-words +msizeof-word+) sync)) (defun init-store (ptr total-n-words) "Invoked when loading an unitialized file. Initialize the magic and free-list, and write them back to file" (declare (type maddress ptr) (type mem-size total-n-words)) (let* ((index (mfree-head-index (mwrite-magic ptr 0 total-n-words))) (free-list (init-free-list ptr index total-n-words))) (mwrite-free-list ptr free-list) (msync ptr total-n-words) free-list)) (defun hldb-open (&key (filename "mmap") (min-words #.(truncate +pagesize+ +msizeof-word+))) (declare (type mem-size min-words)) ;; open file and (if needed) extend it (multiple-value-bind (fd words) (open-fd filename min-words) (setf *fd* fd *fwords* words) (let ((ptr)) (unwind-protect (progn (setf ptr (mmap fd words) *p* ptr) (if-bind index (mread-magic ptr 0 words) (let1 index (mfree-head-index index) (mread-free-list ptr index)) (init-store ptr words))) (unless ptr (close-fd *fd*) (setf *fd* +bad-fd+)))))) (defun hldb-close () (unless (null-pointer? *p*) (munmap (the ffi-address *p*) *fwords*) (setf *p* +null-pointer+)) (setf *mfree* nil) (unless (eql +bad-fd+ *fd*) (close-fd *fd*) (setf *fd* +bad-fd+ *fwords* 0)))
5,289
Common Lisp
.lisp
120
37.383333
92
0.618612
cosmos72/hyperluminal-db
13
3
2
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
5d2e2832af060e29b7af26571d7155886b5a2b6bd6b4bc8db5ddb55bda2b871d
8,945
[ -1 ]
8,946
version.lisp
cosmos72_hyperluminal-db/db/version.lisp
;; -*- lisp -*- ;; This file is part of hyperluminal-DB. ;; Copyright (c) 2013 Massimiliano Ghilardi ;; ;; 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 :hyperluminal-db) (define-constant-once +hldb-version+ '(0 6 0)) (define-constant-once +hldb-abi-version+ '(1 6 0)) (defun hldb-version () "Return HYPERLUMINAL-DB version, in the form '(major minor patch) as for example '(0 4 0)" +hldb-version+) (defun hldb-abi-version () "Return HYPERLUMINAL-DB file format and ABI version, in the form '(major minor patch) as for example '(0 1 0)" +hldb-abi-version+)
1,182
Common Lisp
.lisp
27
42.111111
87
0.744105
cosmos72/hyperluminal-db
13
3
2
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
044d6d927b9bb8603e0e9e7cc8413551a4c17fc4e500a2274db26d34eadd1901
8,946
[ -1 ]
8,947
alloc.lisp
cosmos72_hyperluminal-db/db/alloc.lisp
;; -*- lisp -*- ;; This file is part of hyperluminal-DB. ;; Copyright (c) 2013 Massimiliano Ghilardi ;; ;; 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 :hyperluminal-db) (defun mfree-head-index (index) "Given index to end-of-magic, return index of free areas head" ;; reserve enough space for two words after magic (let ((vid (ceiling (+ 2 index) +mem-box/min-words+))) (- (box-vid->size vid) +mem-box/header-words+))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defvar *mfree* nil "thread-local list of unallocated mmap memory") (defun init-free-list (ptr index total-n-words) "Create and return a new free list containing ALL the words from INDEX up to TOTAL-N-WORDS." (declare (type maddress ptr) (ignore ptr) (type mem-size index total-n-words)) (let ((lo index) (hi (mem-size- total-n-words +mem-box/header-words+))) (setf *mfree* (make-box lo 0 (make-box hi (mem-size- hi lo)))))) (defun mwrite-free-list (ptr free-list) "Write a list of free boxes into memory starting at PTR and return it. FIXME: it currently loads the whole free-list in RAM (bad!)" (declare (type maddress ptr)) (loop for box = free-list then (box-next box) while box do (mwrite-box/free ptr box))) (defun mread-free-list (ptr index) "Read a list of free boxes from memory starting at (PTR + INDEX) and return it. FIXME: it currently loads the whole free-list in RAM (bad!)" (declare (type maddress ptr)) (let ((head) (prev)) (loop (multiple-value-bind (this next-index) (mread-box/free ptr index) (declare (type mem-size next-index)) (if prev (setf (box-next prev) this) (setf head this ;; head is just a pointer to next box, it must have zero free words (box-n-words this) 0)) (when (< next-index +mem-box/min-words+) (return (setf *mfree* head))) (setf prev this index next-index))))) (defun minsert-box/free (ptr prev box lo hi) (declare (type maddress ptr) (type box prev box) (type mem-size lo hi)) (let ((curr (box-next prev))) ;; boxes are written at the end of the free mmap area they represent! (setf (box-index box) hi (box-n-words box) (mem-size- hi lo) (box-next box) curr (box-next prev) box) (mwrite-box/free ptr box) (mwrite-fbox-next ptr prev) prev)) (defun %box-free (ptr head box lo hi) (declare (type maddress ptr) (type box head box) (type mem-size lo hi)) (loop for prev = head then curr for curr = (box-next prev) while curr for curr-hi = (box-index curr) for curr-n = (box-n-words curr) for curr-lo = (mem-size- curr-hi curr-n) do (cond ((> lo curr-hi) nil) ((= lo curr-hi) (setf lo curr-lo) (setf (box-next prev) (box-next curr)) (mwrite-fbox-next ptr prev) (setf curr prev)) ((= hi curr-lo) (setf hi curr-hi) (setf (box-next prev) (box-next curr)) (mwrite-fbox-next ptr prev) (setf curr prev)) ((< hi curr-lo) (loop-finish))) finally (minsert-box/free ptr prev box lo hi))) (defun box-free (ptr box) "A very naive deallocator. Useful only for debugging and development." (declare (type maddress ptr) (type box box)) (let ((head *mfree*) (n-words (box-n-words box))) (unless (zerop n-words) (let* ((lo (mem-size- (box-index box) +mem-box/header-words+)) (hi (mem-size+ lo n-words))) (%box-free ptr head box lo hi))) head)) (defun box-alloc (ptr n-words) "A very naive first-fit allocator for mmap areas. Useful only for debugging and development." (declare (type maddress ptr) (type mem-size n-words)) ;; trying to allocate zero words? then return invalid pointer (when (zerop n-words) (return-from box-alloc nil)) (when (> n-words +mem-box/max-words+) (error "cannot allocate ~S consecutive words from mmap area. Maximum supported is ~S words" n-words +mem-box/max-words+)) ;; round up n-words to a multiple of +mem-box/min-words+ (let ((remainder (logand n-words (1- +mem-box/min-words+)))) (unless (zerop remainder) (incf-mem-size n-words (- +mem-box/min-words+ remainder)))) (loop for prev = *mfree* then this for this = (box-next prev) then next while this for this-len = (box-n-words this) for next = (box-next this) do (when (>= this-len n-words) ;; boxes are written at the end of the free mmap area they represent! (let ((result (mem-size- (box-index this) (mem-size- this-len +mem-box/header-words+))) (box nil)) ;; update this length (decf this-len n-words) (if (zerop this-len) ;; exact match? then remove THIS from free list (it cannot be the head) (let ((next (box-next this))) (setf (box-next prev) next) ;; write back the new link PREV->NEXT that bypasses THIS (mwrite-fbox-next ptr prev) (setf box this (box-index box) result)) ;; otherwise update THIS n-words (progn (setf (box-n-words this) this-len ;; create and return a new box box (make-box result n-words)) (mwrite-fbox-n-words ptr this))) (return-from box-alloc box)))) (error "out of memory! failed to allocate ~S words from mmap area ~S" n-words ptr)) (defun box-alloc-rounded (ptr n-words) "Round up N-WORDS somewhat (typically 25%) then allocate that many words from mmap area." (declare (type maddress ptr) (type mem-size n-words)) (let ((delta (if (<= n-words #.(truncate +mem-box/max-words+ 2)) n-words (mem-size- +mem-box/max-words+ n-words)))) (the (values list &optional) (box-alloc ptr (mem-size+ n-words (ash delta 2)))))) (defun box-realloc (ptr box n-words) "Extend BOX to N-WORDS if possible, otherwise free it then allocate N-WORDS and return them." (declare (type maddress ptr) (type (or null box) box) (type mem-size n-words)) ;; very naive implementation: always frees BOX and allocates a new one. (when box (box-free ptr box)) (box-alloc ptr n-words))
7,288
Common Lisp
.lisp
173
34.289017
96
0.607575
cosmos72/hyperluminal-db
13
3
2
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
38d39b72a1c02772d339f2a012b70fdc2f1c2b4dc5b711feb9ea917a6462b8f6
8,947
[ -1 ]
8,948
hyperluminal-db.asd
cosmos72_hyperluminal-db/hyperluminal-db.asd
;; -*- lisp -*- ;; This file is part of HYPERLUMINAL-DB. ;; Copyright (c) 2013-2015 Massimiliano Ghilardi ;; ;; 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:defsystem :hyperluminal-db :name "HYPERLUMINAL-DB" :version "0.5.1" :license "GPLv3" :author "Massimiliano Ghilardi" :description "Persistent, transactional object store." :depends-on (:log4cl :stmx :hyperluminal-mem :trivial-garbage) :components ((:static-file "hyperluminal-db.asd") (:module :db :components ((:file "package") (:file "version" :depends-on ("package")) (:file "ffi-btree" :depends-on ("version")) (:file "box" :depends-on ("version")) (:file "alloc" :depends-on ("box")) (:file "store" :depends-on ("alloc"))))) :in-order-to ((asdf:test-op (asdf:test-op "hyperluminal-db-test"))))
1,523
Common Lisp
.asd
37
37.405405
71
0.676651
cosmos72/hyperluminal-db
13
3
2
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
41966d3337e91f466ac0d56857dd50bb1d3c740027cc01b4a79f8356f98efec0
8,948
[ -1 ]
8,949
hyperluminal-db-test.asd
cosmos72_hyperluminal-db/hyperluminal-db-test.asd
;; -*- lisp -*- ;; This file is part of HYPERLUMINAL-DB. ;; Copyright (c) 2013-2015 Massimiliano Ghilardi ;; ;; 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:defsystem :hyperluminal-db-test :name "HYPERLUMINAL-DB-TEST" :version "0.5.1" :author "Massimiliano Ghilardi" :license "GPLv3" :description "test suite for hyperluminal-db" :depends-on (:log4cl :fiveam :hyperluminal-db) :components ((:module :test :components ((:file "package")))) :perform (asdf:test-op (o c) (eval (read-from-string "(fiveam:run! 'hyperluminal-db-test:suite)"))))
1,258
Common Lisp
.asd
31
36.548387
83
0.702215
cosmos72/hyperluminal-db
13
3
2
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
62e4e719ace65abcbc7b3e4950e23d3ccf83a7dd9e840f6321dfd419dc260336
8,949
[ -1 ]
8,979
package.lisp
varjagg_also-alsa/package.lisp
;;;; package.lisp (defpackage #:also-alsa (:use #:cl #:cffi) (:export #:pcm-stream #:alsa-open #:alsa-close #:ref #:alsa-write #:alsa-read #:buffer #:direction #:element-type #:pcm-format #:channel-count #:buffer-size #:alsa-element-type #:contents-to-lisp #:with-alsa-device #:alsa-reopen #:get-delay #:get-avail-delay #:drain #:alsa-wait #:alsa-start #:make-alsa-buffer #:alsa-resume #:*alsa-warn* #:alsa-warn #:get-state #:open-mixer #:close-mixer #:access-mixer-element #:set-mixer-element-playback-volume #:set-mixer-element-playback-db #:set-mixer-element-capture-volume #:set-mixer-element-capture-db #:set-mixer-element-volume #:get-mixer-element-playback-db #:get-mixer-element-capture-db #:load-alsa))
754
Common Lisp
.lisp
13
53.769231
82
0.692828
varjagg/also-alsa
12
2
1
LGPL-2.1
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
a704647426412eedd1b2253aded4c5c4503c9d49c741be8ba6958bf5ab373c8c
8,979
[ -1 ]
8,980
also-alsa.lisp
varjagg_also-alsa/also-alsa.lisp
;;; A very basic Advanced Linux Sound Architecture interface (in-package #:also-alsa) (eval-when (:compile-toplevel) (defconstant +epipe+ 32)) (declaim (inline alsa-element-type to-alsa-format ensure-success)) (defvar *alsa-warn* nil) (define-foreign-library libasound (:unix "libasound.so.2") (t (:default "libasound.so"))) (defun load-alsa () (use-foreign-library libasound)) ;;; LW FLI can give us grief during cross builds ;;; We better invoke LOAD-ALSA as needed #-lispworks(use-foreign-library libasound) (defcenum snd-pcm-class (:snd-pcm-class-generic 0) :snd-pcm-class-multi :snd-pcm-class-modem :snd-pcm-class-digitizer) (defcenum snd-pcm-stream (:snd-pcm-stream-playback 0) :snd-pcm-stream-capture) (defcenum snd-pcm-access (:snd-pcm-access-mmap-interleaved 0) :snd-pcm-access-mmap-noninterleaved :snd-pcm-access-mmap-complex :snd-pcm-access-rw-interleaved :snd-pcm-access-rw-noninterleaved) ;; incomplete list of formats (defcenum snd-pcm-format (:snd-pcm-format-unknown -1) (:snd-pcm-format-s8 0) :snd-pcm-format-u8 :snd-pcm-format-s16-le :snd-pcm-format-s16-be :snd-pcm-format-u16-le :snd-pcm-format-u16-be :snd-pcm-format-s24-le :snd-pcm-format-s24-be :snd-pcm-format-u24-le :snd-pcm-format-u24-be :snd-pcm-format-s32-le :snd-pcm-format-s32-be :snd-pcm-format-u32-le :snd-pcm-format-u32-be :snd-pcm-format-float-le :snd-pcm-format-float-be :snd-pcm-format-float64-le :snd-pcm-format-float64-be :snd-pcm-format-iec958-subframe-le :snd-pcm-format-iec958-subframe-be :snd-pcm-format-mu-law :snd-pcm-format-a-law :snd-pcm-format-ima-adpcm :snd-pcm-format-mpeg :snd-pcm-format-gsm (:snd-pcm-format-special 31) (:snd-pcm-format-s24-3le 32) :snd-pcm-format-s24-3be :snd-pcm-format-u24-3le :snd-pcm-format-u24-3be) (defcenum snd-pcm-state :snd-pcm-state-open :snd-pcm-state-setup :snd-pcm-state-prepared :snd-pcm-state-running :snd-pcm-state-xrun :snd-pcm-state-draining :snd-pcm-state-paused :snd-pcm-state-suspended :snd-pcm-state-disconnected) (defctype snd-pcm-uframes :ulong) (defctype snd-pcm-sframes :long) (defcfun "snd_pcm_open" :int (pcm :pointer) (name :string) (stream snd-pcm-stream) (mode :int)) (defcfun "snd_pcm_state" snd-pcm-state (pcm :pointer)) (defcfun "snd_pcm_hw_params_malloc" :int (dptr :pointer)) (defcfun "snd_pcm_hw_params_any" :int (pcm :pointer) (params :pointer)) (defcfun "snd_pcm_hw_params_set_access" :int (pcm :pointer) (params :pointer) (access snd-pcm-access)) (defcfun "snd_pcm_hw_params_set_format" :int (pcm :pointer) (params :pointer) (format snd-pcm-format)) (defcfun "snd_pcm_hw_params_set_rate" :int (pcm :pointer) (params :pointer) (val :int) (dir :int)) (defcfun "snd_pcm_hw_params_set_channels" :int (pcm :pointer) (params :pointer) (val :int)) (defcfun "snd_pcm_hw_params_get_period_size" :int (pcm :pointer) (valp (:pointer :ulong)) (dir :pointer)) (defcfun "snd_pcm_hw_params" :int (pcm :pointer) (params :pointer)) (defcfun "snd_pcm_hw_params_free" :int (params :pointer)) (defcfun "snd_strerror" :string (val :int)) (defcfun "snd_pcm_prepare" :int (pcm :pointer)) (defcfun "snd_pcm_start" :int (pcm :pointer)) (defcfun "snd_pcm_drain" :int (pcm :pointer)) (defcfun "snd_pcm_drop" :int (pcm :pointer)) (defcfun "snd_pcm_close" :int (pcm :pointer)) (defcfun "snd_pcm_writei" snd-pcm-sframes (pcm :pointer) (buffer :pointer) (size snd-pcm-uframes)) (defcfun "snd_pcm_readi" snd-pcm-sframes (pcm :pointer) (buffer :pointer) (size snd-pcm-uframes)) (defcfun "snd_pcm_wait" :int (pcm :pointer) (timeout :int)) (defcfun "snd_pcm_delay" :int (pcm :pointer) (delayp (:pointer :long))) (defcfun "snd_pcm_avail_delay" :int (pcm :pointer) (availp (:pointer :long)) (delayp (:pointer :long))) (defcfun "snd_pcm_sw_params_malloc" :int (dptr :pointer)) (defcfun "snd_pcm_sw_params_current" :int (pcm :pointer) (swparams :pointer)) (defcfun "snd_pcm_sw_params_get_start_threshold" :int (pcm :pointer) (swparams :pointer) (pval (:pointer :ulong))) (defcfun "snd_pcm_sw_params_set_start_threshold" :int (pcm :pointer) (swparams :pointer) (val :ulong)) (defcfun "snd_pcm_sw_params_set_avail_min" :int (pcm :pointer) (swparams :pointer) (val :ulong)) (defcfun "snd_pcm_sw_params" :int (pcm :pointer) (swparams :pointer)) (declaim (inline deref snd-pcm-writei snd-pcm-readi snd-pcm-avail-delay snd-pcm-delay snd-pcm-drain snd-pcm-start snd-pcm-wait snd-pcm-prepare)) (defun deref (var) (mem-ref var :pointer)) (defun ensure-success (value) (unless (zerop value) (error "ALSA error: ~A" (snd-strerror value)))) (defun alsa-warn (string) (when *alsa-warn* (warn string))) (defclass pcm-stream () ((handle :reader handle :initform (foreign-alloc :pointer :initial-contents (list (null-pointer)))) (device :reader device :initarg :device) (params :reader params :initform (foreign-alloc :pointer :initial-contents (list (null-pointer)))) (swparams :reader swparams :initform (foreign-alloc :pointer :initial-contents (list (null-pointer)))) (pcm-format :reader pcm-format :initarg :pcm-format :initform :snd-pcm-format-s16-le) (buffer :reader buffer :initarg :buffer) (buffer-size :reader buffer-size :initarg :buffer-size) (element-type :reader element-type :initarg :element-type) (sample-rate :reader sample-rate :initarg :sample-rate :initform 44100) (direction :reader direction :initarg :direction) (channels-count :reader channels-count :initarg :channels-count) (status :accessor status :initform :initial :type (or :initial :open :closed)))) (defun alsa-element-type (type) (cond ((equalp type '(signed-byte 16)) :int16) ((eql type 'single-float) :float) ((eql type 'double-float) :double) ((equalp type '(unsigned-byte 8)) :uint8) ((equalp type '(signed-byte 8)) :int8) ((equalp type '(unsigned-byte 16)) :uint16) ((equalp type '(unsigned-byte 32)) :uint32) ((equalp type '(signed-byte 32)) :int32) (t (error "Invalid base type ~A" type)))) (defun to-alsa-format (element-type) (cond ((eql element-type 'single-float) :snd-pcm-format-float-le) ((eql element-type 'double-float) :snd-pcm-format-float64-le) ((equalp element-type '(unsigned-byte 8)) :snd-pcm-format-u8) ((equalp element-type '(signed-byte 8)) :snd-pcm-format-s8) ((equalp element-type '(unsigned-byte 16)) :snd-pcm-format-u16-le) ((equalp element-type '(signed-byte 16)) :snd-pcm-format-s16-le) ((equalp element-type '(unsigned-byte 32)) :snd-pcm-format-u32-le) ((equalp element-type '(signed-byte 32)) :snd-pcm-format-s32-le) (t (error "Invalid base type ~A" element-type)))) (defun alsa-open-2 (pcs) (ensure-success (snd-pcm-open (handle pcs) (device pcs) (direction pcs) 0)) (setf (status pcs) :open) (ensure-success (snd-pcm-hw-params-malloc (params pcs))) (ensure-success (snd-pcm-hw-params-any (deref (handle pcs)) (deref (params pcs)))) (ensure-success (snd-pcm-hw-params-set-access (deref (handle pcs)) (deref (params pcs)) :snd-pcm-access-rw-interleaved)) (ensure-success (snd-pcm-hw-params-set-format (deref (handle pcs)) (deref (params pcs)) (pcm-format pcs))) (ensure-success (snd-pcm-hw-params-set-rate (deref (handle pcs)) (deref (params pcs)) (sample-rate pcs) 0)) (ensure-success (snd-pcm-hw-params-set-channels (deref (handle pcs)) (deref (params pcs)) (channels-count pcs))) (ensure-success (snd-pcm-hw-params (deref (handle pcs)) (deref (params pcs)))) (cffi:with-foreign-object (period :uint) (ensure-success (snd-pcm-hw-params-get-period-size (deref (params pcs)) period (cffi:null-pointer)))) (snd-pcm-hw-params-free (deref (params pcs))) (ensure-success (snd-pcm-prepare (deref (handle pcs)))) (ensure-success (snd-pcm-sw-params-malloc (swparams pcs))) (ensure-success (snd-pcm-sw-params-current (deref (handle pcs)) (deref (swparams pcs)))) (ensure-success (snd-pcm-sw-params (deref (handle pcs)) (deref (swparams pcs)))) pcs) (defun make-alsa-buffer (&key element-type size channels) (cffi:make-shareable-byte-vector (* (cffi:foreign-type-size (alsa-element-type element-type)) size channels))) (defun alsa-open (device buffer-size element-type &key direction (sample-rate 44100) (channels-count 2) buffer) (when buffer (assert (and (subtypep (type-of buffer) 'simple-array) (subtypep (array-element-type buffer) element-type)))) (let ((pcs (make-instance 'pcm-stream :direction (case direction (:input :snd-pcm-stream-capture) (:output :snd-pcm-stream-playback)) :device device :element-type element-type :buffer (or buffer (make-alsa-buffer :element-type element-type :size buffer-size :channels channels-count)) :buffer-size (* buffer-size channels-count) ;number of samples really :channels-count channels-count :sample-rate sample-rate :pcm-format (to-alsa-format element-type)))) (alsa-open-2 pcs))) (defgeneric alsa-reopen (pcs device buffer-size element-type &key direction sample-rate channels-count) (:documentation "Reopens the stream. If all parameters are the same, just keeps the exiting one.")) (defmethod alsa-reopen ((pcs pcm-stream) device buffer-size element-type &key direction (sample-rate 44100) (channels-count 2)) (if (or (eql (status pcs) :initial) (not (and (equal device (device pcs)) (= (* buffer-size channels-count) (buffer-size pcs)) (equal element-type (element-type pcs)) (eql direction (case (direction pcs) (:snd-pcm-stream-capture :input) (:snd-pcm-stream-playback :output))) (= sample-rate (sample-rate pcs)) (= channels-count (channels-count pcs))))) (progn (when (eql (status pcs) :open) (alsa-close pcs)) (alsa-open-2 (reinitialize-instance pcs :direction (case direction (:input :snd-pcm-stream-capture) (:output :snd-pcm-stream-playback)) :device device :element-type element-type :buffer (cffi:make-shareable-byte-vector (* (cffi:foreign-type-size (alsa-element-type element-type)) buffer-size channels-count)) #+nil(foreign-alloc (alsa-element-type element-type) :count (* (cffi:foreign-type-size (alsa-element-type element-type)) buffer-size channels-count)) :buffer-size (* buffer-size channels-count) ;number of samples really :channels-count channels-count :sample-rate sample-rate :pcm-format (to-alsa-format element-type)))) (snd-pcm-drop (deref (handle pcs)))) pcs) (defmethod ref ((pcm pcm-stream) position) (error "Deprecated method, use AREF on the (buffer pcm) instead")) (defmethod (setf ref) (value (pcm pcm-stream) position) (error "Deprecated, use aref on the (buffer pcm) instead")) (defmethod drain ((pcm pcm-stream)) (snd-pcm-drain (deref (handle pcm)))) (defmethod alsa-start ((pcm pcm-stream)) (snd-pcm-start (deref (handle pcm)))) (defmethod alsa-resume ((pcm pcm-stream)) (snd-pcm-prepare (deref (handle pcm)))) (defmethod get-delay ((pcm pcm-stream)) (snd-pcm-prepare (deref (handle pcm))) (cffi:with-foreign-object (result :long) (let ((error-code (snd-pcm-delay (deref (handle pcm)) result))) (cond ((eql error-code (- +epipe+)) (alsa-warn "Pipe busted!") 0) ((minusp error-code) (error "ALSA error: ~A" error-code)) (t (mem-ref result :uint)))))) (defmethod get-avail-delay ((pcm pcm-stream)) (cffi:with-foreign-objects ((avail :long) (delay :long)) (let ((error-code (snd-pcm-avail-delay (deref (handle pcm)) avail delay))) (cond ((eql error-code (- +epipe+)) (alsa-warn "Pipe busted!") (values 0 0)) ((minusp error-code) (error "ALSA error: ~A" error-code)) (t (values (mem-ref avail :uint) (mem-ref delay :uint))))))) (defmethod alsa-close ((pcm pcm-stream)) (when (eq (status pcm) :open) (snd-pcm-drain (deref (handle pcm))) (snd-pcm-close (deref (handle pcm)))) (setf (status pcm) :closed) pcm) (defmethod alsa-wait ((pcm pcm-stream) &optional (timeout -1)) (snd-pcm-wait (deref (handle pcm)) timeout)) (defmethod alsa-write ((pcm pcm-stream)) (assert (eql (direction pcm) :snd-pcm-stream-playback)) (let* ((expected (/ (buffer-size pcm) (channels-count pcm))) (result (with-pointer-to-vector-data (ptr (buffer pcm)) (snd-pcm-writei (deref (handle pcm)) ptr expected)))) (cond ((= result (- +epipe+)) ;; Under run, so prepare and retry (alsa-warn "Underrun!") (snd-pcm-prepare (deref (handle pcm))) (alsa-write pcm)) ((/= result expected) (error "ALSA error: ~A" result))))) (defmethod alsa-read ((pcm pcm-stream)) (assert (eql (direction pcm) :snd-pcm-stream-capture)) (let ((result (with-pointer-to-vector-data (ptr (buffer pcm)) (snd-pcm-readi (deref (handle pcm)) ptr (/ (buffer-size pcm) (channels-count pcm)))))) (unless (= result (/ (buffer-size pcm) (channels-count pcm))) (if (eql result (- +epipe+)) (progn (alsa-warn "Underrun!") (snd-pcm-prepare (deref (handle pcm)))) (error "ALSA error: ~A" result))) pcm)) (defmethod contents-to-lisp ((pcm pcm-stream)) (let ((result (make-array (buffer-size pcm) :element-type (element-type pcm)))) (loop for i from 0 below (buffer-size pcm) do (setf (aref result i) (ref pcm i))) result)) (defmacro with-alsa-device ((stream device buffer-size element-type &key direction (sample-rate 44100) (channels-count 2) buffer) &body body) (assert direction) `(let ((,stream (also-alsa:alsa-open ,device ,buffer-size ,element-type :buffer ,buffer :direction ,direction :sample-rate ,sample-rate :channels-count ,channels-count))) (unwind-protect (progn ,@body) (also-alsa:drain ,stream) (also-alsa:alsa-close ,stream)))) (defmacro with-alsa-buffer ((buffer pcm &body body)) `(cffi:with-pointer-to-vector-data (,buffer (buffer ,pcm)) ,@body)) (defmethod get-state ((pcm pcm-stream)) (snd-pcm-state (deref (handle pcm))))
14,132
Common Lisp
.lisp
284
45.369718
141
0.689733
varjagg/also-alsa
12
2
1
LGPL-2.1
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
25699b7f6618965063c2178e37ca407f176714374a1f46810f35623b27016131
8,980
[ -1 ]
8,981
also-mixer.lisp
varjagg_also-alsa/also-mixer.lisp
(in-package :also-alsa) (defcenum snd-mixer-selem-channel-id (:snd-mixer-schn-unknown -1) (:snd-mixer-schn-front-left 0) :snd-mixer-schn-front-right :snd-mixer-schn-rear-left :snd-mixer-schn-rear-right :snd-mixer-schn-front-center :snd-mixer-schn-woofer :snd-mixer-schn-side-left :snd-mixer-schn-side-right :snd-mixer-schn-rear-center (:snd-mixer-schn-last 31) (:snd-mixer-schn-mono 0)) (defcfun "snd_mixer_open" :int (handle :pointer) (mode :int)) (defcfun "snd_mixer_attach" :int (handle :pointer) (card :string)) (defcfun "snd_mixer_selem_register" :int (handle :pointer) (options :pointer) (classp :pointer)) (defcfun "snd_mixer_load" :int (handle :pointer)) (defcfun "snd_mixer_selem_id_set_index" :void (sid :pointer) (val :uint)) (defcfun "snd_mixer_selem_id_set_name" :void (sid :pointer) (val :string)) (defcfun "snd_mixer_find_selem" :pointer (handle :pointer) (sid :pointer)) (defcfun "snd_mixer_selem_get_playback_volume_range" :int (selem :pointer) (min :pointer) (max :pointer)) (defcfun "snd_mixer_selem_get_playback_dB_range" :int (selem :pointer) (min :pointer) (max :pointer)) (defcfun "snd_mixer_selem_get_playback_dB" :int (selem :pointer) (channel snd-mixer-selem-channel-id) (value :pointer)) (defcfun "snd_mixer_selem_get_capture_volume_range" :int (selem :pointer) (min :pointer) (max :pointer)) (defcfun "snd_mixer_selem_get_capture_dB_range" :int (selem :pointer) (min :pointer) (max :pointer)) (defcfun "snd_mixer_selem_get_capture_dB" :int (selem :pointer) (channel snd-mixer-selem-channel-id) (value :pointer)) (defcfun "snd_mixer_selem_set_playback_volume_all" :int (selem :pointer) (volume :long)) (defcfun "snd_mixer_selem_set_capture_volume_all" :int (selem :pointer) (volume :long)) (defcfun "snd_mixer_selem_set_playback_dB_all" :int (selem :pointer) (volume :long) (dir :int)) (defcfun "snd_mixer_selem_set_capture_dB_all" :int (selem :pointer) (volume :long) (dir :int)) (defcfun "snd_mixer_close" :int (handle :pointer)) (defcfun "snd_mixer_wait" :int (handle :pointer) (timeout :int)) (defcstruct snd-mixer-selem-id (name :char :count 60) (index :uint)) (defun open-mixer (&optional (card "default")) (let ((handle (foreign-alloc :pointer :initial-contents (list (null-pointer))))) (ensure-success (snd-mixer-open handle 0)) (ensure-success (snd-mixer-attach (deref handle) card)) (ensure-success (snd-mixer-selem-register (deref handle) (null-pointer) (null-pointer))) (ensure-success (snd-mixer-load (deref handle))) handle)) (defun close-mixer (handle) (ensure-success (snd-mixer-close (deref handle))) (foreign-free handle)) (defun access-mixer-element (handle selem-name) (with-foreign-objects ((sid '(:struct snd-mixer-selem-id))) (snd-mixer-selem-id-set-index sid 0) (snd-mixer-selem-id-set-name sid selem-name) (snd-mixer-find-selem (deref handle) sid))) (defun set-mixer-element-playback-volume (selem volume) (with-foreign-objects ((min :long) (max :long)) (ensure-success (snd-mixer-selem-get-playback-volume-range selem min max)) (ensure-success (snd-mixer-selem-set-playback-volume-all selem (round (* volume (/ (mem-ref max :long) 100))))))) (defun set-mixer-element-playback-db (selem db) (with-foreign-objects ((min :long) (max :long)) (ensure-success (snd-mixer-selem-get-playback-db-range selem min max)) (let ((new-db (round (* db 100)))) (if (<= (mem-ref min :long) new-db (mem-ref max :long)) (ensure-success (snd-mixer-selem-set-playback-db-all selem new-db 0)) (when *alsa-warn* (warn "Supplied dB value ~d is out of range [~d , ~d]" new-db (mem-ref min :long) (mem-ref max :long))))))) (defun set-mixer-element-capture-volume (selem volume) (with-foreign-objects ((min :long) (max :long)) (ensure-success (snd-mixer-selem-get-capture-volume-range selem min max)) (ensure-success (snd-mixer-selem-set-capture-volume-all selem (round (* volume (/ (mem-ref max :long) 100))))))) (defun set-mixer-element-capture-db (selem db) (with-foreign-objects ((min :long) (max :long)) (ensure-success (snd-mixer-selem-get-capture-db-range selem min max)) (let ((new-db (round (* db 100)))) (if (<= (mem-ref min :long) new-db (mem-ref max :long)) (ensure-success (snd-mixer-selem-set-capture-db-all selem new-db 0)) (when *alsa-warn* (warn "Supplied dB value ~d is out of range [~d , ~d]" new-db (mem-ref min :long) (mem-ref max :long))))))) (defun get-mixer-element-playback-db (selem &optional (channel :snd-mixer-schn-mono)) (with-foreign-objects ((value :long)) (ensure-success (snd-mixer-selem-get-playback-db selem channel value)) (/ (mem-ref value :long) 100))) (defun get-mixer-element-capture-db (selem &optional (channel :snd-mixer-schn-mono)) (with-foreign-objects ((value :long)) (ensure-success (snd-mixer-selem-get-capture-db selem channel value)) (/ (mem-ref value :long) 100))) (defun set-mixer-element-volume (volume &key (element "Master") (direction :playback)) (let ((handle (open-mixer))) (unwind-protect (let ((selem (access-mixer-element handle element))) (if (eql direction :playback) (set-mixer-element-playback-volume selem volume) (set-mixer-element-capture-volume selem volume))) (close-mixer handle))))
5,329
Common Lisp
.lisp
97
51.371134
119
0.701211
varjagg/also-alsa
12
2
1
LGPL-2.1
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
9dfde658afd06c7363fc4334e5410989850963b7784d7291d8bb23cf5692496e
8,981
[ -1 ]
8,982
also-alsa.asd
varjagg_also-alsa/also-alsa.asd
(asdf:defsystem #:also-alsa :description "Basic ALSA bindings for Common Lisp" :author "Eugene Zaikonnikov <[email protected]>" :license "LGPL" :depends-on (#:cffi) :serial t :components ((:file "package") (:file "also-alsa") (:file "also-mixer")))
286
Common Lisp
.asd
9
26.777778
52
0.644928
varjagg/also-alsa
12
2
1
LGPL-2.1
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
684e9a67a65f54105e9b50ba20867ff23ca445cdd721cc9cb14badc73c34d421
8,982
[ -1 ]
9,002
core.lisp
kat-co_openapi2cl/core.lisp
(in-package :cl-user) (defpackage :openapi2cl/core (:use #:cl) (:import-from #:yason) (:import-from #:cl-yaml) (:import-from #:cl-strings) (:import-from #:kebab) (:export #:with-directory-generate-files #:with-directory-generate #:with-yaml-generate #:with-json-generate)) (in-package :openapi2cl/core) ;; NOTE: The generation occurs by building up sexps. Any symbols which ;; are written into these sexps must be prepended by the cl-user ;; namespace; otherwise the symbols in the generated code will be ;; prepended by this package's namespace. (defun generate (root-path openapi client-name) "Generates a client and a list of its methods. These are returned in a 2-tuple. openapi: the sexp representation of a openapi document. client-name: the name of the class that hosts all the client methods." (check-type client-name symbol) (let* ((host (gethash "host" openapi)) (base-path (gethash "basePath" openapi)) (consumes-media-types (gethash "consumes" openapi)) (produces-media-types (gethash "produces" openapi)) (schemes (or (gethash "schemes" openapi) '("https"))) (security-schemas (security-schemas-from-hash-table (resolve-object root-path (gethash "securityDefinitions" openapi)))) (client (generate-client client-name schemes host base-path consumes-media-types produces-media-types security-schemas))) (values client (loop for path-name being the hash-keys of (gethash "paths" openapi) using (hash-value path-operation) nconc (generate-path-methods client-name path-name path-operation consumes-media-types security-schemas))))) (defun with-yaml-generate (root-path openapi-yaml client-name) "Generate a client and a list of its methods based on a YAML file. root-path: The root path of the Yaml file. openapi-yaml: a string containing the YAML representation of a openapi document, or a pathname to a YAML document. client-name: the name of the class that hosts all the client methods." (check-type root-path (or string pathname)) (check-type openapi-yaml (or string pathname)) (check-type client-name symbol) (generate root-path (yaml:parse openapi-yaml) client-name)) (defun with-json-generate (root-path openapi-json client-name) "Generate a client and a list of its methods based on a YAML file. root-path: The root path of the Json file. openapi-json: a string containing the JSON representation of a openapi document, or a pathname to a JSON document. client-name: the name of the class that hosts all the client methods." (check-type root-path (or string pathname)) (check-type openapi-json (or string pathname)) (check-type client-name symbol) (generate root-path (yason:parse openapi-json) client-name)) (defun with-directory-generate (path process-results-fn) "Given a pathname, process the YAML and JSON files within, and call `process-results-fn'. This function should take these arguments: (1) The file-path (2) the client definition (3) the list of methods for this client." (check-type process-results-fn function) (flet ((with-file-generate (file-path) (let* ((type (pathname-type file-path)) (name (kebab-symbol-from-string (pathname-name file-path))) (output-path (make-pathname :type "lisp" :defaults file-path))) (multiple-value-bind (client-def methods-list) (cond ((string= type "yaml") (with-yaml-generate (uiop:pathname-directory-pathname file-path) file-path name)) ((string= type "json") (with-json-generate (uiop:pathname-directory-pathname file-path) file-path name))) (funcall process-results-fn output-path client-def methods-list))))) (mapcar #'with-file-generate (directory path)))) (defun with-directory-generate-files (input-path output-path package-root &optional preamble) "Given a pathname, generate lisp files for every specification encountered and processed. package-root will be used as the root of each file's package. The file's name will be appended to this forming the fully qualified package name." (check-type package-root symbol) (flet ((write-defs-out (file-path client-def methods-list) (let ((file-path (make-pathname :defaults file-path :directory output-path)) (*package* (find-package :cl-user))) (with-open-file (stream file-path :direction :output :if-exists :supersede) (format t "Output path: ~a~%" file-path) (when preamble (format stream "~a~%~%" preamble)) (when package-root (dolist (pkg-clause (generate-package-clauses (intern (string-upcase (format nil "~a/~a" package-root (pathname-name file-path)))) :packages-using '(#:cl) :packages-import '(#:cl-strings))) (format stream "~s~%" pkg-clause)) (format stream "~%~%")) (format stream "~s~%" client-def) (dolist (m methods-list) (format stream "~%~%~s~%" m)))))) (with-directory-generate input-path #'write-defs-out))) ;;; Unexported (defun resolve-ref (ref) "Returns the referenced object" (check-type ref pathname) (let ((type (pathname-type ref))) (when (equalp type "yaml") (return-from resolve-ref (yaml:parse ref))) (when (equalp type "json") (return-from resolve-ref (yason:parse ref))) (error "cannot resolve references of type ~a" type))) (defun resolve-object (root-path object) "If OBJECT is a reference, then return the referenced object. Otherwise, just return the object." (check-type root-path (or pathname string)) (check-type object (or hash-table null)) (unless object (return-from resolve-object nil)) (alexandria:if-let (val (gethash "$ref" object)) (resolve-ref (merge-pathnames val root-path)) object)) (defun parameter-name (param) (check-type param hash-table) (gethash "name" param)) (defun kebab-symbol-from-string (s &optional package) (check-type s string) (if package (intern (string-upcase (kebab:to-lisp-case s)) package) (intern (string-upcase (kebab:to-lisp-case s))))) (defun lisp-parameter-name (param) "Converts a string parameter name to a symbol for use in generated code." (check-type param hash-table) (kebab-symbol-from-string (parameter-name param))) (defun parameter-location (param) (check-type param hash-table) (gethash "in" param)) (defun parameter-type (param) (check-type param hash-table) (gethash "type" param)) (defun parameter-required-p (param) (check-type param hash-table) (or (gethash "required" param) (parameter-location-schema-p param))) (defun parameter-location-schema-p (param) (check-type param hash-table) (gethash "schema" param)) (defun parameter-location-query-p (param) (check-type param hash-table) (string= (string-downcase (parameter-location param)) "query")) (defun parameter-location-header-p (param) (check-type param hash-table) (string= (string-downcase (parameter-location param)) "header")) (defun parameter-location-path-p (param) (check-type param hash-table) (string= (string-downcase (parameter-location param)) "path")) (defun parameter-location-body-p (param) (check-type param hash-table) (string= (string-downcase (parameter-location param)) "body")) (defun parameter-location-form-p (param) (check-type param hash-table) (string= (string-downcase (parameter-location param)) "formdata")) (defun openapi-schemes-p (schemes) (and (listp schemes) (= (length schemes) ;; TODO(katco): ws and wss are also valid, but we don't yet handle these. (length (intersection schemes '("https" "http") :test #'string=))))) (defun select-scheme (schemes) "Pick a scheme from a list of options in order of preference." (check-type schemes list) (or (find "https" schemes :test #'string=) (find "http" schemes :test #'string=))) (defun media-type-form-p (media-type) (and media-type (find media-type '("application/x-www-form-urlencoded" "multipart/form-data") :test #'string=))) (defun media-type-subtype (media-type) (check-type media-type string) (subseq media-type (+ 1 (or (position #\+ media-type) (position #\/ media-type))))) (defun select-media-type (media-types) (check-type media-types list) (let ((media-subtypes (mapcar #'media-type-subtype media-types))) (or (find-if (lambda (e) (or (string= e "json") (string= e "yaml"))) media-subtypes) (nth (random (length media-subtypes)) media-subtypes)))) (defun generate-package-clauses (package-name &key packages-using packages-import) (check-type package-name symbol) (check-type packages-using list) (check-type packages-import list) `((in-package :cl-user) (defpackage ,package-name ,@(when packages-using `((:use ,@packages-using))) ,@(when packages-import (loop for pkg in packages-import collect `(:import-from ,pkg)))) (in-package ,package-name))) (defun generate-path-methods (client-name path-name path global-media-types security-schemas) (check-type client-name symbol) (check-type path-name string) (check-type path hash-table) (check-type global-media-types list) (check-type security-schemas list) (loop for operation-name being the hash-keys of path using (hash-value operation) for summary = (gethash "summary" operation) for description = (gethash "description" operation) for operation-id = (gethash "operationId" operation) for produces-media-types = (gethash "produces" operation) for consumes-media-types = (gethash "consumes" operation) for responses = (gethash "responses" operation) for schemes = (gethash "schemes" operation) for parameters = (gethash "parameters" operation) for security-requirement = (gethash "security" operation) ;; Synthesized fields for body-param = (find-if #'parameter-location-schema-p parameters) for method-name = (if operation-id operation-id (format nil "~a-~a" operation-name path-name)) for required-parameters = (remove body-param (remove-if-not #'parameter-required-p parameters)) for optional-parameters = (remove-if #'parameter-required-p parameters) ;; Enumerate through the known valid operations that we know ;; how to handle. Ignore all else. unless (find operation-name '("get" "put" "post" "delete")) do (when body-param (multiple-value-bind (required-body-params optional-body-params) (generate-schema-object-parameters (gethash "schema" body-param)) (setf required-parameters (append required-parameters required-body-params) optional-parameters (append optional-parameters optional-body-params)))) collect (let* ((param-descriptions (generate-parameter-comments (append required-parameters optional-parameters))) (method-comment (concatenate 'string (when summary (format nil "~a~%~%" summary)) (when description (format nil "~a~%~%" description)) (when param-descriptions param-descriptions)))) ;; Generate a method for each operation (generate-operation-method client-name method-name method-comment schemes path-name operation-name global-media-types consumes-media-types produces-media-types required-parameters optional-parameters (select-security-requirement security-schemas security-requirement))))) (defun select-security-requirement (security-schemas security-requirements) "Selects a security requirement from the list of options in an opinionated way. This algorithm prefers API Keys" (check-type security-schemas list) (check-type security-requirements list) (when security-requirements (car security-schemas))) (defun generate-client (client-name schemes host base-path consumes-media-types produces-media-types security-schemas) "Generates a client that all the methods will hang off of." (check-type client-name symbol) (assert (openapi-schemes-p schemes)) (check-type host string) (check-type base-path string) (check-type consumes-media-types list) (check-type produces-media-types list) (check-type security-schemas list) `(defclass ,client-name () ((cl-user::scheme :type string :documentation "The scheme to use for requests when the operation doesn't provide a preference of its own." :initarg :schemes :initform ,(select-scheme schemes) :accessor cl-user::scheme) (cl-user::host :type string :documentation "The host all requests for this client will be sent to." :initarg :host :initform ,host :accessor cl-user::host) (cl-user::base-path :type string :documentation "The base path that will be prepended to the path of all requests." :initarg :base-path :initform ,base-path :accessor cl-user::base-path) (cl-user::consumes-media-type :type string :documentation "The media-type to encode parameters to when operations do not declare a media-type." :initarg :consumes-media-type ,@(when consumes-media-types `(:initform ,(select-media-type consumes-media-types))) :accessor cl-user::consumes-media-type) (cl-user::produces-media-type :type string :documentation "The media-type to dencode results from when operations do not declare a media-type." :initarg :produces-media-type ,@(when produces-media-types `(:initform ,(select-media-type produces-media-types))) :accessor cl-user::produces-media-type) (cl-user::http-request :type function :documentation "A function for making HTTP requests. It needs to have the following signature: (lambda (uri &key method additional-headers content-type content parameters multipart-params))" :initarg :http-request :accessor cl-user::http-request) (cl-user::encoder-from-media-type :type hash-table :documentation "A hash table where the keys are media types the client can handle, and the values are functions which encode these media types to strings for inclusion into the http request." :initarg :encoder-from-media-type :initform (make-hash-table :test #'equalp) :accessor cl-user::encoder-from-media-type) ,@(loop for (name . schema) in security-schemas for lisp-name = (kebab-symbol-from-string (name schema)) when (eq (security-type schema) 'api-key) collect `(,lisp-name :type string :documentation ,(description schema) :accessor ,lisp-name))))) (defun generate-operation-method (client-name method-name method-comment schemes path method global-media-types consumes-media-types produces-media-types required-parameters optional-parameters security-requirement) "Generates a method for a generated client. Methods distinguish between required parameters and optional parameters, and optional parameters are defined as &key arguments. All arguments are run through `check-type' to both ensure the correct type is used and that the provided values meet any defined constraints." (check-type client-name symbol) (check-type method-name string) (check-type method-comment string) (when schemes (assert (openapi-schemes-p schemes))) (check-type path string) (check-type method string) (check-type global-media-types list) (check-type consumes-media-types list) (check-type produces-media-types list) (check-type required-parameters list) (check-type optional-parameters list) (check-type security-requirement list) (let ((lisp-required-parameters (mapcar #'lisp-parameter-name required-parameters)) (lisp-optional-parameters (mapcar #'lisp-parameter-name optional-parameters))) ;; Generated method begins here `(defmethod ,(kebab-symbol-from-string method-name) ((cl-user::client ,client-name) ,@lisp-required-parameters ,@(when lisp-optional-parameters `(&key ,@lisp-optional-parameters))) ,method-comment ,@(generate-check-type (append required-parameters optional-parameters)) ,(let ((path-params (append (remove-if-not #'parameter-location-path-p required-parameters) (remove-if-not #'parameter-location-path-p optional-parameters))) (query-params (append (remove-if-not #'parameter-location-query-p required-parameters) (remove-if-not #'parameter-location-query-p optional-parameters))) (headers (append (remove-if-not #'parameter-location-header-p required-parameters) (remove-if-not #'parameter-location-header-p optional-parameters))) (body-params (append (remove-if-not #'parameter-location-body-p required-parameters) (remove-if-not #'parameter-location-body-p optional-parameters))) (form-params (append (remove-if-not #'parameter-location-form-p required-parameters) (remove-if-not #'parameter-location-form-p optional-parameters))) (consumes-media-type (when consumes-media-types (select-media-type consumes-media-types)))) ;; If the content-type requests form params, put all the ;; body parameters in the form params list. Otherwise, move ;; all the form parameters into the body list so that they ;; can be encoded properly. (if (media-type-form-p consumes-media-type) (setf form-params (append form-params body-params) body-params nil) (setf body-params (append body-params form-params) form-params nil)) `(let (,@(when path-params '((cl-user::path-params (list)))) ,@(when (or query-params (and security-requirement (eq (security-type (cdr security-requirement)) 'api-key))) '((cl-user::query-params (list)))) ,@(when headers '((cl-user::headers (list)))) ,@(when body-params '((cl-user::body-params (list)))) ,@(when (and (media-type-form-p consumes-media-type) form-params) '((cl-user::form-params (list)))) ;; If we can't interpolate the scheme into the ;; request URI's string, grab it from the client. ,@(unless schemes `((cl-user::scheme (cl-user::scheme cl-user::client)))) (cl-user::consumes-media-type ,(if consumes-media-type consumes-media-type '(cl-user::consumes-media-type cl-user::client))) ;; If the operation's declared content-type is form ;; we don't need a hash-table to populate the body. ;; If the operation doesn't have a declared ;; content-type, we can't make the decision at ;; gen-time and we must reflect on what's defined in ;; the client. ,@(when (and body-params (or (not consumes-media-type) (media-type-form-p consumes-media-type))) '((cl-user::req-body (make-hash-table))))) ;; Build up alist of query params ,@(generate-http-request-population path-params 'cl-user::path-params) ,@(generate-http-request-population query-params 'cl-user::query-params) ,(when (and security-requirement (eq (security-type (cdr security-requirement)) 'api-key)) (let ((accessor (kebab-symbol-from-string (car security-requirement))) (requirement (cdr security-requirement))) `(setf cl-user::query-params (push (cons ,(name requirement) (,accessor cl-user::client)) cl-user::query-params)))) ,@(generate-http-request-population headers 'cl-user::headers) ,@(if (media-type-form-p consumes-media-type) (generate-http-request-population form-params 'cl-user::form-params) (generate-http-request-body-population body-params 'cl-user::req-body)) ;; Make the request (flet ((cl-user::replace-path-params (cl-user::uri cl-user::path-vars) (funcall (cl-strings:make-template-parser "{" "}") cl-user::uri cl-user::path-vars))) (funcall (cl-user::http-request cl-user::client) (format nil ,(concatenate 'string (if schemes (select-scheme schemes) "~a:") "//~a~a~a") cl-user::scheme (cl-user::host cl-user::client) (cl-user::base-path cl-user::client) ,(if path-params `(cl-user::replace-path-params ,path cl-user::path-params) path)) :method ,(intern (string-upcase method) "KEYWORD") :content-type cl-user::consumes-media-type ,@(when headers `(:additional-headers cl-user::headers)) ,@(when body-params `(:content (funcall (gethash cl-user::consumes-media-type (cl-user::encoder-from-media-type cl-user::client)) cl-user::req-body))) ,@(when query-params `(:parameters cl-user::query-params)) ,@(when form-params `(:multipart-params cl-user::form-params))))))))) (defun generate-check-type (parameters) (check-type parameters list) (loop for param in parameters for param-name = (lisp-parameter-name param) for param-type = (parameter-type param) for lisp-param-type = (when param-type (kebab-symbol-from-string param-type)) ;; Type must both be present and correspond to a check ;; function in order to perform type checking. when (find lisp-param-type '(string number integer array) :test #'string=) collect (if (parameter-required-p param) `(check-type ,param-name ,lisp-param-type) `(when ,param-name (check-type ,param-name ,lisp-param-type))))) (defun generate-http-request-body-population (params req-body-name) (check-type params list) (loop for param in params for param-name = (parameter-name param) for lisp-param-name = (lisp-parameter-name param) for set-value-sexp = `(setf (gethash ,param-name ,req-body-name) ,lisp-param-name) collect (if (parameter-required-p param) set-value-sexp `(when ,lisp-param-name ,set-value-sexp)))) (defun generate-http-request-population (params request-alist) "Generates code to populate an alist intended to be passed into an http-request." (check-type params list) (check-type request-alist symbol) (loop for param in params for param-name = (parameter-name param) for lisp-param-name = (lisp-parameter-name param) collect (if (parameter-required-p param) `(setf ,request-alist (push (cons ,param-name ,lisp-param-name) ,request-alist)) `(when ,lisp-param-name (setf ,request-alist (push (cons ,param-name ,lisp-param-name) ,request-alist)))))) (defun generate-parameter-comments (parameters) "Generates a single string describing a list of parameters for inclusion in a method's docstring." (check-type parameters list) (with-output-to-string (parameter-desc) (loop for param in parameters for lisp-param-name = (lisp-parameter-name param) for param-desc = (gethash "description" param) when param-desc do (format parameter-desc "~a: ~a~%" lisp-param-name param-desc)))) (defun generate-schema-object-parameters (schema-object) "Generates hash-tables which look like openapi parameters from schema object properties. This is so that we can pass these into generation code that synthesizes CL method parameters from openapi parameters." ;; TODO(katco): Create types since properties and parameters have similarities (check-type schema-object hash-table) (let ((schema-properties (gethash "properties" schema-object)) (required-parameters (list)) (optional-parameters (list)) (declared-as-required (gethash "required" schema-object))) (when schema-properties (loop for prop-name being the hash-keys of schema-properties using (hash-value prop) for prop-type = (parameter-type prop) for prop-desc = (gethash "description" prop) for faux-param = (make-hash-table :test #'equalp) do (setf (gethash "required" faux-param) (find prop-name declared-as-required :test #'string=) (gethash "name" faux-param) prop-name (gethash "type" faux-param) prop-type (gethash "in" faux-param) "body" (gethash "description" faux-param) prop-desc) (if (find prop-name declared-as-required :test #'string=) (setf required-parameters (push faux-param required-parameters)) (setf optional-parameters (push faux-param optional-parameters))))) (values required-parameters optional-parameters))) ;;; Security Scheme Objects (deftype variable-location () '(member query header path body form-data)) (defclass schema-variable () ((name :type string :documentation "The name of the header or query parameter to be used." :initarg :name :reader name) (in :type variable-location :documentation "Where in the HTTP request the variable is placed. Valid values are '(query header path body form-data)" :initarg :in :reader in))) (deftype flow () '(member implicit password application access-code)) (deftype security-type () '(member basic api-key oauth2)) (defun security-schemas-from-hash-table (raw) "Collects security schemas into an alist of (name . instance)." (check-type raw (or hash-table null)) (unless raw (return-from security-schemas-from-hash-table (list))) (loop for schema-name being the hash-keys of raw for schema being the hash-values of raw collect (cons schema-name (make-instance 'security-schema :name (gethash "name" schema) :in (kebab-symbol-from-string (gethash "in" schema) :openapi2cl/core) :type (kebab-symbol-from-string (gethash "type" schema) :openapi2cl/core) :description (gethash "description" schema) :flow (alexandria:when-let (flow (gethash "flow" schema)) (intern flow)) :authorization-url (gethash "authorizationUrl" schema) :token-url (gethash "tokenUrl" schema) :scopes (gethash "scopes" schema))))) (defclass security-schema (schema-variable) ((type :type security-type :documentation "The type of the security scheme." :initarg :type :initform (error "type not specified") :reader security-type) (description :type (or string null) :documentation "A short description for security scheme." :initarg :description :reader description) (flow :type (or flow null) :documentation "The flow used by the OAuth2 security scheme." :initarg :flow) (authorization-url :type (or string null) :documentation "The authorization URL to be used for this flow. This SHOULD be in the form of a URL." :initarg :authorization-url) (token-url :type (or string null) :documentation "The token URL to be used for this flow. This SHOULD be in the form of a URL." :initarg :token-url) (scopes :documentation "The available scopes for the OAuth2 security scheme." :initarg :scopes)) (:documentation "A security schema that an OpenAPI endpoint accepts."))
30,110
Common Lisp
.lisp
568
41.801056
183
0.625339
kat-co/openapi2cl
16
5
4
GPL-3.0
9/19/2024, 11:26:41 AM (Europe/Amsterdam)
a273f329191348ce6374de1f824d224f936bedfbfbfc7f5ab186630f4f832341
9,002
[ -1 ]