summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/jsgen.nim45
-rw-r--r--lib/phpcl.nim2
2 files changed, 25 insertions, 22 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim
index da4c8f2bd..8470291fd 100644
--- a/compiler/jsgen.nim
+++ b/compiler/jsgen.nim
@@ -1435,29 +1435,29 @@ proc genConStrStrPHP(p: PProc, n: PNode, r: var TCompRes) =
     else:
       r.res.add(".$1" % [a.res])
 
+proc genToArray(p: PProc; n: PNode; r: var TCompRes) =
+  # we map mArray to PHP's array constructor, a mild hack:
+  var a, b: TCompRes
+  r.kind = resExpr
+  r.res = rope("array(")
+  let x = skipConv(n[1])
+  if x.kind == nkBracket:
+    for i in countup(0, x.len - 1):
+      let it = x[i]
+      if it.kind == nkPar and it.len == 2:
+        if i > 0: r.res.add(", ")
+        gen(p, it[0], a)
+        gen(p, it[1], b)
+        r.res.add("$# => $#" % [a.rdLoc, b.rdLoc])
+      else:
+        localError(it.info, "'toArray' needs tuple constructors")
+  else:
+    localError(x.info, "'toArray' needs an array literal")
+  r.res.add(")")
+
 proc genRepr(p: PProc, n: PNode, r: var TCompRes) =
   if p.target == targetPHP:
-    if n.sons[0].sym.name.s == "repr":
-      localError(n.info, "'repr' not available for PHP backend")
-    else:
-      # we map mRepr to PHP's array constructor, a mild hack:
-      var a, b: TCompRes
-      r.kind = resExpr
-      r.res = rope("array(")
-      let x = skipConv(n[1])
-      if x.kind == nkBracket:
-        for i in countup(0, x.len - 1):
-          let it = x[i]
-          if it.kind == nkPar and it.len == 2:
-            if i > 0: r.res.add(", ")
-            gen(p, it[0], a)
-            gen(p, it[1], b)
-            r.res.add("$# => $#" % [a.rdLoc, b.rdLoc])
-          else:
-            localError(it.info, "'toArray' needs tuple constructors")
-      else:
-        localError(x.info, "'toArray' needs an array literal")
-      r.res.add(")")
+    localError(n.info, "'repr' not available for PHP backend")
     return
   let t = skipTypes(n.sons[1].typ, abstractVarRange)
   case t.kind
@@ -1621,6 +1621,9 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) =
   of mParseBiggestFloat:
     useMagic(p, "nimParseBiggestFloat")
     genCall(p, n, r)
+  of mArray:
+    if p.target == targetPHP: genToArray(p, n, r)
+    else: genCall(p, n, r)
   else:
     genCall(p, n, r)
     #else internalError(e.info, 'genMagic: ' + magicToStr[op]);
diff --git a/lib/phpcl.nim b/lib/phpcl.nim
index 6d7aa0ea6..5eaa00f80 100644
--- a/lib/phpcl.nim
+++ b/lib/phpcl.nim
@@ -31,7 +31,7 @@ proc strtr*(s: string, replacePairs: PhpArray[string, string]): string {.importc
 proc strtr*(s, fromm, to: string): string {.importc.}
 
 proc toArray*[K,V](pairs: openarray[(K,V)]): PhpArray[K,V] {.magic:
-  "Repr".}
+  "Array".}
 template strtr*(s: string, replacePairs: openarray[(string, string)]): string =
   strtr(toArray(replacePairs))