This commit is contained in:
Dante
2026-05-21 23:40:20 -07:00
parent 3e2915dff7
commit 877a69d844
5737 changed files with 29796 additions and 1589684 deletions

View File

@ -47,7 +47,7 @@ class Closure extends ClosureDispatch {
args;
};
try {
return method.invoke(context, args);
return method.invoke(context, ...args);
} catch (e:java.lang.reflect.InvocationTargetException) {
throw e.getCause();
}

View File

@ -291,7 +291,7 @@ class Jvm {
static public function readFieldClosure(obj:Dynamic, name:String, parameterTypes:NativeArray<java.lang.Class<Dynamic>>):Dynamic {
var cl = (obj : java.lang.Object).getClass();
var method = cl.getMethod(name, parameterTypes);
var method = cl.getMethod(name, ...parameterTypes);
if (method.isBridge()) {
/* This is probably not what we want... go through all methods and see if we find one that
isn't a bridge. This is pretty awkward, but I can't figure out how to use the Java reflection

View File

@ -22,6 +22,8 @@
import jvm.Jvm;
using StringTools;
@:coreApi
class Std {
@:deprecated('Std.is is deprecated. Use Std.isOfType instead.')
@ -63,55 +65,74 @@ class Std {
return cast x;
}
static inline function isSpaceChar(code:Int):Bool
return (code > 8 && code < 14) || code == 32;
static inline function isHexPrefix(cur:Int, next:Int):Bool
return cur == '0'.code && (next == 'x'.code || next == 'X'.code);
static inline function isDecimalDigit(code:Int):Bool
return '0'.code <= code && code <= '9'.code;
static inline function isHexadecimalDigit(code:Int):Bool
return isDecimalDigit(code) || ('a'.code <= code && code <= 'f'.code) || ('A'.code <= code && code <= 'F'.code);
public static function parseInt(x:String):Null<Int> {
if (x == null) {
if (x == null)
return null;
final len = x.length;
var index = 0;
inline function hasIndex(index:Int)
return index < len;
// skip whitespace
while (hasIndex(index)) {
if (!isSpaceChar(x.unsafeCodeAt(index)))
break;
++index;
}
var base = 10;
var len = x.length;
var foundCount = 0;
var sign = 0;
var firstDigitIndex = 0;
var lastDigitIndex = -1;
var previous = 0;
// handle sign
final isNegative = hasIndex(index) && {
final sign = x.unsafeCodeAt(index);
if (sign == '-'.code || sign == '+'.code) {
++index;
}
sign == '-'.code;
}
for (i in 0...len) {
var c = StringTools.fastCodeAt(x, i);
switch c {
case _ if ((c > 8 && c < 14) || c == 32):
if (foundCount > 0) {
return null;
}
continue;
case '-'.code if (foundCount == 0):
sign = -1;
case '+'.code if (foundCount == 0):
sign = 1;
case '0'.code if (foundCount == 0 || (foundCount == 1 && sign != 0)):
case 'x'.code | 'X'.code if (previous == '0'.code && ((foundCount == 1 && sign == 0) || (foundCount == 2 && sign != 0))):
base = 16;
case _ if ('0'.code <= c && c <= '9'.code):
case _ if (base == 16 && (('a'.code <= c && c <= 'z'.code) || ('A'.code <= c && c <= 'Z'.code))):
case _:
break;
// handle base
final isHexadecimal = hasIndex(index + 1) && isHexPrefix(x.unsafeCodeAt(index), x.unsafeCodeAt(index + 1));
if (isHexadecimal)
index += 2; // skip prefix
// handle digits
final firstInvalidIndex = {
var cur = index;
if (isHexadecimal) {
while (hasIndex(cur)) {
if (!isHexadecimalDigit(x.unsafeCodeAt(cur)))
break;
++cur;
}
} else {
while (hasIndex(cur)) {
if (!isDecimalDigit(x.unsafeCodeAt(cur)))
break;
++cur;
}
}
if ((foundCount == 0 && sign == 0) || (foundCount == 1 && sign != 0)) {
firstDigitIndex = i;
}
foundCount++;
lastDigitIndex = i;
previous = c;
cur;
}
if (firstDigitIndex <= lastDigitIndex) {
var digits = x.substring(firstDigitIndex + (base == 16 ? 2 : 0), lastDigitIndex + 1);
return try {
(sign == -1 ? -1 : 1) * java.lang.Integer.parseInt(digits, base);
} catch (e:java.lang.NumberFormatException) {
null;
}
}
return null;
// no valid digits
if (index == firstInvalidIndex)
return null;
final result = java.lang.Integer.parseInt(x.substring(index, firstInvalidIndex), if (isHexadecimal) 16 else 10);
return if (isNegative) -result else result;
}
public static function parseFloat(x:String):Float {

View File

@ -123,17 +123,9 @@ class Type {
}
}
static final emptyArg = {
var a = new java.NativeArray(1);
a[0] = (null : jvm.EmptyConstructor);
a;
}
static final emptyArg = (null : jvm.EmptyConstructor);
static final emptyClass = {
var a = new java.NativeArray(1);
a[0] = jvm.EmptyConstructor.native();
a;
}
static final emptyClass = jvm.EmptyConstructor.native();
public static function createInstance<T>(cl:Class<T>, args:Array<Dynamic>):T {
var args = @:privateAccess args.getNative();
@ -150,7 +142,7 @@ class Type {
switch (Jvm.unifyCallArguments(args, params, true)) {
case Some(args):
ctor.setAccessible(true);
return ctor.newInstance(args);
return ctor.newInstance(...args);
case None:
}
}
@ -166,7 +158,7 @@ class Type {
case Some(args):
var obj = emptyCtor.newInstance(emptyArg);
method.setAccessible(true);
method.invoke(obj, args);
method.invoke(obj, ...args);
return obj;
case None:
}
@ -178,7 +170,8 @@ class Type {
public static function createEmptyInstance<T>(cl:Class<T>):T {
var annotation = (cl.native().getAnnotation((cast ClassReflectionInformation : java.lang.Class<ClassReflectionInformation>)));
if (annotation != null) {
return cl.native().getConstructor(emptyClass).newInstance(emptyArg);
return cl.native().getConstructor(emptyClass)
.newInstance(emptyArg);
} else {
return cl.native().newInstance();
}
@ -241,7 +234,15 @@ class Type {
public static function getEnumConstructs(e:Enum<Dynamic>):Array<String> {
var clInfo:java.lang.Class<EnumReflectionInformation> = cast EnumReflectionInformation;
var annotation = e.native().getAnnotation(clInfo);
return @:privateAccess Array.ofNative(annotation.constructorNames());
if (annotation != null) {
return @:privateAccess Array.ofNative(annotation.constructorNames());
}
var vals = e.values();
var ret = [];
for (i in 0...vals.length) {
ret[i] = vals[i].name();
}
return ret;
}
public static function typeof(v:Dynamic):ValueType {
@ -303,7 +304,7 @@ class Type {
var ret = [];
for (name in all) {
var v = Jvm.readField(e, name);
if (Jvm.instanceof(v, jvm.Enum)) {
if (Jvm.instanceof(v, java.lang.Enum)) {
ret.push(v);
}
}

View File

@ -0,0 +1,61 @@
package haxe;
import haxe.ds.Vector;
import haxe.iterators.RestIterator;
import haxe.iterators.RestKeyValueIterator;
private typedef NativeRest<T> = Vector<T>;
@:coreApi
abstract Rest<T>(NativeRest<T>) {
public var length(get, never):Int;
inline function get_length():Int
return this.length;
inline function new(a:NativeRest<T>) {
this = a;
}
@:arrayAccess inline function get(index:Int):T
return this[index];
@:from extern inline static public function of<T>(array:Array<T>):Rest<T> {
var result = new NativeRest(array.length);
for (i in 0...array.length)
result[i] = array[i];
return new Rest(result);
}
@:from extern inline static function fromNative<T>(a:java.NativeArray<T>):Rest<T> {
return new Rest(Vector.fromData(a));
}
extern inline public function append(item:T):Rest<T> {
var r = new NativeRest(length + 1);
Vector.blit(this, 0, r, 0, length);
r[length] = item;
return new Rest(r);
}
extern inline public function prepend(item:T):Rest<T> {
var r = new NativeRest(length + 1);
Vector.blit(this, 0, r, 1, length);
r[0] = item;
return new Rest(r);
}
public inline function iterator():RestIterator<T>
return new RestIterator<T>(this);
public inline function keyValueIterator():RestKeyValueIterator<T>
return new RestKeyValueIterator<T>(this);
@:to public inline function toArray():Array<T> {
return [for (i in 0...this.length) this[i]];
}
public inline function toString():String {
return toArray().toString();
}
}

View File

@ -72,7 +72,7 @@ class StringMap<T> implements haxe.Constraints.IMap<String, T> {
public function toString():String {
var s = new StringBuf();
s.add("{");
s.add("[");
var it = keys();
for (i in it) {
s.add(i);
@ -81,7 +81,7 @@ class StringMap<T> implements haxe.Constraints.IMap<String, T> {
if (it.hasNext())
s.add(", ");
}
s.add("}");
s.add("]");
return s.toString();
}