2018-04-06 14:52:10 +00:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2018 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2018-01-16 18:42:38 +00:00
|
|
|
import macros
|
|
|
|
|
2018-05-30 16:11:15 +00:00
|
|
|
template pushRes*: untyped =
|
|
|
|
computation.stack.push(res)
|
2018-01-16 18:42:38 +00:00
|
|
|
|
|
|
|
macro quasiBoolean*(name: untyped, op: untyped, signed: untyped = nil, nonzero: untyped = nil): untyped =
|
|
|
|
var signedNode = newEmptyNode()
|
|
|
|
var finishSignedNode = newEmptyNode()
|
|
|
|
let resNode = ident("res")
|
2018-02-20 17:27:43 +00:00
|
|
|
var leftNode = ident("left")
|
|
|
|
var rightNode = ident("right")
|
|
|
|
var actualLeftNode = leftNode
|
|
|
|
var actualRightNode = rightNode
|
2018-01-16 18:42:38 +00:00
|
|
|
if not signed.isNil:
|
2018-02-20 17:27:43 +00:00
|
|
|
actualLeftNode = ident("leftSigned")
|
|
|
|
actualRightNode = ident("rightSigned")
|
2018-01-16 18:42:38 +00:00
|
|
|
signedNode = quote:
|
2018-02-20 17:27:43 +00:00
|
|
|
let `actualLeftNode` = unsignedToSigned(`leftNode`)
|
|
|
|
let `actualRightNode` = unsignedToSigned(`rightNode`)
|
2018-01-16 18:42:38 +00:00
|
|
|
var test = if nonzero.isNil:
|
|
|
|
quote:
|
2018-02-20 17:27:43 +00:00
|
|
|
`op`(`actualLeftNode`, `actualRightNode`)
|
2018-01-16 18:42:38 +00:00
|
|
|
else:
|
|
|
|
quote:
|
2018-02-20 17:27:43 +00:00
|
|
|
`op`(`actualLeftNode`, `actualRightNode`) != 0
|
2018-01-16 18:42:38 +00:00
|
|
|
result = quote:
|
|
|
|
proc `name`*(computation: var BaseComputation) =
|
|
|
|
var (`leftNode`, `rightNode`) = computation.stack.popInt(2)
|
|
|
|
`signedNode`
|
2018-04-06 14:52:10 +00:00
|
|
|
|
2018-02-20 17:27:43 +00:00
|
|
|
var `resNode` = if `test`: 1.u256 else: 0.u256
|
2018-01-16 18:42:38 +00:00
|
|
|
computation.stack.push(`resNode`)
|