Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openjdk8/vectors/simple/20230905a #625

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
998fb86
Rework SIMPLE-VECTOR implementation using openjdk8 facilities
easye Sep 3, 2023
3a04fba
Use SimpleVector(int) constructor for new SIMPLE-VECTOR
easye Sep 3, 2023
ace4069
Use system array copy SIMPLE-VECTOR for SUBSEQ
easye Sep 4, 2023
3da7bb3
Adjust AbstractVector.badIndex() so it can be return'd
easye Sep 4, 2023
9ed1f9a
Remove final from SimpleVector so we can inherit
easye Sep 4, 2023
7807899
Most of an implementation of BasicVectorBuffer for bytes
easye Sep 4, 2023
a90dff7
Add missing SimpleVector no-arg constructor
easye Sep 4, 2023
b8ff2fb
Fix SimpleVector classOf()/typeOf()
easye Sep 4, 2023
3e2df5e
Add static constant for UNSIGNED_BYTE_64
easye Sep 4, 2023
210d033
Minor BasicVectorBuffer adjustments
easye Sep 4, 2023
700f430
Minor SimpleVector tweaks
easye Sep 4, 2023
918f687
Implementation for vectors specialized on primitive types
easye Sep 4, 2023
fc78243
Fix BasicVectorPrimitive.typep()
easye Sep 4, 2023
97981fe
Implement coerceToJavaUnsignedShort
easye Sep 5, 2023
d0588f0
Implement an inefficient conversion of unsigned 64 bit
easye Sep 5, 2023
49dbbe7
Further work on SimpleVector specializations
easye Sep 5, 2023
8695308
Method to convert a Lisp integer to an "unsigned" Java long
easye Sep 5, 2023
39d4ba0
BasicVectorPrimitive might be complete enough to be wired in
easye Sep 5, 2023
fa509a5
Some basic javadoc for the new types
easye Sep 9, 2023
b78f49f
Try using AbstractVector.deleteEQ()
easye Sep 6, 2023
78e139f
The new nio Buffer *might* work on u8 specializations
easye Sep 6, 2023
fc11e7c
DESCRIBE shows which class implementation of SIMPLE-VECTOR
easye Sep 9, 2023
fb64ec8
Check type when coerceing to a LispInteger
easye Sep 9, 2023
a62f71d
BasicVectorPrimitive should be complete
easye Sep 9, 2023
c67f2ee
doc: simple vectors specialization on java.nio works only for u8
easye Sep 9, 2023
f0580c4
Remove generics for SimpleVector
easye Sep 9, 2023
76b41a0
INCOMPLETE Implement nio Buffer as having views of a u8 vector
easye Sep 9, 2023
f8157f0
Simple vectors backed with java.nio.Buffer *might* work
easye Sep 10, 2023
26de4f8
t: fix mistake in test output
easye Sep 11, 2023
d428232
whitespace
easye Sep 11, 2023
86267fe
Java static constant for 2^32 fixnum
easye Sep 11, 2023
2823cbf
Check Lisp type for operations on specialized simple vectors
easye Sep 11, 2023
7cc2638
Move comment for asUnsignedLong()
easye Sep 11, 2023
c4b381e
Fix SUBSEQ and REVERSE on SIMPLE-VECTORS backed by NIO classes
easye Sep 11, 2023
7bf4b40
NIO backed unsigned types working for IRONCLAD
easye Nov 21, 2023
b9164fa
Wire in usage of (UNSIGNED-BYTE 8) types
easye Nov 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/org/armedbear/lisp/AbstractVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public int checkIndex(int index)
return index;
}

protected void badIndex(int index, int limit)
protected LispObject badIndex(int index, int limit)
{
StringBuilder sb = new StringBuilder("Invalid array index ");
sb.append(index);
Expand All @@ -161,12 +161,11 @@ protected void badIndex(int index, int limit)
sb.append(limit);
sb.append(").");
}
error(new TypeError(sb.toString(),
Fixnum.getInstance(index),
list(Symbol.INTEGER,
Fixnum.ZERO,
Fixnum.getInstance(limit - 1))));

return error(new TypeError(sb.toString(),
Fixnum.getInstance(index),
list(Symbol.INTEGER,
Fixnum.ZERO,
Fixnum.getInstance(limit - 1))));
}

public void setFillPointer(int n)
Expand Down
159 changes: 159 additions & 0 deletions src/org/armedbear/lisp/BasicVector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package org.armedbear.lisp;

