summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2016-06-20 23:36:51 +0200
committerAndreas Rumpf <rumpf_a@web.de>2016-06-21 11:50:24 +0200
commit2405f8e347a4cc3be0b1376c0baf795be7c2dd75 (patch)
tree87ad28bc2759bdfb72c4b3b5e4f0c4a29cd0faa0 /compiler
parentba285082bf9909e9bc21fa61e46cf4398d453102 (diff)
downloadNim-2405f8e347a4cc3be0b1376c0baf795be7c2dd75.tar.gz
PHP backend: proper setLen implementation
Diffstat (limited to 'compiler')
-rw-r--r--compiler/jsgen.nim5
1 files changed, 3 insertions, 2 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim
index 41e42b825..73b627f91 100644
--- a/compiler/jsgen.nim
+++ b/compiler/jsgen.nim
@@ -1678,8 +1678,9 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) =
     else:
       if optOverflowCheck notin p.options: binaryExpr(p, n, r, "", "$1 -= $2")
       else: binaryExpr(p, n, r, "subInt", "$1 = subInt($1, $2)")
-  of mSetLengthStr: binaryExpr(p, n, r, "", "$1.length = $2+1; $1[$1.length-1] = 0" | "")
-  of mSetLengthSeq: binaryExpr(p, n, r, "", "$1.length = $2" | "")
+  of mSetLengthStr:
+    binaryExpr(p, n, r, "", "$1.length = $2+1; $1[$1.length-1] = 0" | "$1 = substr($1, 0, $2)")
+  of mSetLengthSeq: binaryExpr(p, n, r, "", "$1.length = $2" | "$1 = array_slice($1, 0, $2)")
   of mCard: unaryExpr(p, n, r, "SetCard", "SetCard($1)")
   of mLtSet: binaryExpr(p, n, r, "SetLt", "SetLt($1, $2)")
   of mLeSet: binaryExpr(p, n, r, "SetLe", "SetLe($1, $2)")