got rid of some mAddU64 etc. magics
This commit is contained in:
parent
695e9d5fb4
commit
43f057c5aa
7 changed files with 25 additions and 31 deletions
|
|
@ -393,7 +393,7 @@ type
|
||||||
mShrI, mShlI, mBitandI, mBitorI, mBitxorI, mMinI, mMaxI,
|
mShrI, mShlI, mBitandI, mBitorI, mBitxorI, mMinI, mMaxI,
|
||||||
mShrI64, mShlI64, mBitandI64, mBitorI64, mBitxorI64, mMinI64, mMaxI64,
|
mShrI64, mShlI64, mBitandI64, mBitorI64, mBitxorI64, mMinI64, mMaxI64,
|
||||||
mMinF64, mMaxF64, mAddU, mSubU, mMulU,
|
mMinF64, mMaxF64, mAddU, mSubU, mMulU,
|
||||||
mDivU, mModU, mAddU64, mSubU64, mMulU64, mDivU64, mModU64, mEqI, mLeI,
|
mDivU, mModU, mEqI, mLeI,
|
||||||
mLtI,
|
mLtI,
|
||||||
mEqI64, mLeI64, mLtI64, mEqF64, mLeF64, mLtF64,
|
mEqI64, mLeI64, mLtI64, mEqF64, mLeF64, mLtF64,
|
||||||
mLeU, mLtU, mLeU64, mLtU64,
|
mLeU, mLtU, mLeU64, mLtU64,
|
||||||
|
|
@ -444,7 +444,7 @@ const
|
||||||
mShrI, mShlI, mBitandI, mBitorI, mBitxorI, mMinI, mMaxI,
|
mShrI, mShlI, mBitandI, mBitorI, mBitxorI, mMinI, mMaxI,
|
||||||
mShrI64, mShlI64, mBitandI64, mBitorI64, mBitxorI64, mMinI64, mMaxI64,
|
mShrI64, mShlI64, mBitandI64, mBitorI64, mBitxorI64, mMinI64, mMaxI64,
|
||||||
mMinF64, mMaxF64, mAddU, mSubU, mMulU,
|
mMinF64, mMaxF64, mAddU, mSubU, mMulU,
|
||||||
mDivU, mModU, mAddU64, mSubU64, mMulU64, mDivU64, mModU64, mEqI, mLeI,
|
mDivU, mModU, mEqI, mLeI,
|
||||||
mLtI,
|
mLtI,
|
||||||
mEqI64, mLeI64, mLtI64, mEqF64, mLeF64, mLtF64,
|
mEqI64, mLeI64, mLtI64, mEqF64, mLeF64, mLtF64,
|
||||||
mLeU, mLtU, mLeU64, mLtU64,
|
mLeU, mLtU, mLeU64, mLtU64,
|
||||||
|
|
|
||||||
|
|
@ -430,11 +430,6 @@ proc binaryArith(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||||
"($4)((NU$3)($1) * (NU$3)($2))", # MulU
|
"($4)((NU$3)($1) * (NU$3)($2))", # MulU
|
||||||
"($4)((NU$3)($1) / (NU$3)($2))", # DivU
|
"($4)((NU$3)($1) / (NU$3)($2))", # DivU
|
||||||
"($4)((NU$3)($1) % (NU$3)($2))", # ModU
|
"($4)((NU$3)($1) % (NU$3)($2))", # ModU
|
||||||
"($4)((NU64)($1) + (NU64)($2))", # AddU64
|
|
||||||
"($4)((NU64)($1) - (NU64)($2))", # SubU64
|
|
||||||
"($4)((NU64)($1) * (NU64)($2))", # MulU64
|
|
||||||
"($4)((NU64)($1) / (NU64)($2))", # DivU64
|
|
||||||
"($4)((NU64)($1) % (NU64)($2))", # ModU64
|
|
||||||
"($1 == $2)", # EqI
|
"($1 == $2)", # EqI
|
||||||
"($1 <= $2)", # LeI
|
"($1 <= $2)", # LeI
|
||||||
"($1 < $2)", # LtI
|
"($1 < $2)", # LtI
|
||||||
|
|
|
||||||
|
|
@ -351,11 +351,6 @@ const # magic checked op; magic unchecked op; checked op; unchecked op
|
||||||
["MulU", "MulU", "MulU($1, $2)", "MulU($1, $2)"], # MulU
|
["MulU", "MulU", "MulU($1, $2)", "MulU($1, $2)"], # MulU
|
||||||
["DivU", "DivU", "DivU($1, $2)", "DivU($1, $2)"], # DivU
|
["DivU", "DivU", "DivU($1, $2)", "DivU($1, $2)"], # DivU
|
||||||
["ModU", "ModU", "ModU($1, $2)", "ModU($1, $2)"], # ModU
|
["ModU", "ModU", "ModU($1, $2)", "ModU($1, $2)"], # ModU
|
||||||
["AddU64", "AddU64", "AddU64($1, $2)", "AddU64($1, $2)"], # AddU64
|
|
||||||
["SubU64", "SubU64", "SubU64($1, $2)", "SubU64($1, $2)"], # SubU64
|
|
||||||
["MulU64", "MulU64", "MulU64($1, $2)", "MulU64($1, $2)"], # MulU64
|
|
||||||
["DivU64", "DivU64", "DivU64($1, $2)", "DivU64($1, $2)"], # DivU64
|
|
||||||
["ModU64", "ModU64", "ModU64($1, $2)", "ModU64($1, $2)"], # ModU64
|
|
||||||
["", "", "($1 == $2)", "($1 == $2)"], # EqI
|
["", "", "($1 == $2)", "($1 == $2)"], # EqI
|
||||||
["", "", "($1 <= $2)", "($1 <= $2)"], # LeI
|
["", "", "($1 <= $2)", "($1 <= $2)"], # LeI
|
||||||
["", "", "($1 < $2)", "($1 < $2)"], # LtI
|
["", "", "($1 < $2)", "($1 < $2)"], # LtI
|
||||||
|
|
|
||||||
|
|
@ -181,11 +181,11 @@ proc getIntervalType*(m: TMagic, n: PNode): PType =
|
||||||
if isIntRange(a) and isIntLit(b):
|
if isIntRange(a) and isIntLit(b):
|
||||||
result = makeRange(a, pickMinInt(n.sons[1]) |-| pickMinInt(n.sons[2]),
|
result = makeRange(a, pickMinInt(n.sons[1]) |-| pickMinInt(n.sons[2]),
|
||||||
pickMaxInt(n.sons[1]) |-| pickMaxInt(n.sons[2]))
|
pickMaxInt(n.sons[1]) |-| pickMaxInt(n.sons[2]))
|
||||||
of mAddI, mAddI64, mAddU, mAddU64:
|
of mAddI, mAddI64, mAddU:
|
||||||
commutativeOp(`|+|`)
|
commutativeOp(`|+|`)
|
||||||
of mMulI, mMulI64, mMulU, mMulU64:
|
of mMulI, mMulI64, mMulU:
|
||||||
commutativeOp(`|*|`)
|
commutativeOp(`|*|`)
|
||||||
of mSubI, mSubI64, mSubU, mSubU64:
|
of mSubI, mSubI64, mSubU:
|
||||||
binaryOp(`|-|`)
|
binaryOp(`|-|`)
|
||||||
of mBitandI, mBitandI64:
|
of mBitandI, mBitandI64:
|
||||||
var a = n.sons[1]
|
var a = n.sons[1]
|
||||||
|
|
@ -196,7 +196,7 @@ proc getIntervalType*(m: TMagic, n: PNode): PType =
|
||||||
let x = b.intVal|+|1
|
let x = b.intVal|+|1
|
||||||
if (x and -x) == x and x >= 0:
|
if (x and -x) == x and x >= 0:
|
||||||
result = makeRange(a.typ, 0, b.intVal)
|
result = makeRange(a.typ, 0, b.intVal)
|
||||||
of mModI, mModI64, mModU, mModU64:
|
of mModI, mModI64, mModU:
|
||||||
# so ... if you ever wondered about modulo's signedness; this defines it:
|
# so ... if you ever wondered about modulo's signedness; this defines it:
|
||||||
let a = n.sons[1]
|
let a = n.sons[1]
|
||||||
let b = n.sons[2]
|
let b = n.sons[2]
|
||||||
|
|
@ -205,7 +205,7 @@ proc getIntervalType*(m: TMagic, n: PNode): PType =
|
||||||
result = makeRange(a.typ, 0, b.intVal-1)
|
result = makeRange(a.typ, 0, b.intVal-1)
|
||||||
else:
|
else:
|
||||||
result = makeRange(a.typ, b.intVal+1, 0)
|
result = makeRange(a.typ, b.intVal+1, 0)
|
||||||
of mDivI, mDivI64, mDivU, mDivU64:
|
of mDivI, mDivI64, mDivU:
|
||||||
binaryOp(`|div|`)
|
binaryOp(`|div|`)
|
||||||
of mMinI, mMinI64:
|
of mMinI, mMinI64:
|
||||||
commutativeOp(min)
|
commutativeOp(min)
|
||||||
|
|
@ -311,11 +311,11 @@ proc evalOp(m: TMagic, n, a, b, c: PNode): PNode =
|
||||||
of mBitandI, mBitandI64, mAnd: result = newIntNodeT(a.getInt and b.getInt, n)
|
of mBitandI, mBitandI64, mAnd: result = newIntNodeT(a.getInt and b.getInt, n)
|
||||||
of mBitorI, mBitorI64, mOr: result = newIntNodeT(getInt(a) or getInt(b), n)
|
of mBitorI, mBitorI64, mOr: result = newIntNodeT(getInt(a) or getInt(b), n)
|
||||||
of mBitxorI, mBitxorI64, mXor: result = newIntNodeT(a.getInt xor b.getInt, n)
|
of mBitxorI, mBitxorI64, mXor: result = newIntNodeT(a.getInt xor b.getInt, n)
|
||||||
of mAddU, mAddU64: result = newIntNodeT(`+%`(getInt(a), getInt(b)), n)
|
of mAddU: result = newIntNodeT(`+%`(getInt(a), getInt(b)), n)
|
||||||
of mSubU, mSubU64: result = newIntNodeT(`-%`(getInt(a), getInt(b)), n)
|
of mSubU: result = newIntNodeT(`-%`(getInt(a), getInt(b)), n)
|
||||||
of mMulU, mMulU64: result = newIntNodeT(`*%`(getInt(a), getInt(b)), n)
|
of mMulU: result = newIntNodeT(`*%`(getInt(a), getInt(b)), n)
|
||||||
of mModU, mModU64: result = newIntNodeT(`%%`(getInt(a), getInt(b)), n)
|
of mModU: result = newIntNodeT(`%%`(getInt(a), getInt(b)), n)
|
||||||
of mDivU, mDivU64: result = newIntNodeT(`/%`(getInt(a), getInt(b)), n)
|
of mDivU: result = newIntNodeT(`/%`(getInt(a), getInt(b)), n)
|
||||||
of mLeSet: result = newIntNodeT(Ord(containsSets(a, b)), n)
|
of mLeSet: result = newIntNodeT(Ord(containsSets(a, b)), n)
|
||||||
of mEqSet: result = newIntNodeT(Ord(equalSets(a, b)), n)
|
of mEqSet: result = newIntNodeT(Ord(equalSets(a, b)), n)
|
||||||
of mLtSet:
|
of mLtSet:
|
||||||
|
|
|
||||||
|
|
@ -2000,13 +2000,17 @@ handled, it is propagated through the call stack. This means that often
|
||||||
the rest of the procedure - that is not within a ``finally`` clause -
|
the rest of the procedure - that is not within a ``finally`` clause -
|
||||||
is not executed (if an exception occurs).
|
is not executed (if an exception occurs).
|
||||||
|
|
||||||
|
|
||||||
|
Except and finally statements
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
`except`:idx: and `finally`:idx: can also be used as a stand-alone statements.
|
`except`:idx: and `finally`:idx: can also be used as a stand-alone statements.
|
||||||
Any statements following them in the current block will be considered to be
|
Any statements following them in the current block will be considered to be
|
||||||
in an implicit try block:
|
in an implicit try block:
|
||||||
|
|
||||||
.. code-block:: nimrod
|
.. code-block:: nimrod
|
||||||
var f = fopen("numbers.txt", "r")
|
var f = open("numbers.txt")
|
||||||
finally: fcsole(f)
|
finally: close(f)
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -533,34 +533,34 @@ proc abs*(x: int64): int64 {.magic: "AbsI64", noSideEffect.}
|
||||||
## checking is turned on).
|
## checking is turned on).
|
||||||
|
|
||||||
type
|
type
|
||||||
IntMax32 = distinct int|int8|int16|int32
|
IntMax32 = distinct int|int8|int16|int32
|
||||||
|
|
||||||
proc `+%` *(x, y: IntMax32): IntMax32 {.magic: "AddU", noSideEffect.}
|
proc `+%` *(x, y: IntMax32): IntMax32 {.magic: "AddU", noSideEffect.}
|
||||||
proc `+%` *(x, y: Int64): Int64 {.magic: "AddU64", noSideEffect.}
|
proc `+%` *(x, y: Int64): Int64 {.magic: "AddU", noSideEffect.}
|
||||||
## treats `x` and `y` as unsigned and adds them. The result is truncated to
|
## treats `x` and `y` as unsigned and adds them. The result is truncated to
|
||||||
## fit into the result. This implements modulo arithmetic. No overflow
|
## fit into the result. This implements modulo arithmetic. No overflow
|
||||||
## errors are possible.
|
## errors are possible.
|
||||||
|
|
||||||
proc `-%` *(x, y: IntMax32): IntMax32 {.magic: "SubU", noSideEffect.}
|
proc `-%` *(x, y: IntMax32): IntMax32 {.magic: "SubU", noSideEffect.}
|
||||||
proc `-%` *(x, y: Int64): Int64 {.magic: "SubU64", noSideEffect.}
|
proc `-%` *(x, y: Int64): Int64 {.magic: "SubU", noSideEffect.}
|
||||||
## treats `x` and `y` as unsigned and subtracts them. The result is
|
## treats `x` and `y` as unsigned and subtracts them. The result is
|
||||||
## truncated to fit into the result. This implements modulo arithmetic.
|
## truncated to fit into the result. This implements modulo arithmetic.
|
||||||
## No overflow errors are possible.
|
## No overflow errors are possible.
|
||||||
|
|
||||||
proc `*%` *(x, y: IntMax32): IntMax32 {.magic: "MulU", noSideEffect.}
|
proc `*%` *(x, y: IntMax32): IntMax32 {.magic: "MulU", noSideEffect.}
|
||||||
proc `*%` *(x, y: Int64): Int64 {.magic: "MulU64", noSideEffect.}
|
proc `*%` *(x, y: Int64): Int64 {.magic: "MulU", noSideEffect.}
|
||||||
## treats `x` and `y` as unsigned and multiplies them. The result is
|
## treats `x` and `y` as unsigned and multiplies them. The result is
|
||||||
## truncated to fit into the result. This implements modulo arithmetic.
|
## truncated to fit into the result. This implements modulo arithmetic.
|
||||||
## No overflow errors are possible.
|
## No overflow errors are possible.
|
||||||
|
|
||||||
proc `/%` *(x, y: IntMax32): IntMax32 {.magic: "DivU", noSideEffect.}
|
proc `/%` *(x, y: IntMax32): IntMax32 {.magic: "DivU", noSideEffect.}
|
||||||
proc `/%` *(x, y: Int64): Int64 {.magic: "DivU64", noSideEffect.}
|
proc `/%` *(x, y: Int64): Int64 {.magic: "DivU", noSideEffect.}
|
||||||
## treats `x` and `y` as unsigned and divides them. The result is
|
## treats `x` and `y` as unsigned and divides them. The result is
|
||||||
## truncated to fit into the result. This implements modulo arithmetic.
|
## truncated to fit into the result. This implements modulo arithmetic.
|
||||||
## No overflow errors are possible.
|
## No overflow errors are possible.
|
||||||
|
|
||||||
proc `%%` *(x, y: IntMax32): IntMax32 {.magic: "ModU", noSideEffect.}
|
proc `%%` *(x, y: IntMax32): IntMax32 {.magic: "ModU", noSideEffect.}
|
||||||
proc `%%` *(x, y: Int64): Int64 {.magic: "ModU64", noSideEffect.}
|
proc `%%` *(x, y: Int64): Int64 {.magic: "ModU", noSideEffect.}
|
||||||
## treats `x` and `y` as unsigned and compute the modulo of `x` and `y`.
|
## treats `x` and `y` as unsigned and compute the modulo of `x` and `y`.
|
||||||
## The result is truncated to fit into the result.
|
## The result is truncated to fit into the result.
|
||||||
## This implements modulo arithmetic.
|
## This implements modulo arithmetic.
|
||||||
|
|
|
||||||
2
todo.txt
2
todo.txt
|
|
@ -1,7 +1,7 @@
|
||||||
version 0.9.0
|
version 0.9.0
|
||||||
=============
|
=============
|
||||||
|
|
||||||
- fix DLLs
|
- fix DLLs #169
|
||||||
- implicit deref for parameter matching
|
- implicit deref for parameter matching
|
||||||
- deprecate ``var x, y = 0`` as it's confusing for tuple consistency
|
- deprecate ``var x, y = 0`` as it's confusing for tuple consistency
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue