diff --git a/src/codegen/swfLoader.ml b/src/codegen/swfLoader.ml index 73be17a7c9a..2915dde5481 100644 --- a/src/codegen/swfLoader.ml +++ b/src/codegen/swfLoader.ml @@ -60,7 +60,7 @@ let rec make_tpath x = let pack, name = match pack, name with | [], "void" -> [], "Void" | [], "int" -> [], "Int" - | [], "uint" -> [], "UInt" + | [], "uint" -> ["haxe"], "UInt32" | [], "Number" -> [], "Float" | [], "Boolean" -> [], "Bool" | [], "Object" -> ["flash";"utils"], "Object" @@ -399,8 +399,10 @@ let build_class com c file = | [] -> [] | f :: l -> match f.cff_kind with - | FVar (Some ((CTPath {path = { tpackage = []; tname = ("String" | "Int" | "UInt")}} as real_t),_),None) - | FProp (("default",_),("never",_),Some ((CTPath { path = { tpackage = []; tname = ("String" | "Int" | "UInt")}}) as real_t,_),None) when List.mem_assoc AStatic f.cff_access -> + | FVar (Some ((CTPath {path = { tpackage = []; tname = ("String" | "Int")}} as real_t),_),None) + | FVar (Some ((CTPath {path = { tpackage = ["haxe"]; tname = "UInt32"}} as real_t),_),None) + | FProp (("default",_),("never",_),Some ((CTPath { path = { tpackage = ["haxe"]; tname = "UInt32"}}) as real_t,_),None) + | FProp (("default",_),("never",_),Some ((CTPath { path = { tpackage = []; tname = ("String" | "Int")}}) as real_t,_),None) when List.mem_assoc AStatic f.cff_access -> (match !real_type with | None -> real_type := Some real_t @@ -463,6 +465,7 @@ let extract_data (_,tags) = let path = (make_tpath f.hlf_name).path in (match path with | { tpackage = []; tname = "Float" | "Bool" | "Int" | "UInt" | "Dynamic" } -> () + | { tpackage = ["haxe"]; tname = "UInt32" } -> () | { tpackage = _; tname = "MethodClosure" } -> () | _ -> Hashtbl.add h (path.tpackage,path.tname) c) | _ -> () diff --git a/src/generators/genhl.ml b/src/generators/genhl.ml index 10b15f5610c..b8397807652 100644 --- a/src/generators/genhl.ml +++ b/src/generators/genhl.ml @@ -314,7 +314,7 @@ let member_fun c t = let rec unsigned t = match follow t with - | TAbstract ({ a_path = [],"UInt" },_) -> true + | TAbstract ({ a_path = ["haxe"],"UInt32" },_) -> true | TAbstract (a,pl) -> unsigned (Abstract.get_underlying_type a pl) | _ -> false @@ -462,7 +462,7 @@ let rec to_type ?tref ctx t = if Meta.has Meta.CoreType a.a_meta then (match a.a_path with | [], "Void" -> HVoid - | [], "Int" | [], "UInt" -> HI32 + | [], "Int" | ["haxe"], "UInt32" -> HI32 | [], "Float" -> HF64 | [], "Single" -> HF32 | [], "Bool" -> HBool diff --git a/src/generators/genhxold.ml b/src/generators/genhxold.ml index 5f8660319f6..a76acc0bc06 100644 --- a/src/generators/genhxold.ml +++ b/src/generators/genhxold.ml @@ -135,7 +135,8 @@ let generate_type com t = else (* we have not found a default value stored in metadata, let's generate it *) n ^ " : " ^ stype t ^ " = " ^ (match follow t with - | TAbstract ({ a_path = [],("Int"|"Float"|"UInt") },_) -> "0" + | TAbstract ({ a_path = [],("Int"|"Float"|"UInt") },_) + | TAbstract ({ a_path = ["haxe"],"UInt32" },_) -> "0" | TAbstract ({ a_path = [],"Bool" },_) -> "false" | _ -> "null") | Some v -> diff --git a/src/generators/genpy.ml b/src/generators/genpy.ml index cc8ccc545d9..ac09ec43dbb 100644 --- a/src/generators/genpy.ml +++ b/src/generators/genpy.ml @@ -2211,6 +2211,7 @@ module Generator = struct | TClassDecl c -> gen_class ctx c | TEnumDecl en when not (has_enum_flag en EnExtern) -> gen_enum ctx en | TAbstractDecl {a_path = [],"UInt"} -> () + | TAbstractDecl {a_path = ["haxe"],"UInt32"} -> () | TAbstractDecl {a_path = [],"Enum"} -> () | TAbstractDecl {a_path = [],"EnumValue"} when not (has_feature ctx "has_enum") -> () | TAbstractDecl {a_path = [],"Void"} -> () diff --git a/src/generators/genswf9.ml b/src/generators/genswf9.ml index 6cfe45c5092..b3d1a5d420d 100644 --- a/src/generators/genswf9.ml +++ b/src/generators/genswf9.ml @@ -180,6 +180,7 @@ let jump_back ctx = let real_path = function | [] , "Int" -> [] , "int" | [] , "UInt" -> [] , "uint" + | ["haxe"] , "UInt32" -> [] , "uint" | [] , "Float" -> [] , "Number" | [] , "Bool" -> [] , "Boolean" | [] , "Enum" -> [] , "Class" @@ -213,12 +214,11 @@ let rec follow_basic t = | TFun _ | TAbstract ({ a_path = ([],"Int") },[]) | TAbstract ({ a_path = ([],"Float") },[]) - | TAbstract ({ a_path = [],"UInt" },[]) + | TAbstract ({ a_path = ["haxe"],"UInt32" },[]) | TAbstract ({ a_path = ([],"Bool") },[]) | TInst ({ cl_path = (["haxe"],"Int32") },[]) -> t | t -> t) - | TType ({ t_path = ["flash";"utils"],"Function" },[]) - | TType ({ t_path = [],"UInt" },[]) -> + | TType ({ t_path = ["flash";"utils"],"Function" },[]) -> t | TType (t,tl) -> follow_basic (apply_typedef t tl) @@ -253,7 +253,7 @@ let rec type_id ctx t = type_path ctx a.a_path | TFun _ | TType ({ t_path = ["flash";"utils"],"Function" },[]) -> type_path ctx ([],"Function") - | TType ({ t_path = ([],"UInt") as path },_) -> + | TAbstract ({ a_path = (["haxe"],"UInt32") as path },_) -> type_path ctx path | TEnum ({ e_path = ["flash"],"XmlType" } as e,_) when has_enum_flag e EnExtern -> HMPath ([],"String") @@ -288,7 +288,7 @@ let classify ctx t = KType (HMPath ([],"String")) | TEnum (e,_) -> KType (type_id ctx t) - | TAbstract ({ a_path = [],"UInt" },_) | TType ({ t_path = [],"UInt" },_) -> + | TAbstract ({ a_path = ["haxe"],"UInt32" },_) | TType ({ t_path = [],"UInt" },_) -> KUInt | TFun _ | TType ({ t_path = ["flash";"utils"],"Function" },[]) -> KType (HMPath ([],"Function")) diff --git a/src/typing/typer.ml b/src/typing/typer.ml index 38ddef5dc96..8c446e662f0 100644 --- a/src/typing/typer.ml +++ b/src/typing/typer.ml @@ -1774,7 +1774,7 @@ and type_expr ?(mode=MGet) ctx (e,p) (with_type:WithType.t) = let call = ECall (field, [ arg_high; arg_low ]), p in type_expr ctx call with_type | "u32" -> - let check = ECheckType ((EConst (Int (s, None)), p), (make_ptp_th (mk_type_path ([],"UInt")) p)), p in + let check = ECheckType ((EConst (Int (s, None)), p), (make_ptp_th (mk_type_path (["haxe"],"UInt32")) p)), p in type_expr ctx check with_type | other -> raise_typing_error (other ^ " is not a valid integer suffix") p) | EConst (Float (s, Some suffix) as c) -> diff --git a/std/UInt.hx b/std/UInt.hx index 862fd74d8b5..aac58c5bb83 100644 --- a/std/UInt.hx +++ b/std/UInt.hx @@ -19,303 +19,12 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ -#if ((flash || flash9doc || hl) && !doc_gen) -/** - The unsigned `Int` type is only defined for Flash. It's currently - handled the same as a normal Int. - - @see https://haxe.org/manual/types-basic-types.html -**/ -@:coreType -@:notNull -@:runtimeValue -@:analyzer(no_const_propagation) -abstract UInt to Int from Int { - @:commutative @:op(A + B) private static function addI(lhs:UInt, rhs:Int):UInt; - - @:commutative @:op(A + B) private static function addF(lhs:UInt, rhs:Float):Float; - - @:op(A + B) private static function add(lhs:UInt, rhs:UInt):UInt; - - @:commutative @:op(A * B) private static function mulI(lhs:UInt, rhs:Int):UInt; - - @:commutative @:op(A * B) private static function mulF(lhs:UInt, rhs:Float):Float; - - @:op(A * B) private static function mul(lhs:UInt, rhs:UInt):UInt; - - @:op(A % B) private static function modI(lhs:UInt, rhs:Int):UInt; - - @:op(A % B) private static function modF(lhs:UInt, rhs:Float):Float; - - @:op(A % B) private static function mod(lhs:UInt, rhs:UInt):UInt; - - @:op(A - B) private static function subI(lhs:UInt, rhs:Int):UInt; - - @:op(A - B) private static function subF(lhs:UInt, rhs:Float):Float; - - @:op(A - B) private static function sub(lhs:UInt, rhs:UInt):UInt; - - @:op(A / B) private static function divI(lhs:UInt, rhs:Int):Float; - - @:op(A / B) private static function divF(lhs:UInt, rhs:Float):Float; - - @:op(A / B) private static function div(lhs:UInt, rhs:UInt):Float; - - @:commutative @:op(A | B) private static function orI(lhs:UInt, rhs:Int):UInt; - - @:op(A | B) private static function or(lhs:UInt, rhs:UInt):UInt; - - @:commutative @:op(A ^ B) private static function xorI(lhs:UInt, rhs:Int):UInt; - - @:op(A ^ B) private static function xor(lhs:UInt, rhs:UInt):UInt; - - @:commutative @:op(A & B) private static function andI(lhs:UInt, rhs:Int):UInt; - - @:op(A & B) private static function and(lhs:UInt, rhs:UInt):UInt; - - @:op(A << B) private static function shl(lhs:UInt, rhs:Int):UInt; - - @:op(A >> B) private static inline function shr(lhs:UInt, rhs:Int):UInt - return lhs >>> rhs; - - @:op(A >>> B) private static function ushr(lhs:UInt, rhs:Int):UInt; - - @:op(A > B) private static function gt(lhs:UInt, rhs:UInt):Bool; - - @:op(A >= B) private static function gte(lhs:UInt, rhs:UInt):Bool; - - @:op(A < B) private static function lt(lhs:UInt, rhs:UInt):Bool; - - @:op(A <= B) private static function lte(lhs:UInt, rhs:UInt):Bool; - - @:op(A > B) private static function gtf(lhs:UInt, rhs:Float):Bool; - - @:op(A > B) private static function gtf2(lhs:Float, rhs:UInt):Bool; - - @:op(A >= B) private static function gtef(lhs:UInt, rhs:Float):Bool; - - @:op(A >= B) private static function gtef2(lhs:Float, rhs:UInt):Bool; - - @:op(A < B) private static function ltf(lhs:UInt, rhs:Float):Bool; - - @:op(A < B) private static function ltf2(lhs:Float, rhs:UInt):Bool; - - @:op(A <= B) private static function ltef(lhs:UInt, rhs:Float):Bool; - - @:op(A <= B) private static function ltef2(lhs:Float, rhs:UInt):Bool; - - @:op(~A) private static function bneg(t:UInt):UInt; - - @:commutative @:op(A == B) private static function equalsInt(a:UInt, b:T):Bool; - - @:commutative @:op(A != B) private static function notEqualsInt(a:UInt, b:T):Bool; - - @:commutative @:op(A == B) private static function equalsFloat(a:UInt, b:T):Bool; - - @:commutative @:op(A != B) private static function notEqualsFloat(a:UInt, b:T):Bool; - - @:op(++A) private function prefixIncrement():UInt; - - @:op(A++) private function postfixIncrement():UInt; - - @:op(--A) private function prefixDecrement():UInt; - - @:op(A--) private function postfixDecrement():UInt; -} -#else /** - The unsigned `Int` type is only defined for Flash. - Simulate it for other platforms. + A cross-platform unsigned 32-bit integer. @see https://haxe.org/manual/types-basic-types.html + @deprecated Use `haxe.UInt32` instead. **/ -@:transitive -abstract UInt(Int) from Int to Int { - @:op(A + B) private static inline function add(a:UInt, b:UInt):UInt { - return a.toInt() + b.toInt(); - } - - @:op(A / B) private static inline function div(a:UInt, b:UInt):Float { - return a.toFloat() / b.toFloat(); - } - - @:op(A * B) private static inline function mul(a:UInt, b:UInt):UInt { - return a.toInt() * b.toInt(); - } - - @:op(A - B) private static inline function sub(a:UInt, b:UInt):UInt { - return a.toInt() - b.toInt(); - } - - @:op(A > B) - private static #if !js inline #end function gt(a:UInt, b:UInt):Bool { - var aNeg = a.toInt() < 0; - var bNeg = b.toInt() < 0; - return if (aNeg != bNeg) aNeg; else a.toInt() > b.toInt(); - } - - @:op(A >= B) - private static #if !js inline #end function gte(a:UInt, b:UInt):Bool { - var aNeg = a.toInt() < 0; - var bNeg = b.toInt() < 0; - return if (aNeg != bNeg) aNeg; else a.toInt() >= b.toInt(); - } - - @:op(A < B) private static inline function lt(a:UInt, b:UInt):Bool { - return gt(b, a); - } - - @:op(A <= B) private static inline function lte(a:UInt, b:UInt):Bool { - return gte(b, a); - } - - @:op(A & B) private static inline function and(a:UInt, b:UInt):UInt { - return a.toInt() & b.toInt(); - } - - @:op(A | B) private static inline function or(a:UInt, b:UInt):UInt { - return a.toInt() | b.toInt(); - } - - @:op(A ^ B) private static inline function xor(a:UInt, b:UInt):UInt { - return a.toInt() ^ b.toInt(); - } - - @:op(A << B) private static inline function shl(a:UInt, b:Int):UInt { - return a.toInt() << b; - } - - @:op(A >> B) private static inline function shr(a:UInt, b:Int):UInt { - return a.toInt() >>> b; - } - - @:op(A >>> B) private static inline function ushr(a:UInt, b:Int):UInt { - return a.toInt() >>> b; - } - - @:op(A % B) private static inline function mod(a:UInt, b:UInt):UInt { - return Std.int(a.toFloat() % b.toFloat()); - } - - @:commutative @:op(A + B) private static inline function addWithFloat(a:UInt, b:Float):Float { - return a.toFloat() + b; - } - - @:commutative @:op(A * B) private static inline function mulWithFloat(a:UInt, b:Float):Float { - return a.toFloat() * b; - } - - @:op(A / B) private static inline function divFloat(a:UInt, b:Float):Float { - return a.toFloat() / b; - } - - @:op(A / B) private static inline function floatDiv(a:Float, b:UInt):Float { - return a / b.toFloat(); - } - - @:op(A - B) private static inline function subFloat(a:UInt, b:Float):Float { - return a.toFloat() - b; - } - - @:op(A - B) private static inline function floatSub(a:Float, b:UInt):Float { - return a - b.toFloat(); - } - - @:op(A > B) private static inline function gtFloat(a:UInt, b:Float):Bool { - return a.toFloat() > b; - } - - @:commutative @:op(A == B) private static inline function equalsInt(a:UInt, b:T):Bool { - return a.toInt() == b; - } - - @:commutative @:op(A != B) private static inline function notEqualsInt(a:UInt, b:T):Bool { - return a.toInt() != b; - } - - @:commutative @:op(A == B) private static inline function equalsFloat(a:UInt, b:T):Bool { - return a.toFloat() == b; - } - - @:commutative @:op(A != B) private static inline function notEqualsFloat(a:UInt, b:T):Bool { - return a.toFloat() != b; - } - - @:op(A >= B) private static inline function gteFloat(a:UInt, b:Float):Bool { - return a.toFloat() >= b; - } - - @:op(A > B) private static inline function floatGt(a:Float, b:UInt):Bool { - return a > b.toFloat(); - } - - @:op(A >= B) private static inline function floatGte(a:Float, b:UInt):Bool { - return a >= b.toFloat(); - } - - @:op(A < B) private static inline function ltFloat(a:UInt, b:Float):Bool { - return a.toFloat() < b; - } - - @:op(A <= B) private static inline function lteFloat(a:UInt, b:Float):Bool { - return a.toFloat() <= b; - } - - @:op(A < B) private static inline function floatLt(a:Float, b:UInt):Bool { - return a < b.toFloat(); - } - - @:op(A <= B) private static inline function floatLte(a:Float, b:UInt):Bool { - return a <= b.toFloat(); - } - - @:op(A % B) private static inline function modFloat(a:UInt, b:Float):Float { - return a.toFloat() % b; - } - - @:op(A % B) private static inline function floatMod(a:Float, b:UInt):Float { - return a % b.toFloat(); - } - - @:op(~A) private inline function negBits():UInt { - return ~this; - } - - @:op(++A) private inline function prefixIncrement():UInt { - return ++this; - } - - @:op(A++) private inline function postfixIncrement():UInt { - return this++; - } - - @:op(--A) private inline function prefixDecrement():UInt { - return --this; - } - - @:op(A--) private inline function postfixDecrement():UInt { - return this--; - } - - // TODO: radix is just defined to deal with doc_gen issues - private inline function toString(?radix:Int):String { - return Std.string(toFloat()); - } - - private inline function toInt():Int { - return this; - } - - @:to private #if (!js || analyzer) inline #end function toFloat():Float { - var int = toInt(); - if (int < 0) { - return 4294967296.0 + int; - } else { - // + 0.0 here to make sure we promote to Float on some platforms - // In particular, PHP was having issues when comparing to Int in the == op. - return int + 0.0; - } - } -} -#end +// @:deprecated("UInt is deprecated, use haxe.UInt32 instead") +typedef UInt = haxe.UInt32; \ No newline at end of file diff --git a/std/haxe/UInt32.hx b/std/haxe/UInt32.hx new file mode 100644 index 00000000000..0d3598d5eec --- /dev/null +++ b/std/haxe/UInt32.hx @@ -0,0 +1,324 @@ +/* + * 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; + +#if ((flash || flash9doc || hl) && !doc_gen) +/** + The unsigned `Int` type is only defined for Flash. It's currently + handled the same as a normal Int. + + @see https://haxe.org/manual/types-basic-types.html +**/ +@:coreType +@:notNull +@:runtimeValue +@:analyzer(no_const_propagation) +abstract UInt32 to Int from Int { + @:commutative @:op(A + B) private static function addI(lhs:UInt32, rhs:Int):UInt32; + + @:commutative @:op(A + B) private static function addF(lhs:UInt32, rhs:Float):Float; + + @:op(A + B) private static function add(lhs:UInt32, rhs:UInt32):UInt32; + + @:commutative @:op(A * B) private static function mulI(lhs:UInt32, rhs:Int):UInt32; + + @:commutative @:op(A * B) private static function mulF(lhs:UInt32, rhs:Float):Float; + + @:op(A * B) private static function mul(lhs:UInt32, rhs:UInt32):UInt32; + + @:op(A % B) private static function modI(lhs:UInt32, rhs:Int):UInt32; + + @:op(A % B) private static function modF(lhs:UInt32, rhs:Float):Float; + + @:op(A % B) private static function mod(lhs:UInt32, rhs:UInt32):UInt32; + + @:op(A - B) private static function subI(lhs:UInt32, rhs:Int):UInt32; + + @:op(A - B) private static function subF(lhs:UInt32, rhs:Float):Float; + + @:op(A - B) private static function sub(lhs:UInt32, rhs:UInt32):UInt32; + + @:op(A / B) private static function divI(lhs:UInt32, rhs:Int):Float; + + @:op(A / B) private static function divF(lhs:UInt32, rhs:Float):Float; + + @:op(A / B) private static function div(lhs:UInt32, rhs:UInt32):Float; + + @:commutative @:op(A | B) private static function orI(lhs:UInt32, rhs:Int):UInt32; + + @:op(A | B) private static function or(lhs:UInt32, rhs:UInt32):UInt32; + + @:commutative @:op(A ^ B) private static function xorI(lhs:UInt32, rhs:Int):UInt32; + + @:op(A ^ B) private static function xor(lhs:UInt32, rhs:UInt32):UInt32; + + @:commutative @:op(A & B) private static function andI(lhs:UInt32, rhs:Int):UInt32; + + @:op(A & B) private static function and(lhs:UInt32, rhs:UInt32):UInt32; + + @:op(A << B) private static function shl(lhs:UInt32, rhs:Int):UInt32; + + @:op(A >> B) private static inline function shr(lhs:UInt32, rhs:Int):UInt32 + return lhs >>> rhs; + + @:op(A >>> B) private static function ushr(lhs:UInt32, rhs:Int):UInt32; + + @:op(A > B) private static function gt(lhs:UInt32, rhs:UInt32):Bool; + + @:op(A >= B) private static function gte(lhs:UInt32, rhs:UInt32):Bool; + + @:op(A < B) private static function lt(lhs:UInt32, rhs:UInt32):Bool; + + @:op(A <= B) private static function lte(lhs:UInt32, rhs:UInt32):Bool; + + @:op(A > B) private static function gtf(lhs:UInt32, rhs:Float):Bool; + + @:op(A > B) private static function gtf2(lhs:Float, rhs:UInt32):Bool; + + @:op(A >= B) private static function gtef(lhs:UInt32, rhs:Float):Bool; + + @:op(A >= B) private static function gtef2(lhs:Float, rhs:UInt32):Bool; + + @:op(A < B) private static function ltf(lhs:UInt32, rhs:Float):Bool; + + @:op(A < B) private static function ltf2(lhs:Float, rhs:UInt32):Bool; + + @:op(A <= B) private static function ltef(lhs:UInt32, rhs:Float):Bool; + + @:op(A <= B) private static function ltef2(lhs:Float, rhs:UInt32):Bool; + + @:op(~A) private static function bneg(t:UInt32):UInt32; + + @:commutative @:op(A == B) private static function equalsInt(a:UInt32, b:T):Bool; + + @:commutative @:op(A != B) private static function notEqualsInt(a:UInt32, b:T):Bool; + + @:commutative @:op(A == B) private static function equalsFloat(a:UInt32, b:T):Bool; + + @:commutative @:op(A != B) private static function notEqualsFloat(a:UInt32, b:T):Bool; + + @:op(++A) private function prefixIncrement():UInt32; + + @:op(A++) private function postfixIncrement():UInt32; + + @:op(--A) private function prefixDecrement():UInt32; + + @:op(A--) private function postfixDecrement():UInt32; +} +#else + +/** + The unsigned `Int` type is only defined for Flash. + Simulate it for other platforms. + + @see https://haxe.org/manual/types-basic-types.html +**/ +@:transitive +abstract UInt32(Int) from Int to Int { + @:op(A + B) private static inline function add(a:UInt32, b:UInt32):UInt32 { + return a.toInt() + b.toInt(); + } + + @:op(A / B) private static inline function div(a:UInt32, b:UInt32):Float { + return a.toFloat() / b.toFloat(); + } + + @:op(A * B) private static inline function mul(a:UInt32, b:UInt32):UInt32 { + return a.toInt() * b.toInt(); + } + + @:op(A - B) private static inline function sub(a:UInt32, b:UInt32):UInt32 { + return a.toInt() - b.toInt(); + } + + @:op(A > B) + private static #if !js inline #end function gt(a:UInt32, b:UInt32):Bool { + var aNeg = a.toInt() < 0; + var bNeg = b.toInt() < 0; + return if (aNeg != bNeg) aNeg; else a.toInt() > b.toInt(); + } + + @:op(A >= B) + private static #if !js inline #end function gte(a:UInt32, b:UInt32):Bool { + var aNeg = a.toInt() < 0; + var bNeg = b.toInt() < 0; + return if (aNeg != bNeg) aNeg; else a.toInt() >= b.toInt(); + } + + @:op(A < B) private static inline function lt(a:UInt32, b:UInt32):Bool { + return gt(b, a); + } + + @:op(A <= B) private static inline function lte(a:UInt32, b:UInt32):Bool { + return gte(b, a); + } + + @:op(A & B) private static inline function and(a:UInt32, b:UInt32):UInt32 { + return a.toInt() & b.toInt(); + } + + @:op(A | B) private static inline function or(a:UInt32, b:UInt32):UInt32 { + return a.toInt() | b.toInt(); + } + + @:op(A ^ B) private static inline function xor(a:UInt32, b:UInt32):UInt32 { + return a.toInt() ^ b.toInt(); + } + + @:op(A << B) private static inline function shl(a:UInt32, b:Int):UInt32 { + return a.toInt() << b; + } + + @:op(A >> B) private static inline function shr(a:UInt32, b:Int):UInt32 { + return a.toInt() >>> b; + } + + @:op(A >>> B) private static inline function ushr(a:UInt32, b:Int):UInt32 { + return a.toInt() >>> b; + } + + @:op(A % B) private static inline function mod(a:UInt32, b:UInt32):UInt32 { + return Std.int(a.toFloat() % b.toFloat()); + } + + @:commutative @:op(A + B) private static inline function addWithFloat(a:UInt32, b:Float):Float { + return a.toFloat() + b; + } + + @:commutative @:op(A * B) private static inline function mulWithFloat(a:UInt32, b:Float):Float { + return a.toFloat() * b; + } + + @:op(A / B) private static inline function divFloat(a:UInt32, b:Float):Float { + return a.toFloat() / b; + } + + @:op(A / B) private static inline function floatDiv(a:Float, b:UInt32):Float { + return a / b.toFloat(); + } + + @:op(A - B) private static inline function subFloat(a:UInt32, b:Float):Float { + return a.toFloat() - b; + } + + @:op(A - B) private static inline function floatSub(a:Float, b:UInt32):Float { + return a - b.toFloat(); + } + + @:op(A > B) private static inline function gtFloat(a:UInt32, b:Float):Bool { + return a.toFloat() > b; + } + + @:commutative @:op(A == B) private static inline function equalsInt(a:UInt32, b:T):Bool { + return a.toInt() == b; + } + + @:commutative @:op(A != B) private static inline function notEqualsInt(a:UInt32, b:T):Bool { + return a.toInt() != b; + } + + @:commutative @:op(A == B) private static inline function equalsFloat(a:UInt32, b:T):Bool { + return a.toFloat() == b; + } + + @:commutative @:op(A != B) private static inline function notEqualsFloat(a:UInt32, b:T):Bool { + return a.toFloat() != b; + } + + @:op(A >= B) private static inline function gteFloat(a:UInt32, b:Float):Bool { + return a.toFloat() >= b; + } + + @:op(A > B) private static inline function floatGt(a:Float, b:UInt32):Bool { + return a > b.toFloat(); + } + + @:op(A >= B) private static inline function floatGte(a:Float, b:UInt32):Bool { + return a >= b.toFloat(); + } + + @:op(A < B) private static inline function ltFloat(a:UInt32, b:Float):Bool { + return a.toFloat() < b; + } + + @:op(A <= B) private static inline function lteFloat(a:UInt32, b:Float):Bool { + return a.toFloat() <= b; + } + + @:op(A < B) private static inline function floatLt(a:Float, b:UInt32):Bool { + return a < b.toFloat(); + } + + @:op(A <= B) private static inline function floatLte(a:Float, b:UInt32):Bool { + return a <= b.toFloat(); + } + + @:op(A % B) private static inline function modFloat(a:UInt32, b:Float):Float { + return a.toFloat() % b; + } + + @:op(A % B) private static inline function floatMod(a:Float, b:UInt32):Float { + return a % b.toFloat(); + } + + @:op(~A) private inline function negBits():UInt32 { + return ~this; + } + + @:op(++A) private inline function prefixIncrement():UInt32 { + return ++this; + } + + @:op(A++) private inline function postfixIncrement():UInt32 { + return this++; + } + + @:op(--A) private inline function prefixDecrement():UInt32 { + return --this; + } + + @:op(A--) private inline function postfixDecrement():UInt32 { + return this--; + } + + // TODO: radix is just defined to deal with doc_gen issues + private inline function toString(?radix:Int):String { + return Std.string(toFloat()); + } + + private inline function toInt():Int { + return this; + } + + @:to private #if (!js || analyzer) inline #end function toFloat():Float { + var int = toInt(); + if (int < 0) { + return 4294967296.0 + int; + } else { + // + 0.0 here to make sure we promote to Float on some platforms + // In particular, PHP was having issues when comparing to Int in the == op. + return int + 0.0; + } + } +} +#end diff --git a/std/hl/_std/String.hx b/std/hl/_std/String.hx index 5ead1aa290e..58685f651ab 100644 --- a/std/hl/_std/String.hx +++ b/std/hl/_std/String.hx @@ -39,14 +39,14 @@ class String { } public function charAt(index:Int):String { - if ((index : UInt) >= (length : UInt)) + if ((index : haxe.UInt32) >= (length : haxe.UInt32)) return ""; return __char__(bytes.getUI16(index << 1)); } public function charCodeAt(index:Int):Null { - var idx:UInt = index; - if (idx >= (length : UInt)) + var idx:haxe.UInt32 = index; + if (idx >= (length : haxe.UInt32)) return null; return bytes.getUI16(index << 1); } @@ -135,7 +135,7 @@ class String { if (len < 0) return ""; } - if (((pos + len) : UInt) > (sl : UInt)) + if (((pos + len) : haxe.UInt32) > (sl : haxe.UInt32)) len = sl - pos; if (pos < 0 || len <= 0) return ""; diff --git a/std/hl/_std/UInt.hx b/std/hl/_std/haxe/UInt32.hx similarity index 58% rename from std/hl/_std/UInt.hx rename to std/hl/_std/haxe/UInt32.hx index b757e900d94..7d3162fd6cc 100644 --- a/std/hl/_std/UInt.hx +++ b/std/hl/_std/haxe/UInt32.hx @@ -19,148 +19,151 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ + +package haxe; + @:coreApi @:transitive -abstract UInt(Int) from Int to Int { - @:op(A + B) private static inline function add(a:UInt, b:UInt):UInt { +abstract UInt32(Int) from Int to Int { + @:op(A + B) private static inline function add(a:UInt32, b:UInt32):UInt32 { return a.toInt() + b.toInt(); } - @:op(A / B) private static inline function div(a:UInt, b:UInt):Float { + @:op(A / B) private static inline function div(a:UInt32, b:UInt32):Float { return a.toFloat() / b.toFloat(); } - @:op(A * B) private static inline function mul(a:UInt, b:UInt):UInt { + @:op(A * B) private static inline function mul(a:UInt32, b:UInt32):UInt32 { return a.toInt() * b.toInt(); } - @:op(A - B) private static inline function sub(a:UInt, b:UInt):UInt { + @:op(A - B) private static inline function sub(a:UInt32, b:UInt32):UInt32 { return a.toInt() - b.toInt(); } - @:op(A > B) private static function gt(a:UInt, b:UInt):Bool; + @:op(A > B) private static function gt(a:UInt32, b:UInt32):Bool; - @:op(A >= B) private static function gte(a:UInt, b:UInt):Bool; + @:op(A >= B) private static function gte(a:UInt32, b:UInt32):Bool; - @:op(A < B) private static function lt(a:UInt, b:UInt):Bool; + @:op(A < B) private static function lt(a:UInt32, b:UInt32):Bool; - @:op(A <= B) private static function lte(a:UInt, b:UInt):Bool; + @:op(A <= B) private static function lte(a:UInt32, b:UInt32):Bool; - @:op(A & B) private static inline function and(a:UInt, b:UInt):UInt { + @:op(A & B) private static inline function and(a:UInt32, b:UInt32):UInt32 { return a.toInt() & b.toInt(); } - @:op(A | B) private static inline function or(a:UInt, b:UInt):UInt { + @:op(A | B) private static inline function or(a:UInt32, b:UInt32):UInt32 { return a.toInt() | b.toInt(); } - @:op(A ^ B) private static inline function xor(a:UInt, b:UInt):UInt { + @:op(A ^ B) private static inline function xor(a:UInt32, b:UInt32):UInt32 { return a.toInt() ^ b.toInt(); } - @:op(A << B) private static inline function shl(a:UInt, b:Int):UInt { + @:op(A << B) private static inline function shl(a:UInt32, b:Int):UInt32 { return a.toInt() << b; } - @:op(A >> B) private static inline function shr(a:UInt, b:Int):UInt { + @:op(A >> B) private static inline function shr(a:UInt32, b:Int):UInt32 { return a.toInt() >>> b; } - @:op(A >>> B) private static inline function ushr(a:UInt, b:Int):UInt { + @:op(A >>> B) private static inline function ushr(a:UInt32, b:Int):UInt32 { return a.toInt() >>> b; } - @:op(A % B) private static function mod(a:UInt, b:UInt):UInt; + @:op(A % B) private static function mod(a:UInt32, b:UInt32):UInt32; - @:commutative @:op(A + B) private static inline function addWithFloat(a:UInt, b:Float):Float { + @:commutative @:op(A + B) private static inline function addWithFloat(a:UInt32, b:Float):Float { return a.toFloat() + b; } - @:commutative @:op(A * B) private static inline function mulWithFloat(a:UInt, b:Float):Float { + @:commutative @:op(A * B) private static inline function mulWithFloat(a:UInt32, b:Float):Float { return a.toFloat() * b; } - @:op(A / B) private static inline function divFloat(a:UInt, b:Float):Float { + @:op(A / B) private static inline function divFloat(a:UInt32, b:Float):Float { return a.toFloat() / b; } - @:op(A / B) private static inline function floatDiv(a:Float, b:UInt):Float { + @:op(A / B) private static inline function floatDiv(a:Float, b:UInt32):Float { return a / b.toFloat(); } - @:op(A - B) private static inline function subFloat(a:UInt, b:Float):Float { + @:op(A - B) private static inline function subFloat(a:UInt32, b:Float):Float { return a.toFloat() - b; } - @:op(A - B) private static inline function floatSub(a:Float, b:UInt):Float { + @:op(A - B) private static inline function floatSub(a:Float, b:UInt32):Float { return a - b.toFloat(); } - @:op(A > B) private static inline function gtFloat(a:UInt, b:Float):Bool { + @:op(A > B) private static inline function gtFloat(a:UInt32, b:Float):Bool { return a.toFloat() > b; } - @:commutative @:op(A == B) private static function equalsInt(a:UInt, b:T):Bool; + @:commutative @:op(A == B) private static function equalsInt(a:UInt32, b:T):Bool; - @:commutative @:op(A != B) private static function notEqualsInt(a:UInt, b:T):Bool; + @:commutative @:op(A != B) private static function notEqualsInt(a:UInt32, b:T):Bool; - @:commutative @:op(A == B) private static function equalsFloat(a:UInt, b:T):Bool; + @:commutative @:op(A == B) private static function equalsFloat(a:UInt32, b:T):Bool; - @:commutative @:op(A != B) private static function notEqualsFloat(a:UInt, b:T):Bool; + @:commutative @:op(A != B) private static function notEqualsFloat(a:UInt32, b:T):Bool; - @:op(A >= B) private static inline function gteFloat(a:UInt, b:Float):Bool { + @:op(A >= B) private static inline function gteFloat(a:UInt32, b:Float):Bool { return a.toFloat() >= b; } - @:op(A > B) private static inline function floatGt(a:Float, b:UInt):Bool { + @:op(A > B) private static inline function floatGt(a:Float, b:UInt32):Bool { return a > b.toFloat(); } - @:op(A >= B) private static inline function floatGte(a:Float, b:UInt):Bool { + @:op(A >= B) private static inline function floatGte(a:Float, b:UInt32):Bool { return a >= b.toFloat(); } - @:op(A < B) private static inline function ltFloat(a:UInt, b:Float):Bool { + @:op(A < B) private static inline function ltFloat(a:UInt32, b:Float):Bool { return a.toFloat() < b; } - @:op(A <= B) private static inline function lteFloat(a:UInt, b:Float):Bool { + @:op(A <= B) private static inline function lteFloat(a:UInt32, b:Float):Bool { return a.toFloat() <= b; } - @:op(A < B) private static inline function floatLt(a:Float, b:UInt):Bool { + @:op(A < B) private static inline function floatLt(a:Float, b:UInt32):Bool { return a < b.toFloat(); } - @:op(A <= B) private static inline function floatLte(a:Float, b:UInt):Bool { + @:op(A <= B) private static inline function floatLte(a:Float, b:UInt32):Bool { return a <= b.toFloat(); } - @:op(A % B) private static inline function modFloat(a:UInt, b:Float):Float { + @:op(A % B) private static inline function modFloat(a:UInt32, b:Float):Float { return a.toFloat() % b; } - @:op(A % B) private static inline function floatMod(a:Float, b:UInt):Float { + @:op(A % B) private static inline function floatMod(a:Float, b:UInt32):Float { return a % b.toFloat(); } - @:op(~A) private inline function negBits():UInt { + @:op(~A) private inline function negBits():UInt32 { return ~this; } - @:op(++A) private inline function prefixIncrement():UInt { + @:op(++A) private inline function prefixIncrement():UInt32 { return ++this; } - @:op(A++) private inline function postfixIncrement():UInt { + @:op(A++) private inline function postfixIncrement():UInt32 { return this++; } - @:op(--A) private inline function prefixDecrement():UInt { + @:op(--A) private inline function prefixDecrement():UInt32 { return --this; } - @:op(A--) private inline function postfixDecrement():UInt { + @:op(A--) private inline function postfixDecrement():UInt32 { return this--; } @@ -174,6 +177,6 @@ abstract UInt(Int) from Int to Int { } @:to private inline function toFloat():Float { - return cast(this : UInt); + return cast(this : UInt32); } } diff --git a/std/hl/_std/haxe/io/Bytes.hx b/std/hl/_std/haxe/io/Bytes.hx index ae7527f728a..a7073978da6 100644 --- a/std/hl/_std/haxe/io/Bytes.hx +++ b/std/hl/_std/haxe/io/Bytes.hx @@ -36,11 +36,11 @@ class Bytes { } inline function out(pos:Int):Bool { - return (pos : UInt) >= (length : UInt); + return (pos : haxe.UInt32) >= (length : haxe.UInt32); } inline function outRange(pos:Int, len:Int):Bool { - return pos < 0 || len < 0 || ((pos + len) : UInt) > (length : UInt); + return pos < 0 || len < 0 || ((pos + len) : haxe.UInt32) > (length : haxe.UInt32); } public function get(pos:Int):Int { diff --git a/tests/misc/eval/projects/Issue4712/Main.hx b/tests/misc/eval/projects/Issue4712/Main.hx index d6840f536d1..9ef937c4beb 100644 --- a/tests/misc/eval/projects/Issue4712/Main.hx +++ b/tests/misc/eval/projects/Issue4712/Main.hx @@ -3,7 +3,7 @@ class Main { haxe.Log.trace = function(s,?p) { Sys.stderr().writeString("" + s + " " + p.customParams[0]); } - var n:UInt = -4; + var n:haxe.UInt32 = -4; if ( n > 0 ) trace("positive", n); else diff --git a/tests/server/src/cases/issues/Issue8004.hx b/tests/server/src/cases/issues/Issue8004.hx index de3d1662556..ce2de0f9f5d 100644 --- a/tests/server/src/cases/issues/Issue8004.hx +++ b/tests/server/src/cases/issues/Issue8004.hx @@ -25,7 +25,7 @@ class Issue8004 extends TestCase { var found = false; for (module in result) { for (symbol in module.symbols) { - if (symbol.name == "UInt" && symbol.kind == Abstract) { + if (symbol.name == "UInt32" && symbol.kind == Abstract) { found = true; break; } diff --git a/tests/unit/src/unit/issues/Issue2990.hx b/tests/unit/src/unit/issues/Issue2990.hx index d49ec1731f7..2be650af123 100644 --- a/tests/unit/src/unit/issues/Issue2990.hx +++ b/tests/unit/src/unit/issues/Issue2990.hx @@ -5,16 +5,16 @@ class Issue2990 extends Test { function test() { - var u:UInt = 11; - eq(typeof(u << 1), 'TAbstract(UInt,[])'); - eq(typeof(~u), 'TAbstract(UInt,[])'); - eq(typeof(u >> 1), 'TAbstract(UInt,[])'); - eq(typeof(u >>> 1), 'TAbstract(UInt,[])'); - eq(typeof(u + 1), 'TAbstract(UInt,[])'); - eq(typeof(u - 1), 'TAbstract(UInt,[])'); + var u:haxe.UInt32 = 11; + eq(typeof(u << 1), 'TAbstract(haxe.UInt32,[])'); + eq(typeof(~u), 'TAbstract(haxe.UInt32,[])'); + eq(typeof(u >> 1), 'TAbstract(haxe.UInt32,[])'); + eq(typeof(u >>> 1), 'TAbstract(haxe.UInt32,[])'); + eq(typeof(u + 1), 'TAbstract(haxe.UInt32,[])'); + eq(typeof(u - 1), 'TAbstract(haxe.UInt32,[])'); eq(typeof(u / 2), 'TAbstract(Float,[])'); - eq(typeof(u * 2), 'TAbstract(UInt,[])'); - eq(typeof(u % 2), 'TAbstract(UInt,[])'); + eq(typeof(u * 2), 'TAbstract(haxe.UInt32,[])'); + eq(typeof(u % 2), 'TAbstract(haxe.UInt32,[])'); eq(typeof(u % 2.1), 'TAbstract(Float,[])'); eq(typeof(u * 2.1), 'TAbstract(Float,[])'); eq(typeof(u / 2.1), 'TAbstract(Float,[])');