summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2016-02-06 19:58:28 +0100
committerAndreas Rumpf <rumpf_a@web.de>2016-02-06 19:58:28 +0100
commit8ec7c0af2046e66fc4f3d3d8b04c06ddfc2b566d (patch)
tree79cb171fcb86b5f09e869ff243b9cd2e480c122b
parentdb4b9b1bdd3309ef8382ff1eda529f8634b12a33 (diff)
downloadNim-8ec7c0af2046e66fc4f3d3d8b04c06ddfc2b566d.tar.gz
php-codegen fixes
-rw-r--r--compiler/jsgen.nim11
-rw-r--r--lib/system/jssys.nim5
2 files changed, 12 insertions, 4 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim
index 972fcf393..7a927f41e 100644
--- a/compiler/jsgen.nim
+++ b/compiler/jsgen.nim
@@ -180,12 +180,15 @@ proc mangleName(s: PSym; target: TTarget): Rope =
       var i = 0
       while i < s.name.s.len:
         let c = s.name.s[i]
-        if c in {'A'..'Z'}:
+        case c
+        of 'A'..'Z':
           if i > 0 and s.name.s[i-1] in {'a'..'z'}:
             x.add '_'
           x.add(chr(c.ord - 'A'.ord + 'a'.ord))
-        else:
+        of 'a'..'z', '_', '0'..'9':
           x.add c
+        else:
+          x.add("HEX" & toHex(ord(c), 2))
         inc i
       result = rope(x)
     add(result, "_")
@@ -1571,7 +1574,7 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) =
                              "(strlen($1)-1)")
     else:
       unaryExpr(p, n, r, "", "($1 != null ? ($1.length-1) : -1)" |
-                             "(count($1.length)-1)")
+                             "(count($1)-1)")
   of mInc:
     if n[1].typ.skipTypes(abstractRange).kind in tyUInt .. tyUInt64:
       binaryUintExpr(p, n, r, "+", true)
@@ -1614,7 +1617,7 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) =
     if p.target == targetJS:
       unaryExpr(p, n, r, "mnewString", "mnewString(0)")
     else:
-      unaryExpr(p, n, r, "", "$# = ''")
+      unaryExpr(p, n, r, "", "''")
   of mDotDot:
     genProcForSymIfNeeded(p, n.sons[0].sym)
     genCall(p, n, r)
diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim
index 8394396b5..ceeb5563f 100644
--- a/lib/system/jssys.nim
+++ b/lib/system/jssys.nim
@@ -275,6 +275,11 @@ proc mnewString(len: int): string {.asmNoStackFrame, compilerproc.} =
       return result;
     """
 
+when defined(nimphp):
+  proc nimSubstr(s: string; a, b: int): string {.
+      asmNoStackFrame, compilerproc.} =
+    asm """return substr(`s`,`a`,`b`-`a`+1);"""
+
 proc SetCard(a: int): int {.compilerproc, asmNoStackFrame.} =
   # argument type is a fake
   when defined(nimphp):