cheatfate / nimcrypto

Nim cryptographic library
MIT License
189 stars 23 forks source link

support tinycc #39

Closed disruptek closed 4 years ago

disruptek commented 4 years ago

This is how I'm doing it.

mratsim commented 4 years ago

Does this really work? I was always under the impression that nimvm was special cased and that you would need to write

template beLoad32*[T: byte|char](src: openarray[T], srco: int): uint32 =
  when nimvm:
    (uint32(src[srco + 0]) shl 24) or (uint32(src[srco + 1]) shl 16) or
      (uint32(src[srco + 2]) shl 8) or uint32(src[srco + 3])
  else:
    when defined(tcc):
      (uint32(src[srco + 0]) shl 24) or (uint32(src[srco + 1]) shl 16) or
        (uint32(src[srco + 2]) shl 8) or uint32(src[srco + 3])
    else:
      let p = cast[ptr uint32](unsafeAddr src[srco])[]
      leSwap32(p)

instead of

template beLoad32*[T: byte|char](src: openarray[T], srco: int): uint32 =
  when nimvm or defined(tcc):
    (uint32(src[srco + 0]) shl 24) or (uint32(src[srco + 1]) shl 16) or
      (uint32(src[srco + 2]) shl 8) or uint32(src[srco + 3])
  else:
    let p = cast[ptr uint32](unsafeAddr src[srco])[]
    leSwap32(p)

otherwise Nim would throw invalid context nimvm error.

disruptek commented 4 years ago

Works for me, but feel free to close; I no longer need this, myself.

cheatfate commented 4 years ago

@disruptek it fails test suite, if you not going to fix it i will close it.