Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
Joey Yakimowich-Payne
4f6cec613f Fix #233: make shl/shr use the direct left operand for type casting 2020-10-17 08:28:38 -06:00
3 changed files with 16 additions and 3 deletions

View file

@ -379,18 +379,28 @@ proc processBinaryExpression(gState: State, node: TSNode, typeofNode: var PNode)
result.add gState.getIdent(nimSym)
let leftNode = gState.processTSNode(left, typeofNode)
var tyNode = typeofNode
if typeofNode.isNil:
typeofNode = nkCall.newTree(
gState.getIdent("typeof"),
leftNode
)
tyNode = typeofNode
let rightNode = gState.processTSNode(right, typeofNode)
# Special case of setting the shift left/right type
# to be the type of the direct left operand
if binarySym in [">>", "<<"]:
tyNode = nkCall.newTree(
gState.getIdent("typeof"),
leftNode
)
let rightNode = gState.processTSNode(right, tyNode)
result.add leftNode
result.add nkCall.newTree(
typeofNode,
tyNode,
rightNode
)
if binarySym == "/":
@ -399,7 +409,7 @@ proc processBinaryExpression(gState: State, node: TSNode, typeofNode: var PNode)
# So we need to emulate C here and cast the whole
# expression to the type of the first arg
result = nkCall.newTree(
typeofNode,
tyNode,
result
)

View file

@ -35,6 +35,7 @@ extern "C" {
#define EQ4 AVAL < BVAL
#define EQ5 AVAL != BVAL
#define EQ6 AVAL == BVAL
#define SX_NEAR_ZERO (1.0f / (1 << 28))
// testing integer out of long int range
#define INT_FAST16_MIN (-9223372036854775807L-1)

View file

@ -134,6 +134,8 @@ assert EQ4 == (AVAL < BVAL)
assert EQ5 == (AVAL != BVAL)
assert EQ6 == (AVAL == BVAL)
assert SX_NEAR_ZERO == 3.725290298461914e-09
assert SIZEOF == 1
assert COERCE == 645635670332'u64