summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--changelog.md3
-rw-r--r--compiler/ast.nim8
-rw-r--r--compiler/ccgexprs.nim21
-rw-r--r--compiler/jsgen.nim1
-rw-r--r--compiler/semfold.nim1
-rw-r--r--compiler/vmgen.nim2
6 files changed, 29 insertions, 7 deletions
diff --git a/changelog.md b/changelog.md
index 40c6c9ace..77a77f2f5 100644
--- a/changelog.md
+++ b/changelog.md
@@ -485,6 +485,9 @@
 - `nim r` now supports cross compilation from unix to windows when specifying `-d:mingw` by using wine,
   e.g.: `nim r --eval:'import os; echo "a" / "b"'` prints `a\b`
 
+- `nim` can compile version 1.4.0 as follows: `nim c --lib:lib --stylecheck:off -d:nimVersion140 compiler/nim`.
+  `-d:nimVersion140` is not needed for bootstrapping, only for building 1.4.0 from devel.
+
 - The style checking of the compiler now supports a `--styleCheck:usages` switch. This switch
   enforces that every symbol is written as it was declared, not enforcing
   the official Nim style guide. To be enabled, this has to be combined either
diff --git a/compiler/ast.nim b/compiler/ast.nim
index 5b54dd8ef..08fbc70e1 100644
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -652,7 +652,9 @@ type
     mUnaryMinusI, mUnaryMinusI64, mAbsI, mNot,
     mUnaryPlusI, mBitnotI,
     mUnaryPlusF64, mUnaryMinusF64,
-    mCharToStr, mBoolToStr, mIntToStr, mInt64ToStr, mCStrToStr,
+    mCharToStr, mBoolToStr, mIntToStr, mInt64ToStr,
+    mFloatToStr, # for -d:nimVersion140
+    mCStrToStr,
     mStrToStr, mEnumToStr,
     mAnd, mOr,
     mImplies, mIff, mExists, mForall, mOld,
@@ -720,7 +722,9 @@ const
     mEqRef, mEqProc, mLePtr, mLtPtr, mEqCString, mXor,
     mUnaryMinusI, mUnaryMinusI64, mAbsI, mNot, mUnaryPlusI, mBitnotI,
     mUnaryPlusF64, mUnaryMinusF64,
-    mCharToStr, mBoolToStr, mIntToStr, mInt64ToStr, mCStrToStr,
+    mCharToStr, mBoolToStr, mIntToStr, mInt64ToStr,
+    mFloatToStr,
+    mCStrToStr,
     mStrToStr, mEnumToStr,
     mAnd, mOr,
     mEqStr, mLeStr, mLtStr,
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index 7eb4a7a1d..374876367 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -894,15 +894,23 @@ proc genFieldCheck(p: BProc, e: PNode, obj: Rope, field: PSym) =
     let discIndex = rdSetElemLoc(p.config, v, u.t)
     if optTinyRtti in p.config.globalOptions:
       # not sure how to use `genEnumToStr` here
-      const code = "{ #raiseFieldError2($1, (NI)$3); $2} $n"
-      linefmt(p, cpsStmts, code, [strLit, raiseInstr(p), discIndex])
+      if p.config.isDefined("nimVersion140"):
+        const code = "{ #raiseFieldError($1); $2} $n"
+        linefmt(p, cpsStmts, code, [strLit, raiseInstr(p)])
+      else:
+        const code = "{ #raiseFieldError2($1, (NI)$3); $2} $n"
+        linefmt(p, cpsStmts, code, [strLit, raiseInstr(p), discIndex])
     else:
       # complication needed for signed types
       let first = p.config.firstOrd(disc.sym.typ)
       let firstLit = int64Literal(cast[int](first))
       let discName = genTypeInfo(p.config, p.module, disc.sym.typ, e.info)
-      const code = "{ #raiseFieldError2($1, #reprDiscriminant(((NI)$3) + (NI)$4, $5)); $2} $n"
-      linefmt(p, cpsStmts, code, [strLit, raiseInstr(p), discIndex, firstLit, discName])
+      if p.config.isDefined("nimVersion140"):
+        const code = "{ #raiseFieldError($1); $2} $n"
+        linefmt(p, cpsStmts, code, [strLit, raiseInstr(p)])
+      else:
+        const code = "{ #raiseFieldError2($1, #reprDiscriminant(((NI)$3) + (NI)$4, $5)); $2} $n"
+        linefmt(p, cpsStmts, code, [strLit, raiseInstr(p), discIndex, firstLit, discName])
 
 proc genCheckedRecordField(p: BProc, e: PNode, d: var TLoc) =
   assert e[0].kind == nkDotExpr
@@ -2320,6 +2328,11 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
   of mInt64ToStr: genDollar(p, e, d, "#nimInt64ToStr($1)")
   of mBoolToStr: genDollar(p, e, d, "#nimBoolToStr($1)")
   of mCharToStr: genDollar(p, e, d, "#nimCharToStr($1)")
+  of mFloatToStr:
+    if e[1].typ.skipTypes(abstractInst).kind == tyFloat32:
+      genDollar(p, e, d, "#nimFloat32ToStr($1)")
+    else:
+      genDollar(p, e, d, "#nimFloatToStr($1)")
   of mCStrToStr: genDollar(p, e, d, "#cstrToNimstr($1)")
   of mStrToStr, mUnown: expr(p, e[1], d)
   of mIsolate: genCall(p, e, d)
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim
index 3aa5c474e..931e56475 100644
--- a/compiler/jsgen.nim
+++ b/compiler/jsgen.nim
@@ -434,6 +434,7 @@ const # magic checked op; magic unchecked op;
     mBoolToStr: ["nimBoolToStr", "nimBoolToStr"],
     mIntToStr: ["cstrToNimstr", "cstrToNimstr"],
     mInt64ToStr: ["cstrToNimstr", "cstrToNimstr"],
+    mFloatToStr: ["cstrToNimstr", "cstrToNimstr"],
     mCStrToStr: ["cstrToNimstr", "cstrToNimstr"],
     mStrToStr: ["", ""]]
 
diff --git a/compiler/semfold.nim b/compiler/semfold.nim
index e5f0643bc..04ed73209 100644
--- a/compiler/semfold.nim
+++ b/compiler/semfold.nim
@@ -290,6 +290,7 @@ proc evalOp(m: TMagic, n, a, b, c: PNode; idgen: IdGenerator; g: ModuleGraph): P
   of mBoolToStr:
     if getOrdValue(a) == 0: result = newStrNodeT("false", n, g)
     else: result = newStrNodeT("true", n, g)
+  of mFloatToStr: result = newStrNodeT($getFloat(a), n, g)
   of mCStrToStr, mCharToStr:
     if a.kind == nkBracket:
       var s = ""
diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim
index 725afdd3f..f2758ff37 100644
--- a/compiler/vmgen.nim
+++ b/compiler/vmgen.nim
@@ -1127,7 +1127,7 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
     let t = skipTypes(n.typ, abstractVar-{tyTypeDesc})
     if t.kind in {tyUInt8..tyUInt32} or (t.kind == tyUInt and t.size < 8):
       c.gABC(n, opcNarrowU, dest, TRegister(t.size*8))
-  of mCharToStr, mBoolToStr, mIntToStr, mInt64ToStr, mCStrToStr, mStrToStr, mEnumToStr:
+  of mCharToStr, mBoolToStr, mIntToStr, mInt64ToStr, mFloatToStr, mCStrToStr, mStrToStr, mEnumToStr:
     genConv(c, n, n[1], dest)
   of mEqStr, mEqCString: genBinaryABC(c, n, dest, opcEqStr)
   of mLeStr: genBinaryABC(c, n, dest, opcLeStr)