forked from armedbear/abcl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tooling around on rainy pandemic Saturday
Create SIMPLE-VECTOR backed with java.nio.Buffer abstractions EXT:MAKE-BYTEBUFFER-BYTE-VECTOR, EXT:MAKE-CHARBUFFER-BYTE-VECTOR, EXT:MAKE-INTBUFFER-BYTE-VECTOR return a simple vector containing unsigned elements for types (unsigned-byte 8), (unsigned-byte 16), (unsigned-byte 32). The EXT:MAKE-NIOBUFFER function provides the means to construct a SIMPLE-VECTOR which shares the NIO-BUFFER contents. (ext:make-niobuffer nio-buffer :element-type '(unsigned-byte 8)) t/static-vector.lisp shows the creation of a bytebuffer for right now. Add "buffers.lisp" to autoload on function definitions, otherwise the function definitions for EXT:MAKE-INTBUFFER-BYTE-VECTOR EXT:MAKE-CHARBUFFER-BYTE-VECTOR aren't loaded when first accessed.
- Loading branch information
Showing
8 changed files
with
153 additions
and
1 deletion.
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
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
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,49 @@ | ||
(in-package :ext) | ||
|
||
(defvar *buffer-allocation* :primitive-array | ||
"The current buffer allocation strategy.") | ||
|
||
(defun choose-buffer-strategy (&key (new-default :nio new-default-p)) | ||
"Return current choices for buffer allocation strategy that can then be chosen as a :new-default strategy | ||
Not currently advisable to call during runtime. " | ||
(if new-default-p | ||
(setf *buffer-allocation* new-default) | ||
'((:nio | ||
((unsigned-byte 8) | ||
. BasicVector_ByteBuffer) | ||
((unsigned-byte 16) | ||
. BasicVector_CharBuffer) | ||
((unsigned-byte 32) | ||
. BasicVector_IntBuffer)) | ||
(:primitive-array | ||
((unsigned-byte 8) | ||
. BasicVector_UnsignedByte8) | ||
((unsigned-byte 16) | ||
. BasicVector_UnsignedByte16) | ||
((unsigned-byte 32) | ||
. BasicVector_UnsignedByte32))))) | ||
|
||
(defun make-niobuffer-vector (nio-buffer &key (element-type '(unsigned-byte 8))) | ||
(unless (subtypep element-type '(unsigned-byte *)) | ||
(signal 'type-error "Need some subtype of (UNSIGNED-BYTE *)")) ;; FIXME: :datum , | ||
(case (second element-type) ;; FIXME: probably wrong for types that aren't 8, 16, or 32 | ||
(8 | ||
(ext:make-bytebuffer-byte-vector nio-buffer)) | ||
(16 | ||
(ext:make-charbuffer-byte-vector nio-buffer)) | ||
(32 | ||
(ext:make-intbuffer-byte-vector nio-buffer)) | ||
(t | ||
(ext:make-bytebuffer-byte-vector nio-buffer)))) | ||
|
||
|
||
(eval-when (:load-toplevel :execute) | ||
;;; FIXME: otherwise EXT:MAKE-INTBUFFER-BYTE-VECTOR doesn't get loaded | ||
(make-array 1 :element-type '(unsigned-byte 16)) | ||
(make-array 2 :element-type '(unsigned-byte 32))) | ||
|
||
|
||
|
||
|
||
|
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,15 @@ | ||
(in-package :cl-user) | ||
|
||
(require :abcl-contrib) | ||
(require :jss) | ||
|
||
(prove:plan 1) | ||
(prove:ok | ||
(let* ((bytebuffer | ||
(#"allocate" 'nio.ByteBuffer 21)) | ||
(vector | ||
(ext:make-bytebuffer-byte-vector bytebuffer))) | ||
(and | ||
vector | ||
(typep vector '(SIMPLE-ARRAY (UNSIGNED-BYTE 8) (21)))))) | ||
(prove:finalize) |