summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorHans Raaf <hara@oderwat.de>2016-02-07 06:00:14 +0100
committerHans Raaf <hara@oderwat.de>2016-02-07 18:01:13 +0100
commit2522ac9133744b94ea58e07abb1d2b5099165109 (patch)
tree9b716d424e6584e4b6e3471500410fe0a933ffba /compiler
parente66f5c419c0b4728b0a9e2c12e13e23c4509d8b1 (diff)
downloadNim-2522ac9133744b94ea58e07abb1d2b5099165109.tar.gz
Made the test tints.nim work for the PHP codegen (uint shifts and
casts).
Diffstat (limited to 'compiler')
-rw-r--r--compiler/jsgen.nim6
1 files changed, 5 insertions, 1 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim
index 052f482ac..f01d4d877 100644
--- a/compiler/jsgen.nim
+++ b/compiler/jsgen.nim
@@ -411,6 +411,7 @@ proc unsignedTrimmerPHP(size: BiggestInt): Rope =
   case size
     of 1: rope"& 0xff"
     of 2: rope"& 0xffff"
+    of 4: rope"& 0xffffffff"
     else: rope""
 
 template unsignedTrimmer(size: BiggestInt): Rope =
@@ -466,6 +467,7 @@ proc arith(p: PProc, n: PNode, r: var TCompRes, op: TMagic) =
     gen(p, n.sons[2], y)
     let trimmer = unsignedTrimmer(n[1].typ.skipTypes(abstractRange).size)
     if p.target == targetPHP:
+      # XXX prevent multi evaluations
       r.res = "(($1 $2) >= 0) ? (($1 $2) >> $3) : ((($1 $2) & 0x7fffffff) >> $3) | (0x40000000 >> ($3 - 1))" % [x.rdLoc, trimmer, y.rdLoc]
     else:
       r.res = "(($1 $2) >>> $3)" % [x.rdLoc, trimmer, y.rdLoc]
@@ -1864,7 +1866,9 @@ proc genCast(p: PProc, n: PNode, r: var TCompRes) =
       r.res = "($1 $2)" % [r.res, trimmer]
     elif fromUint:
       if src.size == 4 and dest.size == 4:
-        r.res = "($1|0)" % [r.res]
+        # XXX prevent multi evaluations
+        r.res = "($1|0)" % [r.res] |
+          "($1>(float)2147483647?(int)$1-4294967296:$1)" % [r.res]
       else:
         let trimmer = unsignedTrimmer(dest.size)
         let minuend = case dest.size