Skip to content

Commit

Permalink
Allow display hint hex for float/i64
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxiaomao committed Apr 4, 2024
1 parent 23dadf0 commit 519a3ff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
25 changes: 16 additions & 9 deletions hld/Eval.hx
Original file line number Diff line number Diff line change
Expand Up @@ -770,20 +770,27 @@ class Eval {
case VNull: "null";
case VInt(i):
switch( v.hint ) {
case HHex: Value.int2Str(i, 16);
case HBin: Value.int2Str(i, 2);
case HHex: Value.intStr(i, 16);
case HBin: Value.intStr(i, 2);
case HEnumFlags(t):
var eproto = module.resolveEnum(t);
if( eproto == null )
throw "Can't resolve enum " + t;
Value.int2EnumFlags(i, eproto);
default:
"" + i;
Value.intEnumFlags(i, eproto);
default: "" + i;
}
case VInt64(i):
switch( v.hint ) {
case HHex: Value.int64Hex(i);
default: "" + i;
}
case VFloat(i):
switch( v.hint ) {
case HHex: Value.intStr(Std.int(i), 16);
default: "" + i;
}
case VInt64(i): "" + i;
case VFloat(v): "" + v;
case VBool(b): b?"true":"false";
case VPointer(p):
case VBool(b): b ? "true" : "false";
case VPointer(_):
switch( v.t ) {
case HObj(p), HStruct(p): p.name.split(".").pop(); // short form (no package)
default: typeStr(v.t);
Expand Down
14 changes: 12 additions & 2 deletions hld/Value.hx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ enum Hint {
}

static final INTBASE = "0123456789ABCDEF";
public static function int2Str( value : Int, base : Int ) : String {
public static function intStr( value : Int, base : Int ) : String {
if( base < 2 || base > INTBASE.length )
throw "Unsupported int base";
var prefix = base == 2 ? "0b" : base == 16 ? "0x" : "";
Expand All @@ -65,7 +65,17 @@ enum Hint {
return (value < 0 ? "-" : "") + prefix + s;
}

public static function int2EnumFlags( value : Int, eproto : format.hl.Data.EnumPrototype ) : String {
public static function int64Hex( value : haxe.Int64 ) : String {
var s = "";
var abs = value >= haxe.Int64.make(0,0) ? value : -value;
while( abs > 0 ) {
s = INTBASE.charAt(abs.low & 15) + s;
abs = abs >> 4;
}
return (value < 0 ? "-" : "") + "0x" + s;
}

public static function intEnumFlags( value : Int, eproto : format.hl.Data.EnumPrototype ) : String {
var f = "";
for( i in 0...eproto.constructs.length ) {
if( (value >> i) % 2 == 1 )
Expand Down

0 comments on commit 519a3ff

Please sign in to comment.