From aa99cb0d7596cdd376b57340fbe4f1ae4e0dc3f4 Mon Sep 17 00:00:00 2001 From: jangko Date: Fri, 23 Jun 2023 08:09:03 +0700 Subject: [PATCH] replace travis/appveyor with github action --- .appveyor.yml | 86 ---------- .github/workflows/ci.yml | 158 ++++++++++++++++++ .gitignore | 1 + .travis.yml | 39 ----- README.md | 3 +- tests/test1.nim | 7 +- tests/test1.nims | 1 - ttmath.nimble | 23 +-- {src => ttmath}/headers/COPYRIGHT | 56 +++---- {src => ttmath}/headers/ttmath.h | 0 {src => ttmath}/headers/ttmathbig.h | 0 {src => ttmath}/headers/ttmathdec.h | 0 {src => ttmath}/headers/ttmathint.h | 0 {src => ttmath}/headers/ttmathmisc.h | 0 {src => ttmath}/headers/ttmathobjects.h | 0 {src => ttmath}/headers/ttmathparser.h | 0 {src => ttmath}/headers/ttmaththreads.h | 0 {src => ttmath}/headers/ttmathtypes.h | 0 {src => ttmath}/headers/ttmathuint.h | 0 {src => ttmath}/headers/ttmathuint_noasm.h | 0 {src => ttmath}/headers/ttmathuint_x86.h | 0 {src => ttmath}/headers/ttmathuint_x86_64.h | 0 .../headers/ttmathuint_x86_64_msvc.asm | 0 {src => ttmath}/ttmath.nim | 10 +- 24 files changed, 209 insertions(+), 175 deletions(-) delete mode 100644 .appveyor.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml delete mode 100644 tests/test1.nims rename {src => ttmath}/headers/COPYRIGHT (98%) rename {src => ttmath}/headers/ttmath.h (100%) rename {src => ttmath}/headers/ttmathbig.h (100%) rename {src => ttmath}/headers/ttmathdec.h (100%) rename {src => ttmath}/headers/ttmathint.h (100%) rename {src => ttmath}/headers/ttmathmisc.h (100%) rename {src => ttmath}/headers/ttmathobjects.h (100%) rename {src => ttmath}/headers/ttmathparser.h (100%) rename {src => ttmath}/headers/ttmaththreads.h (100%) rename {src => ttmath}/headers/ttmathtypes.h (100%) rename {src => ttmath}/headers/ttmathuint.h (100%) rename {src => ttmath}/headers/ttmathuint_noasm.h (100%) rename {src => ttmath}/headers/ttmathuint_x86.h (100%) rename {src => ttmath}/headers/ttmathuint_x86_64.h (100%) rename {src => ttmath}/headers/ttmathuint_x86_64_msvc.asm (100%) rename {src => ttmath}/ttmath.nim (97%) diff --git a/.appveyor.yml b/.appveyor.yml deleted file mode 100644 index 38aebc2..0000000 --- a/.appveyor.yml +++ /dev/null @@ -1,86 +0,0 @@ -version: '{build}' - -cache: -- x86_64-4.9.2-release-win32-seh-rt_v4-rev4.7z -> .appveyor.yml -- i686-4.9.2-release-win32-dwarf-rt_v4-rev4.7z -> .appveyor.yml -- Nim -> .appveyor.yml - -matrix: - # We always want 32 and 64-bit compilation - fast_finish: false - -platform: - - x86 - - x64 - -install: - - setlocal EnableExtensions EnableDelayedExpansion - - - IF "%PLATFORM%" == "x86" ( - SET "MINGW_ARCHIVE=i686-4.9.2-release-win32-dwarf-rt_v4-rev4.7z" & - SET "MINGW_URL=https://sourceforge.net/projects/mingw-w64/files/Toolchains%%20targetting%%20Win32/Personal%%20Builds/mingw-builds/4.9.2/threads-win32/dwarf/i686-4.9.2-release-win32-dwarf-rt_v4-rev4.7z" & - SET "MINGW_DIR=mingw32" - ) ELSE ( - IF "%PLATFORM%" == "x64" ( - SET "MINGW_ARCHIVE=x86_64-4.9.2-release-win32-seh-rt_v4-rev4.7z" & - SET "MINGW_URL=https://sourceforge.net/projects/mingw-w64/files/Toolchains%%20targetting%%20Win64/Personal%%20Builds/mingw-builds/4.9.2/threads-win32/seh/x86_64-4.9.2-release-win32-seh-rt_v4-rev4.7z" & - SET "MINGW_DIR=mingw64" - ) else ( - echo "Unknown platform" - ) - ) - - - SET PATH=%CD%\%MINGW_DIR%\bin;%CD%\Nim\bin;%PATH% - - # Unpack mingw - - IF NOT EXIST "%MINGW_ARCHIVE%" appveyor DownloadFile "%MINGW_URL%" -FileName "%MINGW_ARCHIVE%" - - 7z x -y "%MINGW_ARCHIVE%" > nul - - # build nim from our own branch - this to avoid the day-to-day churn and - # regressions of the fast-paced Nim development while maintaining the - # flexibility to apply patches - - SET "NEED_REBUILD=" - - - IF NOT EXIST "Nim\\.git\\" ( - git clone https://github.com/status-im/Nim.git - ) ELSE ( - ( cd Nim ) & - ( git pull ) & - ( cd .. ) - ) - - # Rebuild Nim if HEAD has moved or if we don't yet have a cached version - - IF NOT EXIST "Nim\\ver.txt" ( - SET NEED_REBUILD=1 - ) ELSE ( - ( CD Nim ) & - ( git rev-parse HEAD > ..\\cur_ver.txt ) & - ( fc ver.txt ..\\cur_ver.txt || SET NEED_REBUILD=1 ) & - ( cd .. ) - ) - - - IF NOT EXIST "Nim\\bin\\nim.exe" SET NEED_REBUILD=1 - - IF NOT EXIST "Nim\\bin\\nimble.exe" SET NEED_REBUILD=1 - - # after building nim, wipe csources to save on cache space - - IF DEFINED NEED_REBUILD ( - cd Nim & - ( IF EXIST "csources" rmdir /s /q csources ) & - git clone --depth 1 https://github.com/nim-lang/csources & - cd csources & - ( IF "%PLATFORM%" == "x64" ( build64.bat ) else ( build.bat ) ) & - cd .. & - bin\nim c koch & - koch boot -d:release & - koch nimble & - git rev-parse HEAD > ver.txt & - rmdir /s /q csources - ) - -build_script: - - cd C:\projects\%APPVEYOR_PROJECT_SLUG% - - nimble install -y -test_script: - - nimble test - -deploy: off diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5dac2db --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,158 @@ +name: CI +on: + push: + branches: + - master + pull_request: + workflow_dispatch: + +jobs: + build: + strategy: + fail-fast: false + matrix: + target: + - os: linux + cpu: amd64 + - os: linux + cpu: i386 + - os: macos + cpu: amd64 + - os: windows + cpu: amd64 + #- os: windows + #cpu: i386 + branch: [version-1-6, version-2-0, devel] + include: + - target: + os: linux + builder: ubuntu-20.04 + shell: bash + - target: + os: macos + builder: macos-12 + shell: bash + - target: + os: windows + builder: windows-latest + shell: msys2 {0} + + defaults: + run: + shell: ${{ matrix.shell }} + + name: '${{ matrix.target.os }}-${{ matrix.target.cpu }} (Nim ${{ matrix.branch }})' + runs-on: ${{ matrix.builder }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install build dependencies (Linux i386) + if: runner.os == 'Linux' && matrix.target.cpu == 'i386' + run: | + sudo dpkg --add-architecture i386 + sudo apt-fast update -qq + sudo DEBIAN_FRONTEND='noninteractive' apt-fast install \ + --no-install-recommends -yq gcc-multilib g++-multilib \ + libssl-dev:i386 + mkdir -p external/bin + cat << EOF > external/bin/gcc + #!/bin/bash + exec $(which gcc) -m32 "\$@" + EOF + cat << EOF > external/bin/g++ + #!/bin/bash + exec $(which g++) -m32 "\$@" + EOF + chmod 755 external/bin/gcc external/bin/g++ + echo '${{ github.workspace }}/external/bin' >> $GITHUB_PATH + + - name: MSYS2 (Windows i386) + if: runner.os == 'Windows' && matrix.target.cpu == 'i386' + uses: msys2/setup-msys2@v2 + with: + path-type: inherit + msystem: MINGW32 + install: >- + base-devel + git + mingw-w64-i686-toolchain + + - name: MSYS2 (Windows amd64) + if: runner.os == 'Windows' && matrix.target.cpu == 'amd64' + uses: msys2/setup-msys2@v2 + with: + path-type: inherit + install: >- + base-devel + git + mingw-w64-x86_64-toolchain + + - name: Restore Nim DLLs dependencies (Windows) from cache + if: runner.os == 'Windows' + id: windows-dlls-cache + uses: actions/cache@v3 + with: + path: external/dlls + key: 'dlls' + + - name: Install DLL dependencies (Windows) + if: > + steps.windows-dlls-cache.outputs.cache-hit != 'true' && + runner.os == 'Windows' + run: | + mkdir external + curl -L "https://nim-lang.org/download/windeps.zip" -o external/windeps.zip + 7z x external/windeps.zip -oexternal/dlls + + - name: Path to cached dependencies (Windows) + if: > + runner.os == 'Windows' + run: | + echo '${{ github.workspace }}'"/external/dlls" >> $GITHUB_PATH + + - name: Derive environment variables + run: | + if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then + PLATFORM=x64 + else + PLATFORM=x86 + fi + echo "PLATFORM=$PLATFORM" >> $GITHUB_ENV + + ncpu= + MAKE_CMD="make" + case '${{ runner.os }}' in + 'Linux') + ncpu=$(nproc) + ;; + 'macOS') + ncpu=$(sysctl -n hw.ncpu) + ;; + 'Windows') + ncpu=$NUMBER_OF_PROCESSORS + MAKE_CMD="mingw32-make" + ;; + esac + [[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1 + echo "ncpu=$ncpu" >> $GITHUB_ENV + echo "MAKE_CMD=${MAKE_CMD}" >> $GITHUB_ENV + + - name: Build Nim and Nimble + run: | + curl -O -L -s -S https://raw.githubusercontent.com/status-im/nimbus-build-system/master/scripts/build_nim.sh + env MAKE="${MAKE_CMD} -j${ncpu}" ARCH_OVERRIDE=${PLATFORM} NIM_COMMIT=${{ matrix.branch }} \ + QUICK_AND_DIRTY_COMPILER=1 QUICK_AND_DIRTY_NIMBLE=1 CC=gcc \ + bash build_nim.sh nim csources dist/nimble NimBinaries + echo '${{ github.workspace }}/nim/bin' >> $GITHUB_PATH + + - name: Run tests + run: | + if [[ "${{ matrix.target.os }}" == "windows" ]]; then + # https://github.com/status-im/nimbus-eth2/issues/3121 + export NIMFLAGS="-d:nimRawSetjmp" + fi + nim --version + nimble --version + nimble install -y --depsOnly + nimble test diff --git a/.gitignore b/.gitignore index c85aefe..a8cd1a5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ nimcache/ build/ +*.exe diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8e56f7e..0000000 --- a/.travis.yml +++ /dev/null @@ -1,39 +0,0 @@ -language: c # or other C/C++ variants - -sudo: false - -# https://docs.travis-ci.com/user/caching/ -# -# Caching the whole nim folder is better than relying on ccache - this way, we -# skip the expensive bootstrap process and linking -cache: - directories: - - nim - -os: - - linux - - osx - -install: - # build nim from our own branch - this to avoid the day-to-day churn and - # regressions of the fast-paced Nim development while maintaining the - # flexibility to apply patches - # - # check version of remote branch - - "export NIMVER=$(git ls-remote https://github.com/status-im/nim.git HEAD | cut -f 1)" - - # after building nim, wipe csources to save on cache space - - "{ [ -f nim/$NIMVER/bin/nim ] && [ -f nim/$NIMVER/bin/nimble ] ; } || - { rm -rf nim ; - mkdir -p nim ; - git clone --depth=1 https://github.com/status-im/nim.git nim/$NIMVER ; - cd nim/$NIMVER ; - sh build_all.sh ; - rm -rf csources ; - cd ../.. ; - }" - - "export PATH=$PWD/nim/$NIMVER/bin:$PATH" - -script: - - nimble install -y - - nimble test diff --git a/README.md b/README.md index f887c4a..789bb55 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,9 @@ # nim-ttmath -[![Build Status (Travis)](https://img.shields.io/travis/status-im/nimbus/master.svg?label=Linux%20/%20macOS "Linux/macOS build status (Travis)")](https://travis-ci.org/status-im/nimbus) -[![Windows build status (Appveyor)](https://img.shields.io/appveyor/ci/nimbus/nimbus/master.svg?label=Windows "Windows build status (Appveyor)")](https://ci.appveyor.com/project/nimbus/nimbus) [![License: Apache](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) ![Stability: experimental](https://img.shields.io/badge/stability-experimental-orange.svg) +![Github action](https://github.com/status-im/nim-ttmath/workflows/CI/badge.svg) A Nim wrapper for [ttmath library](https://www.ttmath.org/), a c++ template library for operating with big integers and floats with fixed sizes. diff --git a/tests/test1.nim b/tests/test1.nim index a0229d9..9c2be50 100644 --- a/tests/test1.nim +++ b/tests/test1.nim @@ -1,16 +1,16 @@ -import ttmath, unittest, strutils +import ../ttmath/ttmath, unittest, strutils suite "ttmath": test "String <-> Int": let a = i256"123456789012345679801234" strVal = $a - check strVal == "123456789012345679801234" + check strVal == "123456789012345679801234" test "String <-> UInt": let a = u256"123456789012345679801234" strVal = $a - check strVal == "123456789012345679801234" + check strVal == "123456789012345679801234" test "Ints": let a = i256"12345678910111213141516" let b = i256"16151413121110987654321" @@ -99,3 +99,4 @@ suite "Confirming consistency: hex vs decimal conversion": "84467545608142925331782333363288012579669270632210954476013542647119929595395".u1024 hexToUInt[1024]("603D0AF084BF906B2CDF6CDDE8B2E1C3E51A41AF5E9ADEC7F3643B3F1AA2AADF") == "43529886636775750164425297556346136250671451061152161143648812009114516499167".u1024 + diff --git a/tests/test1.nims b/tests/test1.nims deleted file mode 100644 index 80091ff..0000000 --- a/tests/test1.nims +++ /dev/null @@ -1 +0,0 @@ -switch("path", "$projectDir/../src") diff --git a/ttmath.nimble b/ttmath.nimble index e0917a9..db16bca 100644 --- a/ttmath.nimble +++ b/ttmath.nimble @@ -3,20 +3,21 @@ version = "0.5.0" author = "Status Research & Development GmbH" description = "A Nim wrapper for ttmath: big numbers with fixed size" license = "Apache License 2.0" -srcDir = "src" ### Dependencies -requires "nim >= 0.18.1" +requires "nim >= 1.6.12" -proc test(name: string, lang = "cpp") = +proc test(args, path: string) = if not dirExists "build": mkDir "build" - if not dirExists "nimcache": - mkDir "nimcache" - --run - --nimcache: "nimcache" - switch("out", ("./build/" & name)) - setCommand lang, "tests/" & name & ".nim" -task test, "Run tests": - test "test1" + exec "nim cpp " & getEnv("NIMFLAGS") & " " & args & + " --outdir:build -r --hints:off --warnings:off --skipParentCfg" & + " --styleCheck:usages --styleCheck:error " & path + if (NimMajor, NimMinor) > (1, 6): + exec "nim cpp " & getEnv("NIMFLAGS") & " " & args & + " --outdir:build -r --mm:refc --hints:off --warnings:off --skipParentCfg" & + " --styleCheck:usages --styleCheck:error " & path + +task test, "Run all tests": + test "", "tests/test1" diff --git a/src/headers/COPYRIGHT b/ttmath/headers/COPYRIGHT similarity index 98% rename from src/headers/COPYRIGHT rename to ttmath/headers/COPYRIGHT index 15bec4e..35b688c 100644 --- a/src/headers/COPYRIGHT +++ b/ttmath/headers/COPYRIGHT @@ -1,28 +1,28 @@ -Copyright (c) 2006-2012, Tomasz Sowa -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name Tomasz Sowa nor the names of contributors to this - project may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. +Copyright (c) 2006-2012, Tomasz Sowa +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name Tomasz Sowa nor the names of contributors to this + project may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/headers/ttmath.h b/ttmath/headers/ttmath.h similarity index 100% rename from src/headers/ttmath.h rename to ttmath/headers/ttmath.h diff --git a/src/headers/ttmathbig.h b/ttmath/headers/ttmathbig.h similarity index 100% rename from src/headers/ttmathbig.h rename to ttmath/headers/ttmathbig.h diff --git a/src/headers/ttmathdec.h b/ttmath/headers/ttmathdec.h similarity index 100% rename from src/headers/ttmathdec.h rename to ttmath/headers/ttmathdec.h diff --git a/src/headers/ttmathint.h b/ttmath/headers/ttmathint.h similarity index 100% rename from src/headers/ttmathint.h rename to ttmath/headers/ttmathint.h diff --git a/src/headers/ttmathmisc.h b/ttmath/headers/ttmathmisc.h similarity index 100% rename from src/headers/ttmathmisc.h rename to ttmath/headers/ttmathmisc.h diff --git a/src/headers/ttmathobjects.h b/ttmath/headers/ttmathobjects.h similarity index 100% rename from src/headers/ttmathobjects.h rename to ttmath/headers/ttmathobjects.h diff --git a/src/headers/ttmathparser.h b/ttmath/headers/ttmathparser.h similarity index 100% rename from src/headers/ttmathparser.h rename to ttmath/headers/ttmathparser.h diff --git a/src/headers/ttmaththreads.h b/ttmath/headers/ttmaththreads.h similarity index 100% rename from src/headers/ttmaththreads.h rename to ttmath/headers/ttmaththreads.h diff --git a/src/headers/ttmathtypes.h b/ttmath/headers/ttmathtypes.h similarity index 100% rename from src/headers/ttmathtypes.h rename to ttmath/headers/ttmathtypes.h diff --git a/src/headers/ttmathuint.h b/ttmath/headers/ttmathuint.h similarity index 100% rename from src/headers/ttmathuint.h rename to ttmath/headers/ttmathuint.h diff --git a/src/headers/ttmathuint_noasm.h b/ttmath/headers/ttmathuint_noasm.h similarity index 100% rename from src/headers/ttmathuint_noasm.h rename to ttmath/headers/ttmathuint_noasm.h diff --git a/src/headers/ttmathuint_x86.h b/ttmath/headers/ttmathuint_x86.h similarity index 100% rename from src/headers/ttmathuint_x86.h rename to ttmath/headers/ttmathuint_x86.h diff --git a/src/headers/ttmathuint_x86_64.h b/ttmath/headers/ttmathuint_x86_64.h similarity index 100% rename from src/headers/ttmathuint_x86_64.h rename to ttmath/headers/ttmathuint_x86_64.h diff --git a/src/headers/ttmathuint_x86_64_msvc.asm b/ttmath/headers/ttmathuint_x86_64_msvc.asm similarity index 100% rename from src/headers/ttmathuint_x86_64_msvc.asm rename to ttmath/headers/ttmathuint_x86_64_msvc.asm diff --git a/src/ttmath.nim b/ttmath/ttmath.nim similarity index 97% rename from src/ttmath.nim rename to ttmath/ttmath.nim index d3b6d06..546d8a3 100644 --- a/src/ttmath.nim +++ b/ttmath/ttmath.nim @@ -2,11 +2,11 @@ import strutils from os import DirSep const ttmathPath = currentSourcePath.rsplit(DirSep, 1)[0] -{.passC: "-I" & ttmathPath.} +{.passc: "-I" & ttmathPath.} when defined(windows): # See https://github.com/status-im/nim-ttmath/issues/14 - {.passC: "-DTTMATH_NOASM".} + {.passc: "-DTTMATH_NOASM".} const TTMATH_HEADER = ttmathPath & DirSep & "headers" & DirSep & "ttmath.h" @@ -141,7 +141,7 @@ proc setMin*(a: var TTInt) {.importcpp: "SetMin", header: TTMATH_HEADER.} proc setMax*(a: var TTInt) {.importcpp: "SetMax", header: TTMATH_HEADER.} proc clearFirstBits*(a: var TTInt, n: uint) {.importcpp: "ClearFirstBits", header: TTMATH_HEADER.} -template max*[T: TTint]: TTInt = +template max*[T: TTInt]: TTInt = var r = initInt[T](0) r.setMax() r @@ -151,14 +151,14 @@ proc `$`*(a: Int or UInt): string {.inline.} = a.toString() proc hexToUInt*[N](hexStr: string): UInt[N] {.inline.} = result.fromHex(hexStr) proc toHex*(a: TTInt): string {.inline.} = a.toString(16) -proc toByteArrayBE*[N](num: UInt[N]): array[N div 8, byte] {.noSideEffect, noInit, inline.} = +proc toByteArrayBE*[N](num: UInt[N]): array[N div 8, byte] {.noSideEffect, noinit, inline.} = ## Convert a TTInt (in native host endianness) to a big-endian byte array const N = result.len for i in 0 ..< N: {.unroll: 4.} result[i] = byte getUInt(num shr uint((N-1-i) * 8)) -proc readUintBE*[N](ba: openarray[byte]): UInt[N] {.noSideEffect, inline.} = +proc readUIntBE*[N](ba: openArray[byte]): UInt[N] {.noSideEffect, inline.} = ## Convert a big-endian array of Bytes to an UInt256 (in native host endianness) const sz = N div 8 assert(ba.len >= sz)