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

@ -43,5 +43,10 @@ extern class Api {
@:hlNative("std", "ptr_compare") static function comparePointer(a:Dynamic, b:Dynamic):Int;
#if (hl_ver >= version("1.12.0"))
@:hlNative("std", "is_prim_loaded") static function isPrimLoaded(f:haxe.Constraints.Function):Bool;
@:hlNative("?std", "mem_compact") static function compact<T>( v : T, exclude : hl.NativeArray<Dynamic>, flags : Int, outCount : hl.Ref<Int> ) : T;
@:hlNative("?std", "sys_check_reload") static function checkReload( ?debugFile : hl.Bytes ) : Bool;
#end
#if (hl_ver >= version("1.13.0"))
@:hlNative("?std", "sys_has_debugger") static function hasDebugger() : Bool;
#end
}

View File

@ -0,0 +1,19 @@
package hl;
@:hlNative("std", "atomic_")
extern class Atomics {
static function add32(r:hl.Ref<Int>, a:Int):Int;
static function sub32(r:hl.Ref<Int>, a:Int):Int;
static function and32(r:hl.Ref<Int>, a:Int):Int;
static function or32(r:hl.Ref<Int>, a:Int):Int;
static function xor32(r:hl.Ref<Int>, a:Int):Int;
static function compareExchange32(r:hl.Ref<Int>, a:Int, b:Int):Int;
static function exchange32(r:hl.Ref<Int>, val:Int):Int;
static function load32(r:hl.Ref<Int>):Int;
static function store32(r:hl.Ref<Int>, val:Int):Int;
static function compareExchangePtr(r:hl.Ref<Dynamic>, a:Dynamic, b:Dynamic):Dynamic;
static function exchangePtr(r:hl.Ref<Dynamic>, val:Dynamic):Dynamic;
static function loadPtr(r:hl.Ref<Dynamic>):Dynamic;
static function storePtr(r:hl.Ref<Dynamic>, val:Dynamic):Dynamic;
}

View File

@ -0,0 +1,36 @@
package hl;
#if (hl_ver >= version("1.13.0"))
/**
CArray is a compact array where all objects are memory aligned and stored as a single GC block.
You must hold a reference to the CArray while any of the objects it contains is still referenced somewhere.
**/
abstract CArray<T>(Abstract<"hl_carray">) {
public var length(get,never) : Int;
inline function get_length() return getLen(cast this);
@:arrayAccess inline function get( index : Int ) : T return getIndex(cast this, index);
public static function alloc<T>( cl : Class<T>, size : Int ) : CArray<T> {
return cast alloc_carray( (cast cl:BaseType).__type__ , size );
}
@:hlNative("?std","carray_get")
static function getIndex( arr : CArray<Dynamic>, index : Int ) : Dynamic {
return null;
}
@:hlNative("?std","carray_length")
static function getLen( arr : CArray<Dynamic> ) : Int {
return 0;
}
@:hlNative("?std","alloc_carray")
static function alloc_carray( t : hl.Type, size : Int ) : CArray<Dynamic> {
return null;
}
}
#end

View File

@ -22,4 +22,46 @@
package hl;
@:coreType @:notNull @:runtimeValue abstract I64 to Int from Int {}
@:coreType @:notNull @:runtimeValue abstract I64 from Int {
/**
Destructively cast to Int
**/
public inline function toInt():Int {
return cast this;
}
@:to
@:deprecated("Implicit cast from I64 to Int (32 bits) is deprecated. Use .toInt() or explicitly cast instead.")
inline function implicitToInt(): Int {
return toInt();
}
#if (hl_ver >= version("1.12.0") && !hl_legacy32)
@:op(a+b) function add(v:I64) : I64;
@:op(a-b) function sub(v:I64) : I64;
@:op(a*b) function mul(v:I64) : I64;
@:op(a/b) function div(v:I64) : I64;
@:op(a%b) function mod(v:I64) : I64;
@:op(a<<b) function shl(v:Int) : I64;
@:op(a>>b) function shr(v:Int) : I64;
@:op(a>>>b) function ushr(v:Int) : I64;
@:op(a|b) function or(v:I64) : I64;
@:op(a&b) function and(v:I64) : I64;
@:op(a^b) function xor(v:I64) : I64;
@:op(-a) function neg() : I64;
@:op(~a) inline function compl() : I64 { return (-1:I64) - this; }
@:op(++a) function incr() : I64;
@:op(--a) function decr() : I64;
@:op(a++) function pincr() : I64;
@:op(a--) function pdecr() : I64;
@:op(a==b) function eq(v:I64) : Bool;
@:op(a>=b) function gte(v:I64) : Bool;
@:op(a<=b) function lte(v:I64) : Bool;
@:op(a>b) function gt(v:I64) : Bool;
@:op(a<b) function lt(v:I64) : Bool;
#end
}

View File

@ -150,7 +150,7 @@ class UI {
}
public static function dialog(title:String, text:String, flags:haxe.EnumFlags<DialogFlags>) {
@:privateAccess _dialog(title.bytes, text.bytes, flags.toInt());
return @:privateAccess _dialog(title.bytes, text.bytes, flags.toInt()) != 0;
}
@:hlNative("ui", "ui_loop")

View File

