From 93403b036133430b904a6c2d4536d5d77a29e3de Mon Sep 17 00:00:00 2001 From: Andrew Binstock <920630+platypusguy@users.noreply.github.com> Date: Fri, 15 Nov 2024 22:35:00 -0800 Subject: [PATCH] JACOBIN-608 Initial implementation of for java/util/HexFormat --- src/gfunction/gfunction.go | 1 + src/gfunction/javaUtilHexFormat.go | 61 ++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/gfunction/javaUtilHexFormat.go diff --git a/src/gfunction/gfunction.go b/src/gfunction/gfunction.go index 3d570241..27e14210 100644 --- a/src/gfunction/gfunction.go +++ b/src/gfunction/gfunction.go @@ -130,6 +130,7 @@ func MTableLoadGFunctions(MTable *classloader.MT) { Load_Util_Concurrent_Atomic_AtomicInteger() Load_Util_Concurrent_Atomic_Atomic_Long() Load_Util_HashMap() + Load_Util_HexFormat() Load_Util_Locale() Load_Util_Random() diff --git a/src/gfunction/javaUtilHexFormat.go b/src/gfunction/javaUtilHexFormat.go new file mode 100644 index 00000000..41bfec27 --- /dev/null +++ b/src/gfunction/javaUtilHexFormat.go @@ -0,0 +1,61 @@ +/* + * Jacobin VM - A Java virtual machine + * Copyright (c) 2024 by the Jacobin authors. Consult jacobin.org. + * Licensed under Mozilla Public License 2.0 (MPL 2.0) All rights reserved. + */ + +package gfunction + +import "jacobin/statics" + +// Implementation of some of the functions in in Java/lang/Class. + +func Load_Util_HexFormat() { + + MethodSignatures["java/util/HexFormat.()V"] = + GMeth{ + ParamSlots: 0, + GFunction: hexMapClinit, + } +} + +// hashMapHash accepts a pointer to an object and returns +// a uint64 MD5 hash value of the pointed-to thing +func hexMapClinit(params []interface{}) interface{} { + DIGITS := [256]int8{ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + } + sDigits := statics.Static{Type: "[B", Value: DIGITS} + statics.AddStatic("java/util/HexFormat.DIGITS", sDigits) + + UPPERCASE_DIGITS := [16]int8{ + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', + } + sUppercaseDigits := statics.Static{Type: "[B", Value: UPPERCASE_DIGITS} + statics.AddStatic("java/util/HexFormat.UPPERCASE_DIGITS", sUppercaseDigits) + + LOWERCASE_DIGITS := [16]int8{ + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', + } + sLowercaseDigits := statics.Static{Type: "[B", Value: LOWERCASE_DIGITS} + statics.AddStatic("java/util/HexFormat.LOWERCASE_DIGITS", sLowercaseDigits) + + return nil +}