hashes: implement murmur3 (#12022)
* hashes: implement murmur3 * refactoring; there is only one murmurHash and it works at compile-time via VM hooks * fixes JS tests * makes toOpenArrayByte work with C++ * make it bootstrap in C++ mode for 0.20
This commit is contained in:
parent
35268c500f
commit
ab48d7901e
7 changed files with 204 additions and 59 deletions
|
|
@ -17,6 +17,8 @@ from os import getEnv, existsEnv, dirExists, fileExists, putEnv, walkDir, getApp
|
|||
from md5 import getMD5
|
||||
from sighashes import symBodyDigest
|
||||
|
||||
from hashes import hash
|
||||
|
||||
template mathop(op) {.dirty.} =
|
||||
registerCallback(c, "stdlib.math." & astToStr(op), `op Wrapper`)
|
||||
|
||||
|
|
@ -157,3 +159,30 @@ proc registerAdditionalOps*(c: PCtx) =
|
|||
stackTrace(c, PStackFrame(prc: c.prc.sym, comesFrom: 0, next: nil), c.exceptionInstr,
|
||||
"isExported() requires a symbol. '" & $n & "' is of kind '" & $n.kind & "'", n.info)
|
||||
setResult(a, sfExported in n.sym.flags)
|
||||
|
||||
proc hashVmImpl(a: VmArgs) =
|
||||
var res = hashes.hash(a.getString(0), a.getInt(1).int, a.getInt(2).int)
|
||||
if c.config.cmd == cmdCompileToJS:
|
||||
# emulate JS's terrible integers:
|
||||
res = cast[int32](res)
|
||||
setResult(a, res)
|
||||
|
||||
registerCallback c, "stdlib.hashes.hashVmImpl", hashVmImpl
|
||||
|
||||
proc hashVmImplByte(a: VmArgs) =
|
||||
# nkBracket[...]
|
||||
let sPos = a.getInt(1).int
|
||||
let ePos = a.getInt(2).int
|
||||
let arr = a.getNode(0)
|
||||
var bytes = newSeq[byte](arr.len)
|
||||
for i in 0 ..< arr.len:
|
||||
bytes[i] = byte(arr[i].intVal and 0xff)
|
||||
|
||||
var res = hashes.hash(bytes, sPos, ePos)
|
||||
if c.config.cmd == cmdCompileToJS:
|
||||
# emulate JS's terrible integers:
|
||||
res = cast[int32](res)
|
||||
setResult(a, res)
|
||||
|
||||
registerCallback c, "stdlib.hashes.hashVmImplByte", hashVmImplByte
|
||||
registerCallback c, "stdlib.hashes.hashVmImplChar", hashVmImplByte
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue