summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2013-08-30 12:24:54 +0200
committerAraq <rumpf_a@web.de>2013-08-30 12:24:54 +0200
commit7056ceda6727d1725645ab046fee4c0d6bb15501 (patch)
tree813f151fb78f422a7b95f8240b9d010f15396e8b /compiler
parent1ad1980f1f9ebf68501a62de55a614207d8a5ec5 (diff)
downloadNim-7056ceda6727d1725645ab046fee4c0d6bb15501.tar.gz
float64 is now an alias to 'float'; fixes #545
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ccgexprs.nim14
-rw-r--r--compiler/magicsys.nim13
-rw-r--r--compiler/semexprs.nim2
-rw-r--r--compiler/semfold.nim7
-rw-r--r--compiler/sigmatch.nim10
-rw-r--r--compiler/types.nim3
6 files changed, 33 insertions, 16 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index 635756220..3475093cb 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -465,10 +465,11 @@ proc unaryArithOverflow(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
 proc binaryArith(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
   const
     binArithTab: array[mAddF64..mXor, string] = [
-      "($1 + $2)",            # AddF64
-      "($1 - $2)",            # SubF64
-      "($1 * $2)",            # MulF64
-      "($1 / $2)",            # DivF64
+      "(($4)($1) + ($4)($2))", # AddF64
+      "(($4)($1) - ($4)($2))", # SubF64
+      "(($4)($1) * ($4)($2))", # MulF64
+      "(($4)($1) / ($4)($2))", # DivF64
+      
       "($4)((NU$3)($1) >> (NU$3)($2))", # ShrI
       "($4)((NU$3)($1) << (NU$3)($2))", # ShlI
       "($4)($1 & $2)",      # BitandI
@@ -1488,8 +1489,9 @@ proc binaryFloatArith(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
     assert(e.sons[2].typ != nil)
     InitLocExpr(p, e.sons[1], a)
     InitLocExpr(p, e.sons[2], b)
-    putIntoDest(p, d, e.typ, rfmt(nil, "($2 $1 $3)",
-                                  toRope(opr[m]), rdLoc(a), rdLoc(b)))
+    putIntoDest(p, d, e.typ, rfmt(nil, "(($4)($2) $1 ($4)($3))",
+                                  toRope(opr[m]), rdLoc(a), rdLoc(b),
+                                  getSimpleTypeDesc(p.module, e[1].typ)))
     if optNanCheck in p.options:
       linefmt(p, cpsStmts, "#nanCheck($1);$n", rdLoc(d))
     if optInfCheck in p.options:
diff --git a/compiler/magicsys.nim b/compiler/magicsys.nim
index 1972dec98..88ae2cb12 100644
--- a/compiler/magicsys.nim
+++ b/compiler/magicsys.nim
@@ -115,11 +115,16 @@ proc getIntLitType*(literal: PNode): PType =
     result = copyType(ti, ti.owner, false)
     result.n = literal
 
+proc getFloatLitType*(literal: PNode): PType =
+  # for now we do not cache these:
+  result = newSysType(tyFloat, size=8)
+  result.n = literal
+
 proc skipIntLit*(t: PType): PType {.inline.} =
-  if t.kind == tyInt and t.n != nil:
-    result = getSysType(tyInt)
-  else:
-    result = t
+  if t.n != nil:
+    if t.kind in {tyInt, tyFloat}:
+      return getSysType(t.kind)
+  result = t
 
 proc AddSonSkipIntLit*(father, son: PType) =
   if isNil(father.sons): father.sons = @[]
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index d88cc28b6..354cbcbd1 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -1808,7 +1808,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
   of nkUInt64Lit: 
     if result.typ == nil: result.typ = getSysType(tyUInt64)
   of nkFloatLit: 
-    if result.typ == nil: result.typ = getSysType(tyFloat)
+    if result.typ == nil: result.typ = getFloatLitType(result)
   of nkFloat32Lit: 
     if result.typ == nil: result.typ = getSysType(tyFloat32)
   of nkFloat64Lit: 
diff --git a/compiler/semfold.nim b/compiler/semfold.nim
index 77ecf2e97..634ea8395 100644
--- a/compiler/semfold.nim
+++ b/compiler/semfold.nim
@@ -21,7 +21,7 @@ proc getConstExpr*(m: PSym, n: PNode): PNode
 proc evalOp*(m: TMagic, n, a, b, c: PNode): PNode
 proc leValueConv*(a, b: PNode): bool
 proc newIntNodeT*(intVal: BiggestInt, n: PNode): PNode
-proc newFloatNodeT*(floatVal: BiggestFloat, n: PNode): PNode
+proc newFloatNodeT(floatVal: BiggestFloat, n: PNode): PNode
 proc newStrNodeT*(strVal: string, n: PNode): PNode
 
 # implementation
@@ -43,7 +43,10 @@ proc newIntNodeT(intVal: BiggestInt, n: PNode): PNode =
 
 proc newFloatNodeT(floatVal: BiggestFloat, n: PNode): PNode = 
   result = newFloatNode(nkFloatLit, floatVal)
-  result.typ = n.typ
+  if skipTypes(n.typ, abstractVarRange).kind == tyFloat:
+    result.typ = getFloatLitType(result)
+  else:
+    result.typ = n.typ
   result.info = n.info
 
 proc newStrNodeT(strVal: string, n: PNode): PNode = 
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 626d16d64..27c780391 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -283,14 +283,18 @@ proc isConvertibleToRange(f, a: PType): bool =
        a.kind in {tyFloat..tyFloat128}:
     result = true
 
-proc handleFloatRange(f, a: PType): TTypeRelation = 
-  if a.kind == f.kind: 
+proc handleFloatRange(f, a: PType): TTypeRelation =
+  if a.kind == f.kind:
     result = isEqual
-  else: 
+  else:
     let ab = skipTypes(a, {tyRange})
     var k = ab.kind
     if k == f.kind: result = isSubrange
+    elif isFloatLit(ab): result = isFromIntLit
     elif isIntLit(ab): result = isConvertible
+    elif f.kind == tyFloat32:
+      # no conversion to "float32" as that might lose precision
+      result = isNone
     elif k >= tyFloat and k <= tyFloat128: result = isConvertible
     else: result = isNone
   
diff --git a/compiler/types.nim b/compiler/types.nim
index 2564741d8..084091630 100644
--- a/compiler/types.nim
+++ b/compiler/types.nim
@@ -109,6 +109,9 @@ proc getOrdValue(n: PNode): biggestInt =
 proc isIntLit*(t: PType): bool {.inline.} =
   result = t.kind == tyInt and t.n != nil and t.n.kind == nkIntLit
 
+proc isFloatLit*(t: PType): bool {.inline.} =
+  result = t.kind == tyFloat and t.n != nil and t.n.kind == nkFloatLit
+
 proc isCompatibleToCString(a: PType): bool = 
   if a.kind == tyArray: 
     if (firstOrd(a.sons[0]) == 0) and