'+=' etc for all floating point types
This commit is contained in:
parent
f3980eb24a
commit
b5d8e8bfaa
6 changed files with 21 additions and 13 deletions
|
|
@ -144,7 +144,7 @@ proc mapSetType(typ: PType): TCTypeKind =
|
||||||
|
|
||||||
proc mapType(typ: PType): TCTypeKind =
|
proc mapType(typ: PType): TCTypeKind =
|
||||||
case typ.kind
|
case typ.kind
|
||||||
of tyNone: result = ctVoid
|
of tyNone, tyStmt: result = ctVoid
|
||||||
of tyBool: result = ctBool
|
of tyBool: result = ctBool
|
||||||
of tyChar: result = ctChar
|
of tyChar: result = ctChar
|
||||||
of tySet: result = mapSetType(typ)
|
of tySet: result = mapSetType(typ)
|
||||||
|
|
|
||||||
|
|
@ -869,8 +869,9 @@ proc typeAllowedAux(marker: var TIntSet, typ: PType, kind: TSymKind): bool =
|
||||||
result = typeAllowedAux(marker, t.sons[0], skResult)
|
result = typeAllowedAux(marker, t.sons[0], skResult)
|
||||||
of tyExpr, tyStmt, tyTypeDesc:
|
of tyExpr, tyStmt, tyTypeDesc:
|
||||||
result = true
|
result = true
|
||||||
of tyGenericBody, tyGenericParam, tyForward, tyNone, tyGenericInvokation, tyTypeClass:
|
of tyGenericBody, tyGenericParam, tyForward, tyNone, tyGenericInvokation,
|
||||||
result = false #InternalError('shit found');
|
tyTypeClass:
|
||||||
|
result = false
|
||||||
of tyEmpty, tyNil:
|
of tyEmpty, tyNil:
|
||||||
result = kind == skConst
|
result = kind == skConst
|
||||||
of tyString, tyBool, tyChar, tyEnum, tyInt..tyBigNum, tyCString, tyPointer:
|
of tyString, tyBool, tyChar, tyEnum, tyInt..tyBigNum, tyCString, tyPointer:
|
||||||
|
|
|
||||||
|
|
@ -2184,19 +2184,19 @@ proc `*=`*[T](x: var ordinal[T], y: ordinal[T]) {.inline, noSideEffect.} =
|
||||||
## Binary `*=` operator for ordinals
|
## Binary `*=` operator for ordinals
|
||||||
x = x * y
|
x = x * y
|
||||||
|
|
||||||
proc `+=` *(x: var float, y:float) {.inline, noSideEffect.} =
|
proc `+=`*[T: float|float32|float64] (x: var T, y: T) {.inline, noSideEffect.} =
|
||||||
## Increments in placee a floating point number
|
## Increments in placee a floating point number
|
||||||
x = x + y
|
x = x + y
|
||||||
|
|
||||||
proc `-=` *(x: var float, y:float) {.inline, noSideEffect.} =
|
proc `-=`*[T: float|float32|float64] (x: var T, y: T) {.inline, noSideEffect.} =
|
||||||
## Decrements in place a floating point number
|
## Decrements in place a floating point number
|
||||||
x = x - y
|
x = x - y
|
||||||
|
|
||||||
proc `*=` *(x: var float, y:float) {.inline, noSideEffect.} =
|
proc `*=`*[T: float|float32|float64] (x: var T, y: T) {.inline, noSideEffect.} =
|
||||||
## Multiplies in place a floating point number
|
## Multiplies in place a floating point number
|
||||||
x = x * y
|
x = x * y
|
||||||
|
|
||||||
proc `/=` *(x: var float, y:float) {.inline, noSideEffect.} =
|
proc `/=`*[T: float|float32|float64] (x: var T, y: T) {.inline, noSideEffect.} =
|
||||||
## Divides in place a floating point number
|
## Divides in place a floating point number
|
||||||
x = x / y
|
x = x / y
|
||||||
|
|
||||||
|
|
|
||||||
9
tests/reject/tenummix.nim
Normal file
9
tests/reject/tenummix.nim
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "type mismatch"
|
||||||
|
"""
|
||||||
|
|
||||||
|
type
|
||||||
|
TE1 = enum eA, eB
|
||||||
|
TE2 = enum eC, eD
|
||||||
|
|
||||||
|
assert eA != eC
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
|
disabled: true
|
||||||
output: '''StmtList
|
output: '''StmtList
|
||||||
VarSection
|
VarSection
|
||||||
IdentDefs
|
IdentDefs
|
||||||
|
|
@ -11,6 +12,8 @@ output: '''StmtList
|
||||||
IntLit 56'''
|
IntLit 56'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# disabled; can't work as the output is done by the compiler
|
||||||
|
|
||||||
import macros
|
import macros
|
||||||
|
|
||||||
#emit("type\n TFoo = object\n bar: int")
|
#emit("type\n TFoo = object\n bar: int")
|
||||||
|
|
|
||||||
7
todo.txt
7
todo.txt
|
|
@ -33,14 +33,9 @@ version 0.9.0
|
||||||
error handling more light-weight
|
error handling more light-weight
|
||||||
people also want ``inc a; inc b``
|
people also want ``inc a; inc b``
|
||||||
|
|
||||||
|
|
||||||
Bugs
|
Bugs
|
||||||
----
|
----
|
||||||
- bug: returning a tyVar does not mean it is save to return it:
|
|
||||||
proc forward[T](x: var T): var T = result = x
|
|
||||||
proc p(): var int =
|
|
||||||
var x: int
|
|
||||||
# reject this call via alias analysis:
|
|
||||||
result = forward(x)
|
|
||||||
|
|
||||||
- bug: stress testing basic method example (eval example)
|
- bug: stress testing basic method example (eval example)
|
||||||
without ``-d:release`` leaks memory?
|
without ``-d:release`` leaks memory?
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue