Skip to content

Commit 1ce8a30

Browse files
author
Dmitry Ignatiev
committed
Initial commit
0 parents  commit 1ce8a30

19 files changed

+1540
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.fasl

COPYRIGHT

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright (C) 2015, Dmitry Ignatiev <lovesan.ru at gmail.com>
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use, copy,
7+
modify, merge, publish, distribute, sublicense, and/or sell copies
8+
of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Common Lisp Runtime
2+
===================
3+
4+
Because we need one...
5+
6+
...Work in progress

clr.asd

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
2+
3+
;;; Copyright (C) 2015, Dmitry Ignatiev <lovesan.ru at gmail.com>
4+
5+
;;; Permission is hereby granted, free of charge, to any person
6+
;;; obtaining a copy of this software and associated documentation
7+
;;; files (the "Software"), to deal in the Software without
8+
;;; restriction, including without limitation the rights to use, copy,
9+
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
10+
;;; of the Software, and to permit persons to whom the Software is
11+
;;; furnished to do so, subject to the following conditions:
12+
13+
;;; The above copyright notice and this permission notice shall be
14+
;;; included in all copies or substantial portions of the Software.
15+
16+
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20+
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21+
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23+
;;; DEALINGS IN THE SOFTWARE.
24+
25+
(defsystem #:clr
26+
:version "0.1.0"
27+
:description "Common Lisp Runtime"
28+
:author "Dmitry Ignatiev <lovesan.ru at gmail.com>"
29+
:maintainer "Dmitry Ignatiev <lovesan.ru at gmail.com>"
30+
:licence "MIT",
31+
:depends-on ()
32+
:serial t
33+
:components ((:module "src"
34+
:serial t
35+
:components (;(:file "package")
36+
;(:file "impl-sbcl")
37+
;(:file "cl-threadpool")
38+
))))
39+
40+
;; vim: ft=lisp et
41+