@ -86,7 +86,7 @@ class Sys {
return makePath(v);
}
public static function putEnv(s:String, v:String):Void {
public static function putEnv(s:String, v:Null<String>):Void {
if (!put_env(getPath(s), if (v == null) null else getPath(v)))
throw "putEnv() failure";
}

View File

@ -38,12 +38,18 @@ class Type {
static inline function get_allTypes():hl.types.BytesMap
return untyped $allTypes();
@:keep static function init():Void {
@:keep static function init():Bool {
if( allTypes != null )
return false;
untyped $allTypes(new hl.types.BytesMap());
return true;
}
@:keep static function initClass(ct:hl.Type, t:hl.Type, name:hl.Bytes):hl.BaseType.Class@:privateAccess {
var c:hl.BaseType.Class = ct.allocObject();
var c:hl.BaseType.Class = cast t.getGlobal();
if( c != null )
return c;
c = ct.allocObject();
t.setGlobal(c);
c.__type__ = t;
c.__name__ = String.fromUCS2(name);
@ -52,7 +58,10 @@ class Type {
}
@:keep static function initEnum(et:hl.Type, t:hl.Type):hl.BaseType.Enum@:privateAccess {
var e:hl.BaseType.Enum = et.allocObject();
var e:hl.BaseType.Enum = cast t.getGlobal();
if( e != null )
return e;
e = et.allocObject();
e.__type__ = t;
e.__evalues__ = t.getEnumValues();
e.__ename__ = t.getTypeName();
@ -246,6 +255,7 @@ class Type {
}
public static function enumParameters(e:EnumValue):Array<Dynamic> {
if( e == null ) (e:Dynamic)(); // trigger null access
var arr = _enumParameters(e);
return cast hl.types.ArrayObj.alloc(arr);
}

View File

@ -9,7 +9,7 @@ class Exception {
@:noCompletion var __exceptionMessage:String;
@:noCompletion var __exceptionStack:Null<CallStack>;
@:noCompletion var __nativeStack:hl.NativeArray<hl.Bytes>;
@:noCompletion var __nativeStack:hl.NativeArray<#if (hl_ver >= "1.12.0") haxe.NativeStackTrace.Symbol #else hl.Bytes #end>;
@:noCompletion @:ifFeature("haxe.Exception.get_stack") var __skipStack:Int = 0;
@:noCompletion var __nativeException:Any;
@:noCompletion var __previousException:Null<Exception>;
@ -18,7 +18,10 @@ class Exception {
if(Std.isOfType(value, Exception)) {
return value;
} else {
return new ValueException(value, null, value);
var e = new ValueException(value, null, value);
// Undo automatic __shiftStack()
e.__unshiftStack();
return e;
}
}
@ -62,6 +65,12 @@ class Exception {
__skipStack++;
}
@:noCompletion
@:ifFeature("haxe.Exception.get_stack")
inline function __unshiftStack():Void {
__skipStack--;
}
function get_message():String {
return __exceptionMessage;
}

View File

@ -0,0 +1,608 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe;
using haxe.Int64;
#if (hl_ver >= version("1.12.0") && !hl_legacy32)
import haxe.Int64Helper;
private typedef __Int64 = hl.I64;
@:coreApi
@:transitive
abstract Int64(__Int64) from __Int64 to __Int64 {
static var MASK : hl.I64 = {
var v : hl.I64 = 0xFFFF;
v | (v << 16);
}
public static inline function make(high:Int32, low:Int32):Int64 {
var h : hl.I64 = high;
var l : hl.I64 = low;
return cast ((h << 32) | (l&MASK));
}
private inline function new(x:__Int64)
this = x;
private var val(get, set):__Int64;
inline function get_val():__Int64
return this;
inline function set_val(x:__Int64):__Int64
return this = x;
public var high(get, never):Int32;
inline function get_high():Int32
return cast(this >> 32);
public var low(get, never):Int32;
inline function get_low():Int32
return cast this;
public inline function copy():Int64
return new Int64(this);
@:from public static inline function ofInt(x:Int):Int64
return cast x;
@:deprecated('haxe.Int64.is() is deprecated. Use haxe.Int64.isInt64() instead')
inline public static function is(val:Dynamic):Bool
return isInt64(val);
inline public static function isInt64(val:Dynamic):Bool
return hl.Type.getDynamic(val).kind == HI64;
public static inline function toInt(x:Int64):Int {
if (x.val < 0x80000000 || x.val > 0x7FFFFFFF)
throw "Overflow";
return cast x.val;
}
public static inline function getHigh(x:Int64):Int32
return cast(x.val >> 32);
public static inline function getLow(x:Int64):Int32
return cast(x.val);
public static inline function isNeg(x:Int64):Bool
return x.val < 0;
public static inline function isZero(x:Int64):Bool
return x.val == 0;
public static inline function compare(a:Int64, b:Int64):Int {
if (a.val < b.val)
return -1;
if (a.val > b.val)
return 1;
return 0;
}
public static inline function ucompare(a:Int64, b:Int64):Int {
if (a.val < 0)
return (b.val < 0) ? compare(a, b) : 1;
return (b.val < 0) ? -1 : compare(a, b);
}
public static inline function toStr(x:Int64):String
return '${x.val}';
public static inline function divMod(dividend:Int64, divisor:Int64):{quotient:Int64, modulus:Int64}
return {quotient: dividend / divisor, modulus: dividend % divisor};
private inline function toString():String
return '$this';
public static function parseString(sParam:String):Int64 {
// can this be done?: return new Int64( java.lang.Long.LongClass.parseLong( sParam ) );
return Int64Helper.parseString(sParam);
}
public static function fromFloat(f:Float):Int64 {
return Int64Helper.fromFloat(f);
}
@:op(-A) public static function neg(x:Int64):Int64
return -x.val;
@:op(++A) private inline function preIncrement():Int64
return ++this;
@:op(A++) private inline function postIncrement():Int64
return this++;
@:op(--A) private inline function preDecrement():Int64
return --this;
@:op(A--) private inline function postDecrement():Int64
return this--;
@:op(A + B) public static inline function add(a:Int64, b:Int64):Int64
return a.val + b.val;
@:op(A + B) @:commutative private static inline function addInt(a:Int64, b:Int):Int64
return a.val + b;
@:op(A - B) public static inline function sub(a:Int64, b:Int64):Int64
return a.val - b.val;
@:op(A - B) private static inline function subInt(a:Int64, b:Int):Int64
return a.val - b;
@:op(A - B) private static inline function intSub(a:Int, b:Int64):Int64
return (a:hl.I64) - b.val;
@:op(A * B) public static inline function mul(a:Int64, b:Int64):Int64
return a.val * b.val;
@:op(A * B) @:commutative private static inline function mulInt(a:Int64, b:Int):Int64
return a.val * b;
@:op(A / B) public static inline function div(a:Int64, b:Int64):Int64
return a.val / b.val;
@:op(A / B) private static inline function divInt(a:Int64, b:Int):Int64
return a.val / b;
@:op(A / B) private static inline function intDiv(a:Int, b:Int64):Int64
return (a:hl.I64) / b.val;
@:op(A % B) public static inline function mod(a:Int64, b:Int64):Int64
return a.val % b.val;
@:op(A % B) private static inline function modInt(a:Int64, b:Int):Int64
return a.val % b;
@:op(A % B) private static inline function intMod(a:Int, b:Int64):Int64
return (a:hl.I64) % b.val;
@:op(A == B) public static inline function eq(a:Int64, b:Int64):Bool
return a.val == b.val;
@:op(A == B) @:commutative private static inline function eqInt(a:Int64, b:Int):Bool
return a.val == b;
@:op(A != B) public static inline function neq(a:Int64, b:Int64):Bool
return a.val != b.val;
@:op(A != B) @:commutative private static inline function neqInt(a:Int64, b:Int):Bool
return a.val != (b:hl.I64);
@:op(A < B) private static inline function lt(a:Int64, b:Int64):Bool
return a.val < b.val;
@:op(A < B) private static inline function ltInt(a:Int64, b:Int):Bool
return a.val < b;
@:op(A < B) private static inline function intLt(a:Int, b:Int64):Bool
return (a:hl.I64) < b.val;
@:op(A <= B) private static inline function lte(a:Int64, b:Int64):Bool
return a.val <= b.val;
@:op(A <= B) private static inline function lteInt(a:Int64, b:Int):Bool
return a.val <= b;
@:op(A <= B) private static inline function intLte(a:Int, b:Int64):Bool
return (a:hl.I64) <= b.val;
@:op(A > B) private static inline function gt(a:Int64, b:Int64):Bool
return a.val > b.val;
@:op(A > B) private static inline function gtInt(a:Int64, b:Int):Bool
return a.val > b;
@:op(A > B) private static inline function intGt(a:Int, b:Int64):Bool
return (a:hl.I64) > b.val;
@:op(A >= B) private static inline function gte(a:Int64, b:Int64):Bool
return a.val >= b.val;
@:op(A >= B) private static inline function gteInt(a:Int64, b:Int):Bool
return a.val >= b;
@:op(A >= B) private static inline function intGte(a:Int, b:Int64):Bool
return (a:hl.I64) >= b.val;
@:op(~A) private static inline function complement(x:Int64):Int64
return ~x.val;
@:op(A & B) public static inline function and(a:Int64, b:Int64):Int64
return a.val & b.val;
@:op(A | B) public static inline function or(a:Int64, b:Int64):Int64
return a.val | b.val;
@:op(A ^ B) public static inline function xor(a:Int64, b:Int64):Int64
return a.val ^ b.val;
@:op(A << B) public static inline function shl(a:Int64, b:Int):Int64
return a.val << b;
@:op(A >> B) public static inline function shr(a:Int64, b:Int):Int64
return a.val >> b;
@:op(A >>> B) public static inline function ushr(a:Int64, b:Int):Int64
return a.val >>> b;
}
#else
@:transitive
abstract Int64(__Int64) from __Int64 to __Int64 {
private inline function new(x:__Int64)
this = x;
public inline function copy():Int64
return make(high, low);
public static inline function make(high:Int32, low:Int32):Int64
return new Int64(new __Int64(high, low));
@:from public static inline function ofInt(x:Int):Int64
return make(x >> 31, x);
public static inline function toInt(x:Int64):Int {
if (x.high != x.low >> 31)
throw "Overflow";
return x.low;
}
@:deprecated('haxe.Int64.is() is deprecated. Use haxe.Int64.isInt64() instead')
inline public static function is(val:Dynamic):Bool {
return isInt64(val);
}
inline public static function isInt64(val:Dynamic):Bool
return Std.isOfType(val, __Int64);
@:deprecated("Use high instead")
public static inline function getHigh(x:Int64):Int32
return x.high;
@:deprecated("Use low instead")
public static inline function getLow(x:Int64):Int32
return x.low;
public static inline function isNeg(x:Int64):Bool
return x.high < 0;
public static inline function isZero(x:Int64):Bool
return x == 0;
public static inline function compare(a:Int64, b:Int64):Int {
var v = a.high - b.high;
v = if (v != 0) v else Int32.ucompare(a.low, b.low);
return a.high < 0 ? (b.high < 0 ? v : -1) : (b.high >= 0 ? v : 1);
}
public static inline function ucompare(a:Int64, b:Int64):Int {
var v = Int32.ucompare(a.high, b.high);
return if (v != 0) v else Int32.ucompare(a.low, b.low);
}
public static inline function toStr(x:Int64):String
return x.toString();
function toString():String {
var i:Int64 = cast this;
if (i == 0)
return "0";
var str = "";
var neg = false;
if (i.isNeg()) {
neg = true;
// i = -i; cannot negate here as --9223372036854775808 = -9223372036854775808
}
var ten:Int64 = 10;
while (i != 0) {
var r = i.divMod(ten);
if (r.modulus.isNeg()) {
str = Int64.neg(r.modulus).low + str;
i = Int64.neg(r.quotient);
} else {
str = r.modulus.low + str;
i = r.quotient;
}
}
if (neg)
str = "-" + str;
return str;
}
public static inline function parseString(sParam:String):Int64 {
return Int64Helper.parseString(sParam);
}
public static inline function fromFloat(f:Float):Int64 {
return Int64Helper.fromFloat(f);
}
public static function divMod(dividend:Int64, divisor:Int64):{quotient:Int64, modulus:Int64} {
// Handle special cases of 0 and 1
if (divisor.high == 0) {
switch (divisor.low) {
case 0:
throw "divide by zero";
case 1:
return {quotient: dividend.copy(), modulus: 0};
}
}
var divSign = dividend.isNeg() != divisor.isNeg();
var modulus = dividend.isNeg() ? -dividend : dividend.copy();
divisor = divisor.isNeg() ? -divisor : divisor;
var quotient:Int64 = 0;
var mask:Int64 = 1;
while (!divisor.isNeg()) {
var cmp = ucompare(divisor, modulus);
divisor <<= 1;
mask <<= 1;
if (cmp >= 0)
break;
}
while (mask != 0) {
if (ucompare(modulus, divisor) >= 0) {
quotient |= mask;
modulus -= divisor;
}
mask >>>= 1;
divisor >>>= 1;
}
if (divSign)
quotient = -quotient;
if (dividend.isNeg())
modulus = -modulus;
return {
quotient: quotient,
modulus: modulus
};
}
@:op(-A) public static inline function neg(x:Int64):Int64 {
var high = ~x.high;
var low = -x.low;
if (low == 0)
high++;
return make(high, low);
}
@:op(++A) private inline function preIncrement():Int64 {
this = copy();
this.low++;
if (this.low == 0)
this.high++;
return cast this;
}
@:op(A++) private inline function postIncrement():Int64 {
var ret = this;
preIncrement();
return ret;
}
@:op(--A) private inline function preDecrement():Int64 {
this = copy();
if (this.low == 0)
this.high--;
this.low--;
return cast this;
}
@:op(A--) private inline function postDecrement():Int64 {
var ret = this;
preDecrement();
return ret;
}
@:op(A + B) public static inline function add(a:Int64, b:Int64):Int64 {
var high = a.high + b.high;
var low = a.low + b.low;
if (Int32.ucompare(low, a.low) < 0)
high++;
return make(high, low);
}
@:op(A + B) @:commutative private static inline function addInt(a:Int64, b:Int):Int64
return add(a, b);
@:op(A - B) public static inline function sub(a:Int64, b:Int64):Int64 {
var high = a.high - b.high;
var low = a.low - b.low;
if (Int32.ucompare(a.low, b.low) < 0)
high--;
return make(high, low);
}
@:op(A - B) private static inline function subInt(a:Int64, b:Int):Int64
return sub(a, b);
@:op(A - B) private static inline function intSub(a:Int, b:Int64):Int64
return sub(a, b);
@:op(A * B)
public static #if !lua inline #end function mul(a:Int64, b:Int64):Int64 {
var mask = 0xFFFF;
var al = a.low & mask, ah = a.low >>> 16;
var bl = b.low & mask, bh = b.low >>> 16;
var p00 = al * bl;
var p10 = ah * bl;
var p01 = al * bh;
var p11 = ah * bh;
var low = p00;
var high = p11 + (p01 >>> 16) + (p10 >>> 16);
p01 <<= 16;
low += p01;
if (Int32.ucompare(low, p01) < 0)
high++;
p10 <<= 16;
low += p10;
if (Int32.ucompare(low, p10) < 0)
high++;
high += a.low * b.high + a.high * b.low;
return make(high, low);
}
@:op(A * B) @:commutative private static inline function mulInt(a:Int64, b:Int):Int64
return mul(a, b);
@:op(A / B) public static inline function div(a:Int64, b:Int64):Int64
return divMod(a, b).quotient;
@:op(A / B) private static inline function divInt(a:Int64, b:Int):Int64
return div(a, b);
@:op(A / B) private static inline function intDiv(a:Int, b:Int64):Int64
return div(a, b).toInt();
@:op(A % B) public static inline function mod(a:Int64, b:Int64):Int64
return divMod(a, b).modulus;
@:op(A % B) private static inline function modInt(a:Int64, b:Int):Int64
return mod(a, b).toInt();
@:op(A % B) private static inline function intMod(a:Int, b:Int64):Int64
return mod(a, b).toInt();
@:op(A == B) public static inline function eq(a:Int64, b:Int64):Bool
return a.high == b.high && a.low == b.low;
@:op(A == B) @:commutative private static inline function eqInt(a:Int64, b:Int):Bool
return eq(a, b);
@:op(A != B) public static inline function neq(a:Int64, b:Int64):Bool
return a.high != b.high || a.low != b.low;
@:op(A != B) @:commutative private static inline function neqInt(a:Int64, b:Int):Bool
return neq(a, b);
@:op(A < B) private static inline function lt(a:Int64, b:Int64):Bool
return compare(a, b) < 0;
@:op(A < B) private static inline function ltInt(a:Int64, b:Int):Bool
return lt(a, b);
@:op(A < B) private static inline function intLt(a:Int, b:Int64):Bool
return lt(a, b);
@:op(A <= B) private static inline function lte(a:Int64, b:Int64):Bool
return compare(a, b) <= 0;
@:op(A <= B) private static inline function lteInt(a:Int64, b:Int):Bool
return lte(a, b);
@:op(A <= B) private static inline function intLte(a:Int, b:Int64):Bool
return lte(a, b);
@:op(A > B) private static inline function gt(a:Int64, b:Int64):Bool
return compare(a, b) > 0;
@:op(A > B) private static inline function gtInt(a:Int64, b:Int):Bool
return gt(a, b);
@:op(A > B) private static inline function intGt(a:Int, b:Int64):Bool
return gt(a, b);
@:op(A >= B) private static inline function gte(a:Int64, b:Int64):Bool
return compare(a, b) >= 0;
@:op(A >= B) private static inline function gteInt(a:Int64, b:Int):Bool
return gte(a, b);
@:op(A >= B) private static inline function intGte(a:Int, b:Int64):Bool
return gte(a, b);
@:op(~A) private static inline function complement(a:Int64):Int64
return make(~a.high, ~a.low);
@:op(A & B) public static inline function and(a:Int64, b:Int64):Int64
return make(a.high & b.high, a.low & b.low);
@:op(A | B) public static inline function or(a:Int64, b:Int64):Int64
return make(a.high | b.high, a.low | b.low);
@:op(A ^ B) public static inline function xor(a:Int64, b:Int64):Int64
return make(a.high ^ b.high, a.low ^ b.low);
@:op(A << B) public static inline function shl(a:Int64, b:Int):Int64 {
b &= 63;
return if (b == 0) a.copy() else if (b < 32) make((a.high << b) | (a.low >>> (32 - b)), a.low << b) else make(a.low << (b - 32), 0);
}
@:op(A >> B) public static inline function shr(a:Int64, b:Int):Int64 {
b &= 63;
return if (b == 0) a.copy() else if (b < 32) make(a.high >> b, (a.high << (32 - b)) | (a.low >>> b)); else make(a.high >> 31, a.high >> (b - 32));
}
@:op(A >>> B) public static inline function ushr(a:Int64, b:Int):Int64 {
b &= 63;
return if (b == 0) a.copy() else if (b < 32) make(a.high >>> b, (a.high << (32 - b)) | (a.low >>> b)); else make(0, a.high >>> (b - 32));
}
public var high(get, never):Int32;
private inline function get_high()
return this.high;
private inline function set_high(x)
return this.high = x;
public var low(get, never):Int32;
private inline function get_low()
return this.low;
private inline function set_low(x)
return this.low = x;
}
private typedef __Int64 = ___Int64;
private class ___Int64 {
public var high:Int32;
public var low:Int32;
public inline function new(high, low) {
this.high = high;
this.low = low;
}
public function toString():String
return Int64.toStr(cast this);
}
#end

View File

@ -4,6 +4,8 @@ import hl.NativeArray;
import hl.Bytes;
import haxe.CallStack.StackItem;
typedef Symbol = #if (hl_ver >= version("1.12.0")) hl.Abstract<"hl_symbol"> #else hl.Bytes #end
/**
Do not use manually.
**/
@ -14,6 +16,42 @@ class NativeStackTrace {
static public inline function saveStack(exception:Any):Void {
}
#if (hl_ver >= version("1.12.0") )
static public function exceptionStack():NativeArray<Symbol> {
var count = exceptionStackRaw(null);
var arr = new NativeArray(count);
exceptionStackRaw(arr);
return arr;
}
static public inline function callStack():NativeArray<Symbol> {
var count = callStackRaw(null);
var arr = new NativeArray(count);
callStackRaw(arr);
// This will avoid errors when compiling hl/c on unix
// See https://github.com/HaxeFoundation/haxe/pull/11382 for long term fix
if (arr.length == 0) return arr;
return arr.sub(1, arr.length - 1);
}
@:hlNative("std", "exception_stack_raw")
static function exceptionStackRaw( arr : NativeArray<Symbol> ) : Int {
return 0;
}
@:hlNative("std", "call_stack_raw")
static function callStackRaw( arr : NativeArray<Symbol> ) : Int {
return 0;
}
@:hlNative("std","resolve_symbol")
static function resolveSymbol( sym : Symbol, buf : hl.Bytes, bufLen : hl.Ref<Int> ) : hl.Bytes {
return null;
}
#else
@:hlNative("std", "exception_stack")
static public function exceptionStack():NativeArray<Bytes> {
return null;
@ -37,15 +75,26 @@ class NativeStackTrace {
return skip < stack.length ? stack.sub(skip, stack.length - skip) : stack;
}
static public function toHaxe(native:NativeArray<Bytes>, skip:Int = 0):Array<StackItem> {
#end
static public function toHaxe(native:NativeArray<Symbol>, skip:Int=0 ):Array<StackItem> {
var stack = [];
var r = ~/^([A-Za-z0-9.$_]+)\.([~A-Za-z0-9_]+(\.[0-9]+)?)\((.+):([0-9]+)\)$/;
var r_fun = ~/^fun\$([0-9]+)\((.+):([0-9]+)\)$/;
for (i in 0...native.length - 1) {
if(skip > i) {
continue;
}
var str = @:privateAccess String.fromUCS2(native[i]);
#if (hl_ver >= version("1.12.0"))
var maxLen = 1024;
var tmpBuf = @:privateAccess hl.Bytes.alloc(maxLen);
#end
for (i in 0...native.length-1) {
if( i < skip ) continue;
#if (hl_ver >= version("1.12.0"))
var len = maxLen;
var bytes = resolveSymbol(native[i],tmpBuf,len);
if( bytes == null ) continue;
#else
var bytes = native[i];
#end
var str = @:privateAccess String.fromUCS2(bytes);
if (r.match(str))
stack.push(FilePos(Method(r.matched(1), r.matched(2)), r.matched(4), Std.parseInt(r.matched(5))));
else if (r_fun.match(str))

View File

@ -0,0 +1,49 @@
package haxe.atomic;
#if (hl_ver < version("1.13.0") && !doc_gen)
#error "Atomic operations require HL 1.13+"
#end
import hl.Atomics;
abstract AtomicInt(hl.NativeArray<Int>) {
public inline function new(value:Int):Void {
this = new hl.NativeArray(1);
this[0] = value;
}
public inline function add(b:Int):Int {
return Atomics.add32(this.getRef(), b);
}
public inline function sub(b:Int):Int {
return Atomics.sub32(this.getRef(), b);
}
public inline function and(b:Int):Int {
return Atomics.and32(this.getRef(), b);
}
public inline function or(b:Int):Int {
return Atomics.or32(this.getRef(), b);
}
public inline function xor(b:Int):Int {
return Atomics.xor32(this.getRef(), b);
}
public inline function compareExchange(expected:Int, replacement:Int):Int {
return Atomics.compareExchange32(this.getRef(), expected, replacement);
}
public inline function exchange(value:Int):Int {
return Atomics.exchange32(this.getRef(), value);
}
public inline function load():Int {
return Atomics.load32(this.getRef());
}
public inline function store(value:Int):Int {
return Atomics.store32(this.getRef(), value);
}
}

View File

@ -0,0 +1,31 @@
package haxe.atomic;
#if (hl_ver < version("1.13.0") && !doc_gen)
#error "Atomic operations require HL 1.13+"
#end
import hl.Atomics;
// use hl.NativeArray<Dynamic> instead of hl.NativeArray<T>
// so that the compiler doesn't get confused and emit hl.Ref.make(this.getRef())
abstract AtomicObject<T:{}>(hl.NativeArray<Dynamic>) {
public inline function new(value:T):Void {
this = new hl.NativeArray(1);
this[0] = value;
}
public inline function compareExchange(expected:T, replacement:T):T {
return Atomics.compareExchangePtr(this.getRef(), expected, replacement);
}
public inline function exchange(value:T):T {
return Atomics.exchangePtr(this.getRef(), value);
}
public inline function load():T {
return Atomics.loadPtr(this.getRef());
}
public inline function store(value:T):T {
return Atomics.storePtr(this.getRef(), value);
}
}

View File

@ -69,7 +69,7 @@ class IntMap<T> implements haxe.Constraints.IMap<Int, T> {
var s = new StringBuf();
var keys = h.keysArray();
var values = h.valuesArray();
s.addChar('{'.code);
s.addChar("[".code);
for (i in 0...keys.length) {
if (i > 0)
s.add(", ");
@ -77,7 +77,7 @@ class IntMap<T> implements haxe.Constraints.IMap<Int, T> {
s.add(" => ");
s.add(values[i]);
}
s.addChar('}'.code);
s.addChar("]".code);
return s.toString();
}

View File

@ -69,7 +69,7 @@ class ObjectMap<K:{}, T> implements haxe.Constraints.IMap<K, T> {
var s = new StringBuf();
var keys = h.keysArray();
var values = h.valuesArray();
s.addChar('{'.code);
s.addChar("[".code);
for (i in 0...keys.length) {
if (i > 0)
s.add(", ");
@ -77,7 +77,7 @@ class ObjectMap<K:{}, T> implements haxe.Constraints.IMap<K, T> {
s.add(" => ");
s.add(values[i]);
}
s.addChar('}'.code);
s.addChar("]".code);
return s.toString();
}

View File

@ -96,7 +96,7 @@ class StringMap<T> implements haxe.Constraints.IMap<String, T> {
var s = new StringBuf();
var keys = h.keysArray();
var values = h.valuesArray();
s.addChar('{'.code);
s.addChar("[".code);
for (i in 0...keys.length) {
if (i > 0)
s.add(", ");
@ -105,7 +105,7 @@ class StringMap<T> implements haxe.Constraints.IMap<String, T> {
s.add(" => ");
s.add(values[i]);
}
s.addChar('}'.code);
s.addChar("]".code);
return s.toString();
}

View File

@ -26,10 +26,16 @@ private typedef VectorData<T> = Array<T>
@:coreApi
abstract Vector<T>(VectorData<T>) {
public inline function new(length:Int) {
extern overload public inline function new(length:Int) {
this = [];
if (length > 0)
this[length - 1] = cast null;
this[length - 1] = @:nullSafety(Off) cast null;
}
extern overload public inline function new(length:Int, defaultValue:T):Vector<T> {
this = [
for (i in 0...length) defaultValue
];
}
@:op([]) public inline function get(index:Int):T {
@ -46,6 +52,9 @@ abstract Vector<T>(VectorData<T>) {
return this.length;
}
public inline function fill(value:T):Void
for (i in 0...length) this[i] = value;
public static inline function blit<T>(src:Vector<T>, srcPos:Int, dest:Vector<T>, destPos:Int, len:Int):Void {
(cast dest : hl.types.ArrayBase.ArrayAccess).blit(destPos, (cast src : hl.types.ArrayBase.ArrayAccess), srcPos, len);
}

View File

@ -45,11 +45,15 @@ class FPHelper {
public static function doubleToI64(v:Float):Int64 {
helper.setF64(0, v);
#if (hl_ver >= version("1.12.0") && !hl_legacy32)
return Int64.make(helper.getI32(4),helper.getI32(0));
#else
var i64 = i64tmp;
@:privateAccess {
i64.set_low(helper.getI32(0));
i64.set_high(helper.getI32(4));
}
return i64;
#end
}
}

View File

@ -50,7 +50,10 @@ private class SocketInput extends haxe.io.Input {
__s.handshake();
var r = @:privateAccess __s.ssl.recv(buf, pos, len);
if (r == -1)
throw haxe.io.Error.Blocked;
if (@:privateAccess __s.isBlocking)
return 0
else
throw haxe.io.Error.Blocked;
else if (r <= 0)
throw new haxe.io.Eof();
return r;
@ -85,7 +88,10 @@ private class SocketOutput extends haxe.io.Output {
__s.handshake();
var r = @:privateAccess __s.ssl.send(buf, pos, len);
if (r == -1)
throw haxe.io.Error.Blocked;
if (@:privateAccess __s.isBlocking)
return 0
else
throw haxe.io.Error.Blocked;
else if (r < 0)
throw new haxe.io.Eof();
return r;

View File

@ -0,0 +1,50 @@
package sys.thread;
#if doc_gen
@:coreApi extern class Condition {
function new():Void;
public function acquire():Void;
public function tryAcquire():Bool;
public function release():Void;
public function wait():Void;
public function signal():Void;
public function broadcast():Void;
}
#else
abstract Condition(hl.Abstract<"hl_condition">) {
public function new():Void {
this = alloc();
}
@:hlNative("std", "condition_acquire")
public function acquire():Void {}
@:hlNative("std", "condition_try_acquire")
public function tryAcquire():Bool {
return false;
}
@:hlNative("std", "condition_release")
public function release():Void {}
@:hlNative("std", "condition_wait")
public function wait():Void {}
@:hlNative("std", "condition_signal")
public function signal():Void {}
@:hlNative("std", "condition_broadcast")
public function broadcast():Void {}
@:hlNative("std", "condition_alloc")
static function alloc():hl.Abstract<"hl_condition"> {
return null;
}
}
#end

View File

@ -0,0 +1,32 @@
package sys.thread;
#if doc_gen
@:coreApi extern class Semaphore {
function new(value:Int):Void;
function acquire():Void;
function tryAcquire(?timeout:Float):Bool;
function release():Void;
}
#else
abstract Semaphore(hl.Abstract<"hl_semaphore">) {
public function new(value:Int):Void {
this = alloc(value);
}
@:hlNative("std", "semaphore_acquire")
public function acquire():Void {}
@:hlNative("std", "semaphore_release")
public function release():Void {}
@:hlNative("std", "semaphore_try_acquire")
public function tryAcquire(?timeout:Float):Bool {
return false;
}
@:hlNative("std", "semaphore_alloc")
static function alloc(value:Int):hl.Abstract<"hl_semaphore"> {
return null;
}
}
#end

View File

@ -51,6 +51,27 @@ abstract Thread(ThreadImpl) from ThreadImpl {
return HaxeThread.current();
}
public function setName( name : String ) {
#if (hl_ver >= version("1.13.0"))
set_name(@:privateAccess this.handle, @:privateAccess name.toUtf8());
#end
}
public function getName() : Null<String> {
#if (hl_ver >= version("1.13.0"))
var name = get_name(@:privateAccess this.handle);
return name == null ? null : @:privateAccess String.fromUTF8(name);
#else
return null;
#end
}
#if (hl_ver >= version("1.13.0"))
@:hlNative("?std", "thread_set_name") static function set_name( t : ThreadHandle, name : hl.Bytes ) {}
@:hlNative("?std", "thread_get_name") static function get_name( t : ThreadHandle ) : hl.Bytes { return null; }
#end
function get_events():EventLoop {
if(this.events == null)
throw new NoEventLoopException();
@ -66,25 +87,24 @@ abstract Thread(ThreadImpl) from ThreadImpl {
private typedef ThreadHandle = hl.Abstract<"hl_thread">;
private class HaxeThread {
static var mainThreadHandle:ThreadHandle;
static var mainThread:HaxeThread;
static var threads:Array<{thread:HaxeThread, handle:ThreadHandle}>;
static var threads:Array<HaxeThread>;
static var threadsMutex:Mutex;
static var UID = 0;
static function __init__() {
mainThreadHandle = currentHandle();
threadsMutex = new Mutex();
threads = [];
mainThread = new HaxeThread();
mainThread = new HaxeThread(currentHandle());
mainThread.events = new EventLoop();
}
var id = UID++;
public var events(default,null):Null<EventLoop>;
var handle : ThreadHandle;
final messages = new Deque();
static var ids = 0;
var id = ids++;
@:hlNative("std", "thread_create")
static function createHandle(callb:Void->Void):ThreadHandle {
return null;
@ -97,47 +117,49 @@ private class HaxeThread {
static public function current():HaxeThread {
var handle = currentHandle();
if(handle == mainThreadHandle) {
if(handle == mainThread.handle) {
return mainThread;
}
threadsMutex.acquire();
var thread = null;
for(item in threads) {
if(item.handle == handle) {
thread = item.thread;
thread = item;
break;
}
}
if(thread == null) {
thread = new HaxeThread();
threads.push({thread:thread, handle:handle});
thread = new HaxeThread(handle);
threads.push(thread);
}
threadsMutex.release();
return thread;
}
public static function create(callb:()->Void, withEventLoop:Bool):Thread {
var item = {handle:null, thread:new HaxeThread()};
var item = new HaxeThread(null);
threadsMutex.acquire();
threads.push(item);
threadsMutex.release();
if(withEventLoop)
item.thread.events = new EventLoop();
item.events = new EventLoop();
item.handle = createHandle(() -> {
if(item.handle == null) {
item.handle = currentHandle();
}
try {
hl.Api.setErrorHandler(function(_){});
callb();
if(withEventLoop)
item.thread.events.loop();
item.events.loop();
} catch(e) {
hl.Api.setErrorHandler(null);
dropThread(item);
throw e;
hl.Api.rethrow(e);
}
dropThread(item);
});
return item.thread;
return item;
}
public static function runWithEventLoop(job:()->Void):Void {
@ -172,7 +194,9 @@ private class HaxeThread {
return messages.pop(block);
}
public function new() {}
public function new(h) {
handle = h;
}
public function sendMessage(msg:Dynamic) {
messages.add(msg);

View File

@ -1 +1 @@
1.10.0
1.12.0

View File

@ -44,26 +44,6 @@ class BytesIterator<T> extends ArrayIterator<T> {
}
}
@:keep
@:generic
class BytesKeyValueIterator<T> extends ArrayKeyValueIterator<T> {
var a : ArrayBytes<T>;
public function new(a) {
super((null:Dynamic));
this.a = a;
}
override public function hasNext():Bool {
return current < a.length;
}
override public function next():{key:Int, value:T} {
var v = @:privateAccess a.bytes.get(current);
return {key:current++, value:v};
}
}
@:keep
@:generic class ArrayBytes<T> extends ArrayBase {
var bytes:hl.BytesAccess<T>;
@ -98,7 +78,9 @@ class BytesKeyValueIterator<T> extends ArrayKeyValueIterator<T> {
if (length == 0)
return null;
length--;
return bytes[length];
var v = bytes[length];
bytes[length] = cast 0;
return v;
}
public function push(x:T):Int {
@ -126,6 +108,7 @@ class BytesKeyValueIterator<T> extends ArrayKeyValueIterator<T> {
var v = bytes[0];
length--;
(bytes : Bytes).blit(0, bytes, 1 << bytes.sizeBits, length << bytes.sizeBits);
bytes[length] = cast 0;
return v;
}
@ -191,6 +174,7 @@ class BytesKeyValueIterator<T> extends ArrayKeyValueIterator<T> {
ret.size = ret.length = len;
var end = pos + len;
(bytes : Bytes).blit(pos << bytes.sizeBits, bytes, end << bytes.sizeBits, (length - end) << bytes.sizeBits);
(bytes : Bytes).fill((length - len) << bytes.sizeBits, (len) << bytes.sizeBits, 0);
length -= len;
return ret;
}
@ -285,7 +269,7 @@ class BytesKeyValueIterator<T> extends ArrayKeyValueIterator<T> {
}
public function keyValueIterator() : ArrayKeyValueIterator<T> {
return new BytesKeyValueIterator<T>(this);
return new ArrayKeyValueIterator<T>(cast this);
}
public function map<S>(f:T->S):ArrayDyn@:privateAccess {

View File

@ -43,24 +43,6 @@ class ArrayDynIterator extends ArrayIterator<Dynamic> {
}
}
class ArrayDynKeyValueIterator extends ArrayKeyValueIterator<Dynamic> {
var a : ArrayBase;
public function new(a) {
super((null:Dynamic));
this.a = a;
}
override public function hasNext() {
return current < a.length;
}
override public function next() {
var v = a.getDyn(current);
return {key:current++, value:v};
}
}
@:keep
class ArrayDyn extends ArrayAccess {
public var length(get, never):Int;
@ -195,7 +177,7 @@ class ArrayDyn extends ArrayAccess {
}
public function keyValueIterator() : ArrayKeyValueIterator<Dynamic> {
return new ArrayDynKeyValueIterator(array);
return new ArrayKeyValueIterator(cast array);
}
public function map(f:Dynamic->Dynamic):ArrayDyn {

View File

@ -42,24 +42,6 @@ class ArrayObjIterator<T> extends ArrayIterator<T> {
}
}
class ArrayObjKeyValueIterator<T> extends ArrayKeyValueIterator<T> {
var arr:ArrayObj<T>;
public inline function new(arr:ArrayObj<T>) {
super((null:Dynamic));
this.arr = arr;
}
override public function hasNext():Bool {
return current < arr.length;
}
override public function next():{key:Int, value:T} {
var v = @:privateAccess arr.array[current];
return {key:current++, value:v};
}
}
@:keep
class ArrayObj<T> extends ArrayBase {
var array:hl.NativeArray<Dynamic>;
@ -291,7 +273,7 @@ class ArrayObj<T> extends ArrayBase {
}
public function keyValueIterator():ArrayKeyValueIterator<T> {
return new ArrayObjKeyValueIterator<T>(this);
return new ArrayKeyValueIterator<T>(cast this);
}
public function map<S>(f:T->S):ArrayDyn {
@ -317,7 +299,7 @@ class ArrayObj<T> extends ArrayBase {
if (length < len) {
__expand(len - 1);
} else if (length > len) {
for (i in length...len) {
for (i in len...length) {
array[i] = null;
}
this.length = len;

View File

@ -0,0 +1,74 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package hl.types;
#if (hl_ver >= version("1.13.0") && !hl_legacy32)
typedef Int64MapData = Abstract<"hl_int64_map">;
abstract Int64Map(Int64MapData) {
extern public inline function new() {
this = alloc();
}
@:hlNative("std", "hi64alloc") static function alloc():Int64MapData {
return null;
}
@:hlNative("std", "hi64set")
public function set(key:haxe.Int64, value:Dynamic) {}
@:hlNative("std", "hi64exists")
public function exists(key:haxe.Int64):Bool {
return false;
}
@:hlNative("std", "hi64get")
public function get(key:haxe.Int64):Dynamic {
return null;
}
@:hlNative("std", "hi64remove")
public function remove(key:haxe.Int64):Bool {
return false;
}
@:hlNative("std", "hi64keys")
public function keysArray():NativeArray<haxe.Int64> {
return null;
}
@:hlNative("std", "hi64values")
public function valuesArray():NativeArray<Dynamic> {
return null;
}
@:hlNative("std", "hi64clear")
public function clear():Void {}
extern public inline function iterator() {
return new NativeArray.NativeArrayIterator<Dynamic>(valuesArray());
}
}
#end

View File

@ -0,0 +1,51 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package hl.uv;
enum abstract Event(Int) {
var Rename = 1;
var Change = 2;
}
@:hlNative("uv")
class Fs extends Handle {
public function new(?loop : Loop, path : String, onContentChanged : Event -> Void) {
if(loop == null)
loop = Loop.getDefault();
super(fs_start_wrap(loop, (e) -> onContentChanged(cast(e, Event)), @:privateAccess path.toUtf8()));
}
public function stop() {
if(handle == null)
return;
fs_stop_wrap(handle);
}
static function fs_start_wrap(loop:Loop, cb : Int -> Void, path : hl.Bytes) : HandleData {
return null;
}
static function fs_stop_wrap(handle:HandleData) : Bool {
return false;
}
}