mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 21:34:33 +00:00
clang compilation error fixed (#5)
This commit is contained in:
parent
39b82b5397
commit
1d81a7c7ba
12
nim.cfg
12
nim.cfg
@ -1,12 +0,0 @@
|
|||||||
# TODO FIXME
|
|
||||||
# Default compiler on Mac is Clang.
|
|
||||||
# Currently it does not compile due to "Flexible array member with non-trivial destruction"
|
|
||||||
# See https://github.com/status-im/nimbus/issues/2 and https://github.com/status-im/nim-ttmath/issues/10
|
|
||||||
# As a workaround, forces GCC-7 on Mac
|
|
||||||
# GCC-7 is available through Homebrew
|
|
||||||
|
|
||||||
@if macosx:
|
|
||||||
cc:"gcc"
|
|
||||||
gcc.cpp.exe:"/usr/local/bin/g++-7"
|
|
||||||
gcc.cpp.linkerexe:"/usr/local/bin/g++-7"
|
|
||||||
@end
|
|
@ -8,10 +8,18 @@ type
|
|||||||
Value* = ref object
|
Value* = ref object
|
||||||
case kind*: ValueKind:
|
case kind*: ValueKind:
|
||||||
of VInt:
|
of VInt:
|
||||||
i*: Int256
|
Fi: array[32, byte] #Int256
|
||||||
of VBinary:
|
of VBinary:
|
||||||
b*: seq[byte]
|
b*: seq[byte]
|
||||||
|
|
||||||
|
# TODO: The Int256 value is stored as array[32, byte], and we bitcast it
|
||||||
|
# back and forth. This is a hacky workaround for the problem that clang
|
||||||
|
# doesn't let you store ttmath types inside nim variant types (unions). Things
|
||||||
|
# should get better when we switch to mpint.
|
||||||
|
|
||||||
|
proc i*(v: Value): Int256 {.inline.} =
|
||||||
|
cast[ptr Int256](unsafeAddr v.Fi)[]
|
||||||
|
|
||||||
proc `$`*(value: Value): string =
|
proc `$`*(value: Value): string =
|
||||||
case value.kind:
|
case value.kind:
|
||||||
of VInt:
|
of VInt:
|
||||||
@ -19,23 +27,16 @@ proc `$`*(value: Value): string =
|
|||||||
of VBinary:
|
of VBinary:
|
||||||
&"Binary({value.b})"
|
&"Binary({value.b})"
|
||||||
|
|
||||||
proc vint*(i: int): Value =
|
proc toArr(i: Int256): array[32, byte] {.inline.} =
|
||||||
Value(kind: VInt, i: i.int256)
|
cast[ptr array[32, byte]](unsafeAddr i)[]
|
||||||
|
|
||||||
proc vint*(i: Int256): Value =
|
proc vint*(i: Int256): Value =
|
||||||
Value(kind: VInt, i: i)
|
Value(kind: VInt, Fi: i.toArr)
|
||||||
|
|
||||||
|
proc vint*(i: int): Value {.inline.} = vint(i.int256)
|
||||||
|
|
||||||
proc vbinary*(b: string): Value =
|
proc vbinary*(b: string): Value =
|
||||||
Value(kind: VBinary, b: b.mapIt(it.byte))
|
Value(kind: VBinary, b: b.mapIt(it.byte))
|
||||||
|
|
||||||
proc vbinary*(b: seq[byte]): Value =
|
proc vbinary*(b: seq[byte]): Value =
|
||||||
Value(kind: VBinary, b: b)
|
Value(kind: VBinary, b: b)
|
||||||
|
|
||||||
proc `==`*(a: Value, b: Value): bool =
|
|
||||||
if a.kind != b.kind:
|
|
||||||
return false
|
|
||||||
case a.kind:
|
|
||||||
of VInt:
|
|
||||||
a.i == b.i
|
|
||||||
of VBinary:
|
|
||||||
a.b == b.b
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user