import static org.armedbear.lisp.Lisp.*;

/**
A basic vector is a specialized vector that is not displaced to another
array, has no fill pointer, and is not expressly adjustable.

All BasicVectors are children of SimpleVector.
*/
abstract public class BasicVector
extends SimpleVector
{
public enum Specialization {
U8(1), U16(2), U32(4), U64(8);

public final int totalBytes;

private Specialization(int bytes) {
totalBytes = bytes;
}

}
Specialization specializedOn;

public BasicVector(Class type) {
if (type.equals(Byte.class) || type.equals(byte.class)) {
specializedOn = Specialization.U8;
} else if (type.equals(Short.class) || type.equals(short.class)) {
specializedOn = Specialization.U16;
} else if (type.equals(Integer.class) || type.equals(int.class)) {
specializedOn = Specialization.U32;
} else if (type.equals(Long.class)|| type.equals(long.class)) {
specializedOn = Specialization.U64;
}
}

public BasicVector(Class type, int capacity) {
this(type);
this.capacity = capacity;
}

@Override
public LispObject typeOf() {
switch (specializedOn) {
case U8:
return list(Symbol.SIMPLE_VECTOR, UNSIGNED_BYTE_8, new Cons(Fixnum.getInstance(capacity)));
case U16:
return list(Symbol.SIMPLE_VECTOR, UNSIGNED_BYTE_16, new Cons(Fixnum.getInstance(capacity)));
case U32:
return list(Symbol.SIMPLE_VECTOR, UNSIGNED_BYTE_32, new Cons(Fixnum.getInstance(capacity)));
case U64:
return list(Symbol.SIMPLE_VECTOR, UNSIGNED_BYTE_64, new Cons(Fixnum.getInstance(capacity)));
}
return program_error("Unreachable");
}

public LispObject typep(LispObject type) {
if (type instanceof Cons) {
if (type.car().equals(Symbol.SIMPLE_VECTOR)) {
LispObject vectorType = type.cdr();
switch (specializedOn) {
case U8:
if (vectorType.equals(UNSIGNED_BYTE_8)) {
return T;
}
break;
case U16:
if (vectorType.equals(UNSIGNED_BYTE_16)) {
return T;
}
break;
case U32:
if (vectorType.equals(UNSIGNED_BYTE_32)) {
return T;
}
break;
case U64:
if (vectorType.equals(UNSIGNED_BYTE_64)) {
return T;
}
break;
}
}
}
return super.typep(type);
}

@Override
public LispObject getElementType() {
switch (specializedOn) {
case U8:
return UNSIGNED_BYTE_8;
case U16:
return UNSIGNED_BYTE_16;
case U32:
return UNSIGNED_BYTE_32;
case U64:
return UNSIGNED_BYTE_64;
}
return program_error("Unknown element type: " + type);
}

@Override
public LispObject getDescription() {
StringBuffer sb = new StringBuffer("A simple vector specialized on ");
switch (specializedOn) {
case U8:
sb.append("(UNSIGNED-BYTE 8)");
break;
case U16:
sb.append("(UNSIGNED-BYTE 16)");
break;
case U32:
sb.append("(UNSIGNED-BYTE 32)");
break;
case U64:
sb.append("(UNSIGNED-BYTE 64)");
break;
}
sb.append(" with ").append(capacity).append(" elements").append(".")
.append("\n");
return new SimpleString(sb);
}

// should be coerceToUnsignedElementType???
LispInteger coerceToElementType(LispObject o) {
LispInteger result = LispInteger.coerceAsUnsigned(o);
switch (specializedOn) {
case U8:
if (result.isLessThan(0)
|| result.isGreaterThan(255)) {
return (LispInteger) type_error(result, UNSIGNED_BYTE_8);
}
break;
case U16:
if (result.isLessThan(0)
|| result.isGreaterThan(65536)) {
return (LispInteger) type_error(result, UNSIGNED_BYTE_16);
}
break;
case U32:
if (result.isLessThan(0)
|| result.isGreaterThan(Bignum.MAX_UNSIGNED_BYTE_32)) {
return (LispInteger) type_error(result, UNSIGNED_BYTE_32);
}
break;
case U64:
if (result.isLessThan(0)
|| result.isGreaterThan(Bignum.MAX_UNSIGNED_BYTE_64)) {
return (LispInteger) type_error(result, UNSIGNED_BYTE_32);
}
break;
}
return result;
}


}
Loading