forked from LeenkxTeam/LNXSDK
Update
This commit is contained in:
@ -23,6 +23,8 @@
|
||||
import cs.Boot;
|
||||
import cs.Lib;
|
||||
|
||||
using StringTools;
|
||||
|
||||
@:coreApi @:nativeGen class Std {
|
||||
@:deprecated('Std.is is deprecated. Use Std.isOfType instead.')
|
||||
public static inline function is(v:Dynamic, t:Dynamic):Bool {
|
||||
@ -79,54 +81,74 @@ import cs.Lib;
|
||||
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)
|
||||
return null;
|
||||
|
||||
var base = 10;
|
||||
var len = x.length;
|
||||
var foundCount = 0;
|
||||
var sign = 0;
|
||||
var firstDigitIndex = 0;
|
||||
var lastDigitIndex = -1;
|
||||
var previous = 0;
|
||||
final len = x.length;
|
||||
var index = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
if((foundCount == 0 && sign == 0) || (foundCount == 1 && sign != 0)) {
|
||||
firstDigitIndex = i;
|
||||
}
|
||||
foundCount++;
|
||||
lastDigitIndex = i;
|
||||
previous = c;
|
||||
inline function hasIndex(index:Int)
|
||||
return index < len;
|
||||
|
||||
// skip whitespace
|
||||
while (hasIndex(index)) {
|
||||
if (!isSpaceChar(x.unsafeCodeAt(index)))
|
||||
break;
|
||||
++index;
|
||||
}
|
||||
if(firstDigitIndex <= lastDigitIndex) {
|
||||
var digits = x.substring(firstDigitIndex, lastDigitIndex + 1);
|
||||
return try {
|
||||
(sign == -1 ? -1 : 1) * cs.system.Convert.ToInt32(digits, base);
|
||||
} catch(e:cs.system.FormatException) {
|
||||
null;
|
||||
|
||||
// handle sign
|
||||
final isNegative = hasIndex(index) && {
|
||||
final sign = x.unsafeCodeAt(index);
|
||||
if (sign == '-'.code || sign == '+'.code) {
|
||||
++index;
|
||||
}
|
||||
sign == '-'.code;
|
||||
}
|
||||
return null;
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
cur;
|
||||
}
|
||||
|
||||
// no valid digits
|
||||
if (index == firstInvalidIndex)
|
||||
return null;
|
||||
|
||||
final result = cs.system.Convert.ToInt32(x.substring(index, firstInvalidIndex), if (isHexadecimal) 16 else 10);
|
||||
return if (isNegative) -result else result;
|
||||
}
|
||||
|
||||
public static function parseFloat(x:String):Float {
|
||||
|
||||
@ -26,7 +26,6 @@ import cs.system.threading.Thread;
|
||||
|
||||
@:coreApi
|
||||
class Sys {
|
||||
private static var _env:haxe.ds.StringMap<String>;
|
||||
private static var _args:Array<String>;
|
||||
|
||||
public static inline function print(v:Dynamic):Void {
|
||||
@ -50,22 +49,17 @@ class Sys {
|
||||
return Environment.GetEnvironmentVariable(s);
|
||||
}
|
||||
|
||||
public static function putEnv(s:String, v:String):Void {
|
||||
public static function putEnv(s:String, v:Null<String>):Void {
|
||||
Environment.SetEnvironmentVariable(s, v);
|
||||
if (_env != null)
|
||||
_env.set(s, v);
|
||||
}
|
||||
|
||||
public static function environment():Map<String, String> {
|
||||
if (_env == null) {
|
||||
var e = _env = new haxe.ds.StringMap();
|
||||
var nenv = Environment.GetEnvironmentVariables().GetEnumerator();
|
||||
while (nenv.MoveNext()) {
|
||||
e.set(nenv.Key, nenv.Value);
|
||||
}
|
||||
final env = new haxe.ds.StringMap();
|
||||
final nenv = Environment.GetEnvironmentVariables().GetEnumerator();
|
||||
while (nenv.MoveNext()) {
|
||||
env.set(nenv.Key, nenv.Value);
|
||||
}
|
||||
|
||||
return _env;
|
||||
return env;
|
||||
}
|
||||
|
||||
public static inline function sleep(seconds:Float):Void {
|
||||
@ -78,7 +72,7 @@ class Sys {
|
||||
}
|
||||
|
||||
public static inline function getCwd():String {
|
||||
return cs.system.io.Directory.GetCurrentDirectory();
|
||||
return haxe.io.Path.addTrailingSlash(cs.system.io.Directory.GetCurrentDirectory());
|
||||
}
|
||||
|
||||
public static inline function setCwd(s:String):Void {
|
||||
|
||||
@ -1,20 +1,26 @@
|
||||
package haxe;
|
||||
|
||||
import haxe.iterators.RestIterator;
|
||||
import haxe.iterators.RestKeyValueIterator;
|
||||
import cs.NativeArray;
|
||||
import cs.system.Array as CsArray;
|
||||
import haxe.iterators.RestIterator;
|
||||
import haxe.iterators.RestKeyValueIterator;
|
||||
|
||||
private typedef NativeRest<T> = #if erase_generics NativeArray<Dynamic> #else NativeArray<T> #end;
|
||||
|
||||
@:coreApi
|
||||
abstract Rest<T>(NativeRest<T>) {
|
||||
public var length(get,never):Int;
|
||||
public var length(get, never):Int;
|
||||
|
||||
inline function get_length():Int
|
||||
return this.Length;
|
||||
|
||||
@:from static public inline function of<T>(array:Array<T>):Rest<T>
|
||||
#if erase_generics
|
||||
// This is wrong but so is everything else in my life
|
||||
return new Rest(@:privateAccess array.__a);
|
||||
#else
|
||||
return new Rest(cs.Lib.nativeArray(array, false));
|
||||
#end
|
||||
|
||||
inline function new(a:NativeRest<T>):Void
|
||||
this = a;
|
||||
@ -51,4 +57,4 @@ abstract Rest<T>(NativeRest<T>) {
|
||||
public function toString():String {
|
||||
return toArray().toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
61
Kha/Tools/windows_x64/std/cs/_std/haxe/atomic/AtomicInt.hx
Normal file
61
Kha/Tools/windows_x64/std/cs/_std/haxe/atomic/AtomicInt.hx
Normal file
@ -0,0 +1,61 @@
|
||||
package haxe.atomic;
|
||||
|
||||
private class IntWrapper {
|
||||
public var value:Int;
|
||||
|
||||
public function new(value:Int) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
abstract AtomicInt(IntWrapper) {
|
||||
public inline function new(value:Int) {
|
||||
this = new IntWrapper(value);
|
||||
}
|
||||
|
||||
private inline function cas_loop(value:Int, op:(a:Int, b:Int) -> Int):Int {
|
||||
var oldValue;
|
||||
var newValue;
|
||||
do {
|
||||
oldValue = load();
|
||||
newValue = op(oldValue, value);
|
||||
} while(compareExchange(oldValue, newValue) != oldValue);
|
||||
return oldValue;
|
||||
}
|
||||
|
||||
public inline function add(b:Int):Int {
|
||||
return cas_loop(b, (a, b) -> a + b);
|
||||
}
|
||||
|
||||
public inline function sub(b:Int):Int {
|
||||
return cas_loop(b, (a, b) -> a - b);
|
||||
}
|
||||
|
||||
public inline function and(b:Int):Int {
|
||||
return cas_loop(b, (a, b) -> cast a & b);
|
||||
}
|
||||
|
||||
public inline function or(b:Int):Int {
|
||||
return cas_loop(b, (a, b) -> cast a | b);
|
||||
}
|
||||
|
||||
public inline function xor(b:Int):Int {
|
||||
return cas_loop(b, (a, b) -> cast a ^ b);
|
||||
}
|
||||
|
||||
public inline function compareExchange(expected:Int, replacement:Int):Int {
|
||||
return cs.Syntax.code("System.Threading.Interlocked.CompareExchange(ref ({0}).value, {1}, {2})", this, replacement, expected);
|
||||
}
|
||||
|
||||
public inline function exchange(value:Int):Int {
|
||||
return cs.Syntax.code("System.Threading.Interlocked.Exchange(ref ({0}).value, {1})", this, value);
|
||||
}
|
||||
|
||||
public inline function load():Int {
|
||||
return this.value; // according to the CLI spec reads and writes are atomic
|
||||
}
|
||||
|
||||
public inline function store(value:Int):Int {
|
||||
return this.value = value; // according to the CLI spec reads and writes are atomic
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package haxe.atomic;
|
||||
|
||||
import cs.system.threading.Interlocked.*;
|
||||
|
||||
private class ObjectWrapper<T:{}> {
|
||||
public var value:T;
|
||||
|
||||
public function new(value:T) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
extern abstract AtomicObject<T:{}>(ObjectWrapper<T>) {
|
||||
public inline function new(value:T) {
|
||||
this = new ObjectWrapper(value);
|
||||
}
|
||||
|
||||
public inline function compareExchange(expected:T, replacement:T):T {
|
||||
return cs.Syntax.code("System.Threading.Interlocked.CompareExchange(ref ({0}).value, {1}, {2})", this, replacement, expected);
|
||||
}
|
||||
|
||||
public inline function exchange(value:T):T {
|
||||
return cs.Syntax.code("System.Threading.Interlocked.Exchange(ref ({0}).value, {1})", this, value);
|
||||
}
|
||||
|
||||
public inline function load():T {
|
||||
return this.value; // according to the CLI spec reads and writes are atomic
|
||||
}
|
||||
|
||||
public inline function store(value:T):T {
|
||||
return this.value = value; // according to the CLI spec reads and writes are atomic
|
||||
}
|
||||
}
|
||||
@ -364,7 +364,7 @@ import cs.NativeArray;
|
||||
|
||||
public function toString():String {
|
||||
var s = new StringBuf();
|
||||
s.add("{");
|
||||
s.add("[");
|
||||
var it = keys();
|
||||
for (i in it) {
|
||||
s.add(i);
|
||||
@ -373,7 +373,7 @@ import cs.NativeArray;
|
||||
if (it.hasNext())
|
||||
s.add(", ");
|
||||
}
|
||||
s.add("}");
|
||||
s.add("]");
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
|
||||
@ -378,7 +378,7 @@ import cs.NativeArray;
|
||||
|
||||
public function toString():String {
|
||||
var s = new StringBuf();
|
||||
s.add("{");
|
||||
s.add("[");
|
||||
var it = keys();
|
||||
for (i in it) {
|
||||
s.add(Std.string(i));
|
||||
@ -387,7 +387,7 @@ import cs.NativeArray;
|
||||
if (it.hasNext())
|
||||
s.add(", ");
|
||||
}
|
||||
s.add("}");
|
||||
s.add("]");
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
|
||||
@ -377,7 +377,7 @@ import cs.NativeArray;
|
||||
|
||||
public function toString():String {
|
||||
var s = new StringBuf();
|
||||
s.add("{");
|
||||
s.add("[");
|
||||
var it = keys();
|
||||
for (i in it) {
|
||||
s.add(i);
|
||||
@ -386,7 +386,7 @@ import cs.NativeArray;
|
||||
if (it.hasNext())
|
||||
s.add(", ");
|
||||
}
|
||||
s.add("}");
|
||||
s.add("]");
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
|
||||
37
Kha/Tools/windows_x64/std/cs/_std/sys/thread/Condition.hx
Normal file
37
Kha/Tools/windows_x64/std/cs/_std/sys/thread/Condition.hx
Normal file
@ -0,0 +1,37 @@
|
||||
package sys.thread;
|
||||
|
||||
import cs.system.threading.Monitor;
|
||||
|
||||
@:coreApi
|
||||
@:access(sys.thread.Mutex)
|
||||
class Condition {
|
||||
final object:cs.system.Object;
|
||||
|
||||
public function new():Void {
|
||||
this.object = new cs.system.Object();
|
||||
}
|
||||
|
||||
public function acquire():Void {
|
||||
Monitor.Enter(object);
|
||||
}
|
||||
|
||||
public function tryAcquire():Bool {
|
||||
return Monitor.TryEnter(object);
|
||||
}
|
||||
|
||||
public function release():Void {
|
||||
Monitor.Exit(object);
|
||||
}
|
||||
|
||||
public function wait():Void {
|
||||
Monitor.Wait(object);
|
||||
}
|
||||
|
||||
public function signal():Void {
|
||||
Monitor.Pulse(object);
|
||||
}
|
||||
|
||||
public function broadcast():Void {
|
||||
Monitor.PulseAll(object);
|
||||
}
|
||||
}
|
||||
22
Kha/Tools/windows_x64/std/cs/_std/sys/thread/Semaphore.hx
Normal file
22
Kha/Tools/windows_x64/std/cs/_std/sys/thread/Semaphore.hx
Normal file
@ -0,0 +1,22 @@
|
||||
package sys.thread;
|
||||
|
||||
@:coreApi
|
||||
class Semaphore {
|
||||
final native:cs.system.threading.Semaphore;
|
||||
|
||||
public function new(value:Int):Void {
|
||||
this.native = new cs.system.threading.Semaphore(value, 0x7FFFFFFF);
|
||||
}
|
||||
|
||||
public function acquire():Void {
|
||||
native.WaitOne();
|
||||
}
|
||||
|
||||
public function tryAcquire(?timeout:Float):Bool {
|
||||
return native.WaitOne(timeout == null ? 0 : Std.int(timeout * 1000));
|
||||
}
|
||||
|
||||
public function release():Void {
|
||||
native.Release();
|
||||
}
|
||||
}
|
||||
@ -230,7 +230,7 @@ class DynamicObject extends HxObject {
|
||||
if (ts != null)
|
||||
return ts();
|
||||
var ret = new StringBuf();
|
||||
ret.add("{");
|
||||
ret.add("[");
|
||||
var first = true;
|
||||
for (f in Reflect.fields(this)) {
|
||||
if (first)
|
||||
@ -244,7 +244,7 @@ class DynamicObject extends HxObject {
|
||||
}
|
||||
if (!first)
|
||||
ret.add(" ");
|
||||
ret.add("}");
|
||||
ret.add("]");
|
||||
return ret.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user