load.lisp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
(in-package #:cl-user)
2+
3+
(flet ((cl-file (f) (load (compile-file (truename f)))))
4+
(cl-file "src/clr.lisp")
5+
#+sbcl
6+
(cl-file "src/impl-sbcl.lisp")
7+
#-(or sbcl)
8+
(error "Implementation not supported"))
9+
10+
(flet ((cl-file (f) (load (compile-file (truename f)))))
11+
(cl-file "src/base-types.lisp")
12+
(cl-file "src/utils.lisp")
13+
(cl-file "src/collections.lisp")
14+
(cl-file "src/iterators.lisp")
15+
(cl-file "src/queue.lisp")
16+
(cl-file "src/stack.lisp")
17+
(cl-file "src/concurrent-stack.lisp")
18+
(cl-file "src/ffi.lisp")
19+
#+clr:windows
20+
(cl-file "src/ffi-windows.lisp")
21+
(cl-file "src/threading.lisp")
22+
(cl-file "src/thread-pool.lisp")
23+
)

src/base-types.lisp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
(in-package #:clr)
2+
3+
(deftype simple-char-string () '(simple-array character (*)))
4+
5+
(deftype int8 () '(signed-byte 8))
6+
7+
(deftype uint8 () '(unsigned-byte 8))
8+
9+
(deftype int16 () '(signed-byte 16))
10+
11+
(deftype short () 'int16)
12+
13+
(deftype uint16 () '(unsigned-byte 16))
14+
15+
(deftype ushort () 'uint16)
16+
17+
(deftype int32 () '(signed-byte 32))
18+
19+
(deftype int () 'int32)
20+
21+
(deftype uint32 () '(unsigned-byte 32))
22+
23+
(deftype uint () 'uint32)
24+
25+
(deftype int64 () '(signed-byte 64))
26+
27+
(deftype long () #+clr:windows 'int32 #-clr:windows 'int64)
28+
29+
(deftype long-long () 'int64)
30+
31+
(deftype uint64 () '(unsigned-byte 64))
32+
33+
(deftype ulong () #+clr:windows 'uint32 #-clr:windows 'uint64)
34+
35+
(deftype ulong-long () 'uint64)
36+
37+
(deftype intptr () '(signed-byte #+clr:x32 32 #+clr:x64 64))
38+
39+
(deftype uintptr () '(unsigned-byte #+clr:x32 32 #+clr:x64 64))
40+
41+
(deftype index () '(integer 0 #.most-positive-fixnum))

src/clr.lisp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
(in-package #:cl-user)
2+
3+
(defpackage #:clr
4+
(:use #:cl)
5+
(:export
6+
7+
;;; features
8+
#:sbcl
9+
#:x32
10+
#:x64
11+
#:x86
12+
#:x86-64
13+
#:windows
14+
#:unix
15+
16+
;;; base types
17+
#:int8
18+
#:uint8
19+
#:int16
20+
#:short
21+
#:uint16
22+
#:ushort
23+
#:int32
24+
#:int
25+
#:uint32
26+
#:uint
27+
#:int64
28+
#:long
29+
#:long-long
30+
#:uint64
31+
#:ulong
32+
#:ulong-long
33+
#:intptr
34+
#:uintptr
35+
#:simple-char-string
36+
#:index
37+
))

src/collections.lisp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
(in-package #:cl-user)
2+
3+
(defpackage #:clr.collections
4+
(:use #:cl #:clr #:clr.impl #:clr.utils)
5+
(:export
6+
#:queue
7+
#:queue-p
8+
#:make-queue
9+
#:queue-add
10+
#:queue-remove
11+
#:queue-peek
12+
#:queue-clear
13+
#:queue-size
14+
#:queue-empty-p
15+
#:stack
16+
#:stack-p
17+
#:make-stack
18+
#:stack-push
19+
#:stack-pop
20+
#:stack-clear
21+
#:stack-peek
22+
#:stack-size
23+
#:stack-empty-p
24+
#:concurrent-stack
25+
#:make-concurrent-stack
26+
#:cstack-p
27+
#:cstack-push
28+
#:cstack-peek
29+
#:cstack-pop
30+
#:cstack-clear
31+
#:cstack-size
32+
#:cstack-empty-p
33+
))

src/concurrent-stack.lisp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
(in-package #:clr.collections)
2+
3+
(defstruct (concurrent-stack
4+
(:constructor %make-cstack)
5+
(:predicate cstack-p)
6+
(:conc-name %cst-))
7+
(size 0 :type index)
8+
(head '() :type list))
9+
10+
(defun make-concurrent-stack ()
11+
(%make-cstack))
12+
13+
(defun cstack-push (cstack value)
14+
(declare (type concurrent-stack cstack))
15+
(loop :with new = (cons value nil)
16+
:for head = (%cst-head cstack) :do
17+
(setf (cdr new) head)
18+
(when (eq head (compare-exchange (%cst-head cstack) head new))
19+
(atomic-incf (%cst-size cstack))
20+
(return cstack))))
21+
22+
(defun cstack-pop (cstack)
23+
(declare (type concurrent-stack cstack))
24+
(loop :for head = (%cst-head cstack)
25+
:for next = (cdr head) :do
26+
(when (null head)
27+
(return (values nil nil)))
28+
(when (eq head (compare-exchange (%cst-head cstack) head next))
29+
(atomic-decf (%cst-size cstack))
30+
(return (values (car head) t)))))
31+
32+
(defun cstack-peek (cstack)
33+
(declare (type concurrent-stack cstack))
34+
(let ((head (%cst-head cstack)))
35+
(if head
36+
(values (car head) t)
37+
(values nil nil))))
38+
39+
(defun cstack-size (cstack)
40+
(declare (type concurrent-stack cstack))
41+
(%cst-size cstack))
42+
43+
(defun cstack-empty-p (cstack)
44+
(declare (type concurrent-stack cstack))
45+
(zerop (%cst-size cstack)))
46+
47+
(defun cstack-clear (cstack)
48+
(declare (type concurrent-stack cstack))
49+
(setf (%cst-size cstack) 0
50+
(%cst-head cstack) '()))

src/ffi-windows.lisp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
(in-package #:cl-user)
2+
3+
(defpackage #:clr.ffi.impl
4+
(:use #:cl #:clr #:clr.impl #:clr.ffi)
5+
(:export
6+
#:cpu-count))
7+
8+
(in-package #:clr.ffi.impl)
9+
10+
(defclib kernel32 "kernel32.dll")
11+
12+
(defmacro syscall (name &rest args-and-types)
13+
`(ffcall (,name :library kernel32 :convention :stdcall) ,@args-and-types))
14+
15+
(defcstruct system-info
16+
(oem-id :uint32)
17+
(page-size :uint32)
18+
(min-alloc :pointer)
19+
(max-alloc :pointer)
20+
(act-proc-mask :uintptr)
21+
(num-proc :uint32)
22+
(proc-type :uint32)
23+
(alloc-gran :uint32)
24+
(proc-level :uint32)
25+
(proc-rev :uint32))
26+
27+
(defun cpu-count ()
28+
"Returieves current CPU count"
29+
(with-cptr (p system-info)
30+
(unless (syscall "GetSystemInfo" :pointer p :bool)
31+
(error "Unable to get system information"))
32+
(cslot p system-info num-proc)))

0 commit comments

Comments
 (0)