summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2016-03-04 21:59:58 +0100
committerAndreas Rumpf <rumpf_a@web.de>2016-03-04 21:59:58 +0100
commit92cf673f37c077a90cc8e95f641810ae31a6fbc7 (patch)
tree4a174b84051098820f4adade68f43ae41a5a4f7b /compiler
parent180a4b7657260af5411a4bea58240d3cac2ea0fe (diff)
downloadNim-92cf673f37c077a90cc8e95f641810ae31a6fbc7.tar.gz
PHP codegen: use nimAt for PHP 5.3 compatibility
Diffstat (limited to 'compiler')
-rw-r--r--compiler/jsgen.nim13
1 files changed, 11 insertions, 2 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim
index d6b546d8b..8aaad6327 100644
--- a/compiler/jsgen.nim
+++ b/compiler/jsgen.nim
@@ -944,8 +944,17 @@ proc genArrayAccess(p: PProc, n: PNode, r: var TCompRes) =
   else: internalError(n.info, "expr(nkBracketExpr, " & $ty.kind & ')')
   r.typ = etyNone
   if r.res == nil: internalError(n.info, "genArrayAccess")
-  if p.target == targetPHP and ty.kind in {tyString, tyCString}:
-    r.res = "ord($1[$2])" % [r.address, r.res]
+  if p.target == targetPHP:
+    if n.sons[0].kind in nkCallKinds+{nkStrLit..nkTripleStrLit}:
+      useMagic(p, "nimAt")
+      if ty.kind in {tyString, tyCString}:
+        r.res = "ord(nimAt($1, $2))" % [r.address, r.res]
+      else:
+        r.res = "nimAt($1, $2)" % [r.address, r.res]
+    elif ty.kind in {tyString, tyCString}:
+      r.res = "ord($1[$2])" % [r.address, r.res]
+    else:
+      r.res = "$1[$2]" % [r.address, r.res]
   else:
     r.res = "$1[$2]" % [r.address, r.res]
   r.address = nil