-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add specialized LispArray and Complex logic
This commit does two main things: 1. Adds (LispArray :t). There are presently no constructors for it, but there is logic to emit appropriately specialized (SIMPLE-ARRAY <t> (*)) declarations in many common monomorphic cases. 2. Handles the repr of (Complex :t) specially from LISP-TYPE so that more specific type declarations are emitted for floating point types.
- Loading branch information
1 parent
cb2fda9
commit f66e728
Showing
5 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
;;;; lisparray.lisp | ||
;;;; | ||
;;;; An interface to Common Lisp rank-1 SIMPLE-ARRAYs. | ||
|
||
(coalton-library/utils:defstdlib-package #:coalton-library/lisparray | ||
(:use #:coalton) | ||
(:local-nicknames (#:ram #:coalton-library/randomaccess) | ||
(#:ty #:coalton-library/types)) | ||
(:export | ||
#:LispArray)) | ||
|
||
(in-package #:coalton-library/lisparray) | ||
|
||
(named-readtables:in-readtable coalton:coalton) | ||
|
||
#+coalton-release | ||
(cl:declaim #.coalton-impl/settings:*coalton-optimize-library*) | ||
|
||
(coalton-toplevel | ||
;; The representation of (LispArray :t) is specially dealt with by | ||
;; the compiler in lisp-type.lisp. | ||
(define-type (LispArray :t) | ||
"A one-dimensional, non-resizable array of elements. | ||
These arrays are represented as possibly specialized `(cl:simple-array <t> (cl:*))` and are meant to be used as a flexible tool to implement efficient data structures. One should consult `Vector` or `Seq` for more general sequential data structure needs. | ||
Whether or not the arrays are specialized depends on the underlying Lisp implementation. Consult `cl:upgraded-array-element-type` to determine whether `LispArray` may get specialized.") | ||
|
||
) ; COALTON-TOPLEVEL | ||
|
||
(coalton-toplevel | ||
(declare make-lisparray (ty:RuntimeRepr :t => UFix -> :t -> (LispArray :t))) | ||
(define (make-lisparray n x) | ||
;; FIXME: how can we get this statically? | ||
(let ((type (ty:runtime-repr (ty:proxy-of x)))) | ||
(lisp (LispArray :t) (n x type) | ||
(cl:make-array n :element-type type :initial-element x))))) | ||
|
||
(coalton-toplevel | ||
(define-instance (ty:RuntimeRepr :t => ram:RandomAccess (LispArray :t) :t) | ||
(define (ram:make n x) | ||
(make-lisparray n x)) | ||
|
||
(define (ram:length v) | ||
(lisp UFix (v) | ||
(cl:length v))) | ||
|
||
(define (ram:readable? v_) | ||
True) | ||
|
||
(define (ram:writable? v_) | ||
True) | ||
|
||
(define (ram:unsafe-aref v i) | ||
(lisp :t (v i) | ||
(cl:aref v i))) | ||
|
||
(define (ram:unsafe-set! v i x) | ||
(lisp Unit (v i x) | ||
(cl:setf (cl:aref v i) x) | ||
Unit)))) | ||
|
||
#+sb-package-locks | ||
(sb-ext:lock-package "COALTON-LIBRARY/LISPARRAY") